@lvce-editor/virtual-dom 6.4.0 → 6.6.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.
Files changed (2) hide show
  1. package/dist/index.js +12 -13
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -709,8 +709,10 @@ const setText = ($Element, value) => {
709
709
  $Element.nodeValue = value;
710
710
  };
711
711
  const removeChild = ($Element, index) => {
712
- const $Child = $Element.children[index];
713
- $Child.remove();
712
+ const $Child = $Element.childNodes[index];
713
+ if ($Child) {
714
+ $Child.remove();
715
+ }
714
716
  };
715
717
  const add$1 = ($Element, nodes, eventMap = {}) => {
716
718
  renderInternal($Element, nodes, eventMap, eventMap);
@@ -719,18 +721,15 @@ const replace = ($Element, nodes, eventMap = {}) => {
719
721
  // Create a temporary container to render the new nodes
720
722
  const $Temp = document.createElement('div');
721
723
  renderInternal($Temp, nodes, eventMap, eventMap);
722
- // Replace the current element with the new ones
723
- let $NewElement = $Temp.firstElementChild;
724
- if (!$NewElement) {
725
- // If no element was created (e.g., only text nodes), we need to create a wrapper
726
- // In this case, we create a div and move all children to it
727
- $NewElement = document.createElement('div');
728
- while ($Temp.firstChild) {
729
- $NewElement.append($Temp.firstChild);
730
- }
724
+ // Replace the current element with the new node(s)
725
+ const $NewNode = $Temp.firstChild;
726
+ if (!$NewNode) {
727
+ // No node was created, just remove the old element
728
+ $Element.remove();
729
+ return $Element;
731
730
  }
732
- $Element.replaceWith($NewElement);
733
- return $NewElement;
731
+ $Element.replaceWith($NewNode);
732
+ return $NewNode;
734
733
  };
735
734
 
736
735
  const SetText = 1;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/virtual-dom",
3
- "version": "6.4.0",
3
+ "version": "6.6.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/lvce-editor/virtual-dom.git"