@schukai/monster 4.57.0 → 4.58.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.
Files changed (29) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/package.json +1 -1
  3. package/source/components/data/stylesheet/metric-graph.mjs +1 -1
  4. package/source/components/data/stylesheet/metric.mjs +1 -1
  5. package/source/components/datatable/datasource/rest.mjs +141 -14
  6. package/source/components/datatable/datatable.mjs +3 -7
  7. package/source/components/datatable/save-button.mjs +348 -334
  8. package/source/components/datatable/status.mjs +7 -0
  9. package/source/components/datatable/util.mjs +7 -0
  10. package/source/components/form/button-bar.mjs +193 -95
  11. package/source/components/form/field-set.mjs +283 -283
  12. package/source/components/form/form.mjs +407 -169
  13. package/source/components/form/login.mjs +1571 -1571
  14. package/source/components/form/quantity.mjs +233 -233
  15. package/source/components/form/select.mjs +3106 -3101
  16. package/source/components/form/style/field-set.pcss +6 -2
  17. package/source/components/form/style/form.pcss +8 -0
  18. package/source/components/form/stylesheet/field-set.mjs +1 -1
  19. package/source/components/form/stylesheet/form.mjs +1 -1
  20. package/source/components/form/stylesheet/select.mjs +13 -6
  21. package/source/components/style/typography.css +2 -2
  22. package/source/components/tree-menu/stylesheet/tree-menu.mjs +1 -1
  23. package/source/constraints/abstract.mjs +17 -17
  24. package/source/dom/customelement.mjs +962 -963
  25. package/source/dom/updater.mjs +874 -863
  26. package/source/dom/util/init-options-from-attributes.mjs +56 -56
  27. package/source/monster.mjs +0 -1
  28. package/source/net/webconnect.mjs +325 -325
  29. package/source/types/is.mjs +66 -66
@@ -17,9 +17,9 @@ import { diff } from "../../data/diff.mjs";
17
17
  import { addAttributeToken } from "../../dom/attributes.mjs";
18
18
  import { ATTRIBUTE_ERRORMESSAGE } from "../../dom/constants.mjs";
19
19
  import {
20
- assembleMethodSymbol,
21
- CustomElement,
22
- registerCustomElement,
20
+ assembleMethodSymbol,
21
+ CustomElement,
22
+ registerCustomElement,
23
23
  } from "../../dom/customelement.mjs";
24
24
  import { findElementWithSelectorUpwards } from "../../dom/util.mjs";
25
25
  import { isString, isArray } from "../../types/is.mjs";
@@ -35,8 +35,8 @@ import { SaveButtonStyleSheet } from "./stylesheet/save-button.mjs";
35
35
  import "../form/state-button.mjs";
36
36
 
37
37
  import {
38
- handleDataSourceChanges,
39
- datasourceLinkedElementSymbol,
38
+ handleDataSourceChanges,
39
+ datasourceLinkedElementSymbol,
40
40
  } from "./util.mjs";
41
41
  import { getLocaleOfDocument } from "../../dom/locale.mjs";
42
42
 
@@ -59,6 +59,7 @@ const originValuesSymbol = Symbol("originValues");
59
59
  * @type {symbol}
60
60
  */
61
61
  const badgeElementSymbol = Symbol("badgeElement");
62
+ const saveInFlightSymbol = Symbol("saveInFlight");
62
63
 
63
64
  /**
64
65
  * A save button component
@@ -73,273 +74,276 @@ const badgeElementSymbol = Symbol("badgeElement");
73
74
  * @summary This is a save button component that can be used to save changes to a datasource.
74
75
  */
75
76
  class SaveButton extends CustomElement {
76
- /**
77
- * This method is called by the `instanceof` operator.
78
- * @return {symbol}
79
- */
80
- static get [instanceSymbol]() {
81
- return Symbol.for(
82
- "@schukai/monster/components/datatable/save-button@@instance",
83
- );
84
- }
85
-
86
- /**
87
- * To set the options via the HTML tag, the attribute `data-monster-options` must be used.
88
- * @see {@link https://monsterjs.org/en/doc/#configurate-a-monster-control}
89
- *
90
- * The individual configuration values can be found in the table.
91
- *
92
- * @property {Object} templates Template definitions
93
- * @property {string} templates.main Main template
94
- * @property {object} datasource The datasource
95
- * @property {string} datasource.selector The selector of the datasource
96
- * @property {string} labels.button The button label
97
- * @property {Object} classes The classes
98
- * @property {string} classes.bar The bar class
99
- * @property {string} classes.badge The badge class
100
- * @property {Array} ignoreChanges The ignore changes (regex)
101
- * @property {Array} data The data
102
- * @property {boolean} disabled The disabled state
103
- * @property {string} logLevel The log level (off, debug)
104
- * @return {Object}
105
- */
106
- get defaults() {
107
- const obj = Object.assign({}, super.defaults, {
108
- templates: {
109
- main: getTemplate(),
110
- },
111
-
112
- labels: getTranslations(),
113
-
114
- classes: {
115
- bar: "monster-button-primary",
116
- badge: "monster-badge-secondary hidden",
117
- },
118
-
119
- datasource: {
120
- selector: null,
121
- },
122
-
123
- changes: "0",
124
-
125
- ignoreChanges: [],
126
-
127
- data: {},
128
-
129
- disabled: false,
130
-
131
- logLevel: "off",
132
- });
133
-
134
- updateOptionsFromArguments.call(this, obj);
135
- return obj;
136
- }
137
-
138
- /**
139
- *
140
- * @return {string}
141
- */
142
- static getTag() {
143
- return "monster-datasource-save-button";
144
- }
145
-
146
- /**
147
- * This method is responsible for assembling the component.
148
- *
149
- * It calls the parent's assemble method first, then initializes control references and event handlers.
150
- * If the `datasource.selector` option is provided and is a string, it searches for the corresponding
151
- * element in the DOM using that selector.
152
- *
153
- * If the selector matches exactly one element, it checks if the element is an instance of the `Datasource` class.
154
- *
155
- * If it is, the component's `datasourceLinkedElementSymbol` property is set to the element, and the component
156
- * attaches an observer to the datasource's changes.
157
- *
158
- * The observer is a function that calls the `handleDataSourceChanges` method in the context of the component.
159
- * Additionally, the component attaches an observer to itself, which also calls the `handleDataSourceChanges`
160
- * method in the component's context.
161
- */
162
- [assembleMethodSymbol]() {
163
- super[assembleMethodSymbol]();
164
- const self = this;
165
-
166
- initControlReferences.call(this);
167
- initEventHandler.call(this);
168
-
169
- const selector = this.getOption("datasource.selector");
170
-
171
- if (isString(selector)) {
172
- const element = findElementWithSelectorUpwards(this, selector);
173
- if (element === null) {
174
- throw new Error("the selector must match exactly one element");
175
- }
176
-
177
- if (!(element instanceof Datasource)) {
178
- throw new TypeError("the element must be a datasource");
179
- }
180
-
181
- if (element instanceof RestDatasource) {
182
- element.addEventListener("monster-datasource-fetch", (event) => {
183
- self[originValuesSymbol] = null;
184
- });
185
- }
186
-
187
- this[datasourceLinkedElementSymbol] = element;
188
- element.datasource.attachObserver(
189
- new Observer(handleDataSourceChanges.bind(this)),
190
- );
191
-
192
- self[originValuesSymbol] = null;
193
-
194
- element.datasource.attachObserver(
195
- new Observer(function () {
196
- if (!self[originValuesSymbol]) {
197
- self[originValuesSymbol] = clone(
198
- self[datasourceLinkedElementSymbol].data,
199
- );
200
- }
201
-
202
- const currentValues = this.getRealSubject();
203
- const ignoreChanges = self.getOption("ignoreChanges");
204
-
205
- const result = diff(self[originValuesSymbol], currentValues);
206
- if (
207
- self.getOption("logLevel") === "debug" ||
208
- location.search.includes("logLevel=debug")
209
- ) {
210
- console.groupCollapsed("SaveButton");
211
- console.log(
212
- "originValues",
213
- JSON.parse(JSON.stringify(currentValues)),
214
- );
215
- console.log("result of diff", result);
216
- console.log("ignoreChanges", ignoreChanges);
217
-
218
- if (isArray(result) && result.length > 0) {
219
- const formattedDiff = result.map((change) => ({
220
- Operator: change?.operator,
221
- Path: change?.path?.join("."),
222
- "First Value": change?.first?.value,
223
- "First Type": change?.first?.type,
224
- "Second Value": change?.second?.value,
225
- "Second Type": change?.second?.type,
226
- }));
227
-
228
- console.table(formattedDiff);
229
- } else {
230
- console.log("There are no changes to save");
231
- }
232
- console.groupEnd();
233
- }
234
-
235
- if (isArray(ignoreChanges) && ignoreChanges.length > 0) {
236
- const itemsToRemove = [];
237
- for (const item of result) {
238
- for (const ignorePattern of ignoreChanges) {
239
- const p = new RegExp(ignorePattern);
240
-
241
- let matchPath = item.path;
242
- if (isArray(item.path)) {
243
- matchPath = item.path.join(".");
244
- }
245
-
246
- if (p.test(matchPath)) {
247
- itemsToRemove.push(item);
248
- break;
249
- }
250
- }
251
- }
252
-
253
- for (const itemToRemove of itemsToRemove) {
254
- const index = result.indexOf(itemToRemove);
255
- if (index > -1) {
256
- result.splice(index, 1);
257
- }
258
- }
259
- }
260
-
261
- if (isArray(result) && result.length > 0) {
262
- self[stateButtonElementSymbol].setState("changed");
263
- self[stateButtonElementSymbol].setOption("disabled", false);
264
- self.setOption("changes", result.length);
265
- self.setOption(
266
- "classes.badge",
267
- new TokenList(self.getOption("classes.badge"))
268
- .remove("hidden")
269
- .toString(),
270
- );
271
- } else {
272
- self[stateButtonElementSymbol].removeState();
273
- self[stateButtonElementSymbol].setOption("disabled", true);
274
- self.setOption("changes", 0);
275
- self.setOption(
276
- "classes.badge",
277
- new TokenList(self.getOption("classes.badge"))
278
- .add("hidden")
279
- .toString(),
280
- );
281
- }
282
- }),
283
- );
284
- }
285
-
286
- this.attachObserver(
287
- new Observer(() => {
288
- handleDataSourceChanges.call(this);
289
- }),
290
- );
291
- }
292
-
293
- /**
294
- *
295
- * @return [CSSStyleSheet]
296
- */
297
- static getCSSStyleSheet() {
298
- return [SaveButtonStyleSheet, BadgeStyleSheet];
299
- }
77
+ /**
78
+ * This method is called by the `instanceof` operator.
79
+ * @return {symbol}
80
+ */
81
+ static get [instanceSymbol]() {
82
+ return Symbol.for(
83
+ "@schukai/monster/components/datatable/save-button@@instance",
84
+ );
85
+ }
86
+
87
+ /**
88
+ * To set the options via the HTML tag, the attribute `data-monster-options` must be used.
89
+ * @see {@link https://monsterjs.org/en/doc/#configurate-a-monster-control}
90
+ *
91
+ * The individual configuration values can be found in the table.
92
+ *
93
+ * @property {Object} templates Template definitions
94
+ * @property {string} templates.main Main template
95
+ * @property {object} datasource The datasource
96
+ * @property {string} datasource.selector The selector of the datasource
97
+ * @property {string} labels.button The button label
98
+ * @property {Object} classes The classes
99
+ * @property {string} classes.bar The bar class
100
+ * @property {string} classes.badge The badge class
101
+ * @property {Array} ignoreChanges The ignore changes (regex)
102
+ * @property {Array} data The data
103
+ * @property {boolean} disabled The disabled state
104
+ * @property {string} logLevel The log level (off, debug)
105
+ * @return {Object}
106
+ */
107
+ get defaults() {
108
+ const obj = Object.assign({}, super.defaults, {
109
+ templates: {
110
+ main: getTemplate(),
111
+ },
112
+
113
+ labels: getTranslations(),
114
+
115
+ classes: {
116
+ bar: "monster-button-primary",
117
+ badge: "monster-badge-secondary hidden",
118
+ },
119
+
120
+ datasource: {
121
+ selector: null,
122
+ },
123
+
124
+ changes: "0",
125
+
126
+ ignoreChanges: [],
127
+
128
+ data: {},
129
+
130
+ disabled: false,
131
+
132
+ logLevel: "off",
133
+ });
134
+
135
+ updateOptionsFromArguments.call(this, obj);
136
+ return obj;
137
+ }
138
+
139
+ /**
140
+ *
141
+ * @return {string}
142
+ */
143
+ static getTag() {
144
+ return "monster-datasource-save-button";
145
+ }
146
+
147
+ /**
148
+ * This method is responsible for assembling the component.
149
+ *
150
+ * It calls the parent's assemble method first, then initializes control references and event handlers.
151
+ * If the `datasource.selector` option is provided and is a string, it searches for the corresponding
152
+ * element in the DOM using that selector.
153
+ *
154
+ * If the selector matches exactly one element, it checks if the element is an instance of the `Datasource` class.
155
+ *
156
+ * If it is, the component's `datasourceLinkedElementSymbol` property is set to the element, and the component
157
+ * attaches an observer to the datasource's changes.
158
+ *
159
+ * The observer is a function that calls the `handleDataSourceChanges` method in the context of the component.
160
+ * Additionally, the component attaches an observer to itself, which also calls the `handleDataSourceChanges`
161
+ * method in the component's context.
162
+ */
163
+ [assembleMethodSymbol]() {
164
+ super[assembleMethodSymbol]();
165
+ const self = this;
166
+
167
+ initControlReferences.call(this);
168
+ initEventHandler.call(this);
169
+
170
+ const selector = this.getOption("datasource.selector");
171
+
172
+ if (isString(selector)) {
173
+ const element = findElementWithSelectorUpwards(this, selector);
174
+ if (element === null) {
175
+ throw new Error("the selector must match exactly one element");
176
+ }
177
+
178
+ if (!(element instanceof Datasource)) {
179
+ throw new TypeError("the element must be a datasource");
180
+ }
181
+
182
+ if (element instanceof RestDatasource) {
183
+ element.addEventListener("monster-datasource-fetch", (event) => {
184
+ if (self[saveInFlightSymbol]) {
185
+ return;
186
+ }
187
+ self[originValuesSymbol] = null;
188
+ });
189
+ }
190
+
191
+ this[datasourceLinkedElementSymbol] = element;
192
+ element.datasource.attachObserver(
193
+ new Observer(handleDataSourceChanges.bind(this)),
194
+ );
195
+
196
+ self[originValuesSymbol] = null;
197
+
198
+ element.datasource.attachObserver(
199
+ new Observer(function () {
200
+ if (!self[originValuesSymbol]) {
201
+ self[originValuesSymbol] = clone(
202
+ self[datasourceLinkedElementSymbol].data,
203
+ );
204
+ }
205
+
206
+ const currentValues = this.getRealSubject();
207
+ const ignoreChanges = self.getOption("ignoreChanges");
208
+
209
+ const result = diff(self[originValuesSymbol], currentValues);
210
+ if (
211
+ self.getOption("logLevel") === "debug" ||
212
+ location.search.includes("logLevel=debug")
213
+ ) {
214
+ console.groupCollapsed("SaveButton");
215
+ console.log(
216
+ "originValues",
217
+ JSON.parse(JSON.stringify(currentValues)),
218
+ );
219
+ console.log("result of diff", result);
220
+ console.log("ignoreChanges", ignoreChanges);
221
+
222
+ if (isArray(result) && result.length > 0) {
223
+ const formattedDiff = result.map((change) => ({
224
+ Operator: change?.operator,
225
+ Path: change?.path?.join("."),
226
+ "First Value": change?.first?.value,
227
+ "First Type": change?.first?.type,
228
+ "Second Value": change?.second?.value,
229
+ "Second Type": change?.second?.type,
230
+ }));
231
+
232
+ console.table(formattedDiff);
233
+ } else {
234
+ console.log("There are no changes to save");
235
+ }
236
+ console.groupEnd();
237
+ }
238
+
239
+ if (isArray(ignoreChanges) && ignoreChanges.length > 0) {
240
+ const itemsToRemove = [];
241
+ for (const item of result) {
242
+ for (const ignorePattern of ignoreChanges) {
243
+ const p = new RegExp(ignorePattern);
244
+
245
+ let matchPath = item.path;
246
+ if (isArray(item.path)) {
247
+ matchPath = item.path.join(".");
248
+ }
249
+
250
+ if (p.test(matchPath)) {
251
+ itemsToRemove.push(item);
252
+ break;
253
+ }
254
+ }
255
+ }
256
+
257
+ for (const itemToRemove of itemsToRemove) {
258
+ const index = result.indexOf(itemToRemove);
259
+ if (index > -1) {
260
+ result.splice(index, 1);
261
+ }
262
+ }
263
+ }
264
+
265
+ if (isArray(result) && result.length > 0) {
266
+ self[stateButtonElementSymbol].setState("changed");
267
+ self[stateButtonElementSymbol].setOption("disabled", false);
268
+ self.setOption("changes", result.length);
269
+ self.setOption(
270
+ "classes.badge",
271
+ new TokenList(self.getOption("classes.badge"))
272
+ .remove("hidden")
273
+ .toString(),
274
+ );
275
+ } else {
276
+ self[stateButtonElementSymbol].removeState();
277
+ self[stateButtonElementSymbol].setOption("disabled", true);
278
+ self.setOption("changes", 0);
279
+ self.setOption(
280
+ "classes.badge",
281
+ new TokenList(self.getOption("classes.badge"))
282
+ .add("hidden")
283
+ .toString(),
284
+ );
285
+ }
286
+ }),
287
+ );
288
+ }
289
+
290
+ this.attachObserver(
291
+ new Observer(() => {
292
+ handleDataSourceChanges.call(this);
293
+ }),
294
+ );
295
+ }
296
+
297
+ /**
298
+ *
299
+ * @return [CSSStyleSheet]
300
+ */
301
+ static getCSSStyleSheet() {
302
+ return [SaveButtonStyleSheet, BadgeStyleSheet];
303
+ }
300
304
  }
301
305
 
302
306
  function getTranslations() {
303
- const locale = getLocaleOfDocument();
304
- switch (locale.language) {
305
- case "de":
306
- return {
307
- button: "Speichern",
308
- };
309
- case "fr":
310
- return {
311
- button: "Enregistrer",
312
- };
313
- case "sp":
314
- return {
315
- button: "Guardar",
316
- };
317
- case "it":
318
- return {
319
- button: "Salva",
320
- };
321
- case "pl":
322
- return {
323
- button: "Zapisz",
324
- };
325
- case "no":
326
- return {
327
- button: "Lagre",
328
- };
329
- case "dk":
330
- return {
331
- button: "Gem",
332
- };
333
- case "sw":
334
- return {
335
- button: "Spara",
336
- };
337
- default:
338
- case "en":
339
- return {
340
- button: "Save",
341
- };
342
- }
307
+ const locale = getLocaleOfDocument();
308
+ switch (locale.language) {
309
+ case "de":
310
+ return {
311
+ button: "Speichern",
312
+ };
313
+ case "fr":
314
+ return {
315
+ button: "Enregistrer",
316
+ };
317
+ case "sp":
318
+ return {
319
+ button: "Guardar",
320
+ };
321
+ case "it":
322
+ return {
323
+ button: "Salva",
324
+ };
325
+ case "pl":
326
+ return {
327
+ button: "Zapisz",
328
+ };
329
+ case "no":
330
+ return {
331
+ button: "Lagre",
332
+ };
333
+ case "dk":
334
+ return {
335
+ button: "Gem",
336
+ };
337
+ case "sw":
338
+ return {
339
+ button: "Spara",
340
+ };
341
+ default:
342
+ case "en":
343
+ return {
344
+ button: "Save",
345
+ };
346
+ }
343
347
  }
344
348
 
345
349
  /**
@@ -353,71 +357,81 @@ function getTranslations() {
353
357
  * @throws {Error} the selector must match exactly one element
354
358
  */
355
359
  function initControlReferences() {
356
- if (!this.shadowRoot) {
357
- throw new Error("no shadow-root is defined");
358
- }
359
-
360
- this[stateButtonElementSymbol] = this.shadowRoot.querySelector(
361
- "[data-monster-role=state-button]",
362
- );
363
-
364
- this[badgeElementSymbol] = this.shadowRoot.querySelector(
365
- "[data-monster-role=badge]",
366
- );
367
-
368
- if (this[stateButtonElementSymbol]) {
369
- queueMicrotask(() => {
370
- const states = {
371
- changed: new State(
372
- "changed",
373
- '<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-cloud-arrow-up" viewBox="0 0 16 16">' +
374
- '<path fill-rule="evenodd" d="M7.646 5.146a.5.5 0 0 1 .708 0l2 2a.5.5 0 0 1-.708.708L8.5 6.707V10.5a.5.5 0 0 1-1 0V6.707L6.354 7.854a.5.5 0 1 1-.708-.708z"/>' +
375
- '<path d="M4.406 3.342A5.53 5.53 0 0 1 8 2c2.69 0 4.923 2 5.166 4.579C14.758 6.804 16 8.137 16 9.773 16 11.569 14.502 13 12.687 13H3.781C1.708 13 0 11.366 0 9.318c0-1.763 1.266-3.223 2.942-3.593.143-.863.698-1.723 1.464-2.383m.653.757c-.757.653-1.153 1.44-1.153 2.056v.448l-.445.049C2.064 6.805 1 7.952 1 9.318 1 10.785 2.23 12 3.781 12h8.906C13.98 12 15 10.988 15 9.773c0-1.216-1.02-2.228-2.313-2.228h-.5v-.5C12.188 4.825 10.328 3 8 3a4.53 4.53 0 0 0-2.941 1.1z"/>' +
376
- "</svg>",
377
- ),
378
- };
379
-
380
- this[stateButtonElementSymbol].removeState();
381
- this[stateButtonElementSymbol].setOption("disabled", "disabled");
382
- this[stateButtonElementSymbol].setOption("states", states);
383
- this[stateButtonElementSymbol].setOption(
384
- "labels.button",
385
- this.getOption("labels.button"),
386
- );
387
- });
388
- }
389
-
390
- return this;
360
+ if (!this.shadowRoot) {
361
+ throw new Error("no shadow-root is defined");
362
+ }
363
+
364
+ this[stateButtonElementSymbol] = this.shadowRoot.querySelector(
365
+ "[data-monster-role=state-button]",
366
+ );
367
+
368
+ this[badgeElementSymbol] = this.shadowRoot.querySelector(
369
+ "[data-monster-role=badge]",
370
+ );
371
+
372
+ if (this[stateButtonElementSymbol]) {
373
+ queueMicrotask(() => {
374
+ const states = {
375
+ changed: new State(
376
+ "changed",
377
+ '<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-cloud-arrow-up" viewBox="0 0 16 16">' +
378
+ '<path fill-rule="evenodd" d="M7.646 5.146a.5.5 0 0 1 .708 0l2 2a.5.5 0 0 1-.708.708L8.5 6.707V10.5a.5.5 0 0 1-1 0V6.707L6.354 7.854a.5.5 0 1 1-.708-.708z"/>' +
379
+ '<path d="M4.406 3.342A5.53 5.53 0 0 1 8 2c2.69 0 4.923 2 5.166 4.579C14.758 6.804 16 8.137 16 9.773 16 11.569 14.502 13 12.687 13H3.781C1.708 13 0 11.366 0 9.318c0-1.763 1.266-3.223 2.942-3.593.143-.863.698-1.723 1.464-2.383m.653.757c-.757.653-1.153 1.44-1.153 2.056v.448l-.445.049C2.064 6.805 1 7.952 1 9.318 1 10.785 2.23 12 3.781 12h8.906C13.98 12 15 10.988 15 9.773c0-1.216-1.02-2.228-2.313-2.228h-.5v-.5C12.188 4.825 10.328 3 8 3a4.53 4.53 0 0 0-2.941 1.1z"/>' +
380
+ "</svg>",
381
+ ),
382
+ };
383
+
384
+ this[stateButtonElementSymbol].removeState();
385
+ this[stateButtonElementSymbol].setOption("disabled", "disabled");
386
+ this[stateButtonElementSymbol].setOption("states", states);
387
+ this[stateButtonElementSymbol].setOption(
388
+ "labels.button",
389
+ this.getOption("labels.button"),
390
+ );
391
+ });
392
+ }
393
+
394
+ return this;
391
395
  }
392
396
 
393
397
  /**
394
398
  * @private
395
399
  */
396
400
  function initEventHandler() {
397
- queueMicrotask(() => {
398
- this[stateButtonElementSymbol].setOption("actions.click", () => {
399
- this[datasourceLinkedElementSymbol]
400
- .write()
401
- .then(() => {
402
- this[originValuesSymbol] = null;
403
- this[originValuesSymbol] = clone(
404
- this[datasourceLinkedElementSymbol].data,
405
- );
406
- this[stateButtonElementSymbol].removeState();
407
- this[stateButtonElementSymbol].setOption("disabled", true);
408
- this.setOption("changes", 0);
409
- this.setOption(
410
- "classes.badge",
411
- new TokenList(this.getOption("classes.badge"))
412
- .add("hidden")
413
- .toString(),
414
- );
415
- })
416
- .catch((error) => {
417
- addAttributeToken(this, ATTRIBUTE_ERRORMESSAGE, error.toString());
418
- });
419
- });
420
- });
401
+ queueMicrotask(() => {
402
+ this[stateButtonElementSymbol].setOption("actions.click", () => {
403
+ if (this[saveInFlightSymbol]) {
404
+ return;
405
+ }
406
+ this[saveInFlightSymbol] = true;
407
+ this[stateButtonElementSymbol].setOption("disabled", true);
408
+
409
+ this[datasourceLinkedElementSymbol]
410
+ .write()
411
+ .then(() => {
412
+ this[originValuesSymbol] = null;
413
+ this[originValuesSymbol] = clone(
414
+ this[datasourceLinkedElementSymbol].data,
415
+ );
416
+ this[stateButtonElementSymbol].removeState();
417
+ this[stateButtonElementSymbol].setOption("disabled", true);
418
+ this.setOption("changes", 0);
419
+ this.setOption(
420
+ "classes.badge",
421
+ new TokenList(this.getOption("classes.badge"))
422
+ .add("hidden")
423
+ .toString(),
424
+ );
425
+ })
426
+ .catch((error) => {
427
+ addAttributeToken(this, ATTRIBUTE_ERRORMESSAGE, error.toString());
428
+ this[stateButtonElementSymbol].setOption("disabled", false);
429
+ })
430
+ .finally(() => {
431
+ this[saveInFlightSymbol] = false;
432
+ });
433
+ });
434
+ });
421
435
  }
422
436
 
423
437
  /**
@@ -425,10 +439,10 @@ function initEventHandler() {
425
439
  * @deprecated 2024-12-31
426
440
  */
427
441
  function updateOptionsFromArguments(options) {
428
- const selector = this.getAttribute(ATTRIBUTE_DATASOURCE_SELECTOR);
429
- if (selector) {
430
- options.datasource.selector = selector;
431
- }
442
+ const selector = this.getAttribute(ATTRIBUTE_DATASOURCE_SELECTOR);
443
+ if (selector) {
444
+ options.datasource.selector = selector;
445
+ }
432
446
  }
433
447
 
434
448
  /**
@@ -436,8 +450,8 @@ function updateOptionsFromArguments(options) {
436
450
  * @return {string}
437
451
  */
438
452
  function getTemplate() {
439
- // language=HTML
440
- return `
453
+ // language=HTML
454
+ return `
441
455
  <div data-monster-role="control" part="control"
442
456
  data-monster-attributes="disabled path:disabled | if:true">
443
457
  <monster-state-button data-monster-role="state-button"></monster-state-button>