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
|
@@ -21,12 +21,14 @@ export function ForEachArray(data, callback, key, configs = {}) {
|
|
|
21
21
|
cleanCache();
|
|
22
22
|
lastNumberOfItems = 0;
|
|
23
23
|
};
|
|
24
|
+
|
|
24
25
|
const getItemKey = (item, indexKey) => {
|
|
25
26
|
if(keysCache.has(item)) {
|
|
26
27
|
return keysCache.get(item);
|
|
27
28
|
}
|
|
28
29
|
return getKey(item, indexKey, key);
|
|
29
30
|
};
|
|
31
|
+
|
|
30
32
|
const getItemChild = (item) => {
|
|
31
33
|
return getChildByKey(getItemKey(item));
|
|
32
34
|
};
|
|
@@ -143,9 +145,9 @@ export function ForEachArray(data, callback, key, configs = {}) {
|
|
|
143
145
|
},
|
|
144
146
|
add(items, delay = 2) {
|
|
145
147
|
const fragment = Actions.toFragment(items);
|
|
146
|
-
|
|
148
|
+
Promise.resolve().then(() => {
|
|
147
149
|
element.appendElement(fragment);
|
|
148
|
-
}
|
|
150
|
+
});
|
|
149
151
|
},
|
|
150
152
|
replace(items) {
|
|
151
153
|
clear();
|
|
File without changes
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import NativeDocumentError from "../errors/NativeDocumentError";
|
|
2
|
+
|
|
3
|
+
export default function EventEmitter() {
|
|
4
|
+
|
|
5
|
+
this.__$events = null;
|
|
6
|
+
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
EventEmitter.prototype.on = function(eventName, callback) {
|
|
10
|
+
if(!this.__$events) {
|
|
11
|
+
this.__$events = new Map();
|
|
12
|
+
}
|
|
13
|
+
if(!this.__$events.has(eventName)) {
|
|
14
|
+
this.__$events.set(eventName, callback);
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
const existingCallback = this.__$events.get(eventName);
|
|
18
|
+
if(!Array.isArray(existingCallback)) {
|
|
19
|
+
this.__$events.set(eventName, [existingCallback, callback]);
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
existingCallback.push(callback);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
EventEmitter.prototype.hasListeners = function(eventName) {
|
|
26
|
+
return !!this.__$events.get(eventName);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
EventEmitter.prototype.trigger = async function(eventName, ...args) {
|
|
30
|
+
const callbacks = this.__$events.get(eventName);
|
|
31
|
+
if(!callbacks) {
|
|
32
|
+
// throw new NativeDocumentError(this.constructor.name, 'Event '+eventName+' not found');
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if(typeof callbacks === 'function') {
|
|
37
|
+
return await Promise.resolve(callbacks.apply(this, args))
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
let result = null;
|
|
41
|
+
for(let i = 0, length = callbacks.length; i < length; i++) {
|
|
42
|
+
result = await Promise.resolve(await callbacks[i].apply(this, args));
|
|
43
|
+
}
|
|
44
|
+
return result;
|
|
45
|
+
};
|
|
46
|
+
EventEmitter.prototype.emit = EventEmitter.prototype.trigger;
|
|
@@ -45,12 +45,14 @@ export const timeEquals = (observableOrValue) => {
|
|
|
45
45
|
|
|
46
46
|
export const timeAfter = (observableOrValue) => {
|
|
47
47
|
return createFilter(observableOrValue, (value, target) => {
|
|
48
|
+
if (!value || !target) return false;
|
|
48
49
|
return getSecondsOfDay(value) > getSecondsOfDay(target);
|
|
49
50
|
});
|
|
50
51
|
};
|
|
51
52
|
|
|
52
53
|
export const timeBefore = (observableOrValue) => {
|
|
53
54
|
return createFilter(observableOrValue, (value, target) => {
|
|
55
|
+
if (!value || !target) return false;
|
|
54
56
|
return getSecondsOfDay(value) < getSecondsOfDay(target);
|
|
55
57
|
});
|
|
56
58
|
};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -35,6 +35,18 @@ export const debounce = function(fn, delay, options = {}) {
|
|
|
35
35
|
}
|
|
36
36
|
};
|
|
37
37
|
|
|
38
|
+
export const nextTick = function(fn) {
|
|
39
|
+
let pending = false;
|
|
40
|
+
return function(...args) {
|
|
41
|
+
if (pending) return;
|
|
42
|
+
pending = true;
|
|
43
|
+
|
|
44
|
+
Promise.resolve().then(() => {
|
|
45
|
+
fn.apply(this, args);
|
|
46
|
+
pending = false;
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
};
|
|
38
50
|
|
|
39
51
|
/**
|
|
40
52
|
*
|
|
File without changes
|
|
File without changes
|
|
@@ -3,6 +3,7 @@ import DebugManager from "./debug-manager";
|
|
|
3
3
|
import NativeDocumentError from "../errors/NativeDocumentError";
|
|
4
4
|
import ObservableChecker from "../data/ObservableChecker";
|
|
5
5
|
import {NDElement} from "../wrappers/NDElement";
|
|
6
|
+
import TemplateBinding from "../wrappers/TemplateBinding";
|
|
6
7
|
|
|
7
8
|
const COMMON_NODE_TYPES = {
|
|
8
9
|
ELEMENT: 1,
|
|
@@ -16,6 +17,9 @@ const Validator = {
|
|
|
16
17
|
isObservable(value) {
|
|
17
18
|
return value?.__$isObservable || value instanceof ObservableItem || value instanceof ObservableChecker;
|
|
18
19
|
},
|
|
20
|
+
isTemplateBinding(value) {
|
|
21
|
+
return value?.__$isTemplateBinding || value instanceof TemplateBinding;
|
|
22
|
+
},
|
|
19
23
|
isObservableWhenResult(value) {
|
|
20
24
|
return value && (value.__$isObservableWhen || (typeof value === 'object' && '$target' in value && '$observer' in value));
|
|
21
25
|
},
|
|
@@ -25,6 +29,9 @@ const Validator = {
|
|
|
25
29
|
isProxy(value) {
|
|
26
30
|
return value?.__isProxy__
|
|
27
31
|
},
|
|
32
|
+
isObservableOrProxy(value) {
|
|
33
|
+
return Validator.isObservable(value) || Validator.isProxy(value);
|
|
34
|
+
},
|
|
28
35
|
isAnchor(value) {
|
|
29
36
|
return value?.__Anchor__
|
|
30
37
|
},
|
|
@@ -2,7 +2,7 @@ import Anchor from "../elements/anchor";
|
|
|
2
2
|
import Validator from "../utils/validator";
|
|
3
3
|
import AttributesWrapper from "./AttributesWrapper";
|
|
4
4
|
import PluginsManager from "../utils/plugins-manager";
|
|
5
|
-
import
|
|
5
|
+
import './prototype-extensions';
|
|
6
6
|
|
|
7
7
|
const $nodeCache = new Map();
|
|
8
8
|
let $textNodeCache = null;
|
|
@@ -92,41 +92,18 @@ export const ElementCreator = {
|
|
|
92
92
|
PluginsManager.emit('AfterProcessChildren', parent);
|
|
93
93
|
},
|
|
94
94
|
getChild(child) {
|
|
95
|
-
if(child
|
|
95
|
+
if(child == null) {
|
|
96
96
|
return null;
|
|
97
97
|
}
|
|
98
|
-
if(
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
return child;
|
|
106
|
-
}
|
|
107
|
-
if (Validator.isObservable(child)) {
|
|
108
|
-
return ElementCreator.createObservableNode(null, child);
|
|
109
|
-
}
|
|
110
|
-
if(Validator.isNDElement(child)) {
|
|
111
|
-
return child.$element ?? child.$build?.() ?? null;
|
|
112
|
-
}
|
|
113
|
-
if(validator.$element) {
|
|
114
|
-
return validator.$element;
|
|
115
|
-
}
|
|
116
|
-
if(Validator.isArray(child)) {
|
|
117
|
-
const fragment = document.createDocumentFragment();
|
|
118
|
-
for(let i = 0, length = child.length; i < length; i++) {
|
|
119
|
-
fragment.appendChild(this.getChild(child[i]));
|
|
120
|
-
}
|
|
121
|
-
return fragment;
|
|
122
|
-
}
|
|
123
|
-
if(Validator.isFunction(child)) {
|
|
124
|
-
PluginsManager.emit('BeforeProcessComponent', child);
|
|
125
|
-
return this.getChild(child());
|
|
126
|
-
}
|
|
127
|
-
if(child?.$hydrate) {
|
|
128
|
-
return ElementCreator.createHydratableNode(null, child);
|
|
98
|
+
if(child.toNdElement) {
|
|
99
|
+
do {
|
|
100
|
+
child = child.toNdElement();
|
|
101
|
+
if(Validator.isElement(child)) {
|
|
102
|
+
return child;
|
|
103
|
+
}
|
|
104
|
+
} while (child.toNdElement);
|
|
129
105
|
}
|
|
106
|
+
|
|
130
107
|
return ElementCreator.createStaticTextNode(null, child);
|
|
131
108
|
},
|
|
132
109
|
/**
|
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import DocumentObserver from "./DocumentObserver";
|
|
2
2
|
import PluginsManager from "../utils/plugins-manager";
|
|
3
|
-
import Validator from "../utils/validator";
|
|
4
3
|
import NativeDocumentError from "../errors/NativeDocumentError.js";
|
|
5
4
|
import DebugManager from "../utils/debug-manager.js";
|
|
6
5
|
|
|
7
|
-
import {EVENTS} from "../utils/events";
|
|
8
|
-
|
|
9
6
|
export function NDElement(element) {
|
|
10
7
|
this.$element = element;
|
|
11
8
|
this.$observer = null;
|
|
@@ -110,130 +107,6 @@ NDElement.prototype.attach = function(bindingHydrator) {
|
|
|
110
107
|
};
|
|
111
108
|
|
|
112
109
|
|
|
113
|
-
/**
|
|
114
|
-
*
|
|
115
|
-
* ND events API
|
|
116
|
-
*
|
|
117
|
-
*/
|
|
118
|
-
|
|
119
|
-
const DelegatedEventsCallbackStore = {};
|
|
120
|
-
|
|
121
|
-
const addCallbackToCallbacksStore = function(element, eventName, callback) {
|
|
122
|
-
if(!element) return;
|
|
123
|
-
if(!DelegatedEventsCallbackStore[eventName]) {
|
|
124
|
-
const eventStore = new WeakMap();
|
|
125
|
-
DelegatedEventsCallbackStore[eventName] = eventStore;
|
|
126
|
-
eventStore.set(element, callback);
|
|
127
|
-
return;
|
|
128
|
-
}
|
|
129
|
-
const eventStore = DelegatedEventsCallbackStore[eventName];
|
|
130
|
-
|
|
131
|
-
if(!eventStore.has(element)) {
|
|
132
|
-
eventStore.set(element, callback);
|
|
133
|
-
return;
|
|
134
|
-
}
|
|
135
|
-
const existingCallbacks = eventStore.get(element);
|
|
136
|
-
if(!Validator.isArray(existingCallbacks)) {
|
|
137
|
-
eventStore.set(element, [store[eventName], callback]);
|
|
138
|
-
return;
|
|
139
|
-
}
|
|
140
|
-
existingCallbacks.push(callback);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
const handleDelegatedCallbacks = function(container, eventName) {
|
|
144
|
-
container.addEventListener(eventName, (event) => {
|
|
145
|
-
const eventStore = DelegatedEventsCallbackStore[eventName];
|
|
146
|
-
if(!eventStore) {
|
|
147
|
-
return;
|
|
148
|
-
}
|
|
149
|
-
let target = event.target;
|
|
150
|
-
while(target && target !== container) {
|
|
151
|
-
const callback = eventStore.get(target);
|
|
152
|
-
if(!callback) {
|
|
153
|
-
target = target.parentElement;
|
|
154
|
-
continue;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
if(Validator.isFunction(callback)) {
|
|
158
|
-
callback.call(target, event);
|
|
159
|
-
}
|
|
160
|
-
else {
|
|
161
|
-
for(let i = 0; i < callback.length; i++) {
|
|
162
|
-
callback[i].call(target, event);
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
return;
|
|
166
|
-
}
|
|
167
|
-
});
|
|
168
|
-
};
|
|
169
|
-
|
|
170
|
-
const preventDefaultWrapper = function(element, eventName, callback) {
|
|
171
|
-
element.addEventListener(eventName, (event) => {
|
|
172
|
-
event.preventDefault();
|
|
173
|
-
callback && callback.call(element, event);
|
|
174
|
-
});
|
|
175
|
-
return this;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
const stopPropagationWrapper = function(element, eventName, callback) {
|
|
179
|
-
element.addEventListener(eventName, (event) => {
|
|
180
|
-
event.stopPropagation();
|
|
181
|
-
callback && callback.call(element, event);
|
|
182
|
-
});
|
|
183
|
-
return this;
|
|
184
|
-
};
|
|
185
|
-
|
|
186
|
-
const preventDefaultAndStopPropagationWrapper = function(element, eventName, callback) {
|
|
187
|
-
element.addEventListener(eventName, (event) => {
|
|
188
|
-
event.stopPropagation();
|
|
189
|
-
event.preventDefault();
|
|
190
|
-
callback && callback.call(element, event);
|
|
191
|
-
});
|
|
192
|
-
return this;
|
|
193
|
-
};
|
|
194
|
-
|
|
195
|
-
const captureEventWrapper = function(element, eventName, directHandler) {
|
|
196
|
-
if(directHandler) {
|
|
197
|
-
element.addEventListener(eventName, directHandler);
|
|
198
|
-
return this;
|
|
199
|
-
}
|
|
200
|
-
handleDelegatedCallbacks(element, eventName);
|
|
201
|
-
return this;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
for(const event of EVENTS) {
|
|
205
|
-
const eventName = event.toLowerCase();
|
|
206
|
-
NDElement.prototype['on'+event] = function(callback) {
|
|
207
|
-
this.$element.addEventListener(eventName, callback);
|
|
208
|
-
return this;
|
|
209
|
-
};
|
|
210
|
-
|
|
211
|
-
NDElement.prototype['onPrevent'+event] = function(callback) {
|
|
212
|
-
preventDefaultWrapper(this.$element, eventName, callback);
|
|
213
|
-
return this;
|
|
214
|
-
};
|
|
215
|
-
|
|
216
|
-
NDElement.prototype['onStop'+event] = function(callback) {
|
|
217
|
-
stopPropagationWrapper(this.$element, eventName, callback);
|
|
218
|
-
return this;
|
|
219
|
-
};
|
|
220
|
-
|
|
221
|
-
NDElement.prototype['onPreventStop'+event] = function(callback) {
|
|
222
|
-
preventDefaultAndStopPropagationWrapper(this.$element, eventName, callback);
|
|
223
|
-
return this;
|
|
224
|
-
};
|
|
225
|
-
|
|
226
|
-
NDElement.prototype['when'+event] = function(callback) {
|
|
227
|
-
addCallbackToCallbacksStore(this.$element, eventName, callback);
|
|
228
|
-
return this;
|
|
229
|
-
};
|
|
230
|
-
|
|
231
|
-
NDElement.prototype['capture'+event] = function(directHandler) {
|
|
232
|
-
captureEventWrapper(this.$element, eventName, directHandler);
|
|
233
|
-
return this;
|
|
234
|
-
};
|
|
235
|
-
}
|
|
236
|
-
|
|
237
110
|
NDElement.prototype.with = function(methods) {
|
|
238
111
|
if (!methods || typeof methods !== 'object') {
|
|
239
112
|
throw new NativeDocumentError('extend() requires an object of methods');
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { NDElement } from "./NDElement";
|
|
2
|
+
import {EVENTS} from "../utils/events";
|
|
3
|
+
|
|
4
|
+
let createNdElementInstance = (target) => {
|
|
5
|
+
attachEventPrototypes && attachEventPrototypes();
|
|
6
|
+
attachEventPrototypes = null;
|
|
7
|
+
createNdElementInstance = (target) => new NDElement(target);
|
|
8
|
+
return new NDElement(target);
|
|
9
|
+
};
|
|
10
|
+
const property = {
|
|
11
|
+
configurable: true,
|
|
12
|
+
get() {
|
|
13
|
+
return createNdElementInstance(this);
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
Object.defineProperty(HTMLElement.prototype, 'nd', property);
|
|
18
|
+
|
|
19
|
+
Object.defineProperty(DocumentFragment.prototype, 'nd', property);
|
|
20
|
+
Object.defineProperty(NDElement.prototype, 'nd', {
|
|
21
|
+
configurable: true,
|
|
22
|
+
get: function() {
|
|
23
|
+
return this;
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
// ----------------------------------------------------------------
|
|
30
|
+
// Events helpers
|
|
31
|
+
// ----------------------------------------------------------------
|
|
32
|
+
|
|
33
|
+
let attachEventPrototypes = () => {
|
|
34
|
+
EVENTS.forEach(eventSourceName => {
|
|
35
|
+
const eventName = eventSourceName.toLowerCase();
|
|
36
|
+
NDElement.prototype['on'+eventSourceName] = function(callback) {
|
|
37
|
+
this.$element.addEventListener(eventName, callback);
|
|
38
|
+
return this;
|
|
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
|
+
};
|
|
50
|
+
|
|
51
|
+
NDElement.prototype['onPreventStop'+eventSourceName] = function(callback) {
|
|
52
|
+
_preventStop(this.$element, eventName, callback);
|
|
53
|
+
return this;
|
|
54
|
+
};
|
|
55
|
+
})
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
NDElement.prototype.on = function(name, callback, options) {
|
|
59
|
+
this.$element.addEventListener(name.toLowerCase(), callback, options);
|
|
60
|
+
return this;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const _prevent = function(element, eventName, callback) {
|
|
64
|
+
const handler = (event) => {
|
|
65
|
+
event.preventDefault();
|
|
66
|
+
callback && callback.call(element, event);
|
|
67
|
+
};
|
|
68
|
+
element.addEventListener(eventName, handler);
|
|
69
|
+
return this;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const _stop = function(element, eventName, callback) {
|
|
73
|
+
const handler = (event) => {
|
|
74
|
+
event.stopPropagation();
|
|
75
|
+
callback && callback.call(element, event);
|
|
76
|
+
};
|
|
77
|
+
element.addEventListener(eventName, handler);
|
|
78
|
+
return this;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const _preventStop = function(element, eventName, callback) {
|
|
82
|
+
const handler = (event) => {
|
|
83
|
+
event.stopPropagation();
|
|
84
|
+
event.preventDefault();
|
|
85
|
+
callback && callback.call(element, event);
|
|
86
|
+
};
|
|
87
|
+
element.addEventListener(eventName, handler);
|
|
88
|
+
return this;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
// ----------------------------------------------------------------
|
|
94
|
+
// Class attributes binder
|
|
95
|
+
// ----------------------------------------------------------------
|
|
96
|
+
const classListMethods = {
|
|
97
|
+
getClasses() {
|
|
98
|
+
return this.$element.className?.split(' ').filter(Boolean);
|
|
99
|
+
},
|
|
100
|
+
add(value) {
|
|
101
|
+
const classes = this.getClasses();
|
|
102
|
+
if(classes.indexOf(value) >= 0) {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
classes.push(value);
|
|
106
|
+
this.$element.className = classes.join(' ');
|
|
107
|
+
},
|
|
108
|
+
remove(value) {
|
|
109
|
+
const classes = this.getClasses();
|
|
110
|
+
const index = classes.indexOf(value);
|
|
111
|
+
if(index < 0) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
classes.splice(index, 1);
|
|
115
|
+
this.$element.className = classes.join(' ');
|
|
116
|
+
},
|
|
117
|
+
toggle(value, force = undefined) {
|
|
118
|
+
const classes = this.getClasses();
|
|
119
|
+
const index = classes.indexOf(value);
|
|
120
|
+
if(index >= 0) {
|
|
121
|
+
if(force === true) {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
classes.splice(index, 1);
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
if(force === false) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
classes.push(value);
|
|
131
|
+
}
|
|
132
|
+
this.$element.className = classes.join(' ');
|
|
133
|
+
},
|
|
134
|
+
contains(value) {
|
|
135
|
+
return this.getClasses().indexOf(value) >= 0;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
Object.defineProperty(HTMLElement.prototype, 'classes', {
|
|
140
|
+
configurable: true,
|
|
141
|
+
get() {
|
|
142
|
+
return {
|
|
143
|
+
$element: this,
|
|
144
|
+
...classListMethods
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {ElementCreator} from "./ElementCreator";
|
|
2
2
|
import {createTextNode} from "./HtmlElementWrapper";
|
|
3
3
|
import Anchor from "../elements/anchor";
|
|
4
|
+
import TemplateBinding from "./TemplateBinding";
|
|
4
5
|
|
|
5
6
|
const cloneBindingsDataCache = new WeakMap();
|
|
6
7
|
|
|
@@ -109,12 +110,10 @@ export function TemplateCloner($fn) {
|
|
|
109
110
|
|
|
110
111
|
|
|
111
112
|
const createBinding = (hydrateFunction, target) => {
|
|
112
|
-
return {
|
|
113
|
-
$
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
},
|
|
117
|
-
}
|
|
113
|
+
return new TemplateBinding((element, property) => {
|
|
114
|
+
$hasBindingData = true;
|
|
115
|
+
$hydrateFn(hydrateFunction, target, element, property)
|
|
116
|
+
});
|
|
118
117
|
};
|
|
119
118
|
|
|
120
119
|
this.style = (fn) => {
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import ObservableItem from "../data/ObservableItem";
|
|
2
|
+
import {NDElement} from "./NDElement";
|
|
3
|
+
import TemplateBinding from "./TemplateBinding";
|
|
4
|
+
import {ElementCreator} from "./ElementCreator";
|
|
5
|
+
import PluginsManager from "../utils/plugins-manager";
|
|
6
|
+
import Validator from "../utils/validator";
|
|
7
|
+
|
|
8
|
+
String.prototype.toNdElement = function () {
|
|
9
|
+
const formattedChild = this.resolveObservableTemplate ? this.resolveObservableTemplate() : this;
|
|
10
|
+
if(Validator.isString(formattedChild)) {
|
|
11
|
+
return ElementCreator.createStaticTextNode(null, formattedChild);
|
|
12
|
+
}
|
|
13
|
+
return ElementCreator.getChild(null, formattedChild);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
Element.prototype.toNdElement = function () {
|
|
17
|
+
return this;
|
|
18
|
+
};
|
|
19
|
+
Text.prototype.toNdElement = function () {
|
|
20
|
+
return this;
|
|
21
|
+
};
|
|
22
|
+
Comment.prototype.toNdElement = function () {
|
|
23
|
+
return this;
|
|
24
|
+
};
|
|
25
|
+
Document.prototype.toNdElement = function () {
|
|
26
|
+
return this;
|
|
27
|
+
};
|
|
28
|
+
DocumentFragment.prototype.toNdElement = function () {
|
|
29
|
+
return this;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
ObservableItem.prototype.toNdElement = function () {
|
|
33
|
+
return ElementCreator.createObservableNode(null, this);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
NDElement.prototype.toNdElement = function () {
|
|
37
|
+
return this.$element ?? this.$build?.() ?? this.build?.() ?? null;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
Array.prototype.toNdElement = function () {
|
|
41
|
+
const fragment = document.createDocumentFragment();
|
|
42
|
+
for(let i = 0, length = this.length; i < length; i++) {
|
|
43
|
+
fragment.appendChild(ElementCreator.getChild(this[i]));
|
|
44
|
+
}
|
|
45
|
+
return fragment;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
Function.prototype.toNdElement = function () {
|
|
49
|
+
const child = this;
|
|
50
|
+
PluginsManager.emit('BeforeProcessComponent', child);
|
|
51
|
+
return ElementCreator.getChild(child());
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
TemplateBinding.prototype.toNdElement = function () {
|
|
55
|
+
return ElementCreator.createHydratableNode(null, this);
|
|
56
|
+
};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/src/router/Route.js
CHANGED
package/src/router/Router.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {Route} from "./Route.js";
|
|
2
|
-
import Validator from "../utils/validator.js";
|
|
3
|
-
import RouterError from "../errors/RouterError.js";
|
|
2
|
+
import Validator from "../core/utils/validator.js";
|
|
3
|
+
import RouterError from "../core/errors/RouterError.js";
|
|
4
4
|
import {RouteGroupHelper} from "./RouteGroupHelper.js";
|
|
5
|
-
import {trim} from "../utils/helpers.js";
|
|
5
|
+
import {trim} from "../core/utils/helpers.js";
|
|
6
6
|
import HashRouter from "./modes/HashRouter.js";
|
|
7
7
|
import HistoryRouter from "./modes/HistoryRouter.js";
|
|
8
8
|
import MemoryRouter from "./modes/MemoryRouter.js";
|
|
9
|
-
import DebugManager from "../utils/debug-manager.js";
|
|
9
|
+
import DebugManager from "../core/utils/debug-manager.js";
|
|
10
10
|
import {RouterComponent} from "./RouterComponent.js";
|
|
11
11
|
|
|
12
12
|
export const DEFAULT_ROUTER_NAME = 'default';
|