@unocss/autocomplete 0.52.7 → 0.53.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/dist/index.cjs +11 -4
- package/dist/index.d.ts +2 -1
- package/dist/index.mjs +11 -5
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -145,6 +145,11 @@ function searchUsageBoundary(line, index) {
|
|
|
145
145
|
end
|
|
146
146
|
};
|
|
147
147
|
}
|
|
148
|
+
function searchAttrKey(content, cursor) {
|
|
149
|
+
const text = content.substring(0, cursor);
|
|
150
|
+
if (text.match(/(<\w+\s*)[^>]*$/) !== null)
|
|
151
|
+
return text.match(/\S+(?=\s*=\s*["']?[^"']*$)/)?.[0];
|
|
152
|
+
}
|
|
148
153
|
|
|
149
154
|
function createAutocomplete(uno) {
|
|
150
155
|
const templateCache = /* @__PURE__ */ new Map();
|
|
@@ -181,8 +186,8 @@ function createAutocomplete(uno) {
|
|
|
181
186
|
templateCache.set(template, parseAutocomplete(template, uno.config.theme));
|
|
182
187
|
return templateCache.get(template).suggest;
|
|
183
188
|
}
|
|
184
|
-
async function suggest(input) {
|
|
185
|
-
if (input.length < 2)
|
|
189
|
+
async function suggest(input, allowsEmptyInput = false) {
|
|
190
|
+
if (!allowsEmptyInput && input.length < 2)
|
|
186
191
|
return [];
|
|
187
192
|
if (cache.has(input))
|
|
188
193
|
return cache.get(input);
|
|
@@ -207,9 +212,10 @@ function createAutocomplete(uno) {
|
|
|
207
212
|
return result;
|
|
208
213
|
}
|
|
209
214
|
async function suggestInFile(content, cursor) {
|
|
215
|
+
const isInsideAttrValue = searchAttrKey(content, cursor) !== void 0;
|
|
210
216
|
const byExtractor = await searchUsageByExtractor(content, cursor);
|
|
211
217
|
if (byExtractor) {
|
|
212
|
-
const suggestions2 = await suggest(byExtractor.extracted);
|
|
218
|
+
const suggestions2 = await suggest(byExtractor.extracted, isInsideAttrValue);
|
|
213
219
|
const formatted = byExtractor.transformSuggestions ? byExtractor.transformSuggestions(suggestions2) : suggestions2;
|
|
214
220
|
return {
|
|
215
221
|
suggestions: suggestions2.map((v, i) => [v, formatted[i]]),
|
|
@@ -217,7 +223,7 @@ function createAutocomplete(uno) {
|
|
|
217
223
|
};
|
|
218
224
|
}
|
|
219
225
|
const regular = searchUsageBoundary(content, cursor);
|
|
220
|
-
const suggestions = await suggest(regular.content);
|
|
226
|
+
const suggestions = await suggest(regular.content, isInsideAttrValue);
|
|
221
227
|
return {
|
|
222
228
|
suggestions: suggestions.map((v) => [v, v]),
|
|
223
229
|
resolveReplacement: (suggestion) => ({
|
|
@@ -286,5 +292,6 @@ function createAutocomplete(uno) {
|
|
|
286
292
|
exports.createAutocomplete = createAutocomplete;
|
|
287
293
|
exports.ignoredThemeKeys = ignoredThemeKeys;
|
|
288
294
|
exports.parseAutocomplete = parseAutocomplete;
|
|
295
|
+
exports.searchAttrKey = searchAttrKey;
|
|
289
296
|
exports.searchUsageBoundary = searchUsageBoundary;
|
|
290
297
|
exports.shorthands = shorthands;
|
package/dist/index.d.ts
CHANGED
|
@@ -38,5 +38,6 @@ declare function searchUsageBoundary(line: string, index: number): {
|
|
|
38
38
|
start: number;
|
|
39
39
|
end: number;
|
|
40
40
|
};
|
|
41
|
+
declare function searchAttrKey(content: string, cursor: number): string | undefined;
|
|
41
42
|
|
|
42
|
-
export { AutocompleteTemplateGroup, AutocompleteTemplatePart, AutocompleteTemplateStatic, AutocompleteTemplateTheme, ParsedAutocompleteTemplate, UnocssAutocomplete, createAutocomplete, ignoredThemeKeys, parseAutocomplete, searchUsageBoundary, shorthands };
|
|
43
|
+
export { AutocompleteTemplateGroup, AutocompleteTemplatePart, AutocompleteTemplateStatic, AutocompleteTemplateTheme, ParsedAutocompleteTemplate, UnocssAutocomplete, createAutocomplete, ignoredThemeKeys, parseAutocomplete, searchAttrKey, searchUsageBoundary, shorthands };
|
package/dist/index.mjs
CHANGED
|
@@ -141,6 +141,11 @@ function searchUsageBoundary(line, index) {
|
|
|
141
141
|
end
|
|
142
142
|
};
|
|
143
143
|
}
|
|
144
|
+
function searchAttrKey(content, cursor) {
|
|
145
|
+
const text = content.substring(0, cursor);
|
|
146
|
+
if (text.match(/(<\w+\s*)[^>]*$/) !== null)
|
|
147
|
+
return text.match(/\S+(?=\s*=\s*["']?[^"']*$)/)?.[0];
|
|
148
|
+
}
|
|
144
149
|
|
|
145
150
|
function createAutocomplete(uno) {
|
|
146
151
|
const templateCache = /* @__PURE__ */ new Map();
|
|
@@ -177,8 +182,8 @@ function createAutocomplete(uno) {
|
|
|
177
182
|
templateCache.set(template, parseAutocomplete(template, uno.config.theme));
|
|
178
183
|
return templateCache.get(template).suggest;
|
|
179
184
|
}
|
|
180
|
-
async function suggest(input) {
|
|
181
|
-
if (input.length < 2)
|
|
185
|
+
async function suggest(input, allowsEmptyInput = false) {
|
|
186
|
+
if (!allowsEmptyInput && input.length < 2)
|
|
182
187
|
return [];
|
|
183
188
|
if (cache.has(input))
|
|
184
189
|
return cache.get(input);
|
|
@@ -203,9 +208,10 @@ function createAutocomplete(uno) {
|
|
|
203
208
|
return result;
|
|
204
209
|
}
|
|
205
210
|
async function suggestInFile(content, cursor) {
|
|
211
|
+
const isInsideAttrValue = searchAttrKey(content, cursor) !== void 0;
|
|
206
212
|
const byExtractor = await searchUsageByExtractor(content, cursor);
|
|
207
213
|
if (byExtractor) {
|
|
208
|
-
const suggestions2 = await suggest(byExtractor.extracted);
|
|
214
|
+
const suggestions2 = await suggest(byExtractor.extracted, isInsideAttrValue);
|
|
209
215
|
const formatted = byExtractor.transformSuggestions ? byExtractor.transformSuggestions(suggestions2) : suggestions2;
|
|
210
216
|
return {
|
|
211
217
|
suggestions: suggestions2.map((v, i) => [v, formatted[i]]),
|
|
@@ -213,7 +219,7 @@ function createAutocomplete(uno) {
|
|
|
213
219
|
};
|
|
214
220
|
}
|
|
215
221
|
const regular = searchUsageBoundary(content, cursor);
|
|
216
|
-
const suggestions = await suggest(regular.content);
|
|
222
|
+
const suggestions = await suggest(regular.content, isInsideAttrValue);
|
|
217
223
|
return {
|
|
218
224
|
suggestions: suggestions.map((v) => [v, v]),
|
|
219
225
|
resolveReplacement: (suggestion) => ({
|
|
@@ -279,4 +285,4 @@ function createAutocomplete(uno) {
|
|
|
279
285
|
}
|
|
280
286
|
}
|
|
281
287
|
|
|
282
|
-
export { createAutocomplete, ignoredThemeKeys, parseAutocomplete, searchUsageBoundary, shorthands };
|
|
288
|
+
export { createAutocomplete, ignoredThemeKeys, parseAutocomplete, searchAttrKey, searchUsageBoundary, shorthands };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unocss/autocomplete",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.53.1",
|
|
4
4
|
"description": "Autocomplete utils for UnoCSS",
|
|
5
5
|
"author": "Anthony Fu <anthonyfu117@hotmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -33,10 +33,10 @@
|
|
|
33
33
|
"dist"
|
|
34
34
|
],
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"lru-cache": "^9.1.
|
|
36
|
+
"lru-cache": "^9.1.2"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@unocss/core": "0.
|
|
39
|
+
"@unocss/core": "0.53.1"
|
|
40
40
|
},
|
|
41
41
|
"scripts": {
|
|
42
42
|
"build": "unbuild",
|