@kerebron/extension-autocomplete 0.4.28 → 0.4.29

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.
@@ -230,3 +230,4 @@ export class AutocompletePlugin extends Plugin {
230
230
  });
231
231
  }
232
232
  }
233
+ //# sourceMappingURL=AutocompletePlugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AutocompletePlugin.js","sourceRoot":"","sources":["../src/AutocompletePlugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAU7D,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD,MAAM,CAAC,MAAM,qBAAqB,GAAG,IAAI,SAAS,CAAC,cAAc,CAAC,CAAC;AAEnE,MAAM,OAAO,kBAAoC,SAAQ,MAAM;IAC7D,YAAY,MAA0B,EAAE,MAAkB;QACxD,IAAI,KAAmD,CAAC;QACxD,MAAM,QAAQ,GAAyB,MAAM,CAAC,QAAQ;YACpD,IAAI,eAAe,CAAC,MAAM,CAAC,CAAC;QAE9B,KAAK,CAAC;YACJ,GAAG,EAAE,qBAAqB;YAC1B,IAAI;gBACF,OAAO;oBACL,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE;wBAChC,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAC;wBAC3C,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,EAAE,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;wBAE5C,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,MAAM;4BACtC,IAAI,CAAC,KAAK,CAAC,IAAI,KAAK,IAA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AW,CAAC,KAAK;oBACf,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,EAAE,GAAG,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;oBAE7D,IAAI,CAAC,MAAM,EAAE,CAAC;wBACZ,OAAO,IAAI,CAAC;oBACd,CAAC;oBAED,MAAM,IAAI,GAAG,QAAQ,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;oBAC5C,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,eAAe,IAAI,wBAAwB,CAAC;oBACpE,IAAI,CAAC,YAAY,CAAC,oBAAoB,EAAE,YAAY,CAAC,CAAC;oBAEtD,OAAO,aAAa,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE;wBACrC,UAAU,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC;qBACpC,CAAC,CAAC;gBACL,CAAC;aACF;SACF,CAAC,CAAC;QAEH,QAAQ,CAAC,gBAAgB,CAAC,OAAO,EAAE,GAAG,EAAE;YACtC,MAAM,EAAE,GAAG,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,OAAO,CAAC,qBAAqB,EAAE;gBACxD,IAAI,EAAE,YAAY;aACnB,CAAC,CAAC;YACH,OAAO,CAAC,IAAI,CAAC,gCAAgC,CAAC,CAAC;YAC/C,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;QAC3B,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
@@ -111,3 +111,4 @@ export class DefaultRenderer extends EventTarget {
111
111
  }
112
112
  }
113
113
  }
114
+ //# sourceMappingURL=DefaultRenderer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DefaultRenderer.js","sourceRoot":"","sources":["../src/DefaultRenderer.ts"],"names":[],"mappings":"AAOA,MAAM,UAAU,GAAG,iBAAiB,CAAC;AAErC,MAAM,OAAO,eAAsB,SAAQ,WAAW;IAOhC;IALpB,OAAO,CAAuB;IAC9B,OA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AA6B;QACxC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;YAClB,OAAO;QACT,CAAC;QAED,IAAI,CAAC,OAAO,CAAC,SAAS,GAAG,EAAE,CAAC;QAC5B,KAAK,IAAI,GAAG,GAAG,CAAC,EAAE,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,GAAG,EAAE,EAAE,CAAC;YACjD,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YAC7B,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,cAAc,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC;QAC3D,CAAC;QAED,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC5B,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,GAAG,MAAM,CAAC;QACtC,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,GAAG,EAAE,CAAC;QAClC,CAAC;QAED,MAAM,IAAI,GAAG,KAAK,EAAE,UAAU,EAAE,EAAE,CAAC;QACnC,IAAI,IAAI,EAAE,MAAM,EAAE,CAAC;YACjB,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;YACvB,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;YAC3B,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;YACtC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,GAAG,MAAM,GAAG,IAAI,CAAC;QACzC,CAAC;IACH,CAAC;CACF"}
@@ -14,3 +14,4 @@ export class ExtensionAutocomplete extends Extension {
14
14
  ];
15
15
  }
16
16
  }
17
+ //# sourceMappingURL=ExtensionAutocomplete.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ExtensionAutocomplete.js","sourceRoot":"","sources":["../src/ExtensionAutocomplete.ts"],"names":[],"mappings":"AAGA,OAAO,EAAmB,SAAS,EAAkB,MAAM,kBAAkB,CAAC;AAE9E,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAwB7D,MAAM,OAAO,qBAAsB,SAAQ,SAAS;IAK7B;IAJrB,IAAI,GAAG,cAAc,CAAC;IACtB,MAAM,CAAwC;IAE9C,YACqB,MAA0B;QAE7C,KAAK,CAAC,MAAM,CAAC,CAAC;QAFK,WAAM,GAAN,MAAM,CAAoB;IAG/C,CAAC;IAEQ,qBAAqB;QAC5B,OAAO;YACL,IAAI,kBAAkB,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC;SACjD,CAAC;IACJ,CAAC;CACF"}
@@ -56,3 +56,4 @@ export function createDefaultMatcher(config = {}) {
56
56
  return null;
57
57
  };
58
58
  }
59
+ //# sourceMappingURL=createDefaultMatcher.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createDefaultMatcher.js","sourceRoot":"","sources":["../src/createDefaultMatcher.ts"],"names":[],"mappings":"AAGA,8CAA8C;AAC9C,MAAM,UAAU,cAAc,CAAC,MAAc;IAC3C,OAAO,MAAM,CAAC,OAAO,CAAC,uBAAuB,EAAE,MAAM,CAAC,CAAC;AACzD,CAAC;AAUD,MAAM,UAAU,oBAAoB,CAClC,SAAwB,EAAE;IAE1B,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,IAAI,GAAG,CAAC;IAChC,MAAM,kBAAkB,GAAG,MAAM,CAAC,kBAAkB,IAAI,KAAK,CAAC;IAC9D,MAAM,eAAe,GAAG,MAAM,CAAC,eAAe,IAAI,CAAC,GAAG,CAAC,CAAC;IACxD,MAAM,WAAW,GAAG,MAAM,CAAC,WAAW,IAAI,KAAK,CAAC;IAEhD,OAAO,CAAC,SAAsB,EAAmB,EAAE;QACjD,MAAM,WAAW,GAAG,MAAM,CAAC,WAAW,IAAI,CAAC,kBAAkB,CAAC;QAE9D,MAAM,WA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B,GAAG,IAAI,MAAM,CACrC,KAAK,eAAe,EAAE,IAAI,CAAC,EAAE,CAAC,OAAO,CACtC;aACE,IAAI,CAAC,WAAW,CAAC,CAAC;QAErB,IAAI,eAAe,KAAK,IAAI,IAAI,CAAC,oBAAoB,EAAE,CAAC;YACtD,OAAO,IAAI,CAAC;QACd,CAAC;QAED,qDAAqD;QACrD,MAAM,IAAI,GAAG,QAAQ,GAAG,KAAK,CAAC,KAAK,CAAC;QACpC,IAAI,EAAE,GAAG,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;QAEhC,0EAA0E;QAC1E,eAAe;QACf,IAAI,WAAW,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,GAAG,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;YAC3D,KAAK,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC;YAChB,EAAE,IAAI,CAAC,CAAC;QACV,CAAC;QAED,8EAA8E;QAC9E,IAAI,IAAI,GAAG,SAAS,CAAC,GAAG,IAAI,EAAE,IAAI,SAAS,CAAC,GAAG,EAAE,CAAC;YAChD,OAAO;gBACL,KAAK,EAAE;oBACL,IAAI;oBACJ,EAAE;iBACH;gBACD,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC;gBACf,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;aACf,CAAC;QACJ,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC,CAAC;AACJ,CAAC"}
@@ -48,3 +48,4 @@ export function createRegexMatcher(regexes) {
48
48
  };
49
49
  };
50
50
  }
51
+ //# sourceMappingURL=createRegexMatcher.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createRegexMatcher.js","sourceRoot":"","sources":["../src/createRegexMatcher.ts"],"names":[],"mappings":"AAGA,MAAM,UAAU,YAAY,CAAC,IAAY,EAAE,KAAc;IACvD,IAAI,EAAE,MAAM,EAAE,GAAG,IAAI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;YACD,KAAK,EAAE,WAAW;YAClB,IAAI,EAAE,WAAW;SAClB,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC"}
package/esm/mod.js CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from './ExtensionAutocomplete.js';
2
2
  export { createRegexMatcher } from './createRegexMatcher.js';
3
+ //# sourceMappingURL=mod.js.map
package/esm/mod.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.js","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAC;AAC3C,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC"}
package/esm/types.js CHANGED
@@ -1 +1,2 @@
1
1
  export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kerebron/extension-autocomplete",
3
- "version": "0.4.28",
3
+ "version": "0.4.29",
4
4
  "license": "MIT",
5
5
  "module": "./esm/mod.js",
6
6
  "exports": {
@@ -18,8 +18,12 @@
18
18
  }
19
19
  },
20
20
  "scripts": {},
21
+ "files": [
22
+ "esm",
23
+ "src"
24
+ ],
21
25
  "dependencies": {
22
- "@kerebron/editor": "0.4.28",
26
+ "@kerebron/editor": "0.4.29",
23
27
  "prosemirror-model": "1.25.3",
24
28
  "prosemirror-state": "1.4.3",
25
29
  "prosemirror-view": "1.40.0"
@@ -0,0 +1,301 @@
1
+ import { Plugin, PluginKey } from 'prosemirror-state';
2
+ import { Decoration, DecorationSet } from 'prosemirror-view';
3
+
4
+ import { type CoreEditor, type TextRange } from '@kerebron/editor';
5
+
6
+ import type { AutocompleteConfig } from './ExtensionAutocomplete.js';
7
+ import {
8
+ AutocompleteMatcher,
9
+ AutocompleteRenderer,
10
+ SuggestionProps,
11
+ } from './types.js';
12
+ import { createDefaultMatcher } from './createDefaultMatcher.js';
13
+ import { DefaultRenderer } from './DefaultRenderer.js';
14
+
15
+ export const AutocompletePluginKey = new PluginKey('autocomplete');
16
+
17
+ export class AutocompletePlugin<Item, TSelected> extends Plugin {
18
+ constructor(config: AutocompleteConfig, editor: CoreEditor) {
19
+ let props: SuggestionProps<Item, TSelected> | undefined;
20
+ const renderer: AutocompleteRenderer = config.renderer ||
21
+ new DefaultRenderer(editor);
22
+
23
+ super({
24
+ key: AutocompletePluginKey,
25
+ view() {
26
+ return {
27
+ update: async (view, prevState) => {
28
+ const prev = this.key?.getState(prevState);
29
+ const next = this.key?.getState(view.state);
30
+
31
+ const moved = prev.active && next.active &&
32
+ prev.range.from !== next.range.from;
33
+ const started = !prev.active && next.active;
34
+ const stopped = prev.active && !next.active;
35
+ const changed = !started && !stopped && prev.query !== next.query;
36
+
37
+ const handleStart = started || (moved && changed);
38
+ const handleChange = changed || moved;
39
+ let handleExit = stopped || (moved && changed);
40
+
41
+ if (!handleStart && !handleChange && !handleExit) {
42
+ return;
43
+ }
44
+
45
+ const state = handleExit && !handleStart ? prev : next;
46
+
47
+ // await new Promise(r => setTimeout(r, 100));
48
+ const decorationNode = view.dom.querySelector(
49
+ `[data-decoration-id="${state.decorationId}"]`,
50
+ );
51
+
52
+ props = {
53
+ range: state.range,
54
+ query: state.query,
55
+ text: state.text,
56
+ items: [],
57
+ command: (selected) => {
58
+ if (!config.onSelect) {
59
+ return () => {};
60
+ }
61
+ return config.onSelect(selected, state.range);
62
+ },
63
+ decorationNode,
64
+ // virtual node for popper.js or tippy.js
65
+ // this can be used for building popups without a DOM node
66
+ clientRect: decorationNode
67
+ ? () => {
68
+ // because of `items` can be asynchrounous we’ll search for the current decoration node
69
+ const { decorationId } = this.key?.getState(editor.state); // eslint-disable-line
70
+ const currentDecorationNode = view.dom.querySelector(
71
+ `[data-decoration-id="${decorationId}"]`,
72
+ );
73
+
74
+ return currentDecorationNode?.getBoundingClientRect() || null;
75
+ }
76
+ : null,
77
+ };
78
+
79
+ if (handleStart) {
80
+ renderer?.onBeforeStart?.(props);
81
+ }
82
+
83
+ if (handleChange) {
84
+ renderer?.onBeforeUpdate?.(props);
85
+ }
86
+
87
+ if (handleChange || handleStart) {
88
+ if (config.getItems) {
89
+ try {
90
+ const ctx = { state, range: state.range, isActive: true };
91
+ props.items = await config.getItems(state.query, ctx);
92
+ } catch (err: any) {
93
+ if (err.isLSP) {
94
+ props.items = [];
95
+ console.error(
96
+ 'LSP error config.getItems()',
97
+ err.message,
98
+ config.getItems,
99
+ );
100
+ } else {
101
+ throw err;
102
+ }
103
+ }
104
+ if (props.items.length === 0) {
105
+ handleExit = true;
106
+ }
107
+ }
108
+ }
109
+
110
+ if (handleExit) {
111
+ renderer?.onExit?.(props);
112
+ }
113
+
114
+ if (handleChange) {
115
+ renderer?.onUpdate?.(props);
116
+ }
117
+
118
+ if (handleStart) {
119
+ renderer?.onStart?.(props);
120
+ }
121
+ },
122
+
123
+ destroy: () => {
124
+ if (!props) {
125
+ return;
126
+ }
127
+
128
+ renderer?.onExit?.(props);
129
+ },
130
+ };
131
+ },
132
+
133
+ state: {
134
+ // Initialize the plugin's internal state.
135
+ init() {
136
+ const state: {
137
+ manual: boolean;
138
+ active: boolean;
139
+ range: TextRange;
140
+ query: null | string;
141
+ text: null | string;
142
+ composing: boolean;
143
+ decorationId?: string | null;
144
+ } = {
145
+ manual: false,
146
+ active: false,
147
+ range: {
148
+ from: 0,
149
+ to: 0,
150
+ },
151
+ query: null,
152
+ text: null,
153
+ composing: false,
154
+ };
155
+
156
+ return state;
157
+ },
158
+
159
+ // Apply changes to the plugin state from a view transaction.
160
+ apply(transaction, prev, _oldState, state) {
161
+ // const { isEditable } = editor; // TODO
162
+ const isEditable = true;
163
+ const { composing } = editor.view;
164
+ const { selection } = transaction;
165
+ const { empty, from } = selection;
166
+ const next = { ...prev };
167
+
168
+ const meta = transaction.getMeta(AutocompletePluginKey);
169
+ if (!meta && !transaction.isGeneric) {
170
+ return next;
171
+ }
172
+
173
+ if (meta?.type === 'deactivate') {
174
+ console.info('Deactivate autocomplete');
175
+ next.active = false;
176
+ return next;
177
+ }
178
+ if (meta?.type === 'activate') {
179
+ console.info('Trigger manual autocomplete');
180
+ next.range = { from: selection.from, to: selection.to };
181
+ next.active = true;
182
+ next.manual = true;
183
+ next.query = null;
184
+ return next;
185
+ }
186
+
187
+ next.composing = composing;
188
+
189
+ const parentNode = selection.$anchor.parent;
190
+
191
+ if (
192
+ !['code_block'].includes(parentNode?.type.name) && isEditable &&
193
+ (empty || editor.view.composing)
194
+ ) {
195
+ // Reset active state if we just left the previous suggestion range
196
+ if (
197
+ (from < prev.range.from || from > prev.range.to) && !composing &&
198
+ !prev.composing
199
+ ) {
200
+ next.active = false;
201
+ }
202
+
203
+ const matchers: AutocompleteMatcher[] = config.matchers ||
204
+ [createDefaultMatcher()];
205
+ let match = undefined;
206
+
207
+ for (const matcher of matchers) {
208
+ match = matcher(selection.$from);
209
+ if (match) {
210
+ break;
211
+ }
212
+ }
213
+
214
+ const decorationId = `id_${Math.floor(Math.random() * 0xffffffff)}`;
215
+
216
+ // If we found a match, update the current state to show it
217
+ if (
218
+ match && (!config.allow || config.allow({
219
+ state,
220
+ range: match.range,
221
+ isActive: prev.active,
222
+ }))
223
+ ) {
224
+ console.info('Trigger matcher autocomplete', match);
225
+ next.active = true;
226
+ next.decorationId = prev.decorationId
227
+ ? prev.decorationId
228
+ : decorationId;
229
+ next.range = match.range;
230
+ next.query = match.query;
231
+ next.text = match.text;
232
+ } else {
233
+ next.active = false;
234
+ }
235
+ } else {
236
+ next.active = false;
237
+ }
238
+
239
+ next.manual = false;
240
+
241
+ // Make sure to empty the range if suggestion is inactive
242
+ if (!next.active) {
243
+ next.decorationId = null;
244
+ next.range = { from: 0, to: 0 };
245
+ next.query = null;
246
+ next.text = null;
247
+ }
248
+
249
+ return next;
250
+ },
251
+ },
252
+
253
+ props: {
254
+ // Call the keydown hook if suggestion is active.
255
+ handleKeyDown(view, event) {
256
+ const { active, range } = this.getState(view.state);
257
+
258
+ if (event.key === ' ' && event.ctrlKey) {
259
+ const tr = view.state.tr.setMeta(AutocompletePluginKey, {
260
+ type: 'activate',
261
+ });
262
+ console.info('Manual autocomplete key');
263
+ view.dispatch(tr);
264
+ return true;
265
+ }
266
+
267
+ if (active) {
268
+ return renderer?.onKeyDown?.({ view, event, range }) || false;
269
+ }
270
+
271
+ return false;
272
+ },
273
+
274
+ // Setup decorator on the currently active suggestion.
275
+ decorations(state) {
276
+ const { active, range, decorationId } = this.getState(state);
277
+
278
+ if (!active) {
279
+ return null;
280
+ }
281
+
282
+ const node = document.createElement('span');
283
+ node.className = config.decorationClass || 'kb-autocomplete--decor';
284
+ node.setAttribute('data-decoration-id', decorationId);
285
+
286
+ return DecorationSet.create(state.doc, [
287
+ Decoration.widget(range.from, node),
288
+ ]);
289
+ },
290
+ },
291
+ });
292
+
293
+ renderer.addEventListener('close', () => {
294
+ const tr = editor.state.tr.setMeta(AutocompletePluginKey, {
295
+ type: 'deactivate',
296
+ });
297
+ console.info('Manual autocomplete deactivate');
298
+ editor.view.dispatch(tr);
299
+ });
300
+ }
301
+ }
@@ -0,0 +1,134 @@
1
+ import { CoreEditor } from '@kerebron/editor';
2
+ import {
3
+ AutocompleteRenderer,
4
+ SuggestionKeyDownProps,
5
+ SuggestionProps,
6
+ } from './types.js';
7
+
8
+ const CSS_PREFIX = 'kb-autocomplete';
9
+
10
+ export class DefaultRenderer<Item> extends EventTarget
11
+ implements AutocompleteRenderer {
12
+ command: (props: any) => void;
13
+ wrapper: HTMLElement | undefined;
14
+ items: Array<Item> = [];
15
+ pos: number = -1;
16
+
17
+ constructor(private editor: CoreEditor) {
18
+ super();
19
+ this.command = () => {};
20
+ }
21
+
22
+ onStart(props: SuggestionProps<Item>) {
23
+ this.command = props.command;
24
+ if (this.wrapper) {
25
+ this.wrapper.parentElement?.removeChild(this.wrapper);
26
+ }
27
+ const root = ('root' in this.editor.view)
28
+ ? this.editor.view.root
29
+ : document || document;
30
+
31
+ this.wrapper = document.createElement('ul');
32
+ this.wrapper.classList.add(CSS_PREFIX + '__wrapper');
33
+ root.appendChild(this.wrapper);
34
+
35
+ this.items.splice(0, this.items.length, ...props.items);
36
+ this.recreateList(props);
37
+ }
38
+
39
+ onUpdate(props: SuggestionProps<Item>) {
40
+ this.command = props.command;
41
+ this.items.splice(0, this.items.length, ...props.items);
42
+ this.recreateList(props);
43
+ }
44
+
45
+ onExit() {
46
+ if (this.wrapper) {
47
+ this.wrapper.parentNode?.removeChild(this.wrapper);
48
+ this.wrapper = undefined;
49
+ }
50
+ this.dispatchEvent(new Event('close'));
51
+ this.pos = -1;
52
+ }
53
+
54
+ onKeyDown(props: SuggestionKeyDownProps) {
55
+ if (!this.wrapper) {
56
+ return false;
57
+ }
58
+ if (this.items.length === 0) {
59
+ return false;
60
+ }
61
+
62
+ if (props.event.key === 'Escape') {
63
+ if (this.wrapper) {
64
+ this.wrapper.parentNode?.removeChild(this.wrapper);
65
+ this.wrapper = undefined;
66
+ return true;
67
+ }
68
+ }
69
+ if (props.event.key === 'ArrowUp') {
70
+ if (this.pos > -1) {
71
+ this.pos = this.pos - 1;
72
+ this.recreateList();
73
+ }
74
+ return true;
75
+ }
76
+
77
+ if (props.event.key === 'ArrowDown') {
78
+ if (this.pos < this.items.length - 1) {
79
+ this.pos++;
80
+ this.recreateList();
81
+ }
82
+ return true;
83
+ }
84
+
85
+ if (props.event.key === 'Enter') {
86
+ if (this.pos > -1 && this.pos < this.items.length) {
87
+ this.command(this.items[this.pos]);
88
+ this.items.splice(0, this.items.length);
89
+ this.onExit();
90
+ return true;
91
+ }
92
+ }
93
+ return false;
94
+ }
95
+
96
+ createListItem(item: Item, cnt: number) { // override
97
+ const li = document.createElement('li');
98
+ if (cnt === this.pos) {
99
+ li.classList.add('active');
100
+ }
101
+ li.innerText = '' + item; // TODO item to string and item formatting
102
+ li.style.cursor = 'pointer';
103
+ li.addEventListener('click', () => {
104
+ this.command(item);
105
+ });
106
+ return li;
107
+ }
108
+
109
+ recreateList(props?: SuggestionProps<Item>) {
110
+ if (!this.wrapper) {
111
+ return;
112
+ }
113
+
114
+ this.wrapper.innerHTML = '';
115
+ for (let cnt = 0; cnt < this.items.length; cnt++) {
116
+ const item = this.items[cnt];
117
+ this.wrapper.appendChild(this.createListItem(item, cnt));
118
+ }
119
+
120
+ if (this.items.length === 0) {
121
+ this.wrapper.style.display = 'none';
122
+ } else {
123
+ this.wrapper.style.display = '';
124
+ }
125
+
126
+ const rect = props?.clientRect?.();
127
+ if (rect?.height) {
128
+ const left = rect.left;
129
+ const bottom = rect.bottom;
130
+ this.wrapper.style.left = left + 'px';
131
+ this.wrapper.style.top = bottom + 'px';
132
+ }
133
+ }
134
+ }
@@ -0,0 +1,45 @@
1
+ import type { EditorState, Plugin } from 'prosemirror-state';
2
+ import { Schema } from 'prosemirror-model';
3
+
4
+ import { type CoreEditor, Extension, type TextRange } from '@kerebron/editor';
5
+
6
+ import { AutocompletePlugin } from './AutocompletePlugin.js';
7
+ import { AutocompleteMatcher, AutocompleteRenderer } from './types.js';
8
+
9
+ export interface AutocompleteProps {
10
+ state: EditorState;
11
+ range: TextRange;
12
+ isActive?: boolean;
13
+ }
14
+
15
+ export interface AutocompleteConfig<I = any, TSelected = any> {
16
+ getItems: (query: string, props: AutocompleteProps) => I[] | Promise<I[]>;
17
+
18
+ onSelect?: (selected: TSelected, range: TextRange) => void;
19
+ allow?: (
20
+ props: AutocompleteProps,
21
+ ) => boolean;
22
+
23
+ matchers?: AutocompleteMatcher[];
24
+ renderer?: AutocompleteRenderer<I, TSelected>;
25
+
26
+ decorationTag?: string;
27
+ decorationClass?: string;
28
+ }
29
+
30
+ export class ExtensionAutocomplete extends Extension {
31
+ name = 'autocomplete';
32
+ plugin!: AutocompletePlugin<unknown, unknown>;
33
+
34
+ public constructor(
35
+ protected override config: AutocompleteConfig,
36
+ ) {
37
+ super(config);
38
+ }
39
+
40
+ override getProseMirrorPlugins(): Plugin[] {
41
+ return [
42
+ new AutocompletePlugin(this.config, this.editor),
43
+ ];
44
+ }
45
+ }
@@ -0,0 +1,95 @@
1
+ import { ResolvedPos } from 'prosemirror-model';
2
+ import { AutocompleteMatcher, SuggestionMatch } from './types.js';
3
+
4
+ // source: https://stackoverflow.com/a/6969486
5
+ export function escapeForRegEx(string: string): string {
6
+ return string.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&');
7
+ }
8
+
9
+ export interface MatcherConfig {
10
+ char?: string;
11
+ allowSpaces?: boolean;
12
+ allowToIncludeChar?: boolean;
13
+ allowedPrefixes?: string[] | null;
14
+ startOfLine?: boolean;
15
+ }
16
+
17
+ export function createDefaultMatcher(
18
+ config: MatcherConfig = {},
19
+ ): AutocompleteMatcher {
20
+ const char = config.char || '@';
21
+ const allowToIncludeChar = config.allowToIncludeChar || false;
22
+ const allowedPrefixes = config.allowedPrefixes || [' '];
23
+ const startOfLine = config.startOfLine || false;
24
+
25
+ return ($position: ResolvedPos): SuggestionMatch => {
26
+ const allowSpaces = config.allowSpaces && !allowToIncludeChar;
27
+
28
+ const escapedChar = escapeForRegEx(char);
29
+ const suffix = new RegExp(`\\s${escapedChar}$`);
30
+ const prefix = startOfLine ? '^' : '';
31
+ const finalEscapedChar = allowToIncludeChar ? '' : escapedChar;
32
+ const regexp = allowSpaces
33
+ ? new RegExp(
34
+ `${prefix}${escapedChar}.*?(?=\\s${finalEscapedChar}|$)`,
35
+ 'gm',
36
+ )
37
+ : new RegExp(
38
+ `${prefix}(?:^)?${escapedChar}[^\\s${finalEscapedChar}]*`,
39
+ 'gm',
40
+ );
41
+
42
+ const text = $position.nodeBefore?.isText && $position.nodeBefore.text;
43
+
44
+ if (!text) {
45
+ return null;
46
+ }
47
+
48
+ const textFrom = $position.pos - text.length;
49
+ const match = Array.from(text.matchAll(regexp)).pop();
50
+
51
+ if (!match || match.input === undefined || match.index === undefined) {
52
+ return null;
53
+ }
54
+
55
+ // JavaScript doesn't have lookbehinds. This hacks a check that first character
56
+ // is a space or the start of the line
57
+ const matchPrefix = match.input.slice(
58
+ Math.max(0, match.index - 1),
59
+ match.index,
60
+ );
61
+ const matchPrefixIsAllowed = new RegExp(
62
+ `^[${allowedPrefixes?.join('')}\0]?$`,
63
+ )
64
+ .test(matchPrefix);
65
+
66
+ if (allowedPrefixes !== null && !matchPrefixIsAllowed) {
67
+ return null;
68
+ }
69
+
70
+ // The absolute position of the match in the document
71
+ const from = textFrom + match.index;
72
+ let to = from + match[0].length;
73
+
74
+ // Edge case handling; if spaces are allowed and we're directly in between
75
+ // two triggers
76
+ if (allowSpaces && suffix.test(text.slice(to - 1, to + 1))) {
77
+ match[0] += ' ';
78
+ to += 1;
79
+ }
80
+
81
+ // If the $position is located within the matched substring, return that range
82
+ if (from < $position.pos && to >= $position.pos) {
83
+ return {
84
+ range: {
85
+ from,
86
+ to,
87
+ },
88
+ query: match[0],
89
+ text: match[0],
90
+ };
91
+ }
92
+
93
+ return null;
94
+ };
95
+ }
@@ -0,0 +1,71 @@
1
+ import type { ResolvedPos } from 'prosemirror-model';
2
+ import { AutocompleteMatcher, SuggestionMatch } from './types.js';
3
+
4
+ export function ensureAnchor(expr: RegExp, start: boolean) {
5
+ let { source } = expr;
6
+ let addStart = start && source[0] != '^',
7
+ addEnd = source[source.length - 1] != '$';
8
+ if (!addStart && !addEnd) return expr;
9
+ return new RegExp(
10
+ `${addStart ? '^' : ''}(?:${source})${addEnd ? '$' : ''}`,
11
+ expr.flags ?? (expr.ignoreCase ? 'i' : ''),
12
+ );
13
+ }
14
+
15
+ function matchBefore($position: ResolvedPos, expr: RegExp) {
16
+ const text = $position.nodeBefore?.isText && $position.nodeBefore.text;
17
+
18
+ if (!text) {
19
+ return null;
20
+ }
21
+
22
+ const textFrom = $position.pos - text.length;
23
+
24
+ const start = Math.max(textFrom, $position.pos - 250);
25
+ const str = text.slice();
26
+
27
+ const found = str.search(ensureAnchor(expr, false));
28
+
29
+ return found < 0
30
+ ? null
31
+ : { from: start + found, to: $position.pos, text: str.slice(found) };
32
+ }
33
+
34
+ export function createRegexMatcher(
35
+ regexes: RegExp[],
36
+ ): AutocompleteMatcher {
37
+ return ($position: ResolvedPos): SuggestionMatch => {
38
+ const text = $position.nodeBefore?.isText && $position.nodeBefore.text;
39
+
40
+ if (!text) {
41
+ return null;
42
+ }
43
+ const textFrom = $position.pos - text.length;
44
+
45
+ const matches = regexes.map((regex) => matchBefore($position, regex))
46
+ .filter((m) => !!m);
47
+
48
+ if (matches.length === 0) {
49
+ return null;
50
+ }
51
+
52
+ matches.sort((a, b) => b.text.length - a.text.length);
53
+
54
+ let from = matches[0].from;
55
+ let matchedText = matches[0].text;
56
+ let to = matches[0].to;
57
+ while (matchedText.match(/^\s/)) {
58
+ matchedText = matchedText.substring(1);
59
+ from++;
60
+ }
61
+
62
+ return {
63
+ range: {
64
+ from,
65
+ to,
66
+ },
67
+ query: matchedText,
68
+ text: matchedText,
69
+ };
70
+ };
71
+ }
package/src/mod.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from './ExtensionAutocomplete.js';
2
+ export { createRegexMatcher } from './createRegexMatcher.js';
package/src/types.ts ADDED
@@ -0,0 +1,79 @@
1
+ import type { ResolvedPos } from 'prosemirror-model';
2
+ import type { TextRange } from '@kerebron/editor';
3
+ import { EditorView } from 'prosemirror-view';
4
+
5
+ export type SuggestionMatch = {
6
+ range: TextRange;
7
+ query: string;
8
+ text: string;
9
+ } | null;
10
+
11
+ export type AutocompleteMatcher = (pos: ResolvedPos) => SuggestionMatch;
12
+
13
+ export interface SuggestionKeyDownProps {
14
+ view: EditorView;
15
+ event: KeyboardEvent;
16
+ range: TextRange;
17
+ }
18
+
19
+ export interface AutocompleteRenderer<I = any, TSelected = any> {
20
+ onBeforeStart?: (props: SuggestionProps<I, TSelected>) => void;
21
+ onStart?: (props: SuggestionProps<I, TSelected>) => void;
22
+ onBeforeUpdate?: (props: SuggestionProps<I, TSelected>) => void;
23
+ onUpdate?: (props: SuggestionProps<I, TSelected>) => void;
24
+ onExit?: (props: SuggestionProps<I, TSelected>) => void;
25
+ onKeyDown?: (props: SuggestionKeyDownProps) => boolean;
26
+
27
+ addEventListener(
28
+ type: string,
29
+ listener: EventListenerOrEventListenerObject,
30
+ options?: boolean | AddEventListenerOptions,
31
+ ): void;
32
+ removeEventListener(
33
+ type: string,
34
+ callback: EventListenerOrEventListenerObject | null,
35
+ options?: EventListenerOptions | boolean,
36
+ ): void;
37
+ }
38
+
39
+ export interface SuggestionProps<I = any, TSelected = any> {
40
+ /**
41
+ * The range of the suggestion.
42
+ */
43
+ range: TextRange;
44
+
45
+ /**
46
+ * The current suggestion query.
47
+ */
48
+ query: string;
49
+
50
+ /**
51
+ * The current suggestion text.
52
+ */
53
+ text: string;
54
+
55
+ /**
56
+ * The suggestion items array.
57
+ */
58
+ items: I[];
59
+
60
+ /**
61
+ * A function that is called when a suggestion is selected.
62
+ * @param props The props object.
63
+ * @returns void
64
+ */
65
+ command: (props: TSelected) => void;
66
+
67
+ /**
68
+ * The decoration node HTML element
69
+ * @default null
70
+ */
71
+ decorationNode: Element | null;
72
+
73
+ /**
74
+ * The function that returns the client rect
75
+ * @default null
76
+ * @example () => new DOMRect(0, 0, 0, 0)
77
+ */
78
+ clientRect?: (() => DOMRect | null) | null;
79
+ }
@@ -1,12 +0,0 @@
1
- .kb-autocomplete__wrapper {
2
- position: fixed;
3
- z-index: 99999;
4
- padding: 6px var(--kb-space-sm);
5
- background: var(--kb-color-surface-elevated);
6
- list-style: none;
7
- }
8
-
9
- .kb-autocomplete__wrapper li.active {
10
- background: rgba(232, 234, 237, 0.08);
11
- color: #fff;
12
- }