native-document 1.0.91 → 1.0.93
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/dist/native-document.components.min.js +1168 -138
- package/dist/native-document.dev.js +792 -217
- 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/docs/advanced-components.md +814 -0
- package/docs/anchor.md +71 -11
- package/docs/cache.md +888 -0
- package/docs/conditional-rendering.md +91 -1
- package/docs/core-concepts.md +9 -2
- package/docs/elements.md +127 -2
- package/docs/extending-native-document-element.md +7 -1
- package/docs/filters.md +1216 -0
- package/docs/getting-started.md +12 -3
- package/docs/lifecycle-events.md +10 -2
- package/docs/list-rendering.md +453 -54
- package/docs/memory-management.md +9 -7
- package/docs/native-document-element.md +30 -9
- package/docs/native-fetch.md +744 -0
- package/docs/observables.md +135 -6
- package/docs/routing.md +7 -1
- package/docs/state-management.md +7 -1
- package/docs/validation.md +8 -1
- package/eslint.config.js +3 -3
- package/package.json +3 -2
- package/readme.md +53 -14
- package/src/components/$traits/HasItems.js +42 -1
- package/src/components/BaseComponent.js +4 -1
- package/src/components/accordion/Accordion.js +112 -8
- package/src/components/accordion/AccordionItem.js +93 -4
- package/src/components/alert/Alert.js +164 -4
- package/src/components/avatar/Avatar.js +236 -22
- package/src/components/menu/index.js +1 -2
- package/src/core/data/ObservableArray.js +120 -2
- package/src/core/data/ObservableChecker.js +50 -0
- package/src/core/data/ObservableItem.js +223 -80
- package/src/core/data/ObservableWhen.js +36 -6
- package/src/core/data/observable-helpers/array.js +12 -3
- package/src/core/data/observable-helpers/computed.js +17 -4
- package/src/core/data/observable-helpers/object.js +19 -3
- package/src/core/elements/control/for-each-array.js +21 -3
- package/src/core/elements/control/for-each.js +17 -5
- package/src/core/elements/control/show-if.js +31 -15
- package/src/core/elements/control/show-when.js +23 -0
- package/src/core/elements/control/switch.js +40 -10
- package/src/core/utils/cache.js +5 -0
- package/src/core/utils/memoize.js +25 -16
- package/src/core/utils/prototypes.js +3 -2
- package/src/core/wrappers/AttributesWrapper.js +1 -1
- package/src/core/wrappers/NDElement.js +41 -1
- package/src/core/wrappers/NdPrototype.js +4 -0
- package/src/core/wrappers/TemplateCloner.js +13 -10
- package/src/core/wrappers/prototypes/bind-class-extensions.js +1 -1
- package/src/core/wrappers/prototypes/nd-element-extensions.js +3 -0
- package/src/router/Route.js +9 -4
- package/src/router/Router.js +28 -9
- package/src/router/errors/RouterError.js +0 -1
- package/types/control-flow.d.ts +9 -6
- package/types/elements.d.ts +6 -3
- package/types/filters/index.d.ts +4 -0
- package/types/nd-element.d.ts +5 -238
- package/types/observable.d.ts +9 -3
- package/types/router.d.ts +5 -1
- package/types/template-cloner.ts +1 -0
- package/types/validator.ts +11 -1
- package/utils.d.ts +2 -1
- package/utils.js +4 -4
- package/src/core/utils/service.js +0 -6
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
import BaseComponent from "../BaseComponent";
|
|
2
2
|
import EventEmitter from "../../../src/core/utils/EventEmitter";
|
|
3
3
|
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Valid children types that can be rendered in the DOM
|
|
7
|
+
* @typedef {HTMLElement|Text|DocumentFragment|string|Array<ValidChildren>} ValidChildren
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Component for creating accordion interfaces with expandable/collapsible items
|
|
12
|
+
* @param {{ items?: Array<AccordionItem>, multiple?: boolean, variant?: string, renderContent?: (field: Accordion) => HTMLElement }} config
|
|
13
|
+
* @returns {Accordion}
|
|
14
|
+
* @class
|
|
15
|
+
*/
|
|
4
16
|
export default function Accordion(config = {}) {
|
|
5
17
|
if (!(this instanceof Accordion)) {
|
|
6
18
|
return new Accordion(config);
|
|
@@ -19,20 +31,47 @@ BaseComponent.extends(Accordion, EventEmitter);
|
|
|
19
31
|
|
|
20
32
|
Accordion.defaultTemplate = null;
|
|
21
33
|
|
|
22
|
-
Accordion.use = function(template) {};
|
|
23
34
|
|
|
35
|
+
/**
|
|
36
|
+
* Sets the default template for all Accordion instances
|
|
37
|
+
* @param {{accordion: (accordion: Accordion) => ValidChildren}} template - Template object containing accordion factory function
|
|
38
|
+
*/
|
|
39
|
+
Accordion.use = function(template) {
|
|
40
|
+
Accordion.defaultTemplate = template.accordion;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Adds an accordion item to the collection
|
|
45
|
+
* @param {AccordionItem} accordionItem - The accordion item to add
|
|
46
|
+
* @returns {Accordion}
|
|
47
|
+
*/
|
|
24
48
|
Accordion.prototype.item = function(accordionItem) {
|
|
25
49
|
this.$description.items.push(accordionItem);
|
|
26
50
|
return this;
|
|
27
51
|
};
|
|
28
52
|
|
|
53
|
+
/**
|
|
54
|
+
* Sets the accordion items collection
|
|
55
|
+
* @param {Array<AccordionItem>} items - Array of accordion items
|
|
56
|
+
* @returns {Accordion}
|
|
57
|
+
*/
|
|
29
58
|
Accordion.prototype.items = function(items) {
|
|
30
59
|
this.$description.items = items;
|
|
31
60
|
return this;
|
|
32
61
|
};
|
|
33
62
|
|
|
63
|
+
/**
|
|
64
|
+
* Alias for item method
|
|
65
|
+
* @param {AccordionItem} accordionItem - The accordion item to add
|
|
66
|
+
* @returns {Accordion}
|
|
67
|
+
*/
|
|
34
68
|
Accordion.prototype.addItem = Accordion.prototype.item;
|
|
35
69
|
|
|
70
|
+
/**
|
|
71
|
+
* Removes an item by its id
|
|
72
|
+
* @param {string} id - The id of the item to remove
|
|
73
|
+
* @returns {Accordion}
|
|
74
|
+
*/
|
|
36
75
|
Accordion.prototype.removeItemById = function(id) {
|
|
37
76
|
if (this.$description.items) {
|
|
38
77
|
this.$description.items = this.$description.items.filter(item => item.id !== id);
|
|
@@ -40,40 +79,77 @@ Accordion.prototype.removeItemById = function(id) {
|
|
|
40
79
|
return this;
|
|
41
80
|
};
|
|
42
81
|
|
|
43
|
-
|
|
82
|
+
/**
|
|
83
|
+
* Removes items matching the filter function
|
|
84
|
+
* @param {Function} filter - Filter function to determine which items to keep
|
|
85
|
+
* @returns {Accordion}
|
|
86
|
+
*/
|
|
87
|
+
Accordion.prototype.remove = function(filter) {
|
|
44
88
|
if (this.$description.items) {
|
|
45
|
-
this.$description.items = this.$description.items.filter(
|
|
89
|
+
this.$description.items = this.$description.items.filter(filter);
|
|
46
90
|
}
|
|
47
91
|
return this;
|
|
48
92
|
};
|
|
49
93
|
|
|
50
|
-
|
|
94
|
+
/**
|
|
95
|
+
* Enables or disables multiple items expansion
|
|
96
|
+
* @param {boolean} [enabled=true] - Whether multiple items can be expanded simultaneously
|
|
97
|
+
* @returns {Accordion}
|
|
98
|
+
*/
|
|
51
99
|
Accordion.prototype.multiple = function(enabled = true) {
|
|
52
100
|
this.$description.multiple = enabled;
|
|
53
101
|
return this;
|
|
54
102
|
};
|
|
55
103
|
|
|
104
|
+
/**
|
|
105
|
+
* Sets the variant style for the accordion
|
|
106
|
+
* @param {string} name - The variant name
|
|
107
|
+
* @returns {Accordion}
|
|
108
|
+
*/
|
|
56
109
|
Accordion.prototype.variant = function(name) {
|
|
57
110
|
this.$description.variant = name;
|
|
58
111
|
return this;
|
|
59
112
|
};
|
|
60
113
|
|
|
114
|
+
/**
|
|
115
|
+
* Sets the accordion variant to 'bordered'
|
|
116
|
+
* @returns {Accordion}
|
|
117
|
+
*/
|
|
61
118
|
Accordion.prototype.bordered = function() {
|
|
62
119
|
return this.variant('bordered');
|
|
63
120
|
};
|
|
64
121
|
|
|
122
|
+
/**
|
|
123
|
+
* Sets the accordion variant to 'separated'
|
|
124
|
+
* @returns {Accordion}
|
|
125
|
+
*/
|
|
65
126
|
Accordion.prototype.separated = function() {
|
|
66
127
|
return this.variant('separated');
|
|
67
128
|
};
|
|
68
129
|
|
|
130
|
+
/**
|
|
131
|
+
* Sets the accordion variant to 'flush'
|
|
132
|
+
* @returns {Accordion}
|
|
133
|
+
*/
|
|
69
134
|
Accordion.prototype.flush = function() {
|
|
70
135
|
return this.variant('flush');
|
|
71
136
|
};
|
|
72
137
|
|
|
138
|
+
/**
|
|
139
|
+
* Retrieves an accordion item by its key
|
|
140
|
+
* @param {string} key - The key of the item to retrieve
|
|
141
|
+
* @returns {AccordionItem|undefined}
|
|
142
|
+
*/
|
|
73
143
|
Accordion.prototype.getByKey = function(key) {
|
|
74
144
|
return this.$description.items.find(item => item.key === key);
|
|
75
145
|
};
|
|
76
146
|
|
|
147
|
+
/**
|
|
148
|
+
* Expands or collapses an accordion item by key
|
|
149
|
+
* @param {string} key - The key of the item
|
|
150
|
+
* @param {boolean} [state=true] - Whether to expand (true) or collapse (false)
|
|
151
|
+
* @returns {Accordion}
|
|
152
|
+
*/
|
|
77
153
|
Accordion.prototype.expanded = function(key, state = true) {
|
|
78
154
|
const item = this.getByKey(key);
|
|
79
155
|
if(item) {
|
|
@@ -86,35 +162,67 @@ Accordion.prototype.expanded = function(key, state = true) {
|
|
|
86
162
|
return this;
|
|
87
163
|
};
|
|
88
164
|
|
|
165
|
+
/**
|
|
166
|
+
* Expands all accordion items
|
|
167
|
+
* @returns {Accordion}
|
|
168
|
+
*/
|
|
89
169
|
Accordion.prototype.expandAll = function() {
|
|
90
170
|
this.$description.items.forEach(item => item.expanded(true));
|
|
91
171
|
return this;
|
|
92
172
|
};
|
|
93
173
|
|
|
174
|
+
/**
|
|
175
|
+
* Collapses all accordion items
|
|
176
|
+
* @returns {Accordion}
|
|
177
|
+
*/
|
|
94
178
|
Accordion.prototype.collapseAll = function() {
|
|
95
179
|
this.$description.items.forEach(item => item.expanded(false));
|
|
96
180
|
return this;
|
|
97
181
|
};
|
|
98
182
|
|
|
183
|
+
/**
|
|
184
|
+
* Checks if an accordion item is expanded
|
|
185
|
+
* @param {string} key - The key of the item to check
|
|
186
|
+
* @returns {boolean|undefined}
|
|
187
|
+
*/
|
|
99
188
|
Accordion.prototype.isExpanded = function(key) {
|
|
100
189
|
return this.getByKey(key)?.isExpanded?.();
|
|
101
190
|
};
|
|
102
191
|
|
|
192
|
+
/**
|
|
193
|
+
* Registers a handler for the expand event
|
|
194
|
+
* @param {Function} handler - The event handler
|
|
195
|
+
* @returns {Accordion}
|
|
196
|
+
*/
|
|
103
197
|
Accordion.prototype.onExpand = function(handler) {
|
|
104
198
|
this.on('expand', handler);
|
|
105
199
|
return this;
|
|
106
200
|
};
|
|
107
201
|
|
|
202
|
+
/**
|
|
203
|
+
* Registers a handler for the collapse event
|
|
204
|
+
* @param {Function} handler - The event handler
|
|
205
|
+
* @returns {Accordion}
|
|
206
|
+
*/
|
|
108
207
|
Accordion.prototype.onCollapse = function(handler) {
|
|
109
208
|
this.on('collapse', handler);
|
|
110
209
|
return this;
|
|
111
210
|
};
|
|
112
211
|
|
|
212
|
+
/**
|
|
213
|
+
* Sets the content render function
|
|
214
|
+
* @param {Function} renderFn - Function to render content
|
|
215
|
+
* @returns {Accordion}
|
|
216
|
+
*/
|
|
113
217
|
Accordion.prototype.renderContent = function(renderFn) {
|
|
114
218
|
this.$description.renderContent = renderFn;
|
|
115
219
|
return this;
|
|
116
220
|
};
|
|
117
221
|
|
|
222
|
+
/**
|
|
223
|
+
* Builds the accordion component
|
|
224
|
+
* @private
|
|
225
|
+
*/
|
|
118
226
|
Accordion.prototype.$build = function() {
|
|
119
227
|
// TODO: Implementation
|
|
120
228
|
// this.$description.items.forEach(item => {
|
|
@@ -126,8 +234,4 @@ Accordion.prototype.$build = function() {
|
|
|
126
234
|
// }
|
|
127
235
|
// });
|
|
128
236
|
// });
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
Accordion.prototype.toNdElement = function() {
|
|
132
|
-
return this.$build();
|
|
133
237
|
};
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { $ } from '../../../index';
|
|
2
2
|
import BaseComponent from "../BaseComponent";
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Represents an individual item within an Accordion component
|
|
6
|
+
* @param {{ id?: string|number, title?: string, icon?: string, collapsible?: boolean, content?: ValidChildren, renderHeader?: Function, renderContent?: Function, render?: Function, expanded?: Observable<boolean>, disabled?: boolean }} config - Configuration object
|
|
7
|
+
* @class
|
|
8
|
+
*/
|
|
4
9
|
export default function AccordionItem(config = {}) {
|
|
5
10
|
if(!(this instanceof AccordionItem)){
|
|
6
11
|
return new AccordionItem()
|
|
@@ -23,42 +28,81 @@ export default function AccordionItem(config = {}) {
|
|
|
23
28
|
|
|
24
29
|
BaseComponent.extends(AccordionItem);
|
|
25
30
|
|
|
31
|
+
/**
|
|
32
|
+
* Gets the id of the accordion item
|
|
33
|
+
* @type {string}
|
|
34
|
+
*/
|
|
26
35
|
Object.defineProperty(AccordionItem.prototype, 'id', {
|
|
27
36
|
get() {
|
|
28
37
|
this.$description.id;
|
|
29
38
|
}
|
|
30
39
|
});
|
|
31
40
|
|
|
41
|
+
/**
|
|
42
|
+
* Sets the identifier for the accordion item
|
|
43
|
+
* @param {string|number} id - The unique identifier
|
|
44
|
+
* @returns {AccordionItem}
|
|
45
|
+
*/
|
|
32
46
|
AccordionItem.prototype.identifyBy = function(id) {
|
|
33
47
|
this.$description.id = id;
|
|
34
48
|
return this;
|
|
35
49
|
};
|
|
36
50
|
|
|
51
|
+
/**
|
|
52
|
+
* Sets the content of the accordion item
|
|
53
|
+
* @param {ValidChildren} content - The content to display
|
|
54
|
+
* @returns {AccordionItem}
|
|
55
|
+
*/
|
|
37
56
|
AccordionItem.prototype.content = function(content) {
|
|
38
57
|
this.$description.content = content;
|
|
39
58
|
return this;
|
|
40
59
|
};
|
|
41
60
|
|
|
61
|
+
/**
|
|
62
|
+
* Sets the title of the accordion item
|
|
63
|
+
* @param {ValidChildren} title
|
|
64
|
+
* @returns {AccordionItem}
|
|
65
|
+
*/
|
|
42
66
|
AccordionItem.prototype.title = function(title) {
|
|
43
67
|
this.$description.title = title;
|
|
44
68
|
return this;
|
|
45
69
|
};
|
|
46
70
|
|
|
71
|
+
/**
|
|
72
|
+
* Sets the icon for the accordion item
|
|
73
|
+
* @param {ValidChildren} icon - The icon identifier or element
|
|
74
|
+
* @returns {AccordionItem}
|
|
75
|
+
*/
|
|
47
76
|
AccordionItem.prototype.icon = function(icon) {
|
|
48
77
|
this.$description.icon = icon;
|
|
49
78
|
return this;
|
|
50
79
|
};
|
|
51
80
|
|
|
81
|
+
/**
|
|
82
|
+
* Shows or hides the expansion indicator
|
|
83
|
+
* @param {boolean} [show=true] - Whether to show the indicator
|
|
84
|
+
* @returns {AccordionItem}
|
|
85
|
+
*/
|
|
52
86
|
AccordionItem.prototype.showIndicator = function(show = true) {
|
|
53
87
|
this.$description.showIndicator = show;
|
|
54
88
|
return this;
|
|
55
89
|
}
|
|
56
90
|
|
|
91
|
+
/**
|
|
92
|
+
* Sets whether the item can be collapsed
|
|
93
|
+
* @param {boolean} [collapsible=true] - Whether the item is collapsible
|
|
94
|
+
* @returns {AccordionItem}
|
|
95
|
+
*/
|
|
57
96
|
AccordionItem.prototype.collapsible = function(collapsible = true) {
|
|
58
97
|
this.$description.collapsible = collapsible;
|
|
59
98
|
return this;
|
|
60
99
|
};
|
|
61
100
|
|
|
101
|
+
/**
|
|
102
|
+
* Expands or collapses the accordion item
|
|
103
|
+
* @param {boolean} [expanded=true] - Whether to expand the item
|
|
104
|
+
* @returns {AccordionItem}
|
|
105
|
+
*/
|
|
62
106
|
AccordionItem.prototype.expanded = function(expanded = true) {
|
|
63
107
|
this.$description.expanded.set(expanded);
|
|
64
108
|
if (this.$description.expanded.val()) {
|
|
@@ -69,51 +113,96 @@ AccordionItem.prototype.expanded = function(expanded = true) {
|
|
|
69
113
|
return this;
|
|
70
114
|
};
|
|
71
115
|
|
|
116
|
+
/**
|
|
117
|
+
* Toggles the expanded state of the accordion item
|
|
118
|
+
* @returns {AccordionItem}
|
|
119
|
+
*/
|
|
72
120
|
AccordionItem.prototype.toggle = function() {
|
|
73
121
|
return this.expanded(!this.$description.expanded.val());
|
|
74
122
|
};
|
|
75
123
|
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Sets the disabled state of the accordion item
|
|
127
|
+
* @param {boolean} [disabled=true] - Whether the item is disabled
|
|
128
|
+
* @returns {AccordionItem}
|
|
129
|
+
*/
|
|
76
130
|
AccordionItem.prototype.disabled = function(disabled = true) {
|
|
77
131
|
this.$description.disabled = disabled;
|
|
78
132
|
return this;
|
|
79
133
|
};
|
|
80
134
|
|
|
135
|
+
/**
|
|
136
|
+
* Checks if the accordion item is currently expanded
|
|
137
|
+
* @returns {boolean}
|
|
138
|
+
*/
|
|
81
139
|
AccordionItem.prototype.isExpanded = function() {
|
|
82
140
|
return this.$description.expanded.val();
|
|
83
141
|
};
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Registers a handler for the expand event
|
|
145
|
+
* @param {Function} handler - The event handler
|
|
146
|
+
* @returns {AccordionItem}
|
|
147
|
+
*/
|
|
84
148
|
AccordionItem.prototype.onExpand = function(handler) {
|
|
85
149
|
this.on('expand', handler );
|
|
86
150
|
return this;
|
|
87
151
|
};
|
|
88
152
|
|
|
153
|
+
/**
|
|
154
|
+
* Registers a handler for the collapse event
|
|
155
|
+
* @param {Function} handler - The event handler
|
|
156
|
+
* @returns {AccordionItem}
|
|
157
|
+
*/
|
|
89
158
|
AccordionItem.prototype.onCollapse = function(handler) {
|
|
90
159
|
this.on('collapse', handler);
|
|
91
160
|
return this;
|
|
92
161
|
};
|
|
93
162
|
|
|
163
|
+
/**
|
|
164
|
+
* Sets the header render function
|
|
165
|
+
* @param {Function} renderFn - Function to render the header
|
|
166
|
+
* @returns {AccordionItem}
|
|
167
|
+
*/
|
|
94
168
|
AccordionItem.prototype.renderHeader = function(renderFn) {
|
|
95
169
|
this.$description.renderHeader = renderFn;
|
|
96
170
|
return this;
|
|
97
171
|
};
|
|
98
172
|
|
|
173
|
+
/**
|
|
174
|
+
* Sets the content render function
|
|
175
|
+
* @param {Function} renderFn - Function to render the content
|
|
176
|
+
* @returns {AccordionItem}
|
|
177
|
+
*/
|
|
99
178
|
AccordionItem.prototype.renderContent = function(renderFn) {
|
|
100
179
|
this.$description.renderContent = renderFn;
|
|
101
180
|
};
|
|
102
181
|
|
|
182
|
+
/**
|
|
183
|
+
* Sets the indicator render function
|
|
184
|
+
* @param {Function} renderFn - Function to render the indicator
|
|
185
|
+
* @returns {AccordionItem}
|
|
186
|
+
*/
|
|
103
187
|
AccordionItem.prototype.renderIndicator = function(renderFn) {
|
|
104
188
|
this.$description.renderIndicator = renderFn;
|
|
105
189
|
return this;
|
|
106
190
|
};
|
|
107
191
|
|
|
192
|
+
/**
|
|
193
|
+
* Sets the render function for the entire item
|
|
194
|
+
* @param {Function} renderFn - Function to render the item
|
|
195
|
+
* @returns {AccordionItem}
|
|
196
|
+
*/
|
|
108
197
|
AccordionItem.prototype.render = function(renderFn) {
|
|
109
198
|
this.$description.render = renderFn;
|
|
110
199
|
return this;
|
|
111
200
|
}
|
|
112
201
|
|
|
202
|
+
/**
|
|
203
|
+
* Builds the accordion item component
|
|
204
|
+
* @private
|
|
205
|
+
*/
|
|
113
206
|
AccordionItem.prototype.$build = function() {
|
|
114
207
|
|
|
115
208
|
};
|
|
116
|
-
|
|
117
|
-
AccordionItem.prototype.toNdElement = function() {
|
|
118
|
-
|
|
119
|
-
}
|