native-document 1.0.47 → 1.0.49
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.
- package/dist/native-document.dev.js +256 -101
- package/dist/native-document.dev.js.map +1 -1
- package/dist/native-document.devtools.min.js +1 -1
- package/dist/native-document.min.js +1 -1
- package/docs/anchor.md +0 -0
- package/docs/conditional-rendering.md +0 -0
- package/docs/contributing.md +0 -0
- package/docs/core-concepts.md +0 -0
- package/docs/elements.md +0 -0
- package/docs/extending-native-document-element.md +0 -0
- package/docs/getting-started.md +0 -0
- package/docs/lifecycle-events.md +0 -0
- package/docs/list-rendering.md +0 -0
- package/docs/memory-management.md +0 -0
- package/docs/native-document-element.md +0 -0
- package/docs/observables.md +0 -0
- package/docs/routing.md +0 -0
- package/docs/state-management.md +0 -0
- package/docs/validation.md +0 -0
- package/elements.d.ts +0 -0
- package/elements.js +0 -0
- package/eslint.config.js +0 -0
- package/index.d.ts +1 -0
- package/index.js +2 -0
- package/package.json +3 -2
- package/readme.md +0 -0
- package/rollup.config.js +0 -0
- package/router.js +0 -0
- package/src/data/MemoryManager.js +0 -0
- package/src/data/Observable.js +17 -0
- package/src/data/ObservableArray.js +114 -0
- package/src/data/ObservableChecker.js +0 -0
- package/src/data/ObservableItem.js +3 -1
- package/src/data/ObservableWhen.js +23 -0
- package/src/data/Store.js +0 -0
- package/src/data/observable-helpers/array.js +4 -100
- package/src/data/observable-helpers/batch.js +0 -0
- package/src/data/observable-helpers/computed.js +0 -0
- package/src/data/observable-helpers/object.js +5 -4
- package/src/devtools/app/App.js +0 -0
- package/src/devtools/app/app.css +0 -0
- package/src/devtools/index.js +0 -0
- package/src/devtools/plugin.js +0 -0
- package/src/devtools/widget/DevToolsWidget.js +0 -0
- package/src/elements/anchor.js +0 -0
- package/src/elements/content-formatter.js +0 -0
- package/src/elements/control/for-each-array.js +0 -0
- package/src/elements/control/for-each.js +0 -0
- package/src/elements/control/show-if.js +1 -1
- package/src/elements/control/show-when.js +31 -0
- package/src/elements/control/switch.js +0 -0
- package/src/elements/description-list.js +0 -0
- package/src/elements/form.js +0 -0
- package/src/elements/html5-semantics.js +0 -0
- package/src/elements/img.js +0 -0
- package/src/elements/index.js +1 -0
- package/src/elements/interactive.js +0 -0
- package/src/elements/list.js +0 -0
- package/src/elements/medias.js +0 -0
- package/src/elements/meta-data.js +0 -0
- package/src/elements/table.js +0 -0
- package/src/errors/ArgTypesError.js +0 -0
- package/src/errors/NativeDocumentError.js +0 -0
- package/src/errors/RouterError.js +0 -0
- package/src/router/Route.js +0 -0
- package/src/router/RouteGroupHelper.js +0 -0
- package/src/router/Router.js +0 -0
- package/src/router/RouterComponent.js +0 -0
- package/src/router/link.js +0 -0
- package/src/router/modes/HashRouter.js +0 -0
- package/src/router/modes/HistoryRouter.js +0 -0
- package/src/router/modes/MemoryRouter.js +0 -0
- package/src/utils/args-types.js +0 -0
- package/src/utils/debug-manager.js +0 -0
- package/src/utils/events.js +0 -0
- package/src/utils/fetch/NativeFetch.js +0 -0
- package/src/utils/helpers.js +0 -0
- package/src/utils/memoize.js +53 -0
- package/src/utils/plugins-manager.js +0 -0
- package/src/utils/property-accumulator.js +0 -0
- package/src/utils/prototypes.js +4 -4
- package/src/utils/service.js +6 -0
- package/src/utils/validator.js +6 -0
- package/src/wrappers/AttributesWrapper.js +3 -3
- package/src/wrappers/DocumentObserver.js +0 -0
- package/src/wrappers/ElementCreator.js +0 -0
- package/src/wrappers/HtmlElementWrapper.js +0 -0
- package/src/wrappers/NDElement.js +0 -0
- package/src/wrappers/NdPrototype.js +0 -0
- package/src/wrappers/SingletonView.js +0 -0
- package/src/wrappers/TemplateCloner.js +0 -0
- package/src/wrappers/constants.js +0 -0
- package/types/args-types.d.ts +0 -0
- package/types/control-flow.d.ts +7 -3
- package/types/elements.d.ts +0 -0
- package/types/forms.d.ts +0 -0
- package/types/images.d.ts +0 -0
- package/types/memoize.d.ts +16 -0
- package/types/nd-element.d.ts +0 -0
- package/types/observable.d.ts +19 -3
- package/types/plugins-manager.d.ts +0 -0
- package/types/polyfill.d.ts +0 -0
- package/types/property-accumulator.d.ts +0 -0
- package/types/router.d.ts +0 -0
- package/types/singleton.d.ts +0 -0
- package/types/store.d.ts +0 -0
- package/types/template-cloner.ts +0 -0
- package/types/validator.ts +0 -0
- package/utils.d.ts +0 -0
- package/utils.js +0 -0
|
@@ -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
|
};
|
|
@@ -445,7 +469,7 @@ var NativeDocument = (function (exports) {
|
|
|
445
469
|
};
|
|
446
470
|
|
|
447
471
|
ObservableItem.prototype.when = function(value) {
|
|
448
|
-
return
|
|
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
|
},
|
|
@@ -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
|
|
1229
|
-
element.classes.toggle(className, value
|
|
1230
|
-
value
|
|
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
|
|
1942
|
-
let getCache =
|
|
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 =
|
|
1994
|
+
getCache = () => $cache.cloneNode(true);
|
|
1948
1995
|
} else if($cache.$element) {
|
|
1949
|
-
getCache =
|
|
1996
|
+
getCache = () => new NDElement($cache.$element.cloneNode(true));
|
|
1950
1997
|
}
|
|
1951
1998
|
}
|
|
1952
1999
|
return getCache();
|
|
@@ -2032,108 +2079,176 @@ var NativeDocument = (function (exports) {
|
|
|
2032
2079
|
};
|
|
2033
2080
|
};
|
|
2034
2081
|
|
|
2035
|
-
const
|
|
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
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
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
|
-
|
|
2148
|
+
ObservableItem.call(this, target);
|
|
2149
|
+
PluginsManager.emit('CreateObservableArray', this);
|
|
2150
|
+
};
|
|
2049
2151
|
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
const result = observer.val()[method](...values);
|
|
2053
|
-
observer.trigger({ action: method, args: values, result });
|
|
2054
|
-
return result;
|
|
2055
|
-
};
|
|
2056
|
-
});
|
|
2152
|
+
ObservableArray.prototype = Object.create(ObservableItem.prototype);
|
|
2153
|
+
ObservableArray.prototype.__$isObservableArray = true;
|
|
2057
2154
|
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2155
|
+
mutationMethods.forEach((method) => {
|
|
2156
|
+
ObservableArray.prototype[method] = function(...values) {
|
|
2157
|
+
const result = this.$currentValue[method](...values);
|
|
2158
|
+
this.trigger({ action: method, args: values, result });
|
|
2159
|
+
return result;
|
|
2062
2160
|
};
|
|
2161
|
+
});
|
|
2063
2162
|
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2163
|
+
noMutationMethods.forEach((method) => {
|
|
2164
|
+
ObservableArray.prototype[method] = function(...values) {
|
|
2165
|
+
return this.$currentValue[method](...values);
|
|
2067
2166
|
};
|
|
2167
|
+
});
|
|
2068
2168
|
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
};
|
|
2169
|
+
ObservableArray.prototype.clear = function() {
|
|
2170
|
+
this.$currentValue.length = 0;
|
|
2171
|
+
this.trigger({ action: 'clear' });
|
|
2172
|
+
return true;
|
|
2173
|
+
};
|
|
2072
2174
|
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
};
|
|
2175
|
+
ObservableArray.prototype.at = function(index) {
|
|
2176
|
+
return this.$currentValue[index];
|
|
2177
|
+
};
|
|
2077
2178
|
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
}
|
|
2083
|
-
observer.trigger({ action: 'remove', args: [index], result: deleted[0] });
|
|
2084
|
-
return deleted;
|
|
2085
|
-
};
|
|
2179
|
+
ObservableArray.prototype.merge = function(values) {
|
|
2180
|
+
this.$currentValue.push(...values);
|
|
2181
|
+
this.trigger({ action: 'merge', args: values });
|
|
2182
|
+
};
|
|
2086
2183
|
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2184
|
+
/**
|
|
2185
|
+
*
|
|
2186
|
+
* @param {Function} condition
|
|
2187
|
+
* @returns {number}
|
|
2188
|
+
*/
|
|
2189
|
+
ObservableArray.prototype.count = function(condition) {
|
|
2190
|
+
let count = 0;
|
|
2191
|
+
this.$currentValue.forEach((item, index) => {
|
|
2192
|
+
if(condition(item, index)) {
|
|
2193
|
+
count++;
|
|
2097
2194
|
}
|
|
2098
|
-
|
|
2099
|
-
|
|
2195
|
+
});
|
|
2196
|
+
return count;
|
|
2197
|
+
};
|
|
2100
2198
|
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
return true;
|
|
2105
|
-
};
|
|
2199
|
+
ObservableArray.prototype.length = function() {
|
|
2200
|
+
return this.$currentValue.length;
|
|
2201
|
+
};
|
|
2106
2202
|
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2203
|
+
ObservableArray.prototype.swap = function(indexA, indexB) {
|
|
2204
|
+
const value = this.$currentValue;
|
|
2205
|
+
const length = value.length;
|
|
2206
|
+
if(length < indexA || length < indexB) {
|
|
2207
|
+
return false;
|
|
2208
|
+
}
|
|
2209
|
+
if(indexB < indexA) {
|
|
2210
|
+
const temp = indexA;
|
|
2211
|
+
indexA = indexB;
|
|
2212
|
+
indexB = temp;
|
|
2213
|
+
}
|
|
2214
|
+
const elementA = value[indexA];
|
|
2215
|
+
const elementB = value[indexB];
|
|
2110
2216
|
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
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
|
-
};
|
|
2217
|
+
value[indexA] = elementB;
|
|
2218
|
+
value[indexB] = elementA;
|
|
2219
|
+
this.trigger({ action: 'swap', args: [indexA, indexB], result: [elementA, elementB] });
|
|
2220
|
+
return true;
|
|
2221
|
+
};
|
|
2128
2222
|
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
});
|
|
2223
|
+
ObservableArray.prototype.remove = function(index) {
|
|
2224
|
+
const deleted = this.$currentValue.splice(index, 1);
|
|
2225
|
+
if(deleted.length === 0) {
|
|
2226
|
+
return [];
|
|
2227
|
+
}
|
|
2228
|
+
this.trigger({ action: 'remove', args: [index], result: deleted[0] });
|
|
2229
|
+
return deleted;
|
|
2230
|
+
};
|
|
2231
|
+
|
|
2232
|
+
ObservableArray.prototype.removeItem = function(item) {
|
|
2233
|
+
const indexOfItem = this.$currentValue.indexOf(item);
|
|
2234
|
+
return this.remove(indexOfItem);
|
|
2235
|
+
};
|
|
2135
2236
|
|
|
2136
|
-
|
|
2237
|
+
ObservableArray.prototype.isEmpty = function() {
|
|
2238
|
+
return this.$currentValue.length === 0;
|
|
2239
|
+
};
|
|
2240
|
+
|
|
2241
|
+
ObservableArray.prototype.populateAndRender = function(iteration, callback) {
|
|
2242
|
+
this.trigger({ action: 'populate', args: [this.$currentValue, iteration, callback] });
|
|
2243
|
+
};
|
|
2244
|
+
|
|
2245
|
+
/**
|
|
2246
|
+
*
|
|
2247
|
+
* @param {Array} target
|
|
2248
|
+
* @returns {ObservableArray}
|
|
2249
|
+
*/
|
|
2250
|
+
Observable.array = function(target) {
|
|
2251
|
+
return new ObservableArray(target);
|
|
2137
2252
|
};
|
|
2138
2253
|
|
|
2139
2254
|
/**
|
|
@@ -2197,6 +2312,7 @@ var NativeDocument = (function (exports) {
|
|
|
2197
2312
|
/**
|
|
2198
2313
|
*
|
|
2199
2314
|
* @param {Object} initialValue
|
|
2315
|
+
* @param {{propagation: boolean, deep: boolean}} configs
|
|
2200
2316
|
* @returns {Proxy}
|
|
2201
2317
|
*/
|
|
2202
2318
|
Observable.init = function(initialValue, { propagation= false, deep = true } = {}) {
|
|
@@ -2205,7 +2321,7 @@ var NativeDocument = (function (exports) {
|
|
|
2205
2321
|
const itemValue = initialValue[key];
|
|
2206
2322
|
if(Array.isArray(itemValue)) {
|
|
2207
2323
|
if(deep) {
|
|
2208
|
-
|
|
2324
|
+
const mappedItemValue = itemValue.map(item => {
|
|
2209
2325
|
if(Validator.isJson(item)) {
|
|
2210
2326
|
return Observable.json(item, { propagation, deep });
|
|
2211
2327
|
}
|
|
@@ -2214,6 +2330,7 @@ var NativeDocument = (function (exports) {
|
|
|
2214
2330
|
}
|
|
2215
2331
|
return Observable(item);
|
|
2216
2332
|
});
|
|
2333
|
+
data[key] = Observable.array(mappedItemValue, { propagation });
|
|
2217
2334
|
continue;
|
|
2218
2335
|
}
|
|
2219
2336
|
data[key] = Observable.array(itemValue, { propagation });
|
|
@@ -2253,12 +2370,15 @@ var NativeDocument = (function (exports) {
|
|
|
2253
2370
|
if(property === '$observables') {
|
|
2254
2371
|
return Object.values(target);
|
|
2255
2372
|
}
|
|
2256
|
-
if(property === '$
|
|
2373
|
+
if(property === '$set' || property === '$updateWith') {
|
|
2257
2374
|
return $updateWith;
|
|
2258
2375
|
}
|
|
2259
2376
|
if(property === '$get') {
|
|
2260
2377
|
return $get;
|
|
2261
2378
|
}
|
|
2379
|
+
if(property === '$val') {
|
|
2380
|
+
return $val;
|
|
2381
|
+
}
|
|
2262
2382
|
if(target[property] !== undefined) {
|
|
2263
2383
|
return target[property];
|
|
2264
2384
|
}
|
|
@@ -2321,12 +2441,13 @@ var NativeDocument = (function (exports) {
|
|
|
2321
2441
|
|
|
2322
2442
|
if(Validator.isObservable(targetItem)) {
|
|
2323
2443
|
if(Validator.isArray(newValue)) {
|
|
2324
|
-
|
|
2444
|
+
const firstElementFromOriginalValue = newValueOrigin.at(0);
|
|
2445
|
+
if(Validator.isObservable(firstElementFromOriginalValue) || Validator.isProxy(firstElementFromOriginalValue)) {
|
|
2325
2446
|
const newValues = newValue.map(item => {
|
|
2326
|
-
if(Validator.
|
|
2327
|
-
return Observable(item);
|
|
2447
|
+
if(Validator.isProxy(firstElementFromOriginalValue)) {
|
|
2448
|
+
return Observable.init(item);
|
|
2328
2449
|
}
|
|
2329
|
-
return Observable
|
|
2450
|
+
return Observable(item);
|
|
2330
2451
|
});
|
|
2331
2452
|
targetItem.set(newValues);
|
|
2332
2453
|
continue;
|
|
@@ -2888,8 +3009,8 @@ var NativeDocument = (function (exports) {
|
|
|
2888
3009
|
* @param {{comment?: string|null, shouldKeepInCache?: Boolean}} configs
|
|
2889
3010
|
* @returns {DocumentFragment}
|
|
2890
3011
|
*/
|
|
2891
|
-
const ShowIf = function(condition, child, { comment = null, shouldKeepInCache = true} = {}) {
|
|
2892
|
-
if(!(Validator.isObservable(condition))) {
|
|
3012
|
+
const ShowIf$1 = function(condition, child, { comment = null, shouldKeepInCache = true} = {}) {
|
|
3013
|
+
if(!(Validator.isObservable(condition)) && !Validator.isObservableWhenResult(condition)) {
|
|
2893
3014
|
return DebugManager$1.warn('ShowIf', "ShowIf : condition must be an Observable / "+comment, condition);
|
|
2894
3015
|
}
|
|
2895
3016
|
const element = new Anchor('Show if : '+(comment || ''));
|
|
@@ -2933,7 +3054,7 @@ var NativeDocument = (function (exports) {
|
|
|
2933
3054
|
const hideCondition = Observable(!condition.val());
|
|
2934
3055
|
condition.subscribe(value => hideCondition.set(!value));
|
|
2935
3056
|
|
|
2936
|
-
return ShowIf(hideCondition, child, configs);
|
|
3057
|
+
return ShowIf$1(hideCondition, child, configs);
|
|
2937
3058
|
};
|
|
2938
3059
|
|
|
2939
3060
|
/**
|
|
@@ -2945,7 +3066,35 @@ var NativeDocument = (function (exports) {
|
|
|
2945
3066
|
* @returns {DocumentFragment}
|
|
2946
3067
|
*/
|
|
2947
3068
|
const HideIfNot = function(condition, child, configs) {
|
|
2948
|
-
return ShowIf(condition, child, configs);
|
|
3069
|
+
return ShowIf$1(condition, child, configs);
|
|
3070
|
+
};
|
|
3071
|
+
|
|
3072
|
+
const ShowWhen = function() {
|
|
3073
|
+
if(arguments.length === 2) {
|
|
3074
|
+
const [observer, target] = arguments;
|
|
3075
|
+
if(!Validator.isObservableWhenResult(observer)) {
|
|
3076
|
+
throw new NativeDocumentError('showWhen observer must be an ObservableWhenResult', {
|
|
3077
|
+
data: observer,
|
|
3078
|
+
'help': 'Use observer.when(target) to create an ObservableWhenResult'
|
|
3079
|
+
});
|
|
3080
|
+
}
|
|
3081
|
+
return ShowIf$1(observer, target);
|
|
3082
|
+
}
|
|
3083
|
+
if(arguments.length === 3) {
|
|
3084
|
+
const [observer, target, view] = arguments;
|
|
3085
|
+
if(!Validator.isObservable(observer)) {
|
|
3086
|
+
throw new NativeDocumentError('showWhen observer must be an Observable', {
|
|
3087
|
+
data: observer,
|
|
3088
|
+
});
|
|
3089
|
+
}
|
|
3090
|
+
return ShowIf$1(observer.when(target), view);
|
|
3091
|
+
}
|
|
3092
|
+
throw new NativeDocumentError('showWhen must have 2 or 3 arguments', {
|
|
3093
|
+
data: [
|
|
3094
|
+
'showWhen(observer, target, view)',
|
|
3095
|
+
'showWhen(observerWhenResult, view)',
|
|
3096
|
+
]
|
|
3097
|
+
});
|
|
2949
3098
|
};
|
|
2950
3099
|
|
|
2951
3100
|
/**
|
|
@@ -3330,7 +3479,8 @@ var NativeDocument = (function (exports) {
|
|
|
3330
3479
|
SearchInput: SearchInput,
|
|
3331
3480
|
Section: Section,
|
|
3332
3481
|
Select: Select,
|
|
3333
|
-
ShowIf: ShowIf,
|
|
3482
|
+
ShowIf: ShowIf$1,
|
|
3483
|
+
ShowWhen: ShowWhen,
|
|
3334
3484
|
SimpleButton: SimpleButton,
|
|
3335
3485
|
Small: Small,
|
|
3336
3486
|
Source: Source,
|
|
@@ -4075,15 +4225,20 @@ var NativeDocument = (function (exports) {
|
|
|
4075
4225
|
exports.NDElement = NDElement;
|
|
4076
4226
|
exports.Observable = Observable;
|
|
4077
4227
|
exports.PluginsManager = PluginsManager;
|
|
4228
|
+
exports.Service = Service;
|
|
4078
4229
|
exports.SingletonView = SingletonView;
|
|
4079
4230
|
exports.Store = Store;
|
|
4080
4231
|
exports.TemplateCloner = TemplateCloner;
|
|
4081
4232
|
exports.Validator = Validator;
|
|
4233
|
+
exports.autoMemoize = autoMemoize;
|
|
4234
|
+
exports.autoOnce = autoOnce;
|
|
4082
4235
|
exports.classPropertyAccumulator = classPropertyAccumulator;
|
|
4083
4236
|
exports.createTextNode = createTextNode;
|
|
4084
4237
|
exports.cssPropertyAccumulator = cssPropertyAccumulator;
|
|
4085
4238
|
exports.elements = elements;
|
|
4239
|
+
exports.memoize = memoize;
|
|
4086
4240
|
exports.normalizeComponentArgs = normalizeComponentArgs;
|
|
4241
|
+
exports.once = once;
|
|
4087
4242
|
exports.router = router;
|
|
4088
4243
|
exports.useCache = useCache;
|
|
4089
4244
|
exports.useSingleton = useSingleton;
|