@lvce-editor/virtual-dom 6.9.0 → 6.11.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
@@ -40,11 +40,15 @@ export interface ReplacePatch {
40
40
  readonly nodes: readonly VirtualDomNode[];
41
41
  readonly type: 2;
42
42
  }
43
+ export interface SetReferenceNodeUidPatch {
44
+ readonly type: 11;
45
+ readonly uid: string;
46
+ }
43
47
  export interface TextPatch {
44
48
  readonly type: 1;
45
49
  readonly value: string;
46
50
  }
47
- export type Patch = TextPatch | AttributePatch | ReplacePatch | RemoveAttributePatch | RemovePatch | AddPatch | NavigateChildPatch | NavigateParentPatch | RemoveChildPatch | NavigateSiblingPatch;
51
+ export type Patch = TextPatch | AttributePatch | ReplacePatch | RemoveAttributePatch | RemovePatch | AddPatch | NavigateChildPatch | NavigateParentPatch | RemoveChildPatch | NavigateSiblingPatch | SetReferenceNodeUidPatch;
48
52
  export declare const applyPatch: ($Element: Node, patches: readonly Patch[], eventMap?: Record<string, any>, id?: any) => void;
49
53
  export declare const setComponentUid: ($Element: any, uid: any) => void;
50
54
  export declare const getComponentUid: ($Element: any) => number;
package/dist/index.js CHANGED
@@ -1,3 +1,11 @@
1
+ const instances = Object.create(null);
2
+ const get$1 = viewletId => {
3
+ return instances[viewletId];
4
+ };
5
+ const set$1 = (viewletId, instance) => {
6
+ instances[viewletId] = instance;
7
+ };
8
+
1
9
  const Audio$2 = 'audio';
2
10
  const Button$2 = 'button';
3
11
  const Col$2 = 'col';
@@ -115,66 +123,66 @@ const Iframe = 68;
115
123
  const Reference$1 = 100;
116
124
 
117
125
  const VirtualDomElements$1 = {
118
- __proto__: null,
119
- A: A$1,
120
- Abbr: Abbr$1,
121
- Article: Article$1,
122
- Aside: Aside$1,
123
- Audio: Audio$1,
124
- Br: Br$1,
125
- Button: Button$1,
126
- Cite: Cite$1,
127
- Code: Code$1,
128
- Col: Col$1,
129
- ColGroup: ColGroup$1,
130
- Data: Data$1,
131
- Dd: Dd$1,
132
- Del: Del$1,
133
- Div: Div$1,
134
- Dl: Dl$1,
135
- Dt: Dt$1,
136
- Figcaption: Figcaption$1,
137
- Figure: Figure$1,
138
- Footer: Footer$1,
139
- H1: H1$1,
140
- H2: H2$1,
141
- H3: H3$1,
142
- H4: H4$1,
143
- H5: H5$1,
144
- H6: H6$1,
145
- Header: Header$1,
146
- Hr: Hr$1,
147
- I: I$1,
148
- Iframe,
149
- Img: Img$1,
150
- Input: Input$1,
151
- Ins: Ins$1,
152
- Kbd: Kbd$1,
153
- Label: Label$1,
154
- Li: Li$1,
155
- Nav: Nav$1,
156
- Ol: Ol$1,
157
- Option: Option$1,
158
- P: P$1,
159
- Pre: Pre$1,
160
- Reference: Reference$1,
161
- Root: Root$1,
162
- Search: Search$1,
163
- Section: Section$1,
164
- Select: Select$1,
165
- Span: Span$1,
166
- TBody: TBody$1,
167
- THead: THead$1,
168
- Table: Table$1,
169
- Td: Td$1,
170
- Text: Text$1,
171
- TextArea: TextArea$1,
172
- Tfoot: Tfoot$1,
173
- Th: Th$1,
174
- Time: Time$1,
175
- Tr: Tr$1,
176
- Ul: Ul$1,
177
- Video: Video$1
126
+ __proto__: null,
127
+ A: A$1,
128
+ Abbr: Abbr$1,
129
+ Article: Article$1,
130
+ Aside: Aside$1,
131
+ Audio: Audio$1,
132
+ Br: Br$1,
133
+ Button: Button$1,
134
+ Cite: Cite$1,
135
+ Code: Code$1,
136
+ Col: Col$1,
137
+ ColGroup: ColGroup$1,
138
+ Data: Data$1,
139
+ Dd: Dd$1,
140
+ Del: Del$1,
141
+ Div: Div$1,
142
+ Dl: Dl$1,
143
+ Dt: Dt$1,
144
+ Figcaption: Figcaption$1,
145
+ Figure: Figure$1,
146
+ Footer: Footer$1,
147
+ H1: H1$1,
148
+ H2: H2$1,
149
+ H3: H3$1,
150
+ H4: H4$1,
151
+ H5: H5$1,
152
+ H6: H6$1,
153
+ Header: Header$1,
154
+ Hr: Hr$1,
155
+ I: I$1,
156
+ Iframe,
157
+ Img: Img$1,
158
+ Input: Input$1,
159
+ Ins: Ins$1,
160
+ Kbd: Kbd$1,
161
+ Label: Label$1,
162
+ Li: Li$1,
163
+ Nav: Nav$1,
164
+ Ol: Ol$1,
165
+ Option: Option$1,
166
+ P: P$1,
167
+ Pre: Pre$1,
168
+ Reference: Reference$1,
169
+ Root: Root$1,
170
+ Search: Search$1,
171
+ Section: Section$1,
172
+ Select: Select$1,
173
+ Span: Span$1,
174
+ TBody: TBody$1,
175
+ THead: THead$1,
176
+ Table: Table$1,
177
+ Td: Td$1,
178
+ Text: Text$1,
179
+ TextArea: TextArea$1,
180
+ Tfoot: Tfoot$1,
181
+ Th: Th$1,
182
+ Time: Time$1,
183
+ Tr: Tr$1,
184
+ Ul: Ul$1,
185
+ Video: Video$1
178
186
  };
179
187
 
180
188
  const getElementTag$1 = type => {
@@ -295,22 +303,14 @@ const getElementTag$1 = type => {
295
303
  };
296
304
 
297
305
  const ElementTagMap = {
298
- __proto__: null,
299
- getElementTag: getElementTag$1
306
+ __proto__: null,
307
+ getElementTag: getElementTag$1
300
308
  };
301
309
 
302
310
  const {
303
311
  getElementTag
304
312
  } = ElementTagMap;
305
313
 
306
- const instances = Object.create(null);
307
- const get$1 = viewletId => {
308
- return instances[viewletId];
309
- };
310
- const set$1 = (viewletId, instance) => {
311
- instances[viewletId] = instance;
312
- };
313
-
314
314
  const getEventListenerOptions = (eventName, value) => {
315
315
  if (value.passive) {
316
316
  return {
@@ -604,65 +604,65 @@ const {
604
604
  } = VirtualDomElements$1;
605
605
 
606
606
  const VirtualDomElements = {
607
- __proto__: null,
608
- A,
609
- Abbr,
610
- Article,
611
- Aside,
612
- Audio,
613
- Br,
614
- Button,
615
- Cite,
616
- Code,
617
- Col,
618
- ColGroup,
619
- Data,
620
- Dd,
621
- Del,
622
- Div,
623
- Dl,
624
- Dt,
625
- Figcaption,
626
- Figure,
627
- Footer,
628
- H1,
629
- H2,
630
- H3,
631
- H4,
632
- H5,
633
- H6,
634
- Header,
635
- Hr,
636
- I,
637
- Img,
638
- Input,
639
- Ins,
640
- Kbd,
641
- Label,
642
- Li,
643
- Nav,
644
- Ol,
645
- Option,
646
- P,
647
- Pre,
648
- Reference,
649
- Root,
650
- Search,
651
- Section,
652
- Select,
653
- Span,
654
- TBody,
655
- THead,
656
- Table,
657
- Td,
658
- Text,
659
- TextArea,
660
- Tfoot,
661
- Th,
662
- Time,
663
- Tr,
664
- Ul,
665
- Video
607
+ __proto__: null,
608
+ A,
609
+ Abbr,
610
+ Article,
611
+ Aside,
612
+ Audio,
613
+ Br,
614
+ Button,
615
+ Cite,
616
+ Code,
617
+ Col,
618
+ ColGroup,
619
+ Data,
620
+ Dd,
621
+ Del,
622
+ Div,
623
+ Dl,
624
+ Dt,
625
+ Figcaption,
626
+ Figure,
627
+ Footer,
628
+ H1,
629
+ H2,
630
+ H3,
631
+ H4,
632
+ H5,
633
+ H6,
634
+ Header,
635
+ Hr,
636
+ I,
637
+ Img,
638
+ Input,
639
+ Ins,
640
+ Kbd,
641
+ Label,
642
+ Li,
643
+ Nav,
644
+ Ol,
645
+ Option,
646
+ P,
647
+ Pre,
648
+ Reference,
649
+ Root,
650
+ Search,
651
+ Section,
652
+ Select,
653
+ Span,
654
+ TBody,
655
+ THead,
656
+ Table,
657
+ Td,
658
+ Text,
659
+ TextArea,
660
+ Tfoot,
661
+ Th,
662
+ Time,
663
+ Tr,
664
+ Ul,
665
+ Video
666
666
  };
667
667
 
668
668
  const renderDomTextNode = element => {
@@ -676,6 +676,9 @@ const renderDomElement = (element, eventMap, newEventMap) => {
676
676
  };
677
677
  const renderReferenceNode = element => {
678
678
  const instance = get$1(element.uid);
679
+ if (!instance || !instance.state) {
680
+ return document.createTextNode('Reference node not found');
681
+ }
679
682
  const $Node = instance.state.$Viewlet;
680
683
  return $Node;
681
684
  };
@@ -765,6 +768,7 @@ const NavigateChild = 7;
765
768
  const NavigateParent = 8;
766
769
  const RemoveChild = 9;
767
770
  const NavigateSibling = 10;
771
+ const SetReferenceNodeUid = 11;
768
772
 
769
773
  const dragInfos = Object.create(null);
770
774
  const setDragInfo = (id, data) => {
@@ -1120,6 +1124,23 @@ const applyPatch = ($Element, patches, eventMap = {}, id = 0) => {
1120
1124
  case SetAttribute:
1121
1125
  setProp($Current, patch.key, patch.value, events);
1122
1126
  break;
1127
+ case SetReferenceNodeUid:
1128
+ {
1129
+ // Get the new reference node instance
1130
+ const instance = get$1(patch.uid);
1131
+ if (!instance || !instance.state) {
1132
+ console.error('Cannot set reference node uid: instance not found', {
1133
+ uid: patch.uid
1134
+ });
1135
+ return;
1136
+ }
1137
+ const $NewNode = instance.state.$Viewlet;
1138
+ // Replace the current reference node with the new viewlet
1139
+ // @ts-ignore
1140
+ $Current.replaceWith($NewNode);
1141
+ $Current = $NewNode;
1142
+ break;
1143
+ }
1123
1144
  case SetText:
1124
1145
  setText($Current, patch.value);
1125
1146
  break;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/virtual-dom",
3
- "version": "6.9.0",
3
+ "version": "6.11.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/lvce-editor/virtual-dom.git"