native-document 1.0.75 → 1.0.77
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 +26 -1
- package/dist/native-document.components.min.js +6401 -1979
- package/dist/native-document.dev.js +138 -82
- 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/jsconfig.json +15 -0
- package/package.json +1 -1
- package/rollup.config.js +4 -2
- package/src/components/$traits/HasItems.js +38 -0
- package/src/components/BaseComponent.js +70 -0
- package/src/components/accordion/Accordion.js +133 -0
- package/src/components/accordion/AccordionItem.js +119 -0
- package/src/components/accordion/index.js +7 -0
- package/src/components/alert/Alert.js +155 -0
- package/src/components/alert/index.js +6 -0
- package/src/components/avatar/Avatar.js +178 -0
- package/src/components/avatar/index.js +5 -0
- package/src/components/badge/Badge.js +103 -0
- package/src/components/badge/index.js +6 -0
- package/src/components/breadcrumb/BreadCrumb.js +70 -0
- package/src/components/breadcrumb/index.js +5 -0
- package/src/components/button/Button.js +174 -0
- package/src/components/button/index.js +5 -0
- package/src/components/card/Card.js +110 -0
- package/src/components/card/index.js +5 -0
- package/src/components/context-menu/ContextMenu.js +60 -0
- package/src/components/context-menu/ContextMenuGroup.js +16 -0
- package/src/components/context-menu/ContextMenuItem.js +16 -0
- package/src/components/context-menu/index.js +10 -0
- package/src/components/divider/Divider.js +126 -0
- package/src/components/divider/index.js +6 -0
- package/src/components/dropdown/Dropdown.js +170 -0
- package/src/components/dropdown/DropdownDivider.js +24 -0
- package/src/components/dropdown/DropdownGroup.js +44 -0
- package/src/components/dropdown/DropdownItem.js +71 -0
- package/src/components/dropdown/DropdownTrigger.js +64 -0
- package/src/components/dropdown/index.js +13 -0
- package/src/components/{fom-control → form}/FormControl.js +30 -22
- package/src/components/{fom-control → form}/field/DefaultRender.js +2 -16
- package/src/components/{fom-control → form}/field/Field.js +67 -140
- package/src/components/{fom-control → form}/field/FieldCollection.js +42 -22
- package/src/components/{fom-control → form}/field/types/AutocompleteField.js +11 -0
- package/src/components/form/field/types/CheckboxField.js +36 -0
- package/src/components/{fom-control → form}/field/types/CheckboxGroupField.js +10 -0
- package/src/components/{fom-control → form}/field/types/ColorField.js +11 -1
- package/src/components/{fom-control → form}/field/types/DateField.js +11 -1
- package/src/components/{fom-control → form}/field/types/EmailField.js +11 -1
- package/src/components/{fom-control → form}/field/types/FileField.js +11 -1
- package/src/components/form/field/types/HiddenField.js +18 -0
- package/src/components/{fom-control → form}/field/types/ImageField.js +11 -1
- package/src/components/{fom-control → form}/field/types/NumberField.js +11 -1
- package/src/components/{fom-control → form}/field/types/PasswordField.js +11 -1
- package/src/components/{fom-control → form}/field/types/RadioField.js +28 -2
- package/src/components/{fom-control → form}/field/types/RangeField.js +10 -0
- package/src/components/{fom-control → form}/field/types/SearchField.js +10 -0
- package/src/components/{fom-control → form}/field/types/SelectField.js +10 -0
- package/src/components/{fom-control → form}/field/types/StringField.js +11 -1
- package/src/components/{fom-control → form}/field/types/TelField.js +11 -2
- package/src/components/{fom-control → form}/field/types/TextAreaField.js +10 -0
- package/src/components/{fom-control → form}/field/types/TimeField.js +11 -2
- package/src/components/{fom-control → form}/field/types/UrlField.js +10 -2
- package/src/components/form/index.js +49 -0
- package/src/components/{fom-control → form}/validation/Validation.js +1 -1
- package/src/components/list/List.js +106 -0
- package/src/components/list/ListGroup.js +67 -0
- package/src/components/list/ListItem.js +103 -0
- package/src/components/list/index.js +10 -0
- package/src/components/menu/Menu.js +82 -0
- package/src/components/menu/MenuDivider.js +22 -0
- package/src/components/menu/MenuGroup.js +42 -0
- package/src/components/menu/MenuItem.js +71 -0
- package/src/components/menu/index.js +13 -0
- package/src/components/modal/Modal.js +153 -0
- package/src/components/modal/index.js +5 -0
- package/src/components/pagination/Pagination.js +229 -0
- package/src/components/pagination/index.js +5 -0
- package/src/components/popover/Popover.js +185 -0
- package/src/components/popover/PopoverFooter.js +37 -0
- package/src/components/popover/PopoverHeader.js +43 -0
- package/src/components/popover/index.js +10 -0
- package/src/components/progress/Progress.js +220 -0
- package/src/components/progress/index.js +6 -0
- package/src/components/skeleton/Skeleton.js +98 -0
- package/src/components/skeleton/SkeletonCard.js +0 -0
- package/src/components/skeleton/SkeletonList.js +0 -0
- package/src/components/skeleton/SkeletonParagraph.js +0 -0
- package/src/components/skeleton/SkeletonTable.js +0 -0
- package/src/components/skeleton/index.js +6 -0
- package/src/components/slider/Slider.js +183 -0
- package/src/components/slider/index.js +5 -0
- package/src/components/spinner/Spinner.js +160 -0
- package/src/components/spinner/index.js +5 -0
- package/src/components/splitter/Splitter.js +95 -0
- package/src/components/splitter/SplitterGutter.js +57 -0
- package/src/components/splitter/SplitterPanel.js +82 -0
- package/src/components/splitter/index.js +8 -0
- package/src/components/stepper/Stepper.js +229 -0
- package/src/components/stepper/StepperStep.js +103 -0
- package/src/components/stepper/index.js +8 -0
- package/src/components/switch/Switch.js +99 -0
- package/src/components/switch/index.js +0 -0
- package/src/components/table/ColumnGroup.js +1 -1
- package/src/components/table/DataTable.js +5 -8
- package/src/components/table/SimpleTable.js +36 -32
- package/src/components/tabs/Tabs.js +110 -0
- package/src/components/tabs/index.js +6 -0
- package/src/components/toast/Toast.js +129 -0
- package/src/components/toast/ToastError.js +0 -0
- package/src/components/toast/ToastInfo.js +0 -0
- package/src/components/toast/ToastSuccess.js +0 -0
- package/src/components/toast/ToastWarning.js +0 -0
- package/src/components/toast/index.js +5 -0
- package/src/components/tooltip/Tooltip.js +98 -0
- package/src/components/tooltip/index.js +5 -0
- package/src/components/tooltip/prototypes.js +6 -0
- package/src/core/data/MemoryManager.js +2 -2
- package/src/core/data/Observable.js +1 -1
- package/src/core/data/ObservableArray.js +14 -8
- package/src/core/data/ObservableItem.js +5 -5
- package/src/core/data/observable-helpers/array.js +2 -2
- package/src/core/data/observable-helpers/batch.js +2 -2
- package/src/core/data/observable-helpers/computed.js +6 -6
- package/src/core/data/observable-helpers/object.js +2 -2
- package/src/core/elements/anchor.js +3 -3
- package/src/core/elements/content-formatter.js +1 -1
- package/src/core/elements/control/for-each-array.js +42 -68
- package/src/core/elements/control/for-each.js +7 -7
- package/src/core/elements/control/show-if.js +5 -5
- package/src/core/elements/control/show-when.js +2 -2
- package/src/core/elements/control/switch.js +4 -4
- package/src/core/elements/description-list.js +1 -1
- package/src/core/elements/form.js +1 -1
- package/src/core/elements/html5-semantics.js +1 -1
- package/src/core/elements/img.js +3 -3
- package/src/core/elements/index.js +1 -1
- package/src/core/elements/interactive.js +1 -1
- package/src/core/elements/list.js +1 -1
- package/src/core/elements/medias.js +1 -1
- package/src/core/elements/meta-data.js +1 -1
- package/src/core/elements/table.js +1 -1
- package/src/core/utils/EventEmitter.js +1 -1
- package/src/core/utils/args-types.js +2 -2
- package/src/core/utils/events.js +68 -0
- package/src/core/utils/filters/standard.js +1 -1
- package/src/core/utils/filters/utils.js +1 -1
- package/src/core/utils/helpers.js +10 -7
- package/src/core/utils/prototypes.js +2 -2
- package/src/core/utils/validator.js +6 -5
- package/src/core/wrappers/AttributesWrapper.js +22 -23
- package/src/core/wrappers/DocumentObserver.js +1 -1
- package/src/core/wrappers/ElementCreator.js +9 -14
- package/src/core/wrappers/HtmlElementWrapper.js +2 -2
- package/src/core/wrappers/NDElement.js +3 -3
- package/src/core/wrappers/NdPrototype.js +24 -31
- package/src/core/wrappers/SingletonView.js +1 -1
- package/src/core/wrappers/TemplateCloner.js +60 -18
- package/src/core/wrappers/constants.js +32 -1
- package/src/core/wrappers/prototypes/attributes-extensions.js +17 -36
- package/src/core/wrappers/prototypes/bind-class-extensions.js +18 -0
- package/src/core/wrappers/prototypes/nd-element-extensions.js +6 -6
- package/src/devtools/app/App.js +2 -2
- package/src/devtools/hrm/ComponentRegistry.js +2 -2
- package/src/devtools/plugin.js +1 -1
- package/src/devtools/widget/DevToolsWidget.js +2 -2
- 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 +1 -1
- package/src/router/link.js +3 -3
- package/src/router/modes/HistoryRouter.js +1 -2
- package/types/filters/dates.d.ts +1 -1
- package/types/filters/standard.d.ts +0 -1
- package/types/filters/types.d.ts +1 -1
- package/utils.js +3 -3
- package/src/components/fom-control/default/DefaultLayout.js +0 -8
- package/src/components/fom-control/default/collection/DefaultCollectionLayout.js +0 -12
- package/src/components/fom-control/default/collection/DefaultCollectionTemplate.js +0 -6
- package/src/components/fom-control/field/types/CheckboxField.js +0 -17
- package/src/components/fom-control/field/types/HiddenField.js +0 -8
- package/src/components/fom-control/index.js +0 -8
- /package/src/components/{fom-control → form}/field/FieldFactory.js +0 -0
- /package/src/components/{fom-control → form}/merge +0 -0
- /package/src/components/{fom-control → form}/utils.js +0 -0
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import BaseComponent from "@components/BaseComponent";
|
|
2
|
+
import EventEmitter from "@src/core/utils/EventEmitter";
|
|
3
|
+
|
|
4
|
+
export default function Toast(message, config = {}) {
|
|
5
|
+
if (!(this instanceof Toast)) {
|
|
6
|
+
return new Toast(message, config);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
this.$description = {
|
|
10
|
+
type: null,
|
|
11
|
+
title: null,
|
|
12
|
+
content: null,
|
|
13
|
+
icon: null,
|
|
14
|
+
showIcon: true,
|
|
15
|
+
duration: 3000,
|
|
16
|
+
closable: true,
|
|
17
|
+
pauseOnHover: true,
|
|
18
|
+
position: 'top-right',
|
|
19
|
+
actions: [],
|
|
20
|
+
render: null,
|
|
21
|
+
...config
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
BaseComponent.extends(Toast, EventEmitter);
|
|
26
|
+
|
|
27
|
+
Toast.use = function(template) {};
|
|
28
|
+
Toast.defaultTemplate = null;
|
|
29
|
+
|
|
30
|
+
// Types
|
|
31
|
+
Toast.prototype.type = function(type) {
|
|
32
|
+
this.$description.type = type;
|
|
33
|
+
return this;
|
|
34
|
+
};
|
|
35
|
+
Toast.prototype.info = function() {
|
|
36
|
+
return this.type('info');
|
|
37
|
+
};
|
|
38
|
+
Toast.prototype.success = function() {
|
|
39
|
+
return this.type('success');
|
|
40
|
+
};
|
|
41
|
+
Toast.prototype.warning = function() {
|
|
42
|
+
return this.type('warning');
|
|
43
|
+
};
|
|
44
|
+
Toast.prototype.error = function() {
|
|
45
|
+
return this.type('error');
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
Toast.prototype.title = function(title) {
|
|
50
|
+
this.$description.title = title;
|
|
51
|
+
return this;
|
|
52
|
+
};
|
|
53
|
+
Toast.prototype.content = function(content) {
|
|
54
|
+
this.$description.content = content;
|
|
55
|
+
return this;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
Toast.prototype.icon = function(icon) {
|
|
59
|
+
this.$description.icon = icon;
|
|
60
|
+
return this;
|
|
61
|
+
};
|
|
62
|
+
Toast.prototype.showIcon = function(show = true) {
|
|
63
|
+
this.$description.showIcon = show;
|
|
64
|
+
return this;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
// Behavior
|
|
68
|
+
Toast.prototype.duration = function(ms) {
|
|
69
|
+
this.$description.duration = ms;
|
|
70
|
+
return this;
|
|
71
|
+
};
|
|
72
|
+
Toast.prototype.closable = function(closable = true) {
|
|
73
|
+
this.$description.closable = closable;
|
|
74
|
+
return this;
|
|
75
|
+
};
|
|
76
|
+
Toast.prototype.pauseOnHover = function(pauseOnHover = true) {
|
|
77
|
+
this.$description.pauseOnHover = pauseOnHover;
|
|
78
|
+
return this;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
// Position
|
|
82
|
+
Toast.prototype.position = function(position) {
|
|
83
|
+
this.$description.position = position;
|
|
84
|
+
return this;
|
|
85
|
+
};
|
|
86
|
+
Toast.prototype.atTopStart = function() {
|
|
87
|
+
return this.position('top-start');
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
Toast.prototype.atTopEnd = function() {
|
|
91
|
+
return this.position('top-end');
|
|
92
|
+
};
|
|
93
|
+
Toast.prototype.atBottomStart = function() {
|
|
94
|
+
return this.position('bottom-start');
|
|
95
|
+
};
|
|
96
|
+
Toast.prototype.atBottomEnd = function() {
|
|
97
|
+
return this.position('bottom-end');
|
|
98
|
+
};
|
|
99
|
+
Toast.prototype.atTopCenter = function() {
|
|
100
|
+
return this.position('top-center');
|
|
101
|
+
};
|
|
102
|
+
Toast.prototype.atBottomCenter = function() {
|
|
103
|
+
return this.position('bottom-center');
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
Toast.prototype.clearActions = function() {
|
|
107
|
+
this.$description.actions = [];
|
|
108
|
+
return this;
|
|
109
|
+
};
|
|
110
|
+
Toast.prototype.action = function(label, handler) {
|
|
111
|
+
this.$description.actions.push({ label, handler });
|
|
112
|
+
return this;
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
Toast.prototype.close = function() {};
|
|
116
|
+
Toast.prototype.onClose = function(handler) {
|
|
117
|
+
this.on('close', handler);
|
|
118
|
+
return this;
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
Toast.prototype.render = function(renderFn) {
|
|
122
|
+
this.$description.render = renderFn;
|
|
123
|
+
return this;
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
Toast.prototype.$build = function() {
|
|
127
|
+
|
|
128
|
+
};
|
|
129
|
+
Toast.prototype.toNdElement = function() {};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tooltip - Interface
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export default function Tooltip(target, content, config = {}) {
|
|
6
|
+
if (!(this instanceof Tooltip)) {
|
|
7
|
+
return new Tooltip(target, content, config);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
this.$description = {
|
|
11
|
+
title: null,
|
|
12
|
+
content: null,
|
|
13
|
+
position: 'top',
|
|
14
|
+
trigger: 'hover',
|
|
15
|
+
target: target,
|
|
16
|
+
hideDelay: 0,
|
|
17
|
+
arrow: true,
|
|
18
|
+
interactive: true,
|
|
19
|
+
variant: null,
|
|
20
|
+
...config,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
Tooltip.use = function(template) {};
|
|
25
|
+
Tooltip.defaultTemplate = null;
|
|
26
|
+
|
|
27
|
+
Tooltip.prototype.title = function(title) {
|
|
28
|
+
this.$description.title = title;
|
|
29
|
+
return this;
|
|
30
|
+
};
|
|
31
|
+
Tooltip.prototype.content = function(content) {
|
|
32
|
+
this.$description.content = content;
|
|
33
|
+
return this;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
Tooltip.prototype.position = function(position) {
|
|
37
|
+
this.$description.position = position;
|
|
38
|
+
return this;
|
|
39
|
+
};
|
|
40
|
+
Tooltip.prototype.top = function() {
|
|
41
|
+
return this.position('top');
|
|
42
|
+
};
|
|
43
|
+
Tooltip.prototype.bottom = function() {
|
|
44
|
+
return this.position('bottom');
|
|
45
|
+
};
|
|
46
|
+
Tooltip.prototype.left = function() {
|
|
47
|
+
return this.position('left');
|
|
48
|
+
};
|
|
49
|
+
Tooltip.prototype.right = function() {
|
|
50
|
+
return this.position('right');
|
|
51
|
+
};
|
|
52
|
+
Tooltip.prototype.auto = function() {
|
|
53
|
+
return this.position('auto');
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
Tooltip.prototype.trigger = function(trigger, target = null) {
|
|
57
|
+
this.$description.trigger = trigger;
|
|
58
|
+
this.$description.target = target;
|
|
59
|
+
return this;
|
|
60
|
+
};
|
|
61
|
+
Tooltip.prototype.showOnHover = function(target = null) {
|
|
62
|
+
return this.trigger('hover', target);
|
|
63
|
+
};
|
|
64
|
+
Tooltip.prototype.showOnClick = function(target = null) {
|
|
65
|
+
return this.trigger('click', target);
|
|
66
|
+
};
|
|
67
|
+
Tooltip.prototype.showOnFocus = function(target = null) {
|
|
68
|
+
return this.trigger('focus', target);
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
Tooltip.prototype.hideDelay = function(ms) {
|
|
72
|
+
this.$description.hideDelay = ms;
|
|
73
|
+
return this;
|
|
74
|
+
};
|
|
75
|
+
Tooltip.prototype.arrow = function(enabled = true) {
|
|
76
|
+
this.$description.arrow = enabled;
|
|
77
|
+
return this;
|
|
78
|
+
};
|
|
79
|
+
Tooltip.prototype.interactive = function(isInteractive = true) {
|
|
80
|
+
this.$description.interactive = isInteractive;
|
|
81
|
+
return this;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
Tooltip.prototype.variant = function(variant) {
|
|
85
|
+
this.$description.variant = variant;
|
|
86
|
+
return this;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
Tooltip.prototype.show = function() {};
|
|
90
|
+
Tooltip.prototype.hide = function() {};
|
|
91
|
+
|
|
92
|
+
Tooltip.prototype.render = function(renderFn) {
|
|
93
|
+
this.$description.render = renderFn;
|
|
94
|
+
return this;
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
Tooltip.prototype.$build = function() {};
|
|
98
|
+
Tooltip.prototype.toNdElement = function() {};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {match} from "
|
|
2
|
-
import Validator from "
|
|
1
|
+
import {match} from "@src/core/utils/filters";
|
|
2
|
+
import Validator from "@src/core/utils/validator";
|
|
3
3
|
import ObservableItem from "./ObservableItem.js";
|
|
4
4
|
import {Observable} from "./Observable.js";
|
|
5
|
-
import PluginsManager from "
|
|
6
|
-
import NativeDocumentError from "
|
|
5
|
+
import PluginsManager from "@src/core/utils/plugins-manager.js";
|
|
6
|
+
import NativeDocumentError from "@src/core/errors/NativeDocumentError.js";
|
|
7
7
|
|
|
8
8
|
const mutationMethods = ['push', 'pop', 'shift', 'unshift', 'reverse', 'sort', 'splice'];
|
|
9
9
|
const noMutationMethods = ['map', 'forEach', 'filter', 'reduce', 'some', 'every', 'find', 'findIndex', 'concat', 'includes', 'indexOf'];
|
|
@@ -28,6 +28,13 @@ ObservableArray.prototype = Object.create(ObservableItem.prototype);
|
|
|
28
28
|
ObservableArray.prototype.constructor = ObservableArray;
|
|
29
29
|
ObservableArray.prototype.__$isObservableArray = true;
|
|
30
30
|
|
|
31
|
+
|
|
32
|
+
Object.defineProperty(ObservableArray.prototype, 'length', {
|
|
33
|
+
get() {
|
|
34
|
+
return this.$currentValue.length;
|
|
35
|
+
}
|
|
36
|
+
})
|
|
37
|
+
|
|
31
38
|
mutationMethods.forEach((method) => {
|
|
32
39
|
ObservableArray.prototype[method] = function(...values) {
|
|
33
40
|
const result = this.$currentValue[method](...values);
|
|
@@ -43,6 +50,9 @@ noMutationMethods.forEach((method) => {
|
|
|
43
50
|
});
|
|
44
51
|
|
|
45
52
|
ObservableArray.prototype.clear = function() {
|
|
53
|
+
if(this.$currentValue.length === 0) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
46
56
|
this.$currentValue.length = 0;
|
|
47
57
|
this.trigger({ action: 'clear' });
|
|
48
58
|
return true;
|
|
@@ -72,10 +82,6 @@ ObservableArray.prototype.count = function(condition) {
|
|
|
72
82
|
return count;
|
|
73
83
|
};
|
|
74
84
|
|
|
75
|
-
ObservableArray.prototype.length = function() {
|
|
76
|
-
return this.$currentValue.length;
|
|
77
|
-
};
|
|
78
|
-
|
|
79
85
|
ObservableArray.prototype.swap = function(indexA, indexB) {
|
|
80
86
|
const value = this.$currentValue;
|
|
81
87
|
const length = value.length;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import DebugManager from "
|
|
1
|
+
import DebugManager from "@src/core/utils/debug-manager";
|
|
2
2
|
import MemoryManager from "./MemoryManager";
|
|
3
|
-
import NativeDocumentError from "
|
|
3
|
+
import NativeDocumentError from "@src/core/errors/NativeDocumentError";
|
|
4
4
|
import ObservableChecker from "./ObservableChecker";
|
|
5
|
-
import PluginsManager from "
|
|
6
|
-
import Validator from "
|
|
5
|
+
import PluginsManager from "@src/core/utils/plugins-manager";
|
|
6
|
+
import Validator from "@src/core/utils/validator";
|
|
7
7
|
import {ObservableWhen} from "./ObservableWhen";
|
|
8
|
-
import {deepClone} from "
|
|
8
|
+
import {deepClone} from "@src/core/utils/helpers.js";
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
*
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import ObservableItem from "
|
|
2
|
-
import Validator from "
|
|
3
|
-
import NativeDocumentError from "
|
|
4
|
-
import {Observable} from "
|
|
5
|
-
import PluginsManager from "
|
|
6
|
-
import {nextTick} from "
|
|
1
|
+
import ObservableItem from "@src/core/data/ObservableItem";
|
|
2
|
+
import Validator from "@src/core/utils/validator";
|
|
3
|
+
import NativeDocumentError from "@src/core/errors/NativeDocumentError";
|
|
4
|
+
import {Observable} from "@src/core/data/Observable";
|
|
5
|
+
import PluginsManager from "@src/core/utils/plugins-manager";
|
|
6
|
+
import {nextTick} from "@src/core/utils/helpers";
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
*
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import Validator from "
|
|
2
|
-
import {Observable} from "
|
|
1
|
+
import Validator from "@src/core/utils/validator";
|
|
2
|
+
import {Observable} from "@src/core/data/Observable";
|
|
3
3
|
|
|
4
4
|
const ObservableObjectValue = function(data) {
|
|
5
5
|
const result = {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import Validator from "
|
|
2
|
-
import DebugManager from "
|
|
3
|
-
import {ElementCreator} from "
|
|
1
|
+
import Validator from "@src/core/utils/validator";
|
|
2
|
+
import DebugManager from "@src/core/utils/debug-manager";
|
|
3
|
+
import {ElementCreator} from "@src/core/wrappers/ElementCreator";
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
export default function Anchor(name, isUniqueChild = false) {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import Anchor from "
|
|
2
|
-
import {Observable} from "
|
|
3
|
-
import Validator from "
|
|
4
|
-
import {getKey} from "
|
|
5
|
-
import { ElementCreator } from "
|
|
6
|
-
import NativeDocumentError from "
|
|
1
|
+
import Anchor from "@src/core/elements/anchor";
|
|
2
|
+
import {Observable} from "@src/core/data/Observable";
|
|
3
|
+
import Validator from "@src/core/utils/validator";
|
|
4
|
+
import {getKey} from "@src/core/utils/helpers";
|
|
5
|
+
import { ElementCreator } from "@src/core/wrappers/ElementCreator";
|
|
6
|
+
import NativeDocumentError from "@src/core/errors/NativeDocumentError";
|
|
7
7
|
|
|
8
|
-
export function ForEachArray(data, callback,
|
|
8
|
+
export function ForEachArray(data, callback, configs = {}) {
|
|
9
9
|
const element = Anchor('ForEach Array');
|
|
10
10
|
const blockEnd = element.endElement();
|
|
11
11
|
const blockStart = element.startElement();
|
|
@@ -14,23 +14,14 @@ export function ForEachArray(data, callback, key, configs = {}) {
|
|
|
14
14
|
let lastNumberOfItems = 0;
|
|
15
15
|
const isIndexRequired = callback.length >= 2;
|
|
16
16
|
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
const clear = () => {
|
|
17
|
+
const clear = (items) => {
|
|
20
18
|
element.removeChildren();
|
|
21
|
-
cleanCache();
|
|
19
|
+
cleanCache(items);
|
|
22
20
|
lastNumberOfItems = 0;
|
|
23
21
|
};
|
|
24
22
|
|
|
25
|
-
const getItemKey = (item, indexKey) => {
|
|
26
|
-
if(keysCache.has(item)) {
|
|
27
|
-
return keysCache.get(item);
|
|
28
|
-
}
|
|
29
|
-
return getKey(item, indexKey, key);
|
|
30
|
-
};
|
|
31
|
-
|
|
32
23
|
const getItemChild = (item) => {
|
|
33
|
-
return
|
|
24
|
+
return cache.get(item)?.child;
|
|
34
25
|
};
|
|
35
26
|
|
|
36
27
|
const updateIndexObservers = (items, startFrom = 0) => {
|
|
@@ -39,16 +30,17 @@ export function ForEachArray(data, callback, key, configs = {}) {
|
|
|
39
30
|
}
|
|
40
31
|
let index = startFrom;
|
|
41
32
|
for(let i = startFrom, length = items?.length; i < length; i++) {
|
|
42
|
-
const cacheItem = cache.get(
|
|
33
|
+
const cacheItem = cache.get(items[i]);
|
|
43
34
|
if(!cacheItem) {
|
|
44
35
|
continue;
|
|
45
36
|
}
|
|
46
|
-
cacheItem.indexObserver?.
|
|
37
|
+
cacheItem.indexObserver?.set(index);
|
|
47
38
|
index++;
|
|
48
39
|
}
|
|
49
40
|
};
|
|
50
41
|
|
|
51
|
-
const removeCacheItem = (
|
|
42
|
+
const removeCacheItem = (item, removeChild = true) => {
|
|
43
|
+
const cacheItem = cache.get(item);
|
|
52
44
|
if(!cacheItem) {
|
|
53
45
|
return;
|
|
54
46
|
}
|
|
@@ -57,14 +49,10 @@ export function ForEachArray(data, callback, key, configs = {}) {
|
|
|
57
49
|
child?.remove();
|
|
58
50
|
cache.delete(cacheItem.keyId);
|
|
59
51
|
}
|
|
60
|
-
cacheItem.indexObserver?.
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const removeCacheItemByKey = (keyId, removeChild = true) => {
|
|
64
|
-
removeCacheItem(cache.get(keyId), removeChild);
|
|
52
|
+
cacheItem.indexObserver?.cleanup();
|
|
65
53
|
};
|
|
66
54
|
|
|
67
|
-
const cleanCache = () => {
|
|
55
|
+
const cleanCache = (items) => {
|
|
68
56
|
if(configs.shouldKeepItemsInCache) {
|
|
69
57
|
return;
|
|
70
58
|
}
|
|
@@ -72,53 +60,41 @@ export function ForEachArray(data, callback, key, configs = {}) {
|
|
|
72
60
|
cache.clear();
|
|
73
61
|
return;
|
|
74
62
|
}
|
|
75
|
-
for (const [
|
|
76
|
-
|
|
63
|
+
for (const [itemAsKey, _] of cache.entries()) {
|
|
64
|
+
if(items && items.contains(itemAsKey)) {
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
removeCacheItem(itemAsKey, false);
|
|
77
68
|
}
|
|
78
69
|
cache.clear();
|
|
79
70
|
}
|
|
80
71
|
|
|
81
72
|
const buildItem = (item, indexKey) => {
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
const cacheItem = cache.get(keyId);
|
|
86
|
-
cacheItem.indexObserver?.deref()?.set(indexKey);
|
|
73
|
+
const cacheItem = cache.get(item);
|
|
74
|
+
if(cacheItem) {
|
|
75
|
+
cacheItem.indexObserver?.set(indexKey);
|
|
87
76
|
const child = cacheItem.child;
|
|
88
77
|
if(child) {
|
|
89
78
|
return child;
|
|
90
79
|
}
|
|
91
|
-
cache.delete(
|
|
80
|
+
cache.delete(item);
|
|
92
81
|
}
|
|
93
82
|
|
|
94
83
|
const indexObserver = isIndexRequired ? Observable(indexKey) : null;
|
|
95
84
|
let child = ElementCreator.getChild(callback(item, indexObserver));
|
|
96
|
-
if(
|
|
97
|
-
|
|
85
|
+
if(child) {
|
|
86
|
+
cache.set(item, {
|
|
87
|
+
child,
|
|
88
|
+
indexObserver: (indexObserver ? new WeakRef(indexObserver) : null)
|
|
89
|
+
});
|
|
90
|
+
return child;
|
|
98
91
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
child: child,
|
|
102
|
-
indexObserver: (indexObserver ? new WeakRef(indexObserver) : null)
|
|
103
|
-
});
|
|
104
|
-
keysCache.set(item, keyId);
|
|
105
|
-
return child;
|
|
106
|
-
};
|
|
107
|
-
const getChildByKey = function(keyId) {
|
|
108
|
-
const cacheItem = cache.get(keyId);
|
|
109
|
-
if(!cacheItem) {
|
|
110
|
-
return null;
|
|
111
|
-
}
|
|
112
|
-
const child = cacheItem.child;
|
|
113
|
-
if(!child) {
|
|
114
|
-
removeCacheItem(cacheItem, false);
|
|
115
|
-
return null;
|
|
116
|
-
}
|
|
117
|
-
return child;
|
|
92
|
+
|
|
93
|
+
throw new NativeDocumentError("ForEachArray child can't be null or undefined!");
|
|
118
94
|
};
|
|
119
95
|
|
|
120
|
-
const
|
|
121
|
-
const cacheItem = cache.get(
|
|
96
|
+
const removeByItem = function(item, fragment) {
|
|
97
|
+
const cacheItem = cache.get(item);
|
|
122
98
|
if(!cacheItem) {
|
|
123
99
|
return null;
|
|
124
100
|
}
|
|
@@ -144,11 +120,10 @@ export function ForEachArray(data, callback, key, configs = {}) {
|
|
|
144
120
|
return fragment;
|
|
145
121
|
},
|
|
146
122
|
add(items, delay = 2) {
|
|
147
|
-
|
|
148
|
-
element.appendElement(fragment);
|
|
123
|
+
element.appendElement(Actions.toFragment(items));
|
|
149
124
|
},
|
|
150
125
|
replace(items) {
|
|
151
|
-
clear();
|
|
126
|
+
clear(items);
|
|
152
127
|
Actions.add(items);
|
|
153
128
|
},
|
|
154
129
|
reOrder(items) {
|
|
@@ -164,7 +139,7 @@ export function ForEachArray(data, callback, key, configs = {}) {
|
|
|
164
139
|
element.appendElement(fragment, blockEnd);
|
|
165
140
|
},
|
|
166
141
|
removeOne(element, index) {
|
|
167
|
-
|
|
142
|
+
removeCacheItem(element, true);
|
|
168
143
|
},
|
|
169
144
|
clear,
|
|
170
145
|
merge(items) {
|
|
@@ -198,16 +173,15 @@ export function ForEachArray(data, callback, key, configs = {}) {
|
|
|
198
173
|
const garbageFragment = document.createDocumentFragment();
|
|
199
174
|
|
|
200
175
|
if(deleted.length > 0) {
|
|
201
|
-
let
|
|
176
|
+
let firstItem = deleted[0];
|
|
202
177
|
if(deleted.length === 1) {
|
|
203
|
-
|
|
178
|
+
removeByItem(firstItem, garbageFragment);
|
|
204
179
|
} else if(deleted.length > 1) {
|
|
205
|
-
const firstChildRemoved =
|
|
180
|
+
const firstChildRemoved = getItemChild(deleted[0]);
|
|
206
181
|
elementBeforeFirst = firstChildRemoved?.previousSibling;
|
|
207
182
|
|
|
208
183
|
for(let i = 0; i < deleted.length; i++) {
|
|
209
|
-
|
|
210
|
-
removeByKey(keyId, garbageFragment);
|
|
184
|
+
firstItem(deleted[i], garbageFragment);
|
|
211
185
|
}
|
|
212
186
|
}
|
|
213
187
|
} else {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {Observable} from "
|
|
2
|
-
import Validator from "
|
|
3
|
-
import Anchor from "
|
|
4
|
-
import DebugManager from "
|
|
5
|
-
import {getKey} from "
|
|
6
|
-
import { ElementCreator } from "
|
|
7
|
-
import NativeDocumentError from "
|
|
1
|
+
import {Observable} from "@src/core/data/Observable";
|
|
2
|
+
import Validator from "@src/core/utils/validator";
|
|
3
|
+
import Anchor from "@src/core/elements/anchor";
|
|
4
|
+
import DebugManager from "@src/core/utils/debug-manager";
|
|
5
|
+
import {getKey} from "@src/core/utils/helpers";
|
|
6
|
+
import { ElementCreator } from "@src/core/wrappers/ElementCreator";
|
|
7
|
+
import NativeDocumentError from "@src/core/errors/NativeDocumentError";
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
*
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Observable } from "
|
|
2
|
-
import Validator from "
|
|
3
|
-
import DebugManager from "
|
|
4
|
-
import Anchor from "
|
|
5
|
-
import {ElementCreator} from "
|
|
1
|
+
import { Observable } from "@src/core/data/Observable";
|
|
2
|
+
import Validator from "@src/core/utils/validator";
|
|
3
|
+
import DebugManager from "@src/core/utils/debug-manager.js";
|
|
4
|
+
import Anchor from "@src/core/elements/anchor";
|
|
5
|
+
import {ElementCreator} from "@src/core/wrappers/ElementCreator";
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Show the element if the condition is true
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import Validator from "
|
|
2
|
-
import NativeDocumentError from "
|
|
1
|
+
import Validator from "@src/core/utils/validator.js";
|
|
2
|
+
import NativeDocumentError from "@src/core/errors/NativeDocumentError.js";
|
|
3
3
|
import {ShowIf} from "./show-if.js";
|
|
4
4
|
|
|
5
5
|
export const ShowWhen = function() {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import NativeDocumentError from "
|
|
2
|
-
import Validator from "
|
|
3
|
-
import Anchor from "
|
|
4
|
-
import {ElementCreator} from "
|
|
1
|
+
import NativeDocumentError from "@src/core/errors/NativeDocumentError";
|
|
2
|
+
import Validator from "@src/core/utils/validator";
|
|
3
|
+
import Anchor from "@src/core/elements/anchor";
|
|
4
|
+
import {ElementCreator} from "@src/core/wrappers/ElementCreator";
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|