@schukai/monster 3.96.1 → 3.96.3
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 +20 -5
- package/package.json +1 -1
- package/source/components/datatable/change-button.mjs +39 -41
- package/source/components/datatable/dataset.mjs +335 -325
- package/source/components/datatable/datasource/rest.mjs +33 -29
- package/source/components/datatable/embedded-pagination.mjs +3 -1
- package/source/components/datatable/filter.mjs +164 -63
- package/source/components/datatable/pagination.mjs +13 -6
- package/source/components/datatable/save-button.mjs +25 -3
- package/source/components/datatable/status.mjs +21 -26
- package/source/components/datatable/style/status.pcss +12 -2
- package/source/components/datatable/stylesheet/status.mjs +1 -1
- package/source/components/datatable/util.mjs +1 -2
- package/source/components/form/form.mjs +5 -4
- package/source/components/form/select.mjs +2008 -2013
- package/source/components/form/style/field-set.pcss +28 -7
- package/source/components/form/style/toggle-switch.pcss +13 -2
- package/source/components/form/stylesheet/field-set.mjs +14 -7
- package/source/components/form/stylesheet/toggle-switch.mjs +14 -7
- package/source/components/form/toggle-switch.mjs +372 -380
- package/source/components/layout/tabs.mjs +1 -2
- package/source/constants.mjs +14 -1
- package/source/data/extend.mjs +2 -1
- package/source/data/transformer.mjs +2 -0
- package/source/dom/constants.mjs +0 -1
- package/source/dom/customelement.mjs +7 -3
- package/source/dom/updater.mjs +5 -1
- package/source/monster.mjs +1 -1
- package/source/text/formatter.mjs +5 -3
- package/source/types/is.mjs +13 -0
- package/source/types/proxyobserver.mjs +7 -2
- package/source/types/version.mjs +1 -1
- package/source/util/clone.mjs +9 -14
- package/test/cases/data/pathfinder.mjs +18 -0
- package/test/cases/monster.mjs +1 -1
- package/test/cases/text/formatter.mjs +21 -1
- package/test/web/test.html +2 -2
- package/test/web/tests.js +266 -176
@@ -12,24 +12,27 @@
|
|
12
12
|
* SPDX-License-Identifier: AGPL-3.0
|
13
13
|
*/
|
14
14
|
|
15
|
-
import {instanceSymbol, internalSymbol} from "../../constants.mjs";
|
16
|
-
import {CustomControl} from "../../dom/customcontrol.mjs";
|
17
|
-
import {Observer} from "../../types/observer.mjs";
|
18
|
-
import {ProxyObserver} from "../../types/proxyobserver.mjs";
|
15
|
+
import { instanceSymbol, internalSymbol } from "../../constants.mjs";
|
16
|
+
import { CustomControl } from "../../dom/customcontrol.mjs";
|
17
|
+
import { Observer } from "../../types/observer.mjs";
|
18
|
+
import { ProxyObserver } from "../../types/proxyobserver.mjs";
|
19
19
|
|
20
|
-
import {addAttributeToken} from "../../dom/attributes.mjs";
|
20
|
+
import { addAttributeToken } from "../../dom/attributes.mjs";
|
21
21
|
import {
|
22
|
-
|
23
|
-
|
24
|
-
|
22
|
+
assembleMethodSymbol,
|
23
|
+
registerCustomElement,
|
24
|
+
updaterTransformerMethodsSymbol,
|
25
25
|
} from "../../dom/customelement.mjs";
|
26
|
-
import {isFunction, isObject} from "../../types/is.mjs";
|
27
|
-
import {ToggleSwitchStyleSheet} from "./stylesheet/toggle-switch.mjs";
|
28
|
-
import {
|
29
|
-
|
30
|
-
|
26
|
+
import { isFunction, isObject } from "../../types/is.mjs";
|
27
|
+
import { ToggleSwitchStyleSheet } from "./stylesheet/toggle-switch.mjs";
|
28
|
+
import {
|
29
|
+
ATTRIBUTE_ERRORMESSAGE,
|
30
|
+
ATTRIBUTE_ROLE,
|
31
|
+
} from "../../dom/constants.mjs";
|
32
|
+
import { getWindow } from "../../dom/util.mjs";
|
33
|
+
import { fireEvent } from "../../dom/events.mjs";
|
31
34
|
|
32
|
-
export {ToggleSwitch};
|
35
|
+
export { ToggleSwitch };
|
33
36
|
|
34
37
|
/**
|
35
38
|
* @private
|
@@ -63,374 +66,363 @@ export const STATE_OFF = "off";
|
|
63
66
|
* @fires monster-changed
|
64
67
|
*/
|
65
68
|
class ToggleSwitch extends CustomControl {
|
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
|
-
return "monster-toggle-switch";
|
325
|
-
}
|
69
|
+
/**
|
70
|
+
* To set the options via the HTML tag, the attribute `data-monster-options` must be used.
|
71
|
+
* @see {@link https://monsterjs.org/en/doc/#configurate-a-monster-control}
|
72
|
+
*
|
73
|
+
* The individual configuration values can be found in the table.
|
74
|
+
*
|
75
|
+
* @property {string} value=current value of the element
|
76
|
+
* @property {Boolean} disabled=disabled=false Disabled state
|
77
|
+
* @property {Object} classes
|
78
|
+
* @property {string} classes.on=specifies the class for the on state.
|
79
|
+
* @property {string} classes.off=specifies the class for the off state.
|
80
|
+
* @property {Object} values
|
81
|
+
* @property {string} values.off=specifies the value of the element if it is not selected
|
82
|
+
* @property {Object} labels
|
83
|
+
* @property {string} labels.on=specifies the label for the on state.
|
84
|
+
* @property {string} labels.off=specifies the label for the off state.
|
85
|
+
* @property {string} actions
|
86
|
+
* @property {string} actions.on=specifies the action for the on state.
|
87
|
+
* @property {string} actions.off=specifies the action for the off state.
|
88
|
+
* @property {Object} templates
|
89
|
+
* @property {string} templates.main the main template used by the control.
|
90
|
+
*/
|
91
|
+
get defaults() {
|
92
|
+
return Object.assign({}, super.defaults, {
|
93
|
+
value: null,
|
94
|
+
disabled: false,
|
95
|
+
classes: {
|
96
|
+
on: "monster-theme-on",
|
97
|
+
off: "monster-theme-off",
|
98
|
+
handle: "monster-theme-primary-1",
|
99
|
+
error: "monster-theme-error-1",
|
100
|
+
},
|
101
|
+
values: {
|
102
|
+
on: "on",
|
103
|
+
off: "off",
|
104
|
+
},
|
105
|
+
labels: {
|
106
|
+
toggleSwitchOn: "✔",
|
107
|
+
toggleSwitchOff: "✖",
|
108
|
+
},
|
109
|
+
templates: {
|
110
|
+
main: getTemplate(),
|
111
|
+
},
|
112
|
+
actions: {
|
113
|
+
on: () => {},
|
114
|
+
off: () => {},
|
115
|
+
},
|
116
|
+
});
|
117
|
+
}
|
118
|
+
|
119
|
+
/**
|
120
|
+
* @return {void}
|
121
|
+
*/
|
122
|
+
[assembleMethodSymbol]() {
|
123
|
+
const self = this;
|
124
|
+
super[assembleMethodSymbol]();
|
125
|
+
|
126
|
+
initControlReferences.call(this);
|
127
|
+
initEventHandler.call(this);
|
128
|
+
|
129
|
+
getWindow().requestAnimationFrame(() => {
|
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
|
+
// this state is a getter
|
151
|
+
if (this.state === STATE_ON) {
|
152
|
+
toggleOn.call(self);
|
153
|
+
} else {
|
154
|
+
toggleOff.call(self);
|
155
|
+
}
|
156
|
+
});
|
157
|
+
}
|
158
|
+
|
159
|
+
/**
|
160
|
+
* updater transformer methods for pipe
|
161
|
+
*
|
162
|
+
* @return {function}
|
163
|
+
*/
|
164
|
+
[updaterTransformerMethodsSymbol]() {
|
165
|
+
return {
|
166
|
+
"state-callback": (Wert) => {
|
167
|
+
return this.state;
|
168
|
+
},
|
169
|
+
};
|
170
|
+
}
|
171
|
+
|
172
|
+
/**
|
173
|
+
* @return [CSSStyleSheet]
|
174
|
+
*/
|
175
|
+
static getCSSStyleSheet() {
|
176
|
+
return [ToggleSwitchStyleSheet];
|
177
|
+
}
|
178
|
+
|
179
|
+
/**
|
180
|
+
* toggle switch
|
181
|
+
*
|
182
|
+
* ```
|
183
|
+
* e = document.querySelector('monster-toggle-switch');
|
184
|
+
* e.click()
|
185
|
+
* ```
|
186
|
+
*/
|
187
|
+
click() {
|
188
|
+
this.toggle();
|
189
|
+
}
|
190
|
+
|
191
|
+
/**
|
192
|
+
* toggle switch on/off
|
193
|
+
*
|
194
|
+
* ```
|
195
|
+
* e = document.querySelector('monster-toggle-switch');
|
196
|
+
* e.toggle()
|
197
|
+
* ```
|
198
|
+
*
|
199
|
+
* @return {ToggleSwitch}
|
200
|
+
*/
|
201
|
+
toggle() {
|
202
|
+
if (this.getOption("value") === this.getOption("values.on")) {
|
203
|
+
return this.toggleOff();
|
204
|
+
}
|
205
|
+
return this.toggleOn();
|
206
|
+
}
|
207
|
+
|
208
|
+
/**
|
209
|
+
* toggle switch on
|
210
|
+
*
|
211
|
+
* ```
|
212
|
+
* e = document.querySelector('monster-toggle-switch');
|
213
|
+
* e.toggleOn()
|
214
|
+
* ```
|
215
|
+
*
|
216
|
+
* @return {ToggleSwitch}
|
217
|
+
*/
|
218
|
+
toggleOn() {
|
219
|
+
this.setOption("value", this.getOption("values.on"));
|
220
|
+
fireEvent(this, "change");
|
221
|
+
return this;
|
222
|
+
}
|
223
|
+
|
224
|
+
/**
|
225
|
+
* toggle switch off
|
226
|
+
*
|
227
|
+
* ```
|
228
|
+
* e = document.querySelector('monster-toggle-switch');
|
229
|
+
* e.toggleOff()
|
230
|
+
* ```
|
231
|
+
*
|
232
|
+
* @return {ToggleSwitch}
|
233
|
+
*/
|
234
|
+
toggleOff() {
|
235
|
+
this.setOption("value", this.getOption("values.off"));
|
236
|
+
fireEvent(this, "change");
|
237
|
+
return this;
|
238
|
+
}
|
239
|
+
|
240
|
+
/**
|
241
|
+
* returns the status of the element
|
242
|
+
*
|
243
|
+
* ```
|
244
|
+
* e = document.querySelector('monster-toggle-switch');
|
245
|
+
* console.log(e.state)
|
246
|
+
* // ↦ off
|
247
|
+
* ```
|
248
|
+
*
|
249
|
+
* @return {string}
|
250
|
+
*/
|
251
|
+
get state() {
|
252
|
+
return this.getOption("value") === this.getOption("values.on")
|
253
|
+
? STATE_ON
|
254
|
+
: STATE_OFF;
|
255
|
+
}
|
256
|
+
|
257
|
+
/**
|
258
|
+
* The current value of the Switch
|
259
|
+
*
|
260
|
+
* ```
|
261
|
+
* e = document.querySelector('monster-toggle-switch');
|
262
|
+
* console.log(e.value)
|
263
|
+
* // ↦ on
|
264
|
+
* ```
|
265
|
+
*
|
266
|
+
* @return {string}
|
267
|
+
*/
|
268
|
+
get value() {
|
269
|
+
return this.getOption("value");
|
270
|
+
}
|
271
|
+
|
272
|
+
/**
|
273
|
+
* Set value
|
274
|
+
*
|
275
|
+
* ```
|
276
|
+
* e = document.querySelector('monster-toggle-switch');
|
277
|
+
* e.value="on"
|
278
|
+
* ```
|
279
|
+
*
|
280
|
+
* @property {string} value
|
281
|
+
*/
|
282
|
+
set value(value) {
|
283
|
+
if (
|
284
|
+
value === this.getOption("values.on") ||
|
285
|
+
value === this.getOption("values.off")
|
286
|
+
) {
|
287
|
+
if (
|
288
|
+
this.state !==
|
289
|
+
(value === this.getOption("values.on") ? STATE_ON : STATE_OFF)
|
290
|
+
) {
|
291
|
+
this.setOption("value", value);
|
292
|
+
}
|
293
|
+
return;
|
294
|
+
}
|
295
|
+
|
296
|
+
addAttributeToken(
|
297
|
+
this,
|
298
|
+
ATTRIBUTE_ERRORMESSAGE,
|
299
|
+
'The value "' +
|
300
|
+
value +
|
301
|
+
'" must be "' +
|
302
|
+
this.getOption("values.on") +
|
303
|
+
'" or "' +
|
304
|
+
this.getOption("values.off"),
|
305
|
+
);
|
306
|
+
|
307
|
+
showError.call(this);
|
308
|
+
}
|
309
|
+
|
310
|
+
/**
|
311
|
+
* This method is called by the `instanceof` operator.
|
312
|
+
* @return {symbol}
|
313
|
+
*/
|
314
|
+
static get [instanceSymbol]() {
|
315
|
+
return Symbol.for(
|
316
|
+
"@schukai/monster/components/form/toggle-switch@@instance",
|
317
|
+
);
|
318
|
+
}
|
319
|
+
|
320
|
+
/**
|
321
|
+
*
|
322
|
+
* @returns {string}
|
323
|
+
*/
|
324
|
+
static getTag() {
|
325
|
+
return "monster-toggle-switch";
|
326
|
+
}
|
326
327
|
}
|
327
328
|
|
328
329
|
/**
|
329
330
|
* @private
|
330
331
|
*/
|
331
332
|
function initControlReferences() {
|
332
|
-
|
333
|
-
|
334
|
-
|
333
|
+
this[switchElementSymbol] = this.shadowRoot.querySelector(
|
334
|
+
`[${ATTRIBUTE_ROLE}=switch]`,
|
335
|
+
);
|
335
336
|
}
|
336
337
|
|
337
|
-
|
338
338
|
/**
|
339
339
|
* @private
|
340
340
|
*/
|
341
341
|
function toggleOn() {
|
342
|
+
if (!this[switchElementSymbol]) {
|
343
|
+
return;
|
344
|
+
}
|
342
345
|
|
343
|
-
|
344
|
-
|
345
|
-
}
|
346
|
+
this[switchElementSymbol].classList.remove(this.getOption("classes.off")); // change color
|
347
|
+
this[switchElementSymbol].classList.add(this.getOption("classes.on")); // change color
|
346
348
|
|
347
|
-
|
348
|
-
|
349
|
+
const callback = this.getOption("actions.on");
|
350
|
+
if (isFunction(callback)) {
|
351
|
+
callback.call(this);
|
352
|
+
}
|
349
353
|
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
}
|
354
|
-
|
355
|
-
if (typeof this.setFormValue === "function") {
|
356
|
-
this.setFormValue(this.getOption("values.on"));
|
357
|
-
}
|
354
|
+
if (typeof this.setFormValue === "function") {
|
355
|
+
this.setFormValue(this.getOption("values.on"));
|
356
|
+
}
|
358
357
|
}
|
359
358
|
|
360
359
|
/**
|
361
360
|
* @private
|
362
361
|
*/
|
363
362
|
function toggleOff() {
|
363
|
+
if (!this[switchElementSymbol]) {
|
364
|
+
return;
|
365
|
+
}
|
364
366
|
|
365
|
-
|
366
|
-
|
367
|
-
}
|
368
|
-
|
369
|
-
this[switchElementSymbol].classList.remove(this.getOption("classes.on")); // change color
|
370
|
-
this[switchElementSymbol].classList.add(this.getOption("classes.off")); // change color
|
371
|
-
|
372
|
-
const callback = this.getOption("actions.off");
|
373
|
-
if (isFunction(callback)) {
|
374
|
-
callback.call(this);
|
375
|
-
}
|
376
|
-
|
377
|
-
if (typeof this.setFormValue === "function") {
|
378
|
-
this.setFormValue(this.getOption("values.off"));
|
379
|
-
}
|
367
|
+
this[switchElementSymbol].classList.remove(this.getOption("classes.on")); // change color
|
368
|
+
this[switchElementSymbol].classList.add(this.getOption("classes.off")); // change color
|
380
369
|
|
370
|
+
const callback = this.getOption("actions.off");
|
371
|
+
if (isFunction(callback)) {
|
372
|
+
callback.call(this);
|
373
|
+
}
|
381
374
|
|
375
|
+
if (typeof this.setFormValue === "function") {
|
376
|
+
this.setFormValue(this.getOption("values.off"));
|
377
|
+
}
|
382
378
|
}
|
383
379
|
|
384
380
|
function showError() {
|
381
|
+
if (!this[switchElementSymbol]) {
|
382
|
+
return;
|
383
|
+
}
|
385
384
|
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
this[switchElementSymbol].classList.remove(this.getOption("classes.on"));
|
391
|
-
this[switchElementSymbol].classList.remove(this.getOption("classes.off"));
|
392
|
-
this[switchElementSymbol].classList.add(this.getOption("classes.error"));
|
385
|
+
this[switchElementSymbol].classList.remove(this.getOption("classes.on"));
|
386
|
+
this[switchElementSymbol].classList.remove(this.getOption("classes.off"));
|
387
|
+
this[switchElementSymbol].classList.add(this.getOption("classes.error"));
|
393
388
|
}
|
394
389
|
|
395
390
|
/**
|
396
391
|
* @private
|
397
392
|
*/
|
398
393
|
function validateAndSetValue() {
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
toggleOff.call(this);
|
432
|
-
|
433
|
-
|
394
|
+
const value = this.getOption("value");
|
395
|
+
|
396
|
+
const validatedValues = [];
|
397
|
+
validatedValues.push(this.getOption("values.on"));
|
398
|
+
validatedValues.push(this.getOption("values.off"));
|
399
|
+
|
400
|
+
if (validatedValues.includes(value) === false) {
|
401
|
+
addAttributeToken(
|
402
|
+
this,
|
403
|
+
ATTRIBUTE_ERRORMESSAGE,
|
404
|
+
'The value "' +
|
405
|
+
value +
|
406
|
+
'" must be "' +
|
407
|
+
this.getOption("values.on") +
|
408
|
+
'" or "' +
|
409
|
+
this.getOption("values.off"),
|
410
|
+
);
|
411
|
+
this.setOption("disabled", true);
|
412
|
+
this.formDisabledCallback(true);
|
413
|
+
showError.call(this);
|
414
|
+
return;
|
415
|
+
}
|
416
|
+
|
417
|
+
this.setOption("disabled", false);
|
418
|
+
this.formDisabledCallback(false);
|
419
|
+
|
420
|
+
if (value === this.getOption("values.on")) {
|
421
|
+
toggleOn.call(this);
|
422
|
+
return;
|
423
|
+
}
|
424
|
+
|
425
|
+
toggleOff.call(this);
|
434
426
|
}
|
435
427
|
|
436
428
|
/**
|
@@ -438,36 +430,36 @@ function validateAndSetValue() {
|
|
438
430
|
* @return {initEventHandler}
|
439
431
|
*/
|
440
432
|
function initEventHandler() {
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
433
|
+
const self = this;
|
434
|
+
|
435
|
+
let lastValue = self.value;
|
436
|
+
self[internalSymbol].attachObserver(
|
437
|
+
new Observer(function () {
|
438
|
+
if (isObject(this) && this instanceof ProxyObserver) {
|
439
|
+
const n = this.getSubject()?.options?.value;
|
440
|
+
if (lastValue !== n) {
|
441
|
+
lastValue = n;
|
442
|
+
validateAndSetValue.call(self);
|
443
|
+
}
|
444
|
+
}
|
445
|
+
}),
|
446
|
+
);
|
447
|
+
|
448
|
+
self.addEventListener("keyup", (event) => {
|
449
|
+
if (event.keyCode === 32) {
|
450
|
+
self.toggle();
|
451
|
+
}
|
452
|
+
});
|
453
|
+
|
454
|
+
self.addEventListener("click", (event) => {
|
455
|
+
self.toggle();
|
456
|
+
});
|
457
|
+
|
458
|
+
self.addEventListener("touch", (event) => {
|
459
|
+
self.toggle();
|
460
|
+
});
|
461
|
+
|
462
|
+
return this;
|
471
463
|
}
|
472
464
|
|
473
465
|
/**
|
@@ -475,8 +467,8 @@ function initEventHandler() {
|
|
475
467
|
* @return {string}
|
476
468
|
*/
|
477
469
|
function getTemplate() {
|
478
|
-
|
479
|
-
|
470
|
+
// language=HTML
|
471
|
+
return `
|
480
472
|
<div data-monster-role="control" part="control" tabindex="0">
|
481
473
|
<div class="switch" data-monster-role="switch"
|
482
474
|
data-monster-attributes="data-monster-state path:value | call:state-callback">
|