@lvce-editor/renderer-process 21.2.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 +114 -92
- package/package.json +1 -1
|
@@ -681,38 +681,6 @@ const propertyToAttribute = {
|
|
|
681
681
|
|
|
682
682
|
// Style properties that need to be set on element.style
|
|
683
683
|
const styleProperties = new Set(['width', 'height', 'top', 'left', 'marginTop', 'paddingLeft', 'paddingRight']);
|
|
684
|
-
|
|
685
|
-
// TODO merge this with the setProp function
|
|
686
|
-
|
|
687
|
-
const setAttribute = ($Element, key, value) => {
|
|
688
|
-
// Handle width/height for images (set as attributes, not style)
|
|
689
|
-
if ((key === 'width' || key === 'height') && $Element instanceof HTMLImageElement) {
|
|
690
|
-
// @ts-ignore - dynamic property access
|
|
691
|
-
$Element[key] = value;
|
|
692
|
-
return;
|
|
693
|
-
}
|
|
694
|
-
|
|
695
|
-
// Handle style properties
|
|
696
|
-
if (styleProperties.has(key)) {
|
|
697
|
-
// @ts-ignore - dynamic style property access
|
|
698
|
-
$Element.style[key] = typeof value === 'number' ? `${value}px` : value;
|
|
699
|
-
return;
|
|
700
|
-
}
|
|
701
|
-
|
|
702
|
-
// Handle aria attributes - map camelCase to hyphenated form
|
|
703
|
-
if (key in propertyToAttribute) {
|
|
704
|
-
$Element.setAttribute(propertyToAttribute[key], value);
|
|
705
|
-
return;
|
|
706
|
-
}
|
|
707
|
-
|
|
708
|
-
// Use property assignment for known DOM properties, attribute for others
|
|
709
|
-
if (key in $Element) {
|
|
710
|
-
// @ts-ignore - dynamic property access
|
|
711
|
-
$Element[key] = value;
|
|
712
|
-
} else {
|
|
713
|
-
$Element.setAttribute(key, value);
|
|
714
|
-
}
|
|
715
|
-
};
|
|
716
684
|
const removeAttribute = ($Element, key) => {
|
|
717
685
|
// Handle style properties
|
|
718
686
|
if (styleProperties.has(key)) {
|
|
@@ -738,7 +706,15 @@ const replace = ($Element, nodes, eventMap = {}) => {
|
|
|
738
706
|
const $Temp = document.createElement('div');
|
|
739
707
|
renderInternal($Temp, nodes, eventMap, eventMap);
|
|
740
708
|
// Replace the current element with the new ones
|
|
741
|
-
|
|
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
|
+
}
|
|
742
718
|
$Element.replaceWith($NewElement);
|
|
743
719
|
return $NewElement;
|
|
744
720
|
};
|
|
@@ -751,40 +727,6 @@ const NavigateChild = 7;
|
|
|
751
727
|
const NavigateParent = 8;
|
|
752
728
|
const RemoveChild = 9;
|
|
753
729
|
const NavigateSibling = 10;
|
|
754
|
-
const applyPatch = ($Element, patches, eventMap = {}) => {
|
|
755
|
-
let $Current = $Element;
|
|
756
|
-
for (const patch of patches) {
|
|
757
|
-
switch (patch.type) {
|
|
758
|
-
case Add:
|
|
759
|
-
add$1($Current, patch.nodes, eventMap);
|
|
760
|
-
break;
|
|
761
|
-
case NavigateChild:
|
|
762
|
-
$Current = $Current.childNodes[patch.index];
|
|
763
|
-
break;
|
|
764
|
-
case NavigateParent:
|
|
765
|
-
$Current = $Current.parentNode;
|
|
766
|
-
break;
|
|
767
|
-
case NavigateSibling:
|
|
768
|
-
$Current = $Current.parentNode.childNodes[patch.index];
|
|
769
|
-
break;
|
|
770
|
-
case RemoveAttribute:
|
|
771
|
-
removeAttribute($Current, patch.key);
|
|
772
|
-
break;
|
|
773
|
-
case RemoveChild:
|
|
774
|
-
removeChild($Current, patch.index);
|
|
775
|
-
break;
|
|
776
|
-
case Replace:
|
|
777
|
-
$Current = replace($Current, patch.nodes, eventMap);
|
|
778
|
-
break;
|
|
779
|
-
case SetAttribute:
|
|
780
|
-
setAttribute($Current, patch.key, patch.value);
|
|
781
|
-
break;
|
|
782
|
-
case SetText:
|
|
783
|
-
setText$3($Current, patch.value);
|
|
784
|
-
break;
|
|
785
|
-
}
|
|
786
|
-
}
|
|
787
|
-
};
|
|
788
730
|
const dragInfos = Object.create(null);
|
|
789
731
|
const setDragInfo = (id, data) => {
|
|
790
732
|
dragInfos[id] = data;
|
|
@@ -795,30 +737,6 @@ const getDragInfo = id => {
|
|
|
795
737
|
const isDragInfoOld = data => {
|
|
796
738
|
return Array.isArray(data);
|
|
797
739
|
};
|
|
798
|
-
let id$1 = 0;
|
|
799
|
-
const create$G = () => {
|
|
800
|
-
return ++id$1;
|
|
801
|
-
};
|
|
802
|
-
const state$8 = Object.create(null);
|
|
803
|
-
const acquire$1 = id => {
|
|
804
|
-
const promise = state$8[id];
|
|
805
|
-
delete state$8[id];
|
|
806
|
-
return promise;
|
|
807
|
-
};
|
|
808
|
-
const getFileHandles$1 = async ids => {
|
|
809
|
-
const promises = ids.map(acquire$1);
|
|
810
|
-
const handles = await Promise.all(promises);
|
|
811
|
-
return handles;
|
|
812
|
-
};
|
|
813
|
-
const add = promise => {
|
|
814
|
-
const id = create$G();
|
|
815
|
-
state$8[id] = promise;
|
|
816
|
-
return id;
|
|
817
|
-
};
|
|
818
|
-
const addFileHandle$1 = fileHandle => {
|
|
819
|
-
const promise = Promise.resolve(fileHandle);
|
|
820
|
-
return add(promise);
|
|
821
|
-
};
|
|
822
740
|
const setDragImage = (dataTransfer, label) => {
|
|
823
741
|
const dragImage = document.createElement('div');
|
|
824
742
|
dragImage.className = 'DragImage';
|
|
@@ -867,6 +785,30 @@ const stopIgnore = () => {
|
|
|
867
785
|
const enabled = () => {
|
|
868
786
|
return ignore;
|
|
869
787
|
};
|
|
788
|
+
let id$1 = 0;
|
|
789
|
+
const create$G = () => {
|
|
790
|
+
return ++id$1;
|
|
791
|
+
};
|
|
792
|
+
const state$8 = Object.create(null);
|
|
793
|
+
const acquire$1 = id => {
|
|
794
|
+
const promise = state$8[id];
|
|
795
|
+
delete state$8[id];
|
|
796
|
+
return promise;
|
|
797
|
+
};
|
|
798
|
+
const getFileHandles$1 = async ids => {
|
|
799
|
+
const promises = ids.map(acquire$1);
|
|
800
|
+
const handles = await Promise.all(promises);
|
|
801
|
+
return handles;
|
|
802
|
+
};
|
|
803
|
+
const add = promise => {
|
|
804
|
+
const id = create$G();
|
|
805
|
+
state$8[id] = promise;
|
|
806
|
+
return id;
|
|
807
|
+
};
|
|
808
|
+
const addFileHandle$1 = fileHandle => {
|
|
809
|
+
const promise = Promise.resolve(fileHandle);
|
|
810
|
+
return add(promise);
|
|
811
|
+
};
|
|
870
812
|
const unwrapItemString = async item => {
|
|
871
813
|
const {
|
|
872
814
|
resolve,
|
|
@@ -1055,6 +997,86 @@ const getEventListenerMap = id => {
|
|
|
1055
997
|
const map = listeners[id];
|
|
1056
998
|
return map;
|
|
1057
999
|
};
|
|
1000
|
+
const applyPatch = ($Element, patches, eventMap = {}, id = 0) => {
|
|
1001
|
+
const events = getEventListenerMap(id) || eventMap;
|
|
1002
|
+
let $Current = $Element;
|
|
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;
|
|
1077
|
+
}
|
|
1078
|
+
}
|
|
1079
|
+
};
|
|
1058
1080
|
const getActiveElementInside = $Viewlet => {
|
|
1059
1081
|
if (!$Viewlet) {
|
|
1060
1082
|
return undefined;
|
|
@@ -9158,7 +9180,7 @@ const setPatches = (uid, patches) => {
|
|
|
9158
9180
|
setDom2(uid, patches[0].nodes);
|
|
9159
9181
|
return;
|
|
9160
9182
|
}
|
|
9161
|
-
applyPatch($Viewlet, patches);
|
|
9183
|
+
applyPatch($Viewlet, patches, {}, uid);
|
|
9162
9184
|
};
|
|
9163
9185
|
|
|
9164
9186
|
// TODO this code is bad
|