native-document 1.0.118 → 1.0.119

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.
@@ -363,16 +363,16 @@ var NativeComponents = (function (exports) {
363
363
  // });
364
364
  };
365
365
 
366
- let DebugManager$1 = {};
366
+ let DebugManager$2 = {};
367
367
  {
368
- DebugManager$1 = {
368
+ DebugManager$2 = {
369
369
  log() {},
370
370
  warn() {},
371
371
  error() {},
372
372
  disable() {}
373
373
  };
374
374
  }
375
- var DebugManager = DebugManager$1;
375
+ var DebugManager$1 = DebugManager$2;
376
376
 
377
377
  /**
378
378
  *
@@ -846,17 +846,17 @@ var NativeComponents = (function (exports) {
846
846
  const method = methods[name];
847
847
 
848
848
  if (typeof method !== 'function') {
849
- DebugManager.warn('NDElement.extend', `"${name}" is not a function, skipping`);
849
+ DebugManager$1.warn('NDElement.extend', `"${name}" is not a function, skipping`);
850
850
  continue;
851
851
  }
852
852
 
853
853
  if (protectedMethods.has(name)) {
854
- DebugManager.error('NDElement.extend', `Cannot override protected method "${name}"`);
854
+ DebugManager$1.error('NDElement.extend', `Cannot override protected method "${name}"`);
855
855
  throw new NativeDocumentError(`Cannot override protected method "${name}"`);
856
856
  }
857
857
 
858
858
  if (NDElement.prototype[name]) {
859
- DebugManager.warn('NDElement.extend', `Overwriting existing prototype method "${name}"`);
859
+ DebugManager$1.warn('NDElement.extend', `Overwriting existing prototype method "${name}"`);
860
860
  }
861
861
 
862
862
  NDElement.prototype[name] = method;
@@ -1081,7 +1081,7 @@ var NativeComponents = (function (exports) {
1081
1081
  }
1082
1082
  }
1083
1083
  if (cleanedCount > 0) {
1084
- DebugManager.log('Memory Auto Clean', `🧹 Cleaned ${cleanedCount} orphaned observables`);
1084
+ DebugManager$1.log('Memory Auto Clean', `🧹 Cleaned ${cleanedCount} orphaned observables`);
1085
1085
  }
1086
1086
  }
1087
1087
  };
@@ -2093,6 +2093,10 @@ var NativeComponents = (function (exports) {
2093
2093
  return ElementCreator.createStaticTextNode(null, this);
2094
2094
  };
2095
2095
 
2096
+ Number.prototype.toNdElement = function () {
2097
+ return ElementCreator.createStaticTextNode(null, this.toString());
2098
+ };
2099
+
2096
2100
  Element.prototype.toNdElement = function () {
2097
2101
  return this;
2098
2102
  };
@@ -2351,8 +2355,103 @@ var NativeComponents = (function (exports) {
2351
2355
  processStyleAttribute: bindStyleAttribute,
2352
2356
  };
2353
2357
 
2358
+ function AnchorWithSentinel(name) {
2359
+ const instance = Reflect.construct(DocumentFragment, [], AnchorWithSentinel);
2360
+ const sentinel = document.createComment((name || '') + ' Anchor Sentinel');
2361
+ const events = {};
2362
+
2363
+ instance.appendChild(sentinel);
2364
+
2365
+ const observer = new MutationObserver(() => {
2366
+ if (sentinel.parentNode !== instance && !(sentinel.parentNode instanceof DocumentFragment)) {
2367
+ events.connected && events.connected(sentinel.parentNode);
2368
+ }
2369
+ });
2370
+
2371
+ observer.observe(document, { childList: true, subtree: true });
2372
+
2373
+
2374
+ instance.$sentinel = sentinel;
2375
+ instance.$observer = observer;
2376
+ instance.$events = events;
2377
+
2378
+ return instance;
2379
+ }
2380
+
2381
+ AnchorWithSentinel.prototype = Object.create(DocumentFragment.prototype);
2382
+ AnchorWithSentinel.prototype.constructor = AnchorWithSentinel;
2383
+
2384
+ AnchorWithSentinel.prototype.onConnected = function(callback) {
2385
+ this.$events.connected = callback;
2386
+ return this;
2387
+ };
2388
+
2389
+ AnchorWithSentinel.prototype.onConnectedOnce = function(callback) {
2390
+ this.$events.connected = (parent) => {
2391
+ callback(parent);
2392
+ this.$observer.disconnect();
2393
+ this.$events.connectedOnce = null;
2394
+ };
2395
+ };
2396
+
2397
+ function oneChildAnchorOverwriting(anchor, parent) {
2398
+
2399
+ anchor.remove = () => {
2400
+ anchor.append.apply(anchor, parent.childNodes);
2401
+ };
2402
+
2403
+ anchor.appendChild = (child) => {
2404
+ child = Validator.isElement(child) ? child : ElementCreator.getChild(child);
2405
+ parent.appendChild(child);
2406
+ };
2407
+
2408
+ anchor.appendElement = anchor.appendChild;
2409
+
2410
+ anchor.removeChildren = () => {
2411
+ parent.replaceChildren();
2412
+ };
2413
+
2414
+ anchor.replaceContent = function(content) {
2415
+ const child = Validator.isElement(content) ? content : ElementCreator.getChild(content);
2416
+ parent.replaceChildren(child);
2417
+ };
2418
+ anchor.setContent = anchor.replaceContent;
2419
+
2420
+ anchor.insertBefore = (child, anchor) => {
2421
+ child = Validator.isElement(child) ? child : ElementCreator.getChild(child);
2422
+ parent.insertBefore(child, anchor);
2423
+ };
2424
+ anchor.appendChildBefore = anchor.insertBefore;
2425
+
2426
+ anchor.clear = anchor.remove;
2427
+ anchor.detach = anchor.remove;
2428
+
2429
+ anchor.replaceChildren = function() {
2430
+ parent.replaceChildren(...arguments);
2431
+ };
2432
+
2433
+ anchor.getByIndex = (index) => {
2434
+ return parent.childNodes[index];
2435
+ };
2436
+ }
2437
+
2354
2438
  function Anchor(name, isUniqueChild = false) {
2355
- const anchorFragment = document.createDocumentFragment();
2439
+ const anchorFragment = new AnchorWithSentinel(name);
2440
+
2441
+ /**
2442
+ * State :
2443
+ * 1. Not injected in the DOM
2444
+ * 2. Injected in the DOM and should be the only child of parent
2445
+ * 3. Injected in the DOM and the parent may have other children
2446
+ */
2447
+
2448
+ anchorFragment.onConnectedOnce((parent) => {
2449
+ if(isUniqueChild) {
2450
+ console.log('Lets overwrite some functions with parent ', parent);
2451
+ oneChildAnchorOverwriting(anchorFragment, parent);
2452
+ }
2453
+ });
2454
+
2356
2455
  anchorFragment.__Anchor__ = true;
2357
2456
 
2358
2457
  const anchorStart = document.createComment('Anchor Start : '+name);
@@ -2366,8 +2465,7 @@ var NativeComponents = (function (exports) {
2366
2465
  anchorFragment.nativeAppend = anchorFragment.append;
2367
2466
 
2368
2467
  const isParentUniqueChild = isUniqueChild
2369
- ? () => true
2370
- : (parent) => (parent.firstChild === anchorStart && parent.lastChild === anchorEnd);
2468
+ ? () => true: (parent) => (parent.firstChild === anchorStart && parent.lastChild === anchorEnd);
2371
2469
 
2372
2470
  const insertBefore = function(parent, child, target) {
2373
2471
  const childElement = Validator.isElement(child) ? child : ElementCreator.getChild(child);
@@ -2382,14 +2480,13 @@ var NativeComponents = (function (exports) {
2382
2480
  parent.insertBefore(childElement, target);
2383
2481
  };
2384
2482
 
2385
- anchorFragment.appendElement = function(child, before = null) {
2483
+ anchorFragment.appendElement = function(child) {
2386
2484
  const parentNode = anchorStart.parentNode;
2387
- const targetBefore = before || anchorEnd;
2388
2485
  if(parentNode === anchorFragment) {
2389
- parentNode.nativeInsertBefore(child, targetBefore);
2486
+ parentNode.nativeInsertBefore(child, anchorEnd);
2390
2487
  return;
2391
2488
  }
2392
- parentNode?.insertBefore(child, targetBefore);
2489
+ parentNode.insertBefore(child, anchorEnd);
2393
2490
  };
2394
2491
 
2395
2492
  anchorFragment.appendChild = function(child, before = null) {
@@ -2402,8 +2499,8 @@ var NativeComponents = (function (exports) {
2402
2499
  insertBefore(parent, child, before);
2403
2500
  };
2404
2501
 
2405
- anchorFragment.append = function(...args ) {
2406
- return anchorFragment.appendChild(args);
2502
+ anchorFragment.append = function() {
2503
+ return anchorFragment.appendChild(Array.from(arguments));
2407
2504
  };
2408
2505
 
2409
2506
  anchorFragment.removeChildren = function() {
@@ -2430,6 +2527,7 @@ var NativeComponents = (function (exports) {
2430
2527
  return;
2431
2528
  }
2432
2529
  if(isParentUniqueChild(parent)) {
2530
+ anchorFragment.append.apply(anchorFragment, parent.childNodes);
2433
2531
  parent.replaceChildren(anchorStart, anchorEnd);
2434
2532
  return;
2435
2533
  }
@@ -2474,9 +2572,11 @@ var NativeComponents = (function (exports) {
2474
2572
  anchorFragment.startElement = function() {
2475
2573
  return anchorStart;
2476
2574
  };
2575
+
2477
2576
  anchorFragment.restore = function() {
2478
2577
  anchorFragment.appendChild(anchorFragment);
2479
2578
  };
2579
+
2480
2580
  anchorFragment.clear = anchorFragment.remove;
2481
2581
  anchorFragment.detach = anchorFragment.remove;
2482
2582
 
@@ -2804,9 +2904,10 @@ var NativeComponents = (function (exports) {
2804
2904
  * @returns {Text}
2805
2905
  */
2806
2906
  const createTextNode = (value) => {
2807
- return (Validator.isObservable(value))
2808
- ? ElementCreator.createObservableNode(null, value)
2809
- : ElementCreator.createStaticTextNode(null, value);
2907
+ if(value) {
2908
+ return value.toNdElement();
2909
+ }
2910
+ return ElementCreator.createTextNode();
2810
2911
  };
2811
2912
 
2812
2913
 
@@ -2900,8 +3001,9 @@ var NativeComponents = (function (exports) {
2900
3001
  const methods = Object.keys(this.$ndMethods);
2901
3002
  if(methods.length === 1) {
2902
3003
  const methodName = methods[0];
3004
+ const callback = this.$ndMethods[methodName];
2903
3005
  steps.push((clonedNode, data) => {
2904
- clonedNode.nd[methodName](this.$ndMethods[methodName].bind(clonedNode, ...data));
3006
+ clonedNode.nd[methodName](callback.bind(clonedNode, ...data));
2905
3007
  });
2906
3008
  } else {
2907
3009
  steps.push((clonedNode, data) => {
@@ -3787,7 +3889,7 @@ var NativeComponents = (function (exports) {
3787
3889
  const $getStoreOrThrow = (method, name) => {
3788
3890
  const item = $stores.get(name);
3789
3891
  if (!item) {
3790
- DebugManager.error('Store', `Store.${method}('${name}') : store not found. Did you call Store.create('${name}') first?`);
3892
+ DebugManager$1.error('Store', `Store.${method}('${name}') : store not found. Did you call Store.create('${name}') first?`);
3791
3893
  throw new NativeDocumentError(
3792
3894
  `Store.${method}('${name}') : store not found.`
3793
3895
  );
@@ -3800,7 +3902,7 @@ var NativeComponents = (function (exports) {
3800
3902
  */
3801
3903
  const $applyReadOnly = (observer, name, context) => {
3802
3904
  const readOnlyError = (method) => () => {
3803
- DebugManager.error('Store', `Store.${context}('${name}') is read-only. '${method}()' is not allowed.`);
3905
+ DebugManager$1.error('Store', `Store.${context}('${name}') is read-only. '${method}()' is not allowed.`);
3804
3906
  throw new NativeDocumentError(
3805
3907
  `Store.${context}('${name}') is read-only.`
3806
3908
  );
@@ -3831,7 +3933,7 @@ var NativeComponents = (function (exports) {
3831
3933
  */
3832
3934
  create(name, value) {
3833
3935
  if ($stores.has(name)) {
3834
- DebugManager.warn('Store', `Store.create('${name}') : a store with this name already exists. Use Store.get('${name}') to retrieve it.`);
3936
+ DebugManager$1.warn('Store', `Store.create('${name}') : a store with this name already exists. Use Store.get('${name}') to retrieve it.`);
3835
3937
  throw new NativeDocumentError(
3836
3938
  `Store.create('${name}') : a store with this name already exists.`
3837
3939
  );
@@ -3852,7 +3954,7 @@ var NativeComponents = (function (exports) {
3852
3954
  */
3853
3955
  createResettable(name, value) {
3854
3956
  if ($stores.has(name)) {
3855
- DebugManager.warn('Store', `Store.createResettable('${name}') : a store with this name already exists.`);
3957
+ DebugManager$1.warn('Store', `Store.createResettable('${name}') : a store with this name already exists.`);
3856
3958
  throw new NativeDocumentError(
3857
3959
  `Store.createResettable('${name}') : a store with this name already exists.`
3858
3960
  );
@@ -3888,7 +3990,7 @@ var NativeComponents = (function (exports) {
3888
3990
  */
3889
3991
  createComposed(name, computation, dependencies) {
3890
3992
  if ($stores.has(name)) {
3891
- DebugManager.warn('Store', `Store.createComposed('${name}') : a store with this name already exists.`);
3993
+ DebugManager$1.warn('Store', `Store.createComposed('${name}') : a store with this name already exists.`);
3892
3994
  throw new NativeDocumentError(
3893
3995
  `Store.createComposed('${name}') : a store with this name already exists.`
3894
3996
  );
@@ -3911,7 +4013,7 @@ var NativeComponents = (function (exports) {
3911
4013
  }
3912
4014
  const depItem = $stores.get(depName);
3913
4015
  if (!depItem) {
3914
- DebugManager.error('Store', `Store.createComposed('${name}') : dependency '${depName}' not found. Create it first.`);
4016
+ DebugManager$1.error('Store', `Store.createComposed('${name}') : dependency '${depName}' not found. Create it first.`);
3915
4017
  throw new NativeDocumentError(
3916
4018
  `Store.createComposed('${name}') : dependency store '${depName}' not found.`
3917
4019
  );
@@ -3945,13 +4047,13 @@ var NativeComponents = (function (exports) {
3945
4047
  reset(name) {
3946
4048
  const item = $getStoreOrThrow('reset', name);
3947
4049
  if (item.composed) {
3948
- DebugManager.error('Store', `Store.reset('${name}') : composed stores cannot be reset. Their value is derived from dependencies.`);
4050
+ DebugManager$1.error('Store', `Store.reset('${name}') : composed stores cannot be reset. Their value is derived from dependencies.`);
3949
4051
  throw new NativeDocumentError(
3950
4052
  `Store.reset('${name}') : composed stores cannot be reset.`
3951
4053
  );
3952
4054
  }
3953
4055
  if (!item.resettable) {
3954
- DebugManager.error('Store', `Store.reset('${name}') : this store is not resettable. Use Store.createResettable('${name}', value) instead of Store.create().`);
4056
+ DebugManager$1.error('Store', `Store.reset('${name}') : this store is not resettable. Use Store.createResettable('${name}', value) instead of Store.create().`);
3955
4057
  throw new NativeDocumentError(
3956
4058
  `Store.reset('${name}') : this store is not resettable. Use Store.createResettable('${name}', value) instead of Store.create().`
3957
4059
  );
@@ -3972,7 +4074,7 @@ var NativeComponents = (function (exports) {
3972
4074
  const item = $getStoreOrThrow('use', name);
3973
4075
 
3974
4076
  if (item.composed) {
3975
- DebugManager.error('Store', `Store.use('${name}') : composed stores are read-only. Use Store.follow('${name}') instead.`);
4077
+ DebugManager$1.error('Store', `Store.use('${name}') : composed stores are read-only. Use Store.follow('${name}') instead.`);
3976
4078
  throw new NativeDocumentError(
3977
4079
  `Store.use('${name}') : composed stores are read-only. Use Store.follow('${name}') instead.`
3978
4080
  );
@@ -4039,7 +4141,7 @@ var NativeComponents = (function (exports) {
4039
4141
  get(name) {
4040
4142
  const item = $stores.get(name);
4041
4143
  if (!item) {
4042
- DebugManager.warn('Store', `Store.get('${name}') : store not found.`);
4144
+ DebugManager$1.warn('Store', `Store.get('${name}') : store not found.`);
4043
4145
  return null;
4044
4146
  }
4045
4147
  return item.observer;
@@ -4061,7 +4163,7 @@ var NativeComponents = (function (exports) {
4061
4163
  delete(name) {
4062
4164
  const item = $stores.get(name);
4063
4165
  if (!item) {
4064
- DebugManager.warn('Store', `Store.delete('${name}') : store not found, nothing to delete.`);
4166
+ DebugManager$1.warn('Store', `Store.delete('${name}') : store not found, nothing to delete.`);
4065
4167
  return;
4066
4168
  }
4067
4169
  item.subscribers.forEach(follower => follower.destroy());
@@ -4163,7 +4265,7 @@ var NativeComponents = (function (exports) {
4163
4265
  return undefined;
4164
4266
  },
4165
4267
  set(target, prop, value) {
4166
- DebugManager.error('Store', `Forbidden: You cannot overwrite the store key '${String(prop)}'. Use .use('${String(prop)}').set(value) instead.`);
4268
+ DebugManager$1.error('Store', `Forbidden: You cannot overwrite the store key '${String(prop)}'. Use .use('${String(prop)}').set(value) instead.`);
4167
4269
  throw new NativeDocumentError(`Store structure is immutable. Use .set() on the observable.`);
4168
4270
  },
4169
4271
  deleteProperty(target, prop) {