valyrian.js 7.2.10 → 7.2.12
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/dataset/index.d.ts +2 -2
- package/dist/dataset/index.d.ts.map +1 -1
- package/dist/dataset/index.js +21 -21
- package/dist/dataset/index.js.map +2 -2
- package/dist/dataset/index.mjs +22 -22
- package/dist/dataset/index.mjs.map +2 -2
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/index.js +17 -32
- package/dist/hooks/index.js.map +3 -3
- package/dist/hooks/index.mjs +17 -32
- package/dist/hooks/index.mjs.map +3 -3
- package/dist/index.d.ts +49 -53
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +378 -326
- package/dist/index.js.map +3 -3
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/dist/index.mjs +378 -326
- package/dist/index.mjs.map +3 -3
- package/dist/node/index.js +115 -88
- package/dist/node/index.js.map +2 -2
- package/dist/node/index.mjs +115 -88
- package/dist/node/index.mjs.map +2 -2
- package/dist/node/utils/tree-adapter.d.ts +5 -0
- package/dist/node/utils/tree-adapter.d.ts.map +1 -1
- package/dist/proxy-signal/index.js +10 -10
- package/dist/proxy-signal/index.js.map +2 -2
- package/dist/proxy-signal/index.mjs +10 -10
- package/dist/proxy-signal/index.mjs.map +2 -2
- package/dist/request/index.js +16 -16
- package/dist/request/index.js.map +2 -2
- package/dist/request/index.mjs +16 -16
- package/dist/request/index.mjs.map +2 -2
- package/dist/router/index.d.ts.map +1 -1
- package/dist/router/index.js +21 -20
- package/dist/router/index.js.map +2 -2
- package/dist/router/index.mjs +21 -20
- package/dist/router/index.mjs.map +2 -2
- package/dist/signal/index.d.ts +7 -18
- package/dist/signal/index.d.ts.map +1 -1
- package/dist/signal/index.js +29 -48
- package/dist/signal/index.js.map +3 -3
- package/dist/signal/index.mjs +31 -50
- package/dist/signal/index.mjs.map +3 -3
- package/dist/store/index.js +2 -2
- package/dist/store/index.js.map +2 -2
- package/dist/store/index.mjs +2 -2
- package/dist/store/index.mjs.map +2 -2
- package/lib/dataset/index.ts +25 -25
- package/lib/hooks/index.ts +25 -54
- package/lib/index.ts +465 -715
- package/lib/node/index.ts +2 -2
- package/lib/node/utils/icons.ts +5 -5
- package/lib/node/utils/inline.ts +17 -17
- package/lib/node/utils/sw.ts +3 -3
- package/lib/node/utils/tree-adapter.ts +95 -62
- package/lib/proxy-signal/index.ts +10 -10
- package/lib/request/index.ts +16 -16
- package/lib/router/index.ts +21 -20
- package/lib/signal/index.ts +56 -131
- package/lib/store/index.ts +2 -2
- package/package.json +10 -3
- package/lib/index.d.ts +0 -0
- package/lib/interfaces.ts.bak +0 -141
package/dist/index.mjs
CHANGED
|
@@ -1,164 +1,116 @@
|
|
|
1
1
|
// lib/index.ts
|
|
2
|
-
var textTag = "#text";
|
|
3
2
|
var isNodeJs = Boolean(typeof process !== "undefined" && process.versions && process.versions.node);
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
function isComponent(component) {
|
|
13
|
-
return Boolean(
|
|
14
|
-
component && (typeof component === "function" || typeof component === "object" && "view" in component)
|
|
15
|
-
);
|
|
16
|
-
}
|
|
17
|
-
var isVnode = (object) => {
|
|
18
|
-
return object instanceof Vnode;
|
|
3
|
+
var Vnode = class {
|
|
4
|
+
constructor(tag, props, children, dom, isSVG) {
|
|
5
|
+
this.tag = tag;
|
|
6
|
+
this.props = props;
|
|
7
|
+
this.children = children;
|
|
8
|
+
this.dom = dom;
|
|
9
|
+
this.isSVG = isSVG;
|
|
10
|
+
}
|
|
19
11
|
};
|
|
12
|
+
var isComponent = (component) => Boolean(typeof component === "function" || component && typeof component === "object" && "view" in component);
|
|
13
|
+
var isVnode = (object) => object instanceof Vnode;
|
|
20
14
|
var isVnodeComponent = (object) => {
|
|
21
15
|
return isVnode(object) && isComponent(object.tag);
|
|
22
16
|
};
|
|
17
|
+
function v(tagOrComponent, props, ...children) {
|
|
18
|
+
return new Vnode(tagOrComponent, props, children);
|
|
19
|
+
}
|
|
20
|
+
v.fragment = (_, ...children) => children;
|
|
23
21
|
function domToVnode(dom) {
|
|
24
22
|
if (dom.nodeType === 3) {
|
|
25
|
-
|
|
26
|
-
vnode2.dom = dom;
|
|
27
|
-
return vnode2;
|
|
23
|
+
return dom.nodeValue;
|
|
28
24
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
25
|
+
if (dom.nodeType === 1) {
|
|
26
|
+
const tag = dom.nodeName.toLowerCase();
|
|
27
|
+
const props = {};
|
|
28
|
+
const children = [];
|
|
29
|
+
for (let i = 0, l = dom.childNodes.length; i < l; i++) {
|
|
30
|
+
const childDom = dom.childNodes[i];
|
|
31
|
+
if (childDom.nodeType === 3) {
|
|
32
|
+
children.push(childDom.nodeValue);
|
|
33
|
+
} else if (childDom.nodeType === 1) {
|
|
34
|
+
const childVnode = domToVnode(childDom);
|
|
35
|
+
children.push(childVnode);
|
|
36
|
+
}
|
|
34
37
|
}
|
|
38
|
+
const attributes = dom.attributes;
|
|
39
|
+
for (let i = 0, l = attributes.length; i < l; i++) {
|
|
40
|
+
const attr = attributes[i];
|
|
41
|
+
props[attr.nodeName] = attr.nodeValue;
|
|
42
|
+
}
|
|
43
|
+
return new Vnode(tag, props, children, dom, tag === "svg");
|
|
35
44
|
}
|
|
36
|
-
let props = {};
|
|
37
|
-
for (let i = 0, l = dom.attributes.length; i < l; i++) {
|
|
38
|
-
let attr = dom.attributes[i];
|
|
39
|
-
props[attr.nodeName] = attr.nodeValue;
|
|
40
|
-
}
|
|
41
|
-
let vnode = new Vnode(dom.tagName.toLowerCase(), props, children);
|
|
42
|
-
vnode.dom = dom;
|
|
43
|
-
return vnode;
|
|
44
45
|
}
|
|
45
46
|
function trust(htmlString) {
|
|
46
|
-
|
|
47
|
+
const div = document.createElement("div");
|
|
47
48
|
div.innerHTML = htmlString.trim();
|
|
48
|
-
return
|
|
49
|
+
return Array.from(div.childNodes).map(domToVnode);
|
|
49
50
|
}
|
|
50
51
|
var mainComponent = null;
|
|
51
52
|
var mainVnode = null;
|
|
52
53
|
var isMounted = false;
|
|
53
54
|
var current = {
|
|
54
55
|
vnode: null,
|
|
55
|
-
oldVnode: null,
|
|
56
56
|
component: null,
|
|
57
57
|
event: null
|
|
58
58
|
};
|
|
59
|
-
var reservedProps =
|
|
60
|
-
key
|
|
61
|
-
state
|
|
62
|
-
"v-keep"
|
|
63
|
-
|
|
64
|
-
"v-if"
|
|
65
|
-
"v-
|
|
66
|
-
"v-
|
|
67
|
-
"v-
|
|
68
|
-
"v-
|
|
69
|
-
"v-
|
|
70
|
-
"v-
|
|
71
|
-
"v-
|
|
72
|
-
"v-
|
|
73
|
-
|
|
74
|
-
};
|
|
59
|
+
var reservedProps = /* @__PURE__ */ new Set([
|
|
60
|
+
"key",
|
|
61
|
+
"state",
|
|
62
|
+
"v-keep",
|
|
63
|
+
"v-text",
|
|
64
|
+
"v-if",
|
|
65
|
+
"v-for",
|
|
66
|
+
"v-show",
|
|
67
|
+
"v-class",
|
|
68
|
+
"v-html",
|
|
69
|
+
"v-model",
|
|
70
|
+
"v-create",
|
|
71
|
+
"v-update",
|
|
72
|
+
"v-cleanup"
|
|
73
|
+
]);
|
|
75
74
|
var onCleanupSet = /* @__PURE__ */ new Set();
|
|
76
75
|
var onMountSet = /* @__PURE__ */ new Set();
|
|
77
76
|
var onUpdateSet = /* @__PURE__ */ new Set();
|
|
78
77
|
var onUnmountSet = /* @__PURE__ */ new Set();
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
onUpdateSet.add(callback);
|
|
86
|
-
}
|
|
87
|
-
function onCleanup(callback) {
|
|
88
|
-
onCleanupSet.add(callback);
|
|
89
|
-
}
|
|
90
|
-
function onUnmount(callback) {
|
|
91
|
-
if (!isMounted) {
|
|
92
|
-
onUnmountSet.add(callback);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
function callSet(set) {
|
|
96
|
-
for (let callback of set) {
|
|
78
|
+
var onMount = (callback) => !isMounted && onMountSet.add(callback);
|
|
79
|
+
var onUpdate = (callback) => onUpdateSet.add(callback);
|
|
80
|
+
var onCleanup = (callback) => onCleanupSet.add(callback);
|
|
81
|
+
var onUnmount = (callback) => !isMounted && onUnmountSet.add(callback);
|
|
82
|
+
var callSet = (set) => {
|
|
83
|
+
for (const callback of set) {
|
|
97
84
|
callback();
|
|
98
85
|
}
|
|
99
86
|
set.clear();
|
|
100
|
-
}
|
|
101
|
-
var
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
if (!e.defaultPrevented) {
|
|
110
|
-
update();
|
|
87
|
+
};
|
|
88
|
+
var handleVIf = (shouldRender) => {
|
|
89
|
+
return (value, vnode) => {
|
|
90
|
+
const bool = shouldRender !== Boolean(value);
|
|
91
|
+
if (bool) {
|
|
92
|
+
const parentNode = vnode.dom?.parentNode;
|
|
93
|
+
if (parentNode) {
|
|
94
|
+
const newdom = document.createTextNode("");
|
|
95
|
+
parentNode.replaceChild(newdom, vnode.dom);
|
|
111
96
|
}
|
|
112
|
-
return;
|
|
97
|
+
return false;
|
|
113
98
|
}
|
|
114
|
-
|
|
115
|
-
}
|
|
116
|
-
current.event = null;
|
|
117
|
-
}
|
|
118
|
-
var hideDirective = (test) => (bool, vnode, oldnode) => {
|
|
119
|
-
let value = test ? bool : !bool;
|
|
120
|
-
if (value) {
|
|
121
|
-
let newdom = document.createTextNode("");
|
|
122
|
-
if (oldnode && oldnode.dom && oldnode.dom.parentNode) {
|
|
123
|
-
oldnode.dom.parentNode.replaceChild(newdom, oldnode.dom);
|
|
124
|
-
}
|
|
125
|
-
vnode.tag = "#text";
|
|
126
|
-
vnode.children = [];
|
|
127
|
-
vnode.props = {};
|
|
128
|
-
vnode.dom = newdom;
|
|
129
|
-
return false;
|
|
130
|
-
}
|
|
99
|
+
};
|
|
131
100
|
};
|
|
132
101
|
var directives = {
|
|
133
|
-
|
|
134
|
-
"v-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
// The "v-for" directive creates a loop and applies a callback function to each item in the loop
|
|
138
|
-
"v-for": (set, vnode) => {
|
|
139
|
-
let newChildren = [];
|
|
140
|
-
let callback = vnode.children[0];
|
|
141
|
-
for (let i = 0, l = set.length; i < l; i++) {
|
|
142
|
-
newChildren.push(callback(set[i], i));
|
|
143
|
-
}
|
|
144
|
-
vnode.children = newChildren;
|
|
145
|
-
},
|
|
146
|
-
// The "v-show" directive shows or hides an element by setting the "display" style property
|
|
147
|
-
"v-show": (bool, vnode) => {
|
|
102
|
+
"v-if": handleVIf(true),
|
|
103
|
+
"v-unless": handleVIf(false),
|
|
104
|
+
"v-show": (value, vnode) => {
|
|
105
|
+
const bool = Boolean(value);
|
|
148
106
|
vnode.dom.style.display = bool ? "" : "none";
|
|
149
107
|
},
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
for (let name in classes) {
|
|
153
|
-
vnode.dom.classList.toggle(name, classes[name]);
|
|
154
|
-
}
|
|
155
|
-
},
|
|
156
|
-
// The "v-html" directive sets the inner HTML of an element to the given HTML string
|
|
157
|
-
"v-html": (html, vnode) => {
|
|
158
|
-
vnode.children = [trust(html)];
|
|
108
|
+
"v-html": (value, vnode) => {
|
|
109
|
+
vnode.children = [trust(value)];
|
|
159
110
|
},
|
|
160
111
|
// The "v-model" directive binds the value of an input element to a model property
|
|
161
|
-
"v-model": (
|
|
112
|
+
"v-model": (val, vnode) => {
|
|
113
|
+
let [model, property, event] = val;
|
|
162
114
|
let value;
|
|
163
115
|
let handler = (e) => model[property] = e.target.value;
|
|
164
116
|
if (vnode.tag === "input") {
|
|
@@ -167,10 +119,10 @@ var directives = {
|
|
|
167
119
|
case "checkbox": {
|
|
168
120
|
if (Array.isArray(model[property])) {
|
|
169
121
|
handler = (e) => {
|
|
170
|
-
|
|
171
|
-
|
|
122
|
+
const val2 = e.target.value;
|
|
123
|
+
const idx = model[property].indexOf(val2);
|
|
172
124
|
if (idx === -1) {
|
|
173
|
-
model[property].push(
|
|
125
|
+
model[property].push(val2);
|
|
174
126
|
} else {
|
|
175
127
|
model[property].splice(idx, 1);
|
|
176
128
|
}
|
|
@@ -204,29 +156,29 @@ var directives = {
|
|
|
204
156
|
event = event || "onclick";
|
|
205
157
|
if (vnode.props.multiple) {
|
|
206
158
|
handler = (e) => {
|
|
207
|
-
|
|
159
|
+
const val2 = e.target.value;
|
|
208
160
|
if (e.ctrlKey) {
|
|
209
|
-
|
|
161
|
+
const idx = model[property].indexOf(val2);
|
|
210
162
|
if (idx === -1) {
|
|
211
|
-
model[property].push(
|
|
163
|
+
model[property].push(val2);
|
|
212
164
|
} else {
|
|
213
165
|
model[property].splice(idx, 1);
|
|
214
166
|
}
|
|
215
167
|
} else {
|
|
216
168
|
model[property].splice(0, model[property].length);
|
|
217
|
-
model[property].push(
|
|
169
|
+
model[property].push(val2);
|
|
218
170
|
}
|
|
219
171
|
};
|
|
220
172
|
vnode.children.forEach((child) => {
|
|
221
173
|
if (child.tag === "option") {
|
|
222
|
-
|
|
174
|
+
const value2 = "value" in child.props ? child.props.value : child.children.join("").trim();
|
|
223
175
|
child.props.selected = model[property].indexOf(value2) !== -1;
|
|
224
176
|
}
|
|
225
177
|
});
|
|
226
178
|
} else {
|
|
227
179
|
vnode.children.forEach((child) => {
|
|
228
180
|
if (child.tag === "option") {
|
|
229
|
-
|
|
181
|
+
const value2 = "value" in child.props ? child.props.value : child.children.join("").trim();
|
|
230
182
|
child.props.selected = value2 === model[property];
|
|
231
183
|
}
|
|
232
184
|
});
|
|
@@ -235,7 +187,7 @@ var directives = {
|
|
|
235
187
|
event = event || "oninput";
|
|
236
188
|
vnode.children = [model[property]];
|
|
237
189
|
}
|
|
238
|
-
|
|
190
|
+
const prevHandler = vnode.props[event];
|
|
239
191
|
sharedSetAttribute(
|
|
240
192
|
event,
|
|
241
193
|
(e) => {
|
|
@@ -244,266 +196,368 @@ var directives = {
|
|
|
244
196
|
prevHandler(e);
|
|
245
197
|
}
|
|
246
198
|
},
|
|
247
|
-
vnode
|
|
248
|
-
oldVnode
|
|
199
|
+
vnode
|
|
249
200
|
);
|
|
250
201
|
},
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
// eslint-disable-next-line no-unused-vars
|
|
255
|
-
"v-create": (callback, vnode, oldVnode) => {
|
|
256
|
-
if (!oldVnode) {
|
|
257
|
-
let cleanup = callback(vnode);
|
|
202
|
+
"v-create": (callback, vnode, oldProps) => {
|
|
203
|
+
if (!oldProps) {
|
|
204
|
+
const cleanup = callback(vnode);
|
|
258
205
|
if (typeof cleanup === "function") {
|
|
259
206
|
onCleanup(cleanup);
|
|
260
207
|
}
|
|
261
208
|
}
|
|
262
209
|
},
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
"v-update": (callback, vnode, oldVnode) => {
|
|
267
|
-
if (oldVnode) {
|
|
268
|
-
let cleanup = callback(vnode, oldVnode);
|
|
210
|
+
"v-update": (callback, vnode, oldProps) => {
|
|
211
|
+
if (oldProps) {
|
|
212
|
+
const cleanup = callback(vnode, oldProps);
|
|
269
213
|
if (typeof cleanup === "function") {
|
|
270
214
|
onCleanup(cleanup);
|
|
271
215
|
}
|
|
272
216
|
}
|
|
273
217
|
},
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
"v-
|
|
278
|
-
|
|
218
|
+
"v-cleanup": (callback, vnode) => {
|
|
219
|
+
onCleanup(() => callback(vnode));
|
|
220
|
+
},
|
|
221
|
+
"v-class": (value, vnode) => {
|
|
222
|
+
if (typeof value === "string") {
|
|
223
|
+
vnode.dom.className = value;
|
|
224
|
+
} else if (Array.isArray(value)) {
|
|
225
|
+
vnode.dom.className = value.join(" ");
|
|
226
|
+
} else if (typeof value === "object") {
|
|
227
|
+
const classList = vnode.dom.classList;
|
|
228
|
+
for (const name in value) {
|
|
229
|
+
const val = typeof value[name] === "function" ? value[name]() : value[name];
|
|
230
|
+
classList.toggle(name, val);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
},
|
|
234
|
+
// Frequent used properties
|
|
235
|
+
class(value, vnode) {
|
|
236
|
+
if (vnode.dom.className !== value) {
|
|
237
|
+
vnode.dom.className = value;
|
|
238
|
+
}
|
|
239
|
+
},
|
|
240
|
+
className(value, vnode) {
|
|
241
|
+
directives.class(value, vnode, null);
|
|
242
|
+
},
|
|
243
|
+
id: (value, vnode) => {
|
|
244
|
+
vnode.dom.id = value;
|
|
245
|
+
},
|
|
246
|
+
style: (value, vnode) => {
|
|
247
|
+
if (typeof value === "string") {
|
|
248
|
+
vnode.dom.style = value;
|
|
249
|
+
} else if (typeof value === "object") {
|
|
250
|
+
vnode.dom.style = "";
|
|
251
|
+
const domStyle = vnode.dom.style;
|
|
252
|
+
for (const name in value) {
|
|
253
|
+
domStyle[name] = value[name];
|
|
254
|
+
}
|
|
255
|
+
}
|
|
279
256
|
}
|
|
280
257
|
};
|
|
281
258
|
function directive(name, directive2) {
|
|
282
|
-
|
|
259
|
+
const directiveName = `v-${name}`;
|
|
283
260
|
directives[directiveName] = directive2;
|
|
284
|
-
reservedProps
|
|
261
|
+
reservedProps.add(directiveName);
|
|
285
262
|
}
|
|
286
|
-
|
|
263
|
+
var eventListenerNames = /* @__PURE__ */ new Set();
|
|
264
|
+
function eventListener(e) {
|
|
265
|
+
current.event = e;
|
|
266
|
+
let dom = e.target;
|
|
267
|
+
const name = `on${e.type}`;
|
|
268
|
+
while (dom) {
|
|
269
|
+
const oldProps = dom.props;
|
|
270
|
+
if (oldProps && oldProps[name]) {
|
|
271
|
+
oldProps[name](e, dom);
|
|
272
|
+
if (!e.defaultPrevented) {
|
|
273
|
+
update();
|
|
274
|
+
}
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
dom = dom.parentNode;
|
|
278
|
+
}
|
|
279
|
+
current.event = null;
|
|
280
|
+
}
|
|
281
|
+
function sharedSetAttribute(name, value, newVnode) {
|
|
282
|
+
const newVnodeDom = newVnode.dom;
|
|
287
283
|
if (typeof value === "function") {
|
|
288
|
-
if (name
|
|
284
|
+
if (!eventListenerNames.has(name)) {
|
|
289
285
|
mainVnode.dom.addEventListener(name.slice(2), eventListener);
|
|
290
|
-
eventListenerNames
|
|
286
|
+
eventListenerNames.add(name);
|
|
291
287
|
}
|
|
292
|
-
newVnode.dom[`v-${name}`] = value;
|
|
293
288
|
return;
|
|
294
289
|
}
|
|
295
|
-
if (name in
|
|
296
|
-
|
|
297
|
-
newVnode.dom[name] = value;
|
|
298
|
-
}
|
|
290
|
+
if (name in newVnodeDom) {
|
|
291
|
+
newVnodeDom[name] = value;
|
|
299
292
|
return;
|
|
300
293
|
}
|
|
301
|
-
if (
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
newVnode.dom.setAttribute(name, value);
|
|
306
|
-
}
|
|
294
|
+
if (value === false) {
|
|
295
|
+
newVnodeDom.removeAttribute(name);
|
|
296
|
+
} else {
|
|
297
|
+
newVnodeDom.setAttribute(name, value);
|
|
307
298
|
}
|
|
308
299
|
}
|
|
309
|
-
function setAttribute(name, value, newVnode
|
|
310
|
-
if (name
|
|
311
|
-
|
|
300
|
+
function setAttribute(name, value, newVnode) {
|
|
301
|
+
if (!reservedProps.has(name)) {
|
|
302
|
+
newVnode.props[name] = value;
|
|
303
|
+
sharedSetAttribute(name, value, newVnode);
|
|
312
304
|
}
|
|
313
|
-
newVnode.props[name] = value;
|
|
314
|
-
sharedSetAttribute(name, value, newVnode, oldVnode);
|
|
315
305
|
}
|
|
316
|
-
function
|
|
317
|
-
if (
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
306
|
+
function removeAttributes(vnode, oldProps) {
|
|
307
|
+
if (!oldProps) {
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
310
|
+
const vnodeDom = vnode.dom;
|
|
311
|
+
const vnodeProps = vnode.props;
|
|
312
|
+
for (const name in oldProps) {
|
|
313
|
+
if (name in vnodeProps === false && !eventListenerNames.has(name) && !reservedProps.has(name)) {
|
|
314
|
+
if (name in vnodeDom) {
|
|
315
|
+
vnodeDom[name] = null;
|
|
316
|
+
} else {
|
|
317
|
+
vnodeDom.removeAttribute(name);
|
|
325
318
|
}
|
|
326
319
|
}
|
|
327
320
|
}
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
321
|
+
}
|
|
322
|
+
function addProperties(vnode, oldProps) {
|
|
323
|
+
const vnodeProps = vnode.props;
|
|
324
|
+
for (const name in vnodeProps) {
|
|
325
|
+
if (directives[name]) {
|
|
326
|
+
if (directives[name](vnodeProps[name], vnode, oldProps) === false) {
|
|
331
327
|
break;
|
|
332
328
|
}
|
|
333
329
|
continue;
|
|
334
330
|
}
|
|
335
|
-
|
|
331
|
+
if (reservedProps.has(name)) {
|
|
332
|
+
continue;
|
|
333
|
+
}
|
|
334
|
+
sharedSetAttribute(name, vnodeProps[name], vnode);
|
|
336
335
|
}
|
|
337
336
|
}
|
|
338
|
-
function
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
newChild.dom = oldChild.dom;
|
|
362
|
-
if ("v-keep" in newChild.props && newChild.props["v-keep"] === oldChild.props["v-keep"]) {
|
|
363
|
-
newChild.children = oldChild.children;
|
|
364
|
-
shouldPatch = false;
|
|
365
|
-
} else {
|
|
366
|
-
updateAttributes(newChild, oldChild);
|
|
367
|
-
}
|
|
368
|
-
} else {
|
|
369
|
-
newChild.dom = createDomElement(newChild.tag, newChild.isSVG);
|
|
370
|
-
updateAttributes(newChild);
|
|
337
|
+
function updateAttributes(newVnode, oldProps) {
|
|
338
|
+
removeAttributes(newVnode, oldProps);
|
|
339
|
+
addProperties(newVnode, oldProps);
|
|
340
|
+
}
|
|
341
|
+
function createElement(tag, isSVG) {
|
|
342
|
+
return isSVG ? document.createElementNS("http://www.w3.org/2000/svg", tag) : document.createElement(tag);
|
|
343
|
+
}
|
|
344
|
+
function flatTree(newVnode, children) {
|
|
345
|
+
current.vnode = newVnode;
|
|
346
|
+
let i = 0;
|
|
347
|
+
while (i < children.length) {
|
|
348
|
+
const newChild = children[i];
|
|
349
|
+
if (newChild == null) {
|
|
350
|
+
children.splice(i, 1);
|
|
351
|
+
continue;
|
|
352
|
+
}
|
|
353
|
+
if (Array.isArray(newChild)) {
|
|
354
|
+
children.splice(i, 1, ...newChild);
|
|
355
|
+
continue;
|
|
356
|
+
}
|
|
357
|
+
if (newChild instanceof Vnode) {
|
|
358
|
+
if (newChild.props === null) {
|
|
359
|
+
newChild.props = {};
|
|
371
360
|
}
|
|
372
|
-
if (
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
361
|
+
if (typeof newChild.tag !== "string") {
|
|
362
|
+
const component = newChild.tag;
|
|
363
|
+
current.component = newChild.tag;
|
|
364
|
+
children[i] = ("view" in component ? component.view : component).bind(component)(
|
|
365
|
+
newChild.props,
|
|
366
|
+
newChild.children
|
|
367
|
+
);
|
|
368
|
+
continue;
|
|
369
|
+
} else {
|
|
370
|
+
newChild.isSVG = newVnode.isSVG || newChild.tag === "svg";
|
|
376
371
|
}
|
|
377
|
-
shouldPatch && patch(newChild, oldChild);
|
|
378
372
|
}
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
373
|
+
i++;
|
|
374
|
+
}
|
|
375
|
+
return children;
|
|
376
|
+
}
|
|
377
|
+
function handleVFor(newVnode) {
|
|
378
|
+
if ("v-for" in newVnode.props) {
|
|
379
|
+
const set = newVnode.props["v-for"];
|
|
380
|
+
const children = [];
|
|
381
|
+
const callback = newVnode.children[0];
|
|
382
|
+
children.length = set.length;
|
|
383
|
+
for (let i = 0, l = set.length; i < l; i++) {
|
|
384
|
+
children[i] = callback(set[i], i);
|
|
383
385
|
}
|
|
386
|
+
return children;
|
|
387
|
+
}
|
|
388
|
+
return [...newVnode.children];
|
|
389
|
+
}
|
|
390
|
+
function createNewElement(newChild, newVnode, oldChild) {
|
|
391
|
+
const dom = createElement(newChild.tag, newChild.isSVG);
|
|
392
|
+
if (oldChild) {
|
|
393
|
+
newVnode.dom.replaceChild(dom, oldChild);
|
|
394
|
+
} else {
|
|
395
|
+
newVnode.dom.appendChild(dom);
|
|
396
|
+
}
|
|
397
|
+
newChild.dom = dom;
|
|
398
|
+
addProperties(newChild, null);
|
|
399
|
+
newChild.dom.props = newChild.props;
|
|
400
|
+
if ("v-text" in newChild.props) {
|
|
401
|
+
newChild.dom.textContent = newChild.props["v-text"];
|
|
384
402
|
return;
|
|
385
403
|
}
|
|
386
|
-
|
|
387
|
-
|
|
404
|
+
const children = flatTree(newChild, handleVFor(newChild));
|
|
405
|
+
if (children.length === 0) {
|
|
406
|
+
newChild.dom.textContent = "";
|
|
388
407
|
return;
|
|
389
408
|
}
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
let newChild = newTree[i];
|
|
394
|
-
if (newChild instanceof Vnode) {
|
|
395
|
-
if (typeof newChild.tag !== "string") {
|
|
396
|
-
current.component = newChild.tag;
|
|
397
|
-
newTree.splice(
|
|
398
|
-
i--,
|
|
399
|
-
1,
|
|
400
|
-
("view" in newChild.tag ? newChild.tag.view.bind(newChild.tag) : newChild.tag.bind(newChild.tag))(
|
|
401
|
-
newChild.props,
|
|
402
|
-
...newChild.children
|
|
403
|
-
)
|
|
404
|
-
);
|
|
405
|
-
}
|
|
409
|
+
for (let i = 0, l = children.length; i < l; i++) {
|
|
410
|
+
if (children[i] instanceof Vnode === false) {
|
|
411
|
+
newChild.dom.appendChild(document.createTextNode(children[i]));
|
|
406
412
|
continue;
|
|
407
413
|
}
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
414
|
+
createNewElement(children[i], newChild, null);
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
function patchKeyed(newVnode, children) {
|
|
418
|
+
const oldTree = [...Array.from(newVnode.dom.childNodes)];
|
|
419
|
+
const childNodes = newVnode.dom.childNodes;
|
|
420
|
+
const oldKeyedList = {};
|
|
421
|
+
const newKeyedList = {};
|
|
422
|
+
for (let i = 0, l = oldTree.length; i < l; i++) {
|
|
423
|
+
const oldProps = oldTree[i].props;
|
|
424
|
+
if (oldProps) {
|
|
425
|
+
oldKeyedList[oldProps.key] = i;
|
|
411
426
|
}
|
|
412
|
-
if (
|
|
413
|
-
|
|
427
|
+
if (i < children.length && children[i] instanceof Vnode) {
|
|
428
|
+
newKeyedList[children[i].props.key] = i;
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
for (let i = 0, l = children.length; i < l; i++) {
|
|
432
|
+
const newChild = children[i];
|
|
433
|
+
const oldChild = oldTree[oldKeyedList[newChild.props.key]];
|
|
434
|
+
if (!oldChild) {
|
|
435
|
+
createNewElement(newChild, newVnode, childNodes[i]);
|
|
414
436
|
continue;
|
|
415
437
|
}
|
|
416
|
-
|
|
438
|
+
newChild.dom = oldChild;
|
|
439
|
+
const currentChild = childNodes[i];
|
|
440
|
+
if (!currentChild) {
|
|
441
|
+
newVnode.dom.appendChild(oldChild);
|
|
442
|
+
} else if (currentChild !== oldChild) {
|
|
443
|
+
newVnode.dom.replaceChild(oldChild, currentChild);
|
|
444
|
+
}
|
|
445
|
+
if ("v-keep" in newChild.props === false || oldChild.props["v-keep"] !== newChild.props["v-keep"]) {
|
|
446
|
+
updateAttributes(newChild, oldChild.props);
|
|
447
|
+
oldChild.props = newChild.props;
|
|
448
|
+
if ("v-text" in newChild.props) {
|
|
449
|
+
if (oldChild.textContent != newChild.props["v-text"]) {
|
|
450
|
+
oldChild.textContent = newChild.props["v-text"];
|
|
451
|
+
}
|
|
452
|
+
continue;
|
|
453
|
+
}
|
|
454
|
+
patch(newChild);
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
for (let i = children.length, l = childNodes.length; i < l; i++) {
|
|
458
|
+
childNodes[i]?.remove();
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
function patch(newVnode) {
|
|
462
|
+
const children = flatTree(newVnode, handleVFor(newVnode));
|
|
463
|
+
const dom = newVnode.dom;
|
|
464
|
+
if (children.length === 0) {
|
|
465
|
+
if (dom.childNodes.length) {
|
|
466
|
+
dom.textContent = "";
|
|
467
|
+
}
|
|
468
|
+
return;
|
|
469
|
+
}
|
|
470
|
+
const oldDomChildren = dom.childNodes;
|
|
471
|
+
const oldChildrenLength = oldDomChildren.length;
|
|
472
|
+
if (oldChildrenLength > 0) {
|
|
473
|
+
const firstOldProps = oldDomChildren[0].props;
|
|
474
|
+
const firstVnode = children[0];
|
|
475
|
+
if (firstOldProps && firstVnode instanceof Vnode && "key" in firstVnode.props && "key" in firstOldProps) {
|
|
476
|
+
patchKeyed(newVnode, children);
|
|
477
|
+
return;
|
|
478
|
+
}
|
|
417
479
|
}
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
if (i
|
|
422
|
-
|
|
423
|
-
newVnode.dom.appendChild(newChild.dom);
|
|
480
|
+
const childrenLength = children.length;
|
|
481
|
+
if (oldChildrenLength === 0) {
|
|
482
|
+
for (let i = 0; i < childrenLength; i++) {
|
|
483
|
+
if (children[i] instanceof Vnode === false) {
|
|
484
|
+
dom.appendChild(document.createTextNode(children[i]));
|
|
424
485
|
continue;
|
|
425
486
|
}
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
487
|
+
createNewElement(children[i], newVnode, null);
|
|
488
|
+
}
|
|
489
|
+
return;
|
|
490
|
+
}
|
|
491
|
+
for (let i = 0; i < childrenLength; i++) {
|
|
492
|
+
const oldChild = oldDomChildren[i];
|
|
493
|
+
const newChild = children[i];
|
|
494
|
+
if (!oldChild) {
|
|
495
|
+
createNewElement(newChild, newVnode, null);
|
|
496
|
+
continue;
|
|
497
|
+
}
|
|
498
|
+
if (newChild instanceof Vnode === false) {
|
|
499
|
+
if (oldChild.nodeType !== 3) {
|
|
500
|
+
newVnode.dom.replaceChild(document.createTextNode(newChild), oldChild);
|
|
430
501
|
continue;
|
|
431
502
|
}
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
oldChild2.dom.textContent = newChild.children[0];
|
|
503
|
+
if (oldChild.nodeValue != newChild) {
|
|
504
|
+
oldChild.nodeValue = newChild;
|
|
435
505
|
}
|
|
436
506
|
continue;
|
|
437
507
|
}
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
508
|
+
if ("v-keep" in newChild.props) {
|
|
509
|
+
if (oldChild.props && oldChild.props["v-keep"] === newChild.props["v-keep"]) {
|
|
510
|
+
continue;
|
|
511
|
+
}
|
|
512
|
+
const nextOldChild = oldDomChildren[i + 1];
|
|
513
|
+
if (nextOldChild && nextOldChild.props && nextOldChild.props["v-keep"] === newChild.props["v-keep"]) {
|
|
514
|
+
oldChild.remove();
|
|
515
|
+
continue;
|
|
516
|
+
}
|
|
445
517
|
}
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
newChild.dom = createDomElement(newChild.tag, newChild.isSVG);
|
|
449
|
-
updateAttributes(newChild);
|
|
450
|
-
newVnode.dom.replaceChild(newChild.dom, oldChild.dom);
|
|
451
|
-
patch(newChild);
|
|
518
|
+
if (newChild.tag !== oldChild.nodeName.toLowerCase()) {
|
|
519
|
+
createNewElement(newChild, newVnode, oldChild);
|
|
452
520
|
continue;
|
|
453
521
|
}
|
|
454
|
-
newChild.dom = oldChild
|
|
455
|
-
|
|
456
|
-
|
|
522
|
+
newChild.dom = oldChild;
|
|
523
|
+
updateAttributes(newChild, oldChild.props || null);
|
|
524
|
+
oldChild.props = newChild.props;
|
|
525
|
+
if ("v-text" in newChild.props) {
|
|
526
|
+
if (newChild.dom.textContent != newChild.props["v-text"]) {
|
|
527
|
+
newChild.dom.textContent = newChild.props["v-text"];
|
|
528
|
+
}
|
|
457
529
|
continue;
|
|
458
530
|
}
|
|
459
|
-
|
|
460
|
-
patch(newChild, oldChild);
|
|
531
|
+
patch(newChild);
|
|
461
532
|
}
|
|
462
|
-
for (let i =
|
|
463
|
-
|
|
464
|
-
}
|
|
465
|
-
}
|
|
466
|
-
function update() {
|
|
467
|
-
if (mainVnode) {
|
|
468
|
-
callSet(onCleanupSet);
|
|
469
|
-
let oldMainVnode = mainVnode;
|
|
470
|
-
mainVnode = new Vnode(oldMainVnode.tag, oldMainVnode.props, [mainComponent]);
|
|
471
|
-
mainVnode.dom = oldMainVnode.dom;
|
|
472
|
-
mainVnode.isSVG = oldMainVnode.isSVG;
|
|
473
|
-
patch(mainVnode, oldMainVnode);
|
|
474
|
-
callSet(isMounted ? onUpdateSet : onMountSet);
|
|
475
|
-
isMounted = true;
|
|
476
|
-
current.vnode = null;
|
|
477
|
-
current.oldVnode = null;
|
|
478
|
-
current.component = null;
|
|
479
|
-
if (isNodeJs) {
|
|
480
|
-
return mainVnode.dom.innerHTML;
|
|
481
|
-
}
|
|
533
|
+
for (let i = childrenLength, l = oldDomChildren.length; i < l; i++) {
|
|
534
|
+
oldDomChildren[i]?.remove();
|
|
482
535
|
}
|
|
483
536
|
}
|
|
484
|
-
function updateVnode(vnode
|
|
537
|
+
function updateVnode(vnode) {
|
|
485
538
|
callSet(onCleanupSet);
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
oldVnode.props = { ...vnode.props };
|
|
489
|
-
oldVnode.children = [...vnode.children];
|
|
490
|
-
oldVnode.dom = vnode.dom;
|
|
491
|
-
oldVnode.isSVG = vnode.isSVG;
|
|
539
|
+
vnode.props = vnode.props || {};
|
|
540
|
+
patch(vnode);
|
|
492
541
|
callSet(isMounted ? onUpdateSet : onMountSet);
|
|
493
542
|
isMounted = true;
|
|
494
543
|
current.vnode = null;
|
|
495
|
-
current.oldVnode = null;
|
|
496
544
|
current.component = null;
|
|
497
545
|
if (isNodeJs) {
|
|
498
546
|
return vnode.dom.innerHTML;
|
|
499
547
|
}
|
|
500
548
|
}
|
|
549
|
+
function update() {
|
|
550
|
+
if (mainVnode) {
|
|
551
|
+
mainVnode.children = [mainComponent];
|
|
552
|
+
return updateVnode(mainVnode);
|
|
553
|
+
}
|
|
554
|
+
}
|
|
501
555
|
function unmount() {
|
|
502
556
|
if (mainVnode) {
|
|
503
|
-
mainComponent =
|
|
504
|
-
|
|
557
|
+
mainComponent = v(() => null, {});
|
|
558
|
+
const result = update();
|
|
505
559
|
callSet(onUnmountSet);
|
|
506
|
-
for (
|
|
560
|
+
for (const name in eventListenerNames) {
|
|
507
561
|
mainVnode.dom.removeEventListener(name.slice(2).toLowerCase(), eventListener);
|
|
508
562
|
Reflect.deleteProperty(eventListenerNames, name);
|
|
509
563
|
}
|
|
@@ -511,28 +565,26 @@ function unmount() {
|
|
|
511
565
|
mainVnode = null;
|
|
512
566
|
isMounted = false;
|
|
513
567
|
current.vnode = null;
|
|
514
|
-
current.oldVnode = null;
|
|
515
568
|
current.component = null;
|
|
569
|
+
current.event = null;
|
|
516
570
|
return result;
|
|
517
571
|
}
|
|
518
572
|
}
|
|
519
573
|
function mount(dom, component) {
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
574
|
+
const container = typeof dom === "string" ? isNodeJs ? createElement(dom, dom === "svg") : document.querySelector(dom) : dom;
|
|
575
|
+
if (isComponent(component)) {
|
|
576
|
+
mainComponent = new Vnode(component, {}, []);
|
|
577
|
+
} else if (isVnodeComponent(component)) {
|
|
578
|
+
mainComponent = component;
|
|
579
|
+
} else {
|
|
580
|
+
mainComponent = new Vnode(() => component, {}, []);
|
|
524
581
|
}
|
|
525
|
-
mainComponent = vnodeComponent;
|
|
526
582
|
mainVnode = domToVnode(container);
|
|
527
583
|
return update();
|
|
528
584
|
}
|
|
529
|
-
var v = (tagOrComponent, props = {}, ...children) => {
|
|
530
|
-
return new Vnode(tagOrComponent, props || {}, children);
|
|
531
|
-
};
|
|
532
|
-
v.fragment = (_, ...children) => children;
|
|
533
585
|
export {
|
|
534
586
|
Vnode,
|
|
535
|
-
|
|
587
|
+
createElement,
|
|
536
588
|
current,
|
|
537
589
|
directive,
|
|
538
590
|
directives,
|