@lvce-editor/renderer-process 26.0.0 → 26.1.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.
@@ -1300,114 +1300,91 @@ const setStyle = ($Element, styleString) => {
1300
1300
  }
1301
1301
  };
1302
1302
 
1303
+ const optionalAttributeProps = new Map([['ariaActivedescendant', 'aria-activedescendant'], ['ariaOwns', 'aria-owns']]);
1304
+ const mappedAttributeProps = new Map([['ariaControls', 'aria-controls'], ['ariaLabelledBy', 'aria-labelledby']]);
1305
+ const pixelStyleProps = new Set(['left', 'marginTop', 'paddingLeft', 'paddingRight', 'top']);
1306
+ const eventProps = new Set(['onBlur', 'onChange', 'onClick', 'onContextMenu', 'onBeforeInput', 'onDblClick', 'onDragEnd', 'onDragEnter', 'onDragLeave', 'onDragOver', 'onDragStart', 'onDrop', 'onFocus', 'onFocusIn', 'onFocusOut', 'onInput', 'onKeydown', 'onKeyDown', 'onKeyUp', 'onMouseDown', 'onMouseMove', 'onMouseOut', 'onMouseOver', 'onMouseUp', 'onPointerDown', 'onPointerMove', 'onPointerOut', 'onPointerOver', 'onScroll', 'onSelectionChange', 'onSubmit', 'onWheel']);
1307
+ const setOptionalAttribute = ($Element, attributeName, value) => {
1308
+ if (value) {
1309
+ $Element.setAttribute(attributeName, value);
1310
+ return;
1311
+ }
1312
+ $Element.removeAttribute(attributeName);
1313
+ };
1314
+ const setDimension = ($Element, key, value) => {
1315
+ if ($Element instanceof HTMLImageElement) {
1316
+ $Element[key] = value;
1317
+ return;
1318
+ }
1319
+ $Element.style[key] = typeof value === 'number' ? `${value}px` : value;
1320
+ };
1321
+ const setPixelStyle = ($Element, key, value) => {
1322
+ $Element.style[key] = typeof value === 'number' ? `${value}px` : value;
1323
+ };
1324
+ const setEventProp = ($Element, key, value, eventMap, newEventMap) => {
1325
+ if (!eventMap || !value) {
1326
+ return;
1327
+ }
1328
+ const eventName = key.slice(2).toLowerCase();
1329
+ attachEvent$1($Element, eventMap, eventName, value, newEventMap);
1330
+ };
1303
1331
  const setProp = ($Element, key, value, eventMap, newEventMap) => {
1304
- switch (key) {
1305
- case 'ariaActivedescendant':
1306
- if (value) {
1307
- $Element.setAttribute('aria-activedescendant', value);
1308
- } else {
1309
- $Element.removeAttribute('aria-activedescendant');
1310
- }
1311
- break;
1312
- case 'ariaControls':
1313
- $Element.setAttribute('aria-controls', value);
1314
- break;
1315
- case 'ariaLabelledBy':
1316
- $Element.setAttribute('aria-labelledby', value);
1317
- break;
1318
- case 'ariaOwns':
1319
- // TODO remove this once idl is supported
1320
- if (value) {
1321
- $Element.setAttribute('aria-owns', value);
1322
- } else {
1323
- $Element.removeAttribute('aria-owns');
1324
- }
1325
- break;
1326
- case 'childCount':
1327
- case 'type':
1328
- break;
1329
- case 'height':
1330
- case 'width':
1331
- if ($Element instanceof HTMLImageElement) {
1332
- $Element[key] = value;
1333
- } else if (typeof value === 'number') {
1334
- $Element.style[key] = `${value}px`;
1335
- } else {
1336
- $Element.style[key] = value;
1337
- }
1338
- break;
1339
- case 'id':
1340
- if (value) {
1341
- $Element[key] = value;
1342
- } else {
1343
- $Element.removeAttribute(key);
1344
- }
1345
- break;
1346
- case 'inputType':
1347
- // @ts-ignore
1348
- $Element.type = value;
1349
- break;
1350
- case 'left':
1351
- case 'marginTop':
1352
- case 'paddingLeft':
1353
- case 'paddingRight':
1354
- case 'top':
1355
- $Element.style[key] = typeof value === 'number' ? `${value}px` : value;
1356
- break;
1357
- case 'maskImage':
1358
- $Element.style.maskImage = `url('${value}')`;
1359
- $Element.style.webkitMaskImage = `url('${value}')`;
1360
- break;
1361
- case 'onBlur':
1362
- case 'onChange':
1363
- case 'onClick':
1364
- case 'onContextMenu':
1365
- case 'onDblClick':
1366
- case 'onDragEnd':
1367
- case 'onDragEnter':
1368
- case 'onDragLeave':
1369
- case 'onDragOver':
1370
- case 'onDragStart':
1371
- case 'onDrop':
1372
- case 'onFocus':
1373
- case 'onFocusIn':
1374
- case 'onFocusOut':
1375
- case 'onInput':
1376
- case 'onKeydown':
1377
- case 'onKeyDown':
1378
- case 'onKeyUp':
1379
- case 'onMouseDown':
1380
- case 'onMouseMove':
1381
- case 'onMouseOut':
1382
- case 'onMouseOver':
1383
- case 'onMouseUp':
1384
- case 'onPointerDown':
1385
- case 'onPointerMove':
1386
- case 'onPointerOut':
1387
- case 'onPointerOver':
1388
- case 'onScroll':
1389
- case 'onSelectionChange':
1390
- case 'onSubmit':
1391
- case 'onWheel':
1392
- const eventName = key.slice(2).toLowerCase();
1393
- if (!eventMap || !value) {
1394
- return;
1395
- }
1396
- attachEvent$1($Element, eventMap, eventName, value, newEventMap);
1397
- break;
1398
- case 'style':
1399
- setStyle($Element, value);
1400
- break;
1401
- case 'translate':
1402
- $Element.style[key] = value;
1403
- break;
1404
- default:
1405
- if (key.startsWith('data-')) {
1406
- $Element.dataset[key.slice('data-'.length)] = value;
1407
- } else {
1408
- $Element[key] = value;
1409
- }
1332
+ const optionalAttributeName = optionalAttributeProps.get(key);
1333
+ if (optionalAttributeName) {
1334
+ setOptionalAttribute($Element, optionalAttributeName, value);
1335
+ return;
1336
+ }
1337
+ const mappedAttributeName = mappedAttributeProps.get(key);
1338
+ if (mappedAttributeName) {
1339
+ $Element.setAttribute(mappedAttributeName, value);
1340
+ return;
1341
+ }
1342
+ if (key === 'childCount' || key === 'type') {
1343
+ return;
1344
+ }
1345
+ if (key === 'height' || key === 'width') {
1346
+ setDimension($Element, key, value);
1347
+ return;
1348
+ }
1349
+ if (key === 'id') {
1350
+ if (value) {
1351
+ $Element[key] = value;
1352
+ } else {
1353
+ $Element.removeAttribute(key);
1354
+ }
1355
+ return;
1410
1356
  }
1357
+ if (key === 'inputType') {
1358
+ // @ts-ignore
1359
+ $Element.type = value;
1360
+ return;
1361
+ }
1362
+ if (pixelStyleProps.has(key)) {
1363
+ setPixelStyle($Element, key, value);
1364
+ return;
1365
+ }
1366
+ if (key === 'maskImage') {
1367
+ $Element.style.maskImage = `url('${value}')`;
1368
+ $Element.style.webkitMaskImage = `url('${value}')`;
1369
+ return;
1370
+ }
1371
+ if (eventProps.has(key)) {
1372
+ setEventProp($Element, key, value, eventMap, newEventMap);
1373
+ return;
1374
+ }
1375
+ if (key === 'style') {
1376
+ setStyle($Element, value);
1377
+ return;
1378
+ }
1379
+ if (key === 'translate') {
1380
+ $Element.style[key] = value;
1381
+ return;
1382
+ }
1383
+ if (key.startsWith('data-')) {
1384
+ $Element.dataset[key.slice('data-'.length)] = value;
1385
+ return;
1386
+ }
1387
+ $Element[key] = value;
1411
1388
  };
1412
1389
 
1413
1390
  const setProps = ($Element, props, eventMap, newEventMap) => {
@@ -1552,117 +1529,136 @@ const RemoveChild = 9;
1552
1529
  const NavigateSibling = 10;
1553
1530
  const SetReferenceNodeUid = 11;
1554
1531
 
1532
+ const handleNavigateChild = (state, patches, patchIndex) => {
1533
+ const patch = patches[patchIndex];
1534
+ const $Children = state.current.childNodes;
1535
+ const $Child = $Children[patch.index];
1536
+ if ($Child) {
1537
+ state.current = $Child;
1538
+ return true;
1539
+ }
1540
+ const nextPatch = patches[patchIndex + 1];
1541
+ if (nextPatch && nextPatch.type === Replace && patch.index === $Children.length) {
1542
+ const $Placeholder = document.createComment('virtual-dom-placeholder');
1543
+ state.current.append($Placeholder);
1544
+ state.current = $Placeholder;
1545
+ return true;
1546
+ }
1547
+ console.error('Cannot navigate to child: child not found at index', {
1548
+ $Current: state.current,
1549
+ index: patch.index,
1550
+ childCount: $Children.length
1551
+ });
1552
+ return false;
1553
+ };
1554
+ const handleNavigateParent = state => {
1555
+ const $Parent = state.current.parentNode;
1556
+ if (!$Parent) {
1557
+ console.error('Cannot navigate to parent: current node has no parent', {
1558
+ $Current: state.current
1559
+ });
1560
+ return false;
1561
+ }
1562
+ state.current = $Parent;
1563
+ return true;
1564
+ };
1565
+ const handleNavigateSibling = (state, patch, $Element, patchIndex) => {
1566
+ const $Parent = state.current.parentNode;
1567
+ if (!$Parent) {
1568
+ console.error('Cannot navigate to sibling: current node has no parent', {
1569
+ patchIndex
1570
+ });
1571
+ return false;
1572
+ }
1573
+ let $Sibling = $Parent.childNodes[patch.index];
1574
+ if (!$Sibling && !state.hasAppliedMutation && state.current !== $Element) {
1575
+ $Sibling = $Element.childNodes[patch.index];
1576
+ }
1577
+ if (!$Sibling) {
1578
+ console.error('Cannot navigate to sibling: sibling not found at index', {
1579
+ $Parent,
1580
+ index: patch.index,
1581
+ childCount: $Parent.childNodes.length
1582
+ });
1583
+ return false;
1584
+ }
1585
+ state.current = $Sibling;
1586
+ return true;
1587
+ };
1588
+ const handleSetReferenceNodeUid = (state, patch) => {
1589
+ const instance = get$a(patch.uid);
1590
+ if (!instance || !instance.state) {
1591
+ console.error('Cannot set reference node uid: instance not found', {
1592
+ uid: patch.uid
1593
+ });
1594
+ return false;
1595
+ }
1596
+ const $NewNode = instance.state.$Viewlet;
1597
+ // @ts-ignore
1598
+ state.current.replaceWith($NewNode);
1599
+ state.current = $NewNode;
1600
+ state.hasAppliedMutation = true;
1601
+ return true;
1602
+ };
1603
+ const handleNavigationPatch = (state, patch, patches, patchIndex, $Element) => {
1604
+ switch (patch.type) {
1605
+ case NavigateChild:
1606
+ return handleNavigateChild(state, patches, patchIndex);
1607
+ case NavigateParent:
1608
+ return handleNavigateParent(state);
1609
+ case NavigateSibling:
1610
+ return handleNavigateSibling(state, patch, $Element, patchIndex);
1611
+ default:
1612
+ return true;
1613
+ }
1614
+ };
1615
+ const applyMutationPatch = (state, patch, events) => {
1616
+ switch (patch.type) {
1617
+ case Add:
1618
+ add(state.current, patch.nodes, events);
1619
+ state.hasAppliedMutation = true;
1620
+ break;
1621
+ case RemoveAttribute:
1622
+ removeAttribute(state.current, patch.key);
1623
+ state.hasAppliedMutation = true;
1624
+ break;
1625
+ case RemoveChild:
1626
+ removeChild(state.current, patch.index);
1627
+ state.hasAppliedMutation = true;
1628
+ break;
1629
+ case Replace:
1630
+ state.current = replace(state.current, patch.nodes, events);
1631
+ state.hasAppliedMutation = true;
1632
+ break;
1633
+ case SetAttribute:
1634
+ setProp(state.current, patch.key, patch.value, events);
1635
+ state.hasAppliedMutation = true;
1636
+ break;
1637
+ case SetText:
1638
+ setText$3(state.current, patch.value);
1639
+ state.hasAppliedMutation = true;
1640
+ break;
1641
+ }
1642
+ };
1555
1643
  const applyPatch = ($Element, patches, eventMap = {}, id = 0) => {
1556
1644
  const events = getEventListenerMap(id) || eventMap;
1557
- let $Current = $Element;
1558
- let hasAppliedMutation = false;
1645
+ const state = {
1646
+ current: $Element,
1647
+ hasAppliedMutation: false
1648
+ };
1559
1649
  for (let patchIndex = 0; patchIndex < patches.length; patchIndex++) {
1560
1650
  const patch = patches[patchIndex];
1561
1651
  try {
1562
- switch (patch.type) {
1563
- case Add:
1564
- add($Current, patch.nodes, events);
1565
- hasAppliedMutation = true;
1566
- break;
1567
- case NavigateChild:
1568
- {
1569
- const $Children = $Current.childNodes;
1570
- const $Child = $Children[patch.index];
1571
- if (!$Child) {
1572
- const nextPatch = patches[patchIndex + 1];
1573
- if (nextPatch && nextPatch.type === Replace && patch.index === $Children.length) {
1574
- const $Placeholder = document.createComment('virtual-dom-placeholder');
1575
- $Current.append($Placeholder);
1576
- $Current = $Placeholder;
1577
- break;
1578
- }
1579
- console.error('Cannot navigate to child: child not found at index', {
1580
- $Current,
1581
- index: patch.index,
1582
- childCount: $Children.length
1583
- });
1584
- return;
1585
- }
1586
- $Current = $Child;
1587
- break;
1588
- }
1589
- case NavigateParent:
1590
- {
1591
- const $Parent = $Current.parentNode;
1592
- if (!$Parent) {
1593
- console.error('Cannot navigate to parent: current node has no parent', {
1594
- $Current
1595
- });
1596
- return;
1597
- }
1598
- $Current = $Parent;
1599
- break;
1600
- }
1601
- case NavigateSibling:
1602
- {
1603
- const $Parent = $Current.parentNode;
1604
- if (!$Parent) {
1605
- console.error('Cannot navigate to sibling: current node has no parent', {
1606
- patchIndex
1607
- });
1608
- return;
1609
- }
1610
- let $Sibling = $Parent.childNodes[patch.index];
1611
- if (!$Sibling && !hasAppliedMutation && $Current !== $Element) {
1612
- $Sibling = $Element.childNodes[patch.index];
1613
- }
1614
- $Current = $Sibling;
1615
- if (!$Current) {
1616
- console.error('Cannot navigate to sibling: sibling not found at index', {
1617
- $Parent,
1618
- index: patch.index,
1619
- childCount: $Parent.childNodes.length
1620
- });
1621
- return;
1622
- }
1623
- break;
1624
- }
1625
- case RemoveAttribute:
1626
- removeAttribute($Current, patch.key);
1627
- hasAppliedMutation = true;
1628
- break;
1629
- case RemoveChild:
1630
- removeChild($Current, patch.index);
1631
- hasAppliedMutation = true;
1632
- break;
1633
- case Replace:
1634
- $Current = replace($Current, patch.nodes, events);
1635
- hasAppliedMutation = true;
1636
- break;
1637
- case SetAttribute:
1638
- setProp($Current, patch.key, patch.value, events);
1639
- hasAppliedMutation = true;
1640
- break;
1641
- case SetReferenceNodeUid:
1642
- {
1643
- // Get the new reference node instance
1644
- const instance = get$a(patch.uid);
1645
- if (!instance || !instance.state) {
1646
- console.error('Cannot set reference node uid: instance not found', {
1647
- uid: patch.uid
1648
- });
1649
- return;
1650
- }
1651
- const $NewNode = instance.state.$Viewlet;
1652
- // Replace the current reference node with the new viewlet
1653
- // @ts-ignore
1654
- $Current.replaceWith($NewNode);
1655
- $Current = $NewNode;
1656
- hasAppliedMutation = true;
1657
- break;
1658
- }
1659
- case SetText:
1660
- setText$3($Current, patch.value);
1661
- hasAppliedMutation = true;
1662
- break;
1663
- default:
1664
- break;
1652
+ if (!handleNavigationPatch(state, patch, patches, patchIndex, $Element)) {
1653
+ return;
1665
1654
  }
1655
+ if (patch.type === SetReferenceNodeUid) {
1656
+ if (!handleSetReferenceNodeUid(state, patch)) {
1657
+ return;
1658
+ }
1659
+ continue;
1660
+ }
1661
+ applyMutationPatch(state, patch, events);
1666
1662
  } catch (error) {
1667
1663
  console.error('Error applying patch at index ' + patchIndex, patch, error);
1668
1664
  throw error;
@@ -1693,71 +1689,96 @@ const focusElement = $Element => {
1693
1689
  preventScroll: true
1694
1690
  });
1695
1691
  };
1696
- const rememberFocus$1 = ($Viewlet, dom, eventMap, uid = 0) => {
1697
- startIgnore();
1698
- const oldLeft = $Viewlet.style.left;
1699
- const oldTop = $Viewlet.style.top;
1700
- const oldWidth = $Viewlet.style.width;
1701
- const oldHeight = $Viewlet.style.height;
1702
- const activeElement = getActiveElementInside($Viewlet);
1703
- const isTreeFocused = activeElement?.getAttribute('role') === 'tree';
1704
- const isRootTree = $Viewlet.getAttribute('role') === 'tree' && activeElement === $Viewlet;
1705
- const focused = activeElement?.getAttribute('name');
1706
- const $Hidden = document.createElement('div');
1707
- $Hidden.style.display = 'none';
1708
- if (focused) {
1709
- if (document.body) {
1710
- document.body.append($Hidden);
1711
- }
1712
- // @ts-ignore
1713
- $Hidden.append(activeElement);
1714
- }
1692
+ const getInputMap = $Viewlet => {
1715
1693
  const $$Inputs = queryInputs($Viewlet);
1716
1694
  const inputMap = Object.create(null);
1717
1695
  for (const $Input of $$Inputs) {
1718
1696
  inputMap[$Input.name] = $Input.value;
1719
1697
  }
1720
- if (uid) {
1721
- const newEventMap = getEventListenerMap(uid);
1722
- const $New = render(dom, eventMap, newEventMap).firstChild;
1723
- setComponentUid($New, uid);
1724
- const $$NewInputs = queryInputs($New);
1725
- for (const $Input of $$NewInputs) {
1726
- $Input.value = inputMap[$Input.name] || $Input.value || '';
1727
- }
1728
- $Viewlet.replaceWith($New);
1729
- if (focused) {
1730
- const $NewFocused = $New.querySelector(`[name="${focused}"]`);
1731
- if ($NewFocused) {
1732
- const $Previous = $Hidden.firstChild;
1733
- $Previous.className = $NewFocused.className;
1734
- $Previous.placeholder = $NewFocused.placeholder;
1735
- if ($NewFocused.childNodes) {
1736
- $Previous.replaceChildren(...$NewFocused.childNodes);
1737
- }
1738
- $NewFocused.replaceWith($Previous);
1739
- }
1740
- }
1741
- $Hidden.remove();
1742
- $Viewlet = $New;
1743
- } else {
1744
- renderInto($Viewlet, dom, eventMap);
1698
+ return inputMap;
1699
+ };
1700
+ const createHiddenContainer = (activeElement, focused) => {
1701
+ const $Hidden = document.createElement('div');
1702
+ $Hidden.style.display = 'none';
1703
+ if (focused && activeElement && document.body) {
1704
+ document.body.append($Hidden);
1705
+ $Hidden.append(activeElement);
1745
1706
  }
1707
+ return $Hidden;
1708
+ };
1709
+ const restoreFocusedElement = ($Hidden, $New, focused) => {
1710
+ const $NewFocused = $New.querySelector(`[name="${focused}"]`);
1711
+ if (!$NewFocused) {
1712
+ return;
1713
+ }
1714
+ const $Previous = $Hidden.firstChild;
1715
+ if (!$Previous) {
1716
+ return;
1717
+ }
1718
+ $Previous.className = $NewFocused.className;
1719
+ $Previous.placeholder = $NewFocused.placeholder;
1720
+ if ($NewFocused.childNodes) {
1721
+ $Previous.replaceChildren(...$NewFocused.childNodes);
1722
+ }
1723
+ $NewFocused.replaceWith($Previous);
1724
+ };
1725
+ const renderWithUid = ($Viewlet, dom, eventMap, uid, inputMap, focused, $Hidden) => {
1726
+ const newEventMap = getEventListenerMap(uid);
1727
+ const $New = render(dom, eventMap, newEventMap).firstChild;
1728
+ setComponentUid($New, uid);
1729
+ const $$NewInputs = queryInputs($New);
1730
+ for (const $Input of $$NewInputs) {
1731
+ $Input.value = inputMap[$Input.name] || $Input.value || '';
1732
+ }
1733
+ $Viewlet.replaceWith($New);
1734
+ if (focused) {
1735
+ restoreFocusedElement($Hidden, $New, focused);
1736
+ }
1737
+ return $New;
1738
+ };
1739
+ const restoreFocus = ($Viewlet, isRootTree, isTreeFocused, focused) => {
1746
1740
  if (isRootTree) {
1747
1741
  focusElement($Viewlet);
1748
- } else if (isTreeFocused) {
1742
+ return;
1743
+ }
1744
+ if (isTreeFocused) {
1749
1745
  const $Tree = $Viewlet.querySelector('[role="tree"]');
1750
1746
  if ($Tree) {
1751
1747
  // @ts-ignore
1752
1748
  focusElement($Tree);
1753
1749
  }
1754
- } else if (focused) {
1755
- const $Focused = $Viewlet.querySelector(`[name="${focused}"]`);
1756
- if ($Focused) {
1757
- // @ts-ignore
1758
- focusElement($Focused);
1759
- }
1750
+ return;
1751
+ }
1752
+ if (!focused) {
1753
+ return;
1754
+ }
1755
+ const $Focused = $Viewlet.querySelector(`[name="${focused}"]`);
1756
+ if ($Focused) {
1757
+ // @ts-ignore
1758
+ focusElement($Focused);
1759
+ }
1760
+ };
1761
+ const rememberFocus$1 = ($Viewlet, dom, eventMap, uid = 0) => {
1762
+ startIgnore();
1763
+ const oldLeft = $Viewlet.style.left;
1764
+ const oldTop = $Viewlet.style.top;
1765
+ const oldWidth = $Viewlet.style.width;
1766
+ const oldHeight = $Viewlet.style.height;
1767
+ const activeElement = getActiveElementInside($Viewlet);
1768
+ const isTreeFocused = activeElement?.getAttribute('role') === 'tree';
1769
+ const isRootTree = $Viewlet.getAttribute('role') === 'tree' && activeElement === $Viewlet;
1770
+ const focused = activeElement?.getAttribute('name') || null;
1771
+ const $Hidden = createHiddenContainer(activeElement, focused);
1772
+ const inputMap = getInputMap($Viewlet);
1773
+ if (uid) {
1774
+ const numericUid = Number(uid);
1775
+ $Viewlet = renderWithUid($Viewlet, dom, eventMap, numericUid, inputMap, focused, $Hidden);
1776
+ $Hidden.remove();
1777
+ } else {
1778
+ renderInto($Viewlet, dom, eventMap);
1779
+ $Hidden.remove();
1760
1780
  }
1781
+ restoreFocus($Viewlet, isRootTree, isTreeFocused, focused);
1761
1782
  $Viewlet.style.top = oldTop;
1762
1783
  $Viewlet.style.left = oldLeft;
1763
1784
  $Viewlet.style.height = oldHeight;
@@ -8975,6 +8996,11 @@ const setUid = (viewletId, uid) => {
8975
8996
  } = instance.state;
8976
8997
  set$3($Viewlet, uid);
8977
8998
  };
8999
+ const emptyFocusCallback = {
9000
+ id: 0,
9001
+ selector: ''
9002
+ };
9003
+ let focusCallback = emptyFocusCallback;
8978
9004
  const focusSelector = (viewletId, selector) => {
8979
9005
  const instance = get$a(viewletId);
8980
9006
  if (!instance) {
@@ -8987,7 +9013,16 @@ const focusSelector = (viewletId, selector) => {
8987
9013
  if (!$Element) {
8988
9014
  return;
8989
9015
  }
8990
- $Element.focus();
9016
+ if ($Element && $Element instanceof HTMLElement) {
9017
+ if ($Element.isConnected) {
9018
+ $Element.focus();
9019
+ } else {
9020
+ focusCallback = {
9021
+ id: viewletId,
9022
+ selector
9023
+ };
9024
+ }
9025
+ }
8991
9026
  };
8992
9027
 
8993
9028
  /**
@@ -9085,6 +9120,7 @@ const setPatches = (uid, patches) => {
9085
9120
  return;
9086
9121
  }
9087
9122
  applyPatch($Viewlet, patches, {}, uid);
9123
+ applyLateFocusMaybe();
9088
9124
  };
9089
9125
  const waitForElement = selector => {
9090
9126
  const element = document.querySelector(selector);
@@ -9266,6 +9302,7 @@ const append = (parentId, childId, referenceNodes) => {
9266
9302
  if (childInstance.factory?.postAppend) {
9267
9303
  childInstance.factory.postAppend(childInstance.state);
9268
9304
  }
9305
+ applyLateFocusMaybe();
9269
9306
  };
9270
9307
  const replaceChildren = (parentId, childIds) => {
9271
9308
  const parentInstance = get$a(parentId);
@@ -9278,11 +9315,32 @@ const replaceChildren = (parentId, childIds) => {
9278
9315
  }
9279
9316
  $Parent.replaceChildren($Fragment);
9280
9317
  };
9318
+ const applyLateFocusMaybe = () => {
9319
+ if (focusCallback !== emptyFocusCallback) {
9320
+ const {
9321
+ id,
9322
+ selector
9323
+ } = focusCallback;
9324
+ focusCallback = emptyFocusCallback;
9325
+ const instance = get$a(id);
9326
+ if (instance) {
9327
+ const {
9328
+ $Viewlet
9329
+ } = instance.state;
9330
+ const $Element = $Viewlet.querySelector(selector);
9331
+ if ($Element) {
9332
+ $Element.focus();
9333
+ focusCallback = emptyFocusCallback;
9334
+ }
9335
+ }
9336
+ }
9337
+ };
9281
9338
  const appendToBody = childId => {
9282
9339
  const $Parent = document.body;
9283
9340
  const childInstance = get$a(childId);
9284
9341
  const $Child = childInstance.state.$Viewlet;
9285
9342
  $Parent.append($Child);
9343
+ applyLateFocusMaybe();
9286
9344
  };
9287
9345
  const executeCommands = commands => {
9288
9346
  for (const [command, ...args] of commands) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/renderer-process",
3
- "version": "26.0.0",
3
+ "version": "26.1.0",
4
4
  "keywords": [
5
5
  "lvce-editor",
6
6
  "renderer-process"