@tiptap/suggestion 2.0.0-beta.22 → 2.0.0-beta.220
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/README.md +6 -6
- package/dist/{tiptap-suggestion.cjs.js → index.cjs} +86 -45
- package/dist/index.cjs.map +1 -0
- package/dist/{tiptap-suggestion.esm.js → index.js} +83 -44
- package/dist/index.js.map +1 -0
- package/dist/{tiptap-suggestion.umd.js → index.umd.js} +88 -48
- package/dist/index.umd.js.map +1 -0
- package/dist/packages/suggestion/src/findSuggestionMatch.d.ts +2 -1
- package/dist/packages/suggestion/src/suggestion.d.ts +22 -13
- package/package.json +28 -11
- package/src/findSuggestionMatch.ts +24 -27
- package/src/suggestion.ts +118 -59
- package/CHANGELOG.md +0 -272
- package/LICENSE.md +0 -21
- package/dist/tiptap-suggestion.bundle.umd.min.js +0 -2
- package/dist/tiptap-suggestion.bundle.umd.min.js.map +0 -1
- package/dist/tiptap-suggestion.cjs.js.map +0 -1
- package/dist/tiptap-suggestion.esm.js.map +0 -1
- package/dist/tiptap-suggestion.umd.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
# @tiptap/
|
|
2
|
-
[](https://www.npmjs.com/package/@tiptap/suggestion)
|
|
3
|
+
[](https://npmcharts.com/compare/tiptap?minimal=true)
|
|
4
|
+
[](https://www.npmjs.com/package/@tiptap/suggestion)
|
|
5
5
|
[](https://github.com/sponsors/ueberdosis)
|
|
6
6
|
|
|
7
7
|
## Introduction
|
|
8
8
|
tiptap is a headless wrapper around [ProseMirror](https://ProseMirror.net) – a toolkit for building rich text WYSIWYG editors, which is already in use at many well-known companies such as *New York Times*, *The Guardian* or *Atlassian*.
|
|
9
9
|
|
|
10
|
-
##
|
|
10
|
+
## Official Documentation
|
|
11
11
|
Documentation can be found on the [tiptap website](https://tiptap.dev).
|
|
12
12
|
|
|
13
13
|
## License
|
|
14
|
-
tiptap is open
|
|
14
|
+
tiptap is open sourced software licensed under the [MIT license](https://github.com/ueberdosis/tiptap/blob/main/LICENSE.md).
|
|
@@ -2,37 +2,37 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var
|
|
6
|
-
var
|
|
5
|
+
var state = require('@tiptap/pm/state');
|
|
6
|
+
var view = require('@tiptap/pm/view');
|
|
7
|
+
var core = require('@tiptap/core');
|
|
7
8
|
|
|
8
9
|
function findSuggestionMatch(config) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
return null;
|
|
13
|
-
}
|
|
14
|
-
// Matching expressions used for later
|
|
15
|
-
const escapedChar = `\\${char}`;
|
|
10
|
+
var _a;
|
|
11
|
+
const { char, allowSpaces, allowedPrefixes, startOfLine, $position, } = config;
|
|
12
|
+
const escapedChar = core.escapeForRegEx(char);
|
|
16
13
|
const suffix = new RegExp(`\\s${escapedChar}$`);
|
|
17
14
|
const prefix = startOfLine ? '^' : '';
|
|
18
15
|
const regexp = allowSpaces
|
|
19
16
|
? new RegExp(`${prefix}${escapedChar}.*?(?=\\s${escapedChar}|$)`, 'gm')
|
|
20
17
|
: new RegExp(`${prefix}(?:^)?${escapedChar}[^\\s${escapedChar}]*`, 'gm');
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
18
|
+
const text = ((_a = $position.nodeBefore) === null || _a === void 0 ? void 0 : _a.isText) && $position.nodeBefore.text;
|
|
19
|
+
if (!text) {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
const textFrom = $position.pos - text.length;
|
|
24
23
|
const match = Array.from(text.matchAll(regexp)).pop();
|
|
25
24
|
if (!match || match.input === undefined || match.index === undefined) {
|
|
26
25
|
return null;
|
|
27
26
|
}
|
|
28
|
-
// JavaScript doesn't have lookbehinds
|
|
29
|
-
// or the line
|
|
27
|
+
// JavaScript doesn't have lookbehinds. This hacks a check that first character
|
|
28
|
+
// is a space or the start of the line
|
|
30
29
|
const matchPrefix = match.input.slice(Math.max(0, match.index - 1), match.index);
|
|
31
|
-
|
|
30
|
+
const matchPrefixIsAllowed = new RegExp(`^[${allowedPrefixes === null || allowedPrefixes === void 0 ? void 0 : allowedPrefixes.join('')}\0]?$`).test(matchPrefix);
|
|
31
|
+
if (allowedPrefixes !== null && !matchPrefixIsAllowed) {
|
|
32
32
|
return null;
|
|
33
33
|
}
|
|
34
34
|
// The absolute position of the match in the document
|
|
35
|
-
const from =
|
|
35
|
+
const from = textFrom + match.index;
|
|
36
36
|
let to = from + match[0].length;
|
|
37
37
|
// Edge case handling; if spaces are allowed and we're directly in between
|
|
38
38
|
// two triggers
|
|
@@ -54,14 +54,16 @@ function findSuggestionMatch(config) {
|
|
|
54
54
|
return null;
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
|
|
57
|
+
const SuggestionPluginKey = new state.PluginKey('suggestion');
|
|
58
|
+
function Suggestion({ pluginKey = SuggestionPluginKey, editor, char = '@', allowSpaces = false, allowedPrefixes = [' '], startOfLine = false, decorationTag = 'span', decorationClass = 'suggestion', command = () => null, items = () => [], render = () => ({}), allow = () => true, }) {
|
|
59
|
+
let props;
|
|
58
60
|
const renderer = render === null || render === void 0 ? void 0 : render();
|
|
59
|
-
|
|
60
|
-
key:
|
|
61
|
+
const plugin = new state.Plugin({
|
|
62
|
+
key: pluginKey,
|
|
61
63
|
view() {
|
|
62
64
|
return {
|
|
63
65
|
update: async (view, prevState) => {
|
|
64
|
-
var _a, _b, _c, _d, _e;
|
|
66
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
65
67
|
const prev = (_a = this.key) === null || _a === void 0 ? void 0 : _a.getState(prevState);
|
|
66
68
|
const next = (_b = this.key) === null || _b === void 0 ? void 0 : _b.getState(view.state);
|
|
67
69
|
// See how the state changed
|
|
@@ -76,16 +78,14 @@ function Suggestion({ editor, char = '@', allowSpaces = false, startOfLine = fal
|
|
|
76
78
|
if (!handleStart && !handleChange && !handleExit) {
|
|
77
79
|
return;
|
|
78
80
|
}
|
|
79
|
-
const state = handleExit ? prev : next;
|
|
80
|
-
const decorationNode =
|
|
81
|
-
|
|
81
|
+
const state = handleExit && !handleStart ? prev : next;
|
|
82
|
+
const decorationNode = view.dom.querySelector(`[data-decoration-id="${state.decorationId}"]`);
|
|
83
|
+
props = {
|
|
82
84
|
editor,
|
|
83
85
|
range: state.range,
|
|
84
86
|
query: state.query,
|
|
85
87
|
text: state.text,
|
|
86
|
-
items:
|
|
87
|
-
? await items(state.query)
|
|
88
|
-
: [],
|
|
88
|
+
items: [],
|
|
89
89
|
command: commandProps => {
|
|
90
90
|
command({
|
|
91
91
|
editor,
|
|
@@ -96,50 +96,89 @@ function Suggestion({ editor, char = '@', allowSpaces = false, startOfLine = fal
|
|
|
96
96
|
decorationNode,
|
|
97
97
|
// virtual node for popper.js or tippy.js
|
|
98
98
|
// this can be used for building popups without a DOM node
|
|
99
|
-
clientRect:
|
|
99
|
+
clientRect: decorationNode
|
|
100
|
+
? () => {
|
|
101
|
+
var _a;
|
|
102
|
+
// because of `items` can be asynchrounous we’ll search for the current decoration node
|
|
103
|
+
const { decorationId } = (_a = this.key) === null || _a === void 0 ? void 0 : _a.getState(editor.state); // eslint-disable-line
|
|
104
|
+
const currentDecorationNode = view.dom.querySelector(`[data-decoration-id="${decorationId}"]`);
|
|
105
|
+
return (currentDecorationNode === null || currentDecorationNode === void 0 ? void 0 : currentDecorationNode.getBoundingClientRect()) || null;
|
|
106
|
+
}
|
|
107
|
+
: null,
|
|
100
108
|
};
|
|
109
|
+
if (handleStart) {
|
|
110
|
+
(_c = renderer === null || renderer === void 0 ? void 0 : renderer.onBeforeStart) === null || _c === void 0 ? void 0 : _c.call(renderer, props);
|
|
111
|
+
}
|
|
112
|
+
if (handleChange) {
|
|
113
|
+
(_d = renderer === null || renderer === void 0 ? void 0 : renderer.onBeforeUpdate) === null || _d === void 0 ? void 0 : _d.call(renderer, props);
|
|
114
|
+
}
|
|
115
|
+
if (handleChange || handleStart) {
|
|
116
|
+
props.items = await items({
|
|
117
|
+
editor,
|
|
118
|
+
query: state.query,
|
|
119
|
+
});
|
|
120
|
+
}
|
|
101
121
|
if (handleExit) {
|
|
102
|
-
(
|
|
122
|
+
(_e = renderer === null || renderer === void 0 ? void 0 : renderer.onExit) === null || _e === void 0 ? void 0 : _e.call(renderer, props);
|
|
103
123
|
}
|
|
104
124
|
if (handleChange) {
|
|
105
|
-
(
|
|
125
|
+
(_f = renderer === null || renderer === void 0 ? void 0 : renderer.onUpdate) === null || _f === void 0 ? void 0 : _f.call(renderer, props);
|
|
106
126
|
}
|
|
107
127
|
if (handleStart) {
|
|
108
|
-
(
|
|
128
|
+
(_g = renderer === null || renderer === void 0 ? void 0 : renderer.onStart) === null || _g === void 0 ? void 0 : _g.call(renderer, props);
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
destroy: () => {
|
|
132
|
+
var _a;
|
|
133
|
+
if (!props) {
|
|
134
|
+
return;
|
|
109
135
|
}
|
|
136
|
+
(_a = renderer === null || renderer === void 0 ? void 0 : renderer.onExit) === null || _a === void 0 ? void 0 : _a.call(renderer, props);
|
|
110
137
|
},
|
|
111
138
|
};
|
|
112
139
|
},
|
|
113
140
|
state: {
|
|
114
141
|
// Initialize the plugin's internal state.
|
|
115
142
|
init() {
|
|
116
|
-
|
|
143
|
+
const state = {
|
|
117
144
|
active: false,
|
|
118
|
-
range: {
|
|
145
|
+
range: {
|
|
146
|
+
from: 0,
|
|
147
|
+
to: 0,
|
|
148
|
+
},
|
|
119
149
|
query: null,
|
|
120
150
|
text: null,
|
|
151
|
+
composing: false,
|
|
121
152
|
};
|
|
153
|
+
return state;
|
|
122
154
|
},
|
|
123
155
|
// Apply changes to the plugin state from a view transaction.
|
|
124
|
-
apply(transaction, prev) {
|
|
156
|
+
apply(transaction, prev, oldState, state) {
|
|
157
|
+
const { isEditable } = editor;
|
|
158
|
+
const { composing } = editor.view;
|
|
125
159
|
const { selection } = transaction;
|
|
160
|
+
const { empty, from } = selection;
|
|
126
161
|
const next = { ...prev };
|
|
127
|
-
|
|
128
|
-
if
|
|
162
|
+
next.composing = composing;
|
|
163
|
+
// We can only be suggesting if the view is editable, and:
|
|
164
|
+
// * there is no selection, or
|
|
165
|
+
// * a composition is active (see: https://github.com/ueberdosis/tiptap/issues/1449)
|
|
166
|
+
if (isEditable && (empty || editor.view.composing)) {
|
|
129
167
|
// Reset active state if we just left the previous suggestion range
|
|
130
|
-
if (
|
|
168
|
+
if ((from < prev.range.from || from > prev.range.to) && !composing && !prev.composing) {
|
|
131
169
|
next.active = false;
|
|
132
170
|
}
|
|
133
171
|
// Try to match against where our cursor currently is
|
|
134
172
|
const match = findSuggestionMatch({
|
|
135
173
|
char,
|
|
136
174
|
allowSpaces,
|
|
175
|
+
allowedPrefixes,
|
|
137
176
|
startOfLine,
|
|
138
177
|
$position: selection.$from,
|
|
139
178
|
});
|
|
140
|
-
const decorationId = `id_${Math.floor(Math.random() *
|
|
179
|
+
const decorationId = `id_${Math.floor(Math.random() * 0xffffffff)}`;
|
|
141
180
|
// If we found a match, update the current state to show it
|
|
142
|
-
if (match && allow({ editor, range: match.range })) {
|
|
181
|
+
if (match && allow({ editor, state, range: match.range })) {
|
|
143
182
|
next.active = true;
|
|
144
183
|
next.decorationId = prev.decorationId ? prev.decorationId : decorationId;
|
|
145
184
|
next.range = match.range;
|
|
@@ -156,7 +195,7 @@ function Suggestion({ editor, char = '@', allowSpaces = false, startOfLine = fal
|
|
|
156
195
|
// Make sure to empty the range if suggestion is inactive
|
|
157
196
|
if (!next.active) {
|
|
158
197
|
next.decorationId = null;
|
|
159
|
-
next.range = {};
|
|
198
|
+
next.range = { from: 0, to: 0 };
|
|
160
199
|
next.query = null;
|
|
161
200
|
next.text = null;
|
|
162
201
|
}
|
|
@@ -167,7 +206,7 @@ function Suggestion({ editor, char = '@', allowSpaces = false, startOfLine = fal
|
|
|
167
206
|
// Call the keydown hook if suggestion is active.
|
|
168
207
|
handleKeyDown(view, event) {
|
|
169
208
|
var _a;
|
|
170
|
-
const { active, range } =
|
|
209
|
+
const { active, range } = plugin.getState(view.state);
|
|
171
210
|
if (!active) {
|
|
172
211
|
return false;
|
|
173
212
|
}
|
|
@@ -175,12 +214,12 @@ function Suggestion({ editor, char = '@', allowSpaces = false, startOfLine = fal
|
|
|
175
214
|
},
|
|
176
215
|
// Setup decorator on the currently active suggestion.
|
|
177
216
|
decorations(state) {
|
|
178
|
-
const { active, range, decorationId } =
|
|
217
|
+
const { active, range, decorationId } = plugin.getState(state);
|
|
179
218
|
if (!active) {
|
|
180
219
|
return null;
|
|
181
220
|
}
|
|
182
|
-
return
|
|
183
|
-
|
|
221
|
+
return view.DecorationSet.create(state.doc, [
|
|
222
|
+
view.Decoration.inline(range.from, range.to, {
|
|
184
223
|
nodeName: decorationTag,
|
|
185
224
|
class: decorationClass,
|
|
186
225
|
'data-decoration-id': decorationId,
|
|
@@ -189,9 +228,11 @@ function Suggestion({ editor, char = '@', allowSpaces = false, startOfLine = fal
|
|
|
189
228
|
},
|
|
190
229
|
},
|
|
191
230
|
});
|
|
231
|
+
return plugin;
|
|
192
232
|
}
|
|
193
233
|
|
|
194
234
|
exports.Suggestion = Suggestion;
|
|
195
|
-
exports.
|
|
235
|
+
exports.SuggestionPluginKey = SuggestionPluginKey;
|
|
236
|
+
exports["default"] = Suggestion;
|
|
196
237
|
exports.findSuggestionMatch = findSuggestionMatch;
|
|
197
|
-
//# sourceMappingURL=
|
|
238
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../src/findSuggestionMatch.ts","../src/suggestion.ts"],"sourcesContent":["import { escapeForRegEx, Range } from '@tiptap/core'\nimport { ResolvedPos } from '@tiptap/pm/model'\n\nexport interface Trigger {\n char: string\n allowSpaces: boolean\n allowedPrefixes: string[] | null\n startOfLine: boolean\n $position: ResolvedPos\n}\n\nexport type SuggestionMatch = {\n range: Range\n query: string\n text: string\n} | null\n\nexport function findSuggestionMatch(config: Trigger): SuggestionMatch {\n const {\n char, allowSpaces, allowedPrefixes, startOfLine, $position,\n } = config\n\n const escapedChar = escapeForRegEx(char)\n const suffix = new RegExp(`\\\\s${escapedChar}$`)\n const prefix = startOfLine ? '^' : ''\n const regexp = allowSpaces\n ? new RegExp(`${prefix}${escapedChar}.*?(?=\\\\s${escapedChar}|$)`, 'gm')\n : new RegExp(`${prefix}(?:^)?${escapedChar}[^\\\\s${escapedChar}]*`, 'gm')\n\n const text = $position.nodeBefore?.isText && $position.nodeBefore.text\n\n if (!text) {\n return null\n }\n\n const textFrom = $position.pos - text.length\n const match = Array.from(text.matchAll(regexp)).pop()\n\n if (!match || match.input === undefined || match.index === undefined) {\n return null\n }\n\n // JavaScript doesn't have lookbehinds. This hacks a check that first character\n // is a space or the start of the line\n const matchPrefix = match.input.slice(Math.max(0, match.index - 1), match.index)\n const matchPrefixIsAllowed = new RegExp(`^[${allowedPrefixes?.join('')}\\0]?$`).test(matchPrefix)\n\n if (allowedPrefixes !== null && !matchPrefixIsAllowed) {\n return null\n }\n\n // The absolute position of the match in the document\n const from = textFrom + match.index\n let to = from + match[0].length\n\n // Edge case handling; if spaces are allowed and we're directly in between\n // two triggers\n if (allowSpaces && suffix.test(text.slice(to - 1, to + 1))) {\n match[0] += ' '\n to += 1\n }\n\n // If the $position is located within the matched substring, return that range\n if (from < $position.pos && to >= $position.pos) {\n return {\n range: {\n from,\n to,\n },\n query: match[0].slice(char.length),\n text: match[0],\n }\n }\n\n return null\n}\n","import { Editor, Range } from '@tiptap/core'\nimport { EditorState, Plugin, PluginKey } from '@tiptap/pm/state'\nimport { Decoration, DecorationSet, EditorView } from '@tiptap/pm/view'\n\nimport { findSuggestionMatch } from './findSuggestionMatch'\n\nexport interface SuggestionOptions<I = any> {\n pluginKey?: PluginKey\n editor: Editor\n char?: string\n allowSpaces?: boolean\n allowedPrefixes?: string[] | null\n startOfLine?: boolean\n decorationTag?: string\n decorationClass?: string\n command?: (props: { editor: Editor; range: Range; props: I }) => void\n items?: (props: { query: string; editor: Editor }) => I[] | Promise<I[]>\n render?: () => {\n onBeforeStart?: (props: SuggestionProps<I>) => void\n onStart?: (props: SuggestionProps<I>) => void\n onBeforeUpdate?: (props: SuggestionProps<I>) => void\n onUpdate?: (props: SuggestionProps<I>) => void\n onExit?: (props: SuggestionProps<I>) => void\n onKeyDown?: (props: SuggestionKeyDownProps) => boolean\n }\n allow?: (props: { editor: Editor; state: EditorState; range: Range }) => boolean\n}\n\nexport interface SuggestionProps<I = any> {\n editor: Editor\n range: Range\n query: string\n text: string\n items: I[]\n command: (props: I) => void\n decorationNode: Element | null\n clientRect?: (() => DOMRect | null) | null\n}\n\nexport interface SuggestionKeyDownProps {\n view: EditorView\n event: KeyboardEvent\n range: Range\n}\n\nexport const SuggestionPluginKey = new PluginKey('suggestion')\n\nexport function Suggestion<I = any>({\n pluginKey = SuggestionPluginKey,\n editor,\n char = '@',\n allowSpaces = false,\n allowedPrefixes = [' '],\n startOfLine = false,\n decorationTag = 'span',\n decorationClass = 'suggestion',\n command = () => null,\n items = () => [],\n render = () => ({}),\n allow = () => true,\n}: SuggestionOptions<I>) {\n let props: SuggestionProps<I> | undefined\n const renderer = render?.()\n\n const plugin: Plugin<any> = new Plugin({\n key: pluginKey,\n\n view() {\n return {\n update: async (view, prevState) => {\n const prev = this.key?.getState(prevState)\n const next = this.key?.getState(view.state)\n\n // See how the state changed\n const moved = prev.active && next.active && prev.range.from !== next.range.from\n const started = !prev.active && next.active\n const stopped = prev.active && !next.active\n const changed = !started && !stopped && prev.query !== next.query\n const handleStart = started || moved\n const handleChange = changed && !moved\n const handleExit = stopped || moved\n\n // Cancel when suggestion isn't active\n if (!handleStart && !handleChange && !handleExit) {\n return\n }\n\n const state = handleExit && !handleStart ? prev : next\n const decorationNode = view.dom.querySelector(\n `[data-decoration-id=\"${state.decorationId}\"]`,\n )\n\n props = {\n editor,\n range: state.range,\n query: state.query,\n text: state.text,\n items: [],\n command: commandProps => {\n command({\n editor,\n range: state.range,\n props: commandProps,\n })\n },\n decorationNode,\n // virtual node for popper.js or tippy.js\n // this can be used for building popups without a DOM node\n clientRect: decorationNode\n ? () => {\n // because of `items` can be asynchrounous we’ll search for the current decoration node\n const { decorationId } = this.key?.getState(editor.state) // eslint-disable-line\n const currentDecorationNode = view.dom.querySelector(\n `[data-decoration-id=\"${decorationId}\"]`,\n )\n\n return currentDecorationNode?.getBoundingClientRect() || null\n }\n : null,\n }\n\n if (handleStart) {\n renderer?.onBeforeStart?.(props)\n }\n\n if (handleChange) {\n renderer?.onBeforeUpdate?.(props)\n }\n\n if (handleChange || handleStart) {\n props.items = await items({\n editor,\n query: state.query,\n })\n }\n\n if (handleExit) {\n renderer?.onExit?.(props)\n }\n\n if (handleChange) {\n renderer?.onUpdate?.(props)\n }\n\n if (handleStart) {\n renderer?.onStart?.(props)\n }\n },\n\n destroy: () => {\n if (!props) {\n return\n }\n\n renderer?.onExit?.(props)\n },\n }\n },\n\n state: {\n // Initialize the plugin's internal state.\n init() {\n const state: {\n active: boolean\n range: Range\n query: null | string\n text: null | string\n composing: boolean\n decorationId?: string | null\n } = {\n active: false,\n range: {\n from: 0,\n to: 0,\n },\n query: null,\n text: null,\n composing: false,\n }\n\n return state\n },\n\n // Apply changes to the plugin state from a view transaction.\n apply(transaction, prev, oldState, state) {\n const { isEditable } = editor\n const { composing } = editor.view\n const { selection } = transaction\n const { empty, from } = selection\n const next = { ...prev }\n\n next.composing = composing\n\n // We can only be suggesting if the view is editable, and:\n // * there is no selection, or\n // * a composition is active (see: https://github.com/ueberdosis/tiptap/issues/1449)\n if (isEditable && (empty || editor.view.composing)) {\n // Reset active state if we just left the previous suggestion range\n if ((from < prev.range.from || from > prev.range.to) && !composing && !prev.composing) {\n next.active = false\n }\n\n // Try to match against where our cursor currently is\n const match = findSuggestionMatch({\n char,\n allowSpaces,\n allowedPrefixes,\n startOfLine,\n $position: selection.$from,\n })\n const decorationId = `id_${Math.floor(Math.random() * 0xffffffff)}`\n\n // If we found a match, update the current state to show it\n if (match && allow({ editor, state, range: match.range })) {\n next.active = true\n next.decorationId = prev.decorationId ? prev.decorationId : decorationId\n next.range = match.range\n next.query = match.query\n next.text = match.text\n } else {\n next.active = false\n }\n } else {\n next.active = false\n }\n\n // Make sure to empty the range if suggestion is inactive\n if (!next.active) {\n next.decorationId = null\n next.range = { from: 0, to: 0 }\n next.query = null\n next.text = null\n }\n\n return next\n },\n },\n\n props: {\n // Call the keydown hook if suggestion is active.\n handleKeyDown(view, event) {\n const { active, range } = plugin.getState(view.state)\n\n if (!active) {\n return false\n }\n\n return renderer?.onKeyDown?.({ view, event, range }) || false\n },\n\n // Setup decorator on the currently active suggestion.\n decorations(state) {\n const { active, range, decorationId } = plugin.getState(state)\n\n if (!active) {\n return null\n }\n\n return DecorationSet.create(state.doc, [\n Decoration.inline(range.from, range.to, {\n nodeName: decorationTag,\n class: decorationClass,\n 'data-decoration-id': decorationId,\n }),\n ])\n },\n },\n })\n\n return plugin\n}\n"],"names":["escapeForRegEx","PluginKey","Plugin","DecorationSet","Decoration"],"mappings":";;;;;;;;AAiBM,SAAU,mBAAmB,CAAC,MAAe,EAAA;;AACjD,IAAA,MAAM,EACJ,IAAI,EAAE,WAAW,EAAE,eAAe,EAAE,WAAW,EAAE,SAAS,GAC3D,GAAG,MAAM,CAAA;AAEV,IAAA,MAAM,WAAW,GAAGA,mBAAc,CAAC,IAAI,CAAC,CAAA;IACxC,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,CAAM,GAAA,EAAA,WAAW,CAAG,CAAA,CAAA,CAAC,CAAA;IAC/C,MAAM,MAAM,GAAG,WAAW,GAAG,GAAG,GAAG,EAAE,CAAA;IACrC,MAAM,MAAM,GAAG,WAAW;AACxB,UAAE,IAAI,MAAM,CAAC,CAAG,EAAA,MAAM,CAAG,EAAA,WAAW,CAAY,SAAA,EAAA,WAAW,CAAK,GAAA,CAAA,EAAE,IAAI,CAAC;AAC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,CAAC,KAAK,CAAC,CAAA;gBAE9D,IAAI,CAAC,MAAM,EAAE;AACX,oBAAA,OAAO,IAAI,CAAA;AACZ,iBAAA;AAED,gBAAA,OAAOC,kBAAa,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE;oBACrCC,eAAU,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,EAAE;AACtC,wBAAA,QAAQ,EAAE,aAAa;AACvB,wBAAA,KAAK,EAAE,eAAe;AACtB,wBAAA,oBAAoB,EAAE,YAAY;qBACnC,CAAC;AACH,iBAAA,CAAC,CAAA;aACH;AACF,SAAA;AACF,KAAA,CAAC,CAAA;AAEF,IAAA,OAAO,MAAM,CAAA;AACf;;;;;;;"}
|
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { DecorationSet, Decoration } from '
|
|
1
|
+
import { PluginKey, Plugin } from '@tiptap/pm/state';
|
|
2
|
+
import { DecorationSet, Decoration } from '@tiptap/pm/view';
|
|
3
|
+
import { escapeForRegEx } from '@tiptap/core';
|
|
3
4
|
|
|
4
5
|
function findSuggestionMatch(config) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
return null;
|
|
9
|
-
}
|
|
10
|
-
// Matching expressions used for later
|
|
11
|
-
const escapedChar = `\\${char}`;
|
|
6
|
+
var _a;
|
|
7
|
+
const { char, allowSpaces, allowedPrefixes, startOfLine, $position, } = config;
|
|
8
|
+
const escapedChar = escapeForRegEx(char);
|
|
12
9
|
const suffix = new RegExp(`\\s${escapedChar}$`);
|
|
13
10
|
const prefix = startOfLine ? '^' : '';
|
|
14
11
|
const regexp = allowSpaces
|
|
15
12
|
? new RegExp(`${prefix}${escapedChar}.*?(?=\\s${escapedChar}|$)`, 'gm')
|
|
16
13
|
: new RegExp(`${prefix}(?:^)?${escapedChar}[^\\s${escapedChar}]*`, 'gm');
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
const text = ((_a = $position.nodeBefore) === null || _a === void 0 ? void 0 : _a.isText) && $position.nodeBefore.text;
|
|
15
|
+
if (!text) {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
const textFrom = $position.pos - text.length;
|
|
20
19
|
const match = Array.from(text.matchAll(regexp)).pop();
|
|
21
20
|
if (!match || match.input === undefined || match.index === undefined) {
|
|
22
21
|
return null;
|
|
23
22
|
}
|
|
24
|
-
// JavaScript doesn't have lookbehinds
|
|
25
|
-
// or the line
|
|
23
|
+
// JavaScript doesn't have lookbehinds. This hacks a check that first character
|
|
24
|
+
// is a space or the start of the line
|
|
26
25
|
const matchPrefix = match.input.slice(Math.max(0, match.index - 1), match.index);
|
|
27
|
-
|
|
26
|
+
const matchPrefixIsAllowed = new RegExp(`^[${allowedPrefixes === null || allowedPrefixes === void 0 ? void 0 : allowedPrefixes.join('')}\0]?$`).test(matchPrefix);
|
|
27
|
+
if (allowedPrefixes !== null && !matchPrefixIsAllowed) {
|
|
28
28
|
return null;
|
|
29
29
|
}
|
|
30
30
|
// The absolute position of the match in the document
|
|
31
|
-
const from =
|
|
31
|
+
const from = textFrom + match.index;
|
|
32
32
|
let to = from + match[0].length;
|
|
33
33
|
// Edge case handling; if spaces are allowed and we're directly in between
|
|
34
34
|
// two triggers
|
|
@@ -50,14 +50,16 @@ function findSuggestionMatch(config) {
|
|
|
50
50
|
return null;
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
|
|
53
|
+
const SuggestionPluginKey = new PluginKey('suggestion');
|
|
54
|
+
function Suggestion({ pluginKey = SuggestionPluginKey, editor, char = '@', allowSpaces = false, allowedPrefixes = [' '], startOfLine = false, decorationTag = 'span', decorationClass = 'suggestion', command = () => null, items = () => [], render = () => ({}), allow = () => true, }) {
|
|
55
|
+
let props;
|
|
54
56
|
const renderer = render === null || render === void 0 ? void 0 : render();
|
|
55
|
-
|
|
56
|
-
key:
|
|
57
|
+
const plugin = new Plugin({
|
|
58
|
+
key: pluginKey,
|
|
57
59
|
view() {
|
|
58
60
|
return {
|
|
59
61
|
update: async (view, prevState) => {
|
|
60
|
-
var _a, _b, _c, _d, _e;
|
|
62
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
61
63
|
const prev = (_a = this.key) === null || _a === void 0 ? void 0 : _a.getState(prevState);
|
|
62
64
|
const next = (_b = this.key) === null || _b === void 0 ? void 0 : _b.getState(view.state);
|
|
63
65
|
// See how the state changed
|
|
@@ -72,16 +74,14 @@ function Suggestion({ editor, char = '@', allowSpaces = false, startOfLine = fal
|
|
|
72
74
|
if (!handleStart && !handleChange && !handleExit) {
|
|
73
75
|
return;
|
|
74
76
|
}
|
|
75
|
-
const state = handleExit ? prev : next;
|
|
76
|
-
const decorationNode =
|
|
77
|
-
|
|
77
|
+
const state = handleExit && !handleStart ? prev : next;
|
|
78
|
+
const decorationNode = view.dom.querySelector(`[data-decoration-id="${state.decorationId}"]`);
|
|
79
|
+
props = {
|
|
78
80
|
editor,
|
|
79
81
|
range: state.range,
|
|
80
82
|
query: state.query,
|
|
81
83
|
text: state.text,
|
|
82
|
-
items:
|
|
83
|
-
? await items(state.query)
|
|
84
|
-
: [],
|
|
84
|
+
items: [],
|
|
85
85
|
command: commandProps => {
|
|
86
86
|
command({
|
|
87
87
|
editor,
|
|
@@ -92,50 +92,89 @@ function Suggestion({ editor, char = '@', allowSpaces = false, startOfLine = fal
|
|
|
92
92
|
decorationNode,
|
|
93
93
|
// virtual node for popper.js or tippy.js
|
|
94
94
|
// this can be used for building popups without a DOM node
|
|
95
|
-
clientRect:
|
|
95
|
+
clientRect: decorationNode
|
|
96
|
+
? () => {
|
|
97
|
+
var _a;
|
|
98
|
+
// because of `items` can be asynchrounous we’ll search for the current decoration node
|
|
99
|
+
const { decorationId } = (_a = this.key) === null || _a === void 0 ? void 0 : _a.getState(editor.state); // eslint-disable-line
|
|
100
|
+
const currentDecorationNode = view.dom.querySelector(`[data-decoration-id="${decorationId}"]`);
|
|
101
|
+
return (currentDecorationNode === null || currentDecorationNode === void 0 ? void 0 : currentDecorationNode.getBoundingClientRect()) || null;
|
|
102
|
+
}
|
|
103
|
+
: null,
|
|
96
104
|
};
|
|
105
|
+
if (handleStart) {
|
|
106
|
+
(_c = renderer === null || renderer === void 0 ? void 0 : renderer.onBeforeStart) === null || _c === void 0 ? void 0 : _c.call(renderer, props);
|
|
107
|
+
}
|
|
108
|
+
if (handleChange) {
|
|
109
|
+
(_d = renderer === null || renderer === void 0 ? void 0 : renderer.onBeforeUpdate) === null || _d === void 0 ? void 0 : _d.call(renderer, props);
|
|
110
|
+
}
|
|
111
|
+
if (handleChange || handleStart) {
|
|
112
|
+
props.items = await items({
|
|
113
|
+
editor,
|
|
114
|
+
query: state.query,
|
|
115
|
+
});
|
|
116
|
+
}
|
|
97
117
|
if (handleExit) {
|
|
98
|
-
(
|
|
118
|
+
(_e = renderer === null || renderer === void 0 ? void 0 : renderer.onExit) === null || _e === void 0 ? void 0 : _e.call(renderer, props);
|
|
99
119
|
}
|
|
100
120
|
if (handleChange) {
|
|
101
|
-
(
|
|
121
|
+
(_f = renderer === null || renderer === void 0 ? void 0 : renderer.onUpdate) === null || _f === void 0 ? void 0 : _f.call(renderer, props);
|
|
102
122
|
}
|
|
103
123
|
if (handleStart) {
|
|
104
|
-
(
|
|
124
|
+
(_g = renderer === null || renderer === void 0 ? void 0 : renderer.onStart) === null || _g === void 0 ? void 0 : _g.call(renderer, props);
|
|
125
|
+
}
|
|
126
|
+
},
|
|
127
|
+
destroy: () => {
|
|
128
|
+
var _a;
|
|
129
|
+
if (!props) {
|
|
130
|
+
return;
|
|
105
131
|
}
|
|
132
|
+
(_a = renderer === null || renderer === void 0 ? void 0 : renderer.onExit) === null || _a === void 0 ? void 0 : _a.call(renderer, props);
|
|
106
133
|
},
|
|
107
134
|
};
|
|
108
135
|
},
|
|
109
136
|
state: {
|
|
110
137
|
// Initialize the plugin's internal state.
|
|
111
138
|
init() {
|
|
112
|
-
|
|
139
|
+
const state = {
|
|
113
140
|
active: false,
|
|
114
|
-
range: {
|
|
141
|
+
range: {
|
|
142
|
+
from: 0,
|
|
143
|
+
to: 0,
|
|
144
|
+
},
|
|
115
145
|
query: null,
|
|
116
146
|
text: null,
|
|
147
|
+
composing: false,
|
|
117
148
|
};
|
|
149
|
+
return state;
|
|
118
150
|
},
|
|
119
151
|
// Apply changes to the plugin state from a view transaction.
|
|
120
|
-
apply(transaction, prev) {
|
|
152
|
+
apply(transaction, prev, oldState, state) {
|
|
153
|
+
const { isEditable } = editor;
|
|
154
|
+
const { composing } = editor.view;
|
|
121
155
|
const { selection } = transaction;
|
|
156
|
+
const { empty, from } = selection;
|
|
122
157
|
const next = { ...prev };
|
|
123
|
-
|
|
124
|
-
if
|
|
158
|
+
next.composing = composing;
|
|
159
|
+
// We can only be suggesting if the view is editable, and:
|
|
160
|
+
// * there is no selection, or
|
|
161
|
+
// * a composition is active (see: https://github.com/ueberdosis/tiptap/issues/1449)
|
|
162
|
+
if (isEditable && (empty || editor.view.composing)) {
|
|
125
163
|
// Reset active state if we just left the previous suggestion range
|
|
126
|
-
if (
|
|
164
|
+
if ((from < prev.range.from || from > prev.range.to) && !composing && !prev.composing) {
|
|
127
165
|
next.active = false;
|
|
128
166
|
}
|
|
129
167
|
// Try to match against where our cursor currently is
|
|
130
168
|
const match = findSuggestionMatch({
|
|
131
169
|
char,
|
|
132
170
|
allowSpaces,
|
|
171
|
+
allowedPrefixes,
|
|
133
172
|
startOfLine,
|
|
134
173
|
$position: selection.$from,
|
|
135
174
|
});
|
|
136
|
-
const decorationId = `id_${Math.floor(Math.random() *
|
|
175
|
+
const decorationId = `id_${Math.floor(Math.random() * 0xffffffff)}`;
|
|
137
176
|
// If we found a match, update the current state to show it
|
|
138
|
-
if (match && allow({ editor, range: match.range })) {
|
|
177
|
+
if (match && allow({ editor, state, range: match.range })) {
|
|
139
178
|
next.active = true;
|
|
140
179
|
next.decorationId = prev.decorationId ? prev.decorationId : decorationId;
|
|
141
180
|
next.range = match.range;
|
|
@@ -152,7 +191,7 @@ function Suggestion({ editor, char = '@', allowSpaces = false, startOfLine = fal
|
|
|
152
191
|
// Make sure to empty the range if suggestion is inactive
|
|
153
192
|
if (!next.active) {
|
|
154
193
|
next.decorationId = null;
|
|
155
|
-
next.range = {};
|
|
194
|
+
next.range = { from: 0, to: 0 };
|
|
156
195
|
next.query = null;
|
|
157
196
|
next.text = null;
|
|
158
197
|
}
|
|
@@ -163,7 +202,7 @@ function Suggestion({ editor, char = '@', allowSpaces = false, startOfLine = fal
|
|
|
163
202
|
// Call the keydown hook if suggestion is active.
|
|
164
203
|
handleKeyDown(view, event) {
|
|
165
204
|
var _a;
|
|
166
|
-
const { active, range } =
|
|
205
|
+
const { active, range } = plugin.getState(view.state);
|
|
167
206
|
if (!active) {
|
|
168
207
|
return false;
|
|
169
208
|
}
|
|
@@ -171,7 +210,7 @@ function Suggestion({ editor, char = '@', allowSpaces = false, startOfLine = fal
|
|
|
171
210
|
},
|
|
172
211
|
// Setup decorator on the currently active suggestion.
|
|
173
212
|
decorations(state) {
|
|
174
|
-
const { active, range, decorationId } =
|
|
213
|
+
const { active, range, decorationId } = plugin.getState(state);
|
|
175
214
|
if (!active) {
|
|
176
215
|
return null;
|
|
177
216
|
}
|
|
@@ -185,8 +224,8 @@ function Suggestion({ editor, char = '@', allowSpaces = false, startOfLine = fal
|
|
|
185
224
|
},
|
|
186
225
|
},
|
|
187
226
|
});
|
|
227
|
+
return plugin;
|
|
188
228
|
}
|
|
189
229
|
|
|
190
|
-
export default
|
|
191
|
-
|
|
192
|
-
//# sourceMappingURL=tiptap-suggestion.esm.js.map
|
|
230
|
+
export { Suggestion, SuggestionPluginKey, Suggestion as default, findSuggestionMatch };
|
|
231
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/findSuggestionMatch.ts","../src/suggestion.ts"],"sourcesContent":["import { escapeForRegEx, Range } from '@tiptap/core'\nimport { ResolvedPos } from '@tiptap/pm/model'\n\nexport interface Trigger {\n char: string\n allowSpaces: boolean\n allowedPrefixes: string[] | null\n startOfLine: boolean\n $position: ResolvedPos\n}\n\nexport type SuggestionMatch = {\n range: Range\n query: string\n text: string\n} | null\n\nexport function findSuggestionMatch(config: Trigger): SuggestionMatch {\n const {\n char, allowSpaces, allowedPrefixes, startOfLine, $position,\n } = config\n\n const escapedChar = escapeForRegEx(char)\n const suffix = new RegExp(`\\\\s${escapedChar}$`)\n const prefix = startOfLine ? '^' : ''\n const regexp = allowSpaces\n ? new RegExp(`${prefix}${escapedChar}.*?(?=\\\\s${escapedChar}|$)`, 'gm')\n : new RegExp(`${prefix}(?:^)?${escapedChar}[^\\\\s${escapedChar}]*`, 'gm')\n\n const text = $position.nodeBefore?.isText && $position.nodeBefore.text\n\n if (!text) {\n return null\n }\n\n const textFrom = $position.pos - text.length\n const match = Array.from(text.matchAll(regexp)).pop()\n\n if (!match || match.input === undefined || match.index === undefined) {\n return null\n }\n\n // JavaScript doesn't have lookbehinds. This hacks a check that first character\n // is a space or the start of the line\n const matchPrefix = match.input.slice(Math.max(0, match.index - 1), match.index)\n const matchPrefixIsAllowed = new RegExp(`^[${allowedPrefixes?.join('')}\\0]?$`).test(matchPrefix)\n\n if (allowedPrefixes !== null && !matchPrefixIsAllowed) {\n return null\n }\n\n // The absolute position of the match in the document\n const from = textFrom + match.index\n let to = from + match[0].length\n\n // Edge case handling; if spaces are allowed and we're directly in between\n // two triggers\n if (allowSpaces && suffix.test(text.slice(to - 1, to + 1))) {\n match[0] += ' '\n to += 1\n }\n\n // If the $position is located within the matched substring, return that range\n if (from < $position.pos && to >= $position.pos) {\n return {\n range: {\n from,\n to,\n },\n query: match[0].slice(char.length),\n text: match[0],\n }\n }\n\n return null\n}\n","import { Editor, Range } from '@tiptap/core'\nimport { EditorState, Plugin, PluginKey } from '@tiptap/pm/state'\nimport { Decoration, DecorationSet, EditorView } from '@tiptap/pm/view'\n\nimport { findSuggestionMatch } from './findSuggestionMatch'\n\nexport interface SuggestionOptions<I = any> {\n pluginKey?: PluginKey\n editor: Editor\n char?: string\n allowSpaces?: boolean\n allowedPrefixes?: string[] | null\n startOfLine?: boolean\n decorationTag?: string\n decorationClass?: string\n command?: (props: { editor: Editor; range: Range; props: I }) => void\n items?: (props: { query: string; editor: Editor }) => I[] | Promise<I[]>\n render?: () => {\n onBeforeStart?: (props: SuggestionProps<I>) => void\n onStart?: (props: SuggestionProps<I>) => void\n onBeforeUpdate?: (props: SuggestionProps<I>) => void\n onUpdate?: (props: SuggestionProps<I>) => void\n onExit?: (props: SuggestionProps<I>) => void\n onKeyDown?: (props: SuggestionKeyDownProps) => boolean\n }\n allow?: (props: { editor: Editor; state: EditorState; range: Range }) => boolean\n}\n\nexport interface SuggestionProps<I = any> {\n editor: Editor\n range: Range\n query: string\n text: string\n items: I[]\n command: (props: I) => void\n decorationNode: Element | null\n clientRect?: (() => DOMRect | null) | null\n}\n\nexport interface SuggestionKeyDownProps {\n view: EditorView\n event: KeyboardEvent\n range: Range\n}\n\nexport const SuggestionPluginKey = new PluginKey('suggestion')\n\nexport function Suggestion<I = any>({\n pluginKey = SuggestionPluginKey,\n editor,\n char = '@',\n allowSpaces = false,\n allowedPrefixes = [' '],\n startOfLine = false,\n decorationTag = 'span',\n decorationClass = 'suggestion',\n command = () => null,\n items = () => [],\n render = () => ({}),\n allow = () => true,\n}: SuggestionOptions<I>) {\n let props: SuggestionProps<I> | undefined\n const renderer = render?.()\n\n const plugin: Plugin<any> = new Plugin({\n key: pluginKey,\n\n view() {\n return {\n update: async (view, prevState) => {\n const prev = this.key?.getState(prevState)\n const next = this.key?.getState(view.state)\n\n // See how the state changed\n const moved = prev.active && next.active && prev.range.from !== next.range.from\n const started = !prev.active && next.active\n const stopped = prev.active && !next.active\n const changed = !started && !stopped && prev.query !== next.query\n const handleStart = started || moved\n const handleChange = changed && !moved\n const handleExit = stopped || moved\n\n // Cancel when suggestion isn't active\n if (!handleStart && !handleChange && !handleExit) {\n return\n }\n\n const state = handleExit && !handleStart ? prev : next\n const decorationNode = view.dom.querySelector(\n `[data-decoration-id=\"${state.decorationId}\"]`,\n )\n\n props = {\n editor,\n range: state.range,\n query: state.query,\n text: state.text,\n items: [],\n command: commandProps => {\n command({\n editor,\n range: state.range,\n props: commandProps,\n })\n },\n decorationNode,\n // virtual node for popper.js or tippy.js\n // this can be used for building popups without a DOM node\n clientRect: decorationNode\n ? () => {\n // because of `items` can be asynchrounous we’ll search for the current decoration node\n const { decorationId } = this.key?.getState(editor.state) // eslint-disable-line\n const currentDecorationNode = view.dom.querySelector(\n `[data-decoration-id=\"${decorationId}\"]`,\n )\n\n return currentDecorationNode?.getBoundingClientRect() || null\n }\n : null,\n }\n\n if (handleStart) {\n renderer?.onBeforeStart?.(props)\n }\n\n if (handleChange) {\n renderer?.onBeforeUpdate?.(props)\n }\n\n if (handleChange || handleStart) {\n props.items = await items({\n editor,\n query: state.query,\n })\n }\n\n if (handleExit) {\n renderer?.onExit?.(props)\n }\n\n if (handleChange) {\n renderer?.onUpdate?.(props)\n }\n\n if (handleStart) {\n renderer?.onStart?.(props)\n }\n },\n\n destroy: () => {\n if (!props) {\n return\n }\n\n renderer?.onExit?.(props)\n },\n }\n },\n\n state: {\n // Initialize the plugin's internal state.\n init() {\n const state: {\n active: boolean\n range: Range\n query: null | string\n text: null | string\n composing: boolean\n decorationId?: string | null\n } = {\n active: false,\n range: {\n from: 0,\n to: 0,\n },\n query: null,\n text: null,\n composing: false,\n }\n\n return state\n },\n\n // Apply changes to the plugin state from a view transaction.\n apply(transaction, prev, oldState, state) {\n const { isEditable } = editor\n const { composing } = editor.view\n const { selection } = transaction\n const { empty, from } = selection\n const next = { ...prev }\n\n next.composing = composing\n\n // We can only be suggesting if the view is editable, and:\n // * there is no selection, or\n // * a composition is active (see: https://github.com/ueberdosis/tiptap/issues/1449)\n if (isEditable && (empty || editor.view.composing)) {\n // Reset active state if we just left the previous suggestion range\n if ((from < prev.range.from || from > prev.range.to) && !composing && !prev.composing) {\n next.active = false\n }\n\n // Try to match against where our cursor currently is\n const match = findSuggestionMatch({\n char,\n allowSpaces,\n allowedPrefixes,\n startOfLine,\n $position: selection.$from,\n })\n const decorationId = `id_${Math.floor(Math.random() * 0xffffffff)}`\n\n // If we found a match, update the current state to show it\n if (match && allow({ editor, state, range: match.range })) {\n next.active = true\n next.decorationId = prev.decorationId ? prev.decorationId : decorationId\n next.range = match.range\n next.query = match.query\n next.text = match.text\n } else {\n next.active = false\n }\n } else {\n next.active = false\n }\n\n // Make sure to empty the range if suggestion is inactive\n if (!next.active) {\n next.decorationId = null\n next.range = { from: 0, to: 0 }\n next.query = null\n next.text = null\n }\n\n return next\n },\n },\n\n props: {\n // Call the keydown hook if suggestion is active.\n handleKeyDown(view, event) {\n const { active, range } = plugin.getState(view.state)\n\n if (!active) {\n return false\n }\n\n return renderer?.onKeyDown?.({ view, event, range }) || false\n },\n\n // Setup decorator on the currently active suggestion.\n decorations(state) {\n const { active, range, decorationId } = plugin.getState(state)\n\n if (!active) {\n return null\n }\n\n return DecorationSet.create(state.doc, [\n Decoration.inline(range.from, range.to, {\n nodeName: decorationTag,\n class: decorationClass,\n 'data-decoration-id': decorationId,\n }),\n ])\n },\n },\n })\n\n return plugin\n}\n"],"names":[],"mappings":";;;;AAiBM,SAAU,mBAAmB,CAAC,MAAe,EAAA;;AACjD,IAAA,MAAM,EACJ,IAAI,EAAE,WAAW,EAAE,eAAe,EAAE,WAAW,EAAE,SAAS,GAC3D,GAAG,MAAM,CAAA;AAEV,IAAA,MAAM,WAAW,GAAG,cAAc,CAAC,IAAI,CAAC,CAAA;IACxC,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,CAAM,GAAA,EAAA,WAAW,CAAG,CAAA,CAAA,CAAC,CAAA;IAC/C,MAAM,MAAM,GAAG,WAAW,GAAG,GAAG,GAAG,EAAE,CAAA;IACrC,MAAM,MAAM,GAAG,WAAW;AACxB,UAAE,IAAI,MAAM,CA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