@atlaskit/editor-plugin-autocomplete 2.5.2 → 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.
@@ -0,0 +1,15 @@
1
+ {
2
+ "name": "@atlaskit/editor-plugin-autocomplete/CANONICAL_FIX__DO_NOT_USE_ME_A",
3
+ "main": "../dist/cjs/pm-plugins/autocomplete-plugin.js",
4
+ "module": "../dist/esm/pm-plugins/autocomplete-plugin.js",
5
+ "module:es2019": "../dist/es2019/pm-plugins/autocomplete-plugin.js",
6
+ "sideEffects": false,
7
+ "types": "../dist/types/pm-plugins/autocomplete-plugin.d.ts",
8
+ "typesVersions": {
9
+ ">=4.5 <5.9": {
10
+ "*": [
11
+ "../dist/types-ts4.5/pm-plugins/autocomplete-plugin.d.ts"
12
+ ]
13
+ }
14
+ }
15
+ }
@@ -0,0 +1,15 @@
1
+ {
2
+ "name": "@atlaskit/editor-plugin-autocomplete/CANONICAL_FIX__DO_NOT_USE_ME_B",
3
+ "main": "../dist/cjs/pm-plugins/slow-lane-client.js",
4
+ "module": "../dist/esm/pm-plugins/slow-lane-client.js",
5
+ "module:es2019": "../dist/es2019/pm-plugins/slow-lane-client.js",
6
+ "sideEffects": false,
7
+ "types": "../dist/types/pm-plugins/slow-lane-client.d.ts",
8
+ "typesVersions": {
9
+ ">=4.5 <5.9": {
10
+ "*": [
11
+ "../dist/types-ts4.5/pm-plugins/slow-lane-client.d.ts"
12
+ ]
13
+ }
14
+ }
15
+ }
@@ -0,0 +1,15 @@
1
+ {
2
+ "name": "@atlaskit/editor-plugin-autocomplete/CANONICAL_FIX__DO_NOT_USE_ME_C",
3
+ "main": "../dist/cjs/pm-plugins/text-predictor.js",
4
+ "module": "../dist/esm/pm-plugins/text-predictor.js",
5
+ "module:es2019": "../dist/es2019/pm-plugins/text-predictor.js",
6
+ "sideEffects": false,
7
+ "types": "../dist/types/pm-plugins/text-predictor.d.ts",
8
+ "typesVersions": {
9
+ ">=4.5 <5.9": {
10
+ "*": [
11
+ "../dist/types-ts4.5/pm-plugins/text-predictor.d.ts"
12
+ ]
13
+ }
14
+ }
15
+ }
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # @atlaskit/editor-plugin-autocomplete
2
2
 
3
+ ## 3.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`f003833231999`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/f003833231999) -
8
+ Code-split the autocomplete vocabulary, L3 word list and word-index JSON via dynamic import so
9
+ they load on autocomplete initialisation instead of being bundled into the editor's main chunk.
10
+
11
+ ## 3.0.0
12
+
13
+ ### Patch Changes
14
+
15
+ - Updated dependencies
16
+
3
17
  ## 2.5.2
4
18
 
5
19
  ### Patch Changes
@@ -38,8 +38,6 @@ var createInitialState = function createInitialState() {
38
38
  var getTextBeforeCursor = function getTextBeforeCursor(state) {
39
39
  var $from = state.selection.$from;
40
40
  var maxChars = 200;
41
-
42
- // 1. Get the perfectly flattened text of the current block up to the cursor
43
41
  var blockNode = $from.parent;
44
42
  var offsetInBlock = $from.parentOffset;
45
43
  var blockText = blockNode.textContent.slice(0, offsetInBlock);
@@ -48,7 +46,7 @@ var getTextBeforeCursor = function getTextBeforeCursor(state) {
48
46
  }
49
47
  var fullText = blockText;
50
48
 
51
- // 2. Walk backwards through previous blocks
49
+ // Walk backwards through previous blocks until we have enough context.
52
50
  var depth = $from.depth - 1;
53
51
  while (fullText.length < maxChars && depth >= 0) {
54
52
  var parentNode = $from.node(depth);
@@ -249,8 +247,6 @@ var createAutocompletePlugin = exports.createAutocompletePlugin = function creat
249
247
  try {
250
248
  var state = view.state;
251
249
  var selection = state.selection;
252
-
253
- // Only predict for cursor selections (not range selections)
254
250
  if (!selection.empty) {
255
251
  return;
256
252
  }
@@ -262,13 +258,9 @@ var createAutocompletePlugin = exports.createAutocompletePlugin = function creat
262
258
  return;
263
259
  }
264
260
  dismissedContext = null;
265
-
266
- // Don't predict if there's not enough context
267
261
  if (textBefore.trim().length < 3) {
268
262
  return;
269
263
  }
270
-
271
- // Tier 1 prediction is synchronous -- no async needed
272
264
  var prediction = (0, _textPredictor.predict)(textBefore);
273
265
  if (prediction && prediction.length > 0) {
274
266
  var typedLength = getTypedLengthForPrediction(textBefore);
@@ -330,8 +322,7 @@ var createAutocompletePlugin = exports.createAutocompletePlugin = function creat
330
322
  return _objectSpread(_objectSpread({}, pluginState), meta);
331
323
  }
332
324
 
333
- // If the document changed, clear the ghost text
334
- // (new prediction will be scheduled from view.update)
325
+ // A new prediction is scheduled from view.update.
335
326
  if (tr.docChanged) {
336
327
  return _objectSpread(_objectSpread({}, pluginState), {}, {
337
328
  ghostText: '',
@@ -339,8 +330,6 @@ var createAutocompletePlugin = exports.createAutocompletePlugin = function creat
339
330
  decorationSet: _view.DecorationSet.empty
340
331
  });
341
332
  }
342
-
343
- // If selection changed without doc change, clear ghost text
344
333
  if (tr.selectionSet && pluginState.ghostText) {
345
334
  return _objectSpread(_objectSpread({}, pluginState), {}, {
346
335
  ghostText: '',
@@ -401,13 +390,11 @@ var createAutocompletePlugin = exports.createAutocompletePlugin = function creat
401
390
  return false;
402
391
  },
403
392
  focus: function focus() {
404
- try {
405
- (0, _textPredictor.loadDefaultVocabulary)();
406
- } catch (error) {
393
+ (0, _textPredictor.loadDefaultVocabulary)().catch(function (error) {
407
394
  (0, _monitoring.logException)(error, {
408
395
  location: 'editor-plugin-autocomplete/loadDefaultVocabulary'
409
396
  });
410
- }
397
+ });
411
398
  (0, _textPredictor.loadVectorsAsync)({
412
399
  getBinaryUrl: options === null || options === void 0 ? void 0 : options.getVectorsBinaryUrl
413
400
  }).catch(function (error) {
@@ -449,12 +436,9 @@ var createAutocompletePlugin = exports.createAutocompletePlugin = function creat
449
436
  if (justAccepted) {
450
437
  justAccepted = false;
451
438
 
452
- // ✨ THE FIX: Memorize the text state right after acceptance.
453
- // Any follow-up transactions will hit the 'dismissedContext'
454
- // block and abort until the user actually types a new character!
439
+ // Snapshot the post-acceptance text so follow-up transactions hit
440
+ // the dismissedContext guard and abort until the user types again.
455
441
  dismissedContext = getTextBeforeCursor(view.state);
456
-
457
- // Also clear any pending debounce timers from before the acceptance
458
442
  if (debounceTimer) {
459
443
  clearTimeout(debounceTimer);
460
444
  }
@@ -18,7 +18,7 @@ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r)
18
18
  function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
19
19
  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; }
20
20
  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
- function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); } /**
21
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t3 in e) "default" !== _t3 && {}.hasOwnProperty.call(e, _t3) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t3)) && (i.get || i.set) ? o(f, _t3, i) : f[_t3] = e[_t3]); return f; })(e, t); } /**
22
22
  * Local Slow Lane Client: On-device inference via @mlc-ai/web-llm.
23
23
  *
24
24
  * Drop-in replacement for the network-based slow-lane-client. Instead of
@@ -127,8 +127,8 @@ var createLocalSlowLaneClient = exports.createLocalSlowLaneClient = function cre
127
127
  };
128
128
  var initEngine = /*#__PURE__*/function () {
129
129
  var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
130
- var _yield$import, CreateMLCEngine, prebuiltAppConfig, customModelRecord, appConfig, errorMsg;
131
- return _regenerator.default.wrap(function _callee$(_context) {
130
+ var _yield$import, CreateMLCEngine, prebuiltAppConfig, customModelRecord, appConfig, errorMsg, _t;
131
+ return _regenerator.default.wrap(function (_context) {
132
132
  while (1) switch (_context.prev = _context.next) {
133
133
  case 0:
134
134
  _context.prev = 0;
@@ -138,16 +138,16 @@ var createLocalSlowLaneClient = exports.createLocalSlowLaneClient = function cre
138
138
  }
139
139
  onStatus === null || onStatus === void 0 || onStatus("Initialising model: ".concat(modelId, "\u2026"));
140
140
  if ('gpu' in navigator) {
141
- _context.next = 5;
141
+ _context.next = 1;
142
142
  break;
143
143
  }
144
144
  throw new Error('WebGPU not supported');
145
- case 5:
146
- _context.next = 7;
145
+ case 1:
146
+ _context.next = 2;
147
147
  return Promise.resolve().then(function () {
148
148
  return _interopRequireWildcard(require( /* webpackChunkName: "@atlaskit-internal_editor-plugin-autocomplete-mlc-web-llm" */'@mlc-ai/web-llm'));
149
149
  });
150
- case 7:
150
+ case 2:
151
151
  _yield$import = _context.sent;
152
152
  CreateMLCEngine = _yield$import.CreateMLCEngine;
153
153
  prebuiltAppConfig = _yield$import.prebuiltAppConfig;
@@ -167,34 +167,34 @@ var createLocalSlowLaneClient = exports.createLocalSlowLaneClient = function cre
167
167
  appConfig = {
168
168
  model_list: [].concat((0, _toConsumableArray2.default)(prebuiltAppConfig.model_list), (0, _toConsumableArray2.default)(customModelRecord ? [customModelRecord] : []))
169
169
  };
170
- _context.next = 14;
170
+ _context.next = 3;
171
171
  return CreateMLCEngine(modelId, {
172
172
  appConfig: appConfig,
173
173
  initProgressCallback: initProgressCallback
174
174
  });
175
- case 14:
175
+ case 3:
176
176
  engine = _context.sent;
177
177
  if (!destroyed) {
178
- _context.next = 19;
178
+ _context.next = 4;
179
179
  break;
180
180
  }
181
181
  // destroy() was called while we were loading — clean up
182
182
  unloadEngine(engine);
183
183
  engine = null;
184
184
  return _context.abrupt("return");
185
- case 19:
185
+ case 4:
186
186
  ready = true;
187
187
  if ((0, _debugMode.isAutocompleteDebugEnabled)()) {
188
188
  // eslint-disable-next-line no-console
189
189
  console.log('%c[LocalSlowLane] %c✅ MLC engine loaded and ready', 'color: #9c27b0; font-weight: bold;', 'color: #4caf50;');
190
190
  }
191
191
  onStatus === null || onStatus === void 0 || onStatus('Model loaded and ready.');
192
- _context.next = 32;
192
+ _context.next = 6;
193
193
  break;
194
- case 24:
195
- _context.prev = 24;
196
- _context.t0 = _context["catch"](0);
197
- errorMsg = _context.t0 instanceof Error ? _context.t0.message : String(_context.t0);
194
+ case 5:
195
+ _context.prev = 5;
196
+ _t = _context["catch"](0);
197
+ errorMsg = _t instanceof Error ? _t.message : String(_t);
198
198
  ready = false;
199
199
  if ((0, _debugMode.isAutocompleteDebugEnabled)()) {
200
200
  // eslint-disable-next-line no-console
@@ -203,11 +203,11 @@ var createLocalSlowLaneClient = exports.createLocalSlowLaneClient = function cre
203
203
  onStatus === null || onStatus === void 0 || onStatus("Engine initialisation failed: ".concat(errorMsg));
204
204
  engineInitPromise = null;
205
205
  initFailed = true;
206
- case 32:
206
+ case 6:
207
207
  case "end":
208
208
  return _context.stop();
209
209
  }
210
- }, _callee, null, [[0, 24]]);
210
+ }, _callee, null, [[0, 5]]);
211
211
  }));
212
212
  return function initEngine() {
213
213
  return _ref.apply(this, arguments);
@@ -234,18 +234,18 @@ var createLocalSlowLaneClient = exports.createLocalSlowLaneClient = function cre
234
234
  */
235
235
  var runInference = /*#__PURE__*/function () {
236
236
  var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(text, requestId) {
237
- var _response$choices, response, lmLogits, logprobsContent, tokenLogprobs, token, _iterator, _step, alt, _token, logitValues, topTokens, errorMsg;
238
- return _regenerator.default.wrap(function _callee2$(_context2) {
237
+ var _response$choices, response, lmLogits, logprobsContent, tokenLogprobs, token, _iterator, _step, alt, _token, logitValues, topTokens, errorMsg, _t2;
238
+ return _regenerator.default.wrap(function (_context2) {
239
239
  while (1) switch (_context2.prev = _context2.next) {
240
240
  case 0:
241
241
  if (!(!engine || destroyed)) {
242
- _context2.next = 2;
242
+ _context2.next = 1;
243
243
  break;
244
244
  }
245
245
  return _context2.abrupt("return");
246
- case 2:
247
- _context2.prev = 2;
248
- _context2.next = 5;
246
+ case 1:
247
+ _context2.prev = 1;
248
+ _context2.next = 2;
249
249
  return engine.chat.completions.create({
250
250
  messages: [{
251
251
  role: 'user',
@@ -256,14 +256,14 @@ var createLocalSlowLaneClient = exports.createLocalSlowLaneClient = function cre
256
256
  top_logprobs: 5,
257
257
  temperature: 0
258
258
  });
259
- case 5:
259
+ case 2:
260
260
  response = _context2.sent;
261
261
  if (!(requestId < latestRequestId || destroyed)) {
262
- _context2.next = 8;
262
+ _context2.next = 3;
263
263
  break;
264
264
  }
265
265
  return _context2.abrupt("return");
266
- case 8:
266
+ case 3:
267
267
  // ── Extract LM logits ───────────────────────────────────────
268
268
  lmLogits = {};
269
269
  logprobsContent = (_response$choices = response.choices) === null || _response$choices === void 0 || (_response$choices = _response$choices[0]) === null || _response$choices === void 0 || (_response$choices = _response$choices.logprobs) === null || _response$choices === void 0 ? void 0 : _response$choices.content;
@@ -341,17 +341,17 @@ var createLocalSlowLaneClient = exports.createLocalSlowLaneClient = function cre
341
341
  hasVector: storedContextVector !== null,
342
342
  hasLmLogits: storedLmLogits !== null
343
343
  });
344
- _context2.next = 26;
344
+ _context2.next = 6;
345
345
  break;
346
- case 17:
347
- _context2.prev = 17;
348
- _context2.t0 = _context2["catch"](2);
346
+ case 4:
347
+ _context2.prev = 4;
348
+ _t2 = _context2["catch"](1);
349
349
  if (!(requestId < latestRequestId)) {
350
- _context2.next = 21;
350
+ _context2.next = 5;
351
351
  break;
352
352
  }
353
353
  return _context2.abrupt("return");
354
- case 21:
354
+ case 5:
355
355
  storedContextVector = null;
356
356
  storedLmLogits = null;
357
357
  onUpdate === null || onUpdate === void 0 || onUpdate({
@@ -359,16 +359,16 @@ var createLocalSlowLaneClient = exports.createLocalSlowLaneClient = function cre
359
359
  hasVector: false,
360
360
  hasLmLogits: false
361
361
  });
362
- errorMsg = _context2.t0 instanceof Error ? _context2.t0.message : String(_context2.t0);
362
+ errorMsg = _t2 instanceof Error ? _t2.message : String(_t2);
363
363
  if ((0, _debugMode.isAutocompleteDebugEnabled)()) {
364
364
  // eslint-disable-next-line no-console
365
365
  console.log("%c[LocalSlowLane] %c\u274C Inference error (request #".concat(requestId, "): ").concat(errorMsg), 'color: #9c27b0; font-weight: bold;', 'color: #f44336;');
366
366
  }
367
- case 26:
367
+ case 6:
368
368
  case "end":
369
369
  return _context2.stop();
370
370
  }
371
- }, _callee2, null, [[2, 17]]);
371
+ }, _callee2, null, [[1, 4]]);
372
372
  }));
373
373
  return function runInference(_x, _x2) {
374
374
  return _ref2.apply(this, arguments);
@@ -166,20 +166,21 @@ function applyGrammarFilter(candidates, previousWord) {
166
166
  dropped.push(entry.candidate.word);
167
167
  }
168
168
  }
169
+
170
+ // Grammar is authoritative.
169
171
  } catch (err) {
170
172
  _iterator2.e(err);
171
173
  } finally {
172
174
  _iterator2.f();
173
175
  }
174
- var finalFiltered = filtered.length > 0 ? filtered : candidates;
175
176
  return {
176
- filtered: finalFiltered,
177
+ filtered: filtered,
177
178
  grammarMeta: {
178
179
  prevWord: lowerPrev,
179
180
  prevTags: prevTags,
180
181
  before: candidates.length,
181
- after: finalFiltered.length,
182
- dropped: filtered.length > 0 ? dropped : []
182
+ after: filtered.length,
183
+ dropped: dropped
183
184
  }
184
185
  };
185
186
  }
@@ -70,16 +70,16 @@ var createSlowLaneClient = exports.createSlowLaneClient = function createSlowLan
70
70
  var inflightRequestId = null;
71
71
  var doUpdateContext = /*#__PURE__*/function () {
72
72
  var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(text, requestId) {
73
- var url, payload, res, data;
74
- return _regenerator.default.wrap(function _callee$(_context) {
73
+ var url, payload, res, data, _t;
74
+ return _regenerator.default.wrap(function (_context) {
75
75
  while (1) switch (_context.prev = _context.next) {
76
76
  case 0:
77
77
  if (!(!text || text.trim().length === 0)) {
78
- _context.next = 2;
78
+ _context.next = 1;
79
79
  break;
80
80
  }
81
81
  return _context.abrupt("return");
82
- case 2:
82
+ case 1:
83
83
  // eslint-disable-next-line require-unicode-regexp
84
84
  url = "".concat(baseUrl.replace(/\/$/, '')).concat(endpoint);
85
85
  payload = {
@@ -99,17 +99,17 @@ var createSlowLaneClient = exports.createSlowLaneClient = function createSlowLan
99
99
  // eslint-disable-next-line no-console
100
100
  console.groupEnd();
101
101
  }
102
- _context.prev = 6;
103
- _context.next = 9;
102
+ _context.prev = 2;
103
+ _context.next = 3;
104
104
  return fetchFn(url, {
105
105
  method: 'POST',
106
106
  headers: headers,
107
107
  body: JSON.stringify(payload)
108
108
  });
109
- case 9:
109
+ case 3:
110
110
  res = _context.sent;
111
111
  if (res.ok) {
112
- _context.next = 16;
112
+ _context.next = 4;
113
113
  break;
114
114
  }
115
115
  storedContextVector = null;
@@ -123,10 +123,10 @@ var createSlowLaneClient = exports.createSlowLaneClient = function createSlowLan
123
123
  console.log("%c[SlowLane] %c\u274C Request failed (".concat(res.status, ")"), 'color: #9c27b0; font-weight: bold;', 'color: #f44336;');
124
124
  }
125
125
  return _context.abrupt("return");
126
- case 16:
127
- _context.next = 18;
126
+ case 4:
127
+ _context.next = 5;
128
128
  return res.json();
129
- case 18:
129
+ case 5:
130
130
  data = _context.sent;
131
131
  if (data.semantic_vector && Array.isArray(data.semantic_vector)) {
132
132
  storedContextVector = new Float32Array(data.semantic_vector);
@@ -159,11 +159,11 @@ var createSlowLaneClient = exports.createSlowLaneClient = function createSlowLan
159
159
  hasLmLogits: storedLmLogits !== null
160
160
  });
161
161
  // eslint-disable-next-line no-unused-vars
162
- _context.next = 32;
162
+ _context.next = 7;
163
163
  break;
164
- case 26:
165
- _context.prev = 26;
166
- _context.t0 = _context["catch"](6);
164
+ case 6:
165
+ _context.prev = 6;
166
+ _t = _context["catch"](2);
167
167
  storedContextVector = null;
168
168
  storedLmLogits = null;
169
169
  (0, _ufo.failExp)(_ufo.EXPERIENCE_NAME.SLOW_LANE_FETCH, requestId, {
@@ -173,17 +173,17 @@ var createSlowLaneClient = exports.createSlowLaneClient = function createSlowLan
173
173
  // eslint-disable-next-line no-console
174
174
  console.log('%c[SlowLane] %c❌ Network error — context cleared', 'color: #9c27b0; font-weight: bold;', 'color: #f44336;');
175
175
  }
176
- case 32:
177
- _context.prev = 32;
176
+ case 7:
177
+ _context.prev = 7;
178
178
  if (inflightRequestId === requestId) {
179
179
  inflightRequestId = null;
180
180
  }
181
- return _context.finish(32);
182
- case 35:
181
+ return _context.finish(7);
182
+ case 8:
183
183
  case "end":
184
184
  return _context.stop();
185
185
  }
186
- }, _callee, null, [[6, 26, 32, 35]]);
186
+ }, _callee, null, [[2, 6, 7, 8]]);
187
187
  }));
188
188
  return function doUpdateContext(_x, _x2) {
189
189
  return _ref.apply(this, arguments);