@lvce-editor/text-search-worker 3.52.0 → 4.0.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.
@@ -1306,12 +1306,6 @@ const diff2 = uid => {
1306
1306
 
1307
1307
  // based on https://github.com/microsoft/vscode/blob/c0769274fa136b45799edeccc0d0a2f645b75caf/src/vs/base/common/arrays.ts#L625 (License MIT)
1308
1308
 
1309
- const isLastIndex = (array, index) => {
1310
- return index === array.length - 1;
1311
- };
1312
- const lastIndex = array => {
1313
- return array.length - 1;
1314
- };
1315
1309
  const remove = (array, index, deleteCount) => {
1316
1310
  return array.toSpliced(index, deleteCount);
1317
1311
  };
@@ -2227,20 +2221,6 @@ const getCommandIds = () => {
2227
2221
  return commandIds;
2228
2222
  };
2229
2223
 
2230
- const getFlags = uid => {
2231
- const {
2232
- newState
2233
- } = get(uid);
2234
- return newState.flags;
2235
- };
2236
-
2237
- const getFocus = uid => {
2238
- const {
2239
- newState
2240
- } = get(uid);
2241
- return newState.focus;
2242
- };
2243
-
2244
2224
  const Tab = 2;
2245
2225
  const Enter = 3;
2246
2226
  const End = 255;
@@ -3036,7 +3016,7 @@ const getFileIcons = async matches => {
3036
3016
  // TODO optimize this function to return the minimum number
3037
3017
  // of visible items needed, e.g. when not scrolled 5 items with
3038
3018
  // 20px fill 100px but when scrolled 6 items are needed
3039
- const getNumberOfVisibleItems = (listHeight, itemHeight) => {
3019
+ const getNumberOfVisibleItems$1 = (listHeight, itemHeight) => {
3040
3020
  return Math.ceil(listHeight / itemHeight) + 1;
3041
3021
  };
3042
3022
 
@@ -3080,33 +3060,11 @@ const getScrollBarSize = (size, contentSize, minimumSliderSize) => {
3080
3060
  }
3081
3061
  return Math.max(Math.round(size ** 2 / contentSize), minimumSliderSize);
3082
3062
  };
3083
- const getScrollBarOffset = (delta, finalDelta, size, scrollBarSize) => {
3063
+ const getScrollBarOffset$1 = (delta, finalDelta, size, scrollBarSize) => {
3084
3064
  const scrollBarOffset = delta / finalDelta * (size - scrollBarSize);
3085
3065
  return scrollBarOffset;
3086
3066
  };
3087
- const getScrollBarY = getScrollBarOffset;
3088
- const getNewDeltaPercent = (height, scrollBarHeight, relativeY) => {
3089
- const halfScrollBarHeight = scrollBarHeight / 2;
3090
- if (relativeY <= halfScrollBarHeight) {
3091
- // clicked at top
3092
- return {
3093
- percent: 0,
3094
- handleOffset: relativeY
3095
- };
3096
- }
3097
- if (relativeY <= height - halfScrollBarHeight) {
3098
- // clicked in middle
3099
- return {
3100
- percent: (relativeY - halfScrollBarHeight) / (height - scrollBarHeight),
3101
- handleOffset: halfScrollBarHeight
3102
- };
3103
- }
3104
- // clicked at bottom
3105
- return {
3106
- percent: 1,
3107
- handleOffset: scrollBarHeight - height + relativeY
3108
- };
3109
- };
3067
+ const getScrollBarY$1 = getScrollBarOffset$1;
3110
3068
 
3111
3069
  const textSearch$6 = async (scheme, root, query) => {
3112
3070
  string(scheme);
@@ -3395,7 +3353,7 @@ const handleUpdate = async (state, update) => {
3395
3353
  const contentHeight = total * itemHeight;
3396
3354
  const listHeight = height - headerHeight;
3397
3355
  const scrollBarHeight = getScrollBarSize(height, contentHeight, minimumSliderSize);
3398
- const numberOfVisible = getNumberOfVisibleItems(listHeight, itemHeight);
3356
+ const numberOfVisible = getNumberOfVisibleItems$1(listHeight, itemHeight);
3399
3357
  const maxLineY = Math.min(numberOfVisible, total);
3400
3358
  const finalDeltaY = Math.max(contentHeight - listHeight, 0);
3401
3359
  const visible = results.slice(0, maxLineY);
@@ -3658,6 +3616,12 @@ const handleSharedInput = (state, name, value, inputSource = Script) => {
3658
3616
  return fn(state, value, inputSource);
3659
3617
  };
3660
3618
 
3619
+ // TODO optimize this function to return the minimum number
3620
+ // of visible items needed, e.g. when not scrolled 5 items with
3621
+ // 20px fill 100px but when scrolled 6 items are needed
3622
+ const getNumberOfVisibleItems = (listHeight, itemHeight) => {
3623
+ return Math.ceil(listHeight / itemHeight) + 1;
3624
+ };
3661
3625
  const focusIndexScrollDown = (state, index, listHeight, itemHeight, itemsLength) => {
3662
3626
  const newMaxLineY = Math.min(index + 1, itemsLength);
3663
3627
  const fittingItems = getNumberOfVisibleItems(listHeight, itemHeight);
@@ -3672,7 +3636,6 @@ const focusIndexScrollDown = (state, index, listHeight, itemHeight, itemsLength)
3672
3636
  deltaY: newDeltaY
3673
3637
  };
3674
3638
  };
3675
-
3676
3639
  const focusIndexScrollUp = (state, index, listHeight, itemHeight, itemsLength) => {
3677
3640
  const newMinLineY = index;
3678
3641
  const fittingItems = getNumberOfVisibleItems(listHeight, itemHeight);
@@ -3687,7 +3650,6 @@ const focusIndexScrollUp = (state, index, listHeight, itemHeight, itemsLength) =
3687
3650
  deltaY: newDeltaY
3688
3651
  };
3689
3652
  };
3690
-
3691
3653
  const focusIndex = (state, index) => {
3692
3654
  const {
3693
3655
  itemHeight,
@@ -3722,7 +3684,6 @@ const focusIndex = (state, index) => {
3722
3684
  focused: true
3723
3685
  };
3724
3686
  };
3725
-
3726
3687
  const first = () => {
3727
3688
  return 0;
3728
3689
  };
@@ -3735,12 +3696,10 @@ const next = (items, index) => {
3735
3696
  const previous = (items, index) => {
3736
3697
  return index === 0 ? items.length - 1 : index - 1;
3737
3698
  };
3738
-
3739
3699
  const focusFirst = state => {
3740
3700
  const firstIndex = first();
3741
3701
  return focusIndex(state, firstIndex);
3742
3702
  };
3743
-
3744
3703
  const focusLast = state => {
3745
3704
  const {
3746
3705
  items
@@ -3748,7 +3707,6 @@ const focusLast = state => {
3748
3707
  const lastIndex = last(items);
3749
3708
  return focusIndex(state, lastIndex);
3750
3709
  };
3751
-
3752
3710
  const focusNext = state => {
3753
3711
  const {
3754
3712
  focusedIndex,
@@ -3758,6 +3716,14 @@ const focusNext = state => {
3758
3716
  return focusIndex(state, nextIndex);
3759
3717
  };
3760
3718
 
3719
+ // based on https://github.com/microsoft/vscode/blob/c0769274fa136b45799edeccc0d0a2f645b75caf/src/vs/base/common/arrays.ts#L625 (License MIT)
3720
+
3721
+ const isLastIndex = (array, index) => {
3722
+ return index === array.length - 1;
3723
+ };
3724
+ const lastIndex = array => {
3725
+ return array.length - 1;
3726
+ };
3761
3727
  const focusNextPage = state => {
3762
3728
  const {
3763
3729
  focusedIndex,
@@ -3771,7 +3737,6 @@ const focusNextPage = state => {
3771
3737
  const indexNextPage = Math.min(maxLineY + (maxLineY - minLineY) - 2, lastIndex(items));
3772
3738
  return focusIndex(state, indexNextPage);
3773
3739
  };
3774
-
3775
3740
  const focusPrevious = state => {
3776
3741
  const {
3777
3742
  focusedIndex,
@@ -3783,7 +3748,6 @@ const focusPrevious = state => {
3783
3748
  const previousIndex = previous(items, focusedIndex);
3784
3749
  return focusIndex(state, previousIndex);
3785
3750
  };
3786
-
3787
3751
  const focusPreviousPage = state => {
3788
3752
  const {
3789
3753
  focusedIndex,
@@ -3796,6 +3760,129 @@ const focusPreviousPage = state => {
3796
3760
  const indexPreviousPage = Math.max(minLineY - (maxLineY - minLineY) + 1, 0);
3797
3761
  return focusIndex(state, indexPreviousPage);
3798
3762
  };
3763
+ const handleScrollBarCaptureLost = state => {
3764
+ return {
3765
+ ...state,
3766
+ scrollBarActive: false
3767
+ };
3768
+ };
3769
+ const getScrollBarOffset = (delta, finalDelta, size, scrollBarSize) => {
3770
+ const scrollBarOffset = delta / finalDelta * (size - scrollBarSize);
3771
+ return scrollBarOffset;
3772
+ };
3773
+ const getScrollBarY = getScrollBarOffset;
3774
+ const getNewDeltaPercent = (height, scrollBarHeight, relativeY) => {
3775
+ const halfScrollBarHeight = scrollBarHeight / 2;
3776
+ if (relativeY <= halfScrollBarHeight) {
3777
+ // clicked at top
3778
+ return {
3779
+ percent: 0,
3780
+ handleOffset: relativeY
3781
+ };
3782
+ }
3783
+ if (relativeY <= height - halfScrollBarHeight) {
3784
+ // clicked in middle
3785
+ return {
3786
+ percent: (relativeY - halfScrollBarHeight) / (height - scrollBarHeight),
3787
+ handleOffset: halfScrollBarHeight
3788
+ };
3789
+ }
3790
+ // clicked at bottom
3791
+ return {
3792
+ percent: 1,
3793
+ handleOffset: scrollBarHeight - height + relativeY
3794
+ };
3795
+ };
3796
+ const clamp = (num, min, max) => {
3797
+ return Math.min(Math.max(num, min), max);
3798
+ };
3799
+ const setDeltaY = (state, value) => {
3800
+ object(state);
3801
+ number(value);
3802
+ const {
3803
+ itemHeight,
3804
+ finalDeltaY,
3805
+ deltaY,
3806
+ height,
3807
+ headerHeight,
3808
+ items
3809
+ } = state;
3810
+ const listHeight = height - headerHeight;
3811
+ const newDeltaY = clamp(value, 0, finalDeltaY);
3812
+ if (deltaY === newDeltaY) {
3813
+ return state;
3814
+ }
3815
+ // TODO when it only moves by one px, extensions don't need to be rerendered, only negative margin
3816
+ const minLineY = Math.floor(newDeltaY / itemHeight);
3817
+ const maxLineY = Math.min(minLineY + getNumberOfVisibleItems(listHeight, itemHeight), items.length);
3818
+
3819
+ // TODO update icons
3820
+ return {
3821
+ ...state,
3822
+ deltaY: newDeltaY,
3823
+ minLineY,
3824
+ maxLineY
3825
+ };
3826
+ };
3827
+ const handleScrollBarClick = (state, eventY) => {
3828
+ const {
3829
+ y,
3830
+ deltaY,
3831
+ headerHeight,
3832
+ finalDeltaY,
3833
+ scrollBarHeight,
3834
+ height
3835
+ } = state;
3836
+ const contentHeight = height - headerHeight;
3837
+ const relativeY = eventY - y - headerHeight;
3838
+ const currentScrollBarY = getScrollBarY(deltaY, finalDeltaY, contentHeight, scrollBarHeight);
3839
+ const diff = relativeY - currentScrollBarY;
3840
+ if (diff >= 0 && diff < scrollBarHeight) {
3841
+ return {
3842
+ ...state,
3843
+ handleOffset: diff,
3844
+ scrollBarActive: true
3845
+ };
3846
+ }
3847
+ const {
3848
+ percent,
3849
+ handleOffset
3850
+ } = getNewDeltaPercent(contentHeight, scrollBarHeight, relativeY);
3851
+ const newDeltaY = percent * finalDeltaY;
3852
+ return {
3853
+ ...setDeltaY(state, newDeltaY),
3854
+ handleOffset,
3855
+ scrollBarActive: true
3856
+ };
3857
+ };
3858
+ const getNewPercent = (contentHeight, scrollBarHeight, relativeY) => {
3859
+ if (relativeY <= contentHeight - scrollBarHeight / 2) {
3860
+ // clicked in middle
3861
+ return relativeY / (contentHeight - scrollBarHeight);
3862
+ }
3863
+ // clicked at bottom
3864
+ return 1;
3865
+ };
3866
+ const handleScrollBarMove = (state, eventY) => {
3867
+ const {
3868
+ y,
3869
+ headerHeight,
3870
+ handleOffset,
3871
+ finalDeltaY,
3872
+ height,
3873
+ scrollBarHeight
3874
+ } = state;
3875
+ const relativeY = eventY - y - headerHeight - handleOffset;
3876
+ const contentHeight = height - headerHeight;
3877
+ const newPercent = getNewPercent(contentHeight, scrollBarHeight, relativeY);
3878
+ const newDeltaY = newPercent * finalDeltaY;
3879
+ return setDeltaY(state, newDeltaY);
3880
+ };
3881
+ const handleWheel = (state, deltaMode, deltaY) => {
3882
+ number(deltaMode);
3883
+ number(deltaY);
3884
+ return setDeltaY(state, state.deltaY + deltaY);
3885
+ };
3799
3886
 
3800
3887
  const getListIndex = (eventX, eventY, x, y, deltaY, itemHeight, topHeight, itemCount) => {
3801
3888
  const relativeY = eventY - y - topHeight + deltaY;
@@ -3859,7 +3946,7 @@ const selectIndexFile = async (state, searchResult, index) => {
3859
3946
  const icons = await getFileIcons(filteredResults);
3860
3947
  const total = filteredResults.length;
3861
3948
  const listHeight = height - headerHeight;
3862
- const numberOfVisible = getNumberOfVisibleItems(listHeight, itemHeight);
3949
+ const numberOfVisible = getNumberOfVisibleItems$1(listHeight, itemHeight);
3863
3950
  const maxLineY = Math.min(numberOfVisible, total);
3864
3951
  return {
3865
3952
  ...state,
@@ -3952,108 +4039,6 @@ const handleClickAt = (state, eventX, eventY) => {
3952
4039
  return selectIndex(state, index);
3953
4040
  };
3954
4041
 
3955
- const handleScrollBarCaptureLost = state => {
3956
- return {
3957
- ...state,
3958
- scrollBarActive: false
3959
- };
3960
- };
3961
-
3962
- const clamp = (num, min, max) => {
3963
- return Math.min(Math.max(num, min), max);
3964
- };
3965
-
3966
- const setDeltaY = (state, value) => {
3967
- object(state);
3968
- number(value);
3969
- const {
3970
- itemHeight,
3971
- finalDeltaY,
3972
- deltaY,
3973
- height,
3974
- headerHeight,
3975
- listItems
3976
- } = state;
3977
- const listHeight = height - headerHeight;
3978
- const newDeltaY = clamp(value, 0, finalDeltaY);
3979
- if (deltaY === newDeltaY) {
3980
- return state;
3981
- }
3982
- // TODO when it only moves by one px, extensions don't need to be rerendered, only negative margin
3983
- const minLineY = Math.floor(newDeltaY / itemHeight);
3984
- const maxLineY = Math.min(minLineY + getNumberOfVisibleItems(listHeight, itemHeight), listItems.length);
3985
-
3986
- // TODO update icons
3987
- return {
3988
- ...state,
3989
- deltaY: newDeltaY,
3990
- minLineY,
3991
- maxLineY
3992
- };
3993
- };
3994
-
3995
- const handleScrollBarClick = (state, eventY) => {
3996
- const {
3997
- y,
3998
- deltaY,
3999
- headerHeight,
4000
- finalDeltaY,
4001
- scrollBarHeight,
4002
- height
4003
- } = state;
4004
- const contentHeight = height - headerHeight;
4005
- const relativeY = eventY - y - headerHeight;
4006
- const currentScrollBarY = getScrollBarY(deltaY, finalDeltaY, contentHeight, scrollBarHeight);
4007
- const diff = relativeY - currentScrollBarY;
4008
- if (diff >= 0 && diff < scrollBarHeight) {
4009
- return {
4010
- ...state,
4011
- handleOffset: diff,
4012
- scrollBarActive: true
4013
- };
4014
- }
4015
- const {
4016
- percent,
4017
- handleOffset
4018
- } = getNewDeltaPercent(contentHeight, scrollBarHeight, relativeY);
4019
- const newDeltaY = percent * finalDeltaY;
4020
- return {
4021
- ...setDeltaY(state, newDeltaY),
4022
- handleOffset,
4023
- scrollBarActive: true
4024
- };
4025
- };
4026
-
4027
- const getNewPercent = (contentHeight, scrollBarHeight, relativeY) => {
4028
- if (relativeY <= contentHeight - scrollBarHeight / 2) {
4029
- // clicked in middle
4030
- return relativeY / (contentHeight - scrollBarHeight);
4031
- }
4032
- // clicked at bottom
4033
- return 1;
4034
- };
4035
- const handleScrollBarMove = (state, eventY) => {
4036
- const {
4037
- y,
4038
- headerHeight,
4039
- handleOffset,
4040
- finalDeltaY,
4041
- height,
4042
- scrollBarHeight
4043
- } = state;
4044
- const relativeY = eventY - y - headerHeight - handleOffset;
4045
- const contentHeight = height - headerHeight;
4046
- const newPercent = getNewPercent(contentHeight, scrollBarHeight, relativeY);
4047
- const newDeltaY = newPercent * finalDeltaY;
4048
- return setDeltaY(state, newDeltaY);
4049
- };
4050
-
4051
- const handleWheel = (state, deltaMode, deltaY) => {
4052
- number(deltaMode);
4053
- number(deltaY);
4054
- return setDeltaY(state, state.deltaY + deltaY);
4055
- };
4056
-
4057
4042
  const getSavedValue = savedState => {
4058
4043
  if (savedState && typeof savedState === 'object' && 'value' in savedState && typeof savedState.value === 'string') {
4059
4044
  return savedState.value;
@@ -4195,7 +4180,7 @@ const createViewModel = state => {
4195
4180
  const displayResults = getDisplayResults(listItems, itemHeight, fileCount, value, minLineY, maxLineY, replacement, icons, listFocusedIndex, collapsedPaths, items);
4196
4181
  const focusOutline = listFocused && listFocusedIndex === -1;
4197
4182
  const scrollBarValue = deltaY / finalDeltaY * 100;
4198
- const scrollBarY = getScrollBarY(deltaY, finalDeltaY, height - headerHeight, scrollBarHeight);
4183
+ const scrollBarY = getScrollBarY$1(deltaY, finalDeltaY, height - headerHeight, scrollBarHeight);
4199
4184
  return {
4200
4185
  displayResults,
4201
4186
  flags,
@@ -4268,16 +4253,6 @@ const render2 = (uid, diffResult) => {
4268
4253
  return commands;
4269
4254
  };
4270
4255
 
4271
- const doRender = uid => {
4272
- const {
4273
- oldState,
4274
- newState
4275
- } = get(uid);
4276
- const diffResult = diff$1(oldState, newState);
4277
- const commands = applyRender(oldState, newState, diffResult);
4278
- return commands;
4279
- };
4280
-
4281
4256
  const renderActions = uid => {
4282
4257
  const {
4283
4258
  oldState,
@@ -4340,7 +4315,7 @@ const getDom = state => {
4340
4315
  const displayResults = getDisplayResults(state.listItems, state.itemHeight, state.fileCount, state.value, state.minLineY, state.maxLineY, state.replacement, state.icons, state.listFocusedIndex, state.collapsedPaths, state.items);
4341
4316
  const focusOutline = state.listFocused && state.listFocusedIndex === -1;
4342
4317
  const scrollBarValue = state.deltaY / state.finalDeltaY * 100;
4343
- const scrollBarY = getScrollBarY(state.deltaY, state.finalDeltaY, state.height - state.headerHeight, state.scrollBarHeight);
4318
+ const scrollBarY = getScrollBarY$1(state.deltaY, state.finalDeltaY, state.height - state.headerHeight, state.scrollBarHeight);
4344
4319
  const dom = getSearchVirtualDom(displayResults, state.flags, state.message, focusOutline, state.searchInputErrorMessage, state.scrollBarHeight, scrollBarY, scrollBarValue, state.deltaY, state.itemHeight, state.matchCount);
4345
4320
  return dom;
4346
4321
  };
@@ -4650,10 +4625,6 @@ const commandMap = {
4650
4625
  'TextSearch.restoreState': restoreState,
4651
4626
  'TextSearch.saveState': saveState,
4652
4627
  'TextSearch.terminate': terminate,
4653
- // deprecated
4654
- 'TextSearch.getFlags': getFlags,
4655
- 'TextSearch.getFocus': getFocus,
4656
- 'TextSearch.render': doRender,
4657
4628
  // TODO needed?
4658
4629
  'TextSearch.textSearch': textSearch
4659
4630
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/text-search-worker",
3
- "version": "3.52.0",
3
+ "version": "4.0.0",
4
4
  "description": "Text Search Worker",
5
5
  "keywords": [
6
6
  "text-search"