@peers-app/peers-ui 0.34.11 → 0.34.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/dist/components/markdown-editor/editor.d.ts +36 -0
  2. package/dist/components/markdown-editor/editor.js +16 -0
  3. package/dist/components/markdown-editor/format-bar.d.ts +16 -0
  4. package/dist/components/markdown-editor/format-bar.js +132 -0
  5. package/dist/components/markdown-editor/format-commands.d.ts +25 -0
  6. package/dist/components/markdown-editor/format-commands.js +140 -0
  7. package/dist/components/markdown-editor/format.d.ts +36 -0
  8. package/dist/components/markdown-editor/format.js +47 -0
  9. package/dist/components/markdown-editor/lexical-editor.d.ts +1 -0
  10. package/dist/components/markdown-editor/lexical-editor.js +5 -1
  11. package/dist/components/markdown-editor/link-plugin.d.ts +9 -5
  12. package/dist/components/markdown-editor/link-plugin.js +47 -22
  13. package/dist/components/markdown-editor/selection-effects-plugin.d.ts +8 -1
  14. package/dist/components/markdown-editor/selection-effects-plugin.js +25 -1
  15. package/dist/components/markdown-render.js +21 -8
  16. package/dist/components/markdown-with-mentions.d.ts +6 -4
  17. package/dist/components/markdown-with-mentions.js +6 -4
  18. package/dist/host-shell/host-shell-consumer.d.ts +13 -5
  19. package/dist/host-shell/host-shell-consumer.js +31 -16
  20. package/dist/index.d.ts +4 -2
  21. package/dist/index.js +5 -1
  22. package/dist/isolated-screens/frame-runtime.js +14 -15
  23. package/dist/links/app-link-prompt.d.ts +29 -0
  24. package/dist/links/app-link-prompt.js +102 -0
  25. package/dist/links/link-schemes.d.ts +30 -0
  26. package/dist/links/link-schemes.js +46 -0
  27. package/dist/links/peers-links.d.ts +33 -0
  28. package/dist/links/peers-links.js +124 -0
  29. package/dist/mentions/mention-chooser.d.ts +12 -0
  30. package/dist/mentions/mention-chooser.js +48 -13
  31. package/dist/root-layout/root-layout-host.js +10 -1
  32. package/dist/screens/invites/accept-invite.js +3 -4
  33. package/dist/screens/invites/invite-capture.d.ts +2 -7
  34. package/dist/screens/invites/invite-capture.js +8 -25
  35. package/dist/screens/settings/settings-page.js +3 -1
  36. package/dist/theme.css +83 -0
  37. package/package.json +3 -3
@@ -1,5 +1,6 @@
1
1
  import type { IMentionLink, Observable } from "@peers-app/peers-sdk";
2
2
  import type React from "react";
3
+ import { type EditorFormat, type ISelectionAction } from "./format";
3
4
  import type { IToolbarControl } from "./toolbar";
4
5
  import "prismjs";
5
6
  /**
@@ -25,6 +26,12 @@ export interface IEditorEffects {
25
26
  * Returns false, changing nothing, when nothing is selected. Set by the editor.
26
27
  */
27
28
  replaceSelectionWithMention?: (link: IMentionLink) => boolean;
29
+ /**
30
+ * Type text at the caret, in place of any selection, and focus the editor, as if typed. An @
31
+ * button types `@`; as with a typed `@`, the mention picker opens once a name follows, if the
32
+ * `@` starts a word. Set by the editor once it has mounted.
33
+ */
34
+ insertText?: (text: string) => void;
28
35
  }
29
36
  /** What {@link MarkdownEditor} takes. */
30
37
  export interface IMarkdownEditorProps {
@@ -38,6 +45,14 @@ export interface IMarkdownEditorProps {
38
45
  autoFocus?: boolean;
39
46
  /** Leave out the formatting toolbar. */
40
47
  hideToolbar?: boolean;
48
+ /**
49
+ * A bar over selected text, with a mouse or trackpad: bold, italic, strikethrough, link and
50
+ * code, then `selectionActions`. For an editor without the toolbar; a touch screen gets
51
+ * {@link MarkdownFormatRow} instead, where the app puts it.
52
+ */
53
+ selectionToolbar?: boolean;
54
+ /** The app's own buttons on the bar over selected text, such as Notes' Make note. */
55
+ selectionActions?: ISelectionAction[];
41
56
  /** Scroll inside the editor past this height. */
42
57
  maxHeight?: string | number;
43
58
  /**
@@ -73,3 +88,24 @@ export interface IMarkdownEditorProps {
73
88
  * Edits are written back to `value`.
74
89
  */
75
90
  export declare function MarkdownEditor(props: IMarkdownEditorProps): React.FunctionComponentElement<IMarkdownEditorProps>;
91
+ /** What {@link MarkdownFormatRow} takes. */
92
+ export interface IMarkdownFormatRowProps {
93
+ /** The same object passed to the {@link MarkdownEditor} the row formats. */
94
+ effects: IEditorEffects;
95
+ /** The buttons, in order; every format if omitted. */
96
+ formats?: readonly EditorFormat[];
97
+ /** Classes for the row, for the app's own spacing. */
98
+ className?: string;
99
+ }
100
+ /**
101
+ * A row of formatting buttons for a {@link MarkdownEditor}, placed wherever the app wants it, such
102
+ * as above a phone's keyboard behind an Aa button: bold, italic, strikethrough, link, code, the
103
+ * three list kinds and quote, each on while the selection has it. A press keeps the editor's focus
104
+ * and selection, except Link's, which opens the link field (as ⌘⇧K does). It works once the
105
+ * editor given the same `effects` has mounted.
106
+ */
107
+ export declare function MarkdownFormatRow(props: IMarkdownFormatRowProps): React.FunctionComponentElement<{
108
+ effects: IEditorEffects;
109
+ formats: readonly EditorFormat[];
110
+ className?: string;
111
+ }>;
@@ -1,8 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MarkdownEditor = MarkdownEditor;
4
+ exports.MarkdownFormatRow = MarkdownFormatRow;
4
5
  const react_1 = require("react");
5
6
  const lazy_module_1 = require("../../lazy-module");
7
+ const format_1 = require("./format");
6
8
  // Prism, which colors the editor's code blocks, still loads with peers-ui. When Prism first loads
7
9
  // it colors every `language-*` code block on the page, and it becomes the page's `Prism`. Loaded
8
10
  // at the first editor instead, it would rewrite code blocks React had already drawn, which then
@@ -27,3 +29,17 @@ const lexicalEditor = (0, lazy_module_1.lazyModule)(() => require("./lexical-edi
27
29
  function MarkdownEditor(props) {
28
30
  return (0, react_1.createElement)(lexicalEditor().LexicalMarkdownEditor, props);
29
31
  }
32
+ /**
33
+ * A row of formatting buttons for a {@link MarkdownEditor}, placed wherever the app wants it, such
34
+ * as above a phone's keyboard behind an Aa button: bold, italic, strikethrough, link, code, the
35
+ * three list kinds and quote, each on while the selection has it. A press keeps the editor's focus
36
+ * and selection, except Link's, which opens the link field (as ⌘⇧K does). It works once the
37
+ * editor given the same `effects` has mounted.
38
+ */
39
+ function MarkdownFormatRow(props) {
40
+ return (0, react_1.createElement)(lexicalEditor().LexicalFormatRow, {
41
+ effects: props.effects,
42
+ formats: props.formats ?? format_1.ALL_FORMATS,
43
+ className: props.className,
44
+ });
45
+ }
@@ -0,0 +1,16 @@
1
+ import type { IEditorEffects } from "./editor";
2
+ import { type EditorFormat, type ISelectionAction } from "./format";
3
+ /**
4
+ * The bar over selected text: bold, italic, strikethrough, link and code, then the app's own
5
+ * buttons. Only with a mouse or trackpad: on a touch screen the system's own menu takes the
6
+ * selection, and the app shows `MarkdownFormatRow` instead.
7
+ */
8
+ export declare function SelectionToolbarPlugin({ actions }: {
9
+ actions?: ISelectionAction[];
10
+ }): import("react/jsx-runtime").JSX.Element | null;
11
+ /** `MarkdownFormatRow`'s implementation. */
12
+ export declare function LexicalFormatRow({ effects, formats, className, }: {
13
+ effects: IEditorEffects;
14
+ formats: readonly EditorFormat[];
15
+ className?: string;
16
+ }): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,132 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SelectionToolbarPlugin = SelectionToolbarPlugin;
4
+ exports.LexicalFormatRow = LexicalFormatRow;
5
+ const jsx_runtime_1 = require("react/jsx-runtime");
6
+ // The bar over selected text and the Aa row (`MarkdownFormatRow`). They load with the editor.
7
+ const LexicalComposerContext_1 = require("@lexical/react/LexicalComposerContext");
8
+ const react_1 = require("react");
9
+ const format_1 = require("./format");
10
+ const format_commands_1 = require("./format-commands");
11
+ /** A press on a bar's button keeps the editor's focus and selection, and a phone's keyboard. */
12
+ const keepFocus = (event) => event.preventDefault();
13
+ /** One button per format, on while the selection has it. */
14
+ function FormatButtons({ formats, state, onFormat, }) {
15
+ return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: formats.map((format) => ((0, jsx_runtime_1.jsx)("button", { type: "button", className: `editor-format-button${state[format] ? " active" : ""}`, "aria-label": format_1.FORMAT_BUTTONS[format].label, "aria-pressed": state[format], title: format_1.FORMAT_BUTTONS[format].label, tabIndex: -1, onPointerDown: keepFocus, onMouseDown: keepFocus, onClick: () => onFormat(format), children: (0, jsx_runtime_1.jsx)("i", { className: `bi bi-${format_1.FORMAT_BUTTONS[format].icon}` }) }, format))) }));
16
+ }
17
+ /**
18
+ * The bar's height and the gap to the text, for placing it above the selection or below: 32 px
19
+ * buttons, 3 px padding and a 1 px border make 40, then 16 to the text (theme.css).
20
+ */
21
+ const BAR_ROOM_PX = 56;
22
+ /**
23
+ * Where the bar over the selection goes, relative to the editor's container: above the selected
24
+ * text, centered on it, or below it when there's no room above in the window.
25
+ */
26
+ function barPlace(editor) {
27
+ const root = editor.getRootElement();
28
+ const selection = root?.ownerDocument.getSelection();
29
+ // Blink's isCollapsed getter requests layout even for a cached caret. A text control can
30
+ // report "Range" with a collapsed document selection, so keep that check for ranges.
31
+ if (!root || selection?.type !== "Range" || selection.isCollapsed)
32
+ return undefined;
33
+ if (!root.contains(selection.anchorNode) || !root.contains(selection.focusNode))
34
+ return undefined;
35
+ if (!finePointer())
36
+ return undefined;
37
+ const container = root.closest(".editor-container");
38
+ if (!container)
39
+ return undefined;
40
+ const rect = selection.getRangeAt(0).getBoundingClientRect();
41
+ if (!rect.width && !rect.height)
42
+ return undefined;
43
+ const frame = container.getBoundingClientRect();
44
+ const below = rect.top < BAR_ROOM_PX;
45
+ return {
46
+ top: (below ? rect.bottom : rect.top) - frame.top,
47
+ left: rect.left - frame.left + rect.width / 2,
48
+ below,
49
+ };
50
+ }
51
+ /** A pointer that can select text precisely: a mouse or trackpad, not a finger. */
52
+ const finePointer = () => typeof window === "undefined" ||
53
+ !window.matchMedia ||
54
+ window.matchMedia("(pointer: fine)").matches;
55
+ /**
56
+ * The bar over selected text: bold, italic, strikethrough, link and code, then the app's own
57
+ * buttons. Only with a mouse or trackpad: on a touch screen the system's own menu takes the
58
+ * selection, and the app shows `MarkdownFormatRow` instead.
59
+ */
60
+ function SelectionToolbarPlugin({ actions }) {
61
+ const [editor] = (0, LexicalComposerContext_1.useLexicalComposerContext)();
62
+ const [place, setPlace] = (0, react_1.useState)();
63
+ const [state, setState] = (0, react_1.useState)(format_1.NO_FORMAT);
64
+ const bar = (0, react_1.useRef)(null);
65
+ (0, react_1.useEffect)(() => {
66
+ // While a mouse drag selects text the bar waits, so it doesn't appear under the pointer and
67
+ // catch an upward drag; it shows when the button comes up.
68
+ let dragging = false;
69
+ const update = () => {
70
+ const next = dragging ? undefined : barPlace(editor);
71
+ setPlace(next);
72
+ if (next)
73
+ setState(editor.getEditorState().read(format_commands_1.$formatState));
74
+ };
75
+ const down = (event) => {
76
+ const root = editor.getRootElement();
77
+ if (event.button !== 0 || !root?.contains(event.target))
78
+ return;
79
+ dragging = true;
80
+ setPlace(undefined);
81
+ };
82
+ const up = () => {
83
+ if (!dragging)
84
+ return;
85
+ dragging = false;
86
+ update();
87
+ };
88
+ const doc = editor.getRootElement()?.ownerDocument ?? document;
89
+ update();
90
+ doc.addEventListener("selectionchange", update);
91
+ doc.addEventListener("pointerdown", down, true);
92
+ doc.addEventListener("pointerup", up, true);
93
+ doc.addEventListener("pointercancel", up, true);
94
+ const stopUpdates = editor.registerUpdateListener(update);
95
+ return () => {
96
+ doc.removeEventListener("selectionchange", update);
97
+ doc.removeEventListener("pointerdown", down, true);
98
+ doc.removeEventListener("pointerup", up, true);
99
+ doc.removeEventListener("pointercancel", up, true);
100
+ stopUpdates();
101
+ };
102
+ }, [editor]);
103
+ // Kept inside the editor's container, so a selection near its edge doesn't push the bar out.
104
+ // Measured again when the app's actions change the visible bar's width; while it's hidden, a
105
+ // new actions array (as from typing) costs no measurement.
106
+ (0, react_1.useLayoutEffect)(() => {
107
+ const element = bar.current;
108
+ const container = element?.parentElement;
109
+ if (!element || !container || !place)
110
+ return;
111
+ const half = element.offsetWidth / 2;
112
+ const left = Math.min(Math.max(place.left, half), container.clientWidth - half);
113
+ element.style.left = `${left}px`;
114
+ }, [place, place && actions]);
115
+ if (!place)
116
+ return null;
117
+ return ((0, jsx_runtime_1.jsxs)("div", { ref: bar, className: `editor-selection-bar${place.below ? " below" : ""}`, role: "toolbar", "aria-label": "Format selected text", style: { top: place.top, left: place.left }, onPointerDown: keepFocus, onMouseDown: keepFocus, children: [(0, jsx_runtime_1.jsx)(FormatButtons, { formats: format_1.INLINE_FORMATS, state: state, onFormat: (format) => (0, format_commands_1.applyFormat)(editor, format) }), actions?.length ? (0, jsx_runtime_1.jsx)("span", { className: "editor-format-divider" }) : null, actions?.map((action) => ((0, jsx_runtime_1.jsxs)("button", { type: "button", className: "editor-format-button editor-format-action", title: action.title, disabled: action.disabled, onClick: action.onClick, children: [(0, jsx_runtime_1.jsx)("i", { className: `bi ${action.iconClass}` }), action.label] }, action.label)))] }));
118
+ }
119
+ /** The editor `effects` belongs to, kept current as it mounts and unmounts. */
120
+ function useEditorFor(effects) {
121
+ return (0, react_1.useSyncExternalStore)((changed) => (0, format_commands_1.onEditorAttached)(effects, changed), () => (0, format_commands_1.editorFor)(effects));
122
+ }
123
+ /** `MarkdownFormatRow`'s implementation. */
124
+ function LexicalFormatRow({ effects, formats, className, }) {
125
+ const editor = useEditorFor(effects);
126
+ const [state, setState] = (0, react_1.useState)(format_1.NO_FORMAT);
127
+ (0, react_1.useEffect)(() => (editor ? (0, format_commands_1.watchFormat)(editor, setState) : undefined), [editor]);
128
+ return ((0, jsx_runtime_1.jsx)("div", { className: `editor-format-row${className ? ` ${className}` : ""}`, role: "toolbar", "aria-label": "Formatting", onPointerDown: keepFocus, onMouseDown: keepFocus, children: (0, jsx_runtime_1.jsx)(FormatButtons, { formats: formats, state: editor ? state : format_1.NO_FORMAT, onFormat: (format) => {
129
+ if (editor)
130
+ (0, format_commands_1.applyFormat)(editor, format);
131
+ } }) }));
132
+ }
@@ -0,0 +1,25 @@
1
+ import { type LexicalEditor } from "lexical";
2
+ import type { IEditorEffects } from "./editor";
3
+ import { type EditorFormat, type IFormatState } from "./format";
4
+ /** Which formats the selection has. Inside an editor read. */
5
+ export declare function $formatState(): IFormatState;
6
+ /**
7
+ * Apply a format to the selection, or take it off when the selection has it; Link opens the link
8
+ * popup instead. With nothing selected, an inline format applies to what's typed next, as Cmd+B
9
+ * does.
10
+ *
11
+ * @param editor - The editor to change.
12
+ * @param format - What to apply.
13
+ */
14
+ export declare function applyFormat(editor: LexicalEditor, format: EditorFormat): void;
15
+ /**
16
+ * Follow the selection's formats: `listener` hears them now and after every change, until the
17
+ * returned function is called.
18
+ */
19
+ export declare function watchFormat(editor: LexicalEditor, listener: (state: IFormatState) => void): () => void;
20
+ /** Note that `effects` now belongs to `editor` (or to none), and tell whoever follows it. */
21
+ export declare function attachEditor(effects: IEditorEffects, editor: LexicalEditor | undefined): void;
22
+ /** The editor `effects` belongs to, if it's mounted. */
23
+ export declare function editorFor(effects: IEditorEffects): LexicalEditor | undefined;
24
+ /** Hear when `effects` gets or loses its editor, until the returned function is called. */
25
+ export declare function onEditorAttached(effects: IEditorEffects, listener: () => void): () => void;
@@ -0,0 +1,140 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.$formatState = $formatState;
4
+ exports.applyFormat = applyFormat;
5
+ exports.watchFormat = watchFormat;
6
+ exports.attachEditor = attachEditor;
7
+ exports.editorFor = editorFor;
8
+ exports.onEditorAttached = onEditorAttached;
9
+ // Formatting commands shared by the toolbar, the bar over selected text and the Aa row
10
+ // (`MarkdownFormatRow`). They load with the editor.
11
+ const list_1 = require("@lexical/list");
12
+ const rich_text_1 = require("@lexical/rich-text");
13
+ const utils_1 = require("@lexical/utils");
14
+ const lexical_1 = require("lexical");
15
+ const format_1 = require("./format");
16
+ const link_plugin_1 = require("./link-plugin");
17
+ /** Which formats the selection has. Inside an editor read. */
18
+ function $formatState() {
19
+ const selection = (0, lexical_1.$getSelection)();
20
+ if (!(0, lexical_1.$isRangeSelection)(selection))
21
+ return format_1.NO_FORMAT;
22
+ const anchor = selection.anchor.getNode();
23
+ const list = (0, utils_1.$getNearestNodeOfType)(anchor, list_1.ListNode);
24
+ const listType = list?.getListType();
25
+ return {
26
+ bold: selection.hasFormat("bold"),
27
+ italic: selection.hasFormat("italic"),
28
+ strikethrough: selection.hasFormat("strikethrough"),
29
+ code: selection.hasFormat("code"),
30
+ link: (0, link_plugin_1.$selectedLink)(selection) !== null,
31
+ bulletList: listType === "bullet",
32
+ numberList: listType === "number",
33
+ checkList: listType === "check",
34
+ // Callouts also inherit from QuoteNode and keep their own markdown marker.
35
+ quote: anchor.getTopLevelElement()?.getType() === "quote",
36
+ };
37
+ }
38
+ /** Toggle paragraphs and ordinary quotes in the selection. Inside an editor update. */
39
+ function $toggleQuote() {
40
+ const selection = (0, lexical_1.$getSelection)();
41
+ if (!(0, lexical_1.$isRangeSelection)(selection))
42
+ return;
43
+ const blocks = new Set();
44
+ let off = true;
45
+ for (const node of [selection.anchor.getNode(), ...selection.getNodes()]) {
46
+ const block = node.getTopLevelElement();
47
+ if (!(0, lexical_1.$isElementNode)(block))
48
+ continue;
49
+ if (block.getType() === "paragraph")
50
+ off = false;
51
+ else if (block.getType() !== "quote")
52
+ continue;
53
+ blocks.add(block);
54
+ }
55
+ // A quoted anchor toggles off even in a mixed range. From a protected block, quote any
56
+ // remaining paragraphs first so the next press can unquote the same range.
57
+ off ||= selection.anchor.getNode().getTopLevelElement()?.getType() === "quote";
58
+ for (const block of blocks) {
59
+ if (block.getType() !== (off ? "quote" : "paragraph"))
60
+ continue;
61
+ block.replace((off ? (0, lexical_1.$createParagraphNode)() : (0, rich_text_1.$createQuoteNode)())
62
+ .setIndent(block.getIndent())
63
+ .setFormat(block.getFormatType())
64
+ .setTextFormat(block.getTextFormat())
65
+ .setDirection(block.getDirection()), true);
66
+ }
67
+ }
68
+ /**
69
+ * Apply a format to the selection, or take it off when the selection has it; Link opens the link
70
+ * popup instead. With nothing selected, an inline format applies to what's typed next, as Cmd+B
71
+ * does.
72
+ *
73
+ * @param editor - The editor to change.
74
+ * @param format - What to apply.
75
+ */
76
+ function applyFormat(editor, format) {
77
+ switch (format) {
78
+ case "bold":
79
+ case "italic":
80
+ case "strikethrough":
81
+ case "code":
82
+ editor.dispatchCommand(lexical_1.FORMAT_TEXT_COMMAND, format);
83
+ return;
84
+ case "link":
85
+ editor.dispatchCommand(link_plugin_1.OPEN_LINK_EDITOR_COMMAND, undefined);
86
+ return;
87
+ case "bulletList":
88
+ case "numberList":
89
+ case "checkList":
90
+ if (editor.getEditorState().read($formatState)[format])
91
+ editor.dispatchCommand(list_1.REMOVE_LIST_COMMAND, undefined);
92
+ else
93
+ editor.dispatchCommand(format === "bulletList"
94
+ ? list_1.INSERT_UNORDERED_LIST_COMMAND
95
+ : format === "numberList"
96
+ ? list_1.INSERT_ORDERED_LIST_COMMAND
97
+ : list_1.INSERT_CHECK_LIST_COMMAND, undefined);
98
+ return;
99
+ case "quote":
100
+ editor.update($toggleQuote);
101
+ return;
102
+ }
103
+ }
104
+ /**
105
+ * Follow the selection's formats: `listener` hears them now and after every change, until the
106
+ * returned function is called.
107
+ */
108
+ function watchFormat(editor, listener) {
109
+ listener(editor.getEditorState().read($formatState));
110
+ return editor.registerUpdateListener(({ editorState }) => {
111
+ listener(editorState.read($formatState));
112
+ });
113
+ }
114
+ // Which editor each `IEditorEffects` belongs to, so a row outside the editor (`MarkdownFormatRow`)
115
+ // can work with it once it's mounted, whichever of the two mounts first.
116
+ const editors = new WeakMap();
117
+ const waiting = new WeakMap();
118
+ /** Note that `effects` now belongs to `editor` (or to none), and tell whoever follows it. */
119
+ function attachEditor(effects, editor) {
120
+ if (editor)
121
+ editors.set(effects, editor);
122
+ else
123
+ editors.delete(effects);
124
+ for (const listener of waiting.get(effects) ?? [])
125
+ listener();
126
+ }
127
+ /** The editor `effects` belongs to, if it's mounted. */
128
+ function editorFor(effects) {
129
+ return editors.get(effects);
130
+ }
131
+ /** Hear when `effects` gets or loses its editor, until the returned function is called. */
132
+ function onEditorAttached(effects, listener) {
133
+ let listeners = waiting.get(effects);
134
+ if (!listeners) {
135
+ listeners = new Set();
136
+ waiting.set(effects, listeners);
137
+ }
138
+ listeners.add(listener);
139
+ return () => listeners.delete(listener);
140
+ }
@@ -0,0 +1,36 @@
1
+ /**
2
+ * A formatting change the editor can make to the selection: bold, italic, strikethrough, inline
3
+ * code, a link, the three list kinds, or a quote. Each toggles: applied again, it's taken off.
4
+ * Link instead opens the link field, where a link is added, edited or removed.
5
+ */
6
+ export type EditorFormat = "bold" | "italic" | "strikethrough" | "code" | "link" | "bulletList" | "numberList" | "checkList" | "quote";
7
+ /** Which formats the selection has, so their buttons show as on. */
8
+ export type IFormatState = Record<EditorFormat, boolean>;
9
+ /** No format on: the state before an editor reports one. */
10
+ export declare const NO_FORMAT: IFormatState;
11
+ /** Each format's button: a Bootstrap Icons name and its tooltip, with the shortcut if it has one. */
12
+ export declare const FORMAT_BUTTONS: Record<EditorFormat, {
13
+ icon: string;
14
+ label: string;
15
+ }>;
16
+ /** The formats for selected text: the bar over a selection shows these. */
17
+ export declare const INLINE_FORMATS: readonly EditorFormat[];
18
+ /** Every format, in the order {@link MarkdownFormatRow} shows them. */
19
+ export declare const ALL_FORMATS: readonly EditorFormat[];
20
+ /**
21
+ * A button an app adds to the bar over selected text, after the formatting ones: Notes' Make note
22
+ * and Make task. The selection stays while it's clicked, so its handler can read and replace it
23
+ * through {@link IEditorEffects}.
24
+ */
25
+ export interface ISelectionAction {
26
+ /** A Bootstrap Icons class, such as `bi-journal-plus`. */
27
+ iconClass: string;
28
+ /** The button's text. */
29
+ label: string;
30
+ /** Its tooltip. */
31
+ title?: string;
32
+ /** Greyed out, as while the action runs. */
33
+ disabled?: boolean;
34
+ /** What it does. */
35
+ onClick: () => void;
36
+ }
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ // What the editor's formatting buttons do and look like. No Lexical here: apps import these types
3
+ // with peers-ui, while the commands that apply them load with the editor (format-commands.ts).
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.ALL_FORMATS = exports.INLINE_FORMATS = exports.FORMAT_BUTTONS = exports.NO_FORMAT = void 0;
6
+ /** No format on: the state before an editor reports one. */
7
+ exports.NO_FORMAT = {
8
+ bold: false,
9
+ italic: false,
10
+ strikethrough: false,
11
+ code: false,
12
+ link: false,
13
+ bulletList: false,
14
+ numberList: false,
15
+ checkList: false,
16
+ quote: false,
17
+ };
18
+ const mac = typeof navigator !== "undefined" && /Mac|iPhone|iPad/.test(navigator.platform);
19
+ const shortcut = (key) => (mac ? `⌘${key}` : `Ctrl+${key}`);
20
+ /** Each format's button: a Bootstrap Icons name and its tooltip, with the shortcut if it has one. */
21
+ exports.FORMAT_BUTTONS = {
22
+ bold: { icon: "type-bold", label: `Bold (${shortcut("B")})` },
23
+ italic: { icon: "type-italic", label: `Italic (${shortcut("I")})` },
24
+ strikethrough: { icon: "type-strikethrough", label: "Strikethrough" },
25
+ code: { icon: "code", label: "Code" },
26
+ link: { icon: "link-45deg", label: `Link (${mac ? "⌘⇧K" : "Ctrl+Shift+K"})` },
27
+ bulletList: { icon: "list-ul", label: "Bulleted list" },
28
+ numberList: { icon: "list-ol", label: "Numbered list" },
29
+ checkList: { icon: "check2-square", label: "Checklist" },
30
+ quote: { icon: "quote", label: "Quote" },
31
+ };
32
+ /** The formats for selected text: the bar over a selection shows these. */
33
+ exports.INLINE_FORMATS = [
34
+ "bold",
35
+ "italic",
36
+ "strikethrough",
37
+ "link",
38
+ "code",
39
+ ];
40
+ /** Every format, in the order {@link MarkdownFormatRow} shows them. */
41
+ exports.ALL_FORMATS = [
42
+ ...exports.INLINE_FORMATS,
43
+ "bulletList",
44
+ "numberList",
45
+ "checkList",
46
+ "quote",
47
+ ];
@@ -1,3 +1,4 @@
1
1
  import type { IMarkdownEditorProps } from "./editor";
2
+ export { LexicalFormatRow } from "./format-bar";
2
3
  /** {@link MarkdownEditor}'s implementation. */
3
4
  export declare function LexicalMarkdownEditor(props: IMarkdownEditorProps): import("react/jsx-runtime").JSX.Element;
@@ -36,6 +36,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
36
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.LexicalFormatRow = void 0;
39
40
  exports.LexicalMarkdownEditor = LexicalMarkdownEditor;
40
41
  const jsx_runtime_1 = require("react/jsx-runtime");
41
42
  // The markdown editor itself, built on Lexical. It loads the first time an editor draws
@@ -64,6 +65,7 @@ const mention_chip_1 = require("../../mentions/mention-chip");
64
65
  const autolink_plugin_1 = require("./autolink-plugin");
65
66
  const blocks_1 = require("./blocks");
66
67
  const code_plugin_1 = require("./code-plugin");
68
+ const format_bar_1 = require("./format-bar");
67
69
  const link_plugin_1 = require("./link-plugin");
68
70
  const markdown_plugin_1 = require("./markdown-plugin");
69
71
  const mention_node_1 = require("./mention-node");
@@ -96,6 +98,8 @@ const editorConfig = {
96
98
  // The editor theme
97
99
  theme: theme_1.default,
98
100
  };
101
+ var format_bar_2 = require("./format-bar");
102
+ Object.defineProperty(exports, "LexicalFormatRow", { enumerable: true, get: function () { return format_bar_2.LexicalFormatRow; } });
99
103
  /** {@link MarkdownEditor}'s implementation. */
100
104
  function LexicalMarkdownEditor(props) {
101
105
  const { effects } = props;
@@ -124,7 +128,7 @@ function LexicalMarkdownEditor(props) {
124
128
  };
125
129
  }
126
130
  const transformers = props.headings === false ? markdown_plugin_1.inlineMarkdownTransformers : markdown_plugin_1.documentMarkdownTransformers;
127
- return ((0, jsx_runtime_1.jsx)(mention_chip_1.MentionGroupContext.Provider, { value: props.groupId, children: (0, jsx_runtime_1.jsx)(LexicalComposer_1.LexicalComposer, { initialConfig: { ...editorConfig }, children: (0, jsx_runtime_1.jsxs)("div", { className: "editor-container", children: [props.hideToolbar ? null : (0, jsx_runtime_1.jsx)(toolbar_1.ToolbarPlugin, { topRightControls: props.topRightControls }), (0, jsx_runtime_1.jsxs)("div", { className: "editor-inner", ref: editorRef, style: { maxHeight: props.maxHeight, overflowY: "auto" }, children: [(0, jsx_runtime_1.jsx)(LexicalRichTextPlugin_1.RichTextPlugin, { contentEditable: (0, jsx_runtime_1.jsx)(LexicalContentEditable_1.ContentEditable, { className: "editor-input p-2" }), placeholder: null, ErrorBoundary: LexicalErrorBoundary_1.LexicalErrorBoundary }), (0, jsx_runtime_1.jsx)(LexicalHistoryPlugin_1.HistoryPlugin, {}), props.autoFocus && (0, jsx_runtime_1.jsx)(LexicalAutoFocusPlugin_1.AutoFocusPlugin, { defaultSelection: "rootEnd" }), (0, jsx_runtime_1.jsx)(LexicalListPlugin_1.ListPlugin, {}), props.mentions !== false && ((0, jsx_runtime_1.jsx)(mentions_plugin_1.MentionsPlugin, { mentionsOpen: mentionsOpen, groupId: props.groupId })), (0, jsx_runtime_1.jsx)(autolink_plugin_1.LexicalAutoLinkPlugin, {}), (0, jsx_runtime_1.jsx)(link_plugin_1.LinksPlugin, {}), (0, jsx_runtime_1.jsx)(code_plugin_1.CodePlugin, {}), (0, jsx_runtime_1.jsx)(BlocksPlugin, {}), (0, jsx_runtime_1.jsx)(markdown_plugin_1.MarkdownPlugin, { markdownObs: props.value, transformers: transformers }), (0, jsx_runtime_1.jsx)(LexicalMarkdownShortcutPlugin_1.MarkdownShortcutPlugin, { transformers: transformers }), (0, jsx_runtime_1.jsx)(LexicalCheckListPlugin_1.CheckListPlugin, {}), (0, jsx_runtime_1.jsx)(LexicalTabIndentationPlugin_1.TabIndentationPlugin, {}), (0, jsx_runtime_1.jsx)(move_line_plugin_1.MoveLineWithAltArrowsPlugin, { mentionsOpen: mentionsOpen }), (0, jsx_runtime_1.jsx)(select_line_boundary_plugin_1.SelectToLineBoundaryPlugin, {}), (0, jsx_runtime_1.jsx)(OnKeyDownPlugin, { effects: props.effects, mentionsOpen: mentionsOpen }), effects ? (0, jsx_runtime_1.jsx)(selection_effects_plugin_1.SelectionEffectsPlugin, { effects: effects }) : null] })] }) }) }));
131
+ return ((0, jsx_runtime_1.jsx)(mention_chip_1.MentionGroupContext.Provider, { value: props.groupId, children: (0, jsx_runtime_1.jsx)(LexicalComposer_1.LexicalComposer, { initialConfig: { ...editorConfig }, children: (0, jsx_runtime_1.jsxs)("div", { className: "editor-container", children: [props.hideToolbar ? null : (0, jsx_runtime_1.jsx)(toolbar_1.ToolbarPlugin, { topRightControls: props.topRightControls }), (0, jsx_runtime_1.jsxs)("div", { className: "editor-inner", ref: editorRef, style: { maxHeight: props.maxHeight, overflowY: "auto" }, children: [(0, jsx_runtime_1.jsx)(LexicalRichTextPlugin_1.RichTextPlugin, { contentEditable: (0, jsx_runtime_1.jsx)(LexicalContentEditable_1.ContentEditable, { className: "editor-input p-2" }), placeholder: null, ErrorBoundary: LexicalErrorBoundary_1.LexicalErrorBoundary }), (0, jsx_runtime_1.jsx)(LexicalHistoryPlugin_1.HistoryPlugin, {}), props.autoFocus && (0, jsx_runtime_1.jsx)(LexicalAutoFocusPlugin_1.AutoFocusPlugin, { defaultSelection: "rootEnd" }), (0, jsx_runtime_1.jsx)(LexicalListPlugin_1.ListPlugin, {}), props.mentions !== false && ((0, jsx_runtime_1.jsx)(mentions_plugin_1.MentionsPlugin, { mentionsOpen: mentionsOpen, groupId: props.groupId })), (0, jsx_runtime_1.jsx)(autolink_plugin_1.LexicalAutoLinkPlugin, {}), (0, jsx_runtime_1.jsx)(link_plugin_1.LinksPlugin, {}), (0, jsx_runtime_1.jsx)(code_plugin_1.CodePlugin, {}), (0, jsx_runtime_1.jsx)(BlocksPlugin, {}), (0, jsx_runtime_1.jsx)(markdown_plugin_1.MarkdownPlugin, { markdownObs: props.value, transformers: transformers }), (0, jsx_runtime_1.jsx)(LexicalMarkdownShortcutPlugin_1.MarkdownShortcutPlugin, { transformers: transformers }), (0, jsx_runtime_1.jsx)(LexicalCheckListPlugin_1.CheckListPlugin, {}), (0, jsx_runtime_1.jsx)(LexicalTabIndentationPlugin_1.TabIndentationPlugin, {}), (0, jsx_runtime_1.jsx)(move_line_plugin_1.MoveLineWithAltArrowsPlugin, { mentionsOpen: mentionsOpen }), (0, jsx_runtime_1.jsx)(select_line_boundary_plugin_1.SelectToLineBoundaryPlugin, {}), (0, jsx_runtime_1.jsx)(OnKeyDownPlugin, { effects: props.effects, mentionsOpen: mentionsOpen }), effects ? (0, jsx_runtime_1.jsx)(selection_effects_plugin_1.SelectionEffectsPlugin, { effects: effects }) : null] }), props.selectionToolbar ? ((0, jsx_runtime_1.jsx)(format_bar_1.SelectionToolbarPlugin, { actions: props.selectionActions })) : null] }) }) }));
128
132
  }
129
133
  const OnKeyDownPlugin = (props) => {
130
134
  const [editor] = (0, LexicalComposerContext_1.useLexicalComposerContext)();
@@ -1,15 +1,18 @@
1
1
  import { type LinkNode } from "@lexical/link";
2
2
  import { type LexicalCommand, type RangeSelection } from "lexical";
3
3
  /**
4
- * Whether `url` is a link the editor keeps: an `http:`, `https:` or `mailto:` URL.
4
+ * Whether `url` is a link the editor keeps and opens: a web or mail link, another app's link
5
+ * (`obsidian://…`), or a `peers://` link. Script, data and file links (`javascript:`, `data:`,
6
+ * `file:`, and the others the host refuses) aren't.
5
7
  *
6
8
  * @param url - The text to check.
7
9
  */
8
10
  export declare function isLinkUrl(url: string): boolean;
9
11
  /**
10
12
  * What a typed link becomes: the URL as given when it's a web or mail link, `https://` before a
11
- * bare domain (`example.com/page`), `mailto:` before an email address, or undefined for anything
12
- * else (another scheme, or text with spaces).
13
+ * bare domain (`example.com/page`), `mailto:` before an email address, another app's or a
14
+ * `peers://` link as given, or undefined for anything else (a refused scheme, a host and port
15
+ * with no scheme, or text with spaces).
13
16
  *
14
17
  * @param text - What the user typed or pasted as the link.
15
18
  */
@@ -30,8 +33,9 @@ export declare const OPEN_LINK_EDITOR_COMMAND: LexicalCommand<void>;
30
33
  export declare function $selectedLink(selection: RangeSelection): LinkNode | null;
31
34
  /**
32
35
  * Links in the editor:
33
- * - Clicking a web or mail link opens it in the browser (through the host's open). A click that
34
- * selects text in a link doesn't.
36
+ * - Clicking a link opens it through `openLink`: a web or mail link in the browser, another
37
+ * app's link in that app after asking, a `peers://` link inside Peers. A click that selects
38
+ * text in a link doesn't.
35
39
  * - ⌘⇧K (Ctrl+Shift+K) or the toolbar's link button links the selected text, or edits the link
36
40
  * the caret is in.
37
41
  * - Pasting a URL over selected text links it.