native-document 1.0.108 → 1.0.110

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.
@@ -3058,12 +3058,10 @@ var NativeComponents = (function (exports) {
3058
3058
  "ContextMenu"
3059
3059
  ];
3060
3060
 
3061
- const $sharedNdElement = new NDElement(null);
3062
3061
  const property = {
3063
3062
  configurable: true,
3064
3063
  get() {
3065
- $sharedNdElement.$element = this;
3066
- return $sharedNdElement;
3064
+ return new NDElement(this);
3067
3065
  }
3068
3066
  };
3069
3067
 
@@ -2916,12 +2916,10 @@ var NativeDocument = (function (exports) {
2916
2916
  "ContextMenu"
2917
2917
  ];
2918
2918
 
2919
- const $sharedNdElement = new NDElement(null);
2920
2919
  const property = {
2921
2920
  configurable: true,
2922
2921
  get() {
2923
- $sharedNdElement.$element = this;
2924
- return $sharedNdElement;
2922
+ return new NDElement(this);
2925
2923
  }
2926
2924
  };
2927
2925
 
@@ -3249,56 +3247,66 @@ var NativeDocument = (function (exports) {
3249
3247
  const $hydrateFn = function(hydrateFunction, targetType, element, property) {
3250
3248
  if(!cloneBindingsDataCache.has(element)) {
3251
3249
  // { classes, styles, attributes, value, attach }
3252
- cloneBindingsDataCache.set(element, {});
3250
+ cloneBindingsDataCache.set(element, { attach: [] });
3253
3251
  }
3254
3252
  const hydrationState = cloneBindingsDataCache.get(element);
3255
3253
  if(targetType === 'value') {
3256
3254
  hydrationState.value = hydrateFunction;
3257
3255
  return;
3258
3256
  }
3257
+ if(targetType === 'attach') {
3258
+ hydrationState.attach = hydrationState.attach || [];
3259
+ hydrationState.attach.push({ methodName: property, fn: hydrateFunction});
3260
+ return;
3261
+ }
3259
3262
  hydrationState[targetType] = hydrationState[targetType] || {};
3260
3263
  hydrationState[targetType][property] = hydrateFunction;
3261
3264
  };
3262
3265
 
3263
3266
  const bindAttachMethods = (node, bindDingData, data) => {
3264
- if(!bindDingData.attach) {
3265
- return null;
3266
- }
3267
- 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];
3268
3269
  node.nd[methodName](function(...args) {
3269
- bindDingData.attach[methodName].apply(this, [...args, ...data]);
3270
+ fn.apply(this, [...args, ...data]);
3270
3271
  });
3271
3272
  }
3272
3273
  };
3273
3274
 
3274
3275
 
3275
- const applyBindingTreePath = (root, target, data, path) => {
3276
- if(path.fn) {
3277
- if(typeof path.fn === 'string') {
3278
- ElementCreator.bindTextNode(target, data[0][path.fn]);
3279
- }
3280
- else {
3281
- path.fn(data, target, root);
3282
- }
3283
- }
3284
- if(path.children) {
3285
- for(let i = 0, length = path.children.length; i < length; i++) {
3286
- const currentPath = path.children[i];
3287
- const pathTargetNode = target.childNodes[currentPath.index];
3288
- applyBindingTreePath(root, pathTargetNode, data, currentPath);
3289
- }
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);
3290
3292
  }
3293
+ parents.length = 0;
3291
3294
  };
3292
3295
 
3296
+ const noUpdate = () => {};
3293
3297
  function TemplateCloner($fn) {
3294
3298
  let $node = null;
3295
3299
  let $hasBindingData = false;
3296
3300
 
3297
- const $bindingTreePath = {
3298
- fn: null,
3299
- children: [],
3300
- };
3301
+ const $bindingTreePath = [
3302
+ {
3303
+ id: 0,
3304
+ parentId: null,
3305
+ fn: noUpdate,
3306
+ }
3307
+ ];
3301
3308
 
3309
+ let pathCounter = 0;
3302
3310
  const clone = (node, data, currentPath) => {
3303
3311
  const bindDingData = cloneBindingsDataCache.get(node);
3304
3312
  if(node.nodeType === 3) {
@@ -3318,33 +3326,47 @@ var NativeDocument = (function (exports) {
3318
3326
  if(bindDingData) {
3319
3327
  bindAttributes(nodeCloned, bindDingData, data);
3320
3328
  bindAttachMethods(nodeCloned, bindDingData, data);
3321
- currentPath.fn = (data, targetNode) => {
3322
- bindAttributes(targetNode, bindDingData, data);
3323
- bindAttachMethods(targetNode, bindDingData, data);
3324
- };
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
+ }
3325
3349
  }
3326
3350
  const childNodes = node.childNodes;
3327
- const bindingPathChildren = [];
3351
+ const parentId = currentPath.id;
3352
+
3328
3353
  for(let i = 0, length = childNodes.length; i < length; i++) {
3329
3354
  const childNode = childNodes[i];
3330
- const path = { index: i, fn: null };
3355
+ const path = { parentId, id: ++pathCounter, index: i, fn: noUpdate };
3331
3356
  const childNodeCloned = clone(childNode, data, path);
3332
- if(path.children || path.fn) {
3333
- bindingPathChildren.push(path);
3357
+ if(path.hasChildren || path.fn) {
3358
+ $bindingTreePath.unshift(path);
3359
+ currentPath.hasChildren = true;
3334
3360
  }
3335
3361
  nodeCloned.appendChild(childNodeCloned);
3336
3362
  }
3337
- if(bindingPathChildren.length) {
3338
- currentPath.children = currentPath.children || [];
3339
- currentPath.children = bindingPathChildren;
3340
- }
3341
3363
  return nodeCloned;
3342
3364
  };
3343
3365
 
3344
3366
  const cloneWithBindingPaths = (data) => {
3345
3367
  let root = $node.cloneNode(true);
3346
3368
 
3347
- applyBindingTreePath(root, root, data, $bindingTreePath);
3369
+ applyBindingTreePath(root, data, $bindingTreePath);
3348
3370
  return root;
3349
3371
  };
3350
3372
 
@@ -3355,7 +3377,7 @@ var NativeDocument = (function (exports) {
3355
3377
  return $node.cloneNode(true);
3356
3378
  }
3357
3379
 
3358
- const firstClone = clone($node, data, $bindingTreePath);
3380
+ const firstClone = clone($node, data, $bindingTreePath[0]);
3359
3381
  this.clone = cloneWithBindingPaths;
3360
3382
  return firstClone;
3361
3383
  };
@@ -3379,7 +3401,9 @@ var NativeDocument = (function (exports) {
3379
3401
  };
3380
3402
  this.value = (callbackOrProperty) => {
3381
3403
  if(typeof callbackOrProperty !== 'function') {
3382
- return createBinding(callbackOrProperty, 'value');
3404
+ return createBinding((data, textNode) => {
3405
+ ElementCreator.bindTextNode(textNode, data[0][callbackOrProperty]);
3406
+ }, 'value');
3383
3407
  }
3384
3408
  return createBinding((data, textNode) => {
3385
3409
  ElementCreator.bindTextNode(textNode, callbackOrProperty(...data));
@@ -3398,10 +3422,11 @@ var NativeDocument = (function (exports) {
3398
3422
  function useCache(fn) {
3399
3423
  let $cache = null;
3400
3424
 
3401
- const wrapper = function(args) {
3402
- if(!$cache) {
3403
- $cache = new TemplateCloner(fn);
3404
- }
3425
+ let wrapper = function(args) {
3426
+ $cache = new TemplateCloner(fn);
3427
+ wrapper = function(args) {
3428
+ return $cache.clone(args);
3429
+ };
3405
3430
  return $cache.clone(args);
3406
3431
  };
3407
3432