native-document 1.0.86 → 1.0.87
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.
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
var NativeDocument = (function (exports) {
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
|
-
let DebugManager
|
|
4
|
+
let DebugManager = {};
|
|
5
5
|
|
|
6
6
|
{
|
|
7
|
-
DebugManager
|
|
7
|
+
DebugManager = {
|
|
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 = DebugManager
|
|
38
|
+
var DebugManager$1 = DebugManager;
|
|
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.log('Memory Auto Clean', `🧹 Cleaned ${cleanedCount} orphaned observables`);
|
|
87
|
+
DebugManager$1.log('Memory Auto Clean', `🧹 Cleaned ${cleanedCount} orphaned observables`);
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
90
|
};
|
|
@@ -141,10 +141,10 @@ var NativeDocument = (function (exports) {
|
|
|
141
141
|
return this.observable.cleanup();
|
|
142
142
|
};
|
|
143
143
|
|
|
144
|
-
let PluginsManager = null;
|
|
144
|
+
let PluginsManager$1 = null;
|
|
145
145
|
|
|
146
146
|
{
|
|
147
|
-
PluginsManager = (function() {
|
|
147
|
+
PluginsManager$1 = (function() {
|
|
148
148
|
|
|
149
149
|
const $plugins = new Map();
|
|
150
150
|
const $pluginByEvents = new Map();
|
|
@@ -210,7 +210,7 @@ var NativeDocument = (function (exports) {
|
|
|
210
210
|
try{
|
|
211
211
|
callback.call(plugin, ...data);
|
|
212
212
|
} catch (error) {
|
|
213
|
-
DebugManager.error('Plugin Manager', `Error in plugin ${plugin.$name} for event ${eventName}`, error);
|
|
213
|
+
DebugManager$1.error('Plugin Manager', `Error in plugin ${plugin.$name} for event ${eventName}`, error);
|
|
214
214
|
}
|
|
215
215
|
}
|
|
216
216
|
}
|
|
@@ -219,7 +219,7 @@ var NativeDocument = (function (exports) {
|
|
|
219
219
|
}());
|
|
220
220
|
}
|
|
221
221
|
|
|
222
|
-
var PluginsManager
|
|
222
|
+
var PluginsManager = PluginsManager$1;
|
|
223
223
|
|
|
224
224
|
const ObservableWhen = function(observer, value) {
|
|
225
225
|
this.$target = value;
|
|
@@ -341,7 +341,7 @@ var NativeDocument = (function (exports) {
|
|
|
341
341
|
}
|
|
342
342
|
}
|
|
343
343
|
{
|
|
344
|
-
PluginsManager
|
|
344
|
+
PluginsManager.emit('CreateObservable', this);
|
|
345
345
|
}
|
|
346
346
|
}
|
|
347
347
|
|
|
@@ -468,12 +468,12 @@ var NativeDocument = (function (exports) {
|
|
|
468
468
|
this.$previousValue = this.$currentValue;
|
|
469
469
|
this.$currentValue = newValue;
|
|
470
470
|
{
|
|
471
|
-
PluginsManager
|
|
471
|
+
PluginsManager.emit('ObservableBeforeChange', this);
|
|
472
472
|
}
|
|
473
473
|
this.trigger();
|
|
474
474
|
this.$previousValue = null;
|
|
475
475
|
{
|
|
476
|
-
PluginsManager
|
|
476
|
+
PluginsManager.emit('ObservableAfterChange', this);
|
|
477
477
|
}
|
|
478
478
|
};
|
|
479
479
|
|
|
@@ -525,7 +525,7 @@ var NativeDocument = (function (exports) {
|
|
|
525
525
|
ObservableItem.prototype.subscribe = function(callback, target = null) {
|
|
526
526
|
this.$listeners = this.$listeners ?? [];
|
|
527
527
|
if (this.$isCleanedUp) {
|
|
528
|
-
DebugManager.warn('Observable subscription', '⚠️ Attempted to subscribe to a cleaned up observable.');
|
|
528
|
+
DebugManager$1.warn('Observable subscription', '⚠️ Attempted to subscribe to a cleaned up observable.');
|
|
529
529
|
return () => {};
|
|
530
530
|
}
|
|
531
531
|
if (typeof callback !== 'function') {
|
|
@@ -535,13 +535,13 @@ var NativeDocument = (function (exports) {
|
|
|
535
535
|
this.$listeners.push(callback);
|
|
536
536
|
this.assocTrigger();
|
|
537
537
|
{
|
|
538
|
-
PluginsManager
|
|
538
|
+
PluginsManager.emit('ObservableSubscribe', this, target);
|
|
539
539
|
}
|
|
540
540
|
return () => {
|
|
541
541
|
this.unsubscribe(callback);
|
|
542
542
|
this.assocTrigger();
|
|
543
543
|
{
|
|
544
|
-
PluginsManager
|
|
544
|
+
PluginsManager.emit('ObservableUnsubscribe', this);
|
|
545
545
|
}
|
|
546
546
|
};
|
|
547
547
|
};
|
|
@@ -763,7 +763,7 @@ var NativeDocument = (function (exports) {
|
|
|
763
763
|
this.$element = element;
|
|
764
764
|
this.$observer = null;
|
|
765
765
|
{
|
|
766
|
-
PluginsManager
|
|
766
|
+
PluginsManager.emit('NDElementCreated', element, this);
|
|
767
767
|
}
|
|
768
768
|
}
|
|
769
769
|
|
|
@@ -884,7 +884,7 @@ var NativeDocument = (function (exports) {
|
|
|
884
884
|
}
|
|
885
885
|
{
|
|
886
886
|
if (this[name] && !this.$localExtensions.has(name)) {
|
|
887
|
-
DebugManager.warn('NDElement.extend', `Method "${name}" already exists and will be overwritten`);
|
|
887
|
+
DebugManager$1.warn('NDElement.extend', `Method "${name}" already exists and will be overwritten`);
|
|
888
888
|
}
|
|
889
889
|
this.$localExtensions.set(name, method);
|
|
890
890
|
}
|
|
@@ -918,23 +918,23 @@ var NativeDocument = (function (exports) {
|
|
|
918
918
|
const method = methods[name];
|
|
919
919
|
|
|
920
920
|
if (typeof method !== 'function') {
|
|
921
|
-
DebugManager.warn('NDElement.extend', `"${name}" is not a function, skipping`);
|
|
921
|
+
DebugManager$1.warn('NDElement.extend', `"${name}" is not a function, skipping`);
|
|
922
922
|
continue;
|
|
923
923
|
}
|
|
924
924
|
|
|
925
925
|
if (protectedMethods.has(name)) {
|
|
926
|
-
DebugManager.error('NDElement.extend', `Cannot override protected method "${name}"`);
|
|
926
|
+
DebugManager$1.error('NDElement.extend', `Cannot override protected method "${name}"`);
|
|
927
927
|
throw new NativeDocumentError(`Cannot override protected method "${name}"`);
|
|
928
928
|
}
|
|
929
929
|
|
|
930
930
|
if (NDElement.prototype[name]) {
|
|
931
|
-
DebugManager.warn('NDElement.extend', `Overwriting existing prototype method "${name}"`);
|
|
931
|
+
DebugManager$1.warn('NDElement.extend', `Overwriting existing prototype method "${name}"`);
|
|
932
932
|
}
|
|
933
933
|
|
|
934
934
|
NDElement.prototype[name] = method;
|
|
935
935
|
}
|
|
936
936
|
{
|
|
937
|
-
PluginsManager
|
|
937
|
+
PluginsManager.emit('NDElementExtended', methods);
|
|
938
938
|
}
|
|
939
939
|
|
|
940
940
|
return NDElement;
|
|
@@ -1079,7 +1079,6 @@ var NativeDocument = (function (exports) {
|
|
|
1079
1079
|
};
|
|
1080
1080
|
{
|
|
1081
1081
|
Validator.validateAttributes = function(attributes) {
|
|
1082
|
-
console.log('AttributesWrapper', attributes);
|
|
1083
1082
|
if (!attributes || typeof attributes !== 'object') {
|
|
1084
1083
|
return attributes;
|
|
1085
1084
|
}
|
|
@@ -1088,7 +1087,7 @@ var NativeDocument = (function (exports) {
|
|
|
1088
1087
|
const foundReserved = Object.keys(attributes).filter(key => reserved.includes(key));
|
|
1089
1088
|
|
|
1090
1089
|
if (foundReserved.length > 0) {
|
|
1091
|
-
DebugManager.warn('Validator', `Reserved attributes found: ${foundReserved.join(', ')}`);
|
|
1090
|
+
DebugManager$1.warn('Validator', `Reserved attributes found: ${foundReserved.join(', ')}`);
|
|
1092
1091
|
}
|
|
1093
1092
|
|
|
1094
1093
|
return attributes;
|
|
@@ -1136,7 +1135,7 @@ var NativeDocument = (function (exports) {
|
|
|
1136
1135
|
anchorFragment.appendChild = function(child, before = null) {
|
|
1137
1136
|
const parent = anchorEnd.parentNode;
|
|
1138
1137
|
if(!parent) {
|
|
1139
|
-
DebugManager.error('Anchor', 'Anchor : parent not found', child);
|
|
1138
|
+
DebugManager$1.error('Anchor', 'Anchor : parent not found', child);
|
|
1140
1139
|
return;
|
|
1141
1140
|
}
|
|
1142
1141
|
before = before ?? anchorEnd;
|
|
@@ -1565,7 +1564,7 @@ var NativeDocument = (function (exports) {
|
|
|
1565
1564
|
Function.prototype.toNdElement = function () {
|
|
1566
1565
|
const child = this;
|
|
1567
1566
|
{
|
|
1568
|
-
PluginsManager
|
|
1567
|
+
PluginsManager.emit('BeforeProcessComponent', child);
|
|
1569
1568
|
}
|
|
1570
1569
|
return ElementCreator.getChild(child());
|
|
1571
1570
|
};
|
|
@@ -1663,14 +1662,14 @@ var NativeDocument = (function (exports) {
|
|
|
1663
1662
|
processChildren(children, parent) {
|
|
1664
1663
|
if(children === null) return;
|
|
1665
1664
|
{
|
|
1666
|
-
PluginsManager
|
|
1665
|
+
PluginsManager.emit('BeforeProcessChildren', parent);
|
|
1667
1666
|
}
|
|
1668
1667
|
let child = this.getChild(children);
|
|
1669
1668
|
if(child) {
|
|
1670
1669
|
parent.appendChild(child);
|
|
1671
1670
|
}
|
|
1672
1671
|
{
|
|
1673
|
-
PluginsManager
|
|
1672
|
+
PluginsManager.emit('AfterProcessChildren', parent);
|
|
1674
1673
|
}
|
|
1675
1674
|
},
|
|
1676
1675
|
getChild(child) {
|
|
@@ -2906,7 +2905,7 @@ var NativeDocument = (function (exports) {
|
|
|
2906
2905
|
|
|
2907
2906
|
ObservableItem.call(this, target, configs);
|
|
2908
2907
|
{
|
|
2909
|
-
PluginsManager
|
|
2908
|
+
PluginsManager.emit('CreateObservableArray', this);
|
|
2910
2909
|
}
|
|
2911
2910
|
};
|
|
2912
2911
|
|
|
@@ -3307,7 +3306,7 @@ var NativeDocument = (function (exports) {
|
|
|
3307
3306
|
const observable = new ObservableItem(initialValue);
|
|
3308
3307
|
const updatedValue = nextTick(() => observable.set(callback()));
|
|
3309
3308
|
{
|
|
3310
|
-
PluginsManager
|
|
3309
|
+
PluginsManager.emit('CreateObservableComputed', observable, dependencies);
|
|
3311
3310
|
}
|
|
3312
3311
|
|
|
3313
3312
|
if(Validator.isFunction(dependencies)) {
|
|
@@ -3467,7 +3466,7 @@ var NativeDocument = (function (exports) {
|
|
|
3467
3466
|
}
|
|
3468
3467
|
cache.set(keyId, { keyId, isNew: true, child: new WeakRef(child), indexObserver});
|
|
3469
3468
|
} catch (e) {
|
|
3470
|
-
DebugManager.error('ForEach', `Error creating element for key ${keyId}` , e);
|
|
3469
|
+
DebugManager$1.error('ForEach', `Error creating element for key ${keyId}` , e);
|
|
3471
3470
|
throw e;
|
|
3472
3471
|
}
|
|
3473
3472
|
return keyId;
|
|
@@ -3813,7 +3812,7 @@ var NativeDocument = (function (exports) {
|
|
|
3813
3812
|
*/
|
|
3814
3813
|
const ShowIf = function(condition, child, { comment = null, shouldKeepInCache = true} = {}) {
|
|
3815
3814
|
if(!(Validator.isObservable(condition)) && !Validator.isObservableWhenResult(condition)) {
|
|
3816
|
-
return DebugManager.warn('ShowIf', "ShowIf : condition must be an Observable / "+comment, condition);
|
|
3815
|
+
return DebugManager$1.warn('ShowIf', "ShowIf : condition must be an Observable / "+comment, condition);
|
|
3817
3816
|
}
|
|
3818
3817
|
const element = Anchor('Show if : '+(comment || ''));
|
|
3819
3818
|
|
|
@@ -4600,7 +4599,7 @@ var NativeDocument = (function (exports) {
|
|
|
4600
4599
|
window.history.pushState({ name: route.name(), params, path}, route.name() || path , path);
|
|
4601
4600
|
this.handleRouteChange(route, params, query, path);
|
|
4602
4601
|
} catch (e) {
|
|
4603
|
-
DebugManager.error('HistoryRouter', 'Error in pushState', e);
|
|
4602
|
+
DebugManager$1.error('HistoryRouter', 'Error in pushState', e);
|
|
4604
4603
|
}
|
|
4605
4604
|
};
|
|
4606
4605
|
/**
|
|
@@ -4613,7 +4612,7 @@ var NativeDocument = (function (exports) {
|
|
|
4613
4612
|
window.history.replaceState({ name: route.name(), params, path}, route.name() || path , path);
|
|
4614
4613
|
this.handleRouteChange(route, params, {}, path);
|
|
4615
4614
|
} catch(e) {
|
|
4616
|
-
DebugManager.error('HistoryRouter', 'Error in replaceState', e);
|
|
4615
|
+
DebugManager$1.error('HistoryRouter', 'Error in replaceState', e);
|
|
4617
4616
|
}
|
|
4618
4617
|
};
|
|
4619
4618
|
this.forward = function() {
|
|
@@ -4640,7 +4639,7 @@ var NativeDocument = (function (exports) {
|
|
|
4640
4639
|
}
|
|
4641
4640
|
this.handleRouteChange(route, params, query, path);
|
|
4642
4641
|
} catch(e) {
|
|
4643
|
-
DebugManager.error('HistoryRouter', 'Error in popstate event', e);
|
|
4642
|
+
DebugManager$1.error('HistoryRouter', 'Error in popstate event', e);
|
|
4644
4643
|
}
|
|
4645
4644
|
});
|
|
4646
4645
|
const { route, params, query, path } = this.resolve(defaultPath || (window.location.pathname+window.location.search));
|
|
@@ -4728,22 +4727,84 @@ var NativeDocument = (function (exports) {
|
|
|
4728
4727
|
function RouterComponent(router, container) {
|
|
4729
4728
|
|
|
4730
4729
|
const $cache = new Map();
|
|
4730
|
+
const $layoutCache = new WeakMap();
|
|
4731
|
+
const $routeInstanceAnchors = new WeakMap();
|
|
4732
|
+
let $currentLayout = null;
|
|
4733
|
+
|
|
4731
4734
|
let $lastNodeInserted = null;
|
|
4732
4735
|
|
|
4733
|
-
const
|
|
4734
|
-
|
|
4736
|
+
const getNodeAnchorForLayout = (node, path) => {
|
|
4737
|
+
const existingAnchor = $routeInstanceAnchors.get(node);
|
|
4738
|
+
if(existingAnchor) {
|
|
4739
|
+
return existingAnchor;
|
|
4740
|
+
}
|
|
4741
|
+
|
|
4742
|
+
let anchor = node;
|
|
4743
|
+
if(!Validator.isAnchor(node)) {
|
|
4744
|
+
anchor = Anchor(path);
|
|
4745
|
+
anchor.appendChild(node);
|
|
4746
|
+
}
|
|
4747
|
+
$routeInstanceAnchors.set(node, anchor);
|
|
4748
|
+
return anchor;
|
|
4749
|
+
};
|
|
4750
|
+
|
|
4751
|
+
const removeLastNodeInserted = () => {
|
|
4752
|
+
if(Validator.isAnchor($lastNodeInserted)) {
|
|
4753
|
+
$lastNodeInserted.remove();
|
|
4754
|
+
}
|
|
4755
|
+
};
|
|
4756
|
+
const cleanContainer = () => {
|
|
4757
|
+
container.nodeValue = '';
|
|
4758
|
+
removeLastNodeInserted();
|
|
4759
|
+
|
|
4760
|
+
if($currentLayout) {
|
|
4761
|
+
$currentLayout.remove();
|
|
4762
|
+
}
|
|
4763
|
+
};
|
|
4764
|
+
|
|
4765
|
+
const getNodeToInsert = (node) => {
|
|
4735
4766
|
let nodeToInsert = node;
|
|
4736
|
-
const layout = route.layout();
|
|
4737
4767
|
if(Validator.isNDElement(node)) {
|
|
4738
4768
|
nodeToInsert = node.node();
|
|
4739
4769
|
}
|
|
4740
|
-
|
|
4741
|
-
|
|
4770
|
+
return nodeToInsert;
|
|
4771
|
+
};
|
|
4772
|
+
|
|
4773
|
+
const updateContainerByLayout = (layout, node, route, path) => {
|
|
4774
|
+
let nodeToInsert = getNodeToInsert(node);
|
|
4775
|
+
|
|
4776
|
+
const cachedLayout = $layoutCache.get(nodeToInsert);
|
|
4777
|
+
if(cachedLayout) {
|
|
4778
|
+
if(cachedLayout === $currentLayout) {
|
|
4779
|
+
const layoutAnchor = getNodeAnchorForLayout(nodeToInsert, path);
|
|
4780
|
+
removeLastNodeInserted();
|
|
4781
|
+
layoutAnchor.replaceContent(nodeToInsert);
|
|
4782
|
+
return;
|
|
4783
|
+
}
|
|
4784
|
+
cleanContainer();
|
|
4785
|
+
$currentLayout = cachedLayout;
|
|
4786
|
+
const layoutAnchor = getNodeAnchorForLayout(nodeToInsert, path);
|
|
4787
|
+
layoutAnchor.replaceContent(nodeToInsert);
|
|
4788
|
+
container.appendChild($currentLayout);
|
|
4742
4789
|
return;
|
|
4743
4790
|
}
|
|
4744
|
-
|
|
4745
|
-
|
|
4791
|
+
cleanContainer();
|
|
4792
|
+
const anchor = getNodeAnchorForLayout(nodeToInsert, path);
|
|
4793
|
+
|
|
4794
|
+
$currentLayout = layout(anchor);
|
|
4795
|
+
$layoutCache.set(nodeToInsert, $currentLayout);
|
|
4796
|
+
container.appendChild($currentLayout);
|
|
4797
|
+
};
|
|
4798
|
+
|
|
4799
|
+
const updateContainer = function(node, route, path) {
|
|
4800
|
+
const layout = route.layout();
|
|
4801
|
+
if(layout) {
|
|
4802
|
+
updateContainerByLayout(layout, node, route, path);
|
|
4803
|
+
return;
|
|
4746
4804
|
}
|
|
4805
|
+
let nodeToInsert = getNodeToInsert(node);
|
|
4806
|
+
|
|
4807
|
+
cleanContainer();
|
|
4747
4808
|
container.appendChild(nodeToInsert);
|
|
4748
4809
|
$lastNodeInserted = node;
|
|
4749
4810
|
};
|
|
@@ -4761,7 +4822,7 @@ var NativeDocument = (function (exports) {
|
|
|
4761
4822
|
const Component = route.component();
|
|
4762
4823
|
const node = Component({ params, query });
|
|
4763
4824
|
$cache.set(path, node);
|
|
4764
|
-
updateContainer(node, route);
|
|
4825
|
+
updateContainer(node, route, path);
|
|
4765
4826
|
};
|
|
4766
4827
|
|
|
4767
4828
|
router.subscribe(handleCurrentRouterState);
|
|
@@ -4803,7 +4864,7 @@ var NativeDocument = (function (exports) {
|
|
|
4803
4864
|
listener(request);
|
|
4804
4865
|
next && next(request);
|
|
4805
4866
|
} catch (e) {
|
|
4806
|
-
DebugManager.warn('Route Listener', 'Error in listener:', e);
|
|
4867
|
+
DebugManager$1.warn('Route Listener', 'Error in listener:', e);
|
|
4807
4868
|
}
|
|
4808
4869
|
}
|
|
4809
4870
|
};
|
|
@@ -4962,7 +5023,7 @@ var NativeDocument = (function (exports) {
|
|
|
4962
5023
|
*/
|
|
4963
5024
|
Router.create = function(options, callback) {
|
|
4964
5025
|
if(!Validator.isFunction(callback)) {
|
|
4965
|
-
DebugManager.error('Router', 'Callback must be a function', e);
|
|
5026
|
+
DebugManager$1.error('Router', 'Callback must be a function', e);
|
|
4966
5027
|
throw new RouterError('Callback must be a function');
|
|
4967
5028
|
}
|
|
4968
5029
|
const router = new Router(options);
|
|
@@ -5146,7 +5207,7 @@ var NativeDocument = (function (exports) {
|
|
|
5146
5207
|
exports.HtmlElementWrapper = HtmlElementWrapper;
|
|
5147
5208
|
exports.NDElement = NDElement;
|
|
5148
5209
|
exports.Observable = Observable;
|
|
5149
|
-
exports.PluginsManager = PluginsManager
|
|
5210
|
+
exports.PluginsManager = PluginsManager;
|
|
5150
5211
|
exports.SingletonView = SingletonView;
|
|
5151
5212
|
exports.Store = Store;
|
|
5152
5213
|
exports.TemplateCloner = TemplateCloner;
|