@lvce-editor/text-search-worker 5.2.0 → 5.3.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.
@@ -829,7 +829,7 @@ const getErrorProperty = (error, prettyError) => {
829
829
  }
830
830
  };
831
831
  };
832
- const create$1$1 = (id, error) => {
832
+ const create$1$2 = (id, error) => {
833
833
  return {
834
834
  jsonrpc: Two,
835
835
  id,
@@ -840,7 +840,7 @@ const getErrorResponse = (id, error, preparePrettyError, logError) => {
840
840
  const prettyError = preparePrettyError(error);
841
841
  logError(error, prettyError);
842
842
  const errorProperty = getErrorProperty(error, prettyError);
843
- return create$1$1(id, errorProperty);
843
+ return create$1$2(id, errorProperty);
844
844
  };
845
845
  const create$6 = (message, result) => {
846
846
  return {
@@ -1081,9 +1081,38 @@ const create$2$1 = async ({
1081
1081
  const rpc = createRpc(ipc);
1082
1082
  return rpc;
1083
1083
  };
1084
- const WebSocketRpcParent = {
1084
+ const Https = 'https:';
1085
+ const Ws = 'ws:';
1086
+ const Wss = 'wss:';
1087
+ const getWebSocketProtocol = locationProtocol => {
1088
+ return locationProtocol === Https ? Wss : Ws;
1089
+ };
1090
+ const getWebSocketUrl = (type, host, locationProtocol) => {
1091
+ const wsProtocol = getWebSocketProtocol(locationProtocol);
1092
+ return `${wsProtocol}//${host}/websocket/${type}`;
1093
+ };
1094
+ const getHost = () => {
1095
+ return location.host;
1096
+ };
1097
+ const getProtocol$1 = () => {
1098
+ return location.protocol;
1099
+ };
1100
+ const create$1$1 = async ({
1101
+ commandMap
1102
+ }) => {
1103
+ const host = getHost();
1104
+ const protocol = getProtocol$1();
1105
+ const wsUrl = getWebSocketUrl('search-process', host, protocol);
1106
+ const webSocket = new WebSocket(wsUrl);
1107
+ const rpc = await create$2$1({
1108
+ webSocket,
1109
+ commandMap
1110
+ });
1111
+ return rpc;
1112
+ };
1113
+ const WebSocketRpcParent2 = {
1085
1114
  __proto__: null,
1086
- create: create$2$1
1115
+ create: create$1$1
1087
1116
  };
1088
1117
  const create$4 = async ({
1089
1118
  commandMap
@@ -1418,7 +1447,9 @@ const create = (uid, x, y, width, height, workspacePath, assetDir, itemHeight, v
1418
1447
  historyIndex: -1,
1419
1448
  viewMode: List$1,
1420
1449
  incrementalSearch: false,
1421
- searchId: ''
1450
+ searchId: '',
1451
+ useChevrons: true,
1452
+ useFileIcons: true
1422
1453
  };
1423
1454
  set(uid, state, state);
1424
1455
  return state;
@@ -2098,7 +2129,7 @@ const getNumberOfVisibleItems$1 = (listHeight, itemHeight) => {
2098
2129
  };
2099
2130
 
2100
2131
  const RE_PROTOCOL = /^([a-z-\d]+):\/\//;
2101
- const getProtocol$1 = uri => {
2132
+ const getProtocol = uri => {
2102
2133
  const protocolMatch = uri.match(RE_PROTOCOL);
2103
2134
  if (protocolMatch) {
2104
2135
  return protocolMatch[1];
@@ -2152,7 +2183,7 @@ const getTextSearchProvider = scheme => {
2152
2183
  const textSearch$6 = async (root, query, options, assetDir, platform) => {
2153
2184
  string(root);
2154
2185
  string(query);
2155
- const scheme = getProtocol$1(root);
2186
+ const scheme = getProtocol(root);
2156
2187
  const provider = getTextSearchProvider(scheme);
2157
2188
  const results = await provider(scheme, root, query, options, assetDir, platform);
2158
2189
  return results;
@@ -2177,7 +2208,7 @@ const handleUpdateFull = async (state, update) => {
2177
2208
  platform
2178
2209
  } = partialNewState;
2179
2210
  const root = state.workspacePath;
2180
- const scheme = getProtocol$1(root);
2211
+ const scheme = getProtocol(root);
2181
2212
  const results = await textSearch$6(root, value, {
2182
2213
  threads,
2183
2214
  isCaseSensitive: Boolean(flags & MatchCase$2),
@@ -2258,10 +2289,14 @@ const {
2258
2289
  } = createLazyRpc(RpcId.SearchProcess);
2259
2290
 
2260
2291
  const waitForNextFrame = async () => {
2261
- await new Promise(r => {
2262
- requestAnimationFrame(r);
2263
- });
2292
+ const {
2293
+ resolve,
2294
+ promise
2295
+ } = Promise.withResolvers();
2296
+ requestAnimationFrame(resolve);
2297
+ await promise;
2264
2298
  };
2299
+
2265
2300
  const textSearchIncremental = async (root, query, options, assetDir, platform, searchId, uid) => {
2266
2301
  string(root);
2267
2302
  string(query);
@@ -2324,7 +2359,7 @@ const handleUpdateIncremental = async (state, update) => {
2324
2359
  platform
2325
2360
  } = partialNewState;
2326
2361
  const root = state.workspacePath;
2327
- const scheme = getProtocol$1(root);
2362
+ const scheme = getProtocol(root);
2328
2363
  const searchId = crypto.randomUUID(); // TODO try to avoid side effect
2329
2364
  const latest1 = get$1(uid);
2330
2365
  const updatedState1 = {
@@ -2690,34 +2725,11 @@ const launchSearchProcessElectron = async () => {
2690
2725
  return rpc;
2691
2726
  };
2692
2727
 
2693
- const Https = 'https:';
2694
- const Ws = 'ws:';
2695
- const Wss = 'wss:';
2696
-
2697
- const getWebSocketProtocol = locationProtocol => {
2698
- return locationProtocol === Https ? Wss : Ws;
2699
- };
2700
-
2701
- const getWebSocketUrl = (type, host, locationProtocol) => {
2702
- const wsProtocol = getWebSocketProtocol(locationProtocol);
2703
- return `${wsProtocol}//${host}/websocket/${type}`;
2704
- };
2705
-
2706
- const getHost = () => {
2707
- return location.host;
2708
- };
2709
- const getProtocol = () => {
2710
- return location.protocol;
2711
- };
2712
-
2713
2728
  const launchSearchProcessNode = async () => {
2714
- const host = getHost();
2715
- const protocol = getProtocol();
2716
- const wsUrl = getWebSocketUrl('search-process', host, protocol);
2717
- const webSocket = new WebSocket(wsUrl);
2718
- const rpc = await WebSocketRpcParent.create({
2719
- webSocket,
2720
- commandMap: {}
2729
+ const rpc = await WebSocketRpcParent2.create({
2730
+ commandMap: {},
2731
+ // @ts-ignore
2732
+ type: 'search-process'
2721
2733
  });
2722
2734
  return rpc;
2723
2735
  };
@@ -3356,18 +3368,6 @@ const getMatchCount = (results, startIndex) => {
3356
3368
  return results.length - startIndex - 1;
3357
3369
  };
3358
3370
 
3359
- const getChildCount = (expanded, matchCount) => {
3360
- let childCount = 1;
3361
- if (expanded === Expanded || expanded === Collapsed) {
3362
- childCount += 2;
3363
- }
3364
- if (matchCount) {
3365
- childCount++;
3366
- }
3367
- childCount++;
3368
- return childCount;
3369
- };
3370
-
3371
3371
  const getSearchDisplayResultFile = (results, fileIcons, i, setSize, collapsedPaths, text, posInSet, relativeIndex, focused, originalResults) => {
3372
3372
  const path = text;
3373
3373
  const absolutePath = getRelativePath(path);
@@ -3375,11 +3375,9 @@ const getSearchDisplayResultFile = (results, fileIcons, i, setSize, collapsedPat
3375
3375
  const index = originalResults.indexOf(results[i]);
3376
3376
  const matchCount = getMatchCount(results, index);
3377
3377
  const expanded = collapsedPaths.includes(path) ? Collapsed : Expanded;
3378
- const childCount = getChildCount(expanded, matchCount);
3379
3378
  const badgeText = `${matchCount}`;
3380
3379
  return {
3381
3380
  badgeText,
3382
- childCount,
3383
3381
  depth: 0,
3384
3382
  expanded,
3385
3383
  focused,
@@ -3397,7 +3395,6 @@ const getSearchDisplayResultFile = (results, fileIcons, i, setSize, collapsedPat
3397
3395
  const getDisplayResultMatch = (setSize, searchTermLength, replacement, text, posInSet, start, focused) => {
3398
3396
  return {
3399
3397
  badgeText: '',
3400
- childCount: getChildCount(None$1, 0),
3401
3398
  depth: 1,
3402
3399
  expanded: None$1,
3403
3400
  focused,
@@ -3408,7 +3405,7 @@ const getDisplayResultMatch = (setSize, searchTermLength, replacement, text, pos
3408
3405
  replacement,
3409
3406
  setSize,
3410
3407
  text: text,
3411
- title: text
3408
+ title: text.trim()
3412
3409
  };
3413
3410
  };
3414
3411
 
@@ -3626,8 +3623,14 @@ const VirtualDomElements = {
3626
3623
  Img,
3627
3624
  Ins,
3628
3625
  Span,
3629
- Text,
3630
3626
  TextArea};
3627
+ const text = data => {
3628
+ return {
3629
+ type: Text,
3630
+ text: data,
3631
+ childCount: 0
3632
+ };
3633
+ };
3631
3634
  const SetText = 1;
3632
3635
  const SetAttribute = 3;
3633
3636
  const RemoveAttribute = 4;
@@ -3883,14 +3886,6 @@ const getSearchDetailsToggleVirtualDom = () => {
3883
3886
  }];
3884
3887
  };
3885
3888
 
3886
- const text = data => {
3887
- return {
3888
- type: VirtualDomElements.Text,
3889
- text: data,
3890
- childCount: 0
3891
- };
3892
- };
3893
-
3894
3889
  const getClassName = indented => {
3895
3890
  if (indented) {
3896
3891
  return mergeClassNames(ClassNames.ViewletSearchMessage, ClassNames.ViewletSearchMessageIndented);
@@ -4250,15 +4245,16 @@ const getAriaExpanded = expanded => {
4250
4245
  }
4251
4246
  };
4252
4247
 
4253
- const getBadgeVirtualDom = (className, badgeText) => {
4248
+ const badge = {
4249
+ type: VirtualDomElements.Div,
4250
+ className: mergeClassNames(ClassNames.Badge, ClassNames.SourceControlBadge),
4251
+ childCount: 1
4252
+ };
4253
+ const getBadgeVirtualDom = badgeText => {
4254
4254
  if (!badgeText) {
4255
4255
  return [];
4256
4256
  }
4257
- return [{
4258
- type: VirtualDomElements.Div,
4259
- className: mergeClassNames(ClassNames.Badge, className),
4260
- childCount: 1
4261
- }, text(badgeText)];
4257
+ return [badge, text(badgeText)];
4262
4258
  };
4263
4259
 
4264
4260
  const chevronDownVirtualDom = {
@@ -4272,6 +4268,17 @@ const chevronRightVirtualDom = {
4272
4268
  childCount: 0
4273
4269
  };
4274
4270
 
4271
+ const getChevronVirtualDom = expanded => {
4272
+ switch (expanded) {
4273
+ case Expanded:
4274
+ return [chevronDownVirtualDom];
4275
+ case Collapsed:
4276
+ return [chevronRightVirtualDom];
4277
+ default:
4278
+ return [];
4279
+ }
4280
+ };
4281
+
4275
4282
  const getFileIconVirtualDom = icon => {
4276
4283
  return {
4277
4284
  type: VirtualDomElements.Img,
@@ -4282,15 +4289,11 @@ const getFileIconVirtualDom = icon => {
4282
4289
  };
4283
4290
  };
4284
4291
 
4285
- const getIconsVirtualDom = (expanded, icon) => {
4286
- switch (expanded) {
4287
- case Expanded:
4288
- return [chevronDownVirtualDom, getFileIconVirtualDom(icon)];
4289
- case Collapsed:
4290
- return [chevronRightVirtualDom, getFileIconVirtualDom(icon)];
4291
- default:
4292
- return [];
4292
+ const getIconsVirtualDom = icon => {
4293
+ if (icon) {
4294
+ return [getFileIconVirtualDom(icon)];
4293
4295
  }
4296
+ return [];
4294
4297
  };
4295
4298
 
4296
4299
  const deleted = {
@@ -4338,6 +4341,36 @@ const getPaddingLeft = depth => {
4338
4341
  return `${Number(depth) + 1}rem`; // TODO use classname and dynamic css
4339
4342
  };
4340
4343
 
4344
+ const getChildCount = (icon, expanded, badgeText) => {
4345
+ let childCount = 0;
4346
+ if (expanded) {
4347
+ childCount++; // chevron
4348
+ }
4349
+ if (icon) {
4350
+ childCount++; // file icon
4351
+ }
4352
+ childCount++; // label
4353
+ if (badgeText) {
4354
+ childCount++; // badge
4355
+ }
4356
+ childCount++; // remove button
4357
+ return childCount;
4358
+ };
4359
+
4360
+ const getSearchRemoveVirtualDom = () => {
4361
+ // TODO add title/aria label
4362
+ const dom = [{
4363
+ type: VirtualDomElements.Div,
4364
+ className: ClassNames.SearchRemove,
4365
+ childCount: 1
4366
+ }, {
4367
+ type: VirtualDomElements.Div,
4368
+ className: ClassNames.CloseMaskIcon,
4369
+ childCount: 0
4370
+ }];
4371
+ return dom;
4372
+ };
4373
+
4341
4374
  const getSearchResultClassName = focused => {
4342
4375
  if (focused) {
4343
4376
  return ClassNames.TreeItem + ' ' + ClassNames.TreeItemActive;
@@ -4360,9 +4393,9 @@ const getSearchResultVirtualDom = rowInfo => {
4360
4393
  replacement,
4361
4394
  focused,
4362
4395
  expanded,
4363
- childCount,
4364
4396
  badgeText
4365
4397
  } = rowInfo;
4398
+ const childCount = getChildCount(icon, expanded, badgeText);
4366
4399
  const dom = [{
4367
4400
  type: VirtualDomElements.Div,
4368
4401
  role: TreeItem,
@@ -4377,15 +4410,7 @@ const getSearchResultVirtualDom = rowInfo => {
4377
4410
  paddingLeft: getPaddingLeft(depth),
4378
4411
  paddingRight: PaddingRight,
4379
4412
  ariaExpanded: getAriaExpanded(expanded)
4380
- }, ...getIconsVirtualDom(expanded, icon), ...getLabelVirtualDom(displayText, matchLength, matchStart, replacement), ...getBadgeVirtualDom(ClassNames.SourceControlBadge, badgeText), {
4381
- type: VirtualDomElements.Div,
4382
- className: ClassNames.SearchRemove,
4383
- childCount: 1
4384
- }, {
4385
- type: VirtualDomElements.Div,
4386
- className: ClassNames.CloseMaskIcon,
4387
- childCount: 0
4388
- }];
4413
+ }, ...getChevronVirtualDom(expanded), ...getIconsVirtualDom(icon), ...getLabelVirtualDom(displayText, matchLength, matchStart, replacement), ...getBadgeVirtualDom(badgeText), ...getSearchRemoveVirtualDom()];
4389
4414
  return dom;
4390
4415
  };
4391
4416
 
@@ -4405,13 +4430,13 @@ const getTreeItemsVirtualDom = (visibleItems, deltaY, itemHeight) => {
4405
4430
  };
4406
4431
 
4407
4432
  const getSearchResultsVirtualDom = (visibleItems, focusOutline, scrollbarHeight, scrollBarY, scrollBarValue, deltaY, itemHeight) => {
4408
- const scrollBarDomNodes = scrollbarHeight === 0 ? 0 : 1;
4433
+ const childCount = scrollbarHeight === 0 ? 1 : 2;
4409
4434
  return [{
4410
4435
  type: VirtualDomElements.Div,
4411
4436
  className: mergeClassNames(ClassNames.Viewlet, ClassNames.List, ClassNames.Tree, focusOutline ? ClassNames.FocusOutline : ClassNames.Empty),
4412
4437
  role: Tree,
4413
4438
  tabIndex: 0,
4414
- childCount: 1 + scrollBarDomNodes
4439
+ childCount
4415
4440
  }, ...getTreeItemsVirtualDom(visibleItems, deltaY, itemHeight), ...getScrollBarVirtualDom(scrollbarHeight, scrollBarY, scrollBarValue)];
4416
4441
  };
4417
4442
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/text-search-worker",
3
- "version": "5.2.0",
3
+ "version": "5.3.0",
4
4
  "description": "Text Search Worker",
5
5
  "keywords": [
6
6
  "text-search"