@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
@@ -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,33 @@
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 that
30
+ * resolves nowhere the user can read (deleted, in a group they're not in, or an id nothing has)
31
+ * is a dotted chip with a `?` and the label it was written with; it opens nothing.
32
+ */
33
+ export declare function MentionChip(props: IMentionLink): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MentionGroupContext = void 0;
4
+ exports.useMentionPlace = useMentionPlace;
5
+ exports.MentionChip = MentionChip;
6
+ const jsx_runtime_1 = require("react/jsx-runtime");
7
+ const react_1 = require("react");
8
+ const use_observable_1 = require("../hooks/use-observable");
9
+ const mentions_client_1 = require("./mentions-client");
10
+ /**
11
+ * The group of the document a mention is in. Mentions resolve there first, and the picker marks
12
+ * results from other groups. Unset, the record is looked for wherever it was last found.
13
+ */
14
+ exports.MentionGroupContext = (0, react_1.createContext)(undefined);
15
+ /**
16
+ * Resolve a mention for rendering, again whenever System Mentions reports a change. The last
17
+ * answer stays while a newer one loads.
18
+ *
19
+ * @param link - The mention.
20
+ * @param groupId - The document's group.
21
+ */
22
+ function useMentionPlace(link, groupId) {
23
+ const [revision] = (0, use_observable_1.useObservable)(mentions_client_1.mentionsRevision);
24
+ const { kind, id } = link;
25
+ // A chip remounted with its answer cached (the editor reloading its text) shows it at once.
26
+ const [state, setState] = (0, react_1.useState)(() => {
27
+ const cached = (0, mentions_client_1.cachedMentionPlace)({ kind, id }, groupId ?? "");
28
+ if (cached === undefined)
29
+ return { status: "loading" };
30
+ return cached ? { status: "found", place: cached } : { status: "missing" };
31
+ });
32
+ // `revision` re-resolves after a change; the cache was cleared when it moved.
33
+ (0, react_1.useEffect)(() => {
34
+ let live = true;
35
+ void (0, mentions_client_1.resolveMentionPlace)({ kind, id }, groupId ?? "").then((place) => {
36
+ if (live)
37
+ setState(place ? { status: "found", place } : { status: "missing" });
38
+ });
39
+ return () => {
40
+ live = false;
41
+ };
42
+ }, [kind, id, groupId, revision]);
43
+ return state;
44
+ }
45
+ /**
46
+ * A mention as it reads in text: the record's icon and live title, struck through when it's
47
+ * done. Clicking opens it (or asks which, when it's in more than one place). A mention that
48
+ * resolves nowhere the user can read (deleted, in a group they're not in, or an id nothing has)
49
+ * is a dotted chip with a `?` and the label it was written with; it opens nothing.
50
+ */
51
+ function MentionChip(props) {
52
+ const { kind, id, label } = props;
53
+ const groupId = (0, react_1.useContext)(exports.MentionGroupContext);
54
+ const state = useMentionPlace({ kind, id }, groupId);
55
+ if (state.status === "missing") {
56
+ return ((0, jsx_runtime_1.jsxs)("span", { className: "peers-mention peers-mention-missing", "data-kind": kind, "data-id": id, title: "Not found: it was deleted, it's in a group you're not in, or nothing has this id", children: [(0, jsx_runtime_1.jsx)("i", { className: "bi bi-question-lg peers-mention-icon", "aria-hidden": true }), label || id] }));
57
+ }
58
+ const place = state.status === "found" ? state.place : undefined;
59
+ const title = place?.title || label;
60
+ const open = () => void (0, mentions_client_1.openMention)({ kind, id }, groupId).catch(console.warn);
61
+ const details = place
62
+ ? [place.kindLabel, place.groupName, place.status].filter(Boolean).join(" · ")
63
+ : undefined;
64
+ return (
65
+ // biome-ignore lint/a11y/useSemanticElements: an <a> would follow peers:// or the hash router
66
+ (0, jsx_runtime_1.jsxs)("span", { role: "link", tabIndex: 0, className: `peers-mention peers-mention-${kind}${place?.done ? " peers-mention-done" : ""}`, "data-kind": kind, "data-id": id, title: details, onClick: (e) => {
67
+ e.preventDefault();
68
+ e.stopPropagation();
69
+ open();
70
+ }, onKeyDown: (e) => {
71
+ if (e.key === "Enter") {
72
+ e.preventDefault();
73
+ open();
74
+ }
75
+ }, children: [(place?.kind ?? kind) === "user" ? ("@") : ((0, jsx_runtime_1.jsx)("i", { className: `${place?.iconClassName ?? "bi bi-link-45deg"} peers-mention-icon` })), title] }));
76
+ }
@@ -0,0 +1,9 @@
1
+ import type { IMentionPlace } from "@peers-app/peers-sdk";
2
+ /**
3
+ * Ask which place to open when a mentioned record is in more than one (a copy in another group,
4
+ * or two packages with the same kind).
5
+ *
6
+ * @param places - Where the record was found.
7
+ * @returns the place picked, or `undefined` when the user closed the chooser
8
+ */
9
+ export declare function chooseMentionPlace(places: IMentionPlace[]): Promise<IMentionPlace | undefined>;
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.chooseMentionPlace = chooseMentionPlace;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const react_1 = require("react");
6
+ const client_1 = require("react-dom/client");
7
+ /**
8
+ * Ask which place to open when a mentioned record is in more than one (a copy in another group,
9
+ * or two packages with the same kind).
10
+ *
11
+ * @param places - Where the record was found.
12
+ * @returns the place picked, or `undefined` when the user closed the chooser
13
+ */
14
+ function chooseMentionPlace(places) {
15
+ return new Promise((resolve) => {
16
+ const host = document.createElement("div");
17
+ document.body.appendChild(host);
18
+ const root = (0, client_1.createRoot)(host);
19
+ const close = (place) => {
20
+ root.unmount();
21
+ host.remove();
22
+ resolve(place);
23
+ };
24
+ root.render((0, jsx_runtime_1.jsx)(MentionChooser, { places: places, onClose: close }));
25
+ });
26
+ }
27
+ function MentionChooser(props) {
28
+ const { places, onClose } = props;
29
+ const first = (0, react_1.useRef)(null);
30
+ (0, react_1.useEffect)(() => {
31
+ first.current?.focus();
32
+ // For when focus has left the chooser (a click on its text); keys inside it stop below.
33
+ const onKey = (e) => {
34
+ if (e.key === "Escape")
35
+ onClose();
36
+ };
37
+ window.addEventListener("keydown", onKey);
38
+ return () => window.removeEventListener("keydown", onKey);
39
+ }, [onClose]);
40
+ return ((0, jsx_runtime_1.jsx)("div", { className: "peers-mention-chooser", role: "dialog", "aria-modal": "true", "aria-label": "Which one?", onMouseDown: (e) => {
41
+ if (e.target === e.currentTarget)
42
+ onClose();
43
+ },
44
+ // Keys pressed in the chooser stay in it, so the screen behind doesn't act on them too
45
+ // (Tasks moves its selection on the arrow keys and closes the open task on Escape).
46
+ onKeyDown: (e) => {
47
+ e.stopPropagation();
48
+ if (e.key === "Escape")
49
+ onClose();
50
+ }, children: (0, jsx_runtime_1.jsxs)("div", { className: "peers-mention-chooser-card", children: [(0, jsx_runtime_1.jsxs)("div", { className: "peers-mention-chooser-head", children: [(0, jsx_runtime_1.jsxs)("span", { children: ["This is in ", places.length, " places. Which one?"] }), (0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn-close", "aria-label": "Close", onClick: () => onClose() })] }), (0, jsx_runtime_1.jsx)("div", { className: "list-group list-group-flush", children: places.map((place, index) => ((0, jsx_runtime_1.jsxs)("button", { ref: index === 0 ? first : undefined, type: "button", className: "list-group-item list-group-item-action", onClick: () => onClose(place), children: [(0, jsx_runtime_1.jsxs)("div", { className: place.done ? "peers-mention-done" : undefined, children: [(0, jsx_runtime_1.jsx)("i", { className: `${place.iconClassName ?? "bi bi-link-45deg"} me-1` }), place.title || place.kindLabel] }), (0, jsx_runtime_1.jsx)("small", { className: "text-body-secondary", children: [place.groupName, place.packageName, place.status].filter(Boolean).join(" · ") })] }, `${place.groupId ?? ""}:${place.packageId ?? ""}`))) })] }) }));
51
+ }
@@ -0,0 +1,47 @@
1
+ import { type IMentionPlace, type IMentionRef, type IMentionSearchResult, type IMentionsConsumer, type IMentionsSearchInput } from "@peers-app/peers-sdk";
2
+ /** Shared handle for System Mentions on the local host. */
3
+ export declare const mentionsContract: import("@peers-app/peers-sdk").IHostContractConsumer<IMentionsConsumer>;
4
+ /**
5
+ * Find records to mention: people, and records packages declare, best first.
6
+ *
7
+ * @param input - The words, optional kinds, the document's group, and a limit.
8
+ */
9
+ export declare function searchMentions(input: IMentionsSearchInput): Promise<IMentionSearchResult[]>;
10
+ /** The active group's id (the user's id for Personal). */
11
+ export declare function activeGroupId(): Promise<string>;
12
+ /**
13
+ * Moves whenever the cached places are dropped because a mentionable record may have changed;
14
+ * mounted chips resolve again.
15
+ */
16
+ export declare const mentionsRevision: import("@peers-app/peers-sdk").Observable<number>;
17
+ /**
18
+ * A mention's place if it's already cached: the place, `null` when it's known to be nowhere the
19
+ * user can read, or `undefined` when it hasn't been resolved since the last change.
20
+ *
21
+ * @param ref - The mention.
22
+ * @param groupId - The document's group, or `""` when it isn't known.
23
+ */
24
+ export declare function cachedMentionPlace(ref: IMentionRef, groupId?: string): IMentionPlace | null | undefined;
25
+ /**
26
+ * Where a mention is, for rendering it: the first place found, looking in the document's group
27
+ * first. `null` when it's nowhere the user can read. Calls made together go in one request.
28
+ *
29
+ * @param ref - The mention.
30
+ * @param groupId - The document's group, or `""` when it isn't known.
31
+ */
32
+ export declare function resolveMentionPlace(ref: IMentionRef, groupId?: string): Promise<IMentionPlace | null>;
33
+ /**
34
+ * Open a place: in its group ({@link openInGroup}), or in the current group for a record that
35
+ * opens anywhere (a person).
36
+ *
37
+ * @param place - Where the record is.
38
+ */
39
+ export declare function openMentionPlace(place: IMentionPlace): Promise<void>;
40
+ /**
41
+ * Open a mentioned record: every group is checked, and when it's in more than one place the
42
+ * user picks one. Nothing opens when it's nowhere the user can read.
43
+ *
44
+ * @param ref - The mention.
45
+ * @param groupId - The document's group.
46
+ */
47
+ export declare function openMention(ref: IMentionRef, groupId?: string): Promise<void>;