@sdxc/kit 0.0.0-pre.1 → 2026.10.16
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/changelog.jsonl +1040 -0
- package/dist/make/declare.js +13 -13
- package/dist/make/generate.d.ts +6 -0
- package/dist/make/generate.js +22 -7
- package/dist/make/imports.js +2 -1
- package/dist/make/migrations.d.ts +26 -6
- package/dist/make/migrations.js +84 -16
- package/dist/releases.js +1 -1
- package/dist/testing.d.ts +4 -1
- package/dist/testing.js +5 -2
- package/dist/upgrade/prompt.js +1 -1
- package/package.json +8 -8
- package/registry/ui/accordion.json +15 -0
- package/registry/ui/alert-dialog.json +20 -0
- package/registry/ui/alert.json +15 -0
- package/registry/ui/aspect-ratio.json +13 -0
- package/registry/ui/attachment.json +15 -0
- package/registry/ui/avatar.json +15 -0
- package/registry/ui/badge.json +13 -0
- package/registry/ui/breadcrumbs.json +15 -0
- package/registry/ui/bubble.json +13 -0
- package/registry/ui/button.json +16 -0
- package/registry/ui/calendar.json +16 -0
- package/registry/ui/card.json +18 -0
- package/registry/ui/carousel.json +15 -0
- package/registry/ui/chart.json +13 -0
- package/registry/ui/checkbox-group.json +13 -0
- package/registry/ui/checkbox.json +16 -0
- package/registry/ui/color-area.json +13 -0
- package/registry/ui/color-field.json +20 -0
- package/registry/ui/color-picker.json +17 -0
- package/registry/ui/color-slider.json +13 -0
- package/registry/ui/color-swatch-picker.json +15 -0
- package/registry/ui/color-swatch.json +13 -0
- package/registry/ui/color-wheel.json +13 -0
- package/registry/ui/combobox.json +15 -0
- package/registry/ui/command.json +13 -0
- package/registry/ui/confirm.json +19 -0
- package/registry/ui/context-menu.json +16 -0
- package/registry/ui/date-field.json +19 -0
- package/registry/ui/date-picker.json +15 -0
- package/registry/ui/date-range-picker.json +16 -0
- package/registry/ui/description.json +13 -0
- package/registry/ui/dialog.json +19 -0
- package/registry/ui/disclosure.json +18 -0
- package/registry/ui/drawer.json +18 -0
- package/registry/ui/drop-indicator.json +13 -0
- package/registry/ui/drop-zone.json +13 -0
- package/registry/ui/empty.json +15 -0
- package/registry/ui/field-error.json +13 -0
- package/registry/ui/file-trigger.json +13 -0
- package/registry/ui/form.json +21 -0
- package/registry/ui/grid-list.json +18 -0
- package/registry/ui/group.json +13 -0
- package/registry/ui/header.json +13 -0
- package/registry/ui/heading-scope.json +20 -0
- package/registry/ui/heading.json +15 -0
- package/registry/ui/highlight.json +16 -0
- package/registry/ui/hover-card.json +13 -0
- package/registry/ui/image-placeholder.json +16 -0
- package/registry/ui/input.json +13 -0
- package/registry/ui/item.json +13 -0
- package/registry/ui/keyboard.json +13 -0
- package/registry/ui/label.json +13 -0
- package/registry/ui/link-button.json +16 -0
- package/registry/ui/link.json +13 -0
- package/registry/ui/listbox.json +15 -0
- package/registry/ui/logo.json +15 -0
- package/registry/ui/marker.json +13 -0
- package/registry/ui/menu.json +19 -0
- package/registry/ui/menubar.json +13 -0
- package/registry/ui/message-scroller.json +16 -0
- package/registry/ui/message.json +13 -0
- package/registry/ui/meter.json +13 -0
- package/registry/ui/modal.json +15 -0
- package/registry/ui/nav-link.json +13 -0
- package/registry/ui/navigation-menu.json +15 -0
- package/registry/ui/number-field.json +15 -0
- package/registry/ui/otp-field.json +15 -0
- package/registry/ui/overlay-arrow.json +13 -0
- package/registry/ui/pagination.json +16 -0
- package/registry/ui/popover.json +13 -0
- package/registry/ui/progress-bar.json +13 -0
- package/registry/ui/radio-group.json +13 -0
- package/registry/ui/range-calendar.json +16 -0
- package/registry/ui/resizable.json +13 -0
- package/registry/ui/scroll-area.json +13 -0
- package/registry/ui/search-field.json +16 -0
- package/registry/ui/section.json +13 -0
- package/registry/ui/select.json +13 -0
- package/registry/ui/selection-indicator.json +13 -0
- package/registry/ui/sentinel-row.json +16 -0
- package/registry/ui/separator.json +13 -0
- package/registry/ui/shared-element.json +13 -0
- package/registry/ui/sheet.json +15 -0
- package/registry/ui/shortcut-list.json +18 -0
- package/registry/ui/sidebar.json +20 -0
- package/registry/ui/skeleton.json +13 -0
- package/registry/ui/slider.json +16 -0
- package/registry/ui/spinner.json +13 -0
- package/registry/ui/switch.json +16 -0
- package/registry/ui/table.json +16 -0
- package/registry/ui/tabs.json +17 -0
- package/registry/ui/tag-group.json +18 -0
- package/registry/ui/text-field.json +19 -0
- package/registry/ui/text.json +13 -0
- package/registry/ui/textarea.json +13 -0
- package/registry/ui/time-field.json +19 -0
- package/registry/ui/toast.json +16 -0
- package/registry/ui/toggle-button.json +17 -0
- package/registry/ui/toolbar.json +13 -0
- package/registry/ui/tooltip.json +16 -0
- package/registry/ui/tree.json +18 -0
- package/registry/ui/typeset.json +16 -0
- package/registry/ui/youtube-embed.json +16 -0
package/dist/make/declare.js
CHANGED
|
@@ -12,7 +12,7 @@ import { readdir, readFile } from "node:fs/promises";
|
|
|
12
12
|
import { dirname, join, posix } from "node:path";
|
|
13
13
|
import { addProperty, findModuleReferences, insertAfterLast } from "@sdxc/codemod";
|
|
14
14
|
import { failure, isFailure, isSuccess, success, wrap } from "@sdxc/result";
|
|
15
|
-
import { memberAccess } from "./generate.js";
|
|
15
|
+
import { literal, memberAccess } from "./generate.js";
|
|
16
16
|
import { ensureImport, resolvesTo, specifierFor } from "./imports.js";
|
|
17
17
|
import { camel } from "./names.js";
|
|
18
18
|
/** The `remix/routes` helper each `--method` declares with; `form` adds a page and an action. */
|
|
@@ -51,10 +51,10 @@ async function declareJob(request, root) {
|
|
|
51
51
|
let groups = initializer === null ? null : reusedGroup(initializer, instance, local, name);
|
|
52
52
|
let path = [...(groups ?? name.segments.slice(0, -1).map(camel)), name.key];
|
|
53
53
|
let value = request.variant === "cron"
|
|
54
|
-
? `job({ cron: ${
|
|
54
|
+
? `job({ cron: ${literal(request.cron ?? "")} })`
|
|
55
55
|
: "job({ input: s.object({}) })";
|
|
56
56
|
let handler = initializer === null ? `~/${request.handler}` : handlerSpecifier(initializer, request.handler);
|
|
57
|
-
let statement = `${instance}.map(${local}.${path.join(".")}, () => import(${
|
|
57
|
+
let statement = `${instance}.map(${local}.${path.join(".")}, () => import(${literal(handler)}));`;
|
|
58
58
|
let manual = (reason) => ({
|
|
59
59
|
kind: "manual",
|
|
60
60
|
path: path.join("."),
|
|
@@ -113,10 +113,10 @@ async function declareController(request, root) {
|
|
|
113
113
|
let path = [...name.segments.slice(0, -1).map(camel), name.key];
|
|
114
114
|
let helper = ROUTE_HELPERS[request.method] ?? "get";
|
|
115
115
|
let pattern = request.pattern ?? `/${name.segments.join("/")}`;
|
|
116
|
-
let value = `${helper}(${
|
|
116
|
+
let value = `${helper}(${literal(pattern)})`;
|
|
117
117
|
let handler = initializer === null ? `~/${request.handler}` : handlerSpecifier(initializer, request.handler);
|
|
118
118
|
let lazyLocal = "lazy";
|
|
119
|
-
let statement = (lazy) => `${instance}.map(${local}.${path.join(".")}, ${lazy}(() => import(${
|
|
119
|
+
let statement = (lazy) => `${instance}.map(${local}.${path.join(".")}, ${lazy}(() => import(${literal(handler)})));`;
|
|
120
120
|
let manual = (reason) => ({
|
|
121
121
|
kind: "manual",
|
|
122
122
|
path: path.join("."),
|
|
@@ -133,7 +133,7 @@ async function declareController(request, root) {
|
|
|
133
133
|
let imported = ensureImport(contract, file.data.source, { kind: "named", name: helper }, (specifier) => specifier === "remix/routes", "remix/routes", helper);
|
|
134
134
|
if (isFailure(imported))
|
|
135
135
|
return manual(imported.error.message);
|
|
136
|
-
value = `${imported.data.local}(${
|
|
136
|
+
value = `${imported.data.local}(${literal(pattern)})`;
|
|
137
137
|
let added = addProperty(contract, imported.data.source, {
|
|
138
138
|
call: "route",
|
|
139
139
|
path: path.slice(0, -1),
|
|
@@ -173,13 +173,13 @@ async function declareMcp(request, root) {
|
|
|
173
173
|
let path = [...name.segments.slice(0, -1).map(camel), name.key];
|
|
174
174
|
let builder = resource ? "resource" : "tool";
|
|
175
175
|
let body = resource
|
|
176
|
-
? [`name: ${
|
|
177
|
-
: [`description: ${
|
|
176
|
+
? [`name: ${literal(request.title)},`, 'mimeType: "text/markdown",']
|
|
177
|
+
: [`description: ${literal(`${request.title}.`)},`, "input: s.object({}),"];
|
|
178
178
|
let first = resource ? request.uri : request.tool;
|
|
179
|
-
let valueWith = (callee, lines) => `${callee}(${
|
|
179
|
+
let valueWith = (callee, lines) => `${callee}(${literal(first)}, {\n${lines.map((line) => `\t${line}`).join("\n")}\n})`;
|
|
180
180
|
let value = valueWith(builder, body);
|
|
181
181
|
let handler = initializer === null ? `~/${request.handler}` : handlerSpecifier(initializer, request.handler);
|
|
182
|
-
let statement = (lazy) => `${instance}.${group}.map(${local}.${path.join(".")}, ${lazy}(() => import(${
|
|
182
|
+
let statement = (lazy) => `${instance}.${group}.map(${local}.${path.join(".")}, ${lazy}(() => import(${literal(handler)})));`;
|
|
183
183
|
let manual = (reason) => ({
|
|
184
184
|
kind: "manual",
|
|
185
185
|
path: path.join("."),
|
|
@@ -248,9 +248,9 @@ async function declareCommand(request, root) {
|
|
|
248
248
|
let initializer = await findInitializer(root, module, "createCLI");
|
|
249
249
|
let instance = initializer === null ? "cli" : instanceOf(initializer, "createCLI");
|
|
250
250
|
let local = initializer === null ? "commandset" : (defaultLocal(initializer, module) ?? "commandset");
|
|
251
|
-
let description =
|
|
251
|
+
let description = literal(request.title);
|
|
252
252
|
let handler = initializer === null ? `~/${request.handler}` : handlerSpecifier(initializer, request.handler);
|
|
253
|
-
let statement = (lazy) => `${instance}.map(${local}${memberAccess(segments)}, ${lazy}(() => import(${
|
|
253
|
+
let statement = (lazy) => `${instance}.map(${local}${memberAccess(segments)}, ${lazy}(() => import(${literal(handler)})));`;
|
|
254
254
|
let manual = (reason) => ({
|
|
255
255
|
kind: "manual",
|
|
256
256
|
path: segments.join("."),
|
|
@@ -337,7 +337,7 @@ function groupValue(call, levels, entry) {
|
|
|
337
337
|
}
|
|
338
338
|
/** A command's key as an identifier when it is one, quoted otherwise. */
|
|
339
339
|
function keyText(key) {
|
|
340
|
-
return /^[A-Za-z_$][\w$]*$/.test(key) ? key :
|
|
340
|
+
return /^[A-Za-z_$][\w$]*$/.test(key) ? key : literal(key);
|
|
341
341
|
}
|
|
342
342
|
/** Every line of `text` indented by one tab. */
|
|
343
343
|
function indentTab(text) {
|
package/dist/make/generate.d.ts
CHANGED
|
@@ -43,6 +43,12 @@ export interface Plan {
|
|
|
43
43
|
export declare function plan(request: MakeRequest, root: string, config: Config, packageRoot: string, overrides?: Readonly<Record<string, string>>): Promise<Result<Plan, Error>>;
|
|
44
44
|
/** The folder a kind's files go in; a migration's comes from its chain instead. */
|
|
45
45
|
export declare function folderOf(kind: KindName, variant: string | null): string;
|
|
46
|
+
/**
|
|
47
|
+
* `value` as a JavaScript string literal that is safe to splice into generated source: quotes,
|
|
48
|
+
* backslashes and control characters are escaped, and so are `<`, `>` and the two Unicode line
|
|
49
|
+
* separators, so a name or path can never close a script element or break the line it sits on.
|
|
50
|
+
*/
|
|
51
|
+
export declare function literal(value: string): string;
|
|
46
52
|
/**
|
|
47
53
|
* The property access that reaches a command's declaration from its contract: `.users.grant`,
|
|
48
54
|
* with a segment that is no identifier read by its quoted key (`["send-digest"]`), since a
|
package/dist/make/generate.js
CHANGED
|
@@ -10,7 +10,7 @@ import { readFile, stat } from "node:fs/promises";
|
|
|
10
10
|
import { join } from "node:path";
|
|
11
11
|
import { failure, isFailure, isSuccess, success, wrap } from "@sdxc/result";
|
|
12
12
|
import { COMMON_PLACEHOLDERS, KINDS, MCP_RESOURCES_FOLDER } from "./kinds.js";
|
|
13
|
-
import { chainFolder,
|
|
13
|
+
import { chainFolder, nextMigrationFile } from "./migrations.js";
|
|
14
14
|
import { camel } from "./names.js";
|
|
15
15
|
import { loadStub, renderStub, stubName } from "./stubs.js";
|
|
16
16
|
/**
|
|
@@ -33,10 +33,10 @@ export async function plan(request, root, config, packageRoot, overrides = {}) {
|
|
|
33
33
|
if (isFailure(chain))
|
|
34
34
|
return chain;
|
|
35
35
|
folder = chain.data;
|
|
36
|
-
let
|
|
37
|
-
if (isFailure(
|
|
38
|
-
return
|
|
39
|
-
file =
|
|
36
|
+
let next = await nextMigrationFile(root, folder, name);
|
|
37
|
+
if (isFailure(next))
|
|
38
|
+
return next;
|
|
39
|
+
file = next.data;
|
|
40
40
|
}
|
|
41
41
|
let path = `${folder}/${file}${kind.extension}`;
|
|
42
42
|
let testPath = `${folder}/${file}.test${kind.extension}`;
|
|
@@ -102,7 +102,7 @@ async function placeholders(request, root, file) {
|
|
|
102
102
|
model: `~/app/models/${name.segments.join("/")}`,
|
|
103
103
|
command: name.segments.join(" "),
|
|
104
104
|
member: memberAccess(name.segments),
|
|
105
|
-
words: name.segments.map((segment) =>
|
|
105
|
+
words: name.segments.map((segment) => literal(segment)).join(", "),
|
|
106
106
|
};
|
|
107
107
|
let values = {};
|
|
108
108
|
for (let key of [...COMMON_PLACEHOLDERS, ...KINDS[request.kind].placeholders]) {
|
|
@@ -112,6 +112,21 @@ async function placeholders(request, root, file) {
|
|
|
112
112
|
}
|
|
113
113
|
return values;
|
|
114
114
|
}
|
|
115
|
+
/** Each character that ends a `<script>` element or a line inside an otherwise valid literal. */
|
|
116
|
+
const UNSAFE_LITERAL_CHARACTERS = {
|
|
117
|
+
"<": "\\u003C",
|
|
118
|
+
">": "\\u003E",
|
|
119
|
+
"\u2028": "\\u2028",
|
|
120
|
+
"\u2029": "\\u2029",
|
|
121
|
+
};
|
|
122
|
+
/**
|
|
123
|
+
* `value` as a JavaScript string literal that is safe to splice into generated source: quotes,
|
|
124
|
+
* backslashes and control characters are escaped, and so are `<`, `>` and the two Unicode line
|
|
125
|
+
* separators, so a name or path can never close a script element or break the line it sits on.
|
|
126
|
+
*/
|
|
127
|
+
export function literal(value) {
|
|
128
|
+
return JSON.stringify(value).replace(/[<>\u2028\u2029]/g, (character) => UNSAFE_LITERAL_CHARACTERS[character] ?? character);
|
|
129
|
+
}
|
|
115
130
|
/**
|
|
116
131
|
* The property access that reaches a command's declaration from its contract: `.users.grant`,
|
|
117
132
|
* with a segment that is no identifier read by its quoted key (`["send-digest"]`), since a
|
|
@@ -119,7 +134,7 @@ async function placeholders(request, root, file) {
|
|
|
119
134
|
*/
|
|
120
135
|
export function memberAccess(segments) {
|
|
121
136
|
return segments
|
|
122
|
-
.map((segment) => /^[A-Za-z_$][\w$]*$/.test(segment) ? `.${segment}` : `[${
|
|
137
|
+
.map((segment) => /^[A-Za-z_$][\w$]*$/.test(segment) ? `.${segment}` : `[${literal(segment)}]`)
|
|
123
138
|
.join("");
|
|
124
139
|
}
|
|
125
140
|
/**
|
package/dist/make/imports.js
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
import { dirname, posix } from "node:path";
|
|
11
11
|
import { findModuleReferences } from "@sdxc/codemod";
|
|
12
12
|
import { isFailure, success } from "@sdxc/result";
|
|
13
|
+
import { literal } from "./generate.js";
|
|
13
14
|
/**
|
|
14
15
|
* `source` importing `what` from a module `matches` accepts, as a value. An existing import is
|
|
15
16
|
* reused under its local name; otherwise `import … from "<specifier>"` is added as `preferred`
|
|
@@ -43,7 +44,7 @@ export function ensureImport(filename, source, what, matches, specifier, preferr
|
|
|
43
44
|
? preferred
|
|
44
45
|
: `{ ${what.name} }`;
|
|
45
46
|
let local = what.kind === "named" ? what.name : preferred;
|
|
46
|
-
let statement = `import ${clause} from ${
|
|
47
|
+
let statement = `import ${clause} from ${literal(specifier)};`;
|
|
47
48
|
return success({ source: insertImport(source, references.data, statement), local });
|
|
48
49
|
}
|
|
49
50
|
/** Whether a bound import name is the kind of binding `what` asks for. */
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Migration chains: each configured chain is a folder of numbered SQL files applied in order
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* Migration chains: each configured chain is a folder of numbered SQL files applied in order of
|
|
3
|
+
* their leading number. A new migration sorts after every file in its chain's folder and is
|
|
4
|
+
* spelled like them, so a chain keeps one naming convention whichever tool wrote each file.
|
|
5
5
|
*
|
|
6
6
|
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
7
|
* @copyright Sergio Xalambrí 2026
|
|
8
8
|
*/
|
|
9
9
|
import type { Result } from "@sdxc/result";
|
|
10
|
+
import type { Name } from "./names.js";
|
|
10
11
|
/** The chain `make migration` writes into without `--chain`. */
|
|
11
12
|
export declare const DEFAULT_CHAIN = "default";
|
|
12
13
|
/**
|
|
@@ -15,7 +16,26 @@ export declare const DEFAULT_CHAIN = "default";
|
|
|
15
16
|
*/
|
|
16
17
|
export declare function chainFolder(chains: Readonly<Record<string, string>>, chain: string | undefined): Result<string, Error>;
|
|
17
18
|
/**
|
|
18
|
-
*
|
|
19
|
-
*
|
|
19
|
+
* How a chain spells its file names. `timestamp` numbers a file with the UTC time it was
|
|
20
|
+
* written (`YYYYMMDDHHmmss`); `sequence` counts up, zero-padded to `width`.
|
|
20
21
|
*/
|
|
21
|
-
export
|
|
22
|
+
export interface MigrationConvention {
|
|
23
|
+
numbering: "sequence" | "timestamp";
|
|
24
|
+
width: number;
|
|
25
|
+
separator: "-" | "_";
|
|
26
|
+
case: "kebab" | "snake" | "pascal" | "camel";
|
|
27
|
+
}
|
|
28
|
+
/** The convention of an empty chain: `0001_CreatePosts.sql`. */
|
|
29
|
+
export declare const DEFAULT_CONVENTION: MigrationConvention;
|
|
30
|
+
/**
|
|
31
|
+
* The convention of the SQL files in `files`, read from the newest file first: a chain that
|
|
32
|
+
* changed its spelling keeps its latest one. A name of one lowercase word takes its case from
|
|
33
|
+
* an older file, or from its separator when none tells; an empty chain takes the default.
|
|
34
|
+
*/
|
|
35
|
+
export declare function inferConvention(files: readonly string[]): MigrationConvention;
|
|
36
|
+
/**
|
|
37
|
+
* The base name, without `.sql`, of the next migration in `folder` named `name`, following the
|
|
38
|
+
* folder's convention. A sequence takes one after the highest number; a timestamp takes `now`,
|
|
39
|
+
* or one past the highest when the clock reads earlier, so the file always applies last.
|
|
40
|
+
*/
|
|
41
|
+
export declare function nextMigrationFile(root: string, folder: string, name: Name, now?: Date): Promise<Result<string, Error>>;
|
package/dist/make/migrations.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Migration chains: each configured chain is a folder of numbered SQL files applied in order
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* Migration chains: each configured chain is a folder of numbered SQL files applied in order of
|
|
3
|
+
* their leading number. A new migration sorts after every file in its chain's folder and is
|
|
4
|
+
* spelled like them, so a chain keeps one naming convention whichever tool wrote each file.
|
|
5
5
|
*
|
|
6
6
|
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
7
|
* @copyright Sergio Xalambrí 2026
|
|
@@ -11,8 +11,6 @@ import { join } from "node:path";
|
|
|
11
11
|
import { failure, isFailure, success, wrap } from "@sdxc/result";
|
|
12
12
|
/** The chain `make migration` writes into without `--chain`. */
|
|
13
13
|
export const DEFAULT_CHAIN = "default";
|
|
14
|
-
/** How many digits a migration number is padded to. */
|
|
15
|
-
const NUMBER_WIDTH = 4;
|
|
16
14
|
/**
|
|
17
15
|
* The folder of `chain` among the configured `chains`. An unknown chain is a failure listing
|
|
18
16
|
* the configured ones.
|
|
@@ -26,23 +24,93 @@ export function chainFolder(chains, chain) {
|
|
|
26
24
|
}
|
|
27
25
|
return success(folder);
|
|
28
26
|
}
|
|
27
|
+
/** The convention of an empty chain: `0001_CreatePosts.sql`. */
|
|
28
|
+
export const DEFAULT_CONVENTION = {
|
|
29
|
+
numbering: "sequence",
|
|
30
|
+
width: 4,
|
|
31
|
+
separator: "_",
|
|
32
|
+
case: "pascal",
|
|
33
|
+
};
|
|
34
|
+
/** A 14-digit leading number is a `YYYYMMDDHHmmss` timestamp. */
|
|
35
|
+
const TIMESTAMP_WIDTH = 14;
|
|
36
|
+
/** The shape of each case; a single lowercase word stays undecided, fitting kebab and snake alike. */
|
|
37
|
+
const CASE_PATTERNS = [
|
|
38
|
+
["kebab", /^[a-z0-9]+(-[a-z0-9]+)+$/],
|
|
39
|
+
["snake", /^[a-z0-9]+(_[a-z0-9]+)+$/],
|
|
40
|
+
["pascal", /^[A-Z][A-Za-z0-9]*$/],
|
|
41
|
+
["camel", /^[a-z][a-z0-9]*[A-Z][A-Za-z0-9]*$/],
|
|
42
|
+
];
|
|
29
43
|
/**
|
|
30
|
-
* The
|
|
31
|
-
*
|
|
44
|
+
* The convention of the SQL files in `files`, read from the newest file first: a chain that
|
|
45
|
+
* changed its spelling keeps its latest one. A name of one lowercase word takes its case from
|
|
46
|
+
* an older file, or from its separator when none tells; an empty chain takes the default.
|
|
32
47
|
*/
|
|
33
|
-
export
|
|
48
|
+
export function inferConvention(files) {
|
|
49
|
+
let parsed = files
|
|
50
|
+
.map(parseMigrationFile)
|
|
51
|
+
.filter((file) => file !== null)
|
|
52
|
+
.sort(compareNumbers)
|
|
53
|
+
.reverse();
|
|
54
|
+
let [newest] = parsed;
|
|
55
|
+
if (newest === undefined)
|
|
56
|
+
return DEFAULT_CONVENTION;
|
|
57
|
+
let width = newest.number.length;
|
|
58
|
+
let found = parsed
|
|
59
|
+
.map((file) => CASE_PATTERNS.find(([, pattern]) => pattern.test(file.name))?.[0])
|
|
60
|
+
.find((name) => name !== undefined);
|
|
61
|
+
return {
|
|
62
|
+
numbering: width === TIMESTAMP_WIDTH ? "timestamp" : "sequence",
|
|
63
|
+
width,
|
|
64
|
+
separator: newest.separator,
|
|
65
|
+
case: found ?? (newest.separator === "-" ? "kebab" : "snake"),
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* The base name, without `.sql`, of the next migration in `folder` named `name`, following the
|
|
70
|
+
* folder's convention. A sequence takes one after the highest number; a timestamp takes `now`,
|
|
71
|
+
* or one past the highest when the clock reads earlier, so the file always applies last.
|
|
72
|
+
*/
|
|
73
|
+
export async function nextMigrationFile(root, folder, name, now = new Date()) {
|
|
34
74
|
let entries = await wrap(() => readdir(join(root, folder)));
|
|
35
75
|
if (isFailure(entries)) {
|
|
36
76
|
let code = entries.error.code;
|
|
37
77
|
if (code !== "ENOENT")
|
|
38
78
|
return entries;
|
|
39
79
|
}
|
|
40
|
-
let
|
|
41
|
-
let
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
80
|
+
let files = isFailure(entries) ? [] : entries.data;
|
|
81
|
+
let convention = inferConvention(files);
|
|
82
|
+
let highest = files
|
|
83
|
+
.map(parseMigrationFile)
|
|
84
|
+
.reduce((max, file) => (file === null ? max : Math.max(max, Number(file.number))), 0);
|
|
85
|
+
let number = highest + 1;
|
|
86
|
+
if (convention.numbering === "timestamp")
|
|
87
|
+
number = Math.max(Number(timestamp(now)), number);
|
|
88
|
+
let digits = String(number).padStart(convention.width, "0");
|
|
89
|
+
return success(`${digits}${convention.separator}${spell(name, convention.case)}`);
|
|
90
|
+
}
|
|
91
|
+
/** `file` split into its parts, or `null` for anything but a numbered SQL file. */
|
|
92
|
+
function parseMigrationFile(file) {
|
|
93
|
+
let match = /^(\d+)([-_])(.+)\.sql$/.exec(file);
|
|
94
|
+
if (match === null)
|
|
95
|
+
return null;
|
|
96
|
+
let [, number = "", separator, name = ""] = match;
|
|
97
|
+
return { number, separator: separator === "-" ? "-" : "_", name };
|
|
98
|
+
}
|
|
99
|
+
/** Orders files by their leading number, as the migration runners apply them. */
|
|
100
|
+
function compareNumbers(a, b) {
|
|
101
|
+
return Number(a.number) - Number(b.number);
|
|
102
|
+
}
|
|
103
|
+
/** `date` in UTC as `YYYYMMDDHHmmss`. */
|
|
104
|
+
function timestamp(date) {
|
|
105
|
+
return date.toISOString().replace(/\D/g, "").slice(0, TIMESTAMP_WIDTH);
|
|
106
|
+
}
|
|
107
|
+
/** `name` in the given case. */
|
|
108
|
+
function spell(name, spelling) {
|
|
109
|
+
if (spelling === "kebab")
|
|
110
|
+
return name.base;
|
|
111
|
+
if (spelling === "snake")
|
|
112
|
+
return name.snake;
|
|
113
|
+
if (spelling === "camel")
|
|
114
|
+
return name.key;
|
|
115
|
+
return name.pascal;
|
|
48
116
|
}
|
package/dist/releases.js
CHANGED
|
@@ -27,7 +27,7 @@ const PACKUMENT_SCHEMA = s.object({
|
|
|
27
27
|
* an unreachable registry or a document without versions.
|
|
28
28
|
*/
|
|
29
29
|
export async function fetchPackument(name, signal) {
|
|
30
|
-
let url = `${REGISTRY}/${name.
|
|
30
|
+
let url = `${REGISTRY}/${name.replaceAll("/", "%2f")}`;
|
|
31
31
|
let response = await wrap(() => fetch(url, { headers: { accept: "application/json" }, signal }));
|
|
32
32
|
if (isFailure(response)) {
|
|
33
33
|
return failure(new Error(`Could not reach the npm registry: ${response.error.message}`));
|
package/dist/testing.d.ts
CHANGED
|
@@ -43,5 +43,8 @@ export declare function typecheck(project: string): Promise<Spawned>;
|
|
|
43
43
|
* `bun run cli` and `sdxc run` start it, answering both output streams together.
|
|
44
44
|
*/
|
|
45
45
|
export declare function runCommandLine(project: string, argv: string[]): Promise<Spawned>;
|
|
46
|
-
/**
|
|
46
|
+
/**
|
|
47
|
+
* Runs the project's own tests with its own Vite+, as `vp test run` inside it does, with
|
|
48
|
+
* `--no-color` so the summary reads as plain text on CI too, where Vite+ colors it otherwise.
|
|
49
|
+
*/
|
|
47
50
|
export declare function testProject(project: string): Promise<Spawned>;
|
package/dist/testing.js
CHANGED
|
@@ -92,9 +92,12 @@ export async function typecheck(project) {
|
|
|
92
92
|
export function runCommandLine(project, argv) {
|
|
93
93
|
return run(["bootstrap/cli.ts", ...argv], project, "bun");
|
|
94
94
|
}
|
|
95
|
-
/**
|
|
95
|
+
/**
|
|
96
|
+
* Runs the project's own tests with its own Vite+, as `vp test run` inside it does, with
|
|
97
|
+
* `--no-color` so the summary reads as plain text on CI too, where Vite+ colors it otherwise.
|
|
98
|
+
*/
|
|
96
99
|
export function testProject(project) {
|
|
97
|
-
return run([join(project, "node_modules/vite-plus/bin/vp"), "test", "run"], project);
|
|
100
|
+
return run([join(project, "node_modules/vite-plus/bin/vp"), "test", "run", "--no-color"], project);
|
|
98
101
|
}
|
|
99
102
|
/** The directory `dependency` is installed at for this package or, failing that, the workspace. */
|
|
100
103
|
async function installed(packageRoot, dependency) {
|
package/dist/upgrade/prompt.js
CHANGED
|
@@ -19,7 +19,7 @@ import { projectImports, readManifest } from "./project.js";
|
|
|
19
19
|
/** Where each release's GitHub Release lives, `<RELEASES>/tag/v<version>`. */
|
|
20
20
|
const RELEASES = "https://github.com/sergiodxa/monorepo/releases";
|
|
21
21
|
/** Each package's reference page, as Markdown an agent reads directly. */
|
|
22
|
-
const DOCUMENTATION = "https://sdxc.
|
|
22
|
+
const DOCUMENTATION = "https://sdxc.dev/api";
|
|
23
23
|
/** Remix's release notes, `<REMIX_RELEASES>/tag/remix@<version>`. */
|
|
24
24
|
const REMIX_RELEASES = "https://github.com/remix-run/remix/releases";
|
|
25
25
|
/** The `package.json` scripts that verify a project, in the order the prompt lists them. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sdxc/kit",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2026.10.16",
|
|
4
4
|
"description": "The sdxc command line: start a Remix v3 app, generate its files, copy UI components into it and upgrade it",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"bin": {
|
|
@@ -13,18 +13,18 @@
|
|
|
13
13
|
"./lock.schema.json": "./lock.schema.json"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@sdxc/cli": "
|
|
17
|
-
"@sdxc/codemod": "
|
|
18
|
-
"@sdxc/json-schema": "2026.10.
|
|
19
|
-
"@sdxc/jsonc": "
|
|
20
|
-
"@sdxc/jsonl": "
|
|
16
|
+
"@sdxc/cli": "2026.10.16",
|
|
17
|
+
"@sdxc/codemod": "2026.10.16",
|
|
18
|
+
"@sdxc/json-schema": "2026.10.16",
|
|
19
|
+
"@sdxc/jsonc": "2026.10.16",
|
|
20
|
+
"@sdxc/jsonl": "2026.10.16",
|
|
21
21
|
"@sdxc/result": "2026.10.13",
|
|
22
22
|
"@sdxc/semver": "2026.10.13"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
25
|
"remix": "3.0.0"
|
|
26
26
|
},
|
|
27
|
-
"gitHead": "
|
|
27
|
+
"gitHead": "1e547d8431568f5ed9bdb079ca3046c936240fde",
|
|
28
28
|
"publishConfig": {
|
|
29
29
|
"access": "public"
|
|
30
30
|
},
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"url": "git+https://github.com/sergiodxa/monorepo.git",
|
|
34
34
|
"directory": "packages/kit"
|
|
35
35
|
},
|
|
36
|
-
"homepage": "https://sdxc.
|
|
36
|
+
"homepage": "https://sdxc.dev/api/kit",
|
|
37
37
|
"author": {
|
|
38
38
|
"name": "Sergio Xalambrí",
|
|
39
39
|
"url": "https://sergiodxa.com"
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "accordion",
|
|
3
|
+
"changedIn": "2026.10.13",
|
|
4
|
+
"dependencies": [
|
|
5
|
+
"disclosure"
|
|
6
|
+
],
|
|
7
|
+
"exports": [
|
|
8
|
+
"Accordion"
|
|
9
|
+
],
|
|
10
|
+
"source": {
|
|
11
|
+
"path": "accordion.tsx",
|
|
12
|
+
"content": "/**\n * A set of expand/collapse sections built on {@link Disclosure}, stacked into\n * one divider-separated list. Each section holds its state on its native\n * `<details>` element; giving sibling {@link Accordion.Item}s the same `name`\n * makes the set exclusive through the platform's `<details name>` behavior,\n * closing whichever section was open as another opens.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type { Handle, Props as TagProps, RemixNode } from \"remix/component\";\n\nimport { bg, borderEdge, fg } from \"@sdxc/u/color\";\nimport { opacity, rounded, transition, transitionDuration } from \"@sdxc/u/effects\";\nimport { justify, shrink } from \"@sdxc/u/layout\";\nimport { media } from \"@sdxc/u/responsive\";\nimport { bs, is, pb, pbe, pi } from \"@sdxc/u/size\";\nimport { hover, open, when } from \"@sdxc/u/state\";\nimport { rotate } from \"@sdxc/u/transform\";\nimport { pretty, text, textDecoration } from \"@sdxc/u/typography\";\n\nimport { Disclosure } from \"@sdxc/ui/disclosure\";\n\n/**\n * Prop types for {@link Accordion} and its compound parts.\n */\nexport namespace Accordion {\n\t/**\n\t * Props accepted by {@link Accordion}.\n\t */\n\texport interface Props extends TagProps<\"div\"> {\n\t\t/** One or more {@link Accordion.Item} sections to stack into a list. */\n\t\tchildren: RemixNode;\n\t}\n\n\t/**\n\t * Every prop {@link Disclosure.Props} accepts, unchanged: the section's\n\t * `open` state and, when set to the same value across siblings, the\n\t * `name` that makes the group exclusive.\n\t */\n\texport interface ItemProps extends Disclosure.Props {}\n\n\t/** Every prop {@link Disclosure.TriggerProps} accepts, unchanged. */\n\texport interface TriggerProps extends Disclosure.TriggerProps {}\n\n\t/** Every prop {@link Disclosure.PanelProps} accepts, unchanged. */\n\texport interface ContentProps extends Disclosure.PanelProps {}\n}\n\n/**\n * Renders the list's root host: a plain `<div>` that stacks\n * {@link Accordion.Item} sections in normal block flow, each drawing its own\n * divider so the whole list reads as one continuous group.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the list's markup.\n * @example\n * <Accordion>\n * \t<Accordion.Item>\n * \t\t<Accordion.Trigger>\n * \t\t\t{t(\"faq.refunds.question\")}\n * \t\t\t<ChevronDownIcon data-slot=\"icon\" aria-hidden />\n * \t\t</Accordion.Trigger>\n * \t\t<Accordion.Content>\n * \t\t\t<p>{t(\"faq.refunds.answer\")}</p>\n * \t\t</Accordion.Content>\n * \t</Accordion.Item>\n * \t<Accordion.Item>\n * \t\t<Accordion.Trigger>\n * \t\t\t{t(\"faq.shipping.question\")}\n * \t\t\t<ChevronDownIcon data-slot=\"icon\" aria-hidden />\n * \t\t</Accordion.Trigger>\n * \t\t<Accordion.Content>\n * \t\t\t<p>{t(\"faq.shipping.answer\")}</p>\n * \t\t</Accordion.Content>\n * \t</Accordion.Item>\n * </Accordion>\n * @example\n * <Accordion>\n * \t<Accordion.Item name=\"faq\" open>\n * \t\t<Accordion.Trigger>\n * \t\t\t{t(\"faq.refunds.question\")}\n * \t\t\t<ChevronDownIcon data-slot=\"icon\" aria-hidden />\n * \t\t</Accordion.Trigger>\n * \t\t<Accordion.Content>\n * \t\t\t<p>{t(\"faq.refunds.answer\")}</p>\n * \t\t</Accordion.Content>\n * \t</Accordion.Item>\n * \t<Accordion.Item name=\"faq\">\n * \t\t<Accordion.Trigger>\n * \t\t\t{t(\"faq.shipping.question\")}\n * \t\t\t<ChevronDownIcon data-slot=\"icon\" aria-hidden />\n * \t\t</Accordion.Trigger>\n * \t\t<Accordion.Content>\n * \t\t\t<p>{t(\"faq.shipping.answer\")}</p>\n * \t\t</Accordion.Content>\n * \t</Accordion.Item>\n * </Accordion>\n */\nexport function Accordion(handle: Handle<Accordion.Props>) {\n\treturn () => {\n\t\tlet { children, mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<div {...rest} mix={[is(\"full\"), mix]}>\n\t\t\t\t{children}\n\t\t\t</div>\n\t\t);\n\t};\n}\n\n/**\n * Renders one section as {@link Disclosure} restyled into a flush list row:\n * only a shared block-end divider survives, restored block-start on the first\n * section. A trigger marked `aria-disabled=\"true\"` dims the whole section.\n *\n * @param handle Runtime handle carrying the host `<details>`'s props.\n * @returns The render function producing the section's markup.\n * @example\n * <Accordion.Item>\n * \t<Accordion.Trigger>\n * \t\t{t(\"faq.refunds.question\")}\n * \t\t<ChevronDownIcon data-slot=\"icon\" aria-hidden />\n * \t</Accordion.Trigger>\n * \t<Accordion.Content>\n * \t\t<p>{t(\"faq.refunds.answer\")}</p>\n * \t</Accordion.Content>\n * </Accordion.Item>\n * @example\n * <Accordion.Item name=\"faq\" open>\n * \t<Accordion.Trigger>\n * \t\t{t(\"faq.refunds.question\")}\n * \t\t<ChevronDownIcon data-slot=\"icon\" aria-hidden />\n * \t</Accordion.Trigger>\n * \t<Accordion.Content>\n * \t\t<p>{t(\"faq.refunds.answer\")}</p>\n * \t</Accordion.Content>\n * </Accordion.Item>\n */\nAccordion.Item = function AccordionItem(handle: Handle<Accordion.ItemProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<Disclosure\n\t\t\t\t{...rest}\n\t\t\t\tmix={[\n\t\t\t\t\trounded(\"none\"),\n\t\t\t\t\tborderEdge(\"inline-start\", { width: \"0\", noStyleDefault: true }),\n\t\t\t\t\tborderEdge(\"inline-end\", { width: \"0\", noStyleDefault: true }),\n\t\t\t\t\tborderEdge(\"block-start\", { width: \"0\", noStyleDefault: true }),\n\t\t\t\t\topen(when('& summary [data-slot=\"icon\"]', rotate(180))),\n\t\t\t\t\twhen(\"&:first-child\", borderEdge(\"block-start\", { width: 1 })),\n\t\t\t\t\twhen('&:has(> summary[aria-disabled=\"true\"])', opacity(50)),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t/>\n\t\t);\n\t};\n};\n\n/**\n * Renders {@link Accordion.TriggerProps.children} as the section's label row,\n * spread to opposite ends and underlined on hover. An icon element carrying\n * `data-slot=\"icon\"` rotates 180 degrees while its section is open.\n *\n * @param handle Runtime handle carrying the host `<summary>`'s props.\n * @returns The render function producing the label row's markup.\n * @example\n * <Accordion.Trigger>\n * \t{t(\"faq.refunds.question\")}\n * \t<ChevronDownIcon data-slot=\"icon\" aria-hidden />\n * </Accordion.Trigger>\n * @example\n * <Accordion.Trigger aria-disabled=\"true\">\n * \t{t(\"faq.archived.question\")}\n * \t<ChevronDownIcon data-slot=\"icon\" aria-hidden />\n * </Accordion.Trigger>\n */\nAccordion.Trigger = function AccordionTrigger(handle: Handle<Accordion.TriggerProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<Disclosure.Trigger\n\t\t\t\t{...rest}\n\t\t\t\tmix={[\n\t\t\t\t\tjustify(\"between\"),\n\t\t\t\t\tpb(4),\n\t\t\t\t\tpi(0),\n\t\t\t\t\trounded(\"none\"),\n\t\t\t\t\thover([bg(\"transparent\"), textDecoration(\"underline\")]),\n\t\t\t\t\twhen('& [data-slot=\"icon\"]', [\n\t\t\t\t\t\tis(4),\n\t\t\t\t\t\tbs(4),\n\t\t\t\t\t\tshrink(),\n\t\t\t\t\t\ttransition(\"transform\", { duration: \"200ms\" }),\n\t\t\t\t\t]),\n\t\t\t\t\tmedia(\n\t\t\t\t\t\t\"(prefers-reduced-motion: reduce)\",\n\t\t\t\t\t\twhen('& [data-slot=\"icon\"]', transitionDuration(\"0s\")),\n\t\t\t\t\t),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t/>\n\t\t);\n\t};\n};\n\n/**\n * Renders {@link Accordion.ContentProps.children} as the section's revealed body:\n * {@link Disclosure.Panel} running edge to edge like its trigger, with block-end\n * padding and small, muted text sized for supporting copy.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the body's markup.\n * @example\n * <Accordion.Content>\n * \t<p>{t(\"faq.refunds.answer\")}</p>\n * </Accordion.Content>\n */\nAccordion.Content = function AccordionContent(handle: Handle<Accordion.ContentProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<Disclosure.Panel {...rest} mix={[pi(0), pbe(4), fg(\"neutral\"), text(\"sm\"), pretty(), mix]} />\n\t\t);\n\t};\n};\n"
|
|
13
|
+
},
|
|
14
|
+
"test": null
|
|
15
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "alert-dialog",
|
|
3
|
+
"changedIn": "2026.10.13",
|
|
4
|
+
"dependencies": [
|
|
5
|
+
"button",
|
|
6
|
+
"dialog",
|
|
7
|
+
"heading-scope"
|
|
8
|
+
],
|
|
9
|
+
"exports": [
|
|
10
|
+
"AlertDialog"
|
|
11
|
+
],
|
|
12
|
+
"source": {
|
|
13
|
+
"path": "alert-dialog.tsx",
|
|
14
|
+
"content": "/**\n * An interruptive modal surface that demands an explicit response before a\n * page continues — confirming a destructive action, surfacing a blocking\n * error — built on the native `<dialog>` host of {@link Dialog}, widened for\n * its two-button layout and sealed against light dismiss. Its compound parts\n * cover a header, title, description, and a two-control footer.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type { Handle, Props as TagProps } from \"remix/component\";\n\nimport { fg } from \"@sdxc/u/color\";\nimport { flex, gap, justify, vstack } from \"@sdxc/u/layout\";\nimport { mbs } from \"@sdxc/u/size\";\nimport { balance, pretty, text, weight } from \"@sdxc/u/typography\";\n\nimport { Button } from \"@sdxc/ui/button\";\nimport { Dialog } from \"@sdxc/ui/dialog\";\nimport { resolveHeadingLevel, TAG_BY_LEVEL } from \"@sdxc/ui/heading-scope\";\n\n/**\n * Invoker Commands verb {@link AlertDialog.Action} and\n * {@link AlertDialog.Cancel} fall back to when `command` is omitted,\n * dismissing the ancestor AlertDialog named by `commandfor`.\n */\nconst DEFAULT_COMMAND = \"close\";\n\n/**\n * Native `button` `type` {@link AlertDialog.Action} and\n * {@link AlertDialog.Cancel} always spell out, since the platform runs an\n * Invoker Command only from a button typed `\"button\"`, `<form>` or not.\n */\nconst DEFAULT_TYPE: NonNullable<Button.Props[\"type\"]> = \"button\";\n\n/** Semantic color role {@link AlertDialog.Action} falls back to when `color` is omitted. */\nconst DEFAULT_ACTION_COLOR: Button.Color = \"danger\";\n\n/** Visual weight {@link AlertDialog.Cancel} falls back to when `variant` is omitted. */\nconst DEFAULT_CANCEL_VARIANT: Button.Variant = \"outline\";\n\n/** Semantic color role {@link AlertDialog.Cancel} falls back to when `color` is omitted. */\nconst DEFAULT_CANCEL_COLOR: Button.Color = \"neutral\";\n\n/**\n * Prop types for {@link AlertDialog} and its compound parts.\n */\nexport namespace AlertDialog {\n\t/**\n\t * Every prop {@link Dialog} accepts, minus the ones this component fixes:\n\t * `role` is always `\"alertdialog\"` and `closedby`/`closedBy` always\n\t * `\"closerequest\"`, so the panel closes only on an explicit close request.\n\t */\n\texport interface Props extends Omit<Dialog.Props, \"role\" | \"closedby\" | \"closedBy\"> {}\n\n\t/**\n\t * Props accepted by {@link AlertDialog.Header}.\n\t */\n\texport interface HeaderProps extends TagProps<\"div\"> {}\n\n\t/**\n\t * Props accepted by {@link AlertDialog.Title}. Every native heading-element\n\t * attribute applies, since the rendered tag follows the nearest ambient\n\t * heading level, falling back to `<h1>`.\n\t */\n\texport interface TitleProps extends TagProps<\"h1\"> {}\n\n\t/**\n\t * Props accepted by {@link AlertDialog.Description}.\n\t */\n\texport interface DescriptionProps extends TagProps<\"p\"> {}\n\n\t/**\n\t * Props accepted by {@link AlertDialog.Footer}.\n\t */\n\texport interface FooterProps extends TagProps<\"div\"> {}\n\n\t/**\n\t * Props accepted by {@link AlertDialog.Action}: every {@link Button.Props}\n\t * field except `commandfor`/`command`, which this type narrows.\n\t */\n\texport interface ActionProps extends Omit<Button.Props, \"commandfor\" | \"command\"> {\n\t\t/**\n\t\t * `id` of the ancestor {@link AlertDialog} this action dismisses.\n\t\t * Required for the default `type=\"button\"` action; a `type=\"submit\"`\n\t\t * action ends the interruption by submitting its enclosing form.\n\t\t */\n\t\tcommandfor?: string;\n\t\t/**\n\t\t * Invoker Commands verb dispatched to the target AlertDialog. Defaults\n\t\t * to `\"close\"`, and is dropped for a `\"submit\"` or `\"reset\"` action,\n\t\t * which the platform drives as a form control instead of an invoker.\n\t\t */\n\t\tcommand?: \"close\";\n\t}\n\n\t/**\n\t * Props accepted by {@link AlertDialog.Cancel}: every {@link Button.Props}\n\t * field except `commandfor`/`command`/`type`, which this type narrows.\n\t */\n\texport interface CancelProps extends Omit<Button.Props, \"commandfor\" | \"command\" | \"type\"> {\n\t\t/** `id` of the ancestor {@link AlertDialog} this cancel control dismisses. */\n\t\tcommandfor: string;\n\t\t/** Invoker Commands verb dispatched to the target AlertDialog. Defaults to `\"close\"`. */\n\t\tcommand?: \"close\";\n\t\t/**\n\t\t * Narrowed to the only value a cancel control carries, and always\n\t\t * rendered, since the platform runs its close command only from a\n\t\t * button typed `\"button\"`, including inside a `<form>`.\n\t\t */\n\t\ttype?: \"button\";\n\t}\n}\n\n/**\n * Renders the alert panel through {@link Dialog}, widened to fit a two-button\n * footer, with `role` fixed to `\"alertdialog\"` and `closedby` to\n * `\"closerequest\"` so the interruption clears through an explicit response.\n *\n * @param handle Runtime handle carrying the host `<dialog>`'s props.\n * @returns The render function producing the panel's markup.\n * @example\n * <Button commandfor=\"delete-project\" command=\"show-modal\" color=\"danger\">{t(\"project.delete\")}</Button>\n * <AlertDialog id=\"delete-project\" aria-labelledby=\"delete-project-title\">\n * \t<AlertDialog.Header>\n * \t\t<AlertDialog.Title id=\"delete-project-title\">{t(\"project.deleteTitle\")}</AlertDialog.Title>\n * \t\t<AlertDialog.Description>{t(\"project.deleteDescription\")}</AlertDialog.Description>\n * \t</AlertDialog.Header>\n * \t<AlertDialog.Footer>\n * \t\t<AlertDialog.Cancel commandfor=\"delete-project\">{t(\"actions.cancel\")}</AlertDialog.Cancel>\n * \t\t<AlertDialog.Action commandfor=\"delete-project\">{t(\"actions.delete\")}</AlertDialog.Action>\n * \t</AlertDialog.Footer>\n * </AlertDialog>\n */\nexport function AlertDialog(handle: Handle<AlertDialog.Props>) {\n\treturn () => {\n\t\tlet { children, mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<Dialog {...rest} role=\"alertdialog\" closedby=\"closerequest\" mix={mix}>\n\t\t\t\t{children}\n\t\t\t</Dialog>\n\t\t);\n\t};\n}\n\n/**\n * Renders {@link AlertDialog.HeaderProps.children} as the panel's header\n * slot: a column stacking {@link AlertDialog.Title} and\n * {@link AlertDialog.Description} with a small gap between them.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the header slot's markup.\n * @example\n * <AlertDialog.Header>\n * \t<AlertDialog.Title>{t(\"project.deleteTitle\")}</AlertDialog.Title>\n * \t<AlertDialog.Description>{t(\"project.deleteDescription\")}</AlertDialog.Description>\n * </AlertDialog.Header>\n */\nAlertDialog.Header = function AlertDialogHeader(handle: Handle<AlertDialog.HeaderProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn <div {...rest} data-slot=\"header\" mix={[vstack({ gap: 2 }), mix]} />;\n\t};\n};\n\n/**\n * Renders {@link AlertDialog.TitleProps.children} as the panel's heading,\n * inside the native heading element matching the nearest ancestor\n * `HeadingScope`'s depth, or `<h1>` where no scope wraps it.\n *\n * @param handle Runtime handle carrying the host heading element's props.\n * @returns The render function producing the heading's markup.\n * @example\n * <AlertDialog.Title>{t(\"project.deleteTitle\")}</AlertDialog.Title>\n */\nAlertDialog.Title = function AlertDialogTitle(handle: Handle<AlertDialog.TitleProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\t\tlet resolved = resolveHeadingLevel(handle);\n\t\tlet Tag = TAG_BY_LEVEL[resolved];\n\n\t\treturn (\n\t\t\t<Tag\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"title\"\n\t\t\t\tmix={[fg(\"neutral.emphasis\"), weight(\"semibold\"), text(\"lg\"), balance(), mix]}\n\t\t\t>\n\t\t\t\t{rest.children}\n\t\t\t</Tag>\n\t\t);\n\t};\n};\n\n/**\n * Renders {@link AlertDialog.DescriptionProps.children} as the panel's\n * supporting copy, in a native `<p>` set to the panel's muted foreground\n * color so it reads as secondary to {@link AlertDialog.Title}.\n *\n * @param handle Runtime handle carrying the host `<p>`'s props.\n * @returns The render function producing the description's markup.\n * @example\n * <AlertDialog.Description>{t(\"project.deleteDescription\")}</AlertDialog.Description>\n */\nAlertDialog.Description = function AlertDialogDescription(\n\thandle: Handle<AlertDialog.DescriptionProps>,\n) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<p {...rest} data-slot=\"description\" mix={[fg(\"neutral.muted\"), text(\"sm\"), pretty(), mix]}>\n\t\t\t\t{rest.children}\n\t\t\t</p>\n\t\t);\n\t};\n};\n\n/**\n * Renders {@link AlertDialog.FooterProps.children} as an end-aligned action\n * row. Compose {@link AlertDialog.Cancel} before {@link AlertDialog.Action}\n * so the emphasized, potentially destructive control renders last.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the action row's markup.\n * @example\n * <AlertDialog.Footer>\n * \t<AlertDialog.Cancel commandfor=\"delete-project\">{t(\"actions.cancel\")}</AlertDialog.Cancel>\n * \t<AlertDialog.Action commandfor=\"delete-project\">{t(\"actions.delete\")}</AlertDialog.Action>\n * </AlertDialog.Footer>\n */\nAlertDialog.Footer = function AlertDialogFooter(handle: Handle<AlertDialog.FooterProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn <div {...rest} data-slot=\"footer\" mix={[gap(2), mbs(6), flex(), justify(\"end\"), mix]} />;\n\t};\n};\n\n/**\n * Renders the panel's emphasized action as a danger-toned {@link Button},\n * typed `\"button\"` so its `command=\"close\"` reaches the {@link AlertDialog}\n * named by `commandfor`; `type=\"submit\"` submits the enclosing form instead.\n *\n * @param handle Runtime handle carrying the host button's props.\n * @returns The render function producing the action's markup.\n * @example\n * <AlertDialog.Action commandfor=\"delete-project\">{t(\"actions.delete\")}</AlertDialog.Action>\n * @example\n * <AlertDialog.Action commandfor=\"publish-post\" color=\"brand\">{t(\"actions.publish\")}</AlertDialog.Action>\n * @example\n * <AlertDialog.Action type=\"submit\" name=\"intent\" value=\"delete\">{t(\"actions.delete\")}</AlertDialog.Action>\n */\nAlertDialog.Action = function AlertDialogAction(handle: Handle<AlertDialog.ActionProps>) {\n\treturn () => {\n\t\tlet { type, color, command, commandfor, ...rest } = handle.props;\n\t\tlet resolvedType = type ?? DEFAULT_TYPE;\n\t\tlet isInvoker = resolvedType === \"button\";\n\t\tlet resolvedColor = color ?? DEFAULT_ACTION_COLOR;\n\n\t\tif (import.meta.env.DEV && isInvoker && !commandfor) {\n\t\t\tconsole.warn(\n\t\t\t\t'AlertDialog.Action: needs \"commandfor\" naming the panel it dismisses, or type=\"submit\" to submit its enclosing form instead — as rendered, pressing it does nothing.',\n\t\t\t);\n\t\t}\n\n\t\treturn (\n\t\t\t<Button\n\t\t\t\t{...rest}\n\t\t\t\ttype={resolvedType}\n\t\t\t\tcolor={resolvedColor}\n\t\t\t\tcommandfor={isInvoker ? commandfor : undefined}\n\t\t\t\tcommand={isInvoker ? (command ?? DEFAULT_COMMAND) : undefined}\n\t\t\t\tdata-slot=\"action\"\n\t\t\t/>\n\t\t);\n\t};\n};\n\n/**\n * Renders the panel's dismiss control as an outline, neutral {@link Button}\n * with `type` fixed to `\"button\"`, so its `command=\"close\"` reaches the\n * {@link AlertDialog} named by `commandfor` from inside a `<form>` too.\n *\n * @param handle Runtime handle carrying the host button's props.\n * @returns The render function producing the cancel control's markup.\n * @example\n * <AlertDialog.Cancel commandfor=\"delete-project\">{t(\"actions.cancel\")}</AlertDialog.Cancel>\n */\nAlertDialog.Cancel = function AlertDialogCancel(handle: Handle<AlertDialog.CancelProps>) {\n\treturn () => {\n\t\tlet { variant, color, command, ...rest } = handle.props;\n\t\tlet resolvedVariant = variant ?? DEFAULT_CANCEL_VARIANT;\n\t\tlet resolvedColor = color ?? DEFAULT_CANCEL_COLOR;\n\t\tlet resolvedCommand = command ?? DEFAULT_COMMAND;\n\n\t\treturn (\n\t\t\t<Button\n\t\t\t\t{...rest}\n\t\t\t\ttype={DEFAULT_TYPE}\n\t\t\t\tvariant={resolvedVariant}\n\t\t\t\tcolor={resolvedColor}\n\t\t\t\tcommand={resolvedCommand}\n\t\t\t\tdata-slot=\"cancel\"\n\t\t\t/>\n\t\t);\n\t};\n};\n"
|
|
15
|
+
},
|
|
16
|
+
"test": {
|
|
17
|
+
"path": "alert-dialog.test.tsx",
|
|
18
|
+
"content": "/**\n * Tests for {@link AlertDialog}'s two footer controls: both render an explicit\n * `type=\"button\"` ahead of their command attributes, which is what lets the\n * platform run their Invoker Command inside a `<form>`, and an action asked to\n * submit renders as a plain submit button.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport { renderToString } from \"remix/component/server\";\nimport { describe, expect, test } from \"vitest\";\n\nimport { AlertDialog } from \"@sdxc/ui/alert-dialog\";\n\ndescribe(\"AlertDialog.Cancel\", () => {\n\ttest('renders an explicit type=\"button\" so its close command survives inside a form', async () => {\n\t\tlet html = await renderToString(\n\t\t\t<AlertDialog.Cancel commandfor=\"delete-project\">Cancel</AlertDialog.Cancel>,\n\t\t);\n\n\t\texpect(html).toContain('type=\"button\"');\n\t\texpect(html).toContain('command=\"close\"');\n\t\texpect(html).toContain('commandfor=\"delete-project\"');\n\t});\n\n\ttest(\"writes that type before the command attributes, where the platform reads it\", async () => {\n\t\tlet html = await renderToString(\n\t\t\t<AlertDialog.Cancel commandfor=\"delete-project\">Cancel</AlertDialog.Cancel>,\n\t\t);\n\n\t\texpect(html.indexOf('type=\"button\"')).toBeLessThan(html.indexOf(\"commandfor=\"));\n\t\texpect(html.indexOf('type=\"button\"')).toBeLessThan(html.indexOf(\"command=\"));\n\t});\n\n\ttest('keeps type=\"button\" even when a consumer passes it explicitly', async () => {\n\t\tlet html = await renderToString(\n\t\t\t<AlertDialog.Cancel commandfor=\"delete-project\" type=\"button\">\n\t\t\t\tCancel\n\t\t\t</AlertDialog.Cancel>,\n\t\t);\n\n\t\texpect(html).toContain('type=\"button\"');\n\t\texpect(html).not.toContain('type=\"submit\"');\n\t});\n});\n\ndescribe(\"AlertDialog.Action\", () => {\n\ttest('renders an explicit type=\"button\" alongside its close command', async () => {\n\t\tlet html = await renderToString(\n\t\t\t<AlertDialog.Action commandfor=\"delete-project\">Delete</AlertDialog.Action>,\n\t\t);\n\n\t\texpect(html).toContain('type=\"button\"');\n\t\texpect(html).toContain('command=\"close\"');\n\t});\n\n\ttest(\"submits its enclosing form, and renders no command at all, when asked to\", async () => {\n\t\tlet html = await renderToString(\n\t\t\t<AlertDialog.Action type=\"submit\" name=\"intent\" value=\"delete\">\n\t\t\t\tDelete\n\t\t\t</AlertDialog.Action>,\n\t\t);\n\n\t\texpect(html).toContain('type=\"submit\"');\n\t\texpect(html).toContain('name=\"intent\"');\n\t\texpect(html).not.toContain(\"command=\");\n\t\texpect(html).not.toContain(\"commandfor=\");\n\t});\n\n\ttest(\"drops a command a submitting action was passed anyway, since the platform would refuse it\", async () => {\n\t\tlet html = await renderToString(\n\t\t\t<AlertDialog.Action type=\"submit\" commandfor=\"delete-project\" command=\"close\">\n\t\t\t\tDelete\n\t\t\t</AlertDialog.Action>,\n\t\t);\n\n\t\texpect(html).toContain('type=\"submit\"');\n\t\texpect(html).not.toContain(\"command=\");\n\t\texpect(html).not.toContain(\"commandfor=\");\n\t});\n});\n"
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "alert",
|
|
3
|
+
"changedIn": "2026.10.13",
|
|
4
|
+
"dependencies": [
|
|
5
|
+
"heading-scope"
|
|
6
|
+
],
|
|
7
|
+
"exports": [
|
|
8
|
+
"Alert"
|
|
9
|
+
],
|
|
10
|
+
"source": {
|
|
11
|
+
"path": "alert.tsx",
|
|
12
|
+
"content": "/**\n * An inline status message rendered as a bordered, tinted panel, colored by\n * one of five semantic tones and announced to assistive technology through\n * `role=\"alert\"` plus a configurable `aria-live` politeness. Compound parts\n * cover an optional leading icon, a title/description content block, and a\n * trailing action, so a page composes only the parts a given message needs.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type { Handle, Props as TagProps, RemixNode } from \"remix/component\";\n\nimport { border, colorMix, fg } from \"@sdxc/u/color\";\nimport { rounded } from \"@sdxc/u/effects\";\nimport { absolute, basis, gap, grow, inset, relative, self, shrink, vstack } from \"@sdxc/u/layout\";\nimport { bs, is, mbe, minIs, p, pis } from \"@sdxc/u/size\";\nimport { when } from \"@sdxc/u/state\";\nimport { balance, fontSize, leading, pretty, tracking, weight } from \"@sdxc/u/typography\";\nimport { attrs } from \"remix/component\";\n\nimport type { SemanticColor } from \"@sdxc/ui/utils\";\n\nimport { semanticColorPanel } from \"@sdxc/ui/styles\";\nimport { DEFAULT_ICON_ARIA_HIDDEN } from \"@sdxc/ui/utils\";\n\nimport { resolveHeadingLevel, TAG_BY_LEVEL } from \"@sdxc/ui/heading-scope\";\n\n/**\n * `role=\"alert\"` applied through {@link attrs} unless a consumer supplies\n * its own `role`, keeping the panel announced as an ARIA alert by default.\n */\nconst DEFAULT_ROLE = \"alert\";\n\n/**\n * Default {@link Alert.Props.color}, rendering an alert with the neutral\n * tone when a consumer names no semantic color.\n */\nconst DEFAULT_COLOR = \"neutral\";\n\n/**\n * Default {@link Alert.Props.live}, announcing an alert's content politely so\n * assistive technology finishes its current utterance first.\n */\nconst DEFAULT_LIVE = \"polite\";\n\n/**\n * `aria-atomic=\"true\"` applied through {@link attrs} unless a consumer\n * overrides it, so assistive technology re-reads the whole alert on update.\n */\nconst DEFAULT_ARIA_ATOMIC = \"true\";\n\n/**\n * Prop types for {@link Alert} and its compound parts.\n */\nexport namespace Alert {\n\t/**\n\t * Semantic tone driving the host element's border, tint, and foreground\n\t * color through the `--ui-*` variables for that color.\n\t */\n\texport type Color = SemanticColor;\n\n\t/**\n\t * `aria-live` politeness applied to the host element. `\"off\"` omits the\n\t * `aria-live` attribute, leaving the element's implicit live-region\n\t * behavior in place.\n\t */\n\texport type Live = \"polite\" | \"assertive\" | \"off\";\n\n\t/**\n\t * Props accepted by {@link Alert}.\n\t */\n\texport interface Props extends TagProps<\"div\"> {\n\t\t/** Semantic tone of the alert. Default: `\"neutral\"`. */\n\t\tcolor?: Color;\n\t\t/** `aria-live` politeness for dynamic alerts. Default: `\"polite\"`. */\n\t\tlive?: Live;\n\t\t/** The alert's compound parts: {@link Alert.Icon}, {@link Alert.Content}, {@link Alert.Action}, or any other content. */\n\t\tchildren: RemixNode;\n\t}\n\n\t/**\n\t * Props accepted by {@link Alert.Icon}.\n\t */\n\texport interface IconProps extends TagProps<\"div\"> {\n\t\t/** The icon graphic, typically a single SVG icon. */\n\t\tchildren: RemixNode;\n\t}\n\n\t/**\n\t * Props accepted by {@link Alert.Content}.\n\t */\n\texport interface ContentProps extends TagProps<\"div\"> {\n\t\t/** The alert's title, description, or other body content. */\n\t\tchildren: RemixNode;\n\t}\n\n\t/**\n\t * Props accepted by {@link Alert.Title}. Every native heading-element\n\t * attribute applies, since the rendered tag follows the nearest ambient\n\t * heading level, falling back to `<h1>`.\n\t */\n\texport interface TitleProps extends TagProps<\"h1\"> {\n\t\t/** The alert's heading text. */\n\t\tchildren: RemixNode;\n\t}\n\n\t/**\n\t * Props accepted by {@link Alert.Description}.\n\t */\n\texport interface DescriptionProps extends TagProps<\"p\"> {\n\t\t/** The alert's supporting message text. */\n\t\tchildren: RemixNode;\n\t}\n\n\t/**\n\t * Props accepted by {@link Alert.Action}.\n\t */\n\texport interface ActionProps extends TagProps<\"div\"> {\n\t\t/** A button, link, or other control the alert offers, e.g. \"Retry\" or \"Dismiss\". */\n\t\tchildren: RemixNode;\n\t}\n}\n\n/**\n * Renders an inline status panel tinted by {@link Alert.Props.color}, gaining\n * inline-start padding through `:has()` when a direct {@link Alert.Icon}\n * needs the room. `role`, `aria-atomic`, and `aria-live` stay overridable.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the alert's markup.\n * @example\n * <Alert color=\"danger\">\n * <Alert.Icon><CircleAlertIcon /></Alert.Icon>\n * <Alert.Content>\n * <Alert.Title>{t(\"alerts.paymentFailed.title\")}</Alert.Title>\n * <Alert.Description>{t(\"alerts.paymentFailed.description\")}</Alert.Description>\n * </Alert.Content>\n * <Alert.Action>\n * <Button size=\"sm\">{t(\"alerts.paymentFailed.retry\")}</Button>\n * </Alert.Action>\n * </Alert>\n * @example\n * <Alert color=\"success\" live=\"assertive\">\n * <Alert.Content>\n * <Alert.Title>{t(\"alerts.saved.title\")}</Alert.Title>\n * </Alert.Content>\n * </Alert>\n */\nexport function Alert(handle: Handle<Alert.Props>) {\n\treturn () => {\n\t\tlet {\n\t\t\tcolor = DEFAULT_COLOR,\n\t\t\tlive = DEFAULT_LIVE,\n\t\t\t\"aria-live\": ariaLiveProp,\n\t\t\tchildren,\n\t\t\tmix,\n\t\t\t...rest\n\t\t} = handle.props;\n\t\tlet ariaLive = ariaLiveProp ?? (live === \"off\" ? undefined : live);\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\t{...rest}\n\t\t\t\taria-live={ariaLive}\n\t\t\t\tdata-color={color}\n\t\t\t\tdata-slot=\"alert\"\n\t\t\t\tmix={[\n\t\t\t\t\tattrs({ role: DEFAULT_ROLE, \"aria-atomic\": DEFAULT_ARIA_ATOMIC }),\n\t\t\t\t\tsemanticColorPanel(),\n\t\t\t\t\trelative(),\n\t\t\t\t\tvstack({ align: \"start\" }),\n\t\t\t\t\tis(\"full\"),\n\t\t\t\t\tgap(3),\n\t\t\t\t\trounded(\"lg\"),\n\t\t\t\t\tborder({ width: 1 }),\n\t\t\t\t\tp(4),\n\t\t\t\t\twhen('&:has(> [data-slot=\"icon\"])', pis(10)),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t>\n\t\t\t\t{children}\n\t\t\t</div>\n\t\t);\n\t};\n}\n\n/**\n * Renders {@link Alert.IconProps.children} as the alert's leading icon,\n * absolutely positioned at the panel's inline/block-start corner with any\n * direct SVG sized to `1rem`. Decorative, since the text carries the meaning.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the icon's markup.\n */\nAlert.Icon = function AlertIcon(handle: Handle<Alert.IconProps>) {\n\treturn () => {\n\t\tlet { children, mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"icon\"\n\t\t\t\tmix={[\n\t\t\t\t\tattrs({ \"aria-hidden\": DEFAULT_ICON_ARIA_HIDDEN }),\n\t\t\t\t\tabsolute(),\n\t\t\t\t\tinset(4, \"auto\", \"auto\", 4),\n\t\t\t\t\twhen(\"& > svg\", [is(4), bs(4)]),\n\t\t\t\t\tfg(\"currentcolor\"),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t>\n\t\t\t\t{children}\n\t\t\t</div>\n\t\t);\n\t};\n};\n\n/**\n * Renders {@link Alert.ContentProps.children} as the alert's body block: a\n * column flex container that shrinks to fit alongside a leading icon or\n * trailing action, holding {@link Alert.Title} and {@link Alert.Description}.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the content block's markup.\n */\nAlert.Content = function AlertContent(handle: Handle<Alert.ContentProps>) {\n\treturn () => {\n\t\tlet { children, mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"content\"\n\t\t\t\tmix={[vstack({ gap: 1 }), minIs(0), grow(), shrink(1), basis(\"0%\"), mix]}\n\t\t\t>\n\t\t\t\t{children}\n\t\t\t</div>\n\t\t);\n\t};\n};\n\n/**\n * Renders {@link Alert.TitleProps.children} as the alert's heading, inside\n * the native heading element matching the nearest ancestor `HeadingScope`'s\n * depth — or `<h1>` where no scope wraps it — styled as a small, tight label.\n *\n * @param handle Runtime handle carrying the host heading element's props.\n * @returns The render function producing the title's markup.\n */\nAlert.Title = function AlertTitle(handle: Handle<Alert.TitleProps>) {\n\treturn () => {\n\t\tlet { children, mix, ...rest } = handle.props;\n\t\tlet resolved = resolveHeadingLevel(handle);\n\t\tlet Tag = TAG_BY_LEVEL[resolved];\n\n\t\treturn (\n\t\t\t<Tag\n\t\t\t\t{...rest}\n\t\t\t\tdata-heading-level={resolved}\n\t\t\t\tdata-slot=\"title\"\n\t\t\t\tmix={[\n\t\t\t\t\tmbe(1),\n\t\t\t\t\tweight(\"medium\"),\n\t\t\t\t\tleading(1),\n\t\t\t\t\ttracking(\"tight\"),\n\t\t\t\t\tfontSize(\"sm\"),\n\t\t\t\t\tbalance(),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t>\n\t\t\t\t{children}\n\t\t\t</Tag>\n\t\t);\n\t};\n};\n\n/**\n * Renders {@link Alert.DescriptionProps.children} as the alert's supporting\n * message, slightly translucent against the alert's foreground color so it\n * reads as secondary to the title. Any nested `<p>` keeps its line height.\n *\n * @param handle Runtime handle carrying the host `<p>`'s props.\n * @returns The render function producing the description's markup.\n */\nAlert.Description = function AlertDescription(handle: Handle<Alert.DescriptionProps>) {\n\treturn () => {\n\t\tlet { children, mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<p\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"description\"\n\t\t\t\tmix={[\n\t\t\t\t\tleading(\"relaxed\"),\n\t\t\t\t\twhen(\"& p\", leading(\"relaxed\")),\n\t\t\t\t\tpretty(),\n\t\t\t\t\tfontSize(\"sm\"),\n\t\t\t\t\tfg(colorMix(\"oklab\", { color: \"currentcolor\", weight: 70 }, \"transparent\")),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t>\n\t\t\t\t{children}\n\t\t\t</p>\n\t\t);\n\t};\n};\n\n/**\n * Renders {@link Alert.ActionProps.children} as the alert's trailing\n * control — a button, link, or dismiss affordance — pinned to the panel's\n * block-start edge at its own natural size.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the action's markup.\n */\nAlert.Action = function AlertAction(handle: Handle<Alert.ActionProps>) {\n\treturn () => {\n\t\tlet { children, mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<div {...rest} data-slot=\"action\" mix={[shrink(), self(\"start\"), mix]}>\n\t\t\t\t{children}\n\t\t\t</div>\n\t\t);\n\t};\n};\n"
|
|
13
|
+
},
|
|
14
|
+
"test": null
|
|
15
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "aspect-ratio",
|
|
3
|
+
"changedIn": "2026.10.2",
|
|
4
|
+
"dependencies": [],
|
|
5
|
+
"exports": [
|
|
6
|
+
"AspectRatio"
|
|
7
|
+
],
|
|
8
|
+
"source": {
|
|
9
|
+
"path": "aspect-ratio.tsx",
|
|
10
|
+
"content": "/**\n * A layout primitive that locks its host to a fixed width-to-height ratio,\n * clipping whatever content it wraps so the box keeps its shape regardless\n * of the content's own intrinsic size. It reserves stable space for media,\n * embeds, and other loading content ahead of time, so nothing around it\n * shifts once that content resolves its own measurements.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type { Handle, Props as TagProps } from \"remix/component\";\n\nimport { var as varUtility, raw } from \"@sdxc/u/general\";\nimport { block } from \"@sdxc/u/layout\";\nimport { overflow } from \"@sdxc/u/overflow\";\nimport { is } from \"@sdxc/u/size\";\n\nimport { mergeStyle } from \"@sdxc/ui/utils\";\n\nconst DEFAULT_RATIO: AspectRatio.Ratio = \"1 / 1\";\n\n/**\n * Prop types for {@link AspectRatio}.\n */\nexport namespace AspectRatio {\n\t/**\n\t * A CSS `aspect-ratio` value: a bare number of width divided by height\n\t * (`1.7778` for a 16:9 box), or a ratio string CSS accepts directly\n\t * (`\"16 / 9\"`).\n\t */\n\texport type Ratio = number | string;\n\n\t/**\n\t * Props accepted by {@link AspectRatio}.\n\t */\n\texport interface Props extends TagProps<\"div\"> {\n\t\t/** Width-to-height ratio the host maintains. Defaults to a square. */\n\t\tratio?: Ratio;\n\t}\n}\n\n/**\n * Fills its container's inline axis and clips any overflow. The ratio rides on\n * the `--ui-aspect-ratio` custom property, set per instance from the `ratio`\n * prop, so an ancestor's stylesheet can override it on its own.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the ratio-locked box's markup.\n * @example\n * <AspectRatio ratio=\"16 / 9\">\n * \t<img src={coverImageUrl} alt={coverImageAlt} />\n * </AspectRatio>\n * @example\n * <AspectRatio ratio={4 / 3} />\n */\nexport function AspectRatio(handle: Handle<AspectRatio.Props>) {\n\treturn () => {\n\t\tlet { ratio, mix, style, ...rest } = handle.props;\n\t\tlet resolvedRatio = ratio ?? DEFAULT_RATIO;\n\t\tlet resolvedStyle = mergeStyle(style, { \"--ui-aspect-ratio\": resolvedRatio });\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\t{...rest}\n\t\t\t\tstyle={resolvedStyle}\n\t\t\t\tmix={[\n\t\t\t\t\tblock(),\n\t\t\t\t\tis(\"full\"),\n\t\t\t\t\toverflow(),\n\t\t\t\t\traw({ aspectRatio: varUtility(\"ui-aspect-ratio\", \"1\") }),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t/>\n\t\t);\n\t};\n}\n"
|
|
11
|
+
},
|
|
12
|
+
"test": null
|
|
13
|
+
}
|