@unocss/autocomplete 0.59.0-beta.1 → 0.59.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/dist/index.d.mts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.mjs +42 -7
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -24,7 +24,7 @@ interface ParsedAutocompleteTemplate {
|
|
|
24
24
|
}
|
|
25
25
|
interface UnocssAutocomplete {
|
|
26
26
|
suggest: (input: string, allowsEmptyInput?: boolean) => Promise<string[]>;
|
|
27
|
-
suggestInFile: (content: string, cursor: number) => Promise<SuggestResult>;
|
|
27
|
+
suggestInFile: (content: string, cursor: number) => Promise<SuggestResult | undefined>;
|
|
28
28
|
templates: (string | AutoCompleteFunction)[];
|
|
29
29
|
cache: LRUCache<string, string[]>;
|
|
30
30
|
reset: () => void;
|
|
@@ -37,11 +37,11 @@ declare const shorthands: Record<string, string>;
|
|
|
37
37
|
declare const ignoredThemeKeys: string[];
|
|
38
38
|
declare function parseAutocomplete(template: string, theme?: any, extraShorthands?: Record<string, string>): ParsedAutocompleteTemplate;
|
|
39
39
|
|
|
40
|
-
declare function searchUsageBoundary(line: string, index: number): {
|
|
40
|
+
declare function searchUsageBoundary(line: string, index: number, attributify?: boolean): {
|
|
41
41
|
content: string;
|
|
42
42
|
start: number;
|
|
43
43
|
end: number;
|
|
44
|
-
};
|
|
44
|
+
} | undefined;
|
|
45
45
|
declare function searchAttrKey(content: string, cursor: number): string | undefined;
|
|
46
46
|
declare function cartesian<T>(arr: T[][]): T[][];
|
|
47
47
|
|
package/dist/index.d.ts
CHANGED
|
@@ -24,7 +24,7 @@ interface ParsedAutocompleteTemplate {
|
|
|
24
24
|
}
|
|
25
25
|
interface UnocssAutocomplete {
|
|
26
26
|
suggest: (input: string, allowsEmptyInput?: boolean) => Promise<string[]>;
|
|
27
|
-
suggestInFile: (content: string, cursor: number) => Promise<SuggestResult>;
|
|
27
|
+
suggestInFile: (content: string, cursor: number) => Promise<SuggestResult | undefined>;
|
|
28
28
|
templates: (string | AutoCompleteFunction)[];
|
|
29
29
|
cache: LRUCache<string, string[]>;
|
|
30
30
|
reset: () => void;
|
|
@@ -37,11 +37,11 @@ declare const shorthands: Record<string, string>;
|
|
|
37
37
|
declare const ignoredThemeKeys: string[];
|
|
38
38
|
declare function parseAutocomplete(template: string, theme?: any, extraShorthands?: Record<string, string>): ParsedAutocompleteTemplate;
|
|
39
39
|
|
|
40
|
-
declare function searchUsageBoundary(line: string, index: number): {
|
|
40
|
+
declare function searchUsageBoundary(line: string, index: number, attributify?: boolean): {
|
|
41
41
|
content: string;
|
|
42
42
|
start: number;
|
|
43
43
|
end: number;
|
|
44
|
-
};
|
|
44
|
+
} | undefined;
|
|
45
45
|
declare function searchAttrKey(content: string, cursor: number): string | undefined;
|
|
46
46
|
declare function cartesian<T>(arr: T[][]): T[][];
|
|
47
47
|
|
package/dist/index.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import { uniq, escapeRegExp, toArray } from '@unocss/core';
|
|
|
2
2
|
import { LRUCache } from 'lru-cache';
|
|
3
3
|
import { Fzf, byStartAsc, byLengthAsc } from 'fzf';
|
|
4
4
|
|
|
5
|
-
function searchUsageBoundary(line, index) {
|
|
5
|
+
function searchUsageBoundary(line, index, attributify = true) {
|
|
6
6
|
let start = index;
|
|
7
7
|
let end = index;
|
|
8
8
|
const regex = /[^\s>"'`;]/;
|
|
@@ -10,11 +10,40 @@ function searchUsageBoundary(line, index) {
|
|
|
10
10
|
--start;
|
|
11
11
|
while (end < line.length && regex.test(line.charAt(end)))
|
|
12
12
|
++end;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
if (attributify) {
|
|
14
|
+
return {
|
|
15
|
+
content: line.slice(start, end),
|
|
16
|
+
start,
|
|
17
|
+
end
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
let temp = start - 1;
|
|
21
|
+
const matchClassText = "class";
|
|
22
|
+
const matchClassNameText = "className";
|
|
23
|
+
while (temp > matchClassText.length && !/[="{}><]/.test(line[temp--])) {
|
|
24
|
+
}
|
|
25
|
+
if (line[temp] !== "=")
|
|
26
|
+
return;
|
|
27
|
+
if (temp > matchClassNameText.length) {
|
|
28
|
+
const data = line.slice(temp - matchClassNameText.length, temp);
|
|
29
|
+
if (data === matchClassNameText) {
|
|
30
|
+
return {
|
|
31
|
+
content: line.slice(start, end),
|
|
32
|
+
start,
|
|
33
|
+
end
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
if (temp > matchClassText.length) {
|
|
38
|
+
const data = line.slice(temp - matchClassText.length, temp);
|
|
39
|
+
if (data === matchClassText) {
|
|
40
|
+
return {
|
|
41
|
+
content: line.slice(start, end),
|
|
42
|
+
start,
|
|
43
|
+
end
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
}
|
|
18
47
|
}
|
|
19
48
|
function searchAttrKey(content, cursor) {
|
|
20
49
|
const text = content.substring(0, cursor);
|
|
@@ -291,7 +320,13 @@ function createAutocomplete(uno, options = {}) {
|
|
|
291
320
|
resolveReplacement: byExtractor.resolveReplacement
|
|
292
321
|
};
|
|
293
322
|
}
|
|
294
|
-
const regular = searchUsageBoundary(
|
|
323
|
+
const regular = searchUsageBoundary(
|
|
324
|
+
content,
|
|
325
|
+
cursor,
|
|
326
|
+
(uno.config.presets || []).some((i) => i.name === "@unocss/preset-attributify")
|
|
327
|
+
);
|
|
328
|
+
if (!regular)
|
|
329
|
+
return;
|
|
295
330
|
const suggestions = await suggest(regular.content, isInsideAttrValue);
|
|
296
331
|
return {
|
|
297
332
|
suggestions: suggestions.map((v) => [v, v]),
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unocss/autocomplete",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.59.0
|
|
4
|
+
"version": "0.59.0",
|
|
5
5
|
"description": "Autocomplete utils for UnoCSS",
|
|
6
6
|
"author": "Anthony Fu <anthonyfu117@hotmail.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"lru-cache": "^10.2.0"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@unocss/core": "0.59.0
|
|
40
|
+
"@unocss/core": "0.59.0"
|
|
41
41
|
},
|
|
42
42
|
"scripts": {
|
|
43
43
|
"build": "unbuild",
|