@lvce-editor/quick-pick-worker 4.20.2 → 4.21.1

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.
@@ -2613,7 +2613,39 @@ const filterQuickPickItem = (pattern, word) => {
2613
2613
  return matches;
2614
2614
  };
2615
2615
 
2616
- const filterQuickPickItems = (items, value) => {
2616
+ const getMatchRank = (label, value) => {
2617
+ if (label === value) {
2618
+ return 4;
2619
+ }
2620
+ if (label.startsWith(value)) {
2621
+ return 3;
2622
+ }
2623
+ let index = label.indexOf(value);
2624
+ if (index === -1) {
2625
+ return 0;
2626
+ }
2627
+ while (index !== -1) {
2628
+ if (!/[\p{L}\p{N}]/u.test(label[index - 1])) {
2629
+ return 2;
2630
+ }
2631
+ index = label.indexOf(value, index + 1);
2632
+ }
2633
+ return 1;
2634
+ };
2635
+ const rankCommandPicks = (items, value) => {
2636
+ const normalizedValue = value.toLowerCase();
2637
+ const ranked = items.map(item => ({
2638
+ item,
2639
+ rank: getMatchRank(item.label.toLowerCase(), normalizedValue)
2640
+ }));
2641
+ // The first match entry is the fuzzy score; the remaining entries describe highlights.
2642
+ ranked.sort((a, b) => b.rank - a.rank || b.item.matches[0] - a.item.matches[0]);
2643
+ return ranked.map(({
2644
+ item
2645
+ }) => item);
2646
+ };
2647
+
2648
+ const filterQuickPickItems = (items, value, rankCommands = false) => {
2617
2649
  if (!value) {
2618
2650
  return items;
2619
2651
  }
@@ -2628,7 +2660,7 @@ const filterQuickPickItems = (items, value) => {
2628
2660
  });
2629
2661
  }
2630
2662
  }
2631
- return results;
2663
+ return rankCommands ? rankCommandPicks(results, value) : results;
2632
2664
  };
2633
2665
 
2634
2666
  const Command = '>';
@@ -2904,6 +2936,11 @@ const invoke$2 = (method, ...args) => {
2904
2936
  return state$1.rpc.invoke(method, ...args);
2905
2937
  };
2906
2938
 
2939
+ const isTextInput = args => {
2940
+ const options = args.at(-1);
2941
+ return options?.type === 'text';
2942
+ };
2943
+
2907
2944
  const toProtoVisibleItem$2 = item => {
2908
2945
  const {
2909
2946
  args,
@@ -2928,6 +2965,9 @@ const toProtoVisibleItem$2 = item => {
2928
2965
  };
2929
2966
  const getPicks$d = async (searchValue, args) => {
2930
2967
  state$2.args = args;
2968
+ if (isTextInput(args)) {
2969
+ return [];
2970
+ }
2931
2971
  const options = args.at(-1);
2932
2972
  let items;
2933
2973
  if (options?.mode === 'quickInput') {
@@ -3762,6 +3802,13 @@ const setValue = async (state, newValue) => {
3762
3802
  if (value === newValue) {
3763
3803
  return state;
3764
3804
  }
3805
+ if (isTextInput(args)) {
3806
+ return {
3807
+ ...state,
3808
+ inputSource: Script,
3809
+ value: newValue
3810
+ };
3811
+ }
3765
3812
  const prefix = getQuickPickPrefix(newValue);
3766
3813
  const subId = getQuickPickSubProviderId(providerId, prefix);
3767
3814
  const quickInput = isQuickInput(args);
@@ -3771,7 +3818,7 @@ const setValue = async (state, newValue) => {
3771
3818
  platform
3772
3819
  });
3773
3820
  const filterValue = quickInput ? '' : getFilterValue(providerId, subId, newValue);
3774
- const items = filterQuickPickItems(newPicks, filterValue);
3821
+ const items = filterQuickPickItems(newPicks, filterValue, subId === Commands$1);
3775
3822
  const focusedIndex = items.length === 0 ? -1 : 0;
3776
3823
  const sliced = items.slice(minLineY, maxLineY);
3777
3824
  const {
@@ -4042,7 +4089,7 @@ const getLoadedState = async state => {
4042
4089
  });
4043
4090
  array(newPicks);
4044
4091
  const filterValue = getFilterValue(id, subId, value);
4045
- const items = filterQuickPickItems(newPicks, filterValue);
4092
+ const items = isTextInput(args) ? newPicks : filterQuickPickItems(newPicks, filterValue, subId === Commands$1);
4046
4093
  const minLineY = 0;
4047
4094
  const maxLineY = Math.min(minLineY + maxVisibleItems, newPicks.length);
4048
4095
  const sliced = newPicks.slice(minLineY, maxLineY);
@@ -4780,14 +4827,17 @@ const QuickPick$1 = 'QuickPick';
4780
4827
  const QuickPickItems = 'QuickPickItems';
4781
4828
  const QuickPickItemActive = 'QuickPickItemActive';
4782
4829
 
4783
- const getQuickPickInputVirtualDom = (placeholder = '', ariaLabel = typeNameofCommandToRun()) => {
4830
+ const getQuickPickInputVirtualDom = (placeholder = '', ariaLabel = typeNameofCommandToRun(), textInput = false) => {
4784
4831
  return [{
4785
4832
  childCount: 1,
4786
4833
  className: QuickPickInputWrapper,
4787
4834
  type: Div
4788
4835
  }, {
4789
- ariaAutoComplete: 'list',
4790
- ariaExpanded: true,
4836
+ ...(!textInput && {
4837
+ ariaAutoComplete: 'list',
4838
+ ariaExpanded: true,
4839
+ role: ComboBox
4840
+ }),
4791
4841
  ariaLabel: ariaLabel,
4792
4842
  autocapitalize: 'off',
4793
4843
  autocomplete: 'off',
@@ -4799,18 +4849,17 @@ const getQuickPickInputVirtualDom = (placeholder = '', ariaLabel = typeNameofCom
4799
4849
  onFocus: HandleFocus,
4800
4850
  onInput: HandleInput,
4801
4851
  placeholder,
4802
- role: ComboBox,
4803
4852
  spellcheck: false,
4804
4853
  type: Input
4805
4854
  }];
4806
4855
  };
4807
4856
 
4808
- const getQuickPickHeaderVirtualDom = (placeholder = '', ariaLabel) => {
4857
+ const getQuickPickHeaderVirtualDom = (placeholder = '', ariaLabel, textInput = false) => {
4809
4858
  return [{
4810
4859
  childCount: 1,
4811
4860
  className: QuickPickHeader,
4812
4861
  type: Div
4813
- }, ...getQuickPickInputVirtualDom(placeholder, ariaLabel)];
4862
+ }, ...getQuickPickInputVirtualDom(placeholder, ariaLabel, textInput)];
4814
4863
  };
4815
4864
 
4816
4865
  const getFileIconVirtualDom = icon => {
@@ -4955,8 +5004,17 @@ const getRootNodeCount = nodes => {
4955
5004
  }
4956
5005
  return count;
4957
5006
  };
4958
- const getQuickPickVirtualDom = (visibleItems, scrollBarHeight, scrollBarTop, placeholder = '', inputAriaLabel) => {
5007
+ const getQuickPickVirtualDom = (visibleItems, scrollBarHeight, scrollBarTop, placeholder = '', inputAriaLabel, textInput = false) => {
4959
5008
  const quickOpen$1 = quickOpen();
5009
+ if (textInput) {
5010
+ return [{
5011
+ ariaLabel: quickOpen$1,
5012
+ childCount: 1,
5013
+ className: mergeClassNames(Viewlet, QuickPick$2),
5014
+ id: QuickPick$1,
5015
+ type: Div
5016
+ }, ...getQuickPickHeaderVirtualDom(placeholder, inputAriaLabel, true)];
5017
+ }
4960
5018
  const shouldShowScrollbar = scrollBarHeight > 0;
4961
5019
  const quickPickItemsDom = getQuickPickItemsVirtualDom(visibleItems);
4962
5020
  const listItemsChildCount = getRootNodeCount(quickPickItemsDom);
@@ -4993,7 +5051,7 @@ const renderItemsDom = state => {
4993
5051
  visibleItems
4994
5052
  } = viewModel;
4995
5053
  const inputAriaLabel = getQuickPickInputAriaLabel(state.providerId, state.value, state.placeholder);
4996
- return getQuickPickVirtualDom(visibleItems, scrollBarHeight, scrollBarTop, state.placeholder, inputAriaLabel);
5054
+ return getQuickPickVirtualDom(visibleItems, scrollBarHeight, scrollBarTop, state.placeholder, inputAriaLabel, isTextInput(state.args));
4997
5055
  };
4998
5056
  const renderItems = (_oldState, newState) => {
4999
5057
  const dom = renderItemsDom(newState);
@@ -5167,6 +5225,7 @@ const showQuickInput = async ({
5167
5225
  initialItems = [],
5168
5226
  initialValue,
5169
5227
  placeholder,
5228
+ type = id === undefined && initialItems.length === 0 ? 'text' : 'select',
5170
5229
  waitUntil
5171
5230
  }) => {
5172
5231
  const customItemsId = add(initialItems);
@@ -5179,6 +5238,7 @@ const showQuickInput = async ({
5179
5238
  mode: 'quickInput',
5180
5239
  placeholder,
5181
5240
  quickInputId: id,
5241
+ type,
5182
5242
  waitUntil
5183
5243
  });
5184
5244
  return result ?? {
@@ -5197,20 +5257,22 @@ const showQuickPick = async ({
5197
5257
  applicationId,
5198
5258
  items,
5199
5259
  placeholder = '',
5260
+ type = 'select',
5200
5261
  waitUntil = 'selected'
5201
5262
  }) => {
5202
- const customItemsId = add(items);
5263
+ const customItemsId = add(type === 'text' ? [] : items);
5203
5264
  const {
5204
5265
  id,
5205
5266
  promise
5206
5267
  } = registerCallback();
5207
5268
  try {
5208
5269
  await invoke(applicationId, 'Viewlet.openWidget', QuickPick, 'custom', [], id, {
5209
- acceptInput,
5270
+ acceptInput: type === 'text' || acceptInput,
5210
5271
  callbackOwner: 'quickPickWorker',
5211
5272
  customItemsId,
5212
5273
  mode: 'quickPick',
5213
- placeholder
5274
+ placeholder,
5275
+ type
5214
5276
  });
5215
5277
  if (waitUntil === 'visible') {
5216
5278
  return undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/quick-pick-worker",
3
- "version": "4.20.2",
3
+ "version": "4.21.1",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/lvce-editor/quick-pick-worker.git"