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.
@@ -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
- delete element.nd?.on?.prevent;
683
- delete element.nd?.on;
684
- delete element.nd;
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
- this.$observer = this.$observer || DocumentObserver.watch(this.$element);
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
- this.$observer.mounted(states.mounted);
698
+ observer.mounted(states.mounted);
695
699
  }
696
700
  if(states.unmounted) {
697
701
  this.$element.setAttribute('data--nd-unmounted', '1');
698
- this.$observer.unmounted(states.unmounted);
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
- this.$element.classes.add(exitClass);
2732
- await waitForVisualEnd(this.$element);
2733
- this.$element.classes.remove(exitClass);
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.classes.add(startClass);
2747
+ const el = this.$element;
2748
+
2749
+ el.classes.add(startClass);
2743
2750
 
2744
2751
  this.mounted(() => {
2745
2752
  requestAnimationFrame(() => {
2746
2753
  requestAnimationFrame(() => {
2747
- this.$element.classes.remove(startClass);
2748
- this.$element.classes.add(endClass);
2754
+ el.classes.remove(startClass);
2755
+ el.classes.add(endClass);
2749
2756
 
2750
- waitForVisualEnd(this.$element).then(() => {
2751
- this.$element.classes.remove(endClass);
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.classes.add(animationName);
2774
+ const el = this.$element;
2775
+ el.classes.add(animationName);
2768
2776
 
2769
- waitForVisualEnd(this.$element).then(() => {
2770
- this.$element.classes.remove(animationName);
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
- delete element.nd?.on?.prevent;
438
- delete element.nd?.on;
439
- delete element.nd;
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
- this.$observer = this.$observer || DocumentObserver.watch(this.$element);
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
- this.$observer.mounted(states.mounted);
453
+ observer.mounted(states.mounted);
450
454
  }
451
455
  if(states.unmounted) {
452
456
  this.$element.setAttribute('data--nd-unmounted', '1');
453
- this.$observer.unmounted(states.unmounted);
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
- this.$element.classes.add(exitClass);
2580
- await waitForVisualEnd(this.$element);
2581
- this.$element.classes.remove(exitClass);
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.classes.add(startClass);
2595
+ const el = this.$element;
2596
+
2597
+ el.classes.add(startClass);
2591
2598
 
2592
2599
  this.mounted(() => {
2593
2600
  requestAnimationFrame(() => {
2594
2601
  requestAnimationFrame(() => {
2595
- this.$element.classes.remove(startClass);
2596
- this.$element.classes.add(endClass);
2602
+ el.classes.remove(startClass);
2603
+ el.classes.add(endClass);
2597
2604
 
2598
- waitForVisualEnd(this.$element).then(() => {
2599
- this.$element.classes.remove(endClass);
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.classes.add(animationName);
2622
+ const el = this.$element;
2623
+ el.classes.add(animationName);
2616
2624
 
2617
- waitForVisualEnd(this.$element).then(() => {
2618
- this.$element.classes.remove(animationName);
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
- if(!bindDingData.attach) {
3255
- return null;
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
- bindDingData.attach[methodName].apply(this, [...args, ...data]);
3270
+ fn.apply(this, [...args, ...data]);
3260
3271
  });
3261
3272
  }
3262
3273
  };
3263
3274
 
3264
3275
 
3265
- const applyBindingTreePath = (root, target, data, path) => {
3266
- if(path.fn) {
3267
- if(typeof path.fn === 'string') {
3268
- ElementCreator.bindTextNode(target, data[0][path.fn]);
3269
- }
3270
- else {
3271
- path.fn(data, target, root);
3272
- }
3273
- }
3274
- if(path.children) {
3275
- for(let i = 0, length = path.children.length; i < length; i++) {
3276
- const currentPath = path.children[i];
3277
- const pathTargetNode = target.childNodes[currentPath.index];
3278
- applyBindingTreePath(root, pathTargetNode, data, currentPath);
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
- fn: null,
3289
- children: [],
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
- currentPath.fn = (data, targetNode) => {
3312
- bindAttributes(targetNode, bindDingData, data);
3313
- bindAttachMethods(targetNode, bindDingData, data);
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 bindingPathChildren = [];
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: null };
3355
+ const path = { parentId, id: ++pathCounter, index: i, fn: noUpdate };
3321
3356
  const childNodeCloned = clone(childNode, data, path);
3322
- if(path.children || path.fn) {
3323
- bindingPathChildren.push(path);
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, root, data, $bindingTreePath);
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(callbackOrProperty, 'value');
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
- const wrapper = function(args) {
3392
- if(!$cache) {
3393
- $cache = new TemplateCloner(fn);
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) {