@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 +5 -1
- package/dist/index.js +150 -129
- package/package.json +1 -1
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
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
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
|
-
|
|
299
|
-
|
|
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
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
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;
|