@peers-app/peers-ui 0.33.6 → 0.33.7

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.
@@ -33,17 +33,16 @@ 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.sharedKinds = sharedKinds;
37
37
  exports.MentionsPlugin = MentionsPlugin;
38
38
  const jsx_runtime_1 = require("react/jsx-runtime");
39
39
  const LexicalComposerContext_1 = require("@lexical/react/LexicalComposerContext");
40
40
  const LexicalTypeaheadMenuPlugin_1 = require("@lexical/react/LexicalTypeaheadMenuPlugin");
41
41
  const peers_sdk_1 = require("@peers-app/peers-sdk");
42
42
  const lexical_1 = require("lexical");
43
- const lodash_1 = require("lodash");
44
- const React = __importStar(require("react"));
45
43
  const react_1 = require("react");
46
44
  const ReactDOM = __importStar(require("react-dom"));
45
+ const mentions_client_1 = require("../../mentions/mentions-client");
47
46
  const mention_node_1 = require("./mention-node");
48
47
  const PUNCTUATION = "\\.,\\+\\*\\?\\$\\@\\|#{}\\(\\)\\^\\-\\[\\]\\\\/!%'\"~=<>_:;";
49
48
  const NAME = `\\b[A-Z][^\\s${PUNCTUATION}]`;
@@ -52,7 +51,8 @@ const DocumentMentionsRegex = {
52
51
  PUNCTUATION,
53
52
  };
54
53
  const PUNC = DocumentMentionsRegex.PUNCTUATION;
55
- const TRIGGERS = ["@", "<"].join("");
54
+ // `@` is the only trigger (Mark, 2026-11-14); `@kind:` narrows the search to one kind.
55
+ const TRIGGERS = "@";
56
56
  // Chars we expect to see in a mention (non-space, non-punctuation).
57
57
  const VALID_CHARS = `[^${TRIGGERS}${PUNC}\\s]`;
58
58
  // Non-standard series of chars. Each series must be preceded and followed by
@@ -89,60 +89,55 @@ const AtSignMentionsRegexAliasRegex = new RegExp("(^|\\s|\\()(" +
89
89
  ALIAS_LENGTH_LIMIT +
90
90
  "})" +
91
91
  ")$");
92
- // At most, 5 suggestions are shown in the popup.
92
+ /** Most suggestions shown. */
93
93
  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)([]);
94
+ /** How long typing pauses before a search. */
95
+ const SEARCH_DEBOUNCE_MS = 120;
96
+ /** What the user typed after `@`: words, and a kind when it starts with `kind:`. */
97
+ function parseQuery(query) {
98
+ const typed = query.replace(/^@/, "");
99
+ const colon = typed.indexOf(":");
100
+ const kind = colon > 0 ? typed.slice(0, colon).toLowerCase() : "";
101
+ if ((0, peers_sdk_1.isMentionKind)(kind))
102
+ return { text: typed.slice(colon + 1), kinds: [kind] };
103
+ return { text: typed };
104
+ }
105
+ /**
106
+ * Search System Mentions as the user types: debounced, and a newer query replaces an older one,
107
+ * so a slow answer never overwrites a newer one.
108
+ */
109
+ function useMentionSearch(query, groupId) {
110
+ const [found, setFound] = (0, react_1.useState)({
111
+ results: [],
112
+ });
97
113
  (0, react_1.useEffect)(() => {
98
- if (!mentionString) {
99
- setResults([]);
114
+ if (!query) {
115
+ setFound({ results: [] });
100
116
  return;
101
117
  }
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());
118
+ let live = true;
119
+ const timer = setTimeout(() => {
120
+ void (async () => {
121
+ const docGroup = groupId ?? (await (0, mentions_client_1.activeGroupId)());
122
+ const results = await (0, mentions_client_1.searchMentions)({
123
+ ...parseQuery(query),
124
+ groupId: docGroup,
125
+ limit: SUGGESTION_LIST_LENGTH_LIMIT,
126
+ });
127
+ if (live)
128
+ setFound({ results, docGroup });
129
+ })().catch((error) => {
130
+ console.warn("[mentions] search failed", error);
131
+ if (live)
132
+ setFound({ results: [] });
140
133
  });
141
- filteredResults = filteredResults.slice(0, SUGGESTION_LIST_LENGTH_LIMIT);
142
- setResults(filteredResults);
143
- })();
144
- }, [mentionString, mentionConfigs?.find, mentionConfigs?.map]);
145
- return results;
134
+ }, SEARCH_DEBOUNCE_MS);
135
+ return () => {
136
+ live = false;
137
+ clearTimeout(timer);
138
+ };
139
+ }, [query, groupId]);
140
+ return found;
146
141
  }
147
142
  function checkForAtSignMentions(text, minMatchLength) {
148
143
  let match = AtSignMentionsRegex.exec(text);
@@ -168,30 +163,58 @@ function getPossibleQueryMatch(text) {
168
163
  return checkForAtSignMentions(text, 1);
169
164
  }
170
165
  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;
166
+ result;
167
+ showPackage;
168
+ /**
169
+ * @param result - The search result.
170
+ * @param showPackage - Name its package: another package's results share its kind.
171
+ */
172
+ constructor(result, showPackage) {
173
+ super(`${result.kind}/${result.id}`);
174
+ this.result = result;
175
+ this.showPackage = showPackage;
182
176
  }
183
177
  }
184
- function MentionsTypeaheadMenuItem({ index, isSelected, onClick, onMouseEnter, option, }) {
185
- let className = "item";
186
- if (isSelected) {
187
- className += " selected";
178
+ /** The kinds that more than one package answers for among these results. */
179
+ function sharedKinds(results) {
180
+ const packages = new Map();
181
+ for (const { kind, packageId } of results) {
182
+ if (!packageId)
183
+ continue;
184
+ packages.set(kind, (packages.get(kind) ?? new Set()).add(packageId));
188
185
  }
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));
186
+ return new Set([...packages].filter(([, ids]) => ids.size > 1).map(([kind]) => kind));
187
+ }
188
+ /**
189
+ * What a result is (with its package when another package shares its kind), its status, its
190
+ * group when not the document's, and any extra places.
191
+ */
192
+ function details(option, docGroup) {
193
+ const { result } = option;
194
+ return [
195
+ result.kind === "user" ? undefined : result.kindLabel,
196
+ option.showPackage ? result.packageName : undefined,
197
+ result.status,
198
+ result.groupId && result.groupId !== docGroup ? result.groupName : undefined,
199
+ result.places > 1 ? `${result.places} places` : undefined,
200
+ ]
201
+ .filter(Boolean)
202
+ .join(" · ");
203
+ }
204
+ function MentionsTypeaheadMenuItem({ index, isSelected, onClick, onMouseEnter, option, docGroup, }) {
205
+ const { result } = option;
206
+ const otherGroup = !!result.groupId && result.groupId !== docGroup;
207
+ const detail = details(option, docGroup);
208
+ return ((0, jsx_runtime_1.jsxs)("li", { tabIndex: -1, className: `item${isSelected ? " selected" : ""}${otherGroup ? " 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: [result.kind === "user" ? ((0, jsx_runtime_1.jsx)("span", { className: "pe-1", children: "@" })) : ((0, jsx_runtime_1.jsx)("i", { className: `${result.iconClassName ?? "bi bi-link-45deg"} pe-1` })), (0, jsx_runtime_1.jsxs)("span", { className: "text", children: [(0, jsx_runtime_1.jsx)("span", { className: result.done ? "peers-mention-done" : undefined, children: result.title || result.kindLabel }), detail && (0, jsx_runtime_1.jsx)("span", { className: "peers-mention-menu-detail", children: detail })] })] }, option.key));
190
209
  }
210
+ /**
211
+ * The `@` picker: people first, then records from every group the user is in, through System
212
+ * Mentions. Picking one inserts a mention chip labeled with the record's title.
213
+ */
191
214
  function MentionsPlugin(props) {
192
215
  const [editor] = (0, LexicalComposerContext_1.useLexicalComposerContext)();
193
216
  const [queryString, setQueryString] = (0, react_1.useState)(null);
194
- const results = useMentionLookupService(queryString, props.mentionConfigs);
217
+ const { results, docGroup } = useMentionSearch(queryString, props.groupId);
195
218
  const [_mentionsOpen] = (0, react_1.useState)(() => (0, peers_sdk_1.observable)(false));
196
219
  if (props.mentionsOpen) {
197
220
  const finalMentionsOpen = _mentionsOpen() && results.length > 0;
@@ -202,28 +225,15 @@ function MentionsPlugin(props) {
202
225
  const checkForSlashTriggerMatch = (0, LexicalTypeaheadMenuPlugin_1.useBasicTypeaheadTriggerMatch)("/", {
203
226
  minLength: 0,
204
227
  });
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]);
228
+ const options = (0, react_1.useMemo)(() => {
229
+ const shown = results.slice(0, SUGGESTION_LIST_LENGTH_LIMIT);
230
+ const shared = sharedKinds(shown);
231
+ return shown.map((r) => new MentionTypeaheadOption(r, shared.has(r.kind)));
232
+ }, [results]);
224
233
  const onSelectOption = (0, react_1.useCallback)((selectedOption, nodeToReplace, closeMenu) => {
225
234
  editor.update(() => {
226
- const mentionNode = (0, mention_node_1.$createMentionNode)(selectedOption.data);
235
+ const { kind, id, title, kindLabel } = selectedOption.result;
236
+ const mentionNode = (0, mention_node_1.$createMentionNode)({ kind, id, label: title || kindLabel });
227
237
  if (nodeToReplace) {
228
238
  nodeToReplace.replace(mentionNode);
229
239
  }
@@ -242,9 +252,8 @@ function MentionsPlugin(props) {
242
252
  }
243
253
  return getPossibleQueryMatch(text);
244
254
  }, [checkForSlashTriggerMatch, editor]);
245
- const _popoverRef = React.useRef(null);
246
255
  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)) {
256
+ if (!(anchorElementRef.current && options.length)) {
248
257
  return null;
249
258
  }
250
259
  // distance from the top of the viewport to the top of the anchor element
@@ -259,6 +268,6 @@ function MentionsPlugin(props) {
259
268
  selectOptionAndCleanUp(option);
260
269
  }, onMouseEnter: () => {
261
270
  setHighlightedIndex(i);
262
- }, option: option }, option.key))) }) }), anchorElementRef.current);
271
+ }, option: option, docGroup: docGroup }, option.key))) }) }), anchorElementRef.current);
263
272
  } }));
264
273
  }
@@ -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
  }>;
@@ -1,20 +1,69 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
2
35
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
37
  };
5
38
  Object.defineProperty(exports, "__esModule", { value: true });
6
39
  exports.MarkdownWithMentions = void 0;
40
+ exports.mentionUrlTransform = mentionUrlTransform;
7
41
  const jsx_runtime_1 = require("react/jsx-runtime");
8
- // import { FileListDisplay } from './file-list-display';
9
42
  const peers_sdk_1 = require("@peers-app/peers-sdk");
10
43
  const react_1 = __importDefault(require("react"));
11
- const react_markdown_1 = __importDefault(require("react-markdown"));
44
+ const react_markdown_1 = __importStar(require("react-markdown"));
12
45
  const remark_gfm_1 = __importDefault(require("remark-gfm"));
13
46
  const host_shell_consumer_1 = require("../host-shell/host-shell-consumer");
14
- const mention_configs_1 = require("../mention-configs");
15
- // Custom Link Renderer
47
+ const mention_chip_1 = require("../mentions/mention-chip");
48
+ /** The text in some rendered markdown children. */
49
+ function textOf(children) {
50
+ return react_1.default.Children.toArray(children)
51
+ .map((child) => {
52
+ if (typeof child === "string" || typeof child === "number")
53
+ return String(child);
54
+ if (react_1.default.isValidElement(child)) {
55
+ return textOf(child.props.children);
56
+ }
57
+ return "";
58
+ })
59
+ .join("");
60
+ }
61
+ /** A link: a mention becomes a chip, and a web link opens in the system browser. */
16
62
  const LinkRenderer = (props) => {
17
63
  const { href } = props;
64
+ const mention = href ? (0, peers_sdk_1.parseMentionUrl)(href) : undefined;
65
+ if (mention)
66
+ return (0, jsx_runtime_1.jsx)(mention_chip_1.MentionChip, { ...mention, label: textOf(props.children) });
18
67
  return ((0, jsx_runtime_1.jsx)("a", { href: href, onClick: (e) => {
19
68
  if (href?.startsWith("http")) {
20
69
  e.preventDefault();
@@ -22,94 +71,36 @@ const LinkRenderer = (props) => {
22
71
  }
23
72
  }, children: props.children }));
24
73
  };
74
+ /**
75
+ * An image. `![label](peers://…)` is a mention typed right after a `!` ("Thanks![Plan](…)"),
76
+ * which the editor shows as `!` and a chip, so it renders the same here.
77
+ */
78
+ const ImageRenderer = ({ node: _node, src, alt, ...props }) => {
79
+ const mention = typeof src === "string" ? (0, peers_sdk_1.parseMentionUrl)(src) : undefined;
80
+ if (mention) {
81
+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: ["!", (0, jsx_runtime_1.jsx)(mention_chip_1.MentionChip, { ...mention, label: alt ?? "" })] }));
82
+ }
83
+ return (0, jsx_runtime_1.jsx)("img", { src: src, alt: alt, ...props });
84
+ };
85
+ /** Text with the older `<$kind:Name:id>` mentions turned into chips (a name alone without an id). */
25
86
  const processTextWithMentions = (text) => {
26
87
  const parts = [];
88
+ const regex = new RegExp((0, peers_sdk_1.mentionRegex)().source, "g");
27
89
  let lastIndex = 0;
28
- let match;
29
- let cnt = 0;
30
- const regex = (0, peers_sdk_1.mentionRegex)();
31
- match = regex.exec(text);
32
- while (match !== null) {
33
- cnt++;
34
- if (match.index > lastIndex) {
35
- parts.push(text.slice(lastIndex, match.index));
36
- }
37
- text = text.slice(match.index + match[0].length);
38
- const kind = match[2];
39
- const name = match[3].replace(/_/g, " ");
40
- const id = match[4];
41
- const data = {
42
- kind,
43
- name,
44
- id,
45
- };
46
- const style = { cursor: "pointer" };
47
- if (name.length < 20) {
48
- style.whiteSpace = "nowrap";
49
- }
50
- const mentionConfig = mention_configs_1.mentionConfigs.find((c) => c.kind === kind);
51
- if (!mentionConfig) {
52
- // A kind Peers no longer has, such as a saved assistant or workflow mention: its name only.
53
- parts.push(name);
54
- lastIndex = regex.lastIndex;
55
- match = regex.exec(text);
56
- continue;
57
- }
58
- const mentionClass = mentionConfig.styleClass || "mention-default-default";
59
- const onClick = mentionConfig.onClick;
60
- const href = (!onClick && `#${kind}s/${id}`) || undefined;
61
- const icon = (kind === "user" && "@") ||
62
- (mentionConfig.iconClass && (0, jsx_runtime_1.jsx)("i", { className: `pe-1 ${mentionConfig.iconClass}` })) || ((0, jsx_runtime_1.jsx)("i", { className: `pe-1 bi bi-question` }));
63
- parts.push((0, jsx_runtime_1.jsxs)("a", { className: mentionClass, "data-kind": kind, "data-id": id, style: style, href: href, onClick: onClick && (() => onClick(data)), children: [icon, data.name] }, cnt));
64
- lastIndex = regex.lastIndex;
65
- match = regex.exec(text);
90
+ for (const match of text.matchAll(regex)) {
91
+ const at = match.index ?? 0;
92
+ if (at > lastIndex)
93
+ parts.push(text.slice(lastIndex, at));
94
+ const [, , kind, name, id] = match;
95
+ const label = name.replace(/_/g, " ");
96
+ const ref = id ? (0, peers_sdk_1.parseMentionUrl)(`peers://${kind.toLowerCase()}/${id}`) : undefined;
97
+ parts.push(ref ? (0, jsx_runtime_1.jsx)(mention_chip_1.MentionChip, { ...ref, label: label }, at) : label);
98
+ lastIndex = at + match[0].length;
66
99
  }
67
- if (lastIndex < text.length) {
100
+ if (lastIndex < text.length)
68
101
  parts.push(text.slice(lastIndex));
69
- }
70
102
  return parts;
71
103
  };
72
- // const TaskCheckbox = (props: { taskId: string }) => {
73
- // const [task, setTask] = useState<ITask | null>(null);
74
- // const [checked, setChecked] = useState(false);
75
- // useEffect(() => {
76
- // Tasks().get(props.taskId).then(task => {
77
- // if (!task) return;
78
- // setTask(task)
79
- // });
80
- // const sub = Tasks().dataChanged.subscribe(evt => {
81
- // if (evt.dataObject.taskId === props.taskId) {
82
- // setChecked(!!evt.dataObject.completeDT);
83
- // setTask(evt.dataObject);
84
- // }
85
- // });
86
- // Tasks().get(props.taskId).then(task => {
87
- // if (task) {
88
- // setChecked(!!task.completeDT);
89
- // }
90
- // });
91
- // return () => {
92
- // sub.unsubscribe();
93
- // };
94
- // }, [props.taskId])
95
- // return (
96
- // <input
97
- // type="checkbox"
98
- // disabled={!task}
99
- // checked={checked}
100
- // onChange={(e) => {
101
- // if (!task) return;
102
- // if (checked) {
103
- // task.completeDT = undefined;
104
- // } else {
105
- // task.completeDT = new Date();
106
- // }
107
- // Tasks().update(task);
108
- // setChecked(!checked);
109
- // }}
110
- // />
111
- // );
112
- // };
113
104
  const createElementWithMentions = (Element) => {
114
105
  return ({ node: _node, ...props }) => {
115
106
  return ((0, jsx_runtime_1.jsx)(Element, { ...props, children: react_1.default.Children.map(props.children, (child) => {
@@ -120,31 +111,40 @@ const createElementWithMentions = (Element) => {
120
111
  }) }));
121
112
  };
122
113
  };
114
+ const components = {
115
+ p: createElementWithMentions("p"),
116
+ h1: createElementWithMentions("h1"),
117
+ h2: createElementWithMentions("h2"),
118
+ h3: createElementWithMentions("h3"),
119
+ h4: createElementWithMentions("h4"),
120
+ h5: createElementWithMentions("h5"),
121
+ h6: createElementWithMentions("h6"),
122
+ li: createElementWithMentions("li"),
123
+ a: LinkRenderer,
124
+ img: ImageRenderer,
125
+ strong: createElementWithMentions("strong"),
126
+ em: createElementWithMentions("em"),
127
+ blockquote: createElementWithMentions("blockquote"),
128
+ code: createElementWithMentions("code"),
129
+ td: createElementWithMentions("td"),
130
+ th: createElementWithMentions("th"),
131
+ };
123
132
  /**
124
- * Render markdown (GitHub-flavored) with `@mentions` turned into links. Web links open in
125
- * the system browser through System Host Shell instead of navigating the app window.
133
+ * Keep `peers://` mention links; every other URL gets react-markdown's default treatment, which
134
+ * blanks `javascript:` and other unsafe schemes in text other members wrote.
126
135
  */
127
- const MarkdownWithMentions = ({ content }) => {
128
- const components = {
129
- p: createElementWithMentions("p"),
130
- h1: createElementWithMentions("h1"),
131
- h2: createElementWithMentions("h2"),
132
- h3: createElementWithMentions("h3"),
133
- h4: createElementWithMentions("h4"),
134
- h5: createElementWithMentions("h5"),
135
- h6: createElementWithMentions("h6"),
136
- li: createElementWithMentions("li"),
137
- // a: createElementWithMentions('a'),
138
- a: LinkRenderer,
139
- strong: createElementWithMentions("strong"),
140
- em: createElementWithMentions("em"),
141
- blockquote: createElementWithMentions("blockquote"),
142
- code: createElementWithMentions("code"),
143
- td: createElementWithMentions("td"),
144
- th: createElementWithMentions("th"),
145
- };
146
- return ((0, jsx_runtime_1.jsx)("div", { className: "markdown", children: (0, jsx_runtime_1.jsx)(react_markdown_1.default, { remarkPlugins: [remark_gfm_1.default],
147
- // @ts-expect-error
148
- components: components, children: content }) }));
149
- };
136
+ function mentionUrlTransform(url) {
137
+ return (0, peers_sdk_1.parseMentionUrl)(url) ? url : (0, react_markdown_1.defaultUrlTransform)(url);
138
+ }
139
+ /**
140
+ * Render markdown (GitHub-flavored) with mentions (`[label](peers://<kind>/<id>)`, and the
141
+ * older `<$kind:Name:id>`) as chips showing each record's live title. Web links open in the
142
+ * system browser through System Host Shell instead of navigating the app window.
143
+ *
144
+ * @param props.content - The markdown.
145
+ * @param props.groupId - The group the text belongs to: mentions resolve there first.
146
+ */
147
+ const MarkdownWithMentions = ({ content, groupId, }) => ((0, jsx_runtime_1.jsx)(mention_chip_1.MentionGroupContext.Provider, { value: groupId, children: (0, jsx_runtime_1.jsx)("div", { className: "markdown", children: (0, jsx_runtime_1.jsx)(react_markdown_1.default, { remarkPlugins: [remark_gfm_1.default], urlTransform: mentionUrlTransform,
148
+ // @ts-expect-error react-markdown's component props are narrower than these wrappers
149
+ components: components, children: content }) }) }));
150
150
  exports.MarkdownWithMentions = MarkdownWithMentions;
package/dist/index.d.ts CHANGED
@@ -13,6 +13,8 @@ export * from "./hooks";
13
13
  export { openLink } from "./host-shell/host-shell-consumer";
14
14
  export * from "./local-network/local-network-access";
15
15
  export * from "./local-network/local-network-offer";
16
+ export { MentionChip, MentionGroupContext, type MentionState, useMentionPlace, } from "./mentions/mention-chip";
17
+ export { openMention } from "./mentions/mentions-client";
16
18
  export { type INotificationHostControls, type NotificationHostState, notificationHostControls, } from "./notifications/host-controls";
17
19
  export * from "./operator-console/operator-console";
18
20
  export * from "./operator-console/operator-console-state";
package/dist/index.js CHANGED
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.updateActiveTabTitle = exports.goToTabPath = exports.closeCurrentTab = exports.activeTabs = exports.activeTabId = exports.setRootLayout = exports.selectedRootLayoutId = exports.getRootLayouts = exports.getRootLayout = exports.DEFAULT_ROOT_LAYOUT_ID = exports.TabsLayoutApp = exports.RootLayoutHost = exports.LayoutPicker = exports.unregisterGlobalOverlay = exports.registerGlobalOverlay = exports.globalOverlays = exports.notificationHostControls = exports.openLink = exports.mainContentPath = exports.isDesktop = exports.Typeahead = exports.MarkdownEditor = void 0;
17
+ exports.updateActiveTabTitle = exports.goToTabPath = exports.closeCurrentTab = exports.activeTabs = exports.activeTabId = exports.setRootLayout = exports.selectedRootLayoutId = exports.getRootLayouts = exports.getRootLayout = exports.DEFAULT_ROOT_LAYOUT_ID = exports.TabsLayoutApp = exports.RootLayoutHost = exports.LayoutPicker = exports.unregisterGlobalOverlay = exports.registerGlobalOverlay = exports.globalOverlays = exports.notificationHostControls = exports.openMention = exports.useMentionPlace = exports.MentionGroupContext = exports.MentionChip = exports.openLink = exports.mainContentPath = exports.isDesktop = exports.Typeahead = exports.MarkdownEditor = void 0;
18
18
  __exportStar(require("./components/data-grid"), exports);
19
19
  __exportStar(require("./components/inverse-lazy-list"), exports);
20
20
  var editor_1 = require("./components/markdown-editor/editor");
@@ -34,6 +34,14 @@ var host_shell_consumer_1 = require("./host-shell/host-shell-consumer");
34
34
  Object.defineProperty(exports, "openLink", { enumerable: true, get: function () { return host_shell_consumer_1.openLink; } });
35
35
  __exportStar(require("./local-network/local-network-access"), exports);
36
36
  __exportStar(require("./local-network/local-network-offer"), exports);
37
+ // Mentions for package screens: chips, and opening a mentioned record. Search stays inside the
38
+ // editor's picker; with isolated screens it becomes a host-owned overlay.
39
+ var mention_chip_1 = require("./mentions/mention-chip");
40
+ Object.defineProperty(exports, "MentionChip", { enumerable: true, get: function () { return mention_chip_1.MentionChip; } });
41
+ Object.defineProperty(exports, "MentionGroupContext", { enumerable: true, get: function () { return mention_chip_1.MentionGroupContext; } });
42
+ Object.defineProperty(exports, "useMentionPlace", { enumerable: true, get: function () { return mention_chip_1.useMentionPlace; } });
43
+ var mentions_client_1 = require("./mentions/mentions-client");
44
+ Object.defineProperty(exports, "openMention", { enumerable: true, get: function () { return mentions_client_1.openMention; } });
37
45
  var host_controls_1 = require("./notifications/host-controls");
38
46
  Object.defineProperty(exports, "notificationHostControls", { enumerable: true, get: function () { return host_controls_1.notificationHostControls; } });
39
47
  __exportStar(require("./operator-console/operator-console"), exports);
@@ -0,0 +1,32 @@
1
+ import type { IMentionLink, IMentionPlace } from "@peers-app/peers-sdk";
2
+ /**
3
+ * The group of the document a mention is in. Mentions resolve there first, and the picker marks
4
+ * results from other groups. Unset, the record is looked for wherever it was last found.
5
+ */
6
+ export declare const MentionGroupContext: import("react").Context<string | undefined>;
7
+ /** Where a mention is now: still looking, found, or nowhere the user can read. */
8
+ export type MentionState = {
9
+ status: "loading";
10
+ } | {
11
+ status: "found";
12
+ place: IMentionPlace;
13
+ } | {
14
+ status: "missing";
15
+ };
16
+ /**
17
+ * Resolve a mention for rendering, again whenever System Mentions reports a change. The last
18
+ * answer stays while a newer one loads.
19
+ *
20
+ * @param link - The mention.
21
+ * @param groupId - The document's group.
22
+ */
23
+ export declare function useMentionPlace(link: {
24
+ kind: string;
25
+ id: string;
26
+ }, groupId?: string): MentionState;
27
+ /**
28
+ * A mention as it reads in text: the record's icon and live title, struck through when it's
29
+ * done. Clicking opens it (or asks which, when it's in more than one place). A mention the user
30
+ * can't read shows its label as plain text.
31
+ */
32
+ export declare function MentionChip(props: IMentionLink): import("react/jsx-runtime").JSX.Element;