@lvce-editor/renderer-process 21.3.0 → 21.5.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.
- package/dist/rendererProcessMain.js +87 -32
- package/package.json +1 -1
|
@@ -695,8 +695,10 @@ const setText$3 = ($Element, value) => {
|
|
|
695
695
|
$Element.nodeValue = value;
|
|
696
696
|
};
|
|
697
697
|
const removeChild = ($Element, index) => {
|
|
698
|
-
const $Child = $Element.
|
|
699
|
-
$Child
|
|
698
|
+
const $Child = $Element.childNodes[index];
|
|
699
|
+
if ($Child) {
|
|
700
|
+
$Child.remove();
|
|
701
|
+
}
|
|
700
702
|
};
|
|
701
703
|
const add$1 = ($Element, nodes, eventMap = {}) => {
|
|
702
704
|
renderInternal($Element, nodes, eventMap, eventMap);
|
|
@@ -706,7 +708,15 @@ const replace = ($Element, nodes, eventMap = {}) => {
|
|
|
706
708
|
const $Temp = document.createElement('div');
|
|
707
709
|
renderInternal($Temp, nodes, eventMap, eventMap);
|
|
708
710
|
// Replace the current element with the new ones
|
|
709
|
-
|
|
711
|
+
let $NewElement = $Temp.firstElementChild;
|
|
712
|
+
if (!$NewElement) {
|
|
713
|
+
// If no element was created (e.g., only text nodes), we need to create a wrapper
|
|
714
|
+
// In this case, we create a div and move all children to it
|
|
715
|
+
$NewElement = document.createElement('div');
|
|
716
|
+
while ($Temp.firstChild) {
|
|
717
|
+
$NewElement.append($Temp.firstChild);
|
|
718
|
+
}
|
|
719
|
+
}
|
|
710
720
|
$Element.replaceWith($NewElement);
|
|
711
721
|
return $NewElement;
|
|
712
722
|
};
|
|
@@ -992,35 +1002,80 @@ const getEventListenerMap = id => {
|
|
|
992
1002
|
const applyPatch = ($Element, patches, eventMap = {}, id = 0) => {
|
|
993
1003
|
const events = getEventListenerMap(id) || eventMap;
|
|
994
1004
|
let $Current = $Element;
|
|
995
|
-
for (
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1005
|
+
for (let patchIndex = 0; patchIndex < patches.length; patchIndex++) {
|
|
1006
|
+
const patch = patches[patchIndex];
|
|
1007
|
+
try {
|
|
1008
|
+
switch (patch.type) {
|
|
1009
|
+
case Add:
|
|
1010
|
+
add$1($Current, patch.nodes, events);
|
|
1011
|
+
break;
|
|
1012
|
+
case NavigateChild:
|
|
1013
|
+
{
|
|
1014
|
+
const $Child = $Current.childNodes[patch.index];
|
|
1015
|
+
if (!$Child) {
|
|
1016
|
+
console.error('Cannot navigate to child: child not found at index', {
|
|
1017
|
+
$Current,
|
|
1018
|
+
index: patch.index,
|
|
1019
|
+
childCount: $Current.childNodes.length
|
|
1020
|
+
});
|
|
1021
|
+
return;
|
|
1022
|
+
}
|
|
1023
|
+
$Current = $Child;
|
|
1024
|
+
break;
|
|
1025
|
+
}
|
|
1026
|
+
case NavigateParent:
|
|
1027
|
+
{
|
|
1028
|
+
const $Parent = $Current.parentNode;
|
|
1029
|
+
if (!$Parent) {
|
|
1030
|
+
console.error('Cannot navigate to parent: current node has no parent', {
|
|
1031
|
+
$Current
|
|
1032
|
+
});
|
|
1033
|
+
return;
|
|
1034
|
+
}
|
|
1035
|
+
$Current = $Parent;
|
|
1036
|
+
break;
|
|
1037
|
+
}
|
|
1038
|
+
case NavigateSibling:
|
|
1039
|
+
{
|
|
1040
|
+
const $Parent = $Current.parentNode;
|
|
1041
|
+
if (!$Parent) {
|
|
1042
|
+
console.error('Cannot navigate to sibling: current node has no parent', {
|
|
1043
|
+
patchIndex
|
|
1044
|
+
});
|
|
1045
|
+
return;
|
|
1046
|
+
}
|
|
1047
|
+
$Current = $Parent.childNodes[patch.index];
|
|
1048
|
+
if (!$Current) {
|
|
1049
|
+
console.error('Cannot navigate to sibling: sibling not found at index', {
|
|
1050
|
+
$Parent,
|
|
1051
|
+
index: patch.index,
|
|
1052
|
+
childCount: $Parent.childNodes.length
|
|
1053
|
+
});
|
|
1054
|
+
return;
|
|
1055
|
+
}
|
|
1056
|
+
break;
|
|
1057
|
+
}
|
|
1058
|
+
case RemoveAttribute:
|
|
1059
|
+
removeAttribute($Current, patch.key);
|
|
1060
|
+
break;
|
|
1061
|
+
case RemoveChild:
|
|
1062
|
+
removeChild($Current, patch.index);
|
|
1063
|
+
break;
|
|
1064
|
+
case Replace:
|
|
1065
|
+
$Current = replace($Current, patch.nodes, events);
|
|
1066
|
+
break;
|
|
1067
|
+
case SetAttribute:
|
|
1068
|
+
setProp($Current, patch.key, patch.value, events);
|
|
1069
|
+
break;
|
|
1070
|
+
case SetText:
|
|
1071
|
+
setText$3($Current, patch.value);
|
|
1072
|
+
break;
|
|
1073
|
+
default:
|
|
1074
|
+
break;
|
|
1075
|
+
}
|
|
1076
|
+
} catch (error) {
|
|
1077
|
+
console.error('Error applying patch at index ' + patchIndex, patch, error);
|
|
1078
|
+
throw error;
|
|
1024
1079
|
}
|
|
1025
1080
|
}
|
|
1026
1081
|
};
|