@peers-app/peers-ui 0.33.7 → 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.
- package/dist/components/markdown-editor/editor.d.ts +22 -8
- package/dist/components/markdown-editor/editor.js +5 -4
- package/dist/components/markdown-editor/mention-preview-card.d.ts +13 -0
- package/dist/components/markdown-editor/mention-preview-card.js +30 -0
- package/dist/components/markdown-editor/mentions-plugin.d.ts +36 -2
- package/dist/components/markdown-editor/mentions-plugin.js +129 -34
- package/dist/components/markdown-editor/selection-effects-plugin.d.ts +18 -0
- package/dist/components/markdown-editor/selection-effects-plugin.js +49 -0
- package/dist/mentions/mention-chip.d.ts +3 -2
- package/dist/mentions/mention-chip.js +5 -4
- package/dist/theme.css +151 -6
- package/dist/ui-router/routes-loader.js +46 -27
- package/dist/ui-router/runnable-version.js +2 -1
- package/package.json +3 -3
|
@@ -1,14 +1,25 @@
|
|
|
1
|
-
import { type Observable } from "@peers-app/peers-sdk";
|
|
1
|
+
import { type IMentionLink, type Observable } from "@peers-app/peers-sdk";
|
|
2
2
|
import React from "react";
|
|
3
3
|
import { type IToolbarControl } from "./toolbar";
|
|
4
4
|
/**
|
|
5
|
-
* Hooks
|
|
6
|
-
* (return true to handle one; skipped while the mention picker is open)
|
|
7
|
-
*
|
|
5
|
+
* Hooks for working with the editor imperatively. The caller sets `onKeyDown`, which sees keys
|
|
6
|
+
* first (return true to handle one; skipped while the mention picker is open). The editor sets
|
|
7
|
+
* the rest once it's mounted, so the caller can focus it and work with the selection.
|
|
8
8
|
*/
|
|
9
9
|
export interface IEditorEffects {
|
|
10
10
|
onKeyDown?: (e: React.KeyboardEvent) => boolean | undefined;
|
|
11
|
+
/** Focus the editor, caret at the end. Set by the editor. */
|
|
11
12
|
focus?: () => void;
|
|
13
|
+
/**
|
|
14
|
+
* The selected text, as plain text; empty when nothing is selected. After the editor loses
|
|
15
|
+
* focus (a click on the caller's button), it's the selection it had. Set by the editor.
|
|
16
|
+
*/
|
|
17
|
+
getSelectedText?: () => string;
|
|
18
|
+
/**
|
|
19
|
+
* Replace the selected text with a mention chip, such as a link to a note made from it.
|
|
20
|
+
* Returns false, changing nothing, when nothing is selected. Set by the editor.
|
|
21
|
+
*/
|
|
22
|
+
replaceSelectionWithMention?: (link: IMentionLink) => boolean;
|
|
12
23
|
}
|
|
13
24
|
/** What {@link MarkdownEditor} takes. */
|
|
14
25
|
export interface IMarkdownEditorProps {
|
|
@@ -24,7 +35,10 @@ export interface IMarkdownEditorProps {
|
|
|
24
35
|
hideToolbar?: boolean;
|
|
25
36
|
/** Scroll inside the editor past this height. */
|
|
26
37
|
maxHeight?: string | number;
|
|
27
|
-
/**
|
|
38
|
+
/**
|
|
39
|
+
* The mention picker (`@` or `<`); on unless false. Mentions already in the text show as chips
|
|
40
|
+
* either way.
|
|
41
|
+
*/
|
|
28
42
|
mentions?: boolean;
|
|
29
43
|
/**
|
|
30
44
|
* The group the text belongs to. Its records come first in the picker, results from other
|
|
@@ -34,8 +48,8 @@ export interface IMarkdownEditorProps {
|
|
|
34
48
|
groupId?: string;
|
|
35
49
|
}
|
|
36
50
|
/**
|
|
37
|
-
* A rich-text editor whose value is markdown: lists and checklists, links, and mentions (`@`
|
|
38
|
-
* finds people and records in every group
|
|
39
|
-
* title). Edits are written back to `value`.
|
|
51
|
+
* A rich-text editor whose value is markdown: lists and checklists, links, and mentions (`@` or
|
|
52
|
+
* `<` finds people and records in every group, and a pasted id becomes its record's chip; a
|
|
53
|
+
* mention shows as a chip with the record's live title). Edits are written back to `value`.
|
|
40
54
|
*/
|
|
41
55
|
export declare function MarkdownEditor(props: IMarkdownEditorProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -63,6 +63,7 @@ const mention_node_1 = require("./mention-node");
|
|
|
63
63
|
const mentions_plugin_1 = require("./mentions-plugin");
|
|
64
64
|
const move_line_plugin_1 = require("./move-line-plugin");
|
|
65
65
|
const select_line_boundary_plugin_1 = require("./select-line-boundary-plugin");
|
|
66
|
+
const selection_effects_plugin_1 = require("./selection-effects-plugin");
|
|
66
67
|
const theme_1 = __importDefault(require("./theme"));
|
|
67
68
|
const toolbar_1 = require("./toolbar");
|
|
68
69
|
const editorConfig = {
|
|
@@ -86,9 +87,9 @@ const editorConfig = {
|
|
|
86
87
|
theme: theme_1.default,
|
|
87
88
|
};
|
|
88
89
|
/**
|
|
89
|
-
* A rich-text editor whose value is markdown: lists and checklists, links, and mentions (`@`
|
|
90
|
-
* finds people and records in every group
|
|
91
|
-
* title). Edits are written back to `value`.
|
|
90
|
+
* A rich-text editor whose value is markdown: lists and checklists, links, and mentions (`@` or
|
|
91
|
+
* `<` finds people and records in every group, and a pasted id becomes its record's chip; a
|
|
92
|
+
* mention shows as a chip with the record's live title). Edits are written back to `value`.
|
|
92
93
|
*/
|
|
93
94
|
function MarkdownEditor(props) {
|
|
94
95
|
const { effects } = props;
|
|
@@ -116,7 +117,7 @@ function MarkdownEditor(props) {
|
|
|
116
117
|
}
|
|
117
118
|
};
|
|
118
119
|
}
|
|
119
|
-
return ((0, jsx_runtime_1.jsx)(mention_chip_1.MentionGroupContext.Provider, { value: props.groupId, children: (0, jsx_runtime_1.jsx)(LexicalComposer_1.LexicalComposer, { initialConfig: { ...editorConfig }, children: (0, jsx_runtime_1.jsxs)("div", { className: "editor-container", children: [props.hideToolbar ? null : (0, jsx_runtime_1.jsx)(toolbar_1.ToolbarPlugin, { topRightControls: props.topRightControls }), (0, jsx_runtime_1.jsxs)("div", { className: "editor-inner", ref: editorRef, style: { maxHeight: props.maxHeight, overflowY: "auto" }, children: [(0, jsx_runtime_1.jsx)(LexicalRichTextPlugin_1.RichTextPlugin, { contentEditable: (0, jsx_runtime_1.jsx)(LexicalContentEditable_1.ContentEditable, { className: "editor-input p-2" }), placeholder: null, ErrorBoundary: LexicalErrorBoundary_1.LexicalErrorBoundary }), (0, jsx_runtime_1.jsx)(LexicalHistoryPlugin_1.HistoryPlugin, {}), props.autoFocus && (0, jsx_runtime_1.jsx)(LexicalAutoFocusPlugin_1.AutoFocusPlugin, { defaultSelection: "rootEnd" }), (0, jsx_runtime_1.jsx)(LexicalListPlugin_1.ListPlugin, {}), props.mentions !== false && ((0, jsx_runtime_1.jsx)(mentions_plugin_1.MentionsPlugin, { mentionsOpen: mentionsOpen, groupId: props.groupId })), (0, jsx_runtime_1.jsx)(autolink_plugin_1.LexicalAutoLinkPlugin, {}), (0, jsx_runtime_1.jsx)(markdown_plugin_1.MarkdownPlugin, { markdownObs: props.value }), (0, jsx_runtime_1.jsx)(LexicalMarkdownShortcutPlugin_1.MarkdownShortcutPlugin, { transformers: markdown_plugin_1.customMarkdownTransformers }), (0, jsx_runtime_1.jsx)(LexicalCheckListPlugin_1.CheckListPlugin, {}), (0, jsx_runtime_1.jsx)(LexicalTabIndentationPlugin_1.TabIndentationPlugin, {}), (0, jsx_runtime_1.jsx)(move_line_plugin_1.MoveLineWithAltArrowsPlugin, { mentionsOpen: mentionsOpen }), (0, jsx_runtime_1.jsx)(select_line_boundary_plugin_1.SelectToLineBoundaryPlugin, {}), (0, jsx_runtime_1.jsx)(OnKeyDownPlugin, { effects: props.effects, mentionsOpen: mentionsOpen })] })] }) }) }));
|
|
120
|
+
return ((0, jsx_runtime_1.jsx)(mention_chip_1.MentionGroupContext.Provider, { value: props.groupId, children: (0, jsx_runtime_1.jsx)(LexicalComposer_1.LexicalComposer, { initialConfig: { ...editorConfig }, children: (0, jsx_runtime_1.jsxs)("div", { className: "editor-container", children: [props.hideToolbar ? null : (0, jsx_runtime_1.jsx)(toolbar_1.ToolbarPlugin, { topRightControls: props.topRightControls }), (0, jsx_runtime_1.jsxs)("div", { className: "editor-inner", ref: editorRef, style: { maxHeight: props.maxHeight, overflowY: "auto" }, children: [(0, jsx_runtime_1.jsx)(LexicalRichTextPlugin_1.RichTextPlugin, { contentEditable: (0, jsx_runtime_1.jsx)(LexicalContentEditable_1.ContentEditable, { className: "editor-input p-2" }), placeholder: null, ErrorBoundary: LexicalErrorBoundary_1.LexicalErrorBoundary }), (0, jsx_runtime_1.jsx)(LexicalHistoryPlugin_1.HistoryPlugin, {}), props.autoFocus && (0, jsx_runtime_1.jsx)(LexicalAutoFocusPlugin_1.AutoFocusPlugin, { defaultSelection: "rootEnd" }), (0, jsx_runtime_1.jsx)(LexicalListPlugin_1.ListPlugin, {}), props.mentions !== false && ((0, jsx_runtime_1.jsx)(mentions_plugin_1.MentionsPlugin, { mentionsOpen: mentionsOpen, groupId: props.groupId })), (0, jsx_runtime_1.jsx)(autolink_plugin_1.LexicalAutoLinkPlugin, {}), (0, jsx_runtime_1.jsx)(markdown_plugin_1.MarkdownPlugin, { markdownObs: props.value }), (0, jsx_runtime_1.jsx)(LexicalMarkdownShortcutPlugin_1.MarkdownShortcutPlugin, { transformers: markdown_plugin_1.customMarkdownTransformers }), (0, jsx_runtime_1.jsx)(LexicalCheckListPlugin_1.CheckListPlugin, {}), (0, jsx_runtime_1.jsx)(LexicalTabIndentationPlugin_1.TabIndentationPlugin, {}), (0, jsx_runtime_1.jsx)(move_line_plugin_1.MoveLineWithAltArrowsPlugin, { mentionsOpen: mentionsOpen }), (0, jsx_runtime_1.jsx)(select_line_boundary_plugin_1.SelectToLineBoundaryPlugin, {}), (0, jsx_runtime_1.jsx)(OnKeyDownPlugin, { effects: props.effects, mentionsOpen: mentionsOpen }), effects ? (0, jsx_runtime_1.jsx)(selection_effects_plugin_1.SelectionEffectsPlugin, { effects: effects }) : null] })] }) }) }));
|
|
120
121
|
}
|
|
121
122
|
const OnKeyDownPlugin = (props) => {
|
|
122
123
|
const [editor] = (0, LexicalComposerContext_1.useLexicalComposerContext)();
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { IMentionSearchResult } from "@peers-app/peers-sdk";
|
|
2
|
+
/**
|
|
3
|
+
* The picker's card for the highlighted result, so the user can tell similar titles apart: what
|
|
4
|
+
* it is, its title and status, its group, and the start of its text when its source declares a
|
|
5
|
+
* preview field. For a pasted id nothing has, it says so.
|
|
6
|
+
*
|
|
7
|
+
* @param props.result - The highlighted result.
|
|
8
|
+
* @param props.showPackage - Name its package: another package's results share its kind.
|
|
9
|
+
*/
|
|
10
|
+
export declare function MentionPreviewCard({ result, showPackage, }: {
|
|
11
|
+
result: IMentionSearchResult;
|
|
12
|
+
showPackage: boolean;
|
|
13
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MentionPreviewCard = MentionPreviewCard;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
/**
|
|
6
|
+
* The picker's card for the highlighted result, so the user can tell similar titles apart: what
|
|
7
|
+
* it is, its title and status, its group, and the start of its text when its source declares a
|
|
8
|
+
* preview field. For a pasted id nothing has, it says so.
|
|
9
|
+
*
|
|
10
|
+
* @param props.result - The highlighted result.
|
|
11
|
+
* @param props.showPackage - Name its package: another package's results share its kind.
|
|
12
|
+
*/
|
|
13
|
+
function MentionPreviewCard({ result, showPackage, }) {
|
|
14
|
+
// A pasted id that matched nothing is offered with no places.
|
|
15
|
+
const unknown = result.places === 0;
|
|
16
|
+
const what = [
|
|
17
|
+
unknown ? "Nothing has this id" : result.kindLabel,
|
|
18
|
+
showPackage ? result.packageName : undefined,
|
|
19
|
+
]
|
|
20
|
+
.filter(Boolean)
|
|
21
|
+
.join(" · ");
|
|
22
|
+
const where = [
|
|
23
|
+
result.status,
|
|
24
|
+
result.groupName,
|
|
25
|
+
result.places > 1 ? `${result.places} places` : "",
|
|
26
|
+
]
|
|
27
|
+
.filter(Boolean)
|
|
28
|
+
.join(" · ");
|
|
29
|
+
return ((0, jsx_runtime_1.jsxs)("div", { className: "peers-mention-preview", "aria-live": "polite", children: [(0, jsx_runtime_1.jsxs)("div", { className: "peers-mention-preview-kind", children: [result.kind === "user" ? ((0, jsx_runtime_1.jsx)("span", { "aria-hidden": true, children: "@" })) : ((0, jsx_runtime_1.jsx)("i", { className: result.iconClassName ?? "bi bi-link-45deg", "aria-hidden": true })), (0, jsx_runtime_1.jsx)("span", { children: what })] }), (0, jsx_runtime_1.jsx)("div", { className: `peers-mention-preview-title${result.done ? " peers-mention-done" : ""}`, children: result.title || result.kindLabel }), where ? (0, jsx_runtime_1.jsx)("div", { className: "peers-mention-preview-where", children: where }) : null, result.preview ? (0, jsx_runtime_1.jsx)("p", { className: "peers-mention-preview-text", children: result.preview }) : null, unknown ? ((0, jsx_runtime_1.jsx)("p", { className: "peers-mention-preview-text", children: "It's linked by id, and shows as a dotted chip until a record with this id turns up in a group you're in." })) : null] }));
|
|
30
|
+
}
|
|
@@ -1,12 +1,46 @@
|
|
|
1
1
|
import { type IMentionSearchResult, type Observable } from "@peers-app/peers-sdk";
|
|
2
|
+
/**
|
|
3
|
+
* What the user typed after `@` or `<`: words, and a kind when it starts with `kind:`.
|
|
4
|
+
*
|
|
5
|
+
* @param query - The text from the trigger on, such as `@task:garden`.
|
|
6
|
+
*/
|
|
7
|
+
export declare function parseQuery(query: string): {
|
|
8
|
+
text: string;
|
|
9
|
+
kinds?: string[];
|
|
10
|
+
};
|
|
11
|
+
/** A search's answer, with the query it answers, so an older one is never taken for a newer. */
|
|
12
|
+
interface Found {
|
|
13
|
+
query: string | null;
|
|
14
|
+
results: IMentionSearchResult[];
|
|
15
|
+
docGroup?: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* What the picker offers for a query, and whether one result should be taken without asking.
|
|
19
|
+
*
|
|
20
|
+
* - Words: the results, as they are.
|
|
21
|
+
* - A pasted id (`@<id>` or `<<id>`), once its search has answered: the one record with that id,
|
|
22
|
+
* taken at once; nothing found, a link to whatever has the id, taken at once; several records
|
|
23
|
+
* (the same id in two kinds), offered to pick from. Before the answer, nothing.
|
|
24
|
+
*
|
|
25
|
+
* @param query - The text from the trigger on, or null when the picker is closed.
|
|
26
|
+
* @param found - The latest search answer.
|
|
27
|
+
* @param declined - A query the user undid an automatic pick for: offered, not taken again.
|
|
28
|
+
*/
|
|
29
|
+
export declare function pickerOptions(query: string | null, found: Found, declined?: string | null): {
|
|
30
|
+
results: IMentionSearchResult[];
|
|
31
|
+
autoPick?: IMentionSearchResult;
|
|
32
|
+
};
|
|
2
33
|
/** The kinds that more than one package answers for among these results. */
|
|
3
34
|
export declare function sharedKinds(results: IMentionSearchResult[]): Set<string>;
|
|
4
35
|
/**
|
|
5
|
-
* The
|
|
6
|
-
*
|
|
36
|
+
* The mention picker, opened by `@` or `<`: people first, then records from every group the user
|
|
37
|
+
* is in, through System Mentions, with a preview of the highlighted one. Picking one inserts a
|
|
38
|
+
* mention chip labeled with the record's title. A pasted id becomes a chip at once: the record's,
|
|
39
|
+
* or a dotted `?` chip for an id that matches nothing.
|
|
7
40
|
*/
|
|
8
41
|
export declare function MentionsPlugin(props: {
|
|
9
42
|
mentionsOpen?: Observable<boolean>;
|
|
10
43
|
/** The document's group; its records come first, and results from other groups are marked. */
|
|
11
44
|
groupId?: string;
|
|
12
45
|
}): JSX.Element | null;
|
|
46
|
+
export {};
|
|
@@ -33,6 +33,8 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.parseQuery = parseQuery;
|
|
37
|
+
exports.pickerOptions = pickerOptions;
|
|
36
38
|
exports.sharedKinds = sharedKinds;
|
|
37
39
|
exports.MentionsPlugin = MentionsPlugin;
|
|
38
40
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
@@ -44,6 +46,7 @@ const react_1 = require("react");
|
|
|
44
46
|
const ReactDOM = __importStar(require("react-dom"));
|
|
45
47
|
const mentions_client_1 = require("../../mentions/mentions-client");
|
|
46
48
|
const mention_node_1 = require("./mention-node");
|
|
49
|
+
const mention_preview_card_1 = require("./mention-preview-card");
|
|
47
50
|
const PUNCTUATION = "\\.,\\+\\*\\?\\$\\@\\|#{}\\(\\)\\^\\-\\[\\]\\\\/!%'\"~=<>_:;";
|
|
48
51
|
const NAME = `\\b[A-Z][^\\s${PUNCTUATION}]`;
|
|
49
52
|
const DocumentMentionsRegex = {
|
|
@@ -51,8 +54,9 @@ const DocumentMentionsRegex = {
|
|
|
51
54
|
PUNCTUATION,
|
|
52
55
|
};
|
|
53
56
|
const PUNC = DocumentMentionsRegex.PUNCTUATION;
|
|
54
|
-
// `@`
|
|
55
|
-
|
|
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
|
|
@@ -93,9 +97,13 @@ const AtSignMentionsRegexAliasRegex = new RegExp("(^|\\s|\\()(" +
|
|
|
93
97
|
const SUGGESTION_LIST_LENGTH_LIMIT = 10;
|
|
94
98
|
/** How long typing pauses before a search. */
|
|
95
99
|
const SEARCH_DEBOUNCE_MS = 120;
|
|
96
|
-
/**
|
|
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
|
+
*/
|
|
97
105
|
function parseQuery(query) {
|
|
98
|
-
const typed = query.replace(
|
|
106
|
+
const typed = query.replace(/^[@<]/, "");
|
|
99
107
|
const colon = typed.indexOf(":");
|
|
100
108
|
const kind = colon > 0 ? typed.slice(0, colon).toLowerCase() : "";
|
|
101
109
|
if ((0, peers_sdk_1.isMentionKind)(kind))
|
|
@@ -107,12 +115,10 @@ function parseQuery(query) {
|
|
|
107
115
|
* so a slow answer never overwrites a newer one.
|
|
108
116
|
*/
|
|
109
117
|
function useMentionSearch(query, groupId) {
|
|
110
|
-
const [found, setFound] = (0, react_1.useState)({
|
|
111
|
-
results: [],
|
|
112
|
-
});
|
|
118
|
+
const [found, setFound] = (0, react_1.useState)({ query: null, results: [] });
|
|
113
119
|
(0, react_1.useEffect)(() => {
|
|
114
120
|
if (!query) {
|
|
115
|
-
setFound({ results: [] });
|
|
121
|
+
setFound({ query, results: [] });
|
|
116
122
|
return;
|
|
117
123
|
}
|
|
118
124
|
let live = true;
|
|
@@ -125,11 +131,12 @@ function useMentionSearch(query, groupId) {
|
|
|
125
131
|
limit: SUGGESTION_LIST_LENGTH_LIMIT,
|
|
126
132
|
});
|
|
127
133
|
if (live)
|
|
128
|
-
setFound({ results, docGroup });
|
|
134
|
+
setFound({ query, results, docGroup });
|
|
129
135
|
})().catch((error) => {
|
|
130
136
|
console.warn("[mentions] search failed", error);
|
|
137
|
+
// A failed search isn't an answer that nothing has this id.
|
|
131
138
|
if (live)
|
|
132
|
-
setFound({ results: [] });
|
|
139
|
+
setFound({ query: null, results: [] });
|
|
133
140
|
});
|
|
134
141
|
}, SEARCH_DEBOUNCE_MS);
|
|
135
142
|
return () => {
|
|
@@ -139,6 +146,47 @@ function useMentionSearch(query, groupId) {
|
|
|
139
146
|
}, [query, groupId]);
|
|
140
147
|
return found;
|
|
141
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] };
|
|
189
|
+
}
|
|
142
190
|
function checkForAtSignMentions(text, minMatchLength) {
|
|
143
191
|
let match = AtSignMentionsRegex.exec(text);
|
|
144
192
|
if (match === null) {
|
|
@@ -186,8 +234,8 @@ function sharedKinds(results) {
|
|
|
186
234
|
return new Set([...packages].filter(([, ids]) => ids.size > 1).map(([kind]) => kind));
|
|
187
235
|
}
|
|
188
236
|
/**
|
|
189
|
-
*
|
|
190
|
-
* group when not the document's
|
|
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.
|
|
191
239
|
*/
|
|
192
240
|
function details(option, docGroup) {
|
|
193
241
|
const { result } = option;
|
|
@@ -196,7 +244,6 @@ function details(option, docGroup) {
|
|
|
196
244
|
option.showPackage ? result.packageName : undefined,
|
|
197
245
|
result.status,
|
|
198
246
|
result.groupId && result.groupId !== docGroup ? result.groupName : undefined,
|
|
199
|
-
result.places > 1 ? `${result.places} places` : undefined,
|
|
200
247
|
]
|
|
201
248
|
.filter(Boolean)
|
|
202
249
|
.join(" · ");
|
|
@@ -205,17 +252,47 @@ function MentionsTypeaheadMenuItem({ index, isSelected, onClick, onMouseEnter, o
|
|
|
205
252
|
const { result } = option;
|
|
206
253
|
const otherGroup = !!result.groupId && result.groupId !== docGroup;
|
|
207
254
|
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: [
|
|
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;
|
|
209
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;
|
|
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;
|
|
210
269
|
/**
|
|
211
|
-
*
|
|
212
|
-
*
|
|
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.
|
|
213
286
|
*/
|
|
214
287
|
function MentionsPlugin(props) {
|
|
215
288
|
const [editor] = (0, LexicalComposerContext_1.useLexicalComposerContext)();
|
|
216
289
|
const [queryString, setQueryString] = (0, react_1.useState)(null);
|
|
217
|
-
const
|
|
290
|
+
const found = useMentionSearch(queryString, props.groupId);
|
|
291
|
+
const { docGroup } = found;
|
|
218
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]);
|
|
219
296
|
if (props.mentionsOpen) {
|
|
220
297
|
const finalMentionsOpen = _mentionsOpen() && results.length > 0;
|
|
221
298
|
if (props.mentionsOpen() !== finalMentionsOpen) {
|
|
@@ -232,11 +309,14 @@ function MentionsPlugin(props) {
|
|
|
232
309
|
}, [results]);
|
|
233
310
|
const onSelectOption = (0, react_1.useCallback)((selectedOption, nodeToReplace, closeMenu) => {
|
|
234
311
|
editor.update(() => {
|
|
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;
|
|
316
|
+
}
|
|
235
317
|
const { kind, id, title, kindLabel } = selectedOption.result;
|
|
236
318
|
const mentionNode = (0, mention_node_1.$createMentionNode)({ kind, id, label: title || kindLabel });
|
|
237
|
-
|
|
238
|
-
nodeToReplace.replace(mentionNode);
|
|
239
|
-
}
|
|
319
|
+
nodeToReplace.replace(mentionNode);
|
|
240
320
|
mentionNode.selectNext(); // Move cursor to the position after the mention
|
|
241
321
|
const selection = (0, lexical_1.$getSelection)();
|
|
242
322
|
if (selection !== null) {
|
|
@@ -252,22 +332,37 @@ function MentionsPlugin(props) {
|
|
|
252
332
|
}
|
|
253
333
|
return getPossibleQueryMatch(text);
|
|
254
334
|
}, [checkForSlashTriggerMatch, editor]);
|
|
255
|
-
return ((0, jsx_runtime_1.jsx)(LexicalTypeaheadMenuPlugin_1.LexicalTypeaheadMenuPlugin, { onQueryChange:
|
|
256
|
-
|
|
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)) {
|
|
257
343
|
return null;
|
|
258
344
|
}
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
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}`));
|
|
265
354
|
}
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
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);
|
|
272
367
|
} }));
|
|
273
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
|
+
}
|
|
@@ -26,7 +26,8 @@ export declare function useMentionPlace(link: {
|
|
|
26
26
|
}, groupId?: string): MentionState;
|
|
27
27
|
/**
|
|
28
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
|
|
30
|
-
* can
|
|
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.
|
|
31
32
|
*/
|
|
32
33
|
export declare function MentionChip(props: IMentionLink): import("react/jsx-runtime").JSX.Element;
|
|
@@ -44,15 +44,16 @@ function useMentionPlace(link, groupId) {
|
|
|
44
44
|
}
|
|
45
45
|
/**
|
|
46
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
|
|
48
|
-
* can
|
|
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.
|
|
49
50
|
*/
|
|
50
51
|
function MentionChip(props) {
|
|
51
52
|
const { kind, id, label } = props;
|
|
52
53
|
const groupId = (0, react_1.useContext)(exports.MentionGroupContext);
|
|
53
54
|
const state = useMentionPlace({ kind, id }, groupId);
|
|
54
55
|
if (state.status === "missing") {
|
|
55
|
-
return ((0, jsx_runtime_1.
|
|
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] }));
|
|
56
57
|
}
|
|
57
58
|
const place = state.status === "found" ? state.place : undefined;
|
|
58
59
|
const title = place?.title || label;
|
|
@@ -71,5 +72,5 @@ function MentionChip(props) {
|
|
|
71
72
|
e.preventDefault();
|
|
72
73
|
open();
|
|
73
74
|
}
|
|
74
|
-
}, children: [kind === "user" ? ("@") : ((0, jsx_runtime_1.jsx)("i", { className: `${place?.iconClassName ?? "bi bi-link-45deg"} peers-mention-icon` })), title] }));
|
|
75
|
+
}, children: [(place?.kind ?? kind) === "user" ? ("@") : ((0, jsx_runtime_1.jsx)("i", { className: `${place?.iconClassName ?? "bi bi-link-45deg"} peers-mention-icon` })), title] }));
|
|
75
76
|
}
|
package/dist/theme.css
CHANGED
|
@@ -164,23 +164,168 @@
|
|
|
164
164
|
text-decoration: line-through;
|
|
165
165
|
}
|
|
166
166
|
|
|
167
|
-
/* A mention the user can
|
|
167
|
+
/* A mention that resolves nowhere the user can read: a dotted chip with a "?" and its label. */
|
|
168
168
|
.peers-mention.peers-mention-missing {
|
|
169
169
|
background: none;
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
170
|
+
border: 1px dotted var(--bs-secondary-color);
|
|
171
|
+
color: var(--bs-secondary-color);
|
|
172
|
+
cursor: default;
|
|
173
|
+
padding: 0 4px;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/* ─── The mention picker ───────────────────────────────────────────────
|
|
177
|
+
The list of results at the caret (above it in the window's lower half), and a
|
|
178
|
+
card beside the list for the highlighted result. On a narrow screen the card
|
|
179
|
+
sits under the list. */
|
|
180
|
+
|
|
181
|
+
.peers-mention-menu {
|
|
182
|
+
--peers-mention-menu-bg: var(--peers-surface-bg, var(--bs-tertiary-bg));
|
|
183
|
+
--peers-mention-menu-border: var(--peers-surface-border, var(--bs-border-color));
|
|
184
|
+
font-size: 14px;
|
|
185
|
+
line-height: 1.35;
|
|
186
|
+
position: relative;
|
|
187
|
+
width: 300px;
|
|
188
|
+
z-index: 1000;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
.peers-mention-menu.is-above {
|
|
192
|
+
bottom: 100%;
|
|
193
|
+
margin-bottom: 30px;
|
|
194
|
+
position: absolute;
|
|
173
195
|
}
|
|
174
196
|
|
|
175
|
-
.
|
|
197
|
+
.peers-mention-menu-list,
|
|
198
|
+
.peers-mention-preview {
|
|
199
|
+
background-color: var(--peers-mention-menu-bg);
|
|
200
|
+
border: 1px solid var(--peers-mention-menu-border);
|
|
201
|
+
border-radius: 8px;
|
|
202
|
+
box-shadow:
|
|
203
|
+
0 8px 24px rgba(0, 0, 0, 0.18),
|
|
204
|
+
0 1px 3px rgba(0, 0, 0, 0.1);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
.peers-mention-menu-list {
|
|
208
|
+
list-style: none;
|
|
209
|
+
margin: 0;
|
|
210
|
+
max-height: 320px;
|
|
211
|
+
overflow-y: auto;
|
|
212
|
+
padding: 4px;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
.peers-mention-menu-item {
|
|
216
|
+
align-items: flex-start;
|
|
217
|
+
border-radius: 6px;
|
|
218
|
+
cursor: pointer;
|
|
219
|
+
display: flex;
|
|
220
|
+
gap: 8px;
|
|
221
|
+
padding: 6px 8px;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
.peers-mention-menu-item.is-selected {
|
|
225
|
+
background-color: rgba(var(--bs-link-color-rgb), 0.14);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
.peers-mention-menu-icon {
|
|
229
|
+
color: var(--bs-secondary-color);
|
|
230
|
+
flex: 0 0 16px;
|
|
231
|
+
text-align: center;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
.peers-mention-menu-text {
|
|
176
235
|
display: flex;
|
|
177
236
|
flex-direction: column;
|
|
178
237
|
min-width: 0;
|
|
179
238
|
}
|
|
180
239
|
|
|
181
|
-
.
|
|
240
|
+
.peers-mention-menu-title {
|
|
241
|
+
color: var(--bs-body-color);
|
|
242
|
+
overflow: hidden;
|
|
243
|
+
text-overflow: ellipsis;
|
|
244
|
+
white-space: nowrap;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
.peers-mention-menu-detail {
|
|
248
|
+
color: var(--bs-secondary-color);
|
|
249
|
+
font-size: 12px;
|
|
250
|
+
overflow: hidden;
|
|
251
|
+
text-overflow: ellipsis;
|
|
252
|
+
white-space: nowrap;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/* Beside the list, top edges level (bottom edges, when the menu opens above the caret). */
|
|
256
|
+
.peers-mention-preview {
|
|
257
|
+
left: calc(100% + 8px);
|
|
258
|
+
padding: 10px 12px;
|
|
259
|
+
position: absolute;
|
|
260
|
+
top: 0;
|
|
261
|
+
width: 300px;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
.peers-mention-menu.is-above .peers-mention-preview {
|
|
265
|
+
bottom: 0;
|
|
266
|
+
top: auto;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
.peers-mention-menu.is-preview-left .peers-mention-preview {
|
|
270
|
+
left: auto;
|
|
271
|
+
right: calc(100% + 8px);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/* Room on neither side: under the list, as on a phone. */
|
|
275
|
+
.peers-mention-menu.is-preview-below .peers-mention-preview {
|
|
276
|
+
margin-top: 6px;
|
|
277
|
+
position: static;
|
|
278
|
+
width: auto;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
.peers-mention-preview-kind {
|
|
282
|
+
align-items: center;
|
|
182
283
|
color: var(--bs-secondary-color);
|
|
284
|
+
display: flex;
|
|
183
285
|
font-size: 12px;
|
|
286
|
+
gap: 6px;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
.peers-mention-preview-title {
|
|
290
|
+
color: var(--bs-body-color);
|
|
291
|
+
font-weight: 600;
|
|
292
|
+
margin-top: 4px;
|
|
293
|
+
overflow-wrap: anywhere;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
.peers-mention-preview-where {
|
|
297
|
+
color: var(--bs-secondary-color);
|
|
298
|
+
font-size: 12px;
|
|
299
|
+
margin-top: 2px;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
.peers-mention-preview-text {
|
|
303
|
+
-webkit-box-orient: vertical;
|
|
304
|
+
-webkit-line-clamp: 5;
|
|
305
|
+
color: var(--bs-body-color);
|
|
306
|
+
display: -webkit-box;
|
|
307
|
+
font-size: 13px;
|
|
308
|
+
margin: 8px 0 0;
|
|
309
|
+
opacity: 0.85;
|
|
310
|
+
overflow: hidden;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
@media (max-width: 640px) {
|
|
314
|
+
.peers-mention-menu {
|
|
315
|
+
width: min(300px, calc(100vw - 24px));
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
.peers-mention-preview,
|
|
319
|
+
.peers-mention-menu.is-above .peers-mention-preview,
|
|
320
|
+
.peers-mention-menu.is-preview-left .peers-mention-preview {
|
|
321
|
+
margin-top: 6px;
|
|
322
|
+
position: static;
|
|
323
|
+
width: auto;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
.peers-mention-preview-text {
|
|
327
|
+
-webkit-line-clamp: 3;
|
|
328
|
+
}
|
|
184
329
|
}
|
|
185
330
|
|
|
186
331
|
.peers-mention-chooser {
|
|
@@ -40,6 +40,47 @@ async function recheckPackage(packageId) {
|
|
|
40
40
|
}
|
|
41
41
|
reloadPackage(packageId);
|
|
42
42
|
}
|
|
43
|
+
const refreshing = {};
|
|
44
|
+
/**
|
|
45
|
+
* Bring one package's entry up to date after its Packages row changed. The list keeps what
|
|
46
|
+
* {@link loadAllRoutes} would list now (not disabled, with a selected version), so a package
|
|
47
|
+
* installed while the app is open appears once its version is activated, and its routes load
|
|
48
|
+
* then. Its routes bundle still runs only when `resolveRunnableVersion` allows it. Refreshes of
|
|
49
|
+
* one package run one at a time, each from the stored row, so a slow one can't overwrite a newer.
|
|
50
|
+
*/
|
|
51
|
+
function refreshPackage(packageId) {
|
|
52
|
+
const next = (refreshing[packageId] ?? Promise.resolve()).then(async () => {
|
|
53
|
+
try {
|
|
54
|
+
const pkg = await (0, peers_sdk_1.Packages)().get(packageId);
|
|
55
|
+
const listed = !!pkg && !pkg.disabled && !!pkg.activePackageVersionId;
|
|
56
|
+
const entry = pkg && listed ? await enrichWithPvAppNavs(pkg) : undefined;
|
|
57
|
+
const _allPackages = (0, exports.allPackages)();
|
|
58
|
+
const idx = _allPackages.findIndex((p) => p.packageId === packageId);
|
|
59
|
+
if (entry) {
|
|
60
|
+
if (idx >= 0)
|
|
61
|
+
_allPackages[idx] = entry;
|
|
62
|
+
else
|
|
63
|
+
_allPackages.push(entry);
|
|
64
|
+
subscribeToPrefs(packageId);
|
|
65
|
+
}
|
|
66
|
+
else if (idx >= 0) {
|
|
67
|
+
_allPackages.splice(idx, 1);
|
|
68
|
+
}
|
|
69
|
+
(0, exports.allPackages)([..._allPackages]);
|
|
70
|
+
if (!entry)
|
|
71
|
+
return;
|
|
72
|
+
if (packageId in routeLoadingPromises)
|
|
73
|
+
reloadPackage(packageId);
|
|
74
|
+
else
|
|
75
|
+
await loadRoutesBundle(entry);
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
console.warn(`Couldn't refresh the app links of package ${packageId}`, error);
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
refreshing[packageId] = next;
|
|
82
|
+
return next;
|
|
83
|
+
}
|
|
43
84
|
/**
|
|
44
85
|
* Enrich an IPackage with appNavs from the device's active PackageVersion record.
|
|
45
86
|
*/
|
|
@@ -62,33 +103,10 @@ const loadAllRoutes = async () => {
|
|
|
62
103
|
for (const pkg of enriched) {
|
|
63
104
|
subscribeToPrefs(pkg.packageId);
|
|
64
105
|
}
|
|
65
|
-
(0, peers_sdk_1.Packages)().dataChanged.subscribe(async (evt) => {
|
|
66
|
-
const enrichedPkg = await enrichWithPvAppNavs(evt.dataObject);
|
|
67
|
-
const _allPackages = (0, exports.allPackages)();
|
|
68
|
-
if (evt.op === "insert") {
|
|
69
|
-
_allPackages.push(enrichedPkg);
|
|
70
|
-
subscribeToPrefs(evt.dataObject.packageId);
|
|
71
|
-
}
|
|
72
|
-
else if (evt.op === "delete") {
|
|
73
|
-
const idx = _allPackages.findIndex((p) => p.packageId === evt.dataObject.packageId);
|
|
74
|
-
if (idx >= 0) {
|
|
75
|
-
_allPackages.splice(idx, 1);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
else {
|
|
79
|
-
const idx = _allPackages.findIndex((p) => p.packageId === evt.dataObject.packageId);
|
|
80
|
-
if (idx >= 0) {
|
|
81
|
-
_allPackages[idx] = enrichedPkg;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
(0, exports.allPackages)([..._allPackages]);
|
|
85
|
-
});
|
|
86
106
|
(0, peers_sdk_1.Packages)().dataChanged.subscribe((evt) => {
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
return;
|
|
91
|
-
reloadPackage(pkg.packageId);
|
|
107
|
+
const packageId = evt.dataObject?.packageId;
|
|
108
|
+
if (packageId)
|
|
109
|
+
void refreshPackage(packageId);
|
|
92
110
|
});
|
|
93
111
|
// A promotion changes only the selected version's row (dev to beta or stable).
|
|
94
112
|
(0, runnable_version_1.onSelectedPackageVersionChanged)((packageId) => void recheckPackage(packageId));
|
|
@@ -144,7 +162,8 @@ function loadRoutesBundle(pkg, forceRefresh) {
|
|
|
144
162
|
}
|
|
145
163
|
const reloadPackage = (0, peers_sdk_1.debounceByArgs)(async (packageId) => {
|
|
146
164
|
const pkg = await (0, peers_sdk_1.Packages)().get(packageId);
|
|
147
|
-
|
|
165
|
+
// A refresh queued before the package was disabled must not run its routes afterwards.
|
|
166
|
+
if (pkg && !pkg.disabled) {
|
|
148
167
|
await loadRoutesBundle(pkg, true);
|
|
149
168
|
}
|
|
150
169
|
}, 200);
|
|
@@ -22,7 +22,8 @@ async function resolveRunnableVersion(pkg) {
|
|
|
22
22
|
try {
|
|
23
23
|
const dataContext = await (0, peers_sdk_1.getDefaultDataContext)();
|
|
24
24
|
const stored = await (0, peers_sdk_1.Packages)(dataContext).get(pkg.packageId);
|
|
25
|
-
|
|
25
|
+
// The package may have been disabled since the caller read its row.
|
|
26
|
+
if (!stored || stored.disabled)
|
|
26
27
|
return undefined;
|
|
27
28
|
let devicePvId;
|
|
28
29
|
try {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@peers-app/peers-ui",
|
|
3
|
-
"version": "0.33.
|
|
3
|
+
"version": "0.33.8",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/peers-app/peers-ui.git"
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"lint:fix": "biome check --write ."
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
|
-
"@peers-app/peers-sdk": "^0.33.
|
|
39
|
+
"@peers-app/peers-sdk": "^0.33.8",
|
|
40
40
|
"bootstrap": "^5.3.3",
|
|
41
41
|
"react": "^18.0.0",
|
|
42
42
|
"react-dom": "^18.0.0"
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"@babel/preset-react": "^7.24.1",
|
|
48
48
|
"@babel/preset-typescript": "^7.27.1",
|
|
49
49
|
"@biomejs/biome": "2.3.11",
|
|
50
|
-
"@peers-app/peers-sdk": "0.33.
|
|
50
|
+
"@peers-app/peers-sdk": "0.33.8",
|
|
51
51
|
"@testing-library/dom": "^10.4.0",
|
|
52
52
|
"@testing-library/jest-dom": "^6.6.3",
|
|
53
53
|
"@testing-library/react": "^16.3.0",
|