@lvce-editor/file-search-worker 3.7.0 → 3.8.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.
@@ -1001,7 +1001,7 @@ const prefixIdWithExt = item => {
1001
1001
  const getExtensionPicks = async () => {
1002
1002
  try {
1003
1003
  // TODO don't call this every time
1004
- const extensionPicks = await invoke$1('ExtensionHostCommands.getCommands');
1004
+ const extensionPicks = await invoke$1('ExtensionHost.getCommands');
1005
1005
  if (!extensionPicks) {
1006
1006
  return [];
1007
1007
  }
@@ -1090,6 +1090,9 @@ const execute = async (method, ...params) => {
1090
1090
  // TODO
1091
1091
  };
1092
1092
 
1093
+ const Directory$1 = 3;
1094
+ const File$2 = 7;
1095
+
1093
1096
  const RE_PROTOCOL = /^([a-z-]+):\/\//;
1094
1097
  const getProtocol = uri => {
1095
1098
  const protocolMatch = uri.match(RE_PROTOCOL);
@@ -1103,9 +1106,6 @@ const Memfs = 'memfs';
1103
1106
  const Html = 'html';
1104
1107
  const Fetch = 'fetch';
1105
1108
 
1106
- const Directory$1 = 3;
1107
- const File$2 = 7;
1108
-
1109
1109
  class FileNotFoundError extends Error {
1110
1110
  constructor(uri) {
1111
1111
  super(`File not found: ${uri}`);
@@ -1877,18 +1877,34 @@ const filterQuickPickItem = (pattern, word) => {
1877
1877
  return matches;
1878
1878
  };
1879
1879
 
1880
- const getBaseName = path => {
1880
+ // TODO this should be in FileSystem module
1881
+ const pathBaseName = path => {
1881
1882
  return path.slice(path.lastIndexOf('/') + 1);
1882
1883
  };
1883
1884
 
1884
- const filterQuickPickItems = (items, value) => {
1885
+ // TODO this should be in FileSystem module
1886
+ const pathDirName = path => {
1887
+ const pathSeparator = '/';
1888
+ const index = path.lastIndexOf(pathSeparator);
1889
+ if (index === -1) {
1890
+ return '';
1891
+ }
1892
+ return path.slice(0, index);
1893
+ };
1894
+
1895
+ const filterQuickPickItems = (items, value, provider) => {
1885
1896
  if (!value) {
1886
1897
  return items.map(convertToPick);
1887
1898
  }
1888
1899
  const results = [];
1889
1900
  for (const item of items) {
1890
- const baseName = getBaseName(item);
1891
- const matches = filterQuickPickItem(value, baseName);
1901
+ let filterValue = '';
1902
+ if (provider) {
1903
+ filterValue = provider.getPickLabel(item);
1904
+ } else {
1905
+ filterValue = pathBaseName(item);
1906
+ }
1907
+ const matches = filterQuickPickItem(value, filterValue);
1892
1908
  if (matches.length > 0) {
1893
1909
  results.push({
1894
1910
  pick: item,
@@ -1959,21 +1975,6 @@ const searchFile$1 = async (path, value, prepare, assetDir) => {
1959
1975
  return result;
1960
1976
  };
1961
1977
 
1962
- // TODO this should be in FileSystem module
1963
- const pathBaseName = path => {
1964
- return path.slice(path.lastIndexOf('/') + 1);
1965
- };
1966
-
1967
- // TODO this should be in FileSystem module
1968
- const pathDirName = path => {
1969
- const pathSeparator = '/';
1970
- const index = path.lastIndexOf(pathSeparator);
1971
- if (index === -1) {
1972
- return '';
1973
- }
1974
- return path.slice(0, index);
1975
- };
1976
-
1977
1978
  const searchFile = async (path, value) => {
1978
1979
  const prepare = true;
1979
1980
  // @ts-ignore
@@ -2048,7 +2049,17 @@ const getPickIcon$4 = () => {
2048
2049
  return '';
2049
2050
  };
2050
2051
  const getPickFileIcon$2 = pick => {
2051
- return '';
2052
+ if (typeof pick === 'object') {
2053
+ pick = pick.pick;
2054
+ }
2055
+ if (typeof pick === 'object') {
2056
+ pick = pick.pick;
2057
+ }
2058
+ const baseName = pathBaseName(pick);
2059
+ return {
2060
+ type: File$2,
2061
+ name: baseName
2062
+ };
2052
2063
  };
2053
2064
  const isPrepared$1 = () => {
2054
2065
  const workspace = '';
@@ -2951,7 +2962,7 @@ const handleInput = async (state, newValue, cursorOffset, inputSource = Script)
2951
2962
  state.inputSource = inputSource;
2952
2963
  const newPicks = await state.provider.getPicks(newValue);
2953
2964
  const filterValue = state.provider.getFilterValue(newValue);
2954
- const items = filterQuickPickItems(newPicks, filterValue);
2965
+ const items = filterQuickPickItems(newPicks, filterValue, state.provider);
2955
2966
  const focusedIndex = items.length === 0 ? -1 : 0;
2956
2967
  return {
2957
2968
  ...state,
@@ -3197,11 +3208,6 @@ const QuickPickEntriesNumber = {
3197
3208
  selectPick: selectPick$1
3198
3209
  };
3199
3210
 
3200
- // TODO support file icons
3201
- const getFolderIcon = () => {
3202
- return '';
3203
- };
3204
-
3205
3211
  const getRecentlyOpened = () => {
3206
3212
  return invoke$1(/* RecentlyOpened.getRecentlyOpened */'RecentlyOpened.getRecentlyOpened');
3207
3213
  };
@@ -3256,8 +3262,17 @@ const getPickDescription$1 = pick => {
3256
3262
  const getPickIcon = () => {
3257
3263
  return '';
3258
3264
  };
3259
- const getPickFileIcon = () => {
3260
- return getFolderIcon();
3265
+ const getPickFileIcon = pick => {
3266
+ if (typeof pick === 'object') {
3267
+ pick = pick.pick;
3268
+ }
3269
+ if (typeof pick === 'object') {
3270
+ pick = pick.pick;
3271
+ }
3272
+ return {
3273
+ type: Directory$1,
3274
+ name: pick
3275
+ };
3261
3276
  };
3262
3277
 
3263
3278
  const QuickPickEntriesOpenRecent = {
@@ -3327,7 +3342,7 @@ const loadContent = async state => {
3327
3342
  array(newPicks);
3328
3343
  // @ts-ignore
3329
3344
  const filterValue = provider.getFilterValue(value);
3330
- const items = filterQuickPickItems(newPicks, filterValue);
3345
+ const items = filterQuickPickItems(newPicks, filterValue, provider);
3331
3346
  // @ts-ignore
3332
3347
  provider.getLabel();
3333
3348
  const minLineY = 0;
@@ -3357,6 +3372,87 @@ const loadQuickPickEntries = moduleId => {
3357
3372
  }
3358
3373
  };
3359
3374
 
3375
+ const getIconRequests = (items, provider) => {
3376
+ const iconRequests = [];
3377
+ for (let i = 0; i < items.length; i++) {
3378
+ const pick = items[i];
3379
+ const iconObject = provider.getPickFileIcon(pick);
3380
+ iconRequests.push({
3381
+ name: iconObject?.name,
3382
+ path: '',
3383
+ type: iconObject?.type
3384
+ });
3385
+ }
3386
+ return iconRequests;
3387
+ };
3388
+
3389
+ const requestFileIcons = async requests => {
3390
+ const promises = requests.map(request => {
3391
+ if (!request.name) {
3392
+ return '';
3393
+ }
3394
+ return request.type === File$2 ? invoke$1('IconTheme.getFileIcon', {
3395
+ name: request.name
3396
+ }) : invoke$1('IconTheme.getFolderIcon', {
3397
+ name: request.name
3398
+ });
3399
+ });
3400
+ return Promise.all(promises);
3401
+ };
3402
+
3403
+ const getPickDescription = (provider, pick) => {
3404
+ if (provider.getPickDescription) {
3405
+ return provider.getPickDescription(pick);
3406
+ }
3407
+ return '';
3408
+ };
3409
+ const getVisible = async (provider, items, minLineY, maxLineY, focusedIndex) => {
3410
+ const visibleItems = [];
3411
+ const setSize = items.length;
3412
+ const max = Math.min(setSize, maxLineY);
3413
+ const iconsRequests = getIconRequests(items.slice(minLineY, maxLineY), provider);
3414
+ const icons = await requestFileIcons(iconsRequests);
3415
+ let iconIndex = 0;
3416
+ for (let i = minLineY; i < max; i++) {
3417
+ const item = items[i];
3418
+ const pick = item.pick;
3419
+ const label = provider.getPickLabel(pick);
3420
+ const description = getPickDescription(provider, pick);
3421
+ const icon = provider.getPickIcon(pick);
3422
+ const fileIcon = icons[iconIndex++];
3423
+ visibleItems.push({
3424
+ label,
3425
+ description,
3426
+ icon,
3427
+ fileIcon,
3428
+ posInSet: i + 1,
3429
+ setSize,
3430
+ isActive: i === focusedIndex,
3431
+ matches: item.matches
3432
+ });
3433
+ }
3434
+ return visibleItems;
3435
+ };
3436
+
3437
+ const createQuickPickViewModel = async (oldState, newState) => {
3438
+ const visibleItems = await getVisible(newState.provider, newState.items, newState.minLineY, newState.maxLineY, newState.focusedIndex);
3439
+ const oldFocusedIndex = oldState.focusedIndex - oldState.minLineY;
3440
+ const newFocusedIndex = newState.focusedIndex - newState.minLineY;
3441
+ const maxLineY = Math.min(newState.maxLineY, newState.items.length);
3442
+ const itemCount = maxLineY - newState.minLineY;
3443
+ const height = itemCount * newState.itemHeight;
3444
+ return {
3445
+ visibleItems,
3446
+ value: newState.value,
3447
+ cursorOffset: newState.cursorOffset,
3448
+ focused: newState.focused,
3449
+ height,
3450
+ oldFocusedIndex,
3451
+ newFocusedIndex,
3452
+ uid: newState.uid
3453
+ };
3454
+ };
3455
+
3360
3456
  const RenderItems = 1;
3361
3457
  const RenderFocus = 2;
3362
3458
  const RenderValue = 3;
@@ -3496,74 +3592,31 @@ const getQuickPickItemsVirtualDom = visibleItems => {
3496
3592
  return dom;
3497
3593
  };
3498
3594
 
3499
- const getPickDescription = (provider, pick) => {
3500
- if (provider.getPickDescription) {
3501
- return provider.getPickDescription(pick);
3502
- }
3503
- return '';
3504
- };
3505
- const getFileIcon = (provider, pick) => {
3506
- if (provider.getPickFileIcon) {
3507
- return provider.getPickFileIcon(pick);
3508
- }
3509
- return '';
3510
- };
3511
- const getVisible = (provider, items, minLineY, maxLineY, focusedIndex) => {
3512
- const visibleItems = [];
3513
- const setSize = items.length;
3514
- const max = Math.min(setSize, maxLineY);
3515
- for (let i = minLineY; i < max; i++) {
3516
- const item = items[i];
3517
- const pick = item.pick;
3518
- const label = provider.getPickLabel(pick);
3519
- const description = getPickDescription(provider, pick);
3520
- const icon = provider.getPickIcon(pick);
3521
- const fileIcon = getFileIcon(provider, pick);
3522
- visibleItems.push({
3523
- label,
3524
- description,
3525
- icon,
3526
- fileIcon,
3527
- posInSet: i + 1,
3528
- setSize,
3529
- isActive: i === focusedIndex,
3530
- matches: item.matches
3531
- });
3532
- }
3533
- return visibleItems;
3534
- };
3535
-
3536
3595
  const SetCursorOffset = 'setCursorOffset';
3537
3596
  const SetFocusedIndex = 'setFocusedIndex';
3538
3597
  const SetItemsHeight = 'setItemsHeight';
3539
3598
  const SetValue = 'setValue';
3540
3599
 
3541
- const renderValue = (oldState, newState) => {
3600
+ const renderValue = newState => {
3542
3601
  return ['Viewlet.send', newState.uid, /* method */SetValue, /* value */newState.value];
3543
3602
  };
3544
- const renderCursorOffset = (oldState, newState) => {
3603
+ const renderCursorOffset = newState => {
3545
3604
  return ['Viewlet.send', newState.uid, /* method */SetCursorOffset, /* cursorOffset */newState.cursorOffset];
3546
3605
  };
3547
- const renderItems = (oldState, newState) => {
3548
- const visibleItems = getVisible(newState.provider, newState.items, newState.minLineY, newState.maxLineY, newState.focusedIndex);
3549
- const dom = getQuickPickItemsVirtualDom(visibleItems);
3606
+ const renderItems = newState => {
3607
+ const dom = getQuickPickItemsVirtualDom(newState.visibleItems);
3550
3608
  return ['Viewlet.send', newState.uid, /* method */'setItemsDom', dom];
3551
3609
  };
3552
- const renderFocusedIndex = (oldState, newState) => {
3553
- const oldFocusedIndex = oldState.focusedIndex - oldState.minLineY;
3554
- const newFocusedIndex = newState.focusedIndex - newState.minLineY;
3555
- return ['Viewlet.send', newState.uid, /* method */SetFocusedIndex, /* oldFocusedIndex */oldFocusedIndex, /* newFocusedIndex */newFocusedIndex];
3610
+ const renderFocusedIndex = newState => {
3611
+ return ['Viewlet.send', newState.uid, /* method */SetFocusedIndex, /* oldFocusedIndex */newState.oldFocusedIndex, /* newFocusedIndex */newState.newFocusedIndex];
3556
3612
  };
3557
- const renderHeight = (oldState, newState) => {
3558
- if (newState.items.length === 0) {
3559
- return ['Viewlet.send', newState.uid, /* method */SetItemsHeight, /* height */newState.itemHeight];
3613
+ const renderHeight = newState => {
3614
+ if (newState.height === 0) {
3615
+ return ['Viewlet.send', newState.uid, /* method */SetItemsHeight, /* height */20];
3560
3616
  }
3561
- const maxLineY = Math.min(newState.maxLineY, newState.items.length);
3562
- const itemCount = maxLineY - newState.minLineY;
3563
- const height = itemCount * newState.itemHeight;
3564
- return ['Viewlet.send', newState.uid, /* method */SetItemsHeight, /* height */height];
3617
+ return ['Viewlet.send', newState.uid, /* method */SetItemsHeight, /* height */newState.height];
3565
3618
  };
3566
- const renderFocus = (oldState, newState) => {
3619
+ const renderFocus = newState => {
3567
3620
  const selector = newState.focused ? '.InputBox' : '';
3568
3621
  return ['Viewlet.focusSelector', selector];
3569
3622
  };
@@ -3586,11 +3639,12 @@ const getRenderer = diffType => {
3586
3639
  }
3587
3640
  };
3588
3641
 
3589
- const applyRender = (oldState, newState, diffResult) => {
3642
+ const applyRender = async (oldState, newState, diffResult) => {
3590
3643
  const commands = [];
3644
+ const viewModel = await createQuickPickViewModel(oldState, newState);
3591
3645
  for (const item of diffResult) {
3592
3646
  const fn = getRenderer(item);
3593
- commands.push(fn(oldState, newState));
3647
+ commands.push(fn(viewModel));
3594
3648
  }
3595
3649
  return commands;
3596
3650
  };
@@ -3662,7 +3716,7 @@ const diff = (oldState, newState) => {
3662
3716
  return diffResult;
3663
3717
  };
3664
3718
 
3665
- const doRender = uid => {
3719
+ const doRender = async uid => {
3666
3720
  const {
3667
3721
  oldState,
3668
3722
  newState
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/file-search-worker",
3
- "version": "3.7.0",
3
+ "version": "3.8.0",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "text-search"