@unocss/autocomplete 0.54.0 → 0.54.2

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 CHANGED
@@ -26,8 +26,6 @@ function searchAttrKey(content, cursor) {
26
26
  return text.match(/\S+(?=\s*=\s*["']?[^"']*$)/)?.[0];
27
27
  }
28
28
  function cartesian(arr) {
29
- if (arr.length < 2)
30
- return arr;
31
29
  return arr.reduce(
32
30
  (a, b) => {
33
31
  const ret = [];
@@ -60,12 +58,16 @@ function handleRegexMatch(str, regex, onMatched, onNotMatched) {
60
58
  if (lastIndex !== str.length)
61
59
  onNotMatched(str.slice(lastIndex), lastIndex, str.length);
62
60
  }
63
- function parseAutocomplete(template, theme = {}) {
61
+ function parseAutocomplete(template, theme = {}, extraShorthands = {}) {
64
62
  const parts = [];
63
+ const newShorthands = {
64
+ ...shorthands,
65
+ ...extraShorthands
66
+ };
65
67
  template = template.replace(/<(\w+)>/g, (_, key) => {
66
- if (!shorthands[key])
68
+ if (!newShorthands[key])
67
69
  throw new Error(`Unknown template shorthand: ${key}`);
68
- return shorthands[key];
70
+ return newShorthands[key];
69
71
  });
70
72
  handleGroups(template);
71
73
  const fzf$1 = new fzf.Fzf(getAllCombination(parts));
@@ -234,7 +236,7 @@ function createAutocomplete(uno, options = {}) {
234
236
  }
235
237
  function getParsed(template) {
236
238
  if (!templateCache.has(template))
237
- templateCache.set(template, parseAutocomplete(template, uno.config.theme));
239
+ templateCache.set(template, parseAutocomplete(template, uno.config.theme, uno.config.autocomplete.shorthands));
238
240
  return templateCache.get(template).suggest;
239
241
  }
240
242
  async function suggest(input, allowsEmptyInput = false) {
package/dist/index.d.ts CHANGED
@@ -35,7 +35,7 @@ declare function createAutocomplete(uno: UnoGenerator, options?: AutocompleteOpt
35
35
 
36
36
  declare const shorthands: Record<string, string>;
37
37
  declare const ignoredThemeKeys: string[];
38
- declare function parseAutocomplete(template: string, theme?: any): ParsedAutocompleteTemplate;
38
+ declare function parseAutocomplete(template: string, theme?: any, extraShorthands?: Record<string, string>): ParsedAutocompleteTemplate;
39
39
 
40
40
  declare function searchUsageBoundary(line: string, index: number): {
41
41
  content: string;
package/dist/index.mjs CHANGED
@@ -22,8 +22,6 @@ function searchAttrKey(content, cursor) {
22
22
  return text.match(/\S+(?=\s*=\s*["']?[^"']*$)/)?.[0];
23
23
  }
24
24
  function cartesian(arr) {
25
- if (arr.length < 2)
26
- return arr;
27
25
  return arr.reduce(
28
26
  (a, b) => {
29
27
  const ret = [];
@@ -56,12 +54,16 @@ function handleRegexMatch(str, regex, onMatched, onNotMatched) {
56
54
  if (lastIndex !== str.length)
57
55
  onNotMatched(str.slice(lastIndex), lastIndex, str.length);
58
56
  }
59
- function parseAutocomplete(template, theme = {}) {
57
+ function parseAutocomplete(template, theme = {}, extraShorthands = {}) {
60
58
  const parts = [];
59
+ const newShorthands = {
60
+ ...shorthands,
61
+ ...extraShorthands
62
+ };
61
63
  template = template.replace(/<(\w+)>/g, (_, key) => {
62
- if (!shorthands[key])
64
+ if (!newShorthands[key])
63
65
  throw new Error(`Unknown template shorthand: ${key}`);
64
- return shorthands[key];
66
+ return newShorthands[key];
65
67
  });
66
68
  handleGroups(template);
67
69
  const fzf = new Fzf(getAllCombination(parts));
@@ -230,7 +232,7 @@ function createAutocomplete(uno, options = {}) {
230
232
  }
231
233
  function getParsed(template) {
232
234
  if (!templateCache.has(template))
233
- templateCache.set(template, parseAutocomplete(template, uno.config.theme));
235
+ templateCache.set(template, parseAutocomplete(template, uno.config.theme, uno.config.autocomplete.shorthands));
234
236
  return templateCache.get(template).suggest;
235
237
  }
236
238
  async function suggest(input, allowsEmptyInput = false) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unocss/autocomplete",
3
- "version": "0.54.0",
3
+ "version": "0.54.2",
4
4
  "description": "Autocomplete utils for UnoCSS",
5
5
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
6
6
  "license": "MIT",
@@ -37,7 +37,7 @@
37
37
  "lru-cache": "^10.0.0"
38
38
  },
39
39
  "devDependencies": {
40
- "@unocss/core": "0.54.0"
40
+ "@unocss/core": "0.54.2"
41
41
  },
42
42
  "scripts": {
43
43
  "build": "unbuild",