@lvce-editor/text-search-worker 5.34.0 → 6.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.
@@ -592,7 +592,7 @@ const callbacks = Object.create(null);
592
592
  const get$3 = id => {
593
593
  return callbacks[id];
594
594
  };
595
- const remove$2 = id => {
595
+ const remove$3 = id => {
596
596
  delete callbacks[id];
597
597
  };
598
598
  class JsonRpcError extends Error {
@@ -745,7 +745,7 @@ const resolve = (id, response) => {
745
745
  return;
746
746
  }
747
747
  fn(response);
748
- remove$2(id);
748
+ remove$3(id);
749
749
  };
750
750
  const E_COMMAND_NOT_FOUND = 'E_COMMAND_NOT_FOUND';
751
751
  const getErrorType = prettyError => {
@@ -1195,6 +1195,25 @@ const WebWorkerRpcClient = {
1195
1195
  __proto__: null,
1196
1196
  create: create$1$1
1197
1197
  };
1198
+ const createMockRpc = ({
1199
+ commandMap
1200
+ }) => {
1201
+ const invocations = [];
1202
+ const invoke = (method, ...params) => {
1203
+ invocations.push([method, ...params]);
1204
+ const command = commandMap[method];
1205
+ if (!command) {
1206
+ throw new Error(`command ${method} not found`);
1207
+ }
1208
+ return command(...params);
1209
+ };
1210
+ const mockRpc = {
1211
+ invocations,
1212
+ invoke,
1213
+ invokeAndTransfer: invoke
1214
+ };
1215
+ return mockRpc;
1216
+ };
1198
1217
 
1199
1218
  const Alert = 'alert';
1200
1219
  const Button$3 = 'button';
@@ -1206,9 +1225,78 @@ const ToolBar = 'toolbar';
1206
1225
  const Tree$1 = 'tree';
1207
1226
  const TreeItem$1 = 'treeitem';
1208
1227
 
1228
+ const Actions = 'Actions';
1229
+ const Badge = 'Badge';
1230
+ const Chevron = 'Chevron';
1231
+ const CloseMaskIcon = 'MaskIcon MaskIconClose';
1232
+ const Empty$1 = '';
1233
+ const FileIcon = 'FileIcon';
1234
+ const FocusOutline = 'FocusOutline';
1235
+ const Grow = 'Grow';
1236
+ const Highlight = 'Highlight';
1237
+ const HighlightDeleted = 'HighlightDeleted';
1238
+ const HighlightInserted = 'HighlightInserted';
1239
+ const IconButton = 'IconButton';
1240
+ const IconButtonDisabled = 'IconButtonDisabled';
1241
+ const Label = 'Label';
1242
+ const List$1 = 'List';
1243
+ const MaskIcon = 'MaskIcon';
1244
+ const MaskIconBook = 'MaskIconBook';
1245
+ const MaskIconCaseSensitive = 'MaskIconCaseSensitive';
1246
+ const MaskIconChevronDown = 'MaskIconChevronDown';
1247
+ const MaskIconChevronRight = 'MaskIconChevronRight';
1248
+ const MaskIconEllipsis = 'MaskIconEllipsis';
1249
+ const MaskIconExclude = 'MaskIconExclude';
1250
+ const MaskIconPreserveCase = 'MaskIconPreserveCase';
1251
+ const MaskIconRegex = 'MaskIconRegex';
1252
+ const MaskIconReplaceAll = 'MaskIconReplaceAll';
1253
+ const MaskIconWholeWord = 'MaskIconWholeWord';
1254
+ const MultilineInputBox = 'MultilineInputBox';
1255
+ const ScrollBar = 'ScrollBar';
1256
+ const ScrollBarThumb = 'ScrollBarThumb';
1257
+ const ScrollBarVertical = 'ScrollBarVertical';
1258
+ const Search$2 = 'Search';
1259
+ const SearchField = 'SearchField';
1260
+ const SearchFieldButton = 'SearchFieldButton';
1261
+ const SearchFieldButtonChecked = 'SearchFieldButtonChecked';
1262
+ const SearchFieldButtonDisabled = 'SearchFieldButtonDisabled';
1263
+ const SearchFieldButtons = 'SearchFieldButtons';
1264
+ const SearchFieldContainer = 'SearchFieldContainer';
1265
+ const SearchFieldError = 'SearchFieldError';
1266
+ const SearchHeader = 'SearchHeader';
1267
+ const SearchHeaderDetails = 'SearchHeaderDetails';
1268
+ const SearchHeaderDetailsExpanded = 'SearchHeaderDetailsExpanded';
1269
+ const SearchHeaderDetailsExpandedTop = 'SearchHeaderDetailsExpandedTop';
1270
+ const SearchHeaderDetailsHeading = 'SearchHeaderDetailsHeading';
1271
+ const SearchHeaderTop = 'SearchHeaderTop';
1272
+ const SearchHeaderTopRight = 'SearchHeaderTopRight';
1273
+ const SearchInputError = 'SearchInputError';
1274
+ const SearchRemove = 'SearchRemove';
1275
+ const SearchToggleButton = 'SearchToggleButton';
1276
+ const SearchToggleButtonExpanded = 'SearchToggleButtonExpanded';
1277
+ const SourceControlBadge = 'SourceControlBadge';
1278
+ const ToggleDetails = 'ToggleDetails';
1279
+ const Tree = 'Tree';
1280
+ const TreeItem = 'TreeItem';
1281
+ const TreeItemActive = 'TreeItemActive';
1282
+ const TreeItems$1 = 'TreeItems';
1283
+ const Viewlet = 'Viewlet';
1284
+ const ViewletSearchMessage = 'ViewletSearchMessage';
1285
+ const ViewletSearchMessageIndented = 'ViewletSearchMessageIndented';
1286
+
1209
1287
  const File$2 = 7;
1210
1288
 
1211
- const Button$2 = 'event.button';
1289
+ const Button$2 = 1;
1290
+ const Div = 4;
1291
+ const Span = 8;
1292
+ const Text = 12;
1293
+ const Img = 17;
1294
+ const Ins = 20;
1295
+ const Del = 21;
1296
+ const H4 = 24;
1297
+ const TextArea = 62;
1298
+
1299
+ const Button$1 = 'event.button';
1212
1300
  const ClientX = 'event.clientX';
1213
1301
  const ClientY = 'event.clientY';
1214
1302
  const DeltaMode = 'event.deltaMode';
@@ -1220,7 +1308,7 @@ const TargetValue = 'event.target.value';
1220
1308
 
1221
1309
  const Script$1 = 2;
1222
1310
 
1223
- const Search$2 = 18;
1311
+ const Search$1 = 18;
1224
1312
  const InputContextMenu = 91;
1225
1313
 
1226
1314
  const Separator = 1;
@@ -1243,7 +1331,22 @@ const SetDom2 = 'Viewlet.setDom2';
1243
1331
  const SetFocusContext = 'Viewlet.setFocusContext';
1244
1332
  const SetValueByName = 'Viewlet.setValueByName';
1245
1333
 
1246
- const FocusSearch$1 = 1013;
1334
+ const Empty = 0;
1335
+ const FocusIgnoreFiles = 1012;
1336
+ const FocusSearch = 1013;
1337
+ const FocusSearchExcludeInput = 1008;
1338
+ const FocusSearchIncludeInput = 1007;
1339
+ const FocusSearchInput = 21;
1340
+ const FocusSearchMatchCase = 32;
1341
+ const FocusSearchOpenEditors = 1011;
1342
+ const FocusSearchPreserveCase = 36;
1343
+ const FocusSearchRegex = 33;
1344
+ const FocusSearchReplaceAll = 35;
1345
+ const FocusSearchReplaceInput = 31;
1346
+ const FocusSearchResults = 22;
1347
+ const FocusSearchWholeWord = 34;
1348
+ const FocusToggleDetails = 1010;
1349
+ const FocusToggleReplace = 1020;
1247
1350
 
1248
1351
  const rpcs = Object.create(null);
1249
1352
  const set$4 = (id, rpc) => {
@@ -1252,7 +1355,11 @@ const set$4 = (id, rpc) => {
1252
1355
  const get$2 = id => {
1253
1356
  return rpcs[id];
1254
1357
  };
1358
+ const remove$2 = id => {
1359
+ delete rpcs[id];
1360
+ };
1255
1361
 
1362
+ /* eslint-disable @typescript-eslint/explicit-function-return-type */
1256
1363
  const create$3 = rpcId => {
1257
1364
  return {
1258
1365
  async dispose() {
@@ -1271,6 +1378,18 @@ const create$3 = rpcId => {
1271
1378
  // @ts-ignore
1272
1379
  return rpc.invokeAndTransfer(method, ...params);
1273
1380
  },
1381
+ registerMockRpc(commandMap) {
1382
+ const mockRpc = createMockRpc({
1383
+ commandMap
1384
+ });
1385
+ set$4(rpcId, mockRpc);
1386
+ // @ts-ignore
1387
+ mockRpc[Symbol.dispose] = () => {
1388
+ remove$2(rpcId);
1389
+ };
1390
+ // @ts-ignore
1391
+ return mockRpc;
1392
+ },
1274
1393
  set(rpc) {
1275
1394
  set$4(rpcId, rpc);
1276
1395
  }
@@ -1407,105 +1526,20 @@ const terminate = () => {
1407
1526
  globalThis.close();
1408
1527
  };
1409
1528
 
1410
- const Actions = 'Actions';
1411
- const Badge = 'Badge';
1412
- const Chevron = 'Chevron';
1413
- const CloseMaskIcon = 'MaskIcon MaskIconClose';
1414
- const Empty$1 = '';
1415
- const FileIcon = 'FileIcon';
1416
- const FocusOutline = 'FocusOutline';
1417
- const Grow = 'Grow';
1418
- const Highlight = 'Highlight';
1419
- const HighlightDeleted = 'HighlightDeleted';
1420
- const HighlightInserted = 'HighlightInserted';
1421
- const IconButton = 'IconButton';
1422
- const IconButtonDisabled = 'IconButtonDisabled';
1423
- const Label = 'Label';
1424
- const List$1 = 'List';
1425
- const MaskIcon = 'MaskIcon';
1426
- const MaskIconBook = 'MaskIconBook';
1427
- const MaskIconCaseSensitive = 'MaskIconCaseSensitive';
1428
- const MaskIconChevronDown = 'MaskIconChevronDown';
1429
- const MaskIconChevronRight = 'MaskIconChevronRight';
1430
- const MaskIconEllipsis = 'MaskIconEllipsis';
1431
- const MaskIconExclude = 'MaskIconExclude';
1432
- const MaskIconPreserveCase = 'MaskIconPreserveCase';
1433
- const MaskIconRegex = 'MaskIconRegex';
1434
- const MaskIconReplaceAll = 'MaskIconReplaceAll';
1435
- const MaskIconWholeWord = 'MaskIconWholeWord';
1436
- const MultilineInputBox = 'MultilineInputBox';
1437
- const ScrollBar = 'ScrollBar';
1438
- const ScrollBarThumb = 'ScrollBarThumb';
1439
- const ScrollBarVertical = 'ScrollBarVertical';
1440
- const Search$1 = 'Search';
1441
- const SearchField = 'SearchField';
1442
- const SearchFieldButton = 'SearchFieldButton';
1443
- const SearchFieldButtonChecked = 'SearchFieldButtonChecked';
1444
- const SearchFieldButtonDisabled = 'SearchFieldButtonDisabled';
1445
- const SearchFieldButtons = 'SearchFieldButtons';
1446
- const SearchFieldContainer = 'SearchFieldContainer';
1447
- const SearchFieldError = 'SearchFieldError';
1448
- const SearchHeader = 'SearchHeader';
1449
- const SearchHeaderDetails = 'SearchHeaderDetails';
1450
- const SearchHeaderDetailsExpanded = 'SearchHeaderDetailsExpanded';
1451
- const SearchHeaderDetailsExpandedTop = 'SearchHeaderDetailsExpandedTop';
1452
- const SearchHeaderDetailsHeading = 'SearchHeaderDetailsHeading';
1453
- const SearchHeaderTop = 'SearchHeaderTop';
1454
- const SearchHeaderTopRight = 'SearchHeaderTopRight';
1455
- const SearchInputError = 'SearchInputError';
1456
- const SearchRemove = 'SearchRemove';
1457
- const SearchToggleButton = 'SearchToggleButton';
1458
- const SearchToggleButtonExpanded = 'SearchToggleButtonExpanded';
1459
- const SourceControlBadge = 'SourceControlBadge';
1460
- const ToggleDetails = 'ToggleDetails';
1461
- const Tree = 'Tree';
1462
- const TreeItem = 'TreeItem';
1463
- const TreeItemActive = 'TreeItemActive';
1464
- const TreeItems$1 = 'TreeItems';
1465
- const Viewlet = 'Viewlet';
1466
- const ViewletSearchMessage = 'ViewletSearchMessage';
1467
- const ViewletSearchMessageIndented = 'ViewletSearchMessageIndented';
1468
-
1469
- const Button$1 = 1;
1470
- const Div = 4;
1471
- const Span = 8;
1472
- const Text = 12;
1473
- const Img = 17;
1474
- const Ins = 20;
1475
- const Del = 21;
1476
- const H4 = 24;
1477
- const TextArea = 62;
1478
-
1479
- const Empty = 0;
1480
- const FocusIgnoreFiles = 1012;
1481
- const FocusSearch = 1013;
1482
- const FocusSearchExcludeInput = 1008;
1483
- const FocusSearchIncludeInput = 1007;
1484
- const FocusSearchInput = 21;
1485
- const FocusSearchMatchCase = 32;
1486
- const FocusSearchOpenEditors = 1011;
1487
- const FocusSearchPreserveCase = 36;
1488
- const FocusSearchRegex = 33;
1489
- const FocusSearchReplaceAll = 35;
1490
- const FocusSearchReplaceInput = 31;
1491
- const FocusSearchResults = 22;
1492
- const FocusSearchWholeWord = 34;
1493
- const FocusToggleDetails = 1010;
1494
- const FocusToggleReplace = 1020;
1495
-
1496
1529
  const mergeClassNames = (...classNames) => {
1497
1530
  return classNames.filter(Boolean).join(' ');
1498
1531
  };
1499
1532
 
1500
1533
  const text = data => {
1501
1534
  return {
1502
- type: Text,
1535
+ childCount: 0,
1503
1536
  text: data,
1504
- childCount: 0
1537
+ type: Text
1505
1538
  };
1506
1539
  };
1507
1540
 
1508
1541
  const SetText = 1;
1542
+ const Replace$1 = 2;
1509
1543
  const SetAttribute = 3;
1510
1544
  const RemoveAttribute = 4;
1511
1545
  const Add = 6;
@@ -1514,24 +1548,6 @@ const NavigateParent = 8;
1514
1548
  const RemoveChild = 9;
1515
1549
  const NavigateSibling = 10;
1516
1550
 
1517
- const applyPendingPatches = (patches, pendingPatches, skip) => {
1518
- for (let k = 0; k < pendingPatches.length - skip; k += 2) {
1519
- const type = pendingPatches[k];
1520
- const index = pendingPatches[k + 1];
1521
- if (type === NavigateParent) {
1522
- patches.push({
1523
- type
1524
- });
1525
- } else {
1526
- patches.push({
1527
- type,
1528
- index
1529
- });
1530
- }
1531
- }
1532
- pendingPatches.length = 0;
1533
- };
1534
-
1535
1551
  const isKey = key => {
1536
1552
  return key !== 'type' && key !== 'childCount';
1537
1553
  };
@@ -1541,183 +1557,262 @@ const getKeys = node => {
1541
1557
  return keys;
1542
1558
  };
1543
1559
 
1544
- const getTotalChildCount = (nodes, index) => {
1545
- let i = index;
1546
- let pending = 1;
1547
- while (pending) {
1560
+ const arrayToTree = nodes => {
1561
+ const result = [];
1562
+ let i = 0;
1563
+ while (i < nodes.length) {
1548
1564
  const node = nodes[i];
1549
- pending += node.childCount;
1550
- pending--;
1551
- i++;
1565
+ const {
1566
+ children,
1567
+ nodesConsumed
1568
+ } = getChildrenWithCount(nodes, i + 1, node.childCount || 0);
1569
+ result.push({
1570
+ node,
1571
+ children
1572
+ });
1573
+ i += 1 + nodesConsumed;
1552
1574
  }
1553
- return i - index;
1575
+ return result;
1576
+ };
1577
+ const getChildrenWithCount = (nodes, startIndex, childCount) => {
1578
+ if (childCount === 0) {
1579
+ return {
1580
+ children: [],
1581
+ nodesConsumed: 0
1582
+ };
1583
+ }
1584
+ const children = [];
1585
+ let i = startIndex;
1586
+ let remaining = childCount;
1587
+ let totalConsumed = 0;
1588
+ while (remaining > 0 && i < nodes.length) {
1589
+ const node = nodes[i];
1590
+ const nodeChildCount = node.childCount || 0;
1591
+ const {
1592
+ children: nodeChildren,
1593
+ nodesConsumed
1594
+ } = getChildrenWithCount(nodes, i + 1, nodeChildCount);
1595
+ children.push({
1596
+ node,
1597
+ children: nodeChildren
1598
+ });
1599
+ const nodeSize = 1 + nodesConsumed;
1600
+ i += nodeSize;
1601
+ totalConsumed += nodeSize;
1602
+ remaining--;
1603
+ }
1604
+ return {
1605
+ children,
1606
+ nodesConsumed: totalConsumed
1607
+ };
1554
1608
  };
1555
1609
 
1556
- const diff$1 = (oldNodes, newNodes) => {
1610
+ const compareNodes = (oldNode, newNode) => {
1557
1611
  const patches = [];
1558
- const pendingPatches = [];
1559
- let i = 0;
1560
- let j = 0;
1561
- let siblingOffset = 0;
1562
- let maxSiblingOffset = 1;
1563
- const indexStack = [0, 1];
1564
- while (i < oldNodes.length && j < newNodes.length) {
1565
- const oldNode = oldNodes[i];
1566
- const newNode = newNodes[j];
1567
- // TODO maybe don't have the current element in indexstack
1568
- if (siblingOffset === maxSiblingOffset) {
1569
- indexStack.pop();
1570
- indexStack.pop();
1571
- pendingPatches.push(NavigateParent, 0);
1572
- maxSiblingOffset = indexStack.pop();
1573
- siblingOffset = indexStack.pop() + 1;
1574
- }
1575
- while (siblingOffset === maxSiblingOffset) {
1576
- pendingPatches.push(NavigateParent, 0);
1577
- maxSiblingOffset = indexStack.pop();
1578
- siblingOffset = indexStack.pop() + 1;
1612
+ // Check if node type changed - return null to signal incompatible nodes
1613
+ // (caller should handle this with a Replace operation)
1614
+ if (oldNode.type !== newNode.type) {
1615
+ return null;
1616
+ }
1617
+ // Handle text nodes
1618
+ if (oldNode.type === Text && newNode.type === Text) {
1619
+ if (oldNode.text !== newNode.text) {
1620
+ patches.push({
1621
+ type: SetText,
1622
+ value: newNode.text
1623
+ });
1579
1624
  }
1580
- if (oldNode.type !== newNode.type) {
1581
- let skip = 0;
1582
- if (pendingPatches.length > 0 && pendingPatches.at(-2) === NavigateChild) {
1583
- skip = 2;
1584
- }
1585
- applyPendingPatches(patches, pendingPatches, skip);
1586
- const oldTotal = getTotalChildCount(oldNodes, i);
1587
- const newTotal = getTotalChildCount(newNodes, j);
1625
+ return patches;
1626
+ }
1627
+ // Compare attributes
1628
+ const oldKeys = getKeys(oldNode);
1629
+ const newKeys = getKeys(newNode);
1630
+ // Check for attribute changes
1631
+ for (const key of newKeys) {
1632
+ if (oldNode[key] !== newNode[key]) {
1588
1633
  patches.push({
1589
- type: RemoveChild,
1590
- index: siblingOffset
1634
+ type: SetAttribute,
1635
+ key,
1636
+ value: newNode[key]
1591
1637
  });
1638
+ }
1639
+ }
1640
+ // Check for removed attributes
1641
+ for (const key of oldKeys) {
1642
+ if (!(key in newNode)) {
1592
1643
  patches.push({
1593
- type: Add,
1594
- nodes: newNodes.slice(j, j + newTotal)
1644
+ type: RemoveAttribute,
1645
+ key
1595
1646
  });
1596
- siblingOffset++;
1597
- i += oldTotal;
1598
- j += newTotal;
1647
+ }
1648
+ }
1649
+ return patches;
1650
+ };
1651
+
1652
+ const treeToArray = node => {
1653
+ const result = [node.node];
1654
+ for (const child of node.children) {
1655
+ result.push(...treeToArray(child));
1656
+ }
1657
+ return result;
1658
+ };
1659
+
1660
+ const diffChildren = (oldChildren, newChildren, patches) => {
1661
+ const maxLength = Math.max(oldChildren.length, newChildren.length);
1662
+ // Track where we are: -1 means at parent, >= 0 means at child index
1663
+ let currentChildIndex = -1;
1664
+ // Collect indices of children to remove (we'll add these patches at the end in reverse order)
1665
+ const indicesToRemove = [];
1666
+ for (let i = 0; i < maxLength; i++) {
1667
+ const oldNode = oldChildren[i];
1668
+ const newNode = newChildren[i];
1669
+ if (!oldNode && !newNode) {
1599
1670
  continue;
1600
1671
  }
1601
- if (oldNode.type === Text && newNode.type === Text) {
1602
- if (oldNode.text !== newNode.text) {
1603
- if (siblingOffset !== 0) {
1604
- pendingPatches.push(NavigateSibling, siblingOffset);
1605
- }
1606
- applyPendingPatches(patches, pendingPatches, 0);
1672
+ if (!oldNode) {
1673
+ // Add new node - we should be at the parent
1674
+ if (currentChildIndex >= 0) {
1675
+ // Navigate back to parent
1607
1676
  patches.push({
1608
- type: SetText,
1609
- value: newNode.text
1677
+ type: NavigateParent
1610
1678
  });
1679
+ currentChildIndex = -1;
1611
1680
  }
1612
- i++;
1613
- j++;
1614
- siblingOffset++;
1615
- continue;
1616
- }
1617
- const oldKeys = getKeys(oldNode);
1618
- const newKeys = getKeys(newNode);
1619
- let hasAttributeChanges = false;
1620
- for (const key of newKeys) {
1621
- if (oldNode[key] !== newNode[key]) {
1622
- hasAttributeChanges = true;
1623
- break;
1624
- }
1625
- }
1626
- for (const key of oldKeys) {
1627
- if (!(key in newNode)) {
1628
- hasAttributeChanges = true;
1629
- break;
1630
- }
1631
- }
1632
- if (hasAttributeChanges) {
1633
- if (siblingOffset > 0) {
1634
- pendingPatches.push(NavigateSibling, siblingOffset);
1635
- }
1636
- applyPendingPatches(patches, pendingPatches, 0);
1637
- for (const key of newKeys) {
1638
- if (oldNode[key] !== newNode[key]) {
1681
+ // Flatten the entire subtree so renderInternal can handle it
1682
+ const flatNodes = treeToArray(newNode);
1683
+ patches.push({
1684
+ type: Add,
1685
+ nodes: flatNodes
1686
+ });
1687
+ } else if (newNode) {
1688
+ // Compare nodes to see if we need any patches
1689
+ const nodePatches = compareNodes(oldNode.node, newNode.node);
1690
+ // If nodePatches is null, the node types are incompatible - need to replace
1691
+ if (nodePatches === null) {
1692
+ // Navigate to this child
1693
+ if (currentChildIndex === -1) {
1639
1694
  patches.push({
1640
- type: SetAttribute,
1641
- key,
1642
- value: newNode[key]
1695
+ type: NavigateChild,
1696
+ index: i
1643
1697
  });
1644
- }
1645
- }
1646
- for (const key of oldKeys) {
1647
- if (!(key in newNode)) {
1698
+ currentChildIndex = i;
1699
+ } else if (currentChildIndex !== i) {
1648
1700
  patches.push({
1649
- type: RemoveAttribute,
1650
- key
1701
+ type: NavigateSibling,
1702
+ index: i
1651
1703
  });
1704
+ currentChildIndex = i;
1652
1705
  }
1653
- }
1654
- }
1655
- if (oldNode.childCount && newNode.childCount) {
1656
- maxSiblingOffset = oldNode.childCount;
1657
- indexStack.push(0, maxSiblingOffset);
1658
- pendingPatches.push(NavigateChild, 0);
1659
- i++;
1660
- j++;
1661
- continue;
1662
- }
1663
- if (oldNode.childCount) {
1664
- applyPendingPatches(patches, pendingPatches, 0);
1665
- for (let k = 0; k < oldNode.childCount; k++) {
1706
+ // Replace the entire subtree
1707
+ const flatNodes = treeToArray(newNode);
1666
1708
  patches.push({
1667
- type: RemoveChild,
1668
- index: 0
1709
+ type: Replace$1,
1710
+ nodes: flatNodes
1669
1711
  });
1712
+ // After replace, we're at the new element (same position)
1713
+ continue;
1670
1714
  }
1671
- i += getTotalChildCount(oldNodes, i);
1672
- j++;
1673
- siblingOffset++;
1674
- continue;
1675
- }
1676
- if (newNode.childCount) {
1677
- applyPendingPatches(patches, pendingPatches, 0);
1678
- const total = getTotalChildCount(newNodes, j);
1679
- patches.push({
1680
- type: Add,
1681
- nodes: newNodes.slice(j + 1, j + total)
1682
- });
1683
- i++;
1684
- j += total;
1685
- continue;
1715
+ // Check if we need to recurse into children
1716
+ const hasChildrenToCompare = oldNode.children.length > 0 || newNode.children.length > 0;
1717
+ // Only navigate to this element if we need to do something
1718
+ if (nodePatches.length > 0 || hasChildrenToCompare) {
1719
+ // Navigate to this child if not already there
1720
+ if (currentChildIndex === -1) {
1721
+ patches.push({
1722
+ type: NavigateChild,
1723
+ index: i
1724
+ });
1725
+ currentChildIndex = i;
1726
+ } else if (currentChildIndex !== i) {
1727
+ patches.push({
1728
+ type: NavigateSibling,
1729
+ index: i
1730
+ });
1731
+ currentChildIndex = i;
1732
+ }
1733
+ // Apply node patches (these apply to the current element, not children)
1734
+ if (nodePatches.length > 0) {
1735
+ patches.push(...nodePatches);
1736
+ }
1737
+ // Compare children recursively
1738
+ if (hasChildrenToCompare) {
1739
+ diffChildren(oldNode.children, newNode.children, patches);
1740
+ }
1741
+ }
1742
+ } else {
1743
+ // Remove old node - collect the index for later removal
1744
+ indicesToRemove.push(i);
1686
1745
  }
1687
- i++;
1688
- j++;
1689
- siblingOffset++;
1690
1746
  }
1691
- while (i < oldNodes.length) {
1692
- if (indexStack.length !== 2) {
1693
- patches.push({
1694
- type: NavigateParent
1695
- });
1696
- }
1747
+ // Navigate back to parent if we ended at a child
1748
+ if (currentChildIndex >= 0) {
1749
+ patches.push({
1750
+ type: NavigateParent
1751
+ });
1752
+ currentChildIndex = -1;
1753
+ }
1754
+ // Add remove patches in reverse order (highest index first)
1755
+ // This ensures indices remain valid as we remove
1756
+ for (let j = indicesToRemove.length - 1; j >= 0; j--) {
1697
1757
  patches.push({
1698
1758
  type: RemoveChild,
1699
- index: siblingOffset
1759
+ index: indicesToRemove[j]
1700
1760
  });
1701
- i += getTotalChildCount(oldNodes, i);
1702
- indexStack.pop();
1703
- indexStack.pop();
1704
1761
  }
1705
- while (j < newNodes.length) {
1706
- if (siblingOffset > 0) {
1762
+ };
1763
+ const diffTrees = (oldTree, newTree, patches, path) => {
1764
+ // At the root level (path.length === 0), we're already AT the element
1765
+ // So we compare the root node directly, then compare its children
1766
+ if (path.length === 0 && oldTree.length === 1 && newTree.length === 1) {
1767
+ const oldNode = oldTree[0];
1768
+ const newNode = newTree[0];
1769
+ // Compare root nodes
1770
+ const nodePatches = compareNodes(oldNode.node, newNode.node);
1771
+ // If nodePatches is null, the root node types are incompatible - need to replace
1772
+ if (nodePatches === null) {
1773
+ const flatNodes = treeToArray(newNode);
1707
1774
  patches.push({
1708
- type: NavigateSibling,
1709
- index: siblingOffset
1775
+ type: Replace$1,
1776
+ nodes: flatNodes
1710
1777
  });
1711
- siblingOffset = 0;
1778
+ return;
1712
1779
  }
1713
- const count = getTotalChildCount(newNodes, j);
1714
- patches.push({
1715
- type: Add,
1716
- nodes: newNodes.slice(j, j + count)
1717
- });
1718
- j += count;
1780
+ if (nodePatches.length > 0) {
1781
+ patches.push(...nodePatches);
1782
+ }
1783
+ // Compare children
1784
+ if (oldNode.children.length > 0 || newNode.children.length > 0) {
1785
+ diffChildren(oldNode.children, newNode.children, patches);
1786
+ }
1787
+ } else {
1788
+ // Non-root level or multiple root elements - use the regular comparison
1789
+ diffChildren(oldTree, newTree, patches);
1719
1790
  }
1720
- return patches;
1791
+ };
1792
+
1793
+ const removeTrailingNavigationPatches = patches => {
1794
+ // Find the last non-navigation patch
1795
+ let lastNonNavigationIndex = -1;
1796
+ for (let i = patches.length - 1; i >= 0; i--) {
1797
+ const patch = patches[i];
1798
+ if (patch.type !== NavigateChild && patch.type !== NavigateParent && patch.type !== NavigateSibling) {
1799
+ lastNonNavigationIndex = i;
1800
+ break;
1801
+ }
1802
+ }
1803
+ // Return patches up to and including the last non-navigation patch
1804
+ return lastNonNavigationIndex === -1 ? [] : patches.slice(0, lastNonNavigationIndex + 1);
1805
+ };
1806
+
1807
+ const diffTree = (oldNodes, newNodes) => {
1808
+ // Step 1: Convert flat arrays to tree structures
1809
+ const oldTree = arrayToTree(oldNodes);
1810
+ const newTree = arrayToTree(newNodes);
1811
+ // Step 3: Compare the trees
1812
+ const patches = [];
1813
+ diffTrees(oldTree, newTree, patches, []);
1814
+ // Remove trailing navigation patches since they serve no purpose
1815
+ return removeTrailingNavigationPatches(patches);
1721
1816
  };
1722
1817
 
1723
1818
  const User = 1;
@@ -1994,6 +2089,7 @@ const create = (uid, x, y, width, height, workspacePath, assetDir, itemHeight, v
1994
2089
  disposed: false,
1995
2090
  fileCount: 0,
1996
2091
  height,
2092
+ initial: true,
1997
2093
  searchResults: [],
1998
2094
  stats: {},
1999
2095
  uid,
@@ -2106,7 +2202,7 @@ const isEqual = (oldState, newState) => {
2106
2202
  };
2107
2203
 
2108
2204
  const modules = [isEqual$2, isEqual$5, isEqual$3, isEqual$6, isEqual$1, isEqual, isEqual$4];
2109
- const numbers = [RenderItems, RenderFocus, RenderIncludeValue, RenderExcludeValue, RenderReplaceValue, RenderValue, RenderFocusContext];
2205
+ const numbers = [RenderIncremental, RenderFocus, RenderIncludeValue, RenderExcludeValue, RenderReplaceValue, RenderValue, RenderFocusContext];
2110
2206
 
2111
2207
  const diff = (oldState, newState) => {
2112
2208
  const diffResult = [];
@@ -2867,7 +2963,7 @@ const getMenuEntriesList = (state, props) => {
2867
2963
  };
2868
2964
 
2869
2965
  const getMenuEntries = (state, props) => {
2870
- if (props.menuId === Search$2) {
2966
+ if (props.menuId === Search$1) {
2871
2967
  return getMenuEntriesList(state, props);
2872
2968
  }
2873
2969
  if (props.menuId === InputContextMenu) {
@@ -2877,7 +2973,7 @@ const getMenuEntries = (state, props) => {
2877
2973
  };
2878
2974
 
2879
2975
  const getMenuEntryIds = () => {
2880
- return [Search$2, InputContextMenu];
2976
+ return [Search$1, InputContextMenu];
2881
2977
  };
2882
2978
 
2883
2979
  const ClearAll$1 = 'ClearAll';
@@ -4476,6 +4572,7 @@ const loadContent = async (state, savedState) => {
4476
4572
  const result = await handleUpdate(state, update);
4477
4573
  return {
4478
4574
  ...result,
4575
+ initial: false,
4479
4576
  loaded: true
4480
4577
  };
4481
4578
  }
@@ -4483,6 +4580,7 @@ const loadContent = async (state, savedState) => {
4483
4580
  ...state,
4484
4581
  ...update,
4485
4582
  flags,
4583
+ initial: false,
4486
4584
  loaded: true,
4487
4585
  threads
4488
4586
  };
@@ -4581,7 +4679,7 @@ const renderFocus = (oldState, newState) => {
4581
4679
  };
4582
4680
 
4583
4681
  const renderFocusContext = (oldState, newState) => {
4584
- return [SetFocusContext, newState.uid, FocusSearch$1, newState.focus];
4682
+ return [SetFocusContext, newState.uid, FocusSearch, newState.focus];
4585
4683
  };
4586
4684
 
4587
4685
  const None = 0;
@@ -4751,7 +4849,7 @@ const getSearchDetailsToggleVirtualDom = () => {
4751
4849
  role: Button$3,
4752
4850
  tabIndex: 0,
4753
4851
  title: toggleSearchDetails(),
4754
- type: Button$1
4852
+ type: Button$2
4755
4853
  }, {
4756
4854
  childCount: 0,
4757
4855
  className: mergeClassNames(MaskIcon, MaskIconEllipsis),
@@ -4871,7 +4969,7 @@ const getSearchFieldButtonVirtualDom = button => {
4871
4969
  role,
4872
4970
  tabIndex: 0,
4873
4971
  title,
4874
- type: Button$1
4972
+ type: Button$2
4875
4973
  }, {
4876
4974
  childCount: 0,
4877
4975
  className: mergeClassNames(MaskIcon, icon),
@@ -5048,7 +5146,7 @@ const getSearchToggleVirtualDom = replaceExpanded => {
5048
5146
  name: ToggleReplace,
5049
5147
  onClick: HandleButtonClick,
5050
5148
  title: toggleReplace$1(),
5051
- type: Button$1
5149
+ type: Button$2
5052
5150
  }, {
5053
5151
  childCount: 0,
5054
5152
  className: mergeClassNames(MaskIcon, replaceExpanded ? MaskIconChevronDown : MaskIconChevronRight),
@@ -5263,7 +5361,7 @@ const getSearchRemoveVirtualDom = () => {
5263
5361
  className: SearchRemove,
5264
5362
  name: Remove,
5265
5363
  title,
5266
- type: Button$1
5364
+ type: Button$2
5267
5365
  }, closeIcon];
5268
5366
  return dom;
5269
5367
  };
@@ -5342,8 +5440,11 @@ const getSearchResultsVirtualDom = (visibleItems, focusOutline, scrollbarHeight,
5342
5440
  }, ...getTreeItemsVirtualDom(visibleItems, deltaY, itemHeight), ...getScrollBarVirtualDom(scrollbarHeight, scrollBarY, scrollBarValue)];
5343
5441
  };
5344
5442
 
5345
- const className = mergeClassNames(Viewlet, Search$1);
5346
- const getSearchVirtualDom = (visibleItems, flags, message, focusOutline, searchInputErrorMessage, scrollBarHeight, scrollBarY, scrollBarValue, deltaY, itemHeight, matchCount, limitHitWarning, focus = 0) => {
5443
+ const className = mergeClassNames(Viewlet, Search$2);
5444
+ const getSearchVirtualDom = (visibleItems, flags, message, focusOutline, searchInputErrorMessage, scrollBarHeight, scrollBarY, scrollBarValue, deltaY, itemHeight, matchCount, limitHitWarning, focus = 0, initial = false) => {
5445
+ if (initial) {
5446
+ return [];
5447
+ }
5347
5448
  const errorDom = getSearchInputErrorVirtualDom(searchInputErrorMessage);
5348
5449
  const childCount = 2 + (errorDom.length > 0 ? 1 : 0);
5349
5450
  return [{
@@ -5355,16 +5456,16 @@ const getSearchVirtualDom = (visibleItems, flags, message, focusOutline, searchI
5355
5456
 
5356
5457
  const renderItems = (oldState, newState) => {
5357
5458
  const viewModel = createViewModel(newState);
5358
- const dom = getSearchVirtualDom(viewModel.displayResults, viewModel.flags, viewModel.message, viewModel.focusOutline, viewModel.searchInputErrorMessage, viewModel.scrollBarHeight, viewModel.scrollBarY, viewModel.scrollBarValue, viewModel.deltaY, viewModel.itemHeight, viewModel.matchCount, newState.limitHitWarning, viewModel.focus);
5459
+ const dom = getSearchVirtualDom(viewModel.displayResults, viewModel.flags, viewModel.message, viewModel.focusOutline, viewModel.searchInputErrorMessage, viewModel.scrollBarHeight, viewModel.scrollBarY, viewModel.scrollBarValue, viewModel.deltaY, viewModel.itemHeight, viewModel.matchCount, newState.limitHitWarning, viewModel.focus, newState.initial);
5359
5460
  return [SetDom2, newState.uid, dom];
5360
5461
  };
5361
5462
 
5362
5463
  // TODO cache rendered dom so that it can be used for dom diffing
5363
5464
  const renderIncremental = (oldState, newState) => {
5364
- const oldDom = renderItems(oldState, oldState);
5365
- const newDom = renderItems(newState, newState);
5366
- const patches = diff$1(oldDom, newDom);
5367
- return patches;
5465
+ const oldDom = renderItems(oldState, oldState)[2];
5466
+ const newDom = renderItems(newState, newState)[2];
5467
+ const patches = diffTree(oldDom, newDom);
5468
+ return ['Viewlet.setPatches', newState.uid, patches];
5368
5469
  };
5369
5470
 
5370
5471
  const renderSelections = (oldState, newState) => {
@@ -5461,7 +5562,7 @@ const getActionButtonVirtualDom = action => {
5461
5562
  className,
5462
5563
  name: id,
5463
5564
  title: label,
5464
- type: Button$1
5565
+ type: Button$2
5465
5566
  }, getIconVirtualDom(icon)];
5466
5567
  };
5467
5568
 
@@ -5558,7 +5659,7 @@ const renderEventListeners = () => {
5558
5659
  params: ['handleClickAt', ClientX, ClientY, TargetName]
5559
5660
  }, {
5560
5661
  name: HandleListPointerDown,
5561
- params: ['handleListPointerDown', Button$2, TargetName]
5662
+ params: ['handleListPointerDown', Button$1, TargetName]
5562
5663
  }, {
5563
5664
  name: HandleToggleButtonClick,
5564
5665
  params: ['handleToggleButtonClick']
@@ -5570,11 +5671,11 @@ const renderEventListeners = () => {
5570
5671
  params: ['handleListBlur']
5571
5672
  }, {
5572
5673
  name: HandleListContextMenu,
5573
- params: ['handleContextMenu', Button$2, ClientX, ClientY],
5674
+ params: ['handleContextMenu', Button$1, ClientX, ClientY],
5574
5675
  preventDefault: true
5575
5676
  }, {
5576
5677
  name: HandleInputContextMenu,
5577
- params: ['handleInputContextMenu', TargetName, Button$2, ClientX, ClientY],
5678
+ params: ['handleInputContextMenu', TargetName, Button$1, ClientX, ClientY],
5578
5679
  preventDefault: true
5579
5680
  }, {
5580
5681
  name: HandleActionClick,
@@ -5782,10 +5883,10 @@ const handleContextMenuKeyboard = async state => {
5782
5883
  x,
5783
5884
  y
5784
5885
  } = state; // TODO
5785
- await show2(uid, Search$2, x, y, {
5886
+ await show2(uid, Search$1, x, y, {
5786
5887
  index: 0,
5787
5888
  // TODO pass proper index
5788
- menuId: Search$2
5889
+ menuId: Search$1
5789
5890
  });
5790
5891
  return state;
5791
5892
  };
@@ -5811,9 +5912,9 @@ const handleContextMenuMouseAt = async (state, eventX, eventY) => {
5811
5912
  focusedIndex: index,
5812
5913
  listFocusedIndex: index
5813
5914
  });
5814
- await show2(uid, Search$2, x, y, {
5915
+ await show2(uid, Search$1, x, y, {
5815
5916
  index,
5816
- menuId: Search$2
5917
+ menuId: Search$1
5817
5918
  });
5818
5919
  return state;
5819
5920
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/text-search-worker",
3
- "version": "5.34.0",
3
+ "version": "6.0.0",
4
4
  "description": "Text Search Worker",
5
5
  "keywords": [
6
6
  "text-search"