@diegopluna/narvi 0.5.0 → 0.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/app-shell/AppShellPanel.svelte +3 -2
- package/dist/components/collapsible/CollapsibleRoot.svelte +7 -1
- package/dist/components/command/CommandDialog.svelte +20 -3
- package/dist/components/command/CommandStatus.svelte +15 -0
- package/dist/components/command/CommandStatus.svelte.d.ts +7 -0
- package/dist/components/command/index.d.ts +2 -4
- package/dist/components/command/index.js +1 -4
- package/dist/components/composer/ComposerModelPicker.svelte +3 -0
- package/dist/components/dialog/ConfirmDialog.svelte +7 -2
- package/dist/components/dialog/DialogContent.svelte +9 -2
- package/dist/components/dialog/DialogRoot.svelte +20 -2
- package/dist/components/dialog/styles.d.ts +3 -0
- package/dist/components/dialog/styles.js +5 -0
- package/dist/components/hover-card/HoverCardContent.svelte +7 -1
- package/dist/components/hover-card/HoverCardRoot.svelte +17 -1
- package/dist/components/menu/ContextMenuContent.svelte +11 -1
- package/dist/components/menu/MenuContent.svelte +7 -1
- package/dist/components/menu/MenuRoot.svelte +27 -0
- package/dist/components/menu/MenuRoot.svelte.d.ts +7 -0
- package/dist/components/menu/MenuSub.svelte +26 -0
- package/dist/components/menu/MenuSub.svelte.d.ts +7 -0
- package/dist/components/menu/context-menu.d.ts +2 -3
- package/dist/components/menu/context-menu.js +2 -4
- package/dist/components/menu/index.d.ts +4 -4
- package/dist/components/menu/index.js +2 -7
- package/dist/components/popover/PopoverContent.svelte +7 -1
- package/dist/components/popover/PopoverRoot.svelte +27 -0
- package/dist/components/popover/PopoverRoot.svelte.d.ts +7 -0
- package/dist/components/popover/index.d.ts +2 -3
- package/dist/components/popover/index.js +1 -5
- package/dist/components/resize-handle/ResizeHandle.svelte +80 -14
- package/dist/components/resize-handle/ResizeHandle.svelte.d.ts +15 -1
- package/dist/components/select/Select.svelte +4 -1
- package/dist/components/sheet/SheetContent.svelte +8 -1
- package/dist/components/split-button/SplitButton.svelte +10 -1
- package/dist/components/tooltip/TooltipContent.svelte +7 -1
- package/dist/components/tooltip/TooltipRoot.svelte +12 -1
- package/dist/index.d.ts +6 -4
- package/dist/index.js +4 -0
- package/dist/internal/popup.d.ts +24 -0
- package/dist/internal/popup.js +56 -0
- package/package.json +1 -1
- package/skills/building-ui/SKILL.md +8 -8
- package/skills/building-ui/references/components.md +42 -0
- package/skills/markdown/SKILL.md +1 -1
- package/skills/setup/SKILL.md +3 -1
- package/skills/styling/SKILL.md +1 -1
- package/skills/theming/SKILL.md +1 -1
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { Popover } from '@ui-sdk/svelte/popover';
|
|
2
|
-
import { type Loosened } from '../../internal/loose.js';
|
|
3
1
|
import Close from './PopoverClose.svelte';
|
|
4
2
|
import Content from './PopoverContent.svelte';
|
|
3
|
+
import Root from './PopoverRoot.svelte';
|
|
5
4
|
import Trigger from './PopoverTrigger.svelte';
|
|
6
|
-
declare const Root: Loosened<typeof Popover>;
|
|
7
5
|
export { Root, Trigger, Content, Close };
|
|
8
6
|
export type { PopoverCloseProps } from './PopoverClose.svelte';
|
|
9
7
|
export type { PopoverContentProps } from './PopoverContent.svelte';
|
|
8
|
+
export type { PopoverRootProps } from './PopoverRoot.svelte';
|
|
10
9
|
export type { PopoverTriggerProps } from './PopoverTrigger.svelte';
|
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
import { Popover } from '@ui-sdk/svelte/popover';
|
|
2
|
-
import { loose } from '../../internal/loose.js';
|
|
3
1
|
import Close from './PopoverClose.svelte';
|
|
4
2
|
import Content from './PopoverContent.svelte';
|
|
3
|
+
import Root from './PopoverRoot.svelte';
|
|
5
4
|
import Trigger from './PopoverTrigger.svelte';
|
|
6
|
-
// Behaviour only, with nothing to style: ui-sdk's own part, typed to take `undefined` for each
|
|
7
|
-
// optional prop (`internal/loose.ts`)
|
|
8
|
-
const Root = loose(Popover);
|
|
9
5
|
export { Root, Trigger, Content, Close };
|
|
@@ -3,8 +3,13 @@
|
|
|
3
3
|
|
|
4
4
|
While dragging, the size is written straight onto the target as a custom
|
|
5
5
|
property, so nothing re-renders on every pointer move; the bound value
|
|
6
|
-
changes once, when the drag ends
|
|
7
|
-
|
|
6
|
+
changes once, when the drag ends, and the property is put back as it was.
|
|
7
|
+
Draw the target from both, the property first and the value as its fallback:
|
|
8
|
+
`width: var(--narvi-size, 320px)`. Narvi registers `--narvi-size` as not
|
|
9
|
+
inherited, so a move restyles the target alone, not what is in it.
|
|
10
|
+
|
|
11
|
+
The keyboard moves it in steps, Home and End go to the limits, and a
|
|
12
|
+
double-click puts it back. (Eregion's ResizableEdge.)
|
|
8
13
|
-->
|
|
9
14
|
<script lang="ts" module>
|
|
10
15
|
import * as stylex from '@stylexjs/stylex';
|
|
@@ -30,9 +35,23 @@
|
|
|
30
35
|
edge?: 'start' | 'end' | undefined;
|
|
31
36
|
/** `vertical` resizes widths; `horizontal` resizes heights, as for a drawer below. */
|
|
32
37
|
orientation?: 'vertical' | 'horizontal' | undefined;
|
|
33
|
-
/** The element being resized
|
|
38
|
+
/** The element being resized. */
|
|
34
39
|
target?: HTMLElement | null | undefined;
|
|
40
|
+
/**
|
|
41
|
+
* The custom property the size is written to on `target` while dragging, and taken off
|
|
42
|
+
* again when the drag ends. `--narvi-size` by default, which Narvi registers as not
|
|
43
|
+
* inherited. Register one of your own the same way
|
|
44
|
+
* (`@property --x { syntax: '*'; inherits: false; }`), or every move restyles all that
|
|
45
|
+
* is in the target.
|
|
46
|
+
*/
|
|
35
47
|
property?: string | undefined;
|
|
48
|
+
/** Called as a drag starts, before the first move. */
|
|
49
|
+
onDragStart?: (() => void) | undefined;
|
|
50
|
+
/**
|
|
51
|
+
* Called as a drag ends, with the size it ended at, once `value` has it. If the handle
|
|
52
|
+
* goes away mid-drag, it is called with the size from before the drag, which is kept.
|
|
53
|
+
*/
|
|
54
|
+
onDragEnd?: ((value: number) => void) | undefined;
|
|
36
55
|
/** Names the handle, for assistive technology: "Resize the panel". */
|
|
37
56
|
label: string;
|
|
38
57
|
sx?: Sx | undefined;
|
|
@@ -82,6 +101,23 @@
|
|
|
82
101
|
'::after': { backgroundColor: colors.accent, transitionDelay: '0ms' }
|
|
83
102
|
}
|
|
84
103
|
});
|
|
104
|
+
|
|
105
|
+
const SIZE_PROPERTY = '--narvi-size';
|
|
106
|
+
|
|
107
|
+
let registered = false;
|
|
108
|
+
/**
|
|
109
|
+
* Registers the handle's own property as not inherited and with no initial value, so writing
|
|
110
|
+
* it restyles the target alone, and where it is unset its fallback applies. Once, in a browser.
|
|
111
|
+
*/
|
|
112
|
+
function register() {
|
|
113
|
+
if (registered || typeof CSS === 'undefined' || !('registerProperty' in CSS)) return;
|
|
114
|
+
registered = true;
|
|
115
|
+
try {
|
|
116
|
+
CSS.registerProperty({ name: SIZE_PROPERTY, syntax: '*', inherits: false });
|
|
117
|
+
} catch {
|
|
118
|
+
// Registered already, by another copy of Narvi or by the app
|
|
119
|
+
}
|
|
120
|
+
}
|
|
85
121
|
</script>
|
|
86
122
|
|
|
87
123
|
<script lang="ts">
|
|
@@ -94,24 +130,32 @@
|
|
|
94
130
|
edge = 'start',
|
|
95
131
|
orientation = 'vertical',
|
|
96
132
|
target,
|
|
97
|
-
property =
|
|
133
|
+
property = SIZE_PROPERTY,
|
|
134
|
+
onDragStart,
|
|
135
|
+
onDragEnd,
|
|
98
136
|
label,
|
|
99
137
|
sx,
|
|
100
138
|
class: className,
|
|
101
139
|
...rest
|
|
102
140
|
}: ResizeHandleProps = $props();
|
|
103
141
|
|
|
142
|
+
register();
|
|
143
|
+
|
|
104
144
|
let dragging = $state(false);
|
|
145
|
+
/** Ends the drag under way: keeps the size it reached, or with `false`, the one before it. */
|
|
146
|
+
let stop: ((keep: boolean) => void) | undefined;
|
|
105
147
|
const limit = () => (typeof max === 'function' ? max() : max);
|
|
106
148
|
const clamp = (size: number, upper = limit()) =>
|
|
107
149
|
Math.round(Math.min(Math.max(size, min), Math.max(min, upper)));
|
|
108
150
|
|
|
151
|
+
// Gone mid-drag, as when its panel goes narrow: nothing is left on the target
|
|
152
|
+
$effect(() => () => stop?.(false));
|
|
153
|
+
|
|
109
154
|
function onpointerdown(event: PointerEvent & { currentTarget: HTMLDivElement }) {
|
|
110
|
-
if (event.button !== 0) return;
|
|
155
|
+
if (event.button !== 0 || stop) return;
|
|
111
156
|
event.preventDefault();
|
|
112
157
|
const handle = event.currentTarget;
|
|
113
158
|
handle.setPointerCapture(event.pointerId);
|
|
114
|
-
dragging = true;
|
|
115
159
|
const start = orientation === 'vertical' ? event.clientX : event.clientY;
|
|
116
160
|
const from = value;
|
|
117
161
|
const upper = limit();
|
|
@@ -120,22 +164,44 @@
|
|
|
120
164
|
let sign = edge === 'start' ? -1 : 1;
|
|
121
165
|
if (orientation === 'vertical' && rtl) sign = -sign;
|
|
122
166
|
let size = from;
|
|
167
|
+
// This drag's target and property, and what the target held there before it
|
|
168
|
+
const element = target;
|
|
169
|
+
const name = property;
|
|
170
|
+
const before = element?.style.getPropertyValue(name) ?? '';
|
|
171
|
+
const priority = element?.style.getPropertyPriority(name) ?? '';
|
|
172
|
+
let written = false;
|
|
123
173
|
|
|
124
174
|
const move = (moving: PointerEvent) => {
|
|
125
175
|
const now = orientation === 'vertical' ? moving.clientX : moving.clientY;
|
|
126
|
-
|
|
127
|
-
|
|
176
|
+
const next = clamp(from + (now - start) * sign, upper);
|
|
177
|
+
// A move that ends at the same pixel, or past a limit, restyles nothing
|
|
178
|
+
if (written && next === size) return;
|
|
179
|
+
size = next;
|
|
180
|
+
written = true;
|
|
181
|
+
element?.style.setProperty(name, `${size}px`);
|
|
128
182
|
};
|
|
129
|
-
const
|
|
183
|
+
const end = () => stop?.(true);
|
|
184
|
+
stop = (keep) => {
|
|
185
|
+
stop = undefined;
|
|
130
186
|
dragging = false;
|
|
131
187
|
handle.removeEventListener('pointermove', move);
|
|
132
|
-
handle.removeEventListener('pointerup',
|
|
133
|
-
handle.removeEventListener('pointercancel',
|
|
134
|
-
|
|
188
|
+
handle.removeEventListener('pointerup', end);
|
|
189
|
+
handle.removeEventListener('pointercancel', end);
|
|
190
|
+
handle.removeEventListener('lostpointercapture', end);
|
|
191
|
+
if (keep) value = size;
|
|
192
|
+
// What was there comes back, and the value draws the target from here, before the
|
|
193
|
+
// next frame: Svelte applies it in a microtask
|
|
194
|
+
if (before) element?.style.setProperty(name, before, priority);
|
|
195
|
+
else element?.style.removeProperty(name);
|
|
196
|
+
onDragEnd?.(keep ? size : from);
|
|
135
197
|
};
|
|
136
198
|
handle.addEventListener('pointermove', move);
|
|
137
|
-
handle.addEventListener('pointerup',
|
|
138
|
-
handle.addEventListener('pointercancel',
|
|
199
|
+
handle.addEventListener('pointerup', end);
|
|
200
|
+
handle.addEventListener('pointercancel', end);
|
|
201
|
+
// The capture is lost without an up when the handle leaves the document, say
|
|
202
|
+
handle.addEventListener('lostpointercapture', end);
|
|
203
|
+
dragging = true;
|
|
204
|
+
onDragStart?.();
|
|
139
205
|
}
|
|
140
206
|
|
|
141
207
|
function onkeydown(event: KeyboardEvent & { currentTarget: HTMLDivElement }) {
|
|
@@ -17,9 +17,23 @@ export type ResizeHandleProps = Omit<HTMLAttributes<HTMLDivElement>, 'children'>
|
|
|
17
17
|
edge?: 'start' | 'end' | undefined;
|
|
18
18
|
/** `vertical` resizes widths; `horizontal` resizes heights, as for a drawer below. */
|
|
19
19
|
orientation?: 'vertical' | 'horizontal' | undefined;
|
|
20
|
-
/** The element being resized
|
|
20
|
+
/** The element being resized. */
|
|
21
21
|
target?: HTMLElement | null | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* The custom property the size is written to on `target` while dragging, and taken off
|
|
24
|
+
* again when the drag ends. `--narvi-size` by default, which Narvi registers as not
|
|
25
|
+
* inherited. Register one of your own the same way
|
|
26
|
+
* (`@property --x { syntax: '*'; inherits: false; }`), or every move restyles all that
|
|
27
|
+
* is in the target.
|
|
28
|
+
*/
|
|
22
29
|
property?: string | undefined;
|
|
30
|
+
/** Called as a drag starts, before the first move. */
|
|
31
|
+
onDragStart?: (() => void) | undefined;
|
|
32
|
+
/**
|
|
33
|
+
* Called as a drag ends, with the size it ended at, once `value` has it. If the handle
|
|
34
|
+
* goes away mid-drag, it is called with the size from before the drag, which is kept.
|
|
35
|
+
*/
|
|
36
|
+
onDragEnd?: ((value: number) => void) | undefined;
|
|
23
37
|
/** Names the handle, for assistive technology: "Resize the panel". */
|
|
24
38
|
label: string;
|
|
25
39
|
sx?: Sx | undefined;
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
import Glyph from '../../internal/Glyph.svelte';
|
|
19
19
|
import { control, type ControlSize } from '../../internal/control.js';
|
|
20
20
|
import { layer } from '../../internal/layer.js';
|
|
21
|
+
import { popupContainer } from '../../internal/popup.js';
|
|
21
22
|
import { attrs, type Sx } from '../../internal/sx.js';
|
|
22
23
|
import { colors, font } from '../../tokens.stylex.js';
|
|
23
24
|
import { getFieldContext } from '../field/context.js';
|
|
@@ -171,6 +172,7 @@
|
|
|
171
172
|
}: SelectProps = $props();
|
|
172
173
|
|
|
173
174
|
const field = getFieldContext();
|
|
175
|
+
const container = popupContainer();
|
|
174
176
|
const selected = $derived(options.find((option) => option.value === value));
|
|
175
177
|
const groups = $derived(grouped(options));
|
|
176
178
|
const detailed = $derived(options.some((option) => option.detail));
|
|
@@ -180,6 +182,7 @@
|
|
|
180
182
|
items={listed(groups)}
|
|
181
183
|
bind:value={() => value ?? null, (next) => (value = next ?? undefined)}
|
|
182
184
|
bind:open={() => open && options.length > 0, (next) => (open = next && options.length > 0)}
|
|
185
|
+
container={container()}
|
|
183
186
|
onValueChange={(next) => {
|
|
184
187
|
if (next !== null) onchange?.(next);
|
|
185
188
|
}}
|
|
@@ -205,7 +208,7 @@
|
|
|
205
208
|
</span>
|
|
206
209
|
<span {...stylex.attrs(styles.selector)}><Glyph name="selector" size={14} /></span>
|
|
207
210
|
</SelectTrigger>
|
|
208
|
-
<!-- In
|
|
211
|
+
<!-- In the top layer, in place unless the app gives a container. The list scrolls in the surface. With
|
|
209
212
|
no options it stays shut, rather than open as an empty sliver. -->
|
|
210
213
|
<SelectContent {align} sideOffset={6} collisionPadding={8} {...stylex.attrs(layer.surface)}>
|
|
211
214
|
{#each groups as group, index (index)}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
<script lang="ts" module>
|
|
2
2
|
import type { Loose, PartProps } from '../../internal/loose.js';
|
|
3
|
+
import { nestDialog, usePopupContainer } from '../../internal/popup.js';
|
|
3
4
|
import { DialogBackdrop, DialogClose, DialogContent } from '@ui-sdk/svelte/dialog';
|
|
4
5
|
import * as stylex from '@stylexjs/stylex';
|
|
5
6
|
import type { Snippet } from 'svelte';
|
|
@@ -41,12 +42,17 @@
|
|
|
41
42
|
closeLabel = 'Close',
|
|
42
43
|
focusOnOpen = 'sheet',
|
|
43
44
|
initialFocus,
|
|
45
|
+
container,
|
|
44
46
|
sx,
|
|
45
47
|
class: className,
|
|
46
48
|
children,
|
|
47
49
|
...rest
|
|
48
50
|
}: SheetContentProps = $props();
|
|
49
51
|
|
|
52
|
+
// In the container around it, or its own; the popups inside it follow
|
|
53
|
+
const target = usePopupContainer(() => container);
|
|
54
|
+
const nested = nestDialog();
|
|
55
|
+
|
|
50
56
|
const across = $derived(side === 'start' || side === 'end');
|
|
51
57
|
</script>
|
|
52
58
|
|
|
@@ -54,8 +60,9 @@
|
|
|
54
60
|
A dialog along an edge, on ui-sdk's Dialog rather than its Drawer: a drawer moves itself, by
|
|
55
61
|
drag and snap points, where a sheet slides in on Narvi's own transition and stays put.
|
|
56
62
|
-->
|
|
57
|
-
<DialogBackdrop {...stylex.attrs(dialog.overlay)} />
|
|
63
|
+
<DialogBackdrop {...stylex.attrs(dialog.overlay, nested && dialog.nested)} />
|
|
58
64
|
<DialogContent
|
|
65
|
+
container={target()}
|
|
59
66
|
data-side={side}
|
|
60
67
|
initialFocus={initialFocus ?? (focusOnOpen === 'first' ? 'auto' : 'content')}
|
|
61
68
|
{...rest}
|
|
@@ -183,7 +183,16 @@
|
|
|
183
183
|
<span {...stylex.attrs(styles.label)}>{@render children?.()}</span>
|
|
184
184
|
</Button>
|
|
185
185
|
{#if menu}
|
|
186
|
-
|
|
186
|
+
<!-- `open` is written back only when the app has not followed (`internal/popup.ts`) -->
|
|
187
|
+
<Menu.Root
|
|
188
|
+
bind:open={
|
|
189
|
+
() => open,
|
|
190
|
+
(next) => {
|
|
191
|
+
if (open !== next) open = next;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
onOpenChange={onopenchange}
|
|
195
|
+
>
|
|
187
196
|
<Menu.Trigger disabled={disabled || loading}>
|
|
188
197
|
{#snippet child({ props })}
|
|
189
198
|
<Button
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
<script lang="ts" module>
|
|
2
2
|
import type { Loose, PartProps } from '../../internal/loose.js';
|
|
3
|
+
import { usePopupContainer } from '../../internal/popup.js';
|
|
3
4
|
import { TooltipContent as UiTooltipContent } from '@ui-sdk/svelte/tooltip';
|
|
4
5
|
import * as stylex from '@stylexjs/stylex';
|
|
5
6
|
import type { Snippet } from 'svelte';
|
|
@@ -83,16 +84,21 @@
|
|
|
83
84
|
collisionPadding = 8,
|
|
84
85
|
shortcut,
|
|
85
86
|
layout = 'row',
|
|
87
|
+
container,
|
|
86
88
|
sx,
|
|
87
89
|
class: className,
|
|
88
90
|
children,
|
|
89
91
|
...rest
|
|
90
92
|
}: TooltipContentProps = $props();
|
|
93
|
+
|
|
94
|
+
// In the container around it, or its own; the popups inside it follow
|
|
95
|
+
const target = usePopupContainer(() => container);
|
|
91
96
|
</script>
|
|
92
97
|
|
|
93
|
-
<!-- In
|
|
98
|
+
<!-- In the top layer, in place unless given a container, and in the page while closed, hidden, so it names or describes
|
|
94
99
|
its trigger before focus reaches it -->
|
|
95
100
|
<UiTooltipContent
|
|
101
|
+
container={target()}
|
|
96
102
|
{sideOffset}
|
|
97
103
|
{collisionPadding}
|
|
98
104
|
{...rest}
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
import { setContext, type Snippet } from 'svelte';
|
|
5
5
|
import { arrivedByKeyboard, listenForNavigation } from './intent.js';
|
|
6
6
|
import { tooltipDefaults } from './TooltipProvider.svelte';
|
|
7
|
+
import { usePopupContainer } from '../../internal/popup.js';
|
|
7
8
|
|
|
8
9
|
export interface TooltipRootProps extends Loose<
|
|
9
10
|
Omit<PartProps<typeof Tooltip>, 'children'> & {
|
|
@@ -37,6 +38,7 @@
|
|
|
37
38
|
disabled,
|
|
38
39
|
type = 'description',
|
|
39
40
|
onOpenChange,
|
|
41
|
+
container,
|
|
40
42
|
children,
|
|
41
43
|
...rest
|
|
42
44
|
}: TooltipRootProps = $props();
|
|
@@ -47,10 +49,19 @@
|
|
|
47
49
|
|
|
48
50
|
let triggerDisabled = $state.raw<() => boolean>(() => false);
|
|
49
51
|
setContext<TriggerRegistry>(TRIGGER_KEY, (get) => (triggerDisabled = get));
|
|
52
|
+
|
|
53
|
+
const target = usePopupContainer(() => container);
|
|
50
54
|
</script>
|
|
51
55
|
|
|
56
|
+
<!-- `open` is written back only when the app has not followed (`internal/popup.ts`) -->
|
|
52
57
|
<Tooltip
|
|
53
|
-
bind:open
|
|
58
|
+
bind:open={
|
|
59
|
+
() => open,
|
|
60
|
+
(next) => {
|
|
61
|
+
if (open !== next) open = next;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
container={target()}
|
|
54
65
|
delay={delay ?? provided?.delay}
|
|
55
66
|
closeDelay={closeDelay ?? provided?.closeDelay}
|
|
56
67
|
disabled={(disabled ?? provided?.disabled ?? false) || triggerDisabled()}
|
package/dist/index.d.ts
CHANGED
|
@@ -30,12 +30,12 @@ export type { ColorFieldLabels, ColorFieldProps, ColorFieldSize } from './compon
|
|
|
30
30
|
export * as Collapsible from './components/collapsible/index.js';
|
|
31
31
|
export type { CollapsibleContentProps, CollapsibleRootProps, CollapsibleTriggerProps } from './components/collapsible/index.js';
|
|
32
32
|
export * as Command from './components/command/index.js';
|
|
33
|
-
export type { CommandDialogProps, CommandEmptyProps, CommandFooterProps, CommandGroupProps, CommandInputProps, CommandItemProps, CommandListProps, CommandRootProps, CommandSeparatorProps } from './components/command/index.js';
|
|
33
|
+
export type { CommandDialogProps, CommandEmptyProps, CommandFooterProps, CommandGroupProps, CommandInputProps, CommandItemProps, CommandListProps, CommandRootProps, CommandSeparatorProps, CommandStatusProps } from './components/command/index.js';
|
|
34
34
|
export * as Composer from './components/composer/index.js';
|
|
35
35
|
export { getComposerContext } from './components/composer/index.js';
|
|
36
36
|
export type { ComposerAttachButtonProps, ComposerAttachmentProps, ComposerAttachmentsProps, ComposerContext, ComposerMessage, ComposerModel, ComposerModelPickerProps, ComposerModelProvider, ComposerRejection, ComposerRootProps, ComposerStatus, ComposerSubmitProps, ComposerTextareaProps, ComposerToggleProps, ComposerToolbarProps, ComposerTrayProps } from './components/composer/index.js';
|
|
37
37
|
export * as ContextMenu from './components/menu/context-menu.js';
|
|
38
|
-
export type { ContextMenuContentProps, ContextMenuTriggerProps } from './components/menu/context-menu.js';
|
|
38
|
+
export type { ContextMenuContentProps, ContextMenuRootProps, ContextMenuTriggerProps } from './components/menu/context-menu.js';
|
|
39
39
|
export * as Conversation from './components/conversation/index.js';
|
|
40
40
|
export { getConversationContext } from './components/conversation/index.js';
|
|
41
41
|
export type { ConversationContentProps, ConversationContext, ConversationMode, ConversationEmptyProps, ConversationRootProps, ConversationScrollButtonProps } from './components/conversation/index.js';
|
|
@@ -67,7 +67,7 @@ export type { KbdProps } from './components/kbd/Kbd.svelte';
|
|
|
67
67
|
export { default as Link } from './components/link/Link.svelte';
|
|
68
68
|
export type { LinkProps } from './components/link/Link.svelte';
|
|
69
69
|
export * as Menu from './components/menu/index.js';
|
|
70
|
-
export type { MenuCheckboxItemProps, MenuContentProps, MenuGroupProps, MenuItemProps, MenuLabelProps, MenuRadioGroupProps, MenuRadioItemProps, MenuSeparatorProps, MenuSubContentProps, MenuSubTriggerProps, MenuTriggerProps } from './components/menu/index.js';
|
|
70
|
+
export type { MenuCheckboxItemProps, MenuContentProps, MenuGroupProps, MenuItemProps, MenuLabelProps, MenuRadioGroupProps, MenuRadioItemProps, MenuRootProps, MenuSeparatorProps, MenuSubProps, MenuSubContentProps, MenuSubTriggerProps, MenuTriggerProps } from './components/menu/index.js';
|
|
71
71
|
export * as Message from './components/message/index.js';
|
|
72
72
|
export type { MessageActionProps, MessageActionsProps, MessageBubbleProps, MessageContentProps, MessageCopyProps, MessageFrom, MessageHeaderProps, MessagePendingProps, MessageRootProps, MessageTextSize, MessageTimeProps } from './components/message/index.js';
|
|
73
73
|
export { default as Markdown } from './components/markdown/Markdown.svelte';
|
|
@@ -84,7 +84,7 @@ export type { PlanProps, PlanStep, PlanStepStatus } from './components/plan/Plan
|
|
|
84
84
|
export { default as Progress } from './components/progress/Progress.svelte';
|
|
85
85
|
export type { ProgressProps } from './components/progress/Progress.svelte';
|
|
86
86
|
export * as Popover from './components/popover/index.js';
|
|
87
|
-
export type { PopoverCloseProps, PopoverContentProps, PopoverTriggerProps } from './components/popover/index.js';
|
|
87
|
+
export type { PopoverCloseProps, PopoverContentProps, PopoverRootProps, PopoverTriggerProps } from './components/popover/index.js';
|
|
88
88
|
export { default as Questionnaire } from './components/questionnaire/Questionnaire.svelte';
|
|
89
89
|
export type { Question, QuestionAnswer, QuestionnaireAnswers, QuestionnaireProps } from './components/questionnaire/Questionnaire.svelte';
|
|
90
90
|
export { default as QueuedMessage } from './components/queued-message/QueuedMessage.svelte';
|
|
@@ -170,6 +170,8 @@ export type { ThemeOverrides, ThemeProps, ThemeScheme } from './components/theme
|
|
|
170
170
|
export { default as WorkFold } from './components/work-fold/WorkFold.svelte';
|
|
171
171
|
export type { WorkFoldProps } from './components/work-fold/WorkFold.svelte';
|
|
172
172
|
export { setPageHidden, whileVisible } from './internal/visible.js';
|
|
173
|
+
export { providePopupContainer } from './internal/popup.js';
|
|
174
|
+
export type { PopupContainer } from './internal/popup.js';
|
|
173
175
|
export { resolveColor, resolveRgba } from './color.js';
|
|
174
176
|
export type { ResolveColorOptions, Rgba } from './color.js';
|
|
175
177
|
export { classes, sx } from './internal/sx.js';
|
package/dist/index.js
CHANGED
|
@@ -133,6 +133,10 @@ export { default as WorkFold } from './components/work-fold/WorkFold.svelte';
|
|
|
133
133
|
// Skeleton, Progress and Markdown's caret use it. `setPageHidden` is the host's word that the
|
|
134
134
|
// page is out of sight where the document cannot tell, such as a minimized Electron window.
|
|
135
135
|
export { setPageHidden, whileVisible } from './internal/visible.js';
|
|
136
|
+
// Where popups render: in place by default. `providePopupContainer(() => document.body)` in the
|
|
137
|
+
// root layout's script renders every menu, popover, select, card, tooltip, dialog and sheet
|
|
138
|
+
// inside it there, out of a text editor or a clickable row that would take their text and presses.
|
|
139
|
+
export { providePopupContainer } from './internal/popup.js';
|
|
136
140
|
// The colour a token paints as, for a <canvas>, WebGL or a chart library, which
|
|
137
141
|
// cannot read `var()` or `light-dark()` themselves.
|
|
138
142
|
export { resolveColor, resolveRgba } from './color.js';
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/** An element a popup renders into, or nothing, for in place. */
|
|
2
|
+
export type PopupContainer = Element | DocumentFragment | null | undefined;
|
|
3
|
+
type Getter = () => PopupContainer;
|
|
4
|
+
/**
|
|
5
|
+
* Renders every Narvi popup inside the calling component into `container` rather than in place:
|
|
6
|
+
* menus, popovers, selects, hover cards, tooltips, dialogs and sheets. Call it in the script of
|
|
7
|
+
* the app's root layout, with a getter where the element exists only in the browser:
|
|
8
|
+
* `providePopupContainer(() => document.body)`. A popup's own `container`, on its root or its
|
|
9
|
+
* content, still wins, and the popups inside it follow it there.
|
|
10
|
+
*/
|
|
11
|
+
export declare function providePopupContainer(container: PopupContainer | Getter): void;
|
|
12
|
+
/**
|
|
13
|
+
* The container a root or a content renders into: its own `container`, else the nearest one
|
|
14
|
+
* around it. Handed on to the popups inside it. Call it in the component's script.
|
|
15
|
+
*/
|
|
16
|
+
export declare function usePopupContainer(own: () => PopupContainer): Getter;
|
|
17
|
+
/** The container around a component that renders a ui-sdk root and its content itself. */
|
|
18
|
+
export declare function popupContainer(): Getter;
|
|
19
|
+
/**
|
|
20
|
+
* Marks what is inside a dialog's content as inside a dialog, and says whether this content is
|
|
21
|
+
* itself inside another. Call it in a dialog content's script.
|
|
22
|
+
*/
|
|
23
|
+
export declare function nestDialog(): boolean;
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What every popup root and content shares: where it renders, and whether it sits in a dialog.
|
|
3
|
+
*
|
|
4
|
+
* ui-sdk renders a popup in place, in the browser's top layer. Its element stays where it was
|
|
5
|
+
* declared in the document, so inside a text editor its text is the editor's, and inside a
|
|
6
|
+
* clickable row a press on it is a press on the row. ui-sdk takes a `container` per root and per
|
|
7
|
+
* content, and hands one down to the popups inside, but keeps the function that sets one for a
|
|
8
|
+
* whole tree to itself. `providePopupContainer` is Narvi's: each root and content reads it and
|
|
9
|
+
* passes it on as its `container`, under one of its own.
|
|
10
|
+
*
|
|
11
|
+
* Each root also binds ui-sdk's `open` with a setter that reads its own `open` first, and writes
|
|
12
|
+
* only when it differs. ui-sdk calls `onOpenChange` before it writes, so an app that keeps `open`
|
|
13
|
+
* in its own state (`open={shown && !dragging}` with an `onOpenChange` that sets `shown`) has
|
|
14
|
+
* followed already. Writing anyway would shadow the app's value with Svelte's local copy of the
|
|
15
|
+
* prop, and when the app's expression came back to what Svelte last read, no change would reach
|
|
16
|
+
* the popup: opened by its trigger, it could never be closed by the app again.
|
|
17
|
+
*/
|
|
18
|
+
import { getContext, setContext } from 'svelte';
|
|
19
|
+
const CONTAINER = Symbol('narvi.popup-container');
|
|
20
|
+
const IN_DIALOG = Symbol('narvi.in-dialog');
|
|
21
|
+
/**
|
|
22
|
+
* Renders every Narvi popup inside the calling component into `container` rather than in place:
|
|
23
|
+
* menus, popovers, selects, hover cards, tooltips, dialogs and sheets. Call it in the script of
|
|
24
|
+
* the app's root layout, with a getter where the element exists only in the browser:
|
|
25
|
+
* `providePopupContainer(() => document.body)`. A popup's own `container`, on its root or its
|
|
26
|
+
* content, still wins, and the popups inside it follow it there.
|
|
27
|
+
*/
|
|
28
|
+
export function providePopupContainer(container) {
|
|
29
|
+
const own = typeof container === 'function' ? container : () => container;
|
|
30
|
+
const around = getContext(CONTAINER);
|
|
31
|
+
setContext(CONTAINER, () => own() ?? around?.());
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* The container a root or a content renders into: its own `container`, else the nearest one
|
|
35
|
+
* around it. Handed on to the popups inside it. Call it in the component's script.
|
|
36
|
+
*/
|
|
37
|
+
export function usePopupContainer(own) {
|
|
38
|
+
const around = getContext(CONTAINER);
|
|
39
|
+
const target = () => own() ?? around?.();
|
|
40
|
+
setContext(CONTAINER, target);
|
|
41
|
+
return target;
|
|
42
|
+
}
|
|
43
|
+
/** The container around a component that renders a ui-sdk root and its content itself. */
|
|
44
|
+
export function popupContainer() {
|
|
45
|
+
const around = getContext(CONTAINER);
|
|
46
|
+
return () => around?.();
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Marks what is inside a dialog's content as inside a dialog, and says whether this content is
|
|
50
|
+
* itself inside another. Call it in a dialog content's script.
|
|
51
|
+
*/
|
|
52
|
+
export function nestDialog() {
|
|
53
|
+
const nested = getContext(IN_DIALOG) ?? false;
|
|
54
|
+
setContext(IN_DIALOG, true);
|
|
55
|
+
return nested;
|
|
56
|
+
}
|
package/package.json
CHANGED
|
@@ -12,7 +12,7 @@ metadata:
|
|
|
12
12
|
Grid, and Narvi's conventions for colour, labels and copy.
|
|
13
13
|
type: core
|
|
14
14
|
library: '@diegopluna/narvi'
|
|
15
|
-
library_version: '0.5.
|
|
15
|
+
library_version: '0.5.2'
|
|
16
16
|
requires:
|
|
17
17
|
- setup
|
|
18
18
|
sources:
|
|
@@ -36,6 +36,7 @@ sources:
|
|
|
36
36
|
- src/lib/components/tab-strip/TabStrip.svelte
|
|
37
37
|
- src/lib/components/split-button/SplitButton.svelte
|
|
38
38
|
- src/lib/components/app-shell/*.svelte
|
|
39
|
+
- src/lib/components/resize-handle/ResizeHandle.svelte
|
|
39
40
|
- src/lib/components/composer/ComposerModelPicker.svelte
|
|
40
41
|
- src/lib/components/questionnaire/Questionnaire.svelte
|
|
41
42
|
- src/lib/components/approval/Approval.svelte
|
|
@@ -46,6 +47,7 @@ sources:
|
|
|
46
47
|
- src/lib/components/tooltip/TooltipProvider.svelte
|
|
47
48
|
- src/lib/components/command/*.svelte
|
|
48
49
|
- src/lib/components/menu/MenuContent.svelte
|
|
50
|
+
- src/lib/internal/popup.ts
|
|
49
51
|
---
|
|
50
52
|
|
|
51
53
|
# Build interfaces with Narvi
|
|
@@ -154,10 +156,9 @@ Children that render nothing (an `{#if}` that is false) leave no empty body.
|
|
|
154
156
|
|
|
155
157
|
### Forms
|
|
156
158
|
|
|
157
|
-
Wrap a text control (`Input`, `Textarea` or `Select`), a `Checkbox` or a `Switch` in `Field`.
|
|
158
|
-
|
|
159
|
-
wires up `id`, `aria-describedby` and `aria-invalid`. Don't hand-write
|
|
160
|
-
wiring for them.
|
|
159
|
+
Wrap a text control (`Input`, `Textarea` or `Select`), a `Checkbox` or a `Switch` in `Field`. They
|
|
160
|
+
read its context, so it gives them a label, help text (`description`) and an error (`error`), and
|
|
161
|
+
wires up `id`, `aria-describedby` and `aria-invalid`. Don't hand-write their `<label>` or ARIA.
|
|
161
162
|
|
|
162
163
|
```svelte
|
|
163
164
|
<Field label="Email" description="We only write when a run needs you." error={emailError}>
|
|
@@ -409,9 +410,8 @@ Parts of the shell that are easy to redraw by hand, and shouldn't be:
|
|
|
409
410
|
`hideCovered`, `edgeLabel` and `edgeTitle` see the [catalogue](references/components.md#panels).
|
|
410
411
|
- **A palette** is `Command.Root`: don't work round its keys, highlight, footer or field by hand
|
|
411
412
|
(the [catalogue](references/components.md#palettes) says what each does).
|
|
412
|
-
- **A Sheet** focuses itself as it opens (`focusOnOpen="sheet"`), so a Rail or a list in it
|
|
413
|
-
|
|
414
|
-
holds a form.
|
|
413
|
+
- **A Sheet** focuses itself as it opens (`focusOnOpen="sheet"`), so a Rail or a list in it shows
|
|
414
|
+
no focus ring until the keys move in. Pass `focusOnOpen="first"` for a sheet that holds a form.
|
|
415
415
|
- `AppShell.Header` draws a line under itself; `divider={false}` leaves it out where the page
|
|
416
416
|
runs on under the header; an `AppShell.Strip` in it runs its height, for a notch TabStrip.
|
|
417
417
|
|
|
@@ -160,6 +160,29 @@ a closed one in the page. Change callbacks get `(value, details)`: `details.reas
|
|
|
160
160
|
`details.cancel()` refuses it. A popup's room is `--available-height`, `--available-width` and
|
|
161
161
|
`--anchor-width`.
|
|
162
162
|
|
|
163
|
+
In place means the popup's element stays where it is declared: inside a text editor its text is
|
|
164
|
+
the editor's, and inside a clickable row a press on it is a press on the row. Render them all out
|
|
165
|
+
of it with `providePopupContainer` in the root layout's script, as a getter so it runs only in the
|
|
166
|
+
browser; a `container` on a Root or a Content still wins, and the popups inside follow it:
|
|
167
|
+
|
|
168
|
+
```svelte
|
|
169
|
+
<script lang="ts">
|
|
170
|
+
import { providePopupContainer } from '@diegopluna/narvi';
|
|
171
|
+
|
|
172
|
+
let { children } = $props();
|
|
173
|
+
providePopupContainer(() => document.body);
|
|
174
|
+
</script>
|
|
175
|
+
|
|
176
|
+
{@render children()}
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
To drive `open` from the app, bind it, or pass it with an `onOpenChange` that keeps your state:
|
|
180
|
+
`open={shown && !dragging} onOpenChange={(next) => (shown = next)}` follows `dragging` even after
|
|
181
|
+
the trigger opened it. An `open` passed with neither is only where it starts, as any Svelte prop
|
|
182
|
+
is. Import popups from Narvi rather than `@ui-sdk/svelte`: ui-sdk's own parts take a prop of any
|
|
183
|
+
name, so a misspelled or renamed one (`openDelay` for `delay`) passes svelte-check and does
|
|
184
|
+
nothing; Narvi's name theirs.
|
|
185
|
+
|
|
163
186
|
| Component | Use it for | Docs slug |
|
|
164
187
|
| --------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------- |
|
|
165
188
|
| `Dialog.Root`, `.Trigger`, `.Content` (`size`, `side`, `as`), `.Header`, `.Title`, `.Description`, `.Body`, `.Footer`, `.Close` | A focused task over the page | `dialog` |
|
|
@@ -296,6 +319,25 @@ page is laid out once per show or hide. What is under `AppShell.Header` glides o
|
|
|
296
319
|
for 200ms; the header, the panel and its edge take their places at once. Don't animate the
|
|
297
320
|
sidebar's width yourself, and don't put a `translate` of your own on `AppShell.Main`'s children.
|
|
298
321
|
|
|
322
|
+
### Resize handles
|
|
323
|
+
|
|
324
|
+
A `ResizeHandle` of your own (`bind:value`, `min`, `max`, `defaultValue`, `edge`,
|
|
325
|
+
`orientation`, `target`, `property`) writes the size onto `target` as `property` while it is
|
|
326
|
+
dragged, and takes it off again when the drag ends, once `value` has the size. Draw the target
|
|
327
|
+
from both, the property first and the value as its fallback:
|
|
328
|
+
|
|
329
|
+
```svelte
|
|
330
|
+
<div bind:this={side} style:width="var(--narvi-size, {width}px)">…</div>
|
|
331
|
+
<ResizeHandle bind:value={width} edge="end" target={side} label="Resize the sidebar" />
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
`--narvi-size`, the default, is registered as not inherited, so a move restyles the target
|
|
335
|
+
alone. A `property` of your own needs the same, or every move restyles all that is in the
|
|
336
|
+
target: `@property --pane-size { syntax: '*'; inherits: false; }`, with no initial value so the
|
|
337
|
+
fallback applies once it's let go. Don't read the property from inside the target; it isn't
|
|
338
|
+
inherited. `onDragStart()` and `onDragEnd(value)` bracket a drag, say to keep an iframe from
|
|
339
|
+
taking the pointer. A handle removed mid-drag ends it with the size from before.
|
|
340
|
+
|
|
299
341
|
## AI chat
|
|
300
342
|
|
|
301
343
|
| Component | Use it for | Docs slug |
|
package/skills/markdown/SKILL.md
CHANGED
package/skills/setup/SKILL.md
CHANGED
|
@@ -11,7 +11,7 @@ metadata:
|
|
|
11
11
|
4 when the app uses it.
|
|
12
12
|
type: lifecycle
|
|
13
13
|
library: '@diegopluna/narvi'
|
|
14
|
-
library_version: '0.5.
|
|
14
|
+
library_version: '0.5.2'
|
|
15
15
|
sources:
|
|
16
16
|
- src/lib/vite.ts
|
|
17
17
|
- src/lib/base.css
|
|
@@ -130,6 +130,8 @@ Narvi lists both naming styles, so neither needs a theme override.
|
|
|
130
130
|
Narvi's types work with `exactOptionalPropertyTypes`. Every optional prop takes `undefined`, so
|
|
131
131
|
`<Notice detail={maybe}>` and `<Tooltip.Content side={maybe}>` type-check as they are, with no
|
|
132
132
|
need to spread a prop only when it is set. That holds for the parts Narvi takes from ui-sdk too.
|
|
133
|
+
Every part names its props, so a misspelled or renamed one is a type error; ui-sdk's own parts,
|
|
134
|
+
imported from `@ui-sdk/svelte`, take a prop of any name and let it through.
|
|
133
135
|
|
|
134
136
|
## With Tailwind CSS 4
|
|
135
137
|
|