@atlaskit/editor-plugin-autocomplete 3.6.2 → 4.0.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,44 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-autocomplete
|
|
2
2
|
|
|
3
|
+
## 4.0.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`560ddb7a914f6`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/560ddb7a914f6) -
|
|
8
|
+
[ux] Fixes a bug where autocomplete suggestions were shown when the cursor was positioned in the
|
|
9
|
+
middle of an existing word. Suggestions are now suppressed unless the cursor is at the trailing
|
|
10
|
+
edge of a token.
|
|
11
|
+
- Updated dependencies
|
|
12
|
+
|
|
13
|
+
## 4.0.0
|
|
14
|
+
|
|
15
|
+
### Major Changes
|
|
16
|
+
|
|
17
|
+
- [`f2dc9097319f0`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/f2dc9097319f0) - ###
|
|
18
|
+
Dropped support for _legacy_ Typescript 4 types. **Typescript 5 is now the new minimum**.
|
|
19
|
+
|
|
20
|
+
Removes the `typesVersions` property and `dist/types-ts4.5` directory from the dist.
|
|
21
|
+
|
|
22
|
+
Types are now exclusively via the `"types": "dist/types/index.d.ts"` property.
|
|
23
|
+
|
|
24
|
+
```diff
|
|
25
|
+
- "typesVersions": {
|
|
26
|
+
- ">=4.5 <4.9": {
|
|
27
|
+
- "*": [
|
|
28
|
+
- "dist/types-ts4.5/*",
|
|
29
|
+
- "dist/types-ts4.5/index.d.ts"
|
|
30
|
+
- ]
|
|
31
|
+
- }
|
|
32
|
+
- },
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Patch Changes
|
|
36
|
+
|
|
37
|
+
- [`f92001e22291e`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/f92001e22291e) -
|
|
38
|
+
Reverts the mid-word cursor suppression for ghost-text suggestions. Autocomplete suggestions will
|
|
39
|
+
again appear regardless of cursor position within a word.
|
|
40
|
+
- Updated dependencies
|
|
41
|
+
|
|
3
42
|
## 3.6.2
|
|
4
43
|
|
|
5
44
|
### Patch Changes
|
|
@@ -188,6 +188,38 @@ var buildSlowLaneText = function buildSlowLaneText(docText, context) {
|
|
|
188
188
|
lines.push("reply ".concat(nextReplyNumber, ": ").concat(docText));
|
|
189
189
|
return lines.join('\n');
|
|
190
190
|
};
|
|
191
|
+
var createMidWordCharacterRegex = function createMidWordCharacterRegex() {
|
|
192
|
+
try {
|
|
193
|
+
// string-built regex avoids TS1501 under the package's ES5 build target
|
|
194
|
+
return new RegExp('[\\p{L}\\p{N}_]', 'u');
|
|
195
|
+
} catch (_unused) {
|
|
196
|
+
return null;
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
var midWordCharacterRegex = createMidWordCharacterRegex();
|
|
200
|
+
var isAsciiWordCharacter = function isAsciiWordCharacter(char) {
|
|
201
|
+
if (char === '_') {
|
|
202
|
+
return true;
|
|
203
|
+
}
|
|
204
|
+
var charCode = char.charCodeAt(0);
|
|
205
|
+
return charCode >= 48 && charCode <= 57 || charCode >= 65 && charCode <= 90 || charCode >= 97 && charCode <= 122;
|
|
206
|
+
};
|
|
207
|
+
var isMidWordCharacter = function isMidWordCharacter(char) {
|
|
208
|
+
if (midWordCharacterRegex) {
|
|
209
|
+
return midWordCharacterRegex.test(char);
|
|
210
|
+
}
|
|
211
|
+
if (isAsciiWordCharacter(char)) {
|
|
212
|
+
return true;
|
|
213
|
+
}
|
|
214
|
+
return char.toLocaleLowerCase() !== char.toLocaleUpperCase();
|
|
215
|
+
};
|
|
216
|
+
var getLeadingTextCharacter = function getLeadingTextCharacter(text) {
|
|
217
|
+
var firstCodePoint = text === null || text === void 0 ? void 0 : text.codePointAt(0);
|
|
218
|
+
if (firstCodePoint === undefined) {
|
|
219
|
+
return undefined;
|
|
220
|
+
}
|
|
221
|
+
return String.fromCodePoint(firstCodePoint);
|
|
222
|
+
};
|
|
191
223
|
var getTypedLengthForPrediction = function getTypedLengthForPrediction(textBefore) {
|
|
192
224
|
var _textBefore$match$, _textBefore$match;
|
|
193
225
|
if ((0, _slowLaneClient.isWordBoundary)(textBefore)) {
|
|
@@ -435,7 +467,6 @@ var createAutocompletePlugin = exports.createAutocompletePlugin = function creat
|
|
|
435
467
|
}
|
|
436
468
|
debounceTimer = setTimeout(function () {
|
|
437
469
|
try {
|
|
438
|
-
var _nodeAfter$text;
|
|
439
470
|
var state = view.state;
|
|
440
471
|
var selection = state.selection;
|
|
441
472
|
if (!selection.empty) {
|
|
@@ -447,11 +478,11 @@ var createAutocompletePlugin = exports.createAutocompletePlugin = function creat
|
|
|
447
478
|
// nodeAfter correctly handles inline atoms (mentions, emojis) where
|
|
448
479
|
// parentOffset and textContent indices diverge.
|
|
449
480
|
var nodeAfter = selection.$from.nodeAfter;
|
|
450
|
-
var charAfterCursor = nodeAfter !== null && nodeAfter !== void 0 && nodeAfter.isText ? (
|
|
481
|
+
var charAfterCursor = nodeAfter !== null && nodeAfter !== void 0 && nodeAfter.isText ? getLeadingTextCharacter(nodeAfter.text) : undefined;
|
|
451
482
|
// Only suppress for Unicode letters, digits, and underscore — hyphens,
|
|
452
483
|
// apostrophes, and similar punctuation are valid left-edge boundaries
|
|
453
484
|
// and should not block suggestions (e.g. cursor before '-' in compound-word).
|
|
454
|
-
if (charAfterCursor &&
|
|
485
|
+
if (charAfterCursor && isMidWordCharacter(charAfterCursor)) {
|
|
455
486
|
return;
|
|
456
487
|
}
|
|
457
488
|
var textBefore = getTextBeforeCursor(state);
|
|
@@ -176,6 +176,38 @@ const buildSlowLaneText = (docText, context) => {
|
|
|
176
176
|
lines.push(`reply ${nextReplyNumber}: ${docText}`);
|
|
177
177
|
return lines.join('\n');
|
|
178
178
|
};
|
|
179
|
+
const createMidWordCharacterRegex = () => {
|
|
180
|
+
try {
|
|
181
|
+
// string-built regex avoids TS1501 under the package's ES5 build target
|
|
182
|
+
return new RegExp('[\\p{L}\\p{N}_]', 'u');
|
|
183
|
+
} catch {
|
|
184
|
+
return null;
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
const midWordCharacterRegex = createMidWordCharacterRegex();
|
|
188
|
+
const isAsciiWordCharacter = char => {
|
|
189
|
+
if (char === '_') {
|
|
190
|
+
return true;
|
|
191
|
+
}
|
|
192
|
+
const charCode = char.charCodeAt(0);
|
|
193
|
+
return charCode >= 48 && charCode <= 57 || charCode >= 65 && charCode <= 90 || charCode >= 97 && charCode <= 122;
|
|
194
|
+
};
|
|
195
|
+
const isMidWordCharacter = char => {
|
|
196
|
+
if (midWordCharacterRegex) {
|
|
197
|
+
return midWordCharacterRegex.test(char);
|
|
198
|
+
}
|
|
199
|
+
if (isAsciiWordCharacter(char)) {
|
|
200
|
+
return true;
|
|
201
|
+
}
|
|
202
|
+
return char.toLocaleLowerCase() !== char.toLocaleUpperCase();
|
|
203
|
+
};
|
|
204
|
+
const getLeadingTextCharacter = text => {
|
|
205
|
+
const firstCodePoint = text === null || text === void 0 ? void 0 : text.codePointAt(0);
|
|
206
|
+
if (firstCodePoint === undefined) {
|
|
207
|
+
return undefined;
|
|
208
|
+
}
|
|
209
|
+
return String.fromCodePoint(firstCodePoint);
|
|
210
|
+
};
|
|
179
211
|
const getTypedLengthForPrediction = textBefore => {
|
|
180
212
|
var _textBefore$match$, _textBefore$match;
|
|
181
213
|
if (isWordBoundary(textBefore)) {
|
|
@@ -415,7 +447,6 @@ export const createAutocompletePlugin = (options, api) => {
|
|
|
415
447
|
}
|
|
416
448
|
debounceTimer = setTimeout(() => {
|
|
417
449
|
try {
|
|
418
|
-
var _nodeAfter$text;
|
|
419
450
|
const {
|
|
420
451
|
state
|
|
421
452
|
} = view;
|
|
@@ -431,11 +462,11 @@ export const createAutocompletePlugin = (options, api) => {
|
|
|
431
462
|
// nodeAfter correctly handles inline atoms (mentions, emojis) where
|
|
432
463
|
// parentOffset and textContent indices diverge.
|
|
433
464
|
const nodeAfter = selection.$from.nodeAfter;
|
|
434
|
-
const charAfterCursor = nodeAfter !== null && nodeAfter !== void 0 && nodeAfter.isText ? (
|
|
465
|
+
const charAfterCursor = nodeAfter !== null && nodeAfter !== void 0 && nodeAfter.isText ? getLeadingTextCharacter(nodeAfter.text) : undefined;
|
|
435
466
|
// Only suppress for Unicode letters, digits, and underscore — hyphens,
|
|
436
467
|
// apostrophes, and similar punctuation are valid left-edge boundaries
|
|
437
468
|
// and should not block suggestions (e.g. cursor before '-' in compound-word).
|
|
438
|
-
if (charAfterCursor &&
|
|
469
|
+
if (charAfterCursor && isMidWordCharacter(charAfterCursor)) {
|
|
439
470
|
return;
|
|
440
471
|
}
|
|
441
472
|
const textBefore = getTextBeforeCursor(state);
|
|
@@ -181,6 +181,38 @@ var buildSlowLaneText = function buildSlowLaneText(docText, context) {
|
|
|
181
181
|
lines.push("reply ".concat(nextReplyNumber, ": ").concat(docText));
|
|
182
182
|
return lines.join('\n');
|
|
183
183
|
};
|
|
184
|
+
var createMidWordCharacterRegex = function createMidWordCharacterRegex() {
|
|
185
|
+
try {
|
|
186
|
+
// string-built regex avoids TS1501 under the package's ES5 build target
|
|
187
|
+
return new RegExp('[\\p{L}\\p{N}_]', 'u');
|
|
188
|
+
} catch (_unused) {
|
|
189
|
+
return null;
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
var midWordCharacterRegex = createMidWordCharacterRegex();
|
|
193
|
+
var isAsciiWordCharacter = function isAsciiWordCharacter(char) {
|
|
194
|
+
if (char === '_') {
|
|
195
|
+
return true;
|
|
196
|
+
}
|
|
197
|
+
var charCode = char.charCodeAt(0);
|
|
198
|
+
return charCode >= 48 && charCode <= 57 || charCode >= 65 && charCode <= 90 || charCode >= 97 && charCode <= 122;
|
|
199
|
+
};
|
|
200
|
+
var isMidWordCharacter = function isMidWordCharacter(char) {
|
|
201
|
+
if (midWordCharacterRegex) {
|
|
202
|
+
return midWordCharacterRegex.test(char);
|
|
203
|
+
}
|
|
204
|
+
if (isAsciiWordCharacter(char)) {
|
|
205
|
+
return true;
|
|
206
|
+
}
|
|
207
|
+
return char.toLocaleLowerCase() !== char.toLocaleUpperCase();
|
|
208
|
+
};
|
|
209
|
+
var getLeadingTextCharacter = function getLeadingTextCharacter(text) {
|
|
210
|
+
var firstCodePoint = text === null || text === void 0 ? void 0 : text.codePointAt(0);
|
|
211
|
+
if (firstCodePoint === undefined) {
|
|
212
|
+
return undefined;
|
|
213
|
+
}
|
|
214
|
+
return String.fromCodePoint(firstCodePoint);
|
|
215
|
+
};
|
|
184
216
|
var getTypedLengthForPrediction = function getTypedLengthForPrediction(textBefore) {
|
|
185
217
|
var _textBefore$match$, _textBefore$match;
|
|
186
218
|
if (isWordBoundary(textBefore)) {
|
|
@@ -428,7 +460,6 @@ export var createAutocompletePlugin = function createAutocompletePlugin(options,
|
|
|
428
460
|
}
|
|
429
461
|
debounceTimer = setTimeout(function () {
|
|
430
462
|
try {
|
|
431
|
-
var _nodeAfter$text;
|
|
432
463
|
var state = view.state;
|
|
433
464
|
var selection = state.selection;
|
|
434
465
|
if (!selection.empty) {
|
|
@@ -440,11 +471,11 @@ export var createAutocompletePlugin = function createAutocompletePlugin(options,
|
|
|
440
471
|
// nodeAfter correctly handles inline atoms (mentions, emojis) where
|
|
441
472
|
// parentOffset and textContent indices diverge.
|
|
442
473
|
var nodeAfter = selection.$from.nodeAfter;
|
|
443
|
-
var charAfterCursor = nodeAfter !== null && nodeAfter !== void 0 && nodeAfter.isText ? (
|
|
474
|
+
var charAfterCursor = nodeAfter !== null && nodeAfter !== void 0 && nodeAfter.isText ? getLeadingTextCharacter(nodeAfter.text) : undefined;
|
|
444
475
|
// Only suppress for Unicode letters, digits, and underscore — hyphens,
|
|
445
476
|
// apostrophes, and similar punctuation are valid left-edge boundaries
|
|
446
477
|
// and should not block suggestions (e.g. cursor before '-' in compound-word).
|
|
447
|
-
if (charAfterCursor &&
|
|
478
|
+
if (charAfterCursor && isMidWordCharacter(charAfterCursor)) {
|
|
448
479
|
return;
|
|
449
480
|
}
|
|
450
481
|
var textBefore = getTextBeforeCursor(state);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-autocomplete",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.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",
|
|
@@ -16,27 +16,19 @@
|
|
|
16
16
|
"module": "dist/esm/index.js",
|
|
17
17
|
"module:es2019": "dist/es2019/index.js",
|
|
18
18
|
"types": "dist/types/index.d.ts",
|
|
19
|
-
"typesVersions": {
|
|
20
|
-
">=4.5 <4.9": {
|
|
21
|
-
"*": [
|
|
22
|
-
"dist/types-ts4.5/*",
|
|
23
|
-
"dist/types-ts4.5/index.d.ts"
|
|
24
|
-
]
|
|
25
|
-
}
|
|
26
|
-
},
|
|
27
19
|
"sideEffects": false,
|
|
28
20
|
"atlaskit:src": "src/index.ts",
|
|
29
21
|
"dependencies": {
|
|
30
|
-
"@atlaskit/editor-prosemirror": "^
|
|
31
|
-
"@atlaskit/ufo": "^0.
|
|
22
|
+
"@atlaskit/editor-prosemirror": "^8.0.0",
|
|
23
|
+
"@atlaskit/ufo": "^1.0.0",
|
|
32
24
|
"@babel/runtime": "^7.0.0",
|
|
33
25
|
"@mlc-ai/web-llm": "^0.2.78",
|
|
34
26
|
"compromise": "^14.15.0",
|
|
35
27
|
"wink-nlp": "^2.4.0"
|
|
36
28
|
},
|
|
37
29
|
"peerDependencies": {
|
|
38
|
-
"@atlaskit/editor-common": "^
|
|
39
|
-
"@atlaskit/editor-plugin-analytics": "^
|
|
30
|
+
"@atlaskit/editor-common": "^116.4.0",
|
|
31
|
+
"@atlaskit/editor-plugin-analytics": "^12.0.0",
|
|
40
32
|
"react": "^18.2.0"
|
|
41
33
|
},
|
|
42
34
|
"techstack": {
|
|
@@ -243,6 +243,52 @@ const buildSlowLaneText = (docText: string, context?: AutocompleteContext): stri
|
|
|
243
243
|
return lines.join('\n');
|
|
244
244
|
};
|
|
245
245
|
|
|
246
|
+
const createMidWordCharacterRegex = (): RegExp | null => {
|
|
247
|
+
try {
|
|
248
|
+
// string-built regex avoids TS1501 under the package's ES5 build target
|
|
249
|
+
return new RegExp('[\\p{L}\\p{N}_]', 'u');
|
|
250
|
+
} catch {
|
|
251
|
+
return null;
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
const midWordCharacterRegex = createMidWordCharacterRegex();
|
|
256
|
+
|
|
257
|
+
const isAsciiWordCharacter = (char: string): boolean => {
|
|
258
|
+
if (char === '_') {
|
|
259
|
+
return true;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
const charCode = char.charCodeAt(0);
|
|
263
|
+
return (
|
|
264
|
+
(charCode >= 48 && charCode <= 57) ||
|
|
265
|
+
(charCode >= 65 && charCode <= 90) ||
|
|
266
|
+
(charCode >= 97 && charCode <= 122)
|
|
267
|
+
);
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
const isMidWordCharacter = (char: string): boolean => {
|
|
271
|
+
if (midWordCharacterRegex) {
|
|
272
|
+
return midWordCharacterRegex.test(char);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
if (isAsciiWordCharacter(char)) {
|
|
276
|
+
return true;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
return char.toLocaleLowerCase() !== char.toLocaleUpperCase();
|
|
280
|
+
};
|
|
281
|
+
|
|
282
|
+
const getLeadingTextCharacter = (text?: string): string | undefined => {
|
|
283
|
+
const firstCodePoint = text?.codePointAt(0);
|
|
284
|
+
|
|
285
|
+
if (firstCodePoint === undefined) {
|
|
286
|
+
return undefined;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
return String.fromCodePoint(firstCodePoint);
|
|
290
|
+
};
|
|
291
|
+
|
|
246
292
|
const getTypedLengthForPrediction = (textBefore: string): number => {
|
|
247
293
|
if (isWordBoundary(textBefore)) {
|
|
248
294
|
return 0;
|
|
@@ -519,11 +565,11 @@ export const createAutocompletePlugin = (
|
|
|
519
565
|
// nodeAfter correctly handles inline atoms (mentions, emojis) where
|
|
520
566
|
// parentOffset and textContent indices diverge.
|
|
521
567
|
const nodeAfter = selection.$from.nodeAfter;
|
|
522
|
-
const charAfterCursor = nodeAfter?.isText ? nodeAfter.text
|
|
568
|
+
const charAfterCursor = nodeAfter?.isText ? getLeadingTextCharacter(nodeAfter.text) : undefined;
|
|
523
569
|
// Only suppress for Unicode letters, digits, and underscore — hyphens,
|
|
524
570
|
// apostrophes, and similar punctuation are valid left-edge boundaries
|
|
525
571
|
// and should not block suggestions (e.g. cursor before '-' in compound-word).
|
|
526
|
-
if (charAfterCursor &&
|
|
572
|
+
if (charAfterCursor && isMidWordCharacter(charAfterCursor)) {
|
|
527
573
|
return;
|
|
528
574
|
}
|
|
529
575
|
|