native-document 1.0.123 → 1.0.125

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.
@@ -14,7 +14,7 @@ var NativeComponents = (function (exports) {
14
14
  if(this.$element) {
15
15
  return this.$element.nd;
16
16
  }
17
- this.$storeElement(this.node());
17
+ this.$storeElement(this.toNdElement());
18
18
  return this.$element?.nd;
19
19
  }
20
20
  });
@@ -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$2 = DebugManager$1;
375
+ var DebugManager$1 = DebugManager$2;
376
376
 
377
377
  /**
378
378
  *
@@ -474,6 +474,16 @@ var NativeComponents = (function (exports) {
474
474
  unmounted: new WeakMap(),
475
475
  unmountedSupposedSize: 0,
476
476
  observer: null,
477
+ initObserver: () => {
478
+ if(DocumentObserver.observer) {
479
+ return;
480
+ }
481
+ DocumentObserver.observer = new MutationObserver(DocumentObserver.checkMutation);
482
+ DocumentObserver.observer.observe(document.body, {
483
+ childList: true,
484
+ subtree: true,
485
+ });
486
+ },
477
487
 
478
488
  executeMountedCallback(node) {
479
489
  const data = DocumentObserver.mounted.get(node);
@@ -521,6 +531,7 @@ var NativeComponents = (function (exports) {
521
531
  },
522
532
 
523
533
  checkMutation: function(mutationsList) {
534
+ console.log('mutationsList', mutationsList);
524
535
  for(const mutation of mutationsList) {
525
536
  if(DocumentObserver.mountedSupposedSize > 0) {
526
537
  for(const node of mutation.addedNodes) {
@@ -559,6 +570,8 @@ var NativeComponents = (function (exports) {
559
570
  let mountedRegistered = false;
560
571
  let unmountedRegistered = false;
561
572
 
573
+ DocumentObserver.initObserver();
574
+
562
575
  let data = {
563
576
  inDom,
564
577
  mounted: null,
@@ -636,12 +649,6 @@ var NativeComponents = (function (exports) {
636
649
  }
637
650
  };
638
651
 
639
- DocumentObserver.observer = new MutationObserver(DocumentObserver.checkMutation);
640
- DocumentObserver.observer.observe(document.body, {
641
- childList: true,
642
- subtree: true,
643
- });
644
-
645
652
  function NDElement(element) {
646
653
  this.$element = element;
647
654
  }
@@ -847,17 +854,17 @@ var NativeComponents = (function (exports) {
847
854
  const method = methods[name];
848
855
 
849
856
  if (typeof method !== 'function') {
850
- DebugManager$2.warn('NDElement.extend', `"${name}" is not a function, skipping`);
857
+ DebugManager$1.warn('NDElement.extend', `"${name}" is not a function, skipping`);
851
858
  continue;
852
859
  }
853
860
 
854
861
  if (protectedMethods.has(name)) {
855
- DebugManager$2.error('NDElement.extend', `Cannot override protected method "${name}"`);
862
+ DebugManager$1.error('NDElement.extend', `Cannot override protected method "${name}"`);
856
863
  throw new NativeDocumentError(`Cannot override protected method "${name}"`);
857
864
  }
858
865
 
859
866
  if (NDElement.prototype[name]) {
860
- DebugManager$2.warn('NDElement.extend', `Overwriting existing prototype method "${name}"`);
867
+ DebugManager$1.warn('NDElement.extend', `Overwriting existing prototype method "${name}"`);
861
868
  }
862
869
 
863
870
  NDElement.prototype[name] = method;
@@ -1082,7 +1089,7 @@ var NativeComponents = (function (exports) {
1082
1089
  }
1083
1090
  }
1084
1091
  if (cleanedCount > 0) {
1085
- DebugManager$2.log('Memory Auto Clean', `🧹 Cleaned ${cleanedCount} orphaned observables`);
1092
+ DebugManager$1.log('Memory Auto Clean', `🧹 Cleaned ${cleanedCount} orphaned observables`);
1086
1093
  }
1087
1094
  }
1088
1095
  };
@@ -2052,35 +2059,6 @@ var NativeComponents = (function (exports) {
2052
2059
  element.setAttribute(attributeName, value.val());
2053
2060
  };
2054
2061
 
2055
-
2056
- const AttributeHandlers = {
2057
- string: (element, attributeName, value) => element.setAttribute(attributeName, value),
2058
- number: (element, attributeName, value) => element.setAttribute(attributeName, value),
2059
- boolean: (element, attributeName, value) => bindBooleanAttribute(element, attributeName, value),
2060
- object: (element, attributeName, value) => {
2061
- if(value == null) {
2062
- return;
2063
- }
2064
-
2065
- if(value.handleNdAttribute) {
2066
- value.handleNdAttribute(element, attributeName);
2067
- return;
2068
- }
2069
-
2070
- if(attributeName === 'class') {
2071
- bindClassAttribute(element, value);
2072
- return;
2073
- }
2074
- if(attributeName === 'style') {
2075
- bindStyleAttribute(element, value);
2076
- return;
2077
- }
2078
- if(BOOLEAN_ATTRIBUTES.has(attributeName)) {
2079
- bindBooleanAttribute(element, attributeName, value);
2080
- }
2081
- }
2082
- };
2083
-
2084
2062
  /**
2085
2063
  *
2086
2064
  * @param {HTMLElement} element
@@ -2091,8 +2069,29 @@ var NativeComponents = (function (exports) {
2091
2069
  for(const originalAttributeName in attributes) {
2092
2070
  const attributeName = originalAttributeName.toLowerCase();
2093
2071
  let value = attributes[originalAttributeName];
2094
- const typeOf = typeof value;
2095
- AttributeHandlers[typeOf](element, attributeName, value);
2072
+ if(value == null) {
2073
+ continue;
2074
+ }
2075
+ if(value.handleNdAttribute) {
2076
+ value.handleNdAttribute(element, attributeName, value);
2077
+ continue;
2078
+ }
2079
+ if(typeof value === 'object') {
2080
+ if(attributeName === 'class') {
2081
+ bindClassAttribute(element, value);
2082
+ continue;
2083
+ }
2084
+ if(attributeName === 'style') {
2085
+ bindStyleAttribute(element, value);
2086
+ continue;
2087
+ }
2088
+ }
2089
+ if(BOOLEAN_ATTRIBUTES.has(attributeName)) {
2090
+ bindBooleanAttribute(element, attributeName, value);
2091
+ continue;
2092
+ }
2093
+
2094
+ element.setAttribute(attributeName, value);
2096
2095
  }
2097
2096
  return element;
2098
2097
  };
@@ -2362,9 +2361,11 @@ var NativeComponents = (function (exports) {
2362
2361
  function AnchorWithSentinel(name) {
2363
2362
  const instance = Reflect.construct(DocumentFragment, [], AnchorWithSentinel);
2364
2363
  const sentinel = document.createComment((name || '') + ' Anchor Sentinel');
2364
+ const anchorStart = document.createComment('Anchor Start : '+name);
2365
+ const anchorEnd = document.createComment('/ Anchor End '+name);
2365
2366
  const events = {};
2366
2367
 
2367
- instance.appendChild(sentinel);
2368
+ instance.append(anchorStart, sentinel, anchorEnd);
2368
2369
 
2369
2370
  const observer = new MutationObserver(() => {
2370
2371
  if (sentinel.parentNode !== instance && !(sentinel.parentNode instanceof DocumentFragment)) {
@@ -2376,6 +2377,8 @@ var NativeComponents = (function (exports) {
2376
2377
 
2377
2378
 
2378
2379
  instance.$sentinel = sentinel;
2380
+ instance.$start = anchorStart;
2381
+ instance.$end = anchorEnd;
2379
2382
  instance.$observer = observer;
2380
2383
  instance.$events = events;
2381
2384
 
@@ -2479,11 +2482,8 @@ var NativeComponents = (function (exports) {
2479
2482
 
2480
2483
  anchorFragment.__Anchor__ = true;
2481
2484
 
2482
- const anchorStart = document.createComment('Anchor Start : '+name);
2483
- const anchorEnd = document.createComment('/ Anchor End '+name);
2484
-
2485
- anchorFragment.appendChild(anchorStart);
2486
- anchorFragment.appendChild(anchorEnd);
2485
+ const anchorStart = anchorFragment.$start;
2486
+ const anchorEnd = anchorFragment.$end;
2487
2487
 
2488
2488
  anchorFragment.nativeInsertBefore = anchorFragment.insertBefore;
2489
2489
  anchorFragment.nativeAppendChild = anchorFragment.appendChild;
@@ -3007,7 +3007,11 @@ var NativeComponents = (function (exports) {
3007
3007
 
3008
3008
  return (attr, children) => createElement(attr, children)
3009
3009
  }
3010
- return () => Anchor('');
3010
+ return (children, name = '') => {
3011
+ const anchor = Anchor(name);
3012
+ anchor.append(children);
3013
+ return anchor;
3014
+ };
3011
3015
  }
3012
3016
 
3013
3017
  function NodeCloner($element) {
@@ -3948,7 +3952,7 @@ var NativeComponents = (function (exports) {
3948
3952
  const $getStoreOrThrow = (method, name) => {
3949
3953
  const item = $stores.get(name);
3950
3954
  if (!item) {
3951
- DebugManager$2.error('Store', `Store.${method}('${name}') : store not found. Did you call Store.create('${name}') first?`);
3955
+ DebugManager$1.error('Store', `Store.${method}('${name}') : store not found. Did you call Store.create('${name}') first?`);
3952
3956
  throw new NativeDocumentError(
3953
3957
  `Store.${method}('${name}') : store not found.`
3954
3958
  );
@@ -3961,7 +3965,7 @@ var NativeComponents = (function (exports) {
3961
3965
  */
3962
3966
  const $applyReadOnly = (observer, name, context) => {
3963
3967
  const readOnlyError = (method) => () => {
3964
- DebugManager$2.error('Store', `Store.${context}('${name}') is read-only. '${method}()' is not allowed.`);
3968
+ DebugManager$1.error('Store', `Store.${context}('${name}') is read-only. '${method}()' is not allowed.`);
3965
3969
  throw new NativeDocumentError(
3966
3970
  `Store.${context}('${name}') is read-only.`
3967
3971
  );
@@ -3992,7 +3996,7 @@ var NativeComponents = (function (exports) {
3992
3996
  */
3993
3997
  create(name, value) {
3994
3998
  if ($stores.has(name)) {
3995
- DebugManager$2.warn('Store', `Store.create('${name}') : a store with this name already exists. Use Store.get('${name}') to retrieve it.`);
3999
+ DebugManager$1.warn('Store', `Store.create('${name}') : a store with this name already exists. Use Store.get('${name}') to retrieve it.`);
3996
4000
  throw new NativeDocumentError(
3997
4001
  `Store.create('${name}') : a store with this name already exists.`
3998
4002
  );
@@ -4013,7 +4017,7 @@ var NativeComponents = (function (exports) {
4013
4017
  */
4014
4018
  createResettable(name, value) {
4015
4019
  if ($stores.has(name)) {
4016
- DebugManager$2.warn('Store', `Store.createResettable('${name}') : a store with this name already exists.`);
4020
+ DebugManager$1.warn('Store', `Store.createResettable('${name}') : a store with this name already exists.`);
4017
4021
  throw new NativeDocumentError(
4018
4022
  `Store.createResettable('${name}') : a store with this name already exists.`
4019
4023
  );
@@ -4049,7 +4053,7 @@ var NativeComponents = (function (exports) {
4049
4053
  */
4050
4054
  createComposed(name, computation, dependencies) {
4051
4055
  if ($stores.has(name)) {
4052
- DebugManager$2.warn('Store', `Store.createComposed('${name}') : a store with this name already exists.`);
4056
+ DebugManager$1.warn('Store', `Store.createComposed('${name}') : a store with this name already exists.`);
4053
4057
  throw new NativeDocumentError(
4054
4058
  `Store.createComposed('${name}') : a store with this name already exists.`
4055
4059
  );
@@ -4072,7 +4076,7 @@ var NativeComponents = (function (exports) {
4072
4076
  }
4073
4077
  const depItem = $stores.get(depName);
4074
4078
  if (!depItem) {
4075
- DebugManager$2.error('Store', `Store.createComposed('${name}') : dependency '${depName}' not found. Create it first.`);
4079
+ DebugManager$1.error('Store', `Store.createComposed('${name}') : dependency '${depName}' not found. Create it first.`);
4076
4080
  throw new NativeDocumentError(
4077
4081
  `Store.createComposed('${name}') : dependency store '${depName}' not found.`
4078
4082
  );
@@ -4106,13 +4110,13 @@ var NativeComponents = (function (exports) {
4106
4110
  reset(name) {
4107
4111
  const item = $getStoreOrThrow('reset', name);
4108
4112
  if (item.composed) {
4109
- DebugManager$2.error('Store', `Store.reset('${name}') : composed stores cannot be reset. Their value is derived from dependencies.`);
4113
+ DebugManager$1.error('Store', `Store.reset('${name}') : composed stores cannot be reset. Their value is derived from dependencies.`);
4110
4114
  throw new NativeDocumentError(
4111
4115
  `Store.reset('${name}') : composed stores cannot be reset.`
4112
4116
  );
4113
4117
  }
4114
4118
  if (!item.resettable) {
4115
- DebugManager$2.error('Store', `Store.reset('${name}') : this store is not resettable. Use Store.createResettable('${name}', value) instead of Store.create().`);
4119
+ DebugManager$1.error('Store', `Store.reset('${name}') : this store is not resettable. Use Store.createResettable('${name}', value) instead of Store.create().`);
4116
4120
  throw new NativeDocumentError(
4117
4121
  `Store.reset('${name}') : this store is not resettable. Use Store.createResettable('${name}', value) instead of Store.create().`
4118
4122
  );
@@ -4133,7 +4137,7 @@ var NativeComponents = (function (exports) {
4133
4137
  const item = $getStoreOrThrow('use', name);
4134
4138
 
4135
4139
  if (item.composed) {
4136
- DebugManager$2.error('Store', `Store.use('${name}') : composed stores are read-only. Use Store.follow('${name}') instead.`);
4140
+ DebugManager$1.error('Store', `Store.use('${name}') : composed stores are read-only. Use Store.follow('${name}') instead.`);
4137
4141
  throw new NativeDocumentError(
4138
4142
  `Store.use('${name}') : composed stores are read-only. Use Store.follow('${name}') instead.`
4139
4143
  );
@@ -4200,7 +4204,7 @@ var NativeComponents = (function (exports) {
4200
4204
  get(name) {
4201
4205
  const item = $stores.get(name);
4202
4206
  if (!item) {
4203
- DebugManager$2.warn('Store', `Store.get('${name}') : store not found.`);
4207
+ DebugManager$1.warn('Store', `Store.get('${name}') : store not found.`);
4204
4208
  return null;
4205
4209
  }
4206
4210
  return item.observer;
@@ -4222,7 +4226,7 @@ var NativeComponents = (function (exports) {
4222
4226
  delete(name) {
4223
4227
  const item = $stores.get(name);
4224
4228
  if (!item) {
4225
- DebugManager$2.warn('Store', `Store.delete('${name}') : store not found, nothing to delete.`);
4229
+ DebugManager$1.warn('Store', `Store.delete('${name}') : store not found, nothing to delete.`);
4226
4230
  return;
4227
4231
  }
4228
4232
  item.subscribers.forEach(follower => follower.destroy());
@@ -4324,7 +4328,7 @@ var NativeComponents = (function (exports) {
4324
4328
  return undefined;
4325
4329
  },
4326
4330
  set(target, prop, value) {
4327
- DebugManager$2.error('Store', `Forbidden: You cannot overwrite the store key '${String(prop)}'. Use .use('${String(prop)}').set(value) instead.`);
4331
+ DebugManager$1.error('Store', `Forbidden: You cannot overwrite the store key '${String(prop)}'. Use .use('${String(prop)}').set(value) instead.`);
4328
4332
  throw new NativeDocumentError(`Store structure is immutable. Use .set() on the observable.`);
4329
4333
  },
4330
4334
  deleteProperty(target, prop) {
@@ -5808,7 +5812,7 @@ var NativeComponents = (function (exports) {
5808
5812
  };
5809
5813
 
5810
5814
  function MenuDivider() {
5811
- if(!this instanceof MenuDivider) {
5815
+ if(!(this instanceof MenuDivider)) {
5812
5816
  return new MenuDivider();
5813
5817
  }
5814
5818
 
@@ -5890,6 +5894,11 @@ var NativeComponents = (function (exports) {
5890
5894
  Menu.defaultTemplate = template.menu;
5891
5895
  };
5892
5896
 
5897
+ Menu.prototype.title = function(title) {
5898
+ this.$description.title = title;
5899
+ return this;
5900
+ };
5901
+
5893
5902
  Menu.prototype.orientation = function(orientation) {
5894
5903
  this.$description.orientation = orientation;
5895
5904
  return this;
@@ -5944,7 +5953,7 @@ var NativeComponents = (function (exports) {
5944
5953
 
5945
5954
  function ContextMenu(config = {}) {
5946
5955
  if(!(this instanceof ContextMenu)) {
5947
- return ContextMenu(config);
5956
+ return new ContextMenu(config);
5948
5957
  }
5949
5958
  Menu.call(this, config);
5950
5959
 
@@ -6007,6 +6016,16 @@ var NativeComponents = (function (exports) {
6007
6016
 
6008
6017
  this.$description = {
6009
6018
  items: [],
6019
+ link: null,
6020
+ target: null,
6021
+ label: null,
6022
+ icon: null,
6023
+ shortcut: null,
6024
+ disabled: false,
6025
+ selected: false,
6026
+ value: null,
6027
+ data: null,
6028
+ render: null,
6010
6029
  ...config
6011
6030
  };
6012
6031
 
@@ -6026,6 +6045,16 @@ var NativeComponents = (function (exports) {
6026
6045
  return this;
6027
6046
  };
6028
6047
 
6048
+ MenuItem.prototype.link = function(link) {
6049
+ this.$description.link = link;
6050
+ return this;
6051
+ };
6052
+
6053
+ MenuItem.prototype.target = function(target) {
6054
+ this.$description.target = target;
6055
+ return this;
6056
+ };
6057
+
6029
6058
  MenuItem.prototype.icon = function(icon) {
6030
6059
  this.$description.icon = icon;
6031
6060
  return this;