@c9up/nebula 0.2.2 → 0.2.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/README.md +8 -7
- package/dist/atoms/Avatar.d.ts +14 -0
- package/dist/atoms/Avatar.js +46 -8
- package/dist/atoms/Checkbox.d.ts +1 -1
- package/dist/atoms/Checkbox.js +1 -1
- package/dist/atoms/Input.d.ts +5 -0
- package/dist/atoms/Input.js +1 -0
- package/dist/cli/add.d.ts +2 -0
- package/dist/cli/add.js +4 -1
- package/dist/cli/diff.d.ts +2 -0
- package/dist/cli/diff.js +4 -1
- package/dist/cli/projectConfig.d.ts +16 -0
- package/dist/cli/projectConfig.js +61 -0
- package/dist/console/AddCommand.js +6 -1
- package/dist/console/DiffCommand.js +6 -1
- package/dist/lib/children.d.ts +13 -8
- package/dist/lib/children.js +5 -0
- package/dist/lib/icons.d.ts +8 -0
- package/dist/lib/icons.js +8 -0
- package/dist/lib/image.js +12 -1
- package/dist/molecules/Breadcrumb.d.ts +11 -2
- package/dist/molecules/Breadcrumb.js +2 -2
- package/dist/molecules/InputOTP.d.ts +14 -0
- package/dist/molecules/InputOTP.js +71 -28
- package/dist/molecules/Pagination.d.ts +34 -2
- package/dist/molecules/Pagination.js +15 -6
- package/dist/molecules/PieceMap.d.ts +72 -0
- package/dist/molecules/PieceMap.js +78 -0
- package/dist/molecules/Resizable.d.ts +2 -0
- package/dist/molecules/Resizable.js +1 -1
- package/dist/molecules/index.d.ts +4 -3
- package/dist/molecules/index.js +2 -1
- package/dist/organisms/Calendar.d.ts +13 -0
- package/dist/organisms/Calendar.js +2 -2
- package/dist/organisms/Carousel.d.ts +8 -0
- package/dist/organisms/Carousel.js +8 -5
- package/dist/organisms/Combobox.d.ts +13 -0
- package/dist/organisms/Combobox.js +5 -2
- package/dist/organisms/Command.js +56 -8
- package/dist/organisms/DataTable.d.ts +23 -1
- package/dist/organisms/DataTable.js +57 -27
- package/dist/organisms/DatePicker.d.ts +7 -0
- package/dist/organisms/DatePicker.js +2 -1
- package/dist/organisms/DateRangePicker.d.ts +2 -0
- package/dist/organisms/DateRangePicker.js +2 -1
- package/dist/organisms/Dialog.d.ts +13 -3
- package/dist/organisms/Dialog.js +12 -5
- package/dist/organisms/Form.d.ts +15 -0
- package/dist/organisms/Form.js +10 -0
- package/dist/organisms/Questionnaire.d.ts +4 -0
- package/dist/organisms/Questionnaire.js +5 -2
- package/dist/organisms/Select.d.ts +25 -4
- package/dist/organisms/Select.js +116 -15
- package/dist/organisms/Sheet.d.ts +2 -0
- package/dist/organisms/Sheet.js +2 -1
- package/dist/organisms/Sidebar.d.ts +10 -2
- package/dist/organisms/Sidebar.js +62 -29
- package/dist/organisms/Sonner.d.ts +243 -0
- package/dist/organisms/Sonner.js +909 -0
- package/dist/organisms/Toaster.d.ts +11 -0
- package/dist/organisms/Toaster.js +34 -9
- package/dist/organisms/Tooltip.d.ts +4 -0
- package/dist/organisms/index.d.ts +8 -2
- package/dist/organisms/index.js +7 -1
- package/dist/primitives/dismissable.d.ts +11 -4
- package/dist/primitives/dismissable.js +8 -6
- package/dist/primitives/floating.d.ts +5 -1
- package/dist/primitives/floating.js +32 -2
- package/dist/primitives/menu.js +2 -1
- package/dist/primitives/modalSurface.js +70 -36
- package/dist/primitives/presence.js +8 -5
- package/dist/templates/SettingsLayout.d.ts +2 -0
- package/dist/templates/SettingsLayout.js +1 -1
- package/nebula.css +2 -2
- package/package.json +3 -3
- package/registry.json +26 -0
- package/src/atoms/Avatar.ts +54 -7
- package/src/atoms/Checkbox.ts +1 -1
- package/src/atoms/Input.ts +6 -0
- package/src/cli/add.ts +7 -1
- package/src/cli/diff.ts +7 -1
- package/src/cli/projectConfig.ts +71 -0
- package/src/console/AddCommand.ts +6 -1
- package/src/console/DiffCommand.ts +6 -1
- package/src/lib/children.ts +15 -7
- package/src/lib/icons.ts +28 -0
- package/src/lib/image.ts +13 -1
- package/src/molecules/Breadcrumb.ts +15 -4
- package/src/molecules/InputOTP.ts +88 -28
- package/src/molecules/Pagination.ts +50 -8
- package/src/molecules/PieceMap.ts +136 -0
- package/src/molecules/Resizable.ts +3 -1
- package/src/molecules/index.ts +17 -0
- package/src/organisms/Calendar.ts +16 -2
- package/src/organisms/Carousel.ts +17 -5
- package/src/organisms/Combobox.ts +18 -2
- package/src/organisms/Command.ts +66 -7
- package/src/organisms/DataTable.ts +95 -30
- package/src/organisms/DatePicker.ts +10 -2
- package/src/organisms/DateRangePicker.ts +4 -2
- package/src/organisms/Dialog.ts +17 -5
- package/src/organisms/Form.ts +21 -0
- package/src/organisms/Questionnaire.ts +10 -2
- package/src/organisms/Select.ts +140 -16
- package/src/organisms/Sheet.ts +5 -1
- package/src/organisms/Sidebar.ts +62 -23
- package/src/organisms/Sonner.ts +1366 -0
- package/src/organisms/Toaster.ts +38 -10
- package/src/organisms/Tooltip.ts +4 -0
- package/src/organisms/index.ts +30 -1
- package/src/primitives/dismissable.ts +16 -8
- package/src/primitives/floating.ts +40 -3
- package/src/primitives/menu.ts +2 -1
- package/src/primitives/modalSurface.ts +77 -40
- package/src/primitives/presence.ts +12 -9
- package/src/templates/SettingsLayout.ts +3 -1
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PieceMap — a transfer drawn as one small square per piece.
|
|
3
|
+
*
|
|
4
|
+
* What a torrent client shows under a download: each square is a piece of the
|
|
5
|
+
* whole, coloured by where it stands — here, missing, on its way, taken from a
|
|
6
|
+
* peer. A progress bar says how much; the map says *which*, and that is what
|
|
7
|
+
* a stalled run, a missing layer or a peer serving one half shows at a glance.
|
|
8
|
+
*
|
|
9
|
+
* The states are the caller's, not a fixed set. A download, a replication and
|
|
10
|
+
* a backup do not have the same ones, so the component takes a string type of
|
|
11
|
+
* its own and a class per state — `tones` — and paints nothing it was not
|
|
12
|
+
* told about. The legend reads the same `tones`, so a square and its key can
|
|
13
|
+
* never drift apart.
|
|
14
|
+
*
|
|
15
|
+
* Pieces come in groups: each group after the first is set off by a rule — a
|
|
16
|
+
* torrent's files, an image's layers. A flat map is one group.
|
|
17
|
+
*
|
|
18
|
+
* A generic function rather than `component<P>`, as DataTable: `State` has to
|
|
19
|
+
* stay open so `tones` is checked against the caller's own states.
|
|
20
|
+
*
|
|
21
|
+
* With a `label`, the map is one image to assistive technology and the label
|
|
22
|
+
* is what it says ("12 of 40 pieces"): a screen reader walking hundreds of
|
|
23
|
+
* squares one by one learns nothing the sentence does not. Each square keeps
|
|
24
|
+
* its `title` for the pointer.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
import { html, type TemplateResult } from "@c9up/aurora";
|
|
28
|
+
import type { Child } from "../lib/children.js";
|
|
29
|
+
import { cn } from "../lib/cn.js";
|
|
30
|
+
import { cva, type VariantProps } from "../lib/cva.js";
|
|
31
|
+
import { type Reactive, read } from "../lib/props.js";
|
|
32
|
+
|
|
33
|
+
export const pieceVariants = cva("inline-block shrink-0 rounded-[2px]", {
|
|
34
|
+
variants: {
|
|
35
|
+
size: {
|
|
36
|
+
sm: "size-2",
|
|
37
|
+
default: "size-2.5",
|
|
38
|
+
lg: "size-3",
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
defaultVariants: { size: "default" },
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
export type PieceVariants = VariantProps<typeof pieceVariants>;
|
|
45
|
+
|
|
46
|
+
export interface Piece<State extends string> {
|
|
47
|
+
state: State;
|
|
48
|
+
/** The square's tooltip: which piece, how big, from where. */
|
|
49
|
+
title?: string;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface PieceMapProps<State extends string> {
|
|
53
|
+
/**
|
|
54
|
+
* The pieces, group after group, or an accessor for pieces that change: the
|
|
55
|
+
* squares are drawn again whenever what it reads changes.
|
|
56
|
+
*/
|
|
57
|
+
groups: Reactive<readonly (readonly Piece<State>[])[]>;
|
|
58
|
+
/** The classes that paint each state: a background, a border, a pulse. */
|
|
59
|
+
tones: Readonly<Record<State, string>>;
|
|
60
|
+
size?: Reactive<PieceVariants["size"]>;
|
|
61
|
+
/** What the map says as a whole. Makes it one image; see above. */
|
|
62
|
+
label?: Reactive<string | undefined>;
|
|
63
|
+
class?: Reactive<string>;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function PieceMap<State extends string>(
|
|
67
|
+
props: PieceMapProps<State>,
|
|
68
|
+
): TemplateResult {
|
|
69
|
+
return html`<div
|
|
70
|
+
data-slot="piece-map"
|
|
71
|
+
role="${() => (read(props.label) === undefined ? undefined : "img")}"
|
|
72
|
+
aria-label="${() => read(props.label)}"
|
|
73
|
+
class="${() => cn("flex flex-wrap gap-1", read(props.class))}"
|
|
74
|
+
>
|
|
75
|
+
${() =>
|
|
76
|
+
read(props.groups).map(
|
|
77
|
+
(pieces, index) => html`<span
|
|
78
|
+
data-slot="piece-map-group"
|
|
79
|
+
class="${cn("flex flex-wrap gap-0.5", index > 0 && "border-border border-s ps-1")}"
|
|
80
|
+
>
|
|
81
|
+
${pieces.map(
|
|
82
|
+
(piece) => html`<span
|
|
83
|
+
data-slot="piece"
|
|
84
|
+
data-state="${piece.state}"
|
|
85
|
+
title="${piece.title}"
|
|
86
|
+
class="${cn(pieceVariants({ size: read(props.size) }), props.tones[piece.state])}"
|
|
87
|
+
></span>`,
|
|
88
|
+
)}
|
|
89
|
+
</span>`,
|
|
90
|
+
)}
|
|
91
|
+
</div>`;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export interface PieceMapLegendItem<State extends string> {
|
|
95
|
+
state: State;
|
|
96
|
+
label: Child;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export interface PieceMapLegendProps<State extends string> {
|
|
100
|
+
/** The same `tones` as the map's. */
|
|
101
|
+
tones: Readonly<Record<State, string>>;
|
|
102
|
+
/** The states to explain, in the order they are read. */
|
|
103
|
+
items: readonly PieceMapLegendItem<State>[];
|
|
104
|
+
/** Said before the keys — the size of the whole, say. */
|
|
105
|
+
children?: Child;
|
|
106
|
+
size?: Reactive<PieceVariants["size"]>;
|
|
107
|
+
class?: Reactive<string>;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** What the squares' colours mean. */
|
|
111
|
+
export function PieceMapLegend<State extends string>(
|
|
112
|
+
props: PieceMapLegendProps<State>,
|
|
113
|
+
): TemplateResult {
|
|
114
|
+
// A space after each key: the gap between them is only drawn, and without
|
|
115
|
+
// one their labels run together for a screen reader and a copy.
|
|
116
|
+
return html`<p
|
|
117
|
+
data-slot="piece-map-legend"
|
|
118
|
+
class="${() =>
|
|
119
|
+
cn(
|
|
120
|
+
"text-muted-foreground flex flex-wrap gap-x-4 gap-y-1 text-xs",
|
|
121
|
+
read(props.class),
|
|
122
|
+
)}"
|
|
123
|
+
>
|
|
124
|
+
${props.children}
|
|
125
|
+
${props.items.map(
|
|
126
|
+
(item) => html`<span class="inline-flex items-center gap-1.5"
|
|
127
|
+
><span
|
|
128
|
+
aria-hidden="true"
|
|
129
|
+
data-state="${item.state}"
|
|
130
|
+
class="${() => cn(pieceVariants({ size: read(props.size) }), props.tones[item.state])}"
|
|
131
|
+
></span
|
|
132
|
+
>${item.label}</span
|
|
133
|
+
> `,
|
|
134
|
+
)}
|
|
135
|
+
</p>`;
|
|
136
|
+
}
|
|
@@ -131,6 +131,8 @@ export const ResizablePanel = component<ResizablePanelProps>((props) => {
|
|
|
131
131
|
export interface ResizableHandleProps {
|
|
132
132
|
/** Show the grip dots. */
|
|
133
133
|
withHandle?: boolean;
|
|
134
|
+
/** The separator's accessible name. Default `"Resize panes"`. */
|
|
135
|
+
label?: string;
|
|
134
136
|
class?: Reactive<string>;
|
|
135
137
|
}
|
|
136
138
|
|
|
@@ -205,7 +207,7 @@ export const ResizableHandle = component<ResizableHandleProps>((props) => {
|
|
|
205
207
|
aria-valuemin="${group.min}"
|
|
206
208
|
aria-valuemax="${group.max}"
|
|
207
209
|
aria-valuenow="${() => Math.round(group.size())}"
|
|
208
|
-
aria-label="Resize panes"
|
|
210
|
+
aria-label="${props.label ?? "Resize panes"}"
|
|
209
211
|
class="${() =>
|
|
210
212
|
cn(
|
|
211
213
|
"bg-border relative flex shrink-0 items-center justify-center outline-none",
|
package/src/molecules/index.ts
CHANGED
|
@@ -42,10 +42,12 @@ export {
|
|
|
42
42
|
export {
|
|
43
43
|
Breadcrumb,
|
|
44
44
|
BreadcrumbEllipsis,
|
|
45
|
+
type BreadcrumbEllipsisProps,
|
|
45
46
|
BreadcrumbItem,
|
|
46
47
|
BreadcrumbLink,
|
|
47
48
|
type BreadcrumbLinkProps,
|
|
48
49
|
BreadcrumbList,
|
|
50
|
+
type BreadcrumbNavProps,
|
|
49
51
|
BreadcrumbPage,
|
|
50
52
|
type BreadcrumbProps,
|
|
51
53
|
BreadcrumbSeparator,
|
|
@@ -131,6 +133,9 @@ export {
|
|
|
131
133
|
type InputOTPSeparatorProps,
|
|
132
134
|
InputOTPSlot,
|
|
133
135
|
type InputOTPSlotProps,
|
|
136
|
+
REGEXP_ONLY_CHARS,
|
|
137
|
+
REGEXP_ONLY_DIGITS,
|
|
138
|
+
REGEXP_ONLY_DIGITS_AND_CHARS,
|
|
134
139
|
} from "./InputOTP.js";
|
|
135
140
|
export {
|
|
136
141
|
Item,
|
|
@@ -153,8 +158,10 @@ export {
|
|
|
153
158
|
PaginationEllipsis,
|
|
154
159
|
type PaginationEllipsisProps,
|
|
155
160
|
PaginationItem,
|
|
161
|
+
type PaginationLabels,
|
|
156
162
|
PaginationLink,
|
|
157
163
|
type PaginationLinkProps,
|
|
164
|
+
type PaginationNavProps,
|
|
158
165
|
PaginationNext,
|
|
159
166
|
PaginationPrevious,
|
|
160
167
|
type PaginationProps,
|
|
@@ -162,6 +169,16 @@ export {
|
|
|
162
169
|
pageWindow,
|
|
163
170
|
} from "./Pagination.js";
|
|
164
171
|
export { Picture, type PictureProps } from "./Picture.js";
|
|
172
|
+
export {
|
|
173
|
+
type Piece,
|
|
174
|
+
PieceMap,
|
|
175
|
+
PieceMapLegend,
|
|
176
|
+
type PieceMapLegendItem,
|
|
177
|
+
type PieceMapLegendProps,
|
|
178
|
+
type PieceMapProps,
|
|
179
|
+
type PieceVariants,
|
|
180
|
+
pieceVariants,
|
|
181
|
+
} from "./PieceMap.js";
|
|
165
182
|
export {
|
|
166
183
|
RadioGroup,
|
|
167
184
|
RadioGroupItem,
|
|
@@ -37,6 +37,19 @@ export interface DateRange {
|
|
|
37
37
|
readonly to?: Date;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
/**
|
|
41
|
+
* The words the calendar writes itself — react-day-picker's `labels`.
|
|
42
|
+
*
|
|
43
|
+
* Month and weekday names come from `Intl` in `locale`; these two do not, and
|
|
44
|
+
* a screen reader would read them in English in the middle of a French page.
|
|
45
|
+
*/
|
|
46
|
+
export interface CalendarLabels {
|
|
47
|
+
/** The previous-month arrow. Default `"Previous month"`. */
|
|
48
|
+
previousMonth: string;
|
|
49
|
+
/** The next-month arrow. Default `"Next month"`. */
|
|
50
|
+
nextMonth: string;
|
|
51
|
+
}
|
|
52
|
+
|
|
40
53
|
export interface CalendarProps {
|
|
41
54
|
/**
|
|
42
55
|
* `"range"` picks a span in two clicks. Default `"single"`.
|
|
@@ -63,6 +76,7 @@ export interface CalendarProps {
|
|
|
63
76
|
/** `0` Sunday, `1` Monday. Defaults to the locale's own first day. */
|
|
64
77
|
weekStartsOn?: number;
|
|
65
78
|
locale?: string;
|
|
79
|
+
labels?: Partial<CalendarLabels>;
|
|
66
80
|
class?: Reactive<string>;
|
|
67
81
|
/** `"single"` mode. */
|
|
68
82
|
onValueChange?: (date: Date) => void;
|
|
@@ -374,7 +388,7 @@ export const Calendar = component<CalendarProps>((props) => {
|
|
|
374
388
|
<div class="flex items-center justify-between pb-4">
|
|
375
389
|
<button
|
|
376
390
|
type="button"
|
|
377
|
-
aria-label="Previous month"
|
|
391
|
+
aria-label="${props.labels?.previousMonth ?? "Previous month"}"
|
|
378
392
|
class="${buttonVariants({ variant: "outline", size: "icon", class: "size-7" })}"
|
|
379
393
|
@click="${() => month(addMonths(month(), -1))}"
|
|
380
394
|
>${ChevronLeftIcon({ class: "size-4" })}</button>
|
|
@@ -383,7 +397,7 @@ export const Calendar = component<CalendarProps>((props) => {
|
|
|
383
397
|
</div>
|
|
384
398
|
<button
|
|
385
399
|
type="button"
|
|
386
|
-
aria-label="Next month"
|
|
400
|
+
aria-label="${props.labels?.nextMonth ?? "Next month"}"
|
|
387
401
|
class="${buttonVariants({ variant: "outline", size: "icon", class: "size-7" })}"
|
|
388
402
|
@click="${() => month(addMonths(month(), 1))}"
|
|
389
403
|
>${ChevronRightIcon({ class: "size-4" })}</button>
|
|
@@ -52,6 +52,8 @@ const CarouselContext = createContext<CarouselApi>("Carousel");
|
|
|
52
52
|
export interface CarouselProps {
|
|
53
53
|
/** Announced before the slides. */
|
|
54
54
|
label?: string;
|
|
55
|
+
/** What a screen reader calls the region. Default `"carousel"`. */
|
|
56
|
+
roleDescription?: string;
|
|
55
57
|
orientation?: "horizontal" | "vertical";
|
|
56
58
|
class?: Reactive<string>;
|
|
57
59
|
children?: Parts;
|
|
@@ -138,7 +140,7 @@ export const Carousel = component<CarouselProps>((props) => {
|
|
|
138
140
|
return html`<div
|
|
139
141
|
data-slot="carousel"
|
|
140
142
|
role="region"
|
|
141
|
-
aria-roledescription="carousel"
|
|
143
|
+
aria-roledescription="${props.roleDescription ?? "carousel"}"
|
|
142
144
|
aria-label="${props.label ?? "Carousel"}"
|
|
143
145
|
class="${() => cn("relative", read(props.class))}"
|
|
144
146
|
@keydown="${onKeyDown}"
|
|
@@ -168,6 +170,10 @@ export const CarouselContent = component<CarouselContentProps>((props) => {
|
|
|
168
170
|
|
|
169
171
|
export interface CarouselItemProps {
|
|
170
172
|
children?: Slot;
|
|
173
|
+
/** What a screen reader calls one slide. Default `"slide"`. */
|
|
174
|
+
roleDescription?: string;
|
|
175
|
+
/** The slide's name from its position. Default `"3 of 7"`. */
|
|
176
|
+
label?: (position: number, count: number) => string;
|
|
171
177
|
class?: Reactive<string>;
|
|
172
178
|
}
|
|
173
179
|
|
|
@@ -184,14 +190,20 @@ export const CarouselItem = component<CarouselItemProps>((props) => {
|
|
|
184
190
|
return html`<div
|
|
185
191
|
data-slot="carousel-item"
|
|
186
192
|
role="group"
|
|
187
|
-
aria-roledescription="slide"
|
|
188
|
-
aria-label="${() =>
|
|
193
|
+
aria-roledescription="${props.roleDescription ?? "slide"}"
|
|
194
|
+
aria-label="${() => (props.label ?? slideOf)(position, carousel.slideCount())}"
|
|
189
195
|
class="${() =>
|
|
190
196
|
cn("min-w-0 shrink-0 grow-0 basis-full snap-start", read(props.class))}"
|
|
191
197
|
>${slot(props.children)}</div>`;
|
|
192
198
|
});
|
|
193
199
|
|
|
200
|
+
function slideOf(position: number, count: number): string {
|
|
201
|
+
return `${position} of ${count}`;
|
|
202
|
+
}
|
|
203
|
+
|
|
194
204
|
export interface CarouselButtonProps {
|
|
205
|
+
/** The arrow's accessible name. Default `"Previous slide"` / `"Next slide"`. */
|
|
206
|
+
label?: string;
|
|
195
207
|
class?: Reactive<string>;
|
|
196
208
|
}
|
|
197
209
|
|
|
@@ -202,7 +214,7 @@ export const CarouselPrevious = component<CarouselButtonProps>((props) => {
|
|
|
202
214
|
return html`<button
|
|
203
215
|
type="button"
|
|
204
216
|
data-slot="carousel-previous"
|
|
205
|
-
aria-label="Previous slide"
|
|
217
|
+
aria-label="${props.label ?? "Previous slide"}"
|
|
206
218
|
?disabled="${() => carousel.atStart()}"
|
|
207
219
|
class="${() =>
|
|
208
220
|
cn(
|
|
@@ -222,7 +234,7 @@ export const CarouselNext = component<CarouselButtonProps>((props) => {
|
|
|
222
234
|
return html`<button
|
|
223
235
|
type="button"
|
|
224
236
|
data-slot="carousel-next"
|
|
225
|
-
aria-label="Next slide"
|
|
237
|
+
aria-label="${props.label ?? "Next slide"}"
|
|
226
238
|
?disabled="${() => carousel.atEnd()}"
|
|
227
239
|
class="${() =>
|
|
228
240
|
cn(
|
|
@@ -20,7 +20,7 @@ import { cn } from "../lib/cn.js";
|
|
|
20
20
|
import { ChevronsUpDownIcon } from "../lib/icons.js";
|
|
21
21
|
import { uid } from "../lib/id.js";
|
|
22
22
|
import { zoomInOut } from "../lib/motion.js";
|
|
23
|
-
import { type Reactive, read, readOr } from "../lib/props.js";
|
|
23
|
+
import { accessor, type Reactive, read, readOr } from "../lib/props.js";
|
|
24
24
|
import { controllable } from "../primitives/controllable.js";
|
|
25
25
|
import { floatingSurface } from "../primitives/floatingSurface.js";
|
|
26
26
|
import { focusSilently } from "../primitives/focusable.js";
|
|
@@ -42,8 +42,21 @@ export interface ComboboxOption {
|
|
|
42
42
|
group?: string;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
+
/**
|
|
46
|
+
* `id`, `label`, `labelledBy` and `describedBy` name the trigger. Upstream's
|
|
47
|
+
* trigger is a Button that takes every button prop; these are the ones that
|
|
48
|
+
* name it — a `<Label for>` or a `FieldLabel` points at the `id`. Without them
|
|
49
|
+
* the combobox's only name was the value it showed.
|
|
50
|
+
*/
|
|
45
51
|
export interface ComboboxProps {
|
|
46
52
|
options: readonly ComboboxOption[];
|
|
53
|
+
/** The trigger's id; a unique one is minted when left out. */
|
|
54
|
+
id?: string;
|
|
55
|
+
/** Accessible name (`aria-label`), for a combobox no `<label>` names. */
|
|
56
|
+
label?: Reactive<string | undefined>;
|
|
57
|
+
/** Id(s) of the element(s) that name it (`aria-labelledby`). */
|
|
58
|
+
labelledBy?: Reactive<string | undefined>;
|
|
59
|
+
describedBy?: Reactive<string | undefined>;
|
|
47
60
|
name?: string;
|
|
48
61
|
value?: Reactive<string | undefined>;
|
|
49
62
|
defaultValue?: string;
|
|
@@ -60,7 +73,7 @@ export interface ComboboxProps {
|
|
|
60
73
|
}
|
|
61
74
|
|
|
62
75
|
export const Combobox = component<ComboboxProps>((props) => {
|
|
63
|
-
const triggerId = uid("combobox-trigger");
|
|
76
|
+
const triggerId = props.id ?? uid("combobox-trigger");
|
|
64
77
|
const contentId = uid("combobox-content");
|
|
65
78
|
const open = signal(false);
|
|
66
79
|
|
|
@@ -165,6 +178,9 @@ export const Combobox = component<ComboboxProps>((props) => {
|
|
|
165
178
|
type="button"
|
|
166
179
|
data-slot="combobox-trigger"
|
|
167
180
|
id="${triggerId}"
|
|
181
|
+
aria-label="${accessor(props.label, undefined)}"
|
|
182
|
+
aria-labelledby="${accessor(props.labelledBy, undefined)}"
|
|
183
|
+
aria-describedby="${accessor(props.describedBy, undefined)}"
|
|
168
184
|
role="combobox"
|
|
169
185
|
aria-haspopup="listbox"
|
|
170
186
|
aria-expanded="${() => (open() ? "true" : "false")}"
|
package/src/organisms/Command.ts
CHANGED
|
@@ -29,6 +29,8 @@ import {
|
|
|
29
29
|
createContext,
|
|
30
30
|
html,
|
|
31
31
|
inject,
|
|
32
|
+
onMount,
|
|
33
|
+
onUnmount,
|
|
32
34
|
provide,
|
|
33
35
|
signal,
|
|
34
36
|
} from "@c9up/aurora";
|
|
@@ -67,13 +69,23 @@ interface RegisteredItem extends CommandCandidate {
|
|
|
67
69
|
run(): void;
|
|
68
70
|
}
|
|
69
71
|
|
|
72
|
+
/** One mounted item's registration. */
|
|
73
|
+
interface Registration {
|
|
74
|
+
/** Run this item — the mounted one, whatever else shares its value. */
|
|
75
|
+
select(): void;
|
|
76
|
+
/** Mounted: the palette's bindings learn it is there. */
|
|
77
|
+
mounted(): void;
|
|
78
|
+
/** Unmounted: it leaves the palette. */
|
|
79
|
+
unregister(): void;
|
|
80
|
+
}
|
|
81
|
+
|
|
70
82
|
interface CommandApi {
|
|
71
83
|
readonly inputId: string;
|
|
72
84
|
readonly listId: string;
|
|
73
85
|
readonly query: () => string;
|
|
74
86
|
readonly active: () => string | undefined;
|
|
75
87
|
setActive(value: string | undefined): void;
|
|
76
|
-
register(item: Omit<RegisteredItem, "id">):
|
|
88
|
+
register(item: Omit<RegisteredItem, "id">): Registration;
|
|
77
89
|
/** This palette's element id for a value. Per instance: ids are page-wide. */
|
|
78
90
|
itemId(value: string): string;
|
|
79
91
|
/** Does this item survive the current query? */
|
|
@@ -139,6 +151,33 @@ export const Command = component<CommandProps>((props) => {
|
|
|
139
151
|
*/
|
|
140
152
|
const explicitActive = signal<string | undefined>(undefined);
|
|
141
153
|
|
|
154
|
+
/**
|
|
155
|
+
* Bumped when items mount or unmount, so the bindings that read the list
|
|
156
|
+
* — the empty state, the groups, the highlight — follow it. `items` itself
|
|
157
|
+
* stays a plain array, filled during setup: a signal written while the
|
|
158
|
+
* items are being built re-entered the effect building them.
|
|
159
|
+
*
|
|
160
|
+
* Coalesced to one bump per task, as cmdk schedules its store updates: a
|
|
161
|
+
* list of a hundred items mounting is one pass over the bindings, not a
|
|
162
|
+
* hundred.
|
|
163
|
+
*/
|
|
164
|
+
const revision = signal(0);
|
|
165
|
+
let scheduled = false;
|
|
166
|
+
function changed(): void {
|
|
167
|
+
if (scheduled) return;
|
|
168
|
+
scheduled = true;
|
|
169
|
+
queueMicrotask(() => {
|
|
170
|
+
scheduled = false;
|
|
171
|
+
// The highlighted item left: back to "the first match", as cmdk
|
|
172
|
+
// re-selects the first item when the selected one unmounts.
|
|
173
|
+
const chosen = explicitActive();
|
|
174
|
+
if (chosen !== undefined && !items.some((i) => i.value === chosen)) {
|
|
175
|
+
explicitActive(undefined);
|
|
176
|
+
}
|
|
177
|
+
revision(revision() + 1);
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
|
|
142
181
|
function active(): string | undefined {
|
|
143
182
|
const chosen = explicitActive();
|
|
144
183
|
if (chosen !== undefined) return chosen;
|
|
@@ -146,15 +185,20 @@ export const Command = component<CommandProps>((props) => {
|
|
|
146
185
|
}
|
|
147
186
|
|
|
148
187
|
function matches(): readonly RegisteredItem[] {
|
|
188
|
+
revision();
|
|
149
189
|
const filter = props.filter ?? defaultFilter;
|
|
150
190
|
return items.filter((item) => !item.disabled && filter(item, query()));
|
|
151
191
|
}
|
|
152
192
|
|
|
193
|
+
function runItem(item: RegisteredItem): void {
|
|
194
|
+
if (item.disabled || !items.includes(item)) return;
|
|
195
|
+
item.run();
|
|
196
|
+
props.onSelect?.(item.value);
|
|
197
|
+
}
|
|
198
|
+
|
|
153
199
|
function run(value: string): void {
|
|
154
200
|
const item = items.find((entry) => entry.value === value);
|
|
155
|
-
if (item
|
|
156
|
-
item.run();
|
|
157
|
-
props.onSelect?.(value);
|
|
201
|
+
if (item !== undefined) runItem(item);
|
|
158
202
|
}
|
|
159
203
|
|
|
160
204
|
function move(delta: number): void {
|
|
@@ -178,7 +222,18 @@ export const Command = component<CommandProps>((props) => {
|
|
|
178
222
|
setActive: (value) => explicitActive(value),
|
|
179
223
|
itemId,
|
|
180
224
|
register(item) {
|
|
181
|
-
|
|
225
|
+
const entry: RegisteredItem = { ...item, id: itemId(item.value) };
|
|
226
|
+
items.push(entry);
|
|
227
|
+
return {
|
|
228
|
+
select: () => runItem(entry),
|
|
229
|
+
mounted: changed,
|
|
230
|
+
unregister(): void {
|
|
231
|
+
const index = items.indexOf(entry);
|
|
232
|
+
if (index === -1) return;
|
|
233
|
+
items.splice(index, 1);
|
|
234
|
+
changed();
|
|
235
|
+
},
|
|
236
|
+
};
|
|
182
237
|
},
|
|
183
238
|
isVisible(value) {
|
|
184
239
|
return matches().some((item) => item.value === value);
|
|
@@ -334,7 +389,9 @@ export const CommandItem = component<CommandItemProps>((props) => {
|
|
|
334
389
|
const children = props.children;
|
|
335
390
|
|
|
336
391
|
const id = command.itemId(props.value);
|
|
337
|
-
|
|
392
|
+
// Registered during setup, so the first pass over the bindings sees it;
|
|
393
|
+
// gone again when it unmounts, as cmdk's item cleanup.
|
|
394
|
+
const registration = command.register({
|
|
338
395
|
value: props.value,
|
|
339
396
|
textValue:
|
|
340
397
|
props.textValue ??
|
|
@@ -344,6 +401,8 @@ export const CommandItem = component<CommandItemProps>((props) => {
|
|
|
344
401
|
groupId: group?.groupId,
|
|
345
402
|
run: () => props.onSelect?.(),
|
|
346
403
|
});
|
|
404
|
+
onMount(() => registration.mounted());
|
|
405
|
+
onUnmount(() => registration.unregister());
|
|
347
406
|
|
|
348
407
|
const chosen = (): boolean => command.active() === props.value;
|
|
349
408
|
return html`<div
|
|
@@ -360,7 +419,7 @@ export const CommandItem = component<CommandItemProps>((props) => {
|
|
|
360
419
|
"relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[active]:bg-accent data-[active]:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4",
|
|
361
420
|
read(props.class),
|
|
362
421
|
)}"
|
|
363
|
-
@click="${() =>
|
|
422
|
+
@click="${() => registration.select()}"
|
|
364
423
|
@pointerenter="${() => command.setActive(props.value)}"
|
|
365
424
|
>${slot(children)}</div>`;
|
|
366
425
|
});
|