@schukai/monster 3.48.0 → 3.50.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/package.json +1 -1
- package/source/data/datasource/server/restapi/data-fetch-error.mjs +1 -2
- package/source/data/datasource/server/restapi.mjs +10 -7
- package/source/data/transformer.mjs +18 -0
- package/source/dom/constants.mjs +2 -2
- package/source/dom/customcontrol.mjs +63 -66
- package/source/dom/customelement.mjs +157 -172
- package/source/dom/dimension.mjs +1 -3
- package/source/dom/util/extract-keys.mjs +10 -6
- package/source/dom/util/init-options-from-attributes.mjs +14 -16
- package/source/dom/util/set-option-from-attribute.mjs +14 -16
- package/source/dom/util.mjs +11 -4
- package/source/logging/handler/console.mjs +0 -4
- package/source/text/bracketed-key-value-hash.mjs +23 -31
- package/source/text/util.mjs +1 -2
- package/source/types/version.mjs +1 -1
- package/test/cases/data/transformer.mjs +3 -0
- package/test/cases/dom/customcontrol.mjs +21 -45
- package/test/cases/dom/customelement.mjs +2 -1
- package/test/cases/monster.mjs +1 -1
package/package.json
CHANGED
|
@@ -27,7 +27,7 @@ class DataFetchError extends Error {
|
|
|
27
27
|
constructor(message, response) {
|
|
28
28
|
super(message);
|
|
29
29
|
this[internalSymbol] = {
|
|
30
|
-
response: response
|
|
30
|
+
response: response,
|
|
31
31
|
};
|
|
32
32
|
}
|
|
33
33
|
|
|
@@ -46,5 +46,4 @@ class DataFetchError extends Error {
|
|
|
46
46
|
getResponse() {
|
|
47
47
|
return this[internalSymbol]["response"];
|
|
48
48
|
}
|
|
49
|
-
|
|
50
49
|
}
|
|
@@ -5,13 +5,13 @@
|
|
|
5
5
|
* License text available at https://www.gnu.org/licenses/agpl-3.0.en.html
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import {internalSymbol, instanceSymbol} from "../../../constants.mjs";
|
|
9
|
-
import {isObject, isFunction} from "../../../types/is.mjs";
|
|
10
|
-
import {Server} from "../server.mjs";
|
|
11
|
-
import {WriteError} from "./restapi/writeerror.mjs";
|
|
12
|
-
import {DataFetchError} from "./restapi/data-fetch-error.mjs";
|
|
8
|
+
import { internalSymbol, instanceSymbol } from "../../../constants.mjs";
|
|
9
|
+
import { isObject, isFunction } from "../../../types/is.mjs";
|
|
10
|
+
import { Server } from "../server.mjs";
|
|
11
|
+
import { WriteError } from "./restapi/writeerror.mjs";
|
|
12
|
+
import { DataFetchError } from "./restapi/data-fetch-error.mjs";
|
|
13
13
|
|
|
14
|
-
export {RestAPI};
|
|
14
|
+
export { RestAPI };
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* @type {symbol}
|
|
@@ -189,7 +189,10 @@ function fetchData(init, key, callback) {
|
|
|
189
189
|
const acceptedStatus = self.getOption(`${key}.acceptedStatus`, [200]);
|
|
190
190
|
|
|
191
191
|
if (acceptedStatus.indexOf(resp.status) === -1) {
|
|
192
|
-
throw new DataFetchError(
|
|
192
|
+
throw new DataFetchError(
|
|
193
|
+
`the response does not contain a accepted status (actual: ${resp.status}).`,
|
|
194
|
+
response,
|
|
195
|
+
);
|
|
193
196
|
}
|
|
194
197
|
|
|
195
198
|
return resp.text();
|
|
@@ -673,6 +673,24 @@ function transform(value) {
|
|
|
673
673
|
throw new Error(`unsupported locale or missing format (${e.message})`);
|
|
674
674
|
}
|
|
675
675
|
|
|
676
|
+
case "datetimeformat":
|
|
677
|
+
date = new Date(value);
|
|
678
|
+
if (isNaN(date.getTime())) {
|
|
679
|
+
throw new Error("invalid date");
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
const options = {
|
|
683
|
+
dateStyle: args.shift() || "medium",
|
|
684
|
+
timeStyle: args.shift() || "medium",
|
|
685
|
+
};
|
|
686
|
+
|
|
687
|
+
try {
|
|
688
|
+
locale = getLocaleOfDocument();
|
|
689
|
+
return new Intl.DateTimeFormat(locale, options).format(date);
|
|
690
|
+
} catch (e) {
|
|
691
|
+
throw new Error(`unsupported locale or missing format (${e.message})`);
|
|
692
|
+
}
|
|
693
|
+
|
|
676
694
|
case "datetime":
|
|
677
695
|
date = new Date(value);
|
|
678
696
|
if (isNaN(date.getTime())) {
|
package/source/dom/constants.mjs
CHANGED
|
@@ -61,7 +61,7 @@ export {
|
|
|
61
61
|
customElementUpdaterLinkSymbol,
|
|
62
62
|
initControlCallbackName,
|
|
63
63
|
ATTRIBUTE_SCRIPT_HOST,
|
|
64
|
-
|
|
64
|
+
ATTRIBUTE_INIT_CALLBACK,
|
|
65
65
|
};
|
|
66
66
|
|
|
67
67
|
/**
|
|
@@ -117,7 +117,7 @@ const ATTRIBUTE_OPTIONS_SELECTOR = `${ATTRIBUTE_PREFIX}options-selector`;
|
|
|
117
117
|
* @since 3.48.0
|
|
118
118
|
* @type {string}
|
|
119
119
|
*/
|
|
120
|
-
const
|
|
120
|
+
const ATTRIBUTE_INIT_CALLBACK = `${ATTRIBUTE_PREFIX}init-callback`;
|
|
121
121
|
|
|
122
122
|
/**
|
|
123
123
|
* This is the name of the callback to pass the callback to a control
|
|
@@ -5,12 +5,13 @@
|
|
|
5
5
|
* License text available at https://www.gnu.org/licenses/agpl-3.0.en.html
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import {extend} from "../data/extend.mjs";
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
8
|
+
import { extend } from "../data/extend.mjs";
|
|
9
|
+
import { addAttributeToken } from "./attributes.mjs";
|
|
10
|
+
import { ATTRIBUTE_ERRORMESSAGE } from "./constants.mjs";
|
|
11
|
+
import { CustomElement, attributeObserverSymbol } from "./customelement.mjs";
|
|
12
|
+
import { instanceSymbol } from "../constants.mjs";
|
|
12
13
|
|
|
13
|
-
export {CustomControl};
|
|
14
|
+
export { CustomControl };
|
|
14
15
|
|
|
15
16
|
/**
|
|
16
17
|
* @private
|
|
@@ -19,54 +20,61 @@ export {CustomControl};
|
|
|
19
20
|
const attachedInternalSymbol = Symbol("attachedInternal");
|
|
20
21
|
|
|
21
22
|
/**
|
|
22
|
-
*
|
|
23
|
+
* This is a base class for creating custom controls using the power of CustomElement.
|
|
23
24
|
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
25
|
+
* After defining a `CustomElement`, the `registerCustomElement` method must be called with the new class name. Only then
|
|
26
|
+
* will the tag defined via the `getTag` method be made known to the DOM.
|
|
26
27
|
*
|
|
27
28
|
* <img src="./images/customcontrol-class.png">
|
|
28
29
|
*
|
|
29
|
-
* This control uses `attachInternals()` to integrate the control into a form.
|
|
30
|
-
*
|
|
30
|
+
* This control uses `attachInternals()` to integrate the control into a form. If the target environment does not support
|
|
31
|
+
* this method, the [polyfill](https://www.npmjs.com/package/element-internals-polyfill) can be used.
|
|
31
32
|
*
|
|
32
|
-
* You can create the object
|
|
33
|
+
* You can create the object using the function `document.createElement()`.
|
|
33
34
|
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
* skinparam shadowing false
|
|
37
|
-
* HTMLElement <|-- CustomElement
|
|
38
|
-
* CustomElement <|-- CustomControl
|
|
39
|
-
* @enduml
|
|
35
|
+
* This control uses `attachInternals()` to integrate the control into a form. If the target environment does not support
|
|
36
|
+
* this method, the Polyfill for attachInternals() can be used: {@link https://www.npmjs.com/package/element-internals-polyfill|element-internals-polyfill}.
|
|
40
37
|
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
38
|
+
* Learn more about WICG Web Components: {@link https://github.com/WICG/webcomponents|WICG Web Components}.
|
|
39
|
+
*
|
|
40
|
+
* Read the HTML specification for Custom Elements: {@link https://html.spec.whatwg.org/multipage/custom-elements.html#custom-elements|Custom Elements}.
|
|
41
|
+
*
|
|
42
|
+
* Read the HTML specification for Custom Element Reactions: {@link https://html.spec.whatwg.org/dev/custom-elements.html#custom-element-reactions|Custom Element Reactions}.
|
|
43
|
+
*
|
|
44
|
+
* @summary A base class for custom controls based on CustomElement.
|
|
45
|
+
* @copyright schukai GmbH
|
|
46
46
|
* @license AGPLv3
|
|
47
47
|
* @since 1.14.0
|
|
48
|
-
* @copyright schukai GmbH
|
|
49
48
|
* @memberOf Monster.DOM
|
|
49
|
+
* @extends Monster.DOM.CustomElement
|
|
50
50
|
*/
|
|
51
51
|
class CustomControl extends CustomElement {
|
|
52
52
|
/**
|
|
53
|
-
*
|
|
53
|
+
* The constructor method of CustomControl, which is called when creating a new instance.
|
|
54
|
+
* It checks whether the element supports `attachInternals()` and initializes an internal form-associated element
|
|
55
|
+
* if supported. Additionally, it initializes a MutationObserver to watch for attribute changes.
|
|
54
56
|
*
|
|
57
|
+
* See the links below for more information:
|
|
58
|
+
* {@link https://html.spec.whatwg.org/multipage/custom-elements.html#dom-customelementregistry-define|CustomElementRegistry.define()}
|
|
59
|
+
* {@link https://html.spec.whatwg.org/multipage/custom-elements.html#dom-customelementregistry-get|CustomElementRegistry.get()}
|
|
60
|
+
* and {@link https://developer.mozilla.org/en-US/docs/Web/API/ElementInternals|ElementInternals}
|
|
61
|
+
*
|
|
62
|
+
* @inheritdoc
|
|
55
63
|
* @throws {Error} the ElementInternals is not supported and a polyfill is necessary
|
|
56
|
-
* @
|
|
64
|
+
* @since 1.7.0
|
|
57
65
|
*/
|
|
58
66
|
constructor() {
|
|
59
67
|
super();
|
|
60
68
|
|
|
69
|
+
// check if element supports `attachInternals()`
|
|
61
70
|
if (typeof this["attachInternals"] === "function") {
|
|
62
|
-
/**
|
|
63
|
-
* currently only supported by chrome
|
|
64
|
-
* @property {Object}
|
|
65
|
-
* @private
|
|
66
|
-
*/
|
|
67
71
|
this[attachedInternalSymbol] = this.attachInternals();
|
|
72
|
+
} else {
|
|
73
|
+
// `attachInternals()` is not supported, so a polyfill is necessary
|
|
74
|
+
throw Error("the ElementInternals is not supported and a polyfill is necessary");
|
|
68
75
|
}
|
|
69
76
|
|
|
77
|
+
// initialize a MutationObserver to watch for attribute changes
|
|
70
78
|
initObserver.call(this);
|
|
71
79
|
}
|
|
72
80
|
|
|
@@ -90,40 +98,27 @@ class CustomControl extends CustomElement {
|
|
|
90
98
|
}
|
|
91
99
|
|
|
92
100
|
/**
|
|
93
|
-
* Adding a static formAssociated property, with a true value, makes an autonomous custom element a form-associated custom element.
|
|
101
|
+
* Adding a static `formAssociated` property, with a true value, makes an autonomous custom element a form-associated custom element.
|
|
94
102
|
*
|
|
95
|
-
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/attachInternals}
|
|
96
|
-
* @see {@link https://html.spec.whatwg.org/multipage/custom-elements.html#custom-elements-face-example}
|
|
103
|
+
* @see [attachInternals()]{@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/attachInternals}
|
|
104
|
+
* @see [Custom Elements Face Example]{@link https://html.spec.whatwg.org/multipage/custom-elements.html#custom-elements-face-example}
|
|
97
105
|
* @since 1.14.0
|
|
98
106
|
* @return {boolean}
|
|
99
107
|
*/
|
|
100
|
-
static formAssociated = true
|
|
108
|
+
static formAssociated = true;
|
|
101
109
|
|
|
102
110
|
/**
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
* ```
|
|
106
|
-
* get defaults() {
|
|
107
|
-
* return extends{}, super.defaults, {
|
|
108
|
-
* myValue:true
|
|
109
|
-
* });
|
|
110
|
-
* }
|
|
111
|
-
* ```
|
|
112
|
-
*
|
|
113
|
-
* @see {@link https://html.spec.whatwg.org/multipage/custom-elements.html#custom-elements-face-example}
|
|
114
|
-
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/attachInternals}
|
|
115
|
-
* @return {object}
|
|
111
|
+
* @inheritdoc
|
|
116
112
|
* @since 1.14.0
|
|
117
|
-
|
|
113
|
+
**/
|
|
118
114
|
get defaults() {
|
|
119
|
-
return extend({
|
|
120
|
-
}, super.defaults);
|
|
115
|
+
return extend({}, super.defaults);
|
|
121
116
|
}
|
|
122
117
|
|
|
123
118
|
/**
|
|
124
119
|
* Must be overridden by a derived class and return the value of the control.
|
|
125
120
|
*
|
|
126
|
-
* This is a method of [internal
|
|
121
|
+
* 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.
|
|
127
122
|
*
|
|
128
123
|
* @since 1.14.0
|
|
129
124
|
* @throws {Error} the value getter must be overwritten by the derived class
|
|
@@ -133,11 +128,11 @@ class CustomControl extends CustomElement {
|
|
|
133
128
|
}
|
|
134
129
|
|
|
135
130
|
/**
|
|
136
|
-
* Must be overridden by a derived class and
|
|
131
|
+
* Must be overridden by a derived class and set the value of the control.
|
|
137
132
|
*
|
|
138
|
-
* This is a method of [internal
|
|
133
|
+
* 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.
|
|
139
134
|
*
|
|
140
|
-
* @param {*} value
|
|
135
|
+
* @param {*} value The value to set.
|
|
141
136
|
* @since 1.14.0
|
|
142
137
|
* @throws {Error} the value setter must be overwritten by the derived class
|
|
143
138
|
*/
|
|
@@ -180,8 +175,8 @@ class CustomControl extends CustomElement {
|
|
|
180
175
|
*
|
|
181
176
|
* @return {ValidityState}
|
|
182
177
|
* @throws {Error} the ElementInternals is not supported and a polyfill is necessary
|
|
183
|
-
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/ValidityState}
|
|
184
|
-
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/validity}
|
|
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}
|
|
185
180
|
*/
|
|
186
181
|
get validity() {
|
|
187
182
|
return getInternal.call(this)?.validity;
|
|
@@ -214,7 +209,7 @@ class CustomControl extends CustomElement {
|
|
|
214
209
|
/**
|
|
215
210
|
* This is a method of [internal api](https://developer.mozilla.org/en-US/docs/Web/API/ElementInternals)
|
|
216
211
|
*
|
|
217
|
-
* @return {
|
|
212
|
+
* @return {boolean}
|
|
218
213
|
* @since 1.14.0
|
|
219
214
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/ElementInternals/states
|
|
220
215
|
* @throws {Error} the ElementInternals is not supported and a polyfill is necessary
|
|
@@ -301,12 +296,15 @@ class CustomControl extends CustomElement {
|
|
|
301
296
|
}
|
|
302
297
|
|
|
303
298
|
/**
|
|
304
|
-
*
|
|
299
|
+
* Sets the `form` attribute of the custom control to the `id` of the passed form element.
|
|
300
|
+
* If no form element is passed, removes the `form` attribute.
|
|
301
|
+
*
|
|
302
|
+
* @param {HTMLFormElement} form - The form element to associate with the control
|
|
305
303
|
*/
|
|
306
304
|
formAssociatedCallback(form) {
|
|
307
305
|
if (form) {
|
|
308
|
-
if(form.id) {
|
|
309
|
-
this.setAttribute("form", form.id);
|
|
306
|
+
if (form.id) {
|
|
307
|
+
this.setAttribute("form", form.id);
|
|
310
308
|
}
|
|
311
309
|
} else {
|
|
312
310
|
this.removeAttribute("form");
|
|
@@ -314,7 +312,9 @@ class CustomControl extends CustomElement {
|
|
|
314
312
|
}
|
|
315
313
|
|
|
316
314
|
/**
|
|
317
|
-
*
|
|
315
|
+
* Sets or removes the `disabled` attribute of the custom control based on the passed value.
|
|
316
|
+
*
|
|
317
|
+
* @param {boolean} disabled - Whether or not the control should be disabled
|
|
318
318
|
*/
|
|
319
319
|
formDisabledCallback(disabled) {
|
|
320
320
|
if (disabled) {
|
|
@@ -328,17 +328,14 @@ class CustomControl extends CustomElement {
|
|
|
328
328
|
* @param {string} state
|
|
329
329
|
* @param {string} mode
|
|
330
330
|
*/
|
|
331
|
-
formStateRestoreCallback(state, mode) {
|
|
332
|
-
|
|
333
|
-
}
|
|
331
|
+
formStateRestoreCallback(state, mode) {}
|
|
334
332
|
|
|
335
333
|
/**
|
|
336
334
|
*
|
|
337
335
|
*/
|
|
338
336
|
formResetCallback() {
|
|
339
|
-
|
|
337
|
+
this.value = "";
|
|
340
338
|
}
|
|
341
|
-
|
|
342
339
|
}
|
|
343
340
|
|
|
344
341
|
/**
|