@lvce-editor/extension-search-view 4.7.0 → 4.9.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.
@@ -1281,9 +1281,22 @@ const Disabled = '@disabled';
1281
1281
  const Builtin = '@builtin';
1282
1282
  const Sort = '@sort';
1283
1283
  const Id = '@id';
1284
+ const Category = '@category';
1284
1285
  const Outdated = '@outdated';
1285
1286
 
1286
1287
  const RE_PARAM = /@\w+/g;
1288
+ const deserializeCategory = value => {
1289
+ if (value.startsWith(':"') && value.endsWith('"')) {
1290
+ return value.slice(2, -1);
1291
+ }
1292
+ if (value.startsWith('"') && value.endsWith('"')) {
1293
+ return value.slice(1, -1);
1294
+ }
1295
+ if (value.startsWith(':')) {
1296
+ return value.slice(1);
1297
+ }
1298
+ return value.trim();
1299
+ };
1287
1300
 
1288
1301
  // TODO test sorting and filtering
1289
1302
  const parseValue = value => {
@@ -1294,6 +1307,7 @@ const parseValue = value => {
1294
1307
  let sort = '';
1295
1308
  let id = '';
1296
1309
  let outdated = false;
1310
+ let category = '';
1297
1311
  // TODO this is not very functional code (assignment)
1298
1312
  const replaced = value.replaceAll(RE_PARAM, (match, by, order) => {
1299
1313
  if (match.startsWith(Installed)) {
@@ -1316,6 +1330,10 @@ const parseValue = value => {
1316
1330
  // TODO improve parsing
1317
1331
  id = value.replace('@id:', '');
1318
1332
  }
1333
+ if (match.startsWith(Category)) {
1334
+ const raw = value.replace('@category', '');
1335
+ category = deserializeCategory(raw);
1336
+ }
1319
1337
  if (match.startsWith(Outdated)) {
1320
1338
  outdated = true;
1321
1339
  }
@@ -1331,7 +1349,8 @@ const parseValue = value => {
1331
1349
  installed,
1332
1350
  id,
1333
1351
  sort,
1334
- isLocal
1352
+ isLocal,
1353
+ category
1335
1354
  };
1336
1355
  };
1337
1356
 
@@ -1343,10 +1362,18 @@ const matchesId = (extension, query) => {
1343
1362
  const extensionIdLower = extension.id.toLowerCase();
1344
1363
  return extensionIdLower.includes(query);
1345
1364
  };
1365
+ const matchesCategory = (extension, category) => {
1366
+ return extension && typeof extension === 'object' && 'categories' in extension && Array.isArray(extension.categories) && extension.categories.some(item => {
1367
+ return item.toLowerCase() === category;
1368
+ });
1369
+ };
1346
1370
  const matchesParsedValue = (extension, parsedValue) => {
1347
1371
  if (parsedValue.id && extension.id) {
1348
1372
  return parsedValue.id === extension.id;
1349
1373
  }
1374
+ if (parsedValue.category && matchesCategory(extension, parsedValue.category)) {
1375
+ return true;
1376
+ }
1350
1377
  if (extension.name) {
1351
1378
  return matchesName(extension, parsedValue.query);
1352
1379
  }
@@ -2749,6 +2776,15 @@ const getId$1 = extension => {
2749
2776
  }
2750
2777
  return extension.id;
2751
2778
  };
2779
+ const isString = item => {
2780
+ return typeof item === 'string';
2781
+ };
2782
+ const getCategories = extension => {
2783
+ if (!extension || !extension.categories || !Array.isArray(extension.categories)) {
2784
+ return [];
2785
+ }
2786
+ return extension.categories.filter(isString);
2787
+ };
2752
2788
 
2753
2789
  const RE_PUBLISHER = /^[a-z\d-]+/;
2754
2790
 
@@ -2772,7 +2808,8 @@ const normalizeExtension$1 = (extension, platform, assetDir) => {
2772
2808
  description: getDescription(extension),
2773
2809
  uri: '',
2774
2810
  publisher: getPublisher(extension),
2775
- icon: getIcon(extension, platform, assetDir)
2811
+ icon: getIcon(extension, platform, assetDir),
2812
+ categories: getCategories(extension)
2776
2813
  };
2777
2814
  };
2778
2815
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/extension-search-view",
3
- "version": "4.7.0",
3
+ "version": "4.9.0",
4
4
  "description": "Extension Search View Worker",
5
5
  "repository": {
6
6
  "type": "git",