native-document 1.0.69 → 1.0.72
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/.npmrc.example +0 -0
- package/components.js +2 -0
- package/dist/native-document.components.min.js +5636 -0
- package/dist/native-document.dev.js +384 -323
- 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/hrm.js +0 -0
- 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 +2 -0
- package/src/{data → core/data}/ObservableItem.js +49 -3
- package/src/{data → core/data}/ObservableWhen.js +0 -0
- 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/{elements → core/elements}/control/show-when.js +0 -0
- package/src/core/utils/EventEmitter.js +46 -0
- package/src/{utils → core/utils}/filters/date.js +2 -0
- package/src/{utils → core/utils}/filters/index.js +0 -0
- package/src/{utils → core/utils}/filters/standard.js +1 -1
- 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}/helpers.js +12 -0
- package/src/{utils → core/utils}/memoize.js +0 -0
- package/src/{utils → core/utils}/service.js +0 -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 +0 -127
- package/src/core/wrappers/NdPrototype.js +147 -0
- package/src/core/wrappers/TemplateBinding.js +7 -0
- package/src/{wrappers → core/wrappers}/TemplateCloner.js +5 -6
- package/src/core/wrappers/prototype-extensions.js +56 -0
- package/src/devtools/hrm/ComponentRegistry.js +1 -1
- package/src/devtools/hrm/hrm.hook.template.js +0 -0
- package/src/devtools/hrm/hrm.orbservable.hook.template.js +0 -0
- package/src/devtools/hrm/nd-vite-hot-reload.js +0 -0
- package/src/devtools/hrm/transformComponent.js +0 -0
- 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/filters/dates.d.ts +43 -0
- package/types/filters/standard.d.ts +71 -0
- package/types/filters/strings.d.ts +21 -0
- package/types/filters/types.d.ts +20 -0
- package/types/forms.d.ts +2 -1
- package/types/memoize.d.ts +0 -0
- package/types/native-fetch.d.ts +0 -0
- package/types/observable.d.ts +6 -0
- package/types/service.d.ts +0 -0
- 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}/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/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}/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/{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
|
@@ -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;
|
|
@@ -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;
|
|
@@ -859,130 +837,6 @@ var NativeDocument = (function (exports) {
|
|
|
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');
|
|
@@ -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
|
},
|
|
@@ -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,17 +1093,17 @@ 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
1109
|
DebugManager$1.error('Anchor', 'Anchor : parent not found', child);
|
|
@@ -1246,13 +1112,13 @@ var NativeDocument = (function (exports) {
|
|
|
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);
|
|
@@ -2069,12 +2118,10 @@ var NativeDocument = (function (exports) {
|
|
|
2069
2118
|
|
|
2070
2119
|
|
|
2071
2120
|
const createBinding = (hydrateFunction, target) => {
|
|
2072
|
-
return {
|
|
2073
|
-
$
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
},
|
|
2077
|
-
}
|
|
2121
|
+
return new TemplateBinding((element, property) => {
|
|
2122
|
+
$hasBindingData = true;
|
|
2123
|
+
$hydrateFn(hydrateFunction, target, 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
|
|
|
@@ -2394,7 +2441,7 @@ var NativeDocument = (function (exports) {
|
|
|
2394
2441
|
);
|
|
2395
2442
|
}
|
|
2396
2443
|
|
|
2397
|
-
function
|
|
2444
|
+
function inArray(observableOrArray){
|
|
2398
2445
|
return createFilter(observableOrArray, (value, arr) => arr.includes(value));
|
|
2399
2446
|
}
|
|
2400
2447
|
|
|
@@ -2541,12 +2588,14 @@ var NativeDocument = (function (exports) {
|
|
|
2541
2588
|
|
|
2542
2589
|
const timeAfter = (observableOrValue) => {
|
|
2543
2590
|
return createFilter(observableOrValue, (value, target) => {
|
|
2591
|
+
if (!value || !target) return false;
|
|
2544
2592
|
return getSecondsOfDay(value) > getSecondsOfDay(target);
|
|
2545
2593
|
});
|
|
2546
2594
|
};
|
|
2547
2595
|
|
|
2548
2596
|
const timeBefore = (observableOrValue) => {
|
|
2549
2597
|
return createFilter(observableOrValue, (value, target) => {
|
|
2598
|
+
if (!value || !target) return false;
|
|
2550
2599
|
return getSecondsOfDay(value) < getSecondsOfDay(target);
|
|
2551
2600
|
});
|
|
2552
2601
|
};
|
|
@@ -2625,7 +2674,6 @@ var NativeDocument = (function (exports) {
|
|
|
2625
2674
|
|
|
2626
2675
|
var index = /*#__PURE__*/Object.freeze({
|
|
2627
2676
|
__proto__: null,
|
|
2628
|
-
In: In,
|
|
2629
2677
|
all: all,
|
|
2630
2678
|
and: and,
|
|
2631
2679
|
any: any,
|
|
@@ -2650,6 +2698,7 @@ var NativeDocument = (function (exports) {
|
|
|
2650
2698
|
greaterThanOrEqual: greaterThanOrEqual,
|
|
2651
2699
|
gt: gt,
|
|
2652
2700
|
gte: gte,
|
|
2701
|
+
inArray: inArray,
|
|
2653
2702
|
includes: includes,
|
|
2654
2703
|
isEmpty: isEmpty,
|
|
2655
2704
|
isNotEmpty: isNotEmpty,
|
|
@@ -2692,6 +2741,7 @@ var NativeDocument = (function (exports) {
|
|
|
2692
2741
|
};
|
|
2693
2742
|
|
|
2694
2743
|
ObservableArray.prototype = Object.create(ObservableItem.prototype);
|
|
2744
|
+
ObservableArray.prototype.constructor = ObservableArray;
|
|
2695
2745
|
ObservableArray.prototype.__$isObservableArray = true;
|
|
2696
2746
|
|
|
2697
2747
|
mutationMethods.forEach((method) => {
|
|
@@ -2857,7 +2907,7 @@ var NativeDocument = (function (exports) {
|
|
|
2857
2907
|
* @param {{propagation: boolean, deep: boolean, reset: boolean}|null} configs
|
|
2858
2908
|
* @returns {ObservableArray}
|
|
2859
2909
|
*/
|
|
2860
|
-
Observable
|
|
2910
|
+
Observable.array = function(target = [], configs = null) {
|
|
2861
2911
|
return new ObservableArray(target, configs);
|
|
2862
2912
|
};
|
|
2863
2913
|
|
|
@@ -2866,8 +2916,8 @@ var NativeDocument = (function (exports) {
|
|
|
2866
2916
|
* @param {Function} callback
|
|
2867
2917
|
* @returns {Function}
|
|
2868
2918
|
*/
|
|
2869
|
-
Observable
|
|
2870
|
-
const $observer = Observable
|
|
2919
|
+
Observable.batch = function(callback) {
|
|
2920
|
+
const $observer = Observable(0);
|
|
2871
2921
|
const batch = function() {
|
|
2872
2922
|
if(Validator.isAsyncFunction(callback)) {
|
|
2873
2923
|
return (callback(...arguments)).then(() => {
|
|
@@ -2925,7 +2975,7 @@ var NativeDocument = (function (exports) {
|
|
|
2925
2975
|
* @param {{propagation: boolean, deep: boolean, reset: boolean}|null} configs
|
|
2926
2976
|
* @returns {Proxy}
|
|
2927
2977
|
*/
|
|
2928
|
-
Observable
|
|
2978
|
+
Observable.init = function(initialValue, configs = null) {
|
|
2929
2979
|
const data = {};
|
|
2930
2980
|
for(const key in initialValue) {
|
|
2931
2981
|
const itemValue = initialValue[key];
|
|
@@ -2933,24 +2983,24 @@ var NativeDocument = (function (exports) {
|
|
|
2933
2983
|
if(configs?.deep !== false) {
|
|
2934
2984
|
const mappedItemValue = itemValue.map(item => {
|
|
2935
2985
|
if(Validator.isJson(item)) {
|
|
2936
|
-
return Observable
|
|
2986
|
+
return Observable.json(item, configs);
|
|
2937
2987
|
}
|
|
2938
2988
|
if(Validator.isArray(item)) {
|
|
2939
|
-
return Observable
|
|
2989
|
+
return Observable.array(item, configs);
|
|
2940
2990
|
}
|
|
2941
|
-
return Observable
|
|
2991
|
+
return Observable(item, configs);
|
|
2942
2992
|
});
|
|
2943
|
-
data[key] = Observable
|
|
2993
|
+
data[key] = Observable.array(mappedItemValue, configs);
|
|
2944
2994
|
continue;
|
|
2945
2995
|
}
|
|
2946
|
-
data[key] = Observable
|
|
2996
|
+
data[key] = Observable.array(itemValue, configs);
|
|
2947
2997
|
continue;
|
|
2948
2998
|
}
|
|
2949
2999
|
if(Validator.isObservable(itemValue) || Validator.isProxy(itemValue)) {
|
|
2950
3000
|
data[key] = itemValue;
|
|
2951
3001
|
continue;
|
|
2952
3002
|
}
|
|
2953
|
-
data[key] = Observable
|
|
3003
|
+
data[key] = Observable(itemValue, configs);
|
|
2954
3004
|
}
|
|
2955
3005
|
|
|
2956
3006
|
const $reset = () => {
|
|
@@ -2962,10 +3012,10 @@ var NativeDocument = (function (exports) {
|
|
|
2962
3012
|
|
|
2963
3013
|
const $val = () => ObservableObjectValue(data);
|
|
2964
3014
|
|
|
2965
|
-
const $clone = () => Observable
|
|
3015
|
+
const $clone = () => Observable.init($val(), configs);
|
|
2966
3016
|
|
|
2967
3017
|
const $updateWith = (values) => {
|
|
2968
|
-
Observable
|
|
3018
|
+
Observable.update(proxy, values);
|
|
2969
3019
|
};
|
|
2970
3020
|
|
|
2971
3021
|
const $get = (key) => ObservableGet(data, key);
|
|
@@ -3003,8 +3053,8 @@ var NativeDocument = (function (exports) {
|
|
|
3003
3053
|
* @param {any[]} data
|
|
3004
3054
|
* @return Proxy[]
|
|
3005
3055
|
*/
|
|
3006
|
-
Observable
|
|
3007
|
-
return data.map(item => Observable
|
|
3056
|
+
Observable.arrayOfObject = function(data) {
|
|
3057
|
+
return data.map(item => Observable.object(item));
|
|
3008
3058
|
};
|
|
3009
3059
|
|
|
3010
3060
|
/**
|
|
@@ -3012,7 +3062,7 @@ var NativeDocument = (function (exports) {
|
|
|
3012
3062
|
* @param {ObservableItem|Object<ObservableItem>} data
|
|
3013
3063
|
* @returns {{}|*|null}
|
|
3014
3064
|
*/
|
|
3015
|
-
Observable
|
|
3065
|
+
Observable.value = function(data) {
|
|
3016
3066
|
if(Validator.isObservable(data)) {
|
|
3017
3067
|
return data.val();
|
|
3018
3068
|
}
|
|
@@ -3023,7 +3073,7 @@ var NativeDocument = (function (exports) {
|
|
|
3023
3073
|
const result = [];
|
|
3024
3074
|
for(let i = 0, length = data.length; i < length; i++) {
|
|
3025
3075
|
const item = data[i];
|
|
3026
|
-
result.push(Observable
|
|
3076
|
+
result.push(Observable.value(item));
|
|
3027
3077
|
}
|
|
3028
3078
|
return result;
|
|
3029
3079
|
}
|
|
@@ -3031,7 +3081,7 @@ var NativeDocument = (function (exports) {
|
|
|
3031
3081
|
};
|
|
3032
3082
|
|
|
3033
3083
|
|
|
3034
|
-
Observable
|
|
3084
|
+
Observable.update = function($target, newData) {
|
|
3035
3085
|
const data = Validator.isProxy(newData) ? newData.$value : newData;
|
|
3036
3086
|
const configs = $target.configs;
|
|
3037
3087
|
|
|
@@ -3046,9 +3096,9 @@ var NativeDocument = (function (exports) {
|
|
|
3046
3096
|
if(Validator.isObservable(firstElementFromOriginalValue) || Validator.isProxy(firstElementFromOriginalValue)) {
|
|
3047
3097
|
const newValues = newValue.map(item => {
|
|
3048
3098
|
if(Validator.isProxy(firstElementFromOriginalValue)) {
|
|
3049
|
-
return Observable
|
|
3099
|
+
return Observable.init(item, configs);
|
|
3050
3100
|
}
|
|
3051
|
-
return Observable
|
|
3101
|
+
return Observable(item, configs);
|
|
3052
3102
|
});
|
|
3053
3103
|
targetItem.set(newValues);
|
|
3054
3104
|
continue;
|
|
@@ -3060,15 +3110,15 @@ var NativeDocument = (function (exports) {
|
|
|
3060
3110
|
continue;
|
|
3061
3111
|
}
|
|
3062
3112
|
if(Validator.isProxy(targetItem)) {
|
|
3063
|
-
Observable
|
|
3113
|
+
Observable.update(targetItem, newValue);
|
|
3064
3114
|
continue;
|
|
3065
3115
|
}
|
|
3066
3116
|
$target[key] = newValue;
|
|
3067
3117
|
}
|
|
3068
3118
|
};
|
|
3069
3119
|
|
|
3070
|
-
Observable
|
|
3071
|
-
Observable
|
|
3120
|
+
Observable.object = Observable.init;
|
|
3121
|
+
Observable.json = Observable.init;
|
|
3072
3122
|
|
|
3073
3123
|
/**
|
|
3074
3124
|
*
|
|
@@ -3076,10 +3126,10 @@ var NativeDocument = (function (exports) {
|
|
|
3076
3126
|
* @param {Array|Function} dependencies
|
|
3077
3127
|
* @returns {ObservableItem}
|
|
3078
3128
|
*/
|
|
3079
|
-
Observable
|
|
3129
|
+
Observable.computed = function(callback, dependencies = []) {
|
|
3080
3130
|
const initialValue = callback();
|
|
3081
3131
|
const observable = new ObservableItem(initialValue);
|
|
3082
|
-
const updatedValue = () => observable.set(callback());
|
|
3132
|
+
const updatedValue = nextTick(() => observable.set(callback()));
|
|
3083
3133
|
|
|
3084
3134
|
PluginsManager.emit('CreateObservableComputed', observable, dependencies);
|
|
3085
3135
|
|
|
@@ -3116,7 +3166,7 @@ var NativeDocument = (function (exports) {
|
|
|
3116
3166
|
*/
|
|
3117
3167
|
use(name) {
|
|
3118
3168
|
const {observer: originalObserver, subscribers } = $stores.get(name);
|
|
3119
|
-
const observerFollower = Observable
|
|
3169
|
+
const observerFollower = Observable(originalObserver.val());
|
|
3120
3170
|
const unSubscriber = originalObserver.subscribe(value => observerFollower.set(value));
|
|
3121
3171
|
const updaterUnsubscriber = observerFollower.subscribe(value => originalObserver.set(value));
|
|
3122
3172
|
observerFollower.destroy = () => {
|
|
@@ -3142,7 +3192,7 @@ var NativeDocument = (function (exports) {
|
|
|
3142
3192
|
* @returns {ObservableItem}
|
|
3143
3193
|
*/
|
|
3144
3194
|
create(name, value) {
|
|
3145
|
-
const observer = Observable
|
|
3195
|
+
const observer = Observable(value);
|
|
3146
3196
|
$stores.set(name, { observer, subscribers: new Set()});
|
|
3147
3197
|
return observer;
|
|
3148
3198
|
},
|
|
@@ -3233,7 +3283,7 @@ var NativeDocument = (function (exports) {
|
|
|
3233
3283
|
}
|
|
3234
3284
|
|
|
3235
3285
|
try {
|
|
3236
|
-
const indexObserver = callback.length >= 2 ? Observable
|
|
3286
|
+
const indexObserver = callback.length >= 2 ? Observable(indexKey) : null;
|
|
3237
3287
|
let child = ElementCreator.getChild(callback(item, indexObserver));
|
|
3238
3288
|
if(!child) {
|
|
3239
3289
|
throw new NativeDocumentError("ForEach child can't be null or undefined!");
|
|
@@ -3338,12 +3388,14 @@ var NativeDocument = (function (exports) {
|
|
|
3338
3388
|
cleanCache();
|
|
3339
3389
|
lastNumberOfItems = 0;
|
|
3340
3390
|
};
|
|
3391
|
+
|
|
3341
3392
|
const getItemKey = (item, indexKey) => {
|
|
3342
3393
|
if(keysCache.has(item)) {
|
|
3343
3394
|
return keysCache.get(item);
|
|
3344
3395
|
}
|
|
3345
3396
|
return getKey(item, indexKey, key);
|
|
3346
3397
|
};
|
|
3398
|
+
|
|
3347
3399
|
const getItemChild = (item) => {
|
|
3348
3400
|
return getChildByKey(getItemKey(item));
|
|
3349
3401
|
};
|
|
@@ -3406,7 +3458,7 @@ var NativeDocument = (function (exports) {
|
|
|
3406
3458
|
cache.delete(keyId);
|
|
3407
3459
|
}
|
|
3408
3460
|
|
|
3409
|
-
const indexObserver = isIndexRequired ? Observable
|
|
3461
|
+
const indexObserver = isIndexRequired ? Observable(indexKey) : null;
|
|
3410
3462
|
let child = ElementCreator.getChild(callback(item, indexObserver));
|
|
3411
3463
|
if(!child) {
|
|
3412
3464
|
throw new NativeDocumentError("ForEachArray child can't be null or undefined!");
|
|
@@ -3460,9 +3512,9 @@ var NativeDocument = (function (exports) {
|
|
|
3460
3512
|
},
|
|
3461
3513
|
add(items, delay = 2) {
|
|
3462
3514
|
const fragment = Actions.toFragment(items);
|
|
3463
|
-
|
|
3515
|
+
Promise.resolve().then(() => {
|
|
3464
3516
|
element.appendElement(fragment);
|
|
3465
|
-
}
|
|
3517
|
+
});
|
|
3466
3518
|
},
|
|
3467
3519
|
replace(items) {
|
|
3468
3520
|
clear();
|
|
@@ -3652,7 +3704,7 @@ var NativeDocument = (function (exports) {
|
|
|
3652
3704
|
* @returns {DocumentFragment}
|
|
3653
3705
|
*/
|
|
3654
3706
|
const HideIf = function(condition, child, configs) {
|
|
3655
|
-
const hideCondition = Observable
|
|
3707
|
+
const hideCondition = Observable(!condition.val());
|
|
3656
3708
|
condition.subscribe(value => hideCondition.set(!value));
|
|
3657
3709
|
|
|
3658
3710
|
return ShowIf(hideCondition, child, configs);
|
|
@@ -4527,15 +4579,24 @@ var NativeDocument = (function (exports) {
|
|
|
4527
4579
|
function RouterComponent(router, container) {
|
|
4528
4580
|
|
|
4529
4581
|
const $cache = new Map();
|
|
4582
|
+
let $lastNodeInserted = null;
|
|
4530
4583
|
|
|
4531
4584
|
const updateContainer = function(node, route) {
|
|
4532
4585
|
container.innerHTML = '';
|
|
4586
|
+
let nodeToInsert = node;
|
|
4533
4587
|
const layout = route.layout();
|
|
4588
|
+
if(Validator.isNDElement(node)) {
|
|
4589
|
+
nodeToInsert = node.node();
|
|
4590
|
+
}
|
|
4534
4591
|
if(layout) {
|
|
4535
|
-
container.appendChild(layout(
|
|
4592
|
+
container.appendChild(layout(nodeToInsert));
|
|
4536
4593
|
return;
|
|
4537
4594
|
}
|
|
4538
|
-
|
|
4595
|
+
if(Validator.isAnchor($lastNodeInserted)) {
|
|
4596
|
+
$lastNodeInserted.remove();
|
|
4597
|
+
}
|
|
4598
|
+
container.appendChild(nodeToInsert);
|
|
4599
|
+
$lastNodeInserted = node;
|
|
4539
4600
|
};
|
|
4540
4601
|
|
|
4541
4602
|
const handleCurrentRouterState = function(state) {
|
|
@@ -4935,7 +4996,7 @@ var NativeDocument = (function (exports) {
|
|
|
4935
4996
|
exports.ElementCreator = ElementCreator;
|
|
4936
4997
|
exports.HtmlElementWrapper = HtmlElementWrapper;
|
|
4937
4998
|
exports.NDElement = NDElement;
|
|
4938
|
-
exports.Observable = Observable
|
|
4999
|
+
exports.Observable = Observable;
|
|
4939
5000
|
exports.PluginsManager = PluginsManager;
|
|
4940
5001
|
exports.SingletonView = SingletonView;
|
|
4941
5002
|
exports.Store = Store;
|