@unocss/autocomplete 0.58.6 → 0.58.7

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
@@ -116,59 +116,69 @@ function parseAutocomplete(template, theme = {}, extraShorthands = {}) {
116
116
  function suggest(input, matchType = "prefix") {
117
117
  if (input.length > 1 && matchType === "fuzzy")
118
118
  return fzf$1.find(input).map((i) => i.item);
119
- let rest = input;
120
- let matched = "";
121
- let combinations = [];
119
+ let rest = input.replace(/-/g, "");
120
+ let matched = [""];
121
+ let combinations = [""];
122
122
  const tempParts = [...parts];
123
123
  while (tempParts.length) {
124
124
  const part = tempParts.shift();
125
125
  if (part.type === "static") {
126
- if (combinations.length)
127
- combinations = combinations.map((i) => i + part.value);
128
- if (part.value.startsWith(rest) && part.value !== rest && !combinations.length) {
129
- combinations = [part.value];
130
- break;
131
- } else if (!rest.startsWith(part.value)) {
132
- break;
133
- }
134
- matched += part.value;
135
- rest = rest.slice(part.value.length);
126
+ const temp = part.value.replace(/-/g, "");
127
+ if (!rest.startsWith(temp) && !part.value.startsWith(rest))
128
+ return [""];
129
+ matched = matched.map((m) => m + part.value);
130
+ rest = rest.slice(temp.length);
136
131
  } else if (part.type === "group") {
137
132
  const fullMatched = part.values.find((i) => i && rest.startsWith(i));
138
- if (fullMatched != null) {
139
- matched += fullMatched;
133
+ if (fullMatched) {
134
+ matched = matched.map((m) => m + fullMatched);
140
135
  rest = rest.slice(fullMatched.length);
136
+ if (!tempParts[0] && rest)
137
+ return [];
138
+ continue;
141
139
  } else {
142
- combinations = part.values.filter((i) => i.startsWith(rest));
143
- if (tempParts[0]?.type !== "static")
140
+ if (tempParts[0]) {
141
+ const values = part.values.filter((i) => i && i.startsWith(rest));
142
+ rest = "";
143
+ if (values.length) {
144
+ matched = matched.map((m) => values.map((n) => m + n)).flat();
145
+ continue;
146
+ }
144
147
  break;
148
+ }
149
+ if (matched[0] === "")
150
+ break;
151
+ combinations = part.values.filter((p) => p.startsWith(rest));
152
+ break;
145
153
  }
146
154
  } else if (part.type === "theme") {
147
155
  const keys = part.objects.flatMap((i) => Object.keys(i)).filter((i) => i && !ignoredThemeKeys.includes(i) && i[0] !== "_");
148
156
  const fullMatched = keys.find((i) => i && rest.startsWith(i));
149
157
  if (fullMatched != null) {
150
- matched += fullMatched;
151
158
  rest = rest.slice(fullMatched.length);
152
159
  const subObjects = part.objects.map((i) => i[fullMatched]).filter((i) => !!i && typeof i === "object");
153
160
  if (subObjects.length) {
161
+ matched = matched.map((m) => `${m + fullMatched}-`);
154
162
  tempParts.unshift({
155
- type: "static",
156
- value: "-"
157
- }, {
158
163
  type: "theme",
159
164
  objects: subObjects
160
165
  });
166
+ } else {
167
+ combinations = keys.filter((i) => i.startsWith(rest));
161
168
  }
162
169
  } else {
163
- combinations = keys.filter((i) => i.startsWith(rest));
164
- if (tempParts[0]?.type !== "static")
165
- break;
170
+ if (tempParts[0] && tempParts[0].type !== "static") {
171
+ const values = tempParts[0].values;
172
+ if (values)
173
+ matched = matched.filter((i) => i && rest.startsWith(i)).map((m) => values.map((n) => m + n)).flat();
174
+ } else {
175
+ combinations = keys.filter((i) => i.startsWith(rest));
176
+ }
177
+ break;
166
178
  }
167
179
  }
168
180
  }
169
- if (combinations.length === 0)
170
- combinations.push("");
171
- return combinations.map((i) => matched + i).filter((i) => i.length >= input.length);
181
+ return combinations.map((i) => matched.map((m) => m + i)).flat().filter((i) => i.length >= input.length);
172
182
  }
173
183
  }
174
184
  function getValuesFromPartTemplate(part) {
@@ -242,7 +252,7 @@ function createAutocomplete(uno, options = {}) {
242
252
  return templateCache.get(template).suggest;
243
253
  }
244
254
  async function suggest(input, allowsEmptyInput = false) {
245
- if (!allowsEmptyInput && input.length < 2)
255
+ if (!allowsEmptyInput && input.length < 1)
246
256
  return [];
247
257
  if (cache.has(input))
248
258
  return cache.get(input);
package/dist/index.mjs CHANGED
@@ -114,59 +114,69 @@ function parseAutocomplete(template, theme = {}, extraShorthands = {}) {
114
114
  function suggest(input, matchType = "prefix") {
115
115
  if (input.length > 1 && matchType === "fuzzy")
116
116
  return fzf.find(input).map((i) => i.item);
117
- let rest = input;
118
- let matched = "";
119
- let combinations = [];
117
+ let rest = input.replace(/-/g, "");
118
+ let matched = [""];
119
+ let combinations = [""];
120
120
  const tempParts = [...parts];
121
121
  while (tempParts.length) {
122
122
  const part = tempParts.shift();
123
123
  if (part.type === "static") {
124
- if (combinations.length)
125
- combinations = combinations.map((i) => i + part.value);
126
- if (part.value.startsWith(rest) && part.value !== rest && !combinations.length) {
127
- combinations = [part.value];
128
- break;
129
- } else if (!rest.startsWith(part.value)) {
130
- break;
131
- }
132
- matched += part.value;
133
- rest = rest.slice(part.value.length);
124
+ const temp = part.value.replace(/-/g, "");
125
+ if (!rest.startsWith(temp) && !part.value.startsWith(rest))
126
+ return [""];
127
+ matched = matched.map((m) => m + part.value);
128
+ rest = rest.slice(temp.length);
134
129
  } else if (part.type === "group") {
135
130
  const fullMatched = part.values.find((i) => i && rest.startsWith(i));
136
- if (fullMatched != null) {
137
- matched += fullMatched;
131
+ if (fullMatched) {
132
+ matched = matched.map((m) => m + fullMatched);
138
133
  rest = rest.slice(fullMatched.length);
134
+ if (!tempParts[0] && rest)
135
+ return [];
136
+ continue;
139
137
  } else {
140
- combinations = part.values.filter((i) => i.startsWith(rest));
141
- if (tempParts[0]?.type !== "static")
138
+ if (tempParts[0]) {
139
+ const values = part.values.filter((i) => i && i.startsWith(rest));
140
+ rest = "";
141
+ if (values.length) {
142
+ matched = matched.map((m) => values.map((n) => m + n)).flat();
143
+ continue;
144
+ }
142
145
  break;
146
+ }
147
+ if (matched[0] === "")
148
+ break;
149
+ combinations = part.values.filter((p) => p.startsWith(rest));
150
+ break;
143
151
  }
144
152
  } else if (part.type === "theme") {
145
153
  const keys = part.objects.flatMap((i) => Object.keys(i)).filter((i) => i && !ignoredThemeKeys.includes(i) && i[0] !== "_");
146
154
  const fullMatched = keys.find((i) => i && rest.startsWith(i));
147
155
  if (fullMatched != null) {
148
- matched += fullMatched;
149
156
  rest = rest.slice(fullMatched.length);
150
157
  const subObjects = part.objects.map((i) => i[fullMatched]).filter((i) => !!i && typeof i === "object");
151
158
  if (subObjects.length) {
159
+ matched = matched.map((m) => `${m + fullMatched}-`);
152
160
  tempParts.unshift({
153
- type: "static",
154
- value: "-"
155
- }, {
156
161
  type: "theme",
157
162
  objects: subObjects
158
163
  });
164
+ } else {
165
+ combinations = keys.filter((i) => i.startsWith(rest));
159
166
  }
160
167
  } else {
161
- combinations = keys.filter((i) => i.startsWith(rest));
162
- if (tempParts[0]?.type !== "static")
163
- break;
168
+ if (tempParts[0] && tempParts[0].type !== "static") {
169
+ const values = tempParts[0].values;
170
+ if (values)
171
+ matched = matched.filter((i) => i && rest.startsWith(i)).map((m) => values.map((n) => m + n)).flat();
172
+ } else {
173
+ combinations = keys.filter((i) => i.startsWith(rest));
174
+ }
175
+ break;
164
176
  }
165
177
  }
166
178
  }
167
- if (combinations.length === 0)
168
- combinations.push("");
169
- return combinations.map((i) => matched + i).filter((i) => i.length >= input.length);
179
+ return combinations.map((i) => matched.map((m) => m + i)).flat().filter((i) => i.length >= input.length);
170
180
  }
171
181
  }
172
182
  function getValuesFromPartTemplate(part) {
@@ -240,7 +250,7 @@ function createAutocomplete(uno, options = {}) {
240
250
  return templateCache.get(template).suggest;
241
251
  }
242
252
  async function suggest(input, allowsEmptyInput = false) {
243
- if (!allowsEmptyInput && input.length < 2)
253
+ if (!allowsEmptyInput && input.length < 1)
244
254
  return [];
245
255
  if (cache.has(input))
246
256
  return cache.get(input);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unocss/autocomplete",
3
- "version": "0.58.6",
3
+ "version": "0.58.7",
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.2.0"
38
38
  },
39
39
  "devDependencies": {
40
- "@unocss/core": "0.58.6"
40
+ "@unocss/core": "0.58.7"
41
41
  },
42
42
  "scripts": {
43
43
  "build": "unbuild",