@peers-app/peers-ui 0.33.21 → 0.33.22

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.
@@ -0,0 +1,41 @@
1
+ import { type LinkNode } from "@lexical/link";
2
+ import { type LexicalCommand, type RangeSelection } from "lexical";
3
+ /**
4
+ * Whether `url` is a link the editor keeps: an `http:`, `https:` or `mailto:` URL.
5
+ *
6
+ * @param url - The text to check.
7
+ */
8
+ export declare function isLinkUrl(url: string): boolean;
9
+ /**
10
+ * 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
+ *
14
+ * @param text - What the user typed or pasted as the link.
15
+ */
16
+ export declare function normalizeLinkUrl(text: string): string | undefined;
17
+ /**
18
+ * Whether a key press is the link shortcut: ⌘⇧K, or Ctrl+Shift+K off the Mac. ⌘K stays Peers'
19
+ * command palette.
20
+ *
21
+ * @param event - The key press.
22
+ */
23
+ export declare function isLinkShortcut(event: KeyboardEvent): boolean;
24
+ /**
25
+ * Opens the link popup for editing: the link the caret is in, or a new link for the selected
26
+ * text (at the caret when nothing is selected). The toolbar's link button sends it.
27
+ */
28
+ export declare const OPEN_LINK_EDITOR_COMMAND: LexicalCommand<void>;
29
+ /** The link a selection is in: the same link at both ends, or none. */
30
+ export declare function $selectedLink(selection: RangeSelection): LinkNode | null;
31
+ /**
32
+ * 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.
35
+ * - ⌘⇧K (Ctrl+Shift+K) or the toolbar's link button links the selected text, or edits the link
36
+ * the caret is in.
37
+ * - Pasting a URL over selected text links it.
38
+ * - With the caret in a link, or its text selected, a popup shows the URL, Edit and Remove.
39
+ * Links found in the text (typed URLs) have no Remove, since the text makes them again.
40
+ */
41
+ export declare function LinksPlugin(): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,334 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OPEN_LINK_EDITOR_COMMAND = void 0;
4
+ exports.isLinkUrl = isLinkUrl;
5
+ exports.normalizeLinkUrl = normalizeLinkUrl;
6
+ exports.isLinkShortcut = isLinkShortcut;
7
+ exports.$selectedLink = $selectedLink;
8
+ exports.LinksPlugin = LinksPlugin;
9
+ const jsx_runtime_1 = require("react/jsx-runtime");
10
+ const link_1 = require("@lexical/link");
11
+ const LexicalComposerContext_1 = require("@lexical/react/LexicalComposerContext");
12
+ const LexicalLinkPlugin_1 = require("@lexical/react/LexicalLinkPlugin");
13
+ const utils_1 = require("@lexical/utils");
14
+ const lexical_1 = require("lexical");
15
+ const react_1 = require("react");
16
+ const react_dom_1 = require("react-dom");
17
+ const host_shell_consumer_1 = require("../../host-shell/host-shell-consumer");
18
+ /** The link schemes the editor makes and opens: web links and email. */
19
+ const LINK_SCHEMES = new Set(["http:", "https:", "mailto:"]);
20
+ /**
21
+ * Whether `url` is a link the editor keeps: an `http:`, `https:` or `mailto:` URL.
22
+ *
23
+ * @param url - The text to check.
24
+ */
25
+ function isLinkUrl(url) {
26
+ try {
27
+ return LINK_SCHEMES.has(new URL(url).protocol);
28
+ }
29
+ catch {
30
+ return false;
31
+ }
32
+ }
33
+ const EMAIL = /^[^\s@<>()[\]\\,;:"]+@[^\s@<>()[\]\\,;:"]+\.[a-z]{2,}$/i;
34
+ const BARE_DOMAIN = /^[\w-]+(\.[\w-]+)+(:\d+)?([/?#]\S*)?$/i;
35
+ /**
36
+ * What a typed link becomes: the URL as given when it's a web or mail link, `https://` before a
37
+ * bare domain (`example.com/page`), `mailto:` before an email address, or undefined for anything
38
+ * else (another scheme, or text with spaces).
39
+ *
40
+ * @param text - What the user typed or pasted as the link.
41
+ */
42
+ function normalizeLinkUrl(text) {
43
+ const value = text.trim();
44
+ if (!value || /\s/.test(value))
45
+ return undefined;
46
+ if (isLinkUrl(value))
47
+ return value;
48
+ if (/^[a-z][a-z\d+.-]*:/i.test(value) && !BARE_DOMAIN.test(value))
49
+ return undefined;
50
+ if (EMAIL.test(value))
51
+ return `mailto:${value}`;
52
+ if (BARE_DOMAIN.test(value))
53
+ return `https://${value}`;
54
+ return undefined;
55
+ }
56
+ /**
57
+ * Whether a key press is the link shortcut: ⌘⇧K, or Ctrl+Shift+K off the Mac. ⌘K stays Peers'
58
+ * command palette.
59
+ *
60
+ * @param event - The key press.
61
+ */
62
+ function isLinkShortcut(event) {
63
+ return ((event.metaKey || event.ctrlKey) &&
64
+ event.shiftKey &&
65
+ !event.altKey &&
66
+ event.key.toLowerCase() === "k");
67
+ }
68
+ /**
69
+ * Opens the link popup for editing: the link the caret is in, or a new link for the selected
70
+ * text (at the caret when nothing is selected). The toolbar's link button sends it.
71
+ */
72
+ exports.OPEN_LINK_EDITOR_COMMAND = (0, lexical_1.createCommand)("OPEN_LINK_EDITOR_COMMAND");
73
+ /** The link a selection is in: the same link at both ends, or none. */
74
+ function $selectedLink(selection) {
75
+ const anchor = (0, utils_1.$findMatchingParent)(selection.anchor.getNode(), link_1.$isLinkNode);
76
+ const focus = (0, utils_1.$findMatchingParent)(selection.focus.getNode(), link_1.$isLinkNode);
77
+ return anchor && focus && anchor.is(focus) ? anchor : null;
78
+ }
79
+ /** The selection's rectangle on screen, or its anchor's element when the DOM has no range. */
80
+ function selectionRect(editor, selection) {
81
+ const root = editor.getRootElement();
82
+ const domSelection = window.getSelection();
83
+ if (root && domSelection && domSelection.rangeCount > 0) {
84
+ const range = domSelection.getRangeAt(0);
85
+ if (root.contains(range.startContainer)) {
86
+ const rect = range.getBoundingClientRect();
87
+ if (rect.width || rect.height)
88
+ return rect;
89
+ }
90
+ }
91
+ const node = selection.anchor.getNode();
92
+ const element = editor.getElementByKey(node.getKey()) ??
93
+ editor.getElementByKey(node.getTopLevelElementOrThrow().getKey());
94
+ return element?.getBoundingClientRect();
95
+ }
96
+ /** The popup for the link at `node`, positioned under its element. */
97
+ function popupFor(editor, link) {
98
+ const rect = editor.getElementByKey(link.getKey())?.getBoundingClientRect();
99
+ if (!rect)
100
+ return undefined;
101
+ return {
102
+ linkKey: link.getKey(),
103
+ url: link.getURL(),
104
+ auto: (0, link_1.$isAutoLinkNode)(link),
105
+ editing: false,
106
+ rect,
107
+ };
108
+ }
109
+ /**
110
+ * Links in the editor:
111
+ * - Clicking a web or mail link opens it in the browser (through the host's open). A click that
112
+ * selects text in a link doesn't.
113
+ * - ⌘⇧K (Ctrl+Shift+K) or the toolbar's link button links the selected text, or edits the link
114
+ * the caret is in.
115
+ * - Pasting a URL over selected text links it.
116
+ * - With the caret in a link, or its text selected, a popup shows the URL, Edit and Remove.
117
+ * Links found in the text (typed URLs) have no Remove, since the text makes them again.
118
+ */
119
+ function LinksPlugin() {
120
+ const [editor] = (0, LexicalComposerContext_1.useLexicalComposerContext)();
121
+ const [popup, setPopup] = (0, react_1.useState)();
122
+ const popupRef = (0, react_1.useRef)(null);
123
+ // The selection when the popup opened for editing, put back before the link is written.
124
+ const savedSelection = (0, react_1.useRef)(null);
125
+ // Show the popup for the link the selection is in, unless its URL is being edited.
126
+ const refresh = (0, react_1.useCallback)(() => {
127
+ setPopup((current) => {
128
+ if (current?.editing)
129
+ return current;
130
+ const root = editor.getRootElement();
131
+ const active = document.activeElement;
132
+ const focused = !!root && !!active && (root === active || root.contains(active));
133
+ const inPopup = !!active && !!popupRef.current?.contains(active);
134
+ if (!focused && !inPopup)
135
+ return undefined;
136
+ return editor.read(() => {
137
+ const selection = (0, lexical_1.$getSelection)();
138
+ if (!(0, lexical_1.$isRangeSelection)(selection))
139
+ return undefined;
140
+ const link = $selectedLink(selection);
141
+ return link ? popupFor(editor, link) : undefined;
142
+ });
143
+ });
144
+ }, [editor]);
145
+ const openEditor = (0, react_1.useCallback)(() => {
146
+ editor.read(() => {
147
+ const selection = (0, lexical_1.$getSelection)();
148
+ if (!(0, lexical_1.$isRangeSelection)(selection))
149
+ return;
150
+ savedSelection.current = selection.clone();
151
+ const link = $selectedLink(selection);
152
+ const rect = link
153
+ ? editor.getElementByKey(link.getKey())?.getBoundingClientRect()
154
+ : selectionRect(editor, selection);
155
+ if (!rect)
156
+ return;
157
+ setPopup({
158
+ linkKey: link?.getKey(),
159
+ url: link?.getURL() ?? "",
160
+ auto: link ? (0, link_1.$isAutoLinkNode)(link) : false,
161
+ editing: true,
162
+ rect,
163
+ });
164
+ });
165
+ }, [editor]);
166
+ (0, react_1.useEffect)(() => {
167
+ const onClick = (event) => {
168
+ const target = event.target;
169
+ if (!(target instanceof Node) || event.button !== 0)
170
+ return;
171
+ // A click that ends a drag selecting text in the link doesn't open it.
172
+ if (window.getSelection()?.isCollapsed === false)
173
+ return;
174
+ let url;
175
+ editor.read(() => {
176
+ const node = (0, lexical_1.$getNearestNodeFromDOMNode)(target);
177
+ const link = node && (0, utils_1.$findMatchingParent)(node, link_1.$isLinkNode);
178
+ if (link)
179
+ url = link.getURL();
180
+ });
181
+ if (!url)
182
+ return;
183
+ event.preventDefault();
184
+ if (isLinkUrl(url))
185
+ void (0, host_shell_consumer_1.openLink)(url);
186
+ };
187
+ return (0, utils_1.mergeRegister)(editor.registerRootListener((root, previous) => {
188
+ previous?.removeEventListener("click", onClick);
189
+ root?.addEventListener("click", onClick);
190
+ }), editor.registerUpdateListener(() => refresh()), editor.registerCommand(lexical_1.BLUR_COMMAND, () => {
191
+ // Focus may be moving into the popup: look once it has landed.
192
+ setTimeout(refresh, 0);
193
+ return false;
194
+ }, lexical_1.COMMAND_PRIORITY_LOW), editor.registerCommand(lexical_1.KEY_DOWN_COMMAND, (event) => {
195
+ if (!isLinkShortcut(event))
196
+ return false;
197
+ event.preventDefault();
198
+ event.stopPropagation();
199
+ openEditor();
200
+ return true;
201
+ }, lexical_1.COMMAND_PRIORITY_NORMAL), editor.registerCommand(exports.OPEN_LINK_EDITOR_COMMAND, () => {
202
+ openEditor();
203
+ return true;
204
+ }, lexical_1.COMMAND_PRIORITY_LOW));
205
+ }, [editor, refresh, openEditor]);
206
+ // Keep the popup under its link while the page or the editor scrolls.
207
+ const showing = !!popup;
208
+ (0, react_1.useEffect)(() => {
209
+ if (!showing)
210
+ return;
211
+ const follow = () => setPopup((current) => {
212
+ const element = current?.linkKey ? editor.getElementByKey(current.linkKey) : null;
213
+ return current && element ? { ...current, rect: element.getBoundingClientRect() } : current;
214
+ });
215
+ window.addEventListener("scroll", follow, true);
216
+ window.addEventListener("resize", follow);
217
+ return () => {
218
+ window.removeEventListener("scroll", follow, true);
219
+ window.removeEventListener("resize", follow);
220
+ };
221
+ }, [editor, showing]);
222
+ const close = (0, react_1.useCallback)((refocus) => {
223
+ setPopup(undefined);
224
+ savedSelection.current = null;
225
+ if (refocus)
226
+ editor.focus();
227
+ }, [editor]);
228
+ const save = (0, react_1.useCallback)((url) => {
229
+ const linkKey = popup?.linkKey;
230
+ editor.update(() => {
231
+ const existing = linkKey ? (0, lexical_1.$getNodeByKey)(linkKey) : null;
232
+ if ((0, link_1.$isLinkNode)(existing)) {
233
+ // A new node either way: an edited link found in the text is the user's link now.
234
+ const link = (0, link_1.$createLinkNode)(url);
235
+ link.append(...existing.getChildren());
236
+ existing.replace(link);
237
+ link.selectEnd();
238
+ return;
239
+ }
240
+ const saved = savedSelection.current;
241
+ if (saved)
242
+ (0, lexical_1.$setSelection)(saved.clone());
243
+ const selection = (0, lexical_1.$getSelection)();
244
+ if (!(0, lexical_1.$isRangeSelection)(selection))
245
+ return;
246
+ if (selection.isCollapsed()) {
247
+ const link = (0, link_1.$createLinkNode)(url);
248
+ link.append((0, lexical_1.$createTextNode)(url));
249
+ selection.insertNodes([link]);
250
+ link.selectEnd();
251
+ }
252
+ else {
253
+ (0, link_1.$toggleLink)(url);
254
+ }
255
+ }, { discrete: true });
256
+ close(true);
257
+ }, [editor, popup?.linkKey, close]);
258
+ const remove = (0, react_1.useCallback)(() => {
259
+ const linkKey = popup?.linkKey;
260
+ editor.update(() => {
261
+ const link = linkKey ? (0, lexical_1.$getNodeByKey)(linkKey) : null;
262
+ if (!(0, link_1.$isLinkNode)(link))
263
+ return;
264
+ const children = link.getChildren();
265
+ for (const child of children)
266
+ link.insertBefore(child);
267
+ link.remove();
268
+ children[children.length - 1]?.selectEnd();
269
+ }, { discrete: true });
270
+ close(true);
271
+ }, [editor, popup?.linkKey, close]);
272
+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(LexicalLinkPlugin_1.LinkPlugin, { validateUrl: isLinkUrl }), popup ? ((0, jsx_runtime_1.jsx)(LinkPopup, { popup: popup, popupRef: popupRef, onEdit: () => {
273
+ editor.read(() => {
274
+ const selection = (0, lexical_1.$getSelection)();
275
+ savedSelection.current = (0, lexical_1.$isRangeSelection)(selection) ? selection.clone() : null;
276
+ });
277
+ setPopup({ ...popup, editing: true });
278
+ }, onSave: save, onRemove: remove, onCancel: () => close(true), onDismiss: () => close(false) })) : null] }));
279
+ }
280
+ /** The popup's width, so it can be kept inside the window. */
281
+ const POPUP_WIDTH = 320;
282
+ /** The link popup: the URL with Edit and Remove, or an input for the URL. */
283
+ function LinkPopup(props) {
284
+ const { popup, popupRef, onDismiss } = props;
285
+ const [text, setText] = (0, react_1.useState)(popup.url);
286
+ const [invalid, setInvalid] = (0, react_1.useState)(false);
287
+ const inputRef = (0, react_1.useRef)(null);
288
+ (0, react_1.useEffect)(() => {
289
+ setText(popup.url);
290
+ setInvalid(false);
291
+ }, [popup.url, popup.editing]);
292
+ (0, react_1.useLayoutEffect)(() => {
293
+ if (popup.editing)
294
+ inputRef.current?.focus();
295
+ }, [popup.editing]);
296
+ // Editing stays open while focus is in the input; a press anywhere else closes it.
297
+ (0, react_1.useEffect)(() => {
298
+ if (!popup.editing)
299
+ return;
300
+ const onPointerDown = (event) => {
301
+ if (!popupRef.current?.contains(event.target))
302
+ onDismiss();
303
+ };
304
+ document.addEventListener("pointerdown", onPointerDown, true);
305
+ return () => document.removeEventListener("pointerdown", onPointerDown, true);
306
+ }, [popup.editing, popupRef, onDismiss]);
307
+ const submit = () => {
308
+ const url = normalizeLinkUrl(text);
309
+ if (url)
310
+ props.onSave(url);
311
+ else
312
+ setInvalid(true);
313
+ };
314
+ const left = Math.max(8, Math.min(popup.rect.left, window.innerWidth - POPUP_WIDTH - 8));
315
+ const style = { top: popup.rect.bottom + 4, left, maxWidth: POPUP_WIDTH };
316
+ // Buttons keep the editor's focus and selection.
317
+ const keepFocus = (event) => event.preventDefault();
318
+ return (0, react_dom_1.createPortal)((0, jsx_runtime_1.jsx)("div", { ref: popupRef, className: "peers-link-popup", style: style, "data-testid": "link-popup", children: popup.editing ? ((0, jsx_runtime_1.jsxs)("form", { className: "d-flex gap-1 align-items-center", onSubmit: (event) => {
319
+ event.preventDefault();
320
+ submit();
321
+ }, children: [(0, jsx_runtime_1.jsx)("input", { ref: inputRef, className: `form-control form-control-sm ${invalid ? "is-invalid" : ""}`, value: text, placeholder: "https://\u2026", "aria-label": "Link URL", onChange: (event) => {
322
+ setText(event.target.value);
323
+ setInvalid(false);
324
+ }, onKeyDown: (event) => {
325
+ if (event.key === "Escape") {
326
+ event.preventDefault();
327
+ props.onCancel();
328
+ }
329
+ } }), (0, jsx_runtime_1.jsx)("button", { type: "submit", className: "btn btn-sm btn-primary", title: "Save link", children: (0, jsx_runtime_1.jsx)("i", { className: "bi bi-check-lg" }) })] })) : ((0, jsx_runtime_1.jsxs)("div", { className: "d-flex gap-1 align-items-center", children: [(0, jsx_runtime_1.jsx)("a", { href: popup.url, className: "peers-link-popup-url text-truncate", title: popup.url, onMouseDown: keepFocus, onClick: (event) => {
330
+ event.preventDefault();
331
+ if (isLinkUrl(popup.url))
332
+ void (0, host_shell_consumer_1.openLink)(popup.url);
333
+ }, children: popup.url.replace(/^mailto:/, "") }), (0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn btn-sm btn-link p-1", title: "Edit link", "aria-label": "Edit link", onMouseDown: keepFocus, onClick: props.onEdit, children: (0, jsx_runtime_1.jsx)("i", { className: "bi bi-pencil" }) }), popup.auto ? null : ((0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn btn-sm btn-link p-1", title: "Remove link", "aria-label": "Remove link", onMouseDown: keepFocus, onClick: props.onRemove, children: (0, jsx_runtime_1.jsx)("i", { className: "bi bi-x-lg" }) }))] })) }), document.body);
334
+ }
@@ -1,9 +1,12 @@
1
1
  import { type Transformer } from "@lexical/markdown";
2
2
  import { type Observable } from "@peers-app/peers-sdk";
3
3
  /**
4
- * Markdown for documents (task bodies, notes): mentions (ahead of Lexical's link transformer,
5
- * which would otherwise take `peers://` links) and checklists (ahead of Lexical's lists, or
6
- * `- [ ]` would read as a plain list item), then Lexical's own, headings included.
4
+ * Markdown for documents (task bodies, notes), in this order:
5
+ * - mentions, ahead of Lexical's link transformer, which would otherwise take `peers://` links;
6
+ * - checklists, ahead of Lexical's lists, or `- [ ]` would read as a plain list item;
7
+ * - dividers (`***`) and callouts (`> [!NOTE]`), the callouts ahead of Lexical's quotes;
8
+ * - then Lexical's own, headings and `==highlight==` included, with code fences written by
9
+ * {@link CODE_BLOCK_TRANSFORMER}.
7
10
  */
8
11
  export declare const documentMarkdownTransformers: Transformer[];
9
12
  /**
@@ -15,8 +18,8 @@ export declare const documentMarkdownTransformers: Transformer[];
15
18
  */
16
19
  export declare function withoutHeadings(transformers: readonly Transformer[]): Transformer[];
17
20
  /**
18
- * Markdown for short inline text such as messages, where a line starting with `#` stays text: the
19
- * document transformers without headings.
21
+ * Markdown for short inline text such as messages: the document transformers without headings,
22
+ * dividers and callouts, so a line starting with `#`, a `---` line and `[!NOTE]` stay text.
20
23
  */
21
24
  export declare const inlineMarkdownTransformers: Transformer[];
22
25
  /** {@link MarkdownPlugin}'s props. */
@@ -8,6 +8,8 @@ const markdown_1 = require("@lexical/markdown");
8
8
  const LexicalComposerContext_1 = require("@lexical/react/LexicalComposerContext");
9
9
  const peers_sdk_1 = require("@peers-app/peers-sdk");
10
10
  const react_1 = require("react");
11
+ const blocks_1 = require("./blocks");
12
+ const code_plugin_1 = require("./code-plugin");
11
13
  const mention_node_1 = require("./mention-node");
12
14
  // Amount of spaces that define indentation level
13
15
  const LIST_INDENT_SIZE = 4;
@@ -135,15 +137,20 @@ const OLD_MENTION_TRANSFORMER = {
135
137
  },
136
138
  };
137
139
  /**
138
- * Markdown for documents (task bodies, notes): mentions (ahead of Lexical's link transformer,
139
- * which would otherwise take `peers://` links) and checklists (ahead of Lexical's lists, or
140
- * `- [ ]` would read as a plain list item), then Lexical's own, headings included.
140
+ * Markdown for documents (task bodies, notes), in this order:
141
+ * - mentions, ahead of Lexical's link transformer, which would otherwise take `peers://` links;
142
+ * - checklists, ahead of Lexical's lists, or `- [ ]` would read as a plain list item;
143
+ * - dividers (`***`) and callouts (`> [!NOTE]`), the callouts ahead of Lexical's quotes;
144
+ * - then Lexical's own, headings and `==highlight==` included, with code fences written by
145
+ * {@link CODE_BLOCK_TRANSFORMER}.
141
146
  */
142
147
  exports.documentMarkdownTransformers = [
143
148
  MENTION_TRANSFORMER,
144
149
  OLD_MENTION_TRANSFORMER,
145
150
  CHECK_LIST_TRANSFORMER,
146
- ...markdown_1.TRANSFORMERS,
151
+ blocks_1.HORIZONTAL_RULE_TRANSFORMER,
152
+ blocks_1.CALLOUT_TRANSFORMER,
153
+ ...markdown_1.TRANSFORMERS.map((transformer) => transformer === markdown_1.CODE ? code_plugin_1.CODE_BLOCK_TRANSFORMER : transformer),
147
154
  ];
148
155
  /**
149
156
  * The transformers without the heading one. It's recognized by its node's type, `"heading"`, not
@@ -159,10 +166,10 @@ function withoutHeadings(transformers) {
159
166
  });
160
167
  }
161
168
  /**
162
- * Markdown for short inline text such as messages, where a line starting with `#` stays text: the
163
- * document transformers without headings.
169
+ * Markdown for short inline text such as messages: the document transformers without headings,
170
+ * dividers and callouts, so a line starting with `#`, a `---` line and `[!NOTE]` stay text.
164
171
  */
165
- exports.inlineMarkdownTransformers = withoutHeadings(exports.documentMarkdownTransformers);
172
+ exports.inlineMarkdownTransformers = withoutHeadings(exports.documentMarkdownTransformers).filter((transformer) => transformer !== blocks_1.HORIZONTAL_RULE_TRANSFORMER && transformer !== blocks_1.CALLOUT_TRANSFORMER);
166
173
  /**
167
174
  * Keeps the editor and a markdown observable in step: the observable's value is loaded into the
168
175
  * editor (without moving the caret or taking focus), and edits are written back as markdown.
@@ -354,7 +354,11 @@ function MentionsPlugin(props) {
354
354
  if (query !== null && query !== autoPicked.current)
355
355
  autoPicked.current = null;
356
356
  setQueryString(query);
357
- }, onSelectOption: onSelectOption, triggerFn: checkForMentionMatch, options: options, onOpen: () => _mentionsOpen(true), onClose: () => _mentionsOpen(false), menuRenderFn: (anchorElementRef, { selectedIndex, selectOptionAndCleanUp, setHighlightedIndex }) => {
357
+ }, onSelectOption: onSelectOption, triggerFn: checkForMentionMatch, options: options, onOpen: () => {
358
+ _mentionsOpen(true);
359
+ }, onClose: () => {
360
+ _mentionsOpen(false);
361
+ }, menuRenderFn: (anchorElementRef, { selectedIndex, selectOptionAndCleanUp, setHighlightedIndex }) => {
358
362
  const anchor = anchorElementRef.current;
359
363
  if (!(anchor && options.length)) {
360
364
  return null;
@@ -5,8 +5,41 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
7
  */
8
+ /** Class names for the editor's nodes and text formats (Lexical's theme). */
8
9
  declare const _default: {
9
10
  code: string;
11
+ codeHighlight: {
12
+ atrule: string;
13
+ attr: string;
14
+ boolean: string;
15
+ builtin: string;
16
+ cdata: string;
17
+ char: string;
18
+ class: string;
19
+ "class-name": string;
20
+ comment: string;
21
+ constant: string;
22
+ deleted: string;
23
+ doctype: string;
24
+ entity: string;
25
+ function: string;
26
+ important: string;
27
+ inserted: string;
28
+ keyword: string;
29
+ namespace: string;
30
+ number: string;
31
+ operator: string;
32
+ prolog: string;
33
+ property: string;
34
+ punctuation: string;
35
+ regex: string;
36
+ selector: string;
37
+ string: string;
38
+ symbol: string;
39
+ tag: string;
40
+ url: string;
41
+ variable: string;
42
+ };
10
43
  heading: {
11
44
  h1: string;
12
45
  h2: string;
@@ -14,6 +47,7 @@ declare const _default: {
14
47
  h4: string;
15
48
  h5: string;
16
49
  };
50
+ hr: string;
17
51
  image: string;
18
52
  link: string;
19
53
  list: {
@@ -36,6 +70,7 @@ declare const _default: {
36
70
  bold: string;
37
71
  code: string;
38
72
  hashtag: string;
73
+ highlight: string;
39
74
  italic: string;
40
75
  overflowed: string;
41
76
  strikethrough: string;
@@ -7,8 +7,42 @@ Object.defineProperty(exports, "__esModule", { value: true });
7
7
  * LICENSE file in the root directory of this source tree.
8
8
  *
9
9
  */
10
+ /** Class names for the editor's nodes and text formats (Lexical's theme). */
10
11
  exports.default = {
11
12
  code: "editor-code",
13
+ // Prism's token types, for highlighted code.
14
+ codeHighlight: {
15
+ atrule: "editor-token-keyword",
16
+ attr: "editor-token-attr",
17
+ boolean: "editor-token-constant",
18
+ builtin: "editor-token-function",
19
+ cdata: "editor-token-comment",
20
+ char: "editor-token-string",
21
+ class: "editor-token-function",
22
+ "class-name": "editor-token-function",
23
+ comment: "editor-token-comment",
24
+ constant: "editor-token-constant",
25
+ deleted: "editor-token-deleted",
26
+ doctype: "editor-token-comment",
27
+ entity: "editor-token-operator",
28
+ function: "editor-token-function",
29
+ important: "editor-token-keyword",
30
+ inserted: "editor-token-inserted",
31
+ keyword: "editor-token-keyword",
32
+ namespace: "editor-token-variable",
33
+ number: "editor-token-constant",
34
+ operator: "editor-token-operator",
35
+ prolog: "editor-token-comment",
36
+ property: "editor-token-attr",
37
+ punctuation: "editor-token-punctuation",
38
+ regex: "editor-token-string",
39
+ selector: "editor-token-function",
40
+ string: "editor-token-string",
41
+ symbol: "editor-token-constant",
42
+ tag: "editor-token-keyword",
43
+ url: "editor-token-string",
44
+ variable: "editor-token-variable",
45
+ },
12
46
  heading: {
13
47
  h1: "editor-heading-h1",
14
48
  h2: "editor-heading-h2",
@@ -16,6 +50,7 @@ exports.default = {
16
50
  h4: "editor-heading-h4",
17
51
  h5: "editor-heading-h5",
18
52
  },
53
+ hr: "editor-hr",
19
54
  image: "editor-image",
20
55
  link: "editor-link",
21
56
  list: {
@@ -39,6 +74,7 @@ exports.default = {
39
74
  bold: "editor-text-bold",
40
75
  code: "editor-text-code",
41
76
  hashtag: "editor-text-hashtag",
77
+ highlight: "editor-text-highlight",
42
78
  italic: "editor-text-italic",
43
79
  overflowed: "editor-text-overflowed",
44
80
  strikethrough: "editor-text-strikethrough",
@@ -1,9 +1,20 @@
1
+ /** A button an app adds to the editor's toolbar, at its top right. */
1
2
  export interface IToolbarControl {
3
+ /** The button's icon: a Bootstrap Icons class, such as `bi-trash`. */
2
4
  iconClass: string;
5
+ /** What the button does. */
3
6
  onClick: () => void;
7
+ /** The button's tooltip. */
4
8
  title?: string;
5
9
  }
10
+ /** The toolbar's options. */
6
11
  export interface IToolbarProps {
12
+ /** The app's own buttons, after the formatting ones. */
7
13
  topRightControls?: IToolbarControl[];
8
14
  }
15
+ /**
16
+ * The editor's formatting toolbar: bold, italic, strikethrough, link and the three list kinds,
17
+ * each lit while the selection has it, plus the app's own buttons. Every app hides it for now
18
+ * (`hideToolbar`).
19
+ */
9
20
  export declare function ToolbarPlugin(props: IToolbarProps): import("react/jsx-runtime").JSX.Element;
@@ -7,10 +7,20 @@ const LexicalComposerContext_1 = require("@lexical/react/LexicalComposerContext"
7
7
  const utils_1 = require("@lexical/utils");
8
8
  const lexical_1 = require("lexical");
9
9
  const react_1 = require("react");
10
+ const link_plugin_1 = require("./link-plugin");
10
11
  const LowPriority = 1;
12
+ /** The link shortcut, as the toolbar's tooltip shows it. */
13
+ const linkShortcutLabel = typeof navigator !== "undefined" && /Mac|iPhone|iPad/.test(navigator.platform)
14
+ ? "⌘⇧K"
15
+ : "Ctrl+Shift+K";
11
16
  function Divider() {
12
17
  return (0, jsx_runtime_1.jsx)("span", { className: "tool-bar-divider" });
13
18
  }
19
+ /**
20
+ * The editor's formatting toolbar: bold, italic, strikethrough, link and the three list kinds,
21
+ * each lit while the selection has it, plus the app's own buttons. Every app hides it for now
22
+ * (`hideToolbar`).
23
+ */
14
24
  function ToolbarPlugin(props) {
15
25
  const [editor] = (0, LexicalComposerContext_1.useLexicalComposerContext)();
16
26
  const toolbarRef = (0, react_1.useRef)(null);
@@ -20,6 +30,7 @@ function ToolbarPlugin(props) {
20
30
  const [isItalic, setIsItalic] = (0, react_1.useState)(false);
21
31
  const [_isUnderline, setIsUnderline] = (0, react_1.useState)(false);
22
32
  const [isStrikethrough, setIsStrikethrough] = (0, react_1.useState)(false);
33
+ const [isLink, setIsLink] = (0, react_1.useState)(false);
23
34
  // New state for list types
24
35
  const [isUnorderedList, setIsUnorderedList] = (0, react_1.useState)(false);
25
36
  const [isOrderedList, setIsOrderedList] = (0, react_1.useState)(false);
@@ -32,6 +43,7 @@ function ToolbarPlugin(props) {
32
43
  setIsItalic(selection.hasFormat("italic"));
33
44
  setIsUnderline(selection.hasFormat("underline"));
34
45
  setIsStrikethrough(selection.hasFormat("strikethrough"));
46
+ setIsLink((0, link_plugin_1.$selectedLink)(selection) !== null);
35
47
  // Update list format
36
48
  const anchorNode = selection.anchor.getNode();
37
49
  const element = anchorNode.getKey() === "root" ? anchorNode : anchorNode.getTopLevelElementOrThrow();
@@ -50,10 +62,7 @@ function ToolbarPlugin(props) {
50
62
  editorState.read(() => {
51
63
  $updateToolbar();
52
64
  });
53
- }), editor.registerCommand(lexical_1.SELECTION_CHANGE_COMMAND, (_payload, _newEditor) => {
54
- $updateToolbar();
55
- return false;
56
- }, LowPriority), editor.registerCommand(lexical_1.CAN_UNDO_COMMAND, (payload) => {
65
+ }), editor.registerCommand(lexical_1.CAN_UNDO_COMMAND, (payload) => {
57
66
  setCanUndo(payload);
58
67
  return false;
59
68
  }, LowPriority), editor.registerCommand(lexical_1.CAN_REDO_COMMAND, (payload) => {
@@ -91,5 +100,7 @@ function ToolbarPlugin(props) {
91
100
  editor.dispatchCommand(lexical_1.FORMAT_TEXT_COMMAND, "italic");
92
101
  }, className: `toolbar-item spaced ${isItalic ? "active" : ""}`, "aria-label": "Format Italics", children: (0, jsx_runtime_1.jsx)("i", { className: "bi bi-type-italic" }) }), (0, jsx_runtime_1.jsx)("button", { tabIndex: -1, onClick: () => {
93
102
  editor.dispatchCommand(lexical_1.FORMAT_TEXT_COMMAND, "strikethrough");
94
- }, className: `toolbar-item spaced ${isStrikethrough ? "active" : ""}`, "aria-label": "Format Strikethrough", children: (0, jsx_runtime_1.jsx)("i", { className: "bi bi-type-strikethrough" }) }), (0, jsx_runtime_1.jsx)(Divider, {}), (0, jsx_runtime_1.jsx)("button", { tabIndex: -1, onClick: insertUnorderedList, className: `toolbar-item spaced ${isUnorderedList ? "active" : ""}`, "aria-label": "Insert Unordered List", children: (0, jsx_runtime_1.jsx)("i", { className: "bi bi-list-ul" }) }), (0, jsx_runtime_1.jsx)("button", { tabIndex: -1, onClick: insertOrderedList, className: `toolbar-item spaced ${isOrderedList ? "active" : ""}`, "aria-label": "Insert Ordered List", children: (0, jsx_runtime_1.jsx)("i", { className: "bi bi-list-ol" }) }), (0, jsx_runtime_1.jsx)("button", { tabIndex: -1, onClick: insertCheckList, className: `toolbar-item spaced ${isCheckList ? "active" : ""}`, "aria-label": "Insert Check List", children: (0, jsx_runtime_1.jsx)("i", { className: "bi bi-list-check" }) }), (props.topRightControls?.length ?? 0) > 0 && ((0, jsx_runtime_1.jsx)("div", { className: "float-end", children: props.topRightControls?.map((control) => ((0, jsx_runtime_1.jsx)("button", { tabIndex: -1, onClick: control.onClick, className: "toolbar-item spaced active", "aria-label": "Insert Check List", title: control.title, children: (0, jsx_runtime_1.jsx)("i", { className: control.iconClass }) }, control.title))) }))] }));
103
+ }, className: `toolbar-item spaced ${isStrikethrough ? "active" : ""}`, "aria-label": "Format Strikethrough", children: (0, jsx_runtime_1.jsx)("i", { className: "bi bi-type-strikethrough" }) }), (0, jsx_runtime_1.jsx)("button", { tabIndex: -1, onMouseDown: (event) => event.preventDefault(), onClick: () => {
104
+ editor.dispatchCommand(link_plugin_1.OPEN_LINK_EDITOR_COMMAND, undefined);
105
+ }, className: `toolbar-item spaced ${isLink ? "active" : ""}`, "aria-label": "Link", title: `Link (${linkShortcutLabel})`, children: (0, jsx_runtime_1.jsx)("i", { className: "bi bi-link-45deg" }) }), (0, jsx_runtime_1.jsx)(Divider, {}), (0, jsx_runtime_1.jsx)("button", { tabIndex: -1, onClick: insertUnorderedList, className: `toolbar-item spaced ${isUnorderedList ? "active" : ""}`, "aria-label": "Insert Unordered List", children: (0, jsx_runtime_1.jsx)("i", { className: "bi bi-list-ul" }) }), (0, jsx_runtime_1.jsx)("button", { tabIndex: -1, onClick: insertOrderedList, className: `toolbar-item spaced ${isOrderedList ? "active" : ""}`, "aria-label": "Insert Ordered List", children: (0, jsx_runtime_1.jsx)("i", { className: "bi bi-list-ol" }) }), (0, jsx_runtime_1.jsx)("button", { tabIndex: -1, onClick: insertCheckList, className: `toolbar-item spaced ${isCheckList ? "active" : ""}`, "aria-label": "Insert Check List", children: (0, jsx_runtime_1.jsx)("i", { className: "bi bi-list-check" }) }), (props.topRightControls?.length ?? 0) > 0 && ((0, jsx_runtime_1.jsx)("div", { className: "float-end", children: props.topRightControls?.map((control) => ((0, jsx_runtime_1.jsx)("button", { tabIndex: -1, onClick: control.onClick, className: "toolbar-item spaced active", "aria-label": "Insert Check List", title: control.title, children: (0, jsx_runtime_1.jsx)("i", { className: control.iconClass }) }, control.title))) }))] }));
95
106
  }