native-document 1.0.168 → 1.0.172
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/CHANGELOG.md +99 -4
- package/components.js +3 -1
- package/dist/native-document.components.min.js +197 -171
- package/dist/native-document.dev.js +92 -75
- package/dist/native-document.dev.js.map +1 -1
- package/dist/native-document.min.js +1 -1
- package/docs/components/icons.md +321 -0
- package/docs/vitepress-conventions.md +2 -2
- package/package.json +11 -4
- package/src/components/BaseComponent.js +43 -1
- package/src/components/accordion/Accordion.js +1 -0
- package/src/components/accordion/AccordionItem.js +1 -0
- package/src/components/alert/Alert.js +4 -0
- package/src/components/avatar/Avatar.js +1 -0
- package/src/components/avatar/AvatarGroup.js +1 -0
- package/src/components/badge/Badge.js +1 -0
- package/src/components/breadcrumb/BreadCrumb.js +4 -0
- package/src/components/button/Button.js +1 -0
- package/src/components/card/Card.js +1 -0
- package/src/components/context-menu/ContextMenu.js +2 -0
- package/src/components/context-menu/ContextMenuGroup.js +2 -0
- package/src/components/context-menu/ContextMenuItem.js +2 -0
- package/src/components/divider/Divider.js +2 -0
- package/src/components/dropdown/Dropdown.js +1 -0
- package/src/components/dropdown/DropdownDivider.js +1 -0
- package/src/components/dropdown/DropdownGroup.js +1 -0
- package/src/components/dropdown/DropdownItem.js +1 -0
- package/src/components/dropdown/DropdownTrigger.js +1 -0
- package/src/components/form/FormControl.js +1 -0
- package/src/components/form/field/Field.js +1 -0
- package/src/components/form/field/types/FileField.js +3 -3
- package/src/components/form/field/types/StringField.js +1 -1
- package/src/components/icon/Icon.js +108 -0
- package/src/components/icon/icon-getters.js +142 -0
- package/src/components/icon/icons.js +171 -0
- package/src/components/icon/index.js +17 -0
- package/src/components/icon/types/Icon.d.ts +191 -0
- package/src/components/index.d.ts +6 -1
- package/src/components/list/ListItem.js +1 -0
- package/src/components/list/types/List.d.ts +45 -32
- package/src/components/list/types/ListDivider.ts +16 -0
- package/src/components/list/types/ListGroup.d.ts +51 -29
- package/src/components/list/types/ListItem.d.ts +20 -21
- package/src/components/menu/Menu.js +3 -0
- package/src/components/menu/MenuDivider.js +1 -0
- package/src/components/menu/MenuGroup.js +1 -0
- package/src/components/menu/MenuItem.js +1 -0
- package/src/components/menu/MenuLink.js +1 -0
- package/src/components/modal/Modal.js +4 -0
- package/src/components/pagination/Pagination.js +1 -0
- package/src/components/popover/Popover.js +1 -0
- package/src/components/popover/PopoverFooter.js +1 -0
- package/src/components/popover/PopoverHeader.js +1 -0
- package/src/components/progress/Progress.js +5 -0
- package/src/components/skeleton/Skeleton.js +4 -0
- package/src/components/slider/Slider.js +1 -0
- package/src/components/spacer/Spacer.js +1 -0
- package/src/components/spinner/Spinner.js +1 -0
- package/src/components/splitter/Splitter.js +1 -0
- package/src/components/splitter/SplitterGutter.js +6 -0
- package/src/components/splitter/SplitterPanel.js +1 -0
- package/src/components/stacks/AbsoluteStack.js +1 -0
- package/src/components/stacks/FixedStack.js +1 -0
- package/src/components/stacks/HStack.js +1 -0
- package/src/components/stacks/PositionStack.js +1 -0
- package/src/components/stacks/RelativeStack.js +1 -0
- package/src/components/stacks/Stack.js +1 -0
- package/src/components/stacks/VStack.js +1 -0
- package/src/components/stepper/Stepper.js +1 -0
- package/src/components/stepper/StepperStep.js +1 -0
- package/src/components/switch/Switch.js +1 -0
- package/src/components/table/DataTable.js +1 -0
- package/src/components/table/SimpleTable.js +1 -0
- package/src/components/tabs/Tabs.js +1 -0
- package/src/components/toast/Toast.js +1 -0
- package/src/components/tooltip/Tooltip.js +1 -0
- package/src/core/data/MemoryManager.js +6 -1
- package/src/core/data/ObservableItem.js +28 -10
- package/src/core/elements/anchor/anchor.js +4 -3
- package/src/core/elements/anchor/one-child-anchor-overwriting.js +4 -4
- package/src/core/elements/content-formatter.js +35 -2
- package/src/core/elements/control/for-each-array-cache.js +59 -0
- package/src/core/elements/control/for-each-array.js +15 -23
- package/src/core/elements/form.js +1 -1
- package/src/core/elements/img.js +1 -1
- package/src/core/elements/medias.js +2 -2
- package/src/core/elements/meta-data.js +1 -1
- package/src/core/wrappers/AttributesWrapper.js +44 -29
- package/src/core/wrappers/ElementCreator.js +38 -22
- package/src/core/wrappers/HtmlElementWrapper.js +33 -9
- package/src/core/wrappers/NDElement.js +35 -9
- package/src/core/wrappers/NdPrototype.js +31 -39
- package/src/core/wrappers/constants.js +12 -12
- package/src/core/wrappers/prototypes/attributes-extensions.js +24 -24
- package/src/core/wrappers/prototypes/nd-element-extensions.js +128 -65
- package/src/ui/components/accordion/AccordionItemRender.js +29 -7
- package/src/ui/components/alert/AlertRender.js +6 -0
- package/src/ui/components/breadcrumb/BreadcrumbRender.js +9 -1
- package/src/ui/components/button/ButtonRender.js +3 -0
- package/src/ui/components/contextmenu/ContextmenuRender.js +2 -0
- package/src/ui/components/dropdown/DropdownRender.js +3 -0
- package/src/ui/components/dropdown/item/DropdownItemRender.js +6 -1
- package/src/ui/components/form/FieldCollectionRender.js +4 -0
- package/src/ui/components/form/fields/CheckboxFieldRender.js +4 -0
- package/src/ui/components/form/fields/CheckboxGroupFieldRender.js +4 -0
- package/src/ui/components/form/fields/RadioFieldRender.js +4 -0
- package/src/ui/components/form/fields/RangeFieldRender.js +4 -0
- package/src/ui/components/form/fields/SelectFieldRender.js +5 -0
- package/src/ui/components/form/fields/SliderFieldRender.js +3 -0
- package/src/ui/components/icon/material/MaterialIconRender.js +71 -0
- package/src/ui/components/icon/material/material.css +15 -0
- package/src/ui/components/icon/material/material.map.js +170 -0
- package/src/ui/components/icon/phosphor/PhosphorIconRender.js +71 -0
- package/src/ui/components/icon/phosphor/phosphor.css +17 -0
- package/src/ui/components/icon/phosphor/phosphor.map.js +165 -0
- package/src/ui/components/icon/tabler/TablerIconRender.js +58 -0
- package/src/ui/components/icon/tabler/tabler.css +14 -0
- package/src/ui/components/icon/tabler/tabler.map.js +165 -0
- package/src/ui/components/list/item/ListItemRender.js +4 -0
- package/src/ui/components/menu/MenuItemRender.js +8 -0
- package/src/ui/components/menu/MenuLinkRender.js +11 -0
- package/src/ui/components/menu/MenuRender.js +5 -0
- package/src/ui/components/menu/helpers.js +2 -1
- package/src/ui/components/modal/ModalRender.js +8 -2
- package/src/ui/components/progress/ProgressRender.js +9 -0
- package/src/ui/components/skeleton/SkeletonRender.js +2 -0
- package/src/ui/components/spinner/SpinnerRender.js +3 -0
- package/src/ui/components/splitter/SplitterGutterRender.js +4 -0
- package/src/ui/components/splitter/SplitterPanelRender.js +4 -0
- package/src/ui/components/splitter/SplitterRender.js +2 -0
- package/src/ui/components/stepper/StepperRender.js +2 -1
- package/src/ui/components/stepper/StepperStepRender.js +8 -1
- package/src/ui/components/switch/SwitchRender.js +3 -0
- package/src/ui/components/table/data-table/DataTableRender.js +4 -0
- package/src/ui/components/table/simple-table/SimpleTableRender.js +2 -0
- package/src/ui/components/toast/ToastRender.js +4 -0
- package/src/ui/index.js +5 -0
- package/src/ui/utils/aria.js +19 -0
- package/tests/integration/ui/attributes-wrapper.test.js +177 -0
- package/tests/integration/ui/for-each-array.test.js +167 -0
- package/tests/integration/ui/lifecycle.test.js +146 -0
- package/tests/integration/ui/show-if.test.js +168 -0
- package/tests/unit/core/observable-array.test.js +404 -0
- package/tests/unit/core/observable-item.test.js +428 -0
- package/tests/unit/core/observable-object.test.js +239 -0
- package/tests/unit/core/observable-resource.test.js +323 -0
- package/tests/unit/core/store.test.js +347 -0
- package/tests/unit/router/route-matching.test.js +169 -0
- package/tests/unit/router/router-guards.test.js +189 -0
- package/tests/unit/utils/cache.test.js +120 -0
- package/tests/unit/utils/filters.test.js +394 -0
- package/types/elements.d.ts +5 -0
- package/vitest.config.js +15 -0
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import Validator from '../utils/validator';
|
|
2
1
|
import AttributesWrapper, { bindClassAttribute, bindStyleAttribute } from './AttributesWrapper';
|
|
3
2
|
import PluginsManager from '../utils/plugins-manager';
|
|
4
3
|
|
|
@@ -8,7 +7,7 @@ export const ElementCreator = {
|
|
|
8
7
|
createTextNode() {
|
|
9
8
|
if(!$textNodeCache) {
|
|
10
9
|
$textNodeCache = document.createTextNode('');
|
|
11
|
-
ElementCreator.createTextNode =
|
|
10
|
+
ElementCreator.createTextNode = $textNodeCache.cloneNode.bind($textNodeCache);
|
|
12
11
|
}
|
|
13
12
|
return $textNodeCache.cloneNode();
|
|
14
13
|
},
|
|
@@ -19,10 +18,19 @@ export const ElementCreator = {
|
|
|
19
18
|
* @returns {Text}
|
|
20
19
|
*/
|
|
21
20
|
createObservableNode: (parent, observable) => {
|
|
21
|
+
const text = ElementCreator.createObservableNodeWithoutParent(observable);
|
|
22
|
+
parent && parent.appendChild(text);
|
|
23
|
+
return text;
|
|
24
|
+
},
|
|
25
|
+
/**
|
|
26
|
+
*
|
|
27
|
+
* @param {ObservableItem} observable
|
|
28
|
+
* @returns {Text}
|
|
29
|
+
*/
|
|
30
|
+
createObservableNodeWithoutParent: (observable) => {
|
|
22
31
|
const text = ElementCreator.createTextNode();
|
|
23
32
|
observable.subscribe(value => text.nodeValue = value);
|
|
24
33
|
text.nodeValue = observable.val();
|
|
25
|
-
parent && parent.appendChild(text);
|
|
26
34
|
return text;
|
|
27
35
|
},
|
|
28
36
|
/**
|
|
@@ -49,6 +57,11 @@ export const ElementCreator = {
|
|
|
49
57
|
parent && parent.appendChild(text);
|
|
50
58
|
return text;
|
|
51
59
|
},
|
|
60
|
+
createStaticTextNodeWithoutParent: (value) => {
|
|
61
|
+
const text = ElementCreator.createTextNode();
|
|
62
|
+
text.nodeValue = value;
|
|
63
|
+
return text;
|
|
64
|
+
},
|
|
52
65
|
/**
|
|
53
66
|
*
|
|
54
67
|
* @param {string} name
|
|
@@ -72,47 +85,50 @@ export const ElementCreator = {
|
|
|
72
85
|
* @param {HTMLElement|DocumentFragment} parent
|
|
73
86
|
*/
|
|
74
87
|
processChildren: (children, parent) => {
|
|
75
|
-
if(children === null) return;
|
|
76
88
|
if(process.env.NODE_ENV === 'development') {
|
|
77
89
|
PluginsManager.emit('BeforeProcessChildren', parent);
|
|
78
90
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
91
|
+
if(Array.isArray(children)) {
|
|
92
|
+
for(let i = 0, length = children.length; i < length; i++) {
|
|
93
|
+
const child = ElementCreator.getChild(children[i]);
|
|
94
|
+
if(child === null) {
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
parent.appendChild(child);
|
|
98
|
+
}
|
|
99
|
+
return;
|
|
82
100
|
}
|
|
101
|
+
const child = ElementCreator.getChild(children);
|
|
102
|
+
parent.appendChild(child);
|
|
83
103
|
if(process.env.NODE_ENV === 'development') {
|
|
84
104
|
PluginsManager.emit('AfterProcessChildren', parent);
|
|
85
105
|
}
|
|
86
106
|
},
|
|
87
107
|
async safeRemove(element) {
|
|
88
108
|
await element.remove();
|
|
89
|
-
|
|
90
109
|
},
|
|
91
110
|
getChild: (child) => {
|
|
92
|
-
if(child == null) {
|
|
111
|
+
if (child == null) {
|
|
93
112
|
return null;
|
|
94
113
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
114
|
+
|
|
115
|
+
child = child.toNdElement();
|
|
116
|
+
if (child && (child instanceof Node)) {
|
|
117
|
+
return child;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
while (child != null && !(child instanceof Node)) {
|
|
121
|
+
child = child.toNdElement?.();
|
|
102
122
|
}
|
|
103
123
|
|
|
104
|
-
return
|
|
124
|
+
return child instanceof Node ? child : null;
|
|
105
125
|
},
|
|
106
126
|
/**
|
|
107
127
|
*
|
|
108
128
|
* @param {HTMLElement} element
|
|
109
129
|
* @param {Object} attributes
|
|
110
130
|
*/
|
|
111
|
-
processAttributes:
|
|
112
|
-
if (attributes) {
|
|
113
|
-
AttributesWrapper(element, attributes);
|
|
114
|
-
}
|
|
115
|
-
},
|
|
131
|
+
processAttributes: AttributesWrapper,
|
|
116
132
|
/**
|
|
117
133
|
*
|
|
118
134
|
* @param {HTMLElement} element
|
|
@@ -3,7 +3,6 @@ import {ElementCreator} from './ElementCreator';
|
|
|
3
3
|
import {normalizeComponentArgs} from '../utils/args-types';
|
|
4
4
|
import './NdPrototype';
|
|
5
5
|
|
|
6
|
-
import './NdPrototype';
|
|
7
6
|
import '../../core/utils/prototypes.js';
|
|
8
7
|
import '../wrappers/prototypes/nd-element-extensions';
|
|
9
8
|
import '../wrappers/prototypes/bind-class-extensions';
|
|
@@ -27,6 +26,22 @@ export const createTextNode = (value) => {
|
|
|
27
26
|
};
|
|
28
27
|
|
|
29
28
|
|
|
29
|
+
/**
|
|
30
|
+
* Applies attributes to an existing HTMLElement.
|
|
31
|
+
* Used internally by HtmlElementWrapper on each cloned node.
|
|
32
|
+
*
|
|
33
|
+
* @internal
|
|
34
|
+
* @param {HTMLElement} element - Element to configure
|
|
35
|
+
* @param {Object|null} attributes - Attributes object or children if no attrs provided
|
|
36
|
+
* @returns {HTMLElement} The configured element
|
|
37
|
+
*/
|
|
38
|
+
export const createVoidHtmlElement = (element, attributes) => {
|
|
39
|
+
attributes && ElementCreator.processAttributes(element, attributes);
|
|
40
|
+
return element;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
const OBJECT_PROTOTYPE = Object.prototype;
|
|
30
45
|
/**
|
|
31
46
|
* Applies attributes and children to an existing HTMLElement.
|
|
32
47
|
* Used internally by HtmlElementWrapper on each cloned node.
|
|
@@ -38,10 +53,18 @@ export const createTextNode = (value) => {
|
|
|
38
53
|
* @returns {HTMLElement} The configured element
|
|
39
54
|
*/
|
|
40
55
|
export const createHtmlElement = (element, _attributes, _children = null) => {
|
|
41
|
-
|
|
56
|
+
let attributes = _attributes, children = _children;
|
|
57
|
+
if(_attributes?.__$isValidNdChild) { // If attributes is a ValidChild
|
|
58
|
+
attributes = _children;
|
|
59
|
+
children = _attributes;
|
|
60
|
+
}
|
|
42
61
|
|
|
43
|
-
|
|
44
|
-
|
|
62
|
+
if(attributes) {
|
|
63
|
+
ElementCreator.processAttributes(element, attributes);
|
|
64
|
+
}
|
|
65
|
+
if(children) {
|
|
66
|
+
ElementCreator.processChildren(children, element);
|
|
67
|
+
}
|
|
45
68
|
return element;
|
|
46
69
|
};
|
|
47
70
|
|
|
@@ -63,16 +86,17 @@ export const createHtmlElement = (element, _attributes, _children = null) => {
|
|
|
63
86
|
* return el;
|
|
64
87
|
* });
|
|
65
88
|
*/
|
|
66
|
-
export default function HtmlElementWrapper(name, customWrapper = null) {
|
|
89
|
+
export default function HtmlElementWrapper(name, customWrapper = null, isVoid = false) {
|
|
90
|
+
const elementCreator = isVoid ? createVoidHtmlElement : createHtmlElement;
|
|
67
91
|
if(name) {
|
|
68
92
|
if(customWrapper) {
|
|
69
93
|
let node = null;
|
|
70
94
|
let createElement = (attr, children) => {
|
|
71
95
|
node = document.createElement(name);
|
|
72
96
|
createElement = (attr, children) => {
|
|
73
|
-
return
|
|
97
|
+
return elementCreator(customWrapper(node.cloneNode()), attr, children);
|
|
74
98
|
};
|
|
75
|
-
return
|
|
99
|
+
return elementCreator(customWrapper(node.cloneNode()), attr, children);;
|
|
76
100
|
};
|
|
77
101
|
|
|
78
102
|
return (attr, children) => createElement(attr, children);
|
|
@@ -82,9 +106,9 @@ export default function HtmlElementWrapper(name, customWrapper = null) {
|
|
|
82
106
|
let createElement = (attr, children) => {
|
|
83
107
|
node = document.createElement(name);
|
|
84
108
|
createElement = (attr, children) => {
|
|
85
|
-
return
|
|
109
|
+
return elementCreator(node.cloneNode(), attr, children);
|
|
86
110
|
};
|
|
87
|
-
return
|
|
111
|
+
return elementCreator(node.cloneNode(), attr, children);
|
|
88
112
|
};
|
|
89
113
|
|
|
90
114
|
return (attr, children) => createElement(attr, children);
|
|
@@ -38,8 +38,19 @@ NDElement.$getChild = (el) => el;
|
|
|
38
38
|
NDElement.prototype.ghostDom = function(element) {
|
|
39
39
|
if(!this.$attachements) {
|
|
40
40
|
this.$attachements = document.createDocumentFragment();
|
|
41
|
+
this.toNdElement = () => {
|
|
42
|
+
const fragment = document.createDocumentFragment();
|
|
43
|
+
if(!this.$attachements.contains(this.$element)) {
|
|
44
|
+
fragment.appendChild(this.$element);
|
|
45
|
+
}
|
|
46
|
+
fragment.appendChild(this.$attachements);
|
|
47
|
+
return fragment;
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
const child = NDElement.$getChild(element);
|
|
51
|
+
if(child) {
|
|
52
|
+
this.$attachements.appendChild(child);
|
|
41
53
|
}
|
|
42
|
-
this.$attachements.appendChild(NDElement.$getChild(element));
|
|
43
54
|
return this;
|
|
44
55
|
};
|
|
45
56
|
|
|
@@ -176,16 +187,32 @@ NDElement.prototype.destroyOnUnmount = function() {
|
|
|
176
187
|
* @returns {this}
|
|
177
188
|
*/
|
|
178
189
|
NDElement.prototype.destroy = function() {
|
|
179
|
-
this.$element
|
|
190
|
+
if(!this.$element) {
|
|
191
|
+
return this;
|
|
192
|
+
}
|
|
193
|
+
const observer = $lifeCycleObservers.get(this.$element);
|
|
194
|
+
if(observer) {
|
|
195
|
+
observer.disconnect();
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
const treewalk = document.createTreeWalker(this.$element, NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_TEXT);
|
|
199
|
+
const nodes = [];
|
|
200
|
+
while(treewalk.nextNode()) {
|
|
201
|
+
nodes.push(treewalk.currentNode);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
for(let i = 0, length = nodes.length; i < length; i++) {
|
|
205
|
+
const child = nodes[i];
|
|
180
206
|
child.remove();
|
|
181
|
-
|
|
182
|
-
|
|
207
|
+
const childObserver = $lifeCycleObservers.get(child);
|
|
208
|
+
if(childObserver) {
|
|
209
|
+
childObserver.disconnect();
|
|
210
|
+
}
|
|
183
211
|
$lifeCycleObservers.delete(child);
|
|
184
|
-
}
|
|
212
|
+
}
|
|
185
213
|
|
|
186
|
-
this.$element.__$controller?.abort();
|
|
187
|
-
this.$element.__$controller = null;
|
|
188
214
|
$lifeCycleObservers.delete(this.$element);
|
|
215
|
+
this.$element.remove();
|
|
189
216
|
this.$element = null;
|
|
190
217
|
};
|
|
191
218
|
|
|
@@ -407,7 +434,6 @@ NDElement.prototype.style = function(style) {
|
|
|
407
434
|
return this;
|
|
408
435
|
};
|
|
409
436
|
|
|
410
|
-
|
|
411
437
|
/**
|
|
412
438
|
* Extends the NDElement prototype with new methods available to all NDElement instances.
|
|
413
439
|
* Use this to add global methods to all NDElements.
|
|
@@ -607,7 +633,7 @@ NDElement.prototype.contentEditable = function($obs, {format = 'html'} = {}) {
|
|
|
607
633
|
|
|
608
634
|
this.$element.addEventListener('input', () => {
|
|
609
635
|
$obs?.set(getValue());
|
|
610
|
-
}
|
|
636
|
+
});
|
|
611
637
|
|
|
612
638
|
return this;
|
|
613
639
|
};
|
|
@@ -20,65 +20,42 @@ Object.defineProperty(NDElement.prototype, 'nd', {
|
|
|
20
20
|
});
|
|
21
21
|
|
|
22
22
|
|
|
23
|
-
|
|
24
23
|
// ----------------------------------------------------------------
|
|
25
24
|
// Events helpers
|
|
26
25
|
// ----------------------------------------------------------------
|
|
27
26
|
EVENTS.forEach(eventSourceName => {
|
|
28
27
|
const eventName = eventSourceName.toLowerCase();
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
28
|
+
const inlineHandler = 'on'+eventName;
|
|
29
|
+
NDElement.prototype['on'+eventSourceName] = function(callback = null, options = null) {
|
|
30
|
+
if(!this.$element[inlineHandler] && !options) {
|
|
31
|
+
this.$element[inlineHandler] = callback;
|
|
32
|
+
return this;
|
|
33
|
+
}
|
|
34
|
+
this.$element.addEventListener(eventName, callback, options);
|
|
34
35
|
return this;
|
|
35
36
|
};
|
|
36
37
|
});
|
|
37
38
|
|
|
38
39
|
EVENTS_WITH_STOP.forEach(eventSourceName => {
|
|
39
40
|
const eventName = eventSourceName.toLowerCase();
|
|
40
|
-
NDElement.prototype['onStop'+eventSourceName] = function(callback = null, options =
|
|
41
|
-
_stop(this.$element, eventName, callback,
|
|
42
|
-
signal: this.$getSignal(),
|
|
43
|
-
...options,
|
|
44
|
-
});
|
|
41
|
+
NDElement.prototype['onStop'+eventSourceName] = function(callback = null, options = null) {
|
|
42
|
+
_stop(this.$element, eventName, callback, options);
|
|
45
43
|
return this;
|
|
46
44
|
};
|
|
47
|
-
NDElement.prototype['onPreventStop'+eventSourceName] = function(callback = null, options =
|
|
48
|
-
_preventStop(this.$element, eventName, callback,
|
|
49
|
-
signal: this.$getSignal(),
|
|
50
|
-
...options,
|
|
51
|
-
});
|
|
45
|
+
NDElement.prototype['onPreventStop'+eventSourceName] = function(callback = null, options = null) {
|
|
46
|
+
_preventStop(this.$element, eventName, callback, options);
|
|
52
47
|
return this;
|
|
53
48
|
};
|
|
54
49
|
});
|
|
55
50
|
|
|
56
51
|
EVENTS_WITH_PREVENT.forEach(eventSourceName => {
|
|
57
52
|
const eventName = eventSourceName.toLowerCase();
|
|
58
|
-
NDElement.prototype['onPrevent'+eventSourceName] = function(callback = null, options =
|
|
59
|
-
_prevent(this.$element, eventName, callback,
|
|
60
|
-
signal: this.$getSignal(),
|
|
61
|
-
...options,
|
|
62
|
-
});
|
|
53
|
+
NDElement.prototype['onPrevent'+eventSourceName] = function(callback = null, options = null) {
|
|
54
|
+
_prevent(this.$element, eventName, callback, options);
|
|
63
55
|
return this;
|
|
64
56
|
};
|
|
65
57
|
});
|
|
66
58
|
|
|
67
|
-
/**
|
|
68
|
-
* Retrieves or creates an AbortController signal tied to this element's lifecycle.
|
|
69
|
-
* The signal is automatically aborted when the element is removed via .nd.remove().
|
|
70
|
-
* Used internally by all event listeners (onClick, onInput, etc.) to auto-cleanup on unmount.
|
|
71
|
-
*
|
|
72
|
-
* @internal
|
|
73
|
-
* @returns {AbortSignal} The signal for this element's AbortController
|
|
74
|
-
*/
|
|
75
|
-
NDElement.prototype.$getSignal = function() {
|
|
76
|
-
if(!this.$element.__$controller) {
|
|
77
|
-
this.$element.__$controller = new AbortController();
|
|
78
|
-
}
|
|
79
|
-
return this.$element.__$controller.signal;
|
|
80
|
-
};
|
|
81
|
-
|
|
82
59
|
|
|
83
60
|
/**
|
|
84
61
|
* Adds a native event listener to the underlying HTMLElement.
|
|
@@ -91,7 +68,6 @@ NDElement.prototype.$getSignal = function() {
|
|
|
91
68
|
*/
|
|
92
69
|
NDElement.prototype.on = function(name, callback, options) {
|
|
93
70
|
this.$element.addEventListener(name.toLowerCase(), callback, {
|
|
94
|
-
signal: this.$getSignal(),
|
|
95
71
|
...options,
|
|
96
72
|
});
|
|
97
73
|
return this;
|
|
@@ -119,7 +95,6 @@ NDElement.prototype.off = function(name, callback) {
|
|
|
119
95
|
*/
|
|
120
96
|
NDElement.prototype.once = function(name, callback) {
|
|
121
97
|
this.$element.addEventListener(name.toLowerCase(), callback, {
|
|
122
|
-
signal: this.$getSignal(),
|
|
123
98
|
once: true,
|
|
124
99
|
});
|
|
125
100
|
return this;
|
|
@@ -151,8 +126,13 @@ const _prevent = function(element, eventName, callback, options) {
|
|
|
151
126
|
event.preventDefault();
|
|
152
127
|
callback && callback.call(element, event);
|
|
153
128
|
};
|
|
129
|
+
|
|
130
|
+
const inlineHandler = 'on' + eventName;
|
|
131
|
+
if(!element[inlineHandler] && !options) {
|
|
132
|
+
element[inlineHandler] = handler;
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
154
135
|
element.addEventListener(eventName, handler, options);
|
|
155
|
-
return this;
|
|
156
136
|
};
|
|
157
137
|
|
|
158
138
|
const _stop = function(element, eventName, callback, options) {
|
|
@@ -160,6 +140,13 @@ const _stop = function(element, eventName, callback, options) {
|
|
|
160
140
|
event.stopPropagation();
|
|
161
141
|
callback && callback.call(element, event);
|
|
162
142
|
};
|
|
143
|
+
|
|
144
|
+
const inlineHandler = 'on' + eventName;
|
|
145
|
+
if(!element[inlineHandler] && !options) {
|
|
146
|
+
element[inlineHandler] = handler;
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
|
|
163
150
|
element.addEventListener(eventName, handler, options);
|
|
164
151
|
return this;
|
|
165
152
|
};
|
|
@@ -170,6 +157,11 @@ const _preventStop = function(element, eventName, callback, options) {
|
|
|
170
157
|
event.preventDefault();
|
|
171
158
|
callback && callback.call(element, event);
|
|
172
159
|
};
|
|
160
|
+
const inlineHandler = 'on' + eventName;
|
|
161
|
+
if(!element[inlineHandler] && !options) {
|
|
162
|
+
element[inlineHandler] = handler;
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
173
165
|
element.addEventListener(eventName, handler, options);
|
|
174
166
|
return this;
|
|
175
167
|
};
|
|
@@ -3,19 +3,19 @@ export const BOOLEAN_ATTRIBUTES = new Set([
|
|
|
3
3
|
'checked',
|
|
4
4
|
'selected',
|
|
5
5
|
'disabled',
|
|
6
|
-
'readonly',
|
|
6
|
+
'readonly', 'readOnly',
|
|
7
7
|
'required',
|
|
8
|
-
'autofocus',
|
|
8
|
+
'autofocus', 'autoFocus',
|
|
9
9
|
'multiple',
|
|
10
|
-
'autocomplete',
|
|
10
|
+
'autocomplete', 'autoComplete',
|
|
11
11
|
'hidden',
|
|
12
|
-
'contenteditable',
|
|
13
|
-
'spellcheck',
|
|
12
|
+
'contenteditable', 'contentEditable',
|
|
13
|
+
'spellcheck', 'spellCheck',
|
|
14
14
|
'translate',
|
|
15
15
|
'draggable',
|
|
16
16
|
'async',
|
|
17
17
|
'defer',
|
|
18
|
-
'autoplay',
|
|
18
|
+
'autoplay', 'autoPlay',
|
|
19
19
|
'controls',
|
|
20
20
|
'loop',
|
|
21
21
|
'muted',
|
|
@@ -23,13 +23,13 @@ export const BOOLEAN_ATTRIBUTES = new Set([
|
|
|
23
23
|
'reversed',
|
|
24
24
|
'open',
|
|
25
25
|
'default',
|
|
26
|
-
'formnovalidate',
|
|
27
|
-
'novalidate',
|
|
26
|
+
'formnovalidate', 'formNoValidate',
|
|
27
|
+
'novalidate', 'noValidate',
|
|
28
28
|
'scoped',
|
|
29
|
-
'itemscope',
|
|
30
|
-
'allowfullscreen',
|
|
31
|
-
'allowpaymentrequest',
|
|
32
|
-
'playsinline',
|
|
29
|
+
'itemscope', 'itemScope',
|
|
30
|
+
'allowfullscreen', 'allowFullscreen',
|
|
31
|
+
'allowpaymentrequest', 'allowPaymentRequest',
|
|
32
|
+
'playsinline', 'playsInline',
|
|
33
33
|
]);
|
|
34
34
|
|
|
35
35
|
export const BOOL_ATTRIBUTES_NAME = {
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
} from '../AttributesWrapper';
|
|
5
|
-
import ObservableItem from '../../data/ObservableItem';
|
|
6
|
-
import TemplateBinding from '../TemplateBinding';
|
|
7
|
-
import {BOOLEAN_ATTRIBUTES} from '../constants';
|
|
8
|
-
import ObservableChecker from '../../data/ObservableChecker';
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
ObservableItem.prototype.handleNdAttribute = function(element, attributeName) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
ObservableChecker.prototype.handleNdAttribute = ObservableItem.prototype.handleNdAttribute;
|
|
21
|
-
|
|
22
|
-
TemplateBinding.prototype.handleNdAttribute = function(element, attributeName) {
|
|
23
|
-
|
|
24
|
-
};
|
|
1
|
+
// import {
|
|
2
|
+
// bindAttributeWithObservable,
|
|
3
|
+
// bindBooleanAttribute,
|
|
4
|
+
// } from '../AttributesWrapper';
|
|
5
|
+
// import ObservableItem from '../../data/ObservableItem';
|
|
6
|
+
// import TemplateBinding from '../TemplateBinding';
|
|
7
|
+
// import {BOOLEAN_ATTRIBUTES} from '../constants';
|
|
8
|
+
// import ObservableChecker from '../../data/ObservableChecker';
|
|
9
|
+
//
|
|
10
|
+
//
|
|
11
|
+
// ObservableItem.prototype.handleNdAttribute = function(element, attributeName) {
|
|
12
|
+
// if(BOOLEAN_ATTRIBUTES.has(attributeName)) {
|
|
13
|
+
// bindBooleanAttribute(element, attributeName, this);
|
|
14
|
+
// return;
|
|
15
|
+
// }
|
|
16
|
+
//
|
|
17
|
+
// bindAttributeWithObservable(element, attributeName, this);
|
|
18
|
+
// };
|
|
19
|
+
//
|
|
20
|
+
// ObservableChecker.prototype.handleNdAttribute = ObservableItem.prototype.handleNdAttribute;
|
|
21
|
+
//
|
|
22
|
+
// TemplateBinding.prototype.handleNdAttribute = function(element, attributeName) {
|
|
23
|
+
// this.$hydrate(element, attributeName);
|
|
24
|
+
// };
|