@schukai/monster 3.55.6 → 3.56.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/package.json +2 -2
  3. package/source/components/datatable/change-button.mjs +265 -0
  4. package/source/components/datatable/dataset.mjs +76 -5
  5. package/source/components/datatable/datasource/dom.mjs +1 -1
  6. package/source/components/datatable/datasource/rest.mjs +401 -345
  7. package/source/components/datatable/datasource.mjs +8 -0
  8. package/source/components/datatable/datatable.mjs +600 -600
  9. package/source/components/datatable/filter/range.mjs +1 -3
  10. package/source/components/datatable/filter/select.mjs +1 -1
  11. package/source/components/datatable/filter.mjs +1 -3
  12. package/source/components/datatable/save-button.mjs +301 -0
  13. package/source/components/datatable/status.mjs +6 -2
  14. package/source/components/datatable/style/change-button.pcss +19 -0
  15. package/source/components/datatable/style/save-button.pcss +44 -0
  16. package/source/components/datatable/stylesheet/change-button.mjs +27 -0
  17. package/source/components/datatable/stylesheet/save-button.mjs +27 -0
  18. package/source/components/datatable/util.mjs +3 -1
  19. package/source/components/form/button-bar.mjs +3 -3
  20. package/source/components/form/button.mjs +1 -2
  21. package/source/components/form/form.mjs +1 -1
  22. package/source/components/form/message-state-button.mjs +1 -1
  23. package/source/components/form/select.mjs +1744 -1777
  24. package/source/components/form/state-button.mjs +1 -1
  25. package/source/components/form/tabs.mjs +3 -3
  26. package/source/components/form/tree-select.mjs +6 -2
  27. package/source/components/host/overlay.mjs +4 -1
  28. package/source/components/tree-menu/tree-menu.mjs +0 -1
  29. package/source/data/datasource/server/restapi.mjs +2 -3
  30. package/source/data/datasource/server.mjs +1 -1
  31. package/source/data/extend.mjs +55 -55
  32. package/source/data/pathfinder.mjs +6 -4
  33. package/source/dom/constants.mjs +9 -0
  34. package/source/dom/customelement.mjs +25 -7
  35. package/source/dom/updater.mjs +34 -3
  36. package/source/i18n/translations.mjs +1 -1
  37. package/source/monster.mjs +0 -1
  38. package/source/types/noderecursiveiterator.mjs +2 -3
  39. package/source/types/version.mjs +1 -1
  40. package/test/cases/monster.mjs +1 -1
@@ -101,7 +101,7 @@ class StateButton extends Button {
101
101
  *
102
102
  * @since 3.18.0 a previously set timeout is cleared
103
103
  *
104
- * @param {state} state
104
+ * @param {string} state
105
105
  * @param {number} timeout
106
106
  * @return {Monster.Components.Form.StateButton}
107
107
  * @throws {TypeError} value is not a string
@@ -330,7 +330,7 @@ function initPopperSwitch() {
330
330
  switchButton.setAttribute(ATTRIBUTE_ROLE, "switch");
331
331
  switchButton.setAttribute("part", "switch");
332
332
  switchButton.classList.add("hidden");
333
- let classList = this.getOption("classes.button");
333
+ const classList = this.getOption("classes.button");
334
334
  if (classList) {
335
335
  switchButton.classList.add(classList);
336
336
  }
@@ -510,7 +510,7 @@ function initPopper() {
510
510
  * @private
511
511
  * @param {HTMLElement} element
512
512
  */
513
- function show(element) {;
513
+ function show(element) {
514
514
  if (!this.shadowRoot) {
515
515
  throw new Error("no shadow-root is defined");
516
516
  }
@@ -593,7 +593,7 @@ function show(element) {;
593
593
  /**
594
594
  * @private
595
595
  */
596
- function initEventHandler() {;
596
+ function initEventHandler() {
597
597
 
598
598
  if (!this.shadowRoot) {
599
599
  throw new Error("no shadow-root is defined");
@@ -16,7 +16,11 @@ import {
16
16
  assembleMethodSymbol,
17
17
  registerCustomElement,
18
18
  } from "../../dom/customelement.mjs";
19
- import {findTargetElementFromEvent, fireCustomEvent, fireEvent} from "../../dom/events.mjs";
19
+ import {
20
+ findTargetElementFromEvent,
21
+ fireCustomEvent,
22
+ fireEvent,
23
+ } from "../../dom/events.mjs";
20
24
  import { Formatter } from "../../text/formatter.mjs";
21
25
  import { isString } from "../../types/is.mjs";
22
26
  import { Node } from "../../types/node.mjs";
@@ -204,7 +208,7 @@ class TreeSelect extends Select {
204
208
  fireCustomEvent(this, "monster-options-set", {
205
209
  options,
206
210
  });
207
-
211
+
208
212
  return this;
209
213
  }
210
214
 
@@ -127,6 +127,7 @@ class Overlay extends CustomElement {
127
127
  * @property {string} classes.overlay Css class to hide the overlay. This class is removed when the component is ready.
128
128
  * @property {Object} features Feature definitions
129
129
  * @property {boolean} features.escapeKey If true the overlay can be closed with the escape key
130
+ * @property {boolean} features.openButton If true the overlay can be opened with a button
130
131
  */
131
132
  get defaults() {
132
133
  return Object.assign({}, super.defaults, {
@@ -146,6 +147,7 @@ class Overlay extends CustomElement {
146
147
  },
147
148
  features: {
148
149
  escapeKey: true,
150
+ openButton: true,
149
151
  },
150
152
  });
151
153
  }
@@ -326,7 +328,8 @@ function getTemplate() {
326
328
  data-monster-attributes="part path:host-overlay.name, data-monster-role path:host-container.overlay"></div>
327
329
  </template>
328
330
 
329
- <div data-monster-role="overlay-open" part="open"></div>
331
+ <div data-monster-role="overlay-open" part="open"
332
+ data-monster-attributes="class path:features.openButton | if:visible:hidden"></div>
330
333
 
331
334
  <div id="overlay" data-monster-role="overlay" part="overlay" data-monster-insert="host-overlay path:overlay"
332
335
  data-monster-attributes="class path:classes.overlay">
@@ -515,7 +515,6 @@ function switchToConfig() {
515
515
  };
516
516
 
517
517
  this[dragEventHandlerSymbol] = (event) => {
518
- console.log(event);
519
518
  event.preventDefault();
520
519
  };
521
520
 
@@ -88,7 +88,7 @@ class RestAPI extends Server {
88
88
  },
89
89
  responseCallback: undefined,
90
90
  acceptedStatus: [200, 201],
91
- url: undefined,
91
+ url: null,
92
92
  mapping: {
93
93
  transformer: undefined,
94
94
  callbacks: [],
@@ -107,7 +107,7 @@ class RestAPI extends Server {
107
107
  },
108
108
  responseCallback: undefined,
109
109
  acceptedStatus: [200],
110
- url: undefined,
110
+ url: null,
111
111
  mapping: {
112
112
  transformer: undefined,
113
113
  callbacks: [],
@@ -123,7 +123,6 @@ class RestAPI extends Server {
123
123
  * @throws {Error} the data cannot be read
124
124
  */
125
125
  read() {
126
-
127
126
  let init = this.getOption("read.init");
128
127
  if (!isObject(init)) init = {};
129
128
  if (!init["method"]) init["method"] = "GET";
@@ -81,7 +81,7 @@ class Server extends Datasource {
81
81
  */
82
82
  function doTransform(type, obj) {
83
83
  const transformation = this.getOption(`${type}.mapping.transformer`);
84
- if (transformation !== undefined) {
84
+ if (transformation !== undefined && transformation !== null) {
85
85
  const pipe = new Pipe(transformation);
86
86
  const callbacks = this.getOption(`${type}.mapping.callbacks`);
87
87
 
@@ -5,10 +5,10 @@
5
5
  * License text available at https://www.gnu.org/licenses/agpl-3.0.en.html
6
6
  */
7
7
 
8
- import {isArray, isObject} from "../types/is.mjs";
9
- import {typeOf} from "../types/typeof.mjs";
8
+ import { isArray, isObject } from "../types/is.mjs";
9
+ import { typeOf } from "../types/typeof.mjs";
10
10
 
11
- export {extend};
11
+ export { extend };
12
12
 
13
13
  /**
14
14
  * Extend copies all enumerable own properties from one or
@@ -25,65 +25,65 @@ export {extend};
25
25
  * @param args
26
26
  */
27
27
  function extend(...args) {
28
- let o;
29
- let i;
28
+ let o;
29
+ let i;
30
30
 
31
- if (typeof args !== "object" || args[0] === null) {
32
- throw new Error(`unsupported argument ${JSON.stringify(args[0])}`);
33
- }
31
+ if (typeof args !== "object" || args[0] === null) {
32
+ throw new Error(`unsupported argument ${JSON.stringify(args[0])}`);
33
+ }
34
34
 
35
- for (i = 0; i < args.length; i++) {
36
- const a = args[i];
35
+ for (i = 0; i < args.length; i++) {
36
+ const a = args[i];
37
37
 
38
- if (!(isObject(a) || isArray(a))) {
39
- throw new Error(`unsupported argument ${JSON.stringify(a)}`);
40
- }
38
+ if (!(isObject(a) || isArray(a))) {
39
+ throw new Error(`unsupported argument ${JSON.stringify(a)}`);
40
+ }
41
41
 
42
- if (o === undefined) {
43
- o = a;
44
- continue;
45
- }
42
+ if (o === undefined) {
43
+ o = a;
44
+ continue;
45
+ }
46
46
 
47
- for (const k in a) {
48
- const v = a?.[k];
47
+ for (const k in a) {
48
+ const v = a?.[k];
49
49
 
50
- if (v === o?.[k]) {
51
- continue;
52
- }
50
+ if (v === o?.[k]) {
51
+ continue;
52
+ }
53
53
 
54
- if ((isObject(v) && typeOf(v) === "object") || isArray(v)) {
55
- if (o[k] === undefined) {
56
- if (isArray(v)) {
57
- o[k] = [];
58
- } else {
59
- o[k] = {};
60
- }
61
- } else {
62
- if (typeOf(o[k]) !== typeOf(v)) {
63
- throw new Error(
64
- `type mismatch: ${JSON.stringify(o[k])}(${typeOf(
65
- o[k],
66
- )}) != ${JSON.stringify(v)}(${typeOf(v)})`,
67
- );
68
- }
69
- }
70
-
71
- if (isArray(o[k])) {
72
- o[k] = [];
73
- o[k].push(...v);
74
- continue;
75
- }
54
+ if ((isObject(v) && typeOf(v) === "object") || isArray(v)) {
55
+ if (o[k] === undefined) {
56
+ if (isArray(v)) {
57
+ o[k] = [];
58
+ } else {
59
+ o[k] = {};
60
+ }
61
+ } else {
62
+ if (typeOf(o[k]) !== typeOf(v)) {
63
+ throw new Error(
64
+ `type mismatch: ${JSON.stringify(o[k])}(${typeOf(
65
+ o[k],
66
+ )}) != ${JSON.stringify(v)}(${typeOf(v)})`,
67
+ );
68
+ }
69
+ }
76
70
 
77
- o[k] = extend(o[k], v);
78
- } else {
79
- if (isArray(o)) {
80
- o.push(v);
81
- continue;
82
- }
83
- o[k] = v;
84
- }
85
- }
86
- }
71
+ if (isArray(o[k])) {
72
+ o[k] = [];
73
+ o[k].push(...v);
74
+ continue;
75
+ }
87
76
 
88
- return o;
77
+ o[k] = extend(o[k], v);
78
+ } else {
79
+ if (isArray(o)) {
80
+ o.push(v);
81
+ continue;
82
+ }
83
+ o[k] = v;
84
+ }
85
+ }
86
+ }
87
+
88
+ return o;
89
89
  }
@@ -83,10 +83,12 @@ const WILDCARD = "*";
83
83
  */
84
84
  class Pathfinder extends Base {
85
85
  /**
86
- * @param {array|object|Map|Set} value
87
- * @since 1.4.0
88
- * @throws {Error} the parameter must not be a simple type
89
- **/
86
+ * Creates a new instance of the constructor.
87
+ *
88
+ * @param {object} object - The object parameter for the constructor.
89
+ *
90
+ * @throws {Error} Throws an error if the provided object parameter is a simple type.
91
+ */
90
92
  constructor(object) {
91
93
  super();
92
94
 
@@ -19,6 +19,7 @@ export {
19
19
  ATTRIBUTE_UPDATER_INSERT_REFERENCE,
20
20
  ATTRIBUTE_UPDATER_REMOVE,
21
21
  ATTRIBUTE_UPDATER_BIND,
22
+ ATTRIBUTE_UPDATER_BIND_TYPE,
22
23
  ATTRIBUTE_TEMPLATE_PREFIX,
23
24
  ATTRIBUTE_ROLE,
24
25
  ATTRIBUTE_DISABLED,
@@ -199,6 +200,14 @@ const ATTRIBUTE_UPDATER_REMOVE = `${ATTRIBUTE_PREFIX}remove`;
199
200
  */
200
201
  const ATTRIBUTE_UPDATER_BIND = `${ATTRIBUTE_PREFIX}bind`;
201
202
 
203
+ /**
204
+ * @memberOf Monster.DOM
205
+ * @type {string}
206
+ * @license AGPLv3
207
+ * @since 1.9.0
208
+ */
209
+ const ATTRIBUTE_UPDATER_BIND_TYPE = `${ATTRIBUTE_UPDATER_BIND}-type`;
210
+
202
211
  /**
203
212
  * @memberOf Monster.DOM
204
213
  * @type {string}
@@ -95,6 +95,12 @@ const attributeMutationObserverSymbol = Symbol(
95
95
  "@schukai/monster/dom/@@mutationObserver",
96
96
  );
97
97
 
98
+ /**
99
+ * @private
100
+ * @type {symbol}
101
+ */
102
+ const updateCloneDataSymbol = Symbol("@schukai/monster/dom/@@updateCloneData");
103
+
98
104
  /**
99
105
  * @private
100
106
  * @type {symbol}
@@ -465,7 +471,7 @@ class CustomElement extends HTMLElement {
465
471
  * @return {*}
466
472
  * @since 1.10.0
467
473
  */
468
- getOption(path, defaultValue=undefined) {
474
+ getOption(path, defaultValue = undefined) {
469
475
  let value;
470
476
 
471
477
  try {
@@ -503,13 +509,10 @@ class CustomElement extends HTMLElement {
503
509
  if (isString(options)) {
504
510
  options = parseOptionsJSON.call(this, options);
505
511
  }
506
- // 2024-01-21: remove this.defaults, otherwise it will overwrite
512
+ // 2024-01-21: remove this.defaults, otherwise it will overwrite
507
513
  // the current settings that have already been made.
508
514
  // https://gitlab.schukai.com/oss/libraries/javascript/monster/-/issues/136
509
- extend(
510
- this[internalSymbol].getSubject()["options"],
511
- options,
512
- );
515
+ extend(this[internalSymbol].getSubject()["options"], options);
513
516
 
514
517
  return this;
515
518
  }
@@ -583,11 +586,16 @@ class CustomElement extends HTMLElement {
583
586
  } catch (e) {
584
587
  nodeList = elements;
585
588
  }
589
+
590
+ this[updateCloneDataSymbol] = clone(
591
+ this[internalSymbol].getRealSubject()["options"],
592
+ );
593
+
586
594
  addObjectWithUpdaterToElement.call(
587
595
  this,
588
596
  nodeList,
589
597
  customElementUpdaterLinkSymbol,
590
- clone(this[internalSymbol].getRealSubject()["options"]),
598
+ this[updateCloneDataSymbol],
591
599
  );
592
600
 
593
601
  // Attach a mutation observer to observe changes to the attributes of the element
@@ -596,6 +604,16 @@ class CustomElement extends HTMLElement {
596
604
  return this;
597
605
  }
598
606
 
607
+ /**
608
+ * You know what you are doing? This function is only for advanced users.
609
+ * The result is a clone of the internal data.
610
+ *
611
+ * @returns {*}
612
+ */
613
+ getInternalUpdateCloneData() {
614
+ return clone(this[updateCloneDataSymbol]);
615
+ }
616
+
599
617
  /**
600
618
  * This method is called every time the element is inserted into the DOM. It checks if the custom element
601
619
  * has already been initialized and if not, calls the assembleMethod to initialize it.
@@ -13,6 +13,7 @@ import {
13
13
  ATTRIBUTE_ERRORMESSAGE,
14
14
  ATTRIBUTE_UPDATER_ATTRIBUTES,
15
15
  ATTRIBUTE_UPDATER_BIND,
16
+ ATTRIBUTE_UPDATER_BIND_TYPE,
16
17
  ATTRIBUTE_UPDATER_INSERT,
17
18
  ATTRIBUTE_UPDATER_INSERT_REFERENCE,
18
19
  ATTRIBUTE_UPDATER_REMOVE,
@@ -21,7 +22,7 @@ import {
21
22
  } from "./constants.mjs";
22
23
 
23
24
  import { Base } from "../types/base.mjs";
24
- import { isArray, isInstance, isIterable } from "../types/is.mjs";
25
+ import { isArray, isString, isInstance, isIterable } from "../types/is.mjs";
25
26
  import { Observer } from "../types/observer.mjs";
26
27
  import { ProxyObserver } from "../types/proxyobserver.mjs";
27
28
  import { validateArray, validateInstance } from "../types/validate.mjs";
@@ -311,7 +312,7 @@ function retrieveAndSetValue(element) {
311
312
  throw new Error("the bind argument must start as a value with a path");
312
313
  }
313
314
 
314
- path = path.substring(5);
315
+ path = path.substring(5); // remove path: from the string
315
316
 
316
317
  let value;
317
318
 
@@ -342,7 +343,7 @@ function retrieveAndSetValue(element) {
342
343
  break;
343
344
  }
344
345
 
345
- // values from customelements
346
+ // values from custom elements
346
347
  } else if (
347
348
  (element?.constructor?.prototype &&
348
349
  !!Object.getOwnPropertyDescriptor(
@@ -356,6 +357,36 @@ function retrieveAndSetValue(element) {
356
357
  throw new Error("unsupported object");
357
358
  }
358
359
 
360
+ if (isString(value)) {
361
+ const type = element.getAttribute(ATTRIBUTE_UPDATER_BIND_TYPE);
362
+ switch (type) {
363
+ case "number":
364
+ case "int":
365
+ case "float":
366
+ case "integer":
367
+ value = Number(value);
368
+ if (isNaN(value)) {
369
+ value = 0;
370
+ }
371
+ break;
372
+ case "boolean":
373
+ case "bool":
374
+ case "checkbox":
375
+ value = value === "true" || value === "1" || value === "on";
376
+ break;
377
+ case "array":
378
+ case "list":
379
+ value = value.split(",");
380
+ break;
381
+ case "object":
382
+ case "json":
383
+ value = JSON.parse(value);
384
+ break;
385
+ default:
386
+ break;
387
+ }
388
+ }
389
+
359
390
  const copy = clone(this[internalSymbol].subject.getRealSubject());
360
391
  const pf = new Pathfinder(copy);
361
392
  pf.setVia(path, value);
@@ -90,7 +90,7 @@ class Translations extends Base {
90
90
  * The appropriate text for this number is then selected. If no suitable key is found, `defaultText` is taken.
91
91
  *
92
92
  * @param {string} key
93
- * @param {integer|count} count
93
+ * @param {integer|string} count
94
94
  * @param {string|undefined} defaultText
95
95
  * @return {string}
96
96
  */
@@ -1,4 +1,3 @@
1
-
2
1
  /**
3
2
  * Copyright schukai GmbH and contributors 2023. All Rights Reserved.
4
3
  * Node module: @schukai/monster
@@ -44,10 +44,10 @@ class NodeRecursiveIterator extends Base {
44
44
  // iterator is a NodeList
45
45
  if (isInstance(node, NodeList)) {
46
46
  const children = node;
47
- let n = new Node();
47
+ const n = new Node();
48
48
  n.childNodes = children;
49
49
  this[isNodeListSymbol] = true;
50
- this[internalSymbol] = n;
50
+ this[internalSymbol] = n;
51
51
  return;
52
52
  }
53
53
 
@@ -80,7 +80,6 @@ class NodeRecursiveIterator extends Base {
80
80
  yield* new NodeRecursiveIterator(node);
81
81
  }
82
82
  }
83
-
84
83
  };
85
84
 
86
85
  /**
@@ -152,7 +152,7 @@ function getMonsterVersion() {
152
152
  }
153
153
 
154
154
  /** don't touch, replaced by make with package.json version */
155
- monsterVersion = new Version("3.55.6");
155
+ monsterVersion = new Version("3.56.0");
156
156
 
157
157
  return monsterVersion;
158
158
  }
@@ -7,7 +7,7 @@ describe('Monster', function () {
7
7
  let monsterVersion
8
8
 
9
9
  /** don´t touch, replaced by make with package.json version */
10
- monsterVersion = new Version("3.55.6")
10
+ monsterVersion = new Version("3.56.0")
11
11
 
12
12
  let m = getMonsterVersion();
13
13