@diegopluna/narvi 0.5.2 → 0.5.4
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/dist/components/toast/Toaster.svelte +69 -3
- package/package.json +3 -3
- package/skills/building-ui/SKILL.md +1 -1
- package/skills/building-ui/references/components.md +22 -16
- package/skills/markdown/SKILL.md +1 -1
- package/skills/setup/SKILL.md +1 -1
- package/skills/styling/SKILL.md +1 -1
- package/skills/theming/SKILL.md +1 -1
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
Where toasts appear. Place one near the root of the app.
|
|
3
3
|
|
|
4
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.
|
|
5
|
+
dialogs, and ui-sdk keeps them usable while a modal dialog is open. A menu, a
|
|
6
|
+
popover or anything else that opens later without a modal opens over them, and
|
|
7
|
+
a new toast comes over everything again. Each
|
|
6
8
|
toast waits while the pointer or focus is on the stack, while the window is
|
|
7
9
|
hidden or in the background, so none goes unread.
|
|
8
10
|
-->
|
|
@@ -62,7 +64,10 @@
|
|
|
62
64
|
overflow: 'visible',
|
|
63
65
|
borderWidth: 0,
|
|
64
66
|
backgroundColor: 'transparent',
|
|
65
|
-
pointerEvents: 'none'
|
|
67
|
+
pointerEvents: 'none',
|
|
68
|
+
// Out of the top layer, while a menu or a popover opened after it is open: still over
|
|
69
|
+
// the page and the app shell's own layers, and under everything in the top layer
|
|
70
|
+
zIndex: 50
|
|
66
71
|
},
|
|
67
72
|
// More toasts than the window holds: the stack stops at the window's foot and scrolls, so
|
|
68
73
|
// the oldest can still be read and put away. Only then, as it clips what spills out of it,
|
|
@@ -161,11 +166,64 @@
|
|
|
161
166
|
</script>
|
|
162
167
|
|
|
163
168
|
<script lang="ts">
|
|
169
|
+
/** Puts the region on top of the top layer, keeping the focus where it is. */
|
|
170
|
+
function raise(region: HTMLElement) {
|
|
171
|
+
const focused = document.activeElement;
|
|
172
|
+
try {
|
|
173
|
+
if (region.matches(':popover-open')) region.hidePopover();
|
|
174
|
+
region.showPopover();
|
|
175
|
+
} catch {
|
|
176
|
+
// Not connected, or not a popover: nothing to raise
|
|
177
|
+
}
|
|
178
|
+
if (focused instanceof HTMLElement && focused !== document.activeElement) {
|
|
179
|
+
focused.focus({ preventScroll: true });
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/** Takes the region out of the top layer, into the page; it stays drawn, under what is in it. */
|
|
184
|
+
function lower(region: HTMLElement) {
|
|
185
|
+
if (!region.matches(':popover-open')) return;
|
|
186
|
+
const focused = document.activeElement;
|
|
187
|
+
try {
|
|
188
|
+
region.hidePopover();
|
|
189
|
+
} catch {
|
|
190
|
+
// Already out
|
|
191
|
+
}
|
|
192
|
+
if (focused instanceof HTMLElement && focused !== document.activeElement) {
|
|
193
|
+
focused.focus({ preventScroll: true });
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
164
197
|
let { offset = '1rem', label = 'Notifications', shortcut }: ToasterProps = $props();
|
|
165
198
|
|
|
166
199
|
const id = $props.id();
|
|
167
200
|
let crowded = $state(false);
|
|
168
201
|
|
|
202
|
+
// ui-sdk raises the region over whatever opens after it, so a toast that waits to be put away
|
|
203
|
+
// covers a menu opened under the corner. Over a modal dialog the toasts must stay on top, to be
|
|
204
|
+
// seen and used; over anything else, what the person opened last is on top. So the region
|
|
205
|
+
// steps out of the top layer, back into the page at its `zIndex`, as a popup that is not modal
|
|
206
|
+
// opens, before ui-sdk raises it (on the document, after the window's capture), and goes back
|
|
207
|
+
// in as a modal opens or a toast arrives.
|
|
208
|
+
$effect(() => {
|
|
209
|
+
const region = document.querySelector<HTMLElement>(`[data-narvi-toaster="${id}"]`);
|
|
210
|
+
if (!region || typeof region.showPopover !== 'function') return;
|
|
211
|
+
const isModal = (element: Element) =>
|
|
212
|
+
element.matches(':modal, [aria-modal="true"], [data-slot$="backdrop"]');
|
|
213
|
+
const modalOpen = () =>
|
|
214
|
+
[...document.querySelectorAll(':popover-open, :modal')].some(
|
|
215
|
+
(element) => element !== region && isModal(element)
|
|
216
|
+
);
|
|
217
|
+
const onToggle = (event: Event) => {
|
|
218
|
+
const opened = event.target;
|
|
219
|
+
if (!(opened instanceof Element) || (event as ToggleEvent).newState !== 'open') return;
|
|
220
|
+
if (opened === region || region.contains(opened)) return;
|
|
221
|
+
if (isModal(opened)) raise(region);
|
|
222
|
+
else if (!modalOpen()) lower(region);
|
|
223
|
+
};
|
|
224
|
+
window.addEventListener('toggle', onToggle, true);
|
|
225
|
+
return () => window.removeEventListener('toggle', onToggle, true);
|
|
226
|
+
});
|
|
169
227
|
// Whether the stack runs past the window's foot. Measured as the stack or the window changes
|
|
170
228
|
// size; while crowded the region keeps one height, and grows again only once the stack fits.
|
|
171
229
|
$effect(() => {
|
|
@@ -202,7 +260,15 @@
|
|
|
202
260
|
{#snippet children(item, place)}
|
|
203
261
|
{@const data = item.data as ToastData}
|
|
204
262
|
<!-- One on its way out can no longer be pressed, nor be read a second time -->
|
|
205
|
-
|
|
263
|
+
<!-- A toast that arrives comes over everything, a menu that is open among it -->
|
|
264
|
+
<Toast
|
|
265
|
+
inert={place.leaving || undefined}
|
|
266
|
+
{...stylex.attrs(shared.focusable, styles.toast)}
|
|
267
|
+
{@attach (element: HTMLElement) => {
|
|
268
|
+
const region = element.closest<HTMLElement>('[data-narvi-toaster]');
|
|
269
|
+
if (region && typeof region.showPopover === 'function') raise(region);
|
|
270
|
+
}}
|
|
271
|
+
>
|
|
206
272
|
<span
|
|
207
273
|
{...stylex.attrs(
|
|
208
274
|
styles.icon,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@diegopluna/narvi",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.4",
|
|
4
4
|
"packageManager": "pnpm@12.18.0",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -186,8 +186,8 @@
|
|
|
186
186
|
"@pierre/highlights": "0.5.0",
|
|
187
187
|
"@stylexjs/stylex": "0.19.1",
|
|
188
188
|
"@stylexjs/unplugin": "0.19.1",
|
|
189
|
-
"@ui-sdk/core": "0.1.0-beta.
|
|
190
|
-
"@ui-sdk/svelte": "0.1.0-beta.
|
|
189
|
+
"@ui-sdk/core": "0.1.0-beta.7",
|
|
190
|
+
"@ui-sdk/svelte": "0.1.0-beta.7",
|
|
191
191
|
"decode-named-character-reference": "1.3.0",
|
|
192
192
|
"dompurify": "3.4.17",
|
|
193
193
|
"esm-env": "^1.2.2",
|
|
@@ -81,7 +81,7 @@ Markdown's table styles: Markdown's tables and this one share their look.
|
|
|
81
81
|
| `ColorField` | A colour: a swatch that opens Narvi's picker, beside a hex field (`label`, `bind:value`, `onchange`, `size`, `labels`) | `color-field` |
|
|
82
82
|
| `SplitButton` | A main action joined to a menu of how to do it (`menu`, `menuLabel`, `label`, `variant` incl. `ghost`, `shape`, `mainDisabled`, `mainSx`/`menuSx`, `menuMinWidth`) | `split-button` |
|
|
83
83
|
| `Toggle` | A button that stays pressed (`tone`: `accent`, or `neutral` for toolbar icons) | `toggle` |
|
|
84
|
-
| `ToggleGroup.Root`, `.Item` | Toggles that belong together: one pressed, or any number
|
|
84
|
+
| `ToggleGroup.Root`, `.Item` | Toggles that belong together: one pressed, or any number; toggle buttons (`aria-pressed`) either way, never radios | `toggle-group` |
|
|
85
85
|
| `SettingsGroup` | A titled group of settings: a heading, an action, the rows on one card | `settings-group` |
|
|
86
86
|
| `SettingsRow` | One setting: what it is, beside its control (`leading`, `dimmed`, `mono`) | `settings-row` |
|
|
87
87
|
| `Tabs` | Views that share one place (`tabs: TabItem[]`, `label`, `bind:value`; `activation="manual"` for a slow panel) | `tabs` |
|
|
@@ -176,6 +176,12 @@ browser; a `container` on a Root or a Content still wins, and the popups inside
|
|
|
176
176
|
{@render children()}
|
|
177
177
|
```
|
|
178
178
|
|
|
179
|
+
With a container outside the element the app is mounted on, as `document.body` is here, an Escape
|
|
180
|
+
handler inside a popup that takes the key for itself (clearing a field, leaving an edit) calls
|
|
181
|
+
`event.preventDefault()`. Stopping propagation alone lets the popup close: ui-sdk listens for
|
|
182
|
+
Escape on `document` and skips only a key whose default is prevented, and Svelte runs a handler
|
|
183
|
+
outside the mount target from `document` too, beside ui-sdk's listener.
|
|
184
|
+
|
|
179
185
|
To drive `open` from the app, bind it, or pass it with an `onOpenChange` that keeps your state:
|
|
180
186
|
`open={shown && !dragging} onOpenChange={(next) => (shown = next)}` follows `dragging` even after
|
|
181
187
|
the trigger opened it. An `open` passed with neither is only where it starts, as any Svelte prop
|
|
@@ -210,21 +216,21 @@ errors with an `Announcer` too.
|
|
|
210
216
|
|
|
211
217
|
## Feedback and status
|
|
212
218
|
|
|
213
|
-
| Component | Use it for
|
|
214
|
-
| ------------------------------------ |
|
|
215
|
-
| `Toaster`, `toast()` | Short notes about something that happened; one Toaster at the root
|
|
216
|
-
| `Notice` | A note in place: what is happening or went wrong, and what to do
|
|
217
|
-
| `EmptyState` | An empty place: what it is for and how to fill it (`title`, `level`, `description`, `media`, `actions`)
|
|
218
|
-
| `Badge` | A status, category or count (`tone`, `info` among them; `color` for a label's own dot)
|
|
219
|
-
| `StatusIndicator` | Where a run, thread or machine stands, by shape and colour
|
|
220
|
-
| `StatusDot` | A small dot of status colour (`tone`, `shape`), beside a name or on a mark
|
|
221
|
-
| `Progress` | How far along a task is
|
|
222
|
-
| `Spinner` | Something in progress
|
|
223
|
-
| `Skeleton` | A stand-in for content on its way
|
|
224
|
-
| `Shimmer` | Text that says work is under way (`tone` `neutral` by default, or `accent` for the one live thing)
|
|
225
|
-
| `RollingText` | A phrase that rolls to its next value ("Reading…", "Running…")
|
|
226
|
-
| `Announcer` | Says a short message to screen readers without showing anything
|
|
227
|
-
| `Avatar.Root`, `.Image`, `.Fallback` | A person: a picture, or initials (`size` `xs` is 20px; `label={null}` beside a written name)
|
|
219
|
+
| Component | Use it for | Docs slug |
|
|
220
|
+
| ------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------ |
|
|
221
|
+
| `Toaster`, `toast()` | Short notes about something that happened; one Toaster at the root. Toasts stay over the page and a modal dialog; a menu or popover opened later is over them, a new toast over everything | `toast` |
|
|
222
|
+
| `Notice` | A note in place: what is happening or went wrong, and what to do | `notice` |
|
|
223
|
+
| `EmptyState` | An empty place: what it is for and how to fill it (`title`, `level`, `description`, `media`, `actions`) | `empty-state` |
|
|
224
|
+
| `Badge` | A status, category or count (`tone`, `info` among them; `color` for a label's own dot) | `badge` |
|
|
225
|
+
| `StatusIndicator` | Where a run, thread or machine stands, by shape and colour | `status-indicator` |
|
|
226
|
+
| `StatusDot` | A small dot of status colour (`tone`, `shape`), beside a name or on a mark | `status-indicator` |
|
|
227
|
+
| `Progress` | How far along a task is | `progress` |
|
|
228
|
+
| `Spinner` | Something in progress | `spinner` |
|
|
229
|
+
| `Skeleton` | A stand-in for content on its way | `skeleton` |
|
|
230
|
+
| `Shimmer` | Text that says work is under way (`tone` `neutral` by default, or `accent` for the one live thing) | `shimmer` |
|
|
231
|
+
| `RollingText` | A phrase that rolls to its next value ("Reading…", "Running…") | none |
|
|
232
|
+
| `Announcer` | Says a short message to screen readers without showing anything | `announcer` |
|
|
233
|
+
| `Avatar.Root`, `.Image`, `.Fallback` | A person: a picture, or initials (`size` `xs` is 20px; `label={null}` beside a written name) | `avatar` |
|
|
228
234
|
|
|
229
235
|
## App shell
|
|
230
236
|
|
package/skills/markdown/SKILL.md
CHANGED
package/skills/setup/SKILL.md
CHANGED
package/skills/styling/SKILL.md
CHANGED
package/skills/theming/SKILL.md
CHANGED