@schukai/monster 3.58.0 → 3.58.2
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 +16 -0
- package/package.json +1 -1
- package/source/components/form/button-bar.mjs +463 -460
- package/source/components/form/style/button-bar.pcss +0 -2
- package/source/components/form/style/toggle-switch.pcss +67 -58
- package/source/components/form/stylesheet/button-bar.mjs +1 -1
- package/source/components/form/stylesheet/toggle-switch.mjs +1 -1
- package/source/components/form/toggle-switch.mjs +4 -5
- package/source/types/version.mjs +1 -1
- package/test/cases/monster.mjs +1 -1
|
@@ -4,34 +4,34 @@
|
|
|
4
4
|
* This file is licensed under the AGPLv3 License.
|
|
5
5
|
* License text available at https://www.gnu.org/licenses/agpl-3.0.en.html
|
|
6
6
|
*/
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
7
|
+
import {instanceSymbol} from "../../constants.mjs";
|
|
8
|
+
import {Pathfinder} from "../../data/pathfinder.mjs";
|
|
9
9
|
import {
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
addAttributeToken,
|
|
11
|
+
removeAttributeToken,
|
|
12
12
|
} from "../../dom/attributes.mjs";
|
|
13
|
-
import { ATTRIBUTE_ROLE
|
|
13
|
+
import {ATTRIBUTE_ERRORMESSAGE, ATTRIBUTE_ROLE} from "../../dom/constants.mjs";
|
|
14
14
|
import {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
assembleMethodSymbol,
|
|
16
|
+
getSlottedElements,
|
|
17
|
+
registerCustomElement,
|
|
18
18
|
} from "../../dom/customelement.mjs";
|
|
19
19
|
import {
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
CustomElement,
|
|
21
|
+
attributeObserverSymbol,
|
|
22
22
|
} from "../../dom/customelement.mjs";
|
|
23
|
-
import {
|
|
24
|
-
import {
|
|
25
|
-
import {
|
|
26
|
-
import {
|
|
27
|
-
import {
|
|
28
|
-
import {
|
|
29
|
-
import {
|
|
30
|
-
import {
|
|
31
|
-
import {
|
|
32
|
-
import {
|
|
33
|
-
|
|
34
|
-
export {
|
|
23
|
+
import {findTargetElementFromEvent} from "../../dom/events.mjs";
|
|
24
|
+
import {getDocument} from "../../dom/util.mjs";
|
|
25
|
+
import {getGlobal} from "../../types/global.mjs";
|
|
26
|
+
import {ID} from "../../types/id.mjs";
|
|
27
|
+
import {DeadMansSwitch} from "../../util/deadmansswitch.mjs";
|
|
28
|
+
import {Processing} from "../../util/processing.mjs";
|
|
29
|
+
import {STYLE_DISPLAY_MODE_BLOCK} from "./constants.mjs";
|
|
30
|
+
import {ButtonBarStyleSheet} from "./stylesheet/button-bar.mjs";
|
|
31
|
+
import {positionPopper} from "./util/floating-ui.mjs";
|
|
32
|
+
import {convertToPixels} from "../../dom/dimension.mjs";
|
|
33
|
+
|
|
34
|
+
export {ButtonBar};
|
|
35
35
|
|
|
36
36
|
/**
|
|
37
37
|
* @private
|
|
@@ -148,154 +148,154 @@ const ATTRIBUTE_POPPER_POSITION = "data-monster-popper-position";
|
|
|
148
148
|
* @fires Monster.Components.Form.event:monster-fetched
|
|
149
149
|
*/
|
|
150
150
|
class ButtonBar extends CustomElement {
|
|
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
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
151
|
+
/**
|
|
152
|
+
* This method is called by the `instanceof` operator.
|
|
153
|
+
* @returns {symbol}
|
|
154
|
+
*/
|
|
155
|
+
static get [instanceSymbol]() {
|
|
156
|
+
return Symbol.for("@schukai/monster/components/form/button-bar@@instance");
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* To set the options via the html tag the attribute `data-monster-options` must be used.
|
|
161
|
+
* @see {@link https://monsterjs.org/en/doc/#configurate-a-monster-control}
|
|
162
|
+
*
|
|
163
|
+
* The individual configuration values can be found in the table.
|
|
164
|
+
*
|
|
165
|
+
* @property {Object} templates Template definitions
|
|
166
|
+
* @property {string} templates.main Main template
|
|
167
|
+
* @property {Object} labels
|
|
168
|
+
* @property {Object} popper FloatingUI popper configuration
|
|
169
|
+
* @property {string} popper.placement=top Placement of the popper
|
|
170
|
+
* @property {number} popper.middleware [middlerware](https://floating-ui.js.org/docs/middleware) to be used
|
|
171
|
+
*/
|
|
172
|
+
get defaults() {
|
|
173
|
+
const obj = Object.assign({}, super.defaults, {
|
|
174
|
+
templates: {
|
|
175
|
+
main: getTemplate(),
|
|
176
|
+
},
|
|
177
|
+
labels: {},
|
|
178
|
+
popper: {
|
|
179
|
+
placement: "bottom",
|
|
180
|
+
},
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
initDefaultsFromAttributes.call(this, obj);
|
|
184
|
+
|
|
185
|
+
return obj;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* This method is called internal and should not be called directly.
|
|
190
|
+
*/
|
|
191
|
+
[assembleMethodSymbol]() {
|
|
192
|
+
super[assembleMethodSymbol]();
|
|
193
|
+
|
|
194
|
+
this[dimensionsSymbol] = new Pathfinder({data: {}});
|
|
195
|
+
|
|
196
|
+
initControlReferences.call(this);
|
|
197
|
+
initEventHandler.call(this);
|
|
198
|
+
|
|
199
|
+
// setup structure
|
|
200
|
+
initButtonBar.call(this).then(() => {
|
|
201
|
+
initPopperSwitch.call(this);
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* This method is called internal and should not be called directly.
|
|
207
|
+
*
|
|
208
|
+
* @return {CSSStyleSheet[]}
|
|
209
|
+
*/
|
|
210
|
+
static getCSSStyleSheet() {
|
|
211
|
+
return [ButtonBarStyleSheet];
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* This method is called internal and should not be called directly.
|
|
216
|
+
*
|
|
217
|
+
* @return {string}
|
|
218
|
+
*/
|
|
219
|
+
static getTag() {
|
|
220
|
+
return "monster-button-bar";
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* This method is called by the dom and should not be called directly.
|
|
225
|
+
*
|
|
226
|
+
* @return {void}
|
|
227
|
+
*/
|
|
228
|
+
connectedCallback() {
|
|
229
|
+
super.connectedCallback();
|
|
230
|
+
|
|
231
|
+
const document = getDocument();
|
|
232
|
+
|
|
233
|
+
for (const [, type] of Object.entries(["click", "touch"])) {
|
|
234
|
+
// close on outside ui-events
|
|
235
|
+
document.addEventListener(type, this[closeEventHandler]);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
setTimeout(() => {
|
|
239
|
+
updatePopper.call(this);
|
|
240
|
+
updateResizeObserverObservation.call(this);
|
|
241
|
+
}, 0);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* This method determines which attributes are to be monitored by `attributeChangedCallback()`.
|
|
246
|
+
*
|
|
247
|
+
* @return {string[]}
|
|
248
|
+
*/
|
|
249
|
+
static get observedAttributes() {
|
|
250
|
+
const attributes = super.observedAttributes;
|
|
251
|
+
attributes.push(ATTRIBUTE_POPPER_POSITION);
|
|
252
|
+
return attributes;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* This method is called by the dom and should not be called directly.
|
|
257
|
+
*
|
|
258
|
+
* @return {void}
|
|
259
|
+
*/
|
|
260
|
+
disconnectedCallback() {
|
|
261
|
+
super.disconnectedCallback();
|
|
262
|
+
|
|
263
|
+
const document = getDocument();
|
|
264
|
+
|
|
265
|
+
// close on outside ui-events
|
|
266
|
+
for (const [, type] of Object.entries(["click", "touch"])) {
|
|
267
|
+
document.removeEventListener(type, this[closeEventHandler]);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
disconnectResizeObserver.call(this);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* Close the slotted dialog.
|
|
275
|
+
* @return {ButtonBar}
|
|
276
|
+
*/
|
|
277
|
+
hideDialog() {
|
|
278
|
+
hide.call(this);
|
|
279
|
+
return this;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* Open the slotted dialog.
|
|
284
|
+
* @return {ButtonBar}
|
|
285
|
+
*/
|
|
286
|
+
showDialog() {
|
|
287
|
+
show.call(this);
|
|
288
|
+
return this;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* Toggle the slotted dialog.
|
|
293
|
+
* @return {ButtonBar}
|
|
294
|
+
*/
|
|
295
|
+
toggleDialog() {
|
|
296
|
+
toggle.call(this);
|
|
297
|
+
return this;
|
|
298
|
+
}
|
|
299
299
|
}
|
|
300
300
|
|
|
301
301
|
/**
|
|
@@ -304,88 +304,88 @@ class ButtonBar extends CustomElement {
|
|
|
304
304
|
* @returns {*}
|
|
305
305
|
*/
|
|
306
306
|
function initDefaultsFromAttributes(obj) {
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
307
|
+
if (this.hasAttribute(ATTRIBUTE_POPPER_POSITION)) {
|
|
308
|
+
obj.popper.placement = this.getAttribute(ATTRIBUTE_POPPER_POSITION);
|
|
309
|
+
}
|
|
310
310
|
|
|
311
|
-
|
|
311
|
+
return obj;
|
|
312
312
|
}
|
|
313
313
|
|
|
314
314
|
/**
|
|
315
315
|
* @private
|
|
316
316
|
*/
|
|
317
|
-
function
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
317
|
+
function initEventHandler() {
|
|
318
|
+
const self = this;
|
|
319
|
+
/**
|
|
320
|
+
* @param {Event} event
|
|
321
|
+
*/
|
|
322
|
+
self[closeEventHandler] = (event) => {
|
|
323
|
+
const path = event.composedPath();
|
|
324
|
+
|
|
325
|
+
for (const [, element] of Object.entries(path)) {
|
|
326
|
+
if (element === self) {
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
hide.call(self);
|
|
332
|
+
};
|
|
333
|
+
|
|
334
|
+
if (self[buttonBarSlotElementSymbol]) {
|
|
335
|
+
self[buttonBarSlotElementSymbol].addEventListener("slotchange", (event) => {
|
|
336
|
+
checkAndRearrangeButtons.call(self);
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
if (self[popperElementSymbol]) {
|
|
341
|
+
self[popperElementSymbol].addEventListener("slotchange", (event) => {
|
|
342
|
+
checkAndRearrangeButtons.call(self);
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
// data-monster-options
|
|
347
|
+
self[attributeObserverSymbol][ATTRIBUTE_POPPER_POSITION] = function (value) {
|
|
348
|
+
self.setOption("classes.button", value);
|
|
349
|
+
};
|
|
350
|
+
|
|
351
|
+
self[resizeObserverSymbol] = new ResizeObserver((entries) => {
|
|
352
|
+
if (self[timerCallbackSymbol] instanceof DeadMansSwitch) {
|
|
353
|
+
try {
|
|
354
|
+
self[timerCallbackSymbol].touch();
|
|
355
|
+
return;
|
|
356
|
+
} catch (e) {
|
|
357
|
+
// catch Error("has already run");
|
|
358
|
+
if (e.message !== "has already run") {
|
|
359
|
+
throw e;
|
|
360
|
+
}
|
|
361
|
+
delete self[timerCallbackSymbol];
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
self[timerCallbackSymbol] = new DeadMansSwitch(200, () => {
|
|
366
|
+
setTimeout(() => {
|
|
367
|
+
updatePopper.call(self);
|
|
368
|
+
self[dimensionsSymbol].setVia("data.calculated", false);
|
|
369
|
+
checkAndRearrangeButtons.call(self);
|
|
370
|
+
}, 50);
|
|
371
|
+
});
|
|
372
|
+
});
|
|
373
|
+
|
|
374
|
+
initSlotChangedHandler.call(self);
|
|
375
375
|
}
|
|
376
376
|
|
|
377
377
|
function initSlotChangedHandler() {
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
378
|
+
this[buttonBarElementSymbol].addEventListener("slotchange", () => {
|
|
379
|
+
updateResizeObserverObservation.call(this);
|
|
380
|
+
});
|
|
381
381
|
}
|
|
382
382
|
|
|
383
383
|
function checkAndRearrangeButtons() {
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
384
|
+
if (this[dimensionsSymbol].getVia("data.calculated", false) !== true) {
|
|
385
|
+
calculateButtonBarDimensions.call(this);
|
|
386
|
+
}
|
|
387
387
|
|
|
388
|
-
|
|
388
|
+
rearrangeButtons.call(this);
|
|
389
389
|
}
|
|
390
390
|
|
|
391
391
|
/**
|
|
@@ -393,59 +393,58 @@ function checkAndRearrangeButtons() {
|
|
|
393
393
|
* @return {Object}
|
|
394
394
|
*/
|
|
395
395
|
function rearrangeButtons() {
|
|
396
|
-
const switchWidth = this[switchElementSymbol].offsetWidth;
|
|
397
|
-
|
|
398
|
-
let sum = switchWidth;
|
|
399
|
-
const space = this[dimensionsSymbol].getVia("data.space");
|
|
400
|
-
|
|
401
|
-
const buttonReferences = this[dimensionsSymbol].getVia(
|
|
402
|
-
"data.buttonReferences",
|
|
403
|
-
);
|
|
404
|
-
|
|
405
|
-
for (const ref of buttonReferences) {
|
|
406
|
-
sum += this[dimensionsSymbol].getVia(`data.button.${ref}`);
|
|
407
|
-
|
|
408
|
-
let elements = getSlottedElements.call(
|
|
409
|
-
this,
|
|
410
|
-
'[data-monster-reference="' + ref + '"]',
|
|
411
|
-
null,
|
|
412
|
-
); // null ↦ o
|
|
413
|
-
if (elements.size === 0) {
|
|
414
|
-
elements = getSlottedElements.call(
|
|
415
|
-
this,
|
|
416
|
-
'[data-monster-reference="' + ref + '"]',
|
|
417
|
-
"popper",
|
|
418
|
-
); // null ↦ o
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
const nextValue = elements.values().next();
|
|
422
|
-
if (!nextValue) {
|
|
423
|
-
continue;
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
const element = nextValue?.value;
|
|
427
|
-
if (!(element instanceof HTMLElement)) {
|
|
428
|
-
continue;
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
const buttonLabel = element.innerText;
|
|
432
|
-
|
|
433
|
-
if (sum > space) {
|
|
434
|
-
element.setAttribute("slot", "popper");
|
|
435
|
-
} else {
|
|
436
|
-
element.removeAttribute("slot");
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
396
|
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
397
|
+
let sum = this[switchElementSymbol].offsetWidth;
|
|
398
|
+
const space = this[dimensionsSymbol].getVia("data.space");
|
|
399
|
+
|
|
400
|
+
const buttonReferences = this[dimensionsSymbol].getVia(
|
|
401
|
+
"data.buttonReferences",
|
|
402
|
+
);
|
|
403
|
+
|
|
404
|
+
for (const ref of buttonReferences) {
|
|
405
|
+
sum += this[dimensionsSymbol].getVia(`data.button.${ref}`);
|
|
406
|
+
|
|
407
|
+
let elements = getSlottedElements.call(
|
|
408
|
+
this,
|
|
409
|
+
'[data-monster-reference="' + ref + '"]',
|
|
410
|
+
null,
|
|
411
|
+
); // null ↦ o
|
|
412
|
+
if (elements.size === 0) {
|
|
413
|
+
elements = getSlottedElements.call(
|
|
414
|
+
this,
|
|
415
|
+
'[data-monster-reference="' + ref + '"]',
|
|
416
|
+
"popper",
|
|
417
|
+
); // null ↦ o
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
const nextValue = elements.values().next();
|
|
421
|
+
if (!nextValue) {
|
|
422
|
+
continue;
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
const element = nextValue?.value;
|
|
426
|
+
if (!(element instanceof HTMLElement)) {
|
|
427
|
+
continue;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
const buttonLabel = element.innerText;
|
|
431
|
+
|
|
432
|
+
if (sum > space) {
|
|
433
|
+
element.setAttribute("slot", "popper");
|
|
434
|
+
} else {
|
|
435
|
+
element.removeAttribute("slot");
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
const inVisibleButtons = getSlottedElements.call(this, ":scope", "popper"); // null ↦ o
|
|
440
|
+
if (inVisibleButtons.size > 0) {
|
|
441
|
+
this[switchElementSymbol].classList.remove("hidden");
|
|
442
|
+
} else {
|
|
443
|
+
this[switchElementSymbol].classList.add("hidden");
|
|
444
|
+
setTimeout(() => {
|
|
445
|
+
hide.call(this);
|
|
446
|
+
}, 1);
|
|
447
|
+
}
|
|
449
448
|
}
|
|
450
449
|
|
|
451
450
|
/**
|
|
@@ -454,18 +453,22 @@ function rearrangeButtons() {
|
|
|
454
453
|
* @return {number}
|
|
455
454
|
*/
|
|
456
455
|
function calcBoxWidth(node) {
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
456
|
+
const dim = getGlobal()?.getComputedStyle(node);
|
|
457
|
+
if (dim === null) {
|
|
458
|
+
addAttributeToken(this, ATTRIBUTE_ERRORMESSAGE, "no computed style");
|
|
459
|
+
throw new Error("no computed style");
|
|
460
|
+
}
|
|
461
|
+
const bounding = node.getBoundingClientRect();
|
|
462
|
+
|
|
463
|
+
return (
|
|
464
|
+
convertToPixels(dim["border-left-width"]) +
|
|
465
|
+
convertToPixels(dim["padding-left"]) +
|
|
466
|
+
convertToPixels(dim["margin-left"]) +
|
|
467
|
+
bounding["width"] +
|
|
468
|
+
convertToPixels(dim["border-right-width"]) +
|
|
469
|
+
convertToPixels(dim["margin-right"]) +
|
|
470
|
+
convertToPixels(dim["padding-left"])
|
|
471
|
+
);
|
|
469
472
|
}
|
|
470
473
|
|
|
471
474
|
/**
|
|
@@ -473,112 +476,112 @@ function calcBoxWidth(node) {
|
|
|
473
476
|
* @return {Object}
|
|
474
477
|
*/
|
|
475
478
|
function calculateButtonBarDimensions() {
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
479
|
+
const computedStyle = getComputedStyle(this.parentElement);
|
|
480
|
+
if (computedStyle === null) {
|
|
481
|
+
throw new Error("no computed style");
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
let width = this.parentElement.clientWidth;
|
|
485
|
+
if (computedStyle.getPropertyValue("box-sizing") !== "border-box") {
|
|
486
|
+
width = computedStyle.getPropertyValue("width");
|
|
487
|
+
this[dimensionsSymbol].setVia("data.space", convertToPixels(width));
|
|
488
|
+
} else {
|
|
489
|
+
let borderWidth = getComputedStyle(this).getPropertyValue(
|
|
490
|
+
"--monster-border-width",
|
|
491
|
+
);
|
|
492
|
+
if (borderWidth === null || borderWidth === "") {
|
|
493
|
+
borderWidth = "0px";
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
const borderWidthWithoutUnit = convertToPixels(borderWidth);
|
|
497
|
+
|
|
498
|
+
// space to be allocated
|
|
499
|
+
this[dimensionsSymbol].setVia(
|
|
500
|
+
"data.space",
|
|
501
|
+
width - 2 * borderWidthWithoutUnit,
|
|
502
|
+
);
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
this[dimensionsSymbol].setVia("data.visible", !(width === 0));
|
|
506
|
+
|
|
507
|
+
const buttonReferences = [];
|
|
508
|
+
|
|
509
|
+
const visibleButtons = getSlottedElements.call(this, ":scope", null); // null ↦ o
|
|
510
|
+
|
|
511
|
+
for (const [, button] of visibleButtons.entries()) {
|
|
512
|
+
if (!button.hasAttribute("data-monster-reference")) {
|
|
513
|
+
button.setAttribute("data-monster-reference", new ID("vb").toString());
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
const ref = button.getAttribute("data-monster-reference");
|
|
517
|
+
if (ref === null) continue;
|
|
518
|
+
|
|
519
|
+
buttonReferences.push(ref);
|
|
520
|
+
this[dimensionsSymbol].setVia(
|
|
521
|
+
`data.button.${ref}`,
|
|
522
|
+
calcBoxWidth.call(this, button),
|
|
523
|
+
);
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
const invisibleButtons = getSlottedElements.call(this, ":scope", "popper"); // null ↦ o
|
|
527
|
+
for (const [, button] of invisibleButtons.entries()) {
|
|
528
|
+
if (!button.hasAttribute("data-monster-reference")) {
|
|
529
|
+
button.setAttribute("data-monster-reference", new ID("ib").toString());
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
const ref = button.getAttribute("data-monster-reference");
|
|
533
|
+
if (ref === null) continue;
|
|
534
|
+
|
|
535
|
+
if (ref.indexOf("ib") !== 0) {
|
|
536
|
+
buttonReferences.push(ref);
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
this[dimensionsSymbol].setVia("data.calculated", true);
|
|
541
|
+
this[dimensionsSymbol].setVia("data.buttonReferences", buttonReferences);
|
|
539
542
|
}
|
|
540
543
|
|
|
541
544
|
/**
|
|
542
545
|
* @private
|
|
543
546
|
*/
|
|
544
547
|
function updateResizeObserverObservation() {
|
|
545
|
-
|
|
548
|
+
this[resizeObserverSymbol].disconnect();
|
|
546
549
|
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
550
|
+
const slottedNodes = getSlottedElements.call(this);
|
|
551
|
+
slottedNodes.forEach((node) => {
|
|
552
|
+
this[resizeObserverSymbol].observe(node);
|
|
553
|
+
});
|
|
551
554
|
|
|
552
|
-
|
|
553
|
-
|
|
555
|
+
if (this.parentElement === null) return;
|
|
556
|
+
this[resizeObserverSymbol].observe(this.parentElement);
|
|
554
557
|
}
|
|
555
558
|
|
|
556
559
|
/**
|
|
557
560
|
* @private
|
|
558
561
|
*/
|
|
559
562
|
function disconnectResizeObserver() {
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
+
if (this[resizeObserverSymbol] instanceof ResizeObserver) {
|
|
564
|
+
this[resizeObserverSymbol].disconnect();
|
|
565
|
+
}
|
|
563
566
|
}
|
|
564
567
|
|
|
565
568
|
/**
|
|
566
569
|
* @private
|
|
567
570
|
*/
|
|
568
571
|
function toggle() {
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
572
|
+
if (this[popperElementSymbol].style.display === STYLE_DISPLAY_MODE_BLOCK) {
|
|
573
|
+
hide.call(this);
|
|
574
|
+
} else {
|
|
575
|
+
show.call(this);
|
|
576
|
+
}
|
|
574
577
|
}
|
|
575
578
|
|
|
576
579
|
/**
|
|
577
580
|
* @private
|
|
578
581
|
*/
|
|
579
582
|
function hide() {
|
|
580
|
-
|
|
581
|
-
|
|
583
|
+
this[popperElementSymbol].style.display = "none";
|
|
584
|
+
removeAttributeToken(this[controlElementSymbol], "class", "open");
|
|
582
585
|
}
|
|
583
586
|
|
|
584
587
|
/**
|
|
@@ -586,40 +589,40 @@ function hide() {
|
|
|
586
589
|
* @this PopperButton
|
|
587
590
|
*/
|
|
588
591
|
function show() {
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
+
if (this.getOption("disabled", false) === true) {
|
|
593
|
+
return;
|
|
594
|
+
}
|
|
592
595
|
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
+
if (this[popperElementSymbol].style.display === STYLE_DISPLAY_MODE_BLOCK) {
|
|
597
|
+
return;
|
|
598
|
+
}
|
|
596
599
|
|
|
597
|
-
|
|
598
|
-
|
|
600
|
+
this[popperElementSymbol].style.visibility = "hidden";
|
|
601
|
+
this[popperElementSymbol].style.display = STYLE_DISPLAY_MODE_BLOCK;
|
|
599
602
|
|
|
600
|
-
|
|
603
|
+
addAttributeToken(this[controlElementSymbol], "class", "open");
|
|
601
604
|
|
|
602
|
-
|
|
605
|
+
updatePopper.call(this);
|
|
603
606
|
}
|
|
604
607
|
|
|
605
608
|
/**
|
|
606
609
|
* @private
|
|
607
610
|
*/
|
|
608
611
|
function updatePopper() {
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
612
|
+
if (this[popperElementSymbol].style.display !== STYLE_DISPLAY_MODE_BLOCK) {
|
|
613
|
+
return;
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
if (this.getOption("disabled", false) === true) {
|
|
617
|
+
return;
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
positionPopper.call(
|
|
621
|
+
this,
|
|
622
|
+
this[switchElementSymbol],
|
|
623
|
+
this[popperElementSymbol],
|
|
624
|
+
this.getOption("popper", {}),
|
|
625
|
+
);
|
|
623
626
|
}
|
|
624
627
|
|
|
625
628
|
/**
|
|
@@ -628,34 +631,34 @@ function updatePopper() {
|
|
|
628
631
|
* @throws {Error} no shadow-root is defined
|
|
629
632
|
*/
|
|
630
633
|
function initControlReferences() {
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
634
|
+
if (!this.shadowRoot) {
|
|
635
|
+
throw new Error("no shadow-root is defined");
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
this[controlElementSymbol] = this.shadowRoot.querySelector(
|
|
639
|
+
`[${ATTRIBUTE_ROLE}=control]`,
|
|
640
|
+
);
|
|
641
|
+
this[buttonBarElementSymbol] = this.shadowRoot.querySelector(
|
|
642
|
+
`[${ATTRIBUTE_ROLE}=button-bar]`,
|
|
643
|
+
);
|
|
644
|
+
this[popperElementSymbol] = this.shadowRoot.querySelector(
|
|
645
|
+
`[${ATTRIBUTE_ROLE}=popper]`,
|
|
646
|
+
);
|
|
647
|
+
this[popperNavElementSymbol] = this.shadowRoot.querySelector(
|
|
648
|
+
`[${ATTRIBUTE_ROLE}=popper-nav]`,
|
|
649
|
+
);
|
|
650
|
+
this[switchElementSymbol] = this.shadowRoot.querySelector(
|
|
651
|
+
`[${ATTRIBUTE_ROLE}=switch]`,
|
|
652
|
+
);
|
|
653
|
+
|
|
654
|
+
this[buttonBarSlotElementSymbol] = null;
|
|
655
|
+
if (this[buttonBarElementSymbol])
|
|
656
|
+
this[buttonBarSlotElementSymbol] =
|
|
657
|
+
this[buttonBarElementSymbol].querySelector(`slot`);
|
|
658
|
+
this[popperSlotElementSymbol] = null;
|
|
659
|
+
if (this[popperElementSymbol])
|
|
660
|
+
this[popperSlotElementSymbol] =
|
|
661
|
+
this[popperElementSymbol].querySelector(`slot`);
|
|
659
662
|
}
|
|
660
663
|
|
|
661
664
|
/**
|
|
@@ -665,36 +668,36 @@ function initControlReferences() {
|
|
|
665
668
|
*
|
|
666
669
|
*/
|
|
667
670
|
function initButtonBar() {
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
+
if (!this.shadowRoot) {
|
|
672
|
+
throw new Error("no shadow-root is defined");
|
|
673
|
+
}
|
|
671
674
|
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
+
return new Processing(() => {
|
|
676
|
+
checkAndRearrangeButtons.call(this);
|
|
677
|
+
}).run();
|
|
675
678
|
}
|
|
676
679
|
|
|
677
680
|
/**
|
|
678
681
|
* @private
|
|
679
682
|
*/
|
|
680
683
|
function initPopperSwitch() {
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
684
|
+
/**
|
|
685
|
+
* @param {Event} event
|
|
686
|
+
*/
|
|
687
|
+
this[popperSwitchEventHandler] = (event) => {
|
|
688
|
+
const element = findTargetElementFromEvent(event, ATTRIBUTE_ROLE, "switch");
|
|
689
|
+
|
|
690
|
+
if (element instanceof HTMLButtonElement) {
|
|
691
|
+
toggle.call(this);
|
|
692
|
+
}
|
|
693
|
+
};
|
|
694
|
+
|
|
695
|
+
for (const type of ["click", "touch"]) {
|
|
696
|
+
this[switchElementSymbol].addEventListener(
|
|
697
|
+
type,
|
|
698
|
+
this[popperSwitchEventHandler],
|
|
699
|
+
);
|
|
700
|
+
}
|
|
698
701
|
}
|
|
699
702
|
|
|
700
703
|
/**
|
|
@@ -702,8 +705,8 @@ function initPopperSwitch() {
|
|
|
702
705
|
* @return {string}
|
|
703
706
|
*/
|
|
704
707
|
function getTemplate() {
|
|
705
|
-
|
|
706
|
-
|
|
708
|
+
// language=HTML
|
|
709
|
+
return `
|
|
707
710
|
<div data-monster-role="control" part="control">
|
|
708
711
|
<div data-monster-role="button-bar">
|
|
709
712
|
<slot></slot>
|