@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.
- package/dist/components/markdown-editor/editor.d.ts +40 -3
- package/dist/components/markdown-editor/editor.js +8 -3
- package/dist/components/markdown-editor/markdown-plugin.d.ts +4 -1
- package/dist/components/markdown-editor/markdown-plugin.js +32 -20
- package/dist/components/markdown-editor/mention-node.d.ts +28 -15
- package/dist/components/markdown-editor/mention-node.js +75 -129
- 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 +43 -4
- package/dist/components/markdown-editor/mentions-plugin.js +211 -107
- 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/components/markdown-with-mentions.d.ts +12 -2
- package/dist/components/markdown-with-mentions.js +110 -110
- package/dist/index.d.ts +2 -0
- package/dist/index.js +9 -1
- package/dist/mentions/mention-chip.d.ts +33 -0
- package/dist/mentions/mention-chip.js +76 -0
- package/dist/mentions/mention-chooser.d.ts +9 -0
- package/dist/mentions/mention-chooser.js +51 -0
- package/dist/mentions/mentions-client.d.ts +47 -0
- package/dist/mentions/mentions-client.js +198 -0
- package/dist/notifications/notifications-client.d.ts +3 -3
- package/dist/notifications/notifications-client.js +6 -63
- package/dist/root-layout/root-layout-host.js +2 -2
- package/dist/theme.css +224 -0
- package/dist/ui-router/open-in-group.d.ts +17 -0
- package/dist/ui-router/open-in-group.js +81 -0
- package/dist/ui-router/routes-loader.js +46 -27
- package/dist/ui-router/runnable-version.js +2 -1
- package/package.json +4 -4
|
@@ -1,18 +1,55 @@
|
|
|
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
|
-
import { type IMentionConfig } from "../../mention-configs";
|
|
4
3
|
import { type IToolbarControl } from "./toolbar";
|
|
4
|
+
/**
|
|
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
|
+
*/
|
|
5
9
|
export interface IEditorEffects {
|
|
6
10
|
onKeyDown?: (e: React.KeyboardEvent) => boolean | undefined;
|
|
11
|
+
/** Focus the editor, caret at the end. Set by the editor. */
|
|
7
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;
|
|
8
23
|
}
|
|
24
|
+
/** What {@link MarkdownEditor} takes. */
|
|
9
25
|
export interface IMarkdownEditorProps {
|
|
26
|
+
/** The text, as markdown: loaded into the editor, and written back as the user edits. */
|
|
10
27
|
value: Observable<string>;
|
|
28
|
+
/** Key handling and focus; see {@link IEditorEffects}. */
|
|
11
29
|
effects?: IEditorEffects;
|
|
30
|
+
/** Buttons at the right end of the toolbar. */
|
|
12
31
|
topRightControls?: IToolbarControl[];
|
|
32
|
+
/** Focus the editor, caret at the end, when it mounts. */
|
|
13
33
|
autoFocus?: boolean;
|
|
34
|
+
/** Leave out the formatting toolbar. */
|
|
14
35
|
hideToolbar?: boolean;
|
|
36
|
+
/** Scroll inside the editor past this height. */
|
|
15
37
|
maxHeight?: string | number;
|
|
16
|
-
|
|
38
|
+
/**
|
|
39
|
+
* The mention picker (`@` or `<`); on unless false. Mentions already in the text show as chips
|
|
40
|
+
* either way.
|
|
41
|
+
*/
|
|
42
|
+
mentions?: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* The group the text belongs to. Its records come first in the picker, results from other
|
|
45
|
+
* groups are marked, and mentions resolve there first. Unset, the picker treats the active
|
|
46
|
+
* group as the document's, and mentions resolve wherever they were last found.
|
|
47
|
+
*/
|
|
48
|
+
groupId?: string;
|
|
17
49
|
}
|
|
50
|
+
/**
|
|
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`.
|
|
54
|
+
*/
|
|
18
55
|
export declare function MarkdownEditor(props: IMarkdownEditorProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -56,13 +56,14 @@ const rich_text_1 = require("@lexical/rich-text");
|
|
|
56
56
|
const peers_sdk_1 = require("@peers-app/peers-sdk");
|
|
57
57
|
const lexical_1 = require("lexical");
|
|
58
58
|
const react_1 = __importStar(require("react"));
|
|
59
|
-
const
|
|
59
|
+
const mention_chip_1 = require("../../mentions/mention-chip");
|
|
60
60
|
const autolink_plugin_1 = require("./autolink-plugin");
|
|
61
61
|
const markdown_plugin_1 = require("./markdown-plugin");
|
|
62
62
|
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 = {
|
|
@@ -85,6 +86,11 @@ const editorConfig = {
|
|
|
85
86
|
// The editor theme
|
|
86
87
|
theme: theme_1.default,
|
|
87
88
|
};
|
|
89
|
+
/**
|
|
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`.
|
|
93
|
+
*/
|
|
88
94
|
function MarkdownEditor(props) {
|
|
89
95
|
const { effects } = props;
|
|
90
96
|
const editorRef = react_1.default.useRef(null);
|
|
@@ -111,8 +117,7 @@ function MarkdownEditor(props) {
|
|
|
111
117
|
}
|
|
112
118
|
};
|
|
113
119
|
}
|
|
114
|
-
|
|
115
|
-
return ((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, {}), _mentionConfigs.length > 0 && ((0, jsx_runtime_1.jsx)(mentions_plugin_1.MentionsPlugin, { mentionConfigs: _mentionConfigs, mentionsOpen: mentionsOpen })), (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] })] }) }) }));
|
|
116
121
|
}
|
|
117
122
|
const OnKeyDownPlugin = (props) => {
|
|
118
123
|
const [editor] = (0, LexicalComposerContext_1.useLexicalComposerContext)();
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { type Observable } from "@peers-app/peers-sdk";
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* The editor's markdown transformers: mentions (ahead of Lexical's link transformer, which would
|
|
4
|
+
* otherwise take `peers://` links) and checklists, then Lexical's own (no headings).
|
|
5
|
+
*/
|
|
3
6
|
export declare const customMarkdownTransformers: import("@lexical/markdown").Transformer[];
|
|
4
7
|
interface IProps {
|
|
5
8
|
markdownObs: Observable<string>;
|
|
@@ -96,35 +96,47 @@ const CHECK_LIST_TRANSFORMER = {
|
|
|
96
96
|
replace: listReplace("check"),
|
|
97
97
|
type: "element",
|
|
98
98
|
};
|
|
99
|
+
/** A mention, `[label](peers://<kind>/<id>)`: a chip in the editor, and the only form written. */
|
|
99
100
|
const MENTION_TRANSFORMER = {
|
|
100
101
|
type: "text-match",
|
|
101
|
-
trigger: "
|
|
102
|
+
trigger: ")",
|
|
102
103
|
dependencies: [mention_node_1.MentionNode],
|
|
103
|
-
importRegExp: (0, peers_sdk_1.
|
|
104
|
-
regExp: (0, peers_sdk_1.
|
|
105
|
-
export: (node) =>
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
104
|
+
importRegExp: (0, peers_sdk_1.mentionLinkRegex)(),
|
|
105
|
+
regExp: new RegExp(`${(0, peers_sdk_1.mentionLinkRegex)().source}$`),
|
|
106
|
+
export: (node) => ((0, mention_node_1.$isMentionNode)(node) ? (0, peers_sdk_1.formatMentionLink)(node.getLink()) : null),
|
|
107
|
+
replace: (textNode, match) => {
|
|
108
|
+
const link = (0, peers_sdk_1.parseMentionLink)(match[0]);
|
|
109
|
+
// A malformed id stays as text.
|
|
110
|
+
if (link)
|
|
111
|
+
textNode.replace((0, mention_node_1.$createMentionNode)(link));
|
|
110
112
|
},
|
|
113
|
+
};
|
|
114
|
+
/**
|
|
115
|
+
* The older form, `<$kind:Name:id>`: read as a chip, so opening a document converts it (the
|
|
116
|
+
* document is written back in the new form). One without an id stays as text.
|
|
117
|
+
*/
|
|
118
|
+
const OLD_MENTION_TRANSFORMER = {
|
|
119
|
+
type: "text-match",
|
|
120
|
+
trigger: ">",
|
|
121
|
+
dependencies: [mention_node_1.MentionNode],
|
|
122
|
+
importRegExp: (0, peers_sdk_1.mentionRegex)(),
|
|
123
|
+
regExp: new RegExp(`${(0, peers_sdk_1.mentionRegex)().source}$`),
|
|
124
|
+
export: () => null,
|
|
111
125
|
replace: (textNode, match) => {
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
name,
|
|
118
|
-
id,
|
|
119
|
-
clickable: false,
|
|
120
|
-
};
|
|
121
|
-
const node = (0, mention_node_1.$createMentionNode)(data);
|
|
122
|
-
textNode.replace(node);
|
|
126
|
+
const ref = match[4]
|
|
127
|
+
? (0, peers_sdk_1.parseMentionUrl)(`peers://${match[2].toLowerCase()}/${match[4]}`)
|
|
128
|
+
: undefined;
|
|
129
|
+
if (ref)
|
|
130
|
+
textNode.replace((0, mention_node_1.$createMentionNode)({ ...ref, label: match[3].replace(/_/g, " ") }));
|
|
123
131
|
},
|
|
124
132
|
};
|
|
125
|
-
/**
|
|
133
|
+
/**
|
|
134
|
+
* The editor's markdown transformers: mentions (ahead of Lexical's link transformer, which would
|
|
135
|
+
* otherwise take `peers://` links) and checklists, then Lexical's own (no headings).
|
|
136
|
+
*/
|
|
126
137
|
exports.customMarkdownTransformers = [
|
|
127
138
|
MENTION_TRANSFORMER,
|
|
139
|
+
OLD_MENTION_TRANSFORMER,
|
|
128
140
|
CHECK_LIST_TRANSFORMER, // This needs to be first or checklists will be treated as unordered lists
|
|
129
141
|
...markdown_1.TRANSFORMERS.filter((transformer) => {
|
|
130
142
|
const t = transformer;
|
|
@@ -1,25 +1,38 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import { type DOMConversionMap, type DOMExportOutput, type
|
|
3
|
-
/** Serialized Lexical payload for a
|
|
1
|
+
import { type IMentionLink } from "@peers-app/peers-sdk";
|
|
2
|
+
import { DecoratorNode, type DOMConversionMap, type DOMExportOutput, type LexicalNode, type NodeKey, type SerializedLexicalNode, type Spread } from "lexical";
|
|
3
|
+
/** Serialized Lexical payload for a mention node. */
|
|
4
4
|
export type SerializedMentionNode = Spread<{
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
kind: string;
|
|
6
|
+
mentionId: string;
|
|
7
|
+
label: string;
|
|
8
|
+
}, SerializedLexicalNode>;
|
|
9
|
+
/**
|
|
10
|
+
* A mention in the editor: an inline, uneditable chip with the record's live title. It's
|
|
11
|
+
* written to markdown as `[label](peers://<kind>/<id>)`, with the label it was inserted with.
|
|
12
|
+
* Backspace next to it deletes it whole; copied as text, it's its label.
|
|
13
|
+
*/
|
|
14
|
+
export declare class MentionNode extends DecoratorNode<JSX.Element> {
|
|
15
|
+
__kind: string;
|
|
16
|
+
__mentionId: string;
|
|
17
|
+
__label: string;
|
|
10
18
|
static getType(): string;
|
|
11
19
|
static clone(node: MentionNode): MentionNode;
|
|
12
20
|
static importJSON(serializedNode: SerializedMentionNode): MentionNode;
|
|
13
|
-
constructor(
|
|
21
|
+
constructor(link: IMentionLink, key?: NodeKey);
|
|
22
|
+
/** The mention: its kind, id and stored label. */
|
|
23
|
+
getLink(): IMentionLink;
|
|
14
24
|
exportJSON(): SerializedMentionNode;
|
|
15
|
-
createDOM(
|
|
25
|
+
createDOM(): HTMLElement;
|
|
26
|
+
updateDOM(): false;
|
|
27
|
+
isInline(): true;
|
|
28
|
+
/** Arrow keys move past a mention instead of selecting it first. */
|
|
29
|
+
isKeyboardSelectable(): false;
|
|
30
|
+
getTextContent(): string;
|
|
31
|
+
decorate(): JSX.Element;
|
|
16
32
|
exportDOM(): DOMExportOutput;
|
|
17
33
|
static importDOM(): DOMConversionMap | null;
|
|
18
|
-
isTextEntity(): true;
|
|
19
|
-
canInsertTextBefore(): boolean;
|
|
20
|
-
canInsertTextAfter(): boolean;
|
|
21
34
|
}
|
|
22
|
-
/** Create a
|
|
23
|
-
export declare function $createMentionNode(
|
|
35
|
+
/** Create a mention node. */
|
|
36
|
+
export declare function $createMentionNode(link: IMentionLink): MentionNode;
|
|
24
37
|
/** Return whether a Lexical node is a {@link MentionNode}. */
|
|
25
38
|
export declare function $isMentionNode(node: LexicalNode | null | undefined): node is MentionNode;
|
|
@@ -3,163 +3,109 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.MentionNode = void 0;
|
|
4
4
|
exports.$createMentionNode = $createMentionNode;
|
|
5
5
|
exports.$isMentionNode = $isMentionNode;
|
|
6
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
7
|
+
const peers_sdk_1 = require("@peers-app/peers-sdk");
|
|
6
8
|
const lexical_1 = require("lexical");
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
+
const mention_chip_1 = require("../../mentions/mention-chip");
|
|
10
|
+
/** A pasted mention: an `<a>` with a `peers://` mention URL, or the older `<span>` form. */
|
|
9
11
|
function $convertMentionElement(domNode) {
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
if (
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
};
|
|
21
|
-
const node = $createMentionNode(data);
|
|
22
|
-
return {
|
|
23
|
-
node,
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
return null;
|
|
12
|
+
const href = domNode.getAttribute("href");
|
|
13
|
+
const ref = href
|
|
14
|
+
? (0, peers_sdk_1.parseMentionUrl)(href)
|
|
15
|
+
: (0, peers_sdk_1.parseMentionUrl)(`peers://${domNode.getAttribute("data-kind") ?? ""}/${domNode.getAttribute("data-id") ?? ""}`);
|
|
16
|
+
if (!ref)
|
|
17
|
+
return null;
|
|
18
|
+
const text = domNode.textContent ?? "";
|
|
19
|
+
// The older form's span showed "@" before a person's name.
|
|
20
|
+
const label = !href && ref.kind === "user" ? text.replace(/^@/, "") : text;
|
|
21
|
+
return { node: $createMentionNode({ ...ref, label }) };
|
|
27
22
|
}
|
|
28
|
-
/**
|
|
29
|
-
|
|
30
|
-
|
|
23
|
+
/**
|
|
24
|
+
* A mention in the editor: an inline, uneditable chip with the record's live title. It's
|
|
25
|
+
* written to markdown as `[label](peers://<kind>/<id>)`, with the label it was inserted with.
|
|
26
|
+
* Backspace next to it deletes it whole; copied as text, it's its label.
|
|
27
|
+
*/
|
|
28
|
+
class MentionNode extends lexical_1.DecoratorNode {
|
|
29
|
+
__kind;
|
|
30
|
+
__mentionId;
|
|
31
|
+
__label;
|
|
31
32
|
static getType() {
|
|
32
33
|
return "mention";
|
|
33
34
|
}
|
|
34
35
|
static clone(node) {
|
|
35
|
-
return new MentionNode(node.
|
|
36
|
+
return new MentionNode(node.getLink(), node.__key);
|
|
36
37
|
}
|
|
37
38
|
static importJSON(serializedNode) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
39
|
+
return $createMentionNode({
|
|
40
|
+
kind: serializedNode.kind,
|
|
41
|
+
id: serializedNode.mentionId,
|
|
42
|
+
label: serializedNode.label,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
constructor(link, key) {
|
|
46
|
+
super(key);
|
|
47
|
+
this.__kind = link.kind;
|
|
48
|
+
this.__mentionId = link.id;
|
|
49
|
+
this.__label = link.label;
|
|
46
50
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
this.data = data;
|
|
51
|
+
/** The mention: its kind, id and stored label. */
|
|
52
|
+
getLink() {
|
|
53
|
+
const self = this.getLatest();
|
|
54
|
+
return { kind: self.__kind, id: self.__mentionId, label: self.__label };
|
|
52
55
|
}
|
|
53
56
|
exportJSON() {
|
|
54
57
|
return {
|
|
55
58
|
...super.exportJSON(),
|
|
56
59
|
type: "mention",
|
|
57
|
-
version:
|
|
58
|
-
|
|
60
|
+
version: 2,
|
|
61
|
+
kind: this.__kind,
|
|
62
|
+
mentionId: this.__mentionId,
|
|
63
|
+
label: this.__label,
|
|
59
64
|
};
|
|
60
65
|
}
|
|
61
|
-
createDOM(
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
dom.style.cursor = "pointer";
|
|
82
|
-
dom.addEventListener("click", () => {
|
|
83
|
-
if (onClick) {
|
|
84
|
-
onClick(this.data);
|
|
85
|
-
}
|
|
86
|
-
else {
|
|
87
|
-
const id = this.data.id;
|
|
88
|
-
const href = kind === "user" ? `identity/people/${id}` : `${kind}s/${id}`;
|
|
89
|
-
(0, globals_1.mainContentPath)(href);
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
if (mentionConfig && kind !== "user") {
|
|
94
|
-
const iconSpan = document.createElement("i");
|
|
95
|
-
iconSpan.className = `pe-1 ${mentionConfig.iconClass}`;
|
|
96
|
-
dom.prepend(iconSpan);
|
|
97
|
-
return dom;
|
|
98
|
-
}
|
|
99
|
-
// else if (kind === 'task') {
|
|
100
|
-
// const ckbx = document.createElement('input');
|
|
101
|
-
// ckbx.type = 'checkbox';
|
|
102
|
-
// ckbx.className = 'me-1';
|
|
103
|
-
// const taskId = this.data.id;
|
|
104
|
-
// Tasks().get(taskId).then(task => {
|
|
105
|
-
// if (!task) return;
|
|
106
|
-
// ckbx.checked = !!task.completeDT;
|
|
107
|
-
// ckbx.addEventListener('change', () => {
|
|
108
|
-
// task.completeDT = ckbx.checked ? new Date() : undefined;
|
|
109
|
-
// Tasks().update(task);
|
|
110
|
-
// });
|
|
111
|
-
// });
|
|
112
|
-
// const sub = Tasks().dataChanged.subscribe(evt => {
|
|
113
|
-
// const task = evt.dataObject as ITask;
|
|
114
|
-
// if (!task || task.taskId !== taskId) return;
|
|
115
|
-
// if (!document.body.contains(ckbx)) {
|
|
116
|
-
// sub.unsubscribe();
|
|
117
|
-
// } else {
|
|
118
|
-
// ckbx.checked = !!task.completeDT;
|
|
119
|
-
// }
|
|
120
|
-
// });
|
|
121
|
-
// dom.prepend(ckbx);
|
|
122
|
-
// }
|
|
123
|
-
return dom;
|
|
66
|
+
createDOM() {
|
|
67
|
+
const span = document.createElement("span");
|
|
68
|
+
span.className = "peers-mention-node";
|
|
69
|
+
return span;
|
|
70
|
+
}
|
|
71
|
+
updateDOM() {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
isInline() {
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
/** Arrow keys move past a mention instead of selecting it first. */
|
|
78
|
+
isKeyboardSelectable() {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
getTextContent() {
|
|
82
|
+
return this.__label;
|
|
83
|
+
}
|
|
84
|
+
decorate() {
|
|
85
|
+
return (0, jsx_runtime_1.jsx)(mention_chip_1.MentionChip, { kind: this.__kind, id: this.__mentionId, label: this.__label });
|
|
124
86
|
}
|
|
125
87
|
exportDOM() {
|
|
126
|
-
const element = document.createElement("
|
|
88
|
+
const element = document.createElement("a");
|
|
89
|
+
element.setAttribute("href", (0, peers_sdk_1.mentionUrl)({ kind: this.__kind, id: this.__mentionId }));
|
|
127
90
|
element.setAttribute("data-lexical-mention", "true");
|
|
128
|
-
element.textContent = this.
|
|
129
|
-
element.setAttribute("data-kind", this.data.kind);
|
|
130
|
-
element.setAttribute("data-id", this.data.id);
|
|
131
|
-
element.setAttribute("data-clickable", this.data.clickable === undefined ? "" : String(this.data.clickable));
|
|
91
|
+
element.textContent = this.__label;
|
|
132
92
|
return { element };
|
|
133
93
|
}
|
|
134
94
|
static importDOM() {
|
|
135
95
|
return {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
priority: 1,
|
|
143
|
-
};
|
|
144
|
-
},
|
|
96
|
+
a: (domNode) => (0, peers_sdk_1.parseMentionUrl)(domNode.getAttribute("href") ?? "")
|
|
97
|
+
? { conversion: $convertMentionElement, priority: 2 }
|
|
98
|
+
: null,
|
|
99
|
+
span: (domNode) => domNode.hasAttribute("data-lexical-mention")
|
|
100
|
+
? { conversion: $convertMentionElement, priority: 1 }
|
|
101
|
+
: null,
|
|
145
102
|
};
|
|
146
103
|
}
|
|
147
|
-
isTextEntity() {
|
|
148
|
-
return true;
|
|
149
|
-
}
|
|
150
|
-
canInsertTextBefore() {
|
|
151
|
-
return false;
|
|
152
|
-
}
|
|
153
|
-
canInsertTextAfter() {
|
|
154
|
-
return false;
|
|
155
|
-
}
|
|
156
104
|
}
|
|
157
105
|
exports.MentionNode = MentionNode;
|
|
158
|
-
/** Create a
|
|
159
|
-
function $createMentionNode(
|
|
160
|
-
|
|
161
|
-
mentionNode.setMode("segmented").toggleDirectionless();
|
|
162
|
-
return (0, lexical_1.$applyNodeReplacement)(mentionNode);
|
|
106
|
+
/** Create a mention node. */
|
|
107
|
+
function $createMentionNode(link) {
|
|
108
|
+
return (0, lexical_1.$applyNodeReplacement)(new MentionNode(link));
|
|
163
109
|
}
|
|
164
110
|
/** Return whether a Lexical node is a {@link MentionNode}. */
|
|
165
111
|
function $isMentionNode(node) {
|
|
@@ -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,7 +1,46 @@
|
|
|
1
|
-
import { type Observable } from "@peers-app/peers-sdk";
|
|
2
|
-
|
|
3
|
-
|
|
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
|
+
};
|
|
33
|
+
/** The kinds that more than one package answers for among these results. */
|
|
34
|
+
export declare function sharedKinds(results: IMentionSearchResult[]): Set<string>;
|
|
35
|
+
/**
|
|
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.
|
|
40
|
+
*/
|
|
4
41
|
export declare function MentionsPlugin(props: {
|
|
5
|
-
mentionConfigs?: IMentionConfig[];
|
|
6
42
|
mentionsOpen?: Observable<boolean>;
|
|
43
|
+
/** The document's group; its records come first, and results from other groups are marked. */
|
|
44
|
+
groupId?: string;
|
|
7
45
|
}): JSX.Element | null;
|
|
46
|
+
export {};
|