@svgrid/grid 2.1.0 → 2.1.2

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.
Files changed (64) hide show
  1. package/dist/FlexRender.svelte +96 -96
  2. package/dist/GridFooter.svelte +178 -178
  3. package/dist/SvGrid.css +2377 -2377
  4. package/dist/SvGrid.svelte +2764 -2764
  5. package/dist/SvGridBoard.svelte +2281 -2281
  6. package/dist/SvGridDropdown.svelte +666 -666
  7. package/dist/cdn/svgrid.js +2 -2
  8. package/dist/cdn/svgrid.svelte-external.js +2 -2
  9. package/package.json +92 -92
  10. package/src/FlexRender.svelte +96 -96
  11. package/src/GridFooter.svelte +178 -178
  12. package/src/SvGrid.controller.svelte.ts +2553 -2553
  13. package/src/SvGrid.css +2377 -2377
  14. package/src/SvGrid.svelte +2764 -2764
  15. package/src/SvGrid.types.ts +944 -944
  16. package/src/SvGridBoard.svelte +2281 -2281
  17. package/src/SvGridDropdown.svelte +666 -666
  18. package/src/a11y.contract.test.ts +49 -49
  19. package/src/a11y.test.ts +59 -59
  20. package/src/a11y.ts +61 -61
  21. package/src/build-api.ts +798 -798
  22. package/src/cell-formatting.ts +169 -169
  23. package/src/cell-render.ts +469 -469
  24. package/src/collaboration.test.ts +104 -104
  25. package/src/collaboration.ts +167 -167
  26. package/src/core.performance.test.ts +30 -30
  27. package/src/core.ts +1111 -1111
  28. package/src/createGrid.svelte.ts +42 -42
  29. package/src/createGrid.test.ts +10 -10
  30. package/src/createGridState.svelte.ts +17 -17
  31. package/src/editing.test.ts +859 -859
  32. package/src/editing.ts +675 -675
  33. package/src/export-data-api.test.ts +126 -126
  34. package/src/export-format.test.ts +107 -107
  35. package/src/export-format.ts +598 -598
  36. package/src/flex-render.ts +3 -3
  37. package/src/index.ts +463 -463
  38. package/src/keyboard.test.ts +59 -59
  39. package/src/keyboard.ts +97 -97
  40. package/src/menus.ts +582 -582
  41. package/src/merge-objects.ts +48 -48
  42. package/src/render-component.ts +28 -28
  43. package/src/selection.test.ts +754 -754
  44. package/src/selection.ts +600 -600
  45. package/src/server-data-source.test.ts +289 -289
  46. package/src/server-data-source.ts +413 -413
  47. package/src/sparkline.test.ts +68 -68
  48. package/src/sparkline.ts +169 -169
  49. package/src/spreadsheet.test.ts +489 -489
  50. package/src/spreadsheet.ts +304 -304
  51. package/src/static-functions.ts +11 -11
  52. package/src/subscribe.ts +38 -38
  53. package/src/svgrid-wrapper.types.ts +439 -439
  54. package/src/svgrid.behavior.test.ts +706 -706
  55. package/src/svgrid.features.test.ts +157 -157
  56. package/src/svgrid.new-features.wrapper.test.ts +251 -251
  57. package/src/svgrid.wrapper.test.ts +40 -40
  58. package/src/themes/index.ts +159 -159
  59. package/src/virtualization/column-virtualizer.test.ts +27 -27
  60. package/src/virtualization/column-virtualizer.ts +30 -30
  61. package/src/virtualization/svelte-virtualizer.svelte.ts +26 -26
  62. package/src/virtualization/types.ts +30 -30
  63. package/src/virtualization/virtualizer.test.ts +47 -47
  64. package/src/virtualization/virtualizer.ts +296 -296
@@ -1,666 +1,666 @@
1
- <script lang="ts">
2
- /**
3
- * Internal dropdown / listbox control used by the `list` and `chips` cell
4
- * editors. We deliberately don't reuse the browser-native `<select>` -
5
- * the native dropdown can't be styled to match the grid theme, picks up
6
- * the OS color scheme, and on Windows draws the option list with an
7
- * opaque white system surface that fights the dark theme.
8
- *
9
- * Modes:
10
- * single - picking an option fires `onChange(value)` and `onCommit()`.
11
- * multi - toggling fires `onChange(values: array)`; the user
12
- * presses Enter / clicks "Done" to fire `onCommit()`.
13
- *
14
- * Keyboard model:
15
- * ArrowDown / ArrowUp - move highlight (opens the panel if closed).
16
- * Enter - single: toggle highlighted + commit.
17
- * multi: toggle highlighted (stay open).
18
- * Escape - close + onCancel.
19
- * Tab - commit and let focus escape.
20
- */
21
- import type { CellEditorOption } from './editors/cell-editors'
22
- import { anchoredRect, portalToBody, popIn, type AnchoredRect } from './popover'
23
-
24
- type Props = {
25
- options: ReadonlyArray<CellEditorOption>
26
- value: unknown
27
- multiple?: boolean
28
- placeholder?: string
29
- /** When provided, the trigger renders as removable chips of the current value(s). */
30
- renderChipsInTrigger?: boolean
31
- /** Add a typeahead input at the top of the popover that filters the
32
- * option list as the user types. Used by the rich-select editor. */
33
- searchable?: boolean
34
- /** Focus the trigger and open the panel on mount. True for in-cell editing
35
- * (you clicked into the cell to edit); set false for form fields, which
36
- * should stay closed and unfocused until the user acts. Default true. */
37
- autoOpen?: boolean
38
- /** Called with the new full value (scalar for single, array for multi). */
39
- onChange?: (next: unknown) => void
40
- /** Called when the user finalizes the selection (single pick, Enter, blur with selection). */
41
- onCommit?: () => void
42
- /** Called when the user dismisses (Escape, blur with no change). */
43
- onCancel?: () => void
44
- }
45
-
46
- let {
47
- options,
48
- value,
49
- multiple = false,
50
- placeholder = 'Select…',
51
- renderChipsInTrigger = false,
52
- searchable = false,
53
- autoOpen = true,
54
- onChange,
55
- onCommit,
56
- onCancel,
57
- }: Props = $props()
58
-
59
- let searchQuery = $state('')
60
- const visibleOptions = $derived(
61
- !searchable || !searchQuery.trim()
62
- ? options
63
- : (() => {
64
- const q = searchQuery.trim().toLowerCase()
65
- return options.filter((o) => o.label.toLowerCase().includes(q))
66
- })(),
67
- )
68
-
69
- let open = $state(false)
70
- let highlighted = $state(-1)
71
- let rootEl: HTMLDivElement | null = $state(null)
72
- let triggerEl: HTMLButtonElement | null = $state(null)
73
- let panelEl: HTMLDivElement | null = $state(null)
74
-
75
- /** Viewport-anchored panel position. We `position: fixed` the panel so it
76
- * escapes the grid's overflow:hidden scroll container - otherwise the
77
- * bottom of the list gets clipped by the pager or the grid's footer. */
78
- let panelRect = $state<AnchoredRect>({
79
- top: 0,
80
- left: 0,
81
- width: 0,
82
- openUpward: false,
83
- })
84
-
85
- const selectedArr = $derived(
86
- Array.isArray(value)
87
- ? (value as Array<string | number>)
88
- : value == null || value === ''
89
- ? []
90
- : [value as string | number],
91
- )
92
-
93
- const triggerSummary = $derived.by(() => {
94
- if (selectedArr.length === 0) return placeholder
95
- if (!multiple) {
96
- const v = selectedArr[0]!
97
- const match = options.find((o) => String(o.value) === String(v))
98
- return match ? match.label : String(v)
99
- }
100
- return `${selectedArr.length} selected`
101
- })
102
-
103
- /** Color of the single selected option, if any (for colored trigger). */
104
- const selectedColor = $derived.by(() => {
105
- if (multiple || selectedArr.length !== 1) return undefined
106
- const v = selectedArr[0]!
107
- return options.find((o) => String(o.value) === String(v))?.color
108
- })
109
-
110
- function isSelected(opt: CellEditorOption): boolean {
111
- return selectedArr.some((v) => String(v) === String(opt.value))
112
- }
113
-
114
- function toggleOption(opt: CellEditorOption) {
115
- if (multiple) {
116
- const exists = isSelected(opt)
117
- const next = exists
118
- ? selectedArr.filter((v) => String(v) !== String(opt.value))
119
- : [...selectedArr, opt.value]
120
- onChange?.(next)
121
- } else {
122
- onChange?.(opt.value)
123
- open = false
124
- onCommit?.()
125
- }
126
- }
127
-
128
- function openPanel() {
129
- if (open) return
130
- open = true
131
- // Seed the highlight to the first selected option, or top of the list.
132
- if (highlighted < 0) {
133
- const idx = options.findIndex((o) => isSelected(o))
134
- highlighted = idx >= 0 ? idx : 0
135
- }
136
- updatePanelPosition()
137
- }
138
-
139
- /** Recompute the panel's fixed-position rect from the trigger. Auto-
140
- * flips upward when there isn't enough room below the trigger. */
141
- function updatePanelPosition() {
142
- if (!triggerEl) return
143
- // Use the smaller of (option count, 10) for the upward-flip math so
144
- // a 3-option list doesn't think it needs 320px of headroom.
145
- const visibleCount = Math.min(options.length, 10)
146
- const estimatedHeight = visibleCount * 32 + (multiple ? 40 : 0) + 8
147
- panelRect = anchoredRect(triggerEl.getBoundingClientRect(), {
148
- estimatedHeight,
149
- // Preserve the original behavior: anchor to the trigger, no clamping.
150
- clampHorizontal: false,
151
- })
152
- }
153
-
154
- // Keep the panel anchored as the page scrolls or resizes - without this,
155
- // scrolling the underlying grid would leave the panel hanging in space.
156
- $effect(() => {
157
- if (!open) return
158
- const reposition = () => updatePanelPosition()
159
- window.addEventListener('scroll', reposition, true)
160
- window.addEventListener('resize', reposition)
161
- return () => {
162
- window.removeEventListener('scroll', reposition, true)
163
- window.removeEventListener('resize', reposition)
164
- }
165
- })
166
-
167
- function closePanel() {
168
- open = false
169
- highlighted = -1
170
- }
171
-
172
- function onKeyDown(event: KeyboardEvent) {
173
- event.stopPropagation()
174
- if (event.key === 'Escape') {
175
- event.preventDefault()
176
- closePanel()
177
- onCancel?.()
178
- return
179
- }
180
- if (event.key === 'ArrowDown') {
181
- event.preventDefault()
182
- if (!open) {
183
- openPanel()
184
- return
185
- }
186
- highlighted = Math.min(highlighted + 1, options.length - 1)
187
- scrollHighlightedIntoView()
188
- } else if (event.key === 'ArrowUp') {
189
- event.preventDefault()
190
- if (!open) {
191
- openPanel()
192
- return
193
- }
194
- highlighted = Math.max(highlighted - 1, 0)
195
- scrollHighlightedIntoView()
196
- } else if (event.key === 'Home') {
197
- if (!open) return
198
- event.preventDefault()
199
- highlighted = 0
200
- scrollHighlightedIntoView()
201
- } else if (event.key === 'End') {
202
- if (!open) return
203
- event.preventDefault()
204
- highlighted = options.length - 1
205
- scrollHighlightedIntoView()
206
- } else if (event.key === 'Enter') {
207
- event.preventDefault()
208
- if (!open) {
209
- openPanel()
210
- return
211
- }
212
- const opt = options[highlighted]
213
- if (opt) toggleOption(opt)
214
- else if (multiple) {
215
- closePanel()
216
- onCommit?.()
217
- }
218
- } else if (event.key === ' ' && open) {
219
- event.preventDefault()
220
- const opt = options[highlighted]
221
- if (opt) toggleOption(opt)
222
- } else if (event.key === 'Tab') {
223
- if (open) closePanel()
224
- onCommit?.()
225
- }
226
- }
227
-
228
- function scrollHighlightedIntoView() {
229
- queueMicrotask(() => {
230
- if (!panelEl) return
231
- const el = panelEl.querySelector<HTMLElement>(`[data-opt-idx="${highlighted}"]`)
232
- el?.scrollIntoView({ block: 'nearest' })
233
- })
234
- }
235
-
236
- function onRootBlur(event: FocusEvent) {
237
- // Defer to the next tick so a click on an option (mousedown → option
238
- // commits, then blur) doesn't race-cancel the selection.
239
- const next = event.relatedTarget as Node | null
240
- if (next && rootEl?.contains(next)) return
241
- if (open) closePanel()
242
- onCommit?.()
243
- }
244
-
245
- function removeChip(v: string | number, event: MouseEvent) {
246
- event.preventDefault()
247
- event.stopPropagation()
248
- const next = selectedArr.filter((x) => String(x) !== String(v))
249
- onChange?.(multiple ? next : next[0] ?? null)
250
- }
251
-
252
- function focusTrigger(node: HTMLButtonElement) {
253
- // Form fields (autoOpen=false) stay closed + unfocused until the user acts;
254
- // in-cell editing auto-focuses + opens to match clicking into a cell.
255
- if (!autoOpen) return
256
- node.focus()
257
- openPanel()
258
- }
259
-
260
- /** Close the panel when the user clicks outside both trigger AND
261
- * panel - `onfocusout` on the dropdown root no longer catches this
262
- * because the portal'd panel is a sibling of body, not a descendant
263
- * of rootEl. Wired up only while the panel is open. */
264
- $effect(() => {
265
- if (!open) return
266
- const onDocPointerDown = (event: PointerEvent) => {
267
- const target = event.target as Node | null
268
- if (!target) return
269
- if (rootEl?.contains(target)) return
270
- if (panelEl?.contains(target)) return
271
- closePanel()
272
- onCommit?.()
273
- }
274
- document.addEventListener('pointerdown', onDocPointerDown, true)
275
- return () => document.removeEventListener('pointerdown', onDocPointerDown, true)
276
- })
277
-
278
- /** Inline style for a chip with a configured `color`. Mirrors the
279
- * helper in SvGrid.svelte so colorful chips look identical in the
280
- * trigger and the in-cell readonly render. */
281
- function colorfulChipStyleInline(color: string): string {
282
- return (
283
- `background: color-mix(in srgb, ${color} 22%, transparent);` +
284
- `border-color: color-mix(in srgb, ${color} 45%, transparent);` +
285
- `color: color-mix(in srgb, ${color} 80%, var(--sg-fg, #0f172a));`
286
- )
287
- }
288
- </script>
289
-
290
- <!-- All pointer/click events are swallowed at the root so they never reach
291
- the surrounding cell's selection / pointerdown handlers - picking a
292
- dropdown option must not also toggle cell selection. -->
293
- <div
294
- class="sv-grid-dropdown"
295
- class:sv-grid-dropdown-open={open}
296
- bind:this={rootEl}
297
- onfocusout={onRootBlur}
298
- onclick={(event) => event.stopPropagation()}
299
- ondblclick={(event) => event.stopPropagation()}
300
- onpointerdown={(event) => event.stopPropagation()}
301
- onmousedown={(event) => event.stopPropagation()}
302
- >
303
- <button
304
- type="button"
305
- class="sv-grid-dropdown-trigger"
306
- class:sv-grid-dropdown-trigger-chips={renderChipsInTrigger && selectedArr.length > 0}
307
- aria-haspopup="listbox"
308
- aria-expanded={open}
309
- bind:this={triggerEl}
310
- use:focusTrigger
311
- onclick={() => (open ? closePanel() : openPanel())}
312
- onkeydown={onKeyDown}
313
- >
314
- {#if renderChipsInTrigger && selectedArr.length > 0}
315
- <span class="sv-grid-dropdown-chips">
316
- {#each selectedArr as v (String(v))}
317
- {@const opt = options.find((o) => String(o.value) === String(v))}
318
- <span
319
- class="sv-grid-chip sv-grid-chip-removable"
320
- style={opt?.color ? colorfulChipStyleInline(opt.color) : ''}
321
- >
322
- {opt ? opt.label : String(v)}
323
- <!-- A <button> can't be nested inside the trigger <button>; this is a
324
- pointer-only affordance (tabindex -1), so a role="button" span is
325
- valid HTML and preserves identical behaviour. -->
326
- <!-- svelte-ignore a11y_no_static_element_interactions a11y_click_events_have_key_events -->
327
- <span
328
- class="sv-grid-chip-remove"
329
- role="button"
330
- aria-label="Remove {opt ? opt.label : String(v)}"
331
- tabindex={-1}
332
- onmousedown={(event) => event.preventDefault()}
333
- onclick={(event) => removeChip(v, event)}
334
- >×</span>
335
- </span>
336
- {/each}
337
- </span>
338
- {:else if !multiple && selectedArr.length === 1 && selectedColor}
339
- <!-- Single-select list whose chosen option carries a color → show it
340
- as a colored chip inside the trigger, matching how the cell
341
- renders when not in edit mode. -->
342
- <span class="sv-grid-chip" style={colorfulChipStyleInline(selectedColor)}>
343
- {triggerSummary}
344
- </span>
345
- {:else}
346
- <span class="sv-grid-dropdown-label">{triggerSummary}</span>
347
- {/if}
348
- <span class="sv-grid-dropdown-caret" aria-hidden="true">▾</span>
349
- </button>
350
-
351
- {#if open}
352
- <!-- Sizing rule:
353
- - ≤ 10 options → no max-height. The panel grows to its content,
354
- overflow:auto stays inert, and no scrollbar is ever drawn.
355
- This matters because measuring "10 × 32px" against the real
356
- rendered option height (which depends on font + line-height)
357
- rounds inconsistently across themes and used to produce a
358
- 1-pixel scrollbar on lists as short as 3 items.
359
- - > 10 options → cap at 10 items + Done-footer chrome so the
360
- panel never overflows the viewport, and the scrollbar appears.
361
- Panel is `position: fixed` + portal'd to <body> so it escapes
362
- the grid's overflow:hidden scroll container. -->
363
- {@const needsScroll = options.length > 10}
364
- {@const panelMax = needsScroll ? 10 * 32 + (multiple ? 40 : 0) + 8 : null}
365
- <div
366
- class="sv-grid-dropdown-panel"
367
- class:sv-grid-dropdown-panel-fits={!needsScroll}
368
- role="listbox"
369
- aria-multiselectable={multiple}
370
- bind:this={panelEl}
371
- use:portalToBody
372
- use:popIn={{ up: panelRect.openUpward }}
373
- style:position="fixed"
374
- style:top={`${panelRect.top}px`}
375
- style:left={`${panelRect.left}px`}
376
- style:width={`${panelRect.width}px`}
377
- style:max-height={panelMax !== null ? `${panelMax}px` : null}
378
- style:z-index="2147483647"
379
- onpointerdown={(event) => event.stopPropagation()}
380
- onmousedown={(event) => event.stopPropagation()}
381
- onclick={(event) => event.stopPropagation()}
382
- >
383
- {#if searchable}
384
- <input
385
- type="search"
386
- class="sv-grid-dropdown-search"
387
- placeholder="Search…"
388
- bind:value={searchQuery}
389
- onmousedown={(event) => event.stopPropagation()}
390
- onclick={(event) => event.stopPropagation()}
391
- onkeydown={(event) => {
392
- if (event.key === 'Escape') { event.preventDefault(); open = false; onCancel?.() }
393
- }}
394
- />
395
- {/if}
396
- {#if visibleOptions.length === 0}
397
- <div class="sv-grid-dropdown-empty">{searchable && searchQuery ? `No matches for "${searchQuery}"` : 'No options'}</div>
398
- {:else}
399
- {#each visibleOptions as opt, i (String(opt.value))}
400
- {@const selected = isSelected(opt)}
401
- <div
402
- class="sv-grid-dropdown-option"
403
- class:sv-grid-dropdown-option-selected={selected}
404
- class:sv-grid-dropdown-option-highlighted={i === highlighted}
405
- role="option"
406
- aria-selected={selected}
407
- data-opt-idx={i}
408
- onmousedown={(event) => {
409
- event.preventDefault()
410
- toggleOption(opt)
411
- }}
412
- onmouseenter={() => (highlighted = i)}
413
- >
414
- {#if multiple}
415
- <span class="sv-grid-dropdown-check" aria-hidden="true">
416
- {selected ? '✓' : ''}
417
- </span>
418
- {/if}
419
- {#if opt.color}
420
- <!-- Colored options render as a full chip (pill) so the
421
- dropdown choices match how the value looks in the cell. -->
422
- <span class="sv-grid-dropdown-option-chip" style={colorfulChipStyleInline(opt.color)}>{opt.label}</span>
423
- {:else}
424
- <span class="sv-grid-dropdown-option-label">{opt.label}</span>
425
- {/if}
426
- </div>
427
- {/each}
428
- {/if}
429
-
430
- {#if multiple}
431
- <div class="sv-grid-dropdown-footer">
432
- <button
433
- type="button"
434
- class="sv-grid-dropdown-done"
435
- onmousedown={(event) => event.preventDefault()}
436
- onclick={() => {
437
- closePanel()
438
- onCommit?.()
439
- }}
440
- >Done</button>
441
- </div>
442
- {/if}
443
- </div>
444
- {/if}
445
- </div>
446
-
447
- <style>
448
- /* All colors derive from the grid's host CSS vars so light/dark themes
449
- "just work". Hard fallbacks are kept so the component is still
450
- usable in an unthemed page. */
451
- .sv-grid-dropdown {
452
- position: absolute;
453
- top: 0;
454
- left: 0;
455
- right: 0;
456
- height: 100%;
457
- background: var(--sg-bg, #ffffff);
458
- color: var(--sg-fg, #0f172a);
459
- }
460
-
461
- .sv-grid-dropdown-trigger {
462
- display: flex;
463
- align-items: center;
464
- gap: 6px;
465
- width: 100%;
466
- height: 100%;
467
- min-height: 28px;
468
- padding: 0 8px;
469
- background: var(--sg-bg, #ffffff);
470
- color: var(--sg-fg, #0f172a);
471
- border: 0;
472
- outline: none;
473
- font: inherit;
474
- text-align: left;
475
- cursor: pointer;
476
- box-sizing: border-box;
477
- }
478
- .sv-grid-dropdown-trigger:focus {
479
- outline: 2px solid var(--sg-accent, #2563eb);
480
- outline-offset: -2px;
481
- }
482
-
483
- .sv-grid-dropdown-trigger-chips {
484
- align-items: center;
485
- padding: 4px 8px;
486
- flex-wrap: wrap;
487
- }
488
- .sv-grid-dropdown-chips {
489
- display: inline-flex;
490
- flex-wrap: wrap;
491
- gap: 4px;
492
- flex: 1 1 auto;
493
- min-width: 0;
494
- align-items: center;
495
- }
496
-
497
- .sv-grid-dropdown-label {
498
- flex: 1 1 auto;
499
- min-width: 0;
500
- overflow: hidden;
501
- text-overflow: ellipsis;
502
- white-space: nowrap;
503
- }
504
- .sv-grid-dropdown-caret {
505
- flex: 0 0 auto;
506
- font-size: 10px;
507
- opacity: 0.7;
508
- line-height: 1;
509
- }
510
-
511
- /* Popover sits absolutely below the trigger. The parent
512
- `.sv-grid-cell-editing` has `overflow: visible`, so this can hang
513
- past the row. Pulls its surface color from the grid's header bg
514
- so it reads as a slightly elevated layer on either theme. */
515
- /* Panel is `position: fixed` AND portal'd into document.body via
516
- `use:portalToBody`, so it escapes every ancestor overflow / clip /
517
- transform / stacking context. Coords come from updatePanelPosition(). */
518
- :global(.sv-grid-dropdown-panel) {
519
- overflow-y: auto;
520
- background: var(--sg-header-bg, var(--sg-bg, #ffffff));
521
- color: var(--sg-fg, #0f172a);
522
- border: 1px solid var(--sg-accent, #2563eb);
523
- border-radius: 6px;
524
- box-shadow: 0 12px 28px rgba(0, 0, 0, 0.45);
525
- padding: 4px 0;
526
- font-family: inherit;
527
- }
528
- /* When the option list fits in one panel we want NO scrollbar at all -
529
- * not even a sub-pixel ghost track. `overflow: visible` rules out the
530
- * scrollbar gutter that some browsers still reserve under
531
- * `overflow: auto` when content equals max-height. */
532
- :global(.sv-grid-dropdown-panel.sv-grid-dropdown-panel-fits) {
533
- overflow: visible;
534
- }
535
- :global(.sv-grid-dropdown-option) {
536
- display: flex;
537
- align-items: center;
538
- gap: 8px;
539
- padding: 6px 10px;
540
- cursor: pointer;
541
- user-select: none;
542
- color: var(--sg-fg, #0f172a);
543
- }
544
- :global(.sv-grid-dropdown-option-highlighted) {
545
- background: var(--sg-row-hover-bg, rgba(37, 99, 235, 0.1));
546
- }
547
- :global(.sv-grid-dropdown-option-selected) {
548
- font-weight: 600;
549
- background: var(--sg-selection-bg, rgba(37, 99, 235, 0.15));
550
- }
551
- :global(.sv-grid-dropdown-option-selected.sv-grid-dropdown-option-highlighted) {
552
- background: var(--sg-row-hover-bg, rgba(37, 99, 235, 0.18));
553
- }
554
- :global(.sv-grid-dropdown-option-label) {
555
- flex: 1 1 auto;
556
- min-width: 0;
557
- overflow: hidden;
558
- text-overflow: ellipsis;
559
- white-space: nowrap;
560
- }
561
- :global(.sv-grid-dropdown-check) {
562
- flex: 0 0 16px;
563
- display: inline-flex;
564
- align-items: center;
565
- justify-content: center;
566
- color: var(--sg-accent, #2563eb);
567
- font-weight: 700;
568
- }
569
- :global(.sv-grid-dropdown-swatch) {
570
- flex: 0 0 12px;
571
- width: 12px;
572
- height: 12px;
573
- border-radius: 999px;
574
- border: 1px solid color-mix(in srgb, var(--sg-fg, #0f172a) 25%, transparent);
575
- }
576
- /* Colored option chip. Declared `:global` because the option panel is
577
- portal'd to <body>, where Svelte's scoped classes don't reach. The
578
- per-chip background / border / text color come from an inline style
579
- (see colorfulChipStyleInline) so each option matches its cell chip. */
580
- :global(.sv-grid-dropdown-option-chip) {
581
- display: inline-flex;
582
- align-items: center;
583
- max-width: 100%;
584
- padding: 2px 11px;
585
- border: 1px solid transparent;
586
- border-radius: 999px;
587
- font-size: 0.9em;
588
- font-weight: 600;
589
- line-height: 1.5;
590
- overflow: hidden;
591
- text-overflow: ellipsis;
592
- white-space: nowrap;
593
- }
594
- :global(.sv-grid-dropdown-empty) {
595
- padding: 8px 10px;
596
- color: var(--sg-muted, rgba(15, 23, 42, 0.55));
597
- font-style: italic;
598
- font-size: 0.9em;
599
- }
600
- :global(.sv-grid-dropdown-footer) {
601
- display: flex;
602
- justify-content: flex-end;
603
- padding: 4px 6px;
604
- border-top: 1px solid var(--sg-border, rgba(15, 23, 42, 0.08));
605
- margin-top: 2px;
606
- }
607
- :global(.sv-grid-dropdown-done) {
608
- font-size: 11px;
609
- text-transform: uppercase;
610
- letter-spacing: 0.04em;
611
- color: #fff;
612
- background: var(--sg-accent, #2563eb);
613
- border: 0;
614
- border-radius: 4px;
615
- padding: 4px 10px;
616
- cursor: pointer;
617
- }
618
- :global(.sv-grid-dropdown-done:hover) {
619
- filter: brightness(1.12);
620
- }
621
-
622
- /* Note: option / footer / swatch styles are declared `:global(...)`
623
- above because the panel is portal'd to <body> and Svelte's scoped
624
- class won't survive on children of an element living outside the
625
- component subtree. */
626
-
627
- /* Theme-aware chip badges. Inside the trigger they sit on the cell
628
- background, so we need a tone that contrasts on BOTH themes - a
629
- translucent accent works well in dark mode and reads as a soft
630
- blue pill in light mode. */
631
- .sv-grid-chip {
632
- display: inline-flex;
633
- align-items: center;
634
- gap: 4px;
635
- padding: 2px 8px;
636
- font-size: 0.85em;
637
- line-height: 1.4;
638
- background: color-mix(in srgb, var(--sg-accent, #2563eb) 18%, transparent);
639
- color: var(--sg-fg, #0f172a);
640
- border-radius: 999px;
641
- border: 1px solid color-mix(in srgb, var(--sg-accent, #2563eb) 35%, transparent);
642
- white-space: nowrap;
643
- }
644
- .sv-grid-chip-removable {
645
- padding-right: 2px;
646
- }
647
- .sv-grid-chip-remove {
648
- display: inline-flex;
649
- align-items: center;
650
- justify-content: center;
651
- width: 16px;
652
- height: 16px;
653
- border: 0;
654
- border-radius: 999px;
655
- background: color-mix(in srgb, var(--sg-fg, #0f172a) 18%, transparent);
656
- color: inherit;
657
- font-size: 12px;
658
- line-height: 1;
659
- cursor: pointer;
660
- padding: 0;
661
- }
662
- .sv-grid-chip-remove:hover {
663
- background: rgba(220, 38, 38, 0.7);
664
- color: #fff;
665
- }
666
- </style>
1
+ <script lang="ts">
2
+ /**
3
+ * Internal dropdown / listbox control used by the `list` and `chips` cell
4
+ * editors. We deliberately don't reuse the browser-native `<select>` -
5
+ * the native dropdown can't be styled to match the grid theme, picks up
6
+ * the OS color scheme, and on Windows draws the option list with an
7
+ * opaque white system surface that fights the dark theme.
8
+ *
9
+ * Modes:
10
+ * single - picking an option fires `onChange(value)` and `onCommit()`.
11
+ * multi - toggling fires `onChange(values: array)`; the user
12
+ * presses Enter / clicks "Done" to fire `onCommit()`.
13
+ *
14
+ * Keyboard model:
15
+ * ArrowDown / ArrowUp - move highlight (opens the panel if closed).
16
+ * Enter - single: toggle highlighted + commit.
17
+ * multi: toggle highlighted (stay open).
18
+ * Escape - close + onCancel.
19
+ * Tab - commit and let focus escape.
20
+ */
21
+ import type { CellEditorOption } from './editors/cell-editors'
22
+ import { anchoredRect, portalToBody, popIn, type AnchoredRect } from './popover'
23
+
24
+ type Props = {
25
+ options: ReadonlyArray<CellEditorOption>
26
+ value: unknown
27
+ multiple?: boolean
28
+ placeholder?: string
29
+ /** When provided, the trigger renders as removable chips of the current value(s). */
30
+ renderChipsInTrigger?: boolean
31
+ /** Add a typeahead input at the top of the popover that filters the
32
+ * option list as the user types. Used by the rich-select editor. */
33
+ searchable?: boolean
34
+ /** Focus the trigger and open the panel on mount. True for in-cell editing
35
+ * (you clicked into the cell to edit); set false for form fields, which
36
+ * should stay closed and unfocused until the user acts. Default true. */
37
+ autoOpen?: boolean
38
+ /** Called with the new full value (scalar for single, array for multi). */
39
+ onChange?: (next: unknown) => void
40
+ /** Called when the user finalizes the selection (single pick, Enter, blur with selection). */
41
+ onCommit?: () => void
42
+ /** Called when the user dismisses (Escape, blur with no change). */
43
+ onCancel?: () => void
44
+ }
45
+
46
+ let {
47
+ options,
48
+ value,
49
+ multiple = false,
50
+ placeholder = 'Select…',
51
+ renderChipsInTrigger = false,
52
+ searchable = false,
53
+ autoOpen = true,
54
+ onChange,
55
+ onCommit,
56
+ onCancel,
57
+ }: Props = $props()
58
+
59
+ let searchQuery = $state('')
60
+ const visibleOptions = $derived(
61
+ !searchable || !searchQuery.trim()
62
+ ? options
63
+ : (() => {
64
+ const q = searchQuery.trim().toLowerCase()
65
+ return options.filter((o) => o.label.toLowerCase().includes(q))
66
+ })(),
67
+ )
68
+
69
+ let open = $state(false)
70
+ let highlighted = $state(-1)
71
+ let rootEl: HTMLDivElement | null = $state(null)
72
+ let triggerEl: HTMLButtonElement | null = $state(null)
73
+ let panelEl: HTMLDivElement | null = $state(null)
74
+
75
+ /** Viewport-anchored panel position. We `position: fixed` the panel so it
76
+ * escapes the grid's overflow:hidden scroll container - otherwise the
77
+ * bottom of the list gets clipped by the pager or the grid's footer. */
78
+ let panelRect = $state<AnchoredRect>({
79
+ top: 0,
80
+ left: 0,
81
+ width: 0,
82
+ openUpward: false,
83
+ })
84
+
85
+ const selectedArr = $derived(
86
+ Array.isArray(value)
87
+ ? (value as Array<string | number>)
88
+ : value == null || value === ''
89
+ ? []
90
+ : [value as string | number],
91
+ )
92
+
93
+ const triggerSummary = $derived.by(() => {
94
+ if (selectedArr.length === 0) return placeholder
95
+ if (!multiple) {
96
+ const v = selectedArr[0]!
97
+ const match = options.find((o) => String(o.value) === String(v))
98
+ return match ? match.label : String(v)
99
+ }
100
+ return `${selectedArr.length} selected`
101
+ })
102
+
103
+ /** Color of the single selected option, if any (for colored trigger). */
104
+ const selectedColor = $derived.by(() => {
105
+ if (multiple || selectedArr.length !== 1) return undefined
106
+ const v = selectedArr[0]!
107
+ return options.find((o) => String(o.value) === String(v))?.color
108
+ })
109
+
110
+ function isSelected(opt: CellEditorOption): boolean {
111
+ return selectedArr.some((v) => String(v) === String(opt.value))
112
+ }
113
+
114
+ function toggleOption(opt: CellEditorOption) {
115
+ if (multiple) {
116
+ const exists = isSelected(opt)
117
+ const next = exists
118
+ ? selectedArr.filter((v) => String(v) !== String(opt.value))
119
+ : [...selectedArr, opt.value]
120
+ onChange?.(next)
121
+ } else {
122
+ onChange?.(opt.value)
123
+ open = false
124
+ onCommit?.()
125
+ }
126
+ }
127
+
128
+ function openPanel() {
129
+ if (open) return
130
+ open = true
131
+ // Seed the highlight to the first selected option, or top of the list.
132
+ if (highlighted < 0) {
133
+ const idx = options.findIndex((o) => isSelected(o))
134
+ highlighted = idx >= 0 ? idx : 0
135
+ }
136
+ updatePanelPosition()
137
+ }
138
+
139
+ /** Recompute the panel's fixed-position rect from the trigger. Auto-
140
+ * flips upward when there isn't enough room below the trigger. */
141
+ function updatePanelPosition() {
142
+ if (!triggerEl) return
143
+ // Use the smaller of (option count, 10) for the upward-flip math so
144
+ // a 3-option list doesn't think it needs 320px of headroom.
145
+ const visibleCount = Math.min(options.length, 10)
146
+ const estimatedHeight = visibleCount * 32 + (multiple ? 40 : 0) + 8
147
+ panelRect = anchoredRect(triggerEl.getBoundingClientRect(), {
148
+ estimatedHeight,
149
+ // Preserve the original behavior: anchor to the trigger, no clamping.
150
+ clampHorizontal: false,
151
+ })
152
+ }
153
+
154
+ // Keep the panel anchored as the page scrolls or resizes - without this,
155
+ // scrolling the underlying grid would leave the panel hanging in space.
156
+ $effect(() => {
157
+ if (!open) return
158
+ const reposition = () => updatePanelPosition()
159
+ window.addEventListener('scroll', reposition, true)
160
+ window.addEventListener('resize', reposition)
161
+ return () => {
162
+ window.removeEventListener('scroll', reposition, true)
163
+ window.removeEventListener('resize', reposition)
164
+ }
165
+ })
166
+
167
+ function closePanel() {
168
+ open = false
169
+ highlighted = -1
170
+ }
171
+
172
+ function onKeyDown(event: KeyboardEvent) {
173
+ event.stopPropagation()
174
+ if (event.key === 'Escape') {
175
+ event.preventDefault()
176
+ closePanel()
177
+ onCancel?.()
178
+ return
179
+ }
180
+ if (event.key === 'ArrowDown') {
181
+ event.preventDefault()
182
+ if (!open) {
183
+ openPanel()
184
+ return
185
+ }
186
+ highlighted = Math.min(highlighted + 1, options.length - 1)
187
+ scrollHighlightedIntoView()
188
+ } else if (event.key === 'ArrowUp') {
189
+ event.preventDefault()
190
+ if (!open) {
191
+ openPanel()
192
+ return
193
+ }
194
+ highlighted = Math.max(highlighted - 1, 0)
195
+ scrollHighlightedIntoView()
196
+ } else if (event.key === 'Home') {
197
+ if (!open) return
198
+ event.preventDefault()
199
+ highlighted = 0
200
+ scrollHighlightedIntoView()
201
+ } else if (event.key === 'End') {
202
+ if (!open) return
203
+ event.preventDefault()
204
+ highlighted = options.length - 1
205
+ scrollHighlightedIntoView()
206
+ } else if (event.key === 'Enter') {
207
+ event.preventDefault()
208
+ if (!open) {
209
+ openPanel()
210
+ return
211
+ }
212
+ const opt = options[highlighted]
213
+ if (opt) toggleOption(opt)
214
+ else if (multiple) {
215
+ closePanel()
216
+ onCommit?.()
217
+ }
218
+ } else if (event.key === ' ' && open) {
219
+ event.preventDefault()
220
+ const opt = options[highlighted]
221
+ if (opt) toggleOption(opt)
222
+ } else if (event.key === 'Tab') {
223
+ if (open) closePanel()
224
+ onCommit?.()
225
+ }
226
+ }
227
+
228
+ function scrollHighlightedIntoView() {
229
+ queueMicrotask(() => {
230
+ if (!panelEl) return
231
+ const el = panelEl.querySelector<HTMLElement>(`[data-opt-idx="${highlighted}"]`)
232
+ el?.scrollIntoView({ block: 'nearest' })
233
+ })
234
+ }
235
+
236
+ function onRootBlur(event: FocusEvent) {
237
+ // Defer to the next tick so a click on an option (mousedown → option
238
+ // commits, then blur) doesn't race-cancel the selection.
239
+ const next = event.relatedTarget as Node | null
240
+ if (next && rootEl?.contains(next)) return
241
+ if (open) closePanel()
242
+ onCommit?.()
243
+ }
244
+
245
+ function removeChip(v: string | number, event: MouseEvent) {
246
+ event.preventDefault()
247
+ event.stopPropagation()
248
+ const next = selectedArr.filter((x) => String(x) !== String(v))
249
+ onChange?.(multiple ? next : next[0] ?? null)
250
+ }
251
+
252
+ function focusTrigger(node: HTMLButtonElement) {
253
+ // Form fields (autoOpen=false) stay closed + unfocused until the user acts;
254
+ // in-cell editing auto-focuses + opens to match clicking into a cell.
255
+ if (!autoOpen) return
256
+ node.focus()
257
+ openPanel()
258
+ }
259
+
260
+ /** Close the panel when the user clicks outside both trigger AND
261
+ * panel - `onfocusout` on the dropdown root no longer catches this
262
+ * because the portal'd panel is a sibling of body, not a descendant
263
+ * of rootEl. Wired up only while the panel is open. */
264
+ $effect(() => {
265
+ if (!open) return
266
+ const onDocPointerDown = (event: PointerEvent) => {
267
+ const target = event.target as Node | null
268
+ if (!target) return
269
+ if (rootEl?.contains(target)) return
270
+ if (panelEl?.contains(target)) return
271
+ closePanel()
272
+ onCommit?.()
273
+ }
274
+ document.addEventListener('pointerdown', onDocPointerDown, true)
275
+ return () => document.removeEventListener('pointerdown', onDocPointerDown, true)
276
+ })
277
+
278
+ /** Inline style for a chip with a configured `color`. Mirrors the
279
+ * helper in SvGrid.svelte so colorful chips look identical in the
280
+ * trigger and the in-cell readonly render. */
281
+ function colorfulChipStyleInline(color: string): string {
282
+ return (
283
+ `background: color-mix(in srgb, ${color} 22%, transparent);` +
284
+ `border-color: color-mix(in srgb, ${color} 45%, transparent);` +
285
+ `color: color-mix(in srgb, ${color} 80%, var(--sg-fg, #0f172a));`
286
+ )
287
+ }
288
+ </script>
289
+
290
+ <!-- All pointer/click events are swallowed at the root so they never reach
291
+ the surrounding cell's selection / pointerdown handlers - picking a
292
+ dropdown option must not also toggle cell selection. -->
293
+ <div
294
+ class="sv-grid-dropdown"
295
+ class:sv-grid-dropdown-open={open}
296
+ bind:this={rootEl}
297
+ onfocusout={onRootBlur}
298
+ onclick={(event) => event.stopPropagation()}
299
+ ondblclick={(event) => event.stopPropagation()}
300
+ onpointerdown={(event) => event.stopPropagation()}
301
+ onmousedown={(event) => event.stopPropagation()}
302
+ >
303
+ <button
304
+ type="button"
305
+ class="sv-grid-dropdown-trigger"
306
+ class:sv-grid-dropdown-trigger-chips={renderChipsInTrigger && selectedArr.length > 0}
307
+ aria-haspopup="listbox"
308
+ aria-expanded={open}
309
+ bind:this={triggerEl}
310
+ use:focusTrigger
311
+ onclick={() => (open ? closePanel() : openPanel())}
312
+ onkeydown={onKeyDown}
313
+ >
314
+ {#if renderChipsInTrigger && selectedArr.length > 0}
315
+ <span class="sv-grid-dropdown-chips">
316
+ {#each selectedArr as v (String(v))}
317
+ {@const opt = options.find((o) => String(o.value) === String(v))}
318
+ <span
319
+ class="sv-grid-chip sv-grid-chip-removable"
320
+ style={opt?.color ? colorfulChipStyleInline(opt.color) : ''}
321
+ >
322
+ {opt ? opt.label : String(v)}
323
+ <!-- A <button> can't be nested inside the trigger <button>; this is a
324
+ pointer-only affordance (tabindex -1), so a role="button" span is
325
+ valid HTML and preserves identical behaviour. -->
326
+ <!-- svelte-ignore a11y_no_static_element_interactions a11y_click_events_have_key_events -->
327
+ <span
328
+ class="sv-grid-chip-remove"
329
+ role="button"
330
+ aria-label="Remove {opt ? opt.label : String(v)}"
331
+ tabindex={-1}
332
+ onmousedown={(event) => event.preventDefault()}
333
+ onclick={(event) => removeChip(v, event)}
334
+ >×</span>
335
+ </span>
336
+ {/each}
337
+ </span>
338
+ {:else if !multiple && selectedArr.length === 1 && selectedColor}
339
+ <!-- Single-select list whose chosen option carries a color → show it
340
+ as a colored chip inside the trigger, matching how the cell
341
+ renders when not in edit mode. -->
342
+ <span class="sv-grid-chip" style={colorfulChipStyleInline(selectedColor)}>
343
+ {triggerSummary}
344
+ </span>
345
+ {:else}
346
+ <span class="sv-grid-dropdown-label">{triggerSummary}</span>
347
+ {/if}
348
+ <span class="sv-grid-dropdown-caret" aria-hidden="true">▾</span>
349
+ </button>
350
+
351
+ {#if open}
352
+ <!-- Sizing rule:
353
+ - ≤ 10 options → no max-height. The panel grows to its content,
354
+ overflow:auto stays inert, and no scrollbar is ever drawn.
355
+ This matters because measuring "10 × 32px" against the real
356
+ rendered option height (which depends on font + line-height)
357
+ rounds inconsistently across themes and used to produce a
358
+ 1-pixel scrollbar on lists as short as 3 items.
359
+ - > 10 options → cap at 10 items + Done-footer chrome so the
360
+ panel never overflows the viewport, and the scrollbar appears.
361
+ Panel is `position: fixed` + portal'd to <body> so it escapes
362
+ the grid's overflow:hidden scroll container. -->
363
+ {@const needsScroll = options.length > 10}
364
+ {@const panelMax = needsScroll ? 10 * 32 + (multiple ? 40 : 0) + 8 : null}
365
+ <div
366
+ class="sv-grid-dropdown-panel"
367
+ class:sv-grid-dropdown-panel-fits={!needsScroll}
368
+ role="listbox"
369
+ aria-multiselectable={multiple}
370
+ bind:this={panelEl}
371
+ use:portalToBody
372
+ use:popIn={{ up: panelRect.openUpward }}
373
+ style:position="fixed"
374
+ style:top={`${panelRect.top}px`}
375
+ style:left={`${panelRect.left}px`}
376
+ style:width={`${panelRect.width}px`}
377
+ style:max-height={panelMax !== null ? `${panelMax}px` : null}
378
+ style:z-index="2147483647"
379
+ onpointerdown={(event) => event.stopPropagation()}
380
+ onmousedown={(event) => event.stopPropagation()}
381
+ onclick={(event) => event.stopPropagation()}
382
+ >
383
+ {#if searchable}
384
+ <input
385
+ type="search"
386
+ class="sv-grid-dropdown-search"
387
+ placeholder="Search…"
388
+ bind:value={searchQuery}
389
+ onmousedown={(event) => event.stopPropagation()}
390
+ onclick={(event) => event.stopPropagation()}
391
+ onkeydown={(event) => {
392
+ if (event.key === 'Escape') { event.preventDefault(); open = false; onCancel?.() }
393
+ }}
394
+ />
395
+ {/if}
396
+ {#if visibleOptions.length === 0}
397
+ <div class="sv-grid-dropdown-empty">{searchable && searchQuery ? `No matches for "${searchQuery}"` : 'No options'}</div>
398
+ {:else}
399
+ {#each visibleOptions as opt, i (String(opt.value))}
400
+ {@const selected = isSelected(opt)}
401
+ <div
402
+ class="sv-grid-dropdown-option"
403
+ class:sv-grid-dropdown-option-selected={selected}
404
+ class:sv-grid-dropdown-option-highlighted={i === highlighted}
405
+ role="option"
406
+ aria-selected={selected}
407
+ data-opt-idx={i}
408
+ onmousedown={(event) => {
409
+ event.preventDefault()
410
+ toggleOption(opt)
411
+ }}
412
+ onmouseenter={() => (highlighted = i)}
413
+ >
414
+ {#if multiple}
415
+ <span class="sv-grid-dropdown-check" aria-hidden="true">
416
+ {selected ? '✓' : ''}
417
+ </span>
418
+ {/if}
419
+ {#if opt.color}
420
+ <!-- Colored options render as a full chip (pill) so the
421
+ dropdown choices match how the value looks in the cell. -->
422
+ <span class="sv-grid-dropdown-option-chip" style={colorfulChipStyleInline(opt.color)}>{opt.label}</span>
423
+ {:else}
424
+ <span class="sv-grid-dropdown-option-label">{opt.label}</span>
425
+ {/if}
426
+ </div>
427
+ {/each}
428
+ {/if}
429
+
430
+ {#if multiple}
431
+ <div class="sv-grid-dropdown-footer">
432
+ <button
433
+ type="button"
434
+ class="sv-grid-dropdown-done"
435
+ onmousedown={(event) => event.preventDefault()}
436
+ onclick={() => {
437
+ closePanel()
438
+ onCommit?.()
439
+ }}
440
+ >Done</button>
441
+ </div>
442
+ {/if}
443
+ </div>
444
+ {/if}
445
+ </div>
446
+
447
+ <style>
448
+ /* All colors derive from the grid's host CSS vars so light/dark themes
449
+ "just work". Hard fallbacks are kept so the component is still
450
+ usable in an unthemed page. */
451
+ .sv-grid-dropdown {
452
+ position: absolute;
453
+ top: 0;
454
+ left: 0;
455
+ right: 0;
456
+ height: 100%;
457
+ background: var(--sg-bg, #ffffff);
458
+ color: var(--sg-fg, #0f172a);
459
+ }
460
+
461
+ .sv-grid-dropdown-trigger {
462
+ display: flex;
463
+ align-items: center;
464
+ gap: 6px;
465
+ width: 100%;
466
+ height: 100%;
467
+ min-height: 28px;
468
+ padding: 0 8px;
469
+ background: var(--sg-bg, #ffffff);
470
+ color: var(--sg-fg, #0f172a);
471
+ border: 0;
472
+ outline: none;
473
+ font: inherit;
474
+ text-align: left;
475
+ cursor: pointer;
476
+ box-sizing: border-box;
477
+ }
478
+ .sv-grid-dropdown-trigger:focus {
479
+ outline: 2px solid var(--sg-accent, #2563eb);
480
+ outline-offset: -2px;
481
+ }
482
+
483
+ .sv-grid-dropdown-trigger-chips {
484
+ align-items: center;
485
+ padding: 4px 8px;
486
+ flex-wrap: wrap;
487
+ }
488
+ .sv-grid-dropdown-chips {
489
+ display: inline-flex;
490
+ flex-wrap: wrap;
491
+ gap: 4px;
492
+ flex: 1 1 auto;
493
+ min-width: 0;
494
+ align-items: center;
495
+ }
496
+
497
+ .sv-grid-dropdown-label {
498
+ flex: 1 1 auto;
499
+ min-width: 0;
500
+ overflow: hidden;
501
+ text-overflow: ellipsis;
502
+ white-space: nowrap;
503
+ }
504
+ .sv-grid-dropdown-caret {
505
+ flex: 0 0 auto;
506
+ font-size: 10px;
507
+ opacity: 0.7;
508
+ line-height: 1;
509
+ }
510
+
511
+ /* Popover sits absolutely below the trigger. The parent
512
+ `.sv-grid-cell-editing` has `overflow: visible`, so this can hang
513
+ past the row. Pulls its surface color from the grid's header bg
514
+ so it reads as a slightly elevated layer on either theme. */
515
+ /* Panel is `position: fixed` AND portal'd into document.body via
516
+ `use:portalToBody`, so it escapes every ancestor overflow / clip /
517
+ transform / stacking context. Coords come from updatePanelPosition(). */
518
+ :global(.sv-grid-dropdown-panel) {
519
+ overflow-y: auto;
520
+ background: var(--sg-header-bg, var(--sg-bg, #ffffff));
521
+ color: var(--sg-fg, #0f172a);
522
+ border: 1px solid var(--sg-accent, #2563eb);
523
+ border-radius: 6px;
524
+ box-shadow: 0 12px 28px rgba(0, 0, 0, 0.45);
525
+ padding: 4px 0;
526
+ font-family: inherit;
527
+ }
528
+ /* When the option list fits in one panel we want NO scrollbar at all -
529
+ * not even a sub-pixel ghost track. `overflow: visible` rules out the
530
+ * scrollbar gutter that some browsers still reserve under
531
+ * `overflow: auto` when content equals max-height. */
532
+ :global(.sv-grid-dropdown-panel.sv-grid-dropdown-panel-fits) {
533
+ overflow: visible;
534
+ }
535
+ :global(.sv-grid-dropdown-option) {
536
+ display: flex;
537
+ align-items: center;
538
+ gap: 8px;
539
+ padding: 6px 10px;
540
+ cursor: pointer;
541
+ user-select: none;
542
+ color: var(--sg-fg, #0f172a);
543
+ }
544
+ :global(.sv-grid-dropdown-option-highlighted) {
545
+ background: var(--sg-row-hover-bg, rgba(37, 99, 235, 0.1));
546
+ }
547
+ :global(.sv-grid-dropdown-option-selected) {
548
+ font-weight: 600;
549
+ background: var(--sg-selection-bg, rgba(37, 99, 235, 0.15));
550
+ }
551
+ :global(.sv-grid-dropdown-option-selected.sv-grid-dropdown-option-highlighted) {
552
+ background: var(--sg-row-hover-bg, rgba(37, 99, 235, 0.18));
553
+ }
554
+ :global(.sv-grid-dropdown-option-label) {
555
+ flex: 1 1 auto;
556
+ min-width: 0;
557
+ overflow: hidden;
558
+ text-overflow: ellipsis;
559
+ white-space: nowrap;
560
+ }
561
+ :global(.sv-grid-dropdown-check) {
562
+ flex: 0 0 16px;
563
+ display: inline-flex;
564
+ align-items: center;
565
+ justify-content: center;
566
+ color: var(--sg-accent, #2563eb);
567
+ font-weight: 700;
568
+ }
569
+ :global(.sv-grid-dropdown-swatch) {
570
+ flex: 0 0 12px;
571
+ width: 12px;
572
+ height: 12px;
573
+ border-radius: 999px;
574
+ border: 1px solid color-mix(in srgb, var(--sg-fg, #0f172a) 25%, transparent);
575
+ }
576
+ /* Colored option chip. Declared `:global` because the option panel is
577
+ portal'd to <body>, where Svelte's scoped classes don't reach. The
578
+ per-chip background / border / text color come from an inline style
579
+ (see colorfulChipStyleInline) so each option matches its cell chip. */
580
+ :global(.sv-grid-dropdown-option-chip) {
581
+ display: inline-flex;
582
+ align-items: center;
583
+ max-width: 100%;
584
+ padding: 2px 11px;
585
+ border: 1px solid transparent;
586
+ border-radius: 999px;
587
+ font-size: 0.9em;
588
+ font-weight: 600;
589
+ line-height: 1.5;
590
+ overflow: hidden;
591
+ text-overflow: ellipsis;
592
+ white-space: nowrap;
593
+ }
594
+ :global(.sv-grid-dropdown-empty) {
595
+ padding: 8px 10px;
596
+ color: var(--sg-muted, rgba(15, 23, 42, 0.55));
597
+ font-style: italic;
598
+ font-size: 0.9em;
599
+ }
600
+ :global(.sv-grid-dropdown-footer) {
601
+ display: flex;
602
+ justify-content: flex-end;
603
+ padding: 4px 6px;
604
+ border-top: 1px solid var(--sg-border, rgba(15, 23, 42, 0.08));
605
+ margin-top: 2px;
606
+ }
607
+ :global(.sv-grid-dropdown-done) {
608
+ font-size: 11px;
609
+ text-transform: uppercase;
610
+ letter-spacing: 0.04em;
611
+ color: #fff;
612
+ background: var(--sg-accent, #2563eb);
613
+ border: 0;
614
+ border-radius: 4px;
615
+ padding: 4px 10px;
616
+ cursor: pointer;
617
+ }
618
+ :global(.sv-grid-dropdown-done:hover) {
619
+ filter: brightness(1.12);
620
+ }
621
+
622
+ /* Note: option / footer / swatch styles are declared `:global(...)`
623
+ above because the panel is portal'd to <body> and Svelte's scoped
624
+ class won't survive on children of an element living outside the
625
+ component subtree. */
626
+
627
+ /* Theme-aware chip badges. Inside the trigger they sit on the cell
628
+ background, so we need a tone that contrasts on BOTH themes - a
629
+ translucent accent works well in dark mode and reads as a soft
630
+ blue pill in light mode. */
631
+ .sv-grid-chip {
632
+ display: inline-flex;
633
+ align-items: center;
634
+ gap: 4px;
635
+ padding: 2px 8px;
636
+ font-size: 0.85em;
637
+ line-height: 1.4;
638
+ background: color-mix(in srgb, var(--sg-accent, #2563eb) 18%, transparent);
639
+ color: var(--sg-fg, #0f172a);
640
+ border-radius: 999px;
641
+ border: 1px solid color-mix(in srgb, var(--sg-accent, #2563eb) 35%, transparent);
642
+ white-space: nowrap;
643
+ }
644
+ .sv-grid-chip-removable {
645
+ padding-right: 2px;
646
+ }
647
+ .sv-grid-chip-remove {
648
+ display: inline-flex;
649
+ align-items: center;
650
+ justify-content: center;
651
+ width: 16px;
652
+ height: 16px;
653
+ border: 0;
654
+ border-radius: 999px;
655
+ background: color-mix(in srgb, var(--sg-fg, #0f172a) 18%, transparent);
656
+ color: inherit;
657
+ font-size: 12px;
658
+ line-height: 1;
659
+ cursor: pointer;
660
+ padding: 0;
661
+ }
662
+ .sv-grid-chip-remove:hover {
663
+ background: rgba(220, 38, 38, 0.7);
664
+ color: #fff;
665
+ }
666
+ </style>