@schukai/monster 4.43.5 → 4.43.6

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.
@@ -13,20 +13,20 @@
13
13
  */
14
14
 
15
15
  import {
16
- CustomElement,
17
- getSlottedElements,
18
- registerCustomElement,
19
- assembleMethodSymbol,
16
+ CustomElement,
17
+ getSlottedElements,
18
+ registerCustomElement,
19
+ assembleMethodSymbol,
20
20
  } from "../../dom/customelement.mjs";
21
21
  import { DeadMansSwitch } from "../../util/deadmansswitch.mjs";
22
22
  import { SiteNavigationStyleSheet } from "./stylesheet/site-navigation.mjs";
23
23
  import {
24
- computePosition,
25
- autoUpdate,
26
- flip,
27
- shift,
28
- offset,
29
- size,
24
+ computePosition,
25
+ autoUpdate,
26
+ flip,
27
+ shift,
28
+ offset,
29
+ size,
30
30
  } from "@floating-ui/dom";
31
31
  import { fireCustomEvent } from "../../dom/events.mjs";
32
32
 
@@ -64,57 +64,57 @@ const hamburgerCloseButtonSymbol = Symbol("hamburgerCloseButton");
64
64
  * @fires monster-submenu-hide - Fired when a submenu is hidden. The event detail contains `{context, trigger, submenu, level}`.
65
65
  */
66
66
  class SiteNavigation extends CustomElement {
67
- static get [instanceSymbol]() {
68
- return Symbol.for("@schukai/monster/components/navigation/site@@instance");
69
- }
70
-
71
- /**
72
- * Configuration options for the SiteNavigation component.
73
- * @see {@link https://monsterjs.org/en/doc/#configurate-a-monster-control}
74
- *
75
- * To set these options via an HTML tag, use the `data-monster-options` attribute.
76
- * The individual configuration values are detailed in the table below.
77
- *
78
- * @property {Object} templates - Template definitions.
79
- * @property {string} templates.main - The main HTML template for the component.
80
- * @property {string} interactionModel="auto" - Defines the interaction with submenus. Possible values: `auto`, `click`, `hover`. With `auto`, `hover` is used on desktop and `click` is used in the hamburger menu.
81
- * @property {Object} features - Container for additional feature flags.
82
- * @property {boolean} features.resetOnClose=true - If `true`, all open submenus within the hamburger menu will be reset when it is closed.
83
- */
84
- get defaults() {
85
- return Object.assign({}, super.defaults, {
86
- templates: { main: getTemplate() },
87
- interactionModel: "auto", // 'auto', 'click', 'hover'
88
- features: {
89
- resetOnClose: true,
90
- },
91
- });
92
- }
93
-
94
- [assembleMethodSymbol]() {
95
- super[assembleMethodSymbol]();
96
- initControlReferences.call(this);
97
- initEventHandler.call(this);
98
- }
99
-
100
- static getCSSStyleSheet() {
101
- return [SiteNavigationStyleSheet];
102
- }
103
-
104
- static getTag() {
105
- return "monster-site-navigation";
106
- }
107
-
108
- connectedCallback() {
109
- super.connectedCallback();
110
- attachResizeObserver.call(this);
111
- setTimeout(() => populateTabs.call(this), 0);
112
- }
113
-
114
- disconnectedCallback() {
115
- super.disconnectedCallback();
116
- detachResizeObserver.call(this);
117
- }
67
+ static get [instanceSymbol]() {
68
+ return Symbol.for("@schukai/monster/components/navigation/site@@instance");
69
+ }
70
+
71
+ /**
72
+ * Configuration options for the SiteNavigation component.
73
+ * @see {@link https://monsterjs.org/en/doc/#configurate-a-monster-control}
74
+ *
75
+ * To set these options via an HTML tag, use the `data-monster-options` attribute.
76
+ * The individual configuration values are detailed in the table below.
77
+ *
78
+ * @property {Object} templates - Template definitions.
79
+ * @property {string} templates.main - The main HTML template for the component.
80
+ * @property {string} interactionModel="auto" - Defines the interaction with submenus. Possible values: `auto`, `click`, `hover`. With `auto`, `hover` is used on desktop and `click` is used in the hamburger menu.
81
+ * @property {Object} features - Container for additional feature flags.
82
+ * @property {boolean} features.resetOnClose=true - If `true`, all open submenus within the hamburger menu will be reset when it is closed.
83
+ */
84
+ get defaults() {
85
+ return Object.assign({}, super.defaults, {
86
+ templates: { main: getTemplate() },
87
+ interactionModel: "auto", // 'auto', 'click', 'hover'
88
+ features: {
89
+ resetOnClose: true,
90
+ },
91
+ });
92
+ }
93
+
94
+ [assembleMethodSymbol]() {
95
+ super[assembleMethodSymbol]();
96
+ initControlReferences.call(this);
97
+ initEventHandler.call(this);
98
+ }
99
+
100
+ static getCSSStyleSheet() {
101
+ return [SiteNavigationStyleSheet];
102
+ }
103
+
104
+ static getTag() {
105
+ return "monster-site-navigation";
106
+ }
107
+
108
+ connectedCallback() {
109
+ super.connectedCallback();
110
+ attachResizeObserver.call(this);
111
+ setTimeout(() => populateTabs.call(this), 0);
112
+ }
113
+
114
+ disconnectedCallback() {
115
+ super.disconnectedCallback();
116
+ detachResizeObserver.call(this);
117
+ }
118
118
  }
119
119
 
120
120
  /**
@@ -123,22 +123,22 @@ class SiteNavigation extends CustomElement {
123
123
  * @this {SiteNavigation}
124
124
  */
125
125
  function initControlReferences() {
126
- if (!this.shadowRoot) throw new Error("Component requires a shadowRoot.");
127
- this[navElementSymbol] = this.shadowRoot.querySelector(
128
- '[data-monster-role="navigation"]',
129
- );
130
- this[visibleElementsSymbol] =
131
- this.shadowRoot.querySelector("#visible-elements");
132
- this[hiddenElementsSymbol] =
133
- this.shadowRoot.querySelector("#hidden-elements");
134
- this[hamburgerButtonSymbol] =
135
- this.shadowRoot.querySelector("#hamburger-button");
136
- this[hamburgerNavSymbol] = this.shadowRoot.querySelector(
137
- '[data-monster-role="hamburger-nav"]',
138
- );
139
- this[hamburgerCloseButtonSymbol] = this.shadowRoot.querySelector(
140
- '[part="hamburger-close-button"]',
141
- );
126
+ if (!this.shadowRoot) throw new Error("Component requires a shadowRoot.");
127
+ this[navElementSymbol] = this.shadowRoot.querySelector(
128
+ '[data-monster-role="navigation"]',
129
+ );
130
+ this[visibleElementsSymbol] =
131
+ this.shadowRoot.querySelector("#visible-elements");
132
+ this[hiddenElementsSymbol] =
133
+ this.shadowRoot.querySelector("#hidden-elements");
134
+ this[hamburgerButtonSymbol] =
135
+ this.shadowRoot.querySelector("#hamburger-button");
136
+ this[hamburgerNavSymbol] = this.shadowRoot.querySelector(
137
+ '[data-monster-role="hamburger-nav"]',
138
+ );
139
+ this[hamburgerCloseButtonSymbol] = this.shadowRoot.querySelector(
140
+ '[part="hamburger-close-button"]',
141
+ );
142
142
  }
143
143
 
144
144
  /**
@@ -147,107 +147,107 @@ function initControlReferences() {
147
147
  * @this {SiteNavigation}
148
148
  */
149
149
  function initEventHandler() {
150
- if (!this.shadowRoot) throw new Error("Component requires a shadowRoot.");
151
-
152
- const hamburgerButton = this[hamburgerButtonSymbol];
153
- const hamburgerNav = this[hamburgerNavSymbol];
154
- const hamburgerCloseButton = this[hamburgerCloseButtonSymbol];
155
- let cleanup;
156
-
157
- if (!hamburgerButton || !hamburgerNav || !hamburgerCloseButton) return;
158
-
159
- const handleOutsideClick = (event) => {
160
- if (
161
- !hamburgerButton.contains(event.target) &&
162
- !hamburgerNav.contains(event.target)
163
- ) {
164
- hideMenu();
165
- }
166
- };
167
-
168
- const hideMenu = () => {
169
- hamburgerNav.style.display = "none";
170
- document.body.classList.remove("monster-navigation-open");
171
-
172
- fireCustomEvent(this, "monster-hamburger-hide", {
173
- button: hamburgerButton,
174
- menu: hamburgerNav,
175
- });
176
-
177
- if (this.getOption("features.resetOnClose") === true) {
178
- this[hiddenElementsSymbol]
179
- .querySelectorAll(".is-open")
180
- .forEach((submenu) => submenu.classList.remove("is-open"));
181
- }
182
-
183
- if (cleanup) {
184
- cleanup();
185
- cleanup = undefined;
186
- }
187
- document.removeEventListener("click", handleOutsideClick);
188
- };
189
-
190
- this[hideHamburgerMenuSymbol] = hideMenu;
191
-
192
- const showMenu = () => {
193
- this[activeSubmenuHiderSymbol]?.();
194
- hamburgerNav.style.display = "block";
195
- document.body.classList.add("monster-navigation-open");
196
-
197
- fireCustomEvent(this, "monster-hamburger-show", {
198
- button: hamburgerButton,
199
- menu: hamburgerNav,
200
- });
201
-
202
- cleanup = autoUpdate(hamburgerButton, hamburgerNav, () => {
203
- // Desktop view where the hamburger menu is a dropdown
204
- if (window.innerWidth > 768) {
205
- computePosition(hamburgerButton, hamburgerNav, {
206
- placement: "bottom-end",
207
- strategy: "fixed",
208
- middleware: [
209
- offset(8),
210
- flip(),
211
- shift({ padding: 8 }),
212
- size({
213
- apply: ({ availableHeight, elements }) => {
214
- Object.assign(elements.floating.style, {
215
- maxHeight: `${availableHeight}px`,
216
- overflowY: "auto",
217
- });
218
- },
219
- padding: 8,
220
- }),
221
- ],
222
- }).then(({ x, y, strategy }) => {
223
- Object.assign(hamburgerNav.style, {
224
- position: strategy,
225
- left: `${x}px`,
226
- top: `${y}px`,
227
- });
228
- });
229
- } else {
230
- // Mobile view (fullscreen overlay), position is handled by CSS
231
- Object.assign(hamburgerNav.style, { position: "", left: "", top: "" });
232
- }
233
- });
234
- setTimeout(() => document.addEventListener("click", handleOutsideClick), 0);
235
- };
236
-
237
- hamburgerButton.addEventListener("click", (event) => {
238
- event.stopPropagation();
239
- const isVisible = hamburgerNav.style.display === "block";
240
- if (isVisible) {
241
- hideMenu();
242
- } else {
243
- showMenu();
244
- }
245
- });
246
-
247
- hamburgerCloseButton.addEventListener("click", (event) => {
248
- event.stopPropagation();
249
- hideMenu();
250
- });
150
+ if (!this.shadowRoot) throw new Error("Component requires a shadowRoot.");
151
+
152
+ const hamburgerButton = this[hamburgerButtonSymbol];
153
+ const hamburgerNav = this[hamburgerNavSymbol];
154
+ const hamburgerCloseButton = this[hamburgerCloseButtonSymbol];
155
+ let cleanup;
156
+
157
+ if (!hamburgerButton || !hamburgerNav || !hamburgerCloseButton) return;
158
+
159
+ const handleOutsideClick = (event) => {
160
+ if (
161
+ !hamburgerButton.contains(event.target) &&
162
+ !hamburgerNav.contains(event.target)
163
+ ) {
164
+ hideMenu();
165
+ }
166
+ };
167
+
168
+ const hideMenu = () => {
169
+ hamburgerNav.style.display = "none";
170
+ document.body.classList.remove("monster-navigation-open");
171
+
172
+ fireCustomEvent(this, "monster-hamburger-hide", {
173
+ button: hamburgerButton,
174
+ menu: hamburgerNav,
175
+ });
176
+
177
+ if (this.getOption("features.resetOnClose") === true) {
178
+ this[hiddenElementsSymbol]
179
+ .querySelectorAll(".is-open")
180
+ .forEach((submenu) => submenu.classList.remove("is-open"));
181
+ }
182
+
183
+ if (cleanup) {
184
+ cleanup();
185
+ cleanup = undefined;
186
+ }
187
+ document.removeEventListener("click", handleOutsideClick);
188
+ };
189
+
190
+ this[hideHamburgerMenuSymbol] = hideMenu;
191
+
192
+ const showMenu = () => {
193
+ this[activeSubmenuHiderSymbol]?.();
194
+ hamburgerNav.style.display = "block";
195
+ document.body.classList.add("monster-navigation-open");
196
+
197
+ fireCustomEvent(this, "monster-hamburger-show", {
198
+ button: hamburgerButton,
199
+ menu: hamburgerNav,
200
+ });
201
+
202
+ cleanup = autoUpdate(hamburgerButton, hamburgerNav, () => {
203
+ // Desktop view where the hamburger menu is a dropdown
204
+ if (window.innerWidth > 768) {
205
+ computePosition(hamburgerButton, hamburgerNav, {
206
+ placement: "bottom-end",
207
+ strategy: "fixed",
208
+ middleware: [
209
+ offset(8),
210
+ flip(),
211
+ shift({ padding: 8 }),
212
+ size({
213
+ apply: ({ availableHeight, elements }) => {
214
+ Object.assign(elements.floating.style, {
215
+ maxHeight: `${availableHeight}px`,
216
+ overflowY: "auto",
217
+ });
218
+ },
219
+ padding: 8,
220
+ }),
221
+ ],
222
+ }).then(({ x, y, strategy }) => {
223
+ Object.assign(hamburgerNav.style, {
224
+ position: strategy,
225
+ left: `${x}px`,
226
+ top: `${y}px`,
227
+ });
228
+ });
229
+ } else {
230
+ // Mobile view (fullscreen overlay), position is handled by CSS
231
+ Object.assign(hamburgerNav.style, { position: "", left: "", top: "" });
232
+ }
233
+ });
234
+ setTimeout(() => document.addEventListener("click", handleOutsideClick), 0);
235
+ };
236
+
237
+ hamburgerButton.addEventListener("click", (event) => {
238
+ event.stopPropagation();
239
+ const isVisible = hamburgerNav.style.display === "block";
240
+ if (isVisible) {
241
+ hideMenu();
242
+ } else {
243
+ showMenu();
244
+ }
245
+ });
246
+
247
+ hamburgerCloseButton.addEventListener("click", (event) => {
248
+ event.stopPropagation();
249
+ hideMenu();
250
+ });
251
251
  }
252
252
 
253
253
  /**
@@ -257,20 +257,20 @@ function initEventHandler() {
257
257
  * @this {SiteNavigation}
258
258
  */
259
259
  function attachResizeObserver() {
260
- this[resizeObserverSymbol] = new ResizeObserver(() => {
261
- if (this[timerCallbackSymbol] instanceof DeadMansSwitch) {
262
- try {
263
- this[timerCallbackSymbol].touch();
264
- return;
265
- } catch (e) {
266
- delete this[timerCallbackSymbol];
267
- }
268
- }
269
- this[timerCallbackSymbol] = new DeadMansSwitch(200, () =>
270
- populateTabs.call(this),
271
- );
272
- });
273
- this[resizeObserverSymbol].observe(this[navElementSymbol]);
260
+ this[resizeObserverSymbol] = new ResizeObserver(() => {
261
+ if (this[timerCallbackSymbol] instanceof DeadMansSwitch) {
262
+ try {
263
+ this[timerCallbackSymbol].touch();
264
+ return;
265
+ } catch (e) {
266
+ delete this[timerCallbackSymbol];
267
+ }
268
+ }
269
+ this[timerCallbackSymbol] = new DeadMansSwitch(200, () =>
270
+ populateTabs.call(this),
271
+ );
272
+ });
273
+ this[resizeObserverSymbol].observe(this[navElementSymbol]);
274
274
  }
275
275
 
276
276
  /**
@@ -279,10 +279,10 @@ function attachResizeObserver() {
279
279
  * @this {SiteNavigation}
280
280
  */
281
281
  function detachResizeObserver() {
282
- if (this[resizeObserverSymbol] instanceof ResizeObserver) {
283
- this[resizeObserverSymbol].disconnect();
284
- delete this[resizeObserverSymbol];
285
- }
282
+ if (this[resizeObserverSymbol] instanceof ResizeObserver) {
283
+ this[resizeObserverSymbol].disconnect();
284
+ delete this[resizeObserverSymbol];
285
+ }
286
286
  }
287
287
 
288
288
  /**
@@ -295,167 +295,167 @@ function detachResizeObserver() {
295
295
  * @param {number} level The nesting level of the submenu (starts at 1).
296
296
  */
297
297
  function setupSubmenu(parentLi, context = "visible", level = 1) {
298
- const submenu = parentLi.querySelector(
299
- ":scope > ul, :scope > div[part='mega-menu']",
300
- );
301
- if (!submenu) return;
302
-
303
- if (submenu.tagName === "UL") {
304
- submenu.setAttribute("part", "submenu");
305
- }
306
-
307
- const interaction = this.getOption("interactionModel", "auto");
308
- const useHover =
309
- interaction === "hover" ||
310
- (interaction === "auto" && context === "visible");
311
-
312
- if (useHover) {
313
- const component = this;
314
- let cleanup;
315
- let hideTimeout;
316
-
317
- const immediateHide = () => {
318
- submenu.style.display = "none";
319
- submenu
320
- .querySelectorAll(
321
- "ul[style*='display: block'], div[part='mega-menu'][style*='display: block']",
322
- )
323
- .forEach((sub) => {
324
- sub.style.display = "none";
325
- });
326
-
327
- fireCustomEvent(this, "monster-submenu-hide", {
328
- context,
329
- trigger: parentLi,
330
- submenu,
331
- level,
332
- });
333
-
334
- if (cleanup) {
335
- cleanup();
336
- cleanup = null;
337
- }
338
-
339
- if (
340
- level === 1 &&
341
- component[activeSubmenuHiderSymbol] === immediateHide
342
- ) {
343
- component[activeSubmenuHiderSymbol] = null;
344
- }
345
- };
346
-
347
- const show = () => {
348
- component[hideHamburgerMenuSymbol]?.();
349
- clearTimeout(hideTimeout);
350
-
351
- if (level === 1) {
352
- if (
353
- component[activeSubmenuHiderSymbol] &&
354
- component[activeSubmenuHiderSymbol] !== immediateHide
355
- ) {
356
- component[activeSubmenuHiderSymbol]();
357
- }
358
- component[activeSubmenuHiderSymbol] = immediateHide;
359
- } else {
360
- [...parentLi.parentElement.children]
361
- .filter((li) => li !== parentLi)
362
- .forEach((sibling) => {
363
- const siblingSubmenu = sibling.querySelector(
364
- ":scope > ul, :scope > div[part='mega-menu']",
365
- );
366
- if (siblingSubmenu) {
367
- siblingSubmenu.style.display = "none";
368
- }
369
- });
370
- }
371
-
372
- submenu.style.display = "block";
373
- fireCustomEvent(this, "monster-submenu-show", {
374
- context,
375
- trigger: parentLi,
376
- submenu,
377
- level,
378
- });
379
-
380
- if (level === 1 && !cleanup) {
381
- cleanup = autoUpdate(parentLi, submenu, () => {
382
- computePosition(parentLi, submenu, {
383
- placement: "bottom-start",
384
- strategy: "fixed",
385
- middleware: [
386
- offset(8),
387
- flip({ fallbackPlacements: ["top-start"] }),
388
- shift({ padding: 8 }),
389
- size({
390
- apply: ({ availableHeight, elements }) => {
391
- Object.assign(elements.floating.style, {
392
- maxHeight: `${availableHeight}px`,
393
- overflowY: "auto",
394
- });
395
- },
396
- padding: 8,
397
- }),
398
- ],
399
- }).then(({ x, y, strategy }) => {
400
- Object.assign(submenu.style, {
401
- position: strategy,
402
- left: `${x}px`,
403
- top: `${y}px`,
404
- });
405
- });
406
- });
407
- }
408
- };
409
-
410
- const hideWithDelay = () => {
411
- hideTimeout = setTimeout(immediateHide, 200);
412
- };
413
-
414
- parentLi.addEventListener("mouseenter", show);
415
- parentLi.addEventListener("mouseleave", hideWithDelay);
416
- submenu.addEventListener("mouseenter", () => clearTimeout(hideTimeout));
417
- submenu.addEventListener("mouseleave", hideWithDelay);
418
- } else {
419
- // Click behavior
420
- const anchor = parentLi.querySelector(":scope > a");
421
- if (anchor) {
422
- anchor.addEventListener("click", (event) => {
423
- event.preventDefault();
424
- event.stopPropagation();
425
-
426
- if (!submenu.classList.contains("is-open")) {
427
- [...parentLi.parentElement.children]
428
- .filter((li) => li !== parentLi)
429
- .forEach((sibling) => {
430
- const siblingSubmenu = sibling.querySelector(
431
- ":scope > ul, :scope > div[part='mega-menu']",
432
- );
433
- if (siblingSubmenu) {
434
- siblingSubmenu.classList.remove("is-open");
435
- }
436
- });
437
- }
438
-
439
- const isOpen = submenu.classList.toggle("is-open");
440
- const eventName = isOpen
441
- ? "monster-submenu-show"
442
- : "monster-submenu-hide";
443
- fireCustomEvent(this, eventName, {
444
- context,
445
- trigger: parentLi,
446
- submenu,
447
- level,
448
- });
449
- });
450
- }
451
- }
452
-
453
- // Recursive call for nested lists
454
- if (submenu.tagName === "UL") {
455
- submenu
456
- .querySelectorAll(":scope > li")
457
- .forEach((li) => setupSubmenu.call(this, li, context, level + 1));
458
- }
298
+ const submenu = parentLi.querySelector(
299
+ ":scope > ul, :scope > div[part='mega-menu']",
300
+ );
301
+ if (!submenu) return;
302
+
303
+ if (submenu.tagName === "UL") {
304
+ submenu.setAttribute("part", "submenu");
305
+ }
306
+
307
+ const interaction = this.getOption("interactionModel", "auto");
308
+ const useHover =
309
+ interaction === "hover" ||
310
+ (interaction === "auto" && context === "visible");
311
+
312
+ if (useHover) {
313
+ const component = this;
314
+ let cleanup;
315
+ let hideTimeout;
316
+
317
+ const immediateHide = () => {
318
+ submenu.style.display = "none";
319
+ submenu
320
+ .querySelectorAll(
321
+ "ul[style*='display: block'], div[part='mega-menu'][style*='display: block']",
322
+ )
323
+ .forEach((sub) => {
324
+ sub.style.display = "none";
325
+ });
326
+
327
+ fireCustomEvent(this, "monster-submenu-hide", {
328
+ context,
329
+ trigger: parentLi,
330
+ submenu,
331
+ level,
332
+ });
333
+
334
+ if (cleanup) {
335
+ cleanup();
336
+ cleanup = null;
337
+ }
338
+
339
+ if (
340
+ level === 1 &&
341
+ component[activeSubmenuHiderSymbol] === immediateHide
342
+ ) {
343
+ component[activeSubmenuHiderSymbol] = null;
344
+ }
345
+ };
346
+
347
+ const show = () => {
348
+ component[hideHamburgerMenuSymbol]?.();
349
+ clearTimeout(hideTimeout);
350
+
351
+ if (level === 1) {
352
+ if (
353
+ component[activeSubmenuHiderSymbol] &&
354
+ component[activeSubmenuHiderSymbol] !== immediateHide
355
+ ) {
356
+ component[activeSubmenuHiderSymbol]();
357
+ }
358
+ component[activeSubmenuHiderSymbol] = immediateHide;
359
+ } else {
360
+ [...parentLi.parentElement.children]
361
+ .filter((li) => li !== parentLi)
362
+ .forEach((sibling) => {
363
+ const siblingSubmenu = sibling.querySelector(
364
+ ":scope > ul, :scope > div[part='mega-menu']",
365
+ );
366
+ if (siblingSubmenu) {
367
+ siblingSubmenu.style.display = "none";
368
+ }
369
+ });
370
+ }
371
+
372
+ submenu.style.display = "block";
373
+ fireCustomEvent(this, "monster-submenu-show", {
374
+ context,
375
+ trigger: parentLi,
376
+ submenu,
377
+ level,
378
+ });
379
+
380
+ if (level === 1 && !cleanup) {
381
+ cleanup = autoUpdate(parentLi, submenu, () => {
382
+ computePosition(parentLi, submenu, {
383
+ placement: "bottom-start",
384
+ strategy: "fixed",
385
+ middleware: [
386
+ offset(8),
387
+ flip({ fallbackPlacements: ["top-start"] }),
388
+ shift({ padding: 8 }),
389
+ size({
390
+ apply: ({ availableHeight, elements }) => {
391
+ Object.assign(elements.floating.style, {
392
+ maxHeight: `${availableHeight}px`,
393
+ overflowY: "auto",
394
+ });
395
+ },
396
+ padding: 8,
397
+ }),
398
+ ],
399
+ }).then(({ x, y, strategy }) => {
400
+ Object.assign(submenu.style, {
401
+ position: strategy,
402
+ left: `${x}px`,
403
+ top: `${y}px`,
404
+ });
405
+ });
406
+ });
407
+ }
408
+ };
409
+
410
+ const hideWithDelay = () => {
411
+ hideTimeout = setTimeout(immediateHide, 200);
412
+ };
413
+
414
+ parentLi.addEventListener("mouseenter", show);
415
+ parentLi.addEventListener("mouseleave", hideWithDelay);
416
+ submenu.addEventListener("mouseenter", () => clearTimeout(hideTimeout));
417
+ submenu.addEventListener("mouseleave", hideWithDelay);
418
+ } else {
419
+ // Click behavior
420
+ const anchor = parentLi.querySelector(":scope > a");
421
+ if (anchor) {
422
+ anchor.addEventListener("click", (event) => {
423
+ event.preventDefault();
424
+ event.stopPropagation();
425
+
426
+ if (!submenu.classList.contains("is-open")) {
427
+ [...parentLi.parentElement.children]
428
+ .filter((li) => li !== parentLi)
429
+ .forEach((sibling) => {
430
+ const siblingSubmenu = sibling.querySelector(
431
+ ":scope > ul, :scope > div[part='mega-menu']",
432
+ );
433
+ if (siblingSubmenu) {
434
+ siblingSubmenu.classList.remove("is-open");
435
+ }
436
+ });
437
+ }
438
+
439
+ const isOpen = submenu.classList.toggle("is-open");
440
+ const eventName = isOpen
441
+ ? "monster-submenu-show"
442
+ : "monster-submenu-hide";
443
+ fireCustomEvent(this, eventName, {
444
+ context,
445
+ trigger: parentLi,
446
+ submenu,
447
+ level,
448
+ });
449
+ });
450
+ }
451
+ }
452
+
453
+ // Recursive call for nested lists
454
+ if (submenu.tagName === "UL") {
455
+ submenu
456
+ .querySelectorAll(":scope > li")
457
+ .forEach((li) => setupSubmenu.call(this, li, context, level + 1));
458
+ }
459
459
  }
460
460
 
461
461
  /**
@@ -466,20 +466,20 @@ function setupSubmenu(parentLi, context = "visible", level = 1) {
466
466
  * @returns {HTMLLIElement} The cloned and configured list item.
467
467
  */
468
468
  function cloneNavItem(item) {
469
- const liClone = item.cloneNode(true);
470
- const aClone = liClone.querySelector("a");
471
- let navItemPart = "nav-item";
472
- let navLinkPart = "nav-link";
469
+ const liClone = item.cloneNode(true);
470
+ const aClone = liClone.querySelector("a");
471
+ let navItemPart = "nav-item";
472
+ let navLinkPart = "nav-link";
473
473
 
474
- if (item.classList.contains("active")) {
475
- navItemPart += " nav-item-active";
476
- if (aClone) navLinkPart += " nav-link-active";
477
- }
474
+ if (item.classList.contains("active")) {
475
+ navItemPart += " nav-item-active";
476
+ if (aClone) navLinkPart += " nav-link-active";
477
+ }
478
478
 
479
- liClone.setAttribute("part", navItemPart);
480
- if (aClone) aClone.setAttribute("part", navLinkPart);
479
+ liClone.setAttribute("part", navItemPart);
480
+ if (aClone) aClone.setAttribute("part", navLinkPart);
481
481
 
482
- return liClone;
482
+ return liClone;
483
483
  }
484
484
 
485
485
  /**
@@ -489,96 +489,96 @@ function cloneNavItem(item) {
489
489
  * @this {SiteNavigation}
490
490
  */
491
491
  function populateTabs() {
492
- const visibleList = this[visibleElementsSymbol];
493
- const hiddenList = this[hiddenElementsSymbol];
494
- const hamburgerButton = this[hamburgerButtonSymbol];
495
- const hamburgerNav = this[hamburgerNavSymbol];
496
- const topLevelUl = [...getSlottedElements.call(this, "ul")].find(
497
- (ul) => ul.parentElement === this,
498
- );
499
-
500
- if (!topLevelUl) {
501
- visibleList.style.visibility = "visible";
502
- hamburgerButton.style.display = "none";
503
- return;
504
- }
505
-
506
- const sourceItems = Array.from(topLevelUl.children).filter(
507
- (item) => item.tagName === "LI",
508
- );
509
-
510
- visibleList.style.visibility = "hidden";
511
- hamburgerButton.style.display = "none";
512
- hamburgerNav.style.display = "none";
513
- visibleList.innerHTML = "";
514
- hiddenList.innerHTML = "";
515
-
516
- const originalDisplay = hamburgerButton.style.display;
517
- hamburgerButton.style.visibility = "hidden";
518
- hamburgerButton.style.display = "flex";
519
- const hamburgerWidth = hamburgerButton.offsetWidth;
520
- hamburgerButton.style.display = originalDisplay;
521
- hamburgerButton.style.visibility = "visible";
522
-
523
- const navWidth = this[navElementSymbol].clientWidth;
524
- if (navWidth === 0) {
525
- visibleList.style.visibility = "visible";
526
- return;
527
- }
528
-
529
- const measurementList = visibleList.cloneNode(true);
530
- Object.assign(measurementList.style, {
531
- position: "absolute",
532
- left: "0",
533
- top: "0",
534
- width: "auto",
535
- visibility: "hidden",
536
- });
537
- this.shadowRoot.appendChild(measurementList);
538
-
539
- const itemsToMove = [];
540
- const availableWidthForTabs = navWidth - hamburgerWidth;
541
-
542
- for (let i = 0; i < sourceItems.length; i++) {
543
- const item = sourceItems[i];
544
- const itemClone = item.cloneNode(true);
545
- const submenu = itemClone.querySelector("ul, div[part='mega-menu']");
546
- if (submenu) submenu.style.display = "none";
547
-
548
- measurementList.appendChild(itemClone);
549
- const isLastItem = i === sourceItems.length - 1;
550
- const effectiveMaxWidth = isLastItem ? navWidth : availableWidthForTabs;
551
-
552
- if (measurementList.scrollWidth > effectiveMaxWidth) {
553
- break;
554
- } else {
555
- itemsToMove.push(item);
556
- }
557
- }
558
- this.shadowRoot.removeChild(measurementList);
559
-
560
- const visibleItems = itemsToMove;
561
- const hiddenItems = sourceItems.slice(visibleItems.length);
562
-
563
- if (visibleItems.length > 0) {
564
- const clonedVisibleItems = visibleItems.map(cloneNavItem);
565
- visibleList.append(...clonedVisibleItems);
566
- visibleList
567
- .querySelectorAll(":scope > li")
568
- .forEach((li) => setupSubmenu.call(this, li, "visible", 1));
569
- }
570
-
571
- if (hiddenItems.length > 0) {
572
- const clonedHiddenItems = hiddenItems.map(cloneNavItem);
573
- hiddenList.append(...clonedHiddenItems);
574
- hamburgerButton.style.display = "flex";
575
- hiddenList
576
- .querySelectorAll(":scope > li")
577
- .forEach((li) => setupSubmenu.call(this, li, "hidden", 1));
578
- }
579
-
580
- visibleList.style.visibility = "visible";
581
- fireCustomEvent(this, "monster-layout-change", { visibleItems, hiddenItems });
492
+ const visibleList = this[visibleElementsSymbol];
493
+ const hiddenList = this[hiddenElementsSymbol];
494
+ const hamburgerButton = this[hamburgerButtonSymbol];
495
+ const hamburgerNav = this[hamburgerNavSymbol];
496
+ const topLevelUl = [...getSlottedElements.call(this, "ul")].find(
497
+ (ul) => ul.parentElement === this,
498
+ );
499
+
500
+ if (!topLevelUl) {
501
+ visibleList.style.visibility = "visible";
502
+ hamburgerButton.style.display = "none";
503
+ return;
504
+ }
505
+
506
+ const sourceItems = Array.from(topLevelUl.children).filter(
507
+ (item) => item.tagName === "LI",
508
+ );
509
+
510
+ visibleList.style.visibility = "hidden";
511
+ hamburgerButton.style.display = "none";
512
+ hamburgerNav.style.display = "none";
513
+ visibleList.innerHTML = "";
514
+ hiddenList.innerHTML = "";
515
+
516
+ const originalDisplay = hamburgerButton.style.display;
517
+ hamburgerButton.style.visibility = "hidden";
518
+ hamburgerButton.style.display = "flex";
519
+ const hamburgerWidth = hamburgerButton.offsetWidth;
520
+ hamburgerButton.style.display = originalDisplay;
521
+ hamburgerButton.style.visibility = "visible";
522
+
523
+ const navWidth = this[navElementSymbol].clientWidth;
524
+ if (navWidth === 0) {
525
+ visibleList.style.visibility = "visible";
526
+ return;
527
+ }
528
+
529
+ const measurementList = visibleList.cloneNode(true);
530
+ Object.assign(measurementList.style, {
531
+ position: "absolute",
532
+ left: "0",
533
+ top: "0",
534
+ width: "auto",
535
+ visibility: "hidden",
536
+ });
537
+ this.shadowRoot.appendChild(measurementList);
538
+
539
+ const itemsToMove = [];
540
+ const availableWidthForTabs = navWidth - hamburgerWidth;
541
+
542
+ for (let i = 0; i < sourceItems.length; i++) {
543
+ const item = sourceItems[i];
544
+ const itemClone = item.cloneNode(true);
545
+ const submenu = itemClone.querySelector("ul, div[part='mega-menu']");
546
+ if (submenu) submenu.style.display = "none";
547
+
548
+ measurementList.appendChild(itemClone);
549
+ const isLastItem = i === sourceItems.length - 1;
550
+ const effectiveMaxWidth = isLastItem ? navWidth : availableWidthForTabs;
551
+
552
+ if (measurementList.scrollWidth > effectiveMaxWidth) {
553
+ break;
554
+ } else {
555
+ itemsToMove.push(item);
556
+ }
557
+ }
558
+ this.shadowRoot.removeChild(measurementList);
559
+
560
+ const visibleItems = itemsToMove;
561
+ const hiddenItems = sourceItems.slice(visibleItems.length);
562
+
563
+ if (visibleItems.length > 0) {
564
+ const clonedVisibleItems = visibleItems.map(cloneNavItem);
565
+ visibleList.append(...clonedVisibleItems);
566
+ visibleList
567
+ .querySelectorAll(":scope > li")
568
+ .forEach((li) => setupSubmenu.call(this, li, "visible", 1));
569
+ }
570
+
571
+ if (hiddenItems.length > 0) {
572
+ const clonedHiddenItems = hiddenItems.map(cloneNavItem);
573
+ hiddenList.append(...clonedHiddenItems);
574
+ hamburgerButton.style.display = "flex";
575
+ hiddenList
576
+ .querySelectorAll(":scope > li")
577
+ .forEach((li) => setupSubmenu.call(this, li, "hidden", 1));
578
+ }
579
+
580
+ visibleList.style.visibility = "visible";
581
+ fireCustomEvent(this, "monster-layout-change", { visibleItems, hiddenItems });
582
582
  }
583
583
 
584
584
  /**
@@ -588,7 +588,7 @@ function populateTabs() {
588
588
  * @returns {string} The combined string.
589
589
  */
590
590
  function html(strings) {
591
- return strings.join("");
591
+ return strings.join("");
592
592
  }
593
593
 
594
594
  /**
@@ -597,7 +597,7 @@ function html(strings) {
597
597
  * @returns {string} The HTML template string.
598
598
  */
599
599
  function getTemplate() {
600
- return html`<div data-monster-role="control" part="control">
600
+ return html`<div data-monster-role="control" part="control">
601
601
  <nav data-monster-role="navigation" role="navigation" part="nav">
602
602
  <ul id="visible-elements" part="visible-list"></ul>
603
603
  </nav>