@atlaskit/editor-plugin-autocomplete 3.0.0 → 3.1.0
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/CHANGELOG.md +8 -0
- package/dist/cjs/pm-plugins/autocomplete-plugin.js +6 -22
- package/dist/cjs/pm-plugins/scoring-pipeline.js +5 -4
- package/dist/cjs/pm-plugins/text-predictor.js +152 -60
- package/dist/es2019/pm-plugins/autocomplete-plugin.js +6 -22
- package/dist/es2019/pm-plugins/scoring-pipeline.js +5 -4
- package/dist/es2019/pm-plugins/text-predictor.js +105 -50
- package/dist/esm/pm-plugins/autocomplete-plugin.js +6 -22
- package/dist/esm/pm-plugins/scoring-pipeline.js +5 -4
- package/dist/esm/pm-plugins/text-predictor.js +144 -60
- package/dist/types/pm-plugins/text-predictor.d.ts +1 -1
- package/dist/types-ts4.5/pm-plugins/text-predictor.d.ts +1 -1
- package/package.json +2 -2
- package/src/pm-plugins/autocomplete-plugin.ts +6 -16
- package/src/pm-plugins/data/word_index_10k.json +7761 -7759
- package/src/pm-plugins/scoring-pipeline.ts +4 -5
- package/src/pm-plugins/text-predictor.ts +124 -45
|
@@ -84,5 +84,5 @@ export declare const loadVectorsAsync: (options?: {
|
|
|
84
84
|
getBinaryUrl?: () => Promise<string>;
|
|
85
85
|
}) => Promise<void>;
|
|
86
86
|
export declare const initVectors: (store: VectorStore) => void;
|
|
87
|
-
export declare const loadDefaultVocabulary: () => void
|
|
87
|
+
export declare const loadDefaultVocabulary: () => Promise<void>;
|
|
88
88
|
export {};
|
|
@@ -84,5 +84,5 @@ export declare const loadVectorsAsync: (options?: {
|
|
|
84
84
|
getBinaryUrl?: () => Promise<string>;
|
|
85
85
|
}) => Promise<void>;
|
|
86
86
|
export declare const initVectors: (store: VectorStore) => void;
|
|
87
|
-
export declare const loadDefaultVocabulary: () => void
|
|
87
|
+
export declare const loadDefaultVocabulary: () => Promise<void>;
|
|
88
88
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-autocomplete",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"description": "Client-side text autocomplete plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"wink-nlp": "^2.4.0"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
|
-
"@atlaskit/editor-common": "^115.
|
|
38
|
+
"@atlaskit/editor-common": "^115.6.0",
|
|
39
39
|
"@atlaskit/editor-plugin-analytics": "^11.0.0",
|
|
40
40
|
"react": "^18.2.0"
|
|
41
41
|
},
|
|
@@ -56,7 +56,6 @@ const getTextBeforeCursor = (state: EditorState): string => {
|
|
|
56
56
|
const { $from } = state.selection;
|
|
57
57
|
const maxChars = 200;
|
|
58
58
|
|
|
59
|
-
// 1. Get the perfectly flattened text of the current block up to the cursor
|
|
60
59
|
const blockNode = $from.parent;
|
|
61
60
|
const offsetInBlock = $from.parentOffset;
|
|
62
61
|
const blockText = blockNode.textContent.slice(0, offsetInBlock);
|
|
@@ -67,7 +66,7 @@ const getTextBeforeCursor = (state: EditorState): string => {
|
|
|
67
66
|
|
|
68
67
|
let fullText = blockText;
|
|
69
68
|
|
|
70
|
-
//
|
|
69
|
+
// Walk backwards through previous blocks until we have enough context.
|
|
71
70
|
let depth = $from.depth - 1;
|
|
72
71
|
|
|
73
72
|
while (fullText.length < maxChars && depth >= 0) {
|
|
@@ -309,7 +308,6 @@ export const createAutocompletePlugin = (
|
|
|
309
308
|
const { state } = view;
|
|
310
309
|
const { selection } = state;
|
|
311
310
|
|
|
312
|
-
// Only predict for cursor selections (not range selections)
|
|
313
311
|
if (!selection.empty) {
|
|
314
312
|
return;
|
|
315
313
|
}
|
|
@@ -323,12 +321,10 @@ export const createAutocompletePlugin = (
|
|
|
323
321
|
}
|
|
324
322
|
dismissedContext = null;
|
|
325
323
|
|
|
326
|
-
// Don't predict if there's not enough context
|
|
327
324
|
if (textBefore.trim().length < 3) {
|
|
328
325
|
return;
|
|
329
326
|
}
|
|
330
327
|
|
|
331
|
-
// Tier 1 prediction is synchronous -- no async needed
|
|
332
328
|
const prediction = predict(textBefore);
|
|
333
329
|
|
|
334
330
|
if (prediction && prediction.length > 0) {
|
|
@@ -402,8 +398,7 @@ export const createAutocompletePlugin = (
|
|
|
402
398
|
return { ...pluginState, ...meta };
|
|
403
399
|
}
|
|
404
400
|
|
|
405
|
-
//
|
|
406
|
-
// (new prediction will be scheduled from view.update)
|
|
401
|
+
// A new prediction is scheduled from view.update.
|
|
407
402
|
if (tr.docChanged) {
|
|
408
403
|
return {
|
|
409
404
|
...pluginState,
|
|
@@ -413,7 +408,6 @@ export const createAutocompletePlugin = (
|
|
|
413
408
|
};
|
|
414
409
|
}
|
|
415
410
|
|
|
416
|
-
// If selection changed without doc change, clear ghost text
|
|
417
411
|
if (tr.selectionSet && pluginState.ghostText) {
|
|
418
412
|
return {
|
|
419
413
|
...pluginState,
|
|
@@ -484,13 +478,11 @@ export const createAutocompletePlugin = (
|
|
|
484
478
|
return false;
|
|
485
479
|
},
|
|
486
480
|
focus: () => {
|
|
487
|
-
|
|
488
|
-
loadDefaultVocabulary();
|
|
489
|
-
} catch (error) {
|
|
481
|
+
loadDefaultVocabulary().catch((error) => {
|
|
490
482
|
logException(error as Error, {
|
|
491
483
|
location: 'editor-plugin-autocomplete/loadDefaultVocabulary',
|
|
492
484
|
});
|
|
493
|
-
}
|
|
485
|
+
});
|
|
494
486
|
loadVectorsAsync({ getBinaryUrl: options?.getVectorsBinaryUrl }).catch((error) => {
|
|
495
487
|
logException(error as Error, {
|
|
496
488
|
location: 'editor-plugin-autocomplete/loadVectorsAsync',
|
|
@@ -533,12 +525,10 @@ export const createAutocompletePlugin = (
|
|
|
533
525
|
if (justAccepted) {
|
|
534
526
|
justAccepted = false;
|
|
535
527
|
|
|
536
|
-
//
|
|
537
|
-
//
|
|
538
|
-
// block and abort until the user actually types a new character!
|
|
528
|
+
// Snapshot the post-acceptance text so follow-up transactions hit
|
|
529
|
+
// the dismissedContext guard and abort until the user types again.
|
|
539
530
|
dismissedContext = getTextBeforeCursor(view.state);
|
|
540
531
|
|
|
541
|
-
// Also clear any pending debounce timers from before the acceptance
|
|
542
532
|
if (debounceTimer) {
|
|
543
533
|
clearTimeout(debounceTimer);
|
|
544
534
|
}
|