@sentropic/design-system-svelte 0.37.2 → 0.39.0

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.
@@ -1,4 +1,5 @@
1
1
  import type { Component } from "svelte";
2
+ import type { SubMenuSide } from "./menu-cascade.js";
2
3
  export type MenuIconProps = {
3
4
  size?: number | string;
4
5
  strokeWidth?: number | string;
@@ -6,6 +7,11 @@ export type MenuIconProps = {
6
7
  class?: string;
7
8
  } & Record<`data-${string}`, unknown>;
8
9
  export type MenuIcon = Component<MenuIconProps> | string;
10
+ export type MenuSubmenuSide = SubMenuSide;
11
+ export interface MenuSelectDetail {
12
+ path: string[];
13
+ item: MenuActionItem;
14
+ }
9
15
  export interface MenuActionItem {
10
16
  kind?: "item";
11
17
  label: string;
@@ -13,6 +19,8 @@ export interface MenuActionItem {
13
19
  disabled?: boolean;
14
20
  danger?: boolean;
15
21
  icon?: MenuIcon;
22
+ children?: MenuItem[];
23
+ selected?: boolean;
16
24
  }
17
25
  export interface MenuDividerItem {
18
26
  kind: "divider";
@@ -30,7 +38,8 @@ type MenuProps = Omit<HTMLAttributes<HTMLDivElement>, "class" | "onselect"> & {
30
38
  dismissOnSelect?: boolean;
31
39
  class?: string;
32
40
  dense?: boolean;
33
- onselect?: (value: string) => void;
41
+ submenuSide?: MenuSubmenuSide;
42
+ onselect?: (value: string, detail?: MenuSelectDetail) => void;
34
43
  };
35
44
  declare const Menu: Component<MenuProps, {}, "open">;
36
45
  type Menu = ReturnType<typeof Menu>;
@@ -1 +1 @@
1
- {"version":3,"file":"Menu.svelte.d.ts","sourceRoot":"","sources":["../src/lib/Menu.svelte.ts"],"names":[],"mappings":"AAGE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAExC,MAAM,MAAM,aAAa,GAAG;IAC1B,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;I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EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAiBpD,KAAK,SAAS,GAAG,IAAI,CAAC,cAAc,CAAC,cAAc,CAAC,EAAE,OAAO,GAAG,UAAU,CAAC,GAAG;IAC5E,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,QAAQ,EAAE,CAAC;IAClB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,WAAW,CAAC,EAAE,eAAe,CAAC;IAC9B,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,gBAAgB,KAAK,IAAI,CAAC;CAC/D,CAAC;AA05BJ,QAAA,MAAM,IAAI,kCAAwC,CAAC;AACnD,KAAK,IAAI,GAAG,UAAU,CAAC,OAAO,IAAI,CAAC,CAAC;AACpC,eAAe,IAAI,CAAC"}
@@ -1,6 +1,12 @@
1
+ <script lang="ts" module>
2
+ let menuPopoverInstanceCounter = 0;
3
+ </script>
4
+
1
5
  <script lang="ts">
6
+ import { setContext } from "svelte";
2
7
  import type { Snippet } from "svelte";
3
8
  import type { HTMLAttributes } from "svelte/elements";
9
+ import { MENU_HOST_CONTEXT, type MenuHostContext } from "./menu-cascade.js";
4
10
 
5
11
  type MenuPopoverProps = Omit<HTMLAttributes<HTMLDivElement>, "class"> & {
6
12
  open?: boolean;
@@ -27,6 +33,28 @@
27
33
  ...rest
28
34
  }: MenuPopoverProps = $props();
29
35
 
36
+ const rootMenuId = `st-menupopover-${++menuPopoverInstanceCounter}`;
37
+
38
+ function requestClose(options: { focusTrigger: boolean }) {
39
+ open = false;
40
+ if (options.focusTrigger) {
41
+ trigger?.focus();
42
+ }
43
+ }
44
+
45
+ // Reported by the inner Menu via setHasCascade (and reset when items lose
46
+ // their cascade): Esc returns focus to the trigger for cascade menus
47
+ // only, flat menus keep their previous behaviour (§3.6, AC-01).
48
+ let hasCascade = $state(false);
49
+ const hostContext: MenuHostContext = {
50
+ rootMenuId,
51
+ requestClose,
52
+ setHasCascade: (value: boolean) => {
53
+ hasCascade = value;
54
+ }
55
+ };
56
+ setContext(MENU_HOST_CONTEXT, hostContext);
57
+
30
58
  let panel: HTMLDivElement | undefined = $state();
31
59
  let top = $state(0);
32
60
  let left = $state(0);
@@ -157,8 +185,9 @@
157
185
  computePosition();
158
186
  showTopLayer();
159
187
  // Re-measure once the panel is laid out (size known for flip/clamp).
188
+ let raf = 0;
160
189
  if (typeof requestAnimationFrame === "function") {
161
- requestAnimationFrame(() => {
190
+ raf = requestAnimationFrame(() => {
162
191
  if (open) computePosition();
163
192
  });
164
193
  }
@@ -169,6 +198,9 @@
169
198
  return () => {
170
199
  window.removeEventListener("scroll", onScroll, true);
171
200
  window.removeEventListener("resize", onResize);
201
+ if (raf !== 0 && typeof cancelAnimationFrame === "function") {
202
+ cancelAnimationFrame(raf);
203
+ }
172
204
  hideTopLayer();
173
205
  };
174
206
  });
@@ -183,7 +215,20 @@
183
215
  return Boolean(target && node.contains(target));
184
216
  }
185
217
 
218
+ // The host generates the root menu id and sets `aria-controls` on its
219
+ // trigger, including an external trigger element passed as prop (§2.2, D10).
220
+ $effect(() => {
221
+ if (!open || !trigger) return;
222
+ trigger.setAttribute("aria-controls", rootMenuId);
223
+ const owned = trigger;
224
+ return () => {
225
+ owned.removeAttribute("aria-controls");
226
+ };
227
+ });
228
+
186
229
  function onWindowPointerDown(event: PointerEvent) {
230
+ // A nested menu level already consumed this event (D4).
231
+ if (event.defaultPrevented) return;
187
232
  if (!open || !closeOnOutside) return;
188
233
  if (isWithin(event, panel)) return;
189
234
  if (isWithin(event, trigger)) return;
@@ -191,10 +236,14 @@
191
236
  }
192
237
 
193
238
  function onWindowKeyDown(event: KeyboardEvent) {
239
+ // A nested menu level already consumed this key (D4).
240
+ if (event.defaultPrevented) return;
194
241
  if (!open || !closeOnEscape) return;
195
242
  if (event.key === "Escape") {
196
243
  event.preventDefault();
197
- open = false;
244
+ // Keyboard closes return focus to the trigger for cascade menus only
245
+ // (the inner Menu reports and resets `hasCascade`, §3.6).
246
+ requestClose({ focusTrigger: hasCascade });
198
247
  }
199
248
  }
200
249
 
@@ -1 +1 @@
1
- {"version":3,"file":"MenuPopover.svelte.d.ts","sourceRoot":"","sources":["../src/lib/MenuPopover.svelte.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAGpD,KAAK,gBAAgB,GAAG,IAAI,CAAC,cAAc,CAAC,cAAc,CAAC,EAAE,OAAO,CAAC,GAAG;IACtE,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,OAAO,EAAE,WAAW,GAAG,IAAI,CAAC;IAC5B,SAAS,CAAC,EAAE,cAAc,GAAG,YAAY,GAAG,WAAW,GAAG,SAAS,CAAC;IACpE,KAAK,CAAC,EAAE,OAAO,GAAG,KAAK,GAAG,QAAQ,CAAC;IACnC,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,CAAC;AAuNJ,QAAA,MAAM,WAAW,0DAAwC,CAAC;AAC1D,KAAK,WAAW,GAAG,UAAU,CAAC,OAAO,WAAW,CAAC,CAAC;AAClD,eAAe,WAAW,CAAC"}
1
+ {"version":3,"file":"MenuPopover.svelte.d.ts","sourceRoot":"","sources":["../src/lib/MenuPopover.svelte.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAIpD,KAAK,gBAAgB,GAAG,IAAI,CAAC,cAAc,CAAC,cAAc,CAAC,EAAE,OAAO,CAAC,GAAG;IACtE,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,OAAO,EAAE,WAAW,GAAG,IAAI,CAAC;IAC5B,SAAS,CAAC,EAAE,cAAc,GAAG,YAAY,GAAG,WAAW,GAAG,SAAS,CAAC;IACpE,KAAK,CAAC,EAAE,OAAO,GAAG,KAAK,GAAG,QAAQ,CAAC;IACnC,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,CAAC;AAsQJ,QAAA,MAAM,WAAW,0DAAwC,CAAC;AAC1D,KAAK,WAAW,GAAG,UAAU,CAAC,OAAO,WAAW,CAAC,CAAC;AAClD,eAAe,WAAW,CAAC"}
@@ -1,5 +1,6 @@
1
1
  <script lang="ts" module>
2
2
  import type { Component } from "svelte";
3
+ import type { SubMenuSide } from "./menu-cascade.js";
3
4
 
4
5
  export type OverflowMenuIconProps = {
5
6
  size?: number | string;
@@ -10,6 +11,8 @@
10
11
 
11
12
  export type OverflowMenuIcon = Component<OverflowMenuIconProps> | string;
12
13
 
14
+ export type OverflowMenuSubmenuSide = SubMenuSide;
15
+
13
16
  export interface OverflowMenuActionItem {
14
17
  kind?: "item";
15
18
  value: string;
@@ -18,6 +21,8 @@
18
21
  danger?: boolean;
19
22
  icon?: OverflowMenuIcon;
20
23
  onclick?: () => void;
24
+ children?: OverflowMenuItem[];
25
+ selected?: boolean;
21
26
  }
22
27
 
23
28
  export interface OverflowMenuDividerItem {
@@ -33,12 +38,17 @@
33
38
  | OverflowMenuActionItem
34
39
  | OverflowMenuDividerItem
35
40
  | OverflowMenuGroupItem;
41
+
42
+ let overflowMenuInstanceCounter = 0;
36
43
  </script>
37
44
 
38
45
  <script lang="ts">
39
46
  import { Ellipsis } from "@lucide/svelte";
47
+ import { setContext, tick } from "svelte";
40
48
  import type { HTMLAttributes } from "svelte/elements";
41
- import { tick } from "svelte";
49
+ import Menu from "./Menu.svelte";
50
+ import type { MenuItem, MenuSelectDetail } from "./Menu.svelte";
51
+ import { MENU_HOST_CONTEXT, type MenuHostContext } from "./menu-cascade.js";
42
52
 
43
53
  type OverflowMenuProps = Omit<HTMLAttributes<HTMLDivElement>, "class" | "onselect"> & {
44
54
  items: OverflowMenuItem[];
@@ -48,7 +58,8 @@
48
58
  class?: string;
49
59
  triggerLabel?: string;
50
60
  dense?: boolean;
51
- onselect?: (value: string) => void;
61
+ submenuSide?: OverflowMenuSubmenuSide;
62
+ onselect?: (value: string, detail?: MenuSelectDetail) => void;
52
63
  };
53
64
 
54
65
  let {
@@ -59,17 +70,21 @@
59
70
  class: className,
60
71
  triggerLabel = "More actions",
61
72
  dense = false,
73
+ submenuSide = "auto",
62
74
  onselect,
63
75
  ...rest
64
76
  }: OverflowMenuProps = $props();
65
77
 
78
+ const rootMenuId = `st-overflowmenu-${++overflowMenuInstanceCounter}`;
79
+
66
80
  let host: HTMLDivElement | undefined = $state();
67
- let list: HTMLUListElement | undefined = $state();
81
+ let trigger: HTMLButtonElement | undefined = $state();
68
82
 
69
83
  // Cap viewport-aware (aligné sur MenuPopover) : sans ça, une longue liste
70
84
  // (~12+ items) déborde du viewport en mobile <768px sans scroll. On borne la
71
85
  // hauteur du panneau à l'espace réellement disponible sous (ou au-dessus, en
72
- // placement `top`) le déclencheur, et `overflow-y:auto` (CSS) rend scrollable.
86
+ // placement `top`) le déclencheur ; le Menu interne scrolle via
87
+ // `--st-menu-maxHeight`.
73
88
  let maxHeight = $state(0);
74
89
  const VIEWPORT_GAP = 4;
75
90
  const VIEWPORT_MARGIN = 8;
@@ -97,31 +112,61 @@
97
112
  };
98
113
  });
99
114
 
100
- function getFocusableItems(): HTMLButtonElement[] {
101
- return Array.from(
102
- list?.querySelectorAll<HTMLButtonElement>('[role="menuitem"]:not(:disabled)') ?? []
103
- );
115
+ function treeHasCascade(list: OverflowMenuItem[]): boolean {
116
+ for (const item of list) {
117
+ if (
118
+ (item.kind === undefined || item.kind === "item") &&
119
+ Array.isArray((item as OverflowMenuActionItem).children) &&
120
+ ((item as OverflowMenuActionItem).children?.length ?? 0) > 0
121
+ ) {
122
+ return true;
123
+ }
124
+ const children = (item as OverflowMenuActionItem).children;
125
+ if (Array.isArray(children) && treeHasCascade(children)) return true;
126
+ }
127
+ return false;
128
+ }
129
+
130
+ function findByValue(list: OverflowMenuItem[], value: string): OverflowMenuActionItem | undefined {
131
+ for (const item of list) {
132
+ if (item.kind !== undefined && item.kind !== "item") continue;
133
+ const action = item as OverflowMenuActionItem;
134
+ if (action.value === value) return action;
135
+ if (Array.isArray(action.children)) {
136
+ const found = findByValue(action.children, value);
137
+ if (found) return found;
138
+ }
139
+ }
140
+ return undefined;
104
141
  }
105
142
 
106
- function moveIndex(index: number, size: number, step: number) {
107
- if (size <= 0) return 0;
108
- return ((index + step) % size + size) % size;
143
+ function requestClose(options: { focusTrigger: boolean }) {
144
+ open = false;
145
+ if (options.focusTrigger) {
146
+ trigger?.focus();
147
+ }
109
148
  }
110
149
 
111
- function focusAt(index: number) {
112
- const focusable = getFocusableItems();
113
- if (!focusable.length) return;
114
- const target = moveIndex(index, focusable.length, 0);
115
- focusable.forEach((button, idx) => {
116
- button.tabIndex = idx === target ? 0 : -1;
117
- });
118
- focusable[target]?.focus();
150
+ // The inner Menu reads `overflowClasses` instead of a public prop (AC-37,
151
+ // B1). Esc focus return is gated on `treeHasCascade(items)` below (§3.6).
152
+ const hostContext: MenuHostContext = {
153
+ rootMenuId,
154
+ requestClose,
155
+ overflowClasses: true
156
+ };
157
+ setContext(MENU_HOST_CONTEXT, hostContext);
158
+
159
+ function focusFirstMenuItem() {
160
+ const first = host?.querySelector<HTMLButtonElement>(
161
+ '[role="menuitem"]:not(:disabled)'
162
+ );
163
+ first?.focus();
119
164
  }
120
165
 
121
166
  function openAndFocus() {
122
167
  open = true;
123
168
  tick().then(() => {
124
- focusAt(0);
169
+ focusFirstMenuItem();
125
170
  });
126
171
  }
127
172
 
@@ -147,69 +192,73 @@
147
192
  open = false;
148
193
  }
149
194
 
150
- function selectItem(item: OverflowMenuActionItem) {
151
- if (item.disabled) return;
152
- item.onclick?.();
153
- onselect?.(item.value);
195
+ function panelPositionStyle(): string {
196
+ // The inner Menu owns the surface; the host only pins the panel box.
197
+ const offset = "calc(100% + var(--st-spacing-1, 0.25rem))";
198
+ let position: string;
199
+ if (placement === "bottom-start") {
200
+ position = `position: absolute; left: 0; top: ${offset};`;
201
+ } else if (placement === "top-end") {
202
+ position = `position: absolute; right: 0; bottom: ${offset};`;
203
+ } else if (placement === "top-start") {
204
+ position = `position: absolute; left: 0; bottom: ${offset};`;
205
+ } else {
206
+ position = `position: absolute; right: 0; top: ${offset};`;
207
+ }
208
+ const cap = maxHeight ? ` --st-menu-maxHeight: ${maxHeight}px;` : "";
209
+ return `${position} z-index: var(--st-component-popover-zIndex, 80);${cap}`;
210
+ }
211
+
212
+ function handleMenuSelect(value: string, detail?: MenuSelectDetail) {
213
+ const cascade = treeHasCascade(items);
214
+ // Leaf `onclick` still precedes `select`; parent activation never reaches
215
+ // here (the Menu opens the sub-menu instead). The Menu passes its item
216
+ // reference through, so `detail.item` is this host's own object.
217
+ const source = detail?.item
218
+ ? (detail.item as unknown as OverflowMenuActionItem)
219
+ : findByValue(items, value);
220
+ source?.onclick?.();
221
+ if (cascade) {
222
+ onselect?.(value, detail);
223
+ } else {
224
+ // Flat menus keep the legacy single-argument call (AC-01).
225
+ onselect?.(value);
226
+ }
154
227
  close();
155
228
  }
156
229
 
157
- function isAction(item: OverflowMenuItem): item is OverflowMenuActionItem {
158
- return item.kind === undefined || item.kind === "item";
159
- }
160
-
161
230
  function onWindowKeydown(event: KeyboardEvent) {
231
+ // A nested menu level already consumed this key (D4).
232
+ if (event.defaultPrevented) return;
162
233
  if (event.key === "Escape" && open) {
163
234
  event.preventDefault();
164
- close();
235
+ // Keyboard closes return focus to the trigger for cascade menus only;
236
+ // flat menus keep their previous behaviour (§3.6, AC-01).
237
+ requestClose({ focusTrigger: treeHasCascade(items) });
165
238
  }
166
239
  }
167
240
 
168
- function onWindowPointerDown(event: MouseEvent) {
241
+ function onWindowPointerDown(event: PointerEvent) {
242
+ if (event.defaultPrevented) return;
169
243
  if (!open) return;
244
+ const composed = event as PointerEvent & { composedPath?: () => EventTarget[] };
245
+ const path = typeof composed.composedPath === "function" ? composed.composedPath() : [];
170
246
  const target = event.target as Node | null;
171
- if (host && target && !host.contains(target)) close();
247
+ const inside =
248
+ host !== undefined &&
249
+ (path.length > 0 ? path.includes(host) : Boolean(target && host.contains(target)));
250
+ if (!inside) close();
172
251
  }
173
252
 
174
253
  function onTriggerKeyDown(event: KeyboardEvent) {
175
254
  if (!["ArrowDown", "Enter", " "].includes(event.key)) return;
176
255
  event.preventDefault();
177
256
  if (open) {
178
- focusAt(0);
257
+ focusFirstMenuItem();
179
258
  } else {
180
259
  openAndFocus();
181
260
  }
182
261
  }
183
-
184
- function onItemKeyDown(event: KeyboardEvent, item: OverflowMenuActionItem) {
185
- const focusable = getFocusableItems();
186
- const current = focusable.indexOf(event.currentTarget as HTMLButtonElement);
187
- if (event.key === "ArrowDown") {
188
- event.preventDefault();
189
- focusAt(current + 1);
190
- return;
191
- }
192
- if (event.key === "ArrowUp") {
193
- event.preventDefault();
194
- focusAt(current - 1);
195
- return;
196
- }
197
- if (event.key === "Home") {
198
- event.preventDefault();
199
- focusAt(0);
200
- return;
201
- }
202
- if (event.key === "End") {
203
- event.preventDefault();
204
- focusAt(focusable.length - 1);
205
- return;
206
- }
207
- if (item.disabled) return;
208
- if (event.key === "Enter" || event.key === " ") {
209
- event.preventDefault();
210
- selectItem(item);
211
- }
212
- }
213
262
  </script>
214
263
 
215
264
  <svelte:window onkeydown={onWindowKeydown} onpointerdown={onWindowPointerDown} />
@@ -217,9 +266,11 @@
217
266
  <div {...rest} bind:this={host} class={classes()}>
218
267
  <button
219
268
  type="button"
269
+ bind:this={trigger}
220
270
  class="st-overflowMenu__trigger"
221
271
  aria-haspopup="menu"
222
272
  aria-expanded={open ? "true" : "false"}
273
+ aria-controls={open ? rootMenuId : undefined}
223
274
  aria-label={triggerLabel}
224
275
  onclick={toggle}
225
276
  onkeydown={onTriggerKeyDown}
@@ -227,47 +278,15 @@
227
278
  <Ellipsis size={18} strokeWidth={2.25} aria-hidden="true" />
228
279
  </button>
229
280
  {#if open}
230
- <ul
231
- bind:this={list}
232
- class="st-overflowMenu__list"
233
- role="menu"
234
- aria-label={label}
235
- style={maxHeight ? `max-height: ${maxHeight}px` : undefined}
236
- >
237
- {#each items as item, index (index)}
238
- {#if isAction(item)}
239
- {@const Icon = item.icon}
240
- <li role="none" class="st-overflowMenu__listItem">
241
- <button
242
- type="button"
243
- class="st-overflowMenu__item"
244
- class:st-overflowMenu__item--danger={item.danger}
245
- role="menuitem"
246
- aria-disabled={item.disabled ? "true" : undefined}
247
- disabled={item.disabled}
248
- tabindex={-1}
249
- onclick={() => selectItem(item)}
250
- onkeydown={(event) => onItemKeyDown(event, item)}
251
- >
252
- {#if Icon}
253
- <span class="st-overflowMenu__itemIcon" aria-hidden="true">
254
- {#if typeof Icon === "string"}
255
- {Icon}
256
- {:else}
257
- <Icon size={16} strokeWidth={2} />
258
- {/if}
259
- </span>
260
- {/if}
261
- <span class="st-overflowMenu__itemLabel">{item.label}</span>
262
- </button>
263
- </li>
264
- {:else if item.kind === "divider"}
265
- <li role="separator" aria-hidden="true" class="st-overflowMenu__divider"></li>
266
- {:else}
267
- <li role="presentation" class="st-overflowMenu__group">{item.label}</li>
268
- {/if}
269
- {/each}
270
- </ul>
281
+ <Menu
282
+ items={items as unknown as MenuItem[]}
283
+ label={label}
284
+ submenuSide={submenuSide}
285
+ dense={dense}
286
+ id={rootMenuId}
287
+ style={panelPositionStyle()}
288
+ onselect={handleMenuSelect}
289
+ />
271
290
  {/if}
272
291
  </div>
273
292
 
@@ -308,7 +327,11 @@
308
327
  background: var(--st-component-control-hoverBackground, var(--st-semantic-surface-subtle));
309
328
  }
310
329
 
311
- .st-overflowMenu__list {
330
+ /* Flat list/item visual (AC-37, D6): restored origin/main rules. Flat rows
331
+ render inside the child Menu (D5), so these selectors are global —
332
+ component scoping cannot reach child-rendered elements. Cascade panels
333
+ keep their `.st-menu*` styling, scoped to the cascade marker. */
334
+ :global(.st-overflowMenu__list) {
312
335
  background: var(--st-component-menu-background, var(--st-semantic-surface-raised));
313
336
  border: 1px solid var(--st-component-menu-border, var(--st-semantic-border-subtle));
314
337
  border-radius: var(--st-component-menu-radius, 0.375rem);
@@ -327,32 +350,32 @@
327
350
  z-index: var(--st-component-popover-zIndex, 80);
328
351
  }
329
352
 
330
- .st-overflowMenu--bottom-end .st-overflowMenu__list {
353
+ :global(.st-overflowMenu--bottom-end .st-overflowMenu__list) {
331
354
  right: 0;
332
355
  top: calc(100% + var(--st-spacing-1, 0.25rem));
333
356
  }
334
357
 
335
- .st-overflowMenu--bottom-start .st-overflowMenu__list {
358
+ :global(.st-overflowMenu--bottom-start .st-overflowMenu__list) {
336
359
  left: 0;
337
360
  top: calc(100% + var(--st-spacing-1, 0.25rem));
338
361
  }
339
362
 
340
- .st-overflowMenu--top-end .st-overflowMenu__list {
363
+ :global(.st-overflowMenu--top-end .st-overflowMenu__list) {
341
364
  bottom: calc(100% + var(--st-spacing-1, 0.25rem));
342
365
  right: 0;
343
366
  }
344
367
 
345
- .st-overflowMenu--top-start .st-overflowMenu__list {
368
+ :global(.st-overflowMenu--top-start .st-overflowMenu__list) {
346
369
  bottom: calc(100% + var(--st-spacing-1, 0.25rem));
347
370
  left: 0;
348
371
  }
349
372
 
350
- .st-overflowMenu__listItem {
373
+ :global(.st-overflowMenu__listItem) {
351
374
  margin: 0;
352
375
  padding: 0;
353
376
  }
354
377
 
355
- .st-overflowMenu__item {
378
+ :global(.st-overflowMenu__item) {
356
379
  align-items: center;
357
380
  background: transparent;
358
381
  border: 0;
@@ -367,27 +390,64 @@
367
390
  width: 100%;
368
391
  }
369
392
 
370
- .st-overflowMenu--dense .st-overflowMenu__item {
393
+ :global(.st-overflowMenu--dense .st-overflowMenu__item) {
371
394
  padding: 0.3rem 0.6rem;
372
395
  }
373
396
 
374
- .st-overflowMenu__item:hover:not(:disabled),
375
- .st-overflowMenu__item:focus-visible {
397
+ :global(.st-overflowMenu__item:hover:not(:disabled)) {
376
398
  background: var(--st-component-control-hoverBackground, var(--st-semantic-surface-subtle));
377
399
  outline: none;
378
400
  }
379
401
 
380
- .st-overflowMenu__item:disabled {
402
+ :global(.st-overflowMenu__item:focus-visible) {
403
+ background: var(--st-component-control-hoverBackground, var(--st-semantic-surface-subtle));
404
+ outline: none;
405
+ }
406
+
407
+ :global(.st-overflowMenu__item:disabled) {
381
408
  color: var(--st-component-menu-disabledText, var(--st-semantic-text-muted));
382
409
  cursor: not-allowed;
383
410
  }
384
411
 
385
- .st-overflowMenu__item--danger {
412
+ /* Selected flat row: existing selectableRow tokens, same no-color-mix
413
+ fallback strategy as Menu (M6). */
414
+ :global(.st-overflowMenu__item--selected) {
415
+ background: var(
416
+ --st-component-selectableRow-selectedBackground,
417
+ color-mix(in oklch, var(--st-semantic-action-primary, #2563eb) 12%, transparent)
418
+ );
419
+ color: var(
420
+ --st-component-selectableRow-selectedText,
421
+ color-mix(in oklch, var(--st-semantic-action-primary, #2563eb) 78%, black)
422
+ );
423
+ }
424
+
425
+ @supports not (color: color-mix(in oklch, red, blue)) {
426
+ :global(.st-overflowMenu__item--selected) {
427
+ background: var(
428
+ --st-component-selectableRow-selectedBackground,
429
+ var(--st-semantic-surface-subtle, #eef2ff)
430
+ );
431
+ color: var(
432
+ --st-component-selectableRow-selectedText,
433
+ var(--st-semantic-text-primary, #0f172a)
434
+ );
435
+ }
436
+ }
437
+
438
+ :global(.st-overflowMenu__item--danger) {
386
439
  color: var(--st-component-overflowMenu-dangerText, var(--st-semantic-feedback-error));
387
440
  }
388
441
 
389
- .st-overflowMenu__item--danger:hover:not(:disabled),
390
- .st-overflowMenu__item--danger:focus-visible {
442
+ :global(.st-overflowMenu__item--danger:hover:not(:disabled)) {
443
+ background: var(
444
+ --st-component-overflowMenu-dangerHoverBackground,
445
+ var(--st-semantic-feedback-error)
446
+ );
447
+ color: var(--st-component-overflowMenu-dangerHoverText, var(--st-semantic-action-primaryText));
448
+ }
449
+
450
+ :global(.st-overflowMenu__item--danger:focus-visible) {
391
451
  background: var(
392
452
  --st-component-overflowMenu-dangerHoverBackground,
393
453
  var(--st-semantic-feedback-error)
@@ -395,28 +455,28 @@
395
455
  color: var(--st-component-overflowMenu-dangerHoverText, var(--st-semantic-action-primaryText));
396
456
  }
397
457
 
398
- .st-overflowMenu__itemIcon {
458
+ :global(.st-overflowMenu__itemIcon) {
399
459
  align-items: center;
400
460
  display: inline-flex;
401
461
  flex: 0 0 auto;
402
462
  justify-content: center;
403
463
  }
404
464
 
405
- .st-overflowMenu__itemLabel {
465
+ :global(.st-overflowMenu__itemLabel) {
406
466
  flex: 1 1 auto;
407
467
  overflow: hidden;
408
468
  text-overflow: ellipsis;
409
469
  white-space: nowrap;
410
470
  }
411
471
 
412
- .st-overflowMenu__divider {
472
+ :global(.st-overflowMenu__divider) {
413
473
  background: var(--st-component-menu-border, var(--st-semantic-border-subtle));
414
474
  height: 1px;
415
475
  list-style: none;
416
476
  margin: 0.25rem 0;
417
477
  }
418
478
 
419
- .st-overflowMenu__group {
479
+ :global(.st-overflowMenu__group) {
420
480
  color: var(--st-component-menu-groupText, var(--st-semantic-text-muted));
421
481
  font-size: 0.72rem;
422
482
  font-weight: 650;
@@ -1,4 +1,5 @@
1
1
  import type { Component } from "svelte";
2
+ import type { SubMenuSide } from "./menu-cascade.js";
2
3
  export type OverflowMenuIconProps = {
3
4
  size?: number | string;
4
5
  strokeWidth?: number | string;
@@ -6,6 +7,7 @@ export type OverflowMenuIconProps = {
6
7
  class?: string;
7
8
  } & Record<`data-${string}`, unknown>;
8
9
  export type OverflowMenuIcon = Component<OverflowMenuIconProps> | string;
10
+ export type OverflowMenuSubmenuSide = SubMenuSide;
9
11
  export interface OverflowMenuActionItem {
10
12
  kind?: "item";
11
13
  value: string;
@@ -14,6 +16,8 @@ export interface OverflowMenuActionItem {
14
16
  danger?: boolean;
15
17
  icon?: OverflowMenuIcon;
16
18
  onclick?: () => void;
19
+ children?: OverflowMenuItem[];
20
+ selected?: boolean;
17
21
  }
18
22
  export interface OverflowMenuDividerItem {
19
23
  kind: "divider";
@@ -24,6 +28,7 @@ export interface OverflowMenuGroupItem {
24
28
  }
25
29
  export type OverflowMenuItem = OverflowMenuActionItem | OverflowMenuDividerItem | OverflowMenuGroupItem;
26
30
  import type { HTMLAttributes } from "svelte/elements";
31
+ import type { MenuSelectDetail } from "./Menu.svelte";
27
32
  type OverflowMenuProps = Omit<HTMLAttributes<HTMLDivElement>, "class" | "onselect"> & {
28
33
  items: OverflowMenuItem[];
29
34
  label?: string;
@@ -32,7 +37,8 @@ type OverflowMenuProps = Omit<HTMLAttributes<HTMLDivElement>, "class" | "onselec
32
37
  class?: string;
33
38
  triggerLabel?: string;
34
39
  dense?: boolean;
35
- onselect?: (value: string) => void;
40
+ submenuSide?: OverflowMenuSubmenuSide;
41
+ onselect?: (value: string, detail?: MenuSelectDetail) => void;
36
42
  };
37
43
  declare const OverflowMenu: Component<OverflowMenuProps, {}, "open">;
38
44
  type OverflowMenu = ReturnType<typeof OverflowMenu>;