@lvce-editor/file-search-worker 3.7.0 → 3.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.
@@ -877,6 +877,9 @@ const state$5 = {
877
877
  const getAll = () => {
878
878
  return state$5.menuEntries;
879
879
  };
880
+ const add = menuEntries => {
881
+ state$5.menuEntries = [...state$5.menuEntries, ...menuEntries];
882
+ };
880
883
 
881
884
  const Hide = 'hide';
882
885
  const KeepOpen = '';
@@ -1001,7 +1004,7 @@ const prefixIdWithExt = item => {
1001
1004
  const getExtensionPicks = async () => {
1002
1005
  try {
1003
1006
  // TODO don't call this every time
1004
- const extensionPicks = await invoke$1('ExtensionHostCommands.getCommands');
1007
+ const extensionPicks = await invoke$1('ExtensionHost.getCommands');
1005
1008
  if (!extensionPicks) {
1006
1009
  return [];
1007
1010
  }
@@ -1090,6 +1093,9 @@ const execute = async (method, ...params) => {
1090
1093
  // TODO
1091
1094
  };
1092
1095
 
1096
+ const Directory$1 = 3;
1097
+ const File$2 = 7;
1098
+
1093
1099
  const RE_PROTOCOL = /^([a-z-]+):\/\//;
1094
1100
  const getProtocol = uri => {
1095
1101
  const protocolMatch = uri.match(RE_PROTOCOL);
@@ -1103,9 +1109,6 @@ const Memfs = 'memfs';
1103
1109
  const Html = 'html';
1104
1110
  const Fetch = 'fetch';
1105
1111
 
1106
- const Directory$1 = 3;
1107
- const File$2 = 7;
1108
-
1109
1112
  class FileNotFoundError extends Error {
1110
1113
  constructor(uri) {
1111
1114
  super(`File not found: ${uri}`);
@@ -1877,18 +1880,34 @@ const filterQuickPickItem = (pattern, word) => {
1877
1880
  return matches;
1878
1881
  };
1879
1882
 
1880
- const getBaseName = path => {
1883
+ // TODO this should be in FileSystem module
1884
+ const pathBaseName = path => {
1881
1885
  return path.slice(path.lastIndexOf('/') + 1);
1882
1886
  };
1883
1887
 
1884
- const filterQuickPickItems = (items, value) => {
1888
+ // TODO this should be in FileSystem module
1889
+ const pathDirName = path => {
1890
+ const pathSeparator = '/';
1891
+ const index = path.lastIndexOf(pathSeparator);
1892
+ if (index === -1) {
1893
+ return '';
1894
+ }
1895
+ return path.slice(0, index);
1896
+ };
1897
+
1898
+ const filterQuickPickItems = (items, value, provider) => {
1885
1899
  if (!value) {
1886
1900
  return items.map(convertToPick);
1887
1901
  }
1888
1902
  const results = [];
1889
1903
  for (const item of items) {
1890
- const baseName = getBaseName(item);
1891
- const matches = filterQuickPickItem(value, baseName);
1904
+ let filterValue = '';
1905
+ if (provider) {
1906
+ filterValue = provider.getPickLabel(item);
1907
+ } else {
1908
+ filterValue = pathBaseName(item);
1909
+ }
1910
+ const matches = filterQuickPickItem(value, filterValue);
1892
1911
  if (matches.length > 0) {
1893
1912
  results.push({
1894
1913
  pick: item,
@@ -1959,21 +1978,6 @@ const searchFile$1 = async (path, value, prepare, assetDir) => {
1959
1978
  return result;
1960
1979
  };
1961
1980
 
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
1981
  const searchFile = async (path, value) => {
1978
1982
  const prepare = true;
1979
1983
  // @ts-ignore
@@ -2048,7 +2052,17 @@ const getPickIcon$4 = () => {
2048
2052
  return '';
2049
2053
  };
2050
2054
  const getPickFileIcon$2 = pick => {
2051
- return '';
2055
+ if (typeof pick === 'object') {
2056
+ pick = pick.pick;
2057
+ }
2058
+ if (typeof pick === 'object') {
2059
+ pick = pick.pick;
2060
+ }
2061
+ const baseName = pathBaseName(pick);
2062
+ return {
2063
+ type: File$2,
2064
+ name: baseName
2065
+ };
2052
2066
  };
2053
2067
  const isPrepared$1 = () => {
2054
2068
  const workspace = '';
@@ -2951,7 +2965,7 @@ const handleInput = async (state, newValue, cursorOffset, inputSource = Script)
2951
2965
  state.inputSource = inputSource;
2952
2966
  const newPicks = await state.provider.getPicks(newValue);
2953
2967
  const filterValue = state.provider.getFilterValue(newValue);
2954
- const items = filterQuickPickItems(newPicks, filterValue);
2968
+ const items = filterQuickPickItems(newPicks, filterValue, state.provider);
2955
2969
  const focusedIndex = items.length === 0 ? -1 : 0;
2956
2970
  return {
2957
2971
  ...state,
@@ -3197,11 +3211,6 @@ const QuickPickEntriesNumber = {
3197
3211
  selectPick: selectPick$1
3198
3212
  };
3199
3213
 
3200
- // TODO support file icons
3201
- const getFolderIcon = () => {
3202
- return '';
3203
- };
3204
-
3205
3214
  const getRecentlyOpened = () => {
3206
3215
  return invoke$1(/* RecentlyOpened.getRecentlyOpened */'RecentlyOpened.getRecentlyOpened');
3207
3216
  };
@@ -3256,8 +3265,17 @@ const getPickDescription$1 = pick => {
3256
3265
  const getPickIcon = () => {
3257
3266
  return '';
3258
3267
  };
3259
- const getPickFileIcon = () => {
3260
- return getFolderIcon();
3268
+ const getPickFileIcon = pick => {
3269
+ if (typeof pick === 'object') {
3270
+ pick = pick.pick;
3271
+ }
3272
+ if (typeof pick === 'object') {
3273
+ pick = pick.pick;
3274
+ }
3275
+ return {
3276
+ type: Directory$1,
3277
+ name: pick
3278
+ };
3261
3279
  };
3262
3280
 
3263
3281
  const QuickPickEntriesOpenRecent = {
@@ -3327,7 +3345,7 @@ const loadContent = async state => {
3327
3345
  array(newPicks);
3328
3346
  // @ts-ignore
3329
3347
  const filterValue = provider.getFilterValue(value);
3330
- const items = filterQuickPickItems(newPicks, filterValue);
3348
+ const items = filterQuickPickItems(newPicks, filterValue, provider);
3331
3349
  // @ts-ignore
3332
3350
  provider.getLabel();
3333
3351
  const minLineY = 0;
@@ -3357,6 +3375,87 @@ const loadQuickPickEntries = moduleId => {
3357
3375
  }
3358
3376
  };
3359
3377
 
3378
+ const getIconRequests = (items, provider) => {
3379
+ const iconRequests = [];
3380
+ for (let i = 0; i < items.length; i++) {
3381
+ const pick = items[i];
3382
+ const iconObject = provider.getPickFileIcon(pick);
3383
+ iconRequests.push({
3384
+ name: iconObject?.name,
3385
+ path: '',
3386
+ type: iconObject?.type
3387
+ });
3388
+ }
3389
+ return iconRequests;
3390
+ };
3391
+
3392
+ const requestFileIcons = async requests => {
3393
+ const promises = requests.map(request => {
3394
+ if (!request.name) {
3395
+ return '';
3396
+ }
3397
+ return request.type === File$2 ? invoke$1('IconTheme.getFileIcon', {
3398
+ name: request.name
3399
+ }) : invoke$1('IconTheme.getFolderIcon', {
3400
+ name: request.name
3401
+ });
3402
+ });
3403
+ return Promise.all(promises);
3404
+ };
3405
+
3406
+ const getPickDescription = (provider, pick) => {
3407
+ if (provider.getPickDescription) {
3408
+ return provider.getPickDescription(pick);
3409
+ }
3410
+ return '';
3411
+ };
3412
+ const getVisible = async (provider, items, minLineY, maxLineY, focusedIndex) => {
3413
+ const visibleItems = [];
3414
+ const setSize = items.length;
3415
+ const max = Math.min(setSize, maxLineY);
3416
+ const iconsRequests = getIconRequests(items.slice(minLineY, maxLineY), provider);
3417
+ const icons = await requestFileIcons(iconsRequests);
3418
+ let iconIndex = 0;
3419
+ for (let i = minLineY; i < max; i++) {
3420
+ const item = items[i];
3421
+ const pick = item.pick;
3422
+ const label = provider.getPickLabel(pick);
3423
+ const description = getPickDescription(provider, pick);
3424
+ const icon = provider.getPickIcon(pick);
3425
+ const fileIcon = icons[iconIndex++];
3426
+ visibleItems.push({
3427
+ label,
3428
+ description,
3429
+ icon,
3430
+ fileIcon,
3431
+ posInSet: i + 1,
3432
+ setSize,
3433
+ isActive: i === focusedIndex,
3434
+ matches: item.matches
3435
+ });
3436
+ }
3437
+ return visibleItems;
3438
+ };
3439
+
3440
+ const createQuickPickViewModel = async (oldState, newState) => {
3441
+ const visibleItems = await getVisible(newState.provider, newState.items, newState.minLineY, newState.maxLineY, newState.focusedIndex);
3442
+ const oldFocusedIndex = oldState.focusedIndex - oldState.minLineY;
3443
+ const newFocusedIndex = newState.focusedIndex - newState.minLineY;
3444
+ const maxLineY = Math.min(newState.maxLineY, newState.items.length);
3445
+ const itemCount = maxLineY - newState.minLineY;
3446
+ const height = itemCount * newState.itemHeight;
3447
+ return {
3448
+ visibleItems,
3449
+ value: newState.value,
3450
+ cursorOffset: newState.cursorOffset,
3451
+ focused: newState.focused,
3452
+ height,
3453
+ oldFocusedIndex,
3454
+ newFocusedIndex,
3455
+ uid: newState.uid
3456
+ };
3457
+ };
3458
+
3360
3459
  const RenderItems = 1;
3361
3460
  const RenderFocus = 2;
3362
3461
  const RenderValue = 3;
@@ -3496,74 +3595,31 @@ const getQuickPickItemsVirtualDom = visibleItems => {
3496
3595
  return dom;
3497
3596
  };
3498
3597
 
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
3598
  const SetCursorOffset = 'setCursorOffset';
3537
3599
  const SetFocusedIndex = 'setFocusedIndex';
3538
3600
  const SetItemsHeight = 'setItemsHeight';
3539
3601
  const SetValue = 'setValue';
3540
3602
 
3541
- const renderValue = (oldState, newState) => {
3603
+ const renderValue = newState => {
3542
3604
  return ['Viewlet.send', newState.uid, /* method */SetValue, /* value */newState.value];
3543
3605
  };
3544
- const renderCursorOffset = (oldState, newState) => {
3606
+ const renderCursorOffset = newState => {
3545
3607
  return ['Viewlet.send', newState.uid, /* method */SetCursorOffset, /* cursorOffset */newState.cursorOffset];
3546
3608
  };
3547
- const renderItems = (oldState, newState) => {
3548
- const visibleItems = getVisible(newState.provider, newState.items, newState.minLineY, newState.maxLineY, newState.focusedIndex);
3549
- const dom = getQuickPickItemsVirtualDom(visibleItems);
3609
+ const renderItems = newState => {
3610
+ const dom = getQuickPickItemsVirtualDom(newState.visibleItems);
3550
3611
  return ['Viewlet.send', newState.uid, /* method */'setItemsDom', dom];
3551
3612
  };
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];
3613
+ const renderFocusedIndex = newState => {
3614
+ return ['Viewlet.send', newState.uid, /* method */SetFocusedIndex, /* oldFocusedIndex */newState.oldFocusedIndex, /* newFocusedIndex */newState.newFocusedIndex];
3556
3615
  };
3557
- const renderHeight = (oldState, newState) => {
3558
- if (newState.items.length === 0) {
3559
- return ['Viewlet.send', newState.uid, /* method */SetItemsHeight, /* height */newState.itemHeight];
3616
+ const renderHeight = newState => {
3617
+ if (newState.height === 0) {
3618
+ return ['Viewlet.send', newState.uid, /* method */SetItemsHeight, /* height */20];
3560
3619
  }
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];
3620
+ return ['Viewlet.send', newState.uid, /* method */SetItemsHeight, /* height */newState.height];
3565
3621
  };
3566
- const renderFocus = (oldState, newState) => {
3622
+ const renderFocus = newState => {
3567
3623
  const selector = newState.focused ? '.InputBox' : '';
3568
3624
  return ['Viewlet.focusSelector', selector];
3569
3625
  };
@@ -3586,11 +3642,12 @@ const getRenderer = diffType => {
3586
3642
  }
3587
3643
  };
3588
3644
 
3589
- const applyRender = (oldState, newState, diffResult) => {
3645
+ const applyRender = async (oldState, newState, diffResult) => {
3590
3646
  const commands = [];
3647
+ const viewModel = await createQuickPickViewModel(oldState, newState);
3591
3648
  for (const item of diffResult) {
3592
3649
  const fn = getRenderer(item);
3593
- commands.push(fn(oldState, newState));
3650
+ commands.push(fn(viewModel));
3594
3651
  }
3595
3652
  return commands;
3596
3653
  };
@@ -3662,7 +3719,7 @@ const diff = (oldState, newState) => {
3662
3719
  return diffResult;
3663
3720
  };
3664
3721
 
3665
- const doRender = uid => {
3722
+ const doRender = async uid => {
3666
3723
  const {
3667
3724
  oldState,
3668
3725
  newState
@@ -3769,6 +3826,7 @@ const commandMap = {
3769
3826
  'QuickPick.selectIndex': wrapCommand(selectIndex),
3770
3827
  'QuickPick.selectItem': wrapCommand(selectItem),
3771
3828
  'QuickPick.setDeltaY': wrapCommand(setDeltaY),
3829
+ 'QuickPick.addMenuEntries': add,
3772
3830
  'SearchFile.filter': filterQuickPickItems,
3773
3831
  'SearchFile.searchFile': searchFile$1,
3774
3832
  'SearchFile.searchFileWithFetch': searchFile$4,
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.9.0",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "text-search"