@atlaskit/editor-plugin-autocomplete 2.5.0 → 2.5.1

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 CHANGED
@@ -1,5 +1,13 @@
1
1
  # @atlaskit/editor-plugin-autocomplete
2
2
 
3
+ ## 2.5.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [`80694949c0036`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/80694949c0036) -
8
+ Fixing typecheck errors
9
+ - Updated dependencies
10
+
3
11
  ## 2.5.0
4
12
 
5
13
  ### Minor Changes
@@ -45,6 +45,11 @@ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r
45
45
  * The client exposes getContextVector() and getLmLogits() which are populated
46
46
  * asynchronously after each updateContext() call.
47
47
  */
48
+ var startsWithAsciiLetter = function startsWithAsciiLetter(value) {
49
+ var firstChar = value.charCodeAt(0);
50
+ return firstChar >= 65 && firstChar <= 90 || firstChar >= 97 && firstChar <= 122;
51
+ };
52
+
48
53
  // ─── Types ───────────────────────────────────────────────────────────────────
49
54
 
50
55
  // Same return type as createSlowLaneClient for drop-in compatibility
@@ -271,7 +276,7 @@ var createLocalSlowLaneClient = exports.createLocalSlowLaneClient = function cre
271
276
  tokenLogprobs = logprobsContent[0]; // Add the top token
272
277
  if (tokenLogprobs.token) {
273
278
  token = tokenLogprobs.token.trim().toLowerCase();
274
- if (token.length > 0 && /^[a-z\u017F\u212A]/i.test(token)) {
279
+ if (token.length > 0 && startsWithAsciiLetter(token)) {
275
280
  lmLogits[token] = Math.exp(tokenLogprobs.logprob);
276
281
  }
277
282
  }
@@ -283,7 +288,7 @@ var createLocalSlowLaneClient = exports.createLocalSlowLaneClient = function cre
283
288
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
284
289
  alt = _step.value;
285
290
  _token = alt.token.trim().toLowerCase();
286
- if (_token.length > 0 && /^[a-z\u017F\u212A]/i.test(_token)) {
291
+ if (_token.length > 0 && startsWithAsciiLetter(_token)) {
287
292
  lmLogits[_token] = Math.exp(alt.logprob);
288
293
  }
289
294
  }
@@ -28,6 +28,10 @@
28
28
 
29
29
  import { isAutocompleteDebugEnabled } from './debug-mode';
30
30
  import { isWordBoundary } from './slow-lane-client';
31
+ const startsWithAsciiLetter = value => {
32
+ const firstChar = value.charCodeAt(0);
33
+ return firstChar >= 65 && firstChar <= 90 || firstChar >= 97 && firstChar <= 122;
34
+ };
31
35
 
32
36
  // ─── Types ───────────────────────────────────────────────────────────────────
33
37
 
@@ -118,6 +122,8 @@ export const createLocalSlowLaneClient = (config = {}) => {
118
122
  if (!('gpu' in navigator)) {
119
123
  throw new Error('WebGPU not supported');
120
124
  }
125
+
126
+ // eslint-disable-next-line @repo/internal/import/no-unresolved, import/dynamic-import-chunkname -- runtime dependency declared in package.json and lazily loaded for webgpu support
121
127
  const {
122
128
  CreateMLCEngine,
123
129
  prebuiltAppConfig
@@ -219,7 +225,7 @@ export const createLocalSlowLaneClient = (config = {}) => {
219
225
  // Add the top token
220
226
  if (tokenLogprobs.token) {
221
227
  const token = tokenLogprobs.token.trim().toLowerCase();
222
- if (token.length > 0 && /^[a-z]/iu.test(token)) {
228
+ if (token.length > 0 && startsWithAsciiLetter(token)) {
223
229
  lmLogits[token] = Math.exp(tokenLogprobs.logprob);
224
230
  }
225
231
  }
@@ -228,7 +234,7 @@ export const createLocalSlowLaneClient = (config = {}) => {
228
234
  if (tokenLogprobs.top_logprobs) {
229
235
  for (const alt of tokenLogprobs.top_logprobs) {
230
236
  const token = alt.token.trim().toLowerCase();
231
- if (token.length > 0 && /^[a-z]/iu.test(token)) {
237
+ if (token.length > 0 && startsWithAsciiLetter(token)) {
232
238
  lmLogits[token] = Math.exp(alt.logprob);
233
239
  }
234
240
  }
@@ -38,6 +38,10 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
38
38
 
39
39
  import { isAutocompleteDebugEnabled } from './debug-mode';
40
40
  import { isWordBoundary } from './slow-lane-client';
41
+ var startsWithAsciiLetter = function startsWithAsciiLetter(value) {
42
+ var firstChar = value.charCodeAt(0);
43
+ return firstChar >= 65 && firstChar <= 90 || firstChar >= 97 && firstChar <= 122;
44
+ };
41
45
 
42
46
  // ─── Types ───────────────────────────────────────────────────────────────────
43
47
 
@@ -263,7 +267,7 @@ export var createLocalSlowLaneClient = function createLocalSlowLaneClient() {
263
267
  tokenLogprobs = logprobsContent[0]; // Add the top token
264
268
  if (tokenLogprobs.token) {
265
269
  token = tokenLogprobs.token.trim().toLowerCase();
266
- if (token.length > 0 && /^[a-z\u017F\u212A]/i.test(token)) {
270
+ if (token.length > 0 && startsWithAsciiLetter(token)) {
267
271
  lmLogits[token] = Math.exp(tokenLogprobs.logprob);
268
272
  }
269
273
  }
@@ -275,7 +279,7 @@ export var createLocalSlowLaneClient = function createLocalSlowLaneClient() {
275
279
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
276
280
  alt = _step.value;
277
281
  _token = alt.token.trim().toLowerCase();
278
- if (_token.length > 0 && /^[a-z\u017F\u212A]/i.test(_token)) {
282
+ if (_token.length > 0 && startsWithAsciiLetter(_token)) {
279
283
  lmLogits[_token] = Math.exp(alt.logprob);
280
284
  }
281
285
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-autocomplete",
3
- "version": "2.5.0",
3
+ "version": "2.5.1",
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": "^114.43.0",
38
+ "@atlaskit/editor-common": "^114.44.0",
39
39
  "@atlaskit/editor-plugin-analytics": "^10.1.0",
40
40
  "react": "^18.2.0"
41
41
  },
@@ -39,8 +39,7 @@ export const EXPERIENCE_NAME = {
39
39
  LOAD_VECTORS: 'load-vectors',
40
40
  } as const;
41
41
 
42
- export type AutocompleteExperienceName =
43
- (typeof EXPERIENCE_NAME)[keyof typeof EXPERIENCE_NAME];
42
+ export type AutocompleteExperienceName = (typeof EXPERIENCE_NAME)[keyof typeof EXPERIENCE_NAME];
44
43
 
45
44
  const isUfoEnabled = (): boolean => !process?.env?.REACT_SSR;
46
45
 
@@ -121,18 +120,12 @@ export const failExp = (
121
120
  }
122
121
  };
123
122
 
124
- export const abortExp = (
125
- name: AutocompleteExperienceName,
126
- id: string,
127
- reason?: string,
128
- ): void => {
123
+ export const abortExp = (name: AutocompleteExperienceName, id: string, reason?: string): void => {
129
124
  if (!isUfoEnabled()) {
130
125
  return;
131
126
  }
132
127
  try {
133
- experiences[name]
134
- .getInstance(id)
135
- .abort(reason ? { metadata: { reason } } : undefined);
128
+ experiences[name].getInstance(id).abort(reason ? { metadata: { reason } } : undefined);
136
129
  } catch {
137
130
  // UFO errors must never break the plugin
138
131
  }
@@ -31,8 +31,7 @@ const DEBOUNCE_MS = 150;
31
31
 
32
32
  const hasDestroy = (
33
33
  client: ReturnType<typeof createSlowLaneClient> | LocalSlowLaneClient,
34
- ): client is LocalSlowLaneClient =>
35
- 'destroy' in client && typeof client.destroy === 'function';
34
+ ): client is LocalSlowLaneClient => 'destroy' in client && typeof client.destroy === 'function';
36
35
 
37
36
  export interface AutocompletePluginState {
38
37
  /** The decoration set containing the ghost text widget */
@@ -33,6 +33,12 @@ import { isWordBoundary } from './slow-lane-client';
33
33
 
34
34
  type WebLlmModelRecord = NonNullable<AppConfig['model_list']>[number];
35
35
 
36
+ const startsWithAsciiLetter = (value: string): boolean => {
37
+ const firstChar = value.charCodeAt(0);
38
+
39
+ return (firstChar >= 65 && firstChar <= 90) || (firstChar >= 97 && firstChar <= 122);
40
+ };
41
+
36
42
  // ─── Types ───────────────────────────────────────────────────────────────────
37
43
 
38
44
  export interface LocalSlowLaneClientConfig {
@@ -145,7 +151,7 @@ export const createLocalSlowLaneClient = (
145
151
  let engineInitPromise: Promise<void> | null = null;
146
152
 
147
153
  const unloadEngine = (engineToUnload: MLCEngine): void => {
148
- engineToUnload.unload().catch((error) => {
154
+ engineToUnload.unload().catch((error: unknown) => {
149
155
  if (isAutocompleteDebugEnabled()) {
150
156
  // eslint-disable-next-line no-console
151
157
  console.log(
@@ -189,6 +195,7 @@ export const createLocalSlowLaneClient = (
189
195
  throw new Error('WebGPU not supported');
190
196
  }
191
197
 
198
+ // eslint-disable-next-line @repo/internal/import/no-unresolved, import/dynamic-import-chunkname -- runtime dependency declared in package.json and lazily loaded for webgpu support
192
199
  const { CreateMLCEngine, prebuiltAppConfig } = await import(
193
200
  /* webpackChunkName: "@atlaskit-internal_editor-plugin-autocomplete-mlc-web-llm" */ '@mlc-ai/web-llm'
194
201
  );
@@ -203,16 +210,16 @@ export const createLocalSlowLaneClient = (
203
210
  ...(customModelConfig.vramRequiredMB !== undefined
204
211
  ? {
205
212
  vram_required_MB: customModelConfig.vramRequiredMB,
206
- }
213
+ }
207
214
  : {}),
208
215
  ...(customModelConfig.contextWindowSize !== undefined
209
216
  ? {
210
217
  overrides: {
211
218
  context_window_size: customModelConfig.contextWindowSize,
212
219
  },
213
- }
220
+ }
214
221
  : {}),
215
- }
222
+ }
216
223
  : undefined;
217
224
 
218
225
  const appConfig: AppConfig = {
@@ -312,7 +319,7 @@ export const createLocalSlowLaneClient = (
312
319
  // Add the top token
313
320
  if (tokenLogprobs.token) {
314
321
  const token = tokenLogprobs.token.trim().toLowerCase();
315
- if (token.length > 0 && /^[a-z]/iu.test(token)) {
322
+ if (token.length > 0 && startsWithAsciiLetter(token)) {
316
323
  lmLogits[token] = Math.exp(tokenLogprobs.logprob);
317
324
  }
318
325
  }
@@ -321,7 +328,7 @@ export const createLocalSlowLaneClient = (
321
328
  if (tokenLogprobs.top_logprobs) {
322
329
  for (const alt of tokenLogprobs.top_logprobs) {
323
330
  const token = alt.token.trim().toLowerCase();
324
- if (token.length > 0 && /^[a-z]/iu.test(token)) {
331
+ if (token.length > 0 && startsWithAsciiLetter(token)) {
325
332
  lmLogits[token] = Math.exp(alt.logprob);
326
333
  }
327
334
  }