@r2digisolutions/components 0.19.19 → 0.19.21

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.
@@ -476,7 +476,7 @@
476
476
  ontoggle={handleToggle}
477
477
  onbeforetoggle={handleBeforeToggle}
478
478
  onkeydown={onMenuKeydown}
479
- class="dropdown-menu m-0 rounded-xl border-border bg-surface-elevated p-1.5 shadow-xl inset-auto flex-col overflow-hidden border text-left outline-none"
479
+ class="dropdown-menu m-0 rounded-xl border-border bg-surface-elevated p-1.5 shadow-xl inset-auto flex-col border text-left outline-none"
480
480
  >
481
481
  {#if canGoBack}
482
482
  <button
@@ -612,12 +612,14 @@
612
612
  }
613
613
 
614
614
  .dropdown-menu-list {
615
- overflow-x: hidden;
616
- overflow-y: var(--dropdown-scroll, visible);
615
+ /* One axis hidden + the other visible computes to auto (nested scrollbar). */
616
+ overflow: var(--dropdown-scroll, visible);
617
617
  overscroll-behavior: contain;
618
618
  }
619
619
 
620
620
  .dropdown-menu:popover-open {
621
621
  display: flex;
622
+ /* UA popover is overflow:auto — that paints a nested scrollbar. */
623
+ overflow: hidden;
622
624
  }
623
625
  </style>
@@ -1133,31 +1133,42 @@
1133
1133
  </IconButton>
1134
1134
  </div>
1135
1135
 
1136
- <div class="flex items-center gap-0.5">
1136
+ <div class="flex items-center rounded-lg border border-border bg-surface p-0.5">
1137
1137
  <Tooltip content="Toggle grid">
1138
1138
  <IconButton
1139
1139
  label="Toggle grid"
1140
1140
  size="sm"
1141
- onclick={() => (showGrid = !showGrid)}
1141
+ aria-pressed={showGrid}
1142
+ onclick={(e) => {
1143
+ showGrid = !showGrid;
1144
+ (e.currentTarget as HTMLButtonElement).blur();
1145
+ }}
1142
1146
  class={showGrid ? 'bg-brand-500/10 text-brand-600' : undefined}
1143
1147
  >
1144
1148
  <Grid3x3 class="h-3.5 w-3.5" />
1145
1149
  </IconButton>
1146
1150
  </Tooltip>
1147
1151
  {#if showGrid}
1148
- <Select
1149
- size="sm"
1150
- class="w-[4.5rem] shrink-0"
1151
- options={gridSizeOptions}
1152
+ <select
1153
+ class="h-8 min-w-0 shrink-0 rounded-md border-0 bg-transparent px-1 font-mono text-[11px] tabular-nums text-secondary outline-none hover:bg-surface-overlay focus-visible:bg-surface-overlay"
1154
+ aria-label="Grid cell size"
1152
1155
  value={String(cellSize)}
1153
- onchange={(v) => (cellSize = Number(v))}
1154
- />
1156
+ onchange={(e) => (cellSize = Number(e.currentTarget.value))}
1157
+ >
1158
+ {#each gridSizeOptions as opt (opt.value)}
1159
+ <option value={opt.value}>{opt.label}</option>
1160
+ {/each}
1161
+ </select>
1155
1162
  {/if}
1156
1163
  <Tooltip content="Snap to grid & guides">
1157
1164
  <IconButton
1158
1165
  label="Toggle snap"
1159
1166
  size="sm"
1160
- onclick={() => (snap = !snap)}
1167
+ aria-pressed={snap}
1168
+ onclick={(e) => {
1169
+ snap = !snap;
1170
+ (e.currentTarget as HTMLButtonElement).blur();
1171
+ }}
1161
1172
  class={snap ? 'bg-brand-500/10 text-brand-600' : undefined}
1162
1173
  >
1163
1174
  <Magnet class="h-3.5 w-3.5" />
@@ -1,4 +1,6 @@
1
1
  <script lang="ts">
2
+ import type { Attachment } from 'svelte/attachments';
3
+
2
4
  export interface MenubarSubItem {
3
5
  id: string;
4
6
  label: string;
@@ -21,17 +23,16 @@
21
23
  interface MenubarProps {
22
24
  items?: MenubarItem[];
23
25
  class?: string;
24
- onselect?: (itemId: string, parentId: string) => void;
26
+ onselect?: (itemId: string, parentId: string, checked?: boolean) => void;
25
27
  }
26
28
 
27
- let {
28
- items = [],
29
- class: className = '',
30
- onselect
31
- }: MenubarProps = $props();
29
+ let { items = [], class: className = '', onselect }: MenubarProps = $props();
32
30
 
33
31
  let openId = $state<string | null>(null);
34
- let flyoutId = $state<string | null>(null);
32
+ /** Local toggle overlay so checks flip even if the parent keeps `checked` static. */
33
+ let localChecked = $state<Record<string, boolean>>({});
34
+ /** Open submenu ids from the root menu down (Export → …). */
35
+ let flyoutPath = $state<string[]>([]);
35
36
  let menubarEl = $state<HTMLElement | null>(null);
36
37
  let menuEl = $state<HTMLDivElement | null>(null);
37
38
  let menuStyle = $state('');
@@ -41,6 +42,10 @@
41
42
  return `menubar-menu-${id}`;
42
43
  }
43
44
 
45
+ function flyoutDomId(id: string) {
46
+ return `menubar-flyout-${id}`;
47
+ }
48
+
44
49
  function close() {
45
50
  if (menuEl?.matches(':popover-open')) {
46
51
  try {
@@ -50,15 +55,13 @@
50
55
  }
51
56
  }
52
57
  openId = null;
53
- flyoutId = null;
58
+ flyoutPath = [];
54
59
  highlightedId = null;
55
60
  menuStyle = '';
56
61
  }
57
62
 
58
63
  function positionMenu(id: string) {
59
- const btn = menubarEl?.querySelector(
60
- `[data-menubar-trigger="${id}"]`
61
- ) as HTMLElement | null;
64
+ const btn = menubarEl?.querySelector(`[data-menubar-trigger="${id}"]`) as HTMLElement | null;
62
65
  if (!btn || !menuEl) return;
63
66
  const rect = btn.getBoundingClientRect();
64
67
  const pad = 8;
@@ -78,9 +81,49 @@
78
81
  }
79
82
  }
80
83
 
84
+ function positionFlyout(id: string, flyoutEl?: HTMLElement | null) {
85
+ const trigger = (menuEl?.querySelector(`[data-menubar-item="${CSS.escape(id)}"]`) ??
86
+ document.querySelector(`[data-menubar-item="${CSS.escape(id)}"]`)) as HTMLElement | null;
87
+ const el = flyoutEl ?? (document.getElementById(flyoutDomId(id)) as HTMLElement | null);
88
+ if (!trigger || !el) return;
89
+ const rect = trigger.getBoundingClientRect();
90
+ const pad = 8;
91
+ const w = Math.max(180, el.offsetWidth || 180);
92
+ const h = el.offsetHeight || 80;
93
+ let left = rect.right - 4;
94
+ if (left + w > window.innerWidth - pad) {
95
+ left = Math.max(pad, rect.left - w + 4);
96
+ }
97
+ let top = rect.top - 4;
98
+ if (top + h > window.innerHeight - pad) {
99
+ top = Math.max(pad, window.innerHeight - h - pad);
100
+ }
101
+ el.style.cssText = `position:fixed;margin:0;inset:auto;top:${Math.round(top)}px;left:${Math.round(left)}px;`;
102
+ }
103
+
104
+ function flyoutAttach(id: string): Attachment<HTMLElement> {
105
+ return (el) => {
106
+ try {
107
+ if (!el.matches(':popover-open')) el.showPopover();
108
+ } catch {
109
+ /* ignore */
110
+ }
111
+ positionFlyout(id, el);
112
+ const frame = requestAnimationFrame(() => positionFlyout(id, el));
113
+ return () => {
114
+ cancelAnimationFrame(frame);
115
+ try {
116
+ if (el.matches(':popover-open')) el.hidePopover();
117
+ } catch {
118
+ /* ignore */
119
+ }
120
+ };
121
+ };
122
+ }
123
+
81
124
  function open(id: string) {
82
125
  openId = id;
83
- flyoutId = null;
126
+ flyoutPath = [];
84
127
  highlightedId = null;
85
128
  queueMicrotask(() => {
86
129
  if (!menuEl) return;
@@ -99,9 +142,20 @@
99
142
  else open(id);
100
143
  }
101
144
 
145
+ function isChecked(item: MenubarSubItem): boolean | undefined {
146
+ if (item.checked === undefined) return undefined;
147
+ return localChecked[item.id] ?? item.checked;
148
+ }
149
+
102
150
  function select(subItem: MenubarSubItem, parentId: string) {
103
151
  if (subItem.disabled || subItem.separator) return;
104
152
  if (subItem.children?.length) return;
153
+ if (subItem.checked !== undefined) {
154
+ const next = !isChecked(subItem);
155
+ localChecked[subItem.id] = next;
156
+ onselect?.(subItem.id, parentId, next);
157
+ return;
158
+ }
105
159
  onselect?.(subItem.id, parentId);
106
160
  close();
107
161
  }
@@ -129,7 +183,7 @@
129
183
  function onToggle(e: ToggleEvent) {
130
184
  if (e.newState === 'closed') {
131
185
  openId = null;
132
- flyoutId = null;
186
+ flyoutPath = [];
133
187
  highlightedId = null;
134
188
  menuStyle = '';
135
189
  }
@@ -141,8 +195,13 @@
141
195
 
142
196
  $effect(() => {
143
197
  if (!openId) return;
198
+ const path = flyoutPath;
144
199
  const onWin = () => {
145
200
  if (openId) positionMenu(openId);
201
+ for (const id of path) {
202
+ const el = document.getElementById(flyoutDomId(id));
203
+ if (el) positionFlyout(id, el);
204
+ }
146
205
  };
147
206
  window.addEventListener('resize', onWin);
148
207
  window.addEventListener('scroll', onWin, true);
@@ -155,31 +214,35 @@
155
214
  const openItem = $derived(items.find((i) => i.id === openId) ?? null);
156
215
  </script>
157
216
 
158
- {#snippet menuRows(list: MenubarSubItem[], parentId: string)}
217
+ {#snippet menuRows(list: MenubarSubItem[], parentId: string, ancestors: string[])}
159
218
  {@const checks = levelHasChecks(list)}
160
219
  {#each list as sub (sub.id)}
161
220
  {#if sub.separator}
162
221
  <div class="menubar-sep" role="separator"></div>
163
222
  {:else}
223
+ {@const checked = isChecked(sub)}
164
224
  {@const hasChildren = Boolean(sub.children?.length)}
165
- {@const isHot = highlightedId === sub.id || flyoutId === sub.id}
225
+ {@const flyoutOpen = flyoutPath[ancestors.length] === sub.id}
226
+ {@const isHot = highlightedId === sub.id || flyoutPath.includes(sub.id)}
166
227
  <div
167
228
  class="relative"
168
229
  role="presentation"
169
230
  onmouseenter={() => {
170
231
  if (sub.disabled) return;
171
232
  highlightedId = sub.id;
172
- flyoutId = hasChildren ? sub.id : null;
233
+ flyoutPath = hasChildren ? [...ancestors, sub.id] : ancestors;
173
234
  }}
174
235
  >
175
236
  <button
176
237
  type="button"
177
- role={sub.checked !== undefined ? 'menuitemcheckbox' : 'menuitem'}
238
+ data-menubar-item={sub.id}
239
+ role={checked !== undefined ? 'menuitemcheckbox' : 'menuitem'}
178
240
  disabled={sub.disabled}
179
241
  aria-disabled={sub.disabled || undefined}
180
- aria-checked={sub.checked !== undefined ? sub.checked : undefined}
242
+ aria-checked={checked}
181
243
  aria-haspopup={hasChildren ? 'menu' : undefined}
182
- aria-expanded={hasChildren ? flyoutId === sub.id : undefined}
244
+ aria-expanded={hasChildren ? flyoutOpen : undefined}
245
+ aria-controls={hasChildren ? flyoutDomId(sub.id) : undefined}
183
246
  onclick={() => select(sub, parentId)}
184
247
  class={[
185
248
  'menubar-item',
@@ -191,8 +254,15 @@
191
254
  >
192
255
  {#if checks}
193
256
  <span class="menubar-check" aria-hidden="true">
194
- {#if sub.checked}
195
- <svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.75">
257
+ {#if checked}
258
+ <svg
259
+ width="12"
260
+ height="12"
261
+ viewBox="0 0 24 24"
262
+ fill="none"
263
+ stroke="currentColor"
264
+ stroke-width="2.75"
265
+ >
196
266
  <path stroke-linecap="round" stroke-linejoin="round" d="M5 13l4 4L19 7" />
197
267
  </svg>
198
268
  {/if}
@@ -217,17 +287,20 @@
217
287
  {/if}
218
288
  </button>
219
289
 
220
- {#if hasChildren && flyoutId === sub.id && sub.children?.length}
290
+ {#if hasChildren && flyoutOpen && sub.children?.length}
221
291
  <div
222
- class="menubar-panel menubar-flyout"
292
+ id={flyoutDomId(sub.id)}
293
+ class="menubar-popover menubar-panel menubar-flyout m-0 outline-none"
294
+ popover="manual"
223
295
  role="menu"
224
296
  tabindex="-1"
297
+ {@attach flyoutAttach(sub.id)}
225
298
  onmouseenter={() => {
226
- flyoutId = sub.id;
299
+ flyoutPath = [...ancestors, sub.id];
227
300
  highlightedId = sub.id;
228
301
  }}
229
302
  >
230
- {@render menuRows(sub.children, parentId)}
303
+ {@render menuRows(sub.children, parentId, [...ancestors, sub.id])}
231
304
  </div>
232
305
  {/if}
233
306
  </div>
@@ -235,7 +308,11 @@
235
308
  {/each}
236
309
  {/snippet}
237
310
 
238
- <div bind:this={menubarEl} class={['menubar-bar flex items-center gap-px', className]} role="menubar">
311
+ <div
312
+ bind:this={menubarEl}
313
+ class={['menubar-bar flex items-center gap-px', className]}
314
+ role="menubar"
315
+ >
239
316
  {#each items as item (item.id)}
240
317
  {@const isOpen = openId === item.id}
241
318
  <button
@@ -250,17 +327,14 @@
250
327
  if (openId !== null && openId !== item.id) open(item.id);
251
328
  }}
252
329
  onkeydown={(e) => handleMenuKeydown(e, item)}
253
- class={[
254
- 'menubar-trigger',
255
- isOpen ? 'menubar-trigger-open' : 'menubar-trigger-idle'
256
- ]}
330
+ class={['menubar-trigger', isOpen ? 'menubar-trigger-open' : 'menubar-trigger-idle']}
257
331
  >
258
332
  {item.label}
259
333
  </button>
260
334
  {/each}
261
335
  </div>
262
336
 
263
- <!-- Single shared menu in the top layer (native Popover) -->
337
+ <!-- Native Popover — overflow visible so UA `overflow:auto` never paints a nested scrollbar -->
264
338
  <div
265
339
  bind:this={menuEl}
266
340
  id={openId ? menuDomId(openId) : 'menubar-menu'}
@@ -272,14 +346,17 @@
272
346
  class="menubar-popover menubar-panel m-0 outline-none"
273
347
  >
274
348
  {#if openItem?.items?.length}
275
- {@render menuRows(openItem.items, openItem.id)}
349
+ {@render menuRows(openItem.items, openItem.id, [])}
276
350
  {/if}
277
351
  </div>
278
352
 
279
353
  <style>
280
- /* UA popover defaults to inset:0 — force anchor via inline style */
354
+ /* UA popover: inset:0 + overflow:auto — both cause the nested scrollbar */
281
355
  .menubar-popover:popover-open {
282
356
  inset: unset;
357
+ overflow: visible;
358
+ height: fit-content;
359
+ width: max-content;
283
360
  }
284
361
 
285
362
  .menubar-trigger {
@@ -293,7 +370,9 @@
293
370
  font-weight: 400;
294
371
  letter-spacing: -0.01em;
295
372
  outline: none;
296
- transition: background-color 80ms ease, color 80ms ease;
373
+ transition:
374
+ background-color 80ms ease,
375
+ color 80ms ease;
297
376
  }
298
377
 
299
378
  .menubar-trigger:focus-visible {
@@ -306,7 +385,11 @@
306
385
 
307
386
  .menubar-trigger-idle:hover {
308
387
  /* text-primary is light in dark mode → soft white wash (never surface-overlay #171717) */
309
- background: color-mix(in oklab, var(--text-primary, var(--color-text-primary, CanvasText)) 14%, transparent);
388
+ background: color-mix(
389
+ in oklab,
390
+ var(--text-primary, var(--color-text-primary, CanvasText)) 14%,
391
+ transparent
392
+ );
310
393
  color: var(--text-primary, var(--color-text-primary, CanvasText));
311
394
  }
312
395
 
@@ -353,13 +436,6 @@
353
436
  0 4px 16px -4px color-mix(in oklab, #000 40%, transparent);
354
437
  }
355
438
 
356
- :global(.menubar-flyout) {
357
- position: absolute;
358
- left: calc(100% - 2px);
359
- top: -0.25rem;
360
- z-index: 2;
361
- }
362
-
363
439
  :global(.menubar-sep) {
364
440
  height: 1px;
365
441
  margin: 0.25rem 0.5rem;
@@ -383,7 +459,9 @@
383
459
  letter-spacing: -0.01em;
384
460
  text-align: left;
385
461
  outline: none;
386
- transition: background-color 60ms ease, color 60ms ease;
462
+ transition:
463
+ background-color 60ms ease,
464
+ color 60ms ease;
387
465
  }
388
466
 
389
467
  :global(.menubar-item-default) {
@@ -18,7 +18,7 @@ export interface MenubarItem {
18
18
  interface MenubarProps {
19
19
  items?: MenubarItem[];
20
20
  class?: string;
21
- onselect?: (itemId: string, parentId: string) => void;
21
+ onselect?: (itemId: string, parentId: string, checked?: boolean) => void;
22
22
  }
23
23
  declare const Menubar: import("svelte").Component<MenubarProps, {}, "">;
24
24
  type Menubar = ReturnType<typeof Menubar>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@r2digisolutions/components",
3
- "version": "0.19.19",
3
+ "version": "0.19.21",
4
4
  "private": false,
5
5
  "description": "R2DigiSolutions Svelte 5 component library — Atomic Design, Tailwind 4, Light/Dark mode",
6
6
  "license": "MIT",