@diegopluna/narvi 0.4.1 → 0.5.1
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.
- package/README.md +3 -1
- package/dist/base.css +3 -0
- package/dist/components/app-shell/AppShellPanel.svelte +3 -2
- package/dist/components/button/Button.svelte +29 -17
- package/dist/components/checkbox/Checkbox.svelte +106 -54
- package/dist/components/checkbox/Checkbox.svelte.d.ts +22 -8
- package/dist/components/choice-cards/ChoiceCards.svelte +68 -39
- package/dist/components/choice-cards/ChoiceCards.svelte.d.ts +12 -8
- package/dist/components/collapsible/CollapsibleContent.svelte +71 -17
- package/dist/components/collapsible/CollapsibleContent.svelte.d.ts +14 -10
- package/dist/components/collapsible/CollapsibleRoot.svelte +13 -9
- package/dist/components/collapsible/CollapsibleRoot.svelte.d.ts +8 -9
- package/dist/components/collapsible/CollapsibleTrigger.svelte +24 -15
- package/dist/components/collapsible/CollapsibleTrigger.svelte.d.ts +10 -14
- package/dist/components/color-field/ColorField.svelte +13 -7
- package/dist/components/command/CommandDialog.svelte +30 -20
- package/dist/components/command/CommandDialog.svelte.d.ts +4 -3
- package/dist/components/command/CommandEmpty.svelte +11 -9
- package/dist/components/command/CommandEmpty.svelte.d.ts +6 -17
- package/dist/components/command/CommandGroup.svelte +32 -11
- package/dist/components/command/CommandGroup.svelte.d.ts +7 -11
- package/dist/components/command/CommandInput.svelte +25 -10
- package/dist/components/command/CommandInput.svelte.d.ts +8 -12
- package/dist/components/command/CommandItem.svelte +67 -29
- package/dist/components/command/CommandItem.svelte.d.ts +6 -32
- package/dist/components/command/CommandList.svelte +8 -10
- package/dist/components/command/CommandList.svelte.d.ts +6 -8
- package/dist/components/command/CommandRoot.svelte +247 -57
- package/dist/components/command/CommandRoot.svelte.d.ts +14 -28
- package/dist/components/command/CommandSeparator.svelte +18 -0
- package/dist/components/command/CommandSeparator.svelte.d.ts +7 -0
- package/dist/components/command/context.d.ts +27 -0
- package/dist/components/command/context.js +16 -0
- package/dist/components/command/index.d.ts +6 -4
- package/dist/components/command/index.js +5 -4
- package/dist/components/command/score.d.ts +27 -0
- package/dist/components/command/score.js +77 -0
- package/dist/components/command/styles.d.ts +32 -9
- package/dist/components/command/styles.js +42 -14
- package/dist/components/composer/ComposerModelPicker.svelte +350 -346
- package/dist/components/composer/ComposerModelPicker.svelte.d.ts +6 -3
- package/dist/components/composer/ComposerRoot.svelte.d.ts +1 -1
- package/dist/components/dialog/ConfirmDialog.svelte +73 -53
- package/dist/components/dialog/DialogClose.svelte +17 -0
- package/dist/components/dialog/DialogClose.svelte.d.ts +10 -0
- package/dist/components/dialog/DialogContent.svelte +35 -33
- package/dist/components/dialog/DialogContent.svelte.d.ts +6 -20
- package/dist/components/dialog/DialogDescription.svelte +9 -12
- package/dist/components/dialog/DialogDescription.svelte.d.ts +6 -8
- package/dist/components/dialog/DialogRoot.svelte +20 -0
- package/dist/components/dialog/DialogRoot.svelte.d.ts +7 -0
- package/dist/components/dialog/DialogTitle.svelte +12 -8
- package/dist/components/dialog/DialogTitle.svelte.d.ts +8 -8
- package/dist/components/dialog/DialogTrigger.svelte +17 -0
- package/dist/components/dialog/DialogTrigger.svelte.d.ts +10 -0
- package/dist/components/dialog/index.d.ts +6 -5
- package/dist/components/dialog/index.js +3 -6
- package/dist/components/dialog/styles.d.ts +1 -2
- package/dist/components/dialog/styles.js +11 -8
- package/dist/components/hover-card/HoverCardContent.svelte +35 -29
- package/dist/components/hover-card/HoverCardContent.svelte.d.ts +8 -12
- package/dist/components/hover-card/HoverCardRoot.svelte +7 -7
- package/dist/components/hover-card/HoverCardRoot.svelte.d.ts +5 -4
- package/dist/components/hover-card/HoverCardTrigger.svelte +18 -0
- package/dist/components/hover-card/HoverCardTrigger.svelte.d.ts +10 -0
- package/dist/components/hover-card/index.d.ts +2 -3
- package/dist/components/hover-card/index.js +1 -5
- package/dist/components/input/Input.svelte.d.ts +1 -1
- package/dist/components/markdown/MarkdownBlock.svelte +6 -3
- package/dist/components/markdown/MarkdownTable.svelte +15 -7
- package/dist/components/menu/ContextMenuContent.svelte +15 -15
- package/dist/components/menu/ContextMenuContent.svelte.d.ts +6 -9
- package/dist/components/menu/ContextMenuTrigger.svelte +14 -16
- package/dist/components/menu/ContextMenuTrigger.svelte.d.ts +8 -14
- package/dist/components/menu/MenuCheckboxItem.svelte +22 -11
- package/dist/components/menu/MenuCheckboxItem.svelte.d.ts +8 -22
- package/dist/components/menu/MenuContent.svelte +16 -18
- package/dist/components/menu/MenuContent.svelte.d.ts +6 -18
- package/dist/components/menu/MenuGroup.svelte +4 -4
- package/dist/components/menu/MenuGroup.svelte.d.ts +5 -4
- package/dist/components/menu/MenuItem.svelte +25 -12
- package/dist/components/menu/MenuItem.svelte.d.ts +6 -21
- package/dist/components/menu/MenuLabel.svelte +7 -11
- package/dist/components/menu/MenuLabel.svelte.d.ts +6 -8
- package/dist/components/menu/MenuRadioGroup.svelte +4 -4
- package/dist/components/menu/MenuRadioGroup.svelte.d.ts +5 -4
- package/dist/components/menu/MenuRadioItem.svelte +16 -14
- package/dist/components/menu/MenuRadioItem.svelte.d.ts +6 -19
- package/dist/components/menu/MenuSeparator.svelte +6 -10
- package/dist/components/menu/MenuSeparator.svelte.d.ts +6 -7
- package/dist/components/menu/MenuSubContent.svelte +22 -19
- package/dist/components/menu/MenuSubContent.svelte.d.ts +8 -15
- package/dist/components/menu/MenuSubTrigger.svelte +7 -11
- package/dist/components/menu/MenuSubTrigger.svelte.d.ts +6 -15
- package/dist/components/menu/MenuTrigger.svelte +17 -0
- package/dist/components/menu/MenuTrigger.svelte.d.ts +10 -0
- package/dist/components/menu/context-menu.d.ts +2 -2
- package/dist/components/menu/context-menu.js +3 -2
- package/dist/components/menu/group.js +1 -1
- package/dist/components/menu/index.d.ts +5 -4
- package/dist/components/menu/index.js +5 -5
- package/dist/components/menu/row.d.ts +20 -0
- package/dist/components/menu/row.js +12 -0
- package/dist/components/popover/PopoverClose.svelte +17 -0
- package/dist/components/popover/PopoverClose.svelte.d.ts +10 -0
- package/dist/components/popover/PopoverContent.svelte +30 -29
- package/dist/components/popover/PopoverContent.svelte.d.ts +6 -17
- package/dist/components/popover/PopoverTrigger.svelte +17 -0
- package/dist/components/popover/PopoverTrigger.svelte.d.ts +10 -0
- package/dist/components/popover/index.d.ts +6 -4
- package/dist/components/popover/index.js +6 -5
- package/dist/components/progress/Progress.svelte +16 -22
- package/dist/components/progress/Progress.svelte.d.ts +6 -5
- package/dist/components/reasoning/ReasoningRoot.svelte.d.ts +1 -1
- package/dist/components/resize-handle/ResizeHandle.svelte +80 -14
- package/dist/components/resize-handle/ResizeHandle.svelte.d.ts +15 -1
- package/dist/components/segmented/SegmentedControl.svelte +100 -91
- package/dist/components/segmented/SegmentedControl.svelte.d.ts +6 -4
- package/dist/components/select/Select.svelte +97 -59
- package/dist/components/select/Select.svelte.d.ts +3 -2
- package/dist/components/sheet/SheetContent.svelte +31 -38
- package/dist/components/sheet/SheetContent.svelte.d.ts +7 -22
- package/dist/components/sheet/index.d.ts +3 -5
- package/dist/components/sheet/index.js +3 -5
- package/dist/components/sheet/styles.js +26 -5
- package/dist/components/sidebar/SidebarItem.svelte +2 -3
- package/dist/components/slider/Slider.svelte +86 -65
- package/dist/components/slider/Slider.svelte.d.ts +9 -8
- package/dist/components/split-button/SplitButton.svelte +20 -3
- package/dist/components/split-button/SplitButton.svelte.d.ts +1 -1
- package/dist/components/switch/Switch.svelte +77 -49
- package/dist/components/switch/Switch.svelte.d.ts +15 -8
- package/dist/components/tab-strip/TabStrip.svelte +87 -68
- package/dist/components/tabs/Tabs.svelte +129 -99
- package/dist/components/tabs/Tabs.svelte.d.ts +6 -4
- package/dist/components/textarea/Textarea.svelte.d.ts +1 -1
- package/dist/components/toast/Toaster.svelte +132 -115
- package/dist/components/toast/Toaster.svelte.d.ts +5 -0
- package/dist/components/toast/toasts.svelte.d.ts +10 -23
- package/dist/components/toast/toasts.svelte.js +62 -40
- package/dist/components/toggle/Toggle.svelte +15 -9
- package/dist/components/toggle/Toggle.svelte.d.ts +8 -17
- package/dist/components/toggle-group/ToggleGroupItem.svelte +20 -9
- package/dist/components/toggle-group/ToggleGroupItem.svelte.d.ts +10 -10
- package/dist/components/toggle-group/ToggleGroupRoot.svelte +33 -18
- package/dist/components/toggle-group/ToggleGroupRoot.svelte.d.ts +4 -4
- package/dist/components/tool/ToolRoot.svelte.d.ts +1 -1
- package/dist/components/tooltip/TooltipContent.svelte +38 -28
- package/dist/components/tooltip/TooltipContent.svelte.d.ts +6 -15
- package/dist/components/tooltip/TooltipProvider.svelte +34 -10
- package/dist/components/tooltip/TooltipProvider.svelte.d.ts +18 -4
- package/dist/components/tooltip/TooltipRoot.svelte +52 -23
- package/dist/components/tooltip/TooltipRoot.svelte.d.ts +10 -10
- package/dist/components/tooltip/TooltipTrigger.svelte +14 -17
- package/dist/components/tooltip/TooltipTrigger.svelte.d.ts +10 -4
- package/dist/components/tooltip/index.d.ts +1 -1
- package/dist/components/tooltip/index.js +1 -1
- package/dist/components/work-fold/WorkFold.svelte +14 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.js +1 -1
- package/dist/internal/TooltipScope.svelte +4 -4
- package/dist/internal/layer.d.ts +11 -9
- package/dist/internal/layer.js +21 -15
- package/dist/internal/loose.d.ts +30 -5
- package/dist/internal/loose.js +1 -1
- package/dist/internal/markers.stylex.d.ts +0 -4
- package/dist/internal/markers.stylex.js +0 -2
- package/dist/internal/toggle.d.ts +3 -0
- package/dist/internal/toggle.js +6 -2
- package/dist/internal/tooltip-trigger.d.ts +7 -6
- package/dist/internal/tooltip-trigger.js +9 -12
- package/dist/vite.d.ts +7 -1
- package/dist/vite.js +20 -5
- package/package.json +3 -2
- package/skills/building-ui/SKILL.md +22 -22
- package/skills/building-ui/references/components.md +30 -4
- package/skills/markdown/SKILL.md +1 -1
- package/skills/setup/SKILL.md +4 -8
- package/skills/styling/SKILL.md +1 -1
- package/skills/theming/SKILL.md +3 -7
|
@@ -1,41 +1,62 @@
|
|
|
1
1
|
<!--
|
|
2
2
|
Where toasts appear. Place one near the root of the app.
|
|
3
3
|
|
|
4
|
-
It sits in the top layer, so toasts stay above
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
Built on ui-sdk's toast region. It sits in the top layer, so toasts stay above
|
|
5
|
+
dialogs, and ui-sdk keeps them usable while a modal dialog is open. Each
|
|
6
|
+
toast waits while the pointer or focus is on the stack, while the window is
|
|
7
|
+
hidden or in the background, so none goes unread.
|
|
7
8
|
-->
|
|
8
9
|
<script lang="ts" module>
|
|
9
10
|
import * as stylex from '@stylexjs/stylex';
|
|
11
|
+
import {
|
|
12
|
+
Toast,
|
|
13
|
+
ToastClose,
|
|
14
|
+
ToastDescription,
|
|
15
|
+
ToastRegion,
|
|
16
|
+
ToastTitle
|
|
17
|
+
} from '@ui-sdk/svelte/toast';
|
|
10
18
|
import { colors, density, font, motion, radius, space } from '../../tokens.stylex.js';
|
|
11
19
|
import { media } from '../../media.stylex.js';
|
|
12
20
|
import Glyph from '../../internal/Glyph.svelte';
|
|
21
|
+
import { shared } from '../../internal/shared.js';
|
|
13
22
|
import Button from '../button/Button.svelte';
|
|
14
23
|
import Spinner from '../spinner/Spinner.svelte';
|
|
15
|
-
import {
|
|
24
|
+
import { answer, toaster, type ToastData } from './toasts.svelte.js';
|
|
16
25
|
|
|
17
26
|
export type ToasterProps = {
|
|
18
27
|
/** Distance from the top of the window, to clear an app's own header. */
|
|
19
28
|
offset?: string | undefined;
|
|
20
29
|
/** Accessible name of the region. */
|
|
21
30
|
label?: string | undefined;
|
|
31
|
+
/**
|
|
32
|
+
* The key that moves focus to the newest toast, and back again: `F6` by default, or
|
|
33
|
+
* `alt+t`. `null` leaves the key to the app, for one that cycles its own areas with F6.
|
|
34
|
+
*/
|
|
35
|
+
shortcut?: string | null | undefined;
|
|
22
36
|
};
|
|
23
37
|
|
|
24
38
|
/** A length at the window's density (`density` in the tokens). */
|
|
25
39
|
const d = (rem: string) => `calc(${rem} * ${density.factor})`;
|
|
26
40
|
|
|
41
|
+
// ui-sdk's state attributes on a toast: its first frame, while it leaves, while it is swiped
|
|
42
|
+
const STARTING = ':is([data-starting-style])';
|
|
43
|
+
const ENDING = ':is([data-ending-style])';
|
|
44
|
+
const SWIPING = ':is([data-swiping])';
|
|
45
|
+
// Where a swipe has taken it, which it leaves from
|
|
46
|
+
const SWIPE = 'var(--toast-swipe-x, 0px) var(--toast-swipe-y, 0px)';
|
|
47
|
+
|
|
27
48
|
const styles = stylex.create({
|
|
28
|
-
// The top layer brings the browser's popover styles; these undo them
|
|
49
|
+
// The top layer brings the browser's popover styles; these undo them. ui-sdk measures the
|
|
50
|
+
// toasts, newest first, and the stack is as tall as they are with the gaps between them.
|
|
29
51
|
region: {
|
|
30
52
|
position: 'fixed',
|
|
31
53
|
inset: 'auto',
|
|
32
54
|
top: 'var(--narvi-toaster-offset)',
|
|
33
55
|
insetInlineEnd: space.x4,
|
|
34
|
-
display: '
|
|
35
|
-
flexDirection: 'column',
|
|
36
|
-
gap: space.x2,
|
|
56
|
+
display: 'block',
|
|
37
57
|
width: 'min(22rem, calc(100vw - 2rem))',
|
|
38
|
-
|
|
58
|
+
maxWidth: 'none',
|
|
59
|
+
height: `max(0px, calc(var(--toast-stack-height, 0px) + (var(--toast-count, 1) - 1) * ${space.x2}))`,
|
|
39
60
|
margin: 0,
|
|
40
61
|
padding: 0,
|
|
41
62
|
overflow: 'visible',
|
|
@@ -43,7 +64,22 @@
|
|
|
43
64
|
backgroundColor: 'transparent',
|
|
44
65
|
pointerEvents: 'none'
|
|
45
66
|
},
|
|
67
|
+
// More toasts than the window holds: the stack stops at the window's foot and scrolls, so
|
|
68
|
+
// the oldest can still be read and put away. Only then, as it clips what spills out of it,
|
|
69
|
+
// a shadow or a toast being swiped away.
|
|
70
|
+
crowded: {
|
|
71
|
+
maxHeight: `calc(100dvh - var(--narvi-toaster-offset) - ${space.x4})`,
|
|
72
|
+
overflowY: 'auto',
|
|
73
|
+
overscrollBehavior: 'contain',
|
|
74
|
+
pointerEvents: 'auto'
|
|
75
|
+
},
|
|
76
|
+
// Each toast below the newer ones. One that leaves keeps its place while it fades, and
|
|
77
|
+
// the rest close up behind it.
|
|
46
78
|
toast: {
|
|
79
|
+
position: 'absolute',
|
|
80
|
+
insetInline: 0,
|
|
81
|
+
top: `calc(var(--toast-offset, 0px) + var(--toast-index, 0) * ${space.x2})`,
|
|
82
|
+
boxSizing: 'border-box',
|
|
47
83
|
display: 'grid',
|
|
48
84
|
gridTemplateColumns: 'auto minmax(0, 1fr) auto',
|
|
49
85
|
alignItems: 'start',
|
|
@@ -59,20 +95,24 @@
|
|
|
59
95
|
fontSize: font.sizeBody,
|
|
60
96
|
lineHeight: font.leadingSnug,
|
|
61
97
|
pointerEvents: 'auto',
|
|
62
|
-
opacity: { default: 1,
|
|
98
|
+
opacity: { default: 1, [STARTING]: 0, [ENDING]: 0 },
|
|
99
|
+
// A swipe follows the pointer, with or without motion
|
|
63
100
|
translate: {
|
|
64
|
-
default:
|
|
65
|
-
[media.motion]: {
|
|
101
|
+
default: SWIPE,
|
|
102
|
+
[media.motion]: {
|
|
103
|
+
default: SWIPE,
|
|
104
|
+
[STARTING]: '0 -0.5rem',
|
|
105
|
+
[ENDING]: 'calc(var(--toast-swipe-x, 0px) + 0.5rem) var(--toast-swipe-y, 0px)'
|
|
106
|
+
}
|
|
66
107
|
},
|
|
67
|
-
transitionProperty: {
|
|
68
|
-
|
|
108
|
+
transitionProperty: {
|
|
109
|
+
default: 'opacity',
|
|
110
|
+
[media.motion]: 'opacity, translate, top',
|
|
111
|
+
[SWIPING]: 'none'
|
|
112
|
+
},
|
|
113
|
+
transitionDuration: { default: motion.slow, [ENDING]: motion.fast },
|
|
69
114
|
transitionTimingFunction: motion.easeOut
|
|
70
115
|
},
|
|
71
|
-
leaving: {
|
|
72
|
-
opacity: 0,
|
|
73
|
-
translate: { default: null, [media.motion]: '0.5rem 0' },
|
|
74
|
-
transitionDuration: motion.fast
|
|
75
|
-
},
|
|
76
116
|
icon: { display: 'grid', placeItems: 'center', width: '1rem', height: '1.25rem' },
|
|
77
117
|
dot: {
|
|
78
118
|
width: '0.375rem',
|
|
@@ -90,7 +130,9 @@
|
|
|
90
130
|
flexDirection: 'column',
|
|
91
131
|
gap: '0.125rem',
|
|
92
132
|
minWidth: 0,
|
|
93
|
-
paddingTop: '1px'
|
|
133
|
+
paddingTop: '1px',
|
|
134
|
+
// A branch or a hash with nowhere to break breaks anywhere, rather than running out
|
|
135
|
+
overflowWrap: 'anywhere'
|
|
94
136
|
},
|
|
95
137
|
title: { fontWeight: font.weightMedium },
|
|
96
138
|
// What went wrong can be selected and copied
|
|
@@ -100,6 +142,14 @@
|
|
|
100
142
|
userSelect: 'text',
|
|
101
143
|
overflowWrap: 'anywhere'
|
|
102
144
|
},
|
|
145
|
+
// An action's label past 10rem is cut short, so the title keeps its room beside it
|
|
146
|
+
action: { maxWidth: '10rem', minWidth: 0 },
|
|
147
|
+
actionLabel: {
|
|
148
|
+
minWidth: 0,
|
|
149
|
+
overflow: 'hidden',
|
|
150
|
+
textOverflow: 'ellipsis',
|
|
151
|
+
whiteSpace: 'nowrap'
|
|
152
|
+
},
|
|
103
153
|
// Its small buttons are centred on the title's line, about 20px, at any density
|
|
104
154
|
actions: {
|
|
105
155
|
display: 'flex',
|
|
@@ -111,131 +161,98 @@
|
|
|
111
161
|
</script>
|
|
112
162
|
|
|
113
163
|
<script lang="ts">
|
|
114
|
-
let { offset = '1rem', label = 'Notifications' }: ToasterProps = $props();
|
|
164
|
+
let { offset = '1rem', label = 'Notifications', shortcut }: ToasterProps = $props();
|
|
115
165
|
|
|
116
|
-
|
|
117
|
-
let
|
|
118
|
-
let hidden = $state(false);
|
|
119
|
-
// Toasts on their way out, by revision, kept a moment so they can fade. A toast replaced
|
|
120
|
-
// while it fades comes back at once.
|
|
121
|
-
let leaving = $state<number[]>([]);
|
|
166
|
+
const id = $props.id();
|
|
167
|
+
let crowded = $state(false);
|
|
122
168
|
|
|
169
|
+
// Whether the stack runs past the window's foot. Measured as the stack or the window changes
|
|
170
|
+
// size; while crowded the region keeps one height, and grows again only once the stack fits.
|
|
123
171
|
$effect(() => {
|
|
124
|
-
region
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
function close(entry: ToastEntry, how: ToastEnd) {
|
|
131
|
-
const { id, revision } = entry;
|
|
132
|
-
if (leaving.includes(revision)) return;
|
|
133
|
-
leaving = [...leaving, revision];
|
|
134
|
-
setTimeout(() => {
|
|
135
|
-
finish(id, how, revision);
|
|
136
|
-
leaving = leaving.filter((each) => each !== revision);
|
|
137
|
-
}, 140);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
// Each toast's own timer, which runs only while nothing holds the stack
|
|
141
|
-
function timed(element: HTMLElement, entry: ToastEntry) {
|
|
142
|
-
let remaining = entry.duration ?? Infinity;
|
|
143
|
-
let started = 0;
|
|
144
|
-
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
145
|
-
const run = () => {
|
|
146
|
-
if (!Number.isFinite(remaining)) return;
|
|
147
|
-
started = performance.now();
|
|
148
|
-
timer = setTimeout(() => close(entry, 'auto'), remaining);
|
|
172
|
+
const region = document.querySelector<HTMLElement>(`[data-narvi-toaster="${id}"]`);
|
|
173
|
+
if (!region) return;
|
|
174
|
+
const measure = () => {
|
|
175
|
+
// The room `crowded` leaves it: down to 1rem above the window's foot
|
|
176
|
+
const room = window.innerHeight - region.getBoundingClientRect().top - 16;
|
|
177
|
+
crowded = region.scrollHeight > room + 1;
|
|
149
178
|
};
|
|
150
|
-
const
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
179
|
+
const observer = new ResizeObserver(measure);
|
|
180
|
+
observer.observe(region);
|
|
181
|
+
window.addEventListener('resize', measure);
|
|
182
|
+
return () => {
|
|
183
|
+
observer.disconnect();
|
|
184
|
+
window.removeEventListener('resize', measure);
|
|
155
185
|
};
|
|
156
|
-
|
|
157
|
-
}
|
|
186
|
+
});
|
|
158
187
|
</script>
|
|
159
188
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
189
|
+
<!-- Every toast shows at once, so nothing waits unseen behind the stack -->
|
|
190
|
+
<ToastRegion
|
|
191
|
+
{toaster}
|
|
192
|
+
side="top"
|
|
193
|
+
align="end"
|
|
194
|
+
maxVisible={Infinity}
|
|
195
|
+
expanded
|
|
196
|
+
{shortcut}
|
|
163
197
|
aria-label={label}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
{...stylex.attrs(styles.region)}
|
|
167
|
-
onpointerenter={() => (held = true)}
|
|
168
|
-
onpointerleave={() => (held = false)}
|
|
169
|
-
onfocusin={() => (held = true)}
|
|
170
|
-
onfocusout={(event) => {
|
|
171
|
-
if (!region?.contains(event.relatedTarget as Node | null)) held = false;
|
|
172
|
-
}}
|
|
198
|
+
style="--narvi-toaster-offset: {offset}"
|
|
199
|
+
data-narvi-toaster={id}
|
|
200
|
+
{...stylex.attrs(styles.region, crowded && styles.crowded)}
|
|
173
201
|
>
|
|
174
|
-
{#
|
|
175
|
-
{@const
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
data-tone={entry.tone}
|
|
179
|
-
{...stylex.attrs(styles.toast, leaving.includes(entry.revision) && styles.leaving)}
|
|
180
|
-
{@attach () => {
|
|
181
|
-
// Restarts when the toast changes, as a loading toast turns into a result
|
|
182
|
-
void entry.revision;
|
|
183
|
-
if (!held && !hidden) clock.run();
|
|
184
|
-
return () => clock.pause();
|
|
185
|
-
}}
|
|
186
|
-
>
|
|
202
|
+
{#snippet children(item, place)}
|
|
203
|
+
{@const data = item.data as ToastData}
|
|
204
|
+
<!-- One on its way out can no longer be pressed, nor be read a second time -->
|
|
205
|
+
<Toast inert={place.leaving || undefined} {...stylex.attrs(shared.focusable, styles.toast)}>
|
|
187
206
|
<span
|
|
188
207
|
{...stylex.attrs(
|
|
189
208
|
styles.icon,
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
(
|
|
209
|
+
data.tone === 'info' && styles.info,
|
|
210
|
+
data.tone === 'success' && styles.success,
|
|
211
|
+
data.tone === 'warning' && styles.warning,
|
|
212
|
+
data.tone === 'error' && styles.error,
|
|
213
|
+
(data.tone === 'default' || data.tone === 'loading') && styles.muted
|
|
195
214
|
)}
|
|
196
215
|
>
|
|
197
|
-
{#if
|
|
216
|
+
{#if data.tone === 'loading'}
|
|
198
217
|
<Spinner size={14} label={null} />
|
|
199
|
-
{:else if
|
|
218
|
+
{:else if data.tone === 'success'}
|
|
200
219
|
<Glyph name="check" stroke={1.75} />
|
|
201
|
-
{:else if
|
|
220
|
+
{:else if data.tone === 'error' || data.tone === 'warning'}
|
|
202
221
|
<Glyph name="alert" />
|
|
203
|
-
{:else if
|
|
222
|
+
{:else if data.tone === 'info'}
|
|
204
223
|
<Glyph name="info" />
|
|
205
224
|
{:else}
|
|
206
225
|
<span {...stylex.attrs(styles.dot)}></span>
|
|
207
226
|
{/if}
|
|
208
227
|
</span>
|
|
209
|
-
<
|
|
210
|
-
<
|
|
211
|
-
{
|
|
212
|
-
|
|
213
|
-
{/if}
|
|
214
|
-
</span>
|
|
228
|
+
<div {...stylex.attrs(styles.text)}>
|
|
229
|
+
<ToastTitle {...stylex.attrs(styles.title)} />
|
|
230
|
+
<ToastDescription {...stylex.attrs(styles.description)} />
|
|
231
|
+
</div>
|
|
215
232
|
<span {...stylex.attrs(styles.actions)}>
|
|
216
|
-
{#if
|
|
233
|
+
{#if data.action}
|
|
234
|
+
{@const action = data.action}
|
|
217
235
|
<Button
|
|
218
236
|
size="sm"
|
|
219
237
|
variant="secondary"
|
|
238
|
+
sx={styles.action}
|
|
220
239
|
onclick={(event) => {
|
|
221
|
-
|
|
222
|
-
if (!event.defaultPrevented)
|
|
240
|
+
action.onclick(event);
|
|
241
|
+
if (!event.defaultPrevented) answer(data.id);
|
|
223
242
|
}}
|
|
224
243
|
>
|
|
225
|
-
{
|
|
244
|
+
<span {...stylex.attrs(styles.actionLabel)}>{action.label}</span>
|
|
226
245
|
</Button>
|
|
227
246
|
{/if}
|
|
228
247
|
<!-- Every toast can be put away, a lasting one most of all; work under way goes on -->
|
|
229
|
-
<
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
>
|
|
236
|
-
<Glyph name="close" size={14} />
|
|
237
|
-
</Button>
|
|
248
|
+
<ToastClose>
|
|
249
|
+
{#snippet render({ props })}
|
|
250
|
+
<Button {...props} size="sm" variant="ghost" iconOnly aria-label="Dismiss">
|
|
251
|
+
<Glyph name="close" size={14} />
|
|
252
|
+
</Button>
|
|
253
|
+
{/snippet}
|
|
254
|
+
</ToastClose>
|
|
238
255
|
</span>
|
|
239
|
-
</
|
|
240
|
-
{/
|
|
241
|
-
</
|
|
256
|
+
</Toast>
|
|
257
|
+
{/snippet}
|
|
258
|
+
</ToastRegion>
|
|
@@ -3,6 +3,11 @@ export type ToasterProps = {
|
|
|
3
3
|
offset?: string | undefined;
|
|
4
4
|
/** Accessible name of the region. */
|
|
5
5
|
label?: string | undefined;
|
|
6
|
+
/**
|
|
7
|
+
* The key that moves focus to the newest toast, and back again: `F6` by default, or
|
|
8
|
+
* `alt+t`. `null` leaves the key to the app, for one that cycles its own areas with F6.
|
|
9
|
+
*/
|
|
10
|
+
shortcut?: string | null | undefined;
|
|
6
11
|
};
|
|
7
12
|
declare const Toaster: import("svelte").Component<ToasterProps, {}, "">;
|
|
8
13
|
type Toaster = ReturnType<typeof Toaster>;
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Toasts: short notes about something that happened away from where the person
|
|
3
|
-
* is looking. Call `toast()` from anywhere; one <Toaster /> shows them.
|
|
4
|
-
*/
|
|
5
1
|
export type ToastTone = 'default' | 'info' | 'success' | 'warning' | 'error' | 'loading';
|
|
6
2
|
/** A toast's id: the one `toast()` returns, or one of your own given as `id`. */
|
|
7
3
|
export type ToastId = string | number;
|
|
@@ -30,33 +26,24 @@ export type ToastOptions = {
|
|
|
30
26
|
/** Called when it goes by itself, as its time runs out. */
|
|
31
27
|
onAutoClose?: ((id: ToastId) => void) | undefined;
|
|
32
28
|
};
|
|
33
|
-
/**
|
|
34
|
-
export type
|
|
35
|
-
export type ToastEntry = {
|
|
29
|
+
/** What the Toaster reads from a toast's `data`: its own id, its tone and its action. */
|
|
30
|
+
export type ToastData = {
|
|
36
31
|
id: ToastId;
|
|
37
|
-
title: string;
|
|
38
32
|
tone: ToastTone;
|
|
39
|
-
description?: string | undefined;
|
|
40
33
|
action?: ToastAction | undefined;
|
|
41
|
-
duration: number | null;
|
|
42
|
-
onDismiss?: ((id: ToastId) => void) | undefined;
|
|
43
|
-
onAutoClose?: ((id: ToastId) => void) | undefined;
|
|
44
|
-
/** Changes each time the toast is replaced or updated, so its clock starts again. */
|
|
45
|
-
revision: number;
|
|
46
34
|
};
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
35
|
+
/**
|
|
36
|
+
* Narvi's queue, on ui-sdk's toaster: its own, so an app's own ui-sdk toasts don't mix with
|
|
37
|
+
* these. The Toaster shows it. ui-sdk keeps each toast's place, and its timer, which starts
|
|
38
|
+
* again whenever the toast changes.
|
|
39
|
+
*/
|
|
40
|
+
export declare const toaster: import("@ui-sdk/core/toast").Toaster<string>;
|
|
51
41
|
declare function show(title: string, options?: ToastOptions): ToastId;
|
|
52
42
|
declare function update(id: ToastId, patch: ToastOptions & {
|
|
53
43
|
title?: string | undefined;
|
|
54
44
|
}): void;
|
|
55
|
-
/**
|
|
56
|
-
|
|
57
|
-
* leaves; `revision` is the one it closed, so a toast replaced meanwhile stays.
|
|
58
|
-
*/
|
|
59
|
-
export declare function finish(id: ToastId, how: ToastEnd, revision?: number): void;
|
|
45
|
+
/** Closes a toast its action answered. The Toaster calls it. */
|
|
46
|
+
export declare function answer(id: ToastId): void;
|
|
60
47
|
/** Closes one toast, or every toast when given no id. Each one's `onDismiss` is called. */
|
|
61
48
|
declare function dismiss(id?: ToastId): void;
|
|
62
49
|
type Message<T> = string | ((value: T) => string);
|
|
@@ -2,65 +2,87 @@
|
|
|
2
2
|
* Toasts: short notes about something that happened away from where the person
|
|
3
3
|
* is looking. Call `toast()` from anywhere; one <Toaster /> shows them.
|
|
4
4
|
*/
|
|
5
|
+
import { createToaster } from '@ui-sdk/svelte/toast';
|
|
5
6
|
const DURATION = 5000;
|
|
6
7
|
let next = 1;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Narvi's queue, on ui-sdk's toaster: its own, so an app's own ui-sdk toasts don't mix with
|
|
10
|
+
* these. The Toaster shows it. ui-sdk keeps each toast's place, and its timer, which starts
|
|
11
|
+
* again whenever the toast changes.
|
|
12
|
+
*/
|
|
13
|
+
export const toaster = createToaster({ duration: DURATION });
|
|
14
|
+
// Each toast as it was last shown or updated, by ui-sdk's id for it
|
|
15
|
+
// eslint-disable-next-line svelte/prefer-svelte-reactivity -- read as toasts end, never by the page
|
|
16
|
+
const entries = new Map();
|
|
17
|
+
// Toasts their own action closed: an answer of its own, which calls neither callback
|
|
18
|
+
// eslint-disable-next-line svelte/prefer-svelte-reactivity -- read as toasts end, never by the page
|
|
19
|
+
const answered = new Set();
|
|
20
|
+
// ui-sdk's ids are strings; Narvi's may be numbers too, and 1 and '1' stay apart
|
|
21
|
+
const key = (id) => (typeof id === 'number' ? `n${id}` : `s${id}`);
|
|
12
22
|
// Errors and work in progress stay until they are dealt with
|
|
13
23
|
const lasting = (tone) => tone === 'error' || tone === 'loading';
|
|
14
|
-
|
|
24
|
+
const durationFor = (tone, duration) => duration !== undefined ? duration : lasting(tone) ? null : DURATION;
|
|
25
|
+
function ended(at, details) {
|
|
26
|
+
const entry = entries.get(at);
|
|
27
|
+
entries.delete(at);
|
|
28
|
+
if (answered.delete(at) || !entry)
|
|
29
|
+
return;
|
|
30
|
+
if (details.reason === 'timeout')
|
|
31
|
+
entry.onAutoClose?.(entry.id);
|
|
32
|
+
else if (details.reason !== 'action')
|
|
33
|
+
entry.onDismiss?.(entry.id);
|
|
34
|
+
}
|
|
35
|
+
// Every field is given each time, so a toast shown again under its id is replaced whole
|
|
36
|
+
function put(entry) {
|
|
37
|
+
const at = key(entry.id);
|
|
38
|
+
entries.set(at, entry);
|
|
39
|
+
toaster({
|
|
40
|
+
id: at,
|
|
41
|
+
title: entry.title,
|
|
42
|
+
description: entry.description,
|
|
43
|
+
type: entry.tone,
|
|
44
|
+
duration: entry.duration ?? Infinity,
|
|
45
|
+
data: { id: entry.id, tone: entry.tone, action: entry.action },
|
|
46
|
+
onDismiss: (details) => ended(at, details)
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
function show(title, options = {}) {
|
|
50
|
+
const id = options.id ?? next++;
|
|
15
51
|
const tone = options.tone ?? 'default';
|
|
16
|
-
|
|
52
|
+
put({
|
|
17
53
|
id,
|
|
18
54
|
title,
|
|
19
55
|
tone,
|
|
20
56
|
description: options.description,
|
|
21
57
|
action: options.action,
|
|
22
|
-
duration:
|
|
58
|
+
duration: durationFor(tone, options.duration),
|
|
23
59
|
onDismiss: options.onDismiss,
|
|
24
|
-
onAutoClose: options.onAutoClose
|
|
25
|
-
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
function show(title, options = {}) {
|
|
29
|
-
const id = options.id ?? next++;
|
|
30
|
-
const entry = entryFrom(id, title, options);
|
|
31
|
-
const at = toasts.list.findIndex((existing) => existing.id === id);
|
|
32
|
-
toasts.list = at === -1 ? [...toasts.list, entry] : toasts.list.with(at, entry);
|
|
60
|
+
onAutoClose: options.onAutoClose
|
|
61
|
+
});
|
|
33
62
|
return id;
|
|
34
63
|
}
|
|
35
64
|
function update(id, patch) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
return { ...entry, ...defined, id, tone, duration, revision: revisions++ };
|
|
43
|
-
});
|
|
65
|
+
const entry = entries.get(key(id));
|
|
66
|
+
if (!entry)
|
|
67
|
+
return;
|
|
68
|
+
const tone = patch.tone ?? entry.tone;
|
|
69
|
+
const defined = Object.fromEntries(Object.entries(patch).filter(([, value]) => value !== undefined));
|
|
70
|
+
put({ ...entry, ...defined, id: entry.id, tone, duration: durationFor(tone, patch.duration) });
|
|
44
71
|
}
|
|
45
|
-
/**
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
export function finish(id, how, revision) {
|
|
50
|
-
const entry = toasts.list.find((existing) => existing.id === id);
|
|
51
|
-
if (!entry || (revision !== undefined && entry.revision !== revision))
|
|
72
|
+
/** Closes a toast its action answered. The Toaster calls it. */
|
|
73
|
+
export function answer(id) {
|
|
74
|
+
const at = key(id);
|
|
75
|
+
if (!entries.has(at))
|
|
52
76
|
return;
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
entry.onDismiss?.(id);
|
|
56
|
-
else if (how === 'auto')
|
|
57
|
-
entry.onAutoClose?.(id);
|
|
77
|
+
answered.add(at);
|
|
78
|
+
toaster.dismiss(at);
|
|
58
79
|
}
|
|
59
80
|
/** Closes one toast, or every toast when given no id. Each one's `onDismiss` is called. */
|
|
60
81
|
function dismiss(id) {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
82
|
+
if (id === undefined)
|
|
83
|
+
toaster.dismiss();
|
|
84
|
+
else
|
|
85
|
+
toaster.dismiss(key(id));
|
|
64
86
|
}
|
|
65
87
|
/**
|
|
66
88
|
* Shows a toast and returns its id.
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
<script lang="ts" module>
|
|
2
|
-
import type { Loose } from '../../internal/loose.js';
|
|
3
|
-
import { Toggle } from '
|
|
2
|
+
import type { Loose, PartProps } from '../../internal/loose.js';
|
|
3
|
+
import { Toggle as UiToggle } from '@ui-sdk/svelte/toggle';
|
|
4
4
|
import type { Snippet } from 'svelte';
|
|
5
5
|
import { attrs, type Sx } from '../../internal/sx.js';
|
|
6
6
|
import { toggle, type ToggleSize, type ToggleTone } from '../../internal/toggle.js';
|
|
7
7
|
|
|
8
|
-
export
|
|
9
|
-
Omit<
|
|
8
|
+
export interface ToggleProps extends Loose<
|
|
9
|
+
Omit<PartProps<typeof UiToggle>, 'children' | 'render' | 'value'> & {
|
|
10
10
|
size?: ToggleSize | undefined;
|
|
11
11
|
/**
|
|
12
12
|
* How it shows it is pressed: lit in the `accent`, or `neutral`, in the fill of what is
|
|
@@ -15,11 +15,13 @@
|
|
|
15
15
|
tone?: ToggleTone | undefined;
|
|
16
16
|
/** Square, for a single icon. Give it an `aria-label`. */
|
|
17
17
|
iconOnly?: boolean | undefined;
|
|
18
|
+
/** The button element. Bindable. */
|
|
19
|
+
ref?: HTMLButtonElement | null | undefined;
|
|
18
20
|
sx?: Sx | undefined;
|
|
19
21
|
/** An icon, a short label, or both. */
|
|
20
22
|
children?: Snippet | undefined;
|
|
21
23
|
}
|
|
22
|
-
|
|
24
|
+
> {}
|
|
23
25
|
</script>
|
|
24
26
|
|
|
25
27
|
<script lang="ts">
|
|
@@ -38,16 +40,20 @@
|
|
|
38
40
|
const square = { sm: toggle.iconSm, md: toggle.iconMd };
|
|
39
41
|
</script>
|
|
40
42
|
|
|
41
|
-
|
|
43
|
+
<!-- An icon put in it takes its size (`data-icons`), as in a Button -->
|
|
44
|
+
<UiToggle
|
|
42
45
|
bind:pressed
|
|
43
|
-
bind:ref
|
|
44
|
-
data-slot="toggle"
|
|
45
46
|
data-tone={tone}
|
|
47
|
+
data-icons
|
|
46
48
|
{...rest}
|
|
47
49
|
{...attrs(
|
|
48
50
|
[toggle.base, tone === 'neutral' && toggle.neutral, toggle[size], iconOnly && square[size], sx],
|
|
49
51
|
className
|
|
50
52
|
)}
|
|
53
|
+
{@attach (element: HTMLButtonElement) => {
|
|
54
|
+
ref = element;
|
|
55
|
+
return () => (ref = null);
|
|
56
|
+
}}
|
|
51
57
|
>
|
|
52
58
|
{@render children?.()}
|
|
53
|
-
</
|
|
59
|
+
</UiToggle>
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { Loose } from '../../internal/loose.js';
|
|
2
|
-
import { Toggle } from '
|
|
1
|
+
import type { Loose, PartProps } from '../../internal/loose.js';
|
|
2
|
+
import { Toggle as UiToggle } from '@ui-sdk/svelte/toggle';
|
|
3
3
|
import type { Snippet } from 'svelte';
|
|
4
4
|
import { type Sx } from '../../internal/sx.js';
|
|
5
5
|
import { type ToggleSize, type ToggleTone } from '../../internal/toggle.js';
|
|
6
|
-
export
|
|
6
|
+
export interface ToggleProps extends Loose<Omit<PartProps<typeof UiToggle>, 'children' | 'render' | 'value'> & {
|
|
7
7
|
size?: ToggleSize | undefined;
|
|
8
8
|
/**
|
|
9
9
|
* How it shows it is pressed: lit in the `accent`, or `neutral`, in the fill of what is
|
|
@@ -12,22 +12,13 @@ export type ToggleProps = Loose<Omit<Toggle.RootProps, 'children' | 'child'> & {
|
|
|
12
12
|
tone?: ToggleTone | undefined;
|
|
13
13
|
/** Square, for a single icon. Give it an `aria-label`. */
|
|
14
14
|
iconOnly?: boolean | undefined;
|
|
15
|
+
/** The button element. Bindable. */
|
|
16
|
+
ref?: HTMLButtonElement | null | undefined;
|
|
15
17
|
sx?: Sx | undefined;
|
|
16
18
|
/** An icon, a short label, or both. */
|
|
17
19
|
children?: Snippet | undefined;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* How it shows it is pressed: lit in the `accent`, or `neutral`, in the fill of what is
|
|
23
|
-
* chosen, for a toolbar's icons that show or hide something.
|
|
24
|
-
*/
|
|
25
|
-
tone?: ToggleTone | undefined;
|
|
26
|
-
/** Square, for a single icon. Give it an `aria-label`. */
|
|
27
|
-
iconOnly?: boolean | undefined;
|
|
28
|
-
sx?: Sx | undefined;
|
|
29
|
-
/** An icon, a short label, or both. */
|
|
30
|
-
children?: Snippet | undefined;
|
|
31
|
-
}>, {}, "ref" | "pressed">;
|
|
20
|
+
}> {
|
|
21
|
+
}
|
|
22
|
+
declare const Toggle: import("svelte").Component<ToggleProps, {}, "ref" | "pressed">;
|
|
32
23
|
type Toggle = ReturnType<typeof Toggle>;
|
|
33
24
|
export default Toggle;
|