native-document 1.0.46 → 1.0.48

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.
Files changed (110) hide show
  1. package/dist/native-document.dev.js +270 -116
  2. package/dist/native-document.dev.js.map +1 -1
  3. package/dist/native-document.devtools.min.js +1 -1
  4. package/dist/native-document.min.js +1 -1
  5. package/docs/anchor.md +0 -0
  6. package/docs/conditional-rendering.md +0 -0
  7. package/docs/contributing.md +0 -0
  8. package/docs/core-concepts.md +0 -0
  9. package/docs/elements.md +0 -0
  10. package/docs/extending-native-document-element.md +0 -0
  11. package/docs/getting-started.md +0 -0
  12. package/docs/lifecycle-events.md +0 -0
  13. package/docs/list-rendering.md +0 -0
  14. package/docs/memory-management.md +0 -0
  15. package/docs/native-document-element.md +0 -0
  16. package/docs/observables.md +0 -0
  17. package/docs/routing.md +0 -0
  18. package/docs/state-management.md +0 -0
  19. package/docs/validation.md +0 -0
  20. package/elements.d.ts +0 -0
  21. package/elements.js +0 -0
  22. package/eslint.config.js +0 -0
  23. package/index.d.ts +1 -0
  24. package/index.js +2 -0
  25. package/package.json +3 -2
  26. package/readme.md +0 -0
  27. package/rollup.config.js +0 -0
  28. package/router.js +0 -0
  29. package/src/data/MemoryManager.js +0 -0
  30. package/src/data/Observable.js +17 -0
  31. package/src/data/ObservableArray.js +113 -0
  32. package/src/data/ObservableChecker.js +0 -0
  33. package/src/data/ObservableItem.js +3 -1
  34. package/src/data/ObservableWhen.js +23 -0
  35. package/src/data/Store.js +0 -0
  36. package/src/data/observable-helpers/array.js +4 -100
  37. package/src/data/observable-helpers/batch.js +0 -0
  38. package/src/data/observable-helpers/computed.js +0 -0
  39. package/src/data/observable-helpers/object.js +10 -5
  40. package/src/devtools/app/App.js +0 -0
  41. package/src/devtools/app/app.css +0 -0
  42. package/src/devtools/index.js +0 -0
  43. package/src/devtools/plugin.js +0 -0
  44. package/src/devtools/widget/DevToolsWidget.js +0 -0
  45. package/src/elements/anchor.js +0 -0
  46. package/src/elements/content-formatter.js +0 -0
  47. package/src/elements/control/for-each-array.js +0 -0
  48. package/src/elements/control/for-each.js +0 -0
  49. package/src/elements/control/show-if.js +1 -1
  50. package/src/elements/control/show-when.js +31 -0
  51. package/src/elements/control/switch.js +0 -0
  52. package/src/elements/description-list.js +0 -0
  53. package/src/elements/form.js +0 -0
  54. package/src/elements/html5-semantics.js +0 -0
  55. package/src/elements/img.js +0 -0
  56. package/src/elements/index.js +1 -0
  57. package/src/elements/interactive.js +0 -0
  58. package/src/elements/list.js +0 -0
  59. package/src/elements/medias.js +0 -0
  60. package/src/elements/meta-data.js +0 -0
  61. package/src/elements/table.js +0 -0
  62. package/src/errors/ArgTypesError.js +0 -0
  63. package/src/errors/NativeDocumentError.js +0 -0
  64. package/src/errors/RouterError.js +0 -0
  65. package/src/router/Route.js +0 -0
  66. package/src/router/RouteGroupHelper.js +0 -0
  67. package/src/router/Router.js +0 -0
  68. package/src/router/RouterComponent.js +0 -0
  69. package/src/router/link.js +0 -0
  70. package/src/router/modes/HashRouter.js +0 -0
  71. package/src/router/modes/HistoryRouter.js +0 -0
  72. package/src/router/modes/MemoryRouter.js +0 -0
  73. package/src/utils/args-types.js +0 -0
  74. package/src/utils/debug-manager.js +0 -0
  75. package/src/utils/events.js +0 -0
  76. package/src/utils/fetch/NativeFetch.js +0 -0
  77. package/src/utils/helpers.js +0 -0
  78. package/src/utils/memoize.js +53 -0
  79. package/src/utils/plugins-manager.js +0 -0
  80. package/src/utils/property-accumulator.js +0 -0
  81. package/src/utils/prototypes.js +4 -4
  82. package/src/utils/service.js +6 -0
  83. package/src/utils/validator.js +6 -0
  84. package/src/wrappers/AttributesWrapper.js +3 -3
  85. package/src/wrappers/DocumentObserver.js +0 -0
  86. package/src/wrappers/ElementCreator.js +0 -0
  87. package/src/wrappers/HtmlElementWrapper.js +0 -0
  88. package/src/wrappers/NDElement.js +0 -0
  89. package/src/wrappers/NdPrototype.js +0 -0
  90. package/src/wrappers/SingletonView.js +0 -0
  91. package/src/wrappers/TemplateCloner.js +0 -0
  92. package/src/wrappers/constants.js +0 -0
  93. package/types/args-types.d.ts +0 -0
  94. package/types/control-flow.d.ts +7 -3
  95. package/types/elements.d.ts +0 -0
  96. package/types/forms.d.ts +0 -0
  97. package/types/images.d.ts +0 -0
  98. package/types/memoize.d.ts +16 -0
  99. package/types/nd-element.d.ts +0 -0
  100. package/types/observable.d.ts +21 -3
  101. package/types/plugins-manager.d.ts +0 -0
  102. package/types/polyfill.d.ts +0 -0
  103. package/types/property-accumulator.d.ts +0 -0
  104. package/types/router.d.ts +0 -0
  105. package/types/singleton.d.ts +0 -0
  106. package/types/store.d.ts +0 -0
  107. package/types/template-cloner.ts +0 -0
  108. package/types/validator.ts +0 -0
  109. package/utils.d.ts +0 -0
  110. package/utils.js +0 -0
@@ -1,10 +1,10 @@
1
1
  var NativeDocument = (function (exports) {
2
2
  'use strict';
3
3
 
4
- let DebugManager = {};
4
+ let DebugManager$1 = {};
5
5
 
6
6
  {
7
- DebugManager = {
7
+ DebugManager$1 = {
8
8
  enabled: false,
9
9
 
10
10
  enable() {
@@ -35,7 +35,7 @@ var NativeDocument = (function (exports) {
35
35
  };
36
36
 
37
37
  }
38
- var DebugManager$1 = DebugManager;
38
+ var DebugManager = DebugManager$1;
39
39
 
40
40
  const MemoryManager = (function() {
41
41
 
@@ -84,7 +84,7 @@ var NativeDocument = (function (exports) {
84
84
  }
85
85
  }
86
86
  if (cleanedCount > 0) {
87
- DebugManager$1.log('Memory Auto Clean', `🧹 Cleaned ${cleanedCount} orphaned observables`);
87
+ DebugManager.log('Memory Auto Clean', `🧹 Cleaned ${cleanedCount} orphaned observables`);
88
88
  }
89
89
  }
90
90
  };
@@ -207,7 +207,7 @@ var NativeDocument = (function (exports) {
207
207
  try{
208
208
  callback.call(plugin, ...data);
209
209
  } catch (error) {
210
- DebugManager$1.error('Plugin Manager', `Error in plugin ${plugin.$name} for event ${eventName}`, error);
210
+ DebugManager.error('Plugin Manager', `Error in plugin ${plugin.$name} for event ${eventName}`, error);
211
211
  }
212
212
  }
213
213
  }
@@ -215,6 +215,29 @@ var NativeDocument = (function (exports) {
215
215
  };
216
216
  }());
217
217
 
218
+ const ObservableWhen = function(observer, value) {
219
+ this.$target = value;
220
+ this.$observer = observer;
221
+ };
222
+
223
+ ObservableWhen.prototype.__$isObservableWhen = true;
224
+
225
+ ObservableWhen.prototype.subscribe = function(callback) {
226
+ return this.$observer.on(this.$target, callback);
227
+ };
228
+
229
+ ObservableWhen.prototype.val = function() {
230
+ return this.$observer.$currentValue === this.$target;
231
+ };
232
+
233
+ ObservableWhen.prototype.isMath = function() {
234
+ return this.$observer.$currentValue === this.$target;
235
+ };
236
+
237
+ ObservableWhen.prototype.isActive = function() {
238
+ return this.$observer.$currentValue === this.$target;
239
+ };
240
+
218
241
  /**
219
242
  *
220
243
  * @param {*} value
@@ -245,6 +268,7 @@ var NativeDocument = (function (exports) {
245
268
  ObservableItem.prototype.__$isObservable = true;
246
269
  const DEFAULT_OPERATIONS = {};
247
270
  const noneTrigger = function() {};
271
+
248
272
  ObservableItem.prototype.triggerFirstListener = function(operations) {
249
273
  this.$listeners[0](this.$currentValue, this.$previousValue, operations || {});
250
274
  };
@@ -371,7 +395,7 @@ var NativeDocument = (function (exports) {
371
395
  ObservableItem.prototype.subscribe = function(callback, target = null) {
372
396
  this.$listeners = this.$listeners ?? [];
373
397
  if (this.$isCleanedUp) {
374
- DebugManager$1.warn('Observable subscription', '⚠️ Attempted to subscribe to a cleaned up observable.');
398
+ DebugManager.warn('Observable subscription', '⚠️ Attempted to subscribe to a cleaned up observable.');
375
399
  return () => {};
376
400
  }
377
401
  if (typeof callback !== 'function') {
@@ -445,7 +469,7 @@ var NativeDocument = (function (exports) {
445
469
  };
446
470
 
447
471
  ObservableItem.prototype.when = function(value) {
448
- return {$target: value, $observer: this};
472
+ return new ObservableWhen(this, value);
449
473
  };
450
474
 
451
475
  ObservableItem.prototype.toString = function() {
@@ -869,6 +893,12 @@ var NativeDocument = (function (exports) {
869
893
  isObservable(value) {
870
894
  return value?.__$isObservable || value instanceof ObservableItem || value instanceof ObservableChecker;
871
895
  },
896
+ isObservableWhenResult(value) {
897
+ return value && (value.__$isObservableWhen || (typeof value === 'object' && '$target' in value && '$observer' in value));
898
+ },
899
+ isArrayObservable(value) {
900
+ return value?.__$isObservableArray;
901
+ },
872
902
  isProxy(value) {
873
903
  return value?.__isProxy__
874
904
  },
@@ -987,7 +1017,7 @@ var NativeDocument = (function (exports) {
987
1017
  const foundReserved = Object.keys(attributes).filter(key => reserved.includes(key));
988
1018
 
989
1019
  if (foundReserved.length > 0) {
990
- DebugManager$1.warn('Validator', `Reserved attributes found: ${foundReserved.join(', ')}`);
1020
+ DebugManager.warn('Validator', `Reserved attributes found: ${foundReserved.join(', ')}`);
991
1021
  }
992
1022
 
993
1023
  return attributes;
@@ -1035,7 +1065,7 @@ var NativeDocument = (function (exports) {
1035
1065
  element.appendChild = function(child, before = null) {
1036
1066
  const parent = anchorEnd.parentNode;
1037
1067
  if(!parent) {
1038
- DebugManager$1.error('Anchor', 'Anchor : parent not found', child);
1068
+ DebugManager.error('Anchor', 'Anchor : parent not found', child);
1039
1069
  return;
1040
1070
  }
1041
1071
  before = before ?? anchorEnd;
@@ -1153,6 +1183,23 @@ var NativeDocument = (function (exports) {
1153
1183
  return new ObservableItem(value);
1154
1184
  }
1155
1185
 
1186
+ /**
1187
+ *
1188
+ * @param {string} propertyName
1189
+ */
1190
+ Observable.useValueProperty = function(propertyName = 'value') {
1191
+ Object.defineProperty(ObservableItem.prototype, propertyName, {
1192
+ get() {
1193
+ return this.$currentValue;
1194
+ },
1195
+ set(value) {
1196
+ this.set(value);
1197
+ },
1198
+ configurable: true,
1199
+ });
1200
+ };
1201
+
1202
+
1156
1203
  /**
1157
1204
  *
1158
1205
  * @param id
@@ -1225,9 +1272,9 @@ var NativeDocument = (function (exports) {
1225
1272
  value.subscribe(toggleElementClass.bind(null, element, className));
1226
1273
  continue;
1227
1274
  }
1228
- if(value.$observer) {
1229
- element.classes.toggle(className, value.$observer.val() === value.$target);
1230
- value.$observer.on(value.$target, toggleElementClass.bind(null, element, className));
1275
+ if(Validator.isObservableWhenResult(value)) {
1276
+ element.classes.toggle(className, value.isMath());
1277
+ value.subscribe(toggleElementClass.bind(null, element, className));
1231
1278
  continue;
1232
1279
  }
1233
1280
  if(value.$hydrate) {
@@ -1938,15 +1985,15 @@ var NativeDocument = (function (exports) {
1938
1985
  };
1939
1986
 
1940
1987
  Function.prototype.cached = function(...args) {
1941
- let $cache = null;
1942
- let getCache = function(){ return $cache; };
1988
+ let $cache;
1989
+ let getCache = () => $cache;
1943
1990
  return () => {
1944
1991
  if(!$cache) {
1945
1992
  $cache = this.apply(this, args);
1946
1993
  if($cache.cloneNode) {
1947
- getCache = function() { return $cache.cloneNode(true); };
1994
+ getCache = () => $cache.cloneNode(true);
1948
1995
  } else if($cache.$element) {
1949
- getCache = function() { return new NDElement($cache.$element.cloneNode(true)); };
1996
+ getCache = () => new NDElement($cache.$element.cloneNode(true));
1950
1997
  }
1951
1998
  }
1952
1999
  return getCache();
@@ -2032,108 +2079,175 @@ var NativeDocument = (function (exports) {
2032
2079
  };
2033
2080
  };
2034
2081
 
2035
- const methods = ['push', 'pop', 'shift', 'unshift', 'reverse', 'sort', 'splice'];
2082
+ const once = (fn) => {
2083
+ let result = null;
2084
+ return (...args) => {
2085
+ if(result === null) {
2086
+ result = fn(...args);
2087
+ }
2088
+ return result;
2089
+ };
2090
+ };
2091
+
2092
+ const autoOnce = (fn) => {
2093
+ let target = null;
2094
+ return new Proxy({}, {
2095
+ get: (_, key) => {
2096
+ if(target === null) {
2097
+ target = fn();
2098
+ }
2099
+ return target[key];
2100
+ }
2101
+ });
2102
+ };
2036
2103
 
2037
- /**
2038
- *
2039
- * @param {Array} target
2040
- * @returns {ObservableItem}
2041
- */
2042
- Observable.array = function(target, { propagation = false, deep = false } = {}) {
2104
+ const memoize = (fn) => {
2105
+ const cache = new Map();
2106
+ return (...args) => {
2107
+ const [key, ...rest] = args;
2108
+ if(!cache.has(key)) {
2109
+ cache.set(key, fn(...rest));
2110
+ }
2111
+ return cache.get(key);
2112
+ };
2113
+ };
2114
+
2115
+ const autoMemoize = (fn) => {
2116
+ const cache = new Map();
2117
+ return new Proxy({}, {
2118
+ get: (_, key) => {
2119
+ if(!cache.has(key)) {
2120
+ if(fn.length > 0) {
2121
+ return (...args) => {
2122
+ const result = fn(...args);
2123
+ cache.set(key, result);
2124
+ return result;
2125
+ }
2126
+ }
2127
+ cache.set(key, fn());
2128
+ }
2129
+ return cache.get(key);
2130
+ }
2131
+ });
2132
+ };
2133
+
2134
+ const Service = {
2135
+ once: fn => autoOnce(fn),
2136
+ memoize: fn => autoMemoize(fn)
2137
+ };
2138
+
2139
+ const mutationMethods = ['push', 'pop', 'shift', 'unshift', 'reverse', 'sort', 'splice'];
2140
+ const noMutationMethods = ['map', 'forEach', 'filter', 'reduce', 'some', 'every', 'find', 'findIndex', 'concat', 'includes', 'indexOf'];
2141
+
2142
+
2143
+ const ObservableArray = function (target, { propagation = false, deep = false } = {}) {
2043
2144
  if(!Array.isArray(target)) {
2044
2145
  throw new NativeDocumentError('Observable.array : target must be an array');
2045
2146
  }
2046
- const observer = Observable(target);
2047
2147
 
2048
- PluginsManager.emit('CreateObservableArray', observer);
2148
+ ObservableItem.apply(this, [target]);
2149
+ PluginsManager.emit('CreateObservableArray', this);
2150
+ };
2049
2151
 
2050
- methods.forEach((method) => {
2051
- observer[method] = function(...values) {
2052
- const result = observer.val()[method](...values);
2053
- observer.trigger({ action: method, args: values, result });
2054
- return result;
2055
- };
2056
- });
2152
+ ObservableArray.prototype.__$isObservableArray = true;
2057
2153
 
2058
- observer.clear = function() {
2059
- observer.val().length = 0;
2060
- observer.trigger({ action: 'clear' });
2061
- return true;
2154
+ mutationMethods.forEach((method) => {
2155
+ ObservableArray.prototype[method] = function(...values) {
2156
+ const result = this.$currentValue[method](...values);
2157
+ this.trigger({ action: method, args: values, result });
2158
+ return result;
2062
2159
  };
2160
+ });
2063
2161
 
2064
- observer.merge = function(values) {
2065
- observer.$value.push(...values);
2066
- observer.trigger({ action: 'merge', args: values });
2162
+ noMutationMethods.forEach((method) => {
2163
+ ObservableArray.prototype[method] = function(...values) {
2164
+ return this.$currentValue[method](...values);
2067
2165
  };
2166
+ });
2068
2167
 
2069
- observer.populateAndRender = function(iteration, callback) {
2070
- observer.trigger({ action: 'populate', args: [observer.val(), iteration, callback] });
2071
- };
2168
+ ObservableArray.prototype.clear = function() {
2169
+ this.$currentValue.length = 0;
2170
+ this.trigger({ action: 'clear' });
2171
+ return true;
2172
+ };
2072
2173
 
2073
- observer.removeItem = function(item) {
2074
- const indexOfItem = observer.val().indexOf(item);
2075
- return observer.remove(indexOfItem);
2076
- };
2174
+ ObservableArray.prototype.at = function(index) {
2175
+ return this.$currentValue[index];
2176
+ };
2077
2177
 
2078
- observer.remove = function(index) {
2079
- const deleted = observer.val().splice(index, 1);
2080
- if(deleted.length === 0) {
2081
- return [];
2082
- }
2083
- observer.trigger({ action: 'remove', args: [index], result: deleted[0] });
2084
- return deleted;
2085
- };
2178
+ ObservableArray.prototype.merge = function(values) {
2179
+ this.$currentValue.push(...values);
2180
+ this.trigger({ action: 'merge', args: values });
2181
+ };
2086
2182
 
2087
- observer.swap = function(indexA, indexB) {
2088
- const value = observer.val();
2089
- const length = value.length;
2090
- if(length < indexA || length < indexB) {
2091
- return false;
2092
- }
2093
- if(indexB < indexA) {
2094
- const temp = indexA;
2095
- indexA = indexB;
2096
- indexB = temp;
2183
+ /**
2184
+ *
2185
+ * @param {Function} condition
2186
+ * @returns {number}
2187
+ */
2188
+ ObservableArray.prototype.count = function(condition) {
2189
+ let count = 0;
2190
+ this.$currentValue.forEach((item, index) => {
2191
+ if(condition(item, index)) {
2192
+ count++;
2097
2193
  }
2098
- const elementA = value[indexA];
2099
- const elementB = value[indexB];
2194
+ });
2195
+ return count;
2196
+ };
2100
2197
 
2101
- value[indexA] = elementB;
2102
- value[indexB] = elementA;
2103
- observer.trigger({ action: 'swap', args: [indexA, indexB], result: [elementA, elementB] });
2104
- return true;
2105
- };
2198
+ ObservableArray.prototype.length = function() {
2199
+ return this.$currentValue.length;
2200
+ };
2106
2201
 
2107
- observer.length = function() {
2108
- return observer.val().length;
2109
- };
2202
+ ObservableArray.prototype.swap = function(indexA, indexB) {
2203
+ const value = this.$currentValue;
2204
+ const length = value.length;
2205
+ if(length < indexA || length < indexB) {
2206
+ return false;
2207
+ }
2208
+ if(indexB < indexA) {
2209
+ const temp = indexA;
2210
+ indexA = indexB;
2211
+ indexB = temp;
2212
+ }
2213
+ const elementA = value[indexA];
2214
+ const elementB = value[indexB];
2110
2215
 
2111
- /**
2112
- *
2113
- * @param {Function} condition
2114
- * @returns {number}
2115
- */
2116
- observer.count = (condition) => {
2117
- let count = 0;
2118
- observer.val().forEach((item, index) => {
2119
- if(condition(item, index)) {
2120
- count++;
2121
- }
2122
- });
2123
- return count;
2124
- };
2125
- observer.isEmpty = function() {
2126
- return observer.val().length === 0;
2127
- };
2216
+ value[indexA] = elementB;
2217
+ value[indexB] = elementA;
2218
+ this.trigger({ action: 'swap', args: [indexA, indexB], result: [elementA, elementB] });
2219
+ return true;
2220
+ };
2128
2221
 
2129
- const overrideMethods = ['map', 'filter', 'reduce', 'some', 'every', 'find', 'findIndex', 'concat', 'includes', 'indexOf'];
2130
- overrideMethods.forEach((method) => {
2131
- observer[method] = (...args) => {
2132
- return observer.val()[method](...args);
2133
- };
2134
- });
2222
+ ObservableArray.prototype.remove = function(index) {
2223
+ const deleted = this.$currentValue.splice(index, 1);
2224
+ if(deleted.length === 0) {
2225
+ return [];
2226
+ }
2227
+ this.trigger({ action: 'remove', args: [index], result: deleted[0] });
2228
+ return deleted;
2229
+ };
2230
+
2231
+ ObservableArray.prototype.removeItem = function(item) {
2232
+ const indexOfItem = this.$currentValue.indexOf(item);
2233
+ return this.remove(indexOfItem);
2234
+ };
2135
2235
 
2136
- return observer;
2236
+ ObservableArray.prototype.isEmpty = function() {
2237
+ return this.$currentValue.length === 0;
2238
+ };
2239
+
2240
+ ObservableArray.prototype.populateAndRender = function(iteration, callback) {
2241
+ this.trigger({ action: 'populate', args: [this.$currentValue, iteration, callback] });
2242
+ };
2243
+
2244
+ /**
2245
+ *
2246
+ * @param {Array} target
2247
+ * @returns {ObservableArray}
2248
+ */
2249
+ Observable.array = function(target) {
2250
+ return new ObservableArray(target);
2137
2251
  };
2138
2252
 
2139
2253
  /**
@@ -2197,6 +2311,7 @@ var NativeDocument = (function (exports) {
2197
2311
  /**
2198
2312
  *
2199
2313
  * @param {Object} initialValue
2314
+ * @param {{propagation: boolean, deep: boolean}} configs
2200
2315
  * @returns {Proxy}
2201
2316
  */
2202
2317
  Observable.init = function(initialValue, { propagation= false, deep = true } = {}) {
@@ -2205,7 +2320,7 @@ var NativeDocument = (function (exports) {
2205
2320
  const itemValue = initialValue[key];
2206
2321
  if(Array.isArray(itemValue)) {
2207
2322
  if(deep) {
2208
- data[key] = itemValue.map(item => {
2323
+ const mappedItemValue = itemValue.map(item => {
2209
2324
  if(Validator.isJson(item)) {
2210
2325
  return Observable.json(item, { propagation, deep });
2211
2326
  }
@@ -2214,6 +2329,7 @@ var NativeDocument = (function (exports) {
2214
2329
  }
2215
2330
  return Observable(item);
2216
2331
  });
2332
+ data[key] = Observable.array(mappedItemValue, { propagation });
2217
2333
  continue;
2218
2334
  }
2219
2335
  data[key] = Observable.array(itemValue, { propagation });
@@ -2253,12 +2369,15 @@ var NativeDocument = (function (exports) {
2253
2369
  if(property === '$observables') {
2254
2370
  return Object.values(target);
2255
2371
  }
2256
- if(property === '$updateWith' || property === '$set') {
2372
+ if(property === '$set' || property === '$updateWith') {
2257
2373
  return $updateWith;
2258
2374
  }
2259
2375
  if(property === '$get') {
2260
2376
  return $get;
2261
2377
  }
2378
+ if(property === '$val') {
2379
+ return $val;
2380
+ }
2262
2381
  if(target[property] !== undefined) {
2263
2382
  return target[property];
2264
2383
  }
@@ -2321,12 +2440,13 @@ var NativeDocument = (function (exports) {
2321
2440
 
2322
2441
  if(Validator.isObservable(targetItem)) {
2323
2442
  if(Validator.isArray(newValue)) {
2324
- if(Validator.isObservable(newValueOrigin[0]) || Validator.isProxy(newValueOrigin[0])) {
2443
+ const firstElementFromOriginalValue = newValueOrigin.at(0);
2444
+ if(Validator.isObservable(firstElementFromOriginalValue) || Validator.isProxy(firstElementFromOriginalValue)) {
2325
2445
  const newValues = newValue.map(item => {
2326
- if(Validator.isObservable(newValueOrigin[0])) {
2327
- return Observable(item);
2446
+ if(Validator.isProxy(firstElementFromOriginalValue)) {
2447
+ return Observable.init(item);
2328
2448
  }
2329
- return Observable.init(newValueOrigin[0]);
2449
+ return Observable(item);
2330
2450
  });
2331
2451
  targetItem.set(newValues);
2332
2452
  continue;
@@ -2518,7 +2638,7 @@ var NativeDocument = (function (exports) {
2518
2638
  }
2519
2639
  cache.set(keyId, { keyId, isNew: true, child: new WeakRef(child), indexObserver});
2520
2640
  } catch (e) {
2521
- DebugManager$1.error('ForEach', `Error creating element for key ${keyId}` , e);
2641
+ DebugManager.error('ForEach', `Error creating element for key ${keyId}` , e);
2522
2642
  throw e;
2523
2643
  }
2524
2644
  return keyId;
@@ -2888,9 +3008,9 @@ var NativeDocument = (function (exports) {
2888
3008
  * @param {{comment?: string|null, shouldKeepInCache?: Boolean}} configs
2889
3009
  * @returns {DocumentFragment}
2890
3010
  */
2891
- const ShowIf = function(condition, child, { comment = null, shouldKeepInCache = true} = {}) {
2892
- if(!(Validator.isObservable(condition))) {
2893
- return DebugManager$1.warn('ShowIf', "ShowIf : condition must be an Observable / "+comment, condition);
3011
+ const ShowIf$1 = function(condition, child, { comment = null, shouldKeepInCache = true} = {}) {
3012
+ if(!(Validator.isObservable(condition)) && !Validator.isObservableWhenResult(condition)) {
3013
+ return DebugManager.warn('ShowIf', "ShowIf : condition must be an Observable / "+comment, condition);
2894
3014
  }
2895
3015
  const element = new Anchor('Show if : '+(comment || ''));
2896
3016
 
@@ -2933,7 +3053,7 @@ var NativeDocument = (function (exports) {
2933
3053
  const hideCondition = Observable(!condition.val());
2934
3054
  condition.subscribe(value => hideCondition.set(!value));
2935
3055
 
2936
- return ShowIf(hideCondition, child, configs);
3056
+ return ShowIf$1(hideCondition, child, configs);
2937
3057
  };
2938
3058
 
2939
3059
  /**
@@ -2945,7 +3065,35 @@ var NativeDocument = (function (exports) {
2945
3065
  * @returns {DocumentFragment}
2946
3066
  */
2947
3067
  const HideIfNot = function(condition, child, configs) {
2948
- return ShowIf(condition, child, configs);
3068
+ return ShowIf$1(condition, child, configs);
3069
+ };
3070
+
3071
+ const ShowWhen = function() {
3072
+ if(arguments.length === 2) {
3073
+ const [observer, target] = arguments;
3074
+ if(!Validator.isObservableWhenResult(observer)) {
3075
+ throw new NativeDocumentError('showWhen observer must be an ObservableWhenResult', {
3076
+ data: observer,
3077
+ 'help': 'Use observer.when(target) to create an ObservableWhenResult'
3078
+ });
3079
+ }
3080
+ return ShowIf$1(observer, target);
3081
+ }
3082
+ if(arguments.length === 3) {
3083
+ const [observer, target, view] = arguments;
3084
+ if(!Validator.isObservable(observer)) {
3085
+ throw new NativeDocumentError('showWhen observer must be an Observable', {
3086
+ data: observer,
3087
+ });
3088
+ }
3089
+ return ShowIf$1(observer.when(target), view);
3090
+ }
3091
+ throw new NativeDocumentError('showWhen must have 2 or 3 arguments', {
3092
+ data: [
3093
+ 'showWhen(observer, target, view)',
3094
+ 'showWhen(observerWhenResult, view)',
3095
+ ]
3096
+ });
2949
3097
  };
2950
3098
 
2951
3099
  /**
@@ -3330,7 +3478,8 @@ var NativeDocument = (function (exports) {
3330
3478
  SearchInput: SearchInput,
3331
3479
  Section: Section,
3332
3480
  Select: Select,
3333
- ShowIf: ShowIf,
3481
+ ShowIf: ShowIf$1,
3482
+ ShowWhen: ShowWhen,
3334
3483
  SimpleButton: SimpleButton,
3335
3484
  Small: Small,
3336
3485
  Source: Source,
@@ -3637,7 +3786,7 @@ var NativeDocument = (function (exports) {
3637
3786
  window.history.pushState({ name: route.name(), params, path}, route.name() || path , path);
3638
3787
  this.handleRouteChange(route, params, query, path);
3639
3788
  } catch (e) {
3640
- DebugManager$1.error('HistoryRouter', 'Error in pushState', e);
3789
+ DebugManager.error('HistoryRouter', 'Error in pushState', e);
3641
3790
  }
3642
3791
  };
3643
3792
  /**
@@ -3650,7 +3799,7 @@ var NativeDocument = (function (exports) {
3650
3799
  window.history.replaceState({ name: route.name(), params, path}, route.name() || path , path);
3651
3800
  this.handleRouteChange(route, params, {}, path);
3652
3801
  } catch(e) {
3653
- DebugManager$1.error('HistoryRouter', 'Error in replaceState', e);
3802
+ DebugManager.error('HistoryRouter', 'Error in replaceState', e);
3654
3803
  }
3655
3804
  };
3656
3805
  this.forward = function() {
@@ -3677,7 +3826,7 @@ var NativeDocument = (function (exports) {
3677
3826
  }
3678
3827
  this.handleRouteChange(route, params, query, path);
3679
3828
  } catch(e) {
3680
- DebugManager$1.error('HistoryRouter', 'Error in popstate event', e);
3829
+ DebugManager.error('HistoryRouter', 'Error in popstate event', e);
3681
3830
  }
3682
3831
  });
3683
3832
  const { route, params, query, path } = this.resolve(defaultPath || (window.location.pathname+window.location.search));
@@ -3831,7 +3980,7 @@ var NativeDocument = (function (exports) {
3831
3980
  listener(request);
3832
3981
  next && next(request);
3833
3982
  } catch (e) {
3834
- DebugManager$1.warn('Route Listener', 'Error in listener:', e);
3983
+ DebugManager.warn('Route Listener', 'Error in listener:', e);
3835
3984
  }
3836
3985
  }
3837
3986
  };
@@ -3990,7 +4139,7 @@ var NativeDocument = (function (exports) {
3990
4139
  */
3991
4140
  Router.create = function(options, callback) {
3992
4141
  if(!Validator.isFunction(callback)) {
3993
- DebugManager$1.error('Router', 'Callback must be a function', e);
4142
+ DebugManager.error('Router', 'Callback must be a function', e);
3994
4143
  throw new RouterError('Callback must be a function');
3995
4144
  }
3996
4145
  const router = new Router(options);
@@ -4075,15 +4224,20 @@ var NativeDocument = (function (exports) {
4075
4224
  exports.NDElement = NDElement;
4076
4225
  exports.Observable = Observable;
4077
4226
  exports.PluginsManager = PluginsManager;
4227
+ exports.Service = Service;
4078
4228
  exports.SingletonView = SingletonView;
4079
4229
  exports.Store = Store;
4080
4230
  exports.TemplateCloner = TemplateCloner;
4081
4231
  exports.Validator = Validator;
4232
+ exports.autoMemoize = autoMemoize;
4233
+ exports.autoOnce = autoOnce;
4082
4234
  exports.classPropertyAccumulator = classPropertyAccumulator;
4083
4235
  exports.createTextNode = createTextNode;
4084
4236
  exports.cssPropertyAccumulator = cssPropertyAccumulator;
4085
4237
  exports.elements = elements;
4238
+ exports.memoize = memoize;
4086
4239
  exports.normalizeComponentArgs = normalizeComponentArgs;
4240
+ exports.once = once;
4087
4241
  exports.router = router;
4088
4242
  exports.useCache = useCache;
4089
4243
  exports.useSingleton = useSingleton;