@lvce-editor/text-search-worker 3.12.0 → 3.14.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.
@@ -1,5 +1,5 @@
1
1
  const Two = '2.0';
2
- const create$4 = (method, params) => {
2
+ const create$4$1 = (method, params) => {
3
3
  return {
4
4
  jsonrpc: Two,
5
5
  method,
@@ -19,14 +19,14 @@ const remove$1 = id => {
19
19
  delete state$2.callbacks[id];
20
20
  };
21
21
  let id = 0;
22
- const create$3 = () => {
22
+ const create$3$1 = () => {
23
23
  return ++id;
24
24
  };
25
25
  const warn = (...args) => {
26
26
  console.warn(...args);
27
27
  };
28
28
  const registerPromise = () => {
29
- const id = create$3();
29
+ const id = create$3$1();
30
30
  const {
31
31
  resolve,
32
32
  promise
@@ -47,7 +47,7 @@ const resolve = (id, response) => {
47
47
  fn(response);
48
48
  remove$1(id);
49
49
  };
50
- const create$2 = (method, params) => {
50
+ const create$2$1 = (method, params) => {
51
51
  const {
52
52
  id,
53
53
  promise
@@ -237,7 +237,7 @@ const getErrorResponse = (message, error, preparePrettyError, logError) => {
237
237
  const errorProperty = getErrorProperty(error, prettyError);
238
238
  return create$1$2(message, errorProperty);
239
239
  };
240
- const create$5 = (message, result) => {
240
+ const create$6 = (message, result) => {
241
241
  return {
242
242
  jsonrpc: Two,
243
243
  id: message.id,
@@ -246,7 +246,7 @@ const create$5 = (message, result) => {
246
246
  };
247
247
  const getSuccessResponse = (message, result) => {
248
248
  const resultProperty = result ?? null;
249
- return create$5(message, resultProperty);
249
+ return create$6(message, resultProperty);
250
250
  };
251
251
  const getResponse = async (message, ipc, execute, preparePrettyError, logError, requiresSocket) => {
252
252
  try {
@@ -326,7 +326,7 @@ const invokeHelper = async (ipc, method, params, useSendAndTransfer) => {
326
326
  const {
327
327
  message,
328
328
  promise
329
- } = create$2(method, params);
329
+ } = create$2$1(method, params);
330
330
  if (useSendAndTransfer && ipc.sendAndTransfer) {
331
331
  ipc.sendAndTransfer(message);
332
332
  } else {
@@ -336,13 +336,13 @@ const invokeHelper = async (ipc, method, params, useSendAndTransfer) => {
336
336
  return unwrapJsonRpcResult(responseMessage);
337
337
  };
338
338
  const send = (transport, method, ...params) => {
339
- const message = create$4(method, params);
339
+ const message = create$4$1(method, params);
340
340
  transport.send(message);
341
341
  };
342
342
  const invoke$2 = (ipc, method, ...params) => {
343
343
  return invokeHelper(ipc, method, params, false);
344
344
  };
345
- const invokeAndTransfer = (ipc, method, ...params) => {
345
+ const invokeAndTransfer$1 = (ipc, method, ...params) => {
346
346
  return invokeHelper(ipc, method, params, true);
347
347
  };
348
348
 
@@ -639,7 +639,7 @@ let VError$1 = class VError extends Error {
639
639
  }
640
640
  }
641
641
  };
642
- class IpcError extends VError$1 {
642
+ let IpcError$1 = class IpcError extends VError$1 {
643
643
  // @ts-ignore
644
644
  constructor(betterMessage, stdout = '', stderr = '') {
645
645
  if (stdout || stderr) {
@@ -664,7 +664,7 @@ class IpcError extends VError$1 {
664
664
  // @ts-ignore
665
665
  this.stderr = stderr;
666
666
  }
667
- }
667
+ };
668
668
  const withResolvers = () => {
669
669
  let _resolve;
670
670
  const promise = new Promise(resolve => {
@@ -693,7 +693,7 @@ const listen$1$1 = async () => {
693
693
  const parentIpc = wrap$5(parentIpcRaw);
694
694
  const firstMessage = await waitForFirstMessage(parentIpc);
695
695
  if (firstMessage.method !== 'initialize') {
696
- throw new IpcError('unexpected first message');
696
+ throw new IpcError$1('unexpected first message');
697
697
  }
698
698
  const type = firstMessage.params[0];
699
699
  if (type === 'message-port') {
@@ -756,7 +756,7 @@ const createRpc = ipc => {
756
756
  return invoke$2(ipc, method, ...params);
757
757
  },
758
758
  invokeAndTransfer(method, ...params) {
759
- return invokeAndTransfer(ipc, method, ...params);
759
+ return invokeAndTransfer$1(ipc, method, ...params);
760
760
  }
761
761
  };
762
762
  return rpc;
@@ -840,6 +840,11 @@ const invoke$1 = (method, ...params) => {
840
840
  // @ts-ignore
841
841
  return rpc.invoke(method, ...params);
842
842
  };
843
+ const invokeAndTransfer = (method, ...params) => {
844
+ const rpc = state$1.rpc;
845
+ // @ts-ignore
846
+ return rpc.invokeAndTransfer(method, ...params);
847
+ };
843
848
  const setRpc = rpc => {
844
849
  state$1.rpc = rpc;
845
850
  };
@@ -870,7 +875,7 @@ const set = (uid, oldState, newState) => {
870
875
  };
871
876
  };
872
877
 
873
- const create$1 = ({
878
+ const create$5 = ({
874
879
  itemHeight,
875
880
  headerHeight = 0,
876
881
  minimumSliderSize = 20
@@ -883,6 +888,7 @@ const create$1 = ({
883
888
  itemHeight,
884
889
  headerHeight,
885
890
  items: [],
891
+ listItems: [],
886
892
  minimumSliderSize,
887
893
  focusedIndex: -1,
888
894
  touchOffsetY: 0,
@@ -893,7 +899,7 @@ const create$1 = ({
893
899
  };
894
900
  };
895
901
 
896
- const create = (uid, x, y, width, height, workspacePath, assetDir, itemHeight, value = '', replacement = '') => {
902
+ const create$4 = (uid, x, y, width, height, workspacePath, assetDir, itemHeight, value = '', replacement = '') => {
897
903
  const state = {
898
904
  uid,
899
905
  searchResults: [],
@@ -906,7 +912,7 @@ const create = (uid, x, y, width, height, workspacePath, assetDir, itemHeight, v
906
912
  y,
907
913
  width,
908
914
  height,
909
- ...create$1({
915
+ ...create$5({
910
916
  itemHeight: itemHeight || 22,
911
917
  minimumSliderSize: minimumSliderSize,
912
918
  headerHeight: 61 // TODO
@@ -979,7 +985,6 @@ const i18nString = (key, placeholders = emptyObject) => {
979
985
  return key;
980
986
  }
981
987
  const replacer = (match, rest) => {
982
- // @ts-ignore
983
988
  return placeholders[rest];
984
989
  };
985
990
  return key.replaceAll(RE_PLACEHOLDER, replacer);
@@ -1274,29 +1279,29 @@ const focusMatchCase$1 = state => {
1274
1279
  };
1275
1280
  };
1276
1281
 
1277
- const PreserveCase = 1 << 0; // 1
1278
- const UseRegularExpression = 1 << 1; // 2
1282
+ const PreserveCase$1 = 1 << 0; // 1
1283
+ const UseRegularExpression$1 = 1 << 1; // 2
1279
1284
  const ReplaceExpanded = 1 << 2; // 4
1280
- const MatchWholeWord = 1 << 3; // 8
1281
- const MatchCase = 1 << 4; // 16
1285
+ const MatchWholeWord$1 = 1 << 3; // 8
1286
+ const MatchCase$1 = 1 << 4; // 16
1282
1287
  const DetailsExpanded = 1 << 5; // 32
1283
1288
  const OpenEditors = 1 << 6; // 64
1284
1289
  const UseIgnoreFiles = 1 << 7; // 128
1285
1290
 
1286
1291
  const hasPreserveCase = flags => {
1287
- return (flags & PreserveCase) === PreserveCase;
1292
+ return (flags & PreserveCase$1) === PreserveCase$1;
1288
1293
  };
1289
1294
  const hasUseRegularExpression = flags => {
1290
- return (flags & UseRegularExpression) === UseRegularExpression;
1295
+ return (flags & UseRegularExpression$1) === UseRegularExpression$1;
1291
1296
  };
1292
1297
  const hasReplaceExpanded = flags => {
1293
1298
  return (flags & ReplaceExpanded) === ReplaceExpanded;
1294
1299
  };
1295
1300
  const hasMatchWholeWord = flags => {
1296
- return (flags & MatchWholeWord) === MatchWholeWord;
1301
+ return (flags & MatchWholeWord$1) === MatchWholeWord$1;
1297
1302
  };
1298
1303
  const hasMatchCase = flags => {
1299
- return (flags & MatchCase) === MatchCase;
1304
+ return (flags & MatchCase$1) === MatchCase$1;
1300
1305
  };
1301
1306
  const hasDetailsExpanded = flags => {
1302
1307
  return (flags & DetailsExpanded) === DetailsExpanded;
@@ -1531,6 +1536,20 @@ const getActionsVirtualDom = actions => {
1531
1536
  }, ...actions.flatMap(getActionVirtualDom)];
1532
1537
  };
1533
1538
 
1539
+ const getFlags = uid => {
1540
+ const {
1541
+ newState
1542
+ } = get(uid);
1543
+ return newState.flags;
1544
+ };
1545
+
1546
+ const getFocus = uid => {
1547
+ const {
1548
+ newState
1549
+ } = get(uid);
1550
+ return newState.focus;
1551
+ };
1552
+
1534
1553
  const Tab = 2;
1535
1554
  const Enter = 3;
1536
1555
  const End = 255;
@@ -1691,26 +1710,8 @@ const getDisplayResult = (result, fileIcons, fileIconIndex, itemHeight, i, setSi
1691
1710
  }
1692
1711
  };
1693
1712
 
1694
- const getFilteredResults = (results, collapsedPaths) => {
1695
- const filteredResults = [];
1696
- let isExcluded = false;
1697
- for (const result of results) {
1698
- if (result.type === File$1) {
1699
- if (collapsedPaths.includes(result.text)) {
1700
- isExcluded = true;
1701
- } else {
1702
- isExcluded = false;
1703
- }
1704
- }
1705
- if (!isExcluded) {
1706
- filteredResults.push(result);
1707
- }
1708
- }
1709
- return filteredResults;
1710
- };
1711
- const getDisplayResults = (results, itemHeight, resultCount, searchTerm, minLineY, maxLineY, replacement, collapsedPaths, fileIcons, focusedIndex) => {
1713
+ const getDisplayResults = (results, itemHeight, resultCount, searchTerm, minLineY, maxLineY, replacement, fileIcons, focusedIndex) => {
1712
1714
  const displayResults = [];
1713
- const filteredResults = getFilteredResults(results, collapsedPaths);
1714
1715
  const setSize = resultCount;
1715
1716
  const searchTermLength = searchTerm.length;
1716
1717
  let fileResult = {
@@ -1718,7 +1719,7 @@ const getDisplayResults = (results, itemHeight, resultCount, searchTerm, minLine
1718
1719
  };
1719
1720
  let fileIconIndex = 0;
1720
1721
  for (let i = minLineY; i < maxLineY; i++) {
1721
- const result = filteredResults[i];
1722
+ const result = results[i];
1722
1723
  const displayResult = getDisplayResult(result, fileIcons, fileIconIndex, itemHeight, i, setSize, searchTermLength, replacement, focusedIndex);
1723
1724
  displayResults.push(displayResult);
1724
1725
  if (result.type === File$1) {
@@ -1845,18 +1846,34 @@ const getSearchFieldVirtualDom = (name, placeholder, onInput, insideButtons, out
1845
1846
  return dom;
1846
1847
  };
1847
1848
 
1849
+ const FilesToExclude = 'FilesToExclude';
1850
+ const FilesToInclude = 'FilesToInclude';
1851
+ const MatchCase = 'MatchCase';
1852
+ const MatchWholeWord = 'MatchWholeWord';
1853
+ const PreserveCase = 'PreserveCase';
1854
+ const ReplaceAll = 'ReplaceAll';
1855
+ const ReplaceValue = 'ReplaceValue';
1856
+ const SearchOnlyOpenEditors = 'SearchOnlyOpenEditors';
1857
+ const SearchValue = 'SearchValue';
1858
+ const ToggleReplace = 'ToggleReplace';
1859
+ const ToggleSearchDetails = 'ToggleSearchDetails';
1860
+ const UseExcludeSettings = 'UseExcludeSettings';
1861
+ const UseRegularExpression = 'UseRegularExpression';
1862
+
1848
1863
  const getSearchHeaderDetailsExpandedVirtualDom = (flags, message) => {
1849
1864
  const includeButtons = [{
1850
1865
  icon: MaskIconBook,
1851
1866
  title: searchOnlyOpenEditors(),
1852
1867
  command: 'searchOnlyOpenEditors',
1853
- checked: Boolean(flags & OpenEditors)
1868
+ checked: Boolean(flags & OpenEditors),
1869
+ name: SearchOnlyOpenEditors
1854
1870
  }];
1855
1871
  const excludeButtons = [{
1856
1872
  icon: MaskIconExclude,
1857
1873
  title: useExcludeSettings(),
1858
1874
  command: 'toggleUseExcludeSettings',
1859
- checked: Boolean(flags & UseIgnoreFiles)
1875
+ checked: Boolean(flags & UseIgnoreFiles),
1876
+ name: UseExcludeSettings
1860
1877
  }];
1861
1878
  return [{
1862
1879
  type: Div,
@@ -1870,11 +1887,11 @@ const getSearchHeaderDetailsExpandedVirtualDom = (flags, message) => {
1870
1887
  type: H4,
1871
1888
  className: SearchHeaderDetailsHeading,
1872
1889
  childCount: 1
1873
- }, text(filesToInclude()), ...getSearchFieldVirtualDom('files-to-include-value', 'Include', 'handleIncludeInput', includeButtons, []), {
1890
+ }, text(filesToInclude()), ...getSearchFieldVirtualDom(FilesToInclude, 'Include', 'handleIncludeInput', includeButtons, []), {
1874
1891
  type: H4,
1875
1892
  className: SearchHeaderDetailsHeading,
1876
1893
  childCount: 1
1877
- }, text(filesToExclude()), ...getSearchFieldVirtualDom('files-to-exclude-value', 'Exclude', 'handleExcludeInput', excludeButtons, []), ...getSearchMessageVirtualDom(message)];
1894
+ }, text(filesToExclude()), ...getSearchFieldVirtualDom(FilesToExclude, 'Exclude', 'handleExcludeInput', excludeButtons, []), ...getSearchMessageVirtualDom(message)];
1878
1895
  };
1879
1896
 
1880
1897
  const getSearchHeaderDetailsVirtualDom = (flags, message) => {
@@ -1911,28 +1928,33 @@ const getSearchHeaderTopVirtualDom = flags => {
1911
1928
  className: SearchHeaderTopRight,
1912
1929
  role: None,
1913
1930
  childCount: hasReplaceExpanded(flags) ? 2 : 1
1914
- }, ...getSearchFieldVirtualDom('search-value', 'Search', 'handleInput', [{
1931
+ }, ...getSearchFieldVirtualDom(SearchValue, 'Search', 'handleInput', [{
1915
1932
  icon: MaskIconCaseSensitive,
1916
1933
  checked: hasMatchCase(flags),
1917
- title: matchCase()
1934
+ title: matchCase(),
1935
+ name: MatchCase
1918
1936
  }, {
1919
1937
  icon: MaskIconWholeWord,
1920
1938
  checked: hasMatchWholeWord(flags),
1921
- title: matchWholeWord()
1939
+ title: matchWholeWord(),
1940
+ name: MatchWholeWord
1922
1941
  }, {
1923
1942
  icon: MaskIconRegex,
1924
1943
  checked: hasUseRegularExpression(flags),
1925
- title: useRegularExpression()
1944
+ title: useRegularExpression(),
1945
+ name: UseRegularExpression
1926
1946
  }], [])];
1927
1947
  if (hasReplaceExpanded(flags)) {
1928
- dom.push(...getSearchFieldVirtualDom('search-replace-value', 'Replace', 'handleReplaceInput', [{
1948
+ dom.push(...getSearchFieldVirtualDom(ReplaceValue, 'Replace', 'handleReplaceInput', [{
1929
1949
  icon: MaskIconPreserveCase,
1930
1950
  checked: hasPreserveCase(flags),
1931
- title: preserveCase()
1951
+ title: preserveCase(),
1952
+ name: PreserveCase
1932
1953
  }], [{
1933
1954
  icon: MaskIconReplaceAll,
1934
1955
  checked: false,
1935
- title: replaceAll$1()
1956
+ title: replaceAll$1(),
1957
+ name: ReplaceAll
1936
1958
  }]));
1937
1959
  }
1938
1960
  return dom;
@@ -2446,7 +2468,7 @@ function promisifyRequest(request) {
2446
2468
  request.removeEventListener('error', error);
2447
2469
  };
2448
2470
  const success = () => {
2449
- resolve(wrap(request.result));
2471
+ resolve(wrap$2(request.result));
2450
2472
  unlisten();
2451
2473
  };
2452
2474
  const error = () => {
@@ -2496,7 +2518,7 @@ let idbProxyTraps = {
2496
2518
  }
2497
2519
  }
2498
2520
  // Else transform whatever we get back.
2499
- return wrap(target[prop]);
2521
+ return wrap$2(target[prop]);
2500
2522
  },
2501
2523
  set(target, prop, value) {
2502
2524
  target[prop] = value;
@@ -2525,13 +2547,13 @@ function wrapFunction(func) {
2525
2547
  // Calling the original function with the proxy as 'this' causes ILLEGAL INVOCATION, so we use
2526
2548
  // the original object.
2527
2549
  func.apply(unwrap(this), args);
2528
- return wrap(this.request);
2550
+ return wrap$2(this.request);
2529
2551
  };
2530
2552
  }
2531
2553
  return function (...args) {
2532
2554
  // Calling the original function with the proxy as 'this' causes ILLEGAL INVOCATION, so we use
2533
2555
  // the original object.
2534
- return wrap(func.apply(unwrap(this), args));
2556
+ return wrap$2(func.apply(unwrap(this), args));
2535
2557
  };
2536
2558
  }
2537
2559
  function transformCachableValue(value) {
@@ -2543,7 +2565,7 @@ function transformCachableValue(value) {
2543
2565
  // Return the same value back if we're not going to transform it.
2544
2566
  return value;
2545
2567
  }
2546
- function wrap(value) {
2568
+ function wrap$2(value) {
2547
2569
  // We sometimes generate multiple promises from a single IDBRequest (eg when cursoring), because
2548
2570
  // IDB is weird and a single IDBRequest can yield many responses, so these can't be cached.
2549
2571
  if (value instanceof IDBRequest) return promisifyRequest(value);
@@ -2575,10 +2597,10 @@ function openDB(name, version, {
2575
2597
  terminated
2576
2598
  } = {}) {
2577
2599
  const request = indexedDB.open(name, version);
2578
- const openPromise = wrap(request);
2600
+ const openPromise = wrap$2(request);
2579
2601
  if (upgrade) {
2580
2602
  request.addEventListener('upgradeneeded', event => {
2581
- upgrade(wrap(request.result), event.oldVersion, event.newVersion, wrap(request.transaction), event);
2603
+ upgrade(wrap$2(request.result), event.oldVersion, event.newVersion, wrap$2(request.transaction), event);
2582
2604
  });
2583
2605
  }
2584
2606
  if (blocked) {
@@ -2888,6 +2910,7 @@ const handleUpdate = async (state, update) => {
2888
2910
  maxLineY: 0,
2889
2911
  deltaY: 0,
2890
2912
  items: [],
2913
+ listItems: [],
2891
2914
  matchCount: 0,
2892
2915
  message: '',
2893
2916
  loaded: true
@@ -2922,6 +2945,7 @@ const handleUpdate = async (state, update) => {
2922
2945
  deltaY: 0,
2923
2946
  value,
2924
2947
  items: results,
2948
+ listItems: results,
2925
2949
  message,
2926
2950
  maxLineY: maxLineY,
2927
2951
  scrollBarHeight,
@@ -2938,6 +2962,7 @@ const handleUpdate = async (state, update) => {
2938
2962
  ...partialNewState,
2939
2963
  message: `${error}`,
2940
2964
  items: [],
2965
+ listItems: [],
2941
2966
  matchCount: 0,
2942
2967
  fileCount: 0,
2943
2968
  minLineY: 0,
@@ -2982,6 +3007,10 @@ const handleInput = (state, value, inputSource = Script) => {
2982
3007
  });
2983
3008
  };
2984
3009
 
3010
+ const handleListBlur = state => {
3011
+ return state;
3012
+ };
3013
+
2985
3014
  const handleReplaceInput = (state, value, inputSource = Script) => {
2986
3015
  return handleUpdate(state, {
2987
3016
  replacement: value,
@@ -3007,6 +3036,296 @@ const handleSharedInput = (state, name, value, inputSource = Script) => {
3007
3036
  return fn(state, value, inputSource);
3008
3037
  };
3009
3038
 
3039
+ const NodeAlternate = 8;
3040
+
3041
+ const getData = event => {
3042
+ const {
3043
+ data
3044
+ } = event;
3045
+ return data;
3046
+ };
3047
+
3048
+ const getPortTuple = () => {
3049
+ const {
3050
+ port1,
3051
+ port2
3052
+ } = new MessageChannel();
3053
+ return {
3054
+ port1,
3055
+ port2
3056
+ };
3057
+ };
3058
+
3059
+ const Open = 1;
3060
+ const Close = 2;
3061
+
3062
+ const Https = 'https:';
3063
+ const Ws = 'ws:';
3064
+ const Wss = 'wss:';
3065
+
3066
+ const getWebSocketProtocol = () => {
3067
+ return location.protocol === Https ? Wss : Ws;
3068
+ };
3069
+
3070
+ const getWebSocketUrl = (type, host) => {
3071
+ const wsProtocol = getWebSocketProtocol();
3072
+ return `${wsProtocol}//${host}/websocket/${type}`;
3073
+ };
3074
+
3075
+ class IpcError extends Error {
3076
+ constructor(message) {
3077
+ super(message);
3078
+ this.name = 'IpcError';
3079
+ }
3080
+ }
3081
+
3082
+ const stringifyCompact = value => {
3083
+ return JSON.stringify(value);
3084
+ };
3085
+ const parse = content => {
3086
+ if (content === 'undefined') {
3087
+ return null;
3088
+ }
3089
+ // TODO use better json parse to throw more helpful error messages if json is invalid
3090
+ try {
3091
+ return JSON.parse(content);
3092
+ } catch (error) {
3093
+ throw new VError(error, 'failed to parse json');
3094
+ }
3095
+ };
3096
+
3097
+ const create$3 = (url, args) => {
3098
+ const webSocket = new WebSocket(url, args);
3099
+ const reconnect = () => {
3100
+ const originalOnMessage = context.webSocket.onmessage;
3101
+ context.webSocket = new WebSocket(url, args);
3102
+ context.webSocket.onmessage = originalOnMessage;
3103
+ context.webSocket.onclose = handleClose;
3104
+ };
3105
+ const handleClose = () => {
3106
+ setTimeout(reconnect, 2000);
3107
+ };
3108
+ const context = {
3109
+ webSocket,
3110
+ get onmessage() {
3111
+ return this.webSocket.onmessage;
3112
+ },
3113
+ set onmessage(value) {
3114
+ this.webSocket.onmessage = value;
3115
+ },
3116
+ send(message) {
3117
+ this.webSocket.send(message);
3118
+ },
3119
+ addEventListener(type, listener) {
3120
+ this.webSocket.addEventListener(type, listener);
3121
+ },
3122
+ removeEventListener(type, listener) {
3123
+ this.webSocket.removeEventListener(type, listener);
3124
+ }
3125
+ };
3126
+ webSocket.onclose = handleClose;
3127
+ return context;
3128
+ };
3129
+
3130
+ const getFirstEvent = (eventTarget, eventMap) => {
3131
+ const {
3132
+ resolve,
3133
+ promise
3134
+ } = Promise.withResolvers();
3135
+ const listenerMap = Object.create(null);
3136
+ const cleanup = value => {
3137
+ for (const event of Object.keys(eventMap)) {
3138
+ eventTarget.removeEventListener(event, listenerMap[event]);
3139
+ }
3140
+ resolve(value);
3141
+ };
3142
+ for (const [event, type] of Object.entries(eventMap)) {
3143
+ const listener = event => {
3144
+ cleanup({
3145
+ type,
3146
+ event
3147
+ });
3148
+ };
3149
+ eventTarget.addEventListener(event, listener);
3150
+ listenerMap[event] = listener;
3151
+ }
3152
+ return promise;
3153
+ };
3154
+
3155
+ const waitForWebSocketToBeOpen = webSocket => {
3156
+ return getFirstEvent(webSocket, {
3157
+ open: Open,
3158
+ close: Close
3159
+ });
3160
+ };
3161
+
3162
+ const getHost = () => {
3163
+ return location.host;
3164
+ };
3165
+
3166
+ const create$2 = async ({
3167
+ type
3168
+ }) => {
3169
+ string(type);
3170
+ const host = getHost();
3171
+ const wsUrl = getWebSocketUrl(type, host);
3172
+ const webSocket = create$3(wsUrl);
3173
+ const firstWebSocketEvent = await waitForWebSocketToBeOpen(webSocket);
3174
+ if (firstWebSocketEvent.type === Close) {
3175
+ throw new IpcError('Websocket connection was immediately closed');
3176
+ }
3177
+ return webSocket;
3178
+ };
3179
+ const getMessage = event => {
3180
+ return parse(event.data);
3181
+ };
3182
+ const wrap$1 = webSocket => {
3183
+ return {
3184
+ webSocket,
3185
+ /**
3186
+ * @type {any}
3187
+ */
3188
+ listener: undefined,
3189
+ get onmessage() {
3190
+ return this.listener;
3191
+ },
3192
+ set onmessage(listener) {
3193
+ this.listener = listener;
3194
+ const wrappedListener = event => {
3195
+ const message = getMessage(event);
3196
+ const syntheticEvent = {
3197
+ data: message,
3198
+ target: this
3199
+ };
3200
+ listener(syntheticEvent);
3201
+ };
3202
+ this.webSocket.onmessage = wrappedListener;
3203
+ },
3204
+ send(message) {
3205
+ const stringifiedMessage = stringifyCompact(message);
3206
+ this.webSocket.send(stringifiedMessage);
3207
+ }
3208
+ };
3209
+ };
3210
+
3211
+ const IpcParentWithWebSocket = {
3212
+ __proto__: null,
3213
+ create: create$2,
3214
+ wrap: wrap$1
3215
+ };
3216
+
3217
+ const Web = 1;
3218
+ const Electron = 2;
3219
+ const Remote = 3;
3220
+
3221
+ const sendMessagePortToElectron = async (port, initialCommand, ipcId) => {
3222
+ object(port);
3223
+ string(initialCommand);
3224
+ await invokeAndTransfer(initialCommand, port, ipcId);
3225
+ };
3226
+
3227
+ const create$1 = async options => {
3228
+ switch (options.platform) {
3229
+ case Web:
3230
+ case Remote:
3231
+ const module = IpcParentWithWebSocket;
3232
+ const rawIpc = await module.create(options);
3233
+ if (options.raw) {
3234
+ return rawIpc;
3235
+ }
3236
+ return {
3237
+ rawIpc,
3238
+ module
3239
+ };
3240
+ case Electron:
3241
+ const {
3242
+ port1,
3243
+ port2
3244
+ } = getPortTuple();
3245
+ await sendMessagePortToElectron(port2, options.initialCommand, options.ipcId);
3246
+ return port1;
3247
+ default:
3248
+ throw new Error('unsupported platform');
3249
+ }
3250
+ };
3251
+ const wrap = port => {
3252
+ if (!(port instanceof MessagePort)) {
3253
+ return port.module.wrap(port.rawIpc);
3254
+ }
3255
+ return {
3256
+ port,
3257
+ /**
3258
+ * @type {any}
3259
+ */
3260
+ listener: undefined,
3261
+ get onmessage() {
3262
+ return this.listener;
3263
+ },
3264
+ set onmessage(listener) {
3265
+ this.listener = listener;
3266
+ const wrappedListener = event => {
3267
+ const data = getData(event);
3268
+ const syntheticEvent = {
3269
+ data,
3270
+ target: this
3271
+ };
3272
+ listener(syntheticEvent);
3273
+ };
3274
+ this.port.onmessage = wrappedListener;
3275
+ },
3276
+ send(message) {
3277
+ this.port.postMessage(message);
3278
+ },
3279
+ sendAndTransfer(message, transfer) {
3280
+ this.port.postMessage(message, transfer);
3281
+ }
3282
+ };
3283
+ };
3284
+
3285
+ const IpcParentWithNodeAlternate = {
3286
+ __proto__: null,
3287
+ create: create$1,
3288
+ wrap
3289
+ };
3290
+
3291
+ const getModule = method => {
3292
+ switch (method) {
3293
+ case NodeAlternate:
3294
+ return IpcParentWithNodeAlternate;
3295
+ default:
3296
+ throw new Error('unexpected ipc type');
3297
+ }
3298
+ };
3299
+
3300
+ const create = async ({
3301
+ method,
3302
+ ...options
3303
+ }) => {
3304
+ const module = getModule(method);
3305
+ // @ts-ignore
3306
+ const rawIpc = await module.create(options);
3307
+ if (options.noReturn) {
3308
+ return undefined;
3309
+ }
3310
+ if (options.raw) {
3311
+ return rawIpc;
3312
+ }
3313
+ const ipc = module.wrap(rawIpc);
3314
+ return ipc;
3315
+ };
3316
+
3317
+ const launchSearchProcess = async () => {
3318
+ const ipc = await create({
3319
+ method: NodeAlternate,
3320
+ type: 'search-process',
3321
+ name: 'Search Process',
3322
+ initialCommand: 'HandleMessagePortForSearchProcess.handleMessagePortForSearchProcess'
3323
+ });
3324
+ // TODO
3325
+ // HandleIpc.handleIpc(ipc)
3326
+ return ipc;
3327
+ };
3328
+
3010
3329
  const first = () => {
3011
3330
  return 0;
3012
3331
  };
@@ -3144,23 +3463,65 @@ const focusPreviousPage = state => {
3144
3463
  return focusIndex(state, indexPreviousPage);
3145
3464
  };
3146
3465
 
3147
- const getListIndex = (eventX, eventY, x, y, deltaY, itemHeight) => {
3148
- const relativeY = eventY - y + deltaY;
3466
+ const getListIndex = (eventX, eventY, x, y, deltaY, itemHeight, topHeight) => {
3467
+ const relativeY = eventY - y - topHeight + deltaY;
3149
3468
  const index = Math.floor(relativeY / itemHeight);
3150
3469
  return index;
3151
3470
  };
3152
3471
 
3472
+ const getTopHeight = flags => {
3473
+ if (flags & ReplaceExpanded && flags & DetailsExpanded) {
3474
+ return 190;
3475
+ }
3476
+ if (flags & DetailsExpanded) {
3477
+ return 158;
3478
+ }
3479
+ if (flags & ReplaceExpanded) {
3480
+ return 93;
3481
+ }
3482
+ return 61;
3483
+ };
3484
+
3485
+ const getFilteredResults = (results, collapsedPaths) => {
3486
+ if (collapsedPaths.length === 0) {
3487
+ return results;
3488
+ }
3489
+ const filteredResults = [];
3490
+ let isExcluded = false;
3491
+ for (const result of results) {
3492
+ if (result.type === File$1) {
3493
+ if (collapsedPaths.includes(result.text)) {
3494
+ isExcluded = true;
3495
+ } else {
3496
+ isExcluded = false;
3497
+ }
3498
+ }
3499
+ if (!isExcluded) {
3500
+ filteredResults.push(result);
3501
+ }
3502
+ }
3503
+ return filteredResults;
3504
+ };
3505
+
3153
3506
  const selectIndexFile = (state, searchResult, index) => {
3154
3507
  const {
3155
- collapsedPaths
3508
+ collapsedPaths,
3509
+ items,
3510
+ maxLineY
3156
3511
  } = state;
3157
3512
  const path = getAbsolutePath(searchResult.text);
3158
3513
  string(path);
3514
+ const pathWithDot = `.${path}`;
3515
+ const newCollapsedPaths = [...collapsedPaths, path, pathWithDot];
3516
+ const filteredResults = getFilteredResults(items, collapsedPaths);
3517
+ const newMaxLineY = Math.min(maxLineY, filteredResults.length);
3159
3518
  return {
3160
3519
  ...state,
3161
- collapsedPaths: [...collapsedPaths, path],
3520
+ collapsedPaths: newCollapsedPaths,
3162
3521
  listFocusedIndex: index,
3163
- listFocused: true
3522
+ listFocused: true,
3523
+ listItems: filteredResults,
3524
+ maxLineY: newMaxLineY
3164
3525
  };
3165
3526
  };
3166
3527
 
@@ -3224,14 +3585,16 @@ const selectIndex = async (state, index) => {
3224
3585
  }
3225
3586
  };
3226
3587
 
3227
- const handleClickAt = async (state, eventX, eventY) => {
3588
+ const handleClickAt = (state, eventX, eventY) => {
3228
3589
  const {
3229
3590
  x,
3230
3591
  y,
3231
3592
  itemHeight,
3232
- deltaY
3593
+ deltaY,
3594
+ flags
3233
3595
  } = state;
3234
- const index = getListIndex(eventX, eventY, x, y, deltaY, itemHeight);
3596
+ const topHeight = getTopHeight(flags);
3597
+ const index = getListIndex(eventX, eventY, x, y, deltaY, itemHeight, topHeight);
3235
3598
  return selectIndex(state, index);
3236
3599
  };
3237
3600
 
@@ -3410,35 +3773,34 @@ const refresh = state => {
3410
3773
  return handleUpdate(state, {});
3411
3774
  };
3412
3775
 
3413
- // TODO just return name
3414
3776
  const getFocusSelector = focusKey => {
3415
3777
  switch (focusKey) {
3416
3778
  case FocusSearchInput:
3417
- return '[name="search-value"]';
3779
+ return SearchValue;
3418
3780
  case FocusSearchReplaceInput:
3419
- return '[name="search-replace-value"]';
3781
+ return ReplaceValue;
3420
3782
  case FocusToggleDetails:
3421
- return '[title="Toggle Search Details"]';
3783
+ return ToggleSearchDetails;
3422
3784
  case FocusSearchMatchCase:
3423
- return '[title="Match Case"]';
3785
+ return MatchCase;
3424
3786
  case FocusSearchPreserveCase:
3425
- return '[title="Preserve Case"]';
3787
+ return PreserveCase;
3426
3788
  case FocusSearchRegex:
3427
- return '[title="Use Regular Expression"]';
3789
+ return UseRegularExpression;
3428
3790
  case FocusSearchIncludeInput:
3429
- return '[name="files-to-include-value"]';
3791
+ return FilesToInclude;
3430
3792
  case FocusSearchExcludeInput:
3431
- return '[name="files-to-exclude-value"]';
3793
+ return FilesToExclude;
3432
3794
  case FocusSearchWholeWord:
3433
- return '[title="Match Whole Word"]';
3795
+ return MatchWholeWord;
3434
3796
  case FocusSearchReplaceAll:
3435
- return '[title="Replace All"]';
3797
+ return ReplaceAll;
3436
3798
  case FocusSearchOpenEditors:
3437
- return '[title="Search Only Open Editors"]';
3799
+ return SearchOnlyOpenEditors;
3438
3800
  case FocusIgnoreFiles:
3439
- return '[title="Use Exclude Settings"]';
3801
+ return UseExcludeSettings;
3440
3802
  case FocusToggleReplace:
3441
- return '[aria-label="Toggle Replace"]';
3803
+ return ToggleReplace;
3442
3804
  default:
3443
3805
  return '';
3444
3806
  }
@@ -3449,7 +3811,7 @@ const renderItems = {
3449
3811
  return oldState.items === newState.items && oldState.minLineY === newState.minLineY && oldState.maxLineY === newState.maxLineY && oldState.replacement === newState.replacement && oldState.flags === newState.flags && oldState.message === newState.message && oldState.loaded === newState.loaded && oldState.collapsedPaths === newState.collapsedPaths && oldState.listFocusedIndex === newState.listFocusedIndex && oldState.listFocused === newState.listFocused && oldState.icons === newState.icons;
3450
3812
  },
3451
3813
  apply(oldState, newState) {
3452
- const displayResults = getDisplayResults(newState.items, newState.itemHeight, newState.fileCount, newState.value, newState.minLineY, newState.maxLineY, newState.replacement, newState.collapsedPaths, newState.icons, newState.focusedIndex);
3814
+ const displayResults = getDisplayResults(newState.listItems, newState.itemHeight, newState.fileCount, newState.value, newState.minLineY, newState.maxLineY, newState.replacement, newState.icons, newState.listFocusedIndex);
3453
3815
  const focusOutline = newState.listFocused && newState.listFocusedIndex === -1;
3454
3816
  const dom = getSearchVirtualDom(displayResults, newState.flags, newState.message, focusOutline);
3455
3817
  return ['Viewlet.setDom2', newState.uid, dom];
@@ -3460,8 +3822,8 @@ const renderFocus = {
3460
3822
  return oldState.focus === newState.focus || newState.focusSource === User;
3461
3823
  },
3462
3824
  apply(oldState, newState) {
3463
- const selector = getFocusSelector(newState.focus);
3464
- return ['Viewlet.send', newState.uid, 'setFocus', selector, newState.focusSource];
3825
+ const name = newState.focusSource === User ? '' : getFocusSelector(newState.focus);
3826
+ return ['Viewlet.focusElementByName', name];
3465
3827
  }
3466
3828
  };
3467
3829
  const renderValue = {
@@ -3634,29 +3996,29 @@ const setFocus = async focusKey => {
3634
3996
 
3635
3997
  const getSearchFocusKey = key => {
3636
3998
  switch (key) {
3637
- case 'search-value':
3999
+ case SearchValue:
3638
4000
  return FocusSearchInput;
3639
- case 'search-replace-value':
4001
+ case ReplaceValue:
3640
4002
  return FocusSearchReplaceInput;
3641
- case 'Match Case':
4003
+ case MatchCase:
3642
4004
  return FocusSearchMatchCase;
3643
- case 'Match Whole Word':
4005
+ case MatchWholeWord:
3644
4006
  return FocusSearchWholeWord;
3645
- case 'Use Regular Expression':
4007
+ case UseRegularExpression:
3646
4008
  return FocusSearchRegex;
3647
- case 'Replace All':
4009
+ case ReplaceAll:
3648
4010
  return FocusSearchReplaceAll;
3649
- case 'Preserve Case':
4011
+ case PreserveCase:
3650
4012
  return FocusSearchPreserveCase;
3651
- case 'Toggle Search Details':
4013
+ case ToggleSearchDetails:
3652
4014
  return FocusToggleDetails;
3653
- case 'files-to-include-value':
4015
+ case FilesToInclude:
3654
4016
  return FocusSearchIncludeInput;
3655
- case 'files-to-exclude-value':
4017
+ case FilesToExclude:
3656
4018
  return FocusSearchExcludeInput;
3657
- case 'Search Only Open Editors':
4019
+ case SearchOnlyOpenEditors:
3658
4020
  return FocusSearchOpenEditors;
3659
- case 'Use Exclude Settings':
4021
+ case UseExcludeSettings:
3660
4022
  return FocusIgnoreFiles;
3661
4023
  default:
3662
4024
  return Empty$1;
@@ -3753,11 +4115,11 @@ const toggleDetailsExpanded = state => {
3753
4115
  };
3754
4116
 
3755
4117
  const toggleMatchCase = state => {
3756
- return toggleSearchFlag(state, MatchCase);
4118
+ return toggleSearchFlag(state, MatchCase$1);
3757
4119
  };
3758
4120
 
3759
4121
  const toggleMatchWholeWord = state => {
3760
- return toggleSearchFlag(state, MatchWholeWord);
4122
+ return toggleSearchFlag(state, MatchWholeWord$1);
3761
4123
  };
3762
4124
 
3763
4125
  const toggleOpenEditors = state => {
@@ -3765,7 +4127,7 @@ const toggleOpenEditors = state => {
3765
4127
  };
3766
4128
 
3767
4129
  const togglePreserveCase = state => {
3768
- return toggleSearchFlag(state, PreserveCase);
4130
+ return toggleSearchFlag(state, PreserveCase$1);
3769
4131
  };
3770
4132
 
3771
4133
  const toggleReplace = state => {
@@ -3777,7 +4139,7 @@ const toggleUseIgnoreFiles = state => {
3777
4139
  };
3778
4140
 
3779
4141
  const toggleUseRegularExpression = state => {
3780
- return toggleSearchFlag(state, UseRegularExpression);
4142
+ return toggleSearchFlag(state, UseRegularExpression$1);
3781
4143
  };
3782
4144
 
3783
4145
  const Keyboard = -1;
@@ -3862,12 +4224,14 @@ const commandMap = {
3862
4224
  'TextSearch.handleIconThemeChange': wrapCommand(handleIconThemeChange),
3863
4225
  'TextSearch.handleIncludeInput': wrapCommand(handleIncludeInput),
3864
4226
  'TextSearch.handleInput': wrapCommand(handleInput),
4227
+ 'TextSearch.handleListBlur': wrapCommand(handleListBlur),
3865
4228
  'TextSearch.handleReplaceInput': wrapCommand(handleReplaceInput),
3866
4229
  'TextSearch.handleScrollBarCaptureLost': wrapCommand(handleScrollBarCaptureLost),
3867
4230
  'TextSearch.handleScrollBarClick': wrapCommand(handleScrollBarClick),
3868
4231
  'TextSearch.handleScrollBarMove': wrapCommand(handleScrollBarMove),
3869
4232
  'TextSearch.handleSharedInput': wrapCommand(handleSharedInput),
3870
4233
  'TextSearch.handleWheel': wrapCommand(handleWheel),
4234
+ 'TextSearch.launchSearchProcess': wrapCommand(launchSearchProcess),
3871
4235
  'TextSearch.loadContent': wrapCommand(loadContent),
3872
4236
  'TextSearch.refresh': wrapCommand(refresh),
3873
4237
  'TextSearch.replaceAll': wrapCommand(replaceAll),
@@ -3882,10 +4246,12 @@ const commandMap = {
3882
4246
  'TextSearch.toggleUseIgnoreFiles': wrapCommand(toggleUseIgnoreFiles),
3883
4247
  'TextSearch.toggleUseRegularExpression': wrapCommand(toggleUseRegularExpression),
3884
4248
  // not wrapped
3885
- 'TextSearch.create': create,
4249
+ 'TextSearch.create': create$4,
4250
+ 'TextSearch.getFlags': getFlags,
4251
+ 'TextSearch.getFocus': getFocus,
4252
+ 'TextSearch.getKeyBindings': getKeyBindings,
3886
4253
  'TextSearch.render': doRender,
3887
4254
  'TextSearch.saveState': saveState,
3888
- 'TextSearch.getKeyBindings': getKeyBindings,
3889
4255
  // TODO needed?
3890
4256
  'TextSearch.textSearch': textSearch
3891
4257
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/text-search-worker",
3
- "version": "3.12.0",
3
+ "version": "3.14.0",
4
4
  "description": "Text Search Worker",
5
5
  "main": "dist/textSearchWorkerMain.js",
6
6
  "type": "module",