@schukai/monster 3.102.5 → 3.103.0
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 +49 -0
- package/package.json +1 -1
- package/source/components/datatable/dataset.mjs +1 -1
- package/source/components/datatable/filter/select.mjs +3 -3
- package/source/components/datatable/filter.mjs +21 -2
- package/source/components/datatable/save-button.mjs +1 -0
- package/source/components/form/select.mjs +2221 -2193
- package/source/dom/customcontrol.mjs +318 -321
- package/source/dom/updater.mjs +146 -89
- package/source/types/version.mjs +1 -1
- package/test/cases/monster.mjs +1 -1
- package/test/web/test.html +2 -2
- package/test/web/tests.js +503 -456
@@ -12,15 +12,15 @@
|
|
12
12
|
* SPDX-License-Identifier: AGPL-3.0
|
13
13
|
*/
|
14
14
|
|
15
|
-
import {extend} from "../data/extend.mjs";
|
16
|
-
import {addAttributeToken} from "./attributes.mjs";
|
17
|
-
import {ATTRIBUTE_ERRORMESSAGE} from "./constants.mjs";
|
18
|
-
import {CustomElement, attributeObserverSymbol} from "./customelement.mjs";
|
19
|
-
import {instanceSymbol} from "../constants.mjs";
|
20
|
-
import {DeadMansSwitch} from "../util/deadmansswitch.mjs";
|
21
|
-
import {addErrorAttribute} from "./error.mjs";
|
15
|
+
import { extend } from "../data/extend.mjs";
|
16
|
+
import { addAttributeToken } from "./attributes.mjs";
|
17
|
+
import { ATTRIBUTE_ERRORMESSAGE } from "./constants.mjs";
|
18
|
+
import { CustomElement, attributeObserverSymbol } from "./customelement.mjs";
|
19
|
+
import { instanceSymbol } from "../constants.mjs";
|
20
|
+
import { DeadMansSwitch } from "../util/deadmansswitch.mjs";
|
21
|
+
import { addErrorAttribute } from "./error.mjs";
|
22
22
|
|
23
|
-
export {CustomControl};
|
23
|
+
export { CustomControl };
|
24
24
|
|
25
25
|
/**
|
26
26
|
* @private
|
@@ -53,286 +53,285 @@ const attachedInternalSymbol = Symbol("attachedInternal");
|
|
53
53
|
* @since 1.14.0
|
54
54
|
*/
|
55
55
|
class CustomControl extends CustomElement {
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
}
|
56
|
+
/**
|
57
|
+
* The constructor method of CustomControl, which is called when creating a new instance.
|
58
|
+
* It checks whether the element supports `attachInternals()` and initializes an internal form-associated element
|
59
|
+
* if supported. Additionally, it initializes a MutationObserver to watch for attribute changes.
|
60
|
+
*
|
61
|
+
* See the links below for more information:
|
62
|
+
* {@link https://html.spec.whatwg.org/multipage/custom-elements.html#dom-customelementregistry-define|CustomElementRegistry.define()}
|
63
|
+
* {@link https://html.spec.whatwg.org/multipage/custom-elements.html#dom-customelementregistry-get|CustomElementRegistry.get()}
|
64
|
+
* and {@link https://developer.mozilla.org/en-US/docs/Web/API/ElementInternals|ElementInternals}
|
65
|
+
*
|
66
|
+
* @inheritdoc
|
67
|
+
* @throws {Error} the ElementInternals is not supported and a polyfill is necessary
|
68
|
+
*/
|
69
|
+
constructor() {
|
70
|
+
super();
|
71
|
+
|
72
|
+
// check if element supports `attachInternals()`
|
73
|
+
if (typeof this["attachInternals"] === "function") {
|
74
|
+
this[attachedInternalSymbol] = this.attachInternals();
|
75
|
+
} else {
|
76
|
+
// `attachInternals()` is not supported, so a polyfill is necessary
|
77
|
+
throw Error(
|
78
|
+
"the ElementInternals is not supported and a polyfill is necessary",
|
79
|
+
);
|
80
|
+
}
|
81
|
+
|
82
|
+
// watch for attribute value changes
|
83
|
+
initValueAttributeObserver.call(this);
|
84
|
+
}
|
85
|
+
|
86
|
+
/**
|
87
|
+
* This method is called by the `instanceof` operator.
|
88
|
+
* @return {symbol}
|
89
|
+
* @since 2.1.0
|
90
|
+
*/
|
91
|
+
static get [instanceSymbol]() {
|
92
|
+
return Symbol.for("@schukai/monster/dom/custom-control@@instance");
|
93
|
+
}
|
94
|
+
|
95
|
+
/**
|
96
|
+
* This method determines which attributes are to be monitored by `attributeChangedCallback()`.
|
97
|
+
*
|
98
|
+
* @return {string[]}
|
99
|
+
* @since 1.15.0
|
100
|
+
*/
|
101
|
+
static get observedAttributes() {
|
102
|
+
return super.observedAttributes;
|
103
|
+
}
|
104
|
+
|
105
|
+
/**
|
106
|
+
* Adding a static `formAssociated` property, with a true value, makes an autonomous custom element a form-associated custom element.
|
107
|
+
*
|
108
|
+
* @see [attachInternals()]{@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/attachInternals}
|
109
|
+
* @see [Custom Elements Face Example]{@link https://html.spec.whatwg.org/multipage/custom-elements.html#custom-elements-face-example}
|
110
|
+
* @return {boolean}
|
111
|
+
*/
|
112
|
+
static formAssociated = true;
|
113
|
+
|
114
|
+
/**
|
115
|
+
* @inheritdoc
|
116
|
+
**/
|
117
|
+
get defaults() {
|
118
|
+
return extend({}, super.defaults);
|
119
|
+
}
|
120
|
+
|
121
|
+
/**
|
122
|
+
* Must be overridden by a derived class and return the value of the control.
|
123
|
+
*
|
124
|
+
* This is a method of [internal API](https://developer.mozilla.org/en-US/docs/Web/API/ElementInternals), which is a part of the web standard for custom elements.
|
125
|
+
*
|
126
|
+
* @throws {Error} the value getter must be overwritten by the derived class
|
127
|
+
*/
|
128
|
+
get value() {
|
129
|
+
throw Error("the value getter must be overwritten by the derived class");
|
130
|
+
}
|
131
|
+
|
132
|
+
/**
|
133
|
+
* Must be overridden by a derived class and set the value of the control.
|
134
|
+
*
|
135
|
+
* This is a method of [internal API](https://developer.mozilla.org/en-US/docs/Web/API/ElementInternals), which is a part of the web standard for custom elements.
|
136
|
+
*
|
137
|
+
* @param {*} value The value to set.
|
138
|
+
* @throws {Error} the value setter must be overwritten by the derived class
|
139
|
+
*/
|
140
|
+
set value(value) {
|
141
|
+
throw Error("the value setter must be overwritten by the derived class");
|
142
|
+
}
|
143
|
+
|
144
|
+
/**
|
145
|
+
* This is a method of [internal api](https://developer.mozilla.org/en-US/docs/Web/API/ElementInternals)
|
146
|
+
*
|
147
|
+
* @return {NodeList}
|
148
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/ElementInternals/labels}
|
149
|
+
* @throws {Error} the ElementInternals is not supported and a polyfill is necessary
|
150
|
+
*/
|
151
|
+
get labels() {
|
152
|
+
return getInternal.call(this)?.labels;
|
153
|
+
}
|
154
|
+
|
155
|
+
/**
|
156
|
+
* This is a method of [internal api](https://developer.mozilla.org/en-US/docs/Web/API/ElementInternals)
|
157
|
+
*
|
158
|
+
* @return {string|null}
|
159
|
+
*/
|
160
|
+
get name() {
|
161
|
+
return this.getAttribute("name");
|
162
|
+
}
|
163
|
+
|
164
|
+
/**
|
165
|
+
* This is a method of [internal api](https://developer.mozilla.org/en-US/docs/Web/API/ElementInternals)
|
166
|
+
*
|
167
|
+
* @return {string}
|
168
|
+
*/
|
169
|
+
get type() {
|
170
|
+
return this.constructor.getTag();
|
171
|
+
}
|
172
|
+
|
173
|
+
/**
|
174
|
+
* This is a method of [internal api](https://developer.mozilla.org/en-US/docs/Web/API/ElementInternals)
|
175
|
+
*
|
176
|
+
* @return {ValidityState}
|
177
|
+
* @throws {Error} the ElementInternals is not supported and a polyfill is necessary
|
178
|
+
* @see [ValidityState]{@link https://developer.mozilla.org/en-US/docs/Web/API/ValidityState}
|
179
|
+
* @see [validity]{@link https://developer.mozilla.org/en-US/docs/Web/API/validity}
|
180
|
+
*/
|
181
|
+
get validity() {
|
182
|
+
return getInternal.call(this)?.validity;
|
183
|
+
}
|
184
|
+
|
185
|
+
/**
|
186
|
+
* This is a method of [internal api](https://developer.mozilla.org/en-US/docs/Web/API/ElementInternals)
|
187
|
+
*
|
188
|
+
* @return {string}
|
189
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/ElementInternals/validationMessage
|
190
|
+
* @throws {Error} the ElementInternals is not supported and a polyfill is necessary
|
191
|
+
*/
|
192
|
+
get validationMessage() {
|
193
|
+
return getInternal.call(this)?.validationMessage;
|
194
|
+
}
|
195
|
+
|
196
|
+
/**
|
197
|
+
* This is a method of [internal api](https://developer.mozilla.org/en-US/docs/Web/API/ElementInternals)
|
198
|
+
*
|
199
|
+
* @return {boolean}
|
200
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/ElementInternals/willValidate
|
201
|
+
* @throws {Error} the ElementInternals is not supported and a polyfill is necessary
|
202
|
+
*/
|
203
|
+
get willValidate() {
|
204
|
+
return getInternal.call(this)?.willValidate;
|
205
|
+
}
|
206
|
+
|
207
|
+
/**
|
208
|
+
* This is a method of [internal api](https://developer.mozilla.org/en-US/docs/Web/API/ElementInternals)
|
209
|
+
*
|
210
|
+
* @return {boolean}
|
211
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/ElementInternals/states
|
212
|
+
* @throws {Error} the ElementInternals is not supported and a polyfill is necessary
|
213
|
+
*/
|
214
|
+
get states() {
|
215
|
+
return getInternal.call(this)?.states;
|
216
|
+
}
|
217
|
+
|
218
|
+
/**
|
219
|
+
* This is a method of [internal api](https://developer.mozilla.org/en-US/docs/Web/API/ElementInternals)
|
220
|
+
*
|
221
|
+
* @return {HTMLFontElement|null}
|
222
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/ElementInternals/form
|
223
|
+
* @throws {Error} the ElementInternals is not supported and a polyfill is necessary
|
224
|
+
*/
|
225
|
+
get form() {
|
226
|
+
return getInternal.call(this)?.form;
|
227
|
+
}
|
228
|
+
|
229
|
+
/**
|
230
|
+
* This is a method of [internal api](https://developer.mozilla.org/en-US/docs/Web/API/ElementInternals)
|
231
|
+
*
|
232
|
+
* ```
|
233
|
+
* // Use the control's name as the base name for submitted data
|
234
|
+
* const n = this.getAttribute('name');
|
235
|
+
* const entries = new FormData();
|
236
|
+
* entries.append(n + '-first-name', this.firstName_);
|
237
|
+
* entries.append(n + '-last-name', this.lastName_);
|
238
|
+
* this.setFormValue(entries);
|
239
|
+
* ```
|
240
|
+
*
|
241
|
+
* @param {File|string|FormData} value
|
242
|
+
* @param {File|string|FormData} state
|
243
|
+
* @return {undefined}
|
244
|
+
* @throws {DOMException} NotSupportedError
|
245
|
+
* @throws {Error} the ElementInternals is not supported and a polyfill is necessary
|
246
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/ElementInternals/setFormValue
|
247
|
+
*/
|
248
|
+
setFormValue(value, state) {
|
249
|
+
getInternal.call(this).setFormValue(value, state);
|
250
|
+
}
|
251
|
+
|
252
|
+
/**
|
253
|
+
*
|
254
|
+
* @param {object} flags
|
255
|
+
* @param {string|undefined} message
|
256
|
+
* @param {HTMLElement} anchor
|
257
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/ElementInternals/setValidity
|
258
|
+
* @return {undefined}
|
259
|
+
* @throws {DOMException} NotSupportedError
|
260
|
+
* @throws {Error} the ElementInternals is not supported and a polyfill is necessary
|
261
|
+
*/
|
262
|
+
setValidity(flags, message, anchor) {
|
263
|
+
getInternal.call(this).setValidity(flags, message, anchor);
|
264
|
+
}
|
265
|
+
|
266
|
+
/**
|
267
|
+
* This is a method of [internal api](https://developer.mozilla.org/en-US/docs/Web/API/ElementInternals)
|
268
|
+
*
|
269
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/ElementInternals/checkValidity
|
270
|
+
* @return {boolean}
|
271
|
+
* @throws {DOMException} NotSupportedError
|
272
|
+
* @throws {Error} the ElementInternals is not supported and a polyfill is necessary
|
273
|
+
*/
|
274
|
+
checkValidity() {
|
275
|
+
return getInternal.call(this)?.checkValidity();
|
276
|
+
}
|
277
|
+
|
278
|
+
/**
|
279
|
+
* This is a method of [internal api](https://developer.mozilla.org/en-US/docs/Web/API/ElementInternals)
|
280
|
+
*
|
281
|
+
* @return {boolean}
|
282
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/ElementInternals/reportValidity
|
283
|
+
* @throws {Error} the ElementInternals is not supported and a polyfill is necessary
|
284
|
+
* @throws {DOMException} NotSupportedError
|
285
|
+
*/
|
286
|
+
reportValidity() {
|
287
|
+
return getInternal.call(this)?.reportValidity();
|
288
|
+
}
|
289
|
+
|
290
|
+
/**
|
291
|
+
* Sets the `form` attribute of the custom control to the `id` of the passed form element.
|
292
|
+
* If no form element is passed, removes the `form` attribute.
|
293
|
+
*
|
294
|
+
* @param {HTMLFormElement} form - The form element to associate with the control
|
295
|
+
*/
|
296
|
+
formAssociatedCallback(form) {
|
297
|
+
if (form) {
|
298
|
+
if (form.id) {
|
299
|
+
this.setAttribute("form", form.id);
|
300
|
+
}
|
301
|
+
} else {
|
302
|
+
this.removeAttribute("form");
|
303
|
+
}
|
304
|
+
}
|
305
|
+
|
306
|
+
/**
|
307
|
+
* Sets or removes the `disabled` attribute of the custom control based on the passed value.
|
308
|
+
*
|
309
|
+
* @param {boolean} disabled - Whether or not the control should be disabled
|
310
|
+
*/
|
311
|
+
formDisabledCallback(disabled) {
|
312
|
+
if (disabled) {
|
313
|
+
if (!this.hasAttribute("disabled")) {
|
314
|
+
this.setAttribute("disabled", "");
|
315
|
+
}
|
316
|
+
} else {
|
317
|
+
if (this.hasAttribute("disabled")) {
|
318
|
+
this.removeAttribute("disabled");
|
319
|
+
}
|
320
|
+
}
|
321
|
+
}
|
322
|
+
|
323
|
+
/**
|
324
|
+
* @param {string} state
|
325
|
+
* @param {string} mode
|
326
|
+
*/
|
327
|
+
formStateRestoreCallback(state, mode) {}
|
328
|
+
|
329
|
+
/**
|
330
|
+
*
|
331
|
+
*/
|
332
|
+
formResetCallback() {
|
333
|
+
this.value = "";
|
334
|
+
}
|
336
335
|
}
|
337
336
|
|
338
337
|
/**
|
@@ -342,13 +341,13 @@ class CustomControl extends CustomElement {
|
|
342
341
|
* @this CustomControl
|
343
342
|
*/
|
344
343
|
function getInternal() {
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
344
|
+
if (!(attachedInternalSymbol in this)) {
|
345
|
+
throw new Error(
|
346
|
+
"ElementInternals is not supported and a polyfill is necessary",
|
347
|
+
);
|
348
|
+
}
|
350
349
|
|
351
|
-
|
350
|
+
return this[attachedInternalSymbol];
|
352
351
|
}
|
353
352
|
|
354
353
|
const debounceValueSymbol = Symbol("debounceValue");
|
@@ -362,31 +361,29 @@ const debounceValueSymbol = Symbol("debounceValue");
|
|
362
361
|
* @this CustomControl
|
363
362
|
*/
|
364
363
|
function initValueAttributeObserver() {
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
});
|
391
|
-
};
|
364
|
+
const self = this;
|
365
|
+
this[attributeObserverSymbol]["value"] = () => {
|
366
|
+
if (self[debounceValueSymbol] instanceof DeadMansSwitch) {
|
367
|
+
try {
|
368
|
+
self[debounceValueSymbol].touch();
|
369
|
+
return;
|
370
|
+
} catch (e) {
|
371
|
+
if (e.message !== "has already run") {
|
372
|
+
throw e;
|
373
|
+
}
|
374
|
+
delete self[debounceValueSymbol];
|
375
|
+
}
|
376
|
+
}
|
377
|
+
|
378
|
+
self[debounceValueSymbol] = new DeadMansSwitch(10, () => {
|
379
|
+
const oldValue = self.getAttribute("value");
|
380
|
+
const newValue = self.getOption("value");
|
381
|
+
|
382
|
+
if (oldValue !== newValue) {
|
383
|
+
setTimeout(() => {
|
384
|
+
this.setOption("value", this.getAttribute("value"));
|
385
|
+
}, 0);
|
386
|
+
}
|
387
|
+
});
|
388
|
+
};
|
392
389
|
}
|