@editorjs-mentions/plugin 0.1.4
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/LICENSE +22 -0
- package/README.md +148 -0
- package/dist/index.d.mts +169 -0
- package/dist/index.d.ts +169 -0
- package/dist/index.js +958 -0
- package/dist/index.mjs +927 -0
- package/docs/mentions-example-autocomplete.png +0 -0
- package/package.json +53 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 editorjs-mentions contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
package/README.md
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
# @editorjs-mentions/plugin
|
|
2
|
+
|
|
3
|
+
[](https://github.com/pmalirz/editorjs-mentions)
|
|
4
|
+
[](https://www.npmjs.com/package/@editorjs-mentions/plugin)
|
|
5
|
+
[](https://github.com/pmalirz/editorjs-mentions/blob/main/LICENSE)
|
|
6
|
+
[](https://github.com/pmalirz/editorjs-mentions/issues)
|
|
7
|
+
[](https://www.npmjs.com/package/@editorjs/editorjs)
|
|
8
|
+
|
|
9
|
+
Mentions autocomplete plugin for Editor.js with:
|
|
10
|
+
|
|
11
|
+
- configurable trigger symbols
|
|
12
|
+
- pluggable provider API
|
|
13
|
+
- structured mention serialization (`text + entities`) for stable backend IDs
|
|
14
|
+
- mention tooltip with optional link
|
|
15
|
+
- metadata-preserving copy/paste in Editor.js
|
|
16
|
+
|
|
17
|
+

|
|
18
|
+
|
|
19
|
+
## Install
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm i @editorjs-mentions/plugin
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Quick Start
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
import { EditorJSMentions, createRestMentionProvider } from "@editorjs-mentions/plugin";
|
|
29
|
+
|
|
30
|
+
const mentions = new EditorJSMentions({
|
|
31
|
+
holder: "editor",
|
|
32
|
+
triggerSymbols: ["@"],
|
|
33
|
+
mentionRenderContext: { currentUserId: "u-1002" },
|
|
34
|
+
renderMention: ({ item, defaultText, element, context }) => {
|
|
35
|
+
const ctx = context as { currentUserId?: string } | undefined;
|
|
36
|
+
const isCurrentUser = ctx?.currentUserId === item.id;
|
|
37
|
+
element.textContent = defaultText;
|
|
38
|
+
element.style.fontWeight = isCurrentUser ? "700" : "400";
|
|
39
|
+
},
|
|
40
|
+
provider: createRestMentionProvider({
|
|
41
|
+
endpoint: "http://localhost:3001/api/mentions/users"
|
|
42
|
+
})
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
mentions.setMentionRenderContext({ currentUserId: "u-1001" });
|
|
46
|
+
|
|
47
|
+
// mentions.destroy();
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Config
|
|
51
|
+
|
|
52
|
+
- `holder: string | HTMLElement` - Editor.js holder element or id.
|
|
53
|
+
- `provider` - mention source function/object (required).
|
|
54
|
+
- `triggerSymbols?: string[]` - defaults to `["@"]`.
|
|
55
|
+
- `maxResults?: number` - defaults to `8`.
|
|
56
|
+
- `minChars?: number` - defaults to `0`.
|
|
57
|
+
- `debounceMs?: number` - defaults to `160`.
|
|
58
|
+
- `className?: string` - custom dropdown class.
|
|
59
|
+
- `onSelect?: (item) => void`.
|
|
60
|
+
- `renderItem?: (item) => string` - custom item renderer.
|
|
61
|
+
- `renderMention?: (args) => void` - customize rendered mention anchor (style/content/classes).
|
|
62
|
+
- `mentionRenderContext?: unknown` - dynamic context available in `renderMention`.
|
|
63
|
+
|
|
64
|
+
## Data Model
|
|
65
|
+
|
|
66
|
+
```ts
|
|
67
|
+
type MentionItem = {
|
|
68
|
+
id: string;
|
|
69
|
+
displayName: string;
|
|
70
|
+
description?: string;
|
|
71
|
+
image?: string;
|
|
72
|
+
link?: string;
|
|
73
|
+
};
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Save/Load with Stable IDs
|
|
77
|
+
|
|
78
|
+
Serialize editor output before sending to backend:
|
|
79
|
+
|
|
80
|
+
```ts
|
|
81
|
+
import { encodeMentionsInOutput, decodeMentionsInOutput } from "@editorjs-mentions/plugin";
|
|
82
|
+
|
|
83
|
+
const nativeOutput = await editor.save();
|
|
84
|
+
const payloadForServer = encodeMentionsInOutput(nativeOutput);
|
|
85
|
+
|
|
86
|
+
// later when loading existing content:
|
|
87
|
+
const payloadFromServer = await fetch(...).then((r) => r.json());
|
|
88
|
+
const payloadForEditor = decodeMentionsInOutput(payloadFromServer);
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Example stored paragraph:
|
|
92
|
+
|
|
93
|
+
```json
|
|
94
|
+
{
|
|
95
|
+
"type": "paragraph",
|
|
96
|
+
"data": {
|
|
97
|
+
"text": "@John Doe @Raj Patel",
|
|
98
|
+
"entities": [
|
|
99
|
+
{
|
|
100
|
+
"type": "mention",
|
|
101
|
+
"id": "u-1001",
|
|
102
|
+
"displayName": "John Doe",
|
|
103
|
+
"start": 0,
|
|
104
|
+
"end": 9,
|
|
105
|
+
"description": "Engineering",
|
|
106
|
+
"link": "https://example.local/users/u-1001"
|
|
107
|
+
}
|
|
108
|
+
]
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## Runtime Styling Updates
|
|
114
|
+
|
|
115
|
+
Use ID-based context and re-render mentions when app state changes:
|
|
116
|
+
|
|
117
|
+
```ts
|
|
118
|
+
mentions.setMentionRenderContext({ currentUserId: loggedUser.id });
|
|
119
|
+
mentions.refreshMentionRendering();
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
`renderMention` receives:
|
|
123
|
+
|
|
124
|
+
```ts
|
|
125
|
+
{
|
|
126
|
+
item: MentionItem; // full mention metadata (id, displayName, ...)
|
|
127
|
+
trigger: string; // matched trigger, e.g. "@"
|
|
128
|
+
defaultText: string; // default visible text, e.g. "@John Doe"
|
|
129
|
+
element: HTMLAnchorElement; // mention DOM element to customize
|
|
130
|
+
source: "insert" | "paste" | "refresh";
|
|
131
|
+
context?: unknown; // mentionRenderContext passed by app
|
|
132
|
+
}
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
## Clipboard Notes
|
|
136
|
+
|
|
137
|
+
- In-editor copy/paste keeps mention structure via custom clipboard payload + HTML normalization.
|
|
138
|
+
- Pasting into external apps falls back to plain text representation (for example `@John Doe`).
|
|
139
|
+
|
|
140
|
+
## Public API
|
|
141
|
+
|
|
142
|
+
- `new EditorJSMentions(config)`
|
|
143
|
+
- `destroy()`
|
|
144
|
+
- `setMentionRenderContext(context: unknown)`
|
|
145
|
+
- `refreshMentionRendering()`
|
|
146
|
+
- `createRestMentionProvider(options)`
|
|
147
|
+
- `encodeMentionsInOutput(output)`
|
|
148
|
+
- `decodeMentionsInOutput(output)`
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
/** Single mention candidate returned by provider and rendered in editor content. */
|
|
2
|
+
type MentionItem = {
|
|
3
|
+
/** Stable backend identifier used for persistence and server-side processing. */
|
|
4
|
+
id: string;
|
|
5
|
+
/** User-visible label rendered in autocomplete and mention chip text. */
|
|
6
|
+
displayName: string;
|
|
7
|
+
/** Optional secondary text displayed in dropdown and tooltip. */
|
|
8
|
+
description?: string;
|
|
9
|
+
/** Optional avatar/icon URL shown in dropdown and tooltip. */
|
|
10
|
+
image?: string;
|
|
11
|
+
/** Optional external URL shown in mention details tooltip. */
|
|
12
|
+
link?: string;
|
|
13
|
+
};
|
|
14
|
+
/** Query payload passed to mention providers during autocomplete lookup. */
|
|
15
|
+
type MentionQuery = {
|
|
16
|
+
/** Trigger symbol that started this query, e.g. "@". */
|
|
17
|
+
trigger: string;
|
|
18
|
+
/** Text typed after the trigger. */
|
|
19
|
+
query: string;
|
|
20
|
+
/** Maximum number of results requested by the plugin. */
|
|
21
|
+
limit: number;
|
|
22
|
+
};
|
|
23
|
+
/** Function-style mention provider contract. */
|
|
24
|
+
type MentionProviderFn = (query: MentionQuery) => Promise<MentionItem[]>;
|
|
25
|
+
/** Object-style mention provider contract. */
|
|
26
|
+
type MentionProviderObject = {
|
|
27
|
+
search: MentionProviderFn;
|
|
28
|
+
};
|
|
29
|
+
/** Supported mention provider shapes. */
|
|
30
|
+
type MentionProvider = MentionProviderFn | MentionProviderObject;
|
|
31
|
+
/** Origin of a mention render call. */
|
|
32
|
+
type MentionRenderSource = "insert" | "paste" | "refresh";
|
|
33
|
+
/** Parameters passed to `renderMention` customization hook. */
|
|
34
|
+
type MentionRenderArgs = {
|
|
35
|
+
/** Mention metadata associated with the rendered element. */
|
|
36
|
+
item: MentionItem;
|
|
37
|
+
/** Trigger symbol used for this mention. */
|
|
38
|
+
trigger: string;
|
|
39
|
+
/** Default display text, typically `${trigger}${displayName}`. */
|
|
40
|
+
defaultText: string;
|
|
41
|
+
/** Mention anchor element that can be styled/customized by integrator. */
|
|
42
|
+
element: HTMLAnchorElement;
|
|
43
|
+
/** Render reason, useful for conditional logic. */
|
|
44
|
+
source: MentionRenderSource;
|
|
45
|
+
/** Arbitrary app context provided through plugin config/update API. */
|
|
46
|
+
context?: unknown;
|
|
47
|
+
};
|
|
48
|
+
/** Main plugin configuration. */
|
|
49
|
+
type MentionsConfig = {
|
|
50
|
+
/** Editor.js holder element or element id. */
|
|
51
|
+
holder: string | HTMLElement;
|
|
52
|
+
/** Data source for autocomplete candidates. */
|
|
53
|
+
provider: MentionProvider;
|
|
54
|
+
/** Trigger symbols that activate mention lookup. Defaults to `["@"]`. */
|
|
55
|
+
triggerSymbols?: string[];
|
|
56
|
+
/** Maximum autocomplete results. */
|
|
57
|
+
maxResults?: number;
|
|
58
|
+
/** Minimum query length after trigger before provider call. */
|
|
59
|
+
minChars?: number;
|
|
60
|
+
/** Debounce in milliseconds for provider calls. */
|
|
61
|
+
debounceMs?: number;
|
|
62
|
+
/** Optional custom dropdown root class name. */
|
|
63
|
+
className?: string;
|
|
64
|
+
/** Callback fired when mention is selected and inserted. */
|
|
65
|
+
onSelect?: (item: MentionItem) => void;
|
|
66
|
+
/** Custom HTML renderer for dropdown rows. */
|
|
67
|
+
renderItem?: (item: MentionItem) => string;
|
|
68
|
+
/** Hook to customize mention anchor rendering/styling in editor content. */
|
|
69
|
+
renderMention?: (args: MentionRenderArgs) => void;
|
|
70
|
+
/** Mutable external context consumed by `renderMention`. */
|
|
71
|
+
mentionRenderContext?: unknown;
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* Persisted mention entity stored alongside plain text content.
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* {
|
|
78
|
+
* "type": "mention",
|
|
79
|
+
* "id": "u-1002",
|
|
80
|
+
* "displayName": "Joanna Smith",
|
|
81
|
+
* "start": 0,
|
|
82
|
+
* "end": 13,
|
|
83
|
+
* "trigger": "@",
|
|
84
|
+
* "description": "Product Management",
|
|
85
|
+
* "image": "https://example.com/avatars/u-1002.png",
|
|
86
|
+
* "link": "https://example.local/users/u-1002"
|
|
87
|
+
* }
|
|
88
|
+
*/
|
|
89
|
+
type MentionEntity = {
|
|
90
|
+
type: "mention";
|
|
91
|
+
/** Stable backend identifier. */
|
|
92
|
+
id: string;
|
|
93
|
+
/** Display name at time of serialization. */
|
|
94
|
+
displayName: string;
|
|
95
|
+
/** Start offset (inclusive) in plain text. */
|
|
96
|
+
start: number;
|
|
97
|
+
/** End offset (exclusive) in plain text. */
|
|
98
|
+
end: number;
|
|
99
|
+
/** Trigger symbol used for rendering. */
|
|
100
|
+
trigger?: string;
|
|
101
|
+
/** Optional metadata copied from mention source. */
|
|
102
|
+
description?: string;
|
|
103
|
+
image?: string;
|
|
104
|
+
link?: string;
|
|
105
|
+
};
|
|
106
|
+
/** Minimal Editor.js block shape used by serializer helpers. */
|
|
107
|
+
type EditorJSBlockLike = {
|
|
108
|
+
id?: string;
|
|
109
|
+
type: string;
|
|
110
|
+
data: Record<string, unknown>;
|
|
111
|
+
};
|
|
112
|
+
/** Minimal Editor.js output shape used by serializer helpers. */
|
|
113
|
+
type EditorJSOutputLike = {
|
|
114
|
+
time?: number;
|
|
115
|
+
version?: string;
|
|
116
|
+
blocks: EditorJSBlockLike[];
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
declare class EditorJSMentions {
|
|
120
|
+
private holder;
|
|
121
|
+
private config;
|
|
122
|
+
private provider;
|
|
123
|
+
private dropdown;
|
|
124
|
+
private debounceTimer;
|
|
125
|
+
private requestSerial;
|
|
126
|
+
private activeContext;
|
|
127
|
+
private destroyed;
|
|
128
|
+
private tooltipRoot;
|
|
129
|
+
constructor(config: MentionsConfig);
|
|
130
|
+
setMentionRenderContext(context: unknown): void;
|
|
131
|
+
refreshMentionRendering(): void;
|
|
132
|
+
destroy(): void;
|
|
133
|
+
private bind;
|
|
134
|
+
private onClick;
|
|
135
|
+
private onDocumentMouseDown;
|
|
136
|
+
private onInput;
|
|
137
|
+
private onCopy;
|
|
138
|
+
private onCut;
|
|
139
|
+
private onPaste;
|
|
140
|
+
private onKeyDown;
|
|
141
|
+
private handleCopyOrCut;
|
|
142
|
+
private evaluateAndFetch;
|
|
143
|
+
private readActiveContext;
|
|
144
|
+
private selectMention;
|
|
145
|
+
private showTooltip;
|
|
146
|
+
private hideTooltip;
|
|
147
|
+
private readMentionFromElement;
|
|
148
|
+
private applyMentionRendering;
|
|
149
|
+
private getCaretRect;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
type RestProviderOptions = {
|
|
153
|
+
endpoint: string;
|
|
154
|
+
queryParam?: string;
|
|
155
|
+
triggerParam?: string;
|
|
156
|
+
limitParam?: string;
|
|
157
|
+
fetchInit?: RequestInit;
|
|
158
|
+
mapResponse?: (json: unknown) => MentionItem[];
|
|
159
|
+
};
|
|
160
|
+
declare function createRestMentionProvider(options: RestProviderOptions): MentionProviderFn;
|
|
161
|
+
|
|
162
|
+
declare function encodeMentionsInOutput(output: EditorJSOutputLike): EditorJSOutputLike;
|
|
163
|
+
declare function decodeMentionsInOutput(output: EditorJSOutputLike): EditorJSOutputLike;
|
|
164
|
+
declare function encodeMentionsFromHtml(html: string): {
|
|
165
|
+
text: string;
|
|
166
|
+
entities: MentionEntity[];
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
export { type EditorJSBlockLike, EditorJSMentions, type EditorJSOutputLike, type MentionEntity, type MentionItem, type MentionProvider, type MentionProviderFn, type MentionProviderObject, type MentionQuery, type MentionRenderArgs, type MentionRenderSource, type MentionsConfig, createRestMentionProvider, decodeMentionsInOutput, encodeMentionsFromHtml, encodeMentionsInOutput };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
/** Single mention candidate returned by provider and rendered in editor content. */
|
|
2
|
+
type MentionItem = {
|
|
3
|
+
/** Stable backend identifier used for persistence and server-side processing. */
|
|
4
|
+
id: string;
|
|
5
|
+
/** User-visible label rendered in autocomplete and mention chip text. */
|
|
6
|
+
displayName: string;
|
|
7
|
+
/** Optional secondary text displayed in dropdown and tooltip. */
|
|
8
|
+
description?: string;
|
|
9
|
+
/** Optional avatar/icon URL shown in dropdown and tooltip. */
|
|
10
|
+
image?: string;
|
|
11
|
+
/** Optional external URL shown in mention details tooltip. */
|
|
12
|
+
link?: string;
|
|
13
|
+
};
|
|
14
|
+
/** Query payload passed to mention providers during autocomplete lookup. */
|
|
15
|
+
type MentionQuery = {
|
|
16
|
+
/** Trigger symbol that started this query, e.g. "@". */
|
|
17
|
+
trigger: string;
|
|
18
|
+
/** Text typed after the trigger. */
|
|
19
|
+
query: string;
|
|
20
|
+
/** Maximum number of results requested by the plugin. */
|
|
21
|
+
limit: number;
|
|
22
|
+
};
|
|
23
|
+
/** Function-style mention provider contract. */
|
|
24
|
+
type MentionProviderFn = (query: MentionQuery) => Promise<MentionItem[]>;
|
|
25
|
+
/** Object-style mention provider contract. */
|
|
26
|
+
type MentionProviderObject = {
|
|
27
|
+
search: MentionProviderFn;
|
|
28
|
+
};
|
|
29
|
+
/** Supported mention provider shapes. */
|
|
30
|
+
type MentionProvider = MentionProviderFn | MentionProviderObject;
|
|
31
|
+
/** Origin of a mention render call. */
|
|
32
|
+
type MentionRenderSource = "insert" | "paste" | "refresh";
|
|
33
|
+
/** Parameters passed to `renderMention` customization hook. */
|
|
34
|
+
type MentionRenderArgs = {
|
|
35
|
+
/** Mention metadata associated with the rendered element. */
|
|
36
|
+
item: MentionItem;
|
|
37
|
+
/** Trigger symbol used for this mention. */
|
|
38
|
+
trigger: string;
|
|
39
|
+
/** Default display text, typically `${trigger}${displayName}`. */
|
|
40
|
+
defaultText: string;
|
|
41
|
+
/** Mention anchor element that can be styled/customized by integrator. */
|
|
42
|
+
element: HTMLAnchorElement;
|
|
43
|
+
/** Render reason, useful for conditional logic. */
|
|
44
|
+
source: MentionRenderSource;
|
|
45
|
+
/** Arbitrary app context provided through plugin config/update API. */
|
|
46
|
+
context?: unknown;
|
|
47
|
+
};
|
|
48
|
+
/** Main plugin configuration. */
|
|
49
|
+
type MentionsConfig = {
|
|
50
|
+
/** Editor.js holder element or element id. */
|
|
51
|
+
holder: string | HTMLElement;
|
|
52
|
+
/** Data source for autocomplete candidates. */
|
|
53
|
+
provider: MentionProvider;
|
|
54
|
+
/** Trigger symbols that activate mention lookup. Defaults to `["@"]`. */
|
|
55
|
+
triggerSymbols?: string[];
|
|
56
|
+
/** Maximum autocomplete results. */
|
|
57
|
+
maxResults?: number;
|
|
58
|
+
/** Minimum query length after trigger before provider call. */
|
|
59
|
+
minChars?: number;
|
|
60
|
+
/** Debounce in milliseconds for provider calls. */
|
|
61
|
+
debounceMs?: number;
|
|
62
|
+
/** Optional custom dropdown root class name. */
|
|
63
|
+
className?: string;
|
|
64
|
+
/** Callback fired when mention is selected and inserted. */
|
|
65
|
+
onSelect?: (item: MentionItem) => void;
|
|
66
|
+
/** Custom HTML renderer for dropdown rows. */
|
|
67
|
+
renderItem?: (item: MentionItem) => string;
|
|
68
|
+
/** Hook to customize mention anchor rendering/styling in editor content. */
|
|
69
|
+
renderMention?: (args: MentionRenderArgs) => void;
|
|
70
|
+
/** Mutable external context consumed by `renderMention`. */
|
|
71
|
+
mentionRenderContext?: unknown;
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* Persisted mention entity stored alongside plain text content.
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* {
|
|
78
|
+
* "type": "mention",
|
|
79
|
+
* "id": "u-1002",
|
|
80
|
+
* "displayName": "Joanna Smith",
|
|
81
|
+
* "start": 0,
|
|
82
|
+
* "end": 13,
|
|
83
|
+
* "trigger": "@",
|
|
84
|
+
* "description": "Product Management",
|
|
85
|
+
* "image": "https://example.com/avatars/u-1002.png",
|
|
86
|
+
* "link": "https://example.local/users/u-1002"
|
|
87
|
+
* }
|
|
88
|
+
*/
|
|
89
|
+
type MentionEntity = {
|
|
90
|
+
type: "mention";
|
|
91
|
+
/** Stable backend identifier. */
|
|
92
|
+
id: string;
|
|
93
|
+
/** Display name at time of serialization. */
|
|
94
|
+
displayName: string;
|
|
95
|
+
/** Start offset (inclusive) in plain text. */
|
|
96
|
+
start: number;
|
|
97
|
+
/** End offset (exclusive) in plain text. */
|
|
98
|
+
end: number;
|
|
99
|
+
/** Trigger symbol used for rendering. */
|
|
100
|
+
trigger?: string;
|
|
101
|
+
/** Optional metadata copied from mention source. */
|
|
102
|
+
description?: string;
|
|
103
|
+
image?: string;
|
|
104
|
+
link?: string;
|
|
105
|
+
};
|
|
106
|
+
/** Minimal Editor.js block shape used by serializer helpers. */
|
|
107
|
+
type EditorJSBlockLike = {
|
|
108
|
+
id?: string;
|
|
109
|
+
type: string;
|
|
110
|
+
data: Record<string, unknown>;
|
|
111
|
+
};
|
|
112
|
+
/** Minimal Editor.js output shape used by serializer helpers. */
|
|
113
|
+
type EditorJSOutputLike = {
|
|
114
|
+
time?: number;
|
|
115
|
+
version?: string;
|
|
116
|
+
blocks: EditorJSBlockLike[];
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
declare class EditorJSMentions {
|
|
120
|
+
private holder;
|
|
121
|
+
private config;
|
|
122
|
+
private provider;
|
|
123
|
+
private dropdown;
|
|
124
|
+
private debounceTimer;
|
|
125
|
+
private requestSerial;
|
|
126
|
+
private activeContext;
|
|
127
|
+
private destroyed;
|
|
128
|
+
private tooltipRoot;
|
|
129
|
+
constructor(config: MentionsConfig);
|
|
130
|
+
setMentionRenderContext(context: unknown): void;
|
|
131
|
+
refreshMentionRendering(): void;
|
|
132
|
+
destroy(): void;
|
|
133
|
+
private bind;
|
|
134
|
+
private onClick;
|
|
135
|
+
private onDocumentMouseDown;
|
|
136
|
+
private onInput;
|
|
137
|
+
private onCopy;
|
|
138
|
+
private onCut;
|
|
139
|
+
private onPaste;
|
|
140
|
+
private onKeyDown;
|
|
141
|
+
private handleCopyOrCut;
|
|
142
|
+
private evaluateAndFetch;
|
|
143
|
+
private readActiveContext;
|
|
144
|
+
private selectMention;
|
|
145
|
+
private showTooltip;
|
|
146
|
+
private hideTooltip;
|
|
147
|
+
private readMentionFromElement;
|
|
148
|
+
private applyMentionRendering;
|
|
149
|
+
private getCaretRect;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
type RestProviderOptions = {
|
|
153
|
+
endpoint: string;
|
|
154
|
+
queryParam?: string;
|
|
155
|
+
triggerParam?: string;
|
|
156
|
+
limitParam?: string;
|
|
157
|
+
fetchInit?: RequestInit;
|
|
158
|
+
mapResponse?: (json: unknown) => MentionItem[];
|
|
159
|
+
};
|
|
160
|
+
declare function createRestMentionProvider(options: RestProviderOptions): MentionProviderFn;
|
|
161
|
+
|
|
162
|
+
declare function encodeMentionsInOutput(output: EditorJSOutputLike): EditorJSOutputLike;
|
|
163
|
+
declare function decodeMentionsInOutput(output: EditorJSOutputLike): EditorJSOutputLike;
|
|
164
|
+
declare function encodeMentionsFromHtml(html: string): {
|
|
165
|
+
text: string;
|
|
166
|
+
entities: MentionEntity[];
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
export { type EditorJSBlockLike, EditorJSMentions, type EditorJSOutputLike, type MentionEntity, type MentionItem, type MentionProvider, type MentionProviderFn, type MentionProviderObject, type MentionQuery, type MentionRenderArgs, type MentionRenderSource, type MentionsConfig, createRestMentionProvider, decodeMentionsInOutput, encodeMentionsFromHtml, encodeMentionsInOutput };
|