@schukai/monster 3.73.6 → 3.73.7

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.
@@ -12,27 +12,26 @@
12
12
  * SPDX-License-Identifier: AGPL-3.0
13
13
  */
14
14
 
15
- import { instanceSymbol } from "../../constants.mjs";
15
+ import {instanceSymbol} from "../../constants.mjs";
16
16
  import {
17
- addAttributeToken,
18
- removeAttributeToken,
17
+ addAttributeToken,
18
+ removeAttributeToken,
19
19
  } from "../../dom/attributes.mjs";
20
- import { ATTRIBUTE_ROLE } from "../../dom/constants.mjs";
20
+ import {ATTRIBUTE_ROLE} from "../../dom/constants.mjs";
21
21
  import {
22
- assembleMethodSymbol,
23
- CustomElement,
24
- registerCustomElement,
22
+ assembleMethodSymbol,
23
+ CustomElement,
24
+ registerCustomElement,
25
25
  } from "../../dom/customelement.mjs";
26
- import { fireCustomEvent } from "../../dom/events.mjs";
27
- import { getDocument } from "../../dom/util.mjs";
28
- import { DeadMansSwitch } from "../../util/deadmansswitch.mjs";
29
- import { STYLE_DISPLAY_MODE_BLOCK } from "../form/constants.mjs";
30
- import { positionPopper } from "../form/util/floating-ui.mjs";
31
- import { CustomControl } from "../../dom/customcontrol.mjs";
32
- import { PopperStyleSheet } from "./stylesheet/popper.mjs";
33
- import { isArray } from "../../types/is.mjs";
26
+ import {fireCustomEvent} from "../../dom/events.mjs";
27
+ import {getDocument} from "../../dom/util.mjs";
28
+ import {DeadMansSwitch} from "../../util/deadmansswitch.mjs";
29
+ import {STYLE_DISPLAY_MODE_BLOCK} from "../form/constants.mjs";
30
+ import {positionPopper} from "../form/util/floating-ui.mjs";
31
+ import {PopperStyleSheet} from "./stylesheet/popper.mjs";
32
+ import {isArray} from "../../types/is.mjs";
34
33
 
35
- export { Popper };
34
+ export {Popper};
36
35
 
37
36
  /**
38
37
  * @private
@@ -97,144 +96,144 @@ const arrowElementSymbol = Symbol("arrowElement");
97
96
  * @fires monster-popper-opened fired when the popper is opened.
98
97
  */
99
98
  class Popper extends CustomElement {
100
- /**
101
- * This method is called by the `instanceof` operator.
102
- * @returns {symbol}
103
- */
104
- static get [instanceSymbol]() {
105
- return Symbol.for("@schukai/monster/components/layout/popper@@instance");
106
- }
107
-
108
- /**
109
- * To set the options via the html tag the attribute `data-monster-options` must be used.
110
- * @see {@link https://monsterjs.org/en/doc/#configurate-a-monster-control}
111
- *
112
- * The individual configuration values can be found in the table.
113
- *
114
- * @property {Object} templates The templates for the control.
115
- * @property {string} templates.main The main template.
116
- * @property {string} mode The mode of the popper. Possible values are `click`, `enter`, `manual`, `focus`, "auto" or a combination of them.
117
- * @property {string} content The content of the popper.
118
- * @property {object} popper The popper options.
119
- * @property {string} popper.placement The placement of the popper. Possible values are `top`, `bottom`, `left` and `right`.
120
- * @property {function[]} popper.middleware The middleware functions of the popper.
121
- * @property {Object} features The features of the popper.
122
- * @property {boolean} features.preventOpenEventSent Prevents the open event from being sent.
123
- */
124
- get defaults() {
125
- return Object.assign({}, super.defaults, {
126
- templates: {
127
- main: getTemplate(),
128
- },
129
- mode: "auto focus",
130
- content: "<slot></slot>",
131
- popper: {
132
- placement: "top",
133
- middleware: ["autoPlacement", "offset:10", "arrow"],
134
- },
135
- features: {
136
- preventOpenEventSent: false,
137
- },
138
- });
139
- }
140
-
141
- /**
142
- * This method is called by the `connectedCallback` method on the first call.
143
- *
144
- * @return {Void}
145
- */
146
- [assembleMethodSymbol]() {
147
- super[assembleMethodSymbol]();
148
- initControlReferences.call(this);
149
- initEventHandler.call(this);
150
- }
151
-
152
- /**
153
- * This method returns the tag name of the element.
154
- *
155
- * @return {string}
156
- */
157
- static getTag() {
158
- return "monster-popper";
159
- }
160
-
161
- /**
162
- * This method returns the css styles of the element.
163
- *
164
- * @return {CSSStyleSheet[]}
165
- */
166
- static getCSSStyleSheet() {
167
- return [PopperStyleSheet];
168
- }
169
-
170
- /**
171
- * This method is called when the element is connected to the dom.
172
- *
173
- * @return {void}
174
- */
175
- connectedCallback() {
176
- super.connectedCallback();
177
-
178
- const document = getDocument();
179
-
180
- for (const [, type] of Object.entries(["click", "touch"])) {
181
- // close on outside ui-events
182
- document.addEventListener(type, this[closeEventHandler]);
183
- }
184
-
185
- updatePopper.call(this);
186
- attachResizeObserver.call(this);
187
- }
188
-
189
- /**
190
- * This method is called when the element is disconnected from the dom.
191
- *
192
- * @return {void}
193
- */
194
- disconnectedCallback() {
195
- super.disconnectedCallback();
196
-
197
- // close on outside ui-events
198
- for (const [, type] of Object.entries(["click", "touch"])) {
199
- document.removeEventListener(type, this[closeEventHandler]);
200
- }
201
-
202
- disconnectResizeObserver.call(this);
203
- }
204
-
205
- /**
206
- * With this method you can show the popper.
207
- *
208
- * @return {Popper}
209
- */
210
- showDialog() {
211
- show.call(this);
212
- return this;
213
- }
214
-
215
- /**
216
- * With this method you can hide the popper.
217
- *
218
- * @return {Popper}
219
- */
220
- hideDialog() {
221
- hide.call(this);
222
- return this;
223
- }
224
-
225
- /**
226
- * With this method you can toggle the popper.
227
- *
228
- * @return {Popper}
229
- */
230
- toggleDialog() {
231
- if (this[popperElementSymbol].style.display === STYLE_DISPLAY_MODE_BLOCK) {
232
- this.hideDialog();
233
- } else {
234
- this.showDialog();
235
- }
236
- return this;
237
- }
99
+ /**
100
+ * This method is called by the `instanceof` operator.
101
+ * @returns {symbol}
102
+ */
103
+ static get [instanceSymbol]() {
104
+ return Symbol.for("@schukai/monster/components/layout/popper@@instance");
105
+ }
106
+
107
+ /**
108
+ * To set the options via the html tag the attribute `data-monster-options` must be used.
109
+ * @see {@link https://monsterjs.org/en/doc/#configurate-a-monster-control}
110
+ *
111
+ * The individual configuration values can be found in the table.
112
+ *
113
+ * @property {Object} templates The templates for the control.
114
+ * @property {string} templates.main The main template.
115
+ * @property {string} mode The mode of the popper. Possible values are `click`, `enter`, `manual`, `focus`, "auto" or a combination of them.
116
+ * @property {string} content The content of the popper.
117
+ * @property {object} popper The popper options.
118
+ * @property {string} popper.placement The placement of the popper. Possible values are `top`, `bottom`, `left` and `right`.
119
+ * @property {function[]} popper.middleware The middleware functions of the popper.
120
+ * @property {Object} features The features of the popper.
121
+ * @property {boolean} features.preventOpenEventSent Prevents the open event from being sent.
122
+ */
123
+ get defaults() {
124
+ return Object.assign({}, super.defaults, {
125
+ templates: {
126
+ main: getTemplate(),
127
+ },
128
+ mode: "auto focus",
129
+ content: "<slot></slot>",
130
+ popper: {
131
+ placement: "top",
132
+ middleware: ["autoPlacement", "shift", "offset:15", "arrow"],
133
+ },
134
+ features: {
135
+ preventOpenEventSent: false,
136
+ },
137
+ });
138
+ }
139
+
140
+ /**
141
+ * This method is called by the `connectedCallback` method on the first call.
142
+ *
143
+ * @return {Void}
144
+ */
145
+ [assembleMethodSymbol]() {
146
+ super[assembleMethodSymbol]();
147
+ initControlReferences.call(this);
148
+ initEventHandler.call(this);
149
+ }
150
+
151
+ /**
152
+ * This method returns the tag name of the element.
153
+ *
154
+ * @return {string}
155
+ */
156
+ static getTag() {
157
+ return "monster-popper";
158
+ }
159
+
160
+ /**
161
+ * This method returns the css styles of the element.
162
+ *
163
+ * @return {CSSStyleSheet[]}
164
+ */
165
+ static getCSSStyleSheet() {
166
+ return [PopperStyleSheet];
167
+ }
168
+
169
+ /**
170
+ * This method is called when the element is connected to the dom.
171
+ *
172
+ * @return {void}
173
+ */
174
+ connectedCallback() {
175
+ super.connectedCallback();
176
+
177
+ const document = getDocument();
178
+
179
+ for (const [, type] of Object.entries(["click", "touch"])) {
180
+ // close on outside ui-events
181
+ document.addEventListener(type, this[closeEventHandler]);
182
+ }
183
+
184
+ updatePopper.call(this);
185
+ attachResizeObserver.call(this);
186
+ }
187
+
188
+ /**
189
+ * This method is called when the element is disconnected from the dom.
190
+ *
191
+ * @return {void}
192
+ */
193
+ disconnectedCallback() {
194
+ super.disconnectedCallback();
195
+
196
+ // close on outside ui-events
197
+ for (const [, type] of Object.entries(["click", "touch"])) {
198
+ document.removeEventListener(type, this[closeEventHandler]);
199
+ }
200
+
201
+ disconnectResizeObserver.call(this);
202
+ }
203
+
204
+ /**
205
+ * With this method you can show the popper.
206
+ *
207
+ * @return {Popper}
208
+ */
209
+ showDialog() {
210
+ show.call(this);
211
+ return this;
212
+ }
213
+
214
+ /**
215
+ * With this method you can hide the popper.
216
+ *
217
+ * @return {Popper}
218
+ */
219
+ hideDialog() {
220
+ hide.call(this);
221
+ return this;
222
+ }
223
+
224
+ /**
225
+ * With this method you can toggle the popper.
226
+ *
227
+ * @return {Popper}
228
+ */
229
+ toggleDialog() {
230
+ if (this[popperElementSymbol].style.display === STYLE_DISPLAY_MODE_BLOCK) {
231
+ this.hideDialog();
232
+ } else {
233
+ this.showDialog();
234
+ }
235
+ return this;
236
+ }
238
237
  }
239
238
 
240
239
  /**
@@ -242,38 +241,38 @@ class Popper extends CustomElement {
242
241
  * @return {Popper}
243
242
  */
244
243
  function initEventHandler() {
245
- this[closeEventHandler] = (event) => {
246
- const path = event.composedPath();
247
-
248
- for (const [, element] of Object.entries(path)) {
249
- if (element === this) {
250
- return;
251
- }
252
- }
253
- hide.call(this);
254
- };
255
-
256
- let modes = null;
257
- const modeOption = this.getOption("mode");
258
-
259
- if (typeof modeOption === "string") {
260
- modes = modeOption.split(" ");
261
- }
262
-
263
- if (
264
- modes === null ||
265
- modes === undefined ||
266
- isArray(modes) === false ||
267
- modes.length === 0
268
- ) {
269
- modes = ["manual"];
270
- }
271
-
272
- for (const [, mode] of Object.entries(modes)) {
273
- initEventHandlerByMode.call(this, mode);
274
- }
275
-
276
- return this;
244
+ this[closeEventHandler] = (event) => {
245
+ const path = event.composedPath();
246
+
247
+ for (const [, element] of Object.entries(path)) {
248
+ if (element === this) {
249
+ return;
250
+ }
251
+ }
252
+ hide.call(this);
253
+ };
254
+
255
+ let modes = null;
256
+ const modeOption = this.getOption("mode");
257
+
258
+ if (typeof modeOption === "string") {
259
+ modes = modeOption.split(" ");
260
+ }
261
+
262
+ if (
263
+ modes === null ||
264
+ modes === undefined ||
265
+ isArray(modes) === false ||
266
+ modes.length === 0
267
+ ) {
268
+ modes = ["manual"];
269
+ }
270
+
271
+ for (const [, mode] of Object.entries(modes)) {
272
+ initEventHandlerByMode.call(this, mode);
273
+ }
274
+
275
+ return this;
277
276
  }
278
277
 
279
278
  /**
@@ -283,159 +282,159 @@ function initEventHandler() {
283
282
  * @throws Error
284
283
  */
285
284
  function initEventHandlerByMode(mode) {
286
- switch (mode) {
287
- case "manual":
288
- break;
289
-
290
- case "focus":
291
- this[buttonElementSymbol].addEventListener("focus", (event) => {
292
- if (this.getOption("features.preventOpenEventSent") === true) {
293
- event.preventDefault();
294
- }
295
- this.showDialog();
296
- });
297
- this[buttonElementSymbol].addEventListener("blur", (event) => {
298
- if (this.getOption("features.preventOpenEventSent") === true) {
299
- event.preventDefault();
300
- }
301
- this.hideDialog();
302
- });
303
- break;
304
-
305
- case "click":
306
- this[buttonElementSymbol].addEventListener("click", (event) => {
307
- if (this.getOption("features.preventOpenEventSent") === true) {
308
- event.preventDefault();
309
- }
310
- this.toggleDialog();
311
- });
312
- break;
313
- case "enter":
314
- this[buttonElementSymbol].addEventListener("mouseenter", (event) => {
315
- if (this.getOption("features.preventOpenEventSent") === true) {
316
- event.preventDefault();
317
- }
318
- this.showDialog();
319
- });
320
- break;
321
-
322
- case "auto": // is hover
323
- this[buttonElementSymbol].addEventListener("mouseenter", (event) => {
324
- if (this.getOption("features.preventOpenEventSent") === true) {
325
- event.preventDefault();
326
- }
327
- this.showDialog();
328
- });
329
- this[buttonElementSymbol].addEventListener("mouseleave", (event) => {
330
- if (this.getOption("features.preventOpenEventSent") === true) {
331
- event.preventDefault();
332
- }
333
- this.hideDialog();
334
- });
335
- break;
336
- default:
337
- throw new Error(`Unknown mode ${mode}`);
338
- }
285
+ switch (mode) {
286
+ case "manual":
287
+ break;
288
+
289
+ case "focus":
290
+ this[buttonElementSymbol].addEventListener("focus", (event) => {
291
+ if (this.getOption("features.preventOpenEventSent") === true) {
292
+ event.preventDefault();
293
+ }
294
+ this.showDialog();
295
+ });
296
+ this[buttonElementSymbol].addEventListener("blur", (event) => {
297
+ if (this.getOption("features.preventOpenEventSent") === true) {
298
+ event.preventDefault();
299
+ }
300
+ this.hideDialog();
301
+ });
302
+ break;
303
+
304
+ case "click":
305
+ this[buttonElementSymbol].addEventListener("click", (event) => {
306
+ if (this.getOption("features.preventOpenEventSent") === true) {
307
+ event.preventDefault();
308
+ }
309
+ this.toggleDialog();
310
+ });
311
+ break;
312
+ case "enter":
313
+ this[buttonElementSymbol].addEventListener("mouseenter", (event) => {
314
+ if (this.getOption("features.preventOpenEventSent") === true) {
315
+ event.preventDefault();
316
+ }
317
+ this.showDialog();
318
+ });
319
+ break;
320
+
321
+ case "auto": // is hover
322
+ this[buttonElementSymbol].addEventListener("mouseenter", (event) => {
323
+ if (this.getOption("features.preventOpenEventSent") === true) {
324
+ event.preventDefault();
325
+ }
326
+ this.showDialog();
327
+ });
328
+ this[buttonElementSymbol].addEventListener("mouseleave", (event) => {
329
+ if (this.getOption("features.preventOpenEventSent") === true) {
330
+ event.preventDefault();
331
+ }
332
+ this.hideDialog();
333
+ });
334
+ break;
335
+ default:
336
+ throw new Error(`Unknown mode ${mode}`);
337
+ }
339
338
  }
340
339
 
341
340
  /**
342
341
  * @private
343
342
  */
344
343
  function attachResizeObserver() {
345
- // against flickering
346
- this[resizeObserverSymbol] = new ResizeObserver((entries) => {
347
- if (this[timerCallbackSymbol] instanceof DeadMansSwitch) {
348
- try {
349
- this[timerCallbackSymbol].touch();
350
- return;
351
- } catch (e) {
352
- delete this[timerCallbackSymbol];
353
- }
354
- }
355
-
356
- this[timerCallbackSymbol] = new DeadMansSwitch(200, () => {
357
- updatePopper.call(this);
358
- });
359
- });
360
-
361
- this[resizeObserverSymbol].observe(this.parentElement);
344
+ // against flickering
345
+ this[resizeObserverSymbol] = new ResizeObserver((entries) => {
346
+ if (this[timerCallbackSymbol] instanceof DeadMansSwitch) {
347
+ try {
348
+ this[timerCallbackSymbol].touch();
349
+ return;
350
+ } catch (e) {
351
+ delete this[timerCallbackSymbol];
352
+ }
353
+ }
354
+
355
+ this[timerCallbackSymbol] = new DeadMansSwitch(200, () => {
356
+ updatePopper.call(this);
357
+ });
358
+ });
359
+
360
+ this[resizeObserverSymbol].observe(this.parentElement);
362
361
  }
363
362
 
364
363
  function disconnectResizeObserver() {
365
- if (this[resizeObserverSymbol] instanceof ResizeObserver) {
366
- this[resizeObserverSymbol].disconnect();
367
- }
364
+ if (this[resizeObserverSymbol] instanceof ResizeObserver) {
365
+ this[resizeObserverSymbol].disconnect();
366
+ }
368
367
  }
369
368
 
370
369
  /**
371
370
  * @private
372
371
  */
373
372
  function hide() {
374
- const self = this;
373
+ const self = this;
375
374
 
376
- fireCustomEvent(self, "monster-popper-hide", {
377
- self,
378
- });
375
+ fireCustomEvent(self, "monster-popper-hide", {
376
+ self,
377
+ });
379
378
 
380
- self[popperElementSymbol].style.display = "none";
381
- removeAttributeToken(self[controlElementSymbol], "class", "open");
379
+ self[popperElementSymbol].style.display = "none";
380
+ removeAttributeToken(self[controlElementSymbol], "class", "open");
382
381
 
383
- setTimeout(() => {
384
- fireCustomEvent(self, "monster-popper-hidden", {
385
- self,
386
- });
387
- }, 0);
382
+ setTimeout(() => {
383
+ fireCustomEvent(self, "monster-popper-hidden", {
384
+ self,
385
+ });
386
+ }, 0);
388
387
  }
389
388
 
390
389
  /**
391
390
  * @private
392
391
  */
393
392
  function show() {
394
- const self = this;
393
+ const self = this;
395
394
 
396
- if (self.getOption("disabled", false) === true) {
397
- return;
398
- }
395
+ if (self.getOption("disabled", false) === true) {
396
+ return;
397
+ }
399
398
 
400
- if (self[popperElementSymbol].style.display === STYLE_DISPLAY_MODE_BLOCK) {
401
- return;
402
- }
399
+ if (self[popperElementSymbol].style.display === STYLE_DISPLAY_MODE_BLOCK) {
400
+ return;
401
+ }
403
402
 
404
- fireCustomEvent(self, "monster-popper-open", {
405
- self,
406
- });
403
+ fireCustomEvent(self, "monster-popper-open", {
404
+ self,
405
+ });
407
406
 
408
- self[popperElementSymbol].style.visibility = "hidden";
409
- self[popperElementSymbol].style.display = STYLE_DISPLAY_MODE_BLOCK;
407
+ self[popperElementSymbol].style.visibility = "hidden";
408
+ self[popperElementSymbol].style.display = STYLE_DISPLAY_MODE_BLOCK;
410
409
 
411
- addAttributeToken(self[controlElementSymbol], "class", "open");
412
- updatePopper.call(self);
410
+ addAttributeToken(self[controlElementSymbol], "class", "open");
411
+ updatePopper.call(self);
413
412
 
414
- setTimeout(() => {
415
- fireCustomEvent(self, "monster-popper-opened", {
416
- self,
417
- });
418
- }, 0);
413
+ setTimeout(() => {
414
+ fireCustomEvent(self, "monster-popper-opened", {
415
+ self,
416
+ });
417
+ }, 0);
419
418
  }
420
419
 
421
420
  /**
422
421
  * @private
423
422
  */
424
423
  function updatePopper() {
425
- if (this[popperElementSymbol].style.display !== STYLE_DISPLAY_MODE_BLOCK) {
426
- return;
427
- }
428
-
429
- if (this.getOption("disabled", false) === true) {
430
- return;
431
- }
432
-
433
- positionPopper.call(
434
- this,
435
- this[controlElementSymbol],
436
- this[popperElementSymbol],
437
- this.getOption("popper", {}),
438
- );
424
+ if (this[popperElementSymbol].style.display !== STYLE_DISPLAY_MODE_BLOCK) {
425
+ return;
426
+ }
427
+
428
+ if (this.getOption("disabled", false) === true) {
429
+ return;
430
+ }
431
+
432
+ positionPopper.call(
433
+ this,
434
+ this[controlElementSymbol],
435
+ this[popperElementSymbol],
436
+ this.getOption("popper", {}),
437
+ );
439
438
  }
440
439
 
441
440
  /**
@@ -443,19 +442,19 @@ function updatePopper() {
443
442
  * @return {Popper}
444
443
  */
445
444
  function initControlReferences() {
446
- this[controlElementSymbol] = this.shadowRoot.querySelector(
447
- `[${ATTRIBUTE_ROLE}=control]`,
448
- );
449
- this[buttonElementSymbol] = this.shadowRoot.querySelector(
450
- `[${ATTRIBUTE_ROLE}=button]`,
451
- );
452
- this[popperElementSymbol] = this.shadowRoot.querySelector(
453
- `[${ATTRIBUTE_ROLE}=popper]`,
454
- );
455
- this[arrowElementSymbol] = this.shadowRoot.querySelector(
456
- `[${ATTRIBUTE_ROLE}=arrow]`,
457
- );
458
- return this;
445
+ this[controlElementSymbol] = this.shadowRoot.querySelector(
446
+ `[${ATTRIBUTE_ROLE}=control]`,
447
+ );
448
+ this[buttonElementSymbol] = this.shadowRoot.querySelector(
449
+ `[${ATTRIBUTE_ROLE}=button]`,
450
+ );
451
+ this[popperElementSymbol] = this.shadowRoot.querySelector(
452
+ `[${ATTRIBUTE_ROLE}=popper]`,
453
+ );
454
+ this[arrowElementSymbol] = this.shadowRoot.querySelector(
455
+ `[${ATTRIBUTE_ROLE}=arrow]`,
456
+ );
457
+ return this;
459
458
  }
460
459
 
461
460
  /**
@@ -463,8 +462,8 @@ function initControlReferences() {
463
462
  * @return {string}
464
463
  */
465
464
  function getTemplate() {
466
- // language=HTML
467
- return `
465
+ // language=HTML
466
+ return `
468
467
  <div data-monster-role="control" part="control">
469
468
  <slot name="button" data-monster-role="button"></slot>
470
469