@schukai/monster 3.96.0 → 3.96.2

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.
Files changed (40) hide show
  1. package/CHANGELOG.md +22 -5
  2. package/package.json +1 -1
  3. package/source/components/content/copy.mjs +1 -1
  4. package/source/components/datatable/change-button.mjs +39 -41
  5. package/source/components/datatable/dataset.mjs +337 -327
  6. package/source/components/datatable/datasource/rest.mjs +3 -22
  7. package/source/components/datatable/embedded-pagination.mjs +3 -1
  8. package/source/components/datatable/pagination.mjs +14 -7
  9. package/source/components/datatable/save-button.mjs +25 -3
  10. package/source/components/datatable/status.mjs +21 -26
  11. package/source/components/datatable/style/status.pcss +12 -2
  12. package/source/components/datatable/stylesheet/status.mjs +1 -1
  13. package/source/components/datatable/util.mjs +1 -2
  14. package/source/components/form/api-bar.mjs +1 -1
  15. package/source/components/form/api-button.mjs +1 -1
  16. package/source/components/form/button-bar.mjs +1 -1
  17. package/source/components/form/button.mjs +2 -2
  18. package/source/components/form/confirm-button.mjs +1 -1
  19. package/source/components/form/form.mjs +6 -5
  20. package/source/components/form/select.mjs +12 -9
  21. package/source/components/form/style/field-set.pcss +35 -5
  22. package/source/components/form/style/toggle-switch.pcss +16 -2
  23. package/source/components/form/stylesheet/field-set.mjs +1 -1
  24. package/source/components/form/stylesheet/toggle-switch.mjs +1 -1
  25. package/source/components/form/toggle-switch.mjs +139 -91
  26. package/source/components/layout/tabs.mjs +4 -5
  27. package/source/components/layout/width-toggle.mjs +1 -1
  28. package/source/components/navigation/table-of-content.mjs +1 -1
  29. package/source/components/notify/message.mjs +1 -1
  30. package/source/components/notify/notify.mjs +2 -2
  31. package/source/components/state/log.mjs +1 -1
  32. package/source/components/state/state.mjs +1 -1
  33. package/source/components/style/theme.css +4 -4
  34. package/source/dom/constants.mjs +7 -5
  35. package/source/dom/updater.mjs +3 -6
  36. package/source/types/version.mjs +1 -1
  37. package/test/cases/components/form/toggle-switch.mjs +80 -65
  38. package/test/cases/monster.mjs +1 -1
  39. package/test/web/test.html +2 -2
  40. package/test/web/tests.js +154 -104
@@ -12,8 +12,7 @@
12
12
  * SPDX-License-Identifier: AGPL-3.0
13
13
  */
14
14
 
15
- import { instanceSymbol } from "../../constants.mjs";
16
- import { internalSymbol } from "../../constants.mjs";
15
+ import { instanceSymbol, internalSymbol } from "../../constants.mjs";
17
16
  import { CustomControl } from "../../dom/customcontrol.mjs";
18
17
  import { Observer } from "../../types/observer.mjs";
19
18
  import { ProxyObserver } from "../../types/proxyobserver.mjs";
@@ -24,12 +23,14 @@ import {
24
23
  registerCustomElement,
25
24
  updaterTransformerMethodsSymbol,
26
25
  } from "../../dom/customelement.mjs";
27
- import { isObject, isFunction } from "../../types/is.mjs";
26
+ import { isFunction, isObject } from "../../types/is.mjs";
28
27
  import { ToggleSwitchStyleSheet } from "./stylesheet/toggle-switch.mjs";
29
28
  import {
30
29
  ATTRIBUTE_ERRORMESSAGE,
31
30
  ATTRIBUTE_ROLE,
32
31
  } from "../../dom/constants.mjs";
32
+ import { getWindow } from "../../dom/util.mjs";
33
+ import { fireEvent } from "../../dom/events.mjs";
33
34
 
34
35
  export { ToggleSwitch };
35
36
 
@@ -54,7 +55,7 @@ export const STATE_OFF = "off";
54
55
  *
55
56
  * @fragments /fragments/components/form/toggle-switch
56
57
  *
57
- * @example /examples/components/form/toggle-switch-simple
58
+ * @example /examples/components/form/toggle-switch-simple Simple example
58
59
  *
59
60
  * @since 3.57.0
60
61
  * @copyright schukai GmbH
@@ -85,7 +86,7 @@ class ToggleSwitch extends CustomControl {
85
86
  * @property {string} actions.on=specifies the action for the on state.
86
87
  * @property {string} actions.off=specifies the action for the off state.
87
88
  * @property {Object} templates
88
- * @property {string} templates.main=specifies the main template used by the control.
89
+ * @property {string} templates.main the main template used by the control.
89
90
  */
90
91
  get defaults() {
91
92
  return Object.assign({}, super.defaults, {
@@ -95,6 +96,7 @@ class ToggleSwitch extends CustomControl {
95
96
  on: "monster-theme-on",
96
97
  off: "monster-theme-off",
97
98
  handle: "monster-theme-primary-1",
99
+ error: "monster-theme-error-1",
98
100
  },
99
101
  values: {
100
102
  on: "on",
@@ -115,53 +117,43 @@ class ToggleSwitch extends CustomControl {
115
117
  }
116
118
 
117
119
  /**
118
- * @return {ToggleSwitch}
120
+ * @return {void}
119
121
  */
120
122
  [assembleMethodSymbol]() {
121
123
  const self = this;
122
124
  super[assembleMethodSymbol]();
125
+
123
126
  initControlReferences.call(this);
124
127
  initEventHandler.call(this);
125
128
 
126
- /**
127
- * init value to off
128
- * if the value was not defined before inserting it into the HTML
129
- */
130
- if (self.getOption("value") === null) {
131
- self.setOption("value", self.getOption("values.off"));
132
- }
133
-
134
- /**
135
- * value from attribute
136
- */
137
- if (self.hasAttribute("value")) {
138
- self.setOption("value", self.getAttribute("value"));
139
- }
140
-
141
- /**
142
- * validate value
143
- */
144
- validateAndSetValue.call(self);
145
-
146
- if (this.state === STATE_ON) {
147
- toggleClassOn.call(self);
148
- } else {
149
- toggleClassOff.call(self);
150
- }
151
-
152
- /**
153
- * is called when options changed
154
- */
155
- self[internalSymbol].attachObserver(
156
- new Observer(function () {
157
- if (isObject(this) && this instanceof ProxyObserver) {
158
- validateAndSetValue.call(self);
159
- toggleClass.call(self);
160
- }
161
- }),
162
- );
163
-
164
- return this;
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
+ });
165
157
  }
166
158
 
167
159
  /**
@@ -193,7 +185,7 @@ class ToggleSwitch extends CustomControl {
193
185
  * ```
194
186
  */
195
187
  click() {
196
- toggleValues.call(this);
188
+ this.toggle();
197
189
  }
198
190
 
199
191
  /**
@@ -207,8 +199,10 @@ class ToggleSwitch extends CustomControl {
207
199
  * @return {ToggleSwitch}
208
200
  */
209
201
  toggle() {
210
- this.click();
211
- return this;
202
+ if (this.getOption("value") === this.getOption("values.on")) {
203
+ return this.toggleOff();
204
+ }
205
+ return this.toggleOn();
212
206
  }
213
207
 
214
208
  /**
@@ -223,6 +217,7 @@ class ToggleSwitch extends CustomControl {
223
217
  */
224
218
  toggleOn() {
225
219
  this.setOption("value", this.getOption("values.on"));
220
+ fireEvent(this, "change");
226
221
  return this;
227
222
  }
228
223
 
@@ -238,6 +233,7 @@ class ToggleSwitch extends CustomControl {
238
233
  */
239
234
  toggleOff() {
240
235
  this.setOption("value", this.getOption("values.off"));
236
+ fireEvent(this, "change");
241
237
  return this;
242
238
  }
243
239
 
@@ -270,9 +266,7 @@ class ToggleSwitch extends CustomControl {
270
266
  * @return {string}
271
267
  */
272
268
  get value() {
273
- return this.state === STATE_ON
274
- ? this.getOption("values.on")
275
- : this.getOption("values.off");
269
+ return this.getOption("value");
276
270
  }
277
271
 
278
272
  /**
@@ -286,7 +280,31 @@ class ToggleSwitch extends CustomControl {
286
280
  * @property {string} value
287
281
  */
288
282
  set value(value) {
289
- this.setOption("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);
290
308
  }
291
309
 
292
310
  /**
@@ -299,6 +317,10 @@ class ToggleSwitch extends CustomControl {
299
317
  );
300
318
  }
301
319
 
320
+ /**
321
+ *
322
+ * @returns {string}
323
+ */
302
324
  static getTag() {
303
325
  return "monster-toggle-switch";
304
326
  }
@@ -316,56 +338,53 @@ function initControlReferences() {
316
338
  /**
317
339
  * @private
318
340
  */
319
- function toggleClassOn() {
341
+ function toggleOn() {
342
+ if (!this[switchElementSymbol]) {
343
+ return;
344
+ }
345
+
320
346
  this[switchElementSymbol].classList.remove(this.getOption("classes.off")); // change color
321
347
  this[switchElementSymbol].classList.add(this.getOption("classes.on")); // change color
322
- }
323
348
 
324
- /**
325
- * @private
326
- */
327
- function toggleClassOff() {
328
- this[switchElementSymbol].classList.remove(this.getOption("classes.on")); // change color
329
- this[switchElementSymbol].classList.add(this.getOption("classes.off")); // change color
330
- }
349
+ const callback = this.getOption("actions.on");
350
+ if (isFunction(callback)) {
351
+ callback.call(this);
352
+ }
331
353
 
332
- /**
333
- * @private
334
- */
335
- function toggleClass() {
336
- if (this.getOption("value") === this.getOption("values.on")) {
337
- toggleClassOn.call(this);
338
- } else {
339
- toggleClassOff.call(this);
354
+ if (typeof this.setFormValue === "function") {
355
+ this.setFormValue(this.getOption("values.on"));
340
356
  }
341
357
  }
342
358
 
343
359
  /**
344
360
  * @private
345
361
  */
346
- function toggleValues() {
347
- if (this.getOption("disabled") === true) {
362
+ function toggleOff() {
363
+ if (!this[switchElementSymbol]) {
348
364
  return;
349
365
  }
350
366
 
351
- let callback, value;
367
+ this[switchElementSymbol].classList.remove(this.getOption("classes.on")); // change color
368
+ this[switchElementSymbol].classList.add(this.getOption("classes.off")); // change color
352
369
 
353
- if (this.getOption("value") === this.getOption("values.on")) {
354
- value = this.getOption("values.off");
355
- callback = this.getOption("actions.off");
356
- } else {
357
- value = this.getOption("values.on");
358
- callback = this.getOption("actions.on");
370
+ const callback = this.getOption("actions.off");
371
+ if (isFunction(callback)) {
372
+ callback.call(this);
359
373
  }
360
374
 
361
- this.setOption("value", value);
362
- this?.setFormValue(value);
375
+ if (typeof this.setFormValue === "function") {
376
+ this.setFormValue(this.getOption("values.off"));
377
+ }
378
+ }
363
379
 
364
- if (isFunction(callback)) {
365
- callback.call(this);
380
+ function showError() {
381
+ if (!this[switchElementSymbol]) {
382
+ return;
366
383
  }
367
384
 
368
- this.setOption("state", this.state);
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"));
369
388
  }
370
389
 
371
390
  /**
@@ -391,10 +410,19 @@ function validateAndSetValue() {
391
410
  );
392
411
  this.setOption("disabled", true);
393
412
  this.formDisabledCallback(true);
394
- } else {
395
- this.setOption("disabled", false);
396
- this.formDisabledCallback(false);
413
+ showError.call(this);
414
+ return;
397
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);
398
426
  }
399
427
 
400
428
  /**
@@ -403,14 +431,34 @@ function validateAndSetValue() {
403
431
  */
404
432
  function initEventHandler() {
405
433
  const self = this;
406
- self.addEventListener("keyup", function (event) {
407
- if (event.code === "Space") {
408
- self[switchElementSymbol].click();
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();
409
451
  }
410
452
  });
411
- self.addEventListener("click", function (event) {
412
- toggleValues.call(self);
453
+
454
+ self.addEventListener("click", (event) => {
455
+ self.toggle();
456
+ });
457
+
458
+ self.addEventListener("touch", (event) => {
459
+ self.toggle();
413
460
  });
461
+
414
462
  return this;
415
463
  }
416
464
 
@@ -145,9 +145,9 @@ const resizeObserverSymbol = Symbol("resizeObserver");
145
145
  *
146
146
  * @fragments /fragments/components/layout/tabs/
147
147
  *
148
- * @example /examples/components/layout/tabs-simple
149
- * @example /examples/components/layout/tabs-active
150
- * @example /examples/components/layout/tabs-removable
148
+ * @example /examples/components/layout/tabs-simple Simple Tabs
149
+ * @example /examples/components/layout/tabs-active Active Tabs
150
+ * @example /examples/components/layout/tabs-removable Removable Tabs
151
151
  *
152
152
  * @issue https://localhost.alvine.dev:8443/development/issues/closed/268.html
153
153
  * @issue https://localhost.alvine.dev:8443/development/issues/closed/271.html
@@ -921,8 +921,7 @@ function initTabButtons() {
921
921
  this.setOption("marker", random());
922
922
 
923
923
  return adjustButtonVisibility.call(this).then(() => {
924
-
925
- if (!activeReference&& this.getOption("features.openFirst") === true) {
924
+ if (!activeReference && this.getOption("features.openFirst") === true) {
926
925
  const firstButton = this.getOption("buttons.standard").find(
927
926
  (button) => button.disabled !== true,
928
927
  );
@@ -59,7 +59,7 @@ const MODE_WIDE = "wide";
59
59
  *
60
60
  * @fragments /fragments/components/layout/width-toggle/
61
61
  *
62
- * @example /examples/components/layout/width-toggle-simple
62
+ * @example /examples/components/layout/width-toggle-simple Toggle Width
63
63
  *
64
64
  * @since 3.57.0
65
65
  * @copyright schukai GmbH
@@ -73,7 +73,7 @@ const scrollableEventHandlerSymbol = Symbol("scrollableEventHandler");
73
73
  *
74
74
  * @fragments /fragments/components/form/table-of-content
75
75
  *
76
- * @example /examples/components/form/table-of-content-simple
76
+ * @example /examples/components/form/table-of-content-simple Table of content
77
77
  *
78
78
  * @since 3.65.0
79
79
  * @copyright schukai GmbH
@@ -70,7 +70,7 @@ const removeEventHandlerSymbol = Symbol("removeEventHandler");
70
70
  *
71
71
  * @fragments /fragments/components/notify/message
72
72
  *
73
- * @example /examples/components/notify/message-simple
73
+ * @example /examples/components/notify/message-simple Message
74
74
  *
75
75
  * @issue https://localhost.alvine.dev:8443/development/issues/closed/269.html
76
76
  *
@@ -49,8 +49,8 @@ const queueSymbol = Symbol("queue");
49
49
  *
50
50
  * @fragments /fragments/components/notify/notify
51
51
  *
52
- * @example /examples/components/notify/notify-simple
53
- * @example /examples/components/notify/notify-inline
52
+ * @example /examples/components/notify/notify-simple Notify
53
+ * @example /examples/components/notify/notify-inline Inline Notify
54
54
  *
55
55
  * @issue https://localhost.alvine.dev:8443/development/issues/closed/269.html
56
56
  *
@@ -44,7 +44,7 @@ const emptyStateElementSymbol = Symbol("emptyStateElement");
44
44
  *
45
45
  * @fragments /fragments/components/state/log
46
46
  *
47
- * @example /examples/components/state/log-simple
47
+ * @example /examples/components/state/log-simple Log
48
48
  *
49
49
  * @issue https://localhost.alvine.dev:8444/development/issues/closed/270.html
50
50
  *
@@ -27,7 +27,7 @@ export { State };
27
27
  *
28
28
  * @fragments /fragments/components/state/state
29
29
  *
30
- * @example /examples/components/state/state-simple
30
+ * @example /examples/components/state/state-simple State
31
31
  *
32
32
  * @since 1.5.0
33
33
  * @copyright schukai GmbH
@@ -36,7 +36,7 @@
36
36
  color: var(--monster-color-selection-1);
37
37
  }
38
38
  .monster-border-color-1 {
39
- border-color: var(--monster-color-border-1);
39
+ border-color: var(--monster-color-primary-4);
40
40
  }
41
41
  .monster-color-neutral-1 {
42
42
  color: var(--monster-color-primary-1);
@@ -119,7 +119,7 @@
119
119
  color: var(--monster-color-selection-2);
120
120
  }
121
121
  .monster-border-color-2 {
122
- border-color: var(--monster-color-border-2);
122
+ border-color: var(--monster-color-primary-3);
123
123
  }
124
124
  .monster-color-neutral-2 {
125
125
  color: var(--monster-color-primary-2);
@@ -202,7 +202,7 @@
202
202
  color: var(--monster-color-selection-3);
203
203
  }
204
204
  .monster-border-color-3 {
205
- border-color: var(--monster-color-border-3);
205
+ border-color: var(--monster-color-primary-2);
206
206
  }
207
207
  .monster-color-neutral-3 {
208
208
  color: var(--monster-color-primary-3);
@@ -285,7 +285,7 @@
285
285
  color: var(--monster-color-selection-4);
286
286
  }
287
287
  .monster-border-color-4 {
288
- border-color: var(--monster-color-border-4);
288
+ border-color: var(--monster-color-primary-1);
289
289
  }
290
290
  .monster-color-neutral-4 {
291
291
  color: var(--monster-color-primary-4);
@@ -196,23 +196,25 @@ const ATTRIBUTE_UPDATER_BIND = `${ATTRIBUTE_PREFIX}bind`;
196
196
  /**
197
197
  * @type {string}
198
198
  * @license AGPLv3
199
- * @since 3.73.0
199
+ * @since 1.9.0
200
200
  */
201
- const ATTRIBUTE_FORM_BIND = `${ATTRIBUTE_PREFIX}form-bind`;
201
+ const ATTRIBUTE_UPDATER_BIND_TYPE = `${ATTRIBUTE_UPDATER_BIND}-type`;
202
202
 
203
203
  /**
204
204
  * @type {string}
205
205
  * @license AGPLv3
206
+ * @deprecated since 2024-12-29
206
207
  * @since 3.73.0
207
208
  */
208
- const ATTRIBUTE_FORM_BIND_TYPE = `${ATTRIBUTE_PREFIX}form-bind-type`;
209
+ const ATTRIBUTE_FORM_BIND = `${ATTRIBUTE_PREFIX}form-bind`;
209
210
 
210
211
  /**
211
212
  * @type {string}
212
213
  * @license AGPLv3
213
- * @since 1.9.0
214
+ * @since 3.73.0
215
+ * @deprecated since 2024-12-29
214
216
  */
215
- const ATTRIBUTE_UPDATER_BIND_TYPE = `${ATTRIBUTE_UPDATER_BIND}-type`;
217
+ const ATTRIBUTE_FORM_BIND_TYPE = `${ATTRIBUTE_PREFIX}form-bind-type`;
216
218
 
217
219
  /**
218
220
  * @type {string}
@@ -74,7 +74,7 @@ class Updater extends Base {
74
74
  * @param {object|ProxyObserver|undefined} subject
75
75
  * @throws {TypeError} value is not a object
76
76
  * @throws {TypeError} value is not an instance of HTMLElement
77
- * @see {@link Monster.DOM.findDocumentTemplate}
77
+ * @see {@link findDocumentTemplate}
78
78
  */
79
79
  constructor(element, subject) {
80
80
  super();
@@ -305,6 +305,7 @@ function getControlEventHandler() {
305
305
  if (element === undefined) {
306
306
  return;
307
307
  }
308
+
308
309
  queueMicrotask(() => {
309
310
  retrieveAndSetValue.call(this, element);
310
311
  });
@@ -850,11 +851,7 @@ function handleInputControlAttributeUpdate(element, name, value) {
850
851
  switch (element.type) {
851
852
  case "select-multiple":
852
853
  for (const [index, opt] of Object.entries(element.options)) {
853
- if (value.indexOf(opt.value) !== -1) {
854
- opt.selected = true;
855
- } else {
856
- opt.selected = false;
857
- }
854
+ opt.selected = value.indexOf(opt.value) !== -1;
858
855
  }
859
856
 
860
857
  break;
@@ -156,7 +156,7 @@ function getMonsterVersion() {
156
156
  }
157
157
 
158
158
  /** don't touch, replaced by make with package.json version */
159
- monsterVersion = new Version("3.95.2");
159
+ monsterVersion = new Version("3.96.1");
160
160
 
161
161
  return monsterVersion;
162
162
  }