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