@sdxc/kit 2026.10.20 → 2026.10.23
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 +178 -93
- package/changelog.jsonl +97 -0
- package/config.schema.json +160 -0
- package/dist/architecture/complexity.d.ts +73 -0
- package/dist/architecture/complexity.js +185 -0
- package/dist/architecture/crap.d.ts +62 -0
- package/dist/architecture/crap.js +121 -0
- package/dist/architecture/graph.d.ts +55 -0
- package/dist/architecture/graph.js +194 -0
- package/dist/architecture/layers.d.ts +29 -0
- package/dist/architecture/layers.js +81 -0
- package/dist/architecture/mermaid.d.ts +20 -0
- package/dist/architecture/mermaid.js +51 -0
- package/dist/cli.js +9 -0
- package/dist/commands/create.js +4 -3
- package/dist/commands/deploy.js +10 -9
- package/dist/commands/destroy.d.ts +1 -1
- package/dist/commands/diagram.d.ts +17 -0
- package/dist/commands/diagram.js +45 -0
- package/dist/commands/fix.d.ts +69 -0
- package/dist/commands/fix.js +102 -0
- package/dist/commands/make.d.ts +77 -2
- package/dist/commands/make.js +53 -1
- package/dist/commands/run.d.ts +15 -11
- package/dist/commands/run.js +21 -16
- package/dist/commands/scaffold.d.ts +2 -1
- package/dist/commands/scaffold.js +1 -0
- package/dist/commands/setup.d.ts +26 -0
- package/dist/commands/setup.js +33 -0
- package/dist/config.d.ts +54 -0
- package/dist/config.js +92 -1
- package/dist/contract.d.ts +56 -3
- package/dist/contract.js +140 -7
- package/dist/dependencies.d.ts +2 -1
- package/dist/dependencies.js +11 -2
- package/dist/deploy/plan.d.ts +5 -0
- package/dist/deploy/plan.js +10 -0
- package/dist/destroy.d.ts +4 -4
- package/dist/destroy.js +24 -11
- package/dist/diagram.d.ts +32 -0
- package/dist/diagram.js +47 -0
- package/dist/doctor/checks.d.ts +2 -1
- package/dist/doctor/checks.js +26 -1
- package/dist/doctor/complexity.d.ts +13 -0
- package/dist/doctor/complexity.js +52 -0
- package/dist/doctor/crap.d.ts +14 -0
- package/dist/doctor/crap.js +67 -0
- package/dist/doctor/dependencies.d.ts +13 -0
- package/dist/doctor/dependencies.js +42 -0
- package/dist/doctor/duplication.d.ts +19 -0
- package/dist/doctor/duplication.js +106 -0
- package/dist/doctor/fan-out.d.ts +12 -0
- package/dist/doctor/fan-out.js +42 -0
- package/dist/doctor/feature-scatter.d.ts +15 -0
- package/dist/doctor/feature-scatter.js +84 -0
- package/dist/doctor/jsdoc.d.ts +44 -0
- package/dist/doctor/jsdoc.js +201 -0
- package/dist/doctor/module-size.d.ts +13 -0
- package/dist/doctor/module-size.js +50 -0
- package/dist/doctor/mutation.d.ts +20 -0
- package/dist/doctor/mutation.js +97 -0
- package/dist/doctor/orphans.d.ts +13 -0
- package/dist/doctor/orphans.js +50 -0
- package/dist/doctor/project.js +8 -5
- package/dist/doctor/result-throws.d.ts +17 -0
- package/dist/doctor/result-throws.js +72 -0
- package/dist/doctor/test-ratio.d.ts +12 -0
- package/dist/doctor/test-ratio.js +31 -0
- package/dist/fix/commands.d.ts +37 -0
- package/dist/fix/commands.js +63 -0
- package/dist/fix/emails.d.ts +21 -0
- package/dist/fix/emails.js +159 -0
- package/dist/fix/env.d.ts +29 -0
- package/dist/fix/env.js +58 -0
- package/dist/fix/index.d.ts +11 -0
- package/dist/fix/index.js +11 -0
- package/dist/fix/models.d.ts +20 -0
- package/dist/fix/models.js +95 -0
- package/dist/lock.js +12 -2
- package/dist/make/binding.d.ts +42 -0
- package/dist/make/binding.js +237 -0
- package/dist/make/generate.d.ts +11 -2
- package/dist/make/generate.js +47 -16
- package/dist/make/imports.js +7 -5
- package/dist/make/index.d.ts +4 -2
- package/dist/make/index.js +4 -1
- package/dist/make/kinds.d.ts +5 -0
- package/dist/make/kinds.js +14 -2
- package/dist/make/schema-diff.js +8 -1
- package/dist/make/stubs.d.ts +7 -2
- package/dist/make/stubs.js +8 -3
- package/dist/make/test.js +1 -0
- package/dist/models.js +7 -7
- package/dist/routes/modules.js +8 -5
- package/dist/routes/parse.js +8 -7
- package/dist/routes/routers.js +9 -5
- package/dist/scaffold/index.d.ts +2 -0
- package/dist/scaffold/index.js +13 -4
- package/dist/scaffold/render.d.ts +11 -1
- package/dist/scaffold/render.js +86 -1
- package/dist/setup/auth.d.ts +12 -0
- package/dist/setup/auth.js +209 -0
- package/dist/setup/billing.d.ts +11 -0
- package/dist/setup/billing.js +116 -0
- package/dist/setup/catalog.d.ts +25 -0
- package/dist/setup/catalog.js +34 -0
- package/dist/setup/credit.d.ts +13 -0
- package/dist/setup/credit.js +21 -0
- package/dist/setup/flags.d.ts +11 -0
- package/dist/setup/flags.js +62 -0
- package/dist/setup/index.d.ts +25 -0
- package/dist/setup/index.js +53 -0
- package/dist/setup/plan.d.ts +38 -0
- package/dist/setup/plan.js +62 -0
- package/dist/testing.js +3 -3
- package/dist/ui/layout.js +1 -1
- package/dist/ui/registry.d.ts +2 -2
- package/dist/upgrade/project.d.ts +2 -2
- package/dist/upgrade/prompt.js +7 -5
- package/package.json +10 -7
- package/registry/ui/attachment.json +2 -2
- package/registry/ui/sidebar.json +3 -3
- package/registry/ui/typeset.json +3 -3
- package/stubs/command.spec.stub +15 -0
- package/stubs/controller.api.spec.stub +15 -0
- package/stubs/controller.spec.stub +15 -0
- package/stubs/mcp.spec.stub +16 -0
- package/stubs/scaffold.migration.stub +2 -1
- package/stubs/scaffold.spec.stub +7 -0
- package/templates/app/AGENTS.md +21 -4
- package/templates/app/README.md +6 -3
- package/templates/app/app/commands/typegen.test.ts +20 -1
- package/templates/app/app/commands/typegen.ts +16 -2
- package/templates/app/app/initializers/cli.ts +7 -0
- package/templates/app/app/initializers/mail-transport.test.ts +8 -2
- package/templates/app/app/test/cloudflare-workers.ts +2 -0
- package/templates/app/package.json +1 -0
- package/templates/app/spec/config.jsonc +16 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Credits setup-written files the way `make` stubs do: `@author` / `@copyright` from the
|
|
3
|
+
* project's package.json `author` or git `user.name`, never a kit maintainer hardcoded in.
|
|
4
|
+
*
|
|
5
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
6
|
+
* @copyright Sergio Xalambrí 2026
|
|
7
|
+
*/
|
|
8
|
+
import { addHeaderTags, headerTags, resolveAuthor } from "../author.js";
|
|
9
|
+
/**
|
|
10
|
+
* Returns `files` with each module JSDoc closed by the project's author tags. A project with
|
|
11
|
+
* no resolvable author leaves the sources unchanged.
|
|
12
|
+
*/
|
|
13
|
+
export async function creditSetupFiles(root, files) {
|
|
14
|
+
let tags = headerTags(await resolveAuthor(root));
|
|
15
|
+
if (tags === "")
|
|
16
|
+
return [...files];
|
|
17
|
+
return files.map((file) => ({
|
|
18
|
+
path: file.path,
|
|
19
|
+
content: addHeaderTags(file.content, tags),
|
|
20
|
+
}));
|
|
21
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `sdxc setup flags`: `@sdxc/flags` + engine store, empty catalog and a wide-event hook ready
|
|
3
|
+
* for the router / dispatcher middleware.
|
|
4
|
+
*
|
|
5
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
6
|
+
* @copyright Sergio Xalambrí 2026
|
|
7
|
+
*/
|
|
8
|
+
import type { Result } from "@sdxc/result";
|
|
9
|
+
import type { SetupPlan } from "./plan.js";
|
|
10
|
+
/** Builds the flags setup plan. */
|
|
11
|
+
export declare function planFlags(root: string): Promise<Result<SetupPlan, Error>>;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `sdxc setup flags`: `@sdxc/flags` + engine store, empty catalog and a wide-event hook ready
|
|
3
|
+
* for the router / dispatcher middleware.
|
|
4
|
+
*
|
|
5
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
6
|
+
* @copyright Sergio Xalambrí 2026
|
|
7
|
+
*/
|
|
8
|
+
import { success } from "@sdxc/result";
|
|
9
|
+
import { creditSetupFiles } from "./credit.js";
|
|
10
|
+
/** Builds the flags setup plan. */
|
|
11
|
+
export async function planFlags(root) {
|
|
12
|
+
let files = await creditSetupFiles(root, [
|
|
13
|
+
{ path: "app/initializers/flags.ts", content: FLAGS_INITIALIZER },
|
|
14
|
+
]);
|
|
15
|
+
return success({
|
|
16
|
+
feature: "flags",
|
|
17
|
+
provider: null,
|
|
18
|
+
files,
|
|
19
|
+
edits: [],
|
|
20
|
+
dependencies: ["@sdxc/flags", "@sdxc/flags-engine"],
|
|
21
|
+
notes: [
|
|
22
|
+
"Install the flags instance on the router and job dispatcher with the package's middleware.",
|
|
23
|
+
"Add flag definitions to FLAG_SET and features as product needs them.",
|
|
24
|
+
],
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
const FLAGS_INITIALIZER = `/**
|
|
28
|
+
* The app's feature flags: the definitions every evaluation resolves against, the typed
|
|
29
|
+
* catalog a call site names one by, and the instance both surfaces evaluate through.
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
import type { StoredFlagSet } from "@sdxc/flags-engine/store";
|
|
33
|
+
|
|
34
|
+
import { createEngine } from "@sdxc/flags-engine";
|
|
35
|
+
import { EngineProvider } from "@sdxc/flags-engine/provider";
|
|
36
|
+
import { InMemoryFlagStore } from "@sdxc/flags-engine/store/memory";
|
|
37
|
+
import { defineFlags } from "@sdxc/flags/catalog";
|
|
38
|
+
import { createFlags, wideEventHook } from "@sdxc/flags/client";
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* What every evaluation resolves against. A key absent from here resolves to the default
|
|
42
|
+
* its call site passed, so retiring a flag is deleting its entry and then its branch.
|
|
43
|
+
*/
|
|
44
|
+
export const FLAG_SET: StoredFlagSet = {
|
|
45
|
+
flags: {},
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Every flag by the name a call site reaches for. Add entries with \`flag.boolean\` /
|
|
50
|
+
* \`flag.number\` / \`flag.string\` as product needs them.
|
|
51
|
+
*/
|
|
52
|
+
export const features = defineFlags({});
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* The instance both surfaces evaluate through, installed by the router's middleware and
|
|
56
|
+
* the job dispatcher's.
|
|
57
|
+
*/
|
|
58
|
+
export const flags = createFlags({
|
|
59
|
+
provider: new EngineProvider(createEngine({ store: new InMemoryFlagStore(FLAG_SET) })),
|
|
60
|
+
hooks: [wideEventHook()],
|
|
61
|
+
});
|
|
62
|
+
`;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `sdxc setup`: feature installers that span app code and config — list known features, print
|
|
3
|
+
* a plan, and with confirmation write every path the feature needs.
|
|
4
|
+
*
|
|
5
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
6
|
+
* @copyright Sergio Xalambrí 2026
|
|
7
|
+
*/
|
|
8
|
+
import type { Result } from "@sdxc/result";
|
|
9
|
+
import type { SetupPlan } from "./plan.js";
|
|
10
|
+
export { SETUP_FEATURES, setupFeature } from "./catalog.js";
|
|
11
|
+
export { applyPlan, formatPlan } from "./plan.js";
|
|
12
|
+
export type { SetupPlan } from "./plan.js";
|
|
13
|
+
/** Lists the features this kit release knows, one line each. */
|
|
14
|
+
export declare function listFeatures(): string;
|
|
15
|
+
/**
|
|
16
|
+
* Plans `feature` for the project at `root`. Unknown features fail naming the catalog.
|
|
17
|
+
*/
|
|
18
|
+
export declare function planSetup(root: string, feature: string, provider: string | undefined): Promise<Result<SetupPlan, Error>>;
|
|
19
|
+
/** Plans then applies, returning early when the plan itself fails. */
|
|
20
|
+
export declare function runSetup(root: string, feature: string, options: {
|
|
21
|
+
provider: string | undefined;
|
|
22
|
+
dryRun: boolean;
|
|
23
|
+
yes: boolean;
|
|
24
|
+
stdout: (text: string) => void;
|
|
25
|
+
}): Promise<Result<void, Error>>;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `sdxc setup`: feature installers that span app code and config — list known features, print
|
|
3
|
+
* a plan, and with confirmation write every path the feature needs.
|
|
4
|
+
*
|
|
5
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
6
|
+
* @copyright Sergio Xalambrí 2026
|
|
7
|
+
*/
|
|
8
|
+
import { failure, isFailure } from "@sdxc/result";
|
|
9
|
+
import { planAuth } from "./auth.js";
|
|
10
|
+
import { planBilling } from "./billing.js";
|
|
11
|
+
import { SETUP_FEATURES, setupFeature } from "./catalog.js";
|
|
12
|
+
import { planFlags } from "./flags.js";
|
|
13
|
+
import { applyPlan } from "./plan.js";
|
|
14
|
+
export { SETUP_FEATURES, setupFeature } from "./catalog.js";
|
|
15
|
+
export { applyPlan, formatPlan } from "./plan.js";
|
|
16
|
+
/** Lists the features this kit release knows, one line each. */
|
|
17
|
+
export function listFeatures() {
|
|
18
|
+
return (SETUP_FEATURES.map((feature) => `${feature.name.padEnd(10)} ${feature.description}`).join("\n") + "\n");
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Plans `feature` for the project at `root`. Unknown features fail naming the catalog.
|
|
22
|
+
*/
|
|
23
|
+
export async function planSetup(root, feature, provider) {
|
|
24
|
+
let known = setupFeature(feature);
|
|
25
|
+
if (known === null) {
|
|
26
|
+
return failure(new Error(`Unknown setup feature "${feature}"; this release ships ${SETUP_FEATURES.map((row) => row.name).join(", ")}`));
|
|
27
|
+
}
|
|
28
|
+
let chosen = provider ??
|
|
29
|
+
known.defaultProvider ??
|
|
30
|
+
(known.providers.length === 1 ? known.providers[0] : undefined);
|
|
31
|
+
if (known.providers.length > 0 && chosen === undefined) {
|
|
32
|
+
return failure(new Error(`setup ${feature} needs --provider ${known.providers.join("|")} (default: ${known.defaultProvider})`));
|
|
33
|
+
}
|
|
34
|
+
if (known.providers.length > 0 && chosen !== undefined && !known.providers.includes(chosen)) {
|
|
35
|
+
return failure(new Error(`Unknown ${feature} provider "${chosen}"; choose ${known.providers.join(", ")}`));
|
|
36
|
+
}
|
|
37
|
+
if (feature === "auth")
|
|
38
|
+
return planAuth(root, chosen ?? "r3-auth");
|
|
39
|
+
if (feature === "billing")
|
|
40
|
+
return planBilling(root, chosen ?? "polar");
|
|
41
|
+
if (feature === "flags")
|
|
42
|
+
return planFlags(root);
|
|
43
|
+
return failure(new Error(`setup ${feature} is listed but has no planner yet`));
|
|
44
|
+
}
|
|
45
|
+
/** Plans then applies, returning early when the plan itself fails. */
|
|
46
|
+
export async function runSetup(root, feature, options) {
|
|
47
|
+
let planned = await planSetup(root, feature, options.provider);
|
|
48
|
+
if (isFailure(planned))
|
|
49
|
+
return planned;
|
|
50
|
+
/** Without `-y`, the plan is printed and nothing is written — the agent-safe default. */
|
|
51
|
+
let dryRun = !options.yes || options.dryRun;
|
|
52
|
+
return applyPlan(root, planned.data, { dryRun, stdout: options.stdout });
|
|
53
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared setup plan: every path a feature will write or edit, printed before confirmation so
|
|
3
|
+
* `--dry-run` is the default agent path until `-y` asks to write.
|
|
4
|
+
*
|
|
5
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
6
|
+
* @copyright Sergio Xalambrí 2026
|
|
7
|
+
*/
|
|
8
|
+
import type { Result } from "@sdxc/result";
|
|
9
|
+
/** One new file the plan writes. */
|
|
10
|
+
export interface SetupFile {
|
|
11
|
+
path: string;
|
|
12
|
+
content: string;
|
|
13
|
+
}
|
|
14
|
+
/** One existing file the plan edits. */
|
|
15
|
+
export interface SetupEdit {
|
|
16
|
+
path: string;
|
|
17
|
+
before: string;
|
|
18
|
+
after: string;
|
|
19
|
+
}
|
|
20
|
+
/** The full plan for one `sdxc setup <feature>` run. */
|
|
21
|
+
export interface SetupPlan {
|
|
22
|
+
feature: string;
|
|
23
|
+
provider: string | null;
|
|
24
|
+
files: SetupFile[];
|
|
25
|
+
edits: SetupEdit[];
|
|
26
|
+
/** Packages to add as `workspace:*` / dated pins when missing. */
|
|
27
|
+
dependencies: string[];
|
|
28
|
+
notes: string[];
|
|
29
|
+
}
|
|
30
|
+
/** Prints the plan as the operator and agent read it. */
|
|
31
|
+
export declare function formatPlan(plan: SetupPlan): string;
|
|
32
|
+
/** Writes the plan's files and edits; under `dryRun` prints diffs and changes nothing. */
|
|
33
|
+
export declare function applyPlan(root: string, plan: SetupPlan, options: {
|
|
34
|
+
dryRun: boolean;
|
|
35
|
+
stdout: (text: string) => void;
|
|
36
|
+
}): Promise<Result<void, Error>>;
|
|
37
|
+
/** Reads a project file, or fails naming the path. */
|
|
38
|
+
export declare function readProjectFile(root: string, path: string): Promise<Result<string, Error>>;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared setup plan: every path a feature will write or edit, printed before confirmation so
|
|
3
|
+
* `--dry-run` is the default agent path until `-y` asks to write.
|
|
4
|
+
*
|
|
5
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
6
|
+
* @copyright Sergio Xalambrí 2026
|
|
7
|
+
*/
|
|
8
|
+
import { access, mkdir, readFile, writeFile } from "node:fs/promises";
|
|
9
|
+
import { dirname, join } from "node:path";
|
|
10
|
+
import { failure, isFailure, isSuccess, success, wrap } from "@sdxc/result";
|
|
11
|
+
import { unifiedDiff } from "../diff.js";
|
|
12
|
+
/** Prints the plan as the operator and agent read it. */
|
|
13
|
+
export function formatPlan(plan) {
|
|
14
|
+
let lines = [
|
|
15
|
+
`setup ${plan.feature}${plan.provider === null ? "" : ` --provider ${plan.provider}`}`,
|
|
16
|
+
];
|
|
17
|
+
for (let file of plan.files)
|
|
18
|
+
lines.push(` write ${file.path}`);
|
|
19
|
+
for (let edit of plan.edits)
|
|
20
|
+
lines.push(` edit ${edit.path}`);
|
|
21
|
+
for (let dependency of plan.dependencies)
|
|
22
|
+
lines.push(` depend ${dependency}`);
|
|
23
|
+
for (let note of plan.notes)
|
|
24
|
+
lines.push(` note ${note}`);
|
|
25
|
+
return `${lines.join("\n")}\n`;
|
|
26
|
+
}
|
|
27
|
+
/** Writes the plan's files and edits; under `dryRun` prints diffs and changes nothing. */
|
|
28
|
+
export async function applyPlan(root, plan, options) {
|
|
29
|
+
if (options.dryRun) {
|
|
30
|
+
options.stdout(formatPlan(plan));
|
|
31
|
+
for (let file of plan.files) {
|
|
32
|
+
options.stdout(unifiedDiff(file.path, null, file.content));
|
|
33
|
+
}
|
|
34
|
+
for (let edit of plan.edits) {
|
|
35
|
+
options.stdout(unifiedDiff(edit.path, edit.before, edit.after));
|
|
36
|
+
}
|
|
37
|
+
return success(undefined);
|
|
38
|
+
}
|
|
39
|
+
for (let file of plan.files) {
|
|
40
|
+
let target = join(root, file.path);
|
|
41
|
+
if (isSuccess(await wrap(() => access(target)))) {
|
|
42
|
+
return failure(new Error(`${file.path} already exists; refuse to overwrite a hand-edited file`));
|
|
43
|
+
}
|
|
44
|
+
await mkdir(dirname(target), { recursive: true });
|
|
45
|
+
await writeFile(target, file.content);
|
|
46
|
+
options.stdout(`wrote ${file.path}\n`);
|
|
47
|
+
}
|
|
48
|
+
for (let edit of plan.edits) {
|
|
49
|
+
await writeFile(join(root, edit.path), edit.after);
|
|
50
|
+
options.stdout(`edited ${edit.path}\n`);
|
|
51
|
+
}
|
|
52
|
+
for (let note of plan.notes)
|
|
53
|
+
options.stdout(`${note}\n`);
|
|
54
|
+
return success(undefined);
|
|
55
|
+
}
|
|
56
|
+
/** Reads a project file, or fails naming the path. */
|
|
57
|
+
export async function readProjectFile(root, path) {
|
|
58
|
+
let source = await wrap(() => readFile(join(root, path), "utf8"));
|
|
59
|
+
if (isFailure(source))
|
|
60
|
+
return failure(new Error(`No ${path} in the project`));
|
|
61
|
+
return success(source.data);
|
|
62
|
+
}
|
package/dist/testing.js
CHANGED
|
@@ -133,7 +133,7 @@ async function installed(packageRoot, dependency) {
|
|
|
133
133
|
}
|
|
134
134
|
/** Runs a script with `args` in `cwd` under `runtime`, Node by default, collecting both output streams. */
|
|
135
135
|
function run(args, cwd, runtime = process.execPath) {
|
|
136
|
-
return new Promise((
|
|
136
|
+
return new Promise((resolve) => {
|
|
137
137
|
let output = "";
|
|
138
138
|
let child = spawn(runtime, args, { cwd, shell: false });
|
|
139
139
|
child.stdout.on("data", (chunk) => {
|
|
@@ -142,7 +142,7 @@ function run(args, cwd, runtime = process.execPath) {
|
|
|
142
142
|
child.stderr.on("data", (chunk) => {
|
|
143
143
|
output += chunk.toString();
|
|
144
144
|
});
|
|
145
|
-
child.once("error", (error) =>
|
|
146
|
-
child.once("close", (code) =>
|
|
145
|
+
child.once("error", (error) => resolve({ code: null, output: error.message }));
|
|
146
|
+
child.once("close", (code) => resolve({ code, output }));
|
|
147
147
|
});
|
|
148
148
|
}
|
package/dist/ui/layout.js
CHANGED
|
@@ -111,7 +111,7 @@ async function readCompilerOptions(path, depth) {
|
|
|
111
111
|
let options = await readCompilerOptions(file, depth + 1);
|
|
112
112
|
if (isFailure(options))
|
|
113
113
|
return options;
|
|
114
|
-
inherited
|
|
114
|
+
Object.assign(inherited, options.data);
|
|
115
115
|
}
|
|
116
116
|
}
|
|
117
117
|
let own = config.compilerOptions ?? {};
|
package/dist/ui/registry.d.ts
CHANGED
|
@@ -18,12 +18,12 @@ export declare const REGISTRY_ENTRY: s.Schema<{
|
|
|
18
18
|
path: string;
|
|
19
19
|
content: string;
|
|
20
20
|
};
|
|
21
|
+
exports: string[];
|
|
21
22
|
test: {
|
|
22
23
|
path: string;
|
|
23
24
|
content: string;
|
|
24
25
|
} | null;
|
|
25
26
|
changedIn: string;
|
|
26
|
-
exports: string[];
|
|
27
27
|
}, {
|
|
28
28
|
name: string;
|
|
29
29
|
dependencies: string[];
|
|
@@ -31,12 +31,12 @@ export declare const REGISTRY_ENTRY: s.Schema<{
|
|
|
31
31
|
path: string;
|
|
32
32
|
content: string;
|
|
33
33
|
};
|
|
34
|
+
exports: string[];
|
|
34
35
|
test: {
|
|
35
36
|
path: string;
|
|
36
37
|
content: string;
|
|
37
38
|
} | null;
|
|
38
39
|
changedIn: string;
|
|
39
|
-
exports: string[];
|
|
40
40
|
}>;
|
|
41
41
|
/** A component as the installed release ships it. */
|
|
42
42
|
export type RegistryEntry = s.InferOutput<typeof REGISTRY_ENTRY>;
|
|
@@ -12,16 +12,16 @@ 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
|
+
optionalDependencies?: Record<string, string> | undefined;
|
|
15
16
|
packageManager?: string | undefined;
|
|
16
17
|
scripts?: Record<string, string> | undefined;
|
|
17
|
-
optionalDependencies?: 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
|
+
optionalDependencies?: Record<string, string> | undefined;
|
|
22
23
|
packageManager?: string | undefined;
|
|
23
24
|
scripts?: Record<string, string> | undefined;
|
|
24
|
-
optionalDependencies?: Record<string, string> | undefined;
|
|
25
25
|
}>;
|
|
26
26
|
/** The project's `package.json` fields the upgrade reads. */
|
|
27
27
|
export type Manifest = s.InferOutput<typeof MANIFEST_SCHEMA>;
|
package/dist/upgrade/prompt.js
CHANGED
|
@@ -225,11 +225,13 @@ function agentsNote(input) {
|
|
|
225
225
|
}
|
|
226
226
|
let url = `${PACKAGE_FILES}/${RELEASE_PACKAGE}@${input.to}/${AGENTS_TEMPLATE}`;
|
|
227
227
|
let markers = "`<!-- sdxc:start …-->` and `<!-- sdxc:end -->`";
|
|
228
|
-
let state
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
228
|
+
let state;
|
|
229
|
+
if (input.agents === "missing")
|
|
230
|
+
state = `This project has no \`${AGENTS_FILE}\`.`;
|
|
231
|
+
else if (input.agents === "unmarked")
|
|
232
|
+
state = `\`${AGENTS_FILE}\` has no sdxc section, so the upgrade left it as it is.`;
|
|
233
|
+
else
|
|
234
|
+
state = `\`${AGENTS_FILE}\` needs exactly one ${markers} line pair, so the upgrade left it as it is.`;
|
|
233
235
|
let action = input.agents === "unbalanced"
|
|
234
236
|
? `Restore one pair around the sdxc section, which for release ${input.to} is in ${url}.`
|
|
235
237
|
: `When this project is an app in the sdxc layout (it has \`bootstrap/worker.ts\`), add the section from ${url}, ${markers} lines included, to \`${AGENTS_FILE}\`, creating the file if needed; \`sdxc upgrade\` then keeps it current.`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sdxc/kit",
|
|
3
|
-
"version": "2026.10.
|
|
3
|
+
"version": "2026.10.23",
|
|
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,19 +14,22 @@
|
|
|
14
14
|
"./lock.schema.json": "./lock.schema.json"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@sdxc/cli": "2026.10.
|
|
18
|
-
"@sdxc/codemod": "2026.10.
|
|
19
|
-
"@sdxc/cron": "2026.10.
|
|
20
|
-
"@sdxc/
|
|
17
|
+
"@sdxc/cli": "2026.10.23",
|
|
18
|
+
"@sdxc/codemod": "2026.10.23",
|
|
19
|
+
"@sdxc/cron": "2026.10.23",
|
|
20
|
+
"@sdxc/diagram": "2026.10.23",
|
|
21
|
+
"@sdxc/iife": "2026.10.23",
|
|
22
|
+
"@sdxc/json-schema": "2026.10.23",
|
|
21
23
|
"@sdxc/jsonc": "2026.10.16",
|
|
22
24
|
"@sdxc/jsonl": "2026.10.16",
|
|
23
25
|
"@sdxc/result": "2026.10.13",
|
|
24
|
-
"@sdxc/semver": "2026.10.13"
|
|
26
|
+
"@sdxc/semver": "2026.10.13",
|
|
27
|
+
"oxc-parser": "^0.154.0"
|
|
25
28
|
},
|
|
26
29
|
"peerDependencies": {
|
|
27
30
|
"remix": "3.0.0"
|
|
28
31
|
},
|
|
29
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "8e428ddf15290d44500a9618ec4d04bd7629fa99",
|
|
30
33
|
"publishConfig": {
|
|
31
34
|
"access": "public"
|
|
32
35
|
},
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "attachment",
|
|
3
|
-
"changedIn": "2026.10.
|
|
3
|
+
"changedIn": "2026.10.23",
|
|
4
4
|
"dependencies": [
|
|
5
5
|
"button"
|
|
6
6
|
],
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
],
|
|
10
10
|
"source": {
|
|
11
11
|
"path": "attachment.tsx",
|
|
12
|
-
"content": "/**\n * A compound card presenting one attached file or image — media preview, name,\n * supporting details, actions — plus a horizontally scrolling row for several\n * cards side by side. Every part styles itself off the card's own `state`, and\n * whole-card click-through stays an opt-in wrapper a consumer mixes in.\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, border, fg, outline } from \"@sdxc/u/color\";\nimport { rounded, transition } from \"@sdxc/u/effects\";\nimport { raw } from \"@sdxc/u/general\";\nimport {\n\tbasis,\n\tblock,\n\tcontainer,\n\tflex,\n\tflexCol,\n\tgap,\n\tgrow,\n\thstack,\n\titems,\n\tjustify,\n\trelative,\n\tshrink,\n\tvstack,\n} from \"@sdxc/u/layout\";\nimport { overflow, overflowX } from \"@sdxc/u/overflow\";\nimport { media } from \"@sdxc/u/responsive\";\nimport { aspect, bs, fit, is, minIs, p } from \"@sdxc/u/size\";\nimport { when } from \"@sdxc/u/state\";\nimport { text, textAlign, truncate, weight } from \"@sdxc/u/typography\";\nimport { attrs } from \"remix/component\";\n\nimport { shimmer } from \"@sdxc/ui/animations\";\nimport { scrollFade } from \"@sdxc/ui/animations\";\n\nimport { Button } from \"@sdxc/ui/button\";\n\nconst DEFAULT_STATE: Attachment.State = \"idle\";\n\n/**\n * Named container {@link Attachment} declares on its own host, so\n * {@link Attachment.Media}, {@link Attachment.Content}, and the inner layout\n * wrapper resolve their width queries against the card itself.\n */\nconst CONTAINER_NAME = \"ui-attachment\";\n\n/**\n * `@container` query every width-adapting part below the root shares: at or\n * under this width the card reflows into a taller tile, the shape\n * {@link Attachment.Group}'s narrow, fixed-width cards need.\n */\nconst NARROW_CONTAINER_QUERY = `@container ${CONTAINER_NAME} (max-width: 12rem)`;\n\n/**\n * Selector fragment gating {@link Attachment.Title}'s shimmer: it matches the\n * title's own `data-state` attribute while that reads `\"uploading\"` or\n * `\"processing\"`, so a title in any other state renders as plain text.\n */\nconst TITLE_SHIMMER_WHEN = ':is([data-state=\"uploading\"], [data-state=\"processing\"])';\n\nconst DEFAULT_ACTION_VARIANT: Button.Variant = \"ghost\";\n\nconst DEFAULT_ACTION_SIZE: Button.Size = \"sm\";\n\nconst DEFAULT_ACTION_COLOR: Button.Color = \"neutral\";\n\n/**\n * Tab-stop order {@link attrs} applies to {@link Attachment.Group} when a\n * consumer supplies no `tabIndex`, so the row itself stays keyboard-reachable\n * and scrollable whatever its cards contain.\n */\nconst DEFAULT_GROUP_TAB_INDEX = 0;\n\nconst GROUP_SCROLL_FADE_SIZE = \"2rem\";\n\n/**\n * Prop types for {@link Attachment} and its compound parts.\n */\nexport namespace Attachment {\n\t/**\n\t * Lifecycle state of a card's file or image. `\"idle\"` and `\"done\"` both\n\t * render as a settled card — `\"idle\"` for a file already on the server,\n\t * `\"done\"` for one whose transfer finished. A consumer owns every transition.\n\t */\n\texport type State = \"idle\" | \"uploading\" | \"processing\" | \"error\" | \"done\";\n\n\t/**\n\t * Props accepted by {@link Attachment}.\n\t */\n\texport interface Props extends TagProps<\"div\"> {\n\t\t/** Lifecycle state of the file or image the card represents. Defaults to `\"idle\"`. */\n\t\tstate?: State;\n\t\t/** The card's compound parts: {@link Attachment.Media}, {@link Attachment.Content}, and {@link Attachment.Actions}. */\n\t\tchildren: RemixNode;\n\t}\n\n\t/**\n\t * Props accepted by {@link Attachment.Media}.\n\t */\n\texport interface MediaProps extends TagProps<\"div\"> {\n\t\t/** The preview itself: an `<img>`, or a decorative icon standing in for the file's type. */\n\t\tchildren: RemixNode;\n\t}\n\n\t/**\n\t * Props accepted by {@link Attachment.Content}.\n\t */\n\texport interface ContentProps extends TagProps<\"div\"> {\n\t\t/** {@link Attachment.Title} and, optionally, {@link Attachment.Description}. */\n\t\tchildren: RemixNode;\n\t}\n\n\t/**\n\t * Props accepted by {@link Attachment.Title}.\n\t */\n\texport interface TitleProps extends TagProps<\"p\"> {\n\t\t/**\n\t\t * The ancestor {@link Attachment}'s own `state`, repeated here because a\n\t\t * component reads only its own props; passing the same value to both is\n\t\t * what keeps them in sync. Left unset, the title renders plain.\n\t\t */\n\t\tstate?: Attachment.State;\n\t\t/** The file or image name. */\n\t\tchildren: RemixNode;\n\t}\n\n\t/**\n\t * Props accepted by {@link Attachment.Description}.\n\t */\n\texport interface DescriptionProps extends TagProps<\"p\"> {\n\t\t/** Supporting detail — a file size, a page count, an error message. */\n\t\tchildren: RemixNode;\n\t}\n\n\t/**\n\t * Props accepted by {@link Attachment.Actions}.\n\t */\n\texport interface ActionsProps extends TagProps<\"div\"> {\n\t\t/** A run of {@link Attachment.Action} controls. */\n\t\tchildren: RemixNode;\n\t}\n\n\t/**\n\t * Props accepted by {@link Attachment.Action}: every {@link Button.Props}\n\t * field, unchanged, so an action keeps the same color, weight, and size\n\t * contract as every other button in the catalog.\n\t */\n\texport interface ActionProps extends Button.Props {}\n\n\t/**\n\t * Props accepted by {@link Attachment.Trigger}.\n\t */\n\texport interface TriggerProps extends TagProps<\"div\"> {\n\t\t/**\n\t\t * Destination the whole card follows once `attachmentTrigger()` is mixed\n\t\t * in, opened in place unless the activation asks for a new tab. It rides on\n\t\t * a `<div>` so a nested {@link Attachment.Action} stays valid markup.\n\t\t */\n\t\thref?: string;\n\t\t/**\n\t\t * `id` of a `<dialog>` element the whole card opens once\n\t\t * `attachmentTrigger()` is mixed in, instead of following `href`.\n\t\t */\n\t\tcommandfor?: string;\n\t\t/** Invoker Commands verb dispatched to `commandfor`'s dialog. Defaults to `\"show-modal\"`. */\n\t\tcommand?: \"show-modal\";\n\t\t/** Where `href` opens: a window/frame name, or `\"_blank\"` for a new tab. Meaningful only alongside `href`. */\n\t\ttarget?: string;\n\t\t/** The card's own markup — typically an {@link Attachment}. */\n\t\tchildren: RemixNode;\n\t}\n\n\t/**\n\t * Props accepted by {@link Attachment.Group}.\n\t */\n\texport interface GroupProps extends TagProps<\"div\"> {\n\t\t/** A run of {@link Attachment} or {@link Attachment.Trigger} cards. */\n\t\tchildren: RemixNode;\n\t}\n}\n\n/**\n * The card's outer host, recolored to the danger tint at `state=\"error\"` and\n * declaring the `ui-attachment` named container so nested parts reflow at the\n * card's width. A busy state sets `aria-busy` to the token ARIA recognizes.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the card's markup.\n * @example\n * <Attachment state=\"uploading\">\n * \t<Attachment.Media><FileIcon aria-hidden /></Attachment.Media>\n * \t<Attachment.Content>\n * \t\t<Attachment.Title state=\"uploading\">quarterly-report.pdf</Attachment.Title>\n * \t\t<Attachment.Description>{t(\"attachment.uploading\")}</Attachment.Description>\n * \t</Attachment.Content>\n * </Attachment>\n * @example\n * <Attachment state=\"error\">\n * \t<Attachment.Media><FileIcon aria-hidden /></Attachment.Media>\n * \t<Attachment.Content>\n * \t\t<Attachment.Title>quarterly-report.pdf</Attachment.Title>\n * \t\t<Attachment.Description>{t(\"attachment.uploadFailed\")}</Attachment.Description>\n * \t</Attachment.Content>\n * \t<Attachment.Actions>\n * \t\t<Attachment.Action aria-label={t(\"attachment.retry\")}><RotateCwIcon /></Attachment.Action>\n * \t</Attachment.Actions>\n * </Attachment>\n */\nexport function Attachment(handle: Handle<Attachment.Props>) {\n\treturn () => {\n\t\tlet { state, children, mix, ...rest } = handle.props;\n\t\tlet resolvedState = state ?? DEFAULT_STATE;\n\t\tlet isBusy = resolvedState === \"uploading\" || resolvedState === \"processing\";\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"attachment\"\n\t\t\t\tdata-state={resolvedState}\n\t\t\t\taria-busy={isBusy ? \"true\" : undefined}\n\t\t\t\tmix={[\n\t\t\t\t\trelative(),\n\t\t\t\t\trounded(\"lg\"),\n\t\t\t\t\tborder({ width: 1 }),\n\t\t\t\t\tborder(\"neutral\"),\n\t\t\t\t\tbg(\"neutral.tint\"),\n\t\t\t\t\tfg(\"neutral.emphasis\"),\n\t\t\t\t\tp(3),\n\t\t\t\t\ttransition(\"border-color, background-color\"),\n\t\t\t\t\tcontainer(CONTAINER_NAME),\n\t\t\t\t\twhen('&[data-state=\"error\"]', [\n\t\t\t\t\t\tborder(\"danger\"),\n\t\t\t\t\t\tbg(\"danger.tint\"),\n\t\t\t\t\t\tfg(\"danger.emphasis\"),\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<div\n\t\t\t\t\tdata-slot=\"body\"\n\t\t\t\t\tmix={[\n\t\t\t\t\t\thstack({ gap: 3, align: \"center\" }),\n\t\t\t\t\t\twhen(NARROW_CONTAINER_QUERY, [flexCol(), items(\"stretch\")]),\n\t\t\t\t\t]}\n\t\t\t\t>\n\t\t\t\t\t{children}\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t);\n\t};\n}\n\n/**\n * The card's media well: a fixed-size, rounded box clipping the preview a\n * consumer nests inside. Inside a narrow container it grows to the card's own\n * inline size at a wider aspect ratio, reading as a thumbnail tile.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the media well's markup.\n * @example\n * <Attachment.Media><img src={file.thumbnailUrl} alt=\"\" /></Attachment.Media>\n * @example\n * <Attachment.Media><FileTextIcon aria-hidden /></Attachment.Media>\n */\nAttachment.Media = function AttachmentMedia(handle: Handle<Attachment.MediaProps>) {\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=\"media\"\n\t\t\t\tmix={[\n\t\t\t\t\tflex(),\n\t\t\t\t\tshrink(0),\n\t\t\t\t\titems(\"center\"),\n\t\t\t\t\tjustify(\"center\"),\n\t\t\t\t\toverflow(),\n\t\t\t\t\tis(10),\n\t\t\t\t\tbs(10),\n\t\t\t\t\trounded(\"md\"),\n\t\t\t\t\tbg(\"neutral.bg-tint-hover\"),\n\t\t\t\t\tfg(\"neutral\"),\n\t\t\t\t\twhen(\"& > svg\", [is(5), bs(5)]),\n\t\t\t\t\twhen(\"& > img\", [is(\"full\"), bs(\"full\"), fit(\"cover\")]),\n\t\t\t\t\twhen(NARROW_CONTAINER_QUERY, [is(\"full\"), bs(\"auto\"), aspect(4, 3), rounded(\"lg\")]),\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 * The card's text column, growing into whatever inline space\n * {@link Attachment.Media} and {@link Attachment.Actions} leave it. Its minimum\n * inline size collapses to `0`, which is what lets its children truncate.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the text column's markup.\n * @example\n * <Attachment.Content>\n * \t<Attachment.Title>quarterly-report.pdf</Attachment.Title>\n * \t<Attachment.Description>2.4 MB</Attachment.Description>\n * </Attachment.Content>\n */\nAttachment.Content = function AttachmentContent(handle: Handle<Attachment.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={[\n\t\t\t\t\tvstack({ gap: 0.5 }),\n\t\t\t\t\tminIs(0),\n\t\t\t\t\tgrow(),\n\t\t\t\t\tshrink(1),\n\t\t\t\t\tbasis(\"0%\"),\n\t\t\t\t\twhen(NARROW_CONTAINER_QUERY, textAlign(\"center\")),\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 * The file or image name in a native `<p>`, truncated to a single line with an\n * ellipsis. Given the same `state` as the ancestor {@link Attachment}, it\n * shimmers while that reads `\"uploading\"` or `\"processing\"`, then settles.\n *\n * @param handle Runtime handle carrying the host `<p>`'s props.\n * @returns The render function producing the title's markup.\n * @example\n * <Attachment.Title>quarterly-report.pdf</Attachment.Title>\n * @example\n * <Attachment.Title state={attachment.state}>{attachment.name}</Attachment.Title>\n */\nAttachment.Title = function AttachmentTitle(handle: Handle<Attachment.TitleProps>) {\n\treturn () => {\n\t\tlet { state, 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=\"title\"\n\t\t\t\tdata-state={state}\n\t\t\t\tmix={[\n\t\t\t\t\tweight(\"semibold\"),\n\t\t\t\t\ttruncate(),\n\t\t\t\t\ttext(\"sm\"),\n\t\t\t\t\t/**\n\t\t\t\t\t * The loop settles visible, because this host carries the file's name: a gated\n\t\t\t\t\t * loop rests hidden outside its gate, which suits an element that exists only\n\t\t\t\t\t * as a loading cue and would leave every finished upload unnamed.\n\t\t\t\t\t */\n\t\t\t\t\tshimmer({ when: TITLE_SHIMMER_WHEN, outsideGate: \"visible\" }),\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 * The card's supporting detail line: a muted, single-line `<p>` carrying a file\n * size, a page count, or the explanation of what went wrong once the ancestor\n * {@link Attachment}'s `state` reads `\"error\"`.\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 * <Attachment.Description>2.4 MB</Attachment.Description>\n * @example\n * <Attachment.Description>{t(\"attachment.uploadFailed\")}</Attachment.Description>\n */\nAttachment.Description = function AttachmentDescription(\n\thandle: Handle<Attachment.DescriptionProps>,\n) {\n\treturn () => {\n\t\tlet { children, mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<p {...rest} data-slot=\"description\" mix={[truncate(), fg(\"neutral.muted\"), text(\"xs\"), mix]}>\n\t\t\t\t{children}\n\t\t\t</p>\n\t\t);\n\t};\n};\n\n/**\n * The card's action row, shrink-proof so a narrow card's width is absorbed by\n * {@link Attachment.Content}'s own truncation while the actions keep their\n * size.\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 * <Attachment.Actions>\n * \t<Attachment.Action aria-label={t(\"attachment.download\")}><DownloadIcon /></Attachment.Action>\n * \t<Attachment.Action aria-label={t(\"attachment.remove\")}><XIcon /></Attachment.Action>\n * </Attachment.Actions>\n */\nAttachment.Actions = function AttachmentActions(handle: Handle<Attachment.ActionsProps>) {\n\treturn () => {\n\t\tlet { children, mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<div {...rest} data-slot=\"actions\" mix={[flex(), shrink(0), items(\"center\"), gap(1), mix]}>\n\t\t\t\t{children}\n\t\t\t</div>\n\t\t);\n\t};\n};\n\n/**\n * A single card action as a {@link Button}, defaulting to a compact, `\"ghost\"`,\n * neutral control so a row of actions reads as secondary to the card's title.\n * Every {@link Button} prop stays available, `type` included.\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 * <Attachment.Action aria-label={t(\"attachment.download\")}>\n * \t<DownloadIcon />\n * </Attachment.Action>\n * @example\n * <Attachment.Action type=\"submit\" name=\"intent\" value=\"retry\" aria-label={t(\"attachment.retry\")}>\n * \t<RotateCwIcon />\n * </Attachment.Action>\n */\nAttachment.Action = function AttachmentAction(handle: Handle<Attachment.ActionProps>) {\n\treturn () => {\n\t\tlet { color, variant, size, mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<Button\n\t\t\t\tcolor={color ?? DEFAULT_ACTION_COLOR}\n\t\t\t\tvariant={variant ?? DEFAULT_ACTION_VARIANT}\n\t\t\t\tsize={size ?? DEFAULT_ACTION_SIZE}\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"action\"\n\t\t\t\tmix={[shrink(0), mix]}\n\t\t\t/>\n\t\t);\n\t};\n};\n\n/**\n * A wrapper `<div>` whose `href` or `commandfor` stays an inert attribute until\n * a consumer mixes in `attachmentTrigger()`. Either one also derives a `role`\n * and `tabIndex`, so whole-card activation is announced and keyboard-reachable.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the wrapper's markup.\n * @example\n * <Attachment.Trigger href=\"/files/quarterly-report.pdf\" mix={attachmentTrigger()}>\n * \t<Attachment state=\"done\">\n * \t\t<Attachment.Media><FileTextIcon aria-hidden /></Attachment.Media>\n * \t\t<Attachment.Content>\n * \t\t\t<Attachment.Title>quarterly-report.pdf</Attachment.Title>\n * \t\t</Attachment.Content>\n * \t\t<Attachment.Actions>\n * \t\t\t<Attachment.Action aria-label={t(\"attachment.download\")}><DownloadIcon /></Attachment.Action>\n * \t\t</Attachment.Actions>\n * \t</Attachment>\n * </Attachment.Trigger>\n * @example\n * <Attachment.Trigger commandfor=\"quarterly-report-preview\" mix={attachmentTrigger()}>\n * \t<Attachment state=\"done\">…</Attachment>\n * </Attachment.Trigger>\n * <Dialog id=\"quarterly-report-preview\">…</Dialog>\n */\nAttachment.Trigger = function AttachmentTrigger(handle: Handle<Attachment.TriggerProps>) {\n\treturn () => {\n\t\tlet { href, commandfor, command, target, role, tabIndex, children, mix, ...rest } =\n\t\t\thandle.props;\n\t\tlet isConfigured = href !== undefined || commandfor !== undefined;\n\t\tlet resolvedRole = role ?? (href !== undefined ? \"link\" : isConfigured ? \"button\" : undefined);\n\t\tlet resolvedTabIndex = tabIndex ?? (isConfigured ? 0 : undefined);\n\n\t\tif (import.meta.env?.DEV && !isConfigured) {\n\t\t\tconsole.warn(\n\t\t\t\t'Attachment.Trigger: rendered with neither \"href\" nor \"commandfor\" — nothing will happen once `attachmentTrigger()` handles an activation.',\n\t\t\t);\n\t\t}\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\t{...rest}\n\t\t\t\trole={resolvedRole}\n\t\t\t\ttabIndex={resolvedTabIndex}\n\t\t\t\tdata-slot=\"trigger\"\n\t\t\t\tmix={[\n\t\t\t\t\tattrs({ href, commandfor, command, target }),\n\t\t\t\t\trelative(),\n\t\t\t\t\tblock(),\n\t\t\t\t\trounded(\"inherit\"),\n\t\t\t\t\twhen(\"&[role]:hover\", bg(\"neutral.bg-tint-hover\")),\n\t\t\t\t\twhen(\"&[role]:focus-visible\", outline({ color: \"brand.ring\", offset: 2 })),\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 * A horizontally scroll-snapping row of cards, faded at both inline edges to\n * hint at cards beyond the current view. The row itself carries the tab stop,\n * since the row is what scrolls.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the row's markup.\n * @example\n * <Attachment.Group aria-label={t(\"thread.attachments\")}>\n * \t{attachments.map((attachment) => (\n * \t\t<Attachment key={attachment.id} state={attachment.state}>…</Attachment>\n * \t))}\n * </Attachment.Group>\n */\nAttachment.Group = function AttachmentGroup(handle: Handle<Attachment.GroupProps>) {\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=\"group\"\n\t\t\t\tmix={[\n\t\t\t\t\tattrs({ tabIndex: DEFAULT_GROUP_TAB_INDEX }),\n\t\t\t\t\tflex(),\n\t\t\t\t\tgap(3),\n\t\t\t\t\toverflowX(\"auto\"),\n\t\t\t\t\traw({\n\t\t\t\t\t\toverscrollBehaviorInline: \"contain\",\n\t\t\t\t\t\tscrollSnapType: \"inline mandatory\",\n\t\t\t\t\t\tscrollPaddingInline: \"0.75rem\",\n\t\t\t\t\t\tscrollBehavior: \"auto\",\n\t\t\t\t\t}),\n\t\t\t\t\twhen(\"& > *\", [shrink(0), raw({ scrollSnapAlign: \"start\" })]),\n\t\t\t\t\tmedia(\"(prefers-reduced-motion: no-preference)\", raw({ scrollBehavior: \"smooth\" })),\n\t\t\t\t\tscrollFade({ axis: \"inline\", size: GROUP_SCROLL_FADE_SIZE }),\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"
|
|
12
|
+
"content": "/**\n * A compound card presenting one attached file or image — media preview, name,\n * supporting details, actions — plus a horizontally scrolling row for several\n * cards side by side. Every part styles itself off the card's own `state`, and\n * whole-card click-through stays an opt-in wrapper a consumer mixes in.\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 { iife } from \"@sdxc/iife\";\nimport { bg, border, fg, outline } from \"@sdxc/u/color\";\nimport { rounded, transition } from \"@sdxc/u/effects\";\nimport { raw } from \"@sdxc/u/general\";\nimport {\n\tbasis,\n\tblock,\n\tcontainer,\n\tflex,\n\tflexCol,\n\tgap,\n\tgrow,\n\thstack,\n\titems,\n\tjustify,\n\trelative,\n\tshrink,\n\tvstack,\n} from \"@sdxc/u/layout\";\nimport { overflow, overflowX } from \"@sdxc/u/overflow\";\nimport { media } from \"@sdxc/u/responsive\";\nimport { aspect, bs, fit, is, minIs, p } from \"@sdxc/u/size\";\nimport { when } from \"@sdxc/u/state\";\nimport { text, textAlign, truncate, weight } from \"@sdxc/u/typography\";\nimport { attrs } from \"remix/component\";\n\nimport { shimmer } from \"@sdxc/ui/animations\";\nimport { scrollFade } from \"@sdxc/ui/animations\";\n\nimport { Button } from \"@sdxc/ui/button\";\n\nconst DEFAULT_STATE: Attachment.State = \"idle\";\n\n/**\n * Named container {@link Attachment} declares on its own host, so\n * {@link Attachment.Media}, {@link Attachment.Content}, and the inner layout\n * wrapper resolve their width queries against the card itself.\n */\nconst CONTAINER_NAME = \"ui-attachment\";\n\n/**\n * `@container` query every width-adapting part below the root shares: at or\n * under this width the card reflows into a taller tile, the shape\n * {@link Attachment.Group}'s narrow, fixed-width cards need.\n */\nconst NARROW_CONTAINER_QUERY = `@container ${CONTAINER_NAME} (max-width: 12rem)`;\n\n/**\n * Selector fragment gating {@link Attachment.Title}'s shimmer: it matches the\n * title's own `data-state` attribute while that reads `\"uploading\"` or\n * `\"processing\"`, so a title in any other state renders as plain text.\n */\nconst TITLE_SHIMMER_WHEN = ':is([data-state=\"uploading\"], [data-state=\"processing\"])';\n\nconst DEFAULT_ACTION_VARIANT: Button.Variant = \"ghost\";\n\nconst DEFAULT_ACTION_SIZE: Button.Size = \"sm\";\n\nconst DEFAULT_ACTION_COLOR: Button.Color = \"neutral\";\n\n/**\n * Tab-stop order {@link attrs} applies to {@link Attachment.Group} when a\n * consumer supplies no `tabIndex`, so the row itself stays keyboard-reachable\n * and scrollable whatever its cards contain.\n */\nconst DEFAULT_GROUP_TAB_INDEX = 0;\n\nconst GROUP_SCROLL_FADE_SIZE = \"2rem\";\n\n/**\n * Prop types for {@link Attachment} and its compound parts.\n */\nexport namespace Attachment {\n\t/**\n\t * Lifecycle state of a card's file or image. `\"idle\"` and `\"done\"` both\n\t * render as a settled card — `\"idle\"` for a file already on the server,\n\t * `\"done\"` for one whose transfer finished. A consumer owns every transition.\n\t */\n\texport type State = \"idle\" | \"uploading\" | \"processing\" | \"error\" | \"done\";\n\n\t/**\n\t * Props accepted by {@link Attachment}.\n\t */\n\texport interface Props extends TagProps<\"div\"> {\n\t\t/** Lifecycle state of the file or image the card represents. Defaults to `\"idle\"`. */\n\t\tstate?: State;\n\t\t/** The card's compound parts: {@link Attachment.Media}, {@link Attachment.Content}, and {@link Attachment.Actions}. */\n\t\tchildren: RemixNode;\n\t}\n\n\t/**\n\t * Props accepted by {@link Attachment.Media}.\n\t */\n\texport interface MediaProps extends TagProps<\"div\"> {\n\t\t/** The preview itself: an `<img>`, or a decorative icon standing in for the file's type. */\n\t\tchildren: RemixNode;\n\t}\n\n\t/**\n\t * Props accepted by {@link Attachment.Content}.\n\t */\n\texport interface ContentProps extends TagProps<\"div\"> {\n\t\t/** {@link Attachment.Title} and, optionally, {@link Attachment.Description}. */\n\t\tchildren: RemixNode;\n\t}\n\n\t/**\n\t * Props accepted by {@link Attachment.Title}.\n\t */\n\texport interface TitleProps extends TagProps<\"p\"> {\n\t\t/**\n\t\t * The ancestor {@link Attachment}'s own `state`, repeated here because a\n\t\t * component reads only its own props; passing the same value to both is\n\t\t * what keeps them in sync. Left unset, the title renders plain.\n\t\t */\n\t\tstate?: Attachment.State;\n\t\t/** The file or image name. */\n\t\tchildren: RemixNode;\n\t}\n\n\t/**\n\t * Props accepted by {@link Attachment.Description}.\n\t */\n\texport interface DescriptionProps extends TagProps<\"p\"> {\n\t\t/** Supporting detail — a file size, a page count, an error message. */\n\t\tchildren: RemixNode;\n\t}\n\n\t/**\n\t * Props accepted by {@link Attachment.Actions}.\n\t */\n\texport interface ActionsProps extends TagProps<\"div\"> {\n\t\t/** A run of {@link Attachment.Action} controls. */\n\t\tchildren: RemixNode;\n\t}\n\n\t/**\n\t * Props accepted by {@link Attachment.Action}: every {@link Button.Props}\n\t * field, unchanged, so an action keeps the same color, weight, and size\n\t * contract as every other button in the catalog.\n\t */\n\texport interface ActionProps extends Button.Props {}\n\n\t/**\n\t * Props accepted by {@link Attachment.Trigger}.\n\t */\n\texport interface TriggerProps extends TagProps<\"div\"> {\n\t\t/**\n\t\t * Destination the whole card follows once `attachmentTrigger()` is mixed\n\t\t * in, opened in place unless the activation asks for a new tab. It rides on\n\t\t * a `<div>` so a nested {@link Attachment.Action} stays valid markup.\n\t\t */\n\t\thref?: string;\n\t\t/**\n\t\t * `id` of a `<dialog>` element the whole card opens once\n\t\t * `attachmentTrigger()` is mixed in, instead of following `href`.\n\t\t */\n\t\tcommandfor?: string;\n\t\t/** Invoker Commands verb dispatched to `commandfor`'s dialog. Defaults to `\"show-modal\"`. */\n\t\tcommand?: \"show-modal\";\n\t\t/** Where `href` opens: a window/frame name, or `\"_blank\"` for a new tab. Meaningful only alongside `href`. */\n\t\ttarget?: string;\n\t\t/** The card's own markup — typically an {@link Attachment}. */\n\t\tchildren: RemixNode;\n\t}\n\n\t/**\n\t * Props accepted by {@link Attachment.Group}.\n\t */\n\texport interface GroupProps extends TagProps<\"div\"> {\n\t\t/** A run of {@link Attachment} or {@link Attachment.Trigger} cards. */\n\t\tchildren: RemixNode;\n\t}\n}\n\n/**\n * The card's outer host, recolored to the danger tint at `state=\"error\"` and\n * declaring the `ui-attachment` named container so nested parts reflow at the\n * card's width. A busy state sets `aria-busy` to the token ARIA recognizes.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the card's markup.\n * @example\n * <Attachment state=\"uploading\">\n * \t<Attachment.Media><FileIcon aria-hidden /></Attachment.Media>\n * \t<Attachment.Content>\n * \t\t<Attachment.Title state=\"uploading\">quarterly-report.pdf</Attachment.Title>\n * \t\t<Attachment.Description>{t(\"attachment.uploading\")}</Attachment.Description>\n * \t</Attachment.Content>\n * </Attachment>\n * @example\n * <Attachment state=\"error\">\n * \t<Attachment.Media><FileIcon aria-hidden /></Attachment.Media>\n * \t<Attachment.Content>\n * \t\t<Attachment.Title>quarterly-report.pdf</Attachment.Title>\n * \t\t<Attachment.Description>{t(\"attachment.uploadFailed\")}</Attachment.Description>\n * \t</Attachment.Content>\n * \t<Attachment.Actions>\n * \t\t<Attachment.Action aria-label={t(\"attachment.retry\")}><RotateCwIcon /></Attachment.Action>\n * \t</Attachment.Actions>\n * </Attachment>\n */\nexport function Attachment(handle: Handle<Attachment.Props>) {\n\treturn () => {\n\t\tlet { state, children, mix, ...rest } = handle.props;\n\t\tlet resolvedState = state ?? DEFAULT_STATE;\n\t\tlet isBusy = resolvedState === \"uploading\" || resolvedState === \"processing\";\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"attachment\"\n\t\t\t\tdata-state={resolvedState}\n\t\t\t\taria-busy={isBusy ? \"true\" : undefined}\n\t\t\t\tmix={[\n\t\t\t\t\trelative(),\n\t\t\t\t\trounded(\"lg\"),\n\t\t\t\t\tborder({ width: 1 }),\n\t\t\t\t\tborder(\"neutral\"),\n\t\t\t\t\tbg(\"neutral.tint\"),\n\t\t\t\t\tfg(\"neutral.emphasis\"),\n\t\t\t\t\tp(3),\n\t\t\t\t\ttransition(\"border-color, background-color\"),\n\t\t\t\t\tcontainer(CONTAINER_NAME),\n\t\t\t\t\twhen('&[data-state=\"error\"]', [\n\t\t\t\t\t\tborder(\"danger\"),\n\t\t\t\t\t\tbg(\"danger.tint\"),\n\t\t\t\t\t\tfg(\"danger.emphasis\"),\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<div\n\t\t\t\t\tdata-slot=\"body\"\n\t\t\t\t\tmix={[\n\t\t\t\t\t\thstack({ gap: 3, align: \"center\" }),\n\t\t\t\t\t\twhen(NARROW_CONTAINER_QUERY, [flexCol(), items(\"stretch\")]),\n\t\t\t\t\t]}\n\t\t\t\t>\n\t\t\t\t\t{children}\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t);\n\t};\n}\n\n/**\n * The card's media well: a fixed-size, rounded box clipping the preview a\n * consumer nests inside. Inside a narrow container it grows to the card's own\n * inline size at a wider aspect ratio, reading as a thumbnail tile.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the media well's markup.\n * @example\n * <Attachment.Media><img src={file.thumbnailUrl} alt=\"\" /></Attachment.Media>\n * @example\n * <Attachment.Media><FileTextIcon aria-hidden /></Attachment.Media>\n */\nAttachment.Media = function AttachmentMedia(handle: Handle<Attachment.MediaProps>) {\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=\"media\"\n\t\t\t\tmix={[\n\t\t\t\t\tflex(),\n\t\t\t\t\tshrink(0),\n\t\t\t\t\titems(\"center\"),\n\t\t\t\t\tjustify(\"center\"),\n\t\t\t\t\toverflow(),\n\t\t\t\t\tis(10),\n\t\t\t\t\tbs(10),\n\t\t\t\t\trounded(\"md\"),\n\t\t\t\t\tbg(\"neutral.bg-tint-hover\"),\n\t\t\t\t\tfg(\"neutral\"),\n\t\t\t\t\twhen(\"& > svg\", [is(5), bs(5)]),\n\t\t\t\t\twhen(\"& > img\", [is(\"full\"), bs(\"full\"), fit(\"cover\")]),\n\t\t\t\t\twhen(NARROW_CONTAINER_QUERY, [is(\"full\"), bs(\"auto\"), aspect(4, 3), rounded(\"lg\")]),\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 * The card's text column, growing into whatever inline space\n * {@link Attachment.Media} and {@link Attachment.Actions} leave it. Its minimum\n * inline size collapses to `0`, which is what lets its children truncate.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the text column's markup.\n * @example\n * <Attachment.Content>\n * \t<Attachment.Title>quarterly-report.pdf</Attachment.Title>\n * \t<Attachment.Description>2.4 MB</Attachment.Description>\n * </Attachment.Content>\n */\nAttachment.Content = function AttachmentContent(handle: Handle<Attachment.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={[\n\t\t\t\t\tvstack({ gap: 0.5 }),\n\t\t\t\t\tminIs(0),\n\t\t\t\t\tgrow(),\n\t\t\t\t\tshrink(1),\n\t\t\t\t\tbasis(\"0%\"),\n\t\t\t\t\twhen(NARROW_CONTAINER_QUERY, textAlign(\"center\")),\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 * The file or image name in a native `<p>`, truncated to a single line with an\n * ellipsis. Given the same `state` as the ancestor {@link Attachment}, it\n * shimmers while that reads `\"uploading\"` or `\"processing\"`, then settles.\n *\n * @param handle Runtime handle carrying the host `<p>`'s props.\n * @returns The render function producing the title's markup.\n * @example\n * <Attachment.Title>quarterly-report.pdf</Attachment.Title>\n * @example\n * <Attachment.Title state={attachment.state}>{attachment.name}</Attachment.Title>\n */\nAttachment.Title = function AttachmentTitle(handle: Handle<Attachment.TitleProps>) {\n\treturn () => {\n\t\tlet { state, 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=\"title\"\n\t\t\t\tdata-state={state}\n\t\t\t\tmix={[\n\t\t\t\t\tweight(\"semibold\"),\n\t\t\t\t\ttruncate(),\n\t\t\t\t\ttext(\"sm\"),\n\t\t\t\t\t/**\n\t\t\t\t\t * The loop settles visible, because this host carries the file's name: a gated\n\t\t\t\t\t * loop rests hidden outside its gate, which suits an element that exists only\n\t\t\t\t\t * as a loading cue and would leave every finished upload unnamed.\n\t\t\t\t\t */\n\t\t\t\t\tshimmer({ when: TITLE_SHIMMER_WHEN, outsideGate: \"visible\" }),\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 * The card's supporting detail line: a muted, single-line `<p>` carrying a file\n * size, a page count, or the explanation of what went wrong once the ancestor\n * {@link Attachment}'s `state` reads `\"error\"`.\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 * <Attachment.Description>2.4 MB</Attachment.Description>\n * @example\n * <Attachment.Description>{t(\"attachment.uploadFailed\")}</Attachment.Description>\n */\nAttachment.Description = function AttachmentDescription(\n\thandle: Handle<Attachment.DescriptionProps>,\n) {\n\treturn () => {\n\t\tlet { children, mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<p {...rest} data-slot=\"description\" mix={[truncate(), fg(\"neutral.muted\"), text(\"xs\"), mix]}>\n\t\t\t\t{children}\n\t\t\t</p>\n\t\t);\n\t};\n};\n\n/**\n * The card's action row, shrink-proof so a narrow card's width is absorbed by\n * {@link Attachment.Content}'s own truncation while the actions keep their\n * size.\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 * <Attachment.Actions>\n * \t<Attachment.Action aria-label={t(\"attachment.download\")}><DownloadIcon /></Attachment.Action>\n * \t<Attachment.Action aria-label={t(\"attachment.remove\")}><XIcon /></Attachment.Action>\n * </Attachment.Actions>\n */\nAttachment.Actions = function AttachmentActions(handle: Handle<Attachment.ActionsProps>) {\n\treturn () => {\n\t\tlet { children, mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<div {...rest} data-slot=\"actions\" mix={[flex(), shrink(0), items(\"center\"), gap(1), mix]}>\n\t\t\t\t{children}\n\t\t\t</div>\n\t\t);\n\t};\n};\n\n/**\n * A single card action as a {@link Button}, defaulting to a compact, `\"ghost\"`,\n * neutral control so a row of actions reads as secondary to the card's title.\n * Every {@link Button} prop stays available, `type` included.\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 * <Attachment.Action aria-label={t(\"attachment.download\")}>\n * \t<DownloadIcon />\n * </Attachment.Action>\n * @example\n * <Attachment.Action type=\"submit\" name=\"intent\" value=\"retry\" aria-label={t(\"attachment.retry\")}>\n * \t<RotateCwIcon />\n * </Attachment.Action>\n */\nAttachment.Action = function AttachmentAction(handle: Handle<Attachment.ActionProps>) {\n\treturn () => {\n\t\tlet { color, variant, size, mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<Button\n\t\t\t\tcolor={color ?? DEFAULT_ACTION_COLOR}\n\t\t\t\tvariant={variant ?? DEFAULT_ACTION_VARIANT}\n\t\t\t\tsize={size ?? DEFAULT_ACTION_SIZE}\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"action\"\n\t\t\t\tmix={[shrink(0), mix]}\n\t\t\t/>\n\t\t);\n\t};\n};\n\n/**\n * A wrapper `<div>` whose `href` or `commandfor` stays an inert attribute until\n * a consumer mixes in `attachmentTrigger()`. Either one also derives a `role`\n * and `tabIndex`, so whole-card activation is announced and keyboard-reachable.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the wrapper's markup.\n * @example\n * <Attachment.Trigger href=\"/files/quarterly-report.pdf\" mix={attachmentTrigger()}>\n * \t<Attachment state=\"done\">\n * \t\t<Attachment.Media><FileTextIcon aria-hidden /></Attachment.Media>\n * \t\t<Attachment.Content>\n * \t\t\t<Attachment.Title>quarterly-report.pdf</Attachment.Title>\n * \t\t</Attachment.Content>\n * \t\t<Attachment.Actions>\n * \t\t\t<Attachment.Action aria-label={t(\"attachment.download\")}><DownloadIcon /></Attachment.Action>\n * \t\t</Attachment.Actions>\n * \t</Attachment>\n * </Attachment.Trigger>\n * @example\n * <Attachment.Trigger commandfor=\"quarterly-report-preview\" mix={attachmentTrigger()}>\n * \t<Attachment state=\"done\">…</Attachment>\n * </Attachment.Trigger>\n * <Dialog id=\"quarterly-report-preview\">…</Dialog>\n */\nAttachment.Trigger = function AttachmentTrigger(handle: Handle<Attachment.TriggerProps>) {\n\treturn () => {\n\t\tlet { href, commandfor, command, target, role, tabIndex, children, mix, ...rest } =\n\t\t\thandle.props;\n\t\tlet isConfigured = href !== undefined || commandfor !== undefined;\n\t\tlet inferredRole = iife((): \"link\" | \"button\" | undefined => {\n\t\t\tif (href !== undefined) return \"link\";\n\t\t\tif (isConfigured) return \"button\";\n\t\t\treturn undefined;\n\t\t});\n\t\tlet resolvedRole = role ?? inferredRole;\n\t\tlet resolvedTabIndex = tabIndex ?? (isConfigured ? 0 : undefined);\n\n\t\tif (import.meta.env?.DEV && !isConfigured) {\n\t\t\tconsole.warn(\n\t\t\t\t'Attachment.Trigger: rendered with neither \"href\" nor \"commandfor\" — nothing will happen once `attachmentTrigger()` handles an activation.',\n\t\t\t);\n\t\t}\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\t{...rest}\n\t\t\t\trole={resolvedRole}\n\t\t\t\ttabIndex={resolvedTabIndex}\n\t\t\t\tdata-slot=\"trigger\"\n\t\t\t\tmix={[\n\t\t\t\t\tattrs({ href, commandfor, command, target }),\n\t\t\t\t\trelative(),\n\t\t\t\t\tblock(),\n\t\t\t\t\trounded(\"inherit\"),\n\t\t\t\t\twhen(\"&[role]:hover\", bg(\"neutral.bg-tint-hover\")),\n\t\t\t\t\twhen(\"&[role]:focus-visible\", outline({ color: \"brand.ring\", offset: 2 })),\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 * A horizontally scroll-snapping row of cards, faded at both inline edges to\n * hint at cards beyond the current view. The row itself carries the tab stop,\n * since the row is what scrolls.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the row's markup.\n * @example\n * <Attachment.Group aria-label={t(\"thread.attachments\")}>\n * \t{attachments.map((attachment) => (\n * \t\t<Attachment key={attachment.id} state={attachment.state}>…</Attachment>\n * \t))}\n * </Attachment.Group>\n */\nAttachment.Group = function AttachmentGroup(handle: Handle<Attachment.GroupProps>) {\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=\"group\"\n\t\t\t\tmix={[\n\t\t\t\t\tattrs({ tabIndex: DEFAULT_GROUP_TAB_INDEX }),\n\t\t\t\t\tflex(),\n\t\t\t\t\tgap(3),\n\t\t\t\t\toverflowX(\"auto\"),\n\t\t\t\t\traw({\n\t\t\t\t\t\toverscrollBehaviorInline: \"contain\",\n\t\t\t\t\t\tscrollSnapType: \"inline mandatory\",\n\t\t\t\t\t\tscrollPaddingInline: \"0.75rem\",\n\t\t\t\t\t\tscrollBehavior: \"auto\",\n\t\t\t\t\t}),\n\t\t\t\t\twhen(\"& > *\", [shrink(0), raw({ scrollSnapAlign: \"start\" })]),\n\t\t\t\t\tmedia(\"(prefers-reduced-motion: no-preference)\", raw({ scrollBehavior: \"smooth\" })),\n\t\t\t\t\tscrollFade({ axis: \"inline\", size: GROUP_SCROLL_FADE_SIZE }),\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"
|
|
13
13
|
},
|
|
14
14
|
"test": null
|
|
15
15
|
}
|