@c9up/nebula 0.2.3 → 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 +7 -6
- package/dist/atoms/Avatar.d.ts +14 -0
- package/dist/atoms/Avatar.js +46 -8
- 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/icons.d.ts +8 -0
- package/dist/lib/icons.js +8 -0
- package/dist/lib/image.js +12 -1
- package/dist/molecules/InputOTP.d.ts +12 -0
- package/dist/molecules/InputOTP.js +68 -27
- package/dist/molecules/index.d.ts +1 -1
- package/dist/molecules/index.js +1 -1
- 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/Form.d.ts +15 -0
- package/dist/organisms/Form.js +10 -0
- package/dist/organisms/Select.d.ts +6 -4
- package/dist/organisms/Select.js +1 -0
- package/dist/organisms/Sidebar.d.ts +4 -2
- package/dist/organisms/Sidebar.js +54 -26
- package/dist/organisms/Sonner.d.ts +243 -0
- package/dist/organisms/Sonner.js +909 -0
- package/dist/organisms/Toaster.d.ts +9 -0
- package/dist/organisms/Toaster.js +28 -5
- package/dist/organisms/Tooltip.d.ts +4 -0
- package/dist/organisms/index.d.ts +6 -0
- package/dist/organisms/index.js +6 -0
- 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 +8 -1
- package/dist/primitives/menu.js +2 -1
- package/dist/primitives/modalSurface.js +70 -36
- package/dist/primitives/presence.js +8 -5
- package/nebula.css +2 -2
- package/package.json +1 -1
- package/registry.json +13 -0
- package/src/atoms/Avatar.ts +54 -7
- 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/icons.ts +28 -0
- package/src/lib/image.ts +13 -1
- package/src/molecules/InputOTP.ts +81 -27
- package/src/molecules/index.ts +3 -0
- package/src/organisms/Combobox.ts +18 -2
- package/src/organisms/Command.ts +66 -7
- package/src/organisms/Form.ts +21 -0
- package/src/organisms/Select.ts +7 -4
- package/src/organisms/Sidebar.ts +47 -19
- package/src/organisms/Sonner.ts +1366 -0
- package/src/organisms/Toaster.ts +30 -6
- package/src/organisms/Tooltip.ts +4 -0
- package/src/organisms/index.ts +23 -0
- package/src/primitives/dismissable.ts +16 -8
- package/src/primitives/floating.ts +13 -2
- package/src/primitives/menu.ts +2 -1
- package/src/primitives/modalSurface.ts +77 -40
- package/src/primitives/presence.ts +12 -9
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The app's `config/nebula.ts`, as the copying commands read it.
|
|
3
|
+
*
|
|
4
|
+
* shadcn's CLI reads `components.json` on every `add` and `diff`; these read
|
|
5
|
+
* the config file the same way. Imported directly rather than taken from the
|
|
6
|
+
* booted application: the console kernel hands the app — and its config —
|
|
7
|
+
* only to a command that starts it, and starting it opens the connections a
|
|
8
|
+
* file copy has no use for, and fails where they are not running.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { existsSync } from "node:fs";
|
|
12
|
+
import { join } from "node:path";
|
|
13
|
+
import { pathToFileURL } from "node:url";
|
|
14
|
+
import type { Language, NebulaPaths } from "../config.js";
|
|
15
|
+
|
|
16
|
+
export interface ProjectConfig {
|
|
17
|
+
paths?: Partial<NebulaPaths>;
|
|
18
|
+
language?: Language;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Tried in order; the first that exists is the config. */
|
|
22
|
+
const CANDIDATES = ["nebula.ts", "nebula.js", "nebula.mjs"];
|
|
23
|
+
|
|
24
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
25
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function pathsOf(
|
|
29
|
+
value: unknown,
|
|
30
|
+
file: string,
|
|
31
|
+
): Partial<NebulaPaths> | undefined {
|
|
32
|
+
if (value === undefined) return undefined;
|
|
33
|
+
if (!isRecord(value)) {
|
|
34
|
+
throw new Error(`${file}: \`paths\` must be an object.`);
|
|
35
|
+
}
|
|
36
|
+
const paths: Partial<NebulaPaths> = {};
|
|
37
|
+
for (const key of ["components", "css", "output"] as const) {
|
|
38
|
+
const entry = value[key];
|
|
39
|
+
if (entry === undefined) continue;
|
|
40
|
+
if (typeof entry !== "string" || entry === "") {
|
|
41
|
+
throw new Error(`${file}: \`paths.${key}\` must be a non-empty string.`);
|
|
42
|
+
}
|
|
43
|
+
paths[key] = entry;
|
|
44
|
+
}
|
|
45
|
+
return paths;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function languageOf(value: unknown, file: string): Language | undefined {
|
|
49
|
+
if (value === undefined) return undefined;
|
|
50
|
+
if (value === "ts" || value === "js") return value;
|
|
51
|
+
throw new Error(`${file}: \`language\` must be "ts" or "js".`);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** The config under `<cwd>/config`, or nothing when the app has none. */
|
|
55
|
+
export async function loadProjectConfig(cwd: string): Promise<ProjectConfig> {
|
|
56
|
+
for (const name of CANDIDATES) {
|
|
57
|
+
const file = join(cwd, "config", name);
|
|
58
|
+
if (!existsSync(file)) continue;
|
|
59
|
+
const label = `config/${name}`;
|
|
60
|
+
const loaded: unknown = await import(pathToFileURL(file).href);
|
|
61
|
+
const config = isRecord(loaded) ? loaded.default : undefined;
|
|
62
|
+
if (!isRecord(config)) {
|
|
63
|
+
throw new Error(`${label} must export its config as the default export.`);
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
paths: pathsOf(config.paths, label),
|
|
67
|
+
language: languageOf(config.language, label),
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
return {};
|
|
71
|
+
}
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
14
|
import { add } from "../cli/add.js";
|
|
15
|
+
import { loadProjectConfig } from "../cli/projectConfig.js";
|
|
15
16
|
import { argument, flag, type NebulaCommandClass } from "./contract.js";
|
|
16
17
|
|
|
17
18
|
export default class NebulaAddCommand {
|
|
@@ -70,12 +71,16 @@ export default class NebulaAddCommand {
|
|
|
70
71
|
return;
|
|
71
72
|
}
|
|
72
73
|
|
|
74
|
+
const cwd = process.cwd();
|
|
75
|
+
const config = await loadProjectConfig(cwd);
|
|
73
76
|
const result = add({
|
|
74
|
-
cwd
|
|
77
|
+
cwd,
|
|
75
78
|
names: this.components,
|
|
76
79
|
force: this.force,
|
|
77
80
|
dryRun: this.dryRun,
|
|
81
|
+
paths: config.paths,
|
|
78
82
|
language: this.ts ? "ts" : this.js ? "js" : undefined,
|
|
83
|
+
defaultLanguage: config.language,
|
|
79
84
|
});
|
|
80
85
|
|
|
81
86
|
const out: string[] = [""];
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import { type DiffState, diff } from "../cli/diff.js";
|
|
11
|
+
import { loadProjectConfig } from "../cli/projectConfig.js";
|
|
11
12
|
import { flag, type NebulaCommandClass } from "./contract.js";
|
|
12
13
|
|
|
13
14
|
/** What each state means, and what to do about it. */
|
|
@@ -54,9 +55,13 @@ export default class NebulaDiffCommand {
|
|
|
54
55
|
js = false;
|
|
55
56
|
|
|
56
57
|
async run(): Promise<void> {
|
|
58
|
+
const cwd = process.cwd();
|
|
59
|
+
const config = await loadProjectConfig(cwd);
|
|
57
60
|
const result = diff({
|
|
58
|
-
cwd
|
|
61
|
+
cwd,
|
|
62
|
+
paths: config.paths,
|
|
59
63
|
language: this.ts ? "ts" : this.js ? "js" : undefined,
|
|
64
|
+
defaultLanguage: config.language,
|
|
60
65
|
});
|
|
61
66
|
|
|
62
67
|
if (result.entries.length === 0) {
|
package/src/lib/icons.ts
CHANGED
|
@@ -133,6 +133,34 @@ export const GripVerticalIcon = (props?: IconProps): TemplateResult =>
|
|
|
133
133
|
props,
|
|
134
134
|
);
|
|
135
135
|
|
|
136
|
+
/** Lucide `circle-check` — shadcn's Sonner success icon. */
|
|
137
|
+
export const CircleCheckIcon = (props?: IconProps): TemplateResult =>
|
|
138
|
+
svg(
|
|
139
|
+
html`<circle cx="12" cy="12" r="10" /><path d="m16 9-5.5 5.5L8 12" />`,
|
|
140
|
+
props,
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
/** Lucide `info` — shadcn's Sonner info icon. */
|
|
144
|
+
export const InfoIcon = (props?: IconProps): TemplateResult =>
|
|
145
|
+
svg(
|
|
146
|
+
html`<circle cx="12" cy="12" r="10" /><path d="M12 16v-4" /><path d="M12 8h.01" />`,
|
|
147
|
+
props,
|
|
148
|
+
);
|
|
149
|
+
|
|
150
|
+
/** Lucide `triangle-alert` — shadcn's Sonner warning icon. */
|
|
151
|
+
export const TriangleAlertIcon = (props?: IconProps): TemplateResult =>
|
|
152
|
+
svg(
|
|
153
|
+
html`<path d="m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3" /><path d="M12 9v4" /><path d="M12 17h.01" />`,
|
|
154
|
+
props,
|
|
155
|
+
);
|
|
156
|
+
|
|
157
|
+
/** Lucide `octagon-x` — shadcn's Sonner error icon. */
|
|
158
|
+
export const OctagonXIcon = (props?: IconProps): TemplateResult =>
|
|
159
|
+
svg(
|
|
160
|
+
html`<path d="m15 9-6 6" /><path d="M2.586 16.726A2 2 0 0 1 2 15.312V8.688a2 2 0 0 1 .586-1.414l4.688-4.688A2 2 0 0 1 8.688 2h6.624a2 2 0 0 1 1.414.586l4.688 4.688A2 2 0 0 1 22 8.688v6.624a2 2 0 0 1-.586 1.414l-4.688 4.688a2 2 0 0 1-1.414.586H8.688a2 2 0 0 1-1.414-.586z" /><path d="m9 9 6 6" />`,
|
|
161
|
+
props,
|
|
162
|
+
);
|
|
163
|
+
|
|
136
164
|
/** The arc Lucide uses for `loader-circle`; spun by the Spinner's animation. */
|
|
137
165
|
export const LoaderIcon = (props?: IconProps): TemplateResult =>
|
|
138
166
|
svg(html`<path d="M21 12a9 9 0 1 1-6.219-8.56" />`, props);
|
package/src/lib/image.ts
CHANGED
|
@@ -351,6 +351,18 @@ export function setImageEndpoint(path: string): void {
|
|
|
351
351
|
endpoint = path;
|
|
352
352
|
}
|
|
353
353
|
|
|
354
|
+
/**
|
|
355
|
+
* A root-relative `src` as the path under the endpoint's public roots.
|
|
356
|
+
*
|
|
357
|
+
* `/photos/hero.png` is how a page names a public file, and the endpoint
|
|
358
|
+
* resolves `src` inside its roots, refusing an absolute path: sent as is,
|
|
359
|
+
* every variant is a 404. Exactly one slash goes, so a protocol-relative
|
|
360
|
+
* `//host/…` stays what it is and is left to an application's own resolver.
|
|
361
|
+
*/
|
|
362
|
+
function relativeToRoots(src: string): string {
|
|
363
|
+
return src.startsWith("/") && !src.startsWith("//") ? src.slice(1) : src;
|
|
364
|
+
}
|
|
365
|
+
|
|
354
366
|
/**
|
|
355
367
|
* The resolver used when an application installs none.
|
|
356
368
|
*
|
|
@@ -360,7 +372,7 @@ export function setImageEndpoint(path: string): void {
|
|
|
360
372
|
*/
|
|
361
373
|
export const defaultImageResolver: ImageUrlResolver = (src, transform) => {
|
|
362
374
|
const params = new URLSearchParams({
|
|
363
|
-
src,
|
|
375
|
+
src: relativeToRoots(src),
|
|
364
376
|
w: String(Math.round(transform.width)),
|
|
365
377
|
});
|
|
366
378
|
if (transform.format !== undefined) params.set("f", transform.format);
|
|
@@ -38,6 +38,7 @@ const slotClasses =
|
|
|
38
38
|
|
|
39
39
|
interface InputOTPApi {
|
|
40
40
|
readonly length: number;
|
|
41
|
+
readonly inputMode: "numeric" | "text";
|
|
41
42
|
readonly disabled: () => boolean;
|
|
42
43
|
readonly slotLabel: (position: number, length: number) => string;
|
|
43
44
|
/** Claim the next box's index, in the order the slots are built. */
|
|
@@ -49,9 +50,22 @@ interface InputOTPApi {
|
|
|
49
50
|
|
|
50
51
|
const InputOTPContext = createContext<InputOTPApi>("InputOTP");
|
|
51
52
|
|
|
53
|
+
/** input-otp's patterns, for the `pattern` prop. */
|
|
54
|
+
export const REGEXP_ONLY_DIGITS = "^\\d+$";
|
|
55
|
+
export const REGEXP_ONLY_CHARS = "^[a-zA-Z]+$";
|
|
56
|
+
export const REGEXP_ONLY_DIGITS_AND_CHARS = "^[a-zA-Z0-9]+$";
|
|
57
|
+
|
|
52
58
|
export interface InputOTPProps {
|
|
53
59
|
/** Number of boxes. Default `6` — and it must match the slots built. */
|
|
54
60
|
length?: number;
|
|
61
|
+
/**
|
|
62
|
+
* What the code may hold, tested against the whole value as input-otp
|
|
63
|
+
* does: a character or a fill that would not match is refused. None by
|
|
64
|
+
* default, as input-otp; `REGEXP_ONLY_DIGITS` for a numeric code.
|
|
65
|
+
*/
|
|
66
|
+
pattern?: RegExp | string;
|
|
67
|
+
/** The on-screen keyboard. Default `"numeric"`. */
|
|
68
|
+
inputMode?: "numeric" | "text";
|
|
55
69
|
/** Each box's accessible name from its position. Default `"Character 2 of 6"`. */
|
|
56
70
|
slotLabel?: (position: number, length: number) => string;
|
|
57
71
|
name?: string;
|
|
@@ -99,8 +113,47 @@ export const InputOTP = component<InputOTPProps>((props) => {
|
|
|
99
113
|
commit(next);
|
|
100
114
|
}
|
|
101
115
|
|
|
116
|
+
const pattern =
|
|
117
|
+
typeof props.pattern === "string"
|
|
118
|
+
? new RegExp(props.pattern)
|
|
119
|
+
: props.pattern;
|
|
120
|
+
|
|
121
|
+
function accepts(next: readonly string[]): boolean {
|
|
122
|
+
const joined = next.join("");
|
|
123
|
+
return pattern === undefined || joined === "" || pattern.test(joined);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** Put the boxes back to what the code holds. */
|
|
127
|
+
function reflect(): void {
|
|
128
|
+
const inputs = boxes();
|
|
129
|
+
characters().forEach((character, position) => {
|
|
130
|
+
const input = inputs[position];
|
|
131
|
+
if (input !== undefined) input.value = character;
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Share a run of characters out over the boxes from `index`: a paste, and
|
|
137
|
+
* a whole code an autofill or an IME put into one box.
|
|
138
|
+
*/
|
|
139
|
+
function spread(index: number, text: string): void {
|
|
140
|
+
const next = [...characters()];
|
|
141
|
+
let cursor = index;
|
|
142
|
+
for (const character of text) {
|
|
143
|
+
if (cursor >= length) break;
|
|
144
|
+
next[cursor] = character;
|
|
145
|
+
cursor += 1;
|
|
146
|
+
}
|
|
147
|
+
if (accepts(next)) commit(next);
|
|
148
|
+
// The boxes are uncontrolled between keystrokes, so writing the signal
|
|
149
|
+
// alone would leave the characters invisible — or a refused fill in place.
|
|
150
|
+
reflect();
|
|
151
|
+
focusBox(Math.min(cursor, length - 1));
|
|
152
|
+
}
|
|
153
|
+
|
|
102
154
|
provide<InputOTPApi>(InputOTPContext, {
|
|
103
155
|
length,
|
|
156
|
+
inputMode: props.inputMode ?? "numeric",
|
|
104
157
|
disabled: () => readOr(props.disabled, false),
|
|
105
158
|
slotLabel:
|
|
106
159
|
props.slotLabel ??
|
|
@@ -114,12 +167,31 @@ export const InputOTP = component<InputOTPProps>((props) => {
|
|
|
114
167
|
const target = event.target;
|
|
115
168
|
if (!(target instanceof HTMLInputElement)) return;
|
|
116
169
|
|
|
117
|
-
|
|
118
|
-
//
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
170
|
+
const value = target.value;
|
|
171
|
+
// One key pressed in a box already holding a character: the box holds
|
|
172
|
+
// both, and the one just typed is what counts.
|
|
173
|
+
const typed =
|
|
174
|
+
event instanceof InputEvent &&
|
|
175
|
+
event.inputType === "insertText" &&
|
|
176
|
+
event.data !== null &&
|
|
177
|
+
[...event.data].length === 1
|
|
178
|
+
? event.data
|
|
179
|
+
: undefined;
|
|
180
|
+
if ([...value].length > 1 && typed === undefined) {
|
|
181
|
+
// A whole code at once: autofill, a password manager, an IME.
|
|
182
|
+
spread(index, value);
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
const character = typed ?? value;
|
|
186
|
+
const next = [...characters()];
|
|
187
|
+
next[index] = character;
|
|
188
|
+
if (!accepts(next)) {
|
|
189
|
+
target.value = characters()[index] ?? "";
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
target.value = character;
|
|
193
|
+
commit(next);
|
|
194
|
+
if (character !== "" && index < length - 1) focusBox(index + 1);
|
|
123
195
|
},
|
|
124
196
|
onKeyDown(index, event) {
|
|
125
197
|
if (event.key === "Backspace") {
|
|
@@ -144,25 +216,7 @@ export const InputOTP = component<InputOTPProps>((props) => {
|
|
|
144
216
|
const pasted = event.clipboardData?.getData("text") ?? "";
|
|
145
217
|
if (pasted === "") return;
|
|
146
218
|
event.preventDefault();
|
|
147
|
-
|
|
148
|
-
const next = [...characters()];
|
|
149
|
-
let cursor = index;
|
|
150
|
-
for (const character of pasted) {
|
|
151
|
-
if (cursor >= length) break;
|
|
152
|
-
next[cursor] = character;
|
|
153
|
-
cursor += 1;
|
|
154
|
-
}
|
|
155
|
-
commit(next);
|
|
156
|
-
|
|
157
|
-
// Reflect into the DOM: the boxes are uncontrolled between keystrokes,
|
|
158
|
-
// so writing the signal alone would leave the pasted characters
|
|
159
|
-
// invisible.
|
|
160
|
-
const inputs = boxes();
|
|
161
|
-
next.forEach((character, position) => {
|
|
162
|
-
const input = inputs[position];
|
|
163
|
-
if (input !== undefined) input.value = character;
|
|
164
|
-
});
|
|
165
|
-
focusBox(Math.min(cursor, length - 1));
|
|
219
|
+
spread(index, pasted);
|
|
166
220
|
},
|
|
167
221
|
});
|
|
168
222
|
|
|
@@ -209,9 +263,9 @@ export const InputOTPSlot = component<InputOTPSlotProps>((props) => {
|
|
|
209
263
|
data-slot="input-otp-slot"
|
|
210
264
|
data-otp-index="${index}"
|
|
211
265
|
type="text"
|
|
212
|
-
inputmode="
|
|
266
|
+
inputmode="${otp.inputMode}"
|
|
213
267
|
autocomplete="${index === 0 ? "one-time-code" : "off"}"
|
|
214
|
-
maxlength="
|
|
268
|
+
maxlength="${otp.length}"
|
|
215
269
|
aria-label="${otp.slotLabel(index + 1, otp.length)}"
|
|
216
270
|
?disabled="${() => otp.disabled()}"
|
|
217
271
|
class="${() => cn(slotClasses, read(props.class))}"
|
package/src/molecules/index.ts
CHANGED
|
@@ -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
|
});
|
package/src/organisms/Form.ts
CHANGED
|
@@ -77,6 +77,17 @@ export function bind<T, K extends keyof T & string>(
|
|
|
77
77
|
|
|
78
78
|
export interface FormProps<T> {
|
|
79
79
|
form: AuroraForm<T>;
|
|
80
|
+
/**
|
|
81
|
+
* How the browser submits it before the page is hydrated, or when a
|
|
82
|
+
* script fails to load. Default `"post"`.
|
|
83
|
+
*/
|
|
84
|
+
method?: "post" | "get" | "dialog";
|
|
85
|
+
/** Where that submission goes. Left out, it goes to the current page. */
|
|
86
|
+
action?: string;
|
|
87
|
+
enctype?:
|
|
88
|
+
| "application/x-www-form-urlencoded"
|
|
89
|
+
| "multipart/form-data"
|
|
90
|
+
| "text/plain";
|
|
80
91
|
children?: Slot;
|
|
81
92
|
class?: Reactive<string>;
|
|
82
93
|
}
|
|
@@ -88,11 +99,21 @@ export interface FormProps<T> {
|
|
|
88
99
|
* styled, appear one at a time, and vanish on scroll — and they would fire
|
|
89
100
|
* before the controller's validation ever runs, so the user would see two
|
|
90
101
|
* different error presentations for the same field.
|
|
102
|
+
*
|
|
103
|
+
* NAMED DEVIATION: `method="post"` unless told otherwise. shadcn's `Form`
|
|
104
|
+
* renders no `<form>`, so the app writes its own method; this one owns the
|
|
105
|
+
* element, and the server renders it. Pressed before hydration, a form with
|
|
106
|
+
* no method is a GET, and every named field — a password included — lands in
|
|
107
|
+
* the URL, the history and the access logs. An app with CSRF protection puts
|
|
108
|
+
* its token field among the children, so that early POST is accepted.
|
|
91
109
|
*/
|
|
92
110
|
export function Form<T>(props: FormProps<T>): ReturnType<typeof html> {
|
|
93
111
|
return html`<form
|
|
94
112
|
data-slot="form"
|
|
95
113
|
novalidate
|
|
114
|
+
method="${props.method ?? "post"}"
|
|
115
|
+
action="${props.action}"
|
|
116
|
+
enctype="${props.enctype}"
|
|
96
117
|
class="${() => cn("flex flex-col gap-6", read(props.class))}"
|
|
97
118
|
@submit="${(event: Event) => {
|
|
98
119
|
// A DOM listener returns nothing, so this promise is nobody's to
|
package/src/organisms/Select.ts
CHANGED
|
@@ -424,10 +424,10 @@ export const Select = component<SelectProps>((props) => {
|
|
|
424
424
|
});
|
|
425
425
|
|
|
426
426
|
/**
|
|
427
|
-
* `id`, `label` and `describedBy
|
|
428
|
-
* button prop, and these are the ones that name it — a
|
|
429
|
-
* `for` at the `id`, and a `<label for>` names a
|
|
430
|
-
* combobox's only name was the value it showed.
|
|
427
|
+
* `id`, `label`, `labelledBy` and `describedBy`, as on `Combobox`: upstream's
|
|
428
|
+
* trigger takes every button prop, and these are the ones that name it — a
|
|
429
|
+
* `FieldLabel` points its `for` at the `id`, and a `<label for>` names a
|
|
430
|
+
* `<button>`. Without them the combobox's only name was the value it showed.
|
|
431
431
|
*/
|
|
432
432
|
export interface SelectTriggerProps {
|
|
433
433
|
children?: Slot;
|
|
@@ -435,6 +435,8 @@ export interface SelectTriggerProps {
|
|
|
435
435
|
id?: string;
|
|
436
436
|
/** Accessible name (`aria-label`), for a select no `<label>` names. */
|
|
437
437
|
label?: Reactive<string | undefined>;
|
|
438
|
+
/** Id(s) of the element(s) that name it (`aria-labelledby`). */
|
|
439
|
+
labelledBy?: Reactive<string | undefined>;
|
|
438
440
|
describedBy?: Reactive<string | undefined>;
|
|
439
441
|
class?: Reactive<string>;
|
|
440
442
|
}
|
|
@@ -446,6 +448,7 @@ export const SelectTrigger = component<SelectTriggerProps>((props) => {
|
|
|
446
448
|
data-slot="select-trigger"
|
|
447
449
|
id="${select.claimTriggerId(props.id)}"
|
|
448
450
|
aria-label="${accessor(props.label, undefined)}"
|
|
451
|
+
aria-labelledby="${accessor(props.labelledBy, undefined)}"
|
|
449
452
|
aria-describedby="${accessor(props.describedBy, undefined)}"
|
|
450
453
|
role="combobox"
|
|
451
454
|
aria-haspopup="listbox"
|