@lvce-editor/virtual-dom 6.1.0 → 6.3.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 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[], eventMap?: Record<string, any>) => void;
48
+ export declare const applyPatch: ($Element: Node, patches: readonly Patch[], eventMap?: Record<string, any>, id?: 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)) {
@@ -767,41 +735,6 @@ const NavigateParent = 8;
767
735
  const RemoveChild = 9;
768
736
  const NavigateSibling = 10;
769
737
 
770
- const applyPatch = ($Element, patches, eventMap = {}) => {
771
- let $Current = $Element;
772
- for (const patch of patches) {
773
- switch (patch.type) {
774
- case Add:
775
- add$1($Current, patch.nodes, eventMap);
776
- break;
777
- case NavigateChild:
778
- $Current = $Current.childNodes[patch.index];
779
- break;
780
- case NavigateParent:
781
- $Current = $Current.parentNode;
782
- break;
783
- case NavigateSibling:
784
- $Current = $Current.parentNode.childNodes[patch.index];
785
- break;
786
- case RemoveAttribute:
787
- removeAttribute($Current, patch.key);
788
- break;
789
- case RemoveChild:
790
- removeChild($Current, patch.index);
791
- break;
792
- case Replace:
793
- $Current = replace($Current, patch.nodes, eventMap);
794
- break;
795
- case SetAttribute:
796
- setAttribute($Current, patch.key, patch.value);
797
- break;
798
- case SetText:
799
- setText($Current, patch.value);
800
- break;
801
- }
802
- }
803
- };
804
-
805
738
  const dragInfos = Object.create(null);
806
739
  const setDragInfo = (id, data) => {
807
740
  dragInfos[id] = data;
@@ -816,32 +749,6 @@ const isDragInfoOld = data => {
816
749
  return Array.isArray(data);
817
750
  };
818
751
 
819
- let id = 0;
820
- const create = () => {
821
- return ++id;
822
- };
823
-
824
- const state = Object.create(null);
825
- const acquire = id => {
826
- const promise = state[id];
827
- delete state[id];
828
- return promise;
829
- };
830
- const getFileHandles = async ids => {
831
- const promises = ids.map(acquire);
832
- const handles = await Promise.all(promises);
833
- return handles;
834
- };
835
- const add = promise => {
836
- const id = create();
837
- state[id] = promise;
838
- return id;
839
- };
840
- const addFileHandle = fileHandle => {
841
- const promise = Promise.resolve(fileHandle);
842
- return add(promise);
843
- };
844
-
845
752
  const setDragImage = (dataTransfer, label) => {
846
753
  const dragImage = document.createElement('div');
847
754
  dragImage.className = 'DragImage';
@@ -894,6 +801,32 @@ const enabled = () => {
894
801
  return ignore;
895
802
  };
896
803
 
804
+ let id = 0;
805
+ const create = () => {
806
+ return ++id;
807
+ };
808
+
809
+ const state = Object.create(null);
810
+ const acquire = id => {
811
+ const promise = state[id];
812
+ delete state[id];
813
+ return promise;
814
+ };
815
+ const getFileHandles = async ids => {
816
+ const promises = ids.map(acquire);
817
+ const handles = await Promise.all(promises);
818
+ return handles;
819
+ };
820
+ const add = promise => {
821
+ const id = create();
822
+ state[id] = promise;
823
+ return id;
824
+ };
825
+ const addFileHandle = fileHandle => {
826
+ const promise = Promise.resolve(fileHandle);
827
+ return add(promise);
828
+ };
829
+
897
830
  const unwrapItemString = async item => {
898
831
  const {
899
832
  resolve,
@@ -1088,6 +1021,42 @@ const getEventListenerMap = id => {
1088
1021
  return map;
1089
1022
  };
1090
1023
 
1024
+ const applyPatch = ($Element, patches, eventMap = {}, id = 0) => {
1025
+ const events = getEventListenerMap(id) || eventMap;
1026
+ let $Current = $Element;
1027
+ for (const patch of patches) {
1028
+ switch (patch.type) {
1029
+ case Add:
1030
+ add$1($Current, patch.nodes, events);
1031
+ break;
1032
+ case NavigateChild:
1033
+ $Current = $Current.childNodes[patch.index];
1034
+ break;
1035
+ case NavigateParent:
1036
+ $Current = $Current.parentNode;
1037
+ break;
1038
+ case NavigateSibling:
1039
+ $Current = $Current.parentNode.childNodes[patch.index];
1040
+ break;
1041
+ case RemoveAttribute:
1042
+ removeAttribute($Current, patch.key);
1043
+ break;
1044
+ case RemoveChild:
1045
+ removeChild($Current, patch.index);
1046
+ break;
1047
+ case Replace:
1048
+ $Current = replace($Current, patch.nodes, events);
1049
+ break;
1050
+ case SetAttribute:
1051
+ setProp($Current, patch.key, patch.value, events);
1052
+ break;
1053
+ case SetText:
1054
+ setText($Current, patch.value);
1055
+ break;
1056
+ }
1057
+ }
1058
+ };
1059
+
1091
1060
  const getActiveElementInside = $Viewlet => {
1092
1061
  if (!$Viewlet) {
1093
1062
  return undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/virtual-dom",
3
- "version": "6.1.0",
3
+ "version": "6.3.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/lvce-editor/virtual-dom.git"