native-document 1.0.107 → 1.0.109
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/native-document.components.min.js +27 -19
- package/dist/native-document.dev.js +110 -64
- package/dist/native-document.dev.js.map +1 -1
- package/dist/native-document.min.js +1 -1
- package/package.json +1 -1
- package/src/core/utils/validator.js +5 -6
- package/src/core/wrappers/AttributesWrapper.js +3 -1
- package/src/core/wrappers/NDElement.js +12 -8
- package/src/core/wrappers/TemplateCloner.js +177 -67
- package/src/core/wrappers/prototypes/nd-element-extensions.js +0 -1
- package/src/core/wrappers/prototypes/nd-element.transition.extensions.js +15 -11
- package/src/router/Router.js +11 -0
- package/src/router/RouterComponent.js +2 -1
- package/types/template-cloner.ts +1 -0
|
@@ -643,7 +643,6 @@ var NativeComponents = (function (exports) {
|
|
|
643
643
|
|
|
644
644
|
function NDElement(element) {
|
|
645
645
|
this.$element = element;
|
|
646
|
-
this.$observer = null;
|
|
647
646
|
}
|
|
648
647
|
|
|
649
648
|
NDElement.prototype.__$isNDElement = true;
|
|
@@ -658,7 +657,7 @@ var NativeComponents = (function (exports) {
|
|
|
658
657
|
};
|
|
659
658
|
|
|
660
659
|
NDElement.prototype.refSelf = function(target, name) {
|
|
661
|
-
target[name] = this;
|
|
660
|
+
target[name] = new NDElement(this.$element);
|
|
662
661
|
return this;
|
|
663
662
|
};
|
|
664
663
|
|
|
@@ -679,23 +678,28 @@ var NativeComponents = (function (exports) {
|
|
|
679
678
|
let element = this.$element;
|
|
680
679
|
element.nd.unmountChildren();
|
|
681
680
|
element.$ndProx = null;
|
|
682
|
-
|
|
683
|
-
delete
|
|
684
|
-
|
|
681
|
+
|
|
682
|
+
$lifeCycleObservers.delete(element);
|
|
683
|
+
|
|
685
684
|
element = null;
|
|
686
685
|
return this;
|
|
687
686
|
};
|
|
688
687
|
|
|
688
|
+
const $lifeCycleObservers = new WeakMap();
|
|
689
689
|
NDElement.prototype.lifecycle = function(states) {
|
|
690
|
-
|
|
690
|
+
const el = this.$element;
|
|
691
|
+
if (!$lifeCycleObservers.has(el)) {
|
|
692
|
+
$lifeCycleObservers.set(el, DocumentObserver.watch(el));
|
|
693
|
+
}
|
|
694
|
+
const observer = $lifeCycleObservers.get(el);
|
|
691
695
|
|
|
692
696
|
if(states.mounted) {
|
|
693
697
|
this.$element.setAttribute('data--nd-mounted', '1');
|
|
694
|
-
|
|
698
|
+
observer.mounted(states.mounted);
|
|
695
699
|
}
|
|
696
700
|
if(states.unmounted) {
|
|
697
701
|
this.$element.setAttribute('data--nd-unmounted', '1');
|
|
698
|
-
|
|
702
|
+
observer.unmounted(states.unmounted);
|
|
699
703
|
}
|
|
700
704
|
return this;
|
|
701
705
|
};
|
|
@@ -2727,10 +2731,11 @@ var NativeComponents = (function (exports) {
|
|
|
2727
2731
|
|
|
2728
2732
|
NDElement.prototype.transitionOut = function(transitionName) {
|
|
2729
2733
|
const exitClass = transitionName + '-exit';
|
|
2734
|
+
const el = this.$element;
|
|
2730
2735
|
this.beforeUnmount('transition-exit', async function() {
|
|
2731
|
-
|
|
2732
|
-
await waitForVisualEnd(
|
|
2733
|
-
|
|
2736
|
+
el.classes.add(exitClass);
|
|
2737
|
+
await waitForVisualEnd(el);
|
|
2738
|
+
el.classes.remove(exitClass);
|
|
2734
2739
|
});
|
|
2735
2740
|
return this;
|
|
2736
2741
|
};
|
|
@@ -2739,16 +2744,18 @@ var NativeComponents = (function (exports) {
|
|
|
2739
2744
|
const startClass = transitionName + '-enter-from';
|
|
2740
2745
|
const endClass = transitionName + '-enter-to';
|
|
2741
2746
|
|
|
2742
|
-
this.$element
|
|
2747
|
+
const el = this.$element;
|
|
2748
|
+
|
|
2749
|
+
el.classes.add(startClass);
|
|
2743
2750
|
|
|
2744
2751
|
this.mounted(() => {
|
|
2745
2752
|
requestAnimationFrame(() => {
|
|
2746
2753
|
requestAnimationFrame(() => {
|
|
2747
|
-
|
|
2748
|
-
|
|
2754
|
+
el.classes.remove(startClass);
|
|
2755
|
+
el.classes.add(endClass);
|
|
2749
2756
|
|
|
2750
|
-
waitForVisualEnd(
|
|
2751
|
-
|
|
2757
|
+
waitForVisualEnd(el).then(() => {
|
|
2758
|
+
el.classes.remove(endClass);
|
|
2752
2759
|
});
|
|
2753
2760
|
});
|
|
2754
2761
|
});
|
|
@@ -2764,10 +2771,11 @@ var NativeComponents = (function (exports) {
|
|
|
2764
2771
|
};
|
|
2765
2772
|
|
|
2766
2773
|
NDElement.prototype.animate = function(animationName) {
|
|
2767
|
-
this.$element
|
|
2774
|
+
const el = this.$element;
|
|
2775
|
+
el.classes.add(animationName);
|
|
2768
2776
|
|
|
2769
|
-
waitForVisualEnd(
|
|
2770
|
-
|
|
2777
|
+
waitForVisualEnd(el).then(() => {
|
|
2778
|
+
el.classes.remove(animationName);
|
|
2771
2779
|
});
|
|
2772
2780
|
|
|
2773
2781
|
return this;
|
|
@@ -395,7 +395,6 @@ var NativeDocument = (function (exports) {
|
|
|
395
395
|
|
|
396
396
|
function NDElement(element) {
|
|
397
397
|
this.$element = element;
|
|
398
|
-
this.$observer = null;
|
|
399
398
|
{
|
|
400
399
|
PluginsManager.emit('NDElementCreated', element, this);
|
|
401
400
|
}
|
|
@@ -413,7 +412,7 @@ var NativeDocument = (function (exports) {
|
|
|
413
412
|
};
|
|
414
413
|
|
|
415
414
|
NDElement.prototype.refSelf = function(target, name) {
|
|
416
|
-
target[name] = this;
|
|
415
|
+
target[name] = new NDElement(this.$element);
|
|
417
416
|
return this;
|
|
418
417
|
};
|
|
419
418
|
|
|
@@ -434,23 +433,28 @@ var NativeDocument = (function (exports) {
|
|
|
434
433
|
let element = this.$element;
|
|
435
434
|
element.nd.unmountChildren();
|
|
436
435
|
element.$ndProx = null;
|
|
437
|
-
|
|
438
|
-
delete
|
|
439
|
-
|
|
436
|
+
|
|
437
|
+
$lifeCycleObservers.delete(element);
|
|
438
|
+
|
|
440
439
|
element = null;
|
|
441
440
|
return this;
|
|
442
441
|
};
|
|
443
442
|
|
|
443
|
+
const $lifeCycleObservers = new WeakMap();
|
|
444
444
|
NDElement.prototype.lifecycle = function(states) {
|
|
445
|
-
|
|
445
|
+
const el = this.$element;
|
|
446
|
+
if (!$lifeCycleObservers.has(el)) {
|
|
447
|
+
$lifeCycleObservers.set(el, DocumentObserver.watch(el));
|
|
448
|
+
}
|
|
449
|
+
const observer = $lifeCycleObservers.get(el);
|
|
446
450
|
|
|
447
451
|
if(states.mounted) {
|
|
448
452
|
this.$element.setAttribute('data--nd-mounted', '1');
|
|
449
|
-
|
|
453
|
+
observer.mounted(states.mounted);
|
|
450
454
|
}
|
|
451
455
|
if(states.unmounted) {
|
|
452
456
|
this.$element.setAttribute('data--nd-unmounted', '1');
|
|
453
|
-
|
|
457
|
+
observer.unmounted(states.unmounted);
|
|
454
458
|
}
|
|
455
459
|
return this;
|
|
456
460
|
};
|
|
@@ -2575,10 +2579,11 @@ var NativeDocument = (function (exports) {
|
|
|
2575
2579
|
|
|
2576
2580
|
NDElement.prototype.transitionOut = function(transitionName) {
|
|
2577
2581
|
const exitClass = transitionName + '-exit';
|
|
2582
|
+
const el = this.$element;
|
|
2578
2583
|
this.beforeUnmount('transition-exit', async function() {
|
|
2579
|
-
|
|
2580
|
-
await waitForVisualEnd(
|
|
2581
|
-
|
|
2584
|
+
el.classes.add(exitClass);
|
|
2585
|
+
await waitForVisualEnd(el);
|
|
2586
|
+
el.classes.remove(exitClass);
|
|
2582
2587
|
});
|
|
2583
2588
|
return this;
|
|
2584
2589
|
};
|
|
@@ -2587,16 +2592,18 @@ var NativeDocument = (function (exports) {
|
|
|
2587
2592
|
const startClass = transitionName + '-enter-from';
|
|
2588
2593
|
const endClass = transitionName + '-enter-to';
|
|
2589
2594
|
|
|
2590
|
-
this.$element
|
|
2595
|
+
const el = this.$element;
|
|
2596
|
+
|
|
2597
|
+
el.classes.add(startClass);
|
|
2591
2598
|
|
|
2592
2599
|
this.mounted(() => {
|
|
2593
2600
|
requestAnimationFrame(() => {
|
|
2594
2601
|
requestAnimationFrame(() => {
|
|
2595
|
-
|
|
2596
|
-
|
|
2602
|
+
el.classes.remove(startClass);
|
|
2603
|
+
el.classes.add(endClass);
|
|
2597
2604
|
|
|
2598
|
-
waitForVisualEnd(
|
|
2599
|
-
|
|
2605
|
+
waitForVisualEnd(el).then(() => {
|
|
2606
|
+
el.classes.remove(endClass);
|
|
2600
2607
|
});
|
|
2601
2608
|
});
|
|
2602
2609
|
});
|
|
@@ -2612,10 +2619,11 @@ var NativeDocument = (function (exports) {
|
|
|
2612
2619
|
};
|
|
2613
2620
|
|
|
2614
2621
|
NDElement.prototype.animate = function(animationName) {
|
|
2615
|
-
this.$element
|
|
2622
|
+
const el = this.$element;
|
|
2623
|
+
el.classes.add(animationName);
|
|
2616
2624
|
|
|
2617
|
-
waitForVisualEnd(
|
|
2618
|
-
|
|
2625
|
+
waitForVisualEnd(el).then(() => {
|
|
2626
|
+
el.classes.remove(animationName);
|
|
2619
2627
|
});
|
|
2620
2628
|
|
|
2621
2629
|
return this;
|
|
@@ -3239,56 +3247,66 @@ var NativeDocument = (function (exports) {
|
|
|
3239
3247
|
const $hydrateFn = function(hydrateFunction, targetType, element, property) {
|
|
3240
3248
|
if(!cloneBindingsDataCache.has(element)) {
|
|
3241
3249
|
// { classes, styles, attributes, value, attach }
|
|
3242
|
-
cloneBindingsDataCache.set(element, {});
|
|
3250
|
+
cloneBindingsDataCache.set(element, { attach: [] });
|
|
3243
3251
|
}
|
|
3244
3252
|
const hydrationState = cloneBindingsDataCache.get(element);
|
|
3245
3253
|
if(targetType === 'value') {
|
|
3246
3254
|
hydrationState.value = hydrateFunction;
|
|
3247
3255
|
return;
|
|
3248
3256
|
}
|
|
3257
|
+
if(targetType === 'attach') {
|
|
3258
|
+
hydrationState.attach = hydrationState.attach || [];
|
|
3259
|
+
hydrationState.attach.push({ methodName: property, fn: hydrateFunction});
|
|
3260
|
+
return;
|
|
3261
|
+
}
|
|
3249
3262
|
hydrationState[targetType] = hydrationState[targetType] || {};
|
|
3250
3263
|
hydrationState[targetType][property] = hydrateFunction;
|
|
3251
3264
|
};
|
|
3252
3265
|
|
|
3253
3266
|
const bindAttachMethods = (node, bindDingData, data) => {
|
|
3254
|
-
|
|
3255
|
-
|
|
3256
|
-
}
|
|
3257
|
-
for(const methodName in bindDingData.attach) {
|
|
3267
|
+
for(let i = 0, length = bindDingData.attach.length; i < length; i++) {
|
|
3268
|
+
const { methodName, fn } = bindDingData.attach[i];
|
|
3258
3269
|
node.nd[methodName](function(...args) {
|
|
3259
|
-
|
|
3270
|
+
fn.apply(this, [...args, ...data]);
|
|
3260
3271
|
});
|
|
3261
3272
|
}
|
|
3262
3273
|
};
|
|
3263
3274
|
|
|
3264
3275
|
|
|
3265
|
-
const applyBindingTreePath = (root,
|
|
3266
|
-
|
|
3267
|
-
|
|
3268
|
-
|
|
3269
|
-
|
|
3270
|
-
|
|
3271
|
-
|
|
3272
|
-
|
|
3273
|
-
|
|
3274
|
-
|
|
3275
|
-
|
|
3276
|
-
|
|
3277
|
-
|
|
3278
|
-
|
|
3279
|
-
|
|
3276
|
+
const applyBindingTreePath = (root, data, paths) => {
|
|
3277
|
+
const rootPath = paths.at(-1);
|
|
3278
|
+
const parents = [];
|
|
3279
|
+
parents[rootPath.id] = root;
|
|
3280
|
+
data[0];
|
|
3281
|
+
const rootPathFn = rootPath.fn;
|
|
3282
|
+
rootPathFn(data, root, root);
|
|
3283
|
+
|
|
3284
|
+
|
|
3285
|
+
for(let i = 0, length = paths.length - 1; i < length; i++) {
|
|
3286
|
+
const path = paths[i];
|
|
3287
|
+
const target = parents[path.parentId].childNodes[path.index];
|
|
3288
|
+
|
|
3289
|
+
parents[path.id] = target;
|
|
3290
|
+
const pathFn = path.fn;
|
|
3291
|
+
pathFn(data, target, root);
|
|
3280
3292
|
}
|
|
3293
|
+
parents.length = 0;
|
|
3281
3294
|
};
|
|
3282
3295
|
|
|
3296
|
+
const noUpdate = () => {};
|
|
3283
3297
|
function TemplateCloner($fn) {
|
|
3284
3298
|
let $node = null;
|
|
3285
3299
|
let $hasBindingData = false;
|
|
3286
3300
|
|
|
3287
|
-
const $bindingTreePath =
|
|
3288
|
-
|
|
3289
|
-
|
|
3290
|
-
|
|
3301
|
+
const $bindingTreePath = [
|
|
3302
|
+
{
|
|
3303
|
+
id: 0,
|
|
3304
|
+
parentId: null,
|
|
3305
|
+
fn: noUpdate,
|
|
3306
|
+
}
|
|
3307
|
+
];
|
|
3291
3308
|
|
|
3309
|
+
let pathCounter = 0;
|
|
3292
3310
|
const clone = (node, data, currentPath) => {
|
|
3293
3311
|
const bindDingData = cloneBindingsDataCache.get(node);
|
|
3294
3312
|
if(node.nodeType === 3) {
|
|
@@ -3308,33 +3326,47 @@ var NativeDocument = (function (exports) {
|
|
|
3308
3326
|
if(bindDingData) {
|
|
3309
3327
|
bindAttributes(nodeCloned, bindDingData, data);
|
|
3310
3328
|
bindAttachMethods(nodeCloned, bindDingData, data);
|
|
3311
|
-
|
|
3312
|
-
|
|
3313
|
-
|
|
3314
|
-
|
|
3329
|
+
|
|
3330
|
+
const hasAttributes = bindDingData.classes || bindDingData.styles || bindDingData.attributes;
|
|
3331
|
+
const hasAttachMethods = bindDingData.attach.length;
|
|
3332
|
+
|
|
3333
|
+
if(hasAttributes && hasAttachMethods) {
|
|
3334
|
+
currentPath.fn = (data, targetNode) => {
|
|
3335
|
+
bindAttributes(targetNode, bindDingData, data);
|
|
3336
|
+
bindAttachMethods(targetNode, bindDingData, data);
|
|
3337
|
+
};
|
|
3338
|
+
}
|
|
3339
|
+
else if(hasAttributes) {
|
|
3340
|
+
currentPath.fn = (data, targetNode) => {
|
|
3341
|
+
bindAttributes(targetNode, bindDingData, data);
|
|
3342
|
+
};
|
|
3343
|
+
}
|
|
3344
|
+
else if(hasAttachMethods) {
|
|
3345
|
+
currentPath.fn = (data, targetNode) => {
|
|
3346
|
+
bindAttachMethods(targetNode, bindDingData, data);
|
|
3347
|
+
};
|
|
3348
|
+
}
|
|
3315
3349
|
}
|
|
3316
3350
|
const childNodes = node.childNodes;
|
|
3317
|
-
const
|
|
3351
|
+
const parentId = currentPath.id;
|
|
3352
|
+
|
|
3318
3353
|
for(let i = 0, length = childNodes.length; i < length; i++) {
|
|
3319
3354
|
const childNode = childNodes[i];
|
|
3320
|
-
const path = { index: i, fn:
|
|
3355
|
+
const path = { parentId, id: ++pathCounter, index: i, fn: noUpdate };
|
|
3321
3356
|
const childNodeCloned = clone(childNode, data, path);
|
|
3322
|
-
if(path.
|
|
3323
|
-
|
|
3357
|
+
if(path.hasChildren || path.fn) {
|
|
3358
|
+
$bindingTreePath.unshift(path);
|
|
3359
|
+
currentPath.hasChildren = true;
|
|
3324
3360
|
}
|
|
3325
3361
|
nodeCloned.appendChild(childNodeCloned);
|
|
3326
3362
|
}
|
|
3327
|
-
if(bindingPathChildren.length) {
|
|
3328
|
-
currentPath.children = currentPath.children || [];
|
|
3329
|
-
currentPath.children = bindingPathChildren;
|
|
3330
|
-
}
|
|
3331
3363
|
return nodeCloned;
|
|
3332
3364
|
};
|
|
3333
3365
|
|
|
3334
3366
|
const cloneWithBindingPaths = (data) => {
|
|
3335
3367
|
let root = $node.cloneNode(true);
|
|
3336
3368
|
|
|
3337
|
-
applyBindingTreePath(root,
|
|
3369
|
+
applyBindingTreePath(root, data, $bindingTreePath);
|
|
3338
3370
|
return root;
|
|
3339
3371
|
};
|
|
3340
3372
|
|
|
@@ -3345,7 +3377,7 @@ var NativeDocument = (function (exports) {
|
|
|
3345
3377
|
return $node.cloneNode(true);
|
|
3346
3378
|
}
|
|
3347
3379
|
|
|
3348
|
-
const firstClone = clone($node, data, $bindingTreePath);
|
|
3380
|
+
const firstClone = clone($node, data, $bindingTreePath[0]);
|
|
3349
3381
|
this.clone = cloneWithBindingPaths;
|
|
3350
3382
|
return firstClone;
|
|
3351
3383
|
};
|
|
@@ -3369,7 +3401,9 @@ var NativeDocument = (function (exports) {
|
|
|
3369
3401
|
};
|
|
3370
3402
|
this.value = (callbackOrProperty) => {
|
|
3371
3403
|
if(typeof callbackOrProperty !== 'function') {
|
|
3372
|
-
return createBinding(
|
|
3404
|
+
return createBinding((data, textNode) => {
|
|
3405
|
+
ElementCreator.bindTextNode(textNode, data[0][callbackOrProperty]);
|
|
3406
|
+
}, 'value');
|
|
3373
3407
|
}
|
|
3374
3408
|
return createBinding((data, textNode) => {
|
|
3375
3409
|
ElementCreator.bindTextNode(textNode, callbackOrProperty(...data));
|
|
@@ -3388,10 +3422,11 @@ var NativeDocument = (function (exports) {
|
|
|
3388
3422
|
function useCache(fn) {
|
|
3389
3423
|
let $cache = null;
|
|
3390
3424
|
|
|
3391
|
-
|
|
3392
|
-
|
|
3393
|
-
|
|
3394
|
-
|
|
3425
|
+
let wrapper = function(args) {
|
|
3426
|
+
$cache = new TemplateCloner(fn);
|
|
3427
|
+
wrapper = function(args) {
|
|
3428
|
+
return $cache.clone(args);
|
|
3429
|
+
};
|
|
3395
3430
|
return $cache.clone(args);
|
|
3396
3431
|
};
|
|
3397
3432
|
|
|
@@ -6714,7 +6749,7 @@ var NativeDocument = (function (exports) {
|
|
|
6714
6749
|
cleanContainer();
|
|
6715
6750
|
const anchor = getNodeAnchorForLayout(nodeToInsert, path);
|
|
6716
6751
|
|
|
6717
|
-
$currentLayout = layout(anchor);
|
|
6752
|
+
$currentLayout = ElementCreator.getChild(layout(anchor));
|
|
6718
6753
|
$layoutCache.set(nodeToInsert, $currentLayout);
|
|
6719
6754
|
container.appendChild($currentLayout);
|
|
6720
6755
|
};
|
|
@@ -7014,6 +7049,17 @@ var NativeDocument = (function (exports) {
|
|
|
7014
7049
|
return Router.get(name).back();
|
|
7015
7050
|
};
|
|
7016
7051
|
|
|
7052
|
+
Router.redirectTo = function(pathOrRouteName, params = null, name = null) {
|
|
7053
|
+
let target = pathOrRouteName;
|
|
7054
|
+
const router = Router.get(name);
|
|
7055
|
+
const route = router.resolve({ name: pathOrRouteName, params });
|
|
7056
|
+
if(route) {
|
|
7057
|
+
target = { name: pathOrRouteName, params};
|
|
7058
|
+
}
|
|
7059
|
+
console.log(target);
|
|
7060
|
+
return router.push(target);
|
|
7061
|
+
};
|
|
7062
|
+
|
|
7017
7063
|
function Link(options, children){
|
|
7018
7064
|
const { to, href, ...attributes } = options;
|
|
7019
7065
|
if(href) {
|