@schukai/monster 3.68.4 → 3.69.0

Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.md CHANGED
@@ -2,36 +2,24 @@
2
2
 
3
3
 
4
4
 
5
+ ## [3.69.0] - 2024-06-23
6
+
7
+ ### Add Features
8
+
9
+ - new field-set control [#186](https://gitlab.schukai.com/oss/libraries/javascript/monster/issues/186)
10
+
5
11
  ## [3.68.4] - 2024-06-23
6
12
 
7
13
  ### Bug Fixes
8
14
 
9
15
  - if the query is empty but astring, getSlottedElements must not report an error [#208](https://gitlab.schukai.com/oss/libraries/javascript/monster/issues/208)
10
16
 
11
-
12
-
13
17
  ## [3.68.3] - 2024-06-23
14
18
 
15
19
  ### Bug Fixes
16
20
 
17
21
  - working on ci pipeline
18
22
 
19
-
20
-
21
- ## [3.68.2] - 2024-06-23
22
-
23
- ### Bug Fixes
24
-
25
- - gitlab pipeline
26
-
27
-
28
-
29
- ## [3.68.1] - 2024-06-23
30
-
31
- ### Bug Fixes
32
-
33
- - wip pipeline
34
-
35
23
  ## [3.68.0] - 2024-06-23
36
24
 
37
25
  ### Add Features
package/package.json CHANGED
@@ -1 +1 @@
1
- {"author":"schukai GmbH","dependencies":{"@floating-ui/dom":"^1.6.5","@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":"3.68.4"}
1
+ {"author":"schukai GmbH","dependencies":{"@floating-ui/dom":"^1.6.5","@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":"3.69.0"}
@@ -234,11 +234,10 @@ class Filter extends CustomElement {
234
234
  formatter: {
235
235
  marker: {
236
236
  open: null,
237
- close: null
238
- }
237
+ close: null,
238
+ },
239
239
  },
240
240
  labels: {
241
-
242
241
  search: "Search",
243
242
  reset: "Reset",
244
243
  save: "Save",
@@ -1013,7 +1012,10 @@ function collectSearchQueries() {
1013
1012
  });
1014
1013
 
1015
1014
  if (self.getOption("formatter.marker.open")) {
1016
- formatter.setMarker(self.getOption("formatter.marker.open"),self.getOption("formatter.marker.close"));
1015
+ formatter.setMarker(
1016
+ self.getOption("formatter.marker.open"),
1017
+ self.getOption("formatter.marker.close"),
1018
+ );
1017
1019
  }
1018
1020
 
1019
1021
  let queryPart = formatter.format(template);
@@ -12,25 +12,24 @@
12
12
  * SPDX-License-Identifier: AGPL-3.0
13
13
  */
14
14
 
15
- import {instanceSymbol} from "../../constants.mjs";
16
- import {addAttributeToken} from "../../dom/attributes.mjs";
15
+ import { instanceSymbol } from "../../constants.mjs";
16
+ import { addAttributeToken } from "../../dom/attributes.mjs";
17
17
  import {
18
- ATTRIBUTE_ERRORMESSAGE,
19
- ATTRIBUTE_ROLE,
18
+ ATTRIBUTE_ERRORMESSAGE,
19
+ ATTRIBUTE_ROLE,
20
20
  } from "../../dom/constants.mjs";
21
- import {CustomControl} from "../../dom/customcontrol.mjs";
21
+ import { CustomControl } from "../../dom/customcontrol.mjs";
22
22
  import {
23
- assembleMethodSymbol,
24
- registerCustomElement,
23
+ assembleMethodSymbol,
24
+ getSlottedElements,
25
+ registerCustomElement,
25
26
  } from "../../dom/customelement.mjs";
26
- import {findTargetElementFromEvent} from "../../dom/events.mjs";
27
- import {isFunction} from "../../types/is.mjs";
28
- import {FieldSetStyleSheet} from "./stylesheet/field-set.mjs";
29
- import {fireCustomEvent} from "../../dom/events.mjs";
27
+ import { isFunction } from "../../types/is.mjs";
28
+ import { FieldSetStyleSheet } from "./stylesheet/field-set.mjs";
30
29
  import "../layout/collapse.mjs";
31
- import {ToggleSwitch} from "./toggle-switch.mjs";
30
+ import "./toggle-switch.mjs";
32
31
 
33
- export {FieldSet};
32
+ export { FieldSet };
34
33
 
35
34
  /**
36
35
  * @private
@@ -44,6 +43,18 @@ const fieldSetElementSymbol = Symbol("fieldSetElement");
44
43
  */
45
44
  const collapseElementSymbol = Symbol("collapseElement");
46
45
 
46
+ /**
47
+ * @private
48
+ * @type {symbol}
49
+ */
50
+ const extendedSwitchSymbol = Symbol("extendedSwitch");
51
+
52
+ /**
53
+ * @private
54
+ * @type {symbol}
55
+ */
56
+ const headerElementSymbol = Symbol("headerElement");
57
+
47
58
  /**
48
59
  * @private
49
60
  * @type {symbol}
@@ -90,174 +101,179 @@ const extendedSwitchElementSymbol = Symbol("extendedSwitchElement");
90
101
  * @summary A simple FieldSet
91
102
  */
92
103
  class FieldSet extends CustomControl {
93
- /**
94
- * This method is called by the `instanceof` operator.
95
- * @returns {symbol}
96
- */
97
- static get [instanceSymbol]() {
98
- return Symbol.for("@schukai/monster/components/form/fieldset@@instance");
99
- }
100
-
101
- /**
102
- *
103
- * @return {Components.Form.FieldSet
104
- */
105
- [assembleMethodSymbol]() {
106
- super[assembleMethodSymbol]();
107
- initControlReferences.call(this);
108
- initEventHandler.call(this);
109
- updateExtendedFields.call(this);
110
- return this;
111
- }
112
-
113
- /**
114
- * To set the options via the html tag the attribute `data-monster-options` must be used.
115
- * @see {@link https://monsterjs.org/en/doc/#configurate-a-monster-control}
116
- *
117
- * The individual configuration values can be found in the table.
118
- *
119
- * @property {Object} templates Template definitions
120
- * @property {string} templates.main Main template
121
- * @property {Object} labels Label definitions
122
- * @property {Object} actions Callbacks
123
- * @property {string} actions.click="throw Error" Callback when clicked
124
- * @property {Object} features Features
125
- * @property {Object} classes CSS classes
126
- * @property {boolean} disabled=false Disabled state
127
- */
128
- get defaults() {
129
- return Object.assign({}, super.defaults, {
130
- templates: {
131
- main: getTemplate(),
132
- },
133
- labels: {},
134
- classes: {},
135
- disabled: false,
136
- features: {},
137
- actions: {
138
- click: () => {
139
- throw new Error("the click action is not defined");
140
- },
141
- },
142
- value: null,
143
- });
144
- }
145
-
146
- /**
147
- *
148
- * @return {string}
149
- */
150
- static getTag() {
151
- return "monster-field-set";
152
- }
153
-
154
- /**
155
- *
156
- * @return {CSSStyleSheet[]}
157
- */
158
- static getCSSStyleSheet() {
159
- return [FieldSetStyleSheet];
160
- }
161
-
162
- /**
163
- * The FieldSet.click() method simulates a click on the internal element.
164
- *
165
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/click}
166
- */
167
- click() {
168
- if (this.getOption("disabled") === true) {
169
- return;
170
- }
171
-
172
- if (
173
- this[fieldSetElementSymbol] &&
174
- isFunction(this[fieldSetElementSymbol].click)
175
- ) {
176
- this[fieldSetElementSymbol].click();
177
- }
178
- }
179
-
180
- /**
181
- * The Button.focus() method sets focus on the internal element.
182
- *
183
- * @param {Object} options
184
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/focus}
185
- */
186
- focus(options) {
187
- if (this.getOption("disabled") === true) {
188
- return;
189
- }
190
-
191
- if (
192
- this[fieldSetElementSymbol] &&
193
- isFunction(this[fieldSetElementSymbol].focus)
194
- ) {
195
- this[fieldSetElementSymbol].focus(options);
196
- }
197
- }
198
-
199
- /**
200
- * The Button.blur() method removes focus from the internal element.
201
- */
202
- blur() {
203
- if (
204
- this[fieldSetElementSymbol] &&
205
- isFunction(this[fieldSetElementSymbol].blur)
206
- ) {
207
- this[fieldSetElementSymbol].blur();
208
- }
209
- }
210
-
211
- /**
212
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/attachInternals}
213
- * @return {boolean}
214
- */
215
- static get formAssociated() {
216
- return true;
217
- }
218
-
219
- /**
220
- * The current value of the form control.
221
- *
222
- * ```js
223
- * e = document.querySelector('monster-field-set');
224
- * console.log(e.value)
225
- * ```
226
- *
227
- * @property {string}
228
- */
229
- get value() {
230
- return this.getOption("value");
231
- }
232
-
233
- /**
234
- * Set value of the form control.
235
- *
236
- * ```
237
- * e = document.querySelector('monster-field-set');
238
- * e.value=1
239
- * ```
240
- *
241
- * @property {string} value
242
- * @throws {Error} unsupported type
243
- */
244
- set value(value) {
245
- this.setOption("value", value);
246
- try {
247
- this?.setFormValue(this.value);
248
- } catch (e) {
249
- addAttributeToken(this, ATTRIBUTE_ERRORMESSAGE, e.message);
250
- }
251
- }
104
+ /**
105
+ * This method is called by the `instanceof` operator.
106
+ * @returns {symbol}
107
+ */
108
+ static get [instanceSymbol]() {
109
+ return Symbol.for("@schukai/monster/components/form/fieldset@@instance");
110
+ }
111
+
112
+ /**
113
+ * @return {Components.Form.FieldSet
114
+ */
115
+ [assembleMethodSymbol]() {
116
+ super[assembleMethodSymbol]();
117
+ initControlReferences.call(this);
118
+ initEventHandler.call(this);
119
+ updateExtendedFields.call(this);
120
+ return this;
121
+ }
122
+
123
+ /**
124
+ * To set the options via the html tag the attribute `data-monster-options` must be used.
125
+ * @see {@link https://monsterjs.org/en/doc/#configurate-a-monster-control}
126
+ *
127
+ * The individual configuration values can be found in the table.
128
+ *
129
+ * @property {Object} templates Template definitions
130
+ * @property {string} templates.main Main template
131
+ * @property {Object} labels Label definitions
132
+ * @property {Object} actions Callbacks
133
+ * @property {string} actions.click="throw Error" Callback when clicked
134
+ * @property {Object} features Features
135
+ * @property {Object} classes CSS classes
136
+ * @property {boolean} disabled=false Disabled state
137
+ */
138
+ get defaults() {
139
+ return Object.assign({}, super.defaults, {
140
+ templates: {
141
+ main: getTemplate(),
142
+ },
143
+ labels: {
144
+ "toggle-switch-on": "✔",
145
+ "toggle-switch-off": "✖",
146
+ "toggle-switch-label": "Expand",
147
+ title: "",
148
+ },
149
+ classes: {},
150
+ disabled: false,
151
+ features: {},
152
+ actions: {
153
+ click: () => {
154
+ throw new Error("the click action is not defined");
155
+ },
156
+ },
157
+ value: null,
158
+ });
159
+ }
160
+
161
+ /**
162
+ *
163
+ * @return {string}
164
+ */
165
+ static getTag() {
166
+ return "monster-field-set";
167
+ }
168
+
169
+ /**
170
+ *
171
+ * @return {CSSStyleSheet[]}
172
+ */
173
+ static getCSSStyleSheet() {
174
+ return [FieldSetStyleSheet];
175
+ }
176
+
177
+ /**
178
+ * The FieldSet.click() method simulates a click on the internal element.
179
+ *
180
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/click}
181
+ */
182
+ click() {
183
+ if (this.getOption("disabled") === true) {
184
+ return;
185
+ }
186
+
187
+ if (
188
+ this[fieldSetElementSymbol] &&
189
+ isFunction(this[fieldSetElementSymbol].click)
190
+ ) {
191
+ this[fieldSetElementSymbol].click();
192
+ }
193
+ }
194
+
195
+ /**
196
+ * The Button.focus() method sets focus on the internal element.
197
+ *
198
+ * @param {Object} options
199
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/focus}
200
+ */
201
+ focus(options) {
202
+ if (this.getOption("disabled") === true) {
203
+ return;
204
+ }
205
+
206
+ if (
207
+ this[fieldSetElementSymbol] &&
208
+ isFunction(this[fieldSetElementSymbol].focus)
209
+ ) {
210
+ this[fieldSetElementSymbol].focus(options);
211
+ }
212
+ }
213
+
214
+ /**
215
+ * The Button.blur() method removes focus from the internal element.
216
+ */
217
+ blur() {
218
+ if (
219
+ this[fieldSetElementSymbol] &&
220
+ isFunction(this[fieldSetElementSymbol].blur)
221
+ ) {
222
+ this[fieldSetElementSymbol].blur();
223
+ }
224
+ }
225
+
226
+ /**
227
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/attachInternals}
228
+ * @return {boolean}
229
+ */
230
+ static get formAssociated() {
231
+ return true;
232
+ }
233
+
234
+ /**
235
+ * The current value of the form control.
236
+ *
237
+ * ```js
238
+ * e = document.querySelector('monster-field-set');
239
+ * console.log(e.value)
240
+ * ```
241
+ *
242
+ * @property {string}
243
+ */
244
+ get value() {
245
+ return this.getOption("value");
246
+ }
247
+
248
+ /**
249
+ * Set value of the form control.
250
+ *
251
+ * ```
252
+ * e = document.querySelector('monster-field-set');
253
+ * e.value=1
254
+ * ```
255
+ *
256
+ * @property {string} value
257
+ * @throws {Error} unsupported type
258
+ */
259
+ set value(value) {
260
+ this.setOption("value", value);
261
+ try {
262
+ this?.setFormValue(this.value);
263
+ } catch (e) {
264
+ addAttributeToken(this, ATTRIBUTE_ERRORMESSAGE, e.message);
265
+ }
266
+ }
252
267
  }
253
268
 
254
269
  function updateExtendedFields() {
255
- // check if slot has extended fields
256
- getSlottedElements.call(this, "", "extended").forEach((node) => {
257
- if (node.hasAttribute(ATTRIBUTE_EXTENDED)) {
258
- this.hasExtended = true;
259
- }
260
- })
270
+ const nodes = getSlottedElements.call(this, "", "extended");
271
+ console.log(nodes.size);
272
+ if (nodes.size > 0) {
273
+ this[extendedSwitchSymbol].classList.remove("hidden");
274
+ } else {
275
+ this[extendedSwitchSymbol].classList.add("hidden");
276
+ }
261
277
  }
262
278
 
263
279
  /**
@@ -266,78 +282,53 @@ function updateExtendedFields() {
266
282
  * @fires Monster.Components.Form.event:monster-field-set-clicked
267
283
  */
268
284
  function initEventHandler() {
269
- // const self = this;
270
- // const element = this[fieldSetElementSymbol];
271
- //
272
- // const type = "click";
273
-
274
- // element.addEventListener(type, function (event) {
275
- // const callback = self.getOption("actions.click");
276
- //
277
- // fireCustomEvent(self, "monster-field-set-clicked", {
278
- // element: self,
279
- // });
280
- //
281
- // if (!isFunction(callback)) {
282
- // return;
283
- // }
284
- //
285
- // const element = findTargetElementFromEvent(
286
- // event,
287
- // ATTRIBUTE_ROLE,
288
- // "control",
289
- // );
290
- //
291
- // if (!(element instanceof Node && self.hasNode(element))) {
292
- // return;
293
- // }
294
- //
295
- // callback.call(self, event);
296
- // });
297
-
298
-
299
- this[toggleSwitchElementSymbol].setOption("actions.on", () => {
300
- console.log( this[collapseElementSymbol],"!!!")
301
- this[collapseElementSymbol].open();
302
- });
303
-
304
- this[toggleSwitchElementSymbol].setOption("actions.off", () => {
305
- this[collapseElementSymbol].close();
306
- });
307
-
308
- // this[extendedSwitchElementSymbol].addEventListener(type, function (event) {
309
- // const element = findTargetElementFromEvent(
310
- // event,
311
- // ATTRIBUTE_ROLE,
312
- // "extended-switch",
313
- // );
314
- //
315
- //
316
- //
317
- // })
318
-
319
- return this;
285
+ this[toggleSwitchElementSymbol].setOption(
286
+ "labels.toggle-switch-on",
287
+ this.getOption("labels.toggle-switch-on"),
288
+ );
289
+ this[toggleSwitchElementSymbol].setOption(
290
+ "labels.toggle-switch-off",
291
+ this.getOption("labels.toggle-switch-off"),
292
+ );
293
+
294
+ this[toggleSwitchElementSymbol].setOption("actions.on", () => {
295
+ this[collapseElementSymbol].open();
296
+ });
297
+
298
+ this[toggleSwitchElementSymbol].setOption("actions.off", () => {
299
+ this[collapseElementSymbol].close();
300
+ });
301
+
302
+ return this;
320
303
  }
321
304
 
322
305
  /**
323
306
  * @private
324
307
  */
325
308
  function initControlReferences() {
326
- this[fieldSetElementSymbol] = this.shadowRoot.querySelector(
327
- `[${ATTRIBUTE_ROLE}="control"]`,
328
- );
309
+ this[fieldSetElementSymbol] = this.shadowRoot.querySelector(
310
+ `[${ATTRIBUTE_ROLE}="control"]`,
311
+ );
312
+
313
+ this[extendedSwitchElementSymbol] = this.shadowRoot.querySelector(
314
+ `[${ATTRIBUTE_ROLE}="extended-switch"]`,
315
+ );
316
+
317
+ this[collapseElementSymbol] = this.shadowRoot.querySelector(
318
+ `[${ATTRIBUTE_ROLE}="collapse"]`,
319
+ );
329
320
 
330
- this[extendedSwitchElementSymbol] = this.shadowRoot.querySelector(
331
- `[${ATTRIBUTE_ROLE}="extended-switch"]`,
332
- );
321
+ this[headerElementSymbol] = this.shadowRoot.querySelector(
322
+ `[${ATTRIBUTE_ROLE}="header"]`,
323
+ );
333
324
 
334
- this[collapseElementSymbol] = this.shadowRoot.querySelector(
335
- `[${ATTRIBUTE_ROLE}="collapse"]`,
336
- );
325
+ this[extendedSwitchSymbol] = this.shadowRoot.querySelector(
326
+ `[${ATTRIBUTE_ROLE}="extended-switch"]`,
327
+ );
337
328
 
338
- this[toggleSwitchElementSymbol] = this.shadowRoot.querySelector(
339
- `monster-toggle-switch`,
340
- );
329
+ this[toggleSwitchElementSymbol] = this.shadowRoot.querySelector(
330
+ `monster-toggle-switch`,
331
+ );
341
332
  }
342
333
 
343
334
  /**
@@ -345,14 +336,20 @@ function initControlReferences() {
345
336
  * @return {string}
346
337
  */
347
338
  function getTemplate() {
348
- // language=HTML
349
- return `
339
+ // language=HTML
340
+ return `
350
341
  <div data-monster-role="control" part="control">
351
342
  <div data-monster-role="header">
352
- <monster-toggle-switch class="hidden"></monster-toggle-switch>
343
+ <div data-monster-replace="path:labels.title" data-monster-role="title"></div>
344
+ <div data-monster-role="extended-switch">
345
+ <label data-monster-replace="path:labels.toggle-switch-label"></label>
346
+ <monster-toggle-switch></monster-toggle-switch>
347
+ </div>
353
348
  </div>
354
349
  <div>
355
- <slot></slot>
350
+ <div class="collapse-alignment">
351
+ <slot></slot>
352
+ </div>
356
353
  <monster-collapse data-monster-role="collapse">
357
354
  <slot name="extended"></slot>
358
355
  </monster-collapse>
@@ -1,3 +1,5 @@
1
+ @import "../../style/color.pcss";
2
+ @import "../../style/theme.pcss";
1
3
  @import "../../style/display.pcss";
2
4
  @import "../../style/border.pcss";
3
5
  @import "../../style/control.pcss";
@@ -9,12 +11,34 @@
9
11
  @import "../../style/floating-ui.pcss";
10
12
 
11
13
  [data-monster-role=control] {
12
-
14
+
15
+ & .collapse-alignment {
16
+ padding: 0 1rem;
17
+ }
18
+
19
+
13
20
  }
14
21
 
15
22
 
16
23
  [data-monster-role=header] {
17
24
  display: flex;
18
25
  align-items: center;
19
- justify-content: flex-end;
26
+ justify-content: space-between;
27
+ border-bottom: var(--monster-border-width) var(--monster-border-style) var(--monster-color-primary-1);
28
+ margin-bottom: 1rem;
29
+ padding-bottom: 0.2rem;
30
+
31
+ & label {
32
+ padding-right: 0.3rem;
33
+ }
34
+
35
+ & [data-monster-role=extended-switch] {
36
+ display: flex;
37
+ align-items: center;
38
+ justify-content: flex-end;
39
+ }
40
+
41
+ & [data-monster-role=title] {
42
+ font-weight: bold;
43
+ }
20
44
  }