native-document 1.0.70 → 1.0.73
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/components.js +2 -0
- package/dist/native-document.components.min.js +5636 -0
- package/dist/native-document.dev.js +412 -353
- 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/elements.js +3 -3
- package/index.js +17 -17
- package/package.json +1 -1
- package/rollup.config.js +17 -1
- package/src/components/fom-control/FormControl.js +247 -0
- package/src/components/fom-control/default/DefaultLayout.js +8 -0
- package/src/components/fom-control/default/collection/DefaultCollectionLayout.js +12 -0
- package/src/components/fom-control/default/collection/DefaultCollectionTemplate.js +6 -0
- package/src/components/fom-control/field/DefaultRender.js +91 -0
- package/src/components/fom-control/field/Field.js +396 -0
- package/src/components/fom-control/field/FieldCollection.js +260 -0
- package/src/components/fom-control/field/FieldFactory.js +107 -0
- package/src/components/fom-control/field/types/AutocompleteField.js +46 -0
- package/src/components/fom-control/field/types/CheckboxField.js +17 -0
- package/src/components/fom-control/field/types/CheckboxGroupField.js +78 -0
- package/src/components/fom-control/field/types/ColorField.js +39 -0
- package/src/components/fom-control/field/types/DateField.js +62 -0
- package/src/components/fom-control/field/types/EmailField.js +44 -0
- package/src/components/fom-control/field/types/FileField.js +66 -0
- package/src/components/fom-control/field/types/HiddenField.js +8 -0
- package/src/components/fom-control/field/types/ImageField.js +49 -0
- package/src/components/fom-control/field/types/NumberField.js +74 -0
- package/src/components/fom-control/field/types/PasswordField.js +72 -0
- package/src/components/fom-control/field/types/RadioField.js +44 -0
- package/src/components/fom-control/field/types/RangeField.js +17 -0
- package/src/components/fom-control/field/types/SearchField.js +17 -0
- package/src/components/fom-control/field/types/SelectField.js +41 -0
- package/src/components/fom-control/field/types/StringField.js +49 -0
- package/src/components/fom-control/field/types/TelField.js +38 -0
- package/src/components/fom-control/field/types/TextAreaField.js +56 -0
- package/src/components/fom-control/field/types/TimeField.js +45 -0
- package/src/components/fom-control/field/types/UrlField.js +53 -0
- package/src/components/fom-control/index.js +8 -0
- package/src/components/fom-control/merge +0 -0
- package/src/components/fom-control/utils.js +17 -0
- package/src/components/fom-control/validation/Validation.js +556 -0
- package/src/components/table/Column.js +106 -0
- package/src/components/table/ColumnGroup.js +54 -0
- package/src/components/table/DataTable.js +195 -0
- package/src/components/table/SimpleTable.js +184 -0
- package/src/components/table/index.js +9 -0
- package/src/{data → core/data}/ObservableArray.js +1 -0
- package/src/{data → core/data}/ObservableItem.js +49 -3
- package/src/{data → core/data}/observable-helpers/computed.js +2 -1
- package/src/{elements → core/elements}/anchor.js +32 -32
- package/src/{elements → core/elements}/control/for-each-array.js +4 -2
- package/src/core/utils/EventEmitter.js +46 -0
- package/src/{utils → core/utils}/helpers.js +12 -0
- package/src/{utils → core/utils}/validator.js +7 -0
- package/src/{wrappers → core/wrappers}/ElementCreator.js +10 -33
- package/src/{wrappers → core/wrappers}/NDElement.js +2 -129
- package/src/core/wrappers/NdPrototype.js +147 -0
- package/src/core/wrappers/TemplateBinding.js +7 -0
- package/src/{wrappers → core/wrappers}/TemplateCloner.js +16 -17
- package/src/core/wrappers/prototype-extensions.js +56 -0
- package/src/devtools/hrm/ComponentRegistry.js +1 -1
- package/src/router/Route.js +1 -1
- package/src/router/RouteGroupHelper.js +1 -1
- package/src/router/Router.js +4 -4
- package/src/router/RouterComponent.js +13 -2
- package/src/router/link.js +2 -2
- package/src/router/modes/HistoryRouter.js +2 -2
- package/types/forms.d.ts +2 -1
- package/types/validator.ts +2 -1
- package/utils.js +3 -3
- package/src/wrappers/NdPrototype.js +0 -71
- /package/src/{data → core/data}/MemoryManager.js +0 -0
- /package/src/{data → core/data}/Observable.js +0 -0
- /package/src/{data → core/data}/ObservableChecker.js +0 -0
- /package/src/{data → core/data}/ObservableWhen.js +0 -0
- /package/src/{data → core/data}/Store.js +0 -0
- /package/src/{data → core/data}/observable-helpers/array.js +0 -0
- /package/src/{data → core/data}/observable-helpers/batch.js +0 -0
- /package/src/{data → core/data}/observable-helpers/object.js +0 -0
- /package/src/{elements → core/elements}/content-formatter.js +0 -0
- /package/src/{elements → core/elements}/control/for-each.js +0 -0
- /package/src/{elements → core/elements}/control/show-if.js +0 -0
- /package/src/{elements → core/elements}/control/show-when.js +0 -0
- /package/src/{elements → core/elements}/control/switch.js +0 -0
- /package/src/{elements → core/elements}/description-list.js +0 -0
- /package/src/{elements → core/elements}/form.js +0 -0
- /package/src/{elements → core/elements}/html5-semantics.js +0 -0
- /package/src/{elements → core/elements}/img.js +0 -0
- /package/src/{elements → core/elements}/index.js +0 -0
- /package/src/{elements → core/elements}/interactive.js +0 -0
- /package/src/{elements → core/elements}/list.js +0 -0
- /package/src/{elements → core/elements}/medias.js +0 -0
- /package/src/{elements → core/elements}/meta-data.js +0 -0
- /package/src/{elements → core/elements}/table.js +0 -0
- /package/src/{errors → core/errors}/ArgTypesError.js +0 -0
- /package/src/{errors → core/errors}/NativeDocumentError.js +0 -0
- /package/src/{errors → core/errors}/RouterError.js +0 -0
- /package/src/{utils → core/utils}/args-types.js +0 -0
- /package/src/{utils → core/utils}/debug-manager.js +0 -0
- /package/src/{utils → core/utils}/events.js +0 -0
- /package/src/{utils → core/utils}/filters/date.js +0 -0
- /package/src/{utils → core/utils}/filters/index.js +0 -0
- /package/src/{utils → core/utils}/filters/standard.js +0 -0
- /package/src/{utils → core/utils}/filters/strings.js +0 -0
- /package/src/{utils → core/utils}/filters/utils.js +0 -0
- /package/src/{utils → core/utils}/memoize.js +0 -0
- /package/src/{utils → core/utils}/plugins-manager.js +0 -0
- /package/src/{utils → core/utils}/property-accumulator.js +0 -0
- /package/src/{utils → core/utils}/prototypes.js +0 -0
- /package/src/{utils → core/utils}/service.js +0 -0
- /package/src/{wrappers → core/wrappers}/AttributesWrapper.js +0 -0
- /package/src/{wrappers → core/wrappers}/DocumentObserver.js +0 -0
- /package/src/{wrappers → core/wrappers}/HtmlElementWrapper.js +0 -0
- /package/src/{wrappers → core/wrappers}/SingletonView.js +0 -0
- /package/src/{wrappers → core/wrappers}/constants.js +0 -0
- /package/src/{utils/fetch → fetch}/NativeFetch.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
|
|
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
|
|
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
|
|
210
|
+
DebugManager.error('Plugin Manager', `Error in plugin ${plugin.$name} for event ${eventName}`, error);
|
|
211
211
|
}
|
|
212
212
|
}
|
|
213
213
|
}
|
|
@@ -238,6 +238,19 @@ var NativeDocument = (function (exports) {
|
|
|
238
238
|
return this.$observer.$currentValue === this.$target;
|
|
239
239
|
};
|
|
240
240
|
|
|
241
|
+
const nextTick = function(fn) {
|
|
242
|
+
let pending = false;
|
|
243
|
+
return function(...args) {
|
|
244
|
+
if (pending) return;
|
|
245
|
+
pending = true;
|
|
246
|
+
|
|
247
|
+
Promise.resolve().then(() => {
|
|
248
|
+
fn.apply(this, args);
|
|
249
|
+
pending = false;
|
|
250
|
+
});
|
|
251
|
+
};
|
|
252
|
+
};
|
|
253
|
+
|
|
241
254
|
/**
|
|
242
255
|
*
|
|
243
256
|
* @param {*} item
|
|
@@ -300,6 +313,8 @@ var NativeDocument = (function (exports) {
|
|
|
300
313
|
* @class ObservableItem
|
|
301
314
|
*/
|
|
302
315
|
function ObservableItem(value, configs = null) {
|
|
316
|
+
value = Validator.isObservable(value) ? value.val() : value;
|
|
317
|
+
|
|
303
318
|
this.$previousValue = null;
|
|
304
319
|
this.$currentValue = value;
|
|
305
320
|
this.$isCleanedUp = false;
|
|
@@ -333,9 +348,15 @@ var NativeDocument = (function (exports) {
|
|
|
333
348
|
const DEFAULT_OPERATIONS = {};
|
|
334
349
|
const noneTrigger = function() {};
|
|
335
350
|
|
|
351
|
+
ObservableItem.prototype.intercept = function(callback) {
|
|
352
|
+
this.$interceptor = callback;
|
|
353
|
+
return this;
|
|
354
|
+
};
|
|
355
|
+
|
|
336
356
|
ObservableItem.prototype.triggerFirstListener = function(operations) {
|
|
337
357
|
this.$listeners[0](this.$currentValue, this.$previousValue, operations || {});
|
|
338
358
|
};
|
|
359
|
+
|
|
339
360
|
ObservableItem.prototype.triggerListeners = function(operations) {
|
|
340
361
|
const $listeners = this.$listeners;
|
|
341
362
|
const $previousValue = this.$previousValue;
|
|
@@ -412,7 +433,17 @@ var NativeDocument = (function (exports) {
|
|
|
412
433
|
* @param {*} data
|
|
413
434
|
*/
|
|
414
435
|
ObservableItem.prototype.set = function(data) {
|
|
415
|
-
|
|
436
|
+
let newValue = (typeof data === 'function') ? data(this.$currentValue) : data;
|
|
437
|
+
newValue = Validator.isObservable(newValue) ? newValue.val() : newValue;
|
|
438
|
+
|
|
439
|
+
if (this.$interceptor) {
|
|
440
|
+
const result = this.$interceptor(newValue, this.$currentValue);
|
|
441
|
+
|
|
442
|
+
if (result !== undefined) {
|
|
443
|
+
newValue = result;
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
|
|
416
447
|
if(this.$currentValue === newValue) {
|
|
417
448
|
return;
|
|
418
449
|
}
|
|
@@ -445,7 +476,18 @@ var NativeDocument = (function (exports) {
|
|
|
445
476
|
this.trigger = noneTrigger;
|
|
446
477
|
};
|
|
447
478
|
|
|
479
|
+
ObservableItem.prototype.onCleanup = function(callback) {
|
|
480
|
+
this.$cleanupListeners = this.$cleanupListeners ?? [];
|
|
481
|
+
this.$cleanupListeners.push(callback);
|
|
482
|
+
};
|
|
483
|
+
|
|
448
484
|
ObservableItem.prototype.cleanup = function() {
|
|
485
|
+
if (this.$cleanupListeners) {
|
|
486
|
+
for (let i = 0; i < this.$cleanupListeners.length; i++) {
|
|
487
|
+
this.$cleanupListeners[i]();
|
|
488
|
+
}
|
|
489
|
+
this.$cleanupListeners = null;
|
|
490
|
+
}
|
|
449
491
|
MemoryManager.unregister(this.$memoryId);
|
|
450
492
|
this.disconnectAll();
|
|
451
493
|
this.$isCleanedUp = true;
|
|
@@ -461,7 +503,7 @@ var NativeDocument = (function (exports) {
|
|
|
461
503
|
ObservableItem.prototype.subscribe = function(callback, target = null) {
|
|
462
504
|
this.$listeners = this.$listeners ?? [];
|
|
463
505
|
if (this.$isCleanedUp) {
|
|
464
|
-
DebugManager
|
|
506
|
+
DebugManager.warn('Observable subscription', '⚠️ Attempted to subscribe to a cleaned up observable.');
|
|
465
507
|
return () => {};
|
|
466
508
|
}
|
|
467
509
|
if (typeof callback !== 'function') {
|
|
@@ -508,6 +550,18 @@ var NativeDocument = (function (exports) {
|
|
|
508
550
|
};
|
|
509
551
|
};
|
|
510
552
|
|
|
553
|
+
ObservableItem.prototype.once = function(predicate, callback) {
|
|
554
|
+
const fn = typeof predicate === 'function' ? predicate : (v) => v === predicate;
|
|
555
|
+
|
|
556
|
+
const unsub = this.subscribe((val) => {
|
|
557
|
+
if (fn(val)) {
|
|
558
|
+
unsub();
|
|
559
|
+
callback(val);
|
|
560
|
+
}
|
|
561
|
+
});
|
|
562
|
+
return unsub;
|
|
563
|
+
};
|
|
564
|
+
|
|
511
565
|
/**
|
|
512
566
|
* Unsubscribe from an observable.
|
|
513
567
|
* @param {Function} callback
|
|
@@ -571,6 +625,11 @@ var NativeDocument = (function (exports) {
|
|
|
571
625
|
this.set(resetValue);
|
|
572
626
|
};
|
|
573
627
|
|
|
628
|
+
|
|
629
|
+
ObservableItem.prototype.toString = function() {
|
|
630
|
+
return String(this.$currentValue);
|
|
631
|
+
};
|
|
632
|
+
|
|
574
633
|
const DocumentObserver = {
|
|
575
634
|
mounted: new WeakMap(),
|
|
576
635
|
mountedSupposedSize: 0,
|
|
@@ -674,87 +733,6 @@ var NativeDocument = (function (exports) {
|
|
|
674
733
|
subtree: true,
|
|
675
734
|
});
|
|
676
735
|
|
|
677
|
-
const EVENTS = [
|
|
678
|
-
"Click",
|
|
679
|
-
"DblClick",
|
|
680
|
-
"MouseDown",
|
|
681
|
-
"MouseEnter",
|
|
682
|
-
"MouseLeave",
|
|
683
|
-
"MouseMove",
|
|
684
|
-
"MouseOut",
|
|
685
|
-
"MouseOver",
|
|
686
|
-
"MouseUp",
|
|
687
|
-
"Wheel",
|
|
688
|
-
"KeyDown",
|
|
689
|
-
"KeyPress",
|
|
690
|
-
"KeyUp",
|
|
691
|
-
"Blur",
|
|
692
|
-
"Change",
|
|
693
|
-
"Focus",
|
|
694
|
-
"Input",
|
|
695
|
-
"Invalid",
|
|
696
|
-
"Reset",
|
|
697
|
-
"Search",
|
|
698
|
-
"Select",
|
|
699
|
-
"Submit",
|
|
700
|
-
"Drag",
|
|
701
|
-
"DragEnd",
|
|
702
|
-
"DragEnter",
|
|
703
|
-
"DragLeave",
|
|
704
|
-
"DragOver",
|
|
705
|
-
"DragStart",
|
|
706
|
-
"Drop",
|
|
707
|
-
"AfterPrint",
|
|
708
|
-
"BeforePrint",
|
|
709
|
-
"BeforeUnload",
|
|
710
|
-
"Error",
|
|
711
|
-
"HashChange",
|
|
712
|
-
"Load",
|
|
713
|
-
"Offline",
|
|
714
|
-
"Online",
|
|
715
|
-
"PageHide",
|
|
716
|
-
"PageShow",
|
|
717
|
-
"Resize",
|
|
718
|
-
"Scroll",
|
|
719
|
-
"Unload",
|
|
720
|
-
"Abort",
|
|
721
|
-
"CanPlay",
|
|
722
|
-
"CanPlayThrough",
|
|
723
|
-
"DurationChange",
|
|
724
|
-
"Emptied",
|
|
725
|
-
"Ended",
|
|
726
|
-
"LoadedData",
|
|
727
|
-
"LoadedMetadata",
|
|
728
|
-
"LoadStart",
|
|
729
|
-
"Pause",
|
|
730
|
-
"Play",
|
|
731
|
-
"Playing",
|
|
732
|
-
"Progress",
|
|
733
|
-
"RateChange",
|
|
734
|
-
"Seeked",
|
|
735
|
-
"Seeking",
|
|
736
|
-
"Stalled",
|
|
737
|
-
"Suspend",
|
|
738
|
-
"TimeUpdate",
|
|
739
|
-
"VolumeChange",
|
|
740
|
-
"Waiting",
|
|
741
|
-
|
|
742
|
-
"TouchCancel",
|
|
743
|
-
"TouchEnd",
|
|
744
|
-
"TouchMove",
|
|
745
|
-
"TouchStart",
|
|
746
|
-
"AnimationEnd",
|
|
747
|
-
"AnimationIteration",
|
|
748
|
-
"AnimationStart",
|
|
749
|
-
"TransitionEnd",
|
|
750
|
-
"Copy",
|
|
751
|
-
"Cut",
|
|
752
|
-
"Paste",
|
|
753
|
-
"FocusIn",
|
|
754
|
-
"FocusOut",
|
|
755
|
-
"ContextMenu"
|
|
756
|
-
];
|
|
757
|
-
|
|
758
736
|
function NDElement(element) {
|
|
759
737
|
this.$element = element;
|
|
760
738
|
this.$observer = null;
|
|
@@ -853,136 +831,12 @@ var NativeDocument = (function (exports) {
|
|
|
853
831
|
return this.shadow('closed', style);
|
|
854
832
|
};
|
|
855
833
|
|
|
856
|
-
NDElement.prototype.attach = function(bindingHydrator) {
|
|
857
|
-
bindingHydrator.$hydrate(this.$element);
|
|
834
|
+
NDElement.prototype.attach = function(methodName, bindingHydrator) {
|
|
835
|
+
bindingHydrator.$hydrate(this.$element, methodName);
|
|
858
836
|
return this.$element;
|
|
859
837
|
};
|
|
860
838
|
|
|
861
839
|
|
|
862
|
-
/**
|
|
863
|
-
*
|
|
864
|
-
* ND events API
|
|
865
|
-
*
|
|
866
|
-
*/
|
|
867
|
-
|
|
868
|
-
const DelegatedEventsCallbackStore = {};
|
|
869
|
-
|
|
870
|
-
const addCallbackToCallbacksStore = function(element, eventName, callback) {
|
|
871
|
-
if(!element) return;
|
|
872
|
-
if(!DelegatedEventsCallbackStore[eventName]) {
|
|
873
|
-
const eventStore = new WeakMap();
|
|
874
|
-
DelegatedEventsCallbackStore[eventName] = eventStore;
|
|
875
|
-
eventStore.set(element, callback);
|
|
876
|
-
return;
|
|
877
|
-
}
|
|
878
|
-
const eventStore = DelegatedEventsCallbackStore[eventName];
|
|
879
|
-
|
|
880
|
-
if(!eventStore.has(element)) {
|
|
881
|
-
eventStore.set(element, callback);
|
|
882
|
-
return;
|
|
883
|
-
}
|
|
884
|
-
const existingCallbacks = eventStore.get(element);
|
|
885
|
-
if(!Validator.isArray(existingCallbacks)) {
|
|
886
|
-
eventStore.set(element, [store[eventName], callback]);
|
|
887
|
-
return;
|
|
888
|
-
}
|
|
889
|
-
existingCallbacks.push(callback);
|
|
890
|
-
};
|
|
891
|
-
|
|
892
|
-
const handleDelegatedCallbacks = function(container, eventName) {
|
|
893
|
-
container.addEventListener(eventName, (event) => {
|
|
894
|
-
const eventStore = DelegatedEventsCallbackStore[eventName];
|
|
895
|
-
if(!eventStore) {
|
|
896
|
-
return;
|
|
897
|
-
}
|
|
898
|
-
let target = event.target;
|
|
899
|
-
while(target && target !== container) {
|
|
900
|
-
const callback = eventStore.get(target);
|
|
901
|
-
if(!callback) {
|
|
902
|
-
target = target.parentElement;
|
|
903
|
-
continue;
|
|
904
|
-
}
|
|
905
|
-
|
|
906
|
-
if(Validator.isFunction(callback)) {
|
|
907
|
-
callback.call(target, event);
|
|
908
|
-
}
|
|
909
|
-
else {
|
|
910
|
-
for(let i = 0; i < callback.length; i++) {
|
|
911
|
-
callback[i].call(target, event);
|
|
912
|
-
}
|
|
913
|
-
}
|
|
914
|
-
return;
|
|
915
|
-
}
|
|
916
|
-
});
|
|
917
|
-
};
|
|
918
|
-
|
|
919
|
-
const preventDefaultWrapper = function(element, eventName, callback) {
|
|
920
|
-
element.addEventListener(eventName, (event) => {
|
|
921
|
-
event.preventDefault();
|
|
922
|
-
callback && callback.call(element, event);
|
|
923
|
-
});
|
|
924
|
-
return this;
|
|
925
|
-
};
|
|
926
|
-
|
|
927
|
-
const stopPropagationWrapper = function(element, eventName, callback) {
|
|
928
|
-
element.addEventListener(eventName, (event) => {
|
|
929
|
-
event.stopPropagation();
|
|
930
|
-
callback && callback.call(element, event);
|
|
931
|
-
});
|
|
932
|
-
return this;
|
|
933
|
-
};
|
|
934
|
-
|
|
935
|
-
const preventDefaultAndStopPropagationWrapper = function(element, eventName, callback) {
|
|
936
|
-
element.addEventListener(eventName, (event) => {
|
|
937
|
-
event.stopPropagation();
|
|
938
|
-
event.preventDefault();
|
|
939
|
-
callback && callback.call(element, event);
|
|
940
|
-
});
|
|
941
|
-
return this;
|
|
942
|
-
};
|
|
943
|
-
|
|
944
|
-
const captureEventWrapper = function(element, eventName, directHandler) {
|
|
945
|
-
if(directHandler) {
|
|
946
|
-
element.addEventListener(eventName, directHandler);
|
|
947
|
-
return this;
|
|
948
|
-
}
|
|
949
|
-
handleDelegatedCallbacks(element, eventName);
|
|
950
|
-
return this;
|
|
951
|
-
};
|
|
952
|
-
|
|
953
|
-
for(const event of EVENTS) {
|
|
954
|
-
const eventName = event.toLowerCase();
|
|
955
|
-
NDElement.prototype['on'+event] = function(callback) {
|
|
956
|
-
this.$element.addEventListener(eventName, callback);
|
|
957
|
-
return this;
|
|
958
|
-
};
|
|
959
|
-
|
|
960
|
-
NDElement.prototype['onPrevent'+event] = function(callback) {
|
|
961
|
-
preventDefaultWrapper(this.$element, eventName, callback);
|
|
962
|
-
return this;
|
|
963
|
-
};
|
|
964
|
-
|
|
965
|
-
NDElement.prototype['onStop'+event] = function(callback) {
|
|
966
|
-
stopPropagationWrapper(this.$element, eventName, callback);
|
|
967
|
-
return this;
|
|
968
|
-
};
|
|
969
|
-
|
|
970
|
-
NDElement.prototype['onPreventStop'+event] = function(callback) {
|
|
971
|
-
preventDefaultAndStopPropagationWrapper(this.$element, eventName, callback);
|
|
972
|
-
return this;
|
|
973
|
-
};
|
|
974
|
-
|
|
975
|
-
NDElement.prototype['when'+event] = function(callback) {
|
|
976
|
-
addCallbackToCallbacksStore(this.$element, eventName, callback);
|
|
977
|
-
return this;
|
|
978
|
-
};
|
|
979
|
-
|
|
980
|
-
NDElement.prototype['capture'+event] = function(directHandler) {
|
|
981
|
-
captureEventWrapper(this.$element, eventName, directHandler);
|
|
982
|
-
return this;
|
|
983
|
-
};
|
|
984
|
-
}
|
|
985
|
-
|
|
986
840
|
NDElement.prototype.with = function(methods) {
|
|
987
841
|
if (!methods || typeof methods !== 'object') {
|
|
988
842
|
throw new NativeDocumentError('extend() requires an object of methods');
|
|
@@ -1002,7 +856,7 @@ var NativeDocument = (function (exports) {
|
|
|
1002
856
|
}
|
|
1003
857
|
{
|
|
1004
858
|
if (this[name] && !this.$localExtensions.has(name)) {
|
|
1005
|
-
DebugManager
|
|
859
|
+
DebugManager.warn('NDElement.extend', `Method "${name}" already exists and will be overwritten`);
|
|
1006
860
|
}
|
|
1007
861
|
this.$localExtensions.set(name, method);
|
|
1008
862
|
}
|
|
@@ -1036,17 +890,17 @@ var NativeDocument = (function (exports) {
|
|
|
1036
890
|
const method = methods[name];
|
|
1037
891
|
|
|
1038
892
|
if (typeof method !== 'function') {
|
|
1039
|
-
DebugManager
|
|
893
|
+
DebugManager.warn('NDElement.extend', `"${name}" is not a function, skipping`);
|
|
1040
894
|
continue;
|
|
1041
895
|
}
|
|
1042
896
|
|
|
1043
897
|
if (protectedMethods.has(name)) {
|
|
1044
|
-
DebugManager
|
|
898
|
+
DebugManager.error('NDElement.extend', `Cannot override protected method "${name}"`);
|
|
1045
899
|
throw new NativeDocumentError(`Cannot override protected method "${name}"`);
|
|
1046
900
|
}
|
|
1047
901
|
|
|
1048
902
|
if (NDElement.prototype[name]) {
|
|
1049
|
-
DebugManager
|
|
903
|
+
DebugManager.warn('NDElement.extend', `Overwriting existing prototype method "${name}"`);
|
|
1050
904
|
}
|
|
1051
905
|
|
|
1052
906
|
NDElement.prototype[name] = method;
|
|
@@ -1057,6 +911,12 @@ var NativeDocument = (function (exports) {
|
|
|
1057
911
|
return NDElement;
|
|
1058
912
|
};
|
|
1059
913
|
|
|
914
|
+
function TemplateBinding(hydrate) {
|
|
915
|
+
this.$hydrate = hydrate;
|
|
916
|
+
}
|
|
917
|
+
|
|
918
|
+
TemplateBinding.prototype.__$isTemplateBinding = true;
|
|
919
|
+
|
|
1060
920
|
const COMMON_NODE_TYPES = {
|
|
1061
921
|
ELEMENT: 1,
|
|
1062
922
|
TEXT: 3,
|
|
@@ -1068,6 +928,9 @@ var NativeDocument = (function (exports) {
|
|
|
1068
928
|
isObservable(value) {
|
|
1069
929
|
return value?.__$isObservable || value instanceof ObservableItem || value instanceof ObservableChecker;
|
|
1070
930
|
},
|
|
931
|
+
isTemplateBinding(value) {
|
|
932
|
+
return value?.__$isTemplateBinding || value instanceof TemplateBinding;
|
|
933
|
+
},
|
|
1071
934
|
isObservableWhenResult(value) {
|
|
1072
935
|
return value && (value.__$isObservableWhen || (typeof value === 'object' && '$target' in value && '$observer' in value));
|
|
1073
936
|
},
|
|
@@ -1077,6 +940,9 @@ var NativeDocument = (function (exports) {
|
|
|
1077
940
|
isProxy(value) {
|
|
1078
941
|
return value?.__isProxy__
|
|
1079
942
|
},
|
|
943
|
+
isObservableOrProxy(value) {
|
|
944
|
+
return Validator.isObservable(value) || Validator.isProxy(value);
|
|
945
|
+
},
|
|
1080
946
|
isAnchor(value) {
|
|
1081
947
|
return value?.__Anchor__
|
|
1082
948
|
},
|
|
@@ -1192,7 +1058,7 @@ var NativeDocument = (function (exports) {
|
|
|
1192
1058
|
const foundReserved = Object.keys(attributes).filter(key => reserved.includes(key));
|
|
1193
1059
|
|
|
1194
1060
|
if (foundReserved.length > 0) {
|
|
1195
|
-
DebugManager
|
|
1061
|
+
DebugManager.warn('Validator', `Reserved attributes found: ${foundReserved.join(', ')}`);
|
|
1196
1062
|
}
|
|
1197
1063
|
|
|
1198
1064
|
return attributes;
|
|
@@ -1200,23 +1066,23 @@ var NativeDocument = (function (exports) {
|
|
|
1200
1066
|
}
|
|
1201
1067
|
|
|
1202
1068
|
function Anchor(name, isUniqueChild = false) {
|
|
1203
|
-
const
|
|
1204
|
-
|
|
1069
|
+
const anchorFragment = document.createDocumentFragment();
|
|
1070
|
+
anchorFragment.__Anchor__ = true;
|
|
1205
1071
|
|
|
1206
1072
|
const anchorStart = document.createComment('Anchor Start : '+name);
|
|
1207
1073
|
const anchorEnd = document.createComment('/ Anchor End '+name);
|
|
1208
1074
|
|
|
1209
|
-
|
|
1210
|
-
|
|
1075
|
+
anchorFragment.appendChild(anchorStart);
|
|
1076
|
+
anchorFragment.appendChild(anchorEnd);
|
|
1211
1077
|
|
|
1212
|
-
|
|
1213
|
-
|
|
1078
|
+
anchorFragment.nativeInsertBefore = anchorFragment.insertBefore;
|
|
1079
|
+
anchorFragment.nativeAppendChild = anchorFragment.appendChild;
|
|
1214
1080
|
|
|
1215
1081
|
const isParentUniqueChild = (parent) => (isUniqueChild || (parent.firstChild === anchorStart && parent.lastChild === anchorEnd));
|
|
1216
1082
|
|
|
1217
1083
|
const insertBefore = function(parent, child, target) {
|
|
1218
1084
|
const childElement = Validator.isElement(child) ? child : ElementCreator.getChild(child);
|
|
1219
|
-
if(parent ===
|
|
1085
|
+
if(parent === anchorFragment) {
|
|
1220
1086
|
parent.nativeInsertBefore(childElement, target);
|
|
1221
1087
|
return;
|
|
1222
1088
|
}
|
|
@@ -1227,32 +1093,32 @@ var NativeDocument = (function (exports) {
|
|
|
1227
1093
|
parent.insertBefore(childElement, target);
|
|
1228
1094
|
};
|
|
1229
1095
|
|
|
1230
|
-
|
|
1096
|
+
anchorFragment.appendElement = function(child, before = null) {
|
|
1231
1097
|
const parentNode = anchorStart.parentNode;
|
|
1232
1098
|
const targetBefore = before || anchorEnd;
|
|
1233
|
-
if(parentNode ===
|
|
1099
|
+
if(parentNode === anchorFragment) {
|
|
1234
1100
|
parentNode.nativeInsertBefore(child, targetBefore);
|
|
1235
1101
|
return;
|
|
1236
1102
|
}
|
|
1237
1103
|
parentNode?.insertBefore(child, targetBefore);
|
|
1238
1104
|
};
|
|
1239
1105
|
|
|
1240
|
-
|
|
1106
|
+
anchorFragment.appendChild = function(child, before = null) {
|
|
1241
1107
|
const parent = anchorEnd.parentNode;
|
|
1242
1108
|
if(!parent) {
|
|
1243
|
-
DebugManager
|
|
1109
|
+
DebugManager.error('Anchor', 'Anchor : parent not found', child);
|
|
1244
1110
|
return;
|
|
1245
1111
|
}
|
|
1246
1112
|
before = before ?? anchorEnd;
|
|
1247
1113
|
insertBefore(parent, child, before);
|
|
1248
1114
|
};
|
|
1249
|
-
|
|
1250
|
-
return
|
|
1115
|
+
anchorFragment.append = function(...args ) {
|
|
1116
|
+
return anchorFragment.appendChild(args);
|
|
1251
1117
|
};
|
|
1252
1118
|
|
|
1253
|
-
|
|
1119
|
+
anchorFragment.removeChildren = function() {
|
|
1254
1120
|
const parent = anchorEnd.parentNode;
|
|
1255
|
-
if(parent ===
|
|
1121
|
+
if(parent === anchorFragment) {
|
|
1256
1122
|
return;
|
|
1257
1123
|
}
|
|
1258
1124
|
if(isParentUniqueChild(parent)) {
|
|
@@ -1269,26 +1135,26 @@ var NativeDocument = (function (exports) {
|
|
|
1269
1135
|
}
|
|
1270
1136
|
fragment.replaceChildren();
|
|
1271
1137
|
};
|
|
1272
|
-
|
|
1138
|
+
anchorFragment.remove = function() {
|
|
1273
1139
|
const parent = anchorEnd.parentNode;
|
|
1274
|
-
if(parent ===
|
|
1140
|
+
if(parent === anchorFragment) {
|
|
1275
1141
|
return;
|
|
1276
1142
|
}
|
|
1277
1143
|
let itemToRemove = anchorStart.nextSibling, tempItem;
|
|
1278
1144
|
while(itemToRemove && itemToRemove !== anchorEnd) {
|
|
1279
1145
|
tempItem = itemToRemove.nextSibling;
|
|
1280
|
-
|
|
1146
|
+
anchorFragment.nativeAppendChild(itemToRemove);
|
|
1281
1147
|
itemToRemove = tempItem;
|
|
1282
1148
|
}
|
|
1283
1149
|
};
|
|
1284
1150
|
|
|
1285
|
-
|
|
1286
|
-
|
|
1151
|
+
anchorFragment.removeWithAnchors = function() {
|
|
1152
|
+
anchorFragment.removeChildren();
|
|
1287
1153
|
anchorStart.remove();
|
|
1288
1154
|
anchorEnd.remove();
|
|
1289
1155
|
};
|
|
1290
1156
|
|
|
1291
|
-
|
|
1157
|
+
anchorFragment.replaceContent = function(child) {
|
|
1292
1158
|
const childElement = Validator.isElement(child) ? child : ElementCreator.getChild(child);
|
|
1293
1159
|
const parent = anchorEnd.parentNode;
|
|
1294
1160
|
if(!parent) {
|
|
@@ -1298,31 +1164,31 @@ var NativeDocument = (function (exports) {
|
|
|
1298
1164
|
parent.replaceChildren(anchorStart, childElement, anchorEnd);
|
|
1299
1165
|
return;
|
|
1300
1166
|
}
|
|
1301
|
-
|
|
1167
|
+
anchorFragment.removeChildren();
|
|
1302
1168
|
parent.insertBefore(childElement, anchorEnd);
|
|
1303
1169
|
};
|
|
1304
1170
|
|
|
1305
|
-
|
|
1171
|
+
anchorFragment.setContent = anchorFragment.replaceContent;
|
|
1306
1172
|
|
|
1307
|
-
|
|
1308
|
-
|
|
1173
|
+
anchorFragment.insertBefore = function(child, anchor = null) {
|
|
1174
|
+
anchorFragment.appendChild(child, anchor);
|
|
1309
1175
|
};
|
|
1310
1176
|
|
|
1311
1177
|
|
|
1312
|
-
|
|
1178
|
+
anchorFragment.endElement = function() {
|
|
1313
1179
|
return anchorEnd;
|
|
1314
1180
|
};
|
|
1315
1181
|
|
|
1316
|
-
|
|
1182
|
+
anchorFragment.startElement = function() {
|
|
1317
1183
|
return anchorStart;
|
|
1318
1184
|
};
|
|
1319
|
-
|
|
1320
|
-
|
|
1185
|
+
anchorFragment.restore = function() {
|
|
1186
|
+
anchorFragment.appendChild(anchorFragment);
|
|
1321
1187
|
};
|
|
1322
|
-
|
|
1323
|
-
|
|
1188
|
+
anchorFragment.clear = anchorFragment.remove;
|
|
1189
|
+
anchorFragment.detach = anchorFragment.remove;
|
|
1324
1190
|
|
|
1325
|
-
|
|
1191
|
+
anchorFragment.getByIndex = function(index) {
|
|
1326
1192
|
let currentNode = anchorStart;
|
|
1327
1193
|
for(let i = 0; i <= index; i++) {
|
|
1328
1194
|
if(!currentNode.nextSibling) {
|
|
@@ -1333,7 +1199,7 @@ var NativeDocument = (function (exports) {
|
|
|
1333
1199
|
return currentNode !== anchorStart ? currentNode : null;
|
|
1334
1200
|
};
|
|
1335
1201
|
|
|
1336
|
-
return
|
|
1202
|
+
return anchorFragment;
|
|
1337
1203
|
}
|
|
1338
1204
|
/**
|
|
1339
1205
|
*
|
|
@@ -1358,18 +1224,18 @@ var NativeDocument = (function (exports) {
|
|
|
1358
1224
|
* @returns {ObservableItem}
|
|
1359
1225
|
* @constructor
|
|
1360
1226
|
*/
|
|
1361
|
-
function Observable
|
|
1227
|
+
function Observable(value, configs = null) {
|
|
1362
1228
|
return new ObservableItem(value, configs);
|
|
1363
1229
|
}
|
|
1364
1230
|
|
|
1365
|
-
const $ = Observable
|
|
1366
|
-
const obs = Observable
|
|
1231
|
+
const $ = Observable;
|
|
1232
|
+
const obs = Observable;
|
|
1367
1233
|
|
|
1368
1234
|
/**
|
|
1369
1235
|
*
|
|
1370
1236
|
* @param {string} propertyName
|
|
1371
1237
|
*/
|
|
1372
|
-
Observable
|
|
1238
|
+
Observable.useValueProperty = function(propertyName = 'value') {
|
|
1373
1239
|
Object.defineProperty(ObservableItem.prototype, propertyName, {
|
|
1374
1240
|
get() {
|
|
1375
1241
|
return this.$currentValue;
|
|
@@ -1387,7 +1253,7 @@ var NativeDocument = (function (exports) {
|
|
|
1387
1253
|
* @param id
|
|
1388
1254
|
* @returns {ObservableItem|null}
|
|
1389
1255
|
*/
|
|
1390
|
-
Observable
|
|
1256
|
+
Observable.getById = function(id) {
|
|
1391
1257
|
const item = MemoryManager.getObservableById(parseInt(id));
|
|
1392
1258
|
if(!item) {
|
|
1393
1259
|
throw new NativeDocumentError('Observable.getById : No observable found with id ' + id);
|
|
@@ -1399,7 +1265,7 @@ var NativeDocument = (function (exports) {
|
|
|
1399
1265
|
*
|
|
1400
1266
|
* @param {ObservableItem} observable
|
|
1401
1267
|
*/
|
|
1402
|
-
Observable
|
|
1268
|
+
Observable.cleanup = function(observable) {
|
|
1403
1269
|
observable.cleanup();
|
|
1404
1270
|
};
|
|
1405
1271
|
|
|
@@ -1408,7 +1274,7 @@ var NativeDocument = (function (exports) {
|
|
|
1408
1274
|
* @param {Boolean} enable
|
|
1409
1275
|
* @param {{interval:Boolean, threshold:number}} options
|
|
1410
1276
|
*/
|
|
1411
|
-
Observable
|
|
1277
|
+
Observable.autoCleanup = function(enable = false, options = {}) {
|
|
1412
1278
|
if(!enable) {
|
|
1413
1279
|
return;
|
|
1414
1280
|
}
|
|
@@ -1556,7 +1422,7 @@ var NativeDocument = (function (exports) {
|
|
|
1556
1422
|
continue;
|
|
1557
1423
|
}
|
|
1558
1424
|
const observables = value.filter(item => Validator.isObservable(item));
|
|
1559
|
-
value = Observable
|
|
1425
|
+
value = Observable.computed(() => {
|
|
1560
1426
|
return value.map(item => Validator.isObservable(item) ? item.val() : item).join(' ') || ' ';
|
|
1561
1427
|
}, observables);
|
|
1562
1428
|
}
|
|
@@ -1586,6 +1452,56 @@ var NativeDocument = (function (exports) {
|
|
|
1586
1452
|
return element;
|
|
1587
1453
|
}
|
|
1588
1454
|
|
|
1455
|
+
String.prototype.toNdElement = function () {
|
|
1456
|
+
const formattedChild = this.resolveObservableTemplate ? this.resolveObservableTemplate() : this;
|
|
1457
|
+
if(Validator.isString(formattedChild)) {
|
|
1458
|
+
return ElementCreator.createStaticTextNode(null, formattedChild);
|
|
1459
|
+
}
|
|
1460
|
+
return ElementCreator.getChild(null, formattedChild);
|
|
1461
|
+
};
|
|
1462
|
+
|
|
1463
|
+
Element.prototype.toNdElement = function () {
|
|
1464
|
+
return this;
|
|
1465
|
+
};
|
|
1466
|
+
Text.prototype.toNdElement = function () {
|
|
1467
|
+
return this;
|
|
1468
|
+
};
|
|
1469
|
+
Comment.prototype.toNdElement = function () {
|
|
1470
|
+
return this;
|
|
1471
|
+
};
|
|
1472
|
+
Document.prototype.toNdElement = function () {
|
|
1473
|
+
return this;
|
|
1474
|
+
};
|
|
1475
|
+
DocumentFragment.prototype.toNdElement = function () {
|
|
1476
|
+
return this;
|
|
1477
|
+
};
|
|
1478
|
+
|
|
1479
|
+
ObservableItem.prototype.toNdElement = function () {
|
|
1480
|
+
return ElementCreator.createObservableNode(null, this);
|
|
1481
|
+
};
|
|
1482
|
+
|
|
1483
|
+
NDElement.prototype.toNdElement = function () {
|
|
1484
|
+
return this.$element ?? this.$build?.() ?? this.build?.() ?? null;
|
|
1485
|
+
};
|
|
1486
|
+
|
|
1487
|
+
Array.prototype.toNdElement = function () {
|
|
1488
|
+
const fragment = document.createDocumentFragment();
|
|
1489
|
+
for(let i = 0, length = this.length; i < length; i++) {
|
|
1490
|
+
fragment.appendChild(ElementCreator.getChild(this[i]));
|
|
1491
|
+
}
|
|
1492
|
+
return fragment;
|
|
1493
|
+
};
|
|
1494
|
+
|
|
1495
|
+
Function.prototype.toNdElement = function () {
|
|
1496
|
+
const child = this;
|
|
1497
|
+
PluginsManager.emit('BeforeProcessComponent', child);
|
|
1498
|
+
return ElementCreator.getChild(child());
|
|
1499
|
+
};
|
|
1500
|
+
|
|
1501
|
+
TemplateBinding.prototype.toNdElement = function () {
|
|
1502
|
+
return ElementCreator.createHydratableNode(null, this);
|
|
1503
|
+
};
|
|
1504
|
+
|
|
1589
1505
|
const $nodeCache = new Map();
|
|
1590
1506
|
let $textNodeCache = null;
|
|
1591
1507
|
|
|
@@ -1674,41 +1590,18 @@ var NativeDocument = (function (exports) {
|
|
|
1674
1590
|
PluginsManager.emit('AfterProcessChildren', parent);
|
|
1675
1591
|
},
|
|
1676
1592
|
getChild(child) {
|
|
1677
|
-
if(child
|
|
1593
|
+
if(child == null) {
|
|
1678
1594
|
return null;
|
|
1679
1595
|
}
|
|
1680
|
-
if(
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
return child;
|
|
1688
|
-
}
|
|
1689
|
-
if (Validator.isObservable(child)) {
|
|
1690
|
-
return ElementCreator.createObservableNode(null, child);
|
|
1691
|
-
}
|
|
1692
|
-
if(Validator.isNDElement(child)) {
|
|
1693
|
-
return child.$element ?? child.$build?.() ?? null;
|
|
1694
|
-
}
|
|
1695
|
-
if(Validator.$element) {
|
|
1696
|
-
return Validator.$element;
|
|
1697
|
-
}
|
|
1698
|
-
if(Validator.isArray(child)) {
|
|
1699
|
-
const fragment = document.createDocumentFragment();
|
|
1700
|
-
for(let i = 0, length = child.length; i < length; i++) {
|
|
1701
|
-
fragment.appendChild(this.getChild(child[i]));
|
|
1702
|
-
}
|
|
1703
|
-
return fragment;
|
|
1704
|
-
}
|
|
1705
|
-
if(Validator.isFunction(child)) {
|
|
1706
|
-
PluginsManager.emit('BeforeProcessComponent', child);
|
|
1707
|
-
return this.getChild(child());
|
|
1708
|
-
}
|
|
1709
|
-
if(child?.$hydrate) {
|
|
1710
|
-
return ElementCreator.createHydratableNode(null, child);
|
|
1596
|
+
if(child.toNdElement) {
|
|
1597
|
+
do {
|
|
1598
|
+
child = child.toNdElement();
|
|
1599
|
+
if(Validator.isElement(child)) {
|
|
1600
|
+
return child;
|
|
1601
|
+
}
|
|
1602
|
+
} while (child.toNdElement);
|
|
1711
1603
|
}
|
|
1604
|
+
|
|
1712
1605
|
return ElementCreator.createStaticTextNode(null, child);
|
|
1713
1606
|
},
|
|
1714
1607
|
/**
|
|
@@ -1735,10 +1628,97 @@ var NativeDocument = (function (exports) {
|
|
|
1735
1628
|
}
|
|
1736
1629
|
};
|
|
1737
1630
|
|
|
1631
|
+
const EVENTS = [
|
|
1632
|
+
"Click",
|
|
1633
|
+
"DblClick",
|
|
1634
|
+
"MouseDown",
|
|
1635
|
+
"MouseEnter",
|
|
1636
|
+
"MouseLeave",
|
|
1637
|
+
"MouseMove",
|
|
1638
|
+
"MouseOut",
|
|
1639
|
+
"MouseOver",
|
|
1640
|
+
"MouseUp",
|
|
1641
|
+
"Wheel",
|
|
1642
|
+
"KeyDown",
|
|
1643
|
+
"KeyPress",
|
|
1644
|
+
"KeyUp",
|
|
1645
|
+
"Blur",
|
|
1646
|
+
"Change",
|
|
1647
|
+
"Focus",
|
|
1648
|
+
"Input",
|
|
1649
|
+
"Invalid",
|
|
1650
|
+
"Reset",
|
|
1651
|
+
"Search",
|
|
1652
|
+
"Select",
|
|
1653
|
+
"Submit",
|
|
1654
|
+
"Drag",
|
|
1655
|
+
"DragEnd",
|
|
1656
|
+
"DragEnter",
|
|
1657
|
+
"DragLeave",
|
|
1658
|
+
"DragOver",
|
|
1659
|
+
"DragStart",
|
|
1660
|
+
"Drop",
|
|
1661
|
+
"AfterPrint",
|
|
1662
|
+
"BeforePrint",
|
|
1663
|
+
"BeforeUnload",
|
|
1664
|
+
"Error",
|
|
1665
|
+
"HashChange",
|
|
1666
|
+
"Load",
|
|
1667
|
+
"Offline",
|
|
1668
|
+
"Online",
|
|
1669
|
+
"PageHide",
|
|
1670
|
+
"PageShow",
|
|
1671
|
+
"Resize",
|
|
1672
|
+
"Scroll",
|
|
1673
|
+
"Unload",
|
|
1674
|
+
"Abort",
|
|
1675
|
+
"CanPlay",
|
|
1676
|
+
"CanPlayThrough",
|
|
1677
|
+
"DurationChange",
|
|
1678
|
+
"Emptied",
|
|
1679
|
+
"Ended",
|
|
1680
|
+
"LoadedData",
|
|
1681
|
+
"LoadedMetadata",
|
|
1682
|
+
"LoadStart",
|
|
1683
|
+
"Pause",
|
|
1684
|
+
"Play",
|
|
1685
|
+
"Playing",
|
|
1686
|
+
"Progress",
|
|
1687
|
+
"RateChange",
|
|
1688
|
+
"Seeked",
|
|
1689
|
+
"Seeking",
|
|
1690
|
+
"Stalled",
|
|
1691
|
+
"Suspend",
|
|
1692
|
+
"TimeUpdate",
|
|
1693
|
+
"VolumeChange",
|
|
1694
|
+
"Waiting",
|
|
1695
|
+
|
|
1696
|
+
"TouchCancel",
|
|
1697
|
+
"TouchEnd",
|
|
1698
|
+
"TouchMove",
|
|
1699
|
+
"TouchStart",
|
|
1700
|
+
"AnimationEnd",
|
|
1701
|
+
"AnimationIteration",
|
|
1702
|
+
"AnimationStart",
|
|
1703
|
+
"TransitionEnd",
|
|
1704
|
+
"Copy",
|
|
1705
|
+
"Cut",
|
|
1706
|
+
"Paste",
|
|
1707
|
+
"FocusIn",
|
|
1708
|
+
"FocusOut",
|
|
1709
|
+
"ContextMenu"
|
|
1710
|
+
];
|
|
1711
|
+
|
|
1712
|
+
let createNdElementInstance = (target) => {
|
|
1713
|
+
attachEventPrototypes && attachEventPrototypes();
|
|
1714
|
+
attachEventPrototypes = null;
|
|
1715
|
+
createNdElementInstance = (target) => new NDElement(target);
|
|
1716
|
+
return new NDElement(target);
|
|
1717
|
+
};
|
|
1738
1718
|
const property = {
|
|
1739
1719
|
configurable: true,
|
|
1740
1720
|
get() {
|
|
1741
|
-
return
|
|
1721
|
+
return createNdElementInstance(this);
|
|
1742
1722
|
}
|
|
1743
1723
|
};
|
|
1744
1724
|
|
|
@@ -1752,6 +1732,75 @@ var NativeDocument = (function (exports) {
|
|
|
1752
1732
|
}
|
|
1753
1733
|
});
|
|
1754
1734
|
|
|
1735
|
+
|
|
1736
|
+
|
|
1737
|
+
// ----------------------------------------------------------------
|
|
1738
|
+
// Events helpers
|
|
1739
|
+
// ----------------------------------------------------------------
|
|
1740
|
+
|
|
1741
|
+
let attachEventPrototypes = () => {
|
|
1742
|
+
EVENTS.forEach(eventSourceName => {
|
|
1743
|
+
const eventName = eventSourceName.toLowerCase();
|
|
1744
|
+
NDElement.prototype['on'+eventSourceName] = function(callback) {
|
|
1745
|
+
this.$element.addEventListener(eventName, callback);
|
|
1746
|
+
return this;
|
|
1747
|
+
};
|
|
1748
|
+
|
|
1749
|
+
NDElement.prototype['onPrevent'+eventSourceName] = function(callback) {
|
|
1750
|
+
_prevent(this.$element, eventName, callback);
|
|
1751
|
+
return this;
|
|
1752
|
+
};
|
|
1753
|
+
|
|
1754
|
+
NDElement.prototype['onStop'+eventSourceName] = function(callback) {
|
|
1755
|
+
_stop(this.$element, eventName, callback);
|
|
1756
|
+
return this;
|
|
1757
|
+
};
|
|
1758
|
+
|
|
1759
|
+
NDElement.prototype['onPreventStop'+eventSourceName] = function(callback) {
|
|
1760
|
+
_preventStop(this.$element, eventName, callback);
|
|
1761
|
+
return this;
|
|
1762
|
+
};
|
|
1763
|
+
});
|
|
1764
|
+
};
|
|
1765
|
+
|
|
1766
|
+
NDElement.prototype.on = function(name, callback, options) {
|
|
1767
|
+
this.$element.addEventListener(name.toLowerCase(), callback, options);
|
|
1768
|
+
return this;
|
|
1769
|
+
};
|
|
1770
|
+
|
|
1771
|
+
const _prevent = function(element, eventName, callback) {
|
|
1772
|
+
const handler = (event) => {
|
|
1773
|
+
event.preventDefault();
|
|
1774
|
+
callback && callback.call(element, event);
|
|
1775
|
+
};
|
|
1776
|
+
element.addEventListener(eventName, handler);
|
|
1777
|
+
return this;
|
|
1778
|
+
};
|
|
1779
|
+
|
|
1780
|
+
const _stop = function(element, eventName, callback) {
|
|
1781
|
+
const handler = (event) => {
|
|
1782
|
+
event.stopPropagation();
|
|
1783
|
+
callback && callback.call(element, event);
|
|
1784
|
+
};
|
|
1785
|
+
element.addEventListener(eventName, handler);
|
|
1786
|
+
return this;
|
|
1787
|
+
};
|
|
1788
|
+
|
|
1789
|
+
const _preventStop = function(element, eventName, callback) {
|
|
1790
|
+
const handler = (event) => {
|
|
1791
|
+
event.stopPropagation();
|
|
1792
|
+
event.preventDefault();
|
|
1793
|
+
callback && callback.call(element, event);
|
|
1794
|
+
};
|
|
1795
|
+
element.addEventListener(eventName, handler);
|
|
1796
|
+
return this;
|
|
1797
|
+
};
|
|
1798
|
+
|
|
1799
|
+
|
|
1800
|
+
|
|
1801
|
+
// ----------------------------------------------------------------
|
|
1802
|
+
// Class attributes binder
|
|
1803
|
+
// ----------------------------------------------------------------
|
|
1755
1804
|
const classListMethods = {
|
|
1756
1805
|
getClasses() {
|
|
1757
1806
|
return this.$element.className?.split(' ').filter(Boolean);
|
|
@@ -1968,7 +2017,7 @@ var NativeDocument = (function (exports) {
|
|
|
1968
2017
|
const bindAttributes = (node, bindDingData, data) => {
|
|
1969
2018
|
let attributes = null;
|
|
1970
2019
|
if(bindDingData.attributes) {
|
|
1971
|
-
attributes =
|
|
2020
|
+
attributes = {};
|
|
1972
2021
|
for (const attr in bindDingData.attributes) {
|
|
1973
2022
|
attributes[attr] = bindDingData.attributes[attr](...data);
|
|
1974
2023
|
}
|
|
@@ -1998,29 +2047,29 @@ var NativeDocument = (function (exports) {
|
|
|
1998
2047
|
return null;
|
|
1999
2048
|
};
|
|
2000
2049
|
|
|
2001
|
-
const $hydrateFn = function(hydrateFunction,
|
|
2050
|
+
const $hydrateFn = function(hydrateFunction, targetType, element, property) {
|
|
2002
2051
|
if(!cloneBindingsDataCache.has(element)) {
|
|
2003
2052
|
// { classes, styles, attributes, value, attach }
|
|
2004
2053
|
cloneBindingsDataCache.set(element, {});
|
|
2005
2054
|
}
|
|
2006
2055
|
const hydrationState = cloneBindingsDataCache.get(element);
|
|
2007
|
-
if(
|
|
2056
|
+
if(targetType === 'value') {
|
|
2008
2057
|
hydrationState.value = hydrateFunction;
|
|
2009
2058
|
return;
|
|
2010
2059
|
}
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
return;
|
|
2014
|
-
}
|
|
2015
|
-
hydrationState[target] = hydrationState[target] || {};
|
|
2016
|
-
hydrationState[target][property] = hydrateFunction;
|
|
2060
|
+
hydrationState[targetType] = hydrationState[targetType] || {};
|
|
2061
|
+
hydrationState[targetType][property] = hydrateFunction;
|
|
2017
2062
|
};
|
|
2018
2063
|
|
|
2019
2064
|
const bindAttachMethods = function(node, bindDingData, data) {
|
|
2020
2065
|
if(!bindDingData.attach) {
|
|
2021
2066
|
return null;
|
|
2022
2067
|
}
|
|
2023
|
-
bindDingData.attach
|
|
2068
|
+
for(const methodName in bindDingData.attach) {
|
|
2069
|
+
node.nd[methodName](function(...args) {
|
|
2070
|
+
bindDingData.attach[methodName].call(this, ...[...args, ...data]);
|
|
2071
|
+
});
|
|
2072
|
+
}
|
|
2024
2073
|
};
|
|
2025
2074
|
|
|
2026
2075
|
function TemplateCloner($fn) {
|
|
@@ -2068,13 +2117,11 @@ var NativeDocument = (function (exports) {
|
|
|
2068
2117
|
};
|
|
2069
2118
|
|
|
2070
2119
|
|
|
2071
|
-
const createBinding = (hydrateFunction,
|
|
2072
|
-
return {
|
|
2073
|
-
$
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
},
|
|
2077
|
-
}
|
|
2120
|
+
const createBinding = (hydrateFunction, targetType) => {
|
|
2121
|
+
return new TemplateBinding((element, property) => {
|
|
2122
|
+
$hasBindingData = true;
|
|
2123
|
+
$hydrateFn(hydrateFunction, targetType, element, property);
|
|
2124
|
+
});
|
|
2078
2125
|
};
|
|
2079
2126
|
|
|
2080
2127
|
this.style = (fn) => {
|
|
@@ -2205,7 +2252,7 @@ var NativeDocument = (function (exports) {
|
|
|
2205
2252
|
String.prototype.use = function(args) {
|
|
2206
2253
|
const value = this;
|
|
2207
2254
|
|
|
2208
|
-
return Observable
|
|
2255
|
+
return Observable.computed(() => {
|
|
2209
2256
|
return value.replace(/\$\{(.*?)}/g, (match, key) => {
|
|
2210
2257
|
const data = args[key];
|
|
2211
2258
|
if(Validator.isObservable(data)) {
|
|
@@ -2225,7 +2272,7 @@ var NativeDocument = (function (exports) {
|
|
|
2225
2272
|
return value;
|
|
2226
2273
|
}
|
|
2227
2274
|
const [_, id] = value.match(/\{\{#ObItem::\(([0-9]+)\)\}\}/);
|
|
2228
|
-
return Observable
|
|
2275
|
+
return Observable.getById(id);
|
|
2229
2276
|
});
|
|
2230
2277
|
};
|
|
2231
2278
|
|
|
@@ -2694,6 +2741,7 @@ var NativeDocument = (function (exports) {
|
|
|
2694
2741
|
};
|
|
2695
2742
|
|
|
2696
2743
|
ObservableArray.prototype = Object.create(ObservableItem.prototype);
|
|
2744
|
+
ObservableArray.prototype.constructor = ObservableArray;
|
|
2697
2745
|
ObservableArray.prototype.__$isObservableArray = true;
|
|
2698
2746
|
|
|
2699
2747
|
mutationMethods.forEach((method) => {
|
|
@@ -2859,7 +2907,7 @@ var NativeDocument = (function (exports) {
|
|
|
2859
2907
|
* @param {{propagation: boolean, deep: boolean, reset: boolean}|null} configs
|
|
2860
2908
|
* @returns {ObservableArray}
|
|
2861
2909
|
*/
|
|
2862
|
-
Observable
|
|
2910
|
+
Observable.array = function(target = [], configs = null) {
|
|
2863
2911
|
return new ObservableArray(target, configs);
|
|
2864
2912
|
};
|
|
2865
2913
|
|
|
@@ -2868,8 +2916,8 @@ var NativeDocument = (function (exports) {
|
|
|
2868
2916
|
* @param {Function} callback
|
|
2869
2917
|
* @returns {Function}
|
|
2870
2918
|
*/
|
|
2871
|
-
Observable
|
|
2872
|
-
const $observer = Observable
|
|
2919
|
+
Observable.batch = function(callback) {
|
|
2920
|
+
const $observer = Observable(0);
|
|
2873
2921
|
const batch = function() {
|
|
2874
2922
|
if(Validator.isAsyncFunction(callback)) {
|
|
2875
2923
|
return (callback(...arguments)).then(() => {
|
|
@@ -2927,7 +2975,7 @@ var NativeDocument = (function (exports) {
|
|
|
2927
2975
|
* @param {{propagation: boolean, deep: boolean, reset: boolean}|null} configs
|
|
2928
2976
|
* @returns {Proxy}
|
|
2929
2977
|
*/
|
|
2930
|
-
Observable
|
|
2978
|
+
Observable.init = function(initialValue, configs = null) {
|
|
2931
2979
|
const data = {};
|
|
2932
2980
|
for(const key in initialValue) {
|
|
2933
2981
|
const itemValue = initialValue[key];
|
|
@@ -2935,24 +2983,24 @@ var NativeDocument = (function (exports) {
|
|
|
2935
2983
|
if(configs?.deep !== false) {
|
|
2936
2984
|
const mappedItemValue = itemValue.map(item => {
|
|
2937
2985
|
if(Validator.isJson(item)) {
|
|
2938
|
-
return Observable
|
|
2986
|
+
return Observable.json(item, configs);
|
|
2939
2987
|
}
|
|
2940
2988
|
if(Validator.isArray(item)) {
|
|
2941
|
-
return Observable
|
|
2989
|
+
return Observable.array(item, configs);
|
|
2942
2990
|
}
|
|
2943
|
-
return Observable
|
|
2991
|
+
return Observable(item, configs);
|
|
2944
2992
|
});
|
|
2945
|
-
data[key] = Observable
|
|
2993
|
+
data[key] = Observable.array(mappedItemValue, configs);
|
|
2946
2994
|
continue;
|
|
2947
2995
|
}
|
|
2948
|
-
data[key] = Observable
|
|
2996
|
+
data[key] = Observable.array(itemValue, configs);
|
|
2949
2997
|
continue;
|
|
2950
2998
|
}
|
|
2951
2999
|
if(Validator.isObservable(itemValue) || Validator.isProxy(itemValue)) {
|
|
2952
3000
|
data[key] = itemValue;
|
|
2953
3001
|
continue;
|
|
2954
3002
|
}
|
|
2955
|
-
data[key] = Observable
|
|
3003
|
+
data[key] = Observable(itemValue, configs);
|
|
2956
3004
|
}
|
|
2957
3005
|
|
|
2958
3006
|
const $reset = () => {
|
|
@@ -2964,10 +3012,10 @@ var NativeDocument = (function (exports) {
|
|
|
2964
3012
|
|
|
2965
3013
|
const $val = () => ObservableObjectValue(data);
|
|
2966
3014
|
|
|
2967
|
-
const $clone = () => Observable
|
|
3015
|
+
const $clone = () => Observable.init($val(), configs);
|
|
2968
3016
|
|
|
2969
3017
|
const $updateWith = (values) => {
|
|
2970
|
-
Observable
|
|
3018
|
+
Observable.update(proxy, values);
|
|
2971
3019
|
};
|
|
2972
3020
|
|
|
2973
3021
|
const $get = (key) => ObservableGet(data, key);
|
|
@@ -3005,8 +3053,8 @@ var NativeDocument = (function (exports) {
|
|
|
3005
3053
|
* @param {any[]} data
|
|
3006
3054
|
* @return Proxy[]
|
|
3007
3055
|
*/
|
|
3008
|
-
Observable
|
|
3009
|
-
return data.map(item => Observable
|
|
3056
|
+
Observable.arrayOfObject = function(data) {
|
|
3057
|
+
return data.map(item => Observable.object(item));
|
|
3010
3058
|
};
|
|
3011
3059
|
|
|
3012
3060
|
/**
|
|
@@ -3014,7 +3062,7 @@ var NativeDocument = (function (exports) {
|
|
|
3014
3062
|
* @param {ObservableItem|Object<ObservableItem>} data
|
|
3015
3063
|
* @returns {{}|*|null}
|
|
3016
3064
|
*/
|
|
3017
|
-
Observable
|
|
3065
|
+
Observable.value = function(data) {
|
|
3018
3066
|
if(Validator.isObservable(data)) {
|
|
3019
3067
|
return data.val();
|
|
3020
3068
|
}
|
|
@@ -3025,7 +3073,7 @@ var NativeDocument = (function (exports) {
|
|
|
3025
3073
|
const result = [];
|
|
3026
3074
|
for(let i = 0, length = data.length; i < length; i++) {
|
|
3027
3075
|
const item = data[i];
|
|
3028
|
-
result.push(Observable
|
|
3076
|
+
result.push(Observable.value(item));
|
|
3029
3077
|
}
|
|
3030
3078
|
return result;
|
|
3031
3079
|
}
|
|
@@ -3033,7 +3081,7 @@ var NativeDocument = (function (exports) {
|
|
|
3033
3081
|
};
|
|
3034
3082
|
|
|
3035
3083
|
|
|
3036
|
-
Observable
|
|
3084
|
+
Observable.update = function($target, newData) {
|
|
3037
3085
|
const data = Validator.isProxy(newData) ? newData.$value : newData;
|
|
3038
3086
|
const configs = $target.configs;
|
|
3039
3087
|
|
|
@@ -3048,9 +3096,9 @@ var NativeDocument = (function (exports) {
|
|
|
3048
3096
|
if(Validator.isObservable(firstElementFromOriginalValue) || Validator.isProxy(firstElementFromOriginalValue)) {
|
|
3049
3097
|
const newValues = newValue.map(item => {
|
|
3050
3098
|
if(Validator.isProxy(firstElementFromOriginalValue)) {
|
|
3051
|
-
return Observable
|
|
3099
|
+
return Observable.init(item, configs);
|
|
3052
3100
|
}
|
|
3053
|
-
return Observable
|
|
3101
|
+
return Observable(item, configs);
|
|
3054
3102
|
});
|
|
3055
3103
|
targetItem.set(newValues);
|
|
3056
3104
|
continue;
|
|
@@ -3062,15 +3110,15 @@ var NativeDocument = (function (exports) {
|
|
|
3062
3110
|
continue;
|
|
3063
3111
|
}
|
|
3064
3112
|
if(Validator.isProxy(targetItem)) {
|
|
3065
|
-
Observable
|
|
3113
|
+
Observable.update(targetItem, newValue);
|
|
3066
3114
|
continue;
|
|
3067
3115
|
}
|
|
3068
3116
|
$target[key] = newValue;
|
|
3069
3117
|
}
|
|
3070
3118
|
};
|
|
3071
3119
|
|
|
3072
|
-
Observable
|
|
3073
|
-
Observable
|
|
3120
|
+
Observable.object = Observable.init;
|
|
3121
|
+
Observable.json = Observable.init;
|
|
3074
3122
|
|
|
3075
3123
|
/**
|
|
3076
3124
|
*
|
|
@@ -3078,10 +3126,10 @@ var NativeDocument = (function (exports) {
|
|
|
3078
3126
|
* @param {Array|Function} dependencies
|
|
3079
3127
|
* @returns {ObservableItem}
|
|
3080
3128
|
*/
|
|
3081
|
-
Observable
|
|
3129
|
+
Observable.computed = function(callback, dependencies = []) {
|
|
3082
3130
|
const initialValue = callback();
|
|
3083
3131
|
const observable = new ObservableItem(initialValue);
|
|
3084
|
-
const updatedValue = () => observable.set(callback());
|
|
3132
|
+
const updatedValue = nextTick(() => observable.set(callback()));
|
|
3085
3133
|
|
|
3086
3134
|
PluginsManager.emit('CreateObservableComputed', observable, dependencies);
|
|
3087
3135
|
|
|
@@ -3118,7 +3166,7 @@ var NativeDocument = (function (exports) {
|
|
|
3118
3166
|
*/
|
|
3119
3167
|
use(name) {
|
|
3120
3168
|
const {observer: originalObserver, subscribers } = $stores.get(name);
|
|
3121
|
-
const observerFollower = Observable
|
|
3169
|
+
const observerFollower = Observable(originalObserver.val());
|
|
3122
3170
|
const unSubscriber = originalObserver.subscribe(value => observerFollower.set(value));
|
|
3123
3171
|
const updaterUnsubscriber = observerFollower.subscribe(value => originalObserver.set(value));
|
|
3124
3172
|
observerFollower.destroy = () => {
|
|
@@ -3144,7 +3192,7 @@ var NativeDocument = (function (exports) {
|
|
|
3144
3192
|
* @returns {ObservableItem}
|
|
3145
3193
|
*/
|
|
3146
3194
|
create(name, value) {
|
|
3147
|
-
const observer = Observable
|
|
3195
|
+
const observer = Observable(value);
|
|
3148
3196
|
$stores.set(name, { observer, subscribers: new Set()});
|
|
3149
3197
|
return observer;
|
|
3150
3198
|
},
|
|
@@ -3235,14 +3283,14 @@ var NativeDocument = (function (exports) {
|
|
|
3235
3283
|
}
|
|
3236
3284
|
|
|
3237
3285
|
try {
|
|
3238
|
-
const indexObserver = callback.length >= 2 ? Observable
|
|
3286
|
+
const indexObserver = callback.length >= 2 ? Observable(indexKey) : null;
|
|
3239
3287
|
let child = ElementCreator.getChild(callback(item, indexObserver));
|
|
3240
3288
|
if(!child) {
|
|
3241
3289
|
throw new NativeDocumentError("ForEach child can't be null or undefined!");
|
|
3242
3290
|
}
|
|
3243
3291
|
cache.set(keyId, { keyId, isNew: true, child: new WeakRef(child), indexObserver});
|
|
3244
3292
|
} catch (e) {
|
|
3245
|
-
DebugManager
|
|
3293
|
+
DebugManager.error('ForEach', `Error creating element for key ${keyId}` , e);
|
|
3246
3294
|
throw e;
|
|
3247
3295
|
}
|
|
3248
3296
|
return keyId;
|
|
@@ -3340,12 +3388,14 @@ var NativeDocument = (function (exports) {
|
|
|
3340
3388
|
cleanCache();
|
|
3341
3389
|
lastNumberOfItems = 0;
|
|
3342
3390
|
};
|
|
3391
|
+
|
|
3343
3392
|
const getItemKey = (item, indexKey) => {
|
|
3344
3393
|
if(keysCache.has(item)) {
|
|
3345
3394
|
return keysCache.get(item);
|
|
3346
3395
|
}
|
|
3347
3396
|
return getKey(item, indexKey, key);
|
|
3348
3397
|
};
|
|
3398
|
+
|
|
3349
3399
|
const getItemChild = (item) => {
|
|
3350
3400
|
return getChildByKey(getItemKey(item));
|
|
3351
3401
|
};
|
|
@@ -3408,7 +3458,7 @@ var NativeDocument = (function (exports) {
|
|
|
3408
3458
|
cache.delete(keyId);
|
|
3409
3459
|
}
|
|
3410
3460
|
|
|
3411
|
-
const indexObserver = isIndexRequired ? Observable
|
|
3461
|
+
const indexObserver = isIndexRequired ? Observable(indexKey) : null;
|
|
3412
3462
|
let child = ElementCreator.getChild(callback(item, indexObserver));
|
|
3413
3463
|
if(!child) {
|
|
3414
3464
|
throw new NativeDocumentError("ForEachArray child can't be null or undefined!");
|
|
@@ -3462,9 +3512,9 @@ var NativeDocument = (function (exports) {
|
|
|
3462
3512
|
},
|
|
3463
3513
|
add(items, delay = 2) {
|
|
3464
3514
|
const fragment = Actions.toFragment(items);
|
|
3465
|
-
|
|
3515
|
+
Promise.resolve().then(() => {
|
|
3466
3516
|
element.appendElement(fragment);
|
|
3467
|
-
}
|
|
3517
|
+
});
|
|
3468
3518
|
},
|
|
3469
3519
|
replace(items) {
|
|
3470
3520
|
clear();
|
|
@@ -3614,7 +3664,7 @@ var NativeDocument = (function (exports) {
|
|
|
3614
3664
|
*/
|
|
3615
3665
|
const ShowIf = function(condition, child, { comment = null, shouldKeepInCache = true} = {}) {
|
|
3616
3666
|
if(!(Validator.isObservable(condition)) && !Validator.isObservableWhenResult(condition)) {
|
|
3617
|
-
return DebugManager
|
|
3667
|
+
return DebugManager.warn('ShowIf', "ShowIf : condition must be an Observable / "+comment, condition);
|
|
3618
3668
|
}
|
|
3619
3669
|
const element = Anchor('Show if : '+(comment || ''));
|
|
3620
3670
|
|
|
@@ -3654,7 +3704,7 @@ var NativeDocument = (function (exports) {
|
|
|
3654
3704
|
* @returns {DocumentFragment}
|
|
3655
3705
|
*/
|
|
3656
3706
|
const HideIf = function(condition, child, configs) {
|
|
3657
|
-
const hideCondition = Observable
|
|
3707
|
+
const hideCondition = Observable(!condition.val());
|
|
3658
3708
|
condition.subscribe(value => hideCondition.set(!value));
|
|
3659
3709
|
|
|
3660
3710
|
return ShowIf(hideCondition, child, configs);
|
|
@@ -4401,7 +4451,7 @@ var NativeDocument = (function (exports) {
|
|
|
4401
4451
|
window.history.pushState({ name: route.name(), params, path}, route.name() || path , path);
|
|
4402
4452
|
this.handleRouteChange(route, params, query, path);
|
|
4403
4453
|
} catch (e) {
|
|
4404
|
-
DebugManager
|
|
4454
|
+
DebugManager.error('HistoryRouter', 'Error in pushState', e);
|
|
4405
4455
|
}
|
|
4406
4456
|
};
|
|
4407
4457
|
/**
|
|
@@ -4414,7 +4464,7 @@ var NativeDocument = (function (exports) {
|
|
|
4414
4464
|
window.history.replaceState({ name: route.name(), params, path}, route.name() || path , path);
|
|
4415
4465
|
this.handleRouteChange(route, params, {}, path);
|
|
4416
4466
|
} catch(e) {
|
|
4417
|
-
DebugManager
|
|
4467
|
+
DebugManager.error('HistoryRouter', 'Error in replaceState', e);
|
|
4418
4468
|
}
|
|
4419
4469
|
};
|
|
4420
4470
|
this.forward = function() {
|
|
@@ -4441,7 +4491,7 @@ var NativeDocument = (function (exports) {
|
|
|
4441
4491
|
}
|
|
4442
4492
|
this.handleRouteChange(route, params, query, path);
|
|
4443
4493
|
} catch(e) {
|
|
4444
|
-
DebugManager
|
|
4494
|
+
DebugManager.error('HistoryRouter', 'Error in popstate event', e);
|
|
4445
4495
|
}
|
|
4446
4496
|
});
|
|
4447
4497
|
const { route, params, query, path } = this.resolve(defaultPath || (window.location.pathname+window.location.search));
|
|
@@ -4529,15 +4579,24 @@ var NativeDocument = (function (exports) {
|
|
|
4529
4579
|
function RouterComponent(router, container) {
|
|
4530
4580
|
|
|
4531
4581
|
const $cache = new Map();
|
|
4582
|
+
let $lastNodeInserted = null;
|
|
4532
4583
|
|
|
4533
4584
|
const updateContainer = function(node, route) {
|
|
4534
4585
|
container.innerHTML = '';
|
|
4586
|
+
let nodeToInsert = node;
|
|
4535
4587
|
const layout = route.layout();
|
|
4588
|
+
if(Validator.isNDElement(node)) {
|
|
4589
|
+
nodeToInsert = node.node();
|
|
4590
|
+
}
|
|
4536
4591
|
if(layout) {
|
|
4537
|
-
container.appendChild(layout(
|
|
4592
|
+
container.appendChild(layout(nodeToInsert));
|
|
4538
4593
|
return;
|
|
4539
4594
|
}
|
|
4540
|
-
|
|
4595
|
+
if(Validator.isAnchor($lastNodeInserted)) {
|
|
4596
|
+
$lastNodeInserted.remove();
|
|
4597
|
+
}
|
|
4598
|
+
container.appendChild(nodeToInsert);
|
|
4599
|
+
$lastNodeInserted = node;
|
|
4541
4600
|
};
|
|
4542
4601
|
|
|
4543
4602
|
const handleCurrentRouterState = function(state) {
|
|
@@ -4595,7 +4654,7 @@ var NativeDocument = (function (exports) {
|
|
|
4595
4654
|
listener(request);
|
|
4596
4655
|
next && next(request);
|
|
4597
4656
|
} catch (e) {
|
|
4598
|
-
DebugManager
|
|
4657
|
+
DebugManager.warn('Route Listener', 'Error in listener:', e);
|
|
4599
4658
|
}
|
|
4600
4659
|
}
|
|
4601
4660
|
};
|
|
@@ -4754,7 +4813,7 @@ var NativeDocument = (function (exports) {
|
|
|
4754
4813
|
*/
|
|
4755
4814
|
Router.create = function(options, callback) {
|
|
4756
4815
|
if(!Validator.isFunction(callback)) {
|
|
4757
|
-
DebugManager
|
|
4816
|
+
DebugManager.error('Router', 'Callback must be a function', e);
|
|
4758
4817
|
throw new RouterError('Callback must be a function');
|
|
4759
4818
|
}
|
|
4760
4819
|
const router = new Router(options);
|
|
@@ -4937,7 +4996,7 @@ var NativeDocument = (function (exports) {
|
|
|
4937
4996
|
exports.ElementCreator = ElementCreator;
|
|
4938
4997
|
exports.HtmlElementWrapper = HtmlElementWrapper;
|
|
4939
4998
|
exports.NDElement = NDElement;
|
|
4940
|
-
exports.Observable = Observable
|
|
4999
|
+
exports.Observable = Observable;
|
|
4941
5000
|
exports.PluginsManager = PluginsManager;
|
|
4942
5001
|
exports.SingletonView = SingletonView;
|
|
4943
5002
|
exports.Store = Store;
|