@atlaskit/editor-plugin-autocomplete 0.2.0 → 0.4.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.
Files changed (35) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/afm-cc/tsconfig.json +1 -4
  3. package/afm-jira/tsconfig.json +1 -4
  4. package/afm-products/tsconfig.json +1 -4
  5. package/build/tsconfig.json +1 -6
  6. package/dist/cjs/pm-plugins/autocomplete-plugin.js +7 -3
  7. package/dist/cjs/pm-plugins/scoring-pipeline.js +1 -3
  8. package/dist/cjs/pm-plugins/slow-lane-client.js +3 -1
  9. package/dist/cjs/pm-plugins/text-predictor.js +47 -23
  10. package/dist/es2019/pm-plugins/autocomplete-plugin.js +7 -3
  11. package/dist/es2019/pm-plugins/scoring-pipeline.js +0 -3
  12. package/dist/es2019/pm-plugins/slow-lane-client.js +5 -2
  13. package/dist/es2019/pm-plugins/text-predictor.js +24 -9
  14. package/dist/esm/pm-plugins/autocomplete-plugin.js +7 -3
  15. package/dist/esm/pm-plugins/scoring-pipeline.js +0 -3
  16. package/dist/esm/pm-plugins/slow-lane-client.js +3 -1
  17. package/dist/esm/pm-plugins/text-predictor.js +47 -23
  18. package/dist/types/pm-plugins/autocomplete-plugin.d.ts +6 -0
  19. package/dist/types/pm-plugins/text-predictor.d.ts +1 -1
  20. package/dist/types-ts4.5/pm-plugins/autocomplete-plugin.d.ts +6 -0
  21. package/dist/types-ts4.5/pm-plugins/text-predictor.d.ts +1 -1
  22. package/package.json +2 -2
  23. package/src/pm-plugins/autocomplete-plugin.ts +20 -5
  24. package/src/pm-plugins/data/combined_l2_l3_pos_tags.json +73571 -3
  25. package/src/pm-plugins/data/ghost_pos_tags.json +43 -3
  26. package/src/pm-plugins/data/grammar_transitions_10k.json +46 -3
  27. package/src/pm-plugins/data/l3_vocabulary.json +20002 -3
  28. package/src/pm-plugins/data/vocabulary_10k.json +38794 -3
  29. package/src/pm-plugins/data/word_index_10k.json +7760 -3
  30. package/src/pm-plugins/scoring-pipeline.ts +0 -3
  31. package/src/pm-plugins/slow-lane-client.ts +4 -2
  32. package/src/pm-plugins/text-predictor.ts +30 -10
  33. package/tsconfig.app.json +2 -2
  34. package/tsconfig.json +1 -1
  35. package/src/pm-plugins/typings.d.ts +0 -12
@@ -32,5 +32,11 @@ export interface AutocompletePluginOptions {
32
32
  * word-frequency boosting. Called lazily so the preset can remain synchronous.
33
33
  */
34
34
  getContext?: () => Promise<AutocompleteContext | undefined>;
35
+ /**
36
+ * Async function that resolves to a URL for the word vectors binary file.
37
+ * When provided, this takes precedence over the bundled asset URL.
38
+ * Use this to serve vectors from a CDN or media service in production.
39
+ */
40
+ getVectorsBinaryUrl?: () => Promise<string>;
35
41
  }
36
42
  export declare const createAutocompletePlugin: (options?: AutocompletePluginOptions) => SafePlugin<AutocompletePluginState>;
@@ -83,7 +83,7 @@ export declare const incrementSessionFreq: (word: string) => void;
83
83
  export declare const ingestDocumentPage: (pageContent: string | undefined) => void;
84
84
  export declare const predict: (textBefore: string) => string | null;
85
85
  export declare const loadVectorsAsync: (options?: {
86
- vectorsUrl?: string;
86
+ getBinaryUrl?: () => Promise<string>;
87
87
  }) => Promise<void>;
88
88
  export declare const initVectors: (store: VectorStore) => void;
89
89
  export declare const loadDefaultVocabulary: () => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-autocomplete",
3
- "version": "0.2.0",
3
+ "version": "0.4.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",
@@ -33,7 +33,7 @@
33
33
  "wink-nlp": "^2.4.0"
34
34
  },
35
35
  "peerDependencies": {
36
- "@atlaskit/editor-common": "^112.16.0",
36
+ "@atlaskit/editor-common": "^112.18.0",
37
37
  "react": "^18.2.0"
38
38
  },
39
39
  "techstack": {
@@ -1,7 +1,11 @@
1
1
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
2
  import { keydownHandler } from '@atlaskit/editor-prosemirror/keymap';
3
3
  import { PluginKey } from '@atlaskit/editor-prosemirror/state';
4
- import type { EditorState, ReadonlyTransaction, Transaction } from '@atlaskit/editor-prosemirror/state';
4
+ import type {
5
+ EditorState,
6
+ ReadonlyTransaction,
7
+ Transaction,
8
+ } from '@atlaskit/editor-prosemirror/state';
5
9
  import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
6
10
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
7
11
 
@@ -162,6 +166,12 @@ export interface AutocompletePluginOptions {
162
166
  * word-frequency boosting. Called lazily so the preset can remain synchronous.
163
167
  */
164
168
  getContext?: () => Promise<AutocompleteContext | undefined>;
169
+ /**
170
+ * Async function that resolves to a URL for the word vectors binary file.
171
+ * When provided, this takes precedence over the bundled asset URL.
172
+ * Use this to serve vectors from a CDN or media service in production.
173
+ */
174
+ getVectorsBinaryUrl?: () => Promise<string>;
165
175
  }
166
176
 
167
177
  /**
@@ -261,14 +271,16 @@ export const createAutocompletePlugin = (options?: AutocompletePluginOptions) =>
261
271
  }
262
272
 
263
273
  const lastChar = newText[newText.length - 1];
264
- if (!/[\s.,;:!?]/u.test(lastChar)) {
274
+ // eslint-disable-next-line require-unicode-regexp
275
+ if (!/[\s.,;:!?]/.test(lastChar)) {
265
276
  return;
266
277
  }
267
278
 
268
279
  // Only fire if the previous state did not already end on a boundary,
269
280
  // so we don't double-count when multiple boundary chars are inserted.
270
281
  const prevLastChar = prevText[prevText.length - 1];
271
- if (prevLastChar && /[\s.,;:!?]/u.test(prevLastChar)) {
282
+ // eslint-disable-next-line require-unicode-regexp
283
+ if (prevLastChar && /[\s.,;:!?]/.test(prevLastChar)) {
272
284
  return;
273
285
  }
274
286
 
@@ -286,7 +298,10 @@ export const createAutocompletePlugin = (options?: AutocompletePluginOptions) =>
286
298
 
287
299
  state: {
288
300
  init: (): AutocompletePluginState => createInitialState(),
289
- apply: (tr: ReadonlyTransaction, pluginState: AutocompletePluginState): AutocompletePluginState => {
301
+ apply: (
302
+ tr: ReadonlyTransaction,
303
+ pluginState: AutocompletePluginState,
304
+ ): AutocompletePluginState => {
290
305
  const meta = tr.getMeta(autocompletePluginKey) as
291
306
  | Partial<AutocompletePluginState>
292
307
  | undefined;
@@ -360,7 +375,7 @@ export const createAutocompletePlugin = (options?: AutocompletePluginOptions) =>
360
375
  },
361
376
  focus: () => {
362
377
  loadDefaultVocabulary();
363
- loadVectorsAsync().catch(() => {});
378
+ loadVectorsAsync({ getBinaryUrl: options?.getVectorsBinaryUrl }).catch(() => {});
364
379
  if (!hasIngestedPage) {
365
380
  hasIngestedPage = true;
366
381
  if (options?.getContext) {