@peers-app/peers-ui 0.33.6 → 0.33.8

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 (31) hide show
  1. package/dist/components/markdown-editor/editor.d.ts +40 -3
  2. package/dist/components/markdown-editor/editor.js +8 -3
  3. package/dist/components/markdown-editor/markdown-plugin.d.ts +4 -1
  4. package/dist/components/markdown-editor/markdown-plugin.js +32 -20
  5. package/dist/components/markdown-editor/mention-node.d.ts +28 -15
  6. package/dist/components/markdown-editor/mention-node.js +75 -129
  7. package/dist/components/markdown-editor/mention-preview-card.d.ts +13 -0
  8. package/dist/components/markdown-editor/mention-preview-card.js +30 -0
  9. package/dist/components/markdown-editor/mentions-plugin.d.ts +43 -4
  10. package/dist/components/markdown-editor/mentions-plugin.js +211 -107
  11. package/dist/components/markdown-editor/selection-effects-plugin.d.ts +18 -0
  12. package/dist/components/markdown-editor/selection-effects-plugin.js +49 -0
  13. package/dist/components/markdown-with-mentions.d.ts +12 -2
  14. package/dist/components/markdown-with-mentions.js +110 -110
  15. package/dist/index.d.ts +2 -0
  16. package/dist/index.js +9 -1
  17. package/dist/mentions/mention-chip.d.ts +33 -0
  18. package/dist/mentions/mention-chip.js +76 -0
  19. package/dist/mentions/mention-chooser.d.ts +9 -0
  20. package/dist/mentions/mention-chooser.js +51 -0
  21. package/dist/mentions/mentions-client.d.ts +47 -0
  22. package/dist/mentions/mentions-client.js +198 -0
  23. package/dist/notifications/notifications-client.d.ts +3 -3
  24. package/dist/notifications/notifications-client.js +6 -63
  25. package/dist/root-layout/root-layout-host.js +2 -2
  26. package/dist/theme.css +224 -0
  27. package/dist/ui-router/open-in-group.d.ts +17 -0
  28. package/dist/ui-router/open-in-group.js +81 -0
  29. package/dist/ui-router/routes-loader.js +46 -27
  30. package/dist/ui-router/runnable-version.js +2 -1
  31. package/package.json +4 -4
@@ -33,18 +33,20 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.MENTIONS_MAX_RESULTS = void 0;
36
+ exports.parseQuery = parseQuery;
37
+ exports.pickerOptions = pickerOptions;
38
+ exports.sharedKinds = sharedKinds;
37
39
  exports.MentionsPlugin = MentionsPlugin;
38
40
  const jsx_runtime_1 = require("react/jsx-runtime");
39
41
  const LexicalComposerContext_1 = require("@lexical/react/LexicalComposerContext");
40
42
  const LexicalTypeaheadMenuPlugin_1 = require("@lexical/react/LexicalTypeaheadMenuPlugin");
41
43
  const peers_sdk_1 = require("@peers-app/peers-sdk");
42
44
  const lexical_1 = require("lexical");
43
- const lodash_1 = require("lodash");
44
- const React = __importStar(require("react"));
45
45
  const react_1 = require("react");
46
46
  const ReactDOM = __importStar(require("react-dom"));
47
+ const mentions_client_1 = require("../../mentions/mentions-client");
47
48
  const mention_node_1 = require("./mention-node");
49
+ const mention_preview_card_1 = require("./mention-preview-card");
48
50
  const PUNCTUATION = "\\.,\\+\\*\\?\\$\\@\\|#{}\\(\\)\\^\\-\\[\\]\\\\/!%'\"~=<>_:;";
49
51
  const NAME = `\\b[A-Z][^\\s${PUNCTUATION}]`;
50
52
  const DocumentMentionsRegex = {
@@ -52,7 +54,9 @@ const DocumentMentionsRegex = {
52
54
  PUNCTUATION,
53
55
  };
54
56
  const PUNC = DocumentMentionsRegex.PUNCTUATION;
55
- const TRIGGERS = ["@", "<"].join("");
57
+ // `@` or `<` starts the picker (Mark, 2026-11-14: `<` as well as `@`); `@kind:` narrows the search
58
+ // to one kind.
59
+ const TRIGGERS = "@<";
56
60
  // Chars we expect to see in a mention (non-space, non-punctuation).
57
61
  const VALID_CHARS = `[^${TRIGGERS}${PUNC}\\s]`;
58
62
  // Non-standard series of chars. Each series must be preceded and followed by
@@ -89,60 +93,99 @@ const AtSignMentionsRegexAliasRegex = new RegExp("(^|\\s|\\()(" +
89
93
  ALIAS_LENGTH_LIMIT +
90
94
  "})" +
91
95
  ")$");
92
- // At most, 5 suggestions are shown in the popup.
96
+ /** Most suggestions shown. */
93
97
  const SUGGESTION_LIST_LENGTH_LIMIT = 10;
94
- exports.MENTIONS_MAX_RESULTS = 10;
95
- function useMentionLookupService(mentionString, mentionConfigs = []) {
96
- const [results, setResults] = (0, react_1.useState)([]);
98
+ /** How long typing pauses before a search. */
99
+ const SEARCH_DEBOUNCE_MS = 120;
100
+ /**
101
+ * What the user typed after `@` or `<`: words, and a kind when it starts with `kind:`.
102
+ *
103
+ * @param query - The text from the trigger on, such as `@task:garden`.
104
+ */
105
+ function parseQuery(query) {
106
+ const typed = query.replace(/^[@<]/, "");
107
+ const colon = typed.indexOf(":");
108
+ const kind = colon > 0 ? typed.slice(0, colon).toLowerCase() : "";
109
+ if ((0, peers_sdk_1.isMentionKind)(kind))
110
+ return { text: typed.slice(colon + 1), kinds: [kind] };
111
+ return { text: typed };
112
+ }
113
+ /**
114
+ * Search System Mentions as the user types: debounced, and a newer query replaces an older one,
115
+ * so a slow answer never overwrites a newer one.
116
+ */
117
+ function useMentionSearch(query, groupId) {
118
+ const [found, setFound] = (0, react_1.useState)({ query: null, results: [] });
97
119
  (0, react_1.useEffect)(() => {
98
- if (!mentionString) {
99
- setResults([]);
120
+ if (!query) {
121
+ setFound({ query, results: [] });
100
122
  return;
101
123
  }
102
- (async () => {
103
- const prefix = mentionString[0];
104
- mentionString = mentionString.slice(1);
105
- // TODO simplify how users can include completed tasks in their search
106
- const searchCompletedTasks = prefix === "$" && mentionString.startsWith("done");
107
- if (searchCompletedTasks) {
108
- mentionString = mentionString.slice(4);
109
- }
110
- let kind = "";
111
- if (mentionString.includes(":")) {
112
- const parts = mentionString.split(":");
113
- kind = parts[0];
114
- mentionString = parts[1] || "";
115
- }
116
- const config = mentionConfigs?.find((c) => c.kind === kind);
117
- if (config) {
118
- const results = await config.query(mentionString);
119
- setResults(results);
120
- return;
121
- }
122
- const results = await Promise.all(mentionConfigs?.map((c) => c.query(mentionString || "")));
123
- let allResults = results.flat();
124
- allResults = (0, lodash_1.uniqBy)(allResults, "id");
125
- let filteredResults = allResults;
126
- if (prefix === "@") {
127
- filteredResults = filteredResults.filter((result) => result.kind === "user");
128
- }
129
- else {
130
- filteredResults = filteredResults.filter((result) => result.kind !== "user");
131
- }
132
- if (kind) {
133
- filteredResults = allResults.filter((result) => result.kind.toLowerCase() === kind.toLowerCase());
134
- }
135
- else if (!filteredResults.length) {
136
- filteredResults = allResults;
137
- }
138
- filteredResults = (0, lodash_1.sortBy)(filteredResults, (r) => {
139
- return r.name.toLowerCase().indexOf((mentionString ?? "").toLowerCase());
124
+ let live = true;
125
+ const timer = setTimeout(() => {
126
+ void (async () => {
127
+ const docGroup = groupId ?? (await (0, mentions_client_1.activeGroupId)());
128
+ const results = await (0, mentions_client_1.searchMentions)({
129
+ ...parseQuery(query),
130
+ groupId: docGroup,
131
+ limit: SUGGESTION_LIST_LENGTH_LIMIT,
132
+ });
133
+ if (live)
134
+ setFound({ query, results, docGroup });
135
+ })().catch((error) => {
136
+ console.warn("[mentions] search failed", error);
137
+ // A failed search isn't an answer that nothing has this id.
138
+ if (live)
139
+ setFound({ query: null, results: [] });
140
140
  });
141
- filteredResults = filteredResults.slice(0, SUGGESTION_LIST_LENGTH_LIMIT);
142
- setResults(filteredResults);
143
- })();
144
- }, [mentionString, mentionConfigs?.find, mentionConfigs?.map]);
145
- return results;
141
+ }, SEARCH_DEBOUNCE_MS);
142
+ return () => {
143
+ live = false;
144
+ clearTimeout(timer);
145
+ };
146
+ }, [query, groupId]);
147
+ return found;
148
+ }
149
+ /**
150
+ * The result offered for a pasted id that matches nothing: a link to whatever has that id, or to
151
+ * the kind the user typed before it (`<task:<id>`).
152
+ */
153
+ function unknownIdResult(id, kind = peers_sdk_1.ANY_MENTION_KIND) {
154
+ return {
155
+ kind,
156
+ id,
157
+ kindLabel: "Not found",
158
+ title: id,
159
+ iconClassName: "bi bi-question-circle",
160
+ route: "",
161
+ places: 0,
162
+ };
163
+ }
164
+ /**
165
+ * What the picker offers for a query, and whether one result should be taken without asking.
166
+ *
167
+ * - Words: the results, as they are.
168
+ * - A pasted id (`@<id>` or `<<id>`), once its search has answered: the one record with that id,
169
+ * taken at once; nothing found, a link to whatever has the id, taken at once; several records
170
+ * (the same id in two kinds), offered to pick from. Before the answer, nothing.
171
+ *
172
+ * @param query - The text from the trigger on, or null when the picker is closed.
173
+ * @param found - The latest search answer.
174
+ * @param declined - A query the user undid an automatic pick for: offered, not taken again.
175
+ */
176
+ function pickerOptions(query, found, declined) {
177
+ if (!query)
178
+ return { results: [] };
179
+ const { text, kinds } = parseQuery(query);
180
+ if (!(0, peers_sdk_1.looksLikeRecordId)(text))
181
+ return { results: found.results };
182
+ if (found.query !== query)
183
+ return { results: [] };
184
+ const exact = found.results.filter((r) => r.id === text);
185
+ const results = exact.length ? exact : [unknownIdResult(text, kinds?.[0])];
186
+ if (results.length > 1 || declined === query)
187
+ return { results };
188
+ return { results, autoPick: results[0] };
146
189
  }
147
190
  function checkForAtSignMentions(text, minMatchLength) {
148
191
  let match = AtSignMentionsRegex.exec(text);
@@ -168,31 +211,88 @@ function getPossibleQueryMatch(text) {
168
211
  return checkForAtSignMentions(text, 1);
169
212
  }
170
213
  class MentionTypeaheadOption extends LexicalTypeaheadMenuPlugin_1.MenuOption {
171
- data;
172
- name;
173
- picture;
174
- id;
175
- userId;
176
- constructor(data, picture) {
177
- super(data.name);
178
- this.data = data;
179
- this.name = data.name;
180
- this.picture = picture;
181
- this.id = data.id;
214
+ result;
215
+ showPackage;
216
+ /**
217
+ * @param result - The search result.
218
+ * @param showPackage - Name its package: another package's results share its kind.
219
+ */
220
+ constructor(result, showPackage) {
221
+ super(`${result.kind}/${result.id}`);
222
+ this.result = result;
223
+ this.showPackage = showPackage;
182
224
  }
183
225
  }
184
- function MentionsTypeaheadMenuItem({ index, isSelected, onClick, onMouseEnter, option, }) {
185
- let className = "item";
186
- if (isSelected) {
187
- className += " selected";
226
+ /** The kinds that more than one package answers for among these results. */
227
+ function sharedKinds(results) {
228
+ const packages = new Map();
229
+ for (const { kind, packageId } of results) {
230
+ if (!packageId)
231
+ continue;
232
+ packages.set(kind, (packages.get(kind) ?? new Set()).add(packageId));
188
233
  }
189
- return ((0, jsx_runtime_1.jsxs)("li", { tabIndex: -1, className: className, ref: option.setRefElement, "aria-selected": isSelected, id: `typeahead-item-${index}`, onMouseEnter: onMouseEnter, onClick: onClick, "data-kind": option.data.kind, "data-id": option.id, "data-user-id": option.userId || undefined, children: [option.picture, (0, jsx_runtime_1.jsx)("span", { className: "text", children: option.name })] }, option.key));
234
+ return new Set([...packages].filter(([, ids]) => ids.size > 1).map(([kind]) => kind));
235
+ }
236
+ /**
237
+ * A row's second line: what it is (with its package when another package shares its kind), its
238
+ * status, and its group when not the document's.
239
+ */
240
+ function details(option, docGroup) {
241
+ const { result } = option;
242
+ return [
243
+ result.kind === "user" ? undefined : result.kindLabel,
244
+ option.showPackage ? result.packageName : undefined,
245
+ result.status,
246
+ result.groupId && result.groupId !== docGroup ? result.groupName : undefined,
247
+ ]
248
+ .filter(Boolean)
249
+ .join(" · ");
250
+ }
251
+ function MentionsTypeaheadMenuItem({ index, isSelected, onClick, onMouseEnter, option, docGroup, }) {
252
+ const { result } = option;
253
+ const otherGroup = !!result.groupId && result.groupId !== docGroup;
254
+ const detail = details(option, docGroup);
255
+ return ((0, jsx_runtime_1.jsxs)("li", { tabIndex: -1, className: `peers-mention-menu-item${isSelected ? " is-selected" : ""}${otherGroup ? " is-other-group" : ""}`, ref: option.setRefElement, "aria-selected": isSelected, id: `typeahead-item-${index}`, onMouseEnter: onMouseEnter, onClick: onClick, "data-kind": result.kind, "data-id": result.id, children: [(0, jsx_runtime_1.jsx)("span", { className: "peers-mention-menu-icon", "aria-hidden": true, children: result.kind === "user" ? ("@") : ((0, jsx_runtime_1.jsx)("i", { className: result.iconClassName ?? "bi bi-link-45deg" })) }), (0, jsx_runtime_1.jsxs)("span", { className: "peers-mention-menu-text", children: [(0, jsx_runtime_1.jsx)("span", { className: `peers-mention-menu-title${result.done ? " peers-mention-done" : ""}`, children: result.title || result.kindLabel }), detail && (0, jsx_runtime_1.jsx)("span", { className: "peers-mention-menu-detail", children: detail })] })] }, option.key));
256
+ }
257
+ /** Takes a result as soon as it's shown: a pasted id that found one record, or none. */
258
+ function AutoPick({ pick }) {
259
+ (0, react_1.useEffect)(() => pick(), []);
260
+ return null;
261
+ }
262
+ /** Whether the menu should open above the caret: the caret is in the lower half of the window. */
263
+ function opensAbove(anchor) {
264
+ return anchor.getBoundingClientRect().top > window.innerHeight / 2;
190
265
  }
266
+ /** The menu's width and the card's, and the gap between them (`theme.css`). */
267
+ const MENU_WIDTH = 300;
268
+ const PREVIEW_GAP = 8;
269
+ /**
270
+ * Where the preview goes: right of the menu, else left of it, else under it (a window too narrow
271
+ * for either, such as a tablet held upright).
272
+ */
273
+ function previewSide(anchor) {
274
+ const { left } = anchor.getBoundingClientRect();
275
+ if (left + MENU_WIDTH + PREVIEW_GAP + MENU_WIDTH <= window.innerWidth)
276
+ return "";
277
+ if (left - PREVIEW_GAP - MENU_WIDTH >= 0)
278
+ return "is-preview-left";
279
+ return "is-preview-below";
280
+ }
281
+ /**
282
+ * The mention picker, opened by `@` or `<`: people first, then records from every group the user
283
+ * is in, through System Mentions, with a preview of the highlighted one. Picking one inserts a
284
+ * mention chip labeled with the record's title. A pasted id becomes a chip at once: the record's,
285
+ * or a dotted `?` chip for an id that matches nothing.
286
+ */
191
287
  function MentionsPlugin(props) {
192
288
  const [editor] = (0, LexicalComposerContext_1.useLexicalComposerContext)();
193
289
  const [queryString, setQueryString] = (0, react_1.useState)(null);
194
- const results = useMentionLookupService(queryString, props.mentionConfigs);
290
+ const found = useMentionSearch(queryString, props.groupId);
291
+ const { docGroup } = found;
195
292
  const [_mentionsOpen] = (0, react_1.useState)(() => (0, peers_sdk_1.observable)(false));
293
+ // The last query taken automatically. An undo brings it back; then it's offered, not retaken.
294
+ const autoPicked = (0, react_1.useRef)(null);
295
+ const { results, autoPick } = (0, react_1.useMemo)(() => pickerOptions(queryString, found, autoPicked.current), [queryString, found]);
196
296
  if (props.mentionsOpen) {
197
297
  const finalMentionsOpen = _mentionsOpen() && results.length > 0;
198
298
  if (props.mentionsOpen() !== finalMentionsOpen) {
@@ -202,31 +302,21 @@ function MentionsPlugin(props) {
202
302
  const checkForSlashTriggerMatch = (0, LexicalTypeaheadMenuPlugin_1.useBasicTypeaheadTriggerMatch)("/", {
203
303
  minLength: 0,
204
304
  });
205
- const options = (0, react_1.useMemo)(() => results
206
- .map((result) => {
207
- const picKey = `mention-pic-${result.kind}-${result.id}`;
208
- let picture = (0, jsx_runtime_1.jsx)("i", { className: "bi bi-question pe-1" }, picKey);
209
- const config = props.mentionConfigs?.find((c) => c.kind === result.kind);
210
- if (config) {
211
- if (config.picture) {
212
- picture = config.picture(result);
213
- }
214
- else {
215
- picture = (0, jsx_runtime_1.jsx)("i", { className: `${config.iconClass} pe-1` }, picKey);
216
- }
217
- }
218
- else {
219
- picture = (0, jsx_runtime_1.jsx)("i", { className: "bi bi-question pe-1" }, picKey);
220
- }
221
- return new MentionTypeaheadOption(result, picture);
222
- })
223
- .slice(0, SUGGESTION_LIST_LENGTH_LIMIT), [results, props.mentionConfigs?.find]);
305
+ const options = (0, react_1.useMemo)(() => {
306
+ const shown = results.slice(0, SUGGESTION_LIST_LENGTH_LIMIT);
307
+ const shared = sharedKinds(shown);
308
+ return shown.map((r) => new MentionTypeaheadOption(r, shared.has(r.kind)));
309
+ }, [results]);
224
310
  const onSelectOption = (0, react_1.useCallback)((selectedOption, nodeToReplace, closeMenu) => {
225
311
  editor.update(() => {
226
- const mentionNode = (0, mention_node_1.$createMentionNode)(selectedOption.data);
227
- if (nodeToReplace) {
228
- nodeToReplace.replace(mentionNode);
312
+ // The typed query is gone (an undo, or a pick already made): nothing to put a chip in.
313
+ if (!nodeToReplace) {
314
+ closeMenu();
315
+ return;
229
316
  }
317
+ const { kind, id, title, kindLabel } = selectedOption.result;
318
+ const mentionNode = (0, mention_node_1.$createMentionNode)({ kind, id, label: title || kindLabel });
319
+ nodeToReplace.replace(mentionNode);
230
320
  mentionNode.selectNext(); // Move cursor to the position after the mention
231
321
  const selection = (0, lexical_1.$getSelection)();
232
322
  if (selection !== null) {
@@ -242,23 +332,37 @@ function MentionsPlugin(props) {
242
332
  }
243
333
  return getPossibleQueryMatch(text);
244
334
  }, [checkForSlashTriggerMatch, editor]);
245
- const _popoverRef = React.useRef(null);
246
- return ((0, jsx_runtime_1.jsx)(LexicalTypeaheadMenuPlugin_1.LexicalTypeaheadMenuPlugin, { onQueryChange: setQueryString, onSelectOption: onSelectOption, triggerFn: checkForMentionMatch, options: options, onOpen: () => _mentionsOpen(true), onClose: () => _mentionsOpen(false), menuRenderFn: (anchorElementRef, { selectedIndex, selectOptionAndCleanUp, setHighlightedIndex }) => {
247
- if (!(anchorElementRef.current && results.length)) {
335
+ return ((0, jsx_runtime_1.jsx)(LexicalTypeaheadMenuPlugin_1.LexicalTypeaheadMenuPlugin, { onQueryChange: (query) => {
336
+ // Closing the menu (null) keeps it, so an undo right after doesn't pick it again.
337
+ if (query !== null && query !== autoPicked.current)
338
+ autoPicked.current = null;
339
+ setQueryString(query);
340
+ }, onSelectOption: onSelectOption, triggerFn: checkForMentionMatch, options: options, onOpen: () => _mentionsOpen(true), onClose: () => _mentionsOpen(false), menuRenderFn: (anchorElementRef, { selectedIndex, selectOptionAndCleanUp, setHighlightedIndex }) => {
341
+ const anchor = anchorElementRef.current;
342
+ if (!(anchor && options.length)) {
248
343
  return null;
249
344
  }
250
- // distance from the top of the viewport to the top of the anchor element
251
- const anchorTop = anchorElementRef.current.getBoundingClientRect().top;
252
- const viewportHeight = window.innerHeight;
253
- let className = "typeahead-popover mentions-menu";
254
- if (anchorTop > viewportHeight / 2) {
255
- className += " mentions-menu-popup";
345
+ if (autoPick) {
346
+ const option = options[0];
347
+ return ((0, jsx_runtime_1.jsx)(AutoPick, { pick: () => {
348
+ // Once per query: React may run the effect twice, and an undo brings it back.
349
+ if (autoPicked.current === queryString)
350
+ return;
351
+ autoPicked.current = queryString;
352
+ selectOptionAndCleanUp(option);
353
+ } }, `${queryString}:${option.key}`));
256
354
  }
257
- return ReactDOM.createPortal((0, jsx_runtime_1.jsx)("div", { className: className, children: (0, jsx_runtime_1.jsx)("ul", { children: options.map((option, i) => ((0, jsx_runtime_1.jsx)(MentionsTypeaheadMenuItem, { index: i, isSelected: selectedIndex === i, onClick: () => {
258
- setHighlightedIndex(i);
259
- selectOptionAndCleanUp(option);
260
- }, onMouseEnter: () => {
261
- setHighlightedIndex(i);
262
- }, option: option }, option.key))) }) }), anchorElementRef.current);
355
+ const highlighted = selectedIndex === null ? undefined : options[selectedIndex];
356
+ const classes = [
357
+ "peers-mention-menu",
358
+ opensAbove(anchor) ? "is-above" : "",
359
+ previewSide(anchor),
360
+ ];
361
+ return ReactDOM.createPortal((0, jsx_runtime_1.jsxs)("div", { className: classes.filter(Boolean).join(" "), children: [(0, jsx_runtime_1.jsx)("ul", { className: "peers-mention-menu-list", children: options.map((option, i) => ((0, jsx_runtime_1.jsx)(MentionsTypeaheadMenuItem, { index: i, isSelected: selectedIndex === i, onClick: () => {
362
+ setHighlightedIndex(i);
363
+ selectOptionAndCleanUp(option);
364
+ }, onMouseEnter: () => {
365
+ setHighlightedIndex(i);
366
+ }, option: option, docGroup: docGroup }, option.key))) }), highlighted ? ((0, jsx_runtime_1.jsx)(mention_preview_card_1.MentionPreviewCard, { result: highlighted.result, showPackage: highlighted.showPackage })) : null] }), anchor);
263
367
  } }));
264
368
  }
@@ -0,0 +1,18 @@
1
+ import type { IMentionLink } from "@peers-app/peers-sdk";
2
+ import type { IEditorEffects } from "./editor";
3
+ /** The selected text as plain text, or empty when nothing is selected. Inside an editor read. */
4
+ export declare function $selectedText(): string;
5
+ /**
6
+ * Replace the selected text with a mention chip. Inside an editor update.
7
+ *
8
+ * @param link - The record and the chip's label.
9
+ * @returns false, changing nothing, when nothing is selected.
10
+ */
11
+ export declare function $replaceSelectionWithMention(link: IMentionLink): boolean;
12
+ /**
13
+ * Fills in the selection hooks of {@link IEditorEffects}, so a screen can turn selected text into
14
+ * a link to something it makes from it (Notes' Make note and Make task).
15
+ */
16
+ export declare function SelectionEffectsPlugin({ effects }: {
17
+ effects: IEditorEffects;
18
+ }): null;
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.$selectedText = $selectedText;
4
+ exports.$replaceSelectionWithMention = $replaceSelectionWithMention;
5
+ exports.SelectionEffectsPlugin = SelectionEffectsPlugin;
6
+ const LexicalComposerContext_1 = require("@lexical/react/LexicalComposerContext");
7
+ const lexical_1 = require("lexical");
8
+ const react_1 = require("react");
9
+ const mention_node_1 = require("./mention-node");
10
+ /** The selected text as plain text, or empty when nothing is selected. Inside an editor read. */
11
+ function $selectedText() {
12
+ const selection = (0, lexical_1.$getSelection)();
13
+ return (0, lexical_1.$isRangeSelection)(selection) && !selection.isCollapsed() ? selection.getTextContent() : "";
14
+ }
15
+ /**
16
+ * Replace the selected text with a mention chip. Inside an editor update.
17
+ *
18
+ * @param link - The record and the chip's label.
19
+ * @returns false, changing nothing, when nothing is selected.
20
+ */
21
+ function $replaceSelectionWithMention(link) {
22
+ const selection = (0, lexical_1.$getSelection)();
23
+ if (!(0, lexical_1.$isRangeSelection)(selection) || selection.isCollapsed())
24
+ return false;
25
+ selection.insertNodes([(0, mention_node_1.$createMentionNode)(link)]);
26
+ return true;
27
+ }
28
+ /**
29
+ * Fills in the selection hooks of {@link IEditorEffects}, so a screen can turn selected text into
30
+ * a link to something it makes from it (Notes' Make note and Make task).
31
+ */
32
+ function SelectionEffectsPlugin({ effects }) {
33
+ const [editor] = (0, LexicalComposerContext_1.useLexicalComposerContext)();
34
+ (0, react_1.useEffect)(() => {
35
+ effects.getSelectedText = () => editor.getEditorState().read($selectedText);
36
+ effects.replaceSelectionWithMention = (link) => {
37
+ let replaced = false;
38
+ editor.update(() => {
39
+ replaced = $replaceSelectionWithMention(link);
40
+ }, { discrete: true });
41
+ return replaced;
42
+ };
43
+ return () => {
44
+ effects.getSelectedText = undefined;
45
+ effects.replaceSelectionWithMention = undefined;
46
+ };
47
+ }, [editor, effects]);
48
+ return null;
49
+ }
@@ -1,8 +1,18 @@
1
1
  import React from "react";
2
2
  /**
3
- * Render markdown (GitHub-flavored) with `@mentions` turned into links. Web links open in
4
- * the system browser through System Host Shell instead of navigating the app window.
3
+ * Keep `peers://` mention links; every other URL gets react-markdown's default treatment, which
4
+ * blanks `javascript:` and other unsafe schemes in text other members wrote.
5
+ */
6
+ export declare function mentionUrlTransform(url: string): string;
7
+ /**
8
+ * Render markdown (GitHub-flavored) with mentions (`[label](peers://<kind>/<id>)`, and the
9
+ * older `<$kind:Name:id>`) as chips showing each record's live title. Web links open in the
10
+ * system browser through System Host Shell instead of navigating the app window.
11
+ *
12
+ * @param props.content - The markdown.
13
+ * @param props.groupId - The group the text belongs to: mentions resolve there first.
5
14
  */
6
15
  export declare const MarkdownWithMentions: React.FC<{
7
16
  content: string;
17
+ groupId?: string;
8
18
  }>;