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