veles 0.0.7 → 0.0.8
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/README.md +24 -247
- package/dist/{chunk-ILNLS6QO.js → chunk-4QXZSBVZ.js} +124 -121
- package/dist/chunk-GVPFIZZW.js +928 -0
- package/dist/index-BA0L7WRK.d.ts +60 -0
- package/dist/index-BOpDMzdf.d.cts +60 -0
- package/dist/index.cjs +969 -535
- package/dist/index.d.cts +14 -5
- package/dist/index.d.ts +14 -5
- package/dist/index.js +14 -10
- package/dist/jsx-runtime.cjs +91 -122
- package/dist/jsx-runtime.d.cts +7 -3252
- package/dist/jsx-runtime.d.ts +7 -3252
- package/dist/jsx-runtime.js +2 -4
- package/dist/types.d-CjiJHqth.d.cts +3954 -0
- package/dist/types.d-CjiJHqth.d.ts +3954 -0
- package/dist/utils/index.cjs +901 -501
- package/dist/utils/index.d.cts +2 -2
- package/dist/utils/index.d.ts +2 -2
- package/dist/utils/index.js +2 -2
- package/package.json +1 -1
- package/dist/chunk-MH6DPZ3V.js +0 -490
- package/dist/chunk-X6QYYW56.js +0 -15
- package/dist/create-state-Bo6TT4qP.d.ts +0 -33
- package/dist/create-state-D1JASFVs.d.cts +0 -33
- package/dist/fragment-CU26z590.d.cts +0 -9
- package/dist/fragment-IVSEC7-Q.d.ts +0 -9
- package/dist/types.d-DgVBp6oa.d.cts +0 -256
- package/dist/types.d-DgVBp6oa.d.ts +0 -256
package/dist/utils/index.cjs
CHANGED
|
@@ -26,58 +26,6 @@ __export(utils_exports, {
|
|
|
26
26
|
});
|
|
27
27
|
module.exports = __toCommonJS(utils_exports);
|
|
28
28
|
|
|
29
|
-
// src/_utils.ts
|
|
30
|
-
function getComponentVelesNode(component) {
|
|
31
|
-
const componentsTree = [];
|
|
32
|
-
if ("velesStringElement" in component) {
|
|
33
|
-
return {
|
|
34
|
-
velesElementNode: component,
|
|
35
|
-
componentsTree: []
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
let childNode = component;
|
|
39
|
-
while ("velesComponent" in childNode) {
|
|
40
|
-
componentsTree.push(childNode);
|
|
41
|
-
if ("velesStringElement" in childNode.tree) {
|
|
42
|
-
return {
|
|
43
|
-
velesElementNode: childNode.tree,
|
|
44
|
-
componentsTree
|
|
45
|
-
};
|
|
46
|
-
} else {
|
|
47
|
-
childNode = childNode.tree;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
return { velesElementNode: childNode, componentsTree };
|
|
51
|
-
}
|
|
52
|
-
function callMountHandlers(component) {
|
|
53
|
-
if ("velesStringElement" in component) {
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
if ("velesComponent" in component) {
|
|
57
|
-
component._privateMethods._callMountHandlers();
|
|
58
|
-
callMountHandlers(component.tree);
|
|
59
|
-
}
|
|
60
|
-
if ("velesNode" in component) {
|
|
61
|
-
component.childComponents.forEach(
|
|
62
|
-
(childComponent) => callMountHandlers(childComponent)
|
|
63
|
-
);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
function identity(value1, value2) {
|
|
67
|
-
return value1 === value2;
|
|
68
|
-
}
|
|
69
|
-
function unique(arr) {
|
|
70
|
-
const map = /* @__PURE__ */ new Map();
|
|
71
|
-
const resultArr = [];
|
|
72
|
-
arr.forEach((element) => {
|
|
73
|
-
if (map.has(element))
|
|
74
|
-
return;
|
|
75
|
-
map.set(element, true);
|
|
76
|
-
resultArr.push(element);
|
|
77
|
-
});
|
|
78
|
-
return resultArr;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
29
|
// src/hooks/lifecycle.ts
|
|
82
30
|
var contextStack = [];
|
|
83
31
|
var currentContext = null;
|
|
@@ -104,6 +52,103 @@ function onUnmount(cb) {
|
|
|
104
52
|
}
|
|
105
53
|
}
|
|
106
54
|
|
|
55
|
+
// src/create-element/create-text-element.ts
|
|
56
|
+
function createTextElement(text) {
|
|
57
|
+
const mountHandlers = [];
|
|
58
|
+
const unmountHandlers = [];
|
|
59
|
+
return {
|
|
60
|
+
velesStringElement: true,
|
|
61
|
+
// in case there is no text, we create an empty Text node, so we still can
|
|
62
|
+
// have a reference to it, replace it, call lifecycle methods, etc
|
|
63
|
+
html: document.createTextNode(text || ""),
|
|
64
|
+
_privateMethods: {
|
|
65
|
+
_addMountHandler(cb) {
|
|
66
|
+
mountHandlers.push(cb);
|
|
67
|
+
},
|
|
68
|
+
_callMountHandlers() {
|
|
69
|
+
mountHandlers.forEach((cb) => cb());
|
|
70
|
+
},
|
|
71
|
+
_addUnmountHandler: (cb) => {
|
|
72
|
+
unmountHandlers.push(cb);
|
|
73
|
+
},
|
|
74
|
+
_callUnmountHandlers: () => {
|
|
75
|
+
unmountHandlers.forEach((cb) => cb());
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// src/create-element/parse-component.ts
|
|
82
|
+
function parseComponent({
|
|
83
|
+
element,
|
|
84
|
+
props
|
|
85
|
+
}) {
|
|
86
|
+
const mountCbs = [];
|
|
87
|
+
const unmountCbs = [];
|
|
88
|
+
return {
|
|
89
|
+
velesComponentObject: true,
|
|
90
|
+
element,
|
|
91
|
+
props,
|
|
92
|
+
_privateMethods: {
|
|
93
|
+
_addMountHandler(cb) {
|
|
94
|
+
mountCbs.push(cb);
|
|
95
|
+
},
|
|
96
|
+
_addUnmountHandler: (cb) => {
|
|
97
|
+
unmountCbs.push(cb);
|
|
98
|
+
},
|
|
99
|
+
_callMountHandlers: () => {
|
|
100
|
+
mountCbs.forEach((cb) => cb());
|
|
101
|
+
},
|
|
102
|
+
_callUnmountHandlers: () => {
|
|
103
|
+
unmountCbs.forEach((cb) => cb());
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
function executeComponent({
|
|
109
|
+
element,
|
|
110
|
+
props
|
|
111
|
+
}) {
|
|
112
|
+
let componentUnmountCbs = [];
|
|
113
|
+
let componentMountCbs = [];
|
|
114
|
+
const componentAPI = {
|
|
115
|
+
onMount: (cb) => {
|
|
116
|
+
componentMountCbs.push(cb);
|
|
117
|
+
},
|
|
118
|
+
onUnmount: (cb) => {
|
|
119
|
+
componentUnmountCbs.push(cb);
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
addContext(componentAPI);
|
|
123
|
+
const _componentTree = element(props, componentAPI);
|
|
124
|
+
const componentTree = typeof _componentTree === "string" || !_componentTree ? createTextElement(_componentTree) : _componentTree;
|
|
125
|
+
popContext();
|
|
126
|
+
const velesComponent = {
|
|
127
|
+
velesComponent: true,
|
|
128
|
+
tree: componentTree,
|
|
129
|
+
_privateMethods: {
|
|
130
|
+
_addMountHandler(cb) {
|
|
131
|
+
componentMountCbs.push(cb);
|
|
132
|
+
},
|
|
133
|
+
_addUnmountHandler: (cb) => {
|
|
134
|
+
componentAPI.onUnmount(cb);
|
|
135
|
+
},
|
|
136
|
+
_callMountHandlers: () => {
|
|
137
|
+
componentMountCbs.forEach((cb) => {
|
|
138
|
+
const mountCbResult = cb();
|
|
139
|
+
if (typeof mountCbResult === "function") {
|
|
140
|
+
componentAPI.onUnmount(mountCbResult);
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
},
|
|
144
|
+
_callUnmountHandlers: () => {
|
|
145
|
+
componentUnmountCbs.forEach((cb) => cb());
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
return velesComponent;
|
|
150
|
+
}
|
|
151
|
+
|
|
107
152
|
// src/create-element/parse-children.ts
|
|
108
153
|
function parseChildren({
|
|
109
154
|
children,
|
|
@@ -114,30 +159,36 @@ function parseChildren({
|
|
|
114
159
|
if (children === void 0 || children === null) {
|
|
115
160
|
return childComponents;
|
|
116
161
|
}
|
|
162
|
+
let lastInsertedNode = null;
|
|
117
163
|
(Array.isArray(children) ? children : [children]).forEach(
|
|
118
164
|
(childComponent) => {
|
|
119
165
|
if (typeof childComponent === "string") {
|
|
120
|
-
const
|
|
121
|
-
htmlElement.append(
|
|
166
|
+
const textNode = createTextElement(childComponent);
|
|
167
|
+
htmlElement.append(textNode.html);
|
|
168
|
+
lastInsertedNode = textNode.html;
|
|
169
|
+
childComponents.push(textNode);
|
|
122
170
|
} else if (typeof childComponent === "number") {
|
|
123
|
-
const
|
|
124
|
-
htmlElement.append(
|
|
171
|
+
const textNode = createTextElement(String(childComponent));
|
|
172
|
+
htmlElement.append(textNode.html);
|
|
173
|
+
lastInsertedNode = textNode.html;
|
|
174
|
+
childComponents.push(textNode);
|
|
125
175
|
} else if (typeof childComponent === "object" && childComponent && "velesNode" in childComponent && (childComponent == null ? void 0 : childComponent.velesNode)) {
|
|
126
176
|
if (childComponent.phantom) {
|
|
127
177
|
childComponent.childComponents.forEach((childComponentofPhantom) => {
|
|
128
178
|
if ("velesNode" in childComponentofPhantom) {
|
|
129
179
|
htmlElement.append(childComponentofPhantom.html);
|
|
130
180
|
childComponentofPhantom.parentVelesElement = velesNode;
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
);
|
|
181
|
+
lastInsertedNode = childComponentofPhantom.html;
|
|
182
|
+
} else if ("velesStringElement" in childComponentofPhantom) {
|
|
183
|
+
const velesElementNode = childComponentofPhantom;
|
|
135
184
|
if (!velesElementNode) {
|
|
136
185
|
console.error("can't find HTML tree in a component chain");
|
|
137
186
|
} else {
|
|
138
187
|
htmlElement.append(velesElementNode.html);
|
|
188
|
+
lastInsertedNode = velesElementNode.html;
|
|
139
189
|
velesElementNode.parentVelesElement = velesNode;
|
|
140
190
|
}
|
|
191
|
+
} else {
|
|
141
192
|
}
|
|
142
193
|
});
|
|
143
194
|
childComponent.parentVelesElement = velesNode;
|
|
@@ -146,39 +197,18 @@ function parseChildren({
|
|
|
146
197
|
htmlElement.append(childComponent.html);
|
|
147
198
|
childComponent.parentVelesElement = velesNode;
|
|
148
199
|
childComponents.push(childComponent);
|
|
200
|
+
lastInsertedNode = childComponent.html;
|
|
149
201
|
}
|
|
150
|
-
} else if (typeof childComponent === "object" && childComponent && "
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
if ("velesNode" in velesElementNode && velesElementNode.phantom) {
|
|
156
|
-
velesElementNode.childComponents.forEach(
|
|
157
|
-
(childComponentofPhantom) => {
|
|
158
|
-
if ("velesNode" in childComponentofPhantom) {
|
|
159
|
-
htmlElement.append(childComponentofPhantom.html);
|
|
160
|
-
childComponentofPhantom.parentVelesElement = velesNode;
|
|
161
|
-
} else {
|
|
162
|
-
const { componentsTree: componentsTree2, velesElementNode: velesElementNode2 } = getComponentVelesNode(childComponentofPhantom);
|
|
163
|
-
if (!velesElementNode2) {
|
|
164
|
-
console.error("can't find HTML tree in a component chain");
|
|
165
|
-
} else {
|
|
166
|
-
htmlElement.append(velesElementNode2.html);
|
|
167
|
-
velesElementNode2.parentVelesElement = velesNode;
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
);
|
|
172
|
-
} else {
|
|
173
|
-
htmlElement.append(velesElementNode.html);
|
|
174
|
-
}
|
|
175
|
-
velesElementNode.parentVelesElement = velesNode;
|
|
176
|
-
childComponents.push(childComponent);
|
|
177
|
-
}
|
|
202
|
+
} else if (typeof childComponent === "object" && childComponent && "velesComponentObject" in childComponent) {
|
|
203
|
+
childComponent.insertAfter = lastInsertedNode;
|
|
204
|
+
childComponent.parentVelesElement = velesNode;
|
|
205
|
+
childComponents.push(childComponent);
|
|
206
|
+
lastInsertedNode = childComponent;
|
|
178
207
|
} else if (typeof childComponent === "object" && childComponent && "velesStringElement" in childComponent && (childComponent == null ? void 0 : childComponent.velesStringElement)) {
|
|
179
208
|
htmlElement.append(childComponent.html);
|
|
180
209
|
childComponent.parentVelesElement = velesNode;
|
|
181
210
|
childComponents.push(childComponent);
|
|
211
|
+
lastInsertedNode = childComponent.html;
|
|
182
212
|
}
|
|
183
213
|
}
|
|
184
214
|
);
|
|
@@ -195,69 +225,33 @@ function assignAttributes({
|
|
|
195
225
|
const isFunction = typeof value === "function";
|
|
196
226
|
if (isFunction && value.velesAttribute === true) {
|
|
197
227
|
const attributeValue = value(htmlElement, key, velesNode);
|
|
198
|
-
|
|
199
|
-
} else if (
|
|
200
|
-
// basically, any form of `on` handlers, like `onClick`, `onCopy`, etc
|
|
201
|
-
isFunction && key.length > 2 && key.startsWith("on")
|
|
202
|
-
) {
|
|
203
|
-
htmlElement.addEventListener(
|
|
204
|
-
key[2].toLocaleLowerCase() + key.slice(3),
|
|
205
|
-
value
|
|
206
|
-
);
|
|
228
|
+
assignAttribute({ key, value: attributeValue, htmlElement });
|
|
207
229
|
} else {
|
|
208
|
-
|
|
230
|
+
assignAttribute({ key, value, htmlElement });
|
|
209
231
|
}
|
|
210
232
|
});
|
|
211
233
|
}
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
props
|
|
234
|
+
function assignAttribute({
|
|
235
|
+
key,
|
|
236
|
+
value,
|
|
237
|
+
htmlElement
|
|
217
238
|
}) {
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
html: document.createTextNode(
|
|
233
|
-
typeof _componentTree === "string" ? _componentTree : ""
|
|
234
|
-
)
|
|
235
|
-
} : _componentTree;
|
|
236
|
-
popContext();
|
|
237
|
-
const velesComponent = {
|
|
238
|
-
velesComponent: true,
|
|
239
|
-
tree: componentTree,
|
|
240
|
-
_privateMethods: {
|
|
241
|
-
_addUnmountHandler: (cb) => {
|
|
242
|
-
componentAPI.onUnmount(cb);
|
|
243
|
-
},
|
|
244
|
-
_callMountHandlers: () => {
|
|
245
|
-
componentMountCbs.forEach((cb) => {
|
|
246
|
-
const mountCbResult = cb();
|
|
247
|
-
if (typeof mountCbResult === "function") {
|
|
248
|
-
componentAPI.onUnmount(mountCbResult);
|
|
249
|
-
}
|
|
250
|
-
});
|
|
251
|
-
},
|
|
252
|
-
_callUnmountHandlers: () => {
|
|
253
|
-
componentUnmountCbs.forEach((cb) => cb());
|
|
254
|
-
if ("_privateMethods" in velesComponent.tree) {
|
|
255
|
-
velesComponent.tree._privateMethods._callUnmountHandlers();
|
|
256
|
-
}
|
|
257
|
-
}
|
|
239
|
+
if (
|
|
240
|
+
// basically, any form of `on` handlers, like `onClick`, `onCopy`, etc
|
|
241
|
+
typeof value === "function" && key.startsWith("on")
|
|
242
|
+
) {
|
|
243
|
+
htmlElement.addEventListener(
|
|
244
|
+
key[2].toLocaleLowerCase() + key.slice(3),
|
|
245
|
+
value
|
|
246
|
+
);
|
|
247
|
+
} else {
|
|
248
|
+
if (typeof value === "boolean") {
|
|
249
|
+
if (value)
|
|
250
|
+
htmlElement.setAttribute(key, "");
|
|
251
|
+
} else {
|
|
252
|
+
htmlElement.setAttribute(key, value);
|
|
258
253
|
}
|
|
259
|
-
}
|
|
260
|
-
return velesComponent;
|
|
254
|
+
}
|
|
261
255
|
}
|
|
262
256
|
|
|
263
257
|
// src/create-element/create-element.ts
|
|
@@ -274,23 +268,25 @@ function createElement(element, props = {}) {
|
|
|
274
268
|
htmlElement: newElement,
|
|
275
269
|
velesNode
|
|
276
270
|
});
|
|
277
|
-
|
|
278
|
-
const callUnmountHandlers = () => {
|
|
279
|
-
unmountHandlers.forEach((cb) => cb());
|
|
280
|
-
unmountHandlers = [];
|
|
281
|
-
childComponents.forEach((childComponent) => {
|
|
282
|
-
childComponent._privateMethods._callUnmountHandlers();
|
|
283
|
-
});
|
|
284
|
-
};
|
|
271
|
+
const unmountHandlers = [];
|
|
285
272
|
velesNode.html = newElement;
|
|
286
273
|
velesNode.velesNode = true;
|
|
287
274
|
velesNode.childComponents = childComponents;
|
|
288
275
|
velesNode.phantom = phantom;
|
|
276
|
+
const mountHandlers = [];
|
|
289
277
|
velesNode._privateMethods = {
|
|
290
|
-
|
|
278
|
+
_addMountHandler(cb) {
|
|
279
|
+
mountHandlers.push(cb);
|
|
280
|
+
},
|
|
281
|
+
_callMountHandlers() {
|
|
282
|
+
mountHandlers.forEach((cb) => cb());
|
|
283
|
+
},
|
|
284
|
+
_addUnmountHandler(cb) {
|
|
291
285
|
unmountHandlers.push(cb);
|
|
292
286
|
},
|
|
293
|
-
_callUnmountHandlers
|
|
287
|
+
_callUnmountHandlers() {
|
|
288
|
+
unmountHandlers.forEach((cb) => cb());
|
|
289
|
+
}
|
|
294
290
|
};
|
|
295
291
|
assignAttributes({ props: otherProps, htmlElement: newElement, velesNode });
|
|
296
292
|
return velesNode;
|
|
@@ -302,333 +298,712 @@ function createElement(element, props = {}) {
|
|
|
302
298
|
);
|
|
303
299
|
}
|
|
304
300
|
|
|
305
|
-
// src/
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
301
|
+
// src/context/index.ts
|
|
302
|
+
var publicContextStack = [];
|
|
303
|
+
function addPublicContext(specificContext) {
|
|
304
|
+
if (specificContext) {
|
|
305
|
+
publicContextStack.push(specificContext);
|
|
306
|
+
} else {
|
|
307
|
+
if (publicContextStack.length === 0) {
|
|
308
|
+
publicContextStack.push({});
|
|
309
|
+
} else {
|
|
310
|
+
const currentContext2 = publicContextStack[publicContextStack.length - 1];
|
|
311
|
+
publicContextStack.push(currentContext2);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
function popPublicContext() {
|
|
316
|
+
publicContextStack.pop();
|
|
317
|
+
}
|
|
318
|
+
function getCurrentContext() {
|
|
319
|
+
return publicContextStack[publicContextStack.length - 1];
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
// src/_utils.ts
|
|
323
|
+
function getExecutedComponentVelesNode(component) {
|
|
324
|
+
if ("executedVelesStringElement" in component) {
|
|
325
|
+
return component;
|
|
326
|
+
}
|
|
327
|
+
let childNode = component;
|
|
328
|
+
while ("executedVelesComponent" in childNode) {
|
|
329
|
+
if ("executedVelesStringElement" in childNode.tree) {
|
|
330
|
+
return childNode.tree;
|
|
331
|
+
} else {
|
|
332
|
+
childNode = childNode.tree;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
return childNode;
|
|
336
|
+
}
|
|
337
|
+
function renderTree(component, { parentVelesElement } = {}) {
|
|
338
|
+
if ("velesStringElement" in component) {
|
|
339
|
+
const executedString = {
|
|
340
|
+
executedVelesStringElement: true,
|
|
341
|
+
_privateMethods: component._privateMethods,
|
|
342
|
+
html: component.html,
|
|
343
|
+
parentVelesElement
|
|
344
|
+
};
|
|
345
|
+
if (component.needExecutedVersion) {
|
|
346
|
+
component.executedVersion = executedString;
|
|
347
|
+
}
|
|
348
|
+
return executedString;
|
|
349
|
+
} else if ("velesComponentObject" in component) {
|
|
350
|
+
addPublicContext();
|
|
351
|
+
const componentTree = executeComponent(component);
|
|
352
|
+
const executedComponent = {};
|
|
353
|
+
executedComponent.executedVelesComponent = true;
|
|
354
|
+
executedComponent.tree = renderTree(componentTree.tree);
|
|
355
|
+
popPublicContext();
|
|
356
|
+
executedComponent._privateMethods = {
|
|
357
|
+
...componentTree._privateMethods,
|
|
358
|
+
_callMountHandlers: () => {
|
|
359
|
+
component._privateMethods._callMountHandlers();
|
|
360
|
+
componentTree._privateMethods._callMountHandlers();
|
|
316
361
|
},
|
|
317
362
|
_callUnmountHandlers: () => {
|
|
318
|
-
|
|
363
|
+
component._privateMethods._callUnmountHandlers();
|
|
364
|
+
componentTree._privateMethods._callUnmountHandlers();
|
|
365
|
+
}
|
|
366
|
+
};
|
|
367
|
+
const newNode = getExecutedComponentVelesNode(executedComponent);
|
|
368
|
+
if (parentVelesElement) {
|
|
369
|
+
if (component.insertAfter) {
|
|
370
|
+
if ("velesComponentObject" in component.insertAfter) {
|
|
371
|
+
const lastNode = insertNode({
|
|
372
|
+
velesElement: newNode,
|
|
373
|
+
adjacentNode: component.insertAfter.html,
|
|
374
|
+
parentVelesElement
|
|
375
|
+
});
|
|
376
|
+
component.html = lastNode;
|
|
377
|
+
} else {
|
|
378
|
+
const lastNode = insertNode({
|
|
379
|
+
velesElement: newNode,
|
|
380
|
+
adjacentNode: component.insertAfter,
|
|
381
|
+
parentVelesElement
|
|
382
|
+
});
|
|
383
|
+
component.html = lastNode;
|
|
384
|
+
}
|
|
385
|
+
} else {
|
|
386
|
+
const lastNode = insertNode({
|
|
387
|
+
velesElement: newNode,
|
|
388
|
+
// it means we are inserting the first element
|
|
389
|
+
adjacentNode: null,
|
|
390
|
+
parentVelesElement
|
|
391
|
+
});
|
|
392
|
+
component.html = lastNode;
|
|
319
393
|
}
|
|
394
|
+
newNode.parentVelesElement = parentVelesElement;
|
|
320
395
|
}
|
|
321
|
-
|
|
396
|
+
if (component.needExecutedVersion) {
|
|
397
|
+
component.executedVersion = executedComponent;
|
|
398
|
+
}
|
|
399
|
+
return executedComponent;
|
|
400
|
+
} else if ("velesNode" in component) {
|
|
401
|
+
const executedNode = {};
|
|
402
|
+
executedNode.executedVelesNode = true;
|
|
403
|
+
executedNode._privateMethods = component._privateMethods;
|
|
404
|
+
executedNode.html = component.html;
|
|
405
|
+
if (parentVelesElement) {
|
|
406
|
+
executedNode.parentVelesElement = parentVelesElement;
|
|
407
|
+
}
|
|
408
|
+
if (component.phantom) {
|
|
409
|
+
executedNode.phantom = component.phantom;
|
|
410
|
+
}
|
|
411
|
+
executedNode.childComponents = component.childComponents.map(
|
|
412
|
+
(childComponent) => renderTree(childComponent, { parentVelesElement: executedNode })
|
|
413
|
+
);
|
|
414
|
+
if (component.needExecutedVersion) {
|
|
415
|
+
component.executedVersion = executedNode;
|
|
416
|
+
}
|
|
417
|
+
return executedNode;
|
|
418
|
+
}
|
|
322
419
|
}
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
420
|
+
function insertNode({
|
|
421
|
+
velesElement,
|
|
422
|
+
adjacentNode,
|
|
423
|
+
parentVelesElement
|
|
424
|
+
}) {
|
|
425
|
+
if (velesElement.phantom) {
|
|
426
|
+
let lastInsertedNode = null;
|
|
427
|
+
velesElement.childComponents.forEach(
|
|
428
|
+
(childComponentofPhantom) => {
|
|
429
|
+
if ("executedVelesNode" in childComponentofPhantom) {
|
|
430
|
+
if (lastInsertedNode) {
|
|
431
|
+
lastInsertedNode.after(childComponentofPhantom.html);
|
|
432
|
+
} else {
|
|
433
|
+
if (adjacentNode) {
|
|
434
|
+
adjacentNode.after(childComponentofPhantom.html);
|
|
435
|
+
} else {
|
|
436
|
+
parentVelesElement.html.prepend(childComponentofPhantom.html);
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
childComponentofPhantom.parentVelesElement = parentVelesElement;
|
|
440
|
+
lastInsertedNode = childComponentofPhantom.html;
|
|
441
|
+
} else if ("executedVelesStringElement" in childComponentofPhantom) {
|
|
442
|
+
if (lastInsertedNode) {
|
|
443
|
+
lastInsertedNode.after(childComponentofPhantom.html);
|
|
444
|
+
} else {
|
|
445
|
+
if (adjacentNode) {
|
|
446
|
+
adjacentNode.after(childComponentofPhantom.html);
|
|
447
|
+
} else {
|
|
448
|
+
parentVelesElement.html.prepend(childComponentofPhantom.html);
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
childComponentofPhantom.parentVelesElement = parentVelesElement;
|
|
452
|
+
lastInsertedNode = childComponentofPhantom.html;
|
|
453
|
+
} else {
|
|
454
|
+
const executedNode = getExecutedComponentVelesNode(
|
|
455
|
+
childComponentofPhantom
|
|
456
|
+
);
|
|
457
|
+
if (lastInsertedNode) {
|
|
458
|
+
lastInsertedNode.after(executedNode.html);
|
|
459
|
+
} else {
|
|
460
|
+
if (adjacentNode) {
|
|
461
|
+
adjacentNode.after(executedNode.html);
|
|
462
|
+
} else {
|
|
463
|
+
parentVelesElement.html.prepend(executedNode.html);
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
executedNode.parentVelesElement = parentVelesElement;
|
|
467
|
+
lastInsertedNode = executedNode.html;
|
|
468
|
+
}
|
|
340
469
|
}
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
470
|
+
);
|
|
471
|
+
velesElement.parentVelesElement = parentVelesElement;
|
|
472
|
+
return lastInsertedNode;
|
|
473
|
+
} else {
|
|
474
|
+
if (adjacentNode) {
|
|
475
|
+
adjacentNode.after(velesElement.html);
|
|
476
|
+
} else {
|
|
477
|
+
parentVelesElement.html.prepend(velesElement.html);
|
|
478
|
+
}
|
|
479
|
+
velesElement.parentVelesElement = parentVelesElement;
|
|
480
|
+
return velesElement.html;
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
function callMountHandlers(component) {
|
|
484
|
+
component._privateMethods._callMountHandlers();
|
|
485
|
+
if ("executedVelesStringElement" in component) {
|
|
486
|
+
return;
|
|
487
|
+
}
|
|
488
|
+
if ("executedVelesComponent" in component) {
|
|
489
|
+
callMountHandlers(component.tree);
|
|
490
|
+
}
|
|
491
|
+
if ("executedVelesNode" in component) {
|
|
492
|
+
component.childComponents.forEach(
|
|
493
|
+
(childComponent) => callMountHandlers(childComponent)
|
|
494
|
+
);
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
function callUnmountHandlers(component) {
|
|
498
|
+
if ("executedVelesStringElement" in component) {
|
|
499
|
+
} else if ("executedVelesComponent" in component) {
|
|
500
|
+
callUnmountHandlers(component.tree);
|
|
501
|
+
} else if ("executedVelesNode" in component) {
|
|
502
|
+
component.childComponents.forEach(
|
|
503
|
+
(childComponent) => callUnmountHandlers(childComponent)
|
|
504
|
+
);
|
|
505
|
+
}
|
|
506
|
+
component._privateMethods._callUnmountHandlers();
|
|
507
|
+
}
|
|
508
|
+
function identity(value1, value2) {
|
|
509
|
+
return value1 === value2;
|
|
510
|
+
}
|
|
511
|
+
function unique(arr) {
|
|
512
|
+
const map = /* @__PURE__ */ new Map();
|
|
513
|
+
const resultArr = [];
|
|
514
|
+
arr.forEach((element) => {
|
|
515
|
+
if (map.has(element))
|
|
516
|
+
return;
|
|
517
|
+
map.set(element, true);
|
|
518
|
+
resultArr.push(element);
|
|
519
|
+
});
|
|
520
|
+
return resultArr;
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
// src/create-state/update-usevalue-selector-value.ts
|
|
524
|
+
function updateUseValueSelector({
|
|
525
|
+
value,
|
|
526
|
+
selectorTrackingElement,
|
|
527
|
+
newTrackingSelectorElements,
|
|
528
|
+
trackers,
|
|
529
|
+
getValue
|
|
530
|
+
}) {
|
|
531
|
+
const { selectedValue, selector, cb, node, comparator, savedContext } = selectorTrackingElement;
|
|
532
|
+
const newSelectedValue = selector ? selector(value) : value;
|
|
533
|
+
if (comparator(selectedValue, newSelectedValue)) {
|
|
534
|
+
newTrackingSelectorElements.push(selectorTrackingElement);
|
|
535
|
+
return;
|
|
536
|
+
}
|
|
537
|
+
addPublicContext(savedContext);
|
|
538
|
+
const returnednewNode = cb ? cb(newSelectedValue) : newSelectedValue == void 0 ? "" : String(newSelectedValue);
|
|
539
|
+
const newNode = !returnednewNode || typeof returnednewNode === "string" ? createTextElement(returnednewNode) : returnednewNode;
|
|
540
|
+
const newRenderedNode = renderTree(newNode);
|
|
541
|
+
popPublicContext();
|
|
542
|
+
newNode.executedVersion = newRenderedNode;
|
|
543
|
+
if (!node.executedVersion) {
|
|
544
|
+
console.error("the node was not mounted");
|
|
545
|
+
return;
|
|
546
|
+
}
|
|
547
|
+
const oldVelesElementNode = getExecutedComponentVelesNode(
|
|
548
|
+
node.executedVersion
|
|
549
|
+
);
|
|
550
|
+
const newVelesElementNode = getExecutedComponentVelesNode(newRenderedNode);
|
|
551
|
+
const parentVelesElement = node.parentVelesElement;
|
|
552
|
+
const parentVelesElementRendered = oldVelesElementNode.parentVelesElement;
|
|
553
|
+
const newTrackingSelectorElement = {
|
|
554
|
+
selector,
|
|
555
|
+
selectedValue: newSelectedValue,
|
|
556
|
+
cb,
|
|
557
|
+
node: newNode,
|
|
558
|
+
comparator,
|
|
559
|
+
savedContext
|
|
560
|
+
};
|
|
561
|
+
if (parentVelesElementRendered) {
|
|
562
|
+
newNode.parentVelesElement = parentVelesElement;
|
|
563
|
+
newVelesElementNode.parentVelesElement = parentVelesElementRendered;
|
|
564
|
+
if ("executedVelesNode" in newVelesElementNode && newVelesElementNode.phantom) {
|
|
565
|
+
const insertAllPhantomChildren = (adjacentNode) => {
|
|
566
|
+
newVelesElementNode.childComponents.forEach(
|
|
567
|
+
(childComponentofPhantom) => {
|
|
568
|
+
if ("executedVelesNode" in childComponentofPhantom) {
|
|
569
|
+
adjacentNode.html.before(childComponentofPhantom.html);
|
|
570
|
+
childComponentofPhantom.parentVelesElement = adjacentNode.parentVelesElement;
|
|
571
|
+
} else {
|
|
572
|
+
const velesElementNode = getExecutedComponentVelesNode(
|
|
573
|
+
childComponentofPhantom
|
|
574
|
+
);
|
|
575
|
+
if (!velesElementNode) {
|
|
576
|
+
console.error("can't find HTML tree in a component chain");
|
|
577
|
+
} else {
|
|
578
|
+
adjacentNode.html.before(velesElementNode.html);
|
|
579
|
+
velesElementNode.parentVelesElement = adjacentNode.parentVelesElement;
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
);
|
|
352
584
|
};
|
|
353
|
-
if (
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
(
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
childComponentofPhantom.parentVelesElement = adjacentNode.parentVelesElement;
|
|
362
|
-
} else {
|
|
363
|
-
const { velesElementNode } = getComponentVelesNode(
|
|
364
|
-
childComponentofPhantom
|
|
365
|
-
);
|
|
366
|
-
if (!velesElementNode) {
|
|
367
|
-
console.error("can't find HTML tree in a component chain");
|
|
368
|
-
} else {
|
|
369
|
-
adjacentNode.html.before(velesElementNode.html);
|
|
370
|
-
velesElementNode.parentVelesElement = adjacentNode.parentVelesElement;
|
|
371
|
-
}
|
|
372
|
-
}
|
|
585
|
+
if ("executedVelesNode" in oldVelesElementNode && oldVelesElementNode.phantom) {
|
|
586
|
+
let isInserted = false;
|
|
587
|
+
oldVelesElementNode.childComponents.forEach(
|
|
588
|
+
(childComponentofPhantom) => {
|
|
589
|
+
if ("executedVelesNode" in childComponentofPhantom) {
|
|
590
|
+
if (!isInserted) {
|
|
591
|
+
insertAllPhantomChildren(childComponentofPhantom);
|
|
592
|
+
isInserted = true;
|
|
373
593
|
}
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
(
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
childComponentofPhantom.html.remove();
|
|
386
|
-
} else {
|
|
387
|
-
const { velesElementNode } = getComponentVelesNode(
|
|
388
|
-
childComponentofPhantom
|
|
389
|
-
);
|
|
390
|
-
if (!velesElementNode) {
|
|
391
|
-
console.error("can't find HTML tree in a component chain");
|
|
392
|
-
} else {
|
|
393
|
-
if (!isInserted) {
|
|
394
|
-
insertAllPhantomChildren(velesElementNode);
|
|
395
|
-
isInserted = true;
|
|
396
|
-
}
|
|
397
|
-
velesElementNode.html.remove();
|
|
398
|
-
}
|
|
594
|
+
childComponentofPhantom.html.remove();
|
|
595
|
+
} else {
|
|
596
|
+
const velesElementNode = getExecutedComponentVelesNode(
|
|
597
|
+
childComponentofPhantom
|
|
598
|
+
);
|
|
599
|
+
if (!velesElementNode) {
|
|
600
|
+
console.error("can't find HTML tree in a component chain");
|
|
601
|
+
} else {
|
|
602
|
+
if (!isInserted) {
|
|
603
|
+
insertAllPhantomChildren(velesElementNode);
|
|
604
|
+
isInserted = true;
|
|
399
605
|
}
|
|
606
|
+
velesElementNode.html.remove();
|
|
400
607
|
}
|
|
401
|
-
|
|
402
|
-
} else {
|
|
403
|
-
insertAllPhantomChildren(oldVelesElementNode);
|
|
404
|
-
oldVelesElementNode.html.remove();
|
|
608
|
+
}
|
|
405
609
|
}
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
610
|
+
);
|
|
611
|
+
} else {
|
|
612
|
+
insertAllPhantomChildren(oldVelesElementNode);
|
|
613
|
+
oldVelesElementNode.html.remove();
|
|
614
|
+
}
|
|
615
|
+
} else {
|
|
616
|
+
if ("executedVelesNode" in oldVelesElementNode && oldVelesElementNode.phantom) {
|
|
617
|
+
let isInserted = false;
|
|
618
|
+
oldVelesElementNode.childComponents.forEach(
|
|
619
|
+
(childComponentofPhantom) => {
|
|
620
|
+
if ("executedVelesNode" in childComponentofPhantom) {
|
|
621
|
+
if (!isInserted) {
|
|
622
|
+
childComponentofPhantom.html.before(newVelesElementNode.html);
|
|
623
|
+
isInserted = true;
|
|
624
|
+
}
|
|
625
|
+
childComponentofPhantom.html.remove();
|
|
626
|
+
} else {
|
|
627
|
+
const velesElementNode = getExecutedComponentVelesNode(
|
|
628
|
+
childComponentofPhantom
|
|
629
|
+
);
|
|
630
|
+
if (!velesElementNode) {
|
|
631
|
+
console.error("can't find HTML tree in a component chain");
|
|
632
|
+
} else {
|
|
633
|
+
if (!isInserted) {
|
|
634
|
+
velesElementNode.html.before(newVelesElementNode.html);
|
|
635
|
+
isInserted = true;
|
|
432
636
|
}
|
|
637
|
+
velesElementNode.html.remove();
|
|
433
638
|
}
|
|
434
|
-
|
|
435
|
-
} else {
|
|
436
|
-
parentVelesElement.html.replaceChild(
|
|
437
|
-
newVelesElementNode.html,
|
|
438
|
-
oldVelesElementNode.html
|
|
439
|
-
);
|
|
639
|
+
}
|
|
440
640
|
}
|
|
441
|
-
}
|
|
442
|
-
parentVelesElement.childComponents = parentVelesElement.childComponents.map(
|
|
443
|
-
(childComponent) => childComponent === node ? newNode : node
|
|
444
641
|
);
|
|
445
|
-
node._privateMethods._callUnmountHandlers();
|
|
446
|
-
callMountHandlers(newNode);
|
|
447
|
-
newNode._privateMethods._addUnmountHandler(() => {
|
|
448
|
-
trackingSelectorElements = trackingSelectorElements.filter(
|
|
449
|
-
(el) => el !== newTrackingSelectorElement
|
|
450
|
-
);
|
|
451
|
-
});
|
|
452
642
|
} else {
|
|
453
|
-
|
|
643
|
+
try {
|
|
644
|
+
parentVelesElementRendered.html.replaceChild(
|
|
645
|
+
newVelesElementNode.html,
|
|
646
|
+
oldVelesElementNode.html
|
|
647
|
+
);
|
|
648
|
+
} catch (e) {
|
|
649
|
+
console.error("failed to update...");
|
|
650
|
+
console.log(document.body.innerHTML);
|
|
651
|
+
console.log(oldVelesElementNode.parentVelesElement.html.innerHTML);
|
|
652
|
+
console.log(
|
|
653
|
+
//@ts-expect-error
|
|
654
|
+
oldVelesElementNode.parentVelesElement.childComponents[0].html.textContent
|
|
655
|
+
);
|
|
656
|
+
}
|
|
454
657
|
}
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
trackingSelectorElements.concat(newTrackingSelectorElements)
|
|
658
|
+
}
|
|
659
|
+
parentVelesElementRendered.childComponents = parentVelesElementRendered.childComponents.map(
|
|
660
|
+
(childComponent) => childComponent === node.executedVersion ? newRenderedNode : childComponent
|
|
459
661
|
);
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
662
|
+
if (parentVelesElement == null ? void 0 : parentVelesElement.childComponents) {
|
|
663
|
+
parentVelesElement.childComponents = parentVelesElement.childComponents.map(
|
|
664
|
+
(childComponent) => childComponent === node ? newNode : childComponent
|
|
665
|
+
);
|
|
666
|
+
}
|
|
667
|
+
callUnmountHandlers(node.executedVersion);
|
|
668
|
+
addUseValueMountHandler({
|
|
669
|
+
usedValue: value,
|
|
670
|
+
trackers,
|
|
671
|
+
getValue,
|
|
672
|
+
trackingSelectorElement: newTrackingSelectorElement
|
|
463
673
|
});
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
}
|
|
470
|
-
cb(newSelectedValue);
|
|
471
|
-
trackingEffect.selectedValue = newSelectedValue;
|
|
674
|
+
callMountHandlers(newRenderedNode);
|
|
675
|
+
newNode._privateMethods._addUnmountHandler(() => {
|
|
676
|
+
trackers.trackingSelectorElements = trackers.trackingSelectorElements.filter(
|
|
677
|
+
(el) => el !== newTrackingSelectorElement
|
|
678
|
+
);
|
|
472
679
|
});
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
680
|
+
} else {
|
|
681
|
+
console.log("parent node was not found");
|
|
682
|
+
}
|
|
683
|
+
newTrackingSelectorElements.push(newTrackingSelectorElement);
|
|
684
|
+
}
|
|
685
|
+
function addUseValueMountHandler({
|
|
686
|
+
usedValue,
|
|
687
|
+
getValue,
|
|
688
|
+
trackers,
|
|
689
|
+
trackingSelectorElement
|
|
690
|
+
}) {
|
|
691
|
+
trackingSelectorElement.node._privateMethods._addMountHandler(() => {
|
|
692
|
+
const currentValue = getValue();
|
|
693
|
+
if (usedValue === currentValue) {
|
|
694
|
+
trackers.trackingSelectorElements.push(trackingSelectorElement);
|
|
695
|
+
trackingSelectorElement.node._privateMethods._addUnmountHandler(() => {
|
|
696
|
+
trackers.trackingSelectorElements = trackers.trackingSelectorElements.filter(
|
|
697
|
+
(el) => trackingSelectorElement !== el
|
|
698
|
+
);
|
|
699
|
+
});
|
|
700
|
+
} else {
|
|
701
|
+
const newTrackingSelectorElements = [];
|
|
702
|
+
updateUseValueSelector({
|
|
703
|
+
value: getValue(),
|
|
704
|
+
trackers,
|
|
705
|
+
selectorTrackingElement: trackingSelectorElement,
|
|
706
|
+
newTrackingSelectorElements,
|
|
707
|
+
getValue
|
|
708
|
+
});
|
|
709
|
+
if (newTrackingSelectorElements[0]) {
|
|
710
|
+
const newTrackingSelectorElement = newTrackingSelectorElements[0];
|
|
711
|
+
if (newTrackingSelectorElement.node === trackingSelectorElement.node) {
|
|
712
|
+
trackers.trackingSelectorElements.push(newTrackingSelectorElement);
|
|
713
|
+
newTrackingSelectorElement.node._privateMethods._addUnmountHandler(
|
|
714
|
+
() => {
|
|
715
|
+
trackers.trackingSelectorElements = trackers.trackingSelectorElements.filter(
|
|
716
|
+
(el) => trackingSelectorElement !== el
|
|
717
|
+
);
|
|
718
|
+
}
|
|
719
|
+
);
|
|
720
|
+
} else {
|
|
721
|
+
}
|
|
722
|
+
} else {
|
|
485
723
|
}
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
724
|
+
}
|
|
725
|
+
});
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
// src/create-state/update-useattribute-value.ts
|
|
729
|
+
function updateUseAttributeValue({
|
|
730
|
+
element,
|
|
731
|
+
value
|
|
732
|
+
}) {
|
|
733
|
+
const { cb, htmlElement, attributeName, attributeValue } = element;
|
|
734
|
+
const newAttributeValue = cb ? cb(value) : value;
|
|
735
|
+
if (typeof newAttributeValue === "boolean") {
|
|
736
|
+
if (newAttributeValue) {
|
|
737
|
+
htmlElement.setAttribute(attributeName, "");
|
|
738
|
+
} else {
|
|
739
|
+
htmlElement.removeAttribute(attributeName);
|
|
740
|
+
}
|
|
741
|
+
} else if (attributeName.startsWith("on")) {
|
|
742
|
+
if (attributeValue === newAttributeValue) {
|
|
743
|
+
return;
|
|
744
|
+
}
|
|
745
|
+
const eventName = attributeName[2].toLocaleLowerCase() + attributeName.slice(3);
|
|
746
|
+
if (attributeValue) {
|
|
747
|
+
htmlElement.removeEventListener(eventName, attributeValue);
|
|
748
|
+
}
|
|
749
|
+
if (newAttributeValue && typeof newAttributeValue === "function") {
|
|
750
|
+
htmlElement.addEventListener(eventName, newAttributeValue);
|
|
751
|
+
}
|
|
752
|
+
element.attributeValue = newAttributeValue;
|
|
753
|
+
} else {
|
|
754
|
+
htmlElement.setAttribute(attributeName, newAttributeValue);
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
// src/create-state/update-usevalueiterator-value.ts
|
|
759
|
+
function updateUseValueIteratorValue({
|
|
760
|
+
value,
|
|
761
|
+
trackingIterator,
|
|
762
|
+
createState: createState2
|
|
763
|
+
}) {
|
|
764
|
+
const {
|
|
765
|
+
cb,
|
|
766
|
+
key,
|
|
767
|
+
renderedElements,
|
|
768
|
+
elementsByKey,
|
|
769
|
+
wrapperComponent,
|
|
770
|
+
selector,
|
|
771
|
+
savedContext
|
|
772
|
+
} = trackingIterator;
|
|
773
|
+
if (!wrapperComponent) {
|
|
774
|
+
console.error("there is no wrapper component for the iterator");
|
|
775
|
+
return;
|
|
776
|
+
}
|
|
777
|
+
if (!wrapperComponent.executedVersion) {
|
|
778
|
+
console.error("it seems the wrapper component was not mounted");
|
|
779
|
+
return;
|
|
780
|
+
}
|
|
781
|
+
const wrapperVelesElementNode = getExecutedComponentVelesNode(
|
|
782
|
+
wrapperComponent.executedVersion
|
|
783
|
+
);
|
|
784
|
+
const parentVelesElement = wrapperVelesElementNode.parentVelesElement;
|
|
785
|
+
if (!parentVelesElement) {
|
|
786
|
+
console.error("there is no parent Veles node for the iterator wrapper");
|
|
787
|
+
return;
|
|
788
|
+
}
|
|
789
|
+
const elements = selector ? selector(value) : value;
|
|
790
|
+
if (Array.isArray(elements)) {
|
|
791
|
+
const newRenderedElements = [];
|
|
792
|
+
const newElementsByKey = {};
|
|
793
|
+
const renderedExistingElements = {};
|
|
794
|
+
elements.forEach((element, index) => {
|
|
795
|
+
let calculatedKey = "";
|
|
796
|
+
if (typeof key === "string" && typeof element === "object" && element !== null && key in element) {
|
|
797
|
+
calculatedKey = element[key];
|
|
798
|
+
} else if (typeof key === "function") {
|
|
799
|
+
calculatedKey = key({ element, index });
|
|
800
|
+
} else {
|
|
801
|
+
}
|
|
802
|
+
if (!calculatedKey) {
|
|
490
803
|
return;
|
|
491
804
|
}
|
|
492
|
-
const
|
|
493
|
-
if (
|
|
494
|
-
|
|
495
|
-
const
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
805
|
+
const existingElement = elementsByKey[calculatedKey];
|
|
806
|
+
if (existingElement) {
|
|
807
|
+
renderedExistingElements[calculatedKey] = true;
|
|
808
|
+
const currentValue = existingElement.elementState.getValue();
|
|
809
|
+
if (currentValue !== element) {
|
|
810
|
+
existingElement.elementState.setValue(element);
|
|
811
|
+
}
|
|
812
|
+
const currentIndex = existingElement.indexState.getValue();
|
|
813
|
+
if (currentIndex !== index) {
|
|
814
|
+
existingElement.indexState.setValue(index);
|
|
815
|
+
}
|
|
816
|
+
newRenderedElements.push([
|
|
817
|
+
existingElement.node,
|
|
818
|
+
calculatedKey,
|
|
819
|
+
existingElement.elementState
|
|
820
|
+
]);
|
|
821
|
+
newElementsByKey[calculatedKey] = {
|
|
822
|
+
elementState: existingElement.elementState,
|
|
823
|
+
indexState: existingElement.indexState,
|
|
824
|
+
indexValue: index,
|
|
825
|
+
node: existingElement.node
|
|
826
|
+
};
|
|
827
|
+
} else {
|
|
828
|
+
const elementState = createState2(element);
|
|
829
|
+
const indexState = createState2(index);
|
|
830
|
+
addPublicContext(savedContext);
|
|
831
|
+
const node = cb({ elementState, indexState });
|
|
832
|
+
const renderedNode = renderTree(node);
|
|
833
|
+
node.executedVersion = renderedNode;
|
|
834
|
+
popPublicContext();
|
|
835
|
+
newRenderedElements.push([node, calculatedKey, elementState]);
|
|
836
|
+
newElementsByKey[calculatedKey] = {
|
|
837
|
+
elementState,
|
|
838
|
+
indexState,
|
|
839
|
+
indexValue: index,
|
|
840
|
+
node
|
|
841
|
+
};
|
|
842
|
+
}
|
|
843
|
+
});
|
|
844
|
+
const newChildRenderedComponents = [];
|
|
845
|
+
const newChildComponents = [];
|
|
846
|
+
const positioningOffset = {};
|
|
847
|
+
let newElementsCount = 0;
|
|
848
|
+
let offset = 0;
|
|
849
|
+
let currentElement = null;
|
|
850
|
+
newRenderedElements.forEach((newRenderedElement, index) => {
|
|
851
|
+
var _a, _b, _c;
|
|
852
|
+
newChildRenderedComponents.push(newRenderedElement[0].executedVersion);
|
|
853
|
+
newChildComponents.push(newRenderedElement[0]);
|
|
854
|
+
if (positioningOffset[index]) {
|
|
855
|
+
offset = offset + positioningOffset[index];
|
|
856
|
+
}
|
|
857
|
+
const [newNode, calculatedKey, newState] = newRenderedElement;
|
|
858
|
+
const existingElement = elementsByKey[calculatedKey];
|
|
859
|
+
if (existingElement) {
|
|
860
|
+
const existingElementNode = getExecutedComponentVelesNode(
|
|
861
|
+
existingElement.node.executedVersion
|
|
862
|
+
);
|
|
863
|
+
if (existingElement.indexValue + offset === index) {
|
|
864
|
+
currentElement = existingElementNode.html;
|
|
865
|
+
return;
|
|
866
|
+
}
|
|
867
|
+
if (existingElement.indexValue + offset > index) {
|
|
868
|
+
if (currentElement) {
|
|
869
|
+
currentElement.after(existingElementNode.html);
|
|
870
|
+
positioningOffset[existingElement.indexValue + 1] = -1;
|
|
530
871
|
} else {
|
|
531
|
-
const
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
indexState,
|
|
538
|
-
indexValue: index,
|
|
539
|
-
node
|
|
540
|
-
};
|
|
541
|
-
}
|
|
542
|
-
});
|
|
543
|
-
const positioningOffset = {};
|
|
544
|
-
let newElementsCount = 0;
|
|
545
|
-
let offset = 0;
|
|
546
|
-
let currentElement = null;
|
|
547
|
-
newRenderedElements.forEach((newRenderedElement, index) => {
|
|
548
|
-
var _a, _b, _c;
|
|
549
|
-
if (positioningOffset[index]) {
|
|
550
|
-
offset = offset + positioningOffset[index];
|
|
551
|
-
}
|
|
552
|
-
const [newNode, calculatedKey, newState] = newRenderedElement;
|
|
553
|
-
const existingElement = elementsByKey[calculatedKey];
|
|
554
|
-
if (existingElement) {
|
|
555
|
-
const { velesElementNode: existingElementNode } = getComponentVelesNode(existingElement.node);
|
|
556
|
-
if (existingElement.indexValue + offset === index) {
|
|
557
|
-
currentElement = existingElementNode.html;
|
|
558
|
-
return;
|
|
559
|
-
}
|
|
560
|
-
if (existingElement.indexValue + offset > index) {
|
|
561
|
-
if (currentElement) {
|
|
562
|
-
currentElement.after(existingElementNode.html);
|
|
563
|
-
positioningOffset[existingElement.indexValue + 1] = -1;
|
|
564
|
-
} else {
|
|
565
|
-
const firstRenderedElement = (_a = renderedElements[0]) == null ? void 0 : _a[0];
|
|
566
|
-
if (firstRenderedElement) {
|
|
567
|
-
const { velesElementNode: firstRenderedVelesNode } = getComponentVelesNode(firstRenderedElement);
|
|
568
|
-
firstRenderedVelesNode.html.before(existingElementNode.html);
|
|
569
|
-
} else {
|
|
570
|
-
}
|
|
571
|
-
}
|
|
572
|
-
currentElement = existingElementNode.html;
|
|
573
|
-
offset = offset + 1;
|
|
872
|
+
const firstRenderedElement = (_a = renderedElements[0]) == null ? void 0 : _a[0];
|
|
873
|
+
if (firstRenderedElement == null ? void 0 : firstRenderedElement.executedVersion) {
|
|
874
|
+
const firstRenderedVelesNode = getExecutedComponentVelesNode(
|
|
875
|
+
firstRenderedElement.executedVersion
|
|
876
|
+
);
|
|
877
|
+
firstRenderedVelesNode.html.before(existingElementNode.html);
|
|
574
878
|
} else {
|
|
575
|
-
if (currentElement) {
|
|
576
|
-
currentElement.after(existingElementNode.html);
|
|
577
|
-
positioningOffset[existingElement.indexValue + 1] = 1;
|
|
578
|
-
} else {
|
|
579
|
-
const firstRenderedElement = (_b = renderedElements[0]) == null ? void 0 : _b[0];
|
|
580
|
-
if (firstRenderedElement) {
|
|
581
|
-
const { velesElementNode: firstRenderedVelesNode } = getComponentVelesNode(firstRenderedElement);
|
|
582
|
-
firstRenderedVelesNode.html.before(existingElementNode.html);
|
|
583
|
-
} else {
|
|
584
|
-
}
|
|
585
|
-
}
|
|
586
|
-
currentElement = existingElementNode.html;
|
|
587
|
-
offset = offset - 1;
|
|
588
879
|
}
|
|
880
|
+
}
|
|
881
|
+
currentElement = existingElementNode.html;
|
|
882
|
+
offset = offset + 1;
|
|
883
|
+
} else {
|
|
884
|
+
if (currentElement) {
|
|
885
|
+
currentElement.after(existingElementNode.html);
|
|
886
|
+
positioningOffset[existingElement.indexValue + 1] = 1;
|
|
589
887
|
} else {
|
|
590
|
-
const
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
888
|
+
const firstRenderedElement = (_b = renderedElements[0]) == null ? void 0 : _b[0];
|
|
889
|
+
if (firstRenderedElement == null ? void 0 : firstRenderedElement.executedVersion) {
|
|
890
|
+
const firstRenderedVelesNode = getExecutedComponentVelesNode(
|
|
891
|
+
firstRenderedElement.executedVersion
|
|
892
|
+
);
|
|
893
|
+
firstRenderedVelesNode.html.before(existingElementNode.html);
|
|
594
894
|
} else {
|
|
595
|
-
const firstRenderedElement = (_c = renderedElements[0]) == null ? void 0 : _c[0];
|
|
596
|
-
if (firstRenderedElement) {
|
|
597
|
-
const { velesElementNode: firstRenderedVelesNode } = getComponentVelesNode(firstRenderedElement);
|
|
598
|
-
firstRenderedVelesNode.html.before(newNodeVelesElement.html);
|
|
599
|
-
} else {
|
|
600
|
-
parentVelesElement.html.prepend(newNodeVelesElement.html);
|
|
601
|
-
}
|
|
602
895
|
}
|
|
603
|
-
offset = offset + 1;
|
|
604
|
-
currentElement = newNodeVelesElement.html;
|
|
605
|
-
newElementsCount = newElementsCount + 1;
|
|
606
|
-
callMountHandlers(newNode);
|
|
607
896
|
}
|
|
608
|
-
|
|
609
|
-
|
|
897
|
+
currentElement = existingElementNode.html;
|
|
898
|
+
offset = offset - 1;
|
|
899
|
+
}
|
|
900
|
+
} else {
|
|
901
|
+
const newNodeVelesElement = getExecutedComponentVelesNode(
|
|
902
|
+
newNode.executedVersion
|
|
903
|
+
);
|
|
904
|
+
newNodeVelesElement.parentVelesElement = parentVelesElement;
|
|
905
|
+
if (currentElement) {
|
|
906
|
+
currentElement.after(newNodeVelesElement.html);
|
|
610
907
|
} else {
|
|
611
|
-
renderedElements
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
(childComponent) => childComponent !== oldNode
|
|
621
|
-
);
|
|
622
|
-
} else {
|
|
623
|
-
throw new Error("Wrapper iterator element is a string");
|
|
624
|
-
}
|
|
625
|
-
}
|
|
626
|
-
});
|
|
908
|
+
const firstRenderedElement = (_c = renderedElements[0]) == null ? void 0 : _c[0];
|
|
909
|
+
if (firstRenderedElement == null ? void 0 : firstRenderedElement.executedVersion) {
|
|
910
|
+
const firstRenderedVelesNode = getExecutedComponentVelesNode(
|
|
911
|
+
firstRenderedElement.executedVersion
|
|
912
|
+
);
|
|
913
|
+
firstRenderedVelesNode.html.before(newNodeVelesElement.html);
|
|
914
|
+
} else {
|
|
915
|
+
parentVelesElement.html.prepend(newNodeVelesElement.html);
|
|
916
|
+
}
|
|
627
917
|
}
|
|
628
|
-
|
|
629
|
-
|
|
918
|
+
offset = offset + 1;
|
|
919
|
+
currentElement = newNodeVelesElement.html;
|
|
920
|
+
newElementsCount = newElementsCount + 1;
|
|
921
|
+
callMountHandlers(newNode.executedVersion);
|
|
630
922
|
}
|
|
631
923
|
});
|
|
924
|
+
if (renderedElements.length === newRenderedElements.length + newElementsCount) {
|
|
925
|
+
} else {
|
|
926
|
+
renderedElements.forEach(([oldNode, calculatedKey]) => {
|
|
927
|
+
if (renderedExistingElements[calculatedKey] === true) {
|
|
928
|
+
return;
|
|
929
|
+
} else {
|
|
930
|
+
const oldRenderedVelesNode = getExecutedComponentVelesNode(
|
|
931
|
+
oldNode.executedVersion
|
|
932
|
+
);
|
|
933
|
+
oldRenderedVelesNode.html.remove();
|
|
934
|
+
callUnmountHandlers(oldNode.executedVersion);
|
|
935
|
+
if ("executedVelesNode" in wrapperVelesElementNode) {
|
|
936
|
+
wrapperVelesElementNode.childComponents = wrapperVelesElementNode.childComponents.filter(
|
|
937
|
+
(childComponent) => childComponent !== oldNode.executedVersion
|
|
938
|
+
);
|
|
939
|
+
} else {
|
|
940
|
+
throw new Error("Wrapper iterator element is a string");
|
|
941
|
+
}
|
|
942
|
+
if ("velesNode" in wrapperComponent) {
|
|
943
|
+
wrapperComponent.childComponents = wrapperComponent.childComponents.filter(
|
|
944
|
+
(childComponent) => childComponent !== oldNode
|
|
945
|
+
);
|
|
946
|
+
}
|
|
947
|
+
}
|
|
948
|
+
});
|
|
949
|
+
}
|
|
950
|
+
if ("executedVelesNode" in wrapperVelesElementNode) {
|
|
951
|
+
wrapperVelesElementNode.childComponents = newChildRenderedComponents;
|
|
952
|
+
}
|
|
953
|
+
if ("velesNode" in wrapperComponent) {
|
|
954
|
+
wrapperComponent.childComponents = newChildComponents;
|
|
955
|
+
}
|
|
956
|
+
trackingIterator.renderedElements = newRenderedElements;
|
|
957
|
+
trackingIterator.elementsByKey = newElementsByKey;
|
|
958
|
+
}
|
|
959
|
+
}
|
|
960
|
+
|
|
961
|
+
// src/create-state/trigger-updates.ts
|
|
962
|
+
function triggerUpdates({
|
|
963
|
+
value,
|
|
964
|
+
createState: createState2,
|
|
965
|
+
trackers,
|
|
966
|
+
getValue
|
|
967
|
+
}) {
|
|
968
|
+
const newTrackingSelectorElements = [];
|
|
969
|
+
trackers.trackingSelectorElements.forEach(
|
|
970
|
+
(selectorTrackingElement) => updateUseValueSelector({
|
|
971
|
+
value,
|
|
972
|
+
selectorTrackingElement,
|
|
973
|
+
newTrackingSelectorElements,
|
|
974
|
+
trackers,
|
|
975
|
+
getValue
|
|
976
|
+
})
|
|
977
|
+
);
|
|
978
|
+
trackers.trackingSelectorElements = unique(
|
|
979
|
+
trackers.trackingSelectorElements.concat(newTrackingSelectorElements)
|
|
980
|
+
);
|
|
981
|
+
trackers.trackingAttributes.forEach((element) => {
|
|
982
|
+
updateUseAttributeValue({ element, value });
|
|
983
|
+
});
|
|
984
|
+
trackers.trackingEffects.forEach((trackingEffect) => {
|
|
985
|
+
const { cb, selectedValue, selector, comparator } = trackingEffect;
|
|
986
|
+
const newSelectedValue = selector ? selector(value) : value;
|
|
987
|
+
if (comparator ? comparator(selectedValue, newSelectedValue) : selectedValue === newSelectedValue) {
|
|
988
|
+
return;
|
|
989
|
+
}
|
|
990
|
+
cb(newSelectedValue);
|
|
991
|
+
trackingEffect.selectedValue = newSelectedValue;
|
|
992
|
+
});
|
|
993
|
+
trackers.trackingIterators.forEach((trackingIterator) => {
|
|
994
|
+
updateUseValueIteratorValue({ value, trackingIterator, createState: createState2 });
|
|
995
|
+
});
|
|
996
|
+
}
|
|
997
|
+
|
|
998
|
+
// src/create-state/index.ts
|
|
999
|
+
function createState(initialValue, subscribeCallback) {
|
|
1000
|
+
let value = initialValue;
|
|
1001
|
+
let previousValue = void 0;
|
|
1002
|
+
const trackers = {
|
|
1003
|
+
trackingEffects: [],
|
|
1004
|
+
trackingSelectorElements: [],
|
|
1005
|
+
trackingAttributes: [],
|
|
1006
|
+
trackingIterators: []
|
|
632
1007
|
};
|
|
633
1008
|
const result = {
|
|
634
1009
|
// supposed to be used at the component level
|
|
@@ -637,7 +1012,7 @@ function createState(initialValue, subscribeCallback) {
|
|
|
637
1012
|
},
|
|
638
1013
|
trackValueSelector(selector, cb, options = {}) {
|
|
639
1014
|
const trackedValue = selector ? selector(value) : value;
|
|
640
|
-
trackingEffects.push({
|
|
1015
|
+
trackers.trackingEffects.push({
|
|
641
1016
|
cb,
|
|
642
1017
|
selector,
|
|
643
1018
|
comparator: options.comparator,
|
|
@@ -653,7 +1028,7 @@ function createState(initialValue, subscribeCallback) {
|
|
|
653
1028
|
}
|
|
654
1029
|
}
|
|
655
1030
|
onUnmount(() => {
|
|
656
|
-
trackingEffects = trackingEffects.filter(
|
|
1031
|
+
trackers.trackingEffects = trackers.trackingEffects.filter(
|
|
657
1032
|
(trackingCallback) => trackingCallback.cb !== cb
|
|
658
1033
|
);
|
|
659
1034
|
});
|
|
@@ -663,70 +1038,79 @@ function createState(initialValue, subscribeCallback) {
|
|
|
663
1038
|
},
|
|
664
1039
|
useValueSelector(selector, cb, comparator = identity) {
|
|
665
1040
|
const selectedValue = selector ? selector(value) : value;
|
|
666
|
-
const returnedNode = cb ? cb(selectedValue) : String(selectedValue);
|
|
1041
|
+
const returnedNode = cb ? cb(selectedValue) : selectedValue == void 0 ? "" : String(selectedValue);
|
|
667
1042
|
const node = !returnedNode || typeof returnedNode === "string" ? createTextElement(returnedNode) : returnedNode;
|
|
1043
|
+
const currentContext2 = getCurrentContext();
|
|
1044
|
+
node.needExecutedVersion = true;
|
|
668
1045
|
const trackingSelectorElement = {
|
|
669
1046
|
selector,
|
|
670
1047
|
selectedValue,
|
|
671
1048
|
cb,
|
|
672
1049
|
node,
|
|
673
|
-
comparator
|
|
1050
|
+
comparator,
|
|
1051
|
+
savedContext: currentContext2
|
|
674
1052
|
};
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
1053
|
+
addUseValueMountHandler({
|
|
1054
|
+
usedValue: value,
|
|
1055
|
+
getValue: () => value,
|
|
1056
|
+
trackers,
|
|
1057
|
+
trackingSelectorElement
|
|
680
1058
|
});
|
|
681
1059
|
return node;
|
|
682
1060
|
},
|
|
683
1061
|
useValueIterator(options, cb) {
|
|
684
|
-
const
|
|
685
|
-
const elementsByKey = {};
|
|
686
|
-
const elements = options.selector ? options.selector(value) : value;
|
|
687
|
-
if (!Array.isArray(elements)) {
|
|
688
|
-
console.error("useValueIterator received non-array value");
|
|
689
|
-
return null;
|
|
690
|
-
}
|
|
691
|
-
elements.forEach((element, index) => {
|
|
692
|
-
let calculatedKey = "";
|
|
693
|
-
if (typeof options.key === "string" && typeof element === "object" && element !== null && options.key in element) {
|
|
694
|
-
calculatedKey = element[options.key];
|
|
695
|
-
} else if (typeof options.key === "function") {
|
|
696
|
-
calculatedKey = options.key({ element, index });
|
|
697
|
-
} else {
|
|
698
|
-
}
|
|
699
|
-
const elementState = createState(element);
|
|
700
|
-
const indexState = createState(index);
|
|
701
|
-
if (!calculatedKey) {
|
|
702
|
-
return;
|
|
703
|
-
}
|
|
704
|
-
let node = cb({ elementState, indexState });
|
|
705
|
-
elementsByKey[calculatedKey] = {
|
|
706
|
-
node,
|
|
707
|
-
indexState,
|
|
708
|
-
indexValue: index,
|
|
709
|
-
elementState
|
|
710
|
-
};
|
|
711
|
-
children.push([node, calculatedKey, elementState]);
|
|
712
|
-
});
|
|
1062
|
+
const currentContext2 = getCurrentContext();
|
|
713
1063
|
const trackingParams = {};
|
|
714
|
-
|
|
715
|
-
const wrapperComponent = createElement(() => {
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
1064
|
+
trackingParams.savedContext = currentContext2;
|
|
1065
|
+
const wrapperComponent = createElement((_props, componentAPI) => {
|
|
1066
|
+
const children = [];
|
|
1067
|
+
const elementsByKey = {};
|
|
1068
|
+
const elements = options.selector ? options.selector(value) : value;
|
|
1069
|
+
if (!Array.isArray(elements)) {
|
|
1070
|
+
console.error("useValueIterator received non-array value");
|
|
1071
|
+
return null;
|
|
1072
|
+
}
|
|
1073
|
+
elements.forEach((element, index) => {
|
|
1074
|
+
let calculatedKey = "";
|
|
1075
|
+
if (typeof options.key === "string" && typeof element === "object" && element !== null && options.key in element) {
|
|
1076
|
+
calculatedKey = element[options.key];
|
|
1077
|
+
} else if (typeof options.key === "function") {
|
|
1078
|
+
calculatedKey = options.key({ element, index });
|
|
1079
|
+
} else {
|
|
1080
|
+
}
|
|
1081
|
+
const elementState = createState(element);
|
|
1082
|
+
const indexState = createState(index);
|
|
1083
|
+
if (!calculatedKey) {
|
|
1084
|
+
return;
|
|
1085
|
+
}
|
|
1086
|
+
let node = cb({ elementState, indexState });
|
|
1087
|
+
node.needExecutedVersion = true;
|
|
1088
|
+
elementsByKey[calculatedKey] = {
|
|
1089
|
+
node,
|
|
1090
|
+
indexState,
|
|
1091
|
+
indexValue: index,
|
|
1092
|
+
elementState
|
|
1093
|
+
};
|
|
1094
|
+
children.push([node, calculatedKey, elementState]);
|
|
1095
|
+
});
|
|
1096
|
+
trackingParams.elementsByKey = elementsByKey;
|
|
1097
|
+
trackingParams.renderedElements = children;
|
|
1098
|
+
trackers.trackingIterators.push(trackingParams);
|
|
1099
|
+
onMount(() => {
|
|
1100
|
+
componentAPI.onUnmount(() => {
|
|
1101
|
+
trackers.trackingIterators = trackers.trackingIterators.filter(
|
|
1102
|
+
(currentTrackingParams) => currentTrackingParams !== trackingParams
|
|
1103
|
+
);
|
|
1104
|
+
});
|
|
720
1105
|
});
|
|
721
1106
|
return createElement("div", {
|
|
722
1107
|
phantom: true,
|
|
723
1108
|
children: children.map((child) => child[0])
|
|
724
1109
|
});
|
|
725
1110
|
});
|
|
1111
|
+
wrapperComponent.needExecutedVersion = true;
|
|
726
1112
|
trackingParams.cb = cb;
|
|
727
1113
|
trackingParams.key = options.key;
|
|
728
|
-
trackingParams.elementsByKey = elementsByKey;
|
|
729
|
-
trackingParams.renderedElements = children;
|
|
730
1114
|
trackingParams.wrapperComponent = wrapperComponent;
|
|
731
1115
|
if (options.selector) {
|
|
732
1116
|
trackingParams.selector = options.selector;
|
|
@@ -734,14 +1118,30 @@ function createState(initialValue, subscribeCallback) {
|
|
|
734
1118
|
return wrapperComponent;
|
|
735
1119
|
},
|
|
736
1120
|
useAttribute: (cb) => {
|
|
1121
|
+
const originalValue = value;
|
|
1122
|
+
let wasMounted = false;
|
|
737
1123
|
const attributeValue = cb ? cb(value) : value;
|
|
738
1124
|
const attributeHelper = (htmlElement, attributeName, node) => {
|
|
739
|
-
const trackingElement = {
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
1125
|
+
const trackingElement = {
|
|
1126
|
+
cb,
|
|
1127
|
+
htmlElement,
|
|
1128
|
+
attributeName,
|
|
1129
|
+
attributeValue
|
|
1130
|
+
};
|
|
1131
|
+
node._privateMethods._addMountHandler(() => {
|
|
1132
|
+
trackers.trackingAttributes.push(trackingElement);
|
|
1133
|
+
if (!wasMounted && value === originalValue) {
|
|
1134
|
+
} else {
|
|
1135
|
+
updateUseAttributeValue({ element: trackingElement, value });
|
|
1136
|
+
}
|
|
1137
|
+
if (!wasMounted) {
|
|
1138
|
+
wasMounted = true;
|
|
1139
|
+
}
|
|
1140
|
+
node._privateMethods._addUnmountHandler(() => {
|
|
1141
|
+
trackers.trackingAttributes = trackers.trackingAttributes.filter(
|
|
1142
|
+
(trackingAttribute) => trackingAttribute !== trackingElement
|
|
1143
|
+
);
|
|
1144
|
+
});
|
|
745
1145
|
});
|
|
746
1146
|
return attributeValue;
|
|
747
1147
|
};
|
|
@@ -766,7 +1166,7 @@ function createState(initialValue, subscribeCallback) {
|
|
|
766
1166
|
if (newValue !== value) {
|
|
767
1167
|
previousValue = value;
|
|
768
1168
|
value = newValue;
|
|
769
|
-
|
|
1169
|
+
triggerUpdates({ value, createState, trackers, getValue: () => value });
|
|
770
1170
|
}
|
|
771
1171
|
}
|
|
772
1172
|
};
|