@atlaskit/editor-plugin-autocomplete 0.3.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.
- package/CHANGELOG.md +11 -0
- package/build/tsconfig.json +0 -1
- package/dist/cjs/pm-plugins/autocomplete-plugin.js +2 -5
- package/dist/cjs/pm-plugins/text-predictor.js +31 -17
- package/dist/es2019/pm-plugins/autocomplete-plugin.js +1 -5
- package/dist/es2019/pm-plugins/text-predictor.js +11 -3
- package/dist/esm/pm-plugins/autocomplete-plugin.js +1 -5
- package/dist/esm/pm-plugins/text-predictor.js +31 -17
- package/dist/types/pm-plugins/autocomplete-plugin.d.ts +7 -1
- package/dist/types/pm-plugins/text-predictor.d.ts +1 -1
- package/dist/types-ts4.5/pm-plugins/autocomplete-plugin.d.ts +7 -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 +7 -6
- package/src/pm-plugins/text-predictor.ts +15 -4
- package/tsconfig.app.json +0 -1
- package/tsconfig.json +0 -1
- package/build/url-module.d.ts +0 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-autocomplete
|
|
2
2
|
|
|
3
|
+
## 0.4.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [`603cd44e7b8c3`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/603cd44e7b8c3) -
|
|
8
|
+
Fetch vectors through media client
|
|
9
|
+
|
|
10
|
+
### Patch Changes
|
|
11
|
+
|
|
12
|
+
- Updated dependencies
|
|
13
|
+
|
|
3
14
|
## 0.3.0
|
|
4
15
|
|
|
5
16
|
### Minor Changes
|
package/build/tsconfig.json
CHANGED
|
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.createAutocompletePlugin = exports.autocompletePluginKey = void 0;
|
|
8
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
|
-
var _wordVectors_10k = _interopRequireDefault(require("url:./data/word-vectors_10k.bin"));
|
|
10
9
|
var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
|
|
11
10
|
var _keymap = require("@atlaskit/editor-prosemirror/keymap");
|
|
12
11
|
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
@@ -15,9 +14,7 @@ var _ghostTextDecoration = require("./ghost-text-decoration");
|
|
|
15
14
|
var _slowLaneClient = require("./slow-lane-client");
|
|
16
15
|
var _textPredictor = require("./text-predictor");
|
|
17
16
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
18
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
19
|
-
// asset URL (content-hashed). For rspack, this is handled via staticAssetsLoader.
|
|
20
|
-
// eslint-disable-next-line @repo/internal/import/no-unresolved
|
|
17
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
21
18
|
var SLOW_LANE_ENDPOINT = '/gateway/api/v1/autocomplete/typeahead-encodings';
|
|
22
19
|
var autocompletePluginKey = exports.autocompletePluginKey = new _state.PluginKey('autocomplete');
|
|
23
20
|
var DEBOUNCE_MS = 150;
|
|
@@ -305,7 +302,7 @@ var createAutocompletePlugin = exports.createAutocompletePlugin = function creat
|
|
|
305
302
|
focus: function focus() {
|
|
306
303
|
(0, _textPredictor.loadDefaultVocabulary)();
|
|
307
304
|
(0, _textPredictor.loadVectorsAsync)({
|
|
308
|
-
|
|
305
|
+
getBinaryUrl: options === null || options === void 0 ? void 0 : options.getVectorsBinaryUrl
|
|
309
306
|
}).catch(function () {});
|
|
310
307
|
if (!hasIngestedPage) {
|
|
311
308
|
hasIngestedPage = true;
|
|
@@ -705,33 +705,47 @@ var loadVectorsAsync = exports.loadVectorsAsync = /*#__PURE__*/function () {
|
|
|
705
705
|
}
|
|
706
706
|
return _context.abrupt("return");
|
|
707
707
|
case 2:
|
|
708
|
-
if (options !== null && options !== void 0 && options.
|
|
708
|
+
if (options !== null && options !== void 0 && options.getBinaryUrl) {
|
|
709
709
|
_context.next = 5;
|
|
710
710
|
break;
|
|
711
711
|
}
|
|
712
712
|
// eslint-disable-next-line no-console
|
|
713
|
-
console.warn('[text-predictor] loadVectorsAsync called without a
|
|
713
|
+
console.warn('[text-predictor] loadVectorsAsync called without a getBinaryUrl — vectors will not load. Pass getVectorsBinaryUrl via plugin options.');
|
|
714
714
|
return _context.abrupt("return");
|
|
715
715
|
case 5:
|
|
716
716
|
vectorsLoadStarted = true;
|
|
717
|
-
|
|
718
|
-
_context.
|
|
719
|
-
|
|
717
|
+
_context.prev = 6;
|
|
718
|
+
_context.next = 9;
|
|
719
|
+
return options.getBinaryUrl();
|
|
720
|
+
case 9:
|
|
721
|
+
url = _context.sent;
|
|
722
|
+
_context.next = 17;
|
|
723
|
+
break;
|
|
724
|
+
case 12:
|
|
725
|
+
_context.prev = 12;
|
|
726
|
+
_context.t0 = _context["catch"](6);
|
|
727
|
+
vectorsLoadStarted = false;
|
|
728
|
+
// eslint-disable-next-line no-console
|
|
729
|
+
console.warn('[text-predictor] Failed to resolve vectors URL:', _context.t0);
|
|
730
|
+
return _context.abrupt("return");
|
|
731
|
+
case 17:
|
|
732
|
+
_context.prev = 17;
|
|
733
|
+
_context.next = 20;
|
|
720
734
|
return fetch(url);
|
|
721
|
-
case
|
|
735
|
+
case 20:
|
|
722
736
|
res = _context.sent;
|
|
723
737
|
if (res.ok) {
|
|
724
|
-
_context.next =
|
|
738
|
+
_context.next = 25;
|
|
725
739
|
break;
|
|
726
740
|
}
|
|
727
741
|
vectorsLoadStarted = false;
|
|
728
742
|
// eslint-disable-next-line no-console
|
|
729
743
|
console.warn("[text-predictor] Failed to load vectors: ".concat(res.status));
|
|
730
744
|
return _context.abrupt("return");
|
|
731
|
-
case
|
|
732
|
-
_context.next =
|
|
745
|
+
case 25:
|
|
746
|
+
_context.next = 27;
|
|
733
747
|
return res.arrayBuffer();
|
|
734
|
-
case
|
|
748
|
+
case 27:
|
|
735
749
|
buffer = _context.sent;
|
|
736
750
|
float32 = new Float32Array(buffer);
|
|
737
751
|
wordIndex = _word_index_10k.default;
|
|
@@ -751,19 +765,19 @@ var loadVectorsAsync = exports.loadVectorsAsync = /*#__PURE__*/function () {
|
|
|
751
765
|
sizeBytes: float32.byteLength
|
|
752
766
|
});
|
|
753
767
|
}
|
|
754
|
-
_context.next =
|
|
768
|
+
_context.next = 41;
|
|
755
769
|
break;
|
|
756
|
-
case
|
|
757
|
-
_context.prev =
|
|
758
|
-
_context.
|
|
770
|
+
case 37:
|
|
771
|
+
_context.prev = 37;
|
|
772
|
+
_context.t1 = _context["catch"](17);
|
|
759
773
|
vectorsLoadStarted = false;
|
|
760
774
|
// eslint-disable-next-line no-console
|
|
761
|
-
console.warn('[text-predictor] Failed to load vectors:', _context.
|
|
762
|
-
case
|
|
775
|
+
console.warn('[text-predictor] Failed to load vectors:', _context.t1);
|
|
776
|
+
case 41:
|
|
763
777
|
case "end":
|
|
764
778
|
return _context.stop();
|
|
765
779
|
}
|
|
766
|
-
}, _callee, null, [[
|
|
780
|
+
}, _callee, null, [[6, 12], [17, 37]]);
|
|
767
781
|
}));
|
|
768
782
|
return function loadVectorsAsync(_x) {
|
|
769
783
|
return _ref4.apply(this, arguments);
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
// url: prefix is an Atlaspack/Parcel directive that resolves this file as an emitted
|
|
2
|
-
// asset URL (content-hashed). For rspack, this is handled via staticAssetsLoader.
|
|
3
|
-
// eslint-disable-next-line @repo/internal/import/no-unresolved
|
|
4
|
-
import wordVectorsUrl from 'url:./data/word-vectors_10k.bin';
|
|
5
1
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
6
2
|
import { keydownHandler } from '@atlaskit/editor-prosemirror/keymap';
|
|
7
3
|
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
@@ -307,7 +303,7 @@ export const createAutocompletePlugin = options => {
|
|
|
307
303
|
focus: () => {
|
|
308
304
|
loadDefaultVocabulary();
|
|
309
305
|
loadVectorsAsync({
|
|
310
|
-
|
|
306
|
+
getBinaryUrl: options === null || options === void 0 ? void 0 : options.getVectorsBinaryUrl
|
|
311
307
|
}).catch(() => {});
|
|
312
308
|
if (!hasIngestedPage) {
|
|
313
309
|
hasIngestedPage = true;
|
|
@@ -569,13 +569,21 @@ export const loadVectorsAsync = async options => {
|
|
|
569
569
|
if (vectorStore || vectorsLoadStarted) {
|
|
570
570
|
return;
|
|
571
571
|
}
|
|
572
|
-
if (!(options !== null && options !== void 0 && options.
|
|
572
|
+
if (!(options !== null && options !== void 0 && options.getBinaryUrl)) {
|
|
573
573
|
// eslint-disable-next-line no-console
|
|
574
|
-
console.warn('[text-predictor] loadVectorsAsync called without a
|
|
574
|
+
console.warn('[text-predictor] loadVectorsAsync called without a getBinaryUrl — vectors will not load. Pass getVectorsBinaryUrl via plugin options.');
|
|
575
575
|
return;
|
|
576
576
|
}
|
|
577
577
|
vectorsLoadStarted = true;
|
|
578
|
-
|
|
578
|
+
let url;
|
|
579
|
+
try {
|
|
580
|
+
url = await options.getBinaryUrl();
|
|
581
|
+
} catch (e) {
|
|
582
|
+
vectorsLoadStarted = false;
|
|
583
|
+
// eslint-disable-next-line no-console
|
|
584
|
+
console.warn('[text-predictor] Failed to resolve vectors URL:', e);
|
|
585
|
+
return;
|
|
586
|
+
}
|
|
579
587
|
try {
|
|
580
588
|
const res = await fetch(url);
|
|
581
589
|
if (!res.ok) {
|
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
2
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
3
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
-
// url: prefix is an Atlaspack/Parcel directive that resolves this file as an emitted
|
|
5
|
-
// asset URL (content-hashed). For rspack, this is handled via staticAssetsLoader.
|
|
6
|
-
// eslint-disable-next-line @repo/internal/import/no-unresolved
|
|
7
|
-
import wordVectorsUrl from 'url:./data/word-vectors_10k.bin';
|
|
8
4
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
9
5
|
import { keydownHandler } from '@atlaskit/editor-prosemirror/keymap';
|
|
10
6
|
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
@@ -299,7 +295,7 @@ export var createAutocompletePlugin = function createAutocompletePlugin(options)
|
|
|
299
295
|
focus: function focus() {
|
|
300
296
|
loadDefaultVocabulary();
|
|
301
297
|
loadVectorsAsync({
|
|
302
|
-
|
|
298
|
+
getBinaryUrl: options === null || options === void 0 ? void 0 : options.getVectorsBinaryUrl
|
|
303
299
|
}).catch(function () {});
|
|
304
300
|
if (!hasIngestedPage) {
|
|
305
301
|
hasIngestedPage = true;
|
|
@@ -702,33 +702,47 @@ export var loadVectorsAsync = /*#__PURE__*/function () {
|
|
|
702
702
|
}
|
|
703
703
|
return _context.abrupt("return");
|
|
704
704
|
case 2:
|
|
705
|
-
if (options !== null && options !== void 0 && options.
|
|
705
|
+
if (options !== null && options !== void 0 && options.getBinaryUrl) {
|
|
706
706
|
_context.next = 5;
|
|
707
707
|
break;
|
|
708
708
|
}
|
|
709
709
|
// eslint-disable-next-line no-console
|
|
710
|
-
console.warn('[text-predictor] loadVectorsAsync called without a
|
|
710
|
+
console.warn('[text-predictor] loadVectorsAsync called without a getBinaryUrl — vectors will not load. Pass getVectorsBinaryUrl via plugin options.');
|
|
711
711
|
return _context.abrupt("return");
|
|
712
712
|
case 5:
|
|
713
713
|
vectorsLoadStarted = true;
|
|
714
|
-
|
|
715
|
-
_context.
|
|
716
|
-
|
|
714
|
+
_context.prev = 6;
|
|
715
|
+
_context.next = 9;
|
|
716
|
+
return options.getBinaryUrl();
|
|
717
|
+
case 9:
|
|
718
|
+
url = _context.sent;
|
|
719
|
+
_context.next = 17;
|
|
720
|
+
break;
|
|
721
|
+
case 12:
|
|
722
|
+
_context.prev = 12;
|
|
723
|
+
_context.t0 = _context["catch"](6);
|
|
724
|
+
vectorsLoadStarted = false;
|
|
725
|
+
// eslint-disable-next-line no-console
|
|
726
|
+
console.warn('[text-predictor] Failed to resolve vectors URL:', _context.t0);
|
|
727
|
+
return _context.abrupt("return");
|
|
728
|
+
case 17:
|
|
729
|
+
_context.prev = 17;
|
|
730
|
+
_context.next = 20;
|
|
717
731
|
return fetch(url);
|
|
718
|
-
case
|
|
732
|
+
case 20:
|
|
719
733
|
res = _context.sent;
|
|
720
734
|
if (res.ok) {
|
|
721
|
-
_context.next =
|
|
735
|
+
_context.next = 25;
|
|
722
736
|
break;
|
|
723
737
|
}
|
|
724
738
|
vectorsLoadStarted = false;
|
|
725
739
|
// eslint-disable-next-line no-console
|
|
726
740
|
console.warn("[text-predictor] Failed to load vectors: ".concat(res.status));
|
|
727
741
|
return _context.abrupt("return");
|
|
728
|
-
case
|
|
729
|
-
_context.next =
|
|
742
|
+
case 25:
|
|
743
|
+
_context.next = 27;
|
|
730
744
|
return res.arrayBuffer();
|
|
731
|
-
case
|
|
745
|
+
case 27:
|
|
732
746
|
buffer = _context.sent;
|
|
733
747
|
float32 = new Float32Array(buffer);
|
|
734
748
|
wordIndex = wordIndexData;
|
|
@@ -748,19 +762,19 @@ export var loadVectorsAsync = /*#__PURE__*/function () {
|
|
|
748
762
|
sizeBytes: float32.byteLength
|
|
749
763
|
});
|
|
750
764
|
}
|
|
751
|
-
_context.next =
|
|
765
|
+
_context.next = 41;
|
|
752
766
|
break;
|
|
753
|
-
case
|
|
754
|
-
_context.prev =
|
|
755
|
-
_context.
|
|
767
|
+
case 37:
|
|
768
|
+
_context.prev = 37;
|
|
769
|
+
_context.t1 = _context["catch"](17);
|
|
756
770
|
vectorsLoadStarted = false;
|
|
757
771
|
// eslint-disable-next-line no-console
|
|
758
|
-
console.warn('[text-predictor] Failed to load vectors:', _context.
|
|
759
|
-
case
|
|
772
|
+
console.warn('[text-predictor] Failed to load vectors:', _context.t1);
|
|
773
|
+
case 41:
|
|
760
774
|
case "end":
|
|
761
775
|
return _context.stop();
|
|
762
776
|
}
|
|
763
|
-
}, _callee, null, [[
|
|
777
|
+
}, _callee, null, [[6, 12], [17, 37]]);
|
|
764
778
|
}));
|
|
765
779
|
return function loadVectorsAsync(_x) {
|
|
766
780
|
return _ref4.apply(this, arguments);
|
|
@@ -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
|
-
export declare const createAutocompletePlugin: (options?: AutocompletePluginOptions) => SafePlugin<
|
|
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
|
-
|
|
86
|
+
getBinaryUrl?: () => Promise<string>;
|
|
87
87
|
}) => Promise<void>;
|
|
88
88
|
export declare const initVectors: (store: VectorStore) => void;
|
|
89
89
|
export declare const loadDefaultVocabulary: () => void;
|
|
@@ -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
|
-
export declare const createAutocompletePlugin: (options?: AutocompletePluginOptions) => SafePlugin<
|
|
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
|
-
|
|
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.
|
|
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.
|
|
36
|
+
"@atlaskit/editor-common": "^112.18.0",
|
|
37
37
|
"react": "^18.2.0"
|
|
38
38
|
},
|
|
39
39
|
"techstack": {
|
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
// url: prefix is an Atlaspack/Parcel directive that resolves this file as an emitted
|
|
2
|
-
// asset URL (content-hashed). For rspack, this is handled via staticAssetsLoader.
|
|
3
|
-
// eslint-disable-next-line @repo/internal/import/no-unresolved
|
|
4
|
-
import wordVectorsUrl from 'url:./data/word-vectors_10k.bin';
|
|
5
|
-
|
|
6
1
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
7
2
|
import { keydownHandler } from '@atlaskit/editor-prosemirror/keymap';
|
|
8
3
|
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
@@ -171,6 +166,12 @@ export interface AutocompletePluginOptions {
|
|
|
171
166
|
* word-frequency boosting. Called lazily so the preset can remain synchronous.
|
|
172
167
|
*/
|
|
173
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>;
|
|
174
175
|
}
|
|
175
176
|
|
|
176
177
|
/**
|
|
@@ -374,7 +375,7 @@ export const createAutocompletePlugin = (options?: AutocompletePluginOptions) =>
|
|
|
374
375
|
},
|
|
375
376
|
focus: () => {
|
|
376
377
|
loadDefaultVocabulary();
|
|
377
|
-
loadVectorsAsync({
|
|
378
|
+
loadVectorsAsync({ getBinaryUrl: options?.getVectorsBinaryUrl }).catch(() => {});
|
|
378
379
|
if (!hasIngestedPage) {
|
|
379
380
|
hasIngestedPage = true;
|
|
380
381
|
if (options?.getContext) {
|
|
@@ -714,20 +714,31 @@ interface VocabularyJson {
|
|
|
714
714
|
>;
|
|
715
715
|
}
|
|
716
716
|
|
|
717
|
-
export const loadVectorsAsync = async (options?: {
|
|
717
|
+
export const loadVectorsAsync = async (options?: {
|
|
718
|
+
getBinaryUrl?: () => Promise<string>;
|
|
719
|
+
}): Promise<void> => {
|
|
718
720
|
if (vectorStore || vectorsLoadStarted) {
|
|
719
721
|
return;
|
|
720
722
|
}
|
|
721
|
-
if (!options?.
|
|
723
|
+
if (!options?.getBinaryUrl) {
|
|
722
724
|
// eslint-disable-next-line no-console
|
|
723
725
|
console.warn(
|
|
724
|
-
'[text-predictor] loadVectorsAsync called without a
|
|
726
|
+
'[text-predictor] loadVectorsAsync called without a getBinaryUrl — vectors will not load. Pass getVectorsBinaryUrl via plugin options.',
|
|
725
727
|
);
|
|
726
728
|
return;
|
|
727
729
|
}
|
|
728
730
|
vectorsLoadStarted = true;
|
|
729
731
|
|
|
730
|
-
|
|
732
|
+
let url: string;
|
|
733
|
+
try {
|
|
734
|
+
url = await options.getBinaryUrl();
|
|
735
|
+
} catch (e) {
|
|
736
|
+
vectorsLoadStarted = false;
|
|
737
|
+
// eslint-disable-next-line no-console
|
|
738
|
+
console.warn('[text-predictor] Failed to resolve vectors URL:', e);
|
|
739
|
+
return;
|
|
740
|
+
}
|
|
741
|
+
|
|
731
742
|
try {
|
|
732
743
|
const res = await fetch(url);
|
|
733
744
|
if (!res.ok) {
|
package/tsconfig.app.json
CHANGED
package/tsconfig.json
CHANGED
package/build/url-module.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
// Ambient declaration for Atlaspack/Parcel url: prefix imports.
|
|
2
|
-
// The url: prefix instructs the bundler to emit the referenced file as a
|
|
3
|
-
// content-hashed asset and return its public URL as a string.
|
|
4
|
-
// For rspack, this is handled via staticAssetsLoader config.
|
|
5
|
-
declare module 'url:*' {
|
|
6
|
-
const url: string;
|
|
7
|
-
export default url;
|
|
8
|
-
}
|