@peers-app/peers-ui 0.33.6 → 0.33.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/markdown-editor/editor.d.ts +25 -2
- package/dist/components/markdown-editor/editor.js +7 -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/mentions-plugin.d.ts +9 -4
- package/dist/components/markdown-editor/mentions-plugin.js +102 -93
- 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 +32 -0
- package/dist/mentions/mention-chip.js +75 -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 +79 -0
- package/dist/ui-router/open-in-group.d.ts +17 -0
- package/dist/ui-router/open-in-group.js +81 -0
- package/package.json +4 -4
|
@@ -1,18 +1,41 @@
|
|
|
1
1
|
import { 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 a caller fills in to work with the editor imperatively: `onKeyDown` sees keys first
|
|
6
|
+
* (return true to handle one; skipped while the mention picker is open), and the editor sets
|
|
7
|
+
* `focus` so the caller can focus it.
|
|
8
|
+
*/
|
|
5
9
|
export interface IEditorEffects {
|
|
6
10
|
onKeyDown?: (e: React.KeyboardEvent) => boolean | undefined;
|
|
7
11
|
focus?: () => void;
|
|
8
12
|
}
|
|
13
|
+
/** What {@link MarkdownEditor} takes. */
|
|
9
14
|
export interface IMarkdownEditorProps {
|
|
15
|
+
/** The text, as markdown: loaded into the editor, and written back as the user edits. */
|
|
10
16
|
value: Observable<string>;
|
|
17
|
+
/** Key handling and focus; see {@link IEditorEffects}. */
|
|
11
18
|
effects?: IEditorEffects;
|
|
19
|
+
/** Buttons at the right end of the toolbar. */
|
|
12
20
|
topRightControls?: IToolbarControl[];
|
|
21
|
+
/** Focus the editor, caret at the end, when it mounts. */
|
|
13
22
|
autoFocus?: boolean;
|
|
23
|
+
/** Leave out the formatting toolbar. */
|
|
14
24
|
hideToolbar?: boolean;
|
|
25
|
+
/** Scroll inside the editor past this height. */
|
|
15
26
|
maxHeight?: string | number;
|
|
16
|
-
|
|
27
|
+
/** The `@` picker; on unless false. Mentions already in the text show as chips either way. */
|
|
28
|
+
mentions?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* The group the text belongs to. Its records come first in the picker, results from other
|
|
31
|
+
* groups are marked, and mentions resolve there first. Unset, the picker treats the active
|
|
32
|
+
* group as the document's, and mentions resolve wherever they were last found.
|
|
33
|
+
*/
|
|
34
|
+
groupId?: string;
|
|
17
35
|
}
|
|
36
|
+
/**
|
|
37
|
+
* A rich-text editor whose value is markdown: lists and checklists, links, and mentions (`@`
|
|
38
|
+
* finds people and records in every group; a mention shows as a chip with the record's live
|
|
39
|
+
* title). Edits are written back to `value`.
|
|
40
|
+
*/
|
|
18
41
|
export declare function MarkdownEditor(props: IMarkdownEditorProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -56,7 +56,7 @@ 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");
|
|
@@ -85,6 +85,11 @@ const editorConfig = {
|
|
|
85
85
|
// The editor theme
|
|
86
86
|
theme: theme_1.default,
|
|
87
87
|
};
|
|
88
|
+
/**
|
|
89
|
+
* A rich-text editor whose value is markdown: lists and checklists, links, and mentions (`@`
|
|
90
|
+
* finds people and records in every group; a mention shows as a chip with the record's live
|
|
91
|
+
* title). Edits are written back to `value`.
|
|
92
|
+
*/
|
|
88
93
|
function MarkdownEditor(props) {
|
|
89
94
|
const { effects } = props;
|
|
90
95
|
const editorRef = react_1.default.useRef(null);
|
|
@@ -111,8 +116,7 @@ function MarkdownEditor(props) {
|
|
|
111
116
|
}
|
|
112
117
|
};
|
|
113
118
|
}
|
|
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 })] })] }) }));
|
|
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 })] })] }) }) }));
|
|
116
120
|
}
|
|
117
121
|
const OnKeyDownPlugin = (props) => {
|
|
118
122
|
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) {
|
|
@@ -1,7 +1,12 @@
|
|
|
1
|
-
import { type Observable } from "@peers-app/peers-sdk";
|
|
2
|
-
|
|
3
|
-
export declare
|
|
1
|
+
import { type IMentionSearchResult, type Observable } from "@peers-app/peers-sdk";
|
|
2
|
+
/** The kinds that more than one package answers for among these results. */
|
|
3
|
+
export declare function sharedKinds(results: IMentionSearchResult[]): Set<string>;
|
|
4
|
+
/**
|
|
5
|
+
* The `@` picker: people first, then records from every group the user is in, through System
|
|
6
|
+
* Mentions. Picking one inserts a mention chip labeled with the record's title.
|
|
7
|
+
*/
|
|
4
8
|
export declare function MentionsPlugin(props: {
|
|
5
|
-
mentionConfigs?: IMentionConfig[];
|
|
6
9
|
mentionsOpen?: Observable<boolean>;
|
|
10
|
+
/** The document's group; its records come first, and results from other groups are marked. */
|
|
11
|
+
groupId?: string;
|
|
7
12
|
}): JSX.Element | null;
|