@lvce-editor/virtual-dom 6.0.0 → 6.2.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/index.d.ts +1 -1
- package/dist/index.js +8 -40
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -45,7 +45,7 @@ export interface TextPatch {
|
|
|
45
45
|
readonly value: string;
|
|
46
46
|
}
|
|
47
47
|
export type Patch = TextPatch | AttributePatch | ReplacePatch | RemoveAttributePatch | RemovePatch | AddPatch | NavigateChildPatch | NavigateParentPatch | RemoveChildPatch | NavigateSiblingPatch;
|
|
48
|
-
export declare const applyPatch: ($Element: Node, patches: readonly Patch[]) => void;
|
|
48
|
+
export declare const applyPatch: ($Element: Node, patches: readonly Patch[], eventMap?: Record<string, any>) => void;
|
|
49
49
|
export declare const setComponentUid: ($Element: any, uid: any) => void;
|
|
50
50
|
export declare const getComponentUid: ($Element: any) => number;
|
|
51
51
|
export declare const getComponentUidFromEvent: (event: any) => number;
|
package/dist/index.js
CHANGED
|
@@ -695,38 +695,6 @@ const propertyToAttribute = {
|
|
|
695
695
|
|
|
696
696
|
// Style properties that need to be set on element.style
|
|
697
697
|
const styleProperties = new Set(['width', 'height', 'top', 'left', 'marginTop', 'paddingLeft', 'paddingRight']);
|
|
698
|
-
|
|
699
|
-
// TODO merge this with the setProp function
|
|
700
|
-
|
|
701
|
-
const setAttribute = ($Element, key, value) => {
|
|
702
|
-
// Handle width/height for images (set as attributes, not style)
|
|
703
|
-
if ((key === 'width' || key === 'height') && $Element instanceof HTMLImageElement) {
|
|
704
|
-
// @ts-ignore - dynamic property access
|
|
705
|
-
$Element[key] = value;
|
|
706
|
-
return;
|
|
707
|
-
}
|
|
708
|
-
|
|
709
|
-
// Handle style properties
|
|
710
|
-
if (styleProperties.has(key)) {
|
|
711
|
-
// @ts-ignore - dynamic style property access
|
|
712
|
-
$Element.style[key] = typeof value === 'number' ? `${value}px` : value;
|
|
713
|
-
return;
|
|
714
|
-
}
|
|
715
|
-
|
|
716
|
-
// Handle aria attributes - map camelCase to hyphenated form
|
|
717
|
-
if (key in propertyToAttribute) {
|
|
718
|
-
$Element.setAttribute(propertyToAttribute[key], value);
|
|
719
|
-
return;
|
|
720
|
-
}
|
|
721
|
-
|
|
722
|
-
// Use property assignment for known DOM properties, attribute for others
|
|
723
|
-
if (key in $Element) {
|
|
724
|
-
// @ts-ignore - dynamic property access
|
|
725
|
-
$Element[key] = value;
|
|
726
|
-
} else {
|
|
727
|
-
$Element.setAttribute(key, value);
|
|
728
|
-
}
|
|
729
|
-
};
|
|
730
698
|
const removeAttribute = ($Element, key) => {
|
|
731
699
|
// Handle style properties
|
|
732
700
|
if (styleProperties.has(key)) {
|
|
@@ -744,13 +712,13 @@ const removeChild = ($Element, index) => {
|
|
|
744
712
|
const $Child = $Element.children[index];
|
|
745
713
|
$Child.remove();
|
|
746
714
|
};
|
|
747
|
-
const add$1 = ($Element, nodes) => {
|
|
748
|
-
renderInternal($Element, nodes,
|
|
715
|
+
const add$1 = ($Element, nodes, eventMap = {}) => {
|
|
716
|
+
renderInternal($Element, nodes, eventMap, eventMap);
|
|
749
717
|
};
|
|
750
|
-
const replace = ($Element, nodes) => {
|
|
718
|
+
const replace = ($Element, nodes, eventMap = {}) => {
|
|
751
719
|
// Create a temporary container to render the new nodes
|
|
752
720
|
const $Temp = document.createElement('div');
|
|
753
|
-
renderInternal($Temp, nodes,
|
|
721
|
+
renderInternal($Temp, nodes, eventMap, eventMap);
|
|
754
722
|
// Replace the current element with the new ones
|
|
755
723
|
const $NewElement = $Temp.firstElementChild;
|
|
756
724
|
$Element.replaceWith($NewElement);
|
|
@@ -767,12 +735,12 @@ const NavigateParent = 8;
|
|
|
767
735
|
const RemoveChild = 9;
|
|
768
736
|
const NavigateSibling = 10;
|
|
769
737
|
|
|
770
|
-
const applyPatch = ($Element, patches) => {
|
|
738
|
+
const applyPatch = ($Element, patches, eventMap = {}) => {
|
|
771
739
|
let $Current = $Element;
|
|
772
740
|
for (const patch of patches) {
|
|
773
741
|
switch (patch.type) {
|
|
774
742
|
case Add:
|
|
775
|
-
add$1($Current, patch.nodes);
|
|
743
|
+
add$1($Current, patch.nodes, eventMap);
|
|
776
744
|
break;
|
|
777
745
|
case NavigateChild:
|
|
778
746
|
$Current = $Current.childNodes[patch.index];
|
|
@@ -790,10 +758,10 @@ const applyPatch = ($Element, patches) => {
|
|
|
790
758
|
removeChild($Current, patch.index);
|
|
791
759
|
break;
|
|
792
760
|
case Replace:
|
|
793
|
-
$Current = replace($Current, patch.nodes);
|
|
761
|
+
$Current = replace($Current, patch.nodes, eventMap);
|
|
794
762
|
break;
|
|
795
763
|
case SetAttribute:
|
|
796
|
-
|
|
764
|
+
setProp($Current, patch.key, patch.value, eventMap);
|
|
797
765
|
break;
|
|
798
766
|
case SetText:
|
|
799
767
|
setText($Current, patch.value);
|