@schukai/monster 3.67.0 → 3.68.0
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +18 -11
- package/package.json +1 -1
- package/source/components/form/field-set.mjs +274 -204
- package/source/components/form/style/field-set.pcss +9 -2
- package/source/components/form/style/toggle-switch.pcss +2 -8
- package/source/components/form/stylesheet/field-set.mjs +8 -17
- package/source/components/form/stylesheet/toggle-switch.mjs +8 -17
- package/source/components/form/toggle-switch.mjs +330 -321
- package/source/components/host/toggle-button.mjs +1 -3
- package/test/cases/components/form/toggle-switch.mjs +2 -0
package/CHANGELOG.md
CHANGED
@@ -2,34 +2,41 @@
|
|
2
2
|
|
3
3
|
|
4
4
|
|
5
|
+
## [3.68.0] - 2024-06-23
|
6
|
+
|
7
|
+
### Add Features
|
8
|
+
|
9
|
+
- add on/off action to toggle switch [#207](https://gitlab.schukai.com/oss/libraries/javascript/monster/issues/207)
|
10
|
+
### Bug Fixes
|
11
|
+
|
12
|
+
- gitlab pipeline
|
13
|
+
### Changes
|
14
|
+
|
15
|
+
- repair toggle test
|
16
|
+
- update changelog + mattermost info call
|
17
|
+
|
5
18
|
## [3.67.0] - 2024-06-22
|
6
19
|
|
7
20
|
### Add Features
|
8
21
|
|
9
|
-
- new options to define the markers that are used for the label template. [#203](https://gitlab.schukai.com/oss/libraries/javascript/monster/issues/203) See merge request oss/libraries/javascript/monster[!53](https://gitlab.schukai.com/oss/libraries/javascript/monster/merge_requests/53)
|
10
22
|
- new options to define the markers that are used for the label template [#203](https://gitlab.schukai.com/oss/libraries/javascript/monster/issues/203)
|
11
23
|
|
12
|
-
## 2024-06-22
|
13
|
-
- new options to define the markers that are used for the label template [#203](https://gitlab.schukai.com/oss/libraries/javascript/monster/issues/203)
|
14
|
-
|
15
24
|
## [3.66.0] - 2024-06-21
|
16
25
|
|
17
26
|
### Add Features
|
18
27
|
|
19
28
|
- new flag feature.useStrictValueComparison [#206](https://gitlab.schukai.com/oss/libraries/javascript/monster/issues/206)
|
20
29
|
- new flag features.storeFetchedData and function Select::getLastFetchedData [#204](https://gitlab.schukai.com/oss/libraries/javascript/monster/issues/204)
|
30
|
+
|
21
31
|
### Bug Fixes
|
22
32
|
|
23
|
-
- [#200](https://gitlab.schukai.com/oss/libraries/javascript/monster/issues/200)
|
24
|
-
|
25
|
-
- [#201](https://gitlab.schukai.com/oss/libraries/javascript/monster/issues/201)
|
26
|
-
- slight color adjustments
|
33
|
+
- Reloading options in a select does not work [#200](https://gitlab.schukai.com/oss/libraries/javascript/monster/issues/200)
|
34
|
+
|
27
35
|
### Changes
|
28
36
|
|
29
37
|
- tidy project files
|
30
|
-
- [#
|
31
|
-
-
|
32
|
-
|
38
|
+
- call Button use findElementWithSelectorUpwards [#201](https://gitlab.schukai.com/oss/libraries/javascript/monster/issues/201)
|
39
|
+
- slight color adjustments
|
33
40
|
|
34
41
|
|
35
42
|
## [3.65.21] - 2024-06-20
|
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.
|
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.0"}
|
@@ -12,30 +12,49 @@
|
|
12
12
|
* SPDX-License-Identifier: AGPL-3.0
|
13
13
|
*/
|
14
14
|
|
15
|
-
import {
|
16
|
-
import {
|
15
|
+
import {instanceSymbol} from "../../constants.mjs";
|
16
|
+
import {addAttributeToken} from "../../dom/attributes.mjs";
|
17
17
|
import {
|
18
|
-
|
19
|
-
|
18
|
+
ATTRIBUTE_ERRORMESSAGE,
|
19
|
+
ATTRIBUTE_ROLE,
|
20
20
|
} from "../../dom/constants.mjs";
|
21
|
-
import {
|
21
|
+
import {CustomControl} from "../../dom/customcontrol.mjs";
|
22
22
|
import {
|
23
|
-
|
24
|
-
|
23
|
+
assembleMethodSymbol,
|
24
|
+
registerCustomElement,
|
25
25
|
} from "../../dom/customelement.mjs";
|
26
|
-
import {
|
27
|
-
import {
|
28
|
-
import {
|
29
|
-
import {
|
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";
|
30
30
|
import "../layout/collapse.mjs";
|
31
|
+
import {ToggleSwitch} from "./toggle-switch.mjs";
|
31
32
|
|
32
|
-
export {
|
33
|
+
export {FieldSet};
|
33
34
|
|
34
35
|
/**
|
35
36
|
* @private
|
36
37
|
* @type {symbol}
|
37
38
|
*/
|
38
|
-
|
39
|
+
const fieldSetElementSymbol = Symbol("fieldSetElement");
|
40
|
+
|
41
|
+
/**
|
42
|
+
* @private
|
43
|
+
* @type {symbol}
|
44
|
+
*/
|
45
|
+
const collapseElementSymbol = Symbol("collapseElement");
|
46
|
+
|
47
|
+
/**
|
48
|
+
* @private
|
49
|
+
* @type {symbol}
|
50
|
+
*/
|
51
|
+
const toggleSwitchElementSymbol = Symbol("toggleSwitchElement");
|
52
|
+
|
53
|
+
/**
|
54
|
+
* @private
|
55
|
+
* @type {symbol}
|
56
|
+
*/
|
57
|
+
const extendedSwitchElementSymbol = Symbol("extendedSwitchElement");
|
39
58
|
|
40
59
|
/**
|
41
60
|
* This CustomControl creates a FieldSet element with a variety of options.
|
@@ -71,164 +90,174 @@ export const fieldSetElementSymbol = Symbol("fieldSetElement");
|
|
71
90
|
* @summary A simple FieldSet
|
72
91
|
*/
|
73
92
|
class FieldSet extends CustomControl {
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
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
|
+
}
|
252
|
+
}
|
253
|
+
|
254
|
+
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
|
+
})
|
232
261
|
}
|
233
262
|
|
234
263
|
/**
|
@@ -237,45 +266,78 @@ class FieldSet extends CustomControl {
|
|
237
266
|
* @fires Monster.Components.Form.event:monster-field-set-clicked
|
238
267
|
*/
|
239
268
|
function initEventHandler() {
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
element.addEventListener(type, function (event) {
|
246
|
-
const callback = self.getOption("actions.click");
|
269
|
+
// const self = this;
|
270
|
+
// const element = this[fieldSetElementSymbol];
|
271
|
+
//
|
272
|
+
// const type = "click";
|
247
273
|
|
248
|
-
|
249
|
-
|
250
|
-
|
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
|
+
// });
|
251
297
|
|
252
|
-
if (!isFunction(callback)) {
|
253
|
-
return;
|
254
|
-
}
|
255
298
|
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
);
|
299
|
+
this[toggleSwitchElementSymbol].setOption("actions.on", () => {
|
300
|
+
console.log( this[collapseElementSymbol],"!!!")
|
301
|
+
this[collapseElementSymbol].open();
|
302
|
+
});
|
261
303
|
|
262
|
-
|
263
|
-
|
264
|
-
|
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
|
+
// })
|
265
318
|
|
266
|
-
|
267
|
-
});
|
268
|
-
|
269
|
-
return this;
|
319
|
+
return this;
|
270
320
|
}
|
271
321
|
|
272
322
|
/**
|
273
323
|
* @private
|
274
324
|
*/
|
275
325
|
function initControlReferences() {
|
276
|
-
|
277
|
-
|
278
|
-
|
326
|
+
this[fieldSetElementSymbol] = this.shadowRoot.querySelector(
|
327
|
+
`[${ATTRIBUTE_ROLE}="control"]`,
|
328
|
+
);
|
329
|
+
|
330
|
+
this[extendedSwitchElementSymbol] = this.shadowRoot.querySelector(
|
331
|
+
`[${ATTRIBUTE_ROLE}="extended-switch"]`,
|
332
|
+
);
|
333
|
+
|
334
|
+
this[collapseElementSymbol] = this.shadowRoot.querySelector(
|
335
|
+
`[${ATTRIBUTE_ROLE}="collapse"]`,
|
336
|
+
);
|
337
|
+
|
338
|
+
this[toggleSwitchElementSymbol] = this.shadowRoot.querySelector(
|
339
|
+
`monster-toggle-switch`,
|
340
|
+
);
|
279
341
|
}
|
280
342
|
|
281
343
|
/**
|
@@ -283,12 +345,20 @@ function initControlReferences() {
|
|
283
345
|
* @return {string}
|
284
346
|
*/
|
285
347
|
function getTemplate() {
|
286
|
-
|
287
|
-
|
348
|
+
// language=HTML
|
349
|
+
return `
|
288
350
|
<div data-monster-role="control" part="control">
|
289
|
-
|
290
|
-
|
291
|
-
|
351
|
+
<div data-monster-role="header">
|
352
|
+
<monster-toggle-switch class="hidden"></monster-toggle-switch>
|
353
|
+
</div>
|
354
|
+
<div>
|
355
|
+
<slot></slot>
|
356
|
+
<monster-collapse data-monster-role="collapse">
|
357
|
+
<slot name="extended"></slot>
|
358
|
+
</monster-collapse>
|
359
|
+
</div>
|
360
|
+
|
361
|
+
|
292
362
|
</div>`;
|
293
363
|
}
|
294
364
|
|
@@ -10,24 +10,21 @@
|
|
10
10
|
margin: 0;
|
11
11
|
outline: none;
|
12
12
|
box-sizing: border-box;
|
13
|
-
|
13
|
+
|
14
14
|
&:focus {
|
15
15
|
outline: 1px dashed var(--monster-color-selection-3);
|
16
16
|
outline-offset: 2px;
|
17
17
|
}
|
18
18
|
|
19
|
-
|
20
19
|
& .switch {
|
21
20
|
position: relative;
|
22
|
-
|
23
|
-
border-width: thin;
|
21
|
+
border-width: var(--monster-border-width);
|
24
22
|
border-style: var(--monster-border-style);
|
25
23
|
transition: background-color 0.2s;
|
26
24
|
display: inline-grid;
|
27
25
|
grid-template-columns: 1fr 1fr;
|
28
26
|
box-sizing: border-box;
|
29
27
|
width: 100%;
|
30
|
-
|
31
28
|
}
|
32
29
|
|
33
30
|
& .label {
|
@@ -35,10 +32,8 @@
|
|
35
32
|
white-space: nowrap;
|
36
33
|
overflow: hidden;
|
37
34
|
text-overflow: ellipsis;
|
38
|
-
height: 2.5em;
|
39
35
|
display: block;
|
40
36
|
text-align: center;
|
41
|
-
line-height: 2.5em;
|
42
37
|
user-select: none;
|
43
38
|
padding: 0 0.2em;
|
44
39
|
}
|
@@ -69,7 +64,6 @@
|
|
69
64
|
visibility: hidden;
|
70
65
|
}
|
71
66
|
|
72
|
-
|
73
67
|
& .switch[data-monster-state="on"] .switch-slider {
|
74
68
|
transform: translateX(100%);
|
75
69
|
|