@schukai/monster 3.79.0 → 3.80.0
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +14 -0
- package/package.json +1 -1
- package/source/components/content/copy.mjs +313 -311
- package/source/components/content/stylesheet/copy.mjs +13 -6
- package/source/components/form/field-set.mjs +1 -2
- package/source/components/form/select.mjs +1945 -1957
- package/source/components/form/stylesheet/field-set.mjs +13 -6
- package/source/components/form/toggle-switch.mjs +319 -319
- package/source/components/layout/collapse.mjs +351 -351
- package/source/components/layout/details.mjs +1 -1
- package/source/components/layout/iframe.mjs +1 -1
- package/source/components/layout/width-toggle.mjs +2 -3
- package/source/components/state/log.mjs +151 -152
- package/source/components/state/state.mjs +1 -1
- package/source/components/stylesheet/form.mjs +13 -6
- package/source/components/tree-menu/tree-menu.mjs +2 -3
- package/source/dom/customelement.mjs +18 -1
- package/source/monster.mjs +2 -1
- package/source/types/version.mjs +1 -1
- package/test/cases/monster.mjs +1 -1
- package/test/util/jsdom.mjs +0 -2
- package/test/web/test.html +2 -2
- package/test/web/tests.js +7455 -8361
@@ -12,26 +12,26 @@
|
|
12
12
|
* SPDX-License-Identifier: AGPL-3.0
|
13
13
|
*/
|
14
14
|
|
15
|
-
import {instanceSymbol} from "../../constants.mjs";
|
16
|
-
import {internalSymbol} from "../../constants.mjs";
|
17
|
-
import {CustomControl} from "../../dom/customcontrol.mjs";
|
18
|
-
import {Observer} from "../../types/observer.mjs";
|
19
|
-
import {ProxyObserver} from "../../types/proxyobserver.mjs";
|
15
|
+
import { instanceSymbol } from "../../constants.mjs";
|
16
|
+
import { internalSymbol } from "../../constants.mjs";
|
17
|
+
import { CustomControl } from "../../dom/customcontrol.mjs";
|
18
|
+
import { Observer } from "../../types/observer.mjs";
|
19
|
+
import { ProxyObserver } from "../../types/proxyobserver.mjs";
|
20
20
|
|
21
|
-
import {addAttributeToken} from "../../dom/attributes.mjs";
|
21
|
+
import { addAttributeToken } from "../../dom/attributes.mjs";
|
22
22
|
import {
|
23
|
-
|
24
|
-
|
25
|
-
|
23
|
+
assembleMethodSymbol,
|
24
|
+
registerCustomElement,
|
25
|
+
updaterTransformerMethodsSymbol,
|
26
26
|
} from "../../dom/customelement.mjs";
|
27
|
-
import {isObject, isFunction} from "../../types/is.mjs";
|
28
|
-
import {ToggleSwitchStyleSheet} from "./stylesheet/toggle-switch.mjs";
|
27
|
+
import { isObject, isFunction } from "../../types/is.mjs";
|
28
|
+
import { ToggleSwitchStyleSheet } from "./stylesheet/toggle-switch.mjs";
|
29
29
|
import {
|
30
|
-
|
31
|
-
|
30
|
+
ATTRIBUTE_ERRORMESSAGE,
|
31
|
+
ATTRIBUTE_ROLE,
|
32
32
|
} from "../../dom/constants.mjs";
|
33
33
|
|
34
|
-
export {ToggleSwitch};
|
34
|
+
export { ToggleSwitch };
|
35
35
|
|
36
36
|
/**
|
37
37
|
* @private
|
@@ -65,340 +65,340 @@ export const STATE_OFF = "off";
|
|
65
65
|
* @fires monster-changed
|
66
66
|
*/
|
67
67
|
class ToggleSwitch extends CustomControl {
|
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
|
-
|
68
|
+
/**
|
69
|
+
* To set the options via the HTML tag, the attribute `data-monster-options` must be used.
|
70
|
+
* @see {@link https://monsterjs.org/en/doc/#configurate-a-monster-control}
|
71
|
+
*
|
72
|
+
* The individual configuration values can be found in the table.
|
73
|
+
*
|
74
|
+
* @property {string} value=current value of the element
|
75
|
+
* @property {Boolean} disabled=disabled=false Disabled state
|
76
|
+
* @property {Object} classes
|
77
|
+
* @property {string} classes.on=specifies the class for the on state.
|
78
|
+
* @property {string} classes.off=specifies the class for the off state.
|
79
|
+
* @property {Object} values
|
80
|
+
* @property {string} values.off=specifies the value of the element if it is not selected
|
81
|
+
* @property {Object} labels
|
82
|
+
* @property {string} labels.on=specifies the label for the on state.
|
83
|
+
* @property {string} labels.off=specifies the label for the off state.
|
84
|
+
* @property {string} actions
|
85
|
+
* @property {string} actions.on=specifies the action for the on state.
|
86
|
+
* @property {string} actions.off=specifies the action for the off state.
|
87
|
+
* @property {Object} templates
|
88
|
+
* @property {string} templates.main=specifies the main template used by the control.
|
89
|
+
*/
|
90
|
+
get defaults() {
|
91
|
+
return Object.assign({}, super.defaults, {
|
92
|
+
value: null,
|
93
|
+
disabled: false,
|
94
|
+
classes: {
|
95
|
+
on: "monster-theme-on",
|
96
|
+
off: "monster-theme-off",
|
97
|
+
handle: "monster-theme-primary-1",
|
98
|
+
},
|
99
|
+
values: {
|
100
|
+
on: "on",
|
101
|
+
off: "off",
|
102
|
+
},
|
103
|
+
labels: {
|
104
|
+
toggleSwitchOn: "✔",
|
105
|
+
toggleSwitchOff: "✖",
|
106
|
+
},
|
107
|
+
templates: {
|
108
|
+
main: getTemplate(),
|
109
|
+
},
|
110
|
+
actions: {
|
111
|
+
on: () => {
|
112
|
+
throw new Error("the on action is not defined");
|
113
|
+
},
|
114
|
+
off: () => {
|
115
|
+
throw new Error("the off action is not defined");
|
116
|
+
},
|
117
|
+
},
|
118
|
+
});
|
119
|
+
}
|
120
|
+
|
121
|
+
/**
|
122
|
+
* @return {ToggleSwitch}
|
123
|
+
*/
|
124
|
+
[assembleMethodSymbol]() {
|
125
|
+
const self = this;
|
126
|
+
super[assembleMethodSymbol]();
|
127
|
+
initControlReferences.call(this);
|
128
|
+
initEventHandler.call(this);
|
129
|
+
|
130
|
+
/**
|
131
|
+
* init value to off
|
132
|
+
* if the value was not defined before inserting it into the HTML
|
133
|
+
*/
|
134
|
+
if (self.getOption("value") === null) {
|
135
|
+
self.setOption("value", self.getOption("values.off"));
|
136
|
+
}
|
137
|
+
|
138
|
+
/**
|
139
|
+
* value from attribute
|
140
|
+
*/
|
141
|
+
if (self.hasAttribute("value")) {
|
142
|
+
self.setOption("value", self.getAttribute("value"));
|
143
|
+
}
|
144
|
+
|
145
|
+
/**
|
146
|
+
* validate value
|
147
|
+
*/
|
148
|
+
validateAndSetValue.call(self);
|
149
|
+
|
150
|
+
if (this.state === STATE_ON) {
|
151
|
+
toggleClassOn.call(self);
|
152
|
+
} else {
|
153
|
+
toggleClassOff.call(self);
|
154
|
+
}
|
155
|
+
|
156
|
+
/**
|
157
|
+
* is called when options changed
|
158
|
+
*/
|
159
|
+
self[internalSymbol].attachObserver(
|
160
|
+
new Observer(function () {
|
161
|
+
if (isObject(this) && this instanceof ProxyObserver) {
|
162
|
+
validateAndSetValue.call(self);
|
163
|
+
toggleClass.call(self);
|
164
|
+
}
|
165
|
+
}),
|
166
|
+
);
|
167
|
+
|
168
|
+
return this;
|
169
|
+
}
|
170
|
+
|
171
|
+
/**
|
172
|
+
* updater transformer methods for pipe
|
173
|
+
*
|
174
|
+
* @return {function}
|
175
|
+
*/
|
176
|
+
[updaterTransformerMethodsSymbol]() {
|
177
|
+
return {
|
178
|
+
"state-callback": (Wert) => {
|
179
|
+
return this.state;
|
180
|
+
},
|
181
|
+
};
|
182
|
+
}
|
183
|
+
|
184
|
+
/**
|
185
|
+
* @return [CSSStyleSheet]
|
186
|
+
*/
|
187
|
+
static getCSSStyleSheet() {
|
188
|
+
return [ToggleSwitchStyleSheet];
|
189
|
+
}
|
190
|
+
|
191
|
+
/**
|
192
|
+
* toggle switch
|
193
|
+
*
|
194
|
+
* ```
|
195
|
+
* e = document.querySelector('monster-toggle-switch');
|
196
|
+
* e.click()
|
197
|
+
* ```
|
198
|
+
*/
|
199
|
+
click() {
|
200
|
+
toggleValues.call(this);
|
201
|
+
}
|
202
|
+
|
203
|
+
/**
|
204
|
+
* toggle switch on/off
|
205
|
+
*
|
206
|
+
* ```
|
207
|
+
* e = document.querySelector('monster-toggle-switch');
|
208
|
+
* e.toggle()
|
209
|
+
* ```
|
210
|
+
*
|
211
|
+
* @return {ToggleSwitch}
|
212
|
+
*/
|
213
|
+
toggle() {
|
214
|
+
this.click();
|
215
|
+
return this;
|
216
|
+
}
|
217
|
+
|
218
|
+
/**
|
219
|
+
* toggle switch on
|
220
|
+
*
|
221
|
+
* ```
|
222
|
+
* e = document.querySelector('monster-toggle-switch');
|
223
|
+
* e.toggleOn()
|
224
|
+
* ```
|
225
|
+
*
|
226
|
+
* @return {ToggleSwitch}
|
227
|
+
*/
|
228
|
+
toggleOn() {
|
229
|
+
this.setOption("value", this.getOption("values.on"));
|
230
|
+
return this;
|
231
|
+
}
|
232
|
+
|
233
|
+
/**
|
234
|
+
* toggle switch off
|
235
|
+
*
|
236
|
+
* ```
|
237
|
+
* e = document.querySelector('monster-toggle-switch');
|
238
|
+
* e.toggleOff()
|
239
|
+
* ```
|
240
|
+
*
|
241
|
+
* @return {ToggleSwitch}
|
242
|
+
*/
|
243
|
+
toggleOff() {
|
244
|
+
this.setOption("value", this.getOption("values.off"));
|
245
|
+
return this;
|
246
|
+
}
|
247
|
+
|
248
|
+
/**
|
249
|
+
* returns the status of the element
|
250
|
+
*
|
251
|
+
* ```
|
252
|
+
* e = document.querySelector('monster-toggle-switch');
|
253
|
+
* console.log(e.state)
|
254
|
+
* // ↦ off
|
255
|
+
* ```
|
256
|
+
*
|
257
|
+
* @return {string}
|
258
|
+
*/
|
259
|
+
get state() {
|
260
|
+
return this.getOption("value") === this.getOption("values.on")
|
261
|
+
? STATE_ON
|
262
|
+
: STATE_OFF;
|
263
|
+
}
|
264
|
+
|
265
|
+
/**
|
266
|
+
* The current value of the Switch
|
267
|
+
*
|
268
|
+
* ```
|
269
|
+
* e = document.querySelector('monster-toggle-switch');
|
270
|
+
* console.log(e.value)
|
271
|
+
* // ↦ on
|
272
|
+
* ```
|
273
|
+
*
|
274
|
+
* @return {string}
|
275
|
+
*/
|
276
|
+
get value() {
|
277
|
+
return this.state === STATE_ON
|
278
|
+
? this.getOption("values.on")
|
279
|
+
: this.getOption("values.off");
|
280
|
+
}
|
281
|
+
|
282
|
+
/**
|
283
|
+
* Set value
|
284
|
+
*
|
285
|
+
* ```
|
286
|
+
* e = document.querySelector('monster-toggle-switch');
|
287
|
+
* e.value="on"
|
288
|
+
* ```
|
289
|
+
*
|
290
|
+
* @property {string} value
|
291
|
+
*/
|
292
|
+
set value(value) {
|
293
|
+
this.setOption("value", value);
|
294
|
+
}
|
295
|
+
|
296
|
+
/**
|
297
|
+
* This method is called by the `instanceof` operator.
|
298
|
+
* @returns {symbol}
|
299
|
+
*/
|
300
|
+
static get [instanceSymbol]() {
|
301
|
+
return Symbol.for(
|
302
|
+
"@schukai/monster/components/form/toggle-switch@@instance",
|
303
|
+
);
|
304
|
+
}
|
305
|
+
|
306
|
+
static getTag() {
|
307
|
+
return "monster-toggle-switch";
|
308
|
+
}
|
309
309
|
}
|
310
310
|
|
311
311
|
/**
|
312
312
|
* @private
|
313
313
|
*/
|
314
314
|
function initControlReferences() {
|
315
|
-
|
316
|
-
|
317
|
-
|
315
|
+
this[switchElementSymbol] = this.shadowRoot.querySelector(
|
316
|
+
`[${ATTRIBUTE_ROLE}=switch]`,
|
317
|
+
);
|
318
318
|
}
|
319
319
|
|
320
320
|
/**
|
321
321
|
* @private
|
322
322
|
*/
|
323
323
|
function toggleClassOn() {
|
324
|
-
|
325
|
-
|
324
|
+
this[switchElementSymbol].classList.remove(this.getOption("classes.off")); // change color
|
325
|
+
this[switchElementSymbol].classList.add(this.getOption("classes.on")); // change color
|
326
326
|
}
|
327
327
|
|
328
328
|
/**
|
329
329
|
* @private
|
330
330
|
*/
|
331
331
|
function toggleClassOff() {
|
332
|
-
|
333
|
-
|
332
|
+
this[switchElementSymbol].classList.remove(this.getOption("classes.on")); // change color
|
333
|
+
this[switchElementSymbol].classList.add(this.getOption("classes.off")); // change color
|
334
334
|
}
|
335
335
|
|
336
336
|
/**
|
337
337
|
* @private
|
338
338
|
*/
|
339
339
|
function toggleClass() {
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
340
|
+
if (this.getOption("value") === this.getOption("values.on")) {
|
341
|
+
toggleClassOn.call(this);
|
342
|
+
} else {
|
343
|
+
toggleClassOff.call(this);
|
344
|
+
}
|
345
345
|
}
|
346
346
|
|
347
347
|
/**
|
348
348
|
* @private
|
349
349
|
*/
|
350
350
|
function toggleValues() {
|
351
|
-
|
352
|
-
|
353
|
-
|
351
|
+
if (this.getOption("disabled") === true) {
|
352
|
+
return;
|
353
|
+
}
|
354
354
|
|
355
|
-
|
355
|
+
let callback, value;
|
356
356
|
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
357
|
+
if (this.getOption("value") === this.getOption("values.on")) {
|
358
|
+
value = this.getOption("values.off");
|
359
|
+
callback = this.getOption("actions.off");
|
360
|
+
} else {
|
361
|
+
value = this.getOption("values.on");
|
362
|
+
callback = this.getOption("actions.on");
|
363
|
+
}
|
364
364
|
|
365
|
-
|
366
|
-
|
365
|
+
this.setOption("value", value);
|
366
|
+
this?.setFormValue(value);
|
367
367
|
|
368
|
-
|
369
|
-
|
370
|
-
|
368
|
+
if (isFunction(callback)) {
|
369
|
+
callback.call(this);
|
370
|
+
}
|
371
371
|
|
372
|
-
|
372
|
+
this.setOption("state", this.state);
|
373
373
|
}
|
374
374
|
|
375
375
|
/**
|
376
376
|
* @private
|
377
377
|
*/
|
378
378
|
function validateAndSetValue() {
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
379
|
+
const value = this.getOption("value");
|
380
|
+
|
381
|
+
const validatedValues = [];
|
382
|
+
validatedValues.push(this.getOption("values.on"));
|
383
|
+
validatedValues.push(this.getOption("values.off"));
|
384
|
+
|
385
|
+
if (validatedValues.includes(value) === false) {
|
386
|
+
addAttributeToken(
|
387
|
+
this,
|
388
|
+
ATTRIBUTE_ERRORMESSAGE,
|
389
|
+
'The value "' +
|
390
|
+
value +
|
391
|
+
'" must be "' +
|
392
|
+
this.getOption("values.on") +
|
393
|
+
'" or "' +
|
394
|
+
this.getOption("values.off"),
|
395
|
+
);
|
396
|
+
this.setOption("disabled", true);
|
397
|
+
this.formDisabledCallback(true);
|
398
|
+
} else {
|
399
|
+
this.setOption("disabled", false);
|
400
|
+
this.formDisabledCallback(false);
|
401
|
+
}
|
402
402
|
}
|
403
403
|
|
404
404
|
/**
|
@@ -406,16 +406,16 @@ function validateAndSetValue() {
|
|
406
406
|
* @return {initEventHandler}
|
407
407
|
*/
|
408
408
|
function initEventHandler() {
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
409
|
+
const self = this;
|
410
|
+
self.addEventListener("keyup", function (event) {
|
411
|
+
if (event.code === "Space") {
|
412
|
+
self[switchElementSymbol].click();
|
413
|
+
}
|
414
|
+
});
|
415
|
+
self.addEventListener("click", function (event) {
|
416
|
+
toggleValues.call(self);
|
417
|
+
});
|
418
|
+
return this;
|
419
419
|
}
|
420
420
|
|
421
421
|
/**
|
@@ -423,8 +423,8 @@ function initEventHandler() {
|
|
423
423
|
* @return {string}
|
424
424
|
*/
|
425
425
|
function getTemplate() {
|
426
|
-
|
427
|
-
|
426
|
+
// language=HTML
|
427
|
+
return `
|
428
428
|
<div data-monster-role="control" part="control" tabindex="0">
|
429
429
|
<div class="switch" data-monster-role="switch"
|
430
430
|
data-monster-attributes="data-monster-state path:value | call:state-callback">
|