@schukai/monster 4.89.0 → 4.90.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/CHANGELOG.md CHANGED
@@ -2,6 +2,14 @@
2
2
 
3
3
 
4
4
 
5
+ ## [4.90.0] - 2026-01-11
6
+
7
+ ### Add Features
8
+
9
+ - Enhance origin values management in SaveButton component
10
+
11
+
12
+
5
13
  ## [4.89.0] - 2026-01-11
6
14
 
7
15
  ### Add Features
package/package.json CHANGED
@@ -1 +1 @@
1
- {"author":"Volker Schukai","dependencies":{"@floating-ui/dom":"^1.7.4","@popperjs/core":"^2.11.8"},"description":"Monster is a simple library for creating fast, robust and lightweight websites.","homepage":"https://monsterjs.org/","keywords":["framework","web","dom","css","sass","mobile-first","app","front-end","templates","schukai","core","shopcloud","alvine","monster","buildmap","stack","observer","observable","uuid","node","nodelist","css-in-js","logger","log","theme"],"license":"AGPL 3.0","main":"source/monster.mjs","module":"source/monster.mjs","name":"@schukai/monster","repository":{"type":"git","url":"https://gitlab.schukai.com/oss/libraries/javascript/monster.git"},"type":"module","version":"4.89.0"}
1
+ {"author":"Volker Schukai","dependencies":{"@floating-ui/dom":"^1.7.4","@popperjs/core":"^2.11.8"},"description":"Monster is a simple library for creating fast, robust and lightweight websites.","homepage":"https://monsterjs.org/","keywords":["framework","web","dom","css","sass","mobile-first","app","front-end","templates","schukai","core","shopcloud","alvine","monster","buildmap","stack","observer","observable","uuid","node","nodelist","css-in-js","logger","log","theme"],"license":"AGPL 3.0","main":"source/monster.mjs","module":"source/monster.mjs","name":"@schukai/monster","repository":{"type":"git","url":"https://gitlab.schukai.com/oss/libraries/javascript/monster.git"},"type":"module","version":"4.90.0"}
@@ -62,7 +62,9 @@ const stateButtonElementSymbol = Symbol("stateButtonElement");
62
62
  * @private
63
63
  * @type {symbol}
64
64
  */
65
- const originValuesSymbol = Symbol("originValues");
65
+ const originValuesSymbol = Symbol.for(
66
+ "@schukai/monster/components/datatable/save-button@@originValues",
67
+ );
66
68
 
67
69
  /**
68
70
  * @private
@@ -192,19 +194,20 @@ class SaveButton extends CustomElement {
192
194
  }
193
195
 
194
196
  if (element instanceof RestDatasource) {
195
- element.addEventListener("monster-datasource-fetch", (event) => {
197
+ element.addEventListener("monster-datasource-fetch", () => {
196
198
  if (self[saveInFlightSymbol]) {
197
199
  self[pendingResetSymbol] = true;
198
200
  return;
199
201
  }
200
202
  self[fetchInFlightSymbol] = true;
201
- self[originValuesSymbol] = null;
203
+ clearOriginValues.call(self);
202
204
  });
203
205
  element.addEventListener("monster-datasource-fetched", () => {
204
206
  self[fetchInFlightSymbol] = false;
205
- if (!self[originValuesSymbol]) {
206
- self[originValuesSymbol] = clone(
207
- self[datasourceLinkedElementSymbol].data,
207
+ if (!getOriginValues.call(self)) {
208
+ setOriginValues.call(
209
+ self,
210
+ clone(self[datasourceLinkedElementSymbol].data),
208
211
  );
209
212
  updateChangesState.call(self);
210
213
  }
@@ -219,22 +222,25 @@ class SaveButton extends CustomElement {
219
222
  new Observer(handleDataSourceChanges.bind(this)),
220
223
  );
221
224
 
222
- self[originValuesSymbol] = null;
225
+ clearOriginValues.call(self);
223
226
 
224
227
  element.datasource.attachObserver(
225
228
  new Observer(function () {
226
229
  if (self[fetchInFlightSymbol] === true) {
227
230
  return;
228
231
  }
229
- if (!self[originValuesSymbol]) {
230
- self[originValuesSymbol] = clone(
231
- self[datasourceLinkedElementSymbol].data,
232
+ if (!getOriginValues.call(self)) {
233
+ setOriginValues.call(
234
+ self,
235
+ clone(self[datasourceLinkedElementSymbol].data),
232
236
  );
233
237
  }
234
238
 
235
239
  updateChangesState.call(self);
236
240
  }),
237
241
  );
242
+
243
+ syncOriginValues.call(self);
238
244
  }
239
245
 
240
246
  this.attachObserver(
@@ -253,6 +259,53 @@ class SaveButton extends CustomElement {
253
259
  }
254
260
  }
255
261
 
262
+ /**
263
+ * @private
264
+ */
265
+ function syncOriginValues() {
266
+ if (getOriginValues.call(this)) {
267
+ return;
268
+ }
269
+ const data = this[datasourceLinkedElementSymbol]?.data;
270
+ if (!data) {
271
+ return;
272
+ }
273
+ setOriginValues.call(this, clone(data));
274
+ updateChangesState.call(this);
275
+ }
276
+
277
+ /**
278
+ * @private
279
+ * @return {*}
280
+ */
281
+ function getOriginValues() {
282
+ const datasource = this[datasourceLinkedElementSymbol];
283
+ return datasource ? datasource[originValuesSymbol] : null;
284
+ }
285
+
286
+ /**
287
+ * @private
288
+ * @param {*} value
289
+ * @return {void}
290
+ */
291
+ function setOriginValues(value) {
292
+ const datasource = this[datasourceLinkedElementSymbol];
293
+ if (datasource) {
294
+ datasource[originValuesSymbol] = value;
295
+ }
296
+ }
297
+
298
+ /**
299
+ * @private
300
+ * @return {void}
301
+ */
302
+ function clearOriginValues() {
303
+ const datasource = this[datasourceLinkedElementSymbol];
304
+ if (datasource) {
305
+ datasource[originValuesSymbol] = null;
306
+ }
307
+ }
308
+
256
309
  function getTranslations() {
257
310
  const locale = getLocaleOfDocument();
258
311
  switch (locale.language) {
@@ -359,9 +412,10 @@ function initEventHandler() {
359
412
  flushLinkedForms.call(this)
360
413
  .then(() => this[datasourceLinkedElementSymbol].write())
361
414
  .then(() => {
362
- this[originValuesSymbol] = null;
363
- this[originValuesSymbol] = clone(
364
- this[datasourceLinkedElementSymbol].data,
415
+ clearOriginValues.call(this);
416
+ setOriginValues.call(
417
+ this,
418
+ clone(this[datasourceLinkedElementSymbol].data),
365
419
  );
366
420
  this[stateButtonElementSymbol].removeState();
367
421
  this[stateButtonElementSymbol].setOption("disabled", true);
@@ -381,7 +435,7 @@ function initEventHandler() {
381
435
  this[saveInFlightSymbol] = false;
382
436
  if (this[pendingResetSymbol]) {
383
437
  this[pendingResetSymbol] = false;
384
- this[originValuesSymbol] = null;
438
+ clearOriginValues.call(this);
385
439
  }
386
440
  });
387
441
  });
@@ -463,7 +517,8 @@ function flushLinkedForms() {
463
517
  function updateChangesState() {
464
518
  const currentValues = this[datasourceLinkedElementSymbol]?.datasource?.get();
465
519
  const ignoreChanges = this.getOption("ignoreChanges");
466
- let result = diff(this[originValuesSymbol], currentValues);
520
+ const originValues = getOriginValues.call(this);
521
+ let result = diff(originValues, currentValues);
467
522
 
468
523
  if (
469
524
  this.getOption("logLevel") === "debug" ||
@@ -472,7 +527,7 @@ function updateChangesState() {
472
527
  console.groupCollapsed("SaveButton");
473
528
  console.log(
474
529
  "originValues",
475
- JSON.parse(JSON.stringify(this[originValuesSymbol])),
530
+ JSON.parse(JSON.stringify(originValues)),
476
531
  );
477
532
  console.log("currentValues", JSON.parse(JSON.stringify(currentValues)));
478
533
  console.log("result of diff", result);