veles 1.0.0-alpha.1 → 1.0.0-alpha.3
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/{_utils-BZ1SMqm2.js → _utils-CCdioDsh.js} +73 -25
- package/dist/{_utils-gPluq0AT.cjs → _utils-Cf3Xvo3q.cjs} +84 -24
- package/dist/{fragment-BdtgAtEr.d.ts → fragment-C16zCm8L.d.cts} +17 -15
- package/dist/{fragment-D252pobF.d.cts → fragment-yC0-T2O-.d.ts} +17 -15
- package/dist/index.cjs +39 -38
- package/dist/index.d.cts +17 -6
- package/dist/index.d.ts +17 -6
- package/dist/index.js +39 -38
- package/dist/jsx-runtime.cjs +1 -1
- package/dist/jsx-runtime.d.cts +1 -1
- package/dist/jsx-runtime.d.ts +1 -1
- package/dist/jsx-runtime.js +1 -1
- package/package.json +1 -1
|
@@ -168,12 +168,45 @@ function parseChildren({ children, htmlElement, velesNode, portal }) {
|
|
|
168
168
|
return childComponents;
|
|
169
169
|
}
|
|
170
170
|
//#endregion
|
|
171
|
+
//#region src/attribute-utils.ts
|
|
172
|
+
const ENUMERATED_BOOLEAN_ATTRIBUTES = {
|
|
173
|
+
draggable: {
|
|
174
|
+
trueValue: "true",
|
|
175
|
+
falseValue: "false"
|
|
176
|
+
},
|
|
177
|
+
contenteditable: {
|
|
178
|
+
trueValue: "true",
|
|
179
|
+
falseValue: "false"
|
|
180
|
+
},
|
|
181
|
+
spellcheck: {
|
|
182
|
+
trueValue: "true",
|
|
183
|
+
falseValue: "false"
|
|
184
|
+
},
|
|
185
|
+
translate: {
|
|
186
|
+
trueValue: "yes",
|
|
187
|
+
falseValue: "no"
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
function assignDomAttribute({ htmlElement, attributeName, value }) {
|
|
191
|
+
if (typeof value === "boolean") {
|
|
192
|
+
const enumeratedConfig = ENUMERATED_BOOLEAN_ATTRIBUTES[attributeName.toLowerCase()];
|
|
193
|
+
if (enumeratedConfig) {
|
|
194
|
+
htmlElement.setAttribute(attributeName, value ? enumeratedConfig.trueValue : enumeratedConfig.falseValue);
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
if (value) htmlElement.setAttribute(attributeName, "");
|
|
198
|
+
else htmlElement.removeAttribute(attributeName);
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
htmlElement.setAttribute(attributeName, value);
|
|
202
|
+
}
|
|
203
|
+
//#endregion
|
|
171
204
|
//#region src/create-element/assign-attributes.ts
|
|
172
205
|
function assignAttributes({ props, htmlElement, velesNode }) {
|
|
173
206
|
Object.entries(props).forEach(([key, value]) => {
|
|
174
|
-
if (typeof value === "
|
|
207
|
+
if (value && typeof value === "object" && value.velesAttribute === true) assignAttribute({
|
|
175
208
|
key,
|
|
176
|
-
value: value(htmlElement, key, velesNode),
|
|
209
|
+
value: value.getValue(htmlElement, key, velesNode),
|
|
177
210
|
htmlElement
|
|
178
211
|
});
|
|
179
212
|
else assignAttribute({
|
|
@@ -185,9 +218,11 @@ function assignAttributes({ props, htmlElement, velesNode }) {
|
|
|
185
218
|
}
|
|
186
219
|
function assignAttribute({ key, value, htmlElement }) {
|
|
187
220
|
if (typeof value === "function" && key.startsWith("on")) htmlElement.addEventListener(key.slice(2).toLocaleLowerCase(), value);
|
|
188
|
-
else
|
|
189
|
-
|
|
190
|
-
|
|
221
|
+
else assignDomAttribute({
|
|
222
|
+
htmlElement,
|
|
223
|
+
attributeName: key,
|
|
224
|
+
value
|
|
225
|
+
});
|
|
191
226
|
}
|
|
192
227
|
//#endregion
|
|
193
228
|
//#region src/create-element/create-element.ts
|
|
@@ -238,14 +273,14 @@ function createElement(element, props = {}) {
|
|
|
238
273
|
});
|
|
239
274
|
else portal.append(childComponent.html);
|
|
240
275
|
else if ("velesStringElement" in childComponent) portal.append(childComponent.html);
|
|
241
|
-
else appendComponentToPortal(getExecutedComponentVelesNode(childComponent
|
|
276
|
+
else appendComponentToPortal(getExecutedComponentVelesNode(getMountedNodeExecutedVersion(childComponent, "Portal child component is not mounted")), portal);
|
|
242
277
|
});
|
|
243
278
|
});
|
|
244
279
|
velesNode._privateMethods._addUnmountHandler(function removeNodeOnUnmount() {
|
|
245
280
|
velesNode.childComponents.forEach((childComponent) => {
|
|
246
281
|
if ("velesNode" in childComponent) childComponent.html.remove();
|
|
247
282
|
else if ("velesStringElement" in childComponent) childComponent.html.remove();
|
|
248
|
-
else cleanupComponentFromPortal(getExecutedComponentVelesNode(childComponent
|
|
283
|
+
else cleanupComponentFromPortal(getExecutedComponentVelesNode(getMountedNodeExecutedVersion(childComponent, "Portal child component is not mounted")));
|
|
249
284
|
});
|
|
250
285
|
});
|
|
251
286
|
}
|
|
@@ -309,8 +344,8 @@ function createContext() {
|
|
|
309
344
|
addContext,
|
|
310
345
|
readContext: () => {
|
|
311
346
|
const currentContext = publicContextStack[publicContextStack.length - 1];
|
|
312
|
-
if (!currentContext)
|
|
313
|
-
|
|
347
|
+
if (!currentContext) throw new Error("no Context currently available");
|
|
348
|
+
return currentContext[contextId];
|
|
314
349
|
}
|
|
315
350
|
};
|
|
316
351
|
}
|
|
@@ -374,21 +409,29 @@ function renderTree(component, { parentVelesElement } = {}) {
|
|
|
374
409
|
*/
|
|
375
410
|
if (parentVelesElement) newNode.parentVelesElement = parentVelesElement;
|
|
376
411
|
} else if (parentVelesElement) {
|
|
377
|
-
if (component.insertAfter) if ("velesComponentObject" in component.insertAfter)
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
}
|
|
412
|
+
if (component.insertAfter) if ("velesComponentObject" in component.insertAfter) {
|
|
413
|
+
const lastNode = insertNode({
|
|
414
|
+
velesElement: newNode,
|
|
415
|
+
adjacentNode: component.insertAfter.html ?? null,
|
|
416
|
+
parentVelesElement
|
|
417
|
+
});
|
|
418
|
+
if (lastNode) component.html = lastNode;
|
|
419
|
+
} else {
|
|
420
|
+
const lastNode = insertNode({
|
|
421
|
+
velesElement: newNode,
|
|
422
|
+
adjacentNode: component.insertAfter,
|
|
423
|
+
parentVelesElement
|
|
424
|
+
});
|
|
425
|
+
if (lastNode) component.html = lastNode;
|
|
426
|
+
}
|
|
427
|
+
else {
|
|
428
|
+
const lastNode = insertNode({
|
|
429
|
+
velesElement: newNode,
|
|
430
|
+
adjacentNode: null,
|
|
431
|
+
parentVelesElement
|
|
432
|
+
});
|
|
433
|
+
if (lastNode) component.html = lastNode;
|
|
434
|
+
}
|
|
392
435
|
newNode.parentVelesElement = parentVelesElement;
|
|
393
436
|
}
|
|
394
437
|
if (component.needExecutedVersion || component.portal) component.executedVersion = executedComponent;
|
|
@@ -405,6 +448,7 @@ function renderTree(component, { parentVelesElement } = {}) {
|
|
|
405
448
|
if (component.needExecutedVersion) component.executedVersion = executedNode;
|
|
406
449
|
return executedNode;
|
|
407
450
|
}
|
|
451
|
+
throw new Error("Unknown component type in renderTree");
|
|
408
452
|
}
|
|
409
453
|
function insertNode({ velesElement, adjacentNode, parentVelesElement }) {
|
|
410
454
|
if (velesElement.phantom) {
|
|
@@ -440,6 +484,10 @@ function insertNode({ velesElement, adjacentNode, parentVelesElement }) {
|
|
|
440
484
|
return velesElement.html;
|
|
441
485
|
}
|
|
442
486
|
}
|
|
487
|
+
function getMountedNodeExecutedVersion(node, errorMessage) {
|
|
488
|
+
if (!node.executedVersion) throw new Error(errorMessage || "Expected node to have executedVersion by this point");
|
|
489
|
+
return node.executedVersion;
|
|
490
|
+
}
|
|
443
491
|
function callMountHandlers(component) {
|
|
444
492
|
component._privateMethods._callMountHandlers();
|
|
445
493
|
if ("executedVelesStringElement" in component) return;
|
|
@@ -465,4 +513,4 @@ function unique(arr) {
|
|
|
465
513
|
return resultArr;
|
|
466
514
|
}
|
|
467
515
|
//#endregion
|
|
468
|
-
export {
|
|
516
|
+
export { onMount as _, identity as a, addPublicContext as c, popPublicContext as d, Fragment as f, hasCurrentLifecycleContext as g, createTextElement as h, getMountedNodeExecutedVersion as i, createContext as l, assignDomAttribute as m, callUnmountHandlers as n, renderTree as o, createElement as p, getExecutedComponentVelesNode as r, unique as s, callMountHandlers as t, getCurrentContext as u, onUnmount as v };
|
|
@@ -168,12 +168,45 @@ function parseChildren({ children, htmlElement, velesNode, portal }) {
|
|
|
168
168
|
return childComponents;
|
|
169
169
|
}
|
|
170
170
|
//#endregion
|
|
171
|
+
//#region src/attribute-utils.ts
|
|
172
|
+
const ENUMERATED_BOOLEAN_ATTRIBUTES = {
|
|
173
|
+
draggable: {
|
|
174
|
+
trueValue: "true",
|
|
175
|
+
falseValue: "false"
|
|
176
|
+
},
|
|
177
|
+
contenteditable: {
|
|
178
|
+
trueValue: "true",
|
|
179
|
+
falseValue: "false"
|
|
180
|
+
},
|
|
181
|
+
spellcheck: {
|
|
182
|
+
trueValue: "true",
|
|
183
|
+
falseValue: "false"
|
|
184
|
+
},
|
|
185
|
+
translate: {
|
|
186
|
+
trueValue: "yes",
|
|
187
|
+
falseValue: "no"
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
function assignDomAttribute({ htmlElement, attributeName, value }) {
|
|
191
|
+
if (typeof value === "boolean") {
|
|
192
|
+
const enumeratedConfig = ENUMERATED_BOOLEAN_ATTRIBUTES[attributeName.toLowerCase()];
|
|
193
|
+
if (enumeratedConfig) {
|
|
194
|
+
htmlElement.setAttribute(attributeName, value ? enumeratedConfig.trueValue : enumeratedConfig.falseValue);
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
if (value) htmlElement.setAttribute(attributeName, "");
|
|
198
|
+
else htmlElement.removeAttribute(attributeName);
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
htmlElement.setAttribute(attributeName, value);
|
|
202
|
+
}
|
|
203
|
+
//#endregion
|
|
171
204
|
//#region src/create-element/assign-attributes.ts
|
|
172
205
|
function assignAttributes({ props, htmlElement, velesNode }) {
|
|
173
206
|
Object.entries(props).forEach(([key, value]) => {
|
|
174
|
-
if (typeof value === "
|
|
207
|
+
if (value && typeof value === "object" && value.velesAttribute === true) assignAttribute({
|
|
175
208
|
key,
|
|
176
|
-
value: value(htmlElement, key, velesNode),
|
|
209
|
+
value: value.getValue(htmlElement, key, velesNode),
|
|
177
210
|
htmlElement
|
|
178
211
|
});
|
|
179
212
|
else assignAttribute({
|
|
@@ -185,9 +218,11 @@ function assignAttributes({ props, htmlElement, velesNode }) {
|
|
|
185
218
|
}
|
|
186
219
|
function assignAttribute({ key, value, htmlElement }) {
|
|
187
220
|
if (typeof value === "function" && key.startsWith("on")) htmlElement.addEventListener(key.slice(2).toLocaleLowerCase(), value);
|
|
188
|
-
else
|
|
189
|
-
|
|
190
|
-
|
|
221
|
+
else assignDomAttribute({
|
|
222
|
+
htmlElement,
|
|
223
|
+
attributeName: key,
|
|
224
|
+
value
|
|
225
|
+
});
|
|
191
226
|
}
|
|
192
227
|
//#endregion
|
|
193
228
|
//#region src/create-element/create-element.ts
|
|
@@ -238,14 +273,14 @@ function createElement(element, props = {}) {
|
|
|
238
273
|
});
|
|
239
274
|
else portal.append(childComponent.html);
|
|
240
275
|
else if ("velesStringElement" in childComponent) portal.append(childComponent.html);
|
|
241
|
-
else appendComponentToPortal(getExecutedComponentVelesNode(childComponent
|
|
276
|
+
else appendComponentToPortal(getExecutedComponentVelesNode(getMountedNodeExecutedVersion(childComponent, "Portal child component is not mounted")), portal);
|
|
242
277
|
});
|
|
243
278
|
});
|
|
244
279
|
velesNode._privateMethods._addUnmountHandler(function removeNodeOnUnmount() {
|
|
245
280
|
velesNode.childComponents.forEach((childComponent) => {
|
|
246
281
|
if ("velesNode" in childComponent) childComponent.html.remove();
|
|
247
282
|
else if ("velesStringElement" in childComponent) childComponent.html.remove();
|
|
248
|
-
else cleanupComponentFromPortal(getExecutedComponentVelesNode(childComponent
|
|
283
|
+
else cleanupComponentFromPortal(getExecutedComponentVelesNode(getMountedNodeExecutedVersion(childComponent, "Portal child component is not mounted")));
|
|
249
284
|
});
|
|
250
285
|
});
|
|
251
286
|
}
|
|
@@ -309,8 +344,8 @@ function createContext() {
|
|
|
309
344
|
addContext,
|
|
310
345
|
readContext: () => {
|
|
311
346
|
const currentContext = publicContextStack[publicContextStack.length - 1];
|
|
312
|
-
if (!currentContext)
|
|
313
|
-
|
|
347
|
+
if (!currentContext) throw new Error("no Context currently available");
|
|
348
|
+
return currentContext[contextId];
|
|
314
349
|
}
|
|
315
350
|
};
|
|
316
351
|
}
|
|
@@ -374,21 +409,29 @@ function renderTree(component, { parentVelesElement } = {}) {
|
|
|
374
409
|
*/
|
|
375
410
|
if (parentVelesElement) newNode.parentVelesElement = parentVelesElement;
|
|
376
411
|
} else if (parentVelesElement) {
|
|
377
|
-
if (component.insertAfter) if ("velesComponentObject" in component.insertAfter)
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
}
|
|
412
|
+
if (component.insertAfter) if ("velesComponentObject" in component.insertAfter) {
|
|
413
|
+
const lastNode = insertNode({
|
|
414
|
+
velesElement: newNode,
|
|
415
|
+
adjacentNode: component.insertAfter.html ?? null,
|
|
416
|
+
parentVelesElement
|
|
417
|
+
});
|
|
418
|
+
if (lastNode) component.html = lastNode;
|
|
419
|
+
} else {
|
|
420
|
+
const lastNode = insertNode({
|
|
421
|
+
velesElement: newNode,
|
|
422
|
+
adjacentNode: component.insertAfter,
|
|
423
|
+
parentVelesElement
|
|
424
|
+
});
|
|
425
|
+
if (lastNode) component.html = lastNode;
|
|
426
|
+
}
|
|
427
|
+
else {
|
|
428
|
+
const lastNode = insertNode({
|
|
429
|
+
velesElement: newNode,
|
|
430
|
+
adjacentNode: null,
|
|
431
|
+
parentVelesElement
|
|
432
|
+
});
|
|
433
|
+
if (lastNode) component.html = lastNode;
|
|
434
|
+
}
|
|
392
435
|
newNode.parentVelesElement = parentVelesElement;
|
|
393
436
|
}
|
|
394
437
|
if (component.needExecutedVersion || component.portal) component.executedVersion = executedComponent;
|
|
@@ -405,6 +448,7 @@ function renderTree(component, { parentVelesElement } = {}) {
|
|
|
405
448
|
if (component.needExecutedVersion) component.executedVersion = executedNode;
|
|
406
449
|
return executedNode;
|
|
407
450
|
}
|
|
451
|
+
throw new Error("Unknown component type in renderTree");
|
|
408
452
|
}
|
|
409
453
|
function insertNode({ velesElement, adjacentNode, parentVelesElement }) {
|
|
410
454
|
if (velesElement.phantom) {
|
|
@@ -440,6 +484,10 @@ function insertNode({ velesElement, adjacentNode, parentVelesElement }) {
|
|
|
440
484
|
return velesElement.html;
|
|
441
485
|
}
|
|
442
486
|
}
|
|
487
|
+
function getMountedNodeExecutedVersion(node, errorMessage) {
|
|
488
|
+
if (!node.executedVersion) throw new Error(errorMessage || "Expected node to have executedVersion by this point");
|
|
489
|
+
return node.executedVersion;
|
|
490
|
+
}
|
|
443
491
|
function callMountHandlers(component) {
|
|
444
492
|
component._privateMethods._callMountHandlers();
|
|
445
493
|
if ("executedVelesStringElement" in component) return;
|
|
@@ -477,6 +525,12 @@ Object.defineProperty(exports, "addPublicContext", {
|
|
|
477
525
|
return addPublicContext;
|
|
478
526
|
}
|
|
479
527
|
});
|
|
528
|
+
Object.defineProperty(exports, "assignDomAttribute", {
|
|
529
|
+
enumerable: true,
|
|
530
|
+
get: function() {
|
|
531
|
+
return assignDomAttribute;
|
|
532
|
+
}
|
|
533
|
+
});
|
|
480
534
|
Object.defineProperty(exports, "callMountHandlers", {
|
|
481
535
|
enumerable: true,
|
|
482
536
|
get: function() {
|
|
@@ -519,6 +573,12 @@ Object.defineProperty(exports, "getExecutedComponentVelesNode", {
|
|
|
519
573
|
return getExecutedComponentVelesNode;
|
|
520
574
|
}
|
|
521
575
|
});
|
|
576
|
+
Object.defineProperty(exports, "getMountedNodeExecutedVersion", {
|
|
577
|
+
enumerable: true,
|
|
578
|
+
get: function() {
|
|
579
|
+
return getMountedNodeExecutedVersion;
|
|
580
|
+
}
|
|
581
|
+
});
|
|
522
582
|
Object.defineProperty(exports, "hasCurrentLifecycleContext", {
|
|
523
583
|
enumerable: true,
|
|
524
584
|
get: function() {
|
|
@@ -353,8 +353,9 @@ declare namespace JSX {
|
|
|
353
353
|
z?: number | string | undefined | AttributeHelper<number | string | undefined>;
|
|
354
354
|
zoomAndPan?: string | undefined | AttributeHelper<string | undefined>;
|
|
355
355
|
}
|
|
356
|
-
export type TargetedEvent<Target extends EventTarget = EventTarget, TypedEvent extends Event = Event> = Omit<TypedEvent, "currentTarget"> & {
|
|
356
|
+
export type TargetedEvent<Target extends EventTarget = EventTarget, TypedEvent extends Event = Event> = Omit<TypedEvent, "currentTarget" | "target"> & {
|
|
357
357
|
readonly currentTarget: Target;
|
|
358
|
+
readonly target: Target;
|
|
358
359
|
};
|
|
359
360
|
export type TargetedAnimationEvent<Target extends EventTarget> = TargetedEvent<Target, AnimationEvent>;
|
|
360
361
|
export type TargetedClipboardEvent<Target extends EventTarget> = TargetedEvent<Target, ClipboardEvent>;
|
|
@@ -1494,33 +1495,33 @@ type ExecutedVelesComponent = {
|
|
|
1494
1495
|
};
|
|
1495
1496
|
// all supported child options
|
|
1496
1497
|
type velesChild = string | number | VelesElement | VelesComponentObject | VelesStringElement;
|
|
1497
|
-
type
|
|
1498
|
-
type
|
|
1498
|
+
type VelesMaybeChild = velesChild | undefined | null;
|
|
1499
|
+
type VelesChildren = VelesMaybeChild | VelesMaybeChild[];
|
|
1500
|
+
type VelesBaseProps = {
|
|
1499
1501
|
children?: VelesChildren;
|
|
1500
1502
|
ref?: {
|
|
1501
1503
|
velesRef: true;
|
|
1502
1504
|
current: any;
|
|
1503
1505
|
};
|
|
1504
|
-
portal?: HTMLElement;
|
|
1505
|
-
//
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
} & JSX.HTMLAttributes;
|
|
1506
|
+
portal?: HTMLElement;
|
|
1507
|
+
phantom?: boolean; // Custom data-* attributes used widely in tests/apps.
|
|
1508
|
+
[dataAttribute: `data-${string}`]: unknown;
|
|
1509
|
+
};
|
|
1510
|
+
type VelesElementProps = VelesBaseProps & JSX.HTMLAttributes;
|
|
1510
1511
|
type ComponentAPI = {
|
|
1511
1512
|
// You can return a function from the mount callback, and it will be
|
|
1512
1513
|
// automatically registered as `onUnmount` callback
|
|
1513
1514
|
onMount: (cb: Function) => void | Function;
|
|
1514
1515
|
onUnmount: (cb: Function) => void;
|
|
1515
1516
|
};
|
|
1516
|
-
type ComponentFunction = (props:
|
|
1517
|
+
type ComponentFunction<Props extends object = VelesElementProps> = (props: Props, componentAPI: ComponentAPI) => VelesElement | VelesComponentObject | VelesStringElement | string | null;
|
|
1517
1518
|
type AttributeHelper<T> = {
|
|
1518
|
-
|
|
1519
|
-
|
|
1519
|
+
velesAttribute: true;
|
|
1520
|
+
getValue: (htmlElement: HTMLElement, attributeName: string, node: VelesElement) => T;
|
|
1520
1521
|
};
|
|
1521
1522
|
type VelesComponentObject = {
|
|
1522
1523
|
velesComponentObject: true;
|
|
1523
|
-
element: ComponentFunction
|
|
1524
|
+
element: ComponentFunction<any>;
|
|
1524
1525
|
props: VelesElementProps;
|
|
1525
1526
|
insertAfter?: VelesComponentObject | HTMLElement | Text | null;
|
|
1526
1527
|
html?: HTMLElement | Text;
|
|
@@ -1537,13 +1538,14 @@ type VelesComponentObject = {
|
|
|
1537
1538
|
};
|
|
1538
1539
|
//#endregion
|
|
1539
1540
|
//#region src/create-element/create-element.d.ts
|
|
1540
|
-
declare function createElement(element:
|
|
1541
|
+
declare function createElement<Tag extends keyof JSX.IntrinsicElements>(element: Tag, props?: VelesBaseProps & JSX.IntrinsicElements[Tag]): VelesElement;
|
|
1542
|
+
declare function createElement<Props extends object>(element: ComponentFunction<Props>, props?: Props): VelesComponentObject;
|
|
1541
1543
|
//#endregion
|
|
1542
1544
|
//#region src/fragment.d.ts
|
|
1543
1545
|
declare function Fragment({
|
|
1544
1546
|
children
|
|
1545
1547
|
}: {
|
|
1546
1548
|
children?: VelesChildren;
|
|
1547
|
-
}): VelesElement
|
|
1549
|
+
}): VelesElement;
|
|
1548
1550
|
//#endregion
|
|
1549
1551
|
export { VelesComponentObject as a, JSX as c, VelesChildren as i, createElement as n, VelesElement as o, AttributeHelper as r, VelesStringElement as s, Fragment as t };
|
|
@@ -353,8 +353,9 @@ declare namespace JSX {
|
|
|
353
353
|
z?: number | string | undefined | AttributeHelper<number | string | undefined>;
|
|
354
354
|
zoomAndPan?: string | undefined | AttributeHelper<string | undefined>;
|
|
355
355
|
}
|
|
356
|
-
export type TargetedEvent<Target extends EventTarget = EventTarget, TypedEvent extends Event = Event> = Omit<TypedEvent, "currentTarget"> & {
|
|
356
|
+
export type TargetedEvent<Target extends EventTarget = EventTarget, TypedEvent extends Event = Event> = Omit<TypedEvent, "currentTarget" | "target"> & {
|
|
357
357
|
readonly currentTarget: Target;
|
|
358
|
+
readonly target: Target;
|
|
358
359
|
};
|
|
359
360
|
export type TargetedAnimationEvent<Target extends EventTarget> = TargetedEvent<Target, AnimationEvent>;
|
|
360
361
|
export type TargetedClipboardEvent<Target extends EventTarget> = TargetedEvent<Target, ClipboardEvent>;
|
|
@@ -1494,33 +1495,33 @@ type ExecutedVelesComponent = {
|
|
|
1494
1495
|
};
|
|
1495
1496
|
// all supported child options
|
|
1496
1497
|
type velesChild = string | number | VelesElement | VelesComponentObject | VelesStringElement;
|
|
1497
|
-
type
|
|
1498
|
-
type
|
|
1498
|
+
type VelesMaybeChild = velesChild | undefined | null;
|
|
1499
|
+
type VelesChildren = VelesMaybeChild | VelesMaybeChild[];
|
|
1500
|
+
type VelesBaseProps = {
|
|
1499
1501
|
children?: VelesChildren;
|
|
1500
1502
|
ref?: {
|
|
1501
1503
|
velesRef: true;
|
|
1502
1504
|
current: any;
|
|
1503
1505
|
};
|
|
1504
|
-
portal?: HTMLElement;
|
|
1505
|
-
//
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
} & JSX.HTMLAttributes;
|
|
1506
|
+
portal?: HTMLElement;
|
|
1507
|
+
phantom?: boolean; // Custom data-* attributes used widely in tests/apps.
|
|
1508
|
+
[dataAttribute: `data-${string}`]: unknown;
|
|
1509
|
+
};
|
|
1510
|
+
type VelesElementProps = VelesBaseProps & JSX.HTMLAttributes;
|
|
1510
1511
|
type ComponentAPI = {
|
|
1511
1512
|
// You can return a function from the mount callback, and it will be
|
|
1512
1513
|
// automatically registered as `onUnmount` callback
|
|
1513
1514
|
onMount: (cb: Function) => void | Function;
|
|
1514
1515
|
onUnmount: (cb: Function) => void;
|
|
1515
1516
|
};
|
|
1516
|
-
type ComponentFunction = (props:
|
|
1517
|
+
type ComponentFunction<Props extends object = VelesElementProps> = (props: Props, componentAPI: ComponentAPI) => VelesElement | VelesComponentObject | VelesStringElement | string | null;
|
|
1517
1518
|
type AttributeHelper<T> = {
|
|
1518
|
-
|
|
1519
|
-
|
|
1519
|
+
velesAttribute: true;
|
|
1520
|
+
getValue: (htmlElement: HTMLElement, attributeName: string, node: VelesElement) => T;
|
|
1520
1521
|
};
|
|
1521
1522
|
type VelesComponentObject = {
|
|
1522
1523
|
velesComponentObject: true;
|
|
1523
|
-
element: ComponentFunction
|
|
1524
|
+
element: ComponentFunction<any>;
|
|
1524
1525
|
props: VelesElementProps;
|
|
1525
1526
|
insertAfter?: VelesComponentObject | HTMLElement | Text | null;
|
|
1526
1527
|
html?: HTMLElement | Text;
|
|
@@ -1537,13 +1538,14 @@ type VelesComponentObject = {
|
|
|
1537
1538
|
};
|
|
1538
1539
|
//#endregion
|
|
1539
1540
|
//#region src/create-element/create-element.d.ts
|
|
1540
|
-
declare function createElement(element:
|
|
1541
|
+
declare function createElement<Tag extends keyof JSX.IntrinsicElements>(element: Tag, props?: VelesBaseProps & JSX.IntrinsicElements[Tag]): VelesElement;
|
|
1542
|
+
declare function createElement<Props extends object>(element: ComponentFunction<Props>, props?: Props): VelesComponentObject;
|
|
1541
1543
|
//#endregion
|
|
1542
1544
|
//#region src/fragment.d.ts
|
|
1543
1545
|
declare function Fragment({
|
|
1544
1546
|
children
|
|
1545
1547
|
}: {
|
|
1546
1548
|
children?: VelesChildren;
|
|
1547
|
-
}): VelesElement
|
|
1549
|
+
}): VelesElement;
|
|
1548
1550
|
//#endregion
|
|
1549
1551
|
export { VelesComponentObject as a, JSX as c, VelesChildren as i, createElement as n, VelesElement as o, AttributeHelper as r, VelesStringElement as s, Fragment as t };
|
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require__utils = require("./_utils-
|
|
2
|
+
const require__utils = require("./_utils-Cf3Xvo3q.cjs");
|
|
3
3
|
//#region src/attach-component.ts
|
|
4
4
|
/**
|
|
5
5
|
* Attach Veles component tree to a regular HTML node.
|
|
@@ -186,15 +186,17 @@ function addUseValueMountHandler({ usedValue, get, trackers, trackingSelectorEle
|
|
|
186
186
|
function updateUseAttributeValue({ element, value }) {
|
|
187
187
|
const { cb, htmlElement, attributeName, attributeValue } = element;
|
|
188
188
|
const newAttributeValue = cb ? cb(value) : value;
|
|
189
|
-
if (
|
|
190
|
-
else htmlElement.removeAttribute(attributeName);
|
|
191
|
-
else if (attributeName.startsWith("on")) {
|
|
189
|
+
if (attributeName.startsWith("on")) {
|
|
192
190
|
if (attributeValue === newAttributeValue) return;
|
|
193
191
|
const eventName = attributeName.slice(2).toLocaleLowerCase();
|
|
194
192
|
if (attributeValue) htmlElement.removeEventListener(eventName, attributeValue);
|
|
195
193
|
if (newAttributeValue && typeof newAttributeValue === "function") htmlElement.addEventListener(eventName, newAttributeValue);
|
|
196
194
|
element.attributeValue = newAttributeValue;
|
|
197
|
-
} else
|
|
195
|
+
} else require__utils.assignDomAttribute({
|
|
196
|
+
htmlElement,
|
|
197
|
+
attributeName,
|
|
198
|
+
value: newAttributeValue
|
|
199
|
+
});
|
|
198
200
|
}
|
|
199
201
|
//#endregion
|
|
200
202
|
//#region src/create-state/update-render-each-value.ts
|
|
@@ -204,11 +206,7 @@ function updateUseValueIteratorValue({ value, trackingIterator, createState }) {
|
|
|
204
206
|
console.error("there is no wrapper component for the iterator");
|
|
205
207
|
return;
|
|
206
208
|
}
|
|
207
|
-
|
|
208
|
-
console.error("it seems the wrapper component was not mounted");
|
|
209
|
-
return;
|
|
210
|
-
}
|
|
211
|
-
const wrapperVelesElementNode = require__utils.getExecutedComponentVelesNode(wrapperComponent.executedVersion);
|
|
209
|
+
const wrapperVelesElementNode = require__utils.getExecutedComponentVelesNode(require__utils.getMountedNodeExecutedVersion(wrapperComponent, "Iterator wrapper is expected to be mounted"));
|
|
212
210
|
const parentVelesElement = wrapperVelesElementNode.parentVelesElement;
|
|
213
211
|
if (!parentVelesElement) {
|
|
214
212
|
console.error("there is no parent Veles node for the iterator wrapper");
|
|
@@ -273,13 +271,13 @@ function updateUseValueIteratorValue({ value, trackingIterator, createState }) {
|
|
|
273
271
|
let offset = 0;
|
|
274
272
|
let currentElement = null;
|
|
275
273
|
newRenderedElements.forEach((newRenderedElement, index) => {
|
|
276
|
-
newChildRenderedComponents.push(newRenderedElement[0]
|
|
274
|
+
newChildRenderedComponents.push(require__utils.getMountedNodeExecutedVersion(newRenderedElement[0], "Iterator child is expected to be mounted"));
|
|
277
275
|
newChildComponents.push(newRenderedElement[0]);
|
|
278
276
|
if (positioningOffset[index]) offset = offset + positioningOffset[index];
|
|
279
277
|
const [newNode, calculatedKey, newState] = newRenderedElement;
|
|
280
278
|
const existingElement = elementsByKey[calculatedKey];
|
|
281
279
|
if (existingElement) {
|
|
282
|
-
const existingElementNode = require__utils.getExecutedComponentVelesNode(existingElement.node
|
|
280
|
+
const existingElementNode = require__utils.getExecutedComponentVelesNode(require__utils.getMountedNodeExecutedVersion(existingElement.node, "Existing iterator node is expected to be mounted"));
|
|
283
281
|
if (existingElement.indexValue + offset === index) {
|
|
284
282
|
currentElement = existingElementNode.html;
|
|
285
283
|
return;
|
|
@@ -306,7 +304,8 @@ function updateUseValueIteratorValue({ value, trackingIterator, createState }) {
|
|
|
306
304
|
offset = offset - 1;
|
|
307
305
|
}
|
|
308
306
|
} else {
|
|
309
|
-
const
|
|
307
|
+
const newNodeExecutedVersion = require__utils.getMountedNodeExecutedVersion(newNode, "New iterator node is expected to be mounted");
|
|
308
|
+
const newNodeVelesElement = require__utils.getExecutedComponentVelesNode(newNodeExecutedVersion);
|
|
310
309
|
newNodeVelesElement.parentVelesElement = parentVelesElement;
|
|
311
310
|
if (currentElement) currentElement.after(newNodeVelesElement.html);
|
|
312
311
|
else {
|
|
@@ -317,15 +316,16 @@ function updateUseValueIteratorValue({ value, trackingIterator, createState }) {
|
|
|
317
316
|
offset = offset + 1;
|
|
318
317
|
currentElement = newNodeVelesElement.html;
|
|
319
318
|
newElementsCount = newElementsCount + 1;
|
|
320
|
-
require__utils.callMountHandlers(
|
|
319
|
+
require__utils.callMountHandlers(newNodeExecutedVersion);
|
|
321
320
|
}
|
|
322
321
|
});
|
|
323
322
|
if (renderedElements.length === newRenderedElements.length + newElementsCount) {} else renderedElements.forEach(([oldNode, calculatedKey]) => {
|
|
324
323
|
if (renderedExistingElements[calculatedKey] === true) return;
|
|
325
324
|
else {
|
|
326
|
-
require__utils.
|
|
327
|
-
require__utils.
|
|
328
|
-
|
|
325
|
+
const oldNodeExecutedVersion = require__utils.getMountedNodeExecutedVersion(oldNode, "Removed iterator node is expected to be mounted");
|
|
326
|
+
require__utils.getExecutedComponentVelesNode(oldNodeExecutedVersion).html.remove();
|
|
327
|
+
require__utils.callUnmountHandlers(oldNodeExecutedVersion);
|
|
328
|
+
if ("executedVelesNode" in wrapperVelesElementNode) wrapperVelesElementNode.childComponents = wrapperVelesElementNode.childComponents.filter((childComponent) => childComponent !== oldNodeExecutedVersion);
|
|
329
329
|
else throw new Error("Wrapper iterator element is a string");
|
|
330
330
|
if ("velesNode" in wrapperComponent) wrapperComponent.childComponents = wrapperComponent.childComponents.filter((childComponent) => childComponent !== oldNode);
|
|
331
331
|
}
|
|
@@ -608,7 +608,7 @@ function createStateFromCore(core, subscribeCallback) {
|
|
|
608
608
|
});
|
|
609
609
|
const result = {
|
|
610
610
|
track: (cb, options = {}) => {
|
|
611
|
-
result.trackSelected(
|
|
611
|
+
result.trackSelected((value) => value, cb, options);
|
|
612
612
|
},
|
|
613
613
|
trackSelected(selector, cb, options = {}) {
|
|
614
614
|
const selectedCore = selector ? core.map(selector, { equality: createCoreEquality(options.comparator) }) : options.comparator ? core.map((value) => value, { equality: createCoreEquality(options.comparator) }) : core;
|
|
@@ -712,28 +712,29 @@ function createStateFromCore(core, subscribeCallback) {
|
|
|
712
712
|
const originalValue = core.get();
|
|
713
713
|
let wasMounted = false;
|
|
714
714
|
const attributeValue = cb ? cb(originalValue) : originalValue;
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
715
|
+
return {
|
|
716
|
+
velesAttribute: true,
|
|
717
|
+
getValue(htmlElement, attributeName, node) {
|
|
718
|
+
const trackingElement = {
|
|
719
|
+
cb,
|
|
720
|
+
htmlElement,
|
|
721
|
+
attributeName,
|
|
722
|
+
attributeValue
|
|
723
|
+
};
|
|
724
|
+
node._privateMethods._addMountHandler(() => {
|
|
725
|
+
trackers.trackingAttributes.push(trackingElement);
|
|
726
|
+
if (!wasMounted && core.get() === originalValue) {} else updateUseAttributeValue({
|
|
727
|
+
element: trackingElement,
|
|
728
|
+
value: core.get()
|
|
729
|
+
});
|
|
730
|
+
if (!wasMounted) wasMounted = true;
|
|
731
|
+
node._privateMethods._addUnmountHandler(() => {
|
|
732
|
+
trackers.trackingAttributes = trackers.trackingAttributes.filter((trackingAttribute) => trackingAttribute !== trackingElement);
|
|
733
|
+
});
|
|
731
734
|
});
|
|
732
|
-
|
|
733
|
-
|
|
735
|
+
return attributeValue;
|
|
736
|
+
}
|
|
734
737
|
};
|
|
735
|
-
attributeHelper.velesAttribute = true;
|
|
736
|
-
return attributeHelper;
|
|
737
738
|
},
|
|
738
739
|
dispose: () => {
|
|
739
740
|
core.dispose();
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as VelesComponentObject, i as VelesChildren, n as createElement, o as VelesElement, r as AttributeHelper, s as VelesStringElement, t as Fragment } from "./fragment-
|
|
1
|
+
import { a as VelesComponentObject, i as VelesChildren, n as createElement, o as VelesElement, r as AttributeHelper, s as VelesStringElement, t as Fragment } from "./fragment-C16zCm8L.cjs";
|
|
2
2
|
|
|
3
3
|
//#region src/attach-component.d.ts
|
|
4
4
|
/**
|
|
@@ -23,6 +23,7 @@ declare function onUnmount(cb: Function): void;
|
|
|
23
23
|
//#region src/create-state/types.d.ts
|
|
24
24
|
type StateEquality<ValueType> = (value1: ValueType, value2: ValueType) => boolean;
|
|
25
25
|
type StateLike<ValueType> = State<ValueType>;
|
|
26
|
+
type ArrayElement<T> = T extends ReadonlyArray<infer Element> ? Element : never;
|
|
26
27
|
type State<ValueType> = {
|
|
27
28
|
track(cb: (value: ValueType) => void | Function, options?: {
|
|
28
29
|
callOnMount?: boolean;
|
|
@@ -40,16 +41,26 @@ type State<ValueType> = {
|
|
|
40
41
|
<SelectorValueType>(selector: (value: ValueType) => SelectorValueType, cb?: (value: SelectorValueType) => VelesElement | VelesComponentObject | string | undefined | null, comparator?: (value1: SelectorValueType, value2: SelectorValueType) => boolean): VelesElement | VelesComponentObject | VelesStringElement;
|
|
41
42
|
};
|
|
42
43
|
attribute(cb?: (value: ValueType) => any): AttributeHelper<any>;
|
|
43
|
-
renderEach<Element>(options: {
|
|
44
|
+
renderEach<Element extends ArrayElement<ValueType> = ArrayElement<ValueType>>(options: ValueType extends ReadonlyArray<any> ? {
|
|
44
45
|
key: string | ((options: {
|
|
45
46
|
element: Element;
|
|
46
47
|
index: number;
|
|
47
48
|
}) => string);
|
|
48
|
-
selector?:
|
|
49
|
+
selector?: undefined;
|
|
50
|
+
} : never, cb: (props: {
|
|
51
|
+
elementState: State<Element>;
|
|
52
|
+
indexState: State<number>;
|
|
53
|
+
}) => VelesElement | VelesComponentObject): VelesComponentObject | VelesElement;
|
|
54
|
+
renderEach<SelectorValueType extends ReadonlyArray<any>, Element extends ArrayElement<SelectorValueType> = ArrayElement<SelectorValueType>>(options: {
|
|
55
|
+
key: string | ((options: {
|
|
56
|
+
element: Element;
|
|
57
|
+
index: number;
|
|
58
|
+
}) => string);
|
|
59
|
+
selector: (value: ValueType) => SelectorValueType;
|
|
49
60
|
}, cb: (props: {
|
|
50
61
|
elementState: State<Element>;
|
|
51
62
|
indexState: State<number>;
|
|
52
|
-
}) => VelesElement | VelesComponentObject): VelesComponentObject | VelesElement
|
|
63
|
+
}) => VelesElement | VelesComponentObject): VelesComponentObject | VelesElement;
|
|
53
64
|
map<SelectorValueType>(selector: (value: ValueType) => SelectorValueType, options?: {
|
|
54
65
|
equality?: StateEquality<SelectorValueType>;
|
|
55
66
|
}): State<SelectorValueType>;
|
|
@@ -101,7 +112,7 @@ declare function createContext<T>(): {
|
|
|
101
112
|
}: {
|
|
102
113
|
value: T;
|
|
103
114
|
children?: VelesChildren;
|
|
104
|
-
}) =>
|
|
115
|
+
}) => VelesComponentObject;
|
|
105
116
|
addContext: (value: T) => void;
|
|
106
117
|
readContext: () => T;
|
|
107
118
|
};
|
|
@@ -113,6 +124,6 @@ declare function Portal({
|
|
|
113
124
|
}: {
|
|
114
125
|
children?: VelesChildren;
|
|
115
126
|
portalNode: HTMLElement;
|
|
116
|
-
}): VelesElement
|
|
127
|
+
}): VelesElement;
|
|
117
128
|
//#endregion
|
|
118
129
|
export { Fragment, Portal, type State, attachComponent, createContext, createElement, createRef, createState, onMount, onUnmount };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as VelesComponentObject, i as VelesChildren, n as createElement, o as VelesElement, r as AttributeHelper, s as VelesStringElement, t as Fragment } from "./fragment-
|
|
1
|
+
import { a as VelesComponentObject, i as VelesChildren, n as createElement, o as VelesElement, r as AttributeHelper, s as VelesStringElement, t as Fragment } from "./fragment-yC0-T2O-.js";
|
|
2
2
|
|
|
3
3
|
//#region src/attach-component.d.ts
|
|
4
4
|
/**
|
|
@@ -23,6 +23,7 @@ declare function onUnmount(cb: Function): void;
|
|
|
23
23
|
//#region src/create-state/types.d.ts
|
|
24
24
|
type StateEquality<ValueType> = (value1: ValueType, value2: ValueType) => boolean;
|
|
25
25
|
type StateLike<ValueType> = State<ValueType>;
|
|
26
|
+
type ArrayElement<T> = T extends ReadonlyArray<infer Element> ? Element : never;
|
|
26
27
|
type State<ValueType> = {
|
|
27
28
|
track(cb: (value: ValueType) => void | Function, options?: {
|
|
28
29
|
callOnMount?: boolean;
|
|
@@ -40,16 +41,26 @@ type State<ValueType> = {
|
|
|
40
41
|
<SelectorValueType>(selector: (value: ValueType) => SelectorValueType, cb?: (value: SelectorValueType) => VelesElement | VelesComponentObject | string | undefined | null, comparator?: (value1: SelectorValueType, value2: SelectorValueType) => boolean): VelesElement | VelesComponentObject | VelesStringElement;
|
|
41
42
|
};
|
|
42
43
|
attribute(cb?: (value: ValueType) => any): AttributeHelper<any>;
|
|
43
|
-
renderEach<Element>(options: {
|
|
44
|
+
renderEach<Element extends ArrayElement<ValueType> = ArrayElement<ValueType>>(options: ValueType extends ReadonlyArray<any> ? {
|
|
44
45
|
key: string | ((options: {
|
|
45
46
|
element: Element;
|
|
46
47
|
index: number;
|
|
47
48
|
}) => string);
|
|
48
|
-
selector?:
|
|
49
|
+
selector?: undefined;
|
|
50
|
+
} : never, cb: (props: {
|
|
51
|
+
elementState: State<Element>;
|
|
52
|
+
indexState: State<number>;
|
|
53
|
+
}) => VelesElement | VelesComponentObject): VelesComponentObject | VelesElement;
|
|
54
|
+
renderEach<SelectorValueType extends ReadonlyArray<any>, Element extends ArrayElement<SelectorValueType> = ArrayElement<SelectorValueType>>(options: {
|
|
55
|
+
key: string | ((options: {
|
|
56
|
+
element: Element;
|
|
57
|
+
index: number;
|
|
58
|
+
}) => string);
|
|
59
|
+
selector: (value: ValueType) => SelectorValueType;
|
|
49
60
|
}, cb: (props: {
|
|
50
61
|
elementState: State<Element>;
|
|
51
62
|
indexState: State<number>;
|
|
52
|
-
}) => VelesElement | VelesComponentObject): VelesComponentObject | VelesElement
|
|
63
|
+
}) => VelesElement | VelesComponentObject): VelesComponentObject | VelesElement;
|
|
53
64
|
map<SelectorValueType>(selector: (value: ValueType) => SelectorValueType, options?: {
|
|
54
65
|
equality?: StateEquality<SelectorValueType>;
|
|
55
66
|
}): State<SelectorValueType>;
|
|
@@ -101,7 +112,7 @@ declare function createContext<T>(): {
|
|
|
101
112
|
}: {
|
|
102
113
|
value: T;
|
|
103
114
|
children?: VelesChildren;
|
|
104
|
-
}) =>
|
|
115
|
+
}) => VelesComponentObject;
|
|
105
116
|
addContext: (value: T) => void;
|
|
106
117
|
readContext: () => T;
|
|
107
118
|
};
|
|
@@ -113,6 +124,6 @@ declare function Portal({
|
|
|
113
124
|
}: {
|
|
114
125
|
children?: VelesChildren;
|
|
115
126
|
portalNode: HTMLElement;
|
|
116
|
-
}): VelesElement
|
|
127
|
+
}): VelesElement;
|
|
117
128
|
//#endregion
|
|
118
129
|
export { Fragment, Portal, type State, attachComponent, createContext, createElement, createRef, createState, onMount, onUnmount };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as
|
|
1
|
+
import { _ as onMount, a as identity, c as addPublicContext, d as popPublicContext, f as Fragment, g as hasCurrentLifecycleContext, h as createTextElement, i as getMountedNodeExecutedVersion, l as createContext, m as assignDomAttribute, n as callUnmountHandlers, o as renderTree, p as createElement, r as getExecutedComponentVelesNode, s as unique, t as callMountHandlers, u as getCurrentContext, v as onUnmount } from "./_utils-CCdioDsh.js";
|
|
2
2
|
//#region src/attach-component.ts
|
|
3
3
|
/**
|
|
4
4
|
* Attach Veles component tree to a regular HTML node.
|
|
@@ -185,15 +185,17 @@ function addUseValueMountHandler({ usedValue, get, trackers, trackingSelectorEle
|
|
|
185
185
|
function updateUseAttributeValue({ element, value }) {
|
|
186
186
|
const { cb, htmlElement, attributeName, attributeValue } = element;
|
|
187
187
|
const newAttributeValue = cb ? cb(value) : value;
|
|
188
|
-
if (
|
|
189
|
-
else htmlElement.removeAttribute(attributeName);
|
|
190
|
-
else if (attributeName.startsWith("on")) {
|
|
188
|
+
if (attributeName.startsWith("on")) {
|
|
191
189
|
if (attributeValue === newAttributeValue) return;
|
|
192
190
|
const eventName = attributeName.slice(2).toLocaleLowerCase();
|
|
193
191
|
if (attributeValue) htmlElement.removeEventListener(eventName, attributeValue);
|
|
194
192
|
if (newAttributeValue && typeof newAttributeValue === "function") htmlElement.addEventListener(eventName, newAttributeValue);
|
|
195
193
|
element.attributeValue = newAttributeValue;
|
|
196
|
-
} else
|
|
194
|
+
} else assignDomAttribute({
|
|
195
|
+
htmlElement,
|
|
196
|
+
attributeName,
|
|
197
|
+
value: newAttributeValue
|
|
198
|
+
});
|
|
197
199
|
}
|
|
198
200
|
//#endregion
|
|
199
201
|
//#region src/create-state/update-render-each-value.ts
|
|
@@ -203,11 +205,7 @@ function updateUseValueIteratorValue({ value, trackingIterator, createState }) {
|
|
|
203
205
|
console.error("there is no wrapper component for the iterator");
|
|
204
206
|
return;
|
|
205
207
|
}
|
|
206
|
-
|
|
207
|
-
console.error("it seems the wrapper component was not mounted");
|
|
208
|
-
return;
|
|
209
|
-
}
|
|
210
|
-
const wrapperVelesElementNode = getExecutedComponentVelesNode(wrapperComponent.executedVersion);
|
|
208
|
+
const wrapperVelesElementNode = getExecutedComponentVelesNode(getMountedNodeExecutedVersion(wrapperComponent, "Iterator wrapper is expected to be mounted"));
|
|
211
209
|
const parentVelesElement = wrapperVelesElementNode.parentVelesElement;
|
|
212
210
|
if (!parentVelesElement) {
|
|
213
211
|
console.error("there is no parent Veles node for the iterator wrapper");
|
|
@@ -272,13 +270,13 @@ function updateUseValueIteratorValue({ value, trackingIterator, createState }) {
|
|
|
272
270
|
let offset = 0;
|
|
273
271
|
let currentElement = null;
|
|
274
272
|
newRenderedElements.forEach((newRenderedElement, index) => {
|
|
275
|
-
newChildRenderedComponents.push(newRenderedElement[0]
|
|
273
|
+
newChildRenderedComponents.push(getMountedNodeExecutedVersion(newRenderedElement[0], "Iterator child is expected to be mounted"));
|
|
276
274
|
newChildComponents.push(newRenderedElement[0]);
|
|
277
275
|
if (positioningOffset[index]) offset = offset + positioningOffset[index];
|
|
278
276
|
const [newNode, calculatedKey, newState] = newRenderedElement;
|
|
279
277
|
const existingElement = elementsByKey[calculatedKey];
|
|
280
278
|
if (existingElement) {
|
|
281
|
-
const existingElementNode = getExecutedComponentVelesNode(existingElement.node
|
|
279
|
+
const existingElementNode = getExecutedComponentVelesNode(getMountedNodeExecutedVersion(existingElement.node, "Existing iterator node is expected to be mounted"));
|
|
282
280
|
if (existingElement.indexValue + offset === index) {
|
|
283
281
|
currentElement = existingElementNode.html;
|
|
284
282
|
return;
|
|
@@ -305,7 +303,8 @@ function updateUseValueIteratorValue({ value, trackingIterator, createState }) {
|
|
|
305
303
|
offset = offset - 1;
|
|
306
304
|
}
|
|
307
305
|
} else {
|
|
308
|
-
const
|
|
306
|
+
const newNodeExecutedVersion = getMountedNodeExecutedVersion(newNode, "New iterator node is expected to be mounted");
|
|
307
|
+
const newNodeVelesElement = getExecutedComponentVelesNode(newNodeExecutedVersion);
|
|
309
308
|
newNodeVelesElement.parentVelesElement = parentVelesElement;
|
|
310
309
|
if (currentElement) currentElement.after(newNodeVelesElement.html);
|
|
311
310
|
else {
|
|
@@ -316,15 +315,16 @@ function updateUseValueIteratorValue({ value, trackingIterator, createState }) {
|
|
|
316
315
|
offset = offset + 1;
|
|
317
316
|
currentElement = newNodeVelesElement.html;
|
|
318
317
|
newElementsCount = newElementsCount + 1;
|
|
319
|
-
callMountHandlers(
|
|
318
|
+
callMountHandlers(newNodeExecutedVersion);
|
|
320
319
|
}
|
|
321
320
|
});
|
|
322
321
|
if (renderedElements.length === newRenderedElements.length + newElementsCount) {} else renderedElements.forEach(([oldNode, calculatedKey]) => {
|
|
323
322
|
if (renderedExistingElements[calculatedKey] === true) return;
|
|
324
323
|
else {
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
324
|
+
const oldNodeExecutedVersion = getMountedNodeExecutedVersion(oldNode, "Removed iterator node is expected to be mounted");
|
|
325
|
+
getExecutedComponentVelesNode(oldNodeExecutedVersion).html.remove();
|
|
326
|
+
callUnmountHandlers(oldNodeExecutedVersion);
|
|
327
|
+
if ("executedVelesNode" in wrapperVelesElementNode) wrapperVelesElementNode.childComponents = wrapperVelesElementNode.childComponents.filter((childComponent) => childComponent !== oldNodeExecutedVersion);
|
|
328
328
|
else throw new Error("Wrapper iterator element is a string");
|
|
329
329
|
if ("velesNode" in wrapperComponent) wrapperComponent.childComponents = wrapperComponent.childComponents.filter((childComponent) => childComponent !== oldNode);
|
|
330
330
|
}
|
|
@@ -607,7 +607,7 @@ function createStateFromCore(core, subscribeCallback) {
|
|
|
607
607
|
});
|
|
608
608
|
const result = {
|
|
609
609
|
track: (cb, options = {}) => {
|
|
610
|
-
result.trackSelected(
|
|
610
|
+
result.trackSelected((value) => value, cb, options);
|
|
611
611
|
},
|
|
612
612
|
trackSelected(selector, cb, options = {}) {
|
|
613
613
|
const selectedCore = selector ? core.map(selector, { equality: createCoreEquality(options.comparator) }) : options.comparator ? core.map((value) => value, { equality: createCoreEquality(options.comparator) }) : core;
|
|
@@ -711,28 +711,29 @@ function createStateFromCore(core, subscribeCallback) {
|
|
|
711
711
|
const originalValue = core.get();
|
|
712
712
|
let wasMounted = false;
|
|
713
713
|
const attributeValue = cb ? cb(originalValue) : originalValue;
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
714
|
+
return {
|
|
715
|
+
velesAttribute: true,
|
|
716
|
+
getValue(htmlElement, attributeName, node) {
|
|
717
|
+
const trackingElement = {
|
|
718
|
+
cb,
|
|
719
|
+
htmlElement,
|
|
720
|
+
attributeName,
|
|
721
|
+
attributeValue
|
|
722
|
+
};
|
|
723
|
+
node._privateMethods._addMountHandler(() => {
|
|
724
|
+
trackers.trackingAttributes.push(trackingElement);
|
|
725
|
+
if (!wasMounted && core.get() === originalValue) {} else updateUseAttributeValue({
|
|
726
|
+
element: trackingElement,
|
|
727
|
+
value: core.get()
|
|
728
|
+
});
|
|
729
|
+
if (!wasMounted) wasMounted = true;
|
|
730
|
+
node._privateMethods._addUnmountHandler(() => {
|
|
731
|
+
trackers.trackingAttributes = trackers.trackingAttributes.filter((trackingAttribute) => trackingAttribute !== trackingElement);
|
|
732
|
+
});
|
|
730
733
|
});
|
|
731
|
-
|
|
732
|
-
|
|
734
|
+
return attributeValue;
|
|
735
|
+
}
|
|
733
736
|
};
|
|
734
|
-
attributeHelper.velesAttribute = true;
|
|
735
|
-
return attributeHelper;
|
|
736
737
|
},
|
|
737
738
|
dispose: () => {
|
|
738
739
|
core.dispose();
|
package/dist/jsx-runtime.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require__utils = require("./_utils-
|
|
2
|
+
const require__utils = require("./_utils-Cf3Xvo3q.cjs");
|
|
3
3
|
exports.Fragment = require__utils.Fragment;
|
|
4
4
|
exports.jsx = require__utils.createElement;
|
|
5
5
|
exports.jsxDEV = require__utils.createElement;
|
package/dist/jsx-runtime.d.cts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { c as JSX, n as createElement, t as Fragment } from "./fragment-
|
|
1
|
+
import { c as JSX, n as createElement, t as Fragment } from "./fragment-C16zCm8L.cjs";
|
|
2
2
|
export { Fragment, type JSX, createElement as jsx, createElement as jsxDEV, createElement as jsxs };
|
package/dist/jsx-runtime.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { c as JSX, n as createElement, t as Fragment } from "./fragment-
|
|
1
|
+
import { c as JSX, n as createElement, t as Fragment } from "./fragment-yC0-T2O-.js";
|
|
2
2
|
export { Fragment, type JSX, createElement as jsx, createElement as jsxDEV, createElement as jsxs };
|
package/dist/jsx-runtime.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { f as Fragment, p as createElement } from "./_utils-CCdioDsh.js";
|
|
2
2
|
export { Fragment, createElement as jsx, createElement as jsxDEV, createElement as jsxs };
|