@diegopluna/narvi 0.3.6 → 0.3.7
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 +37 -11
- package/dist/components/app-shell/AppShellPanel.svelte.d.ts +13 -0
- package/dist/components/command/CommandDialog.svelte +9 -2
- package/dist/components/command/CommandDialog.svelte.d.ts +4 -0
- package/dist/components/command/CommandEmpty.svelte +38 -4
- package/dist/components/command/CommandEmpty.svelte.d.ts +18 -2
- package/dist/components/command/CommandFooter.svelte +5 -7
- package/dist/components/command/CommandFooter.svelte.d.ts +4 -1
- package/dist/components/command/CommandInput.svelte +13 -1
- package/dist/components/command/CommandInput.svelte.d.ts +11 -0
- package/dist/components/command/CommandItem.svelte +32 -6
- package/dist/components/command/CommandItem.svelte.d.ts +20 -0
- package/dist/components/command/CommandRoot.svelte +68 -9
- package/dist/components/command/CommandRoot.svelte.d.ts +13 -3
- package/dist/components/command/styles.d.ts +50 -8
- package/dist/components/command/styles.js +50 -8
- package/dist/components/menu/MenuContent.svelte +7 -1
- package/dist/components/menu/MenuContent.svelte.d.ts +10 -0
- package/dist/components/split-button/SplitButton.svelte +54 -15
- package/dist/components/split-button/SplitButton.svelte.d.ts +21 -4
- package/dist/internal/layer.d.ts +6 -3
- package/dist/internal/layer.js +13 -6
- package/package.json +1 -1
- package/skills/building-ui/SKILL.md +14 -14
- package/skills/building-ui/references/components.md +52 -13
- 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
|
@@ -9,7 +9,10 @@
|
|
|
9
9
|
It can also stand in a row of your own inside AppShell.Main, beside a thread
|
|
10
10
|
rather than beside the page: a flex row with `position: relative`. It then
|
|
11
11
|
measures that row, and narrow or maximized it lies over the row, whose other
|
|
12
|
-
children are inert underneath.
|
|
12
|
+
children are inert underneath, and with `hideCovered` out of sight too.
|
|
13
|
+
|
|
14
|
+
It is raised wherever it stands, so in a row of your own it keeps the sheet's
|
|
15
|
+
colour beside a page of another.
|
|
13
16
|
-->
|
|
14
17
|
<script lang="ts" module>
|
|
15
18
|
import * as stylex from '@stylexjs/stylex';
|
|
@@ -23,6 +26,13 @@
|
|
|
23
26
|
export type AppShellPanelProps = Omit<HTMLAttributes<HTMLElement>, 'children'> & {
|
|
24
27
|
/** Names the region: "Changes", "Files". */
|
|
25
28
|
label: string;
|
|
29
|
+
/**
|
|
30
|
+
* Names the edge that resizes it, for assistive technology. "Resize the changes panel"
|
|
31
|
+
* by default, from `label`.
|
|
32
|
+
*/
|
|
33
|
+
edgeLabel?: string | undefined;
|
|
34
|
+
/** A tooltip on that edge, for the pointer: "Drag to resize, double-click to reset". */
|
|
35
|
+
edgeTitle?: string | undefined;
|
|
26
36
|
/** Its width in pixels. Bindable; store it if it should be remembered. */
|
|
27
37
|
width?: number | undefined;
|
|
28
38
|
minWidth?: number | undefined;
|
|
@@ -39,6 +49,12 @@
|
|
|
39
49
|
* stays in reach.
|
|
40
50
|
*/
|
|
41
51
|
maximized?: boolean | undefined;
|
|
52
|
+
/**
|
|
53
|
+
* In a row of your own, also hides what the panel lies over, as the page is hidden under
|
|
54
|
+
* a maximized panel: out of sight and of find-in-page, still laid out, so its scroll is
|
|
55
|
+
* kept. Without it, what is underneath is only inert.
|
|
56
|
+
*/
|
|
57
|
+
hideCovered?: boolean | undefined;
|
|
42
58
|
sx?: Sx | undefined;
|
|
43
59
|
children?: Snippet | undefined;
|
|
44
60
|
};
|
|
@@ -54,6 +70,7 @@
|
|
|
54
70
|
minWidth: 0,
|
|
55
71
|
minHeight: 0,
|
|
56
72
|
overflow: 'clip',
|
|
73
|
+
backgroundColor: colors.bgRaised,
|
|
57
74
|
borderInlineStartWidth: '1px',
|
|
58
75
|
borderInlineStartStyle: 'solid',
|
|
59
76
|
borderInlineStartColor: colors.border,
|
|
@@ -70,8 +87,7 @@
|
|
|
70
87
|
insetInlineEnd: 0,
|
|
71
88
|
zIndex: 5,
|
|
72
89
|
width: 'auto',
|
|
73
|
-
borderInlineStartWidth: 0
|
|
74
|
-
backgroundColor: colors.bgRaised
|
|
90
|
+
borderInlineStartWidth: 0
|
|
75
91
|
},
|
|
76
92
|
// Under the page's header, which stays in reach with the sidebar's toggle
|
|
77
93
|
narrow: { insetBlockStart: '3rem' },
|
|
@@ -87,11 +103,14 @@
|
|
|
87
103
|
<script lang="ts">
|
|
88
104
|
let {
|
|
89
105
|
label,
|
|
106
|
+
edgeLabel,
|
|
107
|
+
edgeTitle,
|
|
90
108
|
width = $bindable(560),
|
|
91
109
|
minWidth = 320,
|
|
92
110
|
defaultWidth = 560,
|
|
93
111
|
mainMinWidth = 352,
|
|
94
112
|
maximized = false,
|
|
113
|
+
hideCovered = false,
|
|
95
114
|
sx,
|
|
96
115
|
class: className,
|
|
97
116
|
children,
|
|
@@ -141,17 +160,23 @@
|
|
|
141
160
|
});
|
|
142
161
|
|
|
143
162
|
// In a row of the caller's own, what the panel lies over is out of reach underneath:
|
|
144
|
-
// its siblings are inert, and come back as they were
|
|
163
|
+
// its siblings are inert, and hidden if asked, and come back as they were
|
|
145
164
|
$effect(() => {
|
|
146
165
|
const parent = element?.parentElement;
|
|
147
166
|
if (inSheet || !over || !parent || !element) return;
|
|
148
|
-
const
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
for (const child of covered)
|
|
167
|
+
const hide = hideCovered;
|
|
168
|
+
const covered = [...parent.children]
|
|
169
|
+
.filter((child): child is HTMLElement => child instanceof HTMLElement && child !== element)
|
|
170
|
+
.map((child) => ({ child, inert: child.inert, visibility: child.style.visibility }));
|
|
171
|
+
for (const { child } of covered) {
|
|
172
|
+
child.inert = true;
|
|
173
|
+
if (hide) child.style.visibility = 'hidden';
|
|
174
|
+
}
|
|
153
175
|
return () => {
|
|
154
|
-
for (const child of covered)
|
|
176
|
+
for (const { child, inert, visibility } of covered) {
|
|
177
|
+
child.inert = inert;
|
|
178
|
+
if (hide) child.style.visibility = visibility;
|
|
179
|
+
}
|
|
155
180
|
};
|
|
156
181
|
});
|
|
157
182
|
|
|
@@ -177,7 +202,8 @@
|
|
|
177
202
|
edge="start"
|
|
178
203
|
target={element}
|
|
179
204
|
property="--narvi-panel-width"
|
|
180
|
-
label=
|
|
205
|
+
label={edgeLabel ?? `Resize the ${label.toLowerCase()} panel`}
|
|
206
|
+
title={edgeTitle}
|
|
181
207
|
sx={styles.handle}
|
|
182
208
|
/>
|
|
183
209
|
{/if}
|
|
@@ -4,6 +4,13 @@ import { type Sx } from '../../internal/sx.js';
|
|
|
4
4
|
export type AppShellPanelProps = Omit<HTMLAttributes<HTMLElement>, 'children'> & {
|
|
5
5
|
/** Names the region: "Changes", "Files". */
|
|
6
6
|
label: string;
|
|
7
|
+
/**
|
|
8
|
+
* Names the edge that resizes it, for assistive technology. "Resize the changes panel"
|
|
9
|
+
* by default, from `label`.
|
|
10
|
+
*/
|
|
11
|
+
edgeLabel?: string | undefined;
|
|
12
|
+
/** A tooltip on that edge, for the pointer: "Drag to resize, double-click to reset". */
|
|
13
|
+
edgeTitle?: string | undefined;
|
|
7
14
|
/** Its width in pixels. Bindable; store it if it should be remembered. */
|
|
8
15
|
width?: number | undefined;
|
|
9
16
|
minWidth?: number | undefined;
|
|
@@ -20,6 +27,12 @@ export type AppShellPanelProps = Omit<HTMLAttributes<HTMLElement>, 'children'> &
|
|
|
20
27
|
* stays in reach.
|
|
21
28
|
*/
|
|
22
29
|
maximized?: boolean | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* In a row of your own, also hides what the panel lies over, as the page is hidden under
|
|
32
|
+
* a maximized panel: out of sight and of find-in-page, still laid out, so its scroll is
|
|
33
|
+
* kept. Without it, what is underneath is only inert.
|
|
34
|
+
*/
|
|
35
|
+
hideCovered?: boolean | undefined;
|
|
23
36
|
sx?: Sx | undefined;
|
|
24
37
|
children?: Snippet | undefined;
|
|
25
38
|
};
|
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
import { Dialog } from 'bits-ui';
|
|
7
7
|
import * as stylex from '@stylexjs/stylex';
|
|
8
8
|
import type { Snippet } from 'svelte';
|
|
9
|
+
import { attrs, type Sx } from '../../internal/sx.js';
|
|
10
|
+
import { visuallyHidden } from '../../visually-hidden.js';
|
|
9
11
|
import { command } from './styles.js';
|
|
10
12
|
|
|
11
13
|
export type CommandDialogProps = {
|
|
@@ -25,6 +27,9 @@
|
|
|
25
27
|
restoreFocus?: boolean | undefined;
|
|
26
28
|
/** What the palette is, for assistive technology. */
|
|
27
29
|
label?: string | undefined;
|
|
30
|
+
/** On the palette's box: its place, its width, how tall it may grow. */
|
|
31
|
+
sx?: Sx | undefined;
|
|
32
|
+
class?: string | undefined;
|
|
28
33
|
/** A Command.Root with its Input, List and Footer. */
|
|
29
34
|
children?: Snippet | undefined;
|
|
30
35
|
};
|
|
@@ -37,6 +42,8 @@
|
|
|
37
42
|
onopenchange,
|
|
38
43
|
onescape,
|
|
39
44
|
restoreFocus = true,
|
|
45
|
+
sx,
|
|
46
|
+
class: className,
|
|
40
47
|
children
|
|
41
48
|
}: CommandDialogProps = $props();
|
|
42
49
|
</script>
|
|
@@ -50,9 +57,9 @@
|
|
|
50
57
|
onCloseAutoFocus={(event) => {
|
|
51
58
|
if (!restoreFocus) event.preventDefault();
|
|
52
59
|
}}
|
|
53
|
-
{...
|
|
60
|
+
{...attrs([command.dialog, sx], className)}
|
|
54
61
|
>
|
|
55
|
-
<Dialog.Title {...stylex.attrs(
|
|
62
|
+
<Dialog.Title {...stylex.attrs(visuallyHidden)}>{label}</Dialog.Title>
|
|
56
63
|
{@render children?.()}
|
|
57
64
|
</Dialog.Content>
|
|
58
65
|
</Dialog.Portal>
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Snippet } from 'svelte';
|
|
2
|
+
import { type Sx } from '../../internal/sx.js';
|
|
2
3
|
export type CommandDialogProps = {
|
|
3
4
|
/** Whether it is open. Bindable. */
|
|
4
5
|
open?: boolean | undefined;
|
|
@@ -16,6 +17,9 @@ export type CommandDialogProps = {
|
|
|
16
17
|
restoreFocus?: boolean | undefined;
|
|
17
18
|
/** What the palette is, for assistive technology. */
|
|
18
19
|
label?: string | undefined;
|
|
20
|
+
/** On the palette's box: its place, its width, how tall it may grow. */
|
|
21
|
+
sx?: Sx | undefined;
|
|
22
|
+
class?: string | undefined;
|
|
19
23
|
/** A Command.Root with its Input, List and Footer. */
|
|
20
24
|
children?: Snippet | undefined;
|
|
21
25
|
};
|
|
@@ -1,23 +1,57 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
What the list says in place of items: that nothing matches, that results are on
|
|
3
|
+
their way, or that they could not be had. It shows only while the list has no
|
|
4
|
+
items, so results still listed stay as they are while new ones load.
|
|
5
|
+
-->
|
|
1
6
|
<script lang="ts" module>
|
|
2
7
|
import type { Loose } from '../../internal/loose.js';
|
|
3
8
|
import { Command } from 'bits-ui';
|
|
4
9
|
import type { Snippet } from 'svelte';
|
|
5
10
|
import { attrs, type Sx } from '../../internal/sx.js';
|
|
11
|
+
import Spinner from '../spinner/Spinner.svelte';
|
|
6
12
|
import { command } from './styles.js';
|
|
7
13
|
|
|
8
14
|
export type CommandEmptyProps = Loose<
|
|
9
15
|
Omit<Command.EmptyProps, 'children' | 'child'> & {
|
|
16
|
+
/**
|
|
17
|
+
* Why there are no items: `loading`, with a spinner, while they are on their way, or
|
|
18
|
+
* `error`, in the danger colour, when they could not be had. Without it, nothing matches.
|
|
19
|
+
*/
|
|
20
|
+
status?: 'loading' | 'error' | undefined;
|
|
10
21
|
sx?: Sx | undefined;
|
|
11
|
-
/**
|
|
22
|
+
/**
|
|
23
|
+
* What to say. For no match, say what was searched for and what to try; for an error,
|
|
24
|
+
* what went wrong and what to do.
|
|
25
|
+
*/
|
|
12
26
|
children?: Snippet | undefined;
|
|
13
27
|
}
|
|
14
28
|
>;
|
|
29
|
+
|
|
30
|
+
const fallback = {
|
|
31
|
+
empty: 'Nothing matches.',
|
|
32
|
+
loading: 'Searching…',
|
|
33
|
+
error: 'The results could not be loaded.'
|
|
34
|
+
} as const;
|
|
15
35
|
</script>
|
|
16
36
|
|
|
17
37
|
<script lang="ts">
|
|
18
|
-
let { sx, class: className, children, ...rest }: CommandEmptyProps = $props();
|
|
38
|
+
let { status, sx, class: className, children, ...rest }: CommandEmptyProps = $props();
|
|
19
39
|
</script>
|
|
20
40
|
|
|
21
|
-
<Command.Empty
|
|
22
|
-
|
|
41
|
+
<Command.Empty
|
|
42
|
+
data-slot="command-empty"
|
|
43
|
+
data-status={status}
|
|
44
|
+
{...rest}
|
|
45
|
+
{...attrs(
|
|
46
|
+
[
|
|
47
|
+
command.empty,
|
|
48
|
+
status === 'loading' && command.emptyLoading,
|
|
49
|
+
status === 'error' && command.emptyError,
|
|
50
|
+
sx
|
|
51
|
+
],
|
|
52
|
+
className
|
|
53
|
+
)}
|
|
54
|
+
>
|
|
55
|
+
{#if status === 'loading'}<Spinner size={16} label={null} />{/if}
|
|
56
|
+
{#if children}{@render children()}{:else}{fallback[status ?? 'empty']}{/if}
|
|
23
57
|
</Command.Empty>
|
|
@@ -3,13 +3,29 @@ import { Command } from 'bits-ui';
|
|
|
3
3
|
import type { Snippet } from 'svelte';
|
|
4
4
|
import { type Sx } from '../../internal/sx.js';
|
|
5
5
|
export type CommandEmptyProps = Loose<Omit<Command.EmptyProps, 'children' | 'child'> & {
|
|
6
|
+
/**
|
|
7
|
+
* Why there are no items: `loading`, with a spinner, while they are on their way, or
|
|
8
|
+
* `error`, in the danger colour, when they could not be had. Without it, nothing matches.
|
|
9
|
+
*/
|
|
10
|
+
status?: 'loading' | 'error' | undefined;
|
|
6
11
|
sx?: Sx | undefined;
|
|
7
|
-
/**
|
|
12
|
+
/**
|
|
13
|
+
* What to say. For no match, say what was searched for and what to try; for an error,
|
|
14
|
+
* what went wrong and what to do.
|
|
15
|
+
*/
|
|
8
16
|
children?: Snippet | undefined;
|
|
9
17
|
}>;
|
|
10
18
|
declare const CommandEmpty: import("svelte").Component<Loose<Omit<Command.EmptyProps, "children" | "child"> & {
|
|
19
|
+
/**
|
|
20
|
+
* Why there are no items: `loading`, with a spinner, while they are on their way, or
|
|
21
|
+
* `error`, in the danger colour, when they could not be had. Without it, nothing matches.
|
|
22
|
+
*/
|
|
23
|
+
status?: "loading" | "error" | undefined;
|
|
11
24
|
sx?: Sx | undefined;
|
|
12
|
-
/**
|
|
25
|
+
/**
|
|
26
|
+
* What to say. For no match, say what was searched for and what to try; for an error,
|
|
27
|
+
* what went wrong and what to do.
|
|
28
|
+
*/
|
|
13
29
|
children?: Snippet | undefined;
|
|
14
30
|
}>, {}, "">;
|
|
15
31
|
type CommandEmpty = ReturnType<typeof CommandEmpty>;
|
|
@@ -6,7 +6,10 @@
|
|
|
6
6
|
|
|
7
7
|
export type CommandFooterProps = Omit<HTMLAttributes<HTMLDivElement>, 'children'> & {
|
|
8
8
|
sx?: Sx | undefined;
|
|
9
|
-
/**
|
|
9
|
+
/**
|
|
10
|
+
* Hints for the keys, such as "↑↓ to move", a note, or buttons such as Back. It is read
|
|
11
|
+
* out with the rest; pass `aria-hidden="true"` for hints alone, which the keys already say.
|
|
12
|
+
*/
|
|
10
13
|
children?: Snippet | undefined;
|
|
11
14
|
};
|
|
12
15
|
</script>
|
|
@@ -15,11 +18,6 @@
|
|
|
15
18
|
let { sx, class: className, children, ...rest }: CommandFooterProps = $props();
|
|
16
19
|
</script>
|
|
17
20
|
|
|
18
|
-
<div
|
|
19
|
-
data-slot="command-footer"
|
|
20
|
-
aria-hidden="true"
|
|
21
|
-
{...rest}
|
|
22
|
-
{...attrs([command.footer, sx], className)}
|
|
23
|
-
>
|
|
21
|
+
<div data-slot="command-footer" {...rest} {...attrs([command.footer, sx], className)}>
|
|
24
22
|
{@render children?.()}
|
|
25
23
|
</div>
|
|
@@ -3,7 +3,10 @@ import type { HTMLAttributes } from 'svelte/elements';
|
|
|
3
3
|
import { type Sx } from '../../internal/sx.js';
|
|
4
4
|
export type CommandFooterProps = Omit<HTMLAttributes<HTMLDivElement>, 'children'> & {
|
|
5
5
|
sx?: Sx | undefined;
|
|
6
|
-
/**
|
|
6
|
+
/**
|
|
7
|
+
* Hints for the keys, such as "↑↓ to move", a note, or buttons such as Back. It is read
|
|
8
|
+
* out with the rest; pass `aria-hidden="true"` for hints alone, which the keys already say.
|
|
9
|
+
*/
|
|
7
10
|
children?: Snippet | undefined;
|
|
8
11
|
};
|
|
9
12
|
declare const CommandFooter: import("svelte").Component<CommandFooterProps, {}, "">;
|
|
@@ -2,12 +2,20 @@
|
|
|
2
2
|
import type { Loose } from '../../internal/loose.js';
|
|
3
3
|
import { Command } from 'bits-ui';
|
|
4
4
|
import * as stylex from '@stylexjs/stylex';
|
|
5
|
+
import type { Snippet } from 'svelte';
|
|
5
6
|
import Glyph from '../../internal/Glyph.svelte';
|
|
6
7
|
import { attrs, type Sx } from '../../internal/sx.js';
|
|
7
8
|
import { command } from './styles.js';
|
|
8
9
|
|
|
9
10
|
export type CommandInputProps = Loose<
|
|
10
|
-
Omit<Command.InputProps, 'child'> & {
|
|
11
|
+
Omit<Command.InputProps, 'child'> & {
|
|
12
|
+
/**
|
|
13
|
+
* After the field, in its row: a button or two, such as a filter or how to search, or a
|
|
14
|
+
* Spinner while results are on their way.
|
|
15
|
+
*/
|
|
16
|
+
end?: Snippet | undefined;
|
|
17
|
+
sx?: Sx | undefined;
|
|
18
|
+
}
|
|
11
19
|
>;
|
|
12
20
|
</script>
|
|
13
21
|
|
|
@@ -15,6 +23,7 @@
|
|
|
15
23
|
let {
|
|
16
24
|
value = $bindable(''),
|
|
17
25
|
placeholder = 'Search for a command…',
|
|
26
|
+
end,
|
|
18
27
|
sx,
|
|
19
28
|
class: className,
|
|
20
29
|
...rest
|
|
@@ -33,4 +42,7 @@
|
|
|
33
42
|
{...rest}
|
|
34
43
|
{...attrs([command.input, sx], className)}
|
|
35
44
|
/>
|
|
45
|
+
{#if end}<div data-slot="command-input-end" {...stylex.attrs(command.end)}>
|
|
46
|
+
{@render end()}
|
|
47
|
+
</div>{/if}
|
|
36
48
|
</div>
|
|
@@ -1,10 +1,21 @@
|
|
|
1
1
|
import type { Loose } from '../../internal/loose.js';
|
|
2
2
|
import { Command } from 'bits-ui';
|
|
3
|
+
import type { Snippet } from 'svelte';
|
|
3
4
|
import { type Sx } from '../../internal/sx.js';
|
|
4
5
|
export type CommandInputProps = Loose<Omit<Command.InputProps, 'child'> & {
|
|
6
|
+
/**
|
|
7
|
+
* After the field, in its row: a button or two, such as a filter or how to search, or a
|
|
8
|
+
* Spinner while results are on their way.
|
|
9
|
+
*/
|
|
10
|
+
end?: Snippet | undefined;
|
|
5
11
|
sx?: Sx | undefined;
|
|
6
12
|
}>;
|
|
7
13
|
declare const CommandInput: import("svelte").Component<Loose<Omit<Command.InputProps, "child"> & {
|
|
14
|
+
/**
|
|
15
|
+
* After the field, in its row: a button or two, such as a filter or how to search, or a
|
|
16
|
+
* Spinner while results are on their way.
|
|
17
|
+
*/
|
|
18
|
+
end?: Snippet | undefined;
|
|
8
19
|
sx?: Sx | undefined;
|
|
9
20
|
}>, {}, "value">;
|
|
10
21
|
type CommandInput = ReturnType<typeof CommandInput>;
|
|
@@ -17,6 +17,16 @@
|
|
|
17
17
|
* such as one with the words that match the search marked.
|
|
18
18
|
*/
|
|
19
19
|
detail?: string | Snippet | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* Lets the detail wrap to a second line, rather than be cut short, where its end
|
|
22
|
+
* matters: a path. It gives way before the label does.
|
|
23
|
+
*/
|
|
24
|
+
wrapDetail?: boolean | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* Right after the label, before the detail: a mark such as a connected service's, or a
|
|
27
|
+
* Badge. An icon in it is 14px.
|
|
28
|
+
*/
|
|
29
|
+
badge?: Snippet | undefined;
|
|
20
30
|
/**
|
|
21
31
|
* What the key cap on the highlighted item says Enter does. `↵` by default; words such
|
|
22
32
|
* as "Open" for an item that does something of its own, or `null` for none.
|
|
@@ -34,6 +44,8 @@
|
|
|
34
44
|
let {
|
|
35
45
|
icon,
|
|
36
46
|
detail,
|
|
47
|
+
wrapDetail = false,
|
|
48
|
+
badge,
|
|
37
49
|
shortcut,
|
|
38
50
|
hint = '↵',
|
|
39
51
|
sx,
|
|
@@ -47,12 +59,17 @@
|
|
|
47
59
|
{#snippet child({ props })}
|
|
48
60
|
<div {...props}>
|
|
49
61
|
{#if icon}<span data-icons {...stylex.attrs(layer.icon)}>{@render icon()}</span>{/if}
|
|
50
|
-
|
|
51
|
-
{
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
62
|
+
{#if wrapDetail && detail}
|
|
63
|
+
<span {...stylex.attrs(command.wrapRow)}>
|
|
64
|
+
<span {...stylex.attrs(command.wrapLabel)}>{@render label()}</span>
|
|
65
|
+
<span {...stylex.attrs(command.wrapped)}>{@render detailText()}</span>
|
|
66
|
+
</span>
|
|
67
|
+
{:else}
|
|
68
|
+
<span {...stylex.attrs(layer.label)}>
|
|
69
|
+
{@render label()}
|
|
70
|
+
{#if detail}<span {...stylex.attrs(command.detail)}>{@render detailText()}</span>{/if}
|
|
71
|
+
</span>
|
|
72
|
+
{/if}
|
|
56
73
|
<span {...stylex.attrs(layer.trailing)}>
|
|
57
74
|
{#if shortcut}{shortcut}{/if}
|
|
58
75
|
<!-- Enter is the way to choose, shown only on the highlighted row -->
|
|
@@ -61,3 +78,12 @@
|
|
|
61
78
|
</div>
|
|
62
79
|
{/snippet}
|
|
63
80
|
</Command.Item>
|
|
81
|
+
|
|
82
|
+
{#snippet label()}
|
|
83
|
+
{@render children?.()}
|
|
84
|
+
{#if badge}<span data-icons {...stylex.attrs(command.badge)}>{@render badge()}</span>{/if}
|
|
85
|
+
{/snippet}
|
|
86
|
+
|
|
87
|
+
{#snippet detailText()}
|
|
88
|
+
{#if typeof detail === 'function'}{@render detail()}{:else}{detail}{/if}
|
|
89
|
+
{/snippet}
|
|
@@ -10,6 +10,16 @@ export type CommandItemProps = Loose<Omit<Command.ItemProps, 'children' | 'child
|
|
|
10
10
|
* such as one with the words that match the search marked.
|
|
11
11
|
*/
|
|
12
12
|
detail?: string | Snippet | undefined;
|
|
13
|
+
/**
|
|
14
|
+
* Lets the detail wrap to a second line, rather than be cut short, where its end
|
|
15
|
+
* matters: a path. It gives way before the label does.
|
|
16
|
+
*/
|
|
17
|
+
wrapDetail?: boolean | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* Right after the label, before the detail: a mark such as a connected service's, or a
|
|
20
|
+
* Badge. An icon in it is 14px.
|
|
21
|
+
*/
|
|
22
|
+
badge?: Snippet | undefined;
|
|
13
23
|
/**
|
|
14
24
|
* What the key cap on the highlighted item says Enter does. `↵` by default; words such
|
|
15
25
|
* as "Open" for an item that does something of its own, or `null` for none.
|
|
@@ -28,6 +38,16 @@ declare const CommandItem: import("svelte").Component<Loose<Omit<Command.ItemPro
|
|
|
28
38
|
* such as one with the words that match the search marked.
|
|
29
39
|
*/
|
|
30
40
|
detail?: string | Snippet | undefined;
|
|
41
|
+
/**
|
|
42
|
+
* Lets the detail wrap to a second line, rather than be cut short, where its end
|
|
43
|
+
* matters: a path. It gives way before the label does.
|
|
44
|
+
*/
|
|
45
|
+
wrapDetail?: boolean | undefined;
|
|
46
|
+
/**
|
|
47
|
+
* Right after the label, before the detail: a mark such as a connected service's, or a
|
|
48
|
+
* Badge. An icon in it is 14px.
|
|
49
|
+
*/
|
|
50
|
+
badge?: Snippet | undefined;
|
|
31
51
|
/**
|
|
32
52
|
* What the key cap on the highlighted item says Enter does. `↵` by default; words such
|
|
33
53
|
* as "Open" for an item that does something of its own, or `null` for none.
|
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
A list to search and choose from with the keys: the arrows, Page Up and Page
|
|
3
|
+
Down move the highlight, Home and End reach its ends, and Enter chooses.
|
|
4
|
+
|
|
5
|
+
The keys are the list's only where the person is in it: on the root, or in its
|
|
6
|
+
Command.Input. A button, a field or a form of the caller's own inside the root
|
|
7
|
+
keeps its keys, Enter among them, and the search field keeps Home and End to
|
|
8
|
+
move its caret.
|
|
9
|
+
-->
|
|
1
10
|
<script lang="ts" module>
|
|
2
11
|
import type { Loose } from '../../internal/loose.js';
|
|
3
12
|
import { Command } from 'bits-ui';
|
|
@@ -9,7 +18,7 @@
|
|
|
9
18
|
Omit<Command.RootProps, 'children' | 'child'> & {
|
|
10
19
|
/**
|
|
11
20
|
* The value of the highlighted item. Bindable: set it to move the highlight from
|
|
12
|
-
* outside
|
|
21
|
+
* outside. When the highlighted item goes, the highlight goes back to the first.
|
|
13
22
|
*/
|
|
14
23
|
value?: string | undefined;
|
|
15
24
|
/**
|
|
@@ -17,6 +26,11 @@
|
|
|
17
26
|
* to rank them yourself and list only those that match: results from a server, say.
|
|
18
27
|
*/
|
|
19
28
|
shouldFilter?: boolean | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* Whether Ctrl with J and N, or K and P, moves the highlight too, as in Vim and Emacs.
|
|
31
|
+
* Off, those keys are left to the app's own shortcuts.
|
|
32
|
+
*/
|
|
33
|
+
vimBindings?: boolean | undefined;
|
|
20
34
|
sx?: Sx | undefined;
|
|
21
35
|
/** A Command.Input, a Command.List and, if you like, a Command.Footer. */
|
|
22
36
|
children?: Snippet | undefined;
|
|
@@ -25,12 +39,17 @@
|
|
|
25
39
|
|
|
26
40
|
// Page Up and Page Down move the highlight this many items
|
|
27
41
|
const PAGE = 8;
|
|
42
|
+
|
|
43
|
+
// What a caret moves through, where Home and End are the field's
|
|
44
|
+
const FIELD = '[data-command-input]';
|
|
28
45
|
</script>
|
|
29
46
|
|
|
30
47
|
<script lang="ts">
|
|
31
48
|
let {
|
|
32
49
|
value = $bindable(''),
|
|
50
|
+
ref = $bindable(null),
|
|
33
51
|
loop = true,
|
|
52
|
+
vimBindings = false,
|
|
34
53
|
sx,
|
|
35
54
|
class: className,
|
|
36
55
|
children,
|
|
@@ -57,22 +76,62 @@
|
|
|
57
76
|
const at = items.findIndex((item) => item.hasAttribute('data-selected'));
|
|
58
77
|
highlight(Math.min(Math.max((at === -1 ? 0 : at) + step, 0), items.length - 1));
|
|
59
78
|
}
|
|
79
|
+
|
|
80
|
+
const keydown = (
|
|
81
|
+
event: KeyboardEvent & { currentTarget: HTMLDivElement },
|
|
82
|
+
list: ((event: KeyboardEvent) => void) | undefined
|
|
83
|
+
) => {
|
|
84
|
+
onkeydown?.(event);
|
|
85
|
+
// A word being composed keeps its keys (229: Safari's Japanese input, which sends no
|
|
86
|
+
// `isComposing`)
|
|
87
|
+
if (event.defaultPrevented || event.isComposing || event.keyCode === 229) return;
|
|
88
|
+
const target = event.target instanceof Element ? event.target : null;
|
|
89
|
+
const inField = !!target?.matches(FIELD);
|
|
90
|
+
if (target !== event.currentTarget && !inField) return;
|
|
91
|
+
if (inField && (event.key === 'Home' || event.key === 'End')) return;
|
|
92
|
+
if (event.key === 'PageDown' || event.key === 'PageUp') {
|
|
93
|
+
event.preventDefault();
|
|
94
|
+
move(event.key === 'PageDown' ? PAGE : -PAGE);
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
list?.(event);
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
// bits-ui means to move the highlight as its item goes, but compares the item's value with
|
|
101
|
+
// the element's id, so it never does. Here, once the items change, a highlight left on one
|
|
102
|
+
// that is gone goes back to the first.
|
|
103
|
+
$effect(() => {
|
|
104
|
+
const node = ref;
|
|
105
|
+
if (!node) return;
|
|
106
|
+
const observer = new MutationObserver(() => {
|
|
107
|
+
const items = getValidItems();
|
|
108
|
+
if (!items.length || items.some((item) => item.dataset.value === value)) return;
|
|
109
|
+
highlight(0);
|
|
110
|
+
});
|
|
111
|
+
observer.observe(node, { childList: true, subtree: true });
|
|
112
|
+
return () => observer.disconnect();
|
|
113
|
+
});
|
|
60
114
|
</script>
|
|
61
115
|
|
|
62
116
|
<Command.Root
|
|
63
117
|
bind:this={root}
|
|
64
118
|
bind:value
|
|
119
|
+
bind:ref
|
|
65
120
|
{loop}
|
|
121
|
+
{vimBindings}
|
|
66
122
|
data-slot="command"
|
|
67
123
|
{...rest}
|
|
68
|
-
onkeydown={(event: KeyboardEvent & { currentTarget: HTMLDivElement }) => {
|
|
69
|
-
onkeydown?.(event);
|
|
70
|
-
if (event.defaultPrevented || event.isComposing) return;
|
|
71
|
-
if (event.key !== 'PageDown' && event.key !== 'PageUp') return;
|
|
72
|
-
event.preventDefault();
|
|
73
|
-
move(event.key === 'PageDown' ? PAGE : -PAGE);
|
|
74
|
-
}}
|
|
75
124
|
{...attrs([command.root, sx], className)}
|
|
76
125
|
>
|
|
77
|
-
{
|
|
126
|
+
{#snippet child({ props })}
|
|
127
|
+
{@const { onkeydown: list, ...own } = props as typeof props & {
|
|
128
|
+
onkeydown?: (event: KeyboardEvent) => void;
|
|
129
|
+
}}
|
|
130
|
+
<div
|
|
131
|
+
{...own}
|
|
132
|
+
onkeydown={(event: KeyboardEvent & { currentTarget: HTMLDivElement }) => keydown(event, list)}
|
|
133
|
+
>
|
|
134
|
+
{@render children?.()}
|
|
135
|
+
</div>
|
|
136
|
+
{/snippet}
|
|
78
137
|
</Command.Root>
|
|
@@ -5,7 +5,7 @@ import { type Sx } from '../../internal/sx.js';
|
|
|
5
5
|
export type CommandRootProps = Loose<Omit<Command.RootProps, 'children' | 'child'> & {
|
|
6
6
|
/**
|
|
7
7
|
* The value of the highlighted item. Bindable: set it to move the highlight from
|
|
8
|
-
* outside
|
|
8
|
+
* outside. When the highlighted item goes, the highlight goes back to the first.
|
|
9
9
|
*/
|
|
10
10
|
value?: string | undefined;
|
|
11
11
|
/**
|
|
@@ -13,6 +13,11 @@ export type CommandRootProps = Loose<Omit<Command.RootProps, 'children' | 'child
|
|
|
13
13
|
* to rank them yourself and list only those that match: results from a server, say.
|
|
14
14
|
*/
|
|
15
15
|
shouldFilter?: boolean | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* Whether Ctrl with J and N, or K and P, moves the highlight too, as in Vim and Emacs.
|
|
18
|
+
* Off, those keys are left to the app's own shortcuts.
|
|
19
|
+
*/
|
|
20
|
+
vimBindings?: boolean | undefined;
|
|
16
21
|
sx?: Sx | undefined;
|
|
17
22
|
/** A Command.Input, a Command.List and, if you like, a Command.Footer. */
|
|
18
23
|
children?: Snippet | undefined;
|
|
@@ -20,7 +25,7 @@ export type CommandRootProps = Loose<Omit<Command.RootProps, 'children' | 'child
|
|
|
20
25
|
declare const CommandRoot: import("svelte").Component<Loose<Omit<Command.RootProps, "children" | "child"> & {
|
|
21
26
|
/**
|
|
22
27
|
* The value of the highlighted item. Bindable: set it to move the highlight from
|
|
23
|
-
* outside
|
|
28
|
+
* outside. When the highlighted item goes, the highlight goes back to the first.
|
|
24
29
|
*/
|
|
25
30
|
value?: string | undefined;
|
|
26
31
|
/**
|
|
@@ -28,6 +33,11 @@ declare const CommandRoot: import("svelte").Component<Loose<Omit<Command.RootPro
|
|
|
28
33
|
* to rank them yourself and list only those that match: results from a server, say.
|
|
29
34
|
*/
|
|
30
35
|
shouldFilter?: boolean | undefined;
|
|
36
|
+
/**
|
|
37
|
+
* Whether Ctrl with J and N, or K and P, moves the highlight too, as in Vim and Emacs.
|
|
38
|
+
* Off, those keys are left to the app's own shortcuts.
|
|
39
|
+
*/
|
|
40
|
+
vimBindings?: boolean | undefined;
|
|
31
41
|
sx?: Sx | undefined;
|
|
32
42
|
/** A Command.Input, a Command.List and, if you like, a Command.Footer. */
|
|
33
43
|
children?: Snippet | undefined;
|
|
@@ -35,6 +45,6 @@ declare const CommandRoot: import("svelte").Component<Loose<Omit<Command.RootPro
|
|
|
35
45
|
getValidItems: () => HTMLElement[];
|
|
36
46
|
highlight: (index: number) => void;
|
|
37
47
|
move: (step: number) => void;
|
|
38
|
-
}, "value">;
|
|
48
|
+
}, "ref" | "value">;
|
|
39
49
|
type CommandRoot = ReturnType<typeof CommandRoot>;
|
|
40
50
|
export default CommandRoot;
|