@schukai/monster 5.2.5 → 5.2.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.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,22 @@
2
2
 
3
3
 
4
4
 
5
+ ## [5.2.7] - 2026-11-29
6
+
7
+ ### Bug Fixes
8
+
9
+ - **tree-menu:** restore programmatic entry selection ([#613](https://gitlab.schukai.com/oss/libraries/javascript/monster/issues/613))
10
+
11
+
12
+
13
+ ## [5.2.6] - 2026-11-17
14
+
15
+ ### Bug Fixes
16
+
17
+ - **popper:** let nested horizontal overlays escape scrolling ([#612](https://gitlab.schukai.com/oss/libraries/javascript/monster/issues/612))
18
+
19
+
20
+
5
21
  ## [5.2.5] - 2026-11-17
6
22
 
7
23
  ### Bug Fixes
package/package.json CHANGED
@@ -1 +1 @@
1
- {"author":"Volker Schukai","dependencies":{"@floating-ui/dom":"^1.7.6"},"description":"Monster is a simple library for creating fast, robust and lightweight websites.","exports":{".":"./source/monster.mjs","./CHANGELOG.md":"./CHANGELOG.md","./LICENSE":"./LICENSE","./README.md":"./README.md","./documentation/migrations/monster-5-options.md":"./documentation/migrations/monster-5-options.md","./package.json":"./package.json","./source/*":"./source/*","./test/*":"./test/*"},"files":["source","test/cases","test/util","documentation/migrations/monster-5-options.md","CHANGELOG.md"],"homepage":"https://monsterjs.org/","keywords":["framework","web","dom","css","sass","mobile-first","app","front-end","templates","schukai","core","shopcloud","alvine","monster","buildmap","stack","observer","observable","uuid","node","nodelist","css-in-js","logger","log","theme"],"license":"AGPL 3.0","main":"source/monster.mjs","module":"source/monster.mjs","name":"@schukai/monster","repository":{"type":"git","url":"https://gitlab.schukai.com/oss/libraries/javascript/monster.git"},"sideEffects":["./source/monster.mjs","./source/components/**","./source/i18n/**","./test/**"],"type":"module","version":"5.2.5"}
1
+ {"author":"Volker Schukai","dependencies":{"@floating-ui/dom":"^1.7.6"},"description":"Monster is a simple library for creating fast, robust and lightweight websites.","exports":{".":"./source/monster.mjs","./CHANGELOG.md":"./CHANGELOG.md","./LICENSE":"./LICENSE","./README.md":"./README.md","./documentation/migrations/monster-5-options.md":"./documentation/migrations/monster-5-options.md","./package.json":"./package.json","./source/*":"./source/*","./test/*":"./test/*"},"files":["source","test/cases","test/util","documentation/migrations/monster-5-options.md","CHANGELOG.md"],"homepage":"https://monsterjs.org/","keywords":["framework","web","dom","css","sass","mobile-first","app","front-end","templates","schukai","core","shopcloud","alvine","monster","buildmap","stack","observer","observable","uuid","node","nodelist","css-in-js","logger","log","theme"],"license":"AGPL 3.0","main":"source/monster.mjs","module":"source/monster.mjs","name":"@schukai/monster","repository":{"type":"git","url":"https://gitlab.schukai.com/oss/libraries/javascript/monster.git"},"sideEffects":["./source/monster.mjs","./source/components/**","./source/i18n/**","./test/**"],"type":"module","version":"5.2.7"}
@@ -265,12 +265,23 @@ function isPositionedPopperOpen(popperElement) {
265
265
  }
266
266
 
267
267
  function normalizePopperConfig(options, controlElement, popperElement) {
268
+ // Keep ordinary content scrollable while implicit nested overlays escape it.
269
+ // Explicit strategies still override this default below.
270
+ const parentContent = resolveParentPopperContentBoundary(
271
+ controlElement,
272
+ popperElement,
273
+ );
274
+ const defaultStrategy =
275
+ parentContent?.dataset.monsterOverflowMode === "horizontal" &&
276
+ isClippingContainer(getComputedStyle(parentContent))
277
+ ? "fixed"
278
+ : "absolute";
268
279
  const config = Object.assign(
269
280
  {},
270
281
  {
271
282
  placement: "top",
272
283
  engine: "floating",
273
- strategy: "absolute",
284
+ strategy: defaultStrategy,
274
285
  adaptiveSize: true,
275
286
  hideWhenReferenceHidden: false,
276
287
  },
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Copyright © Volker Schukai and all contributing authors, {{copyRightYear}}. All rights reserved.
3
+ * Node module: @schukai/monster
4
+ *
5
+ * This source code is licensed under the GNU Affero General Public License version 3 (AGPLv3).
6
+ * The full text of the license can be found at: https://www.gnu.org/licenses/agpl-3.0.en.html
7
+ *
8
+ * For those who do not wish to adhere to the AGPLv3, a commercial license is available.
9
+ * Acquiring a commercial license allows you to use this software without complying with AGPLv3 terms.
10
+ * For more information about purchasing a commercial license, please contact Volker Schukai.
11
+ *
12
+ * SPDX-License-Identifier: AGPL-3.0
13
+ */
14
+
15
+ /**
16
+ * Bind the configured entry interactions and return the event to dispatch
17
+ * for programmatic activation.
18
+ * @private
19
+ */
20
+ export function bindEntryEvents(menu, handler) {
21
+ const types = Object.values(menu.getOption("toggleEventType", ["click"]));
22
+ for (const type of types) {
23
+ menu.shadowRoot.addEventListener(type, handler);
24
+ }
25
+ return types.includes("click") ? "click" : types[0];
26
+ }
@@ -24,12 +24,16 @@ import {
24
24
  CustomElement,
25
25
  registerCustomElement,
26
26
  } from "../../dom/customelement.mjs";
27
- import { findTargetElementFromEvent } from "../../dom/events.mjs";
28
- import { fireCustomEvent } from "../../dom/events.mjs";
27
+ import {
28
+ findTargetElementFromEvent,
29
+ fireCustomEvent,
30
+ fireEvent,
31
+ } from "../../dom/events.mjs";
29
32
  import { isFunction, isString } from "../../types/is.mjs";
30
33
  import { ID } from "../../types/id.mjs";
31
34
  import { CommonStyleSheet } from "../stylesheet/common.mjs";
32
35
  import { TreeMenuStyleSheet } from "./stylesheet/tree-menu.mjs";
36
+ import { bindEntryEvents } from "./entry-events.mjs";
33
37
  import { ATTRIBUTE_INTEND } from "./../constants.mjs";
34
38
 
35
39
  export { HtmlTreeMenu };
@@ -44,7 +48,7 @@ const entryIndexSymbol = Symbol("entryIndex");
44
48
  * @private
45
49
  * @type {symbol}
46
50
  */
47
- const openEntryEventHandlerSymbol = Symbol("openEntryEventHandler");
51
+ const entryEventTypeSymbol = Symbol("entryEventType");
48
52
 
49
53
  /**
50
54
  * HtmlTreeMenu
@@ -162,33 +166,20 @@ class HtmlTreeMenu extends CustomElement {
162
166
  * @return {void}
163
167
  */
164
168
  selectEntry(value) {
165
- this.shadowRoot
166
- .querySelectorAll("[data-monster-role=entry]")
167
- .forEach((entry) => {
168
- entry.classList.remove("selected");
169
- });
170
-
171
- value = String(value);
172
- const index = findEntryIndex.call(this, value);
173
- if (index === -1) {
169
+ const match = this.findEntry(value);
170
+ if (!match?.node) {
174
171
  return;
175
172
  }
176
173
 
177
- const currentNode = this.shadowRoot.querySelector(
178
- "[data-monster-insert-reference=entries-" + index + "]",
179
- );
180
-
181
- if (!currentNode) {
182
- return;
183
- }
184
-
185
- const allowParentSelect = this.getOption("features.selectParents") === true;
186
- if (currentEntry?.["has-children"] === true && allowParentSelect) {
187
- applySelection.call(this, currentEntry, Number(index), currentNode);
188
- return;
174
+ const { entry, index, node } = match;
175
+ if (
176
+ entry["has-children"] === true &&
177
+ this.getOption("features.selectParents") === true
178
+ ) {
179
+ applySelection.call(this, entry, index, node);
180
+ } else if (this[entryEventTypeSymbol]) {
181
+ fireEvent(node, this[entryEventTypeSymbol]);
189
182
  }
190
-
191
- currentNode.click();
192
183
  }
193
184
 
194
185
  /**
@@ -317,7 +308,7 @@ class HtmlTreeMenu extends CustomElement {
317
308
  * @private
318
309
  */
319
310
  function initEventHandler() {
320
- this[openEntryEventHandlerSymbol] = (event) => {
311
+ this[entryEventTypeSymbol] = bindEntryEvents(this, (event) => {
321
312
  const container = findTargetElementFromEvent(
322
313
  event,
323
314
  ATTRIBUTE_ROLE,
@@ -399,12 +390,7 @@ function initEventHandler() {
399
390
  if (allowParentSelect) {
400
391
  applySelection.call(this, currentEntry, Number(index), container, event);
401
392
  }
402
- };
403
-
404
- const types = this.getOption("toggleEventType", ["click"]);
405
- for (const [, type] of Object.entries(types)) {
406
- this.shadowRoot.addEventListener(type, this[openEntryEventHandlerSymbol]);
407
- }
393
+ });
408
394
  }
409
395
 
410
396
  /**
@@ -569,10 +555,15 @@ function getEntryValue(li) {
569
555
  * @return {number}
570
556
  */
571
557
  function findEntryIndex(value) {
572
- if (this[entryIndexSymbol].has(value)) {
573
- return this[entryIndexSymbol].get(value);
574
- }
575
558
  const entries = this.getOption("entries", []);
559
+ const index = this[entryIndexSymbol]?.get(value);
560
+ if (
561
+ index !== undefined &&
562
+ entries[index] &&
563
+ String(entries[index].value) === value
564
+ ) {
565
+ return index;
566
+ }
576
567
  return entries.findIndex((entry) => String(entry.value) === value);
577
568
  }
578
569
 
@@ -593,8 +584,10 @@ function rebuildEntryIndex() {
593
584
  * @return {HTMLElement|null}
594
585
  */
595
586
  function getEntryNode(index) {
596
- return this.shadowRoot.querySelector(
597
- `[data-monster-insert-reference=entries-${index}]`,
587
+ return (
588
+ this.shadowRoot?.querySelector(
589
+ `[data-monster-insert-reference=entries-${index}]`,
590
+ ) ?? null
598
591
  );
599
592
  }
600
593
 
@@ -42,6 +42,7 @@ import {
42
42
  import { ATTRIBUTE_INTEND } from "./../constants.mjs";
43
43
  import { CommonStyleSheet } from "../stylesheet/common.mjs";
44
44
  import { TreeMenuStyleSheet } from "./stylesheet/tree-menu.mjs";
45
+ import { bindEntryEvents } from "./entry-events.mjs";
45
46
 
46
47
  export { TreeMenu };
47
48
 
@@ -67,7 +68,7 @@ const controlElementSymbol = Symbol("controlElement");
67
68
  * @private
68
69
  * @type {symbol}
69
70
  */
70
- const openEntryEventHandlerSymbol = Symbol("openEntryEventHandler");
71
+ const entryEventTypeSymbol = Symbol("entryEventType");
71
72
 
72
73
  /**
73
74
  * @private
@@ -218,11 +219,10 @@ class TreeMenu extends CustomElement {
218
219
  * @param {string} value
219
220
  */
220
221
  selectEntry(value) {
221
- this.shadowRoot
222
- .querySelectorAll("[data-monster-role=entry]")
223
- .forEach((entry) => {
224
- entry.classList.remove("selected");
225
- });
222
+ const eventType = this[entryEventTypeSymbol];
223
+ if (!eventType) {
224
+ return;
225
+ }
226
226
 
227
227
  value = String(value);
228
228
 
@@ -241,12 +241,11 @@ class TreeMenu extends CustomElement {
241
241
  return;
242
242
  }
243
243
 
244
- currentNode.click();
244
+ fireEvent(currentNode, eventType);
245
245
 
246
246
  let intend = Number.parseInt(currentNode.getAttribute(ATTRIBUTE_INTEND));
247
247
 
248
248
  if (intend > 0) {
249
- const refSet = new Set();
250
249
  let ref = currentNode.previousElementSibling;
251
250
  while (ref?.hasAttribute(ATTRIBUTE_INTEND)) {
252
251
  const i = Number.parseInt(ref.getAttribute(ATTRIBUTE_INTEND));
@@ -256,8 +255,12 @@ class TreeMenu extends CustomElement {
256
255
  }
257
256
 
258
257
  if (i < intend) {
259
- if (ref.getAttribute("data-monster-state") !== "open") {
260
- ref.click();
258
+ const refIndex = ref
259
+ .getAttribute(ATTRIBUTE_UPDATER_INSERT_REFERENCE)
260
+ .split("-")
261
+ .pop();
262
+ if (this.getOption(`entries.${refIndex}.state`) !== "open") {
263
+ fireEvent(ref, eventType);
261
264
  }
262
265
 
263
266
  if (i === 0) {
@@ -325,7 +328,7 @@ function initEventHandler() {
325
328
  });
326
329
  }
327
330
 
328
- this[openEntryEventHandlerSymbol] = (event) => {
331
+ this[entryEventTypeSymbol] = bindEntryEvents(this, (event) => {
329
332
  const container = findTargetElementFromEvent(
330
333
  event,
331
334
  ATTRIBUTE_ROLE,
@@ -447,12 +450,7 @@ function initEventHandler() {
447
450
  if (changed === true) {
448
451
  this.setOption("entries", nextEntries);
449
452
  }
450
- };
451
-
452
- const types = this.getOption("toggleEventType", ["click"]);
453
- for (const [, type] of Object.entries(types)) {
454
- this.shadowRoot.addEventListener(type, this[openEntryEventHandlerSymbol]);
455
- }
453
+ });
456
454
 
457
455
  return this;
458
456
  }
@@ -156,7 +156,7 @@ function getMonsterVersion() {
156
156
  }
157
157
 
158
158
  /** Managed by the release script; keep synchronized with package.json. */
159
- monsterVersion = new Version("5.2.5");
159
+ monsterVersion = new Version("5.2.7");
160
160
 
161
161
  return monsterVersion;
162
162
  }
@@ -11,6 +11,8 @@ let createVisibilityRecoveryConfig;
11
11
  let getFloatingVisibleRatio;
12
12
  let resolveFloatingArrowStaticOffset;
13
13
  let resetAdaptiveFloatingElementSize;
14
+ let openPositionedPopper;
15
+ let closePositionedPopper;
14
16
 
15
17
  describe("form floating-ui boundary resolution", function () {
16
18
  before(function (done) {
@@ -31,6 +33,8 @@ describe("form floating-ui boundary resolution", function () {
31
33
  resolveFloatingArrowStaticOffset =
32
34
  m.resolveFloatingArrowStaticOffset;
33
35
  resetAdaptiveFloatingElementSize = m.resetAdaptiveFloatingElementSize;
36
+ openPositionedPopper = m.openPositionedPopper;
37
+ closePositionedPopper = m.closePositionedPopper;
34
38
  done();
35
39
  })
36
40
  .catch((e) => done(e));
@@ -41,6 +45,50 @@ describe("form floating-ui boundary resolution", function () {
41
45
  mocks.innerHTML = "";
42
46
  });
43
47
 
48
+ for (const [mode, overflow, strategy, expected] of [
49
+ ["horizontal", "auto", undefined, "fixed"],
50
+ ["horizontal", "auto", "absolute", "absolute"],
51
+ ["horizontal", "auto", "fixed", "fixed"],
52
+ ["horizontal", "visible", undefined, "absolute"],
53
+ ["both", "auto", undefined, "absolute"],
54
+ ["visible", "visible", undefined, "absolute"],
55
+ ]) {
56
+ it(`preserves positioning for ${mode}/${overflow}/${strategy ?? "implicit"} (#612)`, () => {
57
+ const parent = document.createElement("div");
58
+ parent.dataset.monsterRole = "popper";
59
+ const content = document.createElement("div");
60
+ content.setAttribute("part", "content");
61
+ content.dataset.monsterOverflowMode = mode;
62
+ content.style.overflow = overflow;
63
+ const reference = document.createElement("button");
64
+ const floating = document.createElement("div");
65
+ parent.append(content);
66
+ content.append(reference, floating);
67
+ document.getElementById("mocks").append(parent);
68
+ const options = strategy ? { strategy } : {};
69
+ openPositionedPopper(reference, floating, options);
70
+ expect(floating.style.position).to.equal(expected);
71
+ expect(options).to.deep.equal(strategy ? { strategy } : {});
72
+ closePositionedPopper(floating);
73
+ });
74
+ }
75
+
76
+ it("resolves horizontal clipping through a slot without changing standalone defaults (#612)", () => {
77
+ const reference = document.createElement("button");
78
+ const floating = document.createElement("div");
79
+ document.getElementById("mocks").append(reference, floating);
80
+ openPositionedPopper(reference, floating, {});
81
+ expect(floating.style.position).to.equal("absolute");
82
+ closePositionedPopper(floating);
83
+ const host = document.createElement("div");
84
+ host.attachShadow({ mode: "open" }).innerHTML = '<div data-monster-role="popper"><div part="content" data-monster-overflow-mode="horizontal" style="overflow:auto"><slot></slot></div></div>';
85
+ host.append(reference, floating);
86
+ document.getElementById("mocks").append(host);
87
+ openPositionedPopper(reference, floating, {});
88
+ expect(floating.style.position).to.equal("fixed");
89
+ closePositionedPopper(floating);
90
+ });
91
+
44
92
  it("should overlap the popper edge by half of the rendered arrow size", function () {
45
93
  expect(resolveFloatingArrowStaticOffset(8)).to.equal(-4);
46
94
  expect(resolveFloatingArrowStaticOffset(0)).to.equal(0);
@@ -0,0 +1,150 @@
1
+ import { expect } from "chai";
2
+ import { initJSDOM } from "../../../util/jsdom.mjs";
3
+
4
+ describe("Tree menu programmatic selection (#613)", () => {
5
+ let menu;
6
+ let selected;
7
+ const frame = () => new Promise((resolve) => requestAnimationFrame(resolve));
8
+ const button = (value) =>
9
+ menu.shadowRoot.querySelector(
10
+ `[data-monster-role=button][value="${value}"]`,
11
+ );
12
+ const marked = () =>
13
+ Array.from(
14
+ menu.shadowRoot.querySelectorAll(".selected [data-monster-role=button]"),
15
+ (node) => node.getAttribute("value"),
16
+ );
17
+
18
+ before(async function () {
19
+ this.timeout(10000);
20
+ await initJSDOM();
21
+ await import("../../../../source/components/tree-menu/html-tree-menu.mjs");
22
+ await import("../../../../source/components/tree-menu/tree-menu.mjs");
23
+ });
24
+ afterEach(() => menu.remove());
25
+
26
+ async function mount(tag, options = {}) {
27
+ menu = document.createElement(tag);
28
+ selected = [];
29
+ if (tag === "monster-html-tree-menu") {
30
+ menu.innerHTML = `<ul>
31
+ <li id="root">Root<ul hidden><li id="one">One</li><li id="two">Two</li></ul></li>
32
+ <li id="link"><a href="#destination">Link</a></li>
33
+ </ul>`;
34
+ } else {
35
+ menu.setOption(
36
+ "entries",
37
+ ["root", "one", "two"].map((value, index) => ({
38
+ value,
39
+ label: value,
40
+ intend: index === 0 ? 0 : 1,
41
+ state: "close",
42
+ visibility: index === 0 ? "visible" : "hidden",
43
+ "has-children": index === 0,
44
+ })),
45
+ );
46
+ }
47
+ menu.setOptions(options);
48
+ menu.setOption("actions.select", (entry) => selected.push(entry.value));
49
+ document.getElementById("mocks").append(menu);
50
+ await frame();
51
+ expect(button("two")).to.exist;
52
+ }
53
+
54
+ for (const tag of ["monster-html-tree-menu", "monster-tree-menu"]) {
55
+ describe(tag, () => {
56
+ it("ignores selection before the menu is mounted", () => {
57
+ menu = document.createElement(tag);
58
+ menu.selectEntry("one");
59
+ });
60
+
61
+ it("selects a leaf once and marks its ancestor", async () => {
62
+ await mount(tag);
63
+ menu.selectEntry("one");
64
+ await frame();
65
+ expect(selected).to.deep.equal(["one"]);
66
+ expect(marked()).to.deep.equal(["root", "one"]);
67
+ });
68
+
69
+ it("keeps the current selection when the target is missing", async () => {
70
+ await mount(tag);
71
+ button("one").click();
72
+ menu.selectEntry("absent");
73
+ expect(marked()).to.deep.equal(["root", "one"]);
74
+ expect(selected).to.deep.equal(["one"]);
75
+ });
76
+
77
+ it("honors a non-click activation configuration", async () => {
78
+ await mount(tag, { toggleEventType: ["dblclick"] });
79
+ button("one").click();
80
+ expect(selected).to.be.empty;
81
+ menu.selectEntry("two");
82
+ expect(selected).to.deep.equal(["two"]);
83
+ });
84
+ });
85
+ }
86
+
87
+ describe("HTML menu", () => {
88
+ it("selects a selectable parent without expanding it", async () => {
89
+ await mount("monster-html-tree-menu", {
90
+ features: { selectParents: true },
91
+ });
92
+ const events = [];
93
+ menu.addEventListener("monster-html-tree-menu-select", ({ detail }) => {
94
+ events.push([detail.entry.value, detail.index]);
95
+ });
96
+ menu.selectEntry("root");
97
+ expect(events).to.deep.equal([["root", 0]]);
98
+ expect(selected).to.deep.equal(["root"]);
99
+ expect(marked()).to.deep.equal(["root"]);
100
+ expect(menu.findEntry("root").entry.state).to.equal("close");
101
+ });
102
+
103
+ it("toggles a parent when parent selection is disabled", async () => {
104
+ await mount("monster-html-tree-menu");
105
+ menu.selectEntry("root");
106
+ expect(menu.findEntry("root").entry.state).to.equal("open");
107
+ menu.selectEntry("root");
108
+ expect(menu.findEntry("root").entry.state).to.equal("close");
109
+ expect(selected).to.be.empty;
110
+ });
111
+
112
+ it("keeps the selection when a link's navigation is canceled", async () => {
113
+ await mount("monster-html-tree-menu");
114
+ button("one").click();
115
+ const navigated = [];
116
+ menu.addEventListener("monster-html-tree-menu-navigate", (event) => {
117
+ navigated.push(event.detail.entry.value);
118
+ event.preventDefault();
119
+ });
120
+ menu.selectEntry("link");
121
+ expect(navigated).to.deep.equal(["link"]);
122
+ expect(selected).to.deep.equal(["one"]);
123
+ expect(marked()).to.deep.equal(["root", "one"]);
124
+ });
125
+
126
+ it("resolves the current entry after reordering the entries option", async () => {
127
+ await mount("monster-html-tree-menu");
128
+ const [root, one, two, link] = menu.getOption("entries");
129
+ menu.setOption("entries", [root, two, one, link]);
130
+ await frame();
131
+ expect(menu.findEntry("one").entry.value).to.equal("one");
132
+ menu.selectEntry("one");
133
+ expect(selected).to.deep.equal(["one"]);
134
+ expect(marked()).to.deep.equal(["root", "one"]);
135
+ });
136
+ });
137
+
138
+ it("keeps TreeMenu ancestors open on consecutive selections before the next render", async () => {
139
+ await mount("monster-tree-menu");
140
+ menu.selectEntry("one");
141
+ menu.selectEntry("two");
142
+ await frame();
143
+ expect(selected).to.deep.equal(["one", "two"]);
144
+ expect(marked()).to.deep.equal(["root", "two"]);
145
+ expect(menu.getOption("entries.0.state")).to.equal("open");
146
+ expect(
147
+ button("two").parentElement.getAttribute("data-monster-visibility"),
148
+ ).to.equal("visible");
149
+ });
150
+ });