@lvce-editor/text-search-worker 5.3.0 → 5.5.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.
@@ -695,7 +695,8 @@ const splitLines = lines => {
695
695
  return lines.split(NewLine);
696
696
  };
697
697
  const getCurrentStack = () => {
698
- const currentStack = joinLines(splitLines(new Error().stack || '').slice(2));
698
+ const stackLinesToSkip = 3;
699
+ const currentStack = joinLines(splitLines(new Error().stack || '').slice(stackLinesToSkip));
699
700
  return currentStack;
700
701
  };
701
702
  const getNewLineIndex = (string, startIndex = undefined) => {
@@ -966,6 +967,12 @@ const invokeAndTransfer = (ipc, method, ...params) => {
966
967
  return invokeHelper(ipc, method, params, true);
967
968
  };
968
969
 
970
+ class CommandNotFoundError extends Error {
971
+ constructor(command) {
972
+ super(`Command not found ${command}`);
973
+ this.name = 'CommandNotFoundError';
974
+ }
975
+ }
969
976
  const commands = Object.create(null);
970
977
  const register = commandMap => {
971
978
  Object.assign(commands, commandMap);
@@ -976,7 +983,7 @@ const getCommand = key => {
976
983
  const execute = (command, ...args) => {
977
984
  const fn = getCommand(command);
978
985
  if (!fn) {
979
- throw new Error(`command not found ${command}`);
986
+ throw new CommandNotFoundError(command);
980
987
  }
981
988
  return fn(...args);
982
989
  };
@@ -1098,11 +1105,12 @@ const getProtocol$1 = () => {
1098
1105
  return location.protocol;
1099
1106
  };
1100
1107
  const create$1$1 = async ({
1101
- commandMap
1108
+ commandMap,
1109
+ type
1102
1110
  }) => {
1103
1111
  const host = getHost();
1104
1112
  const protocol = getProtocol$1();
1105
- const wsUrl = getWebSocketUrl('search-process', host, protocol);
1113
+ const wsUrl = getWebSocketUrl(type, host, protocol);
1106
1114
  const webSocket = new WebSocket(wsUrl);
1107
1115
  const rpc = await create$2$1({
1108
1116
  webSocket,
@@ -1129,8 +1137,13 @@ const WebWorkerRpcClient = {
1129
1137
  create: create$4
1130
1138
  };
1131
1139
 
1140
+ const toCommandId = key => {
1141
+ const dotIndex = key.indexOf('.');
1142
+ return key.slice(dotIndex + 1);
1143
+ };
1132
1144
  const create$3 = () => {
1133
1145
  const states = Object.create(null);
1146
+ const commandMapRef = {};
1134
1147
  return {
1135
1148
  get(uid) {
1136
1149
  return states[uid];
@@ -1171,6 +1184,15 @@ const create$3 = () => {
1171
1184
  };
1172
1185
  return wrapped;
1173
1186
  },
1187
+ wrapGetter(fn) {
1188
+ const wrapped = (uid, ...args) => {
1189
+ const {
1190
+ newState
1191
+ } = states[uid];
1192
+ return fn(newState, ...args);
1193
+ };
1194
+ return wrapped;
1195
+ },
1174
1196
  diff(uid, modules, numbers) {
1175
1197
  const {
1176
1198
  oldState,
@@ -1184,6 +1206,14 @@ const create$3 = () => {
1184
1206
  }
1185
1207
  }
1186
1208
  return diffResult;
1209
+ },
1210
+ getCommandIds() {
1211
+ const keys = Object.keys(commandMapRef);
1212
+ const ids = keys.map(toCommandId);
1213
+ return ids;
1214
+ },
1215
+ registerCommands(commandMap) {
1216
+ Object.assign(commandMapRef, commandMap);
1187
1217
  }
1188
1218
  };
1189
1219
  };
@@ -1194,7 +1224,7 @@ const terminate = () => {
1194
1224
  const User = 1;
1195
1225
  const Script = 2;
1196
1226
 
1197
- const Empty$1 = 0;
1227
+ const Empty = 0;
1198
1228
  const FocusIgnoreFiles = 1012;
1199
1229
  const FocusSearch = 1013;
1200
1230
  const FocusSearchExcludeInput = 1008;
@@ -1428,7 +1458,7 @@ const create = (uid, x, y, width, height, workspacePath, assetDir, itemHeight, v
1428
1458
  workspacePath: workspacePath,
1429
1459
  includeValue: '',
1430
1460
  excludeValue: '',
1431
- focus: Empty$1,
1461
+ focus: Empty,
1432
1462
  loaded: false,
1433
1463
  message: '',
1434
1464
  collapsedPaths: [],
@@ -2156,7 +2186,7 @@ const getTextSearchResultCounts = results => {
2156
2186
  };
2157
2187
  };
2158
2188
 
2159
- const getScrollBarSize = (size, contentSize, minimumSliderSize) => {
2189
+ const getScrollBarSize$1 = (size, contentSize, minimumSliderSize) => {
2160
2190
  if (size >= contentSize) {
2161
2191
  return 0;
2162
2192
  }
@@ -2233,7 +2263,7 @@ const handleUpdateFull = async (state, update) => {
2233
2263
  const total = results.length;
2234
2264
  const contentHeight = total * itemHeight;
2235
2265
  const listHeight = height - headerHeight;
2236
- const scrollBarHeight = getScrollBarSize(height, contentHeight, minimumSliderSize);
2266
+ const scrollBarHeight = getScrollBarSize$1(height, contentHeight, minimumSliderSize);
2237
2267
  const numberOfVisible = getNumberOfVisibleItems$1(listHeight, itemHeight);
2238
2268
  const maxLineY = Math.min(numberOfVisible, total);
2239
2269
  const finalDeltaY = Math.max(contentHeight - listHeight, 0);
@@ -2752,32 +2782,75 @@ const initialize = async platform => {
2752
2782
  const getNumberOfVisibleItems = (listHeight, itemHeight) => {
2753
2783
  return Math.ceil(listHeight / itemHeight) + 1;
2754
2784
  };
2785
+ const getScrollBarOffset = (delta, finalDelta, size, scrollBarSize) => {
2786
+ const scrollBarOffset = delta / finalDelta * (size - scrollBarSize);
2787
+ return scrollBarOffset;
2788
+ };
2789
+ const getScrollBarY = getScrollBarOffset;
2790
+ const getNewDeltaPercent = (height, scrollBarHeight, relativeY) => {
2791
+ const halfScrollBarHeight = scrollBarHeight / 2;
2792
+ if (relativeY <= halfScrollBarHeight) {
2793
+ // clicked at top
2794
+ return {
2795
+ percent: 0,
2796
+ handleOffset: relativeY
2797
+ };
2798
+ }
2799
+ if (relativeY <= height - halfScrollBarHeight) {
2800
+ // clicked in middle
2801
+ return {
2802
+ percent: (relativeY - halfScrollBarHeight) / (height - scrollBarHeight),
2803
+ handleOffset: halfScrollBarHeight
2804
+ };
2805
+ }
2806
+ // clicked at bottom
2807
+ return {
2808
+ percent: 1,
2809
+ handleOffset: scrollBarHeight - height + relativeY
2810
+ };
2811
+ };
2755
2812
  const focusIndexScrollDown = (state, index, listHeight, itemHeight, itemsLength) => {
2813
+ const {
2814
+ finalDeltaY,
2815
+ height,
2816
+ headerHeight,
2817
+ scrollBarHeight
2818
+ } = state;
2756
2819
  const newMaxLineY = Math.min(index + 1, itemsLength);
2757
2820
  const fittingItems = getNumberOfVisibleItems(listHeight, itemHeight);
2758
2821
  const newMinLineY = Math.max(newMaxLineY - fittingItems, 0);
2759
2822
  const newDeltaY = itemsLength < fittingItems ? 0 : newMinLineY * itemHeight - listHeight % itemHeight + itemHeight;
2823
+ const scrollBarY = getScrollBarY(newDeltaY, finalDeltaY, height - headerHeight, scrollBarHeight);
2760
2824
  return {
2761
2825
  ...state,
2762
2826
  focusedIndex: index,
2763
2827
  minLineY: newMinLineY,
2764
2828
  maxLineY: newMaxLineY,
2765
2829
  focused: true,
2766
- deltaY: newDeltaY
2830
+ deltaY: newDeltaY,
2831
+ scrollBarY
2767
2832
  };
2768
2833
  };
2769
2834
  const focusIndexScrollUp = (state, index, listHeight, itemHeight, itemsLength) => {
2835
+ const {
2836
+ finalDeltaY,
2837
+ height,
2838
+ headerHeight,
2839
+ scrollBarHeight
2840
+ } = state;
2770
2841
  const newMinLineY = index;
2771
2842
  const fittingItems = getNumberOfVisibleItems(listHeight, itemHeight);
2772
2843
  const newMaxLineY = Math.min(newMinLineY + fittingItems, itemsLength);
2773
2844
  const newDeltaY = newMinLineY * itemHeight;
2845
+ const scrollBarY = getScrollBarY(newDeltaY, finalDeltaY, height - headerHeight, scrollBarHeight);
2774
2846
  return {
2775
2847
  ...state,
2776
2848
  focusedIndex: index,
2777
2849
  minLineY: newMinLineY,
2778
2850
  maxLineY: newMaxLineY,
2779
2851
  focused: true,
2780
- deltaY: newDeltaY
2852
+ deltaY: newDeltaY,
2853
+ scrollBarY
2781
2854
  };
2782
2855
  };
2783
2856
  const focusIndex = (state, index) => {
@@ -2896,36 +2969,15 @@ const handleScrollBarCaptureLost = state => {
2896
2969
  scrollBarActive: false
2897
2970
  };
2898
2971
  };
2899
- const getScrollBarOffset = (delta, finalDelta, size, scrollBarSize) => {
2900
- const scrollBarOffset = delta / finalDelta * (size - scrollBarSize);
2901
- return scrollBarOffset;
2902
- };
2903
- const getScrollBarY = getScrollBarOffset;
2904
- const getNewDeltaPercent = (height, scrollBarHeight, relativeY) => {
2905
- const halfScrollBarHeight = scrollBarHeight / 2;
2906
- if (relativeY <= halfScrollBarHeight) {
2907
- // clicked at top
2908
- return {
2909
- percent: 0,
2910
- handleOffset: relativeY
2911
- };
2912
- }
2913
- if (relativeY <= height - halfScrollBarHeight) {
2914
- // clicked in middle
2915
- return {
2916
- percent: (relativeY - halfScrollBarHeight) / (height - scrollBarHeight),
2917
- handleOffset: halfScrollBarHeight
2918
- };
2919
- }
2920
- // clicked at bottom
2921
- return {
2922
- percent: 1,
2923
- handleOffset: scrollBarHeight - height + relativeY
2924
- };
2925
- };
2926
2972
  const clamp = (num, min, max) => {
2927
2973
  return Math.min(Math.max(num, min), max);
2928
2974
  };
2975
+ const getScrollBarSize = (size, contentSize, minimumSliderSize) => {
2976
+ if (size >= contentSize) {
2977
+ return 0;
2978
+ }
2979
+ return Math.max(Math.round(size ** 2 / contentSize), minimumSliderSize);
2980
+ };
2929
2981
  const setDeltaY = (state, value) => {
2930
2982
  object(state);
2931
2983
  number(value);
@@ -2935,7 +2987,8 @@ const setDeltaY = (state, value) => {
2935
2987
  deltaY,
2936
2988
  height,
2937
2989
  headerHeight,
2938
- items
2990
+ items,
2991
+ minimumSliderSize
2939
2992
  } = state;
2940
2993
  const listHeight = height - headerHeight;
2941
2994
  const newDeltaY = clamp(value, 0, finalDeltaY);
@@ -2945,13 +2998,18 @@ const setDeltaY = (state, value) => {
2945
2998
  // TODO when it only moves by one px, extensions don't need to be rerendered, only negative margin
2946
2999
  const minLineY = Math.floor(newDeltaY / itemHeight);
2947
3000
  const maxLineY = Math.min(minLineY + getNumberOfVisibleItems(listHeight, itemHeight), items.length);
2948
-
2949
3001
  // TODO update icons
3002
+
3003
+ const total = items.length;
3004
+ const contentHeight = total * itemHeight;
3005
+ const scrollBarHeight = getScrollBarSize(listHeight, contentHeight, minimumSliderSize);
3006
+ const scrollBarY = getScrollBarY(newDeltaY, finalDeltaY, height - headerHeight, scrollBarHeight);
2950
3007
  return {
2951
3008
  ...state,
2952
3009
  deltaY: newDeltaY,
2953
3010
  minLineY,
2954
- maxLineY
3011
+ maxLineY,
3012
+ scrollBarY
2955
3013
  };
2956
3014
  };
2957
3015
  const handleScrollBarClick = (state, eventY) => {
@@ -3489,7 +3547,7 @@ const Actions = 'Actions';
3489
3547
  const Badge = 'Badge';
3490
3548
  const Chevron = 'Chevron';
3491
3549
  const CloseMaskIcon = 'MaskIcon MaskIconClose';
3492
- const Empty = '';
3550
+ const Empty$1 = '';
3493
3551
  const FileIcon = 'FileIcon';
3494
3552
  const FocusOutline = 'FocusOutline';
3495
3553
  const Grow = 'Grow';
@@ -3548,7 +3606,7 @@ const ClassNames = {
3548
3606
  Badge,
3549
3607
  Chevron,
3550
3608
  CloseMaskIcon,
3551
- Empty,
3609
+ Empty: Empty$1,
3552
3610
  FileIcon,
3553
3611
  FocusOutline,
3554
3612
  Grow,
@@ -3600,8 +3658,7 @@ const ClassNames = {
3600
3658
  TreeItems: TreeItems$1,
3601
3659
  Viewlet,
3602
3660
  ViewletSearchMessage,
3603
- ViewletSearchMessageIndented
3604
- };
3661
+ ViewletSearchMessageIndented};
3605
3662
  const mergeClassNames = (...classNames) => {
3606
3663
  return classNames.filter(Boolean).join(' ');
3607
3664
  };
@@ -4779,7 +4836,7 @@ const getSearchFocusKey = key => {
4779
4836
  case ToggleReplace:
4780
4837
  return FocusToggleReplace;
4781
4838
  default:
4782
- return Empty$1;
4839
+ return Empty;
4783
4840
  }
4784
4841
  };
4785
4842
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/text-search-worker",
3
- "version": "5.3.0",
3
+ "version": "5.5.0",
4
4
  "description": "Text Search Worker",
5
5
  "keywords": [
6
6
  "text-search"