@widgetic/design-system 0.5.31 → 0.5.32

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 (33) hide show
  1. package/dist/components/EmptyState.svelte +5 -2
  2. package/dist/components/modals/ActionModal.svelte +10 -9
  3. package/dist/components/modals/README.md +1 -1
  4. package/dist/components/shell/SettingsDialog.svelte +53 -10
  5. package/dist/components/shell/WidgetRow.svelte +8 -1
  6. package/dist/components/shell/WidgetRow.svelte.d.ts +2 -0
  7. package/dist/components/toast/ToasterModal.svelte +54 -10
  8. package/dist/components/toast/ToasterModal.svelte.d.ts +6 -1
  9. package/dist/components/toast/toastDismissCountdown.d.ts +5 -0
  10. package/dist/components/toast/toastDismissCountdown.js +47 -0
  11. package/dist/components/toast/toastDismissCountdownPayload.d.ts +16 -0
  12. package/dist/components/toast/toastDismissCountdownPayload.js +24 -0
  13. package/dist/components/ui/dialog/DialogLayerSync.svelte +38 -0
  14. package/dist/components/ui/dialog/DialogLayerSync.svelte.d.ts +8 -0
  15. package/dist/components/ui/dialog/dialog-content.svelte +63 -20
  16. package/dist/components/ui/dialog/dialog-content.svelte.d.ts +1 -0
  17. package/dist/components/ui/dialog/dialog-overlay.svelte +24 -20
  18. package/dist/components/ui/dialog/overlay-layer-context.d.ts +8 -0
  19. package/dist/components/ui/dialog/overlay-layer-context.js +1 -0
  20. package/dist/components/ui/drawer/drawer-content.svelte +25 -1
  21. package/dist/components/ui/drawer/drawer-overlay.svelte +32 -5
  22. package/dist/components/ui/dropdown-menu/dropdown-menu-content.svelte +3 -1
  23. package/dist/components/ui/dropdown-menu/dropdown-menu-sub-content.svelte +3 -1
  24. package/dist/components/ui/hover-card/hover-card-content.svelte +3 -1
  25. package/dist/components/ui/popover/popover-content.svelte +3 -1
  26. package/dist/components/ui/select/select-content.svelte +3 -1
  27. package/dist/components/ui/tooltip/tooltip-content.svelte +3 -1
  28. package/dist/styles/global.css +33 -61
  29. package/dist/utils/overlayLayerStack.d.ts +54 -0
  30. package/dist/utils/overlayLayerStack.js +89 -0
  31. package/dist/utils/overlayMotion.d.ts +14 -46
  32. package/dist/utils/overlayMotion.js +36 -63
  33. package/package.json +1 -1
@@ -72,11 +72,14 @@
72
72
  if (height === '100%') return `min-height: 0; height: 100%; ${extra}`;
73
73
  return `height: ${height}; ${extra}`;
74
74
  });
75
+
76
+ const containerOverflow = $derived(height === 'auto' ? 'overflow-visible' : 'overflow-hidden');
75
77
  </script>
76
78
 
77
79
  <div
78
80
  class={cn(
79
- 'empty-state-container flex min-h-0 w-full items-center justify-center overflow-hidden',
81
+ 'empty-state-container flex min-h-0 w-full items-center justify-center',
82
+ containerOverflow,
80
83
  className
81
84
  )}
82
85
  style={containerStyle}
@@ -95,7 +98,7 @@
95
98
  {/if}
96
99
 
97
100
  <div class="flex w-full min-w-0 flex-col gap-1">
98
- <p class="text-body text-muted-foreground" style={titleStyle}>{message}</p>
101
+ <p class="text-body text-foreground font-medium" style={titleStyle}>{message}</p>
99
102
  {#if description}
100
103
  <p class="text-body text-muted-foreground">{description}</p>
101
104
  {/if}
@@ -1,6 +1,6 @@
1
1
  <script lang="ts">
2
2
  // Svelte imports
3
- import { createEventDispatcher, onMount } from 'svelte';
3
+ import { createEventDispatcher, onDestroy, onMount } from 'svelte';
4
4
  const dispatch = createEventDispatcher();
5
5
 
6
6
  // Local imports
@@ -42,15 +42,20 @@
42
42
  /* INTERNAL STATE */
43
43
  let confirmResult: string = '';
44
44
  let isInitialized = false;
45
+ let isComponentDestroyed = false;
45
46
 
46
47
  // Only initialize once mounted
47
48
  onMount(() => {
48
49
  isInitialized = true;
49
50
  });
50
51
 
52
+ onDestroy(() => {
53
+ isComponentDestroyed = true;
54
+ });
55
+
51
56
  // Initialize modalData with our current props if not provided externally
52
57
  // Only do this when modal is actually open
53
- $: if (isOpen && isInitialized && modalData === null) {
58
+ $: if (!isComponentDestroyed && isOpen && isInitialized && modalData === null) {
54
59
  modalData = {
55
60
  items,
56
61
  title,
@@ -62,7 +67,6 @@
62
67
  };
63
68
  }
64
69
 
65
- // Check if buttons are present
66
70
  $: hasButtons = cancelLabel || confirmLabel;
67
71
 
68
72
  function handleClose(event: Event) {
@@ -72,15 +76,17 @@
72
76
  }
73
77
 
74
78
  async function handleConfirm() {
79
+ if (isComponentDestroyed) return;
75
80
  // call the onConfirm handler
76
81
  let result = await onConfirm();
82
+ if (isComponentDestroyed) return;
77
83
  confirmResult = result || '';
78
84
 
79
85
  // Dispatch a confirmation event with all items
80
86
  dispatch('confirm', { items });
81
87
 
82
88
  // Callers that show an error inside the dialog set closeOnConfirm to false.
83
- if (closeOnConfirm) isOpen = false;
89
+ if (closeOnConfirm && !isComponentDestroyed) isOpen = false;
84
90
  }
85
91
 
86
92
  // Support for restoring modal state
@@ -109,11 +115,6 @@
109
115
  }
110
116
  }
111
117
 
112
- // Only log when modal is actually open
113
- $: if (isOpen && isInitialized && items && items.length > 0 && showLogs) {
114
- // console.log('Items in open modal:', items);
115
- // console.log('First item name:', items[0]?.name);
116
- }
117
118
  </script>
118
119
 
119
120
  <BaseModal
@@ -126,7 +126,7 @@ another language passes its own words and nothing else changes.
126
126
  | `NewItemDialog` | `messages`: `invalidTitle`, `required`, `invalidCharacters`, `tooLong` (`{max}`). The English defaults are built from `itemType` ("Folder name is required"). |
127
127
  | `Breadcrumbs` | `backLabel`, `forwardLabel`, `rootLabel`, `breadcrumbLabel` |
128
128
  | `PDFViewer` | `loadingLabel`, `failedLabel`, `pageLabel` (`{page}`, `{total}`), `previousPageLabel`, `nextPageLabel` |
129
- | `ToasterModal` (`components/toast`) | `containerAriaLabel` (the region that holds the toasts, "Notifications"; the library adds the key that moves focus to it), `closeButtonAriaLabel` ("Close toast"). The title and description of a toast are the words of whoever calls `showToast`. |
129
+ | `ToasterModal` (`components/toast`) | `containerAriaLabel` (the region that holds the toasts, "Notifications"; the library adds the key that moves focus to it), `closeButtonAriaLabel` ("Close toast"). The title and description of a toast are the words of whoever calls `showToast`. Every toast uses the unstyled Widgetic pill (`toast.success` and `showToast` alike). Pointer hover pauses dismiss; leaving the stack or blurring keyboard focus restarts the full duration. |
130
130
 
131
131
  A key of `messages` that is left out keeps its English text. A message can hold the values named next to it in
132
132
  curly braces: `tooLong: 'Der Name darf höchstens {max} Zeichen haben'`.
@@ -31,6 +31,18 @@
31
31
  import SettingsNav from './SettingsNav.svelte';
32
32
  import type { SettingsNavGroup } from './settings-nav-types.js';
33
33
  import { createNestedModalTracker } from './nested-modal-guard.js';
34
+ import { onDestroy, setContext } from 'svelte';
35
+ import { claimOverlayLayerPair } from '../../utils/overlayLayerStack.js';
36
+ import {
37
+ OVERLAY_LAYER_CONTEXT_KEY,
38
+ type OverlayLayerContext
39
+ } from '../ui/dialog/overlay-layer-context.js';
40
+ import DialogLayerSync from '../ui/dialog/DialogLayerSync.svelte';
41
+ import {
42
+ overlayReducedMotionClasses,
43
+ overlayScrimFadeTransition
44
+ } from '../../utils/overlayMotion.js';
45
+ import { fade } from 'svelte/transition';
34
46
 
35
47
  let {
36
48
  open = $bindable(false),
@@ -53,6 +65,22 @@
53
65
 
54
66
  // A modal a pane opens (ActionModal, RenameDialog, ...) is drawn outside this dialog: while one is open, a click or
55
67
  // Escape in it must not close the settings dialog, and the focus trap must let its fields take the focus.
68
+ const overlayLayerContext: OverlayLayerContext = {
69
+ ensureLayer() {
70
+ if (!this.layer) {
71
+ this.layer = claimOverlayLayerPair();
72
+ }
73
+ return this.layer;
74
+ },
75
+ releaseLayer() {
76
+ this.layer?.release();
77
+ this.layer = null;
78
+ },
79
+ layer: null
80
+ };
81
+ setContext(OVERLAY_LAYER_CONTEXT_KEY, overlayLayerContext);
82
+ onDestroy(() => overlayLayerContext.releaseLayer());
83
+
56
84
  const nestedModalTracker = createNestedModalTracker();
57
85
  const nestedModalOpen = $derived($modalState.isOpen);
58
86
  $effect(() => {
@@ -119,20 +147,32 @@
119
147
  <!-- The scrim is the shared one of every overlay (muted foreground at 80%, 3px blur), set by the dialog overlay itself -->
120
148
  <Dialog.Overlay />
121
149
  <DialogPrimitive.Content
122
- class={cn(
123
- 'data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 border-border bg-background duration-base fixed z-50 flex overflow-hidden border',
124
- 'inset-0 h-full max-h-none w-full rounded-none',
125
- // Centred with auto margins, not with a translate: a CSS transform would make this box the containing block
126
- // of every `position: fixed` element inside a pane (a legacy confirm dialog would be drawn, and clipped, inside it).
127
- 'lg:h-settings-modal lg:w-settings-modal lg:rounded-panel lg:m-auto lg:max-h-[calc(100vh-2rem)] lg:max-w-[calc(100vw-2rem)]',
128
- // bits-ui's inline `contain: layout style` wins over a `style` prop, so the override has to be `!important`.
129
- 'contain-none!',
130
- className
131
- )}
150
+ forceMount
132
151
  aria-describedby={description || descriptionSlot ? 'settings-dialog-description' : undefined}
133
152
  trapFocus={!nestedModalOpen}
134
153
  onEscapeKeydown={handleEscapeKeydown}
154
+ class={className}
135
155
  >
156
+ {#snippet child({ props, open })}
157
+ <DialogLayerSync {open} {overlayLayerContext} />
158
+ {#if open}
159
+ <div
160
+ {...props}
161
+ data-widgetic-overlay="dialog-panel"
162
+ style:z-index|important={overlayLayerContext.ensureLayer().scrimZ + 1}
163
+ class={cn(
164
+ 'border-border bg-background fixed flex overflow-hidden border',
165
+ overlayReducedMotionClasses,
166
+ 'inset-0 h-full max-h-none w-full rounded-none',
167
+ // Centred with auto margins, not with a translate: a CSS transform would make this box the containing block
168
+ // of every `position: fixed` element inside a pane (a legacy confirm dialog would be drawn, and clipped, inside it).
169
+ 'lg:h-settings-modal lg:w-settings-modal lg:rounded-panel lg:m-auto lg:max-h-[calc(100vh-2rem)] lg:max-w-[calc(100vw-2rem)]',
170
+ 'contain-none!',
171
+ className
172
+ )}
173
+ in:fade|global={overlayScrimFadeTransition()}
174
+ out:fade|global={overlayScrimFadeTransition()}
175
+ >
136
176
  <div class="flex min-h-0 min-w-0 flex-1 flex-col lg:flex-row">
137
177
  <aside
138
178
  class="border-border bg-sidebar flex w-full shrink-0 flex-col border-b p-3 lg:w-64 lg:border-e lg:border-b-0"
@@ -184,6 +224,9 @@
184
224
  <span class="sr-only">{closeLabel}</span>
185
225
  </DialogPrimitive.Close>
186
226
  </div>
227
+ </div>
228
+ {/if}
229
+ {/snippet}
187
230
  </DialogPrimitive.Content>
188
231
  </Dialog.Portal>
189
232
  </Dialog.Root>
@@ -37,6 +37,7 @@
37
37
  meta = '',
38
38
  showBadge = true,
39
39
  badgeLabel = 'Published',
40
+ badgeTone = 'published',
40
41
  selected = false,
41
42
  loading = false,
42
43
  visualState = undefined,
@@ -49,6 +50,8 @@
49
50
  meta?: string;
50
51
  showBadge?: boolean;
51
52
  badgeLabel?: string;
53
+ /** Figma 55:441 — Published uses the green pill; Draft is plain neutral text without a dot. */
54
+ badgeTone?: 'published' | 'draft';
52
55
  selected?: boolean;
53
56
  loading?: boolean;
54
57
  visualState?: WidgetRowVisualState;
@@ -109,7 +112,11 @@
109
112
  </div>
110
113
 
111
114
  {#if showBadge}
112
- <Badge variant="secondary" showDot class="shrink-0 max-sm:hidden">{badgeLabel}</Badge>
115
+ {#if badgeTone === 'draft'}
116
+ <span class="text-caption text-muted-foreground shrink-0 max-sm:hidden">{badgeLabel}</span>
117
+ {:else}
118
+ <Badge variant="secondary" showDot class="shrink-0 max-sm:hidden">{badgeLabel}</Badge>
119
+ {/if}
113
120
  {/if}
114
121
 
115
122
  {#if actions}
@@ -65,6 +65,8 @@ type $$ComponentProps = HTMLAttributes<HTMLDivElement> & {
65
65
  meta?: string;
66
66
  showBadge?: boolean;
67
67
  badgeLabel?: string;
68
+ /** Figma 55:441 — Published uses the green pill; Draft is plain neutral text without a dot. */
69
+ badgeTone?: 'published' | 'draft';
68
70
  selected?: boolean;
69
71
  loading?: boolean;
70
72
  visualState?: WidgetRowVisualState;
@@ -5,7 +5,11 @@
5
5
  import IconExclamationCircle from '@tabler/icons-svelte/icons/exclamation-circle';
6
6
  import IconInfoCircle from '@tabler/icons-svelte/icons/info-circle';
7
7
  import { toastLookupRoots } from './toasterRoots';
8
- import { toastEnterDurationMs, toastExitDurationMs } from '../../utils/toastMotion.js';
8
+ import { toastEnterDurationMs, toastExitDurationMs, toastMaxWidthClass } from '../../utils/toastMotion.js';
9
+ import {
10
+ holdActiveToastsDuringKeyboardFocus,
11
+ restartDismissCountdownForActiveToasts
12
+ } from './toastDismissCountdown';
9
13
 
10
14
  type ToastTypes = 'success' | 'error' | 'warning' | 'info' | 'loading';
11
15
 
@@ -24,9 +28,14 @@
24
28
 
25
29
  let toastMainClass = 'toast-modal';
26
30
 
31
+ /**
32
+ * Show one centered pill toast: a single message line (no separate title/description in the UI).
33
+ * `message` is the sentence users see. Legacy callers may still pass `options.description`; it is
34
+ * only used when `message` is empty, otherwise ignored so the toast stays one line.
35
+ */
27
36
  export function showToast(
28
37
  type: string = 'success',
29
- title: string,
38
+ message: string,
30
39
  options: Record<string, unknown> | null = null
31
40
  ) {
32
41
  if (options === null) {
@@ -34,20 +43,30 @@
34
43
  }
35
44
 
36
45
  const duration = (options?.duration as number | undefined) || defaultDuration;
46
+ const descriptionText =
47
+ typeof options.description === 'string' ? options.description.trim() : '';
48
+ const messageText = typeof message === 'string' ? message.trim() : '';
49
+ let line = messageText || descriptionText;
50
+ if (messageText && descriptionText && !messageText.includes(descriptionText)) {
51
+ line = `${messageText} — ${descriptionText}`;
52
+ }
37
53
 
38
54
  const toneIcon = toneIcons[type as ToastTypes];
39
55
  if (toneIcon) options.icon = toneIcon;
40
56
 
57
+ const { description: _ignoredDescription, ...toastOptions } = options;
58
+
41
59
  let toastKey: ToastTypes = type as ToastTypes;
42
60
  if (typeof toast[toastKey] !== 'function') {
43
61
  console.warn(`[showToast] Unknown toast type "${type}", showing it as info.`);
44
62
  toastKey = 'info';
45
63
  }
46
64
 
47
- return toast[toastKey](title, {
48
- ...options,
65
+ return toast[toastKey](line, {
66
+ ...toastOptions,
49
67
  duration,
50
- unstyled: true
68
+ unstyled: true,
69
+ description: undefined
51
70
  });
52
71
  }
53
72
  </script>
@@ -64,6 +83,25 @@
64
83
  onMount(() => registerToasterRoot(rootMarker.getRootNode() as Document | ShadowRoot));
65
84
 
66
85
  const textDirection = useTextDirection();
86
+
87
+ let keyboardFocusWithinToastStack = 0;
88
+
89
+ function handleToasterMouseLeave() {
90
+ // Run after svelte-sonner clears its expanded/pause state so the fresh duration sticks.
91
+ queueMicrotask(() => restartDismissCountdownForActiveToasts(defaultDuration));
92
+ }
93
+
94
+ function handleToasterFocusIn() {
95
+ keyboardFocusWithinToastStack += 1;
96
+ holdActiveToastsDuringKeyboardFocus(defaultDuration);
97
+ }
98
+
99
+ function handleToasterFocusOut() {
100
+ keyboardFocusWithinToastStack = Math.max(0, keyboardFocusWithinToastStack - 1);
101
+ if (keyboardFocusWithinToastStack === 0) {
102
+ queueMicrotask(() => restartDismissCountdownForActiveToasts(defaultDuration));
103
+ }
104
+ }
67
105
  </script>
68
106
 
69
107
  <span hidden bind:this={rootMarker}></span>
@@ -74,20 +112,26 @@
74
112
  {containerAriaLabel}
75
113
  {closeButtonAriaLabel}
76
114
  closeButton
115
+ onmouseleave={handleToasterMouseLeave}
116
+ onfocusin={handleToasterFocusIn}
117
+ onfocusout={handleToasterFocusOut}
77
118
  toastOptions={{
78
119
  duration: defaultDuration,
120
+ unstyled: true,
79
121
  classes: {
80
122
  toast:
81
123
  toastMainClass +
82
- ' !flex !min-w-0 !max-w-[420px] !flex-wrap !items-center !gap-2 !rounded-xl !border !px-4 !py-2.5 !pe-9 !text-sm !font-medium !shadow-none [&>[data-icon]]:!hidden',
83
- title: toastMainClass + '-title !text-inherit',
84
- description: toastMainClass + '-description !text-inherit/90 !text-sm',
124
+ ` !relative !flex !w-max !min-w-0 ${toastMaxWidthClass} !flex-nowrap !items-center !gap-2 !rounded-xl !border !px-4 !py-2.5 !pe-9 !text-sm !font-medium !shadow-none [&>[data-icon]]:!hidden [&>[data-content]]:!min-w-0 [&>[data-content]]:!flex-1 [&>[data-content]]:!truncate`,
125
+ title:
126
+ toastMainClass +
127
+ '-title !min-w-0 !flex-1 !truncate !whitespace-nowrap !text-inherit',
128
+ description: toastMainClass + '-description !hidden',
85
129
  actionButton:
86
130
  '!h-8 !rounded-lg !border !border-current/30 !bg-transparent !px-2 !text-label !text-inherit hover:!bg-current/15',
87
131
  cancelButton: '',
88
132
  closeButton:
89
133
  toastMainClass +
90
- '-close-button !absolute !end-1.5 !top-1/2 !-translate-y-1/2 !flex !size-7 !items-center justify-center !rounded-full !border-0 !bg-transparent !p-0 !text-inherit !transition-colors hover:!bg-current/20 focus-visible:!bg-current/20 focus-visible:!outline-hidden [&_svg]:!size-3.5 [&_svg]:!stroke-2',
134
+ '-close-button !absolute !end-1.5 !top-1/2 !z-10 !-translate-y-1/2 !flex !size-7 !shrink-0 !items-center !justify-center !rounded-full !border-0 !bg-transparent !p-0 !text-inherit !transition-colors hover:!bg-current/20 focus-visible:!bg-current/20 focus-visible:!outline-hidden [&_svg]:!size-3.5 [&_svg]:!stroke-2',
91
135
  info: '!border-border !bg-popover !text-popover-foreground',
92
136
  success:
93
137
  '!border-transparent !bg-toast-green !text-inverse-foreground [&>[data-icon]]:!hidden',
@@ -100,5 +144,5 @@
100
144
  visibleToasts={3}
101
145
  offset="1rem"
102
146
  class="{className} toast-modal-host"
103
- style="--toast-enter-ms: {toastEnterDurationMs}ms; --toast-exit-ms: {toastExitDurationMs}ms;{style}"
147
+ style="--width: max-content; --toast-enter-ms: {toastEnterDurationMs}ms; --toast-exit-ms: {toastExitDurationMs}ms;{style}"
104
148
  />
@@ -3,7 +3,12 @@ export { className as class };
3
3
  export declare let style: string;
4
4
  export declare let defaultDuration: number;
5
5
  export declare let element: HTMLElement | null;
6
- export declare function showToast(type: string | undefined, title: string, options?: Record<string, unknown> | null): string | number;
6
+ /**
7
+ * Show one centered pill toast: a single message line (no separate title/description in the UI).
8
+ * `message` is the sentence users see. Legacy callers may still pass `options.description`; it is
9
+ * only used when `message` is empty, otherwise ignored so the toast stays one line.
10
+ */
11
+ export declare function showToast(type: string | undefined, message: string, options?: Record<string, unknown> | null): string | number;
7
12
  interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
8
13
  new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
9
14
  $$bindings?: Bindings;
@@ -0,0 +1,5 @@
1
+ export { buildToastRefreshPayload, resolveDismissDurationMs } from './toastDismissCountdownPayload.js';
2
+ /** Tell svelte-sonner to run the full dismiss duration again from zero (not the remaining slice). */
3
+ export declare function restartDismissCountdownForActiveToasts(defaultDurationMs: number): void;
4
+ /** Pause auto-dismiss while keyboard focus is inside the toast stack (pointer hover is handled by svelte-sonner). */
5
+ export declare function holdActiveToastsDuringKeyboardFocus(defaultDurationMs: number): void;
@@ -0,0 +1,47 @@
1
+ import { toast } from '../ui/sonner/index.js';
2
+ import { buildToastRefreshPayload, resolveDismissDurationMs } from './toastDismissCountdownPayload.js';
3
+ export { buildToastRefreshPayload, resolveDismissDurationMs } from './toastDismissCountdownPayload.js';
4
+ /** Last finite dismiss length before a keyboard-hold refresh overwrote duration with Infinity. */
5
+ const finiteDismissMsBeforeKeyboardHold = new Map();
6
+ /**
7
+ * Show a toast again with fresh options, through the presenter of its type when svelte-sonner has one (`toast.success(…)`),
8
+ * else through `toast(…)` with the type in the options. svelte-sonner types `toast` as a callable with named presenters and
9
+ * without an index signature, so the lookup by name goes through `unknown`.
10
+ */
11
+ function presentToastAgain(toastType, title, payload) {
12
+ const presentersByType = toast;
13
+ const presenter = presentersByType[toastType];
14
+ if (typeof presenter === 'function') {
15
+ presenter(title, payload);
16
+ return;
17
+ }
18
+ toast(title, { ...payload, type: toastType });
19
+ }
20
+ /** Tell svelte-sonner to run the full dismiss duration again from zero (not the remaining slice). */
21
+ export function restartDismissCountdownForActiveToasts(defaultDurationMs) {
22
+ for (const activeToast of toast.getActiveToasts()) {
23
+ if (activeToast.type === 'loading')
24
+ continue;
25
+ const title = typeof activeToast.title === 'string' ? activeToast.title : '';
26
+ const stored = finiteDismissMsBeforeKeyboardHold.get(activeToast.id);
27
+ finiteDismissMsBeforeKeyboardHold.delete(activeToast.id);
28
+ const dismissMs = resolveDismissDurationMs(activeToast, defaultDurationMs, stored);
29
+ const payload = buildToastRefreshPayload(activeToast, dismissMs);
30
+ presentToastAgain(activeToast.type ?? 'default', title, payload);
31
+ }
32
+ }
33
+ /** Pause auto-dismiss while keyboard focus is inside the toast stack (pointer hover is handled by svelte-sonner). */
34
+ export function holdActiveToastsDuringKeyboardFocus(defaultDurationMs) {
35
+ for (const activeToast of toast.getActiveToasts()) {
36
+ if (activeToast.type === 'loading')
37
+ continue;
38
+ const title = typeof activeToast.title === 'string' ? activeToast.title : '';
39
+ const finiteMs = resolveDismissDurationMs(activeToast, defaultDurationMs);
40
+ finiteDismissMsBeforeKeyboardHold.set(activeToast.id, finiteMs);
41
+ const payload = {
42
+ ...buildToastRefreshPayload(activeToast, Number.POSITIVE_INFINITY),
43
+ duration: Number.POSITIVE_INFINITY
44
+ };
45
+ presentToastAgain(activeToast.type ?? 'default', title, payload);
46
+ }
47
+ }
@@ -0,0 +1,16 @@
1
+ /** Fields we keep when asking svelte-sonner to refresh a toast's dismiss timer. */
2
+ export type RefreshableToastFields = {
3
+ id: string | number;
4
+ title?: unknown;
5
+ type?: string;
6
+ duration?: number;
7
+ description?: unknown;
8
+ action?: unknown;
9
+ cancel?: unknown;
10
+ icon?: unknown;
11
+ class?: unknown;
12
+ classes?: unknown;
13
+ };
14
+ /** Full dismiss length to use after hover/focus ends (ignores Infinity from a hold refresh). */
15
+ export declare function resolveDismissDurationMs(activeToast: RefreshableToastFields, defaultDurationMs: number, storedFiniteMs?: number): number;
16
+ export declare function buildToastRefreshPayload(activeToast: RefreshableToastFields, dismissDurationMs: number): Record<string, unknown>;
@@ -0,0 +1,24 @@
1
+ /** Full dismiss length to use after hover/focus ends (ignores Infinity from a hold refresh). */
2
+ export function resolveDismissDurationMs(activeToast, defaultDurationMs, storedFiniteMs) {
3
+ if (typeof storedFiniteMs === 'number' && Number.isFinite(storedFiniteMs) && storedFiniteMs > 0) {
4
+ return storedFiniteMs;
5
+ }
6
+ const fromToast = activeToast.duration;
7
+ if (typeof fromToast === 'number' && Number.isFinite(fromToast) && fromToast > 0) {
8
+ return fromToast;
9
+ }
10
+ return defaultDurationMs;
11
+ }
12
+ export function buildToastRefreshPayload(activeToast, dismissDurationMs) {
13
+ return {
14
+ id: activeToast.id,
15
+ duration: dismissDurationMs,
16
+ description: activeToast.description,
17
+ action: activeToast.action,
18
+ cancel: activeToast.cancel,
19
+ icon: activeToast.icon,
20
+ class: activeToast.class,
21
+ classes: activeToast.classes,
22
+ unstyled: true
23
+ };
24
+ }
@@ -0,0 +1,38 @@
1
+ <script lang="ts">
2
+ import { onDestroy } from 'svelte';
3
+ import type { OverlayLayerContext } from './overlay-layer-context.js';
4
+ import { overlayTransitionDurationMs } from '../../../utils/overlayMotion.js';
5
+
6
+ let {
7
+ open,
8
+ overlayLayerContext
9
+ }: { open: boolean; overlayLayerContext: OverlayLayerContext } = $props();
10
+
11
+ let releaseTimer: ReturnType<typeof setTimeout> | undefined;
12
+
13
+ const isVitest =
14
+ typeof process !== 'undefined' && (process.env.VITEST === 'true' || process.env.NODE_ENV === 'test');
15
+
16
+ $effect(() => {
17
+ if (open) {
18
+ if (releaseTimer !== undefined) {
19
+ clearTimeout(releaseTimer);
20
+ releaseTimer = undefined;
21
+ }
22
+ overlayLayerContext.ensureLayer();
23
+ return;
24
+ }
25
+ if (overlayLayerContext.layer) {
26
+ const delay = isVitest ? 0 : overlayTransitionDurationMs + 32;
27
+ releaseTimer = setTimeout(() => {
28
+ overlayLayerContext.releaseLayer();
29
+ releaseTimer = undefined;
30
+ }, delay);
31
+ }
32
+ });
33
+
34
+ onDestroy(() => {
35
+ if (releaseTimer !== undefined) clearTimeout(releaseTimer);
36
+ overlayLayerContext.releaseLayer();
37
+ });
38
+ </script>
@@ -0,0 +1,8 @@
1
+ import type { OverlayLayerContext } from './overlay-layer-context.js';
2
+ type $$ComponentProps = {
3
+ open: boolean;
4
+ overlayLayerContext: OverlayLayerContext;
5
+ };
6
+ declare const DialogLayerSync: import("svelte").Component<$$ComponentProps, {}, "">;
7
+ type DialogLayerSync = ReturnType<typeof DialogLayerSync>;
8
+ export default DialogLayerSync;
@@ -2,47 +2,90 @@
2
2
  import { Dialog as DialogPrimitive, type WithoutChildrenOrChild } from "bits-ui";
3
3
  import IconX from "@tabler/icons-svelte/icons/x";
4
4
  import type { Snippet } from "svelte";
5
+ import { fly } from "svelte/transition";
6
+ import { onDestroy, setContext } from "svelte";
5
7
  import * as Dialog from "./index.js";
6
8
  import { cn } from "../../../utils.js";
7
9
  import {
8
- overlayDialogContentClasses,
10
+ overlayDialogPanelCardClasses,
11
+ overlayPanelFlyTransition,
9
12
  overlayReducedMotionClasses
10
13
  } from "../../../utils/overlayMotion.js";
14
+ import { claimOverlayLayerPair, overlayLayerZIndexStyle } from "../../../utils/overlayLayerStack.js";
15
+ import { OVERLAY_LAYER_CONTEXT_KEY, type OverlayLayerContext } from "./overlay-layer-context.js";
16
+ import DialogLayerSync from "./DialogLayerSync.svelte";
11
17
 
12
18
  let {
13
19
  ref = $bindable(null),
14
20
  class: className,
15
21
  portalProps,
16
- // The name the close button has for a screen reader (it is drawn as an X): a page in another language gives its own.
17
22
  closeLabel = "Close",
23
+ // Where this dialog's layers start (see `claimOverlayLayerPair`). Only a host that draws layers of its own above 50
24
+ // needs it: the creator's floating panels sit at 2003, so its confirm dialogs start above that.
25
+ layerBase,
18
26
  children,
19
27
  ...restProps
20
28
  }: WithoutChildrenOrChild<DialogPrimitive.ContentProps> & {
21
29
  portalProps?: DialogPrimitive.PortalProps;
22
30
  closeLabel?: string;
31
+ layerBase?: number;
23
32
  children: Snippet;
24
33
  } = $props();
34
+
35
+ const overlayLayerContext: OverlayLayerContext = {
36
+ ensureLayer() {
37
+ if (!this.layer) {
38
+ this.layer = claimOverlayLayerPair(layerBase);
39
+ }
40
+ return this.layer;
41
+ },
42
+ releaseLayer() {
43
+ this.layer?.release();
44
+ this.layer = null;
45
+ },
46
+ layer: null
47
+ };
48
+ setContext(OVERLAY_LAYER_CONTEXT_KEY, overlayLayerContext);
49
+ onDestroy(() => overlayLayerContext.releaseLayer());
50
+
51
+ const panelFly = $derived(overlayPanelFlyTransition());
25
52
  </script>
26
53
 
27
54
  <Dialog.Portal {...portalProps}>
28
55
  <Dialog.Overlay />
29
- <DialogPrimitive.Content
30
- bind:ref
31
- data-widgetic-overlay="dialog-panel"
32
- class={cn(
33
- "bg-background border-border fixed start-1/2 top-1/2 z-50 grid w-dialog max-w-[calc(100vw-3rem)] -translate-x-1/2 -translate-y-1/2 gap-4 rounded-panel border p-6",
34
- overlayDialogContentClasses,
35
- overlayReducedMotionClasses,
36
- className
37
- )}
38
- {...restProps}
39
- >
40
- {@render children?.()}
41
- <DialogPrimitive.Close
42
- class="text-foreground hover:bg-accent absolute end-4 top-4 inline-flex size-8 items-center justify-center rounded-lg transition-colors duration-fast focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:pointer-events-none"
43
- >
44
- <IconX class="size-4 stroke-2" />
45
- <span class="sr-only">{closeLabel}</span>
46
- </DialogPrimitive.Close>
56
+ <DialogPrimitive.Content bind:ref forceMount {...restProps}>
57
+ {#snippet child({ props, open })}
58
+ <DialogLayerSync {open} {overlayLayerContext} />
59
+ {#if open}
60
+ <!-- Full-viewport host: layout only. bits-ui `ref` + dismissible bounds must sit on the card: an inset-0 host made every pointer event "inside" the dialog. -->
61
+ <div
62
+ data-widgetic-overlay="dialog-panel"
63
+ class={cn(
64
+ "fixed inset-0 flex items-center justify-center p-6 pointer-events-none",
65
+ overlayReducedMotionClasses
66
+ )}
67
+ style={overlayLayerZIndexStyle(overlayLayerContext.ensureLayer().scrimZ + 1)}
68
+ >
69
+ <div
70
+ {...props}
71
+ class={cn(
72
+ "bg-background border-border pointer-events-auto grid w-dialog max-w-[calc(100vw-3rem)] gap-4 rounded-panel border p-6",
73
+ overlayDialogPanelCardClasses,
74
+ className
75
+ )}
76
+ in:fly|global={panelFly}
77
+ out:fly|global={panelFly}
78
+ >
79
+ {@render children?.()}
80
+ <DialogPrimitive.Close
81
+ class="text-foreground hover:bg-accent absolute end-4 top-4 inline-flex size-8 items-center justify-center rounded-lg transition-colors duration-fast focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:pointer-events-none"
82
+ >
83
+ <IconX class="size-4 stroke-2" />
84
+ <span class="sr-only">{closeLabel}</span>
85
+ </DialogPrimitive.Close>
86
+ </div>
87
+ </div>
88
+ {/if}
89
+ {/snippet}
47
90
  </DialogPrimitive.Content>
48
91
  </Dialog.Portal>
@@ -3,6 +3,7 @@ import type { Snippet } from "svelte";
3
3
  type $$ComponentProps = WithoutChildrenOrChild<DialogPrimitive.ContentProps> & {
4
4
  portalProps?: DialogPrimitive.PortalProps;
5
5
  closeLabel?: string;
6
+ layerBase?: number;
6
7
  children: Snippet;
7
8
  };
8
9
  declare const DialogContent: import("svelte").Component<$$ComponentProps, {}, "ref">;