@sdxc/kit 2026.11.1 → 2026.11.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 +68 -0
- package/changelog.jsonl +260 -0
- package/config.schema.json +14 -0
- package/dist/ci/install.d.ts +15 -0
- package/dist/ci/install.js +27 -0
- package/dist/ci/locate.d.ts +23 -0
- package/dist/ci/locate.js +43 -0
- package/dist/cli.js +6 -0
- package/dist/commands/ci/clean.d.ts +11 -0
- package/dist/commands/ci/clean.js +15 -0
- package/dist/commands/ci/list.d.ts +16 -0
- package/dist/commands/ci/list.js +24 -0
- package/dist/commands/ci/run.d.ts +70 -0
- package/dist/commands/ci/run.js +43 -0
- package/dist/commands/ci/signoff.d.ts +15 -0
- package/dist/commands/ci/signoff.js +15 -0
- package/dist/commands/ci/verify.d.ts +17 -0
- package/dist/commands/ci/verify.js +15 -0
- package/dist/commands/create.js +3 -0
- package/dist/commands/pkg.d.ts +16 -0
- package/dist/commands/pkg.js +71 -0
- package/dist/commands/routes.d.ts +1 -1
- package/dist/config.d.ts +10 -4
- package/dist/config.js +8 -0
- package/dist/contract.d.ts +65 -1
- package/dist/contract.js +51 -0
- package/dist/create/workspace.d.ts +15 -0
- package/dist/create/workspace.js +42 -0
- package/dist/doctor/checks.js +4 -0
- package/dist/doctor/ci.d.ts +15 -0
- package/dist/doctor/ci.js +63 -0
- package/dist/doctor/translations.d.ts +19 -0
- package/dist/doctor/translations.js +144 -0
- package/dist/package-manager.d.ts +2 -0
- package/dist/package-manager.js +16 -2
- package/dist/pkg/catalog.d.ts +12 -0
- package/dist/pkg/catalog.js +153 -0
- package/dist/pkg/resolve.d.ts +67 -0
- package/dist/pkg/resolve.js +147 -0
- package/dist/upgrade/changelog.d.ts +2 -2
- package/dist/upgrade/project.d.ts +2 -2
- package/package.json +10 -8
- package/registry/ui/banner.json +16 -0
- package/registry/ui/confirm.json +8 -4
- package/registry/ui/group.json +2 -2
- package/registry/ui/input.json +2 -2
- package/registry/ui/link-button.json +2 -2
- package/registry/ui/property-list.json +18 -0
- package/registry/ui/relative-time.json +17 -0
- package/registry/ui/status-dot.json +16 -0
- package/registry/ui/text-field.json +7 -3
- package/registry/ui/timeline.json +16 -0
- package/registry/ui/typeset.json +2 -2
- package/templates/app/.config/sdxc/ci.ts +26 -0
- package/templates/app/.github/workflows/ci.yml +46 -0
- package/templates/app/README.md +4 -0
- package/templates/app/package.json +1 -0
- package/templates/app/public/_headers +4 -0
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `@sdxc` packages `sdxc pkg` knows by name: those with a command line, each with what it
|
|
3
|
+
* does for `sdxc pkg --help`, and those without one, so a request for one gets an answer
|
|
4
|
+
* naming where to ask for it. A repository test holds both lists to the published packages.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
/** Every package with a command line, by name, with what its command line does. */
|
|
10
|
+
export const PACKAGE_COMMAND_LINES = {
|
|
11
|
+
ci: "run a CI script locally or on a CI host, and sign green commits off on GitHub",
|
|
12
|
+
cron: "upcoming runs, descriptions and validation for cron schedules",
|
|
13
|
+
crypto: "tokens, digests, MACs, one-time codes and password hashes",
|
|
14
|
+
diagram: "Mermaid sequence, class, state and flowchart diagrams to SVG",
|
|
15
|
+
distill: "extract the article from a web page",
|
|
16
|
+
doh: "typed DNS over HTTPS lookups",
|
|
17
|
+
"email-address": "parse and check email addresses",
|
|
18
|
+
"email-auth": "check a domain's email-authentication DNS policies",
|
|
19
|
+
font: "inspect and subset fonts",
|
|
20
|
+
html: "read a served page by role and accessible name",
|
|
21
|
+
"http-signatures": "sign and verify HTTP message signatures",
|
|
22
|
+
icalendar: "check iCalendar files and expand their recurrences",
|
|
23
|
+
ip: "IPv4 and IPv6 addresses against the IANA special-purpose registries",
|
|
24
|
+
jscalendar: "convert, expand and validate RFC 8984 JSCalendar documents",
|
|
25
|
+
jscontact: "JSContact, vCard and jCard contacts",
|
|
26
|
+
jsdoc: "JSDoc from JavaScript and TypeScript sources as JSON",
|
|
27
|
+
"json-canonical": "RFC 8785 canonical JSON for hashing and signing",
|
|
28
|
+
"json-patch": "apply, diff and validate RFC 6902 JSON Patch documents",
|
|
29
|
+
jsonc: "check JSON with comments and strip it to plain JSON",
|
|
30
|
+
jsonpath: "RFC 9535 JSONPath queries over JSON documents",
|
|
31
|
+
jwt: "decode, verify and sign JSON Web Tokens, and generate their keys",
|
|
32
|
+
"merge-patch": "apply and compute RFC 7396 JSON merge patches",
|
|
33
|
+
openapi: "check OpenAPI 3.1 documents",
|
|
34
|
+
openpgp: "sign and verify with OpenPGP keys, inspect them and generate them",
|
|
35
|
+
qr: "QR codes as SVG or PNG",
|
|
36
|
+
rdap: "domain registration data from the registry, over RDAP",
|
|
37
|
+
robots: "read and evaluate robots.txt (RFC 9309)",
|
|
38
|
+
"security-headers": "audit and parse security response headers",
|
|
39
|
+
semver: "SemVer 2.0.0 validation, comparison and sorting",
|
|
40
|
+
sitemap: "read and check sitemaps",
|
|
41
|
+
typeid: "generate, parse and encode TypeIDs",
|
|
42
|
+
"user-agent": "read User-Agent strings",
|
|
43
|
+
uuid: "generate and validate UUIDs",
|
|
44
|
+
"web-push": "VAPID keys and test notifications for Web Push",
|
|
45
|
+
webmention: "discover, send and verify Webmentions",
|
|
46
|
+
"well-known": "read and check /.well-known/ documents",
|
|
47
|
+
"zone-file": "read, check and write RFC 1035 DNS zone files",
|
|
48
|
+
};
|
|
49
|
+
/** Every published package without a command line yet. */
|
|
50
|
+
export const PACKAGES_WITHOUT_COMMAND_LINES = [
|
|
51
|
+
"activitypub",
|
|
52
|
+
"api-client",
|
|
53
|
+
"assets-middleware",
|
|
54
|
+
"atom",
|
|
55
|
+
"attribution",
|
|
56
|
+
"auth",
|
|
57
|
+
"authz",
|
|
58
|
+
"backoff",
|
|
59
|
+
"billing",
|
|
60
|
+
"bracket-params",
|
|
61
|
+
"cache",
|
|
62
|
+
"captcha",
|
|
63
|
+
"catch-response-middleware",
|
|
64
|
+
"cbor",
|
|
65
|
+
"cli",
|
|
66
|
+
"cloudflare-mocks",
|
|
67
|
+
"cloudflare-pricing",
|
|
68
|
+
"codemod",
|
|
69
|
+
"csv",
|
|
70
|
+
"data-model",
|
|
71
|
+
"data-table-d1",
|
|
72
|
+
"data-table-sqlstorage",
|
|
73
|
+
"database-middleware",
|
|
74
|
+
"dates",
|
|
75
|
+
"digest-fields",
|
|
76
|
+
"duration",
|
|
77
|
+
"epub",
|
|
78
|
+
"expression",
|
|
79
|
+
"feed",
|
|
80
|
+
"file-storage-r2",
|
|
81
|
+
"flags",
|
|
82
|
+
"flags-engine",
|
|
83
|
+
"get-client-ip",
|
|
84
|
+
"health",
|
|
85
|
+
"highlight",
|
|
86
|
+
"honeypot",
|
|
87
|
+
"hostname",
|
|
88
|
+
"http",
|
|
89
|
+
"i18n",
|
|
90
|
+
"icons",
|
|
91
|
+
"idempotency",
|
|
92
|
+
"iife",
|
|
93
|
+
"jmap",
|
|
94
|
+
"jobs",
|
|
95
|
+
"json-feed",
|
|
96
|
+
"json-pointer",
|
|
97
|
+
"json-schema",
|
|
98
|
+
"jsonl",
|
|
99
|
+
"lazy-frame",
|
|
100
|
+
"lazy-route",
|
|
101
|
+
"link-header",
|
|
102
|
+
"location",
|
|
103
|
+
"logger",
|
|
104
|
+
"mail",
|
|
105
|
+
"markdown",
|
|
106
|
+
"math",
|
|
107
|
+
"messageformat",
|
|
108
|
+
"messaging",
|
|
109
|
+
"microformats",
|
|
110
|
+
"micropub",
|
|
111
|
+
"newsletter",
|
|
112
|
+
"no-www-middleware",
|
|
113
|
+
"opml",
|
|
114
|
+
"outbound",
|
|
115
|
+
"pagination",
|
|
116
|
+
"passkey",
|
|
117
|
+
"password-policy",
|
|
118
|
+
"pdf",
|
|
119
|
+
"png",
|
|
120
|
+
"privacy-pass",
|
|
121
|
+
"problem",
|
|
122
|
+
"random",
|
|
123
|
+
"raster",
|
|
124
|
+
"rate-limit",
|
|
125
|
+
"response",
|
|
126
|
+
"result",
|
|
127
|
+
"rss",
|
|
128
|
+
"saml",
|
|
129
|
+
"sample",
|
|
130
|
+
"scim",
|
|
131
|
+
"scitt",
|
|
132
|
+
"search",
|
|
133
|
+
"seo",
|
|
134
|
+
"server-timing",
|
|
135
|
+
"session-storage-kv",
|
|
136
|
+
"spam",
|
|
137
|
+
"strings",
|
|
138
|
+
"structured-fields",
|
|
139
|
+
"trace-context",
|
|
140
|
+
"trailing-slash-middleware",
|
|
141
|
+
"types",
|
|
142
|
+
"u",
|
|
143
|
+
"ui",
|
|
144
|
+
"uri-template",
|
|
145
|
+
"validate",
|
|
146
|
+
"webhooks",
|
|
147
|
+
"websub",
|
|
148
|
+
"workers-cache",
|
|
149
|
+
"x402",
|
|
150
|
+
"xml",
|
|
151
|
+
"yaml",
|
|
152
|
+
"zip",
|
|
153
|
+
];
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How `sdxc pkg <name>` turns a typed name into a command: the package it names (or the one a
|
|
3
|
+
* typo most likely meant), the copy installed at or above the working directory when there is
|
|
4
|
+
* one, and otherwise `bunx`, or `npx` without Bun, downloading the published package.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
/** Where a request for a package's command line is posted, with the package in the title. */
|
|
10
|
+
export declare const REQUEST_URL = "https://github.com/sergiodxa/monorepo/discussions/new?category=ideas";
|
|
11
|
+
/** What a typed name refers to. */
|
|
12
|
+
export type PackageLookup = {
|
|
13
|
+
kind: "command-line";
|
|
14
|
+
name: string;
|
|
15
|
+
} | {
|
|
16
|
+
kind: "without-command-line";
|
|
17
|
+
name: string;
|
|
18
|
+
} | {
|
|
19
|
+
kind: "unknown";
|
|
20
|
+
name: string;
|
|
21
|
+
suggestion: string | undefined;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* The package `input` names. The package name, its `@sdxc/` specifier and its `sdxc-` binary
|
|
25
|
+
* name all resolve, so pasting any of the three works; any other name is unknown, with the
|
|
26
|
+
* nearest name that has a command line as its suggestion.
|
|
27
|
+
*
|
|
28
|
+
* @example lookupPackage("@sdxc/uuid") // { kind: "command-line", name: "uuid" }
|
|
29
|
+
* @example lookupPackage("uiid") // { kind: "unknown", name: "uiid", suggestion: "uuid" }
|
|
30
|
+
*/
|
|
31
|
+
export declare function lookupPackage(input: string): PackageLookup;
|
|
32
|
+
/**
|
|
33
|
+
* The link that opens a request for `name`'s command line in the Ideas discussions, titled
|
|
34
|
+
* with the package alone so nothing else from the command line leaves the machine.
|
|
35
|
+
*/
|
|
36
|
+
export declare function requestURL(name: string): string;
|
|
37
|
+
/**
|
|
38
|
+
* The binary of `@sdxc/<name>` installed at or above `cwd`, or declared by a workspace that
|
|
39
|
+
* contains `cwd`, or `null` when neither holds it. A workspace runs its checked-out source,
|
|
40
|
+
* and a project runs the version it installs.
|
|
41
|
+
*/
|
|
42
|
+
export declare function installedBinary(cwd: string, name: string): Promise<string | null>;
|
|
43
|
+
/**
|
|
44
|
+
* Whether an executable named `program` is in one of `path`'s directories. On Windows the file
|
|
45
|
+
* carries an extension, so `bun.exe` and `bun.cmd` count as `bun` there.
|
|
46
|
+
*
|
|
47
|
+
* @param platform - The operating system, as `process.platform` names it
|
|
48
|
+
*/
|
|
49
|
+
export declare function onPath(program: string, path: string | undefined, platform?: NodeJS.Platform): Promise<boolean>;
|
|
50
|
+
/**
|
|
51
|
+
* The release the project around `cwd` pins its `@sdxc` packages to, or `null` outside a
|
|
52
|
+
* project or in one that pins none, so a downloaded command line matches the project's code.
|
|
53
|
+
*/
|
|
54
|
+
export declare function projectRelease(cwd: string): Promise<string | null>;
|
|
55
|
+
/**
|
|
56
|
+
* The command that runs `name`'s command line with `args`: the installed binary under Bun when
|
|
57
|
+
* Bun is on `PATH` and under Node otherwise, or the published package through `bunx --bun`,
|
|
58
|
+
* falling back to `npx`. Bun runs an installed binary that is still TypeScript source.
|
|
59
|
+
*
|
|
60
|
+
* A download takes the package's newest version at `release`, since a daily release republishes
|
|
61
|
+
* only the packages that changed, or the newest version when `release` is `null`.
|
|
62
|
+
*
|
|
63
|
+
* @param binary - The installed binary, from `installedBinary`, or `null` to download it
|
|
64
|
+
* @param bun - Whether `bun` is on `PATH`
|
|
65
|
+
* @param release - The project's release, from `projectRelease`
|
|
66
|
+
*/
|
|
67
|
+
export declare function packageCommand(name: string, args: readonly string[], binary: string | null, bun: boolean, release?: string | null): string[];
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How `sdxc pkg <name>` turns a typed name into a command: the package it names (or the one a
|
|
3
|
+
* typo most likely meant), the copy installed at or above the working directory when there is
|
|
4
|
+
* one, and otherwise `bunx`, or `npx` without Bun, downloading the published package.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
import { readFile, stat } from "node:fs/promises";
|
|
10
|
+
import { delimiter, dirname, join } from "node:path";
|
|
11
|
+
import { closest } from "@sdxc/cli";
|
|
12
|
+
import { isFailure, isSuccess, wrap } from "@sdxc/result";
|
|
13
|
+
import { findProjectRoot } from "../project.js";
|
|
14
|
+
import { currentRelease, readManifest } from "../upgrade/project.js";
|
|
15
|
+
import { PACKAGE_COMMAND_LINES, PACKAGES_WITHOUT_COMMAND_LINES } from "./catalog.js";
|
|
16
|
+
/** Where a request for a package's command line is posted, with the package in the title. */
|
|
17
|
+
export const REQUEST_URL = "https://github.com/sergiodxa/monorepo/discussions/new?category=ideas";
|
|
18
|
+
/**
|
|
19
|
+
* The package `input` names. The package name, its `@sdxc/` specifier and its `sdxc-` binary
|
|
20
|
+
* name all resolve, so pasting any of the three works; any other name is unknown, with the
|
|
21
|
+
* nearest name that has a command line as its suggestion.
|
|
22
|
+
*
|
|
23
|
+
* @example lookupPackage("@sdxc/uuid") // { kind: "command-line", name: "uuid" }
|
|
24
|
+
* @example lookupPackage("uiid") // { kind: "unknown", name: "uiid", suggestion: "uuid" }
|
|
25
|
+
*/
|
|
26
|
+
export function lookupPackage(input) {
|
|
27
|
+
let name = input
|
|
28
|
+
.trim()
|
|
29
|
+
.toLowerCase()
|
|
30
|
+
.replace(/^@sdxc\//, "")
|
|
31
|
+
.replace(/^sdxc-/, "");
|
|
32
|
+
if (Object.hasOwn(PACKAGE_COMMAND_LINES, name))
|
|
33
|
+
return { kind: "command-line", name };
|
|
34
|
+
if (PACKAGES_WITHOUT_COMMAND_LINES.includes(name))
|
|
35
|
+
return { kind: "without-command-line", name };
|
|
36
|
+
return { kind: "unknown", name, suggestion: closest(name, Object.keys(PACKAGE_COMMAND_LINES)) };
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* The link that opens a request for `name`'s command line in the Ideas discussions, titled
|
|
40
|
+
* with the package alone so nothing else from the command line leaves the machine.
|
|
41
|
+
*/
|
|
42
|
+
export function requestURL(name) {
|
|
43
|
+
return `${REQUEST_URL}&title=${encodeURIComponent(`Command line for @sdxc/${name}`)}`;
|
|
44
|
+
}
|
|
45
|
+
/** The `package.json` in `dir`, or `null` when it is missing or unreadable. */
|
|
46
|
+
async function manifestIn(dir) {
|
|
47
|
+
let read = await wrap(async () => {
|
|
48
|
+
return JSON.parse(await readFile(join(dir, "package.json"), "utf8"));
|
|
49
|
+
});
|
|
50
|
+
return isSuccess(read) ? read.data : null;
|
|
51
|
+
}
|
|
52
|
+
/** The path of the `sdxc-<name>` binary a package in `dir` declares, or `null`. */
|
|
53
|
+
function binaryOf(dir, manifest, name) {
|
|
54
|
+
let bin = manifest.bin;
|
|
55
|
+
let target = typeof bin === "string" ? bin : bin?.[`sdxc-${name}`];
|
|
56
|
+
return target === undefined ? null : join(dir, target);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* The folder of the workspace package named `@sdxc/<name>` that the workspace root `dir`
|
|
60
|
+
* declares, through a `packages/*`-style pattern or an exact path, or `null`.
|
|
61
|
+
*/
|
|
62
|
+
async function workspacePackage(dir, manifest, name) {
|
|
63
|
+
let patterns = Array.isArray(manifest.workspaces)
|
|
64
|
+
? manifest.workspaces
|
|
65
|
+
: (manifest.workspaces?.packages ?? []);
|
|
66
|
+
for (let pattern of patterns) {
|
|
67
|
+
let folder = pattern.endsWith("/*")
|
|
68
|
+
? join(dir, pattern.slice(0, -2), name)
|
|
69
|
+
: join(dir, pattern);
|
|
70
|
+
let candidate = await manifestIn(folder);
|
|
71
|
+
if (candidate?.name === `@sdxc/${name}`)
|
|
72
|
+
return { folder, manifest: candidate };
|
|
73
|
+
}
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* The binary of `@sdxc/<name>` installed at or above `cwd`, or declared by a workspace that
|
|
78
|
+
* contains `cwd`, or `null` when neither holds it. A workspace runs its checked-out source,
|
|
79
|
+
* and a project runs the version it installs.
|
|
80
|
+
*/
|
|
81
|
+
export async function installedBinary(cwd, name) {
|
|
82
|
+
let dir = cwd;
|
|
83
|
+
for (;;) {
|
|
84
|
+
let installed = join(dir, "node_modules", "@sdxc", name);
|
|
85
|
+
let manifest = await manifestIn(installed);
|
|
86
|
+
if (manifest !== null)
|
|
87
|
+
return binaryOf(installed, manifest, name);
|
|
88
|
+
let root = await manifestIn(dir);
|
|
89
|
+
let member = root === null ? null : await workspacePackage(dir, root, name);
|
|
90
|
+
if (member !== null)
|
|
91
|
+
return binaryOf(member.folder, member.manifest, name);
|
|
92
|
+
let parent = dirname(dir);
|
|
93
|
+
if (parent === dir)
|
|
94
|
+
return null;
|
|
95
|
+
dir = parent;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Whether an executable named `program` is in one of `path`'s directories. On Windows the file
|
|
100
|
+
* carries an extension, so `bun.exe` and `bun.cmd` count as `bun` there.
|
|
101
|
+
*
|
|
102
|
+
* @param platform - The operating system, as `process.platform` names it
|
|
103
|
+
*/
|
|
104
|
+
export async function onPath(program, path, platform = process.platform) {
|
|
105
|
+
let names = platform === "win32" ? [`${program}.exe`, `${program}.cmd`, program] : [program];
|
|
106
|
+
for (let dir of (path ?? "").split(delimiter)) {
|
|
107
|
+
if (dir === "")
|
|
108
|
+
continue;
|
|
109
|
+
for (let name of names) {
|
|
110
|
+
if (isSuccess(await wrap(() => stat(join(dir, name)))))
|
|
111
|
+
return true;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* The release the project around `cwd` pins its `@sdxc` packages to, or `null` outside a
|
|
118
|
+
* project or in one that pins none, so a downloaded command line matches the project's code.
|
|
119
|
+
*/
|
|
120
|
+
export async function projectRelease(cwd) {
|
|
121
|
+
let root = await findProjectRoot(cwd);
|
|
122
|
+
if (isFailure(root))
|
|
123
|
+
return null;
|
|
124
|
+
let manifest = await readManifest(root.data);
|
|
125
|
+
return isFailure(manifest) ? null : currentRelease(manifest.data.manifest);
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* The command that runs `name`'s command line with `args`: the installed binary under Bun when
|
|
129
|
+
* Bun is on `PATH` and under Node otherwise, or the published package through `bunx --bun`,
|
|
130
|
+
* falling back to `npx`. Bun runs an installed binary that is still TypeScript source.
|
|
131
|
+
*
|
|
132
|
+
* A download takes the package's newest version at `release`, since a daily release republishes
|
|
133
|
+
* only the packages that changed, or the newest version when `release` is `null`.
|
|
134
|
+
*
|
|
135
|
+
* @param binary - The installed binary, from `installedBinary`, or `null` to download it
|
|
136
|
+
* @param bun - Whether `bun` is on `PATH`
|
|
137
|
+
* @param release - The project's release, from `projectRelease`
|
|
138
|
+
*/
|
|
139
|
+
export function packageCommand(name, args, binary, bun, release = null) {
|
|
140
|
+
if (binary !== null)
|
|
141
|
+
return [bun ? "bun" : "node", binary, ...args];
|
|
142
|
+
let specifier = release === null ? `@sdxc/${name}` : `@sdxc/${name}@<=${release}`;
|
|
143
|
+
let program = `sdxc-${name}`;
|
|
144
|
+
if (bun)
|
|
145
|
+
return ["bunx", "--bun", "--package", specifier, program, ...args];
|
|
146
|
+
return ["npx", "--yes", "--package", specifier, program, ...args];
|
|
147
|
+
}
|
|
@@ -12,16 +12,16 @@ import * as s from "@sdxc/json-schema";
|
|
|
12
12
|
export declare const CHANGELOG_FILE = "changelog.jsonl";
|
|
13
13
|
/** One line of the changelog; unknown keys are ignored so a newer file still reads. */
|
|
14
14
|
declare const ENTRY_SCHEMA: s.Schema<{
|
|
15
|
-
type: string;
|
|
16
15
|
title: string;
|
|
16
|
+
type: string;
|
|
17
17
|
body: string;
|
|
18
18
|
release: string;
|
|
19
19
|
package: string;
|
|
20
20
|
breaking: boolean;
|
|
21
21
|
correctedIn?: string | undefined;
|
|
22
22
|
}, {
|
|
23
|
-
type: string;
|
|
24
23
|
title: string;
|
|
24
|
+
type: string;
|
|
25
25
|
body: string;
|
|
26
26
|
release: string;
|
|
27
27
|
package: string;
|
|
@@ -12,15 +12,15 @@ declare const MANIFEST_SCHEMA: s.Schema<{
|
|
|
12
12
|
name?: string | undefined;
|
|
13
13
|
dependencies?: Record<string, string> | undefined;
|
|
14
14
|
devDependencies?: Record<string, string> | undefined;
|
|
15
|
-
packageManager?: string | undefined;
|
|
16
15
|
optionalDependencies?: Record<string, string> | undefined;
|
|
16
|
+
packageManager?: string | undefined;
|
|
17
17
|
scripts?: Record<string, string> | undefined;
|
|
18
18
|
}, {
|
|
19
19
|
name?: string | undefined;
|
|
20
20
|
dependencies?: Record<string, string> | undefined;
|
|
21
21
|
devDependencies?: Record<string, string> | undefined;
|
|
22
|
-
packageManager?: string | undefined;
|
|
23
22
|
optionalDependencies?: Record<string, string> | undefined;
|
|
23
|
+
packageManager?: string | undefined;
|
|
24
24
|
scripts?: Record<string, string> | undefined;
|
|
25
25
|
}>;
|
|
26
26
|
/** The project's `package.json` fields the upgrade reads. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sdxc/kit",
|
|
3
|
-
"version": "2026.11.
|
|
3
|
+
"version": "2026.11.4",
|
|
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": {
|
|
@@ -14,22 +14,24 @@
|
|
|
14
14
|
"./lock.schema.json": "./lock.schema.json"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@sdxc/
|
|
17
|
+
"@sdxc/ci": "2026.11.4",
|
|
18
|
+
"@sdxc/cli": "2026.11.3",
|
|
18
19
|
"@sdxc/codemod": "2026.10.29",
|
|
19
|
-
"@sdxc/cron": "2026.
|
|
20
|
-
"@sdxc/diagram": "2026.
|
|
20
|
+
"@sdxc/cron": "2026.11.3",
|
|
21
|
+
"@sdxc/diagram": "2026.11.3",
|
|
21
22
|
"@sdxc/iife": "2026.10.23",
|
|
22
23
|
"@sdxc/json-schema": "2026.10.24",
|
|
23
|
-
"@sdxc/jsonc": "2026.
|
|
24
|
-
"@sdxc/jsonl": "2026.
|
|
24
|
+
"@sdxc/jsonc": "2026.11.3",
|
|
25
|
+
"@sdxc/jsonl": "2026.11.3",
|
|
26
|
+
"@sdxc/messageformat": "2026.10.23",
|
|
25
27
|
"@sdxc/result": "2026.10.13",
|
|
26
|
-
"@sdxc/semver": "2026.
|
|
28
|
+
"@sdxc/semver": "2026.11.3",
|
|
27
29
|
"oxc-parser": "^0.154.0"
|
|
28
30
|
},
|
|
29
31
|
"peerDependencies": {
|
|
30
32
|
"remix": "3.1.0"
|
|
31
33
|
},
|
|
32
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "f9b4adfc3d85b98a3d628b69cc2e1b9c0b7af2d8",
|
|
33
35
|
"publishConfig": {
|
|
34
36
|
"access": "public"
|
|
35
37
|
},
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "banner",
|
|
3
|
+
"changedIn": "2026.11.3",
|
|
4
|
+
"dependencies": [],
|
|
5
|
+
"exports": [
|
|
6
|
+
"Banner"
|
|
7
|
+
],
|
|
8
|
+
"source": {
|
|
9
|
+
"path": "banner.tsx",
|
|
10
|
+
"content": "/**\n * A full-width strip above a page or the whole app for state that outlives one\n * action: an overdue invoice, a failing integration, a maintenance window. It\n * sits in the flow and pushes the frame down, so it never covers what it warns about.\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 { CircleAlertIcon, CircleCheckIcon, InfoIcon, TriangleAlertIcon, XIcon } from \"@sdxc/icons\";\nimport { bg, border, fg, outline } from \"@sdxc/u/color\";\nimport { rounded, transition } from \"@sdxc/u/effects\";\nimport { mergeMix, raw } from \"@sdxc/u/general\";\nimport { flex, flexWrap, gap, grow, inlineFlex, items, justify, shrink } from \"@sdxc/u/layout\";\nimport { bs, is, minIs, pb, pi } from \"@sdxc/u/size\";\nimport { hover, when } from \"@sdxc/u/state\";\nimport { fontSize, leading, overflowWrap, pretty, weight } from \"@sdxc/u/typography\";\n\nimport type { SemanticColor } from \"@sdxc/ui/utils\";\n\nimport { semanticColorPanel } from \"@sdxc/ui/styles\";\n\n/** Default {@link Banner.Props.color}: an informational strip. */\nconst DEFAULT_COLOR: Banner.Color = \"brand\";\n\n/** Prop types for {@link Banner}. */\nexport namespace Banner {\n\t/** Semantic tone of the strip: warning for billing, danger for a failing integration. */\n\texport type Color = SemanticColor;\n\n\t/** Props accepted by {@link Banner}. */\n\texport interface Props extends Omit<TagProps<\"section\">, \"children\"> {\n\t\t/** Accessible name of the strip's region landmark, such as \"Billing\". */\n\t\tlabel: string;\n\t\t/** Default: `\"brand\"`. */\n\t\tcolor?: Color;\n\t\t/** Leading icon in place of the tone's own, or `null` for none. */\n\t\ticon?: RemixNode;\n\t\t/** The one fixing action, such as an \"Update Payment Method\" button or link. */\n\t\taction?: RemixNode;\n\t\t/**\n\t\t * Lets the reader close the strip through a form, so the server records it\n\t\t * and stops rendering the banner. Leave it out for state that needs resolving.\n\t\t */\n\t\tdismiss?: Dismiss;\n\t\t/** The message: what is wrong and what fixing it changes, in a sentence or two. */\n\t\tchildren: RemixNode;\n\t}\n\n\t/** How a dismissible {@link Banner} closes. */\n\texport interface Dismiss {\n\t\t/** Accessible name of the close button, such as \"Dismiss\". */\n\t\tlabel: string;\n\t\t/** URL the dismissal submits to. */\n\t\taction: string;\n\t\t/** Default: `\"post\"`. */\n\t\tmethod?: \"get\" | \"post\";\n\t\t/** Hidden fields sent with it, such as the banner's id. */\n\t\tfields?: Record<string, string>;\n\t}\n}\n\n/**\n * Renders the strip as a named region: tone icon, message, one action, and a\n * close form only when `dismiss` is given. One banner at a time; it wraps on a\n * phone and flows above the app frame, pushing it down.\n *\n * @param handle Runtime handle carrying the host `<section>`'s props.\n * @returns The render function producing the strip's markup.\n * @example\n * <Banner color=\"warning\" label={t(\"billing.region\")} action={<Button href=\"/billing\">{t(\"billing.update\")}</Button>}>\n * \t{t(\"billing.declined\")}\n * </Banner>\n * @example\n * <Banner label={t(\"maintenance.region\")} dismiss={{ label: t(\"actions.dismiss\"), action: \"/banners/dismiss\", fields: { id: \"maintenance\" } }}>\n * \t{t(\"maintenance.message\")}\n * </Banner>\n */\nexport function Banner(handle: Handle<Banner.Props>) {\n\treturn () => {\n\t\tlet {\n\t\t\tlabel,\n\t\t\tcolor = DEFAULT_COLOR,\n\t\t\ticon,\n\t\t\taction,\n\t\t\tdismiss,\n\t\t\tchildren,\n\t\t\tmix,\n\t\t\t...rest\n\t\t} = handle.props;\n\t\tlet toneIcon = icon === null ? null : (icon ?? <BannerToneIcon color={color} />);\n\n\t\treturn (\n\t\t\t<section\n\t\t\t\taria-label={label}\n\t\t\t\t{...rest}\n\t\t\t\tdata-color={color}\n\t\t\t\tdata-slot=\"banner\"\n\t\t\t\tmix={mergeMix(\n\t\t\t\t\t[\n\t\t\t\t\t\tsemanticColorPanel(),\n\t\t\t\t\t\tflex(),\n\t\t\t\t\t\tflexWrap(),\n\t\t\t\t\t\titems(\"center\"),\n\t\t\t\t\t\tgap(3),\n\t\t\t\t\t\tis(\"full\"),\n\t\t\t\t\t\tminIs(0),\n\t\t\t\t\t\tpb(\"0.5rem\"),\n\t\t\t\t\t\tpi(\"1rem\"),\n\t\t\t\t\t\traw({ borderWidth: \"0\", borderBlockEndWidth: \"1px\", borderStyle: \"solid\" }),\n\t\t\t\t\t\tfontSize(\"sm\"),\n\t\t\t\t\t],\n\t\t\t\t\tmix,\n\t\t\t\t)}\n\t\t\t>\n\t\t\t\t{toneIcon ? (\n\t\t\t\t\t<span\n\t\t\t\t\t\taria-hidden=\"true\"\n\t\t\t\t\t\tdata-slot=\"banner-icon\"\n\t\t\t\t\t\tmix={[inlineFlex(), shrink(0), fg(\"currentcolor\")]}\n\t\t\t\t\t>\n\t\t\t\t\t\t{toneIcon}\n\t\t\t\t\t</span>\n\t\t\t\t) : null}\n\t\t\t\t<p\n\t\t\t\t\tdata-slot=\"banner-message\"\n\t\t\t\t\tmix={[\n\t\t\t\t\t\tgrow(),\n\t\t\t\t\t\traw({ flexBasis: \"16rem\" }),\n\t\t\t\t\t\tminIs(0),\n\t\t\t\t\t\tleading(\"snug\"),\n\t\t\t\t\t\tweight(\"medium\"),\n\t\t\t\t\t\tpretty(),\n\t\t\t\t\t\toverflowWrap(\"anywhere\"),\n\t\t\t\t\t]}\n\t\t\t\t>\n\t\t\t\t\t{children}\n\t\t\t\t</p>\n\t\t\t\t{action ? (\n\t\t\t\t\t<div data-slot=\"banner-action\" mix={[flex(), items(\"center\"), shrink(0)]}>\n\t\t\t\t\t\t{action}\n\t\t\t\t\t</div>\n\t\t\t\t) : null}\n\t\t\t\t{dismiss ? <BannerDismiss dismiss={dismiss} /> : null}\n\t\t\t</section>\n\t\t);\n\t};\n}\n\n/**\n * Picks the icon a tone carries, so a warning and a failure read apart before\n * the message does.\n *\n * @param handle Runtime handle carrying the banner's tone.\n * @returns The render function producing the icon.\n */\nfunction BannerToneIcon(handle: Handle<{ color: Banner.Color }>) {\n\treturn () => {\n\t\tlet { color } = handle.props;\n\t\tif (color === \"success\") return <CircleCheckIcon size={16} />;\n\t\tif (color === \"danger\") return <CircleAlertIcon size={16} />;\n\t\tif (color === \"warning\") return <TriangleAlertIcon size={16} />;\n\t\treturn <InfoIcon size={16} />;\n\t};\n}\n\n/**\n * The close control of a dismissible {@link Banner}: an icon button that\n * submits its form, so the dismissal reaches the server with or without\n * JavaScript and the banner stays gone on the next page.\n *\n * @param handle Runtime handle carrying the dismissal form.\n * @returns The render function producing the form's markup.\n */\nfunction BannerDismiss(handle: Handle<{ dismiss: Banner.Dismiss }>) {\n\treturn () => {\n\t\tlet { dismiss } = handle.props;\n\n\t\treturn (\n\t\t\t<form\n\t\t\t\tmethod={dismiss.method ?? \"post\"}\n\t\t\t\taction={dismiss.action}\n\t\t\t\tdata-slot=\"banner-dismiss\"\n\t\t\t\tmix={[flex(), shrink(0), raw({ marginInlineStart: \"auto\" })]}\n\t\t\t>\n\t\t\t\t{Object.entries(dismiss.fields ?? {}).map(([name, value]) => (\n\t\t\t\t\t<input key={name} type=\"hidden\" name={name} value={value} />\n\t\t\t\t))}\n\t\t\t\t<button\n\t\t\t\t\ttype=\"submit\"\n\t\t\t\t\taria-label={dismiss.label}\n\t\t\t\t\ttitle={dismiss.label}\n\t\t\t\t\tmix={[\n\t\t\t\t\t\tinlineFlex(),\n\t\t\t\t\t\titems(\"center\"),\n\t\t\t\t\t\tjustify(\"center\"),\n\t\t\t\t\t\tis(\"2rem\"),\n\t\t\t\t\t\tbs(\"2rem\"),\n\t\t\t\t\t\trounded(\"md\"),\n\t\t\t\t\t\tborder({ width: 0 }),\n\t\t\t\t\t\tbg(\"transparent\"),\n\t\t\t\t\t\tfg(\"currentcolor\"),\n\t\t\t\t\t\ttransition(\"background-color\"),\n\t\t\t\t\t\thover(bg(\"neutral.bg-tint-hover\")),\n\t\t\t\t\t\twhen(\"&:focus-visible\", outline({ color: \"brand.ring\", width: 2 })),\n\t\t\t\t\t]}\n\t\t\t\t>\n\t\t\t\t\t<XIcon size={16} />\n\t\t\t\t</button>\n\t\t\t</form>\n\t\t);\n\t};\n}\n"
|
|
11
|
+
},
|
|
12
|
+
"test": {
|
|
13
|
+
"path": "banner.browser.test.tsx",
|
|
14
|
+
"content": "/**\n * Lays the banner out in a real browser: a named region in the flow that pushes the\n * app frame down instead of covering it, no close control unless dismissible, a\n * dismissal that is a real form, and a 320px phone that wraps instead of overflowing.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type {} from \"@vitest/browser-playwright\";\nimport type { RenderResult } from \"remix/component/test\";\n\nimport { render } from \"remix/component/test\";\nimport { afterEach, describe, expect, test } from \"vitest\";\nimport { page } from \"vitest/browser\";\n\nimport { Banner } from \"@sdxc/ui/banner\";\n\nimport \"@sdxc/ui/reset.css\";\n\nlet mounted: RenderResult | undefined;\n\nafterEach(async () => {\n\tmounted?.cleanup();\n\tmounted = undefined;\n\tdocument.body.replaceChildren();\n\tawait page.viewport(1280, 800);\n});\n\n/** Mounts `node` in a host `width` pixels wide and returns the host. */\nfunction mount(node: JSX.Element, width = 1024): HTMLElement {\n\tlet host = document.createElement(\"div\");\n\thost.style.width = `${width}px`;\n\tdocument.body.appendChild(host);\n\tmounted = render(node, { container: host });\n\treturn host;\n}\n\n/** The fixing action a billing banner offers. */\nfunction UpdateLink() {\n\treturn () => <a href=\"/billing\">Update Payment Method</a>;\n}\n\ndescribe(\"Banner\", () => {\n\ttest(\"is a named region in the flow that pushes the app frame down\", () => {\n\t\tlet host = mount(\n\t\t\t<>\n\t\t\t\t<Banner color=\"warning\" label=\"Billing\" action={<UpdateLink />}>\n\t\t\t\t\tYour card was declined. Update it to keep monitors running.\n\t\t\t\t</Banner>\n\t\t\t\t<main data-testid=\"frame\">Dashboard</main>\n\t\t\t</>,\n\t\t);\n\t\tlet banner = host.querySelector<HTMLElement>('[data-slot=\"banner\"]')!;\n\t\tlet frame = host.querySelector<HTMLElement>('[data-testid=\"frame\"]')!;\n\n\t\texpect(banner.tagName).toBe(\"SECTION\");\n\t\texpect(banner.getAttribute(\"aria-label\")).toBe(\"Billing\");\n\t\texpect(getComputedStyle(banner).position).toBe(\"static\");\n\t\texpect(frame.getBoundingClientRect().top).toBeCloseTo(banner.getBoundingClientRect().bottom, 1);\n\t\texpect(banner.getBoundingClientRect().width).toBe(1024);\n\t});\n\n\ttest(\"draws the tone's icon, hidden from assistive technology, unless told otherwise\", () => {\n\t\tlet host = mount(\n\t\t\t<>\n\t\t\t\t<Banner color=\"danger\" label=\"Integrations\" data-testid=\"toned\">\n\t\t\t\t\tSlack stopped accepting alerts.\n\t\t\t\t</Banner>\n\t\t\t\t<Banner color=\"danger\" label=\"Integrations\" icon={null} data-testid=\"bare\">\n\t\t\t\t\tSlack stopped accepting alerts.\n\t\t\t\t</Banner>\n\t\t\t</>,\n\t\t);\n\n\t\tlet icon = host.querySelector('[data-testid=\"toned\"] [data-slot=\"banner-icon\"]')!;\n\t\texpect(icon.getAttribute(\"aria-hidden\")).toBe(\"true\");\n\t\texpect(icon.querySelector(\"svg\")).not.toBeNull();\n\t\texpect(host.querySelector('[data-testid=\"bare\"] [data-slot=\"banner-icon\"]')).toBeNull();\n\t});\n\n\ttest(\"offers no close control while the state needs resolving\", () => {\n\t\tlet host = mount(\n\t\t\t<Banner color=\"warning\" label=\"Billing\" action={<UpdateLink />}>\n\t\t\t\tYour card was declined.\n\t\t\t</Banner>,\n\t\t);\n\n\t\texpect(host.querySelector(\"button\")).toBeNull();\n\t\texpect(host.querySelector(\"form\")).toBeNull();\n\t\texpect(host.querySelectorAll('[data-slot=\"banner-action\"] a')).toHaveLength(1);\n\t});\n\n\ttest(\"dismisses through a real form when dismissible\", () => {\n\t\tlet host = mount(\n\t\t\t<Banner\n\t\t\t\tlabel=\"Maintenance\"\n\t\t\t\tdismiss={{\n\t\t\t\t\tlabel: \"Dismiss\",\n\t\t\t\t\taction: \"/banners/dismiss\",\n\t\t\t\t\tfields: { id: \"maintenance-nov\" },\n\t\t\t\t}}\n\t\t\t>\n\t\t\t\tChecks pause for 10 minutes on Sunday at 02:00 UTC.\n\t\t\t</Banner>,\n\t\t);\n\t\tlet form = host.querySelector(\"form\")!;\n\t\tlet button = form.querySelector(\"button\")!;\n\n\t\texpect(form.getAttribute(\"method\")).toBe(\"post\");\n\t\texpect(form.getAttribute(\"action\")).toBe(\"/banners/dismiss\");\n\t\texpect(new FormData(form).get(\"id\")).toBe(\"maintenance-nov\");\n\t\texpect(button.type).toBe(\"submit\");\n\t\texpect(button.getAttribute(\"aria-label\")).toBe(\"Dismiss\");\n\t});\n\n\ttest(\"wraps on a 320px phone without scrolling sideways\", async () => {\n\t\tawait page.viewport(320, 640);\n\t\tlet host = mount(\n\t\t\t<Banner\n\t\t\t\tcolor=\"warning\"\n\t\t\t\tlabel=\"Billing\"\n\t\t\t\taction={<UpdateLink />}\n\t\t\t\tdismiss={{ label: \"Dismiss\", action: \"/banners/dismiss\" }}\n\t\t\t>\n\t\t\t\tYour card ending 4242 was declined three times. Update it to keep 48 monitors running.\n\t\t\t</Banner>,\n\t\t\t320,\n\t\t);\n\t\tlet banner = host.querySelector<HTMLElement>('[data-slot=\"banner\"]')!;\n\n\t\texpect(banner.scrollWidth).toBeLessThanOrEqual(banner.clientWidth);\n\t\texpect(document.documentElement.scrollWidth).toBeLessThanOrEqual(320);\n\t\tlet action = host.querySelector('[data-slot=\"banner-action\"]')!.getBoundingClientRect();\n\t\tlet message = host.querySelector('[data-slot=\"banner-message\"]')!.getBoundingClientRect();\n\t\texpect(action.top).toBeGreaterThanOrEqual(message.bottom);\n\t});\n});\n"
|
|
15
|
+
}
|
|
16
|
+
}
|
package/registry/ui/confirm.json
CHANGED
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "confirm",
|
|
3
|
-
"changedIn": "2026.
|
|
3
|
+
"changedIn": "2026.11.3",
|
|
4
4
|
"dependencies": [
|
|
5
5
|
"alert-dialog",
|
|
6
|
-
"button"
|
|
6
|
+
"button",
|
|
7
|
+
"input",
|
|
8
|
+
"label"
|
|
7
9
|
],
|
|
8
10
|
"exports": [
|
|
9
|
-
"Confirm"
|
|
11
|
+
"Confirm",
|
|
12
|
+
"ConfirmPhraseProps",
|
|
13
|
+
"ConfirmPhrase"
|
|
10
14
|
],
|
|
11
15
|
"source": {
|
|
12
16
|
"path": "confirm.tsx",
|
|
13
|
-
"content": "/**\n * A convenience wrapper composing a two-control confirmation prompt in one\n * call: an {@link AlertDialog} panel prefilled with a heading, an optional\n * supporting passage, and a cancel/confirm control pair, so a single\n * consequential decision needs no compound assembly of its own. The\n * confirming control defaults to the semantic danger tone, keeping an\n * irreversible action behind an explicit confirmation step in that tone.\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 { flex, flexCol, gap } from \"@sdxc/u/layout\";\n\nimport type { Button } from \"@sdxc/ui/button\";\n\nimport { AlertDialog } from \"@sdxc/ui/alert-dialog\";\n\n/** Semantic color role {@link Confirm} falls back to when `color` is omitted. */\nconst DEFAULT_COLOR: Button.Color = \"danger\";\n\n/** HTTP method a submitting {@link Confirm} falls back to when `form.method` is omitted. */\nconst DEFAULT_METHOD: NonNullable<Confirm.FormProps[\"method\"]> = \"post\";\n\n/**\n * Column gap the wrapping `<form>` re-declares in submit mode, matching the\n * panel's own child gap — the form becomes the panel's single child, so\n * without this the header and footer would lose their spacing.\n */\nconst PANEL_GAP = 6;\n\n/**\n * Prop types for {@link Confirm}.\n */\nexport namespace Confirm {\n\t/**\n\t * Per-part styling for the elements this convenience wrapper composes in\n\t * one call, layered after each part's own built-in styling.\n\t */\n\texport interface PartsProps {\n\t\t/** Styling for the header slot wrapping the title and description, rendered through {@link AlertDialog.Header}. */\n\t\theader?: TagProps<\"div\">[\"mix\"];\n\t\t/** Styling for the heading, rendered through {@link AlertDialog.Title}, whichever heading tag its ambient level resolves to. */\n\t\ttitle?: TagProps<\"h1\" | \"h2\" | \"h3\" | \"h4\" | \"h5\" | \"h6\">[\"mix\"];\n\t\t/** Styling for the supporting description, rendered through {@link AlertDialog.Description} only when `description` is set. */\n\t\tdescription?: TagProps<\"p\">[\"mix\"];\n\t\t/** Styling for the action row wrapping the cancel and confirm controls, rendered through {@link AlertDialog.Footer}. */\n\t\tfooter?: TagProps<\"div\">[\"mix\"];\n\t\t/** Styling for the control that backs out without confirming, rendered through {@link AlertDialog.Cancel}. */\n\t\tcancel?: TagProps<\"button\">[\"mix\"];\n\t\t/** Styling for the confirming control, rendered through {@link AlertDialog.Action}. */\n\t\taction?: TagProps<\"button\">[\"mix\"];\n\t\t/** Styling for the `<form>` wrapping the panel's content, rendered only in submit mode. */\n\t\tform?: TagProps<\"form\">[\"mix\"];\n\t}\n\n\t/**\n\t * The submission a confirming control performs instead of merely closing\n\t * the panel. Passing this switches {@link Confirm} into submit mode, where\n\t * the form's response is what ends the interruption.\n\t */\n\texport interface FormProps {\n\t\t/** URL the confirmation submits to. Omit to submit to the current URL, as a native `<form>` with no `action` does. */\n\t\taction?: string;\n\t\t/** HTTP method the confirmation submits with. Defaults to {@link DEFAULT_METHOD}, since a confirmed action changes state. */\n\t\tmethod?: \"get\" | \"post\";\n\t\t/**\n\t\t * Hidden inputs submitted along with the confirmation — a CSRF token,\n\t\t * an intent discriminator, the id of the record being acted on. They\n\t\t * render first inside the form, before the panel's own content.\n\t\t */\n\t\tfields?: RemixNode;\n\t}\n\n\t/**\n\t * Props accepted by {@link Confirm}. `mix` styles the underlying\n\t * {@link AlertDialog} host directly; style the composed header, title,\n\t * description, footer, and controls individually through `parts` instead.\n\t */\n\texport interface Props extends Omit<AlertDialog.Props, \"id\" | \"children\" | \"title\"> {\n\t\t/**\n\t\t * Stable identifier the panel renders as its own `id`; a trigger\n\t\t * elsewhere on the page targets it via `commandfor`/`command=\"show-modal\"`,\n\t\t * and the cancel and confirm controls point back at it automatically.\n\t\t */\n\t\tid: string;\n\t\t/** The panel's heading, rendered through {@link AlertDialog.Title}. */\n\t\ttitle: RemixNode;\n\t\t/**\n\t\t * Supporting copy rendered through {@link AlertDialog.Description}\n\t\t * beneath the title. Omit to render no description.\n\t\t */\n\t\tdescription?: RemixNode;\n\t\t/** Label for the confirming control, rendered through {@link AlertDialog.Action}. */\n\t\tconfirmLabel: RemixNode;\n\t\t/** Label for the control that backs out without confirming, rendered through {@link AlertDialog.Cancel}. */\n\t\tcancelLabel: RemixNode;\n\t\t/** Semantic color for the confirming control. Defaults to {@link DEFAULT_COLOR}. */\n\t\tcolor?: Button.Color;\n\t\t/**\n\t\t * Submission the confirming control performs. Omitting it leaves\n\t\t * confirming as a close-only action for the page to react to; setting it\n\t\t * submits a real form instead.\n\t\t */\n\t\tform?: FormProps;\n\t\t/** Per-part styling for this wrapper's internally composed elements. */\n\t\tparts?: PartsProps;\n\t}\n}\n\n/**\n * Composes {@link AlertDialog} into a confirmation prompt, wiring title and\n * description ids to `aria-labelledby`/`aria-describedby`. Omit\n * {@link Confirm.Props.form} to close on confirm, or pass it to submit a real `<form>` instead.\n *\n * @param handle Runtime handle carrying the panel's props and this instance's stable identifier.\n * @returns The render function producing the confirmation prompt's markup.\n * @example\n * <Button commandfor=\"confirm-delete\" command=\"show-modal\" color=\"danger\">{t(\"project.delete\")}</Button>\n * <Confirm\n * \tid=\"confirm-delete\"\n * \ttitle={t(\"project.deleteTitle\")}\n * \tdescription={t(\"project.deleteDescription\")}\n * \tconfirmLabel={t(\"actions.delete\")}\n * \tcancelLabel={t(\"actions.cancel\")}\n * />\n * @example\n * <Confirm\n * \tid=\"publish-post\"\n * \ttitle={t(\"post.publishTitle\")}\n * \tconfirmLabel={t(\"actions.publish\")}\n * \tcancelLabel={t(\"actions.cancel\")}\n * \tcolor=\"brand\"\n * />\n * @example\n * <Confirm\n * \tid=\"revoke-session\"\n * \ttitle={t(\"session.revokeTitle\")}\n * \tconfirmLabel={t(\"actions.revoke\")}\n * \tcancelLabel={t(\"actions.cancel\")}\n * \tform={{ action: revokeUrl, fields: <input type=\"hidden\" name=\"csrf\" value={token} /> }}\n * />\n */\nexport function Confirm(handle: Handle<Confirm.Props>) {\n\treturn () => {\n\t\tlet {\n\t\t\tid,\n\t\t\ttitle,\n\t\t\tdescription,\n\t\t\tconfirmLabel,\n\t\t\tcancelLabel,\n\t\t\tcolor,\n\t\t\tform,\n\t\t\t\"aria-labelledby\": ariaLabelledByProp,\n\t\t\t\"aria-describedby\": ariaDescribedByProp,\n\t\t\tparts,\n\t\t\tmix,\n\t\t\t...rest\n\t\t} = handle.props;\n\t\tlet resolvedColor = color ?? DEFAULT_COLOR;\n\t\tlet titleId = `${handle.id}-title`;\n\t\tlet descriptionId = description ? `${handle.id}-description` : undefined;\n\t\tlet content = (\n\t\t\t<>\n\t\t\t\t<AlertDialog.Header mix={parts?.header}>\n\t\t\t\t\t<AlertDialog.Title id={titleId} mix={parts?.title}>\n\t\t\t\t\t\t{title}\n\t\t\t\t\t</AlertDialog.Title>\n\t\t\t\t\t{description ? (\n\t\t\t\t\t\t<AlertDialog.Description id={descriptionId} mix={parts?.description}>\n\t\t\t\t\t\t\t{description}\n\t\t\t\t\t\t</AlertDialog.Description>\n\t\t\t\t\t) : null}\n\t\t\t\t</AlertDialog.Header>\n\t\t\t\t<AlertDialog.Footer mix={parts?.footer}>\n\t\t\t\t\t<AlertDialog.Cancel commandfor={id} mix={parts?.cancel}>\n\t\t\t\t\t\t{cancelLabel}\n\t\t\t\t\t</AlertDialog.Cancel>\n\t\t\t\t\t<AlertDialog.Action\n\t\t\t\t\t\ttype={form ? \"submit\" : undefined}\n\t\t\t\t\t\tcommandfor={form ? undefined : id}\n\t\t\t\t\t\tcolor={resolvedColor}\n\t\t\t\t\t\tmix={parts?.action}\n\t\t\t\t\t>\n\t\t\t\t\t\t{confirmLabel}\n\t\t\t\t\t</AlertDialog.Action>\n\t\t\t\t</AlertDialog.Footer>\n\t\t\t</>\n\t\t);\n\n\t\treturn (\n\t\t\t<AlertDialog\n\t\t\t\t{...rest}\n\t\t\t\tid={id}\n\t\t\t\taria-labelledby={ariaLabelledByProp ?? titleId}\n\t\t\t\taria-describedby={ariaDescribedByProp ?? descriptionId}\n\t\t\t\tmix={mix}\n\t\t\t>\n\t\t\t\t{form ? (\n\t\t\t\t\t<form\n\t\t\t\t\t\taction={form.action}\n\t\t\t\t\t\tmethod={form.method ?? DEFAULT_METHOD}\n\t\t\t\t\t\tmix={[flex(), flexCol(), gap(PANEL_GAP), parts?.form]}\n\t\t\t\t\t>\n\t\t\t\t\t\t{form.fields}\n\t\t\t\t\t\t{content}\n\t\t\t\t\t</form>\n\t\t\t\t) : (\n\t\t\t\t\tcontent\n\t\t\t\t)}\n\t\t\t</AlertDialog>\n\t\t);\n\t};\n}\n"
|
|
17
|
+
"content": "/**\n * A convenience wrapper composing a two-control confirmation prompt in one\n * call: an {@link AlertDialog} panel prefilled with a heading, an optional\n * supporting passage, and a cancel/confirm control pair, so a single\n * consequential decision needs no compound assembly of its own. The\n * confirming control defaults to the semantic danger tone, and a\n * type-to-confirm variant holds a big irreversible action until its name is typed.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type { EntryComponent, Handle, Props as TagProps, RemixNode } from \"remix/component\";\n\nimport { flex, flexCol, gap, vstack } from \"@sdxc/u/layout\";\nimport { clientEntry } from \"remix/component\";\n\nimport { confirmPhrase } from \"@sdxc/ui/mixins\";\n\nimport type { Button } from \"@sdxc/ui/button\";\n\nimport { AlertDialog } from \"@sdxc/ui/alert-dialog\";\nimport { Input } from \"@sdxc/ui/input\";\nimport { Label } from \"@sdxc/ui/label\";\n\n/** Semantic color role {@link Confirm} falls back to when `color` is omitted. */\nconst DEFAULT_COLOR: Button.Color = \"danger\";\n\n/** HTTP method a submitting {@link Confirm} falls back to when `form.method` is omitted. */\nconst DEFAULT_METHOD: NonNullable<Confirm.FormProps[\"method\"]> = \"post\";\n\n/**\n * Column gap the wrapping `<form>` re-declares in submit mode, matching the\n * panel's own child gap — the form becomes the panel's single child, so\n * without this the header and footer would lose their spacing.\n */\nconst PANEL_GAP = 6;\n\n/** Characters a `pattern` (compiled with the `v` flag) reads as syntax, escaped to match literally. */\nconst PATTERN_SYNTAX = /[\\\\^$.*+?()[\\]{}|/]/g;\n\n/**\n * Prop types for {@link Confirm}.\n */\nexport namespace Confirm {\n\t/**\n\t * Per-part styling for the elements this convenience wrapper composes in\n\t * one call, layered after each part's own built-in styling.\n\t */\n\texport interface PartsProps {\n\t\t/** Styling for the header slot wrapping the title and description, rendered through {@link AlertDialog.Header}. */\n\t\theader?: TagProps<\"div\">[\"mix\"];\n\t\t/** Styling for the heading, rendered through {@link AlertDialog.Title}, whichever heading tag its ambient level resolves to. */\n\t\ttitle?: TagProps<\"h1\" | \"h2\" | \"h3\" | \"h4\" | \"h5\" | \"h6\">[\"mix\"];\n\t\t/** Styling for the supporting description, rendered through {@link AlertDialog.Description} only when `description` is set. */\n\t\tdescription?: TagProps<\"p\">[\"mix\"];\n\t\t/** Styling for the action row wrapping the cancel and confirm controls, rendered through {@link AlertDialog.Footer}. */\n\t\tfooter?: TagProps<\"div\">[\"mix\"];\n\t\t/** Styling for the control that backs out without confirming, rendered through {@link AlertDialog.Cancel}. */\n\t\tcancel?: TagProps<\"button\">[\"mix\"];\n\t\t/** Styling for the confirming control, rendered through {@link AlertDialog.Action}. */\n\t\taction?: TagProps<\"button\">[\"mix\"];\n\t\t/** Styling for the `<form>` wrapping the panel's content, rendered only in submit mode. */\n\t\tform?: TagProps<\"form\">[\"mix\"];\n\t}\n\n\t/**\n\t * The submission a confirming control performs instead of merely closing\n\t * the panel. Passing this switches {@link Confirm} into submit mode, where\n\t * the form's response is what ends the interruption.\n\t */\n\texport interface FormProps {\n\t\t/** URL the confirmation submits to. Omit to submit to the current URL, as a native `<form>` with no `action` does. */\n\t\taction?: string;\n\t\t/** HTTP method the confirmation submits with. Defaults to {@link DEFAULT_METHOD}, since a confirmed action changes state. */\n\t\tmethod?: \"get\" | \"post\";\n\t\t/**\n\t\t * Hidden inputs submitted along with the confirmation — a CSRF token,\n\t\t * an intent discriminator, the id of the record being acted on. They\n\t\t * render first inside the form, before the panel's own content.\n\t\t */\n\t\tfields?: RemixNode;\n\t}\n\n\t/**\n\t * The phrase a person types before a big irreversible action unlocks, such as\n\t * the team's name. Reserve it for deleting something large; on routine\n\t * confirms it reads as melodrama.\n\t */\n\texport interface TypeToConfirm {\n\t\t/** The exact text that unlocks the confirming control, compared case-sensitively. */\n\t\tvalue: string;\n\t\t/** The field's label, such as `Type \"acme\" to confirm`. */\n\t\tlabel: RemixNode;\n\t\t/** Name the typed text submits under in submit mode, so the server can check it again. */\n\t\tname?: string;\n\t}\n\n\t/**\n\t * Props accepted by {@link Confirm}. `mix` styles the underlying\n\t * {@link AlertDialog} host directly; style the composed header, title,\n\t * description, footer, and controls individually through `parts` instead.\n\t */\n\texport interface Props extends Omit<AlertDialog.Props, \"id\" | \"children\" | \"title\"> {\n\t\t/**\n\t\t * Stable identifier the panel renders as its own `id`; a trigger\n\t\t * elsewhere on the page targets it via `commandfor`/`command=\"show-modal\"`,\n\t\t * and the cancel and confirm controls point back at it automatically.\n\t\t */\n\t\tid: string;\n\t\t/** The panel's heading, rendered through {@link AlertDialog.Title}. */\n\t\ttitle: RemixNode;\n\t\t/**\n\t\t * Supporting copy rendered through {@link AlertDialog.Description}\n\t\t * beneath the title. Omit to render no description.\n\t\t */\n\t\tdescription?: RemixNode;\n\t\t/** Label for the confirming control, rendered through {@link AlertDialog.Action}. */\n\t\tconfirmLabel: RemixNode;\n\t\t/** Label for the control that backs out without confirming, rendered through {@link AlertDialog.Cancel}. */\n\t\tcancelLabel: RemixNode;\n\t\t/** Semantic color for the confirming control. Defaults to {@link DEFAULT_COLOR}. */\n\t\tcolor?: Button.Color;\n\t\t/**\n\t\t * Submission the confirming control performs. Omitting it leaves\n\t\t * confirming as a close-only action for the page to react to; setting it\n\t\t * submits a real form instead.\n\t\t */\n\t\tform?: FormProps;\n\t\t/**\n\t\t * Holds the confirming control disabled until this phrase is typed. Without\n\t\t * script the field's `pattern` blocks the submission instead.\n\t\t */\n\t\ttypeToConfirm?: TypeToConfirm;\n\t\t/** Per-part styling for this wrapper's internally composed elements. */\n\t\tparts?: PartsProps;\n\t}\n}\n\n/**\n * Composes {@link AlertDialog} into a confirmation prompt, wiring title and\n * description ids to `aria-labelledby`/`aria-describedby`. Focus opens on Cancel, or\n * on the phrase field with `typeToConfirm`; pass `form` to submit a real `<form>`.\n *\n * @param handle Runtime handle carrying the panel's props and this instance's stable identifier.\n * @returns The render function producing the confirmation prompt's markup.\n * @example\n * <Button commandfor=\"confirm-delete\" command=\"show-modal\" color=\"danger\">{t(\"project.delete\")}</Button>\n * <Confirm\n * \tid=\"confirm-delete\"\n * \ttitle={t(\"project.deleteTitle\")}\n * \tdescription={t(\"project.deleteDescription\")}\n * \tconfirmLabel={t(\"actions.delete\")}\n * \tcancelLabel={t(\"actions.cancel\")}\n * />\n * @example\n * <Confirm\n * \tid=\"publish-post\"\n * \ttitle={t(\"post.publishTitle\")}\n * \tconfirmLabel={t(\"actions.publish\")}\n * \tcancelLabel={t(\"actions.cancel\")}\n * \tcolor=\"brand\"\n * />\n * @example\n * <Confirm\n * \tid=\"revoke-session\"\n * \ttitle={t(\"session.revokeTitle\")}\n * \tconfirmLabel={t(\"actions.revoke\")}\n * \tcancelLabel={t(\"actions.cancel\")}\n * \tform={{ action: revokeUrl, fields: <input type=\"hidden\" name=\"csrf\" value={token} /> }}\n * />\n * @example\n * <Confirm\n * \tid=\"delete-team\"\n * \ttitle=\"Delete team?\"\n * \tdescription=\"Acme, its 12 monitors and their history are deleted.\"\n * \tconfirmLabel=\"Delete team\"\n * \tcancelLabel=\"Cancel\"\n * \ttypeToConfirm={{ value: \"acme\", label: 'Type \"acme\" to confirm', name: \"confirmation\" }}\n * \tform={{ action: \"/teams/acme/delete\" }}\n * />\n */\nexport function Confirm(handle: Handle<Confirm.Props>) {\n\treturn () => {\n\t\tlet {\n\t\t\tid,\n\t\t\ttitle,\n\t\t\tdescription,\n\t\t\tconfirmLabel,\n\t\t\tcancelLabel,\n\t\t\tcolor,\n\t\t\tform,\n\t\t\ttypeToConfirm,\n\t\t\t\"aria-labelledby\": ariaLabelledByProp,\n\t\t\t\"aria-describedby\": ariaDescribedByProp,\n\t\t\tparts,\n\t\t\tmix,\n\t\t\t...rest\n\t\t} = handle.props;\n\t\tlet resolvedColor = color ?? DEFAULT_COLOR;\n\t\tlet titleId = `${handle.id}-title`;\n\t\tlet descriptionId = description ? `${handle.id}-description` : undefined;\n\t\tlet content = (\n\t\t\t<>\n\t\t\t\t<AlertDialog.Header mix={parts?.header}>\n\t\t\t\t\t<AlertDialog.Title id={titleId} mix={parts?.title}>\n\t\t\t\t\t\t{title}\n\t\t\t\t\t</AlertDialog.Title>\n\t\t\t\t\t{description ? (\n\t\t\t\t\t\t<AlertDialog.Description id={descriptionId} mix={parts?.description}>\n\t\t\t\t\t\t\t{description}\n\t\t\t\t\t\t</AlertDialog.Description>\n\t\t\t\t\t) : null}\n\t\t\t\t</AlertDialog.Header>\n\t\t\t\t{typeToConfirm ? (\n\t\t\t\t\t<ConfirmPhrase\n\t\t\t\t\t\tid={`${handle.id}-phrase`}\n\t\t\t\t\t\tvalue={typeToConfirm.value}\n\t\t\t\t\t\tlabel={typeToConfirm.label}\n\t\t\t\t\t\tname={typeToConfirm.name}\n\t\t\t\t\t/>\n\t\t\t\t) : null}\n\t\t\t\t<AlertDialog.Footer mix={parts?.footer}>\n\t\t\t\t\t{/* oxlint-disable-next-line jsx-a11y/no-autofocus -- Focus inside an opened modal, where a destructive confirm starts on the safe choice. */}\n\t\t\t\t\t<AlertDialog.Cancel\n\t\t\t\t\t\tcommandfor={id}\n\t\t\t\t\t\tautofocus={typeToConfirm ? undefined : true}\n\t\t\t\t\t\tmix={parts?.cancel}\n\t\t\t\t\t>\n\t\t\t\t\t\t{cancelLabel}\n\t\t\t\t\t</AlertDialog.Cancel>\n\t\t\t\t\t<AlertDialog.Action\n\t\t\t\t\t\tdata-confirm-action=\"\"\n\t\t\t\t\t\ttype={form ? \"submit\" : undefined}\n\t\t\t\t\t\tcommandfor={form ? undefined : id}\n\t\t\t\t\t\tcolor={resolvedColor}\n\t\t\t\t\t\tmix={parts?.action}\n\t\t\t\t\t>\n\t\t\t\t\t\t{confirmLabel}\n\t\t\t\t\t</AlertDialog.Action>\n\t\t\t\t</AlertDialog.Footer>\n\t\t\t</>\n\t\t);\n\n\t\treturn (\n\t\t\t<AlertDialog\n\t\t\t\t{...rest}\n\t\t\t\tid={id}\n\t\t\t\taria-labelledby={ariaLabelledByProp ?? titleId}\n\t\t\t\taria-describedby={ariaDescribedByProp ?? descriptionId}\n\t\t\t\tmix={mix}\n\t\t\t>\n\t\t\t\t{form ? (\n\t\t\t\t\t<form\n\t\t\t\t\t\taction={form.action}\n\t\t\t\t\t\tmethod={form.method ?? DEFAULT_METHOD}\n\t\t\t\t\t\tmix={[flex(), flexCol(), gap(PANEL_GAP), parts?.form]}\n\t\t\t\t\t>\n\t\t\t\t\t\t{form.fields}\n\t\t\t\t\t\t{content}\n\t\t\t\t\t</form>\n\t\t\t\t) : (\n\t\t\t\t\tcontent\n\t\t\t\t)}\n\t\t\t</AlertDialog>\n\t\t);\n\t};\n}\n\n/**\n * Props {@link ConfirmPhrase} serializes into the page for hydration, which is why they are\n * a `type`: `SerializableProps` rejects an interface.\n */\nexport type ConfirmPhraseProps = {\n\t/** The input's `id`, which its label points at. */\n\tid: string;\n\t/** The exact text that unlocks the confirming control. */\n\tvalue: string;\n\tlabel: RemixNode;\n\tname?: string;\n};\n\n/**\n * Turns a phrase into a `pattern` that matches only that phrase.\n *\n * @param value The phrase to match literally.\n * @returns The phrase with every pattern syntax character escaped.\n */\nfunction escapePattern(value: string): string {\n\treturn value.replace(PATTERN_SYNTAX, \"\\\\$&\");\n}\n\n/**\n * Client island: the field a type-to-confirm prompt holds. It disables the dialog's\n * confirming control until the typed text matches and clears itself when the dialog\n * closes, so every opening starts locked; without script, `pattern` blocks the submit.\n *\n * @example\n * <ConfirmPhrase id=\"delete-team-phrase\" value=\"acme\" label='Type \"acme\" to confirm' />\n */\nexport const ConfirmPhrase: EntryComponent<ConfirmPhraseProps> = clientEntry(\n\t\"@sdxc/ui/confirm#ConfirmPhrase\",\n\tfunction ConfirmPhrase(handle) {\n\t\treturn () => {\n\t\t\tlet { id, label, name, value } = handle.props;\n\n\t\t\treturn (\n\t\t\t\t<div data-slot=\"confirm-phrase\" mix={[vstack({ gap: 1.5, align: \"stretch\" })]}>\n\t\t\t\t\t<Label htmlFor={id}>{label}</Label>\n\t\t\t\t\t{/* oxlint-disable-next-line jsx-a11y/no-autofocus -- Focus inside an opened modal, landing on the one field the decision needs. */}\n\t\t\t\t\t<Input\n\t\t\t\t\t\tid={id}\n\t\t\t\t\t\tname={name}\n\t\t\t\t\t\trequired\n\t\t\t\t\t\tautofocus\n\t\t\t\t\t\tautocomplete=\"off\"\n\t\t\t\t\t\tspellcheck={false}\n\t\t\t\t\t\tpattern={escapePattern(value)}\n\t\t\t\t\t\tmix={[confirmPhrase(value)]}\n\t\t\t\t\t/>\n\t\t\t\t</div>\n\t\t\t);\n\t\t};\n\t},\n);\n"
|
|
14
18
|
},
|
|
15
19
|
"test": {
|
|
16
20
|
"path": "confirm.test.tsx",
|
package/registry/ui/group.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "group",
|
|
3
|
-
"changedIn": "2026.11.
|
|
3
|
+
"changedIn": "2026.11.3",
|
|
4
4
|
"dependencies": [],
|
|
5
5
|
"exports": [
|
|
6
6
|
"Group"
|
|
7
7
|
],
|
|
8
8
|
"source": {
|
|
9
9
|
"path": "group.tsx",
|
|
10
|
-
"content": "/**\n * A visual and semantic wrapper binding a cluster of related controls into\n * one unit — a text input paired with its clear button, a row of segmented\n * buttons, a search field with a trailing submit action. The host lays its\n * children out in a single row, joining their edges so the cluster reads as one\n * control, with the seam between two of them drawn structurally rather than\n * through any tracked state.\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 { outlineColor } from \"@sdxc/u/color\";\nimport {
|
|
10
|
+
"content": "/**\n * A visual and semantic wrapper binding a cluster of related controls into\n * one unit — a text input paired with its clear button, a row of segmented\n * buttons, a search field with a trailing submit action. The host lays its\n * children out in a single row, joining their edges so the cluster reads as one\n * control, with the seam between two of them drawn structurally rather than\n * through any tracked state.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type { Handle, Props as TagProps } from \"remix/component\";\nimport type { RemixNode } from \"remix/component\";\n\nimport { bg, border, fg, outline, outlineColor } from \"@sdxc/u/color\";\nimport { opacity, rounded } from \"@sdxc/u/effects\";\nimport { cursor, mergeMix, raw } from \"@sdxc/u/general\";\nimport { flex, grow, items, shrink } from \"@sdxc/u/layout\";\nimport { bs, minIs, mis, pi } from \"@sdxc/u/size\";\nimport { z } from \"@sdxc/u/stacking\";\nimport { when } from \"@sdxc/u/state\";\nimport { nowrap, text } from \"@sdxc/u/typography\";\nimport { attrs } from \"remix/component\";\n\n/**\n * Default ARIA role applied through {@link attrs} unless a consumer\n * overrides `role`; pass `\"region\"` for landmark-worthy content or\n * `\"presentation\"` for purely visual grouping.\n */\nconst DEFAULT_ROLE = \"group\";\n\n/** A group holding a {@link Group.Text} addon, which makes it one field drawing its own rings. */\nconst WITH_ADDON = '&:has(> [data-slot=\"group-text\"])';\n\n/** A control whose value fails validation, by the platform's own check or the field's `aria-invalid`. */\nconst INVALID_CONTROL = ':is(:user-invalid, [aria-invalid=\"true\"])';\n\n/**\n * Prop types for {@link Group}.\n */\nexport namespace Group {\n\t/**\n\t * Native `<div>` attributes plus `mix`. `role` defaults to\n\t * {@link DEFAULT_ROLE} (or `\"region\"`/`\"presentation\"`); `aria-invalid`\n\t * gives the focus ring the danger tone, `aria-disabled` marks it disabled.\n\t */\n\texport interface Props extends TagProps<\"div\"> {}\n\n\t/**\n\t * Native `<label>` attributes plus `mix`. Set `htmlFor` to the control's `id` so a\n\t * click on the addon focuses it, and `id` to list the addon in the control's\n\t * `aria-describedby`; give the control its name through `aria-label` or\n\t * `aria-labelledby`, which keeps the addon's text out of that name.\n\t */\n\texport interface TextProps extends TagProps<\"label\"> {\n\t\t/** The addon's static text: a currency, a unit, a domain. */\n\t\tchildren: RemixNode;\n\t}\n}\n\n/**\n * Lays children out in a centered flex row with no border, background, or gap, joining\n * their edges into one shape: only the cluster's outer corners stay round, and the seam\n * two controls share is drawn once. Focus is shown by whichever control holds it.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the group's markup.\n * @example\n * <Group>\n * \t<Button>{t(\"stepper.decrement\")}</Button>\n * \t<Button>{t(\"stepper.increment\")}</Button>\n * </Group>\n * @example\n * <Group aria-invalid=\"true\">\n * \t<input aria-label={t(\"form.email\")} />\n * \t<Button aria-label={t(\"form.clear\")}>\n * \t\t<XIcon />\n * \t</Button>\n * </Group>\n */\nexport function Group(handle: Handle<Group.Props>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\t{...rest}\n\t\t\t\tmix={mergeMix(\n\t\t\t\t\t[\n\t\t\t\t\t\tattrs({ role: DEFAULT_ROLE }),\n\t\t\t\t\t\tflex(),\n\t\t\t\t\t\titems(\"center\"),\n\t\t\t\t\t\t/**\n\t\t\t\t\t\t * The controls compose into one shape, so the cluster keeps the rounding on\n\t\t\t\t\t\t * its own outer corners and the seam where two of them meet is drawn once; the\n\t\t\t\t\t\t * last control before a trailing `<link rel=\"prefetch\">` hint keeps its corners.\n\t\t\t\t\t\t * The square corners are `!important` so they hold over every child's own\n\t\t\t\t\t\t * rounding, whichever reached the page first.\n\t\t\t\t\t\t */\n\t\t\t\t\t\twhen(\"& > *:not(:first-child)\", [\n\t\t\t\t\t\t\traw({\n\t\t\t\t\t\t\t\tborderStartStartRadius: \"0 !important\",\n\t\t\t\t\t\t\t\tborderEndStartRadius: \"0 !important\",\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\tmis(\"-1px\"),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\twhen(\n\t\t\t\t\t\t\t\"& > *:has(~ :not(link))\",\n\t\t\t\t\t\t\traw({\n\t\t\t\t\t\t\t\tborderStartEndRadius: \"0 !important\",\n\t\t\t\t\t\t\t\tborderEndEndRadius: \"0 !important\",\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t),\n\t\t\t\t\t\t/**\n\t\t\t\t\t\t * Focus shows on the control holding it, naming which control has it where a ring\n\t\t\t\t\t\t * around the cluster names only the group. That control is raised so its ring\n\t\t\t\t\t\t * crosses the seam it shares with a neighbour.\n\t\t\t\t\t\t */\n\t\t\t\t\t\twhen(\"& > *:focus-visible\", z(1)),\n\t\t\t\t\t\twhen('&[aria-invalid=\"true\"] > *:focus-visible', outlineColor(\"danger\")),\n\t\t\t\t\t\t/**\n\t\t\t\t\t\t * With an addon the cluster is one field, so it carries the field's rounding and\n\t\t\t\t\t\t * rings, and the control takes the width the addons leave, down to nothing.\n\t\t\t\t\t\t */\n\t\t\t\t\t\twhen(WITH_ADDON, rounded(\"md\")),\n\t\t\t\t\t\twhen(`${WITH_ADDON} > :not([data-slot=\"group-text\"])`, [grow(), minIs(0)]),\n\t\t\t\t\t\twhen(\n\t\t\t\t\t\t\t`${WITH_ADDON}:has(> :focus-visible)`,\n\t\t\t\t\t\t\toutline({ color: \"brand.ring\", offset: 2 }),\n\t\t\t\t\t\t),\n\t\t\t\t\t\twhen(\n\t\t\t\t\t\t\t`${WITH_ADDON}:has(> [data-color=\"success\"]:focus-visible)`,\n\t\t\t\t\t\t\toutlineColor(\"success.ring\"),\n\t\t\t\t\t\t),\n\t\t\t\t\t\twhen(\n\t\t\t\t\t\t\t`${WITH_ADDON}:has(> [data-color=\"warning\"]:focus-visible)`,\n\t\t\t\t\t\t\toutlineColor(\"warning.ring\"),\n\t\t\t\t\t\t),\n\t\t\t\t\t\twhen(\n\t\t\t\t\t\t\t`${WITH_ADDON}:has(> [data-color=\"danger\"]:focus-visible)`,\n\t\t\t\t\t\t\toutlineColor(\"danger.ring\"),\n\t\t\t\t\t\t),\n\t\t\t\t\t\twhen(\n\t\t\t\t\t\t\t`${WITH_ADDON}:has(> ${INVALID_CONTROL})`,\n\t\t\t\t\t\t\toutline({ color: \"danger.ring\", offset: 2 }),\n\t\t\t\t\t\t),\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 a static addon joined to the control beside it — a currency, a unit, a domain —\n * as a muted, bordered `<label>` that keeps its text on one line. The `<label>` makes a\n * click on the addon focus the control; it dims with a disabled control and takes the\n * danger border with an invalid one, and its group draws the field's focus and invalid rings.\n *\n * @param handle Runtime handle carrying the host `<label>`'s props.\n * @returns The render function producing the addon's markup.\n * @example\n * <Group>\n * \t<Group.Text id=\"slug-prefix\" htmlFor=\"slug\">pulse.dev/</Group.Text>\n * \t<Input id=\"slug\" aria-labelledby=\"slug-label\" aria-describedby=\"slug-prefix\" />\n * </Group>\n */\nGroup.Text = function GroupText(handle: Handle<Group.TextProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<label\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"group-text\"\n\t\t\t\tmix={mergeMix(\n\t\t\t\t\t[\n\t\t\t\t\t\tflex(),\n\t\t\t\t\t\titems(\"center\"),\n\t\t\t\t\t\tshrink(0),\n\t\t\t\t\t\tnowrap(),\n\t\t\t\t\t\tbs(10),\n\t\t\t\t\t\tpi(3),\n\t\t\t\t\t\trounded(\"md\"),\n\t\t\t\t\t\tborder({ color: \"neutral\", width: 1 }),\n\t\t\t\t\t\tbg(\"neutral.tint\"),\n\t\t\t\t\t\tfg(\"neutral.muted\"),\n\t\t\t\t\t\ttext(\"sm\"),\n\t\t\t\t\t\tcursor(\"text\"),\n\t\t\t\t\t\twhen(`${INVALID_CONTROL} ~ &, &:has(~ ${INVALID_CONTROL})`, border(\"danger\")),\n\t\t\t\t\t\twhen(\":disabled ~ &, &:has(~ :disabled)\", [opacity(50), cursor(\"not-allowed\")]),\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"
|
|
11
11
|
},
|
|
12
12
|
"test": {
|
|
13
13
|
"path": "group.test.tsx",
|