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