native-document 1.0.76 → 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 +6360 -1925
- package/dist/native-document.dev.js +122 -56
- 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 +1 -1
- 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 +21 -38
- 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 +18 -5
- 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
package/src/core/elements/img.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import HtmlElementWrapper from "
|
|
2
|
-
import Validator from "
|
|
3
|
-
import NativeDocumentError from "
|
|
1
|
+
import HtmlElementWrapper from "@src/core/wrappers/HtmlElementWrapper"
|
|
2
|
+
import Validator from "@src/core/utils/validator";
|
|
3
|
+
import NativeDocumentError from "@src/core/errors/NativeDocumentError";
|
|
4
4
|
|
|
5
5
|
export const BaseImage = HtmlElementWrapper('img');
|
|
6
6
|
export const Img = function(src, attributes) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import Validator from "./validator";
|
|
2
|
-
import ArgTypesError from "
|
|
3
|
-
import NativeDocumentError from "
|
|
2
|
+
import ArgTypesError from "@src/core/errors/ArgTypesError";
|
|
3
|
+
import NativeDocumentError from "@src/core/errors/NativeDocumentError";
|
|
4
4
|
|
|
5
5
|
let withValidation = (fn) => fn;
|
|
6
6
|
let ArgTypes = {};
|
package/src/core/utils/events.js
CHANGED
|
@@ -63,6 +63,74 @@ export const EVENTS = [
|
|
|
63
63
|
"VolumeChange",
|
|
64
64
|
"Waiting",
|
|
65
65
|
|
|
66
|
+
"TouchCancel",
|
|
67
|
+
"TouchEnd",
|
|
68
|
+
"TouchMove",
|
|
69
|
+
"TouchStart",
|
|
70
|
+
"AnimationEnd",
|
|
71
|
+
"AnimationIteration",
|
|
72
|
+
"AnimationStart",
|
|
73
|
+
"TransitionEnd",
|
|
74
|
+
"Copy",
|
|
75
|
+
"Cut",
|
|
76
|
+
"Paste",
|
|
77
|
+
"FocusIn",
|
|
78
|
+
"FocusOut",
|
|
79
|
+
"ContextMenu"
|
|
80
|
+
];
|
|
81
|
+
|
|
82
|
+
export const EVENTS_WITH_PREVENT = [
|
|
83
|
+
"Click",
|
|
84
|
+
"DblClick",
|
|
85
|
+
"MouseDown",
|
|
86
|
+
"MouseUp",
|
|
87
|
+
"Wheel",
|
|
88
|
+
"KeyDown",
|
|
89
|
+
"KeyPress",
|
|
90
|
+
"Invalid",
|
|
91
|
+
"Reset",
|
|
92
|
+
"Submit",
|
|
93
|
+
"DragOver",
|
|
94
|
+
"Drop",
|
|
95
|
+
"BeforeUnload",
|
|
96
|
+
"TouchCancel",
|
|
97
|
+
"TouchEnd",
|
|
98
|
+
"TouchMove",
|
|
99
|
+
"TouchStart",
|
|
100
|
+
"Copy",
|
|
101
|
+
"Cut",
|
|
102
|
+
"Paste",
|
|
103
|
+
"ContextMenu"
|
|
104
|
+
];
|
|
105
|
+
|
|
106
|
+
export const EVENTS_WITH_STOP = [
|
|
107
|
+
"Click",
|
|
108
|
+
"DblClick",
|
|
109
|
+
"MouseDown",
|
|
110
|
+
"MouseMove",
|
|
111
|
+
"MouseOut",
|
|
112
|
+
"MouseOver",
|
|
113
|
+
"MouseUp",
|
|
114
|
+
"Wheel",
|
|
115
|
+
"KeyDown",
|
|
116
|
+
"KeyPress",
|
|
117
|
+
"KeyUp",
|
|
118
|
+
"Change",
|
|
119
|
+
"Input",
|
|
120
|
+
"Invalid",
|
|
121
|
+
"Reset",
|
|
122
|
+
"Search",
|
|
123
|
+
"Select",
|
|
124
|
+
"Submit",
|
|
125
|
+
"Drag",
|
|
126
|
+
"DragEnd",
|
|
127
|
+
"DragEnter",
|
|
128
|
+
"DragLeave",
|
|
129
|
+
"DragOver",
|
|
130
|
+
"DragStart",
|
|
131
|
+
"Drop",
|
|
132
|
+
"BeforeUnload",
|
|
133
|
+
"HashChange",
|
|
66
134
|
"TouchCancel",
|
|
67
135
|
"TouchEnd",
|
|
68
136
|
"TouchMove",
|
|
@@ -56,15 +56,18 @@ export const nextTick = function(fn) {
|
|
|
56
56
|
* @returns {*}
|
|
57
57
|
*/
|
|
58
58
|
export const getKey = (item, defaultKey, key) => {
|
|
59
|
-
if(Validator.
|
|
60
|
-
|
|
61
|
-
const
|
|
62
|
-
return (
|
|
59
|
+
if (Validator.isString(key)) {
|
|
60
|
+
const val = Validator.isObservable(item) ? item.val() : item;
|
|
61
|
+
const result = val?.[key];
|
|
62
|
+
return Validator.isObservable(result) ? result.val() : (result ?? defaultKey);
|
|
63
63
|
}
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
|
|
65
|
+
if (Validator.isFunction(key)) {
|
|
66
|
+
return key(item, defaultKey);
|
|
66
67
|
}
|
|
67
|
-
|
|
68
|
+
|
|
69
|
+
const val = Validator.isObservable(item) ? item.val() : item;
|
|
70
|
+
return val ?? defaultKey;
|
|
68
71
|
};
|
|
69
72
|
|
|
70
73
|
export const trim = function(str, char) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {withValidation} from "./args-types.js";
|
|
2
|
-
import {Observable} from "
|
|
2
|
+
import {Observable} from "@src/core/data/Observable";
|
|
3
3
|
import Validator from "./validator";
|
|
4
|
-
import {NDElement} from "
|
|
4
|
+
import {NDElement} from "@src/core/wrappers/NDElement";
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
Function.prototype.args = function(...args) {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import ObservableItem from "
|
|
1
|
+
import ObservableItem from "@src/core/data/ObservableItem";
|
|
2
2
|
import DebugManager from "./debug-manager";
|
|
3
|
-
import NativeDocumentError from "
|
|
4
|
-
import ObservableChecker from "
|
|
5
|
-
import {NDElement} from "
|
|
6
|
-
import TemplateBinding from "
|
|
3
|
+
import NativeDocumentError from "@src/core/errors/NativeDocumentError";
|
|
4
|
+
import ObservableChecker from "@src/core/data/ObservableChecker";
|
|
5
|
+
import {NDElement} from "@src/core/wrappers/NDElement";
|
|
6
|
+
import TemplateBinding from "@src/core/wrappers/TemplateBinding";
|
|
7
7
|
|
|
8
8
|
const COMMON_NODE_TYPES = {
|
|
9
9
|
ELEMENT: 1,
|
|
@@ -139,6 +139,7 @@ const Validator = {
|
|
|
139
139
|
};
|
|
140
140
|
if(process.env.NODE_ENV === 'development') {
|
|
141
141
|
Validator.validateAttributes = function(attributes) {
|
|
142
|
+
console.log('AttributesWrapper', attributes);
|
|
142
143
|
if (!attributes || typeof attributes !== 'object') {
|
|
143
144
|
return attributes;
|
|
144
145
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import Validator from "
|
|
2
|
-
import NativeDocumentError from "
|
|
1
|
+
import Validator from "@src/core/utils/validator";
|
|
2
|
+
import NativeDocumentError from "@src/core/errors/NativeDocumentError";
|
|
3
3
|
import {BOOLEAN_ATTRIBUTES} from "./constants.js";
|
|
4
|
-
import {Observable} from "
|
|
4
|
+
import {Observable} from "@src/core/data/Observable";
|
|
5
|
+
import './prototypes/bind-class-extensions';
|
|
5
6
|
|
|
6
7
|
|
|
7
8
|
export function toggleElementClass(element, className, shouldAdd) {
|
|
@@ -36,18 +37,8 @@ export function updateObserverFromInput(element, attributeName, defaultValue, va
|
|
|
36
37
|
export function bindClassAttribute(element, data) {
|
|
37
38
|
for(let className in data) {
|
|
38
39
|
const value = data[className];
|
|
39
|
-
if(
|
|
40
|
-
|
|
41
|
-
value.subscribe(toggleElementClass.bind(null, element, className));
|
|
42
|
-
continue;
|
|
43
|
-
}
|
|
44
|
-
if(Validator.isObservableWhenResult(value)) {
|
|
45
|
-
element.classes.toggle(className, value.isMath());
|
|
46
|
-
value.subscribe(toggleElementClass.bind(null, element, className));
|
|
47
|
-
continue;
|
|
48
|
-
}
|
|
49
|
-
if(value.$hydrate) {
|
|
50
|
-
value.$hydrate(element, className);
|
|
40
|
+
if(value?.bindNdClass) {
|
|
41
|
+
value.bindNdClass(element, className);
|
|
51
42
|
continue;
|
|
52
43
|
}
|
|
53
44
|
element.classes.toggle(className, value)
|
|
@@ -117,6 +108,12 @@ export function bindAttributeWithObservable(element, attributeName, value) {
|
|
|
117
108
|
}
|
|
118
109
|
}
|
|
119
110
|
|
|
111
|
+
const NdBindings = {
|
|
112
|
+
class: (element, value) => bindClassAttribute(element, value),
|
|
113
|
+
style: (element, value) => bindStyleAttribute(element, value),
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
|
|
120
117
|
/**
|
|
121
118
|
*
|
|
122
119
|
* @param {HTMLElement} element
|
|
@@ -132,41 +129,27 @@ export default function AttributesWrapper(element, attributes) {
|
|
|
132
129
|
|
|
133
130
|
for(let key in attributes) {
|
|
134
131
|
const attributeName = key.toLowerCase();
|
|
135
|
-
let value = attributes[
|
|
136
|
-
if(value
|
|
132
|
+
let value = attributes[key];
|
|
133
|
+
if(value == null) {
|
|
137
134
|
continue;
|
|
138
135
|
}
|
|
139
136
|
if(value.handleNdAttribute) {
|
|
140
137
|
value.handleNdAttribute(element, attributeName, value)
|
|
141
138
|
continue;
|
|
142
139
|
}
|
|
143
|
-
if(
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
continue;
|
|
150
|
-
}
|
|
151
|
-
if(attributeName === 'style' && Validator.isObject(value)) {
|
|
152
|
-
bindStyleAttribute(element, value);
|
|
153
|
-
continue;
|
|
140
|
+
if(typeof value === 'object') {
|
|
141
|
+
const binding = NdBindings[attributeName];
|
|
142
|
+
if(binding) {
|
|
143
|
+
binding(element, value);
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
154
146
|
}
|
|
155
|
-
if(BOOLEAN_ATTRIBUTES.
|
|
147
|
+
if(BOOLEAN_ATTRIBUTES.has(attributeName)) {
|
|
156
148
|
bindBooleanAttribute(element, attributeName, value);
|
|
157
149
|
continue;
|
|
158
150
|
}
|
|
159
|
-
if(Validator.isObservable(value)) {
|
|
160
|
-
bindAttributeWithObservable(element, attributeName, value);
|
|
161
|
-
continue;
|
|
162
|
-
}
|
|
163
|
-
if(value.$hydrate) {
|
|
164
|
-
value.$hydrate(element, attributeName);
|
|
165
|
-
continue;
|
|
166
|
-
}
|
|
167
151
|
|
|
168
152
|
element.setAttribute(attributeName, value);
|
|
169
|
-
|
|
170
153
|
}
|
|
171
154
|
return element;
|
|
172
155
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import Anchor from "
|
|
2
|
-
import Validator from "
|
|
1
|
+
import Anchor from "@src/core/elements/anchor";
|
|
2
|
+
import Validator from "@src/core/utils/validator";
|
|
3
3
|
import AttributesWrapper from "./AttributesWrapper";
|
|
4
|
-
import PluginsManager from "
|
|
4
|
+
import PluginsManager from "@src/core/utils/plugins-manager";
|
|
5
5
|
import './prototypes/nd-element-extensions';
|
|
6
6
|
import './prototypes/attributes-extensions';
|
|
7
7
|
|
|
@@ -83,19 +83,14 @@ export const ElementCreator = {
|
|
|
83
83
|
PluginsManager.emit('AfterProcessChildren', parent);
|
|
84
84
|
},
|
|
85
85
|
getChild(child) {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
child = child.toNdElement();
|
|
92
|
-
if(Validator.isElement(child)) {
|
|
93
|
-
return child;
|
|
94
|
-
}
|
|
95
|
-
} while (child.toNdElement);
|
|
86
|
+
while (child?.toNdElement) {
|
|
87
|
+
child = child.toNdElement();
|
|
88
|
+
|
|
89
|
+
if (Validator.isElement(child)) return child;
|
|
90
|
+
if (!child) return null;
|
|
96
91
|
}
|
|
97
92
|
|
|
98
|
-
return ElementCreator.createStaticTextNode(null, child);
|
|
93
|
+
return child ? ElementCreator.createStaticTextNode(null, child) : null;
|
|
99
94
|
},
|
|
100
95
|
/**
|
|
101
96
|
*
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import Validator from "
|
|
1
|
+
import Validator from "@src/core/utils/validator";
|
|
2
2
|
import {ElementCreator} from "./ElementCreator";
|
|
3
3
|
import './NdPrototype';
|
|
4
|
-
import {normalizeComponentArgs} from "
|
|
4
|
+
import {normalizeComponentArgs} from "@src/core/utils/args-types";
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
*
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import DocumentObserver from "./DocumentObserver";
|
|
2
|
-
import PluginsManager from "
|
|
3
|
-
import NativeDocumentError from "
|
|
4
|
-
import DebugManager from "
|
|
2
|
+
import PluginsManager from "@src/core/utils/plugins-manager";
|
|
3
|
+
import NativeDocumentError from "@src/core/errors/NativeDocumentError.js";
|
|
4
|
+
import DebugManager from "@src/core/utils/debug-manager.js";
|
|
5
5
|
|
|
6
6
|
export function NDElement(element) {
|
|
7
7
|
this.$element = element;
|
|
@@ -1,22 +1,17 @@
|
|
|
1
1
|
import { NDElement } from "./NDElement";
|
|
2
|
-
import {EVENTS} from "
|
|
2
|
+
import {EVENTS, EVENTS_WITH_PREVENT, EVENTS_WITH_STOP} from "@src/core/utils/events";
|
|
3
3
|
|
|
4
|
-
let createNdElementInstance = (target) => {
|
|
5
|
-
attachEventPrototypes && attachEventPrototypes();
|
|
6
|
-
attachEventPrototypes = null;
|
|
7
|
-
createNdElementInstance = (target) => new NDElement(target);
|
|
8
|
-
return new NDElement(target);
|
|
9
|
-
};
|
|
10
4
|
const property = {
|
|
11
5
|
configurable: true,
|
|
12
6
|
get() {
|
|
13
|
-
return
|
|
7
|
+
return new NDElement(this);
|
|
14
8
|
}
|
|
15
9
|
};
|
|
16
10
|
|
|
17
11
|
Object.defineProperty(HTMLElement.prototype, 'nd', property);
|
|
18
12
|
|
|
19
13
|
Object.defineProperty(DocumentFragment.prototype, 'nd', property);
|
|
14
|
+
|
|
20
15
|
Object.defineProperty(NDElement.prototype, 'nd', {
|
|
21
16
|
configurable: true,
|
|
22
17
|
get: function() {
|
|
@@ -29,31 +24,29 @@ Object.defineProperty(NDElement.prototype, 'nd', {
|
|
|
29
24
|
// ----------------------------------------------------------------
|
|
30
25
|
// Events helpers
|
|
31
26
|
// ----------------------------------------------------------------
|
|
27
|
+
EVENTS.forEach(eventSourceName => {
|
|
28
|
+
const eventName = eventSourceName.toLowerCase();
|
|
29
|
+
NDElement.prototype['on'+eventSourceName] = function(callback = null) {
|
|
30
|
+
this.$element.addEventListener(eventName, callback);
|
|
31
|
+
return this;
|
|
32
|
+
};
|
|
33
|
+
})
|
|
32
34
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
NDElement.prototype['onPrevent'+eventSourceName] = function(callback) {
|
|
42
|
-
_prevent(this.$element, eventName, callback);
|
|
43
|
-
return this;
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
NDElement.prototype['onStop'+eventSourceName] = function(callback) {
|
|
47
|
-
_stop(this.$element, eventName, callback);
|
|
48
|
-
return this;
|
|
49
|
-
};
|
|
35
|
+
EVENTS_WITH_STOP.forEach(eventSourceName => {
|
|
36
|
+
const eventName = eventSourceName.toLowerCase();
|
|
37
|
+
NDElement.prototype['onStop'+eventSourceName] = function(callback = null) {
|
|
38
|
+
_stop(this.$element, eventName, callback);
|
|
39
|
+
return this;
|
|
40
|
+
};
|
|
41
|
+
});
|
|
50
42
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
};
|
|
43
|
+
EVENTS_WITH_PREVENT.forEach(eventSourceName => {
|
|
44
|
+
const eventName = eventSourceName.toLowerCase();
|
|
45
|
+
NDElement.prototype['onPrevent'+eventSourceName] = function(callback = null) {
|
|
46
|
+
_prevent(this.$element, eventName, callback);
|
|
47
|
+
return this;
|
|
48
|
+
};
|
|
49
|
+
});
|
|
57
50
|
|
|
58
51
|
NDElement.prototype.on = function(name, callback, options) {
|
|
59
52
|
this.$element.addEventListener(name.toLowerCase(), callback, options);
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import {ElementCreator} from "./ElementCreator";
|
|
2
2
|
import {createTextNode} from "./HtmlElementWrapper";
|
|
3
|
-
import Anchor from "../elements/anchor";
|
|
4
3
|
import TemplateBinding from "./TemplateBinding";
|
|
5
4
|
|
|
6
5
|
const cloneBindingsDataCache = new WeakMap();
|
|
@@ -11,7 +10,7 @@ const bindAttributes = (node, bindDingData, data) => {
|
|
|
11
10
|
if(bindDingData.attributes) {
|
|
12
11
|
attributes = {};
|
|
13
12
|
for (const attr in bindDingData.attributes) {
|
|
14
|
-
attributes[attr] = bindDingData.attributes[attr](
|
|
13
|
+
attributes[attr] = bindDingData.attributes[attr].apply(null, data);
|
|
15
14
|
}
|
|
16
15
|
}
|
|
17
16
|
|
|
@@ -19,7 +18,7 @@ const bindAttributes = (node, bindDingData, data) => {
|
|
|
19
18
|
attributes = attributes || {};
|
|
20
19
|
attributes.class = {};
|
|
21
20
|
for (const className in bindDingData.classes) {
|
|
22
|
-
attributes.class[className] = bindDingData.classes[className](
|
|
21
|
+
attributes.class[className] = bindDingData.classes[className].apply(null, data);
|
|
23
22
|
}
|
|
24
23
|
}
|
|
25
24
|
|
|
@@ -27,7 +26,7 @@ const bindAttributes = (node, bindDingData, data) => {
|
|
|
27
26
|
attributes = attributes || {};
|
|
28
27
|
attributes.style = {};
|
|
29
28
|
for (const property in bindDingData.styles) {
|
|
30
|
-
attributes.style[property] = bindDingData.styles[property](
|
|
29
|
+
attributes.style[property] = bindDingData.styles[property].apply(null, data);
|
|
31
30
|
}
|
|
32
31
|
}
|
|
33
32
|
|
|
@@ -39,6 +38,14 @@ const bindAttributes = (node, bindDingData, data) => {
|
|
|
39
38
|
return null;
|
|
40
39
|
};
|
|
41
40
|
|
|
41
|
+
const findByPath = (root, path) => {
|
|
42
|
+
let target = root;
|
|
43
|
+
for (let i = 0, len = path.length; i < len; i++) {
|
|
44
|
+
target = target.childNodes[path[i]];
|
|
45
|
+
}
|
|
46
|
+
return target;
|
|
47
|
+
};
|
|
48
|
+
|
|
42
49
|
const $hydrateFn = function(hydrateFunction, targetType, element, property) {
|
|
43
50
|
if(!cloneBindingsDataCache.has(element)) {
|
|
44
51
|
// { classes, styles, attributes, value, attach }
|
|
@@ -59,7 +66,7 @@ const bindAttachMethods = function(node, bindDingData, data) {
|
|
|
59
66
|
}
|
|
60
67
|
for(const methodName in bindDingData.attach) {
|
|
61
68
|
node.nd[methodName](function(...args) {
|
|
62
|
-
bindDingData.attach[methodName].
|
|
69
|
+
bindDingData.attach[methodName].apply(this, [...args, ...data]);
|
|
63
70
|
});
|
|
64
71
|
}
|
|
65
72
|
};
|
|
@@ -68,44 +75,78 @@ export function TemplateCloner($fn) {
|
|
|
68
75
|
let $node = null;
|
|
69
76
|
let $hasBindingData = false;
|
|
70
77
|
|
|
71
|
-
const
|
|
78
|
+
const $bindingPaths = [];
|
|
79
|
+
|
|
80
|
+
const clone = (node, data, path) => {
|
|
72
81
|
const bindDingData = cloneBindingsDataCache.get(node);
|
|
73
82
|
if(node.nodeType === 3) {
|
|
74
83
|
if(bindDingData && bindDingData.value) {
|
|
84
|
+
$bindingPaths.push({
|
|
85
|
+
path: [...path],
|
|
86
|
+
fn: (data, targetNode, currentRoot) => {
|
|
87
|
+
const newNode = bindDingData.value(data);
|
|
88
|
+
targetNode.replaceWith(newNode);
|
|
89
|
+
if (targetNode === currentRoot) {
|
|
90
|
+
return newNode;
|
|
91
|
+
}
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
});
|
|
75
95
|
return bindDingData.value(data);
|
|
76
96
|
}
|
|
77
97
|
return node.cloneNode(true);
|
|
78
98
|
}
|
|
79
99
|
const nodeCloned = node.cloneNode(node.fullCloneNode);
|
|
100
|
+
if(node.fullCloneNode) {
|
|
101
|
+
return nodeCloned;
|
|
102
|
+
}
|
|
80
103
|
if(bindDingData) {
|
|
81
104
|
bindAttributes(nodeCloned, bindDingData, data);
|
|
82
105
|
bindAttachMethods(nodeCloned, bindDingData, data);
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
106
|
+
$bindingPaths.push({
|
|
107
|
+
path: [...path],
|
|
108
|
+
fn: (data, targetNode) => {
|
|
109
|
+
bindAttributes(targetNode, bindDingData, data);
|
|
110
|
+
bindAttachMethods(targetNode, bindDingData, data);
|
|
111
|
+
}
|
|
112
|
+
})
|
|
86
113
|
}
|
|
87
114
|
const childNodes = node.childNodes;
|
|
88
115
|
for(let i = 0, length = childNodes.length; i < length; i++) {
|
|
89
116
|
const childNode = childNodes[i];
|
|
90
|
-
|
|
117
|
+
path.push(i);
|
|
118
|
+
const childNodeCloned = clone(childNode, data, path);
|
|
119
|
+
path.pop();
|
|
91
120
|
nodeCloned.appendChild(childNodeCloned);
|
|
92
121
|
}
|
|
93
122
|
return nodeCloned;
|
|
94
123
|
};
|
|
95
124
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
125
|
+
const cloneWithBindingPaths = (data) => {
|
|
126
|
+
let root = $node.cloneNode(true);
|
|
127
|
+
|
|
128
|
+
for (let i = 0, len = $bindingPaths.length; i < len; i++) {
|
|
129
|
+
const binding = $bindingPaths[i];
|
|
130
|
+
const target = findByPath(root, binding.path);
|
|
131
|
+
const newRoot = binding.fn(data, target, root);
|
|
132
|
+
if(newRoot) {
|
|
133
|
+
root = newRoot;
|
|
103
134
|
}
|
|
104
135
|
}
|
|
136
|
+
|
|
137
|
+
return root;
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
this.clone = (data) => {
|
|
141
|
+
$node = $fn(this);
|
|
105
142
|
if(!$hasBindingData) {
|
|
143
|
+
this.clone = () => $node.cloneNode(true);
|
|
106
144
|
return $node.cloneNode(true);
|
|
107
145
|
}
|
|
108
|
-
|
|
146
|
+
|
|
147
|
+
const firstClone = clone($node, data, []);
|
|
148
|
+
this.clone = cloneWithBindingPaths;
|
|
149
|
+
return firstClone;
|
|
109
150
|
};
|
|
110
151
|
|
|
111
152
|
|
|
@@ -164,3 +205,4 @@ export function useCache(fn) {
|
|
|
164
205
|
return wrapper([_, __, ...args]);
|
|
165
206
|
};
|
|
166
207
|
}
|
|
208
|
+
w
|