@widgetic/design-system 0.5.27 → 0.5.29

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/components/CopyableHeader.svelte +29 -10
  2. package/dist/components/CopyableHeader.svelte.d.ts +3 -0
  3. package/dist/components/EmptyState.svelte +13 -3
  4. package/dist/components/chat/ChatHeader.svelte +29 -3
  5. package/dist/components/chat/ChatHeader.svelte.d.ts +5 -0
  6. package/dist/components/chat/Composer.svelte +58 -1
  7. package/dist/components/chat/Composer.svelte.d.ts +8 -0
  8. package/dist/components/chat/MessageCheckpointRow.svelte +87 -0
  9. package/dist/components/chat/MessageCheckpointRow.svelte.d.ts +21 -0
  10. package/dist/components/chat/MessageRatingActions.svelte +157 -0
  11. package/dist/components/chat/MessageRatingActions.svelte.d.ts +26 -0
  12. package/dist/components/chat/chatHeaderLogic.d.ts +8 -0
  13. package/dist/components/chat/chatHeaderLogic.js +14 -0
  14. package/dist/components/chat/composerModelMenuLogic.d.ts +9 -0
  15. package/dist/components/chat/composerModelMenuLogic.js +12 -0
  16. package/dist/components/chat/index.d.ts +10 -0
  17. package/dist/components/chat/index.js +8 -0
  18. package/dist/components/chat/messageRatingActionsLogic.d.ts +11 -0
  19. package/dist/components/chat/messageRatingActionsLogic.js +17 -0
  20. package/dist/components/chat/messageRatingTypes.d.ts +2 -0
  21. package/dist/components/chat/messageRatingTypes.js +1 -0
  22. package/dist/components/modals/BaseModal.svelte +133 -11
  23. package/dist/components/modals/BaseModal.svelte.d.ts +1 -0
  24. package/dist/components/modals/NewItemDialog.svelte +2 -0
  25. package/dist/components/shad-editor/custom/Extentions/SearchAndReplace.js +0 -1
  26. package/dist/components/shad-editor/custom/utils.d.ts +1 -1
  27. package/dist/components/shad-editor/custom/utils.js +0 -1
  28. package/dist/components/shell/ErrorState.svelte +5 -2
  29. package/dist/components/shell/ErrorState.svelte.d.ts +2 -1
  30. package/dist/components/shell/NavRow.svelte +5 -4
  31. package/dist/components/shell/NavRow.svelte.d.ts +3 -3
  32. package/dist/components/shell/SettingsDialog.svelte +65 -4
  33. package/dist/components/shell/WidgetRow.svelte +6 -6
  34. package/dist/components/shell/WidgetRow.svelte.d.ts +2 -2
  35. package/dist/components/ui/accordion/accordion-content.svelte +5 -1
  36. package/dist/components/ui/accordion/accordion-item.svelte +2 -1
  37. package/dist/components/ui/accordion/accordion-trigger.svelte +38 -0
  38. package/dist/components/ui/button/button.svelte +1 -1
  39. package/dist/components/ui/button/button.svelte.d.ts +3 -3
  40. package/dist/components/ui/calendar/calendar.svelte.d.ts +1 -1
  41. package/dist/components/ui/checkbox/checkbox.svelte +1 -1
  42. package/dist/components/ui/dialog/dialog-overlay.svelte +8 -1
  43. package/dist/components/ui/icon-button/icon-button.svelte +1 -1
  44. package/dist/components/ui/icon-button/icon-button.svelte.d.ts +2 -2
  45. package/dist/components/ui/input-otp/input-otp-slot.svelte.d.ts +1 -1
  46. package/dist/components/ui/radio-group/radio-group-item.svelte +1 -1
  47. package/dist/components/ui/range-calendar/range-calendar.svelte.d.ts +1 -1
  48. package/dist/components/ui/scroll-area/scroll-area-scrollbar.svelte +1 -1
  49. package/dist/components/ui/select/select-content.svelte +2 -2
  50. package/dist/components/ui/select/select-scroll-down-button.svelte +1 -1
  51. package/dist/components/ui/select/select-scroll-up-button.svelte +1 -1
  52. package/dist/components/ui/select/select-trigger.svelte +1 -1
  53. package/dist/components/ui/stepper-button/stepper-button.svelte +1 -1
  54. package/dist/components/ui/tooltip/tooltip-content.svelte +1 -1
  55. package/dist/components/widget-system/Moveable.svelte +24 -21
  56. package/dist/utils/isEditableEventTarget.d.ts +5 -0
  57. package/dist/utils/isEditableEventTarget.js +25 -0
  58. package/dist/utils/modalFocusTrap.d.ts +28 -0
  59. package/dist/utils/modalFocusTrap.js +135 -0
  60. package/dist/utils/overlayMotion.d.ts +6 -0
  61. package/dist/utils/overlayMotion.js +7 -0
  62. package/dist/utils/overlayStacking.d.ts +47 -0
  63. package/dist/utils/overlayStacking.js +63 -0
  64. package/package.json +1 -1
@@ -0,0 +1,157 @@
1
+ <!--
2
+ Figma: Message actions row (copy, regenerate, thumbs) on assistant turns.
3
+ -->
4
+ <script lang="ts" module>
5
+ import type { HTMLAttributes } from 'svelte/elements';
6
+ import type { VersionRatingKind } from './messageRatingTypes.js';
7
+ import type { VersionThumb } from './messageRatingActionsLogic.js';
8
+
9
+ export type MessageRatingActionsMessages = {
10
+ copy: string;
11
+ copied: string;
12
+ regenerate: string;
13
+ rateGroup: string;
14
+ rateUp: string;
15
+ rateDown: string;
16
+ };
17
+
18
+ export type MessageRatingActionsProps = HTMLAttributes<HTMLDivElement> & {
19
+ ref?: HTMLDivElement | null;
20
+ class?: string;
21
+ copyText?: string;
22
+ canRegenerate?: boolean;
23
+ ratedMessageId?: string | null;
24
+ rating?: VersionRatingKind;
25
+ messages?: Partial<MessageRatingActionsMessages>;
26
+ onCopy?: () => void | Promise<void>;
27
+ onRegenerate?: () => void;
28
+ onRate?: (messageId: string, pressed: VersionThumb) => void;
29
+ };
30
+ </script>
31
+
32
+ <script lang="ts">
33
+ import IconCopy from '@tabler/icons-svelte/icons/copy';
34
+ import IconRefresh from '@tabler/icons-svelte/icons/refresh';
35
+ import IconThumbDown from '@tabler/icons-svelte/icons/thumb-down';
36
+ import IconThumbUp from '@tabler/icons-svelte/icons/thumb-up';
37
+ import IconCheck from '@tabler/icons-svelte/icons/check';
38
+ import { cn } from '../../utils.js';
39
+ import { IconButton } from '../ui/icon-button/index.js';
40
+ import {
41
+ shouldRenderMessageRatingBar,
42
+ shouldShowCopyAction,
43
+ shouldShowRatingActions,
44
+ shouldShowRegenerateAction,
45
+ thumbIsPressed
46
+ } from './messageRatingActionsLogic.js';
47
+
48
+ const defaultMessages: MessageRatingActionsMessages = {
49
+ copy: 'Copy message',
50
+ copied: 'Copied',
51
+ regenerate: 'Regenerate response',
52
+ rateGroup: 'Rate this version',
53
+ rateUp: 'Good result',
54
+ rateDown: 'Poor result'
55
+ };
56
+
57
+ let {
58
+ ref = $bindable(null),
59
+ class: className,
60
+ copyText = '',
61
+ canRegenerate = false,
62
+ ratedMessageId = null,
63
+ rating = 'none',
64
+ messages: messagesProp,
65
+ onCopy,
66
+ onRegenerate,
67
+ onRate,
68
+ ...restProps
69
+ }: MessageRatingActionsProps = $props();
70
+
71
+ const messages = $derived({ ...defaultMessages, ...messagesProp });
72
+ const visible = $derived(
73
+ shouldRenderMessageRatingBar({ copyText, canRegenerate, ratedMessageId })
74
+ );
75
+
76
+ let copied = $state(false);
77
+ let copiedTimer: ReturnType<typeof setTimeout> | null = null;
78
+
79
+ async function handleCopy(event: MouseEvent) {
80
+ const button = event.currentTarget instanceof HTMLElement ? event.currentTarget : null;
81
+ try {
82
+ await onCopy?.();
83
+ copied = true;
84
+ if (copiedTimer) clearTimeout(copiedTimer);
85
+ copiedTimer = setTimeout(() => {
86
+ copied = false;
87
+ copiedTimer = null;
88
+ }, 2000);
89
+ button?.focus({ preventScroll: true });
90
+ } catch (error) {
91
+ console.error('[MessageRatingActions] Copy failed:', error);
92
+ }
93
+ }
94
+
95
+ $effect(() => {
96
+ return () => {
97
+ if (copiedTimer) clearTimeout(copiedTimer);
98
+ };
99
+ });
100
+ </script>
101
+
102
+ {#if visible}
103
+ <div
104
+ bind:this={ref}
105
+ class={cn('flex min-h-8 flex-wrap items-center gap-1', className)}
106
+ role="group"
107
+ aria-label={messages.rateGroup}
108
+ {...restProps}
109
+ >
110
+ {#if shouldShowCopyAction(copyText) && onCopy}
111
+ <IconButton variant="ghost" label={copied ? messages.copied : messages.copy} onclick={handleCopy}>
112
+ {#if copied}
113
+ <IconCheck class="size-4 stroke-2" aria-hidden="true" />
114
+ {:else}
115
+ <IconCopy class="size-4 stroke-2" aria-hidden="true" />
116
+ {/if}
117
+ </IconButton>
118
+ {/if}
119
+
120
+ {#if shouldShowRegenerateAction(canRegenerate) && onRegenerate}
121
+ <IconButton variant="ghost" label={messages.regenerate} onclick={onRegenerate}>
122
+ <IconRefresh class="size-4 stroke-2" aria-hidden="true" />
123
+ </IconButton>
124
+ {/if}
125
+
126
+ {#if shouldShowRatingActions(ratedMessageId) && onRate && ratedMessageId}
127
+ <span class="inline-flex items-center gap-0.5" role="group" aria-label={messages.rateGroup}>
128
+ <IconButton
129
+ variant="ghost"
130
+ label={messages.rateUp}
131
+ aria-pressed={thumbIsPressed(rating, 'up')}
132
+ onclick={() => onRate(ratedMessageId, 'up')}
133
+ >
134
+ <IconThumbUp
135
+ class="size-4 stroke-2"
136
+ fill={thumbIsPressed(rating, 'up') ? 'currentColor' : 'none'}
137
+ aria-hidden="true"
138
+ />
139
+ </IconButton>
140
+ <IconButton
141
+ variant="ghost"
142
+ label={messages.rateDown}
143
+ aria-pressed={thumbIsPressed(rating, 'down')}
144
+ onclick={() => onRate(ratedMessageId, 'down')}
145
+ >
146
+ <IconThumbDown
147
+ class="size-4 stroke-2"
148
+ fill={thumbIsPressed(rating, 'down') ? 'currentColor' : 'none'}
149
+ aria-hidden="true"
150
+ />
151
+ </IconButton>
152
+ </span>
153
+ {/if}
154
+
155
+ <span class="sr-only" aria-live="polite">{copied ? messages.copied : ''}</span>
156
+ </div>
157
+ {/if}
@@ -0,0 +1,26 @@
1
+ import type { HTMLAttributes } from 'svelte/elements';
2
+ import type { VersionRatingKind } from './messageRatingTypes.js';
3
+ import type { VersionThumb } from './messageRatingActionsLogic.js';
4
+ export type MessageRatingActionsMessages = {
5
+ copy: string;
6
+ copied: string;
7
+ regenerate: string;
8
+ rateGroup: string;
9
+ rateUp: string;
10
+ rateDown: string;
11
+ };
12
+ export type MessageRatingActionsProps = HTMLAttributes<HTMLDivElement> & {
13
+ ref?: HTMLDivElement | null;
14
+ class?: string;
15
+ copyText?: string;
16
+ canRegenerate?: boolean;
17
+ ratedMessageId?: string | null;
18
+ rating?: VersionRatingKind;
19
+ messages?: Partial<MessageRatingActionsMessages>;
20
+ onCopy?: () => void | Promise<void>;
21
+ onRegenerate?: () => void;
22
+ onRate?: (messageId: string, pressed: VersionThumb) => void;
23
+ };
24
+ declare const MessageRatingActions: import("svelte").Component<MessageRatingActionsProps, {}, "ref">;
25
+ type MessageRatingActions = ReturnType<typeof MessageRatingActions>;
26
+ export default MessageRatingActions;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Whether the chat header shows the debug console control instead of the pin control.
3
+ */
4
+ export declare function shouldShowConsoleButton(showConsole: boolean, onToggleConsole?: (() => void) | null): boolean;
5
+ /**
6
+ * Pin stays available for hosts that still use it; hidden when the console control is shown.
7
+ */
8
+ export declare function shouldShowPinButton(showConsole: boolean, onToggleConsole?: (() => void) | null, onPin?: (() => void) | null): boolean;
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Whether the chat header shows the debug console control instead of the pin control.
3
+ */
4
+ export function shouldShowConsoleButton(showConsole, onToggleConsole) {
5
+ return showConsole && typeof onToggleConsole === 'function';
6
+ }
7
+ /**
8
+ * Pin stays available for hosts that still use it; hidden when the console control is shown.
9
+ */
10
+ export function shouldShowPinButton(showConsole, onToggleConsole, onPin) {
11
+ if (shouldShowConsoleButton(showConsole, onToggleConsole))
12
+ return false;
13
+ return typeof onPin === 'function';
14
+ }
@@ -0,0 +1,9 @@
1
+ export type ComposerModelOption = {
2
+ id: string;
3
+ label: string;
4
+ };
5
+ /**
6
+ * The Assistant menu is shown only when the host offers at least one model.
7
+ */
8
+ export declare function shouldShowComposerModelMenu(models: ComposerModelOption[] | null | undefined): boolean;
9
+ export declare function selectedModelLabel(models: ComposerModelOption[], selectedModelId: string | null | undefined, fallbackLabel: string): string;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * The Assistant menu is shown only when the host offers at least one model.
3
+ */
4
+ export function shouldShowComposerModelMenu(models) {
5
+ return Array.isArray(models) && models.length > 0;
6
+ }
7
+ export function selectedModelLabel(models, selectedModelId, fallbackLabel) {
8
+ if (!selectedModelId)
9
+ return fallbackLabel;
10
+ const match = models.find((model) => model.id === selectedModelId);
11
+ return match?.label?.trim() || fallbackLabel;
12
+ }
@@ -1,3 +1,5 @@
1
+ export { Chip } from '../ui/chip';
2
+ export { IconButton } from '../ui/icon-button';
1
3
  export { default as Composer, type ComposerMessages, type ComposerProps } from './Composer.svelte';
2
4
  export { default as Message, type MessageMessages, type MessageProps, type MessageRole } from './Message.svelte';
3
5
  export { default as ActivityRow, type ActivityRowProps, type ActivityRowStatus } from './ActivityRow.svelte';
@@ -14,3 +16,11 @@ export type { QuestionCardMessages, QuestionItem, QuestionOption } from './Quest
14
16
  export { canSubmitQuestion, formatQuestionStep, isFirstQuestion, isLastQuestion, moveFocusedIndex, optionItemRole, primaryQuestionLabel, selectionRole, toggleOption } from './questionCardLogic.js';
15
17
  export { default as SuggestionCard } from './SuggestionCard.svelte';
16
18
  export type { SuggestionCardMessages } from './SuggestionCard.svelte';
19
+ export { default as MessageRatingActions } from './MessageRatingActions.svelte';
20
+ export type { MessageRatingActionsMessages, MessageRatingActionsProps } from './MessageRatingActions.svelte';
21
+ export { default as MessageCheckpointRow } from './MessageCheckpointRow.svelte';
22
+ export type { MessageCheckpointRowMessages, MessageCheckpointRowProps } from './MessageCheckpointRow.svelte';
23
+ export { shouldShowConsoleButton, shouldShowPinButton } from './chatHeaderLogic.js';
24
+ export { shouldRenderMessageRatingBar, shouldShowCopyAction, shouldShowRatingActions, shouldShowRegenerateAction, thumbIsPressed, type VersionThumb } from './messageRatingActionsLogic.js';
25
+ export type { VersionRatingKind } from './messageRatingTypes.js';
26
+ export { selectedModelLabel, shouldShowComposerModelMenu, type ComposerModelOption } from './composerModelMenuLogic.js';
@@ -1,6 +1,9 @@
1
1
  // Chat components (composer, messages, plan and question cards) built from the Figma design system.
2
2
  // Each component is exported here by the agent that owns src/lib/components/chat.
3
3
  // [C1 exports]
4
+ export { Chip } from '../ui/chip';
5
+ // The chat's composer draws its attach "+" with the same icon button (the chat imports only this barrel).
6
+ export { IconButton } from '../ui/icon-button';
4
7
  export { default as Composer } from './Composer.svelte';
5
8
  export { default as Message } from './Message.svelte';
6
9
  export { default as ActivityRow } from './ActivityRow.svelte';
@@ -14,3 +17,8 @@ export { default as PlanCard } from './PlanCard.svelte';
14
17
  export { default as QuestionCard } from './QuestionCard.svelte';
15
18
  export { canSubmitQuestion, formatQuestionStep, isFirstQuestion, isLastQuestion, moveFocusedIndex, optionItemRole, primaryQuestionLabel, selectionRole, toggleOption } from './questionCardLogic.js';
16
19
  export { default as SuggestionCard } from './SuggestionCard.svelte';
20
+ export { default as MessageRatingActions } from './MessageRatingActions.svelte';
21
+ export { default as MessageCheckpointRow } from './MessageCheckpointRow.svelte';
22
+ export { shouldShowConsoleButton, shouldShowPinButton } from './chatHeaderLogic.js';
23
+ export { shouldRenderMessageRatingBar, shouldShowCopyAction, shouldShowRatingActions, shouldShowRegenerateAction, thumbIsPressed } from './messageRatingActionsLogic.js';
24
+ export { selectedModelLabel, shouldShowComposerModelMenu } from './composerModelMenuLogic.js';
@@ -0,0 +1,11 @@
1
+ import type { VersionRatingKind } from './messageRatingTypes.js';
2
+ export type VersionThumb = 'up' | 'down';
3
+ export declare function shouldShowCopyAction(copyText: string): boolean;
4
+ export declare function shouldShowRegenerateAction(canRegenerate: boolean): boolean;
5
+ export declare function shouldShowRatingActions(ratedMessageId: string | null | undefined): boolean;
6
+ export declare function shouldRenderMessageRatingBar(input: {
7
+ copyText: string;
8
+ canRegenerate: boolean;
9
+ ratedMessageId: string | null | undefined;
10
+ }): boolean;
11
+ export declare function thumbIsPressed(rating: VersionRatingKind | undefined, thumb: VersionThumb): boolean;
@@ -0,0 +1,17 @@
1
+ export function shouldShowCopyAction(copyText) {
2
+ return copyText.trim().length > 0;
3
+ }
4
+ export function shouldShowRegenerateAction(canRegenerate) {
5
+ return canRegenerate;
6
+ }
7
+ export function shouldShowRatingActions(ratedMessageId) {
8
+ return typeof ratedMessageId === 'string' && ratedMessageId.length > 0;
9
+ }
10
+ export function shouldRenderMessageRatingBar(input) {
11
+ return (shouldShowCopyAction(input.copyText) ||
12
+ shouldShowRegenerateAction(input.canRegenerate) ||
13
+ shouldShowRatingActions(input.ratedMessageId));
14
+ }
15
+ export function thumbIsPressed(rating, thumb) {
16
+ return rating === thumb;
17
+ }
@@ -0,0 +1,2 @@
1
+ /** Rating on an assistant version message, as stored by the host. */
2
+ export type VersionRatingKind = 'none' | 'up' | 'down';
@@ -0,0 +1 @@
1
+ export {};
@@ -1,8 +1,16 @@
1
1
  <script lang="ts">
2
2
  // Svelte imports
3
3
  import { fade, scale } from 'svelte/transition';
4
- import { createEventDispatcher, onDestroy, onMount } from 'svelte';
4
+ import { createEventDispatcher, onDestroy, onMount, tick } from 'svelte';
5
5
  const dispatch = createEventDispatcher();
6
+ import {
7
+ deepActiveElement,
8
+ getTabbableElements,
9
+ isFocusAllowed,
10
+ isFocusable,
11
+ nextModalTitleId,
12
+ tabWrapTarget
13
+ } from '../../utils/modalFocusTrap.js';
6
14
 
7
15
  // Design system componentsimports
8
16
  import { IconButton, WScrollArea, Portal } from '..';
@@ -23,6 +31,8 @@
23
31
  overlayTransitionDurationMs,
24
32
  overlayTransitionEasing
25
33
  } from '../../utils/overlayMotion.js';
34
+ // A scrim drawn over another scrim only dims (the page is blurred once): see overlayStacking.ts.
35
+ import { stackedScrimMark } from '../../utils/overlayStacking.js';
26
36
 
27
37
  /* COMPONENT PROPS */
28
38
  // class and style props
@@ -58,6 +68,8 @@
58
68
  export let closeOnBackdropClick = true;
59
69
  /** When false, Escape does not close. Default: Escape dismisses unless a nested control already handled the key. */
60
70
  export let closeOnEscape = true;
71
+ /** Spoken name of the dialog when there is no visible title row (a bare modal should pass one, for example the file's name). */
72
+ export let ariaLabel: string | undefined = undefined;
61
73
 
62
74
  // children prop(svelte 5) to replace the traditional slot(svelte 4)
63
75
  export let children: any;
@@ -68,7 +80,8 @@
68
80
  const easing = overlayTransitionEasing;
69
81
  const transitionOpts = { duration: transitionDuration, easing };
70
82
 
71
- const focusRingGutterPx = 4;
83
+ /** Room for focus-visible rings (2px) plus ring-offset (2px), plus one pixel for anti-aliasing. */
84
+ const focusRingGutterPx = 6;
72
85
 
73
86
  // Update constants for modal constraints
74
87
  const PADDING = 24; // Consistent padding for sides and bottom
@@ -115,6 +128,74 @@
115
128
  // Show logs
116
129
  let showLogs = false;
117
130
 
131
+ let modalPanelEl: HTMLDivElement | undefined;
132
+ // One id per modal, never shared: two modals of the same type open at once (one over the other) each name themselves.
133
+ const titleElementId = nextModalTitleId();
134
+ let focusBeforeOpen: HTMLElement | null = null;
135
+ let focusTrapActive = false;
136
+
137
+ async function engageFocusTrap() {
138
+ if (focusTrapActive) return;
139
+ if (!open || !isTopModal() || !modalPanelEl) return;
140
+ focusTrapActive = true;
141
+ await tick();
142
+ if (!modalPanelEl) return;
143
+ // Content that already put focus on one of its own controls while it mounted keeps it
144
+ const focusedNow = deepActiveElement();
145
+ if (focusedNow && focusedNow !== modalPanelEl && modalPanelEl.contains(focusedNow)) return;
146
+ const autofocusTarget = modalPanelEl.querySelector<HTMLElement>('[autofocus]');
147
+ if (autofocusTarget && isFocusable(autofocusTarget)) {
148
+ autofocusTarget.focus();
149
+ } else {
150
+ modalPanelEl.focus();
151
+ }
152
+ }
153
+
154
+ function disengageFocusTrap() {
155
+ if (!focusTrapActive) return;
156
+ focusTrapActive = false;
157
+ const restoreTarget = focusBeforeOpen;
158
+ focusBeforeOpen = null;
159
+ // `isConnected`, not `document.contains`: the control may live in a shadow root
160
+ if (restoreTarget && restoreTarget.isConnected && isFocusable(restoreTarget)) {
161
+ try {
162
+ restoreTarget.focus({ preventScroll: true });
163
+ } catch {
164
+ /* element became unfocusable */
165
+ }
166
+ }
167
+ }
168
+
169
+ function handleDocumentKeydownTab(event: KeyboardEvent) {
170
+ if (!focusTrapActive || !open || !isTopModal() || !modalPanelEl || event.key !== 'Tab') return;
171
+ const activeElement = deepActiveElement();
172
+ // Focus is in a menu, list or popover that a control of this modal opened: that layer handles Tab itself
173
+ if (
174
+ activeElement &&
175
+ !modalPanelEl.contains(activeElement) &&
176
+ isFocusAllowed(modalPanelEl, activeElement)
177
+ ) {
178
+ return;
179
+ }
180
+ const tabbables = getTabbableElements(modalPanelEl);
181
+ if (tabbables.length === 0) {
182
+ event.preventDefault();
183
+ modalPanelEl.focus();
184
+ return;
185
+ }
186
+ // Only at the two ends of the modal (or when focus is outside it) does the trap choose where focus goes
187
+ const wrapTarget = tabWrapTarget({
188
+ elements: tabbables,
189
+ active: activeElement,
190
+ shiftKey: event.shiftKey,
191
+ modalRoot: modalPanelEl
192
+ });
193
+ if (wrapTarget) {
194
+ event.preventDefault();
195
+ wrapTarget.focus();
196
+ }
197
+ }
198
+
118
199
  /* METHODS */
119
200
  function toggleUpdateContentDimensions(flag: boolean = true) {
120
201
  if (!flag) {
@@ -171,9 +252,12 @@
171
252
  }
172
253
 
173
254
  window.addEventListener('keydown', handleKeydown);
255
+ document.addEventListener('keydown', handleDocumentKeydownTab, true);
174
256
 
175
257
  return () => {
176
258
  window.removeEventListener('keydown', handleKeydown);
259
+ document.removeEventListener('keydown', handleDocumentKeydownTab, true);
260
+ disengageFocusTrap();
177
261
  popModalStore();
178
262
  toggleUpdateContentDimensions(false);
179
263
  };
@@ -257,6 +341,7 @@
257
341
  }
258
342
 
259
343
  function handleClose() {
344
+ disengageFocusTrap();
260
345
  open = false;
261
346
  toggleUpdateContentDimensions(false);
262
347
  dispatch('close');
@@ -287,11 +372,29 @@
287
372
  }
288
373
  }
289
374
 
375
+ // The element that had focus when the modal opened, captured BEFORE the card exists: content that focuses itself while it
376
+ // mounts (the autofocus input of a rename dialog) must not be taken for it, or focus would not go back to the button that
377
+ // opened the modal when the dialog closes.
378
+ let focusCapturedForThisOpening = false;
379
+ $: if (open && !focusCapturedForThisOpening) {
380
+ focusCapturedForThisOpening = true;
381
+ const activeElement = typeof document !== 'undefined' ? deepActiveElement() : null;
382
+ focusBeforeOpen = activeElement && activeElement !== document.body ? activeElement : null;
383
+ } else if (!open) {
384
+ focusCapturedForThisOpening = false;
385
+ }
386
+
290
387
  // Only update the modal store when `open` is true (push once per open); closing is handled in outro / destroy.
291
388
  $: if (open) {
292
389
  pushModalStore();
293
390
  keepPortalMounted = true;
294
391
  exiting = false;
392
+ } else if (!exiting) {
393
+ disengageFocusTrap();
394
+ }
395
+
396
+ $: if (open && modalPanelEl && isTopModal()) {
397
+ void engageFocusTrap();
295
398
  }
296
399
 
297
400
  $: if (prevOpenForExit && !open) {
@@ -317,12 +420,14 @@
317
420
  >
318
421
  {#if open || exiting}
319
422
  <!-- Host-scoped scrim (absolute fills the portal host, not the viewport). -->
320
- <!-- svelte-ignore a11y_no_static_element_interactions -->
423
+ <!-- The panel below now has role="dialog", so the old svelte-ignore for a11y_no_static_element_interactions that sat here is not needed any more (the Svelte autofixer reported it as unused). -->
321
424
  <div class="modal-dismiss-layer pointer-events-none absolute inset-0 z-[1000]">
322
425
  <!-- svelte-ignore a11y_click_events_have_key_events -->
323
426
  <div
324
427
  role="presentation"
325
428
  data-widgetic-overlay="base-modal-backdrop"
429
+ data-state={open ? 'open' : 'closed'}
430
+ data-stacked={stackedScrimMark()}
326
431
  class="modal-backdrop-container bg-muted-foreground/80 pointer-events-auto absolute inset-0"
327
432
  style="backdrop-filter: blur({backdropBlur}); z-index: 0;"
328
433
  in:fade|global={reduceMotion ? { duration: 0 } : transitionOpts}
@@ -335,8 +440,14 @@
335
440
  >
336
441
  <!-- svelte-ignore a11y_click_events_have_key_events -->
337
442
  <div
443
+ bind:this={modalPanelEl}
444
+ role="dialog"
445
+ aria-modal="true"
446
+ aria-labelledby={title ? titleElementId : undefined}
447
+ aria-label={title ? undefined : ariaLabel}
448
+ tabindex="-1"
338
449
  data-widgetic-overlay="base-modal-panel"
339
- class="modal-content-inner-container bg-background border-border rounded-panel pointer-events-auto relative max-h-[calc(100vh-3rem)] select-text overflow-hidden border {bare
450
+ class="modal-content-inner-container bg-background border-border rounded-panel pointer-events-auto relative max-h-[calc(100vh-3rem)] select-text overflow-hidden border outline-none {bare
340
451
  ? 'p-0'
341
452
  : 'p-6'}"
342
453
  style="
@@ -384,7 +495,10 @@
384
495
  aria-selected={isSelected}
385
496
  >
386
497
  {#if title}
387
- <h2 class="text-heading-page text-foreground min-w-0 flex-1 break-words text-start">
498
+ <h2
499
+ id={titleElementId}
500
+ class="text-heading-page text-foreground min-w-0 flex-1 break-words text-start"
501
+ >
388
502
  {title}
389
503
  </h2>
390
504
  {:else}
@@ -422,14 +536,13 @@
422
536
  {/if}
423
537
  {:else}
424
538
  <!--
425
- Focus ring gutter: the clip wrapper uses margin -4px / padding +4px so the overflow clip edge sits
426
- outside the content box; the inner flow/scroll root keeps the same footprint as before (no inner
427
- padding), so layout parity stays 25px from the card border. For showScroll, the scroll root is
428
- extended by 8px and an inner wrapper provides the 4px pad for rings without changing measured height.
539
+ Focus ring gutter: the clip wrapper uses negative margin and matching padding so the overflow clip
540
+ edge sits outside the content box (rectangular clip — not the card radius). For showScroll, the scroll
541
+ root is extended and an inner wrapper provides the same pad for rings without changing measured height.
429
542
  -->
430
543
  <div
431
544
  class="modal-focus-ring-clip min-h-0 overflow-hidden"
432
- style="margin: -{focusRingGutterPx}px; padding: {focusRingGutterPx}px; border-radius: inherit;"
545
+ style="margin: -{focusRingGutterPx}px; padding: {focusRingGutterPx}px;"
433
546
  >
434
547
  {#if showScroll}
435
548
  <WScrollArea
@@ -439,7 +552,10 @@
439
552
  style="margin: -{focusRingGutterPx}px; width: calc(100% + {2 *
440
553
  focusRingGutterPx}px); height: {contentAvailableHeight + 2 * focusRingGutterPx}px;"
441
554
  >
442
- <div class="modal-scroll-focus-gutter box-border min-h-0 p-1">
555
+ <div
556
+ class="modal-scroll-focus-gutter box-border min-h-0"
557
+ style="padding: {focusRingGutterPx}px;"
558
+ >
443
559
  {@render contentSlot()}
444
560
  </div>
445
561
  </WScrollArea>
@@ -481,6 +597,12 @@
481
597
  pointer-events: auto;
482
598
  }
483
599
 
600
+ /* Drawn over another scrim (see overlayStacking.ts): it only dims, the page is blurred once. The blur is inline on the
601
+ element, so taking it off needs !important. */
602
+ .modal-backdrop-container[data-stacked] {
603
+ backdrop-filter: none !important;
604
+ }
605
+
484
606
  :global(.ScrollAreaViewport) {
485
607
  width: 100%;
486
608
  height: 100%;
@@ -31,6 +31,7 @@ declare const BaseModal: $$__sveltets_2_IsomorphicComponent<{
31
31
  bare?: boolean;
32
32
  /** When false, clicks and taps on the scrim do not close (destructive confirms can set this). Default matches Figma: scrim dismisses. */ closeOnBackdropClick?: boolean;
33
33
  /** When false, Escape does not close. Default: Escape dismisses unless a nested control already handled the key. */ closeOnEscape?: boolean;
34
+ /** Spoken name of the dialog when there is no visible title row (a bare modal should pass one, for example the file's name). */ ariaLabel?: string | undefined;
34
35
  children: any;
35
36
  }, {
36
37
  pointerdown: PointerEvent;
@@ -164,9 +164,11 @@
164
164
  {style}
165
165
  >
166
166
  <div class="flex flex-col gap-1.5">
167
+ <!-- The name is what this dialog asks for: BaseModal's focus trap puts the cursor here when the dialog opens (round 26) -->
167
168
  <Input
168
169
  bind:ref={inputElement}
169
170
  bind:value={itemName}
171
+ autofocus
170
172
  {placeholder}
171
173
  maxlength={maxLength}
172
174
  aria-invalid={Boolean(currentError)}
@@ -18,7 +18,6 @@
18
18
  import { Extension } from '@tiptap/core';
19
19
  import { Decoration, DecorationSet } from '@tiptap/pm/view';
20
20
  import { Plugin, PluginKey } from '@tiptap/pm/state';
21
- import { Node as PMNode } from '@tiptap/pm/model';
22
21
  const getRegex = (s, disableRegex, caseSensitive) => {
23
22
  return RegExp(disableRegex ? s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') : s, caseSensitive ? 'gu' : 'gui');
24
23
  };
@@ -1,5 +1,5 @@
1
1
  import type { Editor } from '@tiptap/core';
2
- import { Node } from '@tiptap/pm/model';
2
+ import type { Node } from '@tiptap/pm/model';
3
3
  import { DecorationSet } from '@tiptap/pm/view';
4
4
  export default function (doc: Node): DecorationSet;
5
5
  export declare const duplicateContent: (editor: Editor) => void;
@@ -1,4 +1,3 @@
1
- import { Node } from '@tiptap/pm/model';
2
1
  import { Decoration, DecorationSet } from '@tiptap/pm/view';
3
2
  export default function (doc) {
4
3
  const hexColor = /(#[0-9a-f]{3,6})\b/gi;
@@ -1,6 +1,7 @@
1
1
  <!-- Figma: Error State (component set 139:2, node 139:2). -->
2
2
  <script lang="ts">
3
3
  import type { Snippet } from 'svelte';
4
+ import type { HTMLAttributes } from 'svelte/elements';
4
5
  import IconAlertTriangle from '@tabler/icons-svelte/icons/alert-triangle';
5
6
  import IconRefresh from '@tabler/icons-svelte/icons/refresh';
6
7
  import { cn } from '../../utils.js';
@@ -12,8 +13,9 @@
12
13
  messages = defaultErrorStateMessages,
13
14
  onRetry,
14
15
  onSupport,
15
- actions
16
- }: {
16
+ actions,
17
+ ...restProps
18
+ }: HTMLAttributes<HTMLDivElement> & {
17
19
  class?: string;
18
20
  messages?: ErrorStateMessages;
19
21
  onRetry?: () => void;
@@ -31,6 +33,7 @@
31
33
  className
32
34
  )}
33
35
  role="alert"
36
+ {...restProps}
34
37
  >
35
38
  <div class="relative flex size-12 items-center justify-center overflow-hidden rounded-xl">
36
39
  <span class="bg-destructive absolute inset-0 rounded-xl opacity-10" aria-hidden="true"></span>
@@ -1,6 +1,7 @@
1
1
  import type { Snippet } from 'svelte';
2
+ import type { HTMLAttributes } from 'svelte/elements';
2
3
  import { type ErrorStateMessages } from './error-state-messages.js';
3
- type $$ComponentProps = {
4
+ type $$ComponentProps = HTMLAttributes<HTMLDivElement> & {
4
5
  class?: string;
5
6
  messages?: ErrorStateMessages;
6
7
  onRetry?: () => void;