@sdxc/kit 2026.11.27 → 2026.11.29

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.
Files changed (38) hide show
  1. package/changelog.jsonl +189 -0
  2. package/dist/pkg/catalog.js +1 -0
  3. package/dist/scaffold/render.js +2 -2
  4. package/package.json +2 -2
  5. package/registry/ui/anchor-heading.json +19 -0
  6. package/registry/ui/autocomplete.json +3 -3
  7. package/registry/ui/banner.json +3 -3
  8. package/registry/ui/button.json +3 -3
  9. package/registry/ui/callout.json +16 -0
  10. package/registry/ui/checkbox.json +2 -2
  11. package/registry/ui/code-block.json +18 -0
  12. package/registry/ui/confirm.json +3 -3
  13. package/registry/ui/copy-button.json +14 -0
  14. package/registry/ui/date-field.json +4 -7
  15. package/registry/ui/date-picker.json +3 -5
  16. package/registry/ui/date-range-picker.json +2 -3
  17. package/registry/ui/dialog-dismiss.json +2 -2
  18. package/registry/ui/field-parts.json +30 -0
  19. package/registry/ui/filter-links.json +16 -0
  20. package/registry/ui/form.json +3 -3
  21. package/registry/ui/listbox.json +2 -2
  22. package/registry/ui/media-grid.json +3 -3
  23. package/registry/ui/pager.json +16 -0
  24. package/registry/ui/property-list.json +3 -3
  25. package/registry/ui/radio-group.json +2 -2
  26. package/registry/ui/range-calendar.json +2 -2
  27. package/registry/ui/range-months.json +3 -3
  28. package/registry/ui/rating-input.json +3 -3
  29. package/registry/ui/rating.json +3 -3
  30. package/registry/ui/review-card.json +3 -3
  31. package/registry/ui/search-field.json +6 -3
  32. package/registry/ui/section-bar.json +3 -3
  33. package/registry/ui/sidebar.json +2 -2
  34. package/registry/ui/table-of-contents.json +17 -0
  35. package/registry/ui/text-field.json +5 -9
  36. package/registry/ui/time-field.json +4 -7
  37. package/registry/ui/timeline.json +3 -3
  38. package/registry/ui/typeset.json +2 -2
@@ -0,0 +1,18 @@
1
+ {
2
+ "name": "code-block",
3
+ "changedIn": "2026.11.29",
4
+ "dependencies": [
5
+ "copy-button"
6
+ ],
7
+ "exports": [
8
+ "CodeBlock"
9
+ ],
10
+ "source": {
11
+ "path": "code-block.tsx",
12
+ "content": "/**\n * A titled code card for documentation: the file it belongs to (with an icon for its\n * kind) or \"Terminal\", highlighted, added and removed lines, optional line numbers, and a\n * copy button that copies what a reader should paste — no `$` prompts, no output lines.\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 { tokenize } from \"@sdxc/highlight\";\nimport { FileCodeIcon, FileIcon, TerminalIcon } from \"@sdxc/icons\";\nimport { bg, border, borderEdge, fg } from \"@sdxc/u/color\";\nimport { rounded } from \"@sdxc/u/effects\";\nimport { mergeMix, raw } from \"@sdxc/u/general\";\nimport { absolute, hstack, inlineFlex, insBs, insIe, relative, shrink } from \"@sdxc/u/layout\";\nimport { overflowX } from \"@sdxc/u/overflow\";\nimport { bs, m, minIs, pi } from \"@sdxc/u/size\";\nimport { z } from \"@sdxc/u/stacking\";\nimport { when } from \"@sdxc/u/state\";\nimport { font, text, truncate } from \"@sdxc/u/typography\";\n\nimport { COPY_EXCLUDE_ATTRIBUTE } from \"@sdxc/ui/mixins\";\nimport { codeLines } from \"@sdxc/ui/utils\";\nimport { fileIcon } from \"@sdxc/ui/utils\";\n\nimport { CopyButton } from \"@sdxc/ui/copy-button\";\n\n/** Inline padding of every line, which a marked line splits between its bar and its text. */\nconst LINE_INSET = \"1rem\";\n\n/** Width of the bar a marked line draws on its inline-start edge. */\nconst MARK_BAR = \"2px\";\n\n/** Languages whose blocks are shell sessions: a `$ ` prompt marks a command, not code. */\nconst SHELL_LANGUAGES = new Set([\"sh\", \"bash\", \"shell\", \"zsh\", \"fish\", \"console\", \"terminal\"]);\n\n/** The prompt a shell block draws before each command, outside the copied text. */\nconst PROMPT = \"$ \";\n\n/**\n * Token colors as `[light, dark]` pairs, the GitHub palettes the shared highlight\n * stylesheet ships, used when the page declares no `--highlight-*` property of its own.\n */\nconst TOKEN_PALETTE: Record<string, readonly [string, string]> = {\n\tcomment: [\"#6a737d\", \"#8b949e\"],\n\tkeyword: [\"#d73a49\", \"#ff7b72\"],\n\toperator: [\"#d73a49\", \"#ff7b72\"],\n\tstring: [\"#032f62\", \"#a5d6ff\"],\n\tbuiltin: [\"#032f62\", \"#a5d6ff\"],\n\t\"attr-name\": [\"#032f62\", \"#a5d6ff\"],\n\t\"attr-value\": [\"#032f62\", \"#a5d6ff\"],\n\tnumber: [\"#005cc5\", \"#79c0ff\"],\n\tboolean: [\"#005cc5\", \"#79c0ff\"],\n\tconstant: [\"#005cc5\", \"#79c0ff\"],\n\tproperty: [\"#005cc5\", \"#79c0ff\"],\n\ttag: [\"#005cc5\", \"#79c0ff\"],\n\tfunction: [\"#6f42c1\", \"#d2a8ff\"],\n\t\"class-name\": [\"#6f42c1\", \"#d2a8ff\"],\n\tregex: [\"#e36209\", \"#ffa657\"],\n\tvariable: [\"#e36209\", \"#ffa657\"],\n\tpunctuation: [\"#24292f\", \"#e6edf3\"],\n\tinserted: [\"#22863a\", \"#7ee787\"],\n\tdeleted: [\"#b31d28\", \"#ffa198\"],\n};\n\n/** FNV-1a offset basis, the starting state of the hash that names a block's code. */\nconst FNV_OFFSET = 0x811c9dc5;\n\n/** FNV-1a prime, which spreads each character through the hash. */\nconst FNV_PRIME = 0x01000193;\n\n/** The marker attribute the card's layout selects its floating copy button by. */\nconst PART = \"data-code-block-part\";\n\n/**\n * Prop types for {@link CodeBlock} and its parts.\n */\nexport namespace CodeBlock {\n\t/** What the card shares with its parts. */\n\texport interface Context {\n\t\t/** The `id` of the `<code>` element the copy button targets. */\n\t\tcodeId: string;\n\t\t/** The copy button's strings, which a {@link CodeBlock.Copy} reads too. */\n\t\tlabels: Labels;\n\t\t/** Whether the block is a shell session, which a title's icon shows as a terminal. */\n\t\tshell: boolean;\n\t}\n\n\t/** What a header shares with the copy button inside it. */\n\texport interface HeaderContext {\n\t\tinHeader: true;\n\t}\n\n\t/** Every native `<figcaption>` attribute. */\n\texport interface HeaderProps extends TagProps<\"figcaption\"> {}\n\n\t/**\n\t * Every native `<span>` attribute. A text title that names a file path is set in the mono\n\t * face after an icon for its kind; \"Terminal\" or a shell block draws a terminal.\n\t */\n\texport interface TitleProps extends TagProps<\"span\"> {}\n\n\t/** Every native `<span>` attribute of the button's box. */\n\texport interface CopyProps extends TagProps<\"span\"> {}\n\n\t/**\n\t * One painted run of source. Structural, so the runs a Markdown pipeline already\n\t * painted with `@sdxc/highlight` pass straight through.\n\t */\n\texport interface Token {\n\t\ttype: string;\n\t\tvalue: string;\n\t}\n\n\t/** The copy button's strings; the library ships no copy of its own. */\n\texport interface Labels {\n\t\t/** The button's accessible name, such as \"Copy code\". */\n\t\tcopy: string;\n\t\t/** What a screen reader announces after a copy, such as \"Copied\". */\n\t\tcopied: string;\n\t}\n\n\t/** How a line is marked: a changed line to look at, or a line a diff adds or removes. */\n\texport type Mark = \"highlight\" | \"add\" | \"remove\";\n\n\t/**\n\t * Props accepted by {@link CodeBlock}. Line numbers in `highlight`, `add` and `remove`\n\t * count from 1, the way prose refers to them.\n\t */\n\texport interface Props extends TagProps<\"figure\"> {\n\t\t/** The source as written; a single trailing newline is dropped. */\n\t\tcode: string;\n\t\t/** Language the code highlights as, named the way a fence names it (`ts`, `sh`). */\n\t\tlanguage?: string;\n\t\t/** Runs already painted for `code`, which skip highlighting here. */\n\t\ttokens?: readonly Token[];\n\t\t/**\n\t\t * The parts drawn over the code, such as a {@link CodeBlock.Header} naming the file.\n\t\t * Without any, the card draws a header naming the language with the copy button, or,\n\t\t * with no language either, floats the copy button over the code.\n\t\t */\n\t\tchildren?: RemixNode;\n\t\thighlight?: readonly number[];\n\t\tadd?: readonly number[];\n\t\t/** Lines a diff removes; they stay on screen and stay off the clipboard. */\n\t\tremove?: readonly number[];\n\t\t/** Numbers each line in a gutter, for long listings prose refers to by line. */\n\t\tlineNumbers?: boolean;\n\t\t/** The copy button's strings, which a {@link CodeBlock.Copy} reads too. */\n\t\tlabels: Labels;\n\t\t/**\n\t\t * The `id` of the `<code>` element the copy button targets. Defaults to one derived\n\t\t * from the code, which stays the same on every render of the same block.\n\t\t */\n\t\tcodeId?: string;\n\t}\n}\n\n/** One source line as the block draws it. */\ninterface Line {\n\ttokens: CodeBlock.Token[];\n\tmark: CodeBlock.Mark | undefined;\n\t/** Whether the line is a shell command drawn after a prompt. */\n\tprompt: boolean;\n\t/** Whether the line is shell output, which stays off the clipboard. */\n\toutput: boolean;\n}\n\n/**\n * Renders the card: the parts it holds (or a header naming the language with the copy button),\n * then the code, which scrolls sideways inside the card. Marked lines tint across the full\n * scroll width with a 2px bar whose width comes out of the line's padding, so no text moves.\n *\n * @param handle Runtime handle carrying the block's props.\n * @returns The render function producing the card.\n * @example\n * <CodeBlock language=\"ts\" code={source} highlight={[4, 5]} labels={{ copy: t(\"copy\"), copied: t(\"copied\") }}>\n * \t<CodeBlock.Header>\n * \t\t<CodeBlock.Title>vite.config.ts</CodeBlock.Title>\n * \t\t<CodeBlock.Copy />\n * \t</CodeBlock.Header>\n * </CodeBlock>\n * @example\n * <CodeBlock language=\"sh\" code={\"$ npm add @sdxc/ui\"} labels={labels} />\n */\nexport function CodeBlock(handle: Handle<CodeBlock.Props, CodeBlock.Context>) {\n\treturn () => {\n\t\tlet {\n\t\t\tadd,\n\t\t\tchildren,\n\t\t\tcode,\n\t\t\tcodeId,\n\t\t\thighlight,\n\t\t\tlabels,\n\t\t\tlanguage,\n\t\t\tlineNumbers = false,\n\t\t\tmix,\n\t\t\tremove,\n\t\t\ttokens,\n\t\t\t...rest\n\t\t} = handle.props;\n\n\t\tlet shell = isShell(language);\n\t\tlet lines = paintLines(code, language, tokens, shell, { add, highlight, remove });\n\t\tlet id = codeId ?? stableId(code);\n\t\tlet digits = Math.max(2, String(lines.length).length);\n\t\thandle.context.set({ codeId: id, labels, shell });\n\n\t\treturn (\n\t\t\t<figure\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"code-block\"\n\t\t\t\tdata-language={language}\n\t\t\t\tmix={mergeMix(\n\t\t\t\t\t[\n\t\t\t\t\t\trelative(),\n\t\t\t\t\t\tm(0),\n\t\t\t\t\t\tminIs(0),\n\t\t\t\t\t\trounded(\"lg\"),\n\t\t\t\t\t\tborder({ color: \"neutral.border\", width: 1, style: \"solid\" }),\n\t\t\t\t\t\tbg(\"neutral.bg-tint\"),\n\t\t\t\t\t\traw({ overflow: \"hidden\" }),\n\t\t\t\t\t\twhen(`&:has(> [${PART}=copy])`, raw({ \"--ui-code-block-line-end\": \"3rem\" })),\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{children ?? <DefaultHeader language={language} />}\n\n\t\t\t\t<pre\n\t\t\t\t\tdata-not-typeset=\"\"\n\t\t\t\t\tdata-line-numbers={lineNumbers ? \"\" : undefined}\n\t\t\t\t\tmix={[\n\t\t\t\t\t\tm(0),\n\t\t\t\t\t\toverflowX(\"auto\"),\n\t\t\t\t\t\tfg(\"neutral.emphasis\"),\n\t\t\t\t\t\tfont(\"mono\"),\n\t\t\t\t\t\traw({\n\t\t\t\t\t\t\tpaddingBlock: \"0.875rem\",\n\t\t\t\t\t\t\tpaddingInline: 0,\n\t\t\t\t\t\t\tborder: 0,\n\t\t\t\t\t\t\tborderRadius: 0,\n\t\t\t\t\t\t\tbackground: \"transparent\",\n\t\t\t\t\t\t\tfontSize: \"0.8125rem\",\n\t\t\t\t\t\t\tlineHeight: 1.7,\n\t\t\t\t\t\t\twhiteSpace: \"pre\",\n\t\t\t\t\t\t\ttabSize: 4,\n\t\t\t\t\t\t\toverscrollBehaviorInline: \"contain\",\n\t\t\t\t\t\t}),\n\t\t\t\t\t]}\n\t\t\t\t>\n\t\t\t\t\t<code\n\t\t\t\t\t\tid={id}\n\t\t\t\t\t\tclassName={language ? `language-${language}` : undefined}\n\t\t\t\t\t\tmix={[lineRules(lineNumbers, digits)]}\n\t\t\t\t\t>\n\t\t\t\t\t\t{renderLines(lines)}\n\t\t\t\t\t</code>\n\t\t\t\t</pre>\n\t\t\t</figure>\n\t\t);\n\t};\n}\n\n/** Props {@link DefaultHeader} reads. */\ninterface DefaultHeaderProps {\n\tlanguage: string | undefined;\n}\n\n/**\n * What a card with no parts draws: a header naming its language with the copy button, or the\n * copy button floating over the code when the block names no language.\n *\n * @param handle Runtime handle carrying the block's language.\n * @returns The render function producing the header or the floating button.\n */\nfunction DefaultHeader(handle: Handle<DefaultHeaderProps>) {\n\treturn () => {\n\t\tlet { language } = handle.props;\n\t\tif (!language || language === \"plain\") return <CodeBlock.Copy />;\n\t\treturn (\n\t\t\t<CodeBlock.Header>\n\t\t\t\t<CodeBlock.Title>{language}</CodeBlock.Title>\n\t\t\t\t<CodeBlock.Copy />\n\t\t\t</CodeBlock.Header>\n\t\t);\n\t};\n}\n\n/**\n * The header row over the code, holding a {@link CodeBlock.Title} at its start and a\n * {@link CodeBlock.Copy} at its end.\n *\n * @param handle Runtime handle carrying the host `<figcaption>`'s props.\n * @returns The render function producing the header.\n */\nCodeBlock.Header = function CodeBlockHeader(\n\thandle: Handle<CodeBlock.HeaderProps, CodeBlock.HeaderContext>,\n) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\t\thandle.context.set({ inHeader: true });\n\t\treturn (\n\t\t\t<figcaption\n\t\t\t\tdata-slot=\"code-block-header\"\n\t\t\t\t{...rest}\n\t\t\t\tmix={mergeMix(\n\t\t\t\t\t[\n\t\t\t\t\t\thstack({ gap: 2, align: \"center\", justify: \"between\" }),\n\t\t\t\t\t\tbs(\"2.5rem\"),\n\t\t\t\t\t\tpi(4, 1),\n\t\t\t\t\t\tborderEdge(\"block-end\", { color: \"neutral.border\", width: 1, style: \"solid\" }),\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 * What the header reads as, after an icon for its kind: a file path in the mono face, or any\n * other words (such as \"Terminal\") as written, truncated to one line.\n *\n * @param handle Runtime handle carrying the host `<span>`'s props.\n * @returns The render function producing the title.\n * @example <CodeBlock.Title>app/routes.ts</CodeBlock.Title>\n */\nCodeBlock.Title = function CodeBlockTitle(handle: Handle<CodeBlock.TitleProps>) {\n\treturn () => {\n\t\tlet { children, mix, ...rest } = handle.props;\n\t\tlet context = handle.context.get(CodeBlock) as CodeBlock.Context | undefined;\n\t\tlet title = typeof children === \"string\" ? children : undefined;\n\t\tlet shell = (context?.shell ?? false) || title?.trim().toLowerCase() === \"terminal\";\n\t\treturn (\n\t\t\t<span\n\t\t\t\tdata-slot=\"code-block-title\"\n\t\t\t\t{...rest}\n\t\t\t\tmix={mergeMix([hstack({ gap: 2, align: \"center\" }), minIs(0), fg(\"neutral\")], mix)}\n\t\t\t>\n\t\t\t\t<span data-slot=\"code-block-icon\" mix={[inlineFlex(), shrink(0)]}>\n\t\t\t\t\t<TitleIcon title={title} shell={shell} />\n\t\t\t\t</span>\n\t\t\t\t<span mix={[minIs(0), truncate(), title && isPath(title) ? font(\"mono\") : [], text(\"xs\")]}>\n\t\t\t\t\t{children}\n\t\t\t\t</span>\n\t\t\t</span>\n\t\t);\n\t};\n};\n\n/**\n * The copy button, which copies what a reader should paste: at a header's end, or floating over\n * the code's top corner when written directly in the card.\n *\n * @param handle Runtime handle carrying the button box's props.\n * @returns The render function producing the button.\n */\nCodeBlock.Copy = function CodeBlockCopy(handle: Handle<CodeBlock.CopyProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\t\tlet context = handle.context.get(CodeBlock) as CodeBlock.Context | undefined;\n\t\tlet header = handle.context.get(CodeBlock.Header) as CodeBlock.HeaderContext | undefined;\n\t\tlet labels = context?.labels;\n\t\treturn (\n\t\t\t<span\n\t\t\t\tdata-slot=\"code-block-copy\"\n\t\t\t\t{...rest}\n\t\t\t\tdata-code-block-part=\"copy\"\n\t\t\t\tmix={mergeMix(\n\t\t\t\t\theader ? [inlineFlex()] : [absolute(), insBs(\"0.375rem\"), insIe(\"0.375rem\"), z(1)],\n\t\t\t\t\tmix,\n\t\t\t\t)}\n\t\t\t>\n\t\t\t\t<CopyButton\n\t\t\t\t\ttarget={context?.codeId ?? \"\"}\n\t\t\t\t\tlabel={labels?.copy ?? \"\"}\n\t\t\t\t\tcopiedLabel={labels?.copied ?? \"\"}\n\t\t\t\t/>\n\t\t\t</span>\n\t\t);\n\t};\n};\n\n/**\n * Every rule the lines follow, in one block so a marked line's padding, bar and tint\n * resolve by specificity alone. The grid makes each line as wide as the longest one, so a\n * tint runs the full scroll width, and drops the newlines between lines from layout while\n * leaving them in the text a copy reads.\n *\n * Lines end on `--ui-code-block-line-end`, which a card with a floating copy button widens.\n *\n * @param lineNumbers Whether lines draw a gutter number.\n * @param digits Digits the widest line number needs.\n */\nfunction lineRules(lineNumbers: boolean, digits: number) {\n\tlet markedInset = `calc(${LINE_INSET} - ${MARK_BAR})`;\n\tlet tint = (tone: string) => `color-mix(in oklab, var(--ui-${tone}-fg) 12%, transparent)`;\n\n\treturn raw({\n\t\tdisplay: \"grid\",\n\t\tminInlineSize: \"100%\",\n\t\tinlineSize: \"max-content\",\n\t\tcounterReset: \"line\",\n\t\tfont: \"inherit\",\n\t\tbackground: \"transparent\",\n\t\tpadding: 0,\n\t\t\"& > [data-line]\": {\n\t\t\tposition: \"relative\",\n\t\t\tminBlockSize: \"1lh\",\n\t\t\tpaddingInlineStart: LINE_INSET,\n\t\t\tpaddingInlineEnd: `var(--ui-code-block-line-end, ${LINE_INSET})`,\n\t\t\tcounterIncrement: \"line\",\n\t\t},\n\t\t\"& > [data-mark]\": {\n\t\t\tpaddingInlineStart: markedInset,\n\t\t\tborderInlineStartWidth: MARK_BAR,\n\t\t\tborderInlineStartStyle: \"solid\",\n\t\t},\n\t\t'& > [data-mark=\"highlight\"]': {\n\t\t\tbackgroundColor: tint(\"brand\"),\n\t\t\tborderInlineStartColor: `var(--ui-brand-fg)`,\n\t\t},\n\t\t'& > [data-mark=\"add\"]': {\n\t\t\tbackgroundColor: tint(\"success\"),\n\t\t\tborderInlineStartColor: `var(--ui-success-fg)`,\n\t\t},\n\t\t'& > [data-mark=\"remove\"]': {\n\t\t\tbackgroundColor: tint(\"danger\"),\n\t\t\tborderInlineStartColor: `var(--ui-danger-fg)`,\n\t\t},\n\t\t'& > [data-mark=\"add\"]::after, & > [data-mark=\"remove\"]::after': {\n\t\t\tposition: \"absolute\",\n\t\t\tinsetInlineStart: \"0.3rem\",\n\t\t\tuserSelect: \"none\",\n\t\t\tcolor: \"var(--ui-neutral-fg-muted)\",\n\t\t},\n\t\t'& > [data-mark=\"add\"]::after': { content: '\"+\"' },\n\t\t'& > [data-mark=\"remove\"]::after': { content: '\"-\"' },\n\t\t\"& > [data-output]\": { color: \"var(--ui-neutral-fg-muted)\" },\n\t\t\"& [data-prompt]::before\": {\n\t\t\tcontent: `\"${PROMPT}\"`,\n\t\t\tuserSelect: \"none\",\n\t\t\tcolor: \"var(--ui-neutral-fg-muted)\",\n\t\t},\n\t\t...(lineNumbers\n\t\t\t? {\n\t\t\t\t\t\"& > [data-line]::before\": {\n\t\t\t\t\t\tcontent: \"counter(line)\",\n\t\t\t\t\t\tdisplay: \"inline-block\",\n\t\t\t\t\t\tinlineSize: `${digits}ch`,\n\t\t\t\t\t\tmarginInlineEnd: \"1.5ch\",\n\t\t\t\t\t\ttextAlign: \"end\",\n\t\t\t\t\t\tuserSelect: \"none\",\n\t\t\t\t\t\tcolor: \"var(--ui-neutral-fg-muted)\",\n\t\t\t\t\t},\n\t\t\t\t}\n\t\t\t: {}),\n\t});\n}\n\n/** Props for {@link TitleIcon}. */\ninterface TitleIconProps {\n\ttitle: string | undefined;\n\tshell: boolean;\n}\n\n/**\n * The glyph before the header text: a terminal for a shell session, otherwise a file\n * glyph picked by the title's extension, so a reader sees what kind of file it is; an\n * extension without a glyph of its own reads as source code.\n */\nfunction TitleIcon(handle: Handle<TitleIconProps>) {\n\treturn () => {\n\t\tlet { shell, title } = handle.props;\n\t\tlet extension = title?.match(/\\.([a-z0-9]+)$/i)?.[1]?.toLowerCase();\n\n\t\tif (shell && !extension) return <TerminalIcon size={14} aria-hidden=\"true\" />;\n\t\tlet Glyph = title && extension ? fileIcon(title, { fallback: FileCodeIcon }) : FileIcon;\n\t\treturn <Glyph size={14} aria-hidden=\"true\" />;\n\t};\n}\n\n/** Whether a title names a file, which sets it in the mono face. */\nfunction isPath(title: string): boolean {\n\treturn /[/.]/.test(title) && !/\\s/.test(title);\n}\n\n/** Whether the block is a shell session, by its language. */\nfunction isShell(language: string | undefined): boolean {\n\treturn Boolean(language && SHELL_LANGUAGES.has(language.toLowerCase()));\n}\n\n/**\n * Splits the code into lines, each holding its runs and its mark. In a shell block a\n * line opening with `$ ` loses the prompt, which the line draws as decoration instead,\n * and once any line has a prompt the lines that are neither commands nor a continued\n * command (after a trailing `\\`) read as output.\n */\nfunction paintLines(\n\tcode: string,\n\tlanguage: string | undefined,\n\ttokens: readonly CodeBlock.Token[] | undefined,\n\tshell: boolean,\n\tmarks: Pick<CodeBlock.Props, \"add\" | \"highlight\" | \"remove\">,\n): Line[] {\n\tlet source = code.replace(/\\r?\\n$/, \"\");\n\tlet rawLines = source.split(/\\r?\\n/);\n\tlet prompts = rawLines.map((line) => shell && line.startsWith(PROMPT));\n\tlet hasPrompts = prompts.some(Boolean);\n\tlet stripped = rawLines.map((line, index) => (prompts[index] ? line.slice(PROMPT.length) : line));\n\n\tlet text = hasPrompts ? stripped.join(\"\\n\") : source;\n\tlet runs: readonly CodeBlock.Token[] =\n\t\ttokens ?? (language ? tokenize(text, language) : [{ type: \"plain\", value: text }]);\n\n\tlet lines: Line[] = [];\n\tlet continued = false;\n\n\tfor (let [index, lineTokens] of codeLines(runs).slice(0, rawLines.length).entries()) {\n\t\tlet prompt = prompts[index] ?? false;\n\t\tlet command: boolean = prompt || continued;\n\t\tcontinued = command && (rawLines[index] ?? \"\").endsWith(\"\\\\\");\n\t\tlines.push({\n\t\t\ttokens: tokens && prompt ? dropLeading(lineTokens, PROMPT.length) : lineTokens,\n\t\t\tmark: markOf(index + 1, marks),\n\t\t\tprompt,\n\t\t\toutput: hasPrompts && !command,\n\t\t});\n\t}\n\n\treturn lines;\n}\n\n/** The mark a line carries; a removal or addition wins over a plain highlight. */\nfunction markOf(\n\tnumber: number,\n\tmarks: Pick<CodeBlock.Props, \"add\" | \"highlight\" | \"remove\">,\n): CodeBlock.Mark | undefined {\n\tif (marks.remove?.includes(number)) return \"remove\";\n\tif (marks.add?.includes(number)) return \"add\";\n\tif (marks.highlight?.includes(number)) return \"highlight\";\n\treturn undefined;\n}\n\n/** Drops the first `count` characters of a line's runs, for a prompt already painted in. */\nfunction dropLeading(runs: CodeBlock.Token[], count: number): CodeBlock.Token[] {\n\tlet remaining = count;\n\tlet result: CodeBlock.Token[] = [];\n\tfor (let run of runs) {\n\t\tif (remaining >= run.value.length) {\n\t\t\tremaining -= run.value.length;\n\t\t\tcontinue;\n\t\t}\n\t\tresult.push({ type: run.type, value: run.value.slice(remaining) });\n\t\tremaining = 0;\n\t}\n\treturn result;\n}\n\n/**\n * Draws every line with a newline between each pair, so the text a copy reads keeps the\n * source's shape. Output and removed lines carry the attribute that keeps them off the\n * clipboard.\n */\nfunction renderLines(lines: Line[]): RemixNode[] {\n\tlet nodes: RemixNode[] = [];\n\tfor (let [index, line] of lines.entries()) {\n\t\tif (index > 0) nodes.push(\"\\n\");\n\t\tlet excluded = line.output || line.mark === \"remove\";\n\t\tnodes.push(\n\t\t\t<span\n\t\t\t\tdata-line=\"\"\n\t\t\t\tdata-mark={line.mark}\n\t\t\t\tdata-output={line.output ? \"\" : undefined}\n\t\t\t\t{...(excluded ? { [COPY_EXCLUDE_ATTRIBUTE]: \"\" } : {})}\n\t\t\t>\n\t\t\t\t{line.prompt ? <span data-prompt=\"\" /> : null}\n\t\t\t\t{renderRuns(line.tokens)}\n\t\t\t</span>,\n\t\t);\n\t}\n\treturn nodes;\n}\n\n/**\n * Renders runs as text and `span.token.<type>` elements, the class contract the shared\n * highlight stylesheet colors; each span also carries its color with a scheme-aware\n * fallback, so code reads in color on a page that never loaded that stylesheet.\n */\nfunction renderRuns(runs: CodeBlock.Token[]): RemixNode[] {\n\treturn runs.map((run) => {\n\t\tlet palette = TOKEN_PALETTE[run.type];\n\t\tif (run.type === \"plain\" || !palette) return run.value;\n\t\tlet [light, dark] = palette;\n\t\treturn (\n\t\t\t<span\n\t\t\t\tclassName={`token ${run.type}`}\n\t\t\t\tmix={[raw({ color: `var(--highlight-${run.type}, light-dark(${light}, ${dark}))` })]}\n\t\t\t>\n\t\t\t\t{run.value}\n\t\t\t</span>\n\t\t);\n\t});\n}\n\n/**\n * An element id derived from the code. A documentation page is cached against the bytes\n * it rendered, so an id that changed per render would cost a fresh download.\n */\nfunction stableId(value: string): string {\n\tlet hash = FNV_OFFSET;\n\tfor (let index = 0; index < value.length; index += 1) {\n\t\thash ^= value.charCodeAt(index);\n\t\thash = Math.imul(hash, FNV_PRIME);\n\t}\n\treturn `code-${(hash >>> 0).toString(36)}`;\n}\n"
13
+ },
14
+ "test": {
15
+ "path": "code-block.browser.test.tsx",
16
+ "content": "/**\n * Lays {@link CodeBlock} out in a real browser: marked lines tint the full scroll width\n * without moving their text, the copy button writes what a reader should paste and\n * announces it, the header names the file, and a long line scrolls inside the card.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type { RemixNode } from \"remix/component\";\n\nimport { render } from \"remix/component/test\";\nimport { afterEach, describe, expect, test, vi } from \"vitest\";\n\nimport { CodeBlock } from \"@sdxc/ui/code-block\";\nimport { Typeset } from \"@sdxc/ui/typeset\";\n\nimport \"@sdxc/ui/theme.css\";\n\n/** The copy strings every block in these tests carries. */\nconst LABELS = { copy: \"Copy code\", copied: \"Copied\" };\n\n/** Hosts mounted by a test, removed after it so layout never leaks between cases. */\nlet hosts: HTMLElement[] = [];\n\nafterEach(() => {\n\tfor (let host of hosts) host.remove();\n\thosts = [];\n\tvi.restoreAllMocks();\n});\n\n/** Mounts `node` in a column `width` pixels wide and returns the block. */\nfunction mount(node: RemixNode, width = 640): HTMLElement {\n\tlet host = document.createElement(\"div\");\n\thost.style.width = `${width}px`;\n\thost.style.setProperty(\"--ui-brand-fg\", \"rgb(37 99 235)\");\n\tdocument.body.appendChild(host);\n\thosts.push(host);\n\trender(node, { container: host });\n\treturn host.querySelector<HTMLElement>('[data-slot=\"code-block\"]')!;\n}\n\n/** Left edge of the first non-whitespace glyph under `element`. */\nfunction inkLeft(element: Element): number {\n\tlet walker = document.createTreeWalker(element, NodeFilter.SHOW_TEXT);\n\tfor (let node = walker.nextNode(); node; node = walker.nextNode()) {\n\t\tlet offset = node.textContent!.search(/\\S/);\n\t\tif (offset < 0) continue;\n\t\tlet range = document.createRange();\n\t\trange.setStart(node, offset);\n\t\trange.setEnd(node, offset + 1);\n\t\treturn range.getBoundingClientRect().left;\n\t}\n\treturn Number.NaN;\n}\n\n/** Clicks the block's copy button and resolves with the text it wrote. */\nasync function copy(block: HTMLElement): Promise<string> {\n\tlet write = vi.spyOn(navigator.clipboard, \"writeText\").mockResolvedValue(undefined);\n\tlet button = block.querySelector<HTMLButtonElement>('[data-slot=\"copy-button\"]')!;\n\tlet copied = new Promise<void>((resolve) => {\n\t\tbutton.addEventListener(\"ui:copy\", () => resolve(), { once: true });\n\t});\n\tbutton.click();\n\tawait copied;\n\treturn String(write.mock.calls[0]?.[0]);\n}\n\ndescribe(\"CodeBlock\", () => {\n\ttest(\"tints a marked line across the full scroll width without moving its text\", () => {\n\t\tlet code = `import { defineConfig } from \"vite\";\\nexport default defineConfig({ plugins: [remix(), anotherPluginWithAVeryLongNameThatOverflows()] });\\nconsole.log(\"done\");`;\n\t\tlet block = mount(\n\t\t\t<CodeBlock language=\"ts\" code={code} highlight={[3]} add={[1]} labels={LABELS}>\n\t\t\t\t<CodeBlock.Header>\n\t\t\t\t\t<CodeBlock.Title>vite.config.ts</CodeBlock.Title>\n\t\t\t\t\t<CodeBlock.Copy />\n\t\t\t\t</CodeBlock.Header>\n\t\t\t</CodeBlock>,\n\t\t\t360,\n\t\t);\n\t\tlet pre = block.querySelector(\"pre\")!;\n\t\tlet lines = [...block.querySelectorAll<HTMLElement>(\"[data-line]\")];\n\n\t\texpect(pre.scrollWidth).toBeGreaterThan(pre.clientWidth);\n\t\texpect(lines[2]!.getBoundingClientRect().width).toBeCloseTo(pre.scrollWidth, 0);\n\t\texpect(lines[0]!.getBoundingClientRect().width).toBeCloseTo(pre.scrollWidth, 0);\n\n\t\tlet marked = getComputedStyle(lines[2]!);\n\t\texpect(marked.borderInlineStartWidth).toBe(\"2px\");\n\t\texpect(marked.backgroundColor).not.toBe(\"rgba(0, 0, 0, 0)\");\n\t\texpect(inkLeft(lines[2]!)).toBeCloseTo(inkLeft(lines[1]!), 1);\n\t\texpect(inkLeft(lines[0]!)).toBeCloseTo(inkLeft(lines[1]!), 1);\n\t});\n\n\ttest(\"draws no empty last line when painted tokens end in a newline\", () => {\n\t\tlet block = mount(\n\t\t\t<CodeBlock\n\t\t\t\tlanguage=\"sh\"\n\t\t\t\tcode={\"npm add remix\\n\"}\n\t\t\t\ttokens={[\n\t\t\t\t\t{ type: \"function\", value: \"npm\" },\n\t\t\t\t\t{ type: \"plain\", value: \" add remix\\n\" },\n\t\t\t\t]}\n\t\t\t\tlabels={LABELS}\n\t\t\t/>,\n\t\t);\n\n\t\texpect(block.querySelectorAll(\"[data-line]\")).toHaveLength(1);\n\t});\n\n\ttest(\"keeps its own code styles inside a Typeset\", () => {\n\t\tlet plain = mount(<CodeBlock language=\"ts\" code=\"let a = 1;\" labels={LABELS} />);\n\t\tlet typeset = mount(\n\t\t\t<Typeset preset=\"docs\">\n\t\t\t\t<CodeBlock language=\"ts\" code=\"let b = 2;\" labels={LABELS} />\n\t\t\t</Typeset>,\n\t\t);\n\t\tlet style = (block: HTMLElement) => getComputedStyle(block.querySelector(\"pre\")!);\n\n\t\texpect(style(typeset).borderTopWidth).toBe(style(plain).borderTopWidth);\n\t\texpect(style(typeset).fontSize).toBe(style(plain).fontSize);\n\t\texpect(style(typeset).paddingInlineStart).toBe(style(plain).paddingInlineStart);\n\t});\n\n\ttest(\"keeps an empty line one line tall\", () => {\n\t\tlet block = mount(\n\t\t\t<CodeBlock language=\"ts\" code={\"let a = 1;\\n\\nlet b = 2;\"} labels={LABELS} />,\n\t\t);\n\t\tlet lines = block.querySelectorAll<HTMLElement>(\"[data-line]\");\n\t\texpect(lines[1]!.getBoundingClientRect().height).toBeCloseTo(\n\t\t\tlines[0]!.getBoundingClientRect().height,\n\t\t\t0,\n\t\t);\n\t\texpect(block.querySelector(\"pre\")!.getBoundingClientRect().height).toBeGreaterThan(3 * 20);\n\t});\n\n\ttest(\"copies a shell session without prompts or output and announces it\", async () => {\n\t\tlet code = \"$ npm add @sdxc/ui \\\\\\n @sdxc/u\\nadded 2 packages\\n$ npm run dev\";\n\t\tlet block = mount(\n\t\t\t<CodeBlock language=\"sh\" code={code} labels={LABELS}>\n\t\t\t\t<CodeBlock.Header>\n\t\t\t\t\t<CodeBlock.Title>Terminal</CodeBlock.Title>\n\t\t\t\t\t<CodeBlock.Copy />\n\t\t\t\t</CodeBlock.Header>\n\t\t\t</CodeBlock>,\n\t\t);\n\n\t\texpect(block.querySelector(\"code\")!.textContent).not.toContain(\"$\");\n\t\texpect(await copy(block)).toBe(\"npm add @sdxc/ui \\\\\\n @sdxc/u\\nnpm run dev\");\n\n\t\tlet button = block.querySelector<HTMLButtonElement>('[data-slot=\"copy-button\"]')!;\n\t\texpect(button.hasAttribute(\"data-copied\")).toBe(true);\n\t\texpect(button.querySelector('[role=\"status\"]')!.textContent).toBe(\"Copied\");\n\t\texpect(getComputedStyle(button.querySelector('[data-icon=\"check\"]')!).display).not.toBe(\"none\");\n\t\texpect(getComputedStyle(button.querySelector('[data-icon=\"copy\"]')!).display).toBe(\"none\");\n\t});\n\n\ttest(\"draws the prompt before each command, outside the selectable text\", () => {\n\t\tlet block = mount(<CodeBlock language=\"sh\" code=\"$ bun install\" labels={LABELS} />);\n\t\tlet prompt = block.querySelector(\"[data-prompt]\")!;\n\t\texpect(getComputedStyle(prompt, \"::before\").content).toBe('\"$ \"');\n\t\texpect(getComputedStyle(prompt, \"::before\").userSelect).toBe(\"none\");\n\t});\n\n\ttest(\"copies the file a diff produces, without its removed lines\", async () => {\n\t\tlet code = \"let a = 1;\\nlet b = 2;\\nlet c = 3;\";\n\t\tlet block = mount(\n\t\t\t<CodeBlock language=\"ts\" code={code} remove={[2]} add={[3]} lineNumbers labels={LABELS} />,\n\t\t);\n\t\texpect(await copy(block)).toBe(\"let a = 1;\\nlet c = 3;\");\n\t});\n\n\ttest(\"names the file in the header and the language when untitled\", () => {\n\t\tlet titled = mount(\n\t\t\t<CodeBlock language=\"ts\" code=\"export {};\" labels={LABELS}>\n\t\t\t\t<CodeBlock.Header>\n\t\t\t\t\t<CodeBlock.Title>app/routes.ts</CodeBlock.Title>\n\t\t\t\t\t<CodeBlock.Copy />\n\t\t\t\t</CodeBlock.Header>\n\t\t\t</CodeBlock>,\n\t\t);\n\t\texpect(titled.querySelector(\"figcaption\")!.textContent).toBe(\"app/routes.ts\");\n\t\texpect(titled.querySelector('[data-slot=\"code-block-icon\"] svg')).not.toBeNull();\n\n\t\tlet untitled = mount(<CodeBlock language=\"json\" code=\"{}\" labels={LABELS} />);\n\t\texpect(untitled.querySelector(\"figcaption\")!.textContent).toBe(\"json\");\n\n\t\tlet bare = mount(<CodeBlock code=\"plain text\" labels={LABELS} />);\n\t\texpect(bare.querySelector(\"figcaption\")).toBeNull();\n\t\texpect(bare.querySelector('[data-slot=\"copy-button\"]')).not.toBeNull();\n\t});\n\n\ttest(\"numbers lines in a gutter the copy leaves out\", async () => {\n\t\tlet block = mount(<CodeBlock language=\"ts\" code={\"a();\\nb();\"} lineNumbers labels={LABELS} />);\n\t\tlet line = block.querySelector(\"[data-line]\")!;\n\t\texpect(getComputedStyle(line, \"::before\").content).toBe(\"counter(line)\");\n\t\texpect(await copy(block)).toBe(\"a();\\nb();\");\n\t});\n\n\ttest(\"scrolls a long line inside the card at 320px instead of widening the page\", () => {\n\t\tlet code = `$ npx some-very-long-command --with-a-flag --and-another-flag --and-one-more-for-good-measure`;\n\t\tlet block = mount(\n\t\t\t<CodeBlock language=\"sh\" code={code} labels={LABELS}>\n\t\t\t\t<CodeBlock.Header>\n\t\t\t\t\t<CodeBlock.Title>Terminal</CodeBlock.Title>\n\t\t\t\t\t<CodeBlock.Copy />\n\t\t\t\t</CodeBlock.Header>\n\t\t\t</CodeBlock>,\n\t\t\t320,\n\t\t);\n\t\tlet pre = block.querySelector(\"pre\")!;\n\t\texpect(block.getBoundingClientRect().width).toBeLessThanOrEqual(320);\n\t\texpect(pre.scrollWidth).toBeGreaterThan(pre.clientWidth);\n\t\texpect(document.documentElement.scrollWidth).toBeLessThanOrEqual(window.innerWidth);\n\t});\n\n\ttest(\"floats a copy button written directly in the card and widens the lines' end\", () => {\n\t\tlet block = mount(\n\t\t\t<CodeBlock language=\"ts\" code=\"let a = 1;\" labels={LABELS}>\n\t\t\t\t<CodeBlock.Copy />\n\t\t\t</CodeBlock>,\n\t\t);\n\t\tlet copyBox = block.querySelector<HTMLElement>('[data-slot=\"code-block-copy\"]')!;\n\n\t\texpect(block.querySelector(\"figcaption\")).toBeNull();\n\t\texpect(getComputedStyle(copyBox).position).toBe(\"absolute\");\n\t\texpect(getComputedStyle(block.querySelector(\"[data-line]\")!).paddingRight).toBe(\"48px\");\n\t});\n});\n"
17
+ }
18
+ }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "confirm",
3
- "changedIn": "2026.11.3",
3
+ "changedIn": "2026.11.29",
4
4
  "dependencies": [
5
5
  "alert-dialog",
6
6
  "button",
@@ -14,10 +14,10 @@
14
14
  ],
15
15
  "source": {
16
16
  "path": "confirm.tsx",
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"
17
+ "content": "/**\n * A confirmation prompt built from parts over {@link AlertDialog}: the root wires the\n * heading and description ids and the panel's `id` into every control, a `.Form` turns\n * confirming into a real submission, and a `.Phrase` holds a big irreversible action\n * until its name is typed. The confirming control defaults to the danger tone.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type { EntryComponent, Handle, Props as TagProps } from \"remix/component\";\n\nimport { mergeMix } from \"@sdxc/u/general\";\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 {@link Confirm.Form} falls back to when `method` is omitted. */\nconst DEFAULT_METHOD = \"post\";\n\n/**\n * Column gap the form re-declares, matching the panel's own child gap: the form becomes\n * the panel's single child, so without it 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} and its parts.\n */\nexport namespace Confirm {\n\t/** What the root shares with its parts. */\n\texport interface Context {\n\t\t/** The panel's `id`, which Cancel and Action close. */\n\t\tid: string;\n\t\tcolor: Button.Color;\n\t\t/** The id {@link Confirm.Title} takes, which names the panel. */\n\t\ttitleId: string;\n\t\t/** The id {@link Confirm.Description} takes, which describes the panel. */\n\t\tdescriptionId: string;\n\t\t/** The id the phrase field takes. */\n\t\tphraseId: string;\n\t}\n\n\t/** What a {@link Confirm.Form} shares with the confirming control. */\n\texport interface FormContext {\n\t\tsubmits: true;\n\t}\n\n\t/**\n\t * Every {@link AlertDialog} attribute, with a required `id` a trigger elsewhere targets\n\t * through `commandfor`/`command=\"show-modal\"`, plus the confirming control's colour.\n\t */\n\texport interface Props extends Omit<AlertDialog.Props, \"id\"> {\n\t\tid: string;\n\t\t/** @default {@link DEFAULT_COLOR} */\n\t\tcolor?: Button.Color;\n\t}\n\n\t/** Every native `<form>` attribute; `method` defaults to `\"post\"`, since a confirmed action changes state. */\n\texport interface FormProps extends Omit<TagProps<\"form\">, \"method\"> {\n\t\tmethod?: \"get\" | \"post\";\n\t}\n\n\t/** Every native `<input>` attribute's essentials for the phrase field, and its label as children. */\n\texport interface PhraseProps extends Omit<TagProps<\"div\">, \"children\"> {\n\t\t/** The exact text that unlocks the confirming control, compared case-sensitively. */\n\t\tvalue: string;\n\t\t/** Name the typed text submits under inside a {@link Confirm.Form}, so the server can check it again. */\n\t\tname?: string;\n\t\t/** The field's label, such as `Type \"acme\" to confirm`. */\n\t\tchildren: TagProps<\"label\">[\"children\"];\n\t}\n}\n\n/**\n * Renders the {@link AlertDialog} panel, named by its {@link Confirm.Title} and described by its\n * {@link Confirm.Description} through generated ids. Focus opens on {@link Confirm.Cancel}, or on\n * a {@link Confirm.Phrase} field, which comes first in the panel.\n *\n * @param handle Runtime handle carrying the panel's props and this instance's stable identifier.\n * @returns The render function producing the panel.\n * @example\n * <Button commandfor=\"confirm-delete\" command=\"show-modal\" color=\"danger\">Delete project</Button>\n * <Confirm id=\"confirm-delete\">\n * \t<Confirm.Header>\n * \t\t<Confirm.Title>Delete project?</Confirm.Title>\n * \t\t<Confirm.Description>Its monitors and their history are deleted.</Confirm.Description>\n * \t</Confirm.Header>\n * \t<Confirm.Footer>\n * \t\t<Confirm.Cancel>Cancel</Confirm.Cancel>\n * \t\t<Confirm.Action>Delete</Confirm.Action>\n * \t</Confirm.Footer>\n * </Confirm>\n */\nexport function Confirm(handle: Handle<Confirm.Props, Confirm.Context>) {\n\treturn () => {\n\t\tlet {\n\t\t\tid,\n\t\t\tcolor = DEFAULT_COLOR,\n\t\t\t\"aria-labelledby\": ariaLabelledBy,\n\t\t\t\"aria-describedby\": ariaDescribedBy,\n\t\t\t...rest\n\t\t} = handle.props;\n\t\tlet titleId = `${handle.id}-title`;\n\t\tlet descriptionId = `${handle.id}-description`;\n\t\thandle.context.set({ id, color, titleId, descriptionId, phraseId: `${handle.id}-phrase` });\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={ariaLabelledBy ?? titleId}\n\t\t\t\taria-describedby={ariaDescribedBy ?? descriptionId}\n\t\t\t/>\n\t\t);\n\t};\n}\n\n/**\n * Turns confirming into a real submission: the panel's parts go inside, the confirming control\n * becomes its submit button, and hidden inputs (a CSRF token, the record's id) go in as children.\n *\n * @param handle Runtime handle carrying the host `<form>`'s props.\n * @returns The render function producing the form.\n * @example\n * <Confirm.Form action={revokeUrl}>\n * \t<input type=\"hidden\" name=\"csrf\" value={token} />\n * \t<Confirm.Header><Confirm.Title>Revoke this session?</Confirm.Title></Confirm.Header>\n * \t<Confirm.Footer><Confirm.Cancel>Cancel</Confirm.Cancel><Confirm.Action>Revoke</Confirm.Action></Confirm.Footer>\n * </Confirm.Form>\n */\nConfirm.Form = function ConfirmForm(handle: Handle<Confirm.FormProps, Confirm.FormContext>) {\n\treturn () => {\n\t\tlet { method = DEFAULT_METHOD, mix, ...rest } = handle.props;\n\t\thandle.context.set({ submits: true });\n\t\treturn (\n\t\t\t<form\n\t\t\t\tdata-slot=\"confirm-form\"\n\t\t\t\t{...rest}\n\t\t\t\tmethod={method}\n\t\t\t\tmix={mergeMix([flex(), flexCol(), gap(PANEL_GAP)], mix)}\n\t\t\t/>\n\t\t);\n\t};\n};\n\n/**\n * The column stacking the title and description.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the header.\n */\nConfirm.Header = function ConfirmHeader(handle: Handle<AlertDialog.HeaderProps>) {\n\treturn () => <AlertDialog.Header {...handle.props} />;\n};\n\n/**\n * The panel's heading, which names it.\n *\n * @param handle Runtime handle carrying the heading's props.\n * @returns The render function producing the heading.\n */\nConfirm.Title = function ConfirmTitle(handle: Handle<AlertDialog.TitleProps>) {\n\treturn () => {\n\t\tlet context = handle.context.get(Confirm) as Confirm.Context | undefined;\n\t\treturn <AlertDialog.Title id={context?.titleId} {...handle.props} />;\n\t};\n};\n\n/**\n * The supporting copy under the title, which describes the panel.\n *\n * @param handle Runtime handle carrying the host `<p>`'s props.\n * @returns The render function producing the description.\n */\nConfirm.Description = function ConfirmDescription(handle: Handle<AlertDialog.DescriptionProps>) {\n\treturn () => {\n\t\tlet context = handle.context.get(Confirm) as Confirm.Context | undefined;\n\t\treturn <AlertDialog.Description id={context?.descriptionId} {...handle.props} />;\n\t};\n};\n\n/**\n * The type-to-confirm field: its label, then an input that keeps the confirming control\n * disabled until the phrase matches. Reserve it for deleting something large.\n *\n * @param handle Runtime handle carrying the wrapper's props, the phrase and the label.\n * @returns The render function producing the field.\n * @example <Confirm.Phrase value=\"acme\" name=\"confirmation\">Type \"acme\" to confirm</Confirm.Phrase>\n */\nConfirm.Phrase = function ConfirmPhraseField(handle: Handle<Confirm.PhraseProps>) {\n\treturn () => {\n\t\tlet { value, name, children, mix, ...rest } = handle.props;\n\t\tlet context = handle.context.get(Confirm) as Confirm.Context | undefined;\n\t\tlet id = context?.phraseId ?? `${handle.id}-phrase`;\n\t\treturn (\n\t\t\t<div\n\t\t\t\tdata-slot=\"confirm-phrase\"\n\t\t\t\t{...rest}\n\t\t\t\tmix={mergeMix([vstack({ gap: 1.5, align: \"stretch\" })], mix)}\n\t\t\t>\n\t\t\t\t<Label htmlFor={id}>{children}</Label>\n\t\t\t\t<ConfirmPhrase id={id} value={value} name={name} />\n\t\t\t</div>\n\t\t);\n\t};\n};\n\n/**\n * The end-aligned row holding Cancel, then the confirming control.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the row.\n */\nConfirm.Footer = function ConfirmFooter(handle: Handle<AlertDialog.FooterProps>) {\n\treturn () => <AlertDialog.Footer {...handle.props} />;\n};\n\n/**\n * Backs out without confirming, closing the panel. It takes focus when the panel opens, so\n * Enter on a destructive prompt starts on the safe choice.\n *\n * @param handle Runtime handle carrying the button's props.\n * @returns The render function producing the control.\n */\nConfirm.Cancel = function ConfirmCancel(\n\thandle: Handle<Omit<AlertDialog.CancelProps, \"commandfor\">>,\n) {\n\treturn () => {\n\t\tlet context = handle.context.get(Confirm) as Confirm.Context | undefined;\n\t\treturn (\n\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<AlertDialog.Cancel commandfor={context?.id ?? \"\"} autofocus {...handle.props} />\n\t\t);\n\t};\n};\n\n/**\n * The confirming control in the root's colour: inside a {@link Confirm.Form} it submits the\n * form, otherwise it closes the panel for the page to react to.\n *\n * @param handle Runtime handle carrying the button's props.\n * @returns The render function producing the control.\n */\nConfirm.Action = function ConfirmAction(\n\thandle: Handle<Omit<AlertDialog.ActionProps, \"commandfor\">>,\n) {\n\treturn () => {\n\t\tlet context = handle.context.get(Confirm) as Confirm.Context | undefined;\n\t\tlet form = handle.context.get(Confirm.Form) as Confirm.FormContext | undefined;\n\t\treturn (\n\t\t\t<AlertDialog.Action\n\t\t\t\tdata-confirm-action=\"\"\n\t\t\t\ttype={form ? \"submit\" : undefined}\n\t\t\t\tcommandfor={form ? undefined : context?.id}\n\t\t\t\tcolor={context?.color ?? DEFAULT_COLOR}\n\t\t\t\t{...handle.props}\n\t\t\t/>\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\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 input 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\" />\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, name, value } = handle.props;\n\n\t\t\treturn (\n\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<Input\n\t\t\t\t\tid={id}\n\t\t\t\t\tname={name}\n\t\t\t\t\trequired\n\t\t\t\t\tautofocus\n\t\t\t\t\tautocomplete=\"off\"\n\t\t\t\t\tspellcheck={false}\n\t\t\t\t\tpattern={escapePattern(value)}\n\t\t\t\t\tmix={[confirmPhrase(value)]}\n\t\t\t\t/>\n\t\t\t);\n\t\t};\n\t},\n);\n"
18
18
  },
19
19
  "test": {
20
20
  "path": "confirm.test.tsx",
21
- "content": "/**\n * Tests for {@link Confirm}'s two modes: the default, where confirming only\n * closes the panel through an Invoker Command, and the submit mode `form`\n * switches on, where the panel's content is wrapped in a real `<form>` and\n * the confirming control becomes its submit button — the shape a\n * server-rendered destructive action needs.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport { renderToString } from \"remix/component/server\";\nimport { describe, expect, test } from \"vitest\";\n\nimport { Confirm } from \"@sdxc/ui/confirm\";\n\ndescribe(Confirm.name, () => {\n\ttest(\"closes the panel with a command, and renders no form, by default\", async () => {\n\t\tlet html = await renderToString(\n\t\t\t<Confirm\n\t\t\t\tid=\"confirm-delete\"\n\t\t\t\ttitle=\"Delete project?\"\n\t\t\t\tconfirmLabel=\"Delete\"\n\t\t\t\tcancelLabel=\"Cancel\"\n\t\t\t/>,\n\t\t);\n\n\t\texpect(html).not.toContain(\"<form\");\n\t\texpect(html).toContain('command=\"close\"');\n\t\texpect(html).toContain('commandfor=\"confirm-delete\"');\n\t});\n\n\ttest(\"wraps its content in a real form and submits it once form is set\", async () => {\n\t\tlet html = await renderToString(\n\t\t\t<Confirm\n\t\t\t\tid=\"revoke-session\"\n\t\t\t\ttitle=\"Revoke this session?\"\n\t\t\t\tconfirmLabel=\"Revoke\"\n\t\t\t\tcancelLabel=\"Cancel\"\n\t\t\t\tform={{ action: \"/account/sessions/abc/revoke\" }}\n\t\t\t/>,\n\t\t);\n\n\t\texpect(html).toContain(\"<form\");\n\t\texpect(html).toContain('action=\"/account/sessions/abc/revoke\"');\n\t\texpect(html).toContain('method=\"post\"');\n\t\texpect(html).toContain('type=\"submit\"');\n\t});\n\n\ttest(\"renders the panel's content inside the form, not beside it\", async () => {\n\t\tlet html = await renderToString(\n\t\t\t<Confirm\n\t\t\t\tid=\"revoke-session\"\n\t\t\t\ttitle=\"Revoke this session?\"\n\t\t\t\tconfirmLabel=\"Revoke\"\n\t\t\t\tcancelLabel=\"Cancel\"\n\t\t\t\tform={{ action: \"/revoke\" }}\n\t\t\t/>,\n\t\t);\n\n\t\texpect(html.indexOf(\"<form\")).toBeLessThan(html.indexOf(\"Revoke this session?\"));\n\t\texpect(html.indexOf(\"Revoke this session?\")).toBeLessThan(html.indexOf(\"</form>\"));\n\t\texpect(html.indexOf('type=\"submit\"')).toBeLessThan(html.indexOf(\"</form>\"));\n\t});\n\n\ttest(\"submits the hidden fields it was given, ahead of the panel's own content\", async () => {\n\t\tlet html = await renderToString(\n\t\t\t<Confirm\n\t\t\t\tid=\"delete-client\"\n\t\t\t\ttitle=\"Delete client?\"\n\t\t\t\tconfirmLabel=\"Delete\"\n\t\t\t\tcancelLabel=\"Cancel\"\n\t\t\t\tform={{\n\t\t\t\t\taction: \"/admin/clients/abc\",\n\t\t\t\t\tfields: <input type=\"hidden\" name=\"csrf\" value=\"t0ken\" />,\n\t\t\t\t}}\n\t\t\t/>,\n\t\t);\n\n\t\texpect(html).toContain('name=\"csrf\"');\n\t\texpect(html).toContain('value=\"t0ken\"');\n\t\texpect(html.indexOf('name=\"csrf\"')).toBeLessThan(html.indexOf(\"Delete client?\"));\n\t});\n\n\ttest(\"submits with the method it was given instead of the default\", async () => {\n\t\tlet html = await renderToString(\n\t\t\t<Confirm\n\t\t\t\tid=\"search-again\"\n\t\t\t\ttitle=\"Run the search again?\"\n\t\t\t\tconfirmLabel=\"Search\"\n\t\t\t\tcancelLabel=\"Cancel\"\n\t\t\t\tform={{ action: \"/search\", method: \"get\" }}\n\t\t\t/>,\n\t\t);\n\n\t\texpect(html).toContain('method=\"get\"');\n\t\texpect(html).not.toContain('method=\"post\"');\n\t});\n\n\ttest(\"keeps cancel a close-command button in submit mode, so cancelling never submits\", async () => {\n\t\tlet html = await renderToString(\n\t\t\t<Confirm\n\t\t\t\tid=\"revoke-session\"\n\t\t\t\ttitle=\"Revoke this session?\"\n\t\t\t\tconfirmLabel=\"Revoke\"\n\t\t\t\tcancelLabel=\"Cancel\"\n\t\t\t\tform={{ action: \"/revoke\" }}\n\t\t\t/>,\n\t\t);\n\n\t\texpect(html).toContain('type=\"button\"');\n\t\texpect(html).toContain('command=\"close\"');\n\t\texpect(html).toContain('commandfor=\"revoke-session\"');\n\t});\n});\n"
21
+ "content": "/**\n * Tests for {@link Confirm}'s two modes: the default, where confirming only closes the\n * panel through an Invoker Command, and a `.Form`, which wraps the parts in a real\n * `<form>` and makes the confirming control its submit button, the shape a\n * server-rendered destructive action needs.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type { Handle } from \"remix/component\";\n\nimport { renderToString } from \"remix/component/server\";\nimport { describe, expect, test } from \"vitest\";\n\nimport { Confirm } from \"@sdxc/ui/confirm\";\n\n/** Props {@link Parts} reads. */\ninterface PartsProps {\n\ttitle: string;\n\tconfirm: string;\n}\n\n/** The header and footer every prompt here draws. */\nfunction Parts(handle: Handle<PartsProps>) {\n\treturn () => (\n\t\t<>\n\t\t\t<Confirm.Header>\n\t\t\t\t<Confirm.Title>{handle.props.title}</Confirm.Title>\n\t\t\t</Confirm.Header>\n\t\t\t<Confirm.Footer>\n\t\t\t\t<Confirm.Cancel>Cancel</Confirm.Cancel>\n\t\t\t\t<Confirm.Action>{handle.props.confirm}</Confirm.Action>\n\t\t\t</Confirm.Footer>\n\t\t</>\n\t);\n}\n\ndescribe(Confirm.name, () => {\n\ttest(\"closes the panel with a command, and renders no form, by default\", async () => {\n\t\tlet html = await renderToString(\n\t\t\t<Confirm id=\"confirm-delete\">\n\t\t\t\t<Parts title=\"Delete project?\" confirm=\"Delete\" />\n\t\t\t</Confirm>,\n\t\t);\n\n\t\texpect(html).not.toContain(\"<form\");\n\t\texpect(html).toContain('command=\"close\"');\n\t\texpect(html).toContain('commandfor=\"confirm-delete\"');\n\t});\n\n\ttest(\"wraps its content in a real form and submits it inside a Form\", async () => {\n\t\tlet html = await renderToString(\n\t\t\t<Confirm id=\"revoke-session\">\n\t\t\t\t<Confirm.Form action=\"/account/sessions/abc/revoke\">\n\t\t\t\t\t<Parts title=\"Revoke this session?\" confirm=\"Revoke\" />\n\t\t\t\t</Confirm.Form>\n\t\t\t</Confirm>,\n\t\t);\n\n\t\texpect(html).toContain(\"<form\");\n\t\texpect(html).toContain('action=\"/account/sessions/abc/revoke\"');\n\t\texpect(html).toContain('method=\"post\"');\n\t\texpect(html).toContain('type=\"submit\"');\n\t\texpect(html.indexOf(\"<form\")).toBeLessThan(html.indexOf(\"Revoke this session?\"));\n\t\texpect(html.indexOf('type=\"submit\"')).toBeLessThan(html.indexOf(\"</form>\"));\n\t});\n\n\ttest(\"submits the hidden fields written inside the form\", async () => {\n\t\tlet html = await renderToString(\n\t\t\t<Confirm id=\"delete-client\">\n\t\t\t\t<Confirm.Form action=\"/admin/clients/abc\">\n\t\t\t\t\t<input type=\"hidden\" name=\"csrf\" value=\"t0ken\" />\n\t\t\t\t\t<Parts title=\"Delete client?\" confirm=\"Delete\" />\n\t\t\t\t</Confirm.Form>\n\t\t\t</Confirm>,\n\t\t);\n\n\t\texpect(html).toContain('name=\"csrf\"');\n\t\texpect(html).toContain('value=\"t0ken\"');\n\t\texpect(html.indexOf('name=\"csrf\"')).toBeLessThan(html.indexOf(\"Delete client?\"));\n\t});\n\n\ttest(\"submits with the method it was given instead of the default\", async () => {\n\t\tlet html = await renderToString(\n\t\t\t<Confirm id=\"search-again\">\n\t\t\t\t<Confirm.Form action=\"/search\" method=\"get\">\n\t\t\t\t\t<Parts title=\"Run the search again?\" confirm=\"Search\" />\n\t\t\t\t</Confirm.Form>\n\t\t\t</Confirm>,\n\t\t);\n\n\t\texpect(html).toContain('method=\"get\"');\n\t\texpect(html).not.toContain('method=\"post\"');\n\t});\n\n\ttest(\"keeps cancel a close-command button in a form, so cancelling never submits\", async () => {\n\t\tlet html = await renderToString(\n\t\t\t<Confirm id=\"revoke-session\">\n\t\t\t\t<Confirm.Form action=\"/revoke\">\n\t\t\t\t\t<Parts title=\"Revoke this session?\" confirm=\"Revoke\" />\n\t\t\t\t</Confirm.Form>\n\t\t\t</Confirm>,\n\t\t);\n\n\t\texpect(html).toContain('type=\"button\"');\n\t\texpect(html).toContain('command=\"close\"');\n\t\texpect(html).toContain('commandfor=\"revoke-session\"');\n\t});\n\n\ttest(\"names the panel by its title and colours the action from the root\", async () => {\n\t\tlet html = await renderToString(\n\t\t\t<Confirm id=\"publish\" color=\"brand\">\n\t\t\t\t<Parts title=\"Publish?\" confirm=\"Publish\" />\n\t\t\t</Confirm>,\n\t\t);\n\t\tlet titleId = /<h1[^>]*id=\"([^\"]+)\"/.exec(html)?.[1];\n\n\t\texpect(titleId).toBeTruthy();\n\t\texpect(html).toContain(`aria-labelledby=\"${titleId}\"`);\n\t\texpect(html).toContain('data-color=\"brand\"');\n\t});\n\n\ttest(\"draws a part alone with the default colour\", async () => {\n\t\tlet html = await renderToString(<Confirm.Action>Delete</Confirm.Action>);\n\n\t\texpect(html).toContain('data-color=\"danger\"');\n\t\texpect(html).toContain(\"Delete\");\n\t});\n});\n"
22
22
  }
23
23
  }
@@ -0,0 +1,14 @@
1
+ {
2
+ "name": "copy-button",
3
+ "changedIn": "2026.11.29",
4
+ "dependencies": [],
5
+ "exports": [
6
+ "CopyButtonProps",
7
+ "CopyButton"
8
+ ],
9
+ "source": {
10
+ "path": "copy-button.tsx",
11
+ "content": "/**\n * Client island: the copy button a code block carries. It copies the text of the element\n * it names, swaps its glyph for a check and announces the copy, so the block it sits in\n * stays server HTML and only this button hydrates.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type { EntryComponent } from \"remix/component\";\n\nimport { CheckIcon, CopyIcon } from \"@sdxc/icons\";\nimport { visuallyHidden } from \"@sdxc/u/a11y\";\nimport { bg, fg, outline } from \"@sdxc/u/color\";\nimport { rounded, transition } from \"@sdxc/u/effects\";\nimport { cursor, raw } from \"@sdxc/u/general\";\nimport { inlineFlex, items, justify, shrink } from \"@sdxc/u/layout\";\nimport { p } from \"@sdxc/u/size\";\nimport { hover, when } from \"@sdxc/u/state\";\nimport { clientEntry } from \"remix/component\";\n\nimport { copyFeedback } from \"@sdxc/ui/mixins\";\nimport { COPY_COMMAND, copyToClipboard } from \"@sdxc/ui/mixins\";\n\n/**\n * Props {@link CopyButton} serializes into the page for hydration, which is why they are\n * a `type`: `SerializableProps` rejects an interface.\n */\nexport type CopyButtonProps = {\n\t/** The `id` of the element whose text is copied. */\n\ttarget: string;\n\t/** The button's accessible name and tooltip, such as \"Copy code\". */\n\tlabel: string;\n\t/** What a screen reader announces once the text is on the clipboard, such as \"Copied\". */\n\tcopiedLabel: string;\n};\n\n/**\n * Renders the button. The island loads from the bare `@sdxc/ui/copy-button` specifier,\n * which the app's browser entry maps to a dynamic import; until then the button is inert\n * and the code beside it stays selectable.\n *\n * @example\n * <pre><code id=\"install\">npm add @sdxc/ui</code></pre>\n * <CopyButton target=\"install\" label={t(\"code.copy\")} copiedLabel={t(\"code.copied\")} />\n */\nexport const CopyButton: EntryComponent<CopyButtonProps> = clientEntry(\n\t\"@sdxc/ui/copy-button#CopyButton\",\n\tfunction CopyButton(handle) {\n\t\treturn () => {\n\t\t\tlet { copiedLabel, label, target } = handle.props;\n\n\t\t\treturn (\n\t\t\t\t<button\n\t\t\t\t\ttype=\"button\"\n\t\t\t\t\tdata-slot=\"copy-button\"\n\t\t\t\t\taria-label={label}\n\t\t\t\t\ttitle={label}\n\t\t\t\t\tcommandfor={target}\n\t\t\t\t\tcommand={COPY_COMMAND}\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\tshrink(0),\n\t\t\t\t\t\tp(1.5),\n\t\t\t\t\t\trounded(\"md\"),\n\t\t\t\t\t\tbg(\"transparent\"),\n\t\t\t\t\t\tfg(\"neutral\"),\n\t\t\t\t\t\tcursor(\"pointer\"),\n\t\t\t\t\t\ttransition(\"color, background-color\"),\n\t\t\t\t\t\thover([fg(\"neutral.emphasis\"), bg(\"neutral.bg-tint-hover\")]),\n\t\t\t\t\t\twhen(\"&:focus-visible\", outline({ color: \"brand.ring\", offset: 2 })),\n\t\t\t\t\t\traw({\n\t\t\t\t\t\t\tborder: 0,\n\t\t\t\t\t\t\t\"& > [data-icon]\": { display: \"inline-flex\" },\n\t\t\t\t\t\t\t'& > [data-icon=\"check\"]': { display: \"none\" },\n\t\t\t\t\t\t\t'&[data-copied] > [data-icon=\"copy\"]': { display: \"none\" },\n\t\t\t\t\t\t\t'&[data-copied] > [data-icon=\"check\"]': { display: \"inline-flex\" },\n\t\t\t\t\t\t}),\n\t\t\t\t\t\tcopyToClipboard(),\n\t\t\t\t\t\tcopyFeedback(copiedLabel),\n\t\t\t\t\t]}\n\t\t\t\t>\n\t\t\t\t\t<span data-icon=\"copy\">\n\t\t\t\t\t\t<CopyIcon size={16} aria-hidden=\"true\" />\n\t\t\t\t\t</span>\n\t\t\t\t\t<span data-icon=\"check\" mix={[fg(\"success\")]}>\n\t\t\t\t\t\t<CheckIcon size={16} aria-hidden=\"true\" />\n\t\t\t\t\t</span>\n\t\t\t\t\t<span role=\"status\" mix={[visuallyHidden()]} />\n\t\t\t\t</button>\n\t\t\t);\n\t\t};\n\t},\n);\n"
12
+ },
13
+ "test": null
14
+ }
@@ -1,19 +1,16 @@
1
1
  {
2
2
  "name": "date-field",
3
- "changedIn": "2026.11.1",
3
+ "changedIn": "2026.11.29",
4
4
  "dependencies": [
5
- "description",
6
- "field-error",
7
- "form",
8
- "input",
9
- "label"
5
+ "field-parts",
6
+ "input"
10
7
  ],
11
8
  "exports": [
12
9
  "DateField"
13
10
  ],
14
11
  "source": {
15
12
  "path": "date-field.tsx",
16
- "content": "/**\n * A convenience wrapper composing a labeled, described, and validated date\n * field in one call: a caption through {@link Label}, a native\n * `<input type=\"date\">` styled through {@link Input}, an optional supporting\n * passage through {@link Description}, and an optional validation message\n * through {@link FieldError}. Every id and `aria-describedby` relationship\n * between the parts is computed from this instance's own stable identifier,\n * leaving no id bookkeeping to the consumer.\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 { mergeMix } from \"@sdxc/u/general\";\nimport { tabularNums } from \"@sdxc/u/typography\";\n\nimport type { FieldPartsProps } from \"@sdxc/ui/utils\";\n\nimport { fieldStackLayout } from \"@sdxc/ui/styles\";\nimport { resolveFieldWiring } from \"@sdxc/ui/utils\";\n\nimport { Description } from \"@sdxc/ui/description\";\nimport { FieldError } from \"@sdxc/ui/field-error\";\nimport { resolveFieldIssue } from \"@sdxc/ui/form\";\nimport { Input } from \"@sdxc/ui/input\";\nimport { Label } from \"@sdxc/ui/label\";\n\n/**\n * Prop types for {@link DateField}.\n */\nexport namespace DateField {\n\t/**\n\t * Semantic color role for the control's keyboard focus ring, each mapped\n\t * to its matching `--ui-*` variables.\n\t */\n\texport type Color = \"brand\" | \"neutral\" | \"success\" | \"warning\" | \"danger\";\n\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 type PartsProps = FieldPartsProps;\n\n\t/**\n\t * Props accepted by {@link DateField}. `mix` styles the root element\n\t * grouping the field's parts; style the composed label, control,\n\t * description, and error individually through `parts` instead.\n\t */\n\texport interface Props extends Omit<TagProps<\"div\">, \"children\"> {\n\t\t/** Semantic color role for the control's focus ring. Defaults to `\"neutral\"` when omitted. */\n\t\tcolor?: Color;\n\t\t/**\n\t\t * The field's caption, rendered through {@link Label} and associated\n\t\t * with the control through a native `for`/`id` relationship computed\n\t\t * from this instance's own identifier.\n\t\t */\n\t\tlabel: RemixNode;\n\t\t/**\n\t\t * Supporting copy rendered through {@link Description} beneath the\n\t\t * control and referenced by the control's `aria-describedby`. Omit to\n\t\t * render no description.\n\t\t */\n\t\tdescription?: RemixNode;\n\t\t/**\n\t\t * Validation message rendered through {@link FieldError} beneath the\n\t\t * control; its presence alone marks `aria-invalid` unless set\n\t\t * explicitly. Inside a {@link Form} carrying `issues`, an explicit value still wins over the field's own by-`name` lookup.\n\t\t */\n\t\terrorMessage?: RemixNode;\n\t\t/**\n\t\t * Native `autofocus`. Defaults to `true` for the first invalid field of an\n\t\t * enclosing {@link Form}'s `issues`, landing keyboard focus on the problem\n\t\t * after a server round-trip; pass it explicitly to override for this field.\n\t\t */\n\t\tautoFocus?: boolean;\n\t\t/** Native `name` submitted with an enclosing form. */\n\t\tname?: string;\n\t\t/** Current value, in `YYYY-MM-DD` form, for a control a consumer tracks itself. */\n\t\tvalue?: string;\n\t\t/** Initial value, in `YYYY-MM-DD` form, for a control left to the platform's own uncontrolled state. */\n\t\tdefaultValue?: string;\n\t\t/** Earliest accepted date, in `YYYY-MM-DD` form. */\n\t\tmin?: string;\n\t\t/** Latest accepted date, in `YYYY-MM-DD` form. */\n\t\tmax?: string;\n\t\t/** Granularity, in days, the control's value must fall on. */\n\t\tstep?: number;\n\t\t/** Marks the control required for its enclosing form. */\n\t\trequired?: boolean;\n\t\t/** Marks the control inert and excluded from the tab order. */\n\t\tdisabled?: boolean;\n\t\t/** Marks the control's value fixed, while keeping it focusable and included in form submission. */\n\t\treadOnly?: boolean;\n\t\t/** Native autofill hint, e.g. `\"bday\"`. */\n\t\tautoComplete?: string;\n\t\t/** Per-part styling for this wrapper's internally composed elements. */\n\t\tparts?: PartsProps;\n\t}\n}\n\n/**\n * Renders a complete date field in one call, stacking {@link Label},\n * {@link Input}, and, when supplied, {@link Description} and {@link FieldError}.\n * An invalid state — from `errorMessage` or an explicit `aria-invalid` override — recolors the border and ring to the semantic danger tone regardless of `color`.\n *\n * @param handle Runtime handle carrying the root element's props and this instance's stable identifier.\n * @returns The render function producing the field's markup.\n * @example\n * <DateField label={t(\"form.birthday.label\")} name=\"birthday\" autoComplete=\"bday\" />\n * @example\n * <DateField\n * \tlabel={t(\"form.startDate.label\")}\n * \tname=\"startDate\"\n * \tmin=\"2026-01-01\"\n * \tmax=\"2026-12-31\"\n * \tdescription={t(\"form.startDate.hint\")}\n * />\n * @example\n * <DateField\n * \tlabel={t(\"form.dueDate.label\")}\n * \tname=\"dueDate\"\n * \tdefaultValue=\"2026-07-20\"\n * \terrorMessage={t(\"form.dueDate.pastDate\")}\n * />\n */\nexport function DateField(handle: Handle<DateField.Props>) {\n\treturn () => {\n\t\tlet {\n\t\t\tcolor,\n\t\t\tlabel,\n\t\t\tdescription,\n\t\t\terrorMessage: errorMessageProp,\n\t\t\tautoFocus,\n\t\t\tname,\n\t\t\tvalue,\n\t\t\tdefaultValue,\n\t\t\tmin,\n\t\t\tmax,\n\t\t\tstep,\n\t\t\trequired,\n\t\t\tdisabled,\n\t\t\treadOnly,\n\t\t\tautoComplete,\n\t\t\t\"aria-invalid\": ariaInvalidProp,\n\t\t\tparts,\n\t\t\tmix,\n\t\t\t...rest\n\t\t} = handle.props;\n\t\tlet { errorMessage, isFirstInvalid } = resolveFieldIssue(handle, name, errorMessageProp);\n\t\tlet resolvedAutoFocus = autoFocus ?? (isFirstInvalid || undefined);\n\t\tlet { resolvedColor, resolvedInvalid, descriptionId, errorId, describedBy } =\n\t\t\tresolveFieldWiring(handle.id, {\n\t\t\t\tcolor,\n\t\t\t\terrorMessage,\n\t\t\t\tdescription,\n\t\t\t\tariaInvalid: ariaInvalidProp,\n\t\t\t});\n\n\t\treturn (\n\t\t\t<div {...rest} data-slot=\"date-field\" mix={mergeMix(fieldStackLayout(), mix)}>\n\t\t\t\t<Label htmlFor={handle.id} mix={parts?.label}>\n\t\t\t\t\t{label}\n\t\t\t\t</Label>\n\t\t\t\t<Input\n\t\t\t\t\tid={handle.id}\n\t\t\t\t\ttype=\"date\"\n\t\t\t\t\tname={name}\n\t\t\t\t\tvalue={value}\n\t\t\t\t\tdefaultValue={defaultValue}\n\t\t\t\t\tmin={min}\n\t\t\t\t\tmax={max}\n\t\t\t\t\tstep={step}\n\t\t\t\t\trequired={required}\n\t\t\t\t\tdisabled={disabled}\n\t\t\t\t\treadOnly={readOnly}\n\t\t\t\t\tautoComplete={autoComplete}\n\t\t\t\t\t// oxlint-disable-next-line jsx-a11y/no-autofocus -- Not a focus grab on page load: this only ever resolves true for the first field an enclosing Form reports as invalid, so a failed submit lands the user on the problem instead of leaving them to hunt for it.\n\t\t\t\t\tautoFocus={resolvedAutoFocus}\n\t\t\t\t\taria-invalid={resolvedInvalid}\n\t\t\t\t\taria-describedby={describedBy}\n\t\t\t\t\tcolor={resolvedColor}\n\t\t\t\t\tmix={[tabularNums(), parts?.input]}\n\t\t\t\t/>\n\t\t\t\t{description ? (\n\t\t\t\t\t<Description id={descriptionId} mix={parts?.description}>\n\t\t\t\t\t\t{description}\n\t\t\t\t\t</Description>\n\t\t\t\t) : null}\n\t\t\t\t{errorMessage ? (\n\t\t\t\t\t<FieldError id={errorId} mix={parts?.error}>\n\t\t\t\t\t\t{errorMessage}\n\t\t\t\t\t</FieldError>\n\t\t\t\t) : null}\n\t\t\t</div>\n\t\t);\n\t};\n}\n"
13
+ "content": "/**\n * A labeled, described and validated date field: the root renders a native\n * `<input type=\"date\">` from its native attributes, and the caller writes the caption,\n * description and error as parts. Every id and `aria-describedby` link between them\n * comes from this instance's own identifier, leaving no id bookkeeping to the caller.\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 { tabularNums } from \"@sdxc/u/typography\";\n\nimport {\n\tFieldDescription,\n\tFieldErrorMessage,\n\tFieldLabel,\n\tFieldScope,\n\twireField,\n} from \"@sdxc/ui/field-parts\";\nimport { Input } from \"@sdxc/ui/input\";\n\n/**\n * Prop types for {@link DateField} and its parts.\n */\nexport namespace DateField {\n\t/**\n\t * Semantic color role for the control's keyboard focus ring, each mapped\n\t * to its matching `--ui-*` variables.\n\t */\n\texport type Color = \"brand\" | \"neutral\" | \"success\" | \"warning\" | \"danger\";\n\n\t/**\n\t * Props accepted by {@link DateField}. `mix` and the remaining native attributes\n\t * style the root element; the control's own native attributes are listed below,\n\t * and `children` holds the field's parts.\n\t */\n\texport interface Props extends TagProps<\"div\"> {\n\t\t/** Semantic color role for the control's focus ring. Defaults to `\"neutral\"` when omitted. */\n\t\tcolor?: Color;\n\t\t/**\n\t\t * Native `autofocus`. Defaults to `true` for the first invalid field of an\n\t\t * enclosing {@link Form}'s `issues`, landing keyboard focus on the problem\n\t\t * after a server round-trip; pass it explicitly to override for this field.\n\t\t */\n\t\tautoFocus?: boolean;\n\t\t/** Native `name`; it also finds the enclosing {@link Form}'s issue for this field. */\n\t\tname?: string;\n\t\t/** Current value, in `YYYY-MM-DD` form, for a control a consumer tracks itself. */\n\t\tvalue?: string;\n\t\t/** Initial value, in `YYYY-MM-DD` form, for a control left to the platform's own uncontrolled state. */\n\t\tdefaultValue?: string;\n\t\t/** Earliest accepted date, in `YYYY-MM-DD` form. */\n\t\tmin?: string;\n\t\t/** Latest accepted date, in `YYYY-MM-DD` form. */\n\t\tmax?: string;\n\t\t/** Granularity, in days, the control's value must fall on. */\n\t\tstep?: number;\n\t\trequired?: boolean;\n\t\tdisabled?: boolean;\n\t\treadOnly?: boolean;\n\t\t/** Native autofill hint, e.g. `\"bday\"`. */\n\t\tautoComplete?: string;\n\t\t/**\n\t\t * The field's parts: `.Label`, `.Description` and `.Error`. The control follows\n\t\t * the caption, and the rest keep their order.\n\t\t */\n\t\tchildren?: RemixNode;\n\t}\n\n\t/** Props accepted by {@link DateField.Label}: a native `<label>` pointing at the control. */\n\texport interface LabelProps extends FieldScope.LabelProps {}\n\t/** Props accepted by {@link DateField.Description}: a native `<p>` the control describes itself by. */\n\texport interface DescriptionProps extends FieldScope.DescriptionProps {}\n\t/** Props accepted by {@link DateField.Error}: a native `<span>` holding the message. */\n\texport interface ErrorProps extends FieldScope.ErrorProps {}\n}\n\n/**\n * Renders a date field: the native date control, laid out with the parts the caller\n * writes. An error, from `.Error` or an enclosing {@link Form}'s issue for `name`, marks\n * the control invalid and recolors its border and ring to the danger tone.\n *\n * @param handle Runtime handle carrying the root element's props and this instance's stable identifier.\n * @returns The render function producing the field's markup.\n * @example\n * <DateField name=\"birthday\" autoComplete=\"bday\">\n * \t<DateField.Label>{t(\"form.birthday.label\")}</DateField.Label>\n * </DateField>\n * @example\n * <DateField name=\"startDate\" min=\"2026-01-01\" max=\"2026-12-31\">\n * \t<DateField.Label>{t(\"form.startDate.label\")}</DateField.Label>\n * \t<DateField.Description>{t(\"form.startDate.hint\")}</DateField.Description>\n * </DateField>\n */\nexport function DateField(handle: Handle<DateField.Props>) {\n\treturn () => {\n\t\tlet {\n\t\t\tcolor,\n\t\t\tautoFocus,\n\t\t\tname,\n\t\t\tvalue,\n\t\t\tdefaultValue,\n\t\t\tmin,\n\t\t\tmax,\n\t\t\tstep,\n\t\t\trequired,\n\t\t\tdisabled,\n\t\t\treadOnly,\n\t\t\tautoComplete,\n\t\t\t\"aria-invalid\": ariaInvalid,\n\t\t\tchildren,\n\t\t\t...rest\n\t\t} = handle.props;\n\t\tlet field = wireField(handle, {\n\t\t\tslot: \"date-field\",\n\t\t\tchildren,\n\t\t\tname,\n\t\t\tcolor,\n\t\t\tautoFocus,\n\t\t\tariaInvalid,\n\t\t});\n\n\t\treturn (\n\t\t\t<FieldScope {...rest} context={field.context}>\n\t\t\t\t{field.arrange(\n\t\t\t\t\t<Input\n\t\t\t\t\t\t{...field.control}\n\t\t\t\t\t\ttype=\"date\"\n\t\t\t\t\t\tname={name}\n\t\t\t\t\t\tvalue={value}\n\t\t\t\t\t\tdefaultValue={defaultValue}\n\t\t\t\t\t\tmin={min}\n\t\t\t\t\t\tmax={max}\n\t\t\t\t\t\tstep={step}\n\t\t\t\t\t\trequired={required}\n\t\t\t\t\t\tdisabled={disabled}\n\t\t\t\t\t\treadOnly={readOnly}\n\t\t\t\t\t\tautoComplete={autoComplete}\n\t\t\t\t\t\tmix={tabularNums()}\n\t\t\t\t\t/>,\n\t\t\t\t)}\n\t\t\t</FieldScope>\n\t\t);\n\t};\n}\n\nDateField.Label = FieldLabel;\nDateField.Description = FieldDescription;\nDateField.Error = FieldErrorMessage;\n"
17
14
  },
18
15
  "test": null
19
16
  }
@@ -1,15 +1,13 @@
1
1
  {
2
2
  "name": "date-picker",
3
- "changedIn": "2026.11.1",
4
- "dependencies": [
5
- "date-field"
6
- ],
3
+ "changedIn": "2026.11.29",
4
+ "dependencies": [],
7
5
  "exports": [
8
6
  "DatePicker"
9
7
  ],
10
8
  "source": {
11
9
  "path": "date-picker.tsx",
12
- "content": "/**\n * A labeled date field built on {@link DateField}, with a\n * {@link DatePicker.Group} row for composing more than one field into a single\n * control. The calendar is the platform's: the field is a native date input, so\n * the picker, its keyboard handling and its locale all come from the browser and\n * all of it works before any script loads. Leaving `children` unset renders the\n * field on its own.\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 { outline } from \"@sdxc/u/color\";\nimport { roundedCorner } from \"@sdxc/u/effects\";\nimport { raw, mergeMix } from \"@sdxc/u/general\";\nimport { flex, flexCol, gap, items } from \"@sdxc/u/layout\";\nimport { mis } from \"@sdxc/u/size\";\nimport { z } from \"@sdxc/u/stacking\";\nimport { when } from \"@sdxc/u/state\";\n\nimport { DateField } from \"@sdxc/ui/date-field\";\n\n/**\n * Prop types for {@link DatePicker} and its compound parts.\n */\nexport namespace DatePicker {\n\t/**\n\t * Semantic color role for the fallback field's keyboard focus ring. Read\n\t * only by the fallback field — {@link DatePicker.Group}'s composed\n\t * control carries no `color` prop of its own.\n\t */\n\texport type Color = DateField.Color;\n\n\t/**\n\t * Every prop {@link DateField.PartsProps} accepts, applied only to the\n\t * field's internally composed parts; a composed layout styles the controls\n\t * inside {@link DatePicker.Group} individually.\n\t */\n\texport interface PartsProps extends DateField.PartsProps {}\n\n\t/**\n\t * Props accepted by {@link DatePicker}. Leaving `children` unset renders the\n\t * field using every prop below; composing {@link DatePicker.Group} instead\n\t * renders the joined row and leaves every prop below unread.\n\t */\n\texport interface Props extends Omit<TagProps<\"div\">, \"children\"> {\n\t\t/** Semantic color role for the fallback field's focus ring. Read only when `children` is unset. */\n\t\tcolor?: Color;\n\t\t/** The fallback field's caption, rendered through {@link DateField}. Read only when `children` is unset. */\n\t\tlabel?: RemixNode;\n\t\t/** Supporting copy beneath the fallback field. Read only when `children` is unset. */\n\t\tdescription?: RemixNode;\n\t\t/** Validation message beneath the fallback field. Read only when `children` is unset. */\n\t\terrorMessage?: RemixNode;\n\t\t/** Native `name` submitted with an enclosing form, read only by the fallback field. */\n\t\tname?: string;\n\t\t/** Current value, in `YYYY-MM-DD` form, for a fallback field a consumer tracks itself. */\n\t\tvalue?: string;\n\t\t/** Initial value, in `YYYY-MM-DD` form, for a fallback field left to the platform's own uncontrolled state. */\n\t\tdefaultValue?: string;\n\t\t/** Earliest accepted date, in `YYYY-MM-DD` form, read only by the fallback field. */\n\t\tmin?: string;\n\t\t/** Latest accepted date, in `YYYY-MM-DD` form, read only by the fallback field. */\n\t\tmax?: string;\n\t\t/** Granularity, in days, the fallback field's value must fall on. */\n\t\tstep?: number;\n\t\t/** Marks the fallback field required for its enclosing form. */\n\t\trequired?: boolean;\n\t\t/** Marks the fallback field inert and excluded from the tab order. */\n\t\tdisabled?: boolean;\n\t\t/** Marks the fallback field's value fixed, while keeping it focusable and included in form submission. */\n\t\treadOnly?: boolean;\n\t\t/** Native autofill hint for the fallback field, e.g. `\"bday\"`. */\n\t\tautoComplete?: string;\n\t\t/** Per-part styling for the fallback field's internally composed parts. Read only when `children` is unset. */\n\t\tparts?: PartsProps;\n\t\t/**\n\t\t * The composed layout — typically a `Label` and a\n\t\t * {@link DatePicker.Group} — rendered in place of the field, leaving every\n\t\t * field above unread.\n\t\t */\n\t\tchildren?: RemixNode;\n\t}\n\n\t/**\n\t * Every native `<div>` attribute, unchanged, plus the `mix` passthrough.\n\t * `children` composes the field's own control, and a second one for a\n\t * range, into one visual row.\n\t */\n\texport interface GroupProps extends TagProps<\"div\"> {}\n}\n\n/**\n * Renders {@link DatePicker}'s root. Leaving `children` unset renders the field,\n * passing every prop above through unchanged; composing\n * {@link DatePicker.Group} as `children` instead renders the joined row and\n * leaves those props unread.\n *\n * @param handle Runtime handle carrying the root element's props.\n * @returns The render function producing the date picker's markup.\n * @example\n * <DatePicker label={t(\"form.birthday.label\")} name=\"birthday\" autoComplete=\"bday\" />\n * @example\n * <DatePicker>\n * \t<Label htmlFor=\"startDate\">{t(\"form.startDate.label\")}</Label>\n * \t<DatePicker.Group>\n * \t\t<Input id=\"startDate\" type=\"date\" name=\"startDate\" />\n * \t</DatePicker.Group>\n * </DatePicker>\n */\nexport function DatePicker(handle: Handle<DatePicker.Props>) {\n\treturn () => {\n\t\tlet {\n\t\t\tcolor,\n\t\t\tlabel,\n\t\t\tdescription,\n\t\t\terrorMessage,\n\t\t\tname,\n\t\t\tvalue,\n\t\t\tdefaultValue,\n\t\t\tmin,\n\t\t\tmax,\n\t\t\tstep,\n\t\t\trequired,\n\t\t\tdisabled,\n\t\t\treadOnly,\n\t\t\tautoComplete,\n\t\t\tparts,\n\t\t\tchildren,\n\t\t\tmix,\n\t\t\t...rest\n\t\t} = handle.props;\n\n\t\tif (import.meta.env?.DEV && !children && !label) {\n\t\t\tconsole.warn(\n\t\t\t\t'DatePicker: falling back to DateField\\'s plain \"input type=date\" needs a \"label\" describing what it collects for assistive technology.',\n\t\t\t);\n\t\t}\n\n\t\tif (!children) {\n\t\t\treturn (\n\t\t\t\t<DateField\n\t\t\t\t\t{...rest}\n\t\t\t\t\tcolor={color}\n\t\t\t\t\tlabel={label}\n\t\t\t\t\tdescription={description}\n\t\t\t\t\terrorMessage={errorMessage}\n\t\t\t\t\tname={name}\n\t\t\t\t\tvalue={value}\n\t\t\t\t\tdefaultValue={defaultValue}\n\t\t\t\t\tmin={min}\n\t\t\t\t\tmax={max}\n\t\t\t\t\tstep={step}\n\t\t\t\t\trequired={required}\n\t\t\t\t\tdisabled={disabled}\n\t\t\t\t\treadOnly={readOnly}\n\t\t\t\t\tautoComplete={autoComplete}\n\t\t\t\t\tparts={parts}\n\t\t\t\t\tmix={mix}\n\t\t\t\t/>\n\t\t\t);\n\t\t}\n\n\t\treturn (\n\t\t\t<div {...rest} data-slot=\"date-picker\" mix={mergeMix([flex(), flexCol(), gap(1)], mix)}>\n\t\t\t\t{children}\n\t\t\t</div>\n\t\t);\n\t};\n}\n\n/**\n * Renders {@link DatePicker}'s control row: a flex host laying one or more date\n * controls side by side and joining their edges, so a pair reads as one field.\n * Focus and validity are drawn the way `Group` draws them — focus by the control\n * that holds it, validity once around the row.\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 * <DatePicker.Group>\n * \t<Input id=\"startDate\" type=\"date\" name=\"startDate\" />\n * </DatePicker.Group>\n */\nDatePicker.Group = function DatePickerGroup(handle: Handle<DatePicker.GroupProps>) {\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\tdata-slot=\"group\"\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\t/**\n\t\t\t\t\t\t * The fields compose into one control, so the pair keeps the rounding on its own\n\t\t\t\t\t\t * outer corners and the seam the two share is drawn once.\n\t\t\t\t\t\t */\n\t\t\t\t\t\twhen(\"& > *:not(:first-child)\", [\n\t\t\t\t\t\t\troundedCorner(\"start-start\", \"none\"),\n\t\t\t\t\t\t\troundedCorner(\"end-start\", \"none\"),\n\t\t\t\t\t\t\tmis(\"-1px\"),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\twhen(\"& > *:not(:last-child)\", [\n\t\t\t\t\t\t\troundedCorner(\"start-end\", \"none\"),\n\t\t\t\t\t\t\troundedCorner(\"end-end\", \"none\"),\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 field holding it, naming which date has it where a ring around\n\t\t\t\t\t\t * the pair names only the group. That field is raised so its ring crosses the seam.\n\t\t\t\t\t\t */\n\t\t\t\t\t\twhen(\"& > *:focus-visible\", z(1)),\n\t\t\t\t\t\t/**\n\t\t\t\t\t\t * Validity belongs to the pair, since a range is one value and half of one makes it\n\t\t\t\t\t\t * invalid: one ring is drawn around the group and each field's own ring is released,\n\t\t\t\t\t\t * so the seam shows one field needing attention.\n\t\t\t\t\t\t */\n\t\t\t\t\t\twhen(\n\t\t\t\t\t\t\t'&:has(> :user-invalid), &:has(> [aria-invalid=\"true\"])',\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\twhen(\n\t\t\t\t\t\t\t'& > :user-invalid:not(:focus-visible), & > [aria-invalid=\"true\"]:not(:focus-visible)',\n\t\t\t\t\t\t\t/**\n\t\t\t\t\t\t\t * Important so it reaches across to the cascade layer where `Input` states the field's\n\t\t\t\t\t\t\t * invalid ring. The selector excludes `:focus-visible`, so a field being filled in still\n\t\t\t\t\t\t\t * shows its own focus ring.\n\t\t\t\t\t\t\t */\n\t\t\t\t\t\t\traw({ outline: \"none !important\" }),\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"
10
+ "content": "/**\n * A labeled date control composed from a caption, a {@link DatePicker.Group} row joining\n * one or more native date inputs into a single control, and any supporting copy. The\n * calendar is the platform's: each input is a native date input, so the picker, its\n * keyboard handling and its locale all come from the browser before any script loads.\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 { outline } from \"@sdxc/u/color\";\nimport { roundedCorner } from \"@sdxc/u/effects\";\nimport { raw, mergeMix } from \"@sdxc/u/general\";\nimport { flex, flexCol, gap, items } from \"@sdxc/u/layout\";\nimport { mis } from \"@sdxc/u/size\";\nimport { z } from \"@sdxc/u/stacking\";\nimport { when } from \"@sdxc/u/state\";\n\n/**\n * Prop types for {@link DatePicker} and its compound parts.\n */\nexport namespace DatePicker {\n\t/**\n\t * Every native `<div>` attribute plus the `mix` passthrough. `children` composes the\n\t * control: typically a `Label`, a {@link DatePicker.Group} and a `Description`. A lone\n\t * labeled date input is a `DateField`.\n\t */\n\texport interface Props extends TagProps<\"div\"> {}\n\n\t/**\n\t * Every native `<div>` attribute, unchanged, plus the `mix` passthrough.\n\t * `children` composes the field's own control, and a second one for a\n\t * range, into one visual row.\n\t */\n\texport interface GroupProps extends TagProps<\"div\"> {}\n}\n\n/**\n * Renders {@link DatePicker}'s root: a column stacking the caption, the joined row and\n * any supporting copy the caller writes, in the order written.\n *\n * @param handle Runtime handle carrying the root element's props.\n * @returns The render function producing the date picker's markup.\n * @example\n * <DatePicker>\n * \t<Label htmlFor=\"startDate\">{t(\"form.startDate.label\")}</Label>\n * \t<DatePicker.Group>\n * \t\t<Input id=\"startDate\" type=\"date\" name=\"startDate\" />\n * \t</DatePicker.Group>\n * </DatePicker>\n */\nexport function DatePicker(handle: Handle<DatePicker.Props>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<div {...rest} data-slot=\"date-picker\" mix={mergeMix([flex(), flexCol(), gap(1)], mix)} />\n\t\t);\n\t};\n}\n\n/**\n * Renders {@link DatePicker}'s control row: a flex host laying one or more date\n * controls side by side and joining their edges, so a pair reads as one field.\n * Focus and validity are drawn the way `Group` draws them — focus by the control\n * that holds it, validity once around the row.\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 * <DatePicker.Group>\n * \t<Input id=\"startDate\" type=\"date\" name=\"startDate\" />\n * </DatePicker.Group>\n */\nDatePicker.Group = function DatePickerGroup(handle: Handle<DatePicker.GroupProps>) {\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\tdata-slot=\"group\"\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\t/**\n\t\t\t\t\t\t * The fields compose into one control, so the pair keeps the rounding on its own\n\t\t\t\t\t\t * outer corners and the seam the two share is drawn once.\n\t\t\t\t\t\t */\n\t\t\t\t\t\twhen(\"& > *:not(:first-child)\", [\n\t\t\t\t\t\t\troundedCorner(\"start-start\", \"none\"),\n\t\t\t\t\t\t\troundedCorner(\"end-start\", \"none\"),\n\t\t\t\t\t\t\tmis(\"-1px\"),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\twhen(\"& > *:not(:last-child)\", [\n\t\t\t\t\t\t\troundedCorner(\"start-end\", \"none\"),\n\t\t\t\t\t\t\troundedCorner(\"end-end\", \"none\"),\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 field holding it, naming which date has it where a ring around\n\t\t\t\t\t\t * the pair names only the group. That field is raised so its ring crosses the seam.\n\t\t\t\t\t\t */\n\t\t\t\t\t\twhen(\"& > *:focus-visible\", z(1)),\n\t\t\t\t\t\t/**\n\t\t\t\t\t\t * Validity belongs to the pair, since a range is one value and half of one makes it\n\t\t\t\t\t\t * invalid: one ring is drawn around the group and each field's own ring is released,\n\t\t\t\t\t\t * so the seam shows one field needing attention.\n\t\t\t\t\t\t */\n\t\t\t\t\t\twhen(\n\t\t\t\t\t\t\t'&:has(> :user-invalid), &:has(> [aria-invalid=\"true\"])',\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\twhen(\n\t\t\t\t\t\t\t'& > :user-invalid:not(:focus-visible), & > [aria-invalid=\"true\"]:not(:focus-visible)',\n\t\t\t\t\t\t\t/**\n\t\t\t\t\t\t\t * Important so it reaches across to the cascade layer where `Input` states the field's\n\t\t\t\t\t\t\t * invalid ring. The selector excludes `:focus-visible`, so a field being filled in still\n\t\t\t\t\t\t\t * shows its own focus ring.\n\t\t\t\t\t\t\t */\n\t\t\t\t\t\t\traw({ outline: \"none !important\" }),\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"
13
11
  },
14
12
  "test": null
15
13
  }
@@ -1,8 +1,7 @@
1
1
  {
2
2
  "name": "date-range-picker",
3
- "changedIn": "2026.11.1",
3
+ "changedIn": "2026.11.29",
4
4
  "dependencies": [
5
- "date-field",
6
5
  "date-picker"
7
6
  ],
8
7
  "exports": [
@@ -10,7 +9,7 @@
10
9
  ],
11
10
  "source": {
12
11
  "path": "date-range-picker.tsx",
13
- "content": "/**\n * A paired-field date range control built on {@link DateField} — independent\n * start-date and end-date fields, each fully labeled, described, and validated\n * on its own — with a {@link DateRangePicker.Group} row for joining the two\n * into one control. The calendar is the platform's, since each field is a\n * native date input, so the whole range is pickable before any script loads.\n * Leaving `children` unset renders the pair on its own.\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 { mergeMix } from \"@sdxc/u/general\";\nimport { flex, flexCol, gap, items } from \"@sdxc/u/layout\";\nimport { attrs } from \"remix/component\";\n\nimport { DateField } from \"@sdxc/ui/date-field\";\nimport { DatePicker } from \"@sdxc/ui/date-picker\";\n\n/**\n * Prop types for {@link DateRangePicker} and its compound parts.\n * {@link DateRangePicker.Group} aliases {@link DatePicker.Group} directly,\n * since a row of fields reads the same for a range as for a single date.\n */\nexport namespace DateRangePicker {\n\t/**\n\t * Semantic color role for the fallback pair's keyboard focus rings. Read\n\t * only by the fallback fields — {@link DateRangePicker.Group}'s composed\n\t * control carries no `color` prop of its own.\n\t */\n\texport type Color = DateField.Color;\n\n\t/**\n\t * Per-part styling for the two {@link DateField} instances the fallback\n\t * pair composes, each forwarded to that field's own `parts`. Read only\n\t * when `children` is unset; the composed layout styles its own parts individually instead.\n\t */\n\texport interface PartsProps {\n\t\t/** Per-part styling for the fallback pair's start-date field. */\n\t\tstart?: DateField.PartsProps;\n\t\t/** Per-part styling for the fallback pair's end-date field. */\n\t\tend?: DateField.PartsProps;\n\t}\n\n\t/**\n\t * Props accepted by {@link DateRangePicker}. Leaving `children` unset\n\t * renders two independent {@link DateField} instances — one per end of\n\t * the range — using every field below; composing\n\t * {@link DateRangePicker.Group} instead renders the joined row and leaves\n\t * every field below unread.\n\t */\n\texport interface Props extends Omit<TagProps<\"div\">, \"children\"> {\n\t\t/** Semantic color role for the fallback pair's focus rings. Read only when `children` is unset. */\n\t\tcolor?: Color;\n\t\t/** The start-date field's caption, rendered through {@link DateField}. Read only when `children` is unset. */\n\t\tstartLabel?: RemixNode;\n\t\t/** The end-date field's caption, rendered through {@link DateField}. Read only when `children` is unset. */\n\t\tendLabel?: RemixNode;\n\t\t/** Supporting copy beneath the start-date field. Read only when `children` is unset. */\n\t\tstartDescription?: RemixNode;\n\t\t/** Supporting copy beneath the end-date field. Read only when `children` is unset. */\n\t\tendDescription?: RemixNode;\n\t\t/** Validation message beneath the start-date field. Read only when `children` is unset. */\n\t\tstartErrorMessage?: RemixNode;\n\t\t/** Validation message beneath the end-date field. Read only when `children` is unset. */\n\t\tendErrorMessage?: RemixNode;\n\t\t/** Native `name` submitted with an enclosing form for the start-date field. */\n\t\tstartName?: string;\n\t\t/** Native `name` submitted with an enclosing form for the end-date field. */\n\t\tendName?: string;\n\t\t/** Current start-of-range value, in `YYYY-MM-DD` form, for a fallback pair a consumer tracks itself. */\n\t\tstartValue?: string;\n\t\t/** Current end-of-range value, in `YYYY-MM-DD` form, for a fallback pair a consumer tracks itself. */\n\t\tendValue?: string;\n\t\t/** Initial start-of-range value, in `YYYY-MM-DD` form, for a fallback pair left to the platform's own uncontrolled state. */\n\t\tstartDefaultValue?: string;\n\t\t/** Initial end-of-range value, in `YYYY-MM-DD` form, for a fallback pair left to the platform's own uncontrolled state. */\n\t\tendDefaultValue?: string;\n\t\t/** Earliest accepted date, in `YYYY-MM-DD` form, read by both of the fallback pair's fields. */\n\t\tmin?: string;\n\t\t/** Latest accepted date, in `YYYY-MM-DD` form, read by both of the fallback pair's fields. */\n\t\tmax?: string;\n\t\t/** Granularity, in days, both of the fallback pair's values must fall on. */\n\t\tstep?: number;\n\t\t/** Marks both of the fallback pair's fields required for their enclosing form. */\n\t\trequired?: boolean;\n\t\t/** Marks both of the fallback pair's fields inert and excluded from the tab order. */\n\t\tdisabled?: boolean;\n\t\t/** Marks both of the fallback pair's fields' values fixed, while keeping them focusable and included in form submission. */\n\t\treadOnly?: boolean;\n\t\t/** Native autofill hint for both of the fallback pair's fields. */\n\t\tautoComplete?: string;\n\t\t/** Per-part styling for the fallback pair's internally composed {@link DateField} instances. Read only when `children` is unset. */\n\t\tparts?: PartsProps;\n\t\t/**\n\t\t * The joined layout — typically a `Label` and a\n\t\t * {@link DateRangePicker.Group} — rendered in place of the paired fields,\n\t\t * leaving every field above unread when set.\n\t\t */\n\t\tchildren?: RemixNode;\n\t}\n\n\t/**\n\t * Every prop {@link DatePicker.GroupProps} accepts, unchanged. `children`\n\t * composes the range's own start and end controls into one visual row.\n\t */\n\texport interface GroupProps extends DatePicker.GroupProps {}\n}\n\n/**\n * Renders {@link DateRangePicker}'s root. Leaving `children` unset renders\n * two independent {@link DateField} instances side by side under a native\n * `role=\"group\"`, each aligned to its own start edge so a validation message\n * under one never shifts the other's label; composing\n * {@link DateRangePicker.Group} as `children` instead joins the two fields into\n * one row and leaves every field prop above unread.\n *\n * @param handle Runtime handle carrying the root element's props.\n * @returns The render function producing the date range picker's markup.\n * @example\n * <DateRangePicker\n * \tstartLabel={t(\"form.stay.checkIn\")}\n * \tendLabel={t(\"form.stay.checkOut\")}\n * \tstartName=\"checkIn\"\n * \tendName=\"checkOut\"\n * />\n * @example\n * <DateRangePicker>\n * \t<Label htmlFor=\"tripStart\">{t(\"form.trip.label\")}</Label>\n * \t<DateRangePicker.Group>\n * \t\t<Input id=\"tripStart\" type=\"date\" name=\"tripStart\" aria-label={t(\"form.trip.start\")} />\n * \t\t<Input id=\"tripEnd\" type=\"date\" name=\"tripEnd\" aria-label={t(\"form.trip.end\")} />\n * \t</DateRangePicker.Group>\n * </DateRangePicker>\n */\nexport function DateRangePicker(handle: Handle<DateRangePicker.Props>) {\n\treturn () => {\n\t\tlet {\n\t\t\tcolor,\n\t\t\tstartLabel,\n\t\t\tendLabel,\n\t\t\tstartDescription,\n\t\t\tendDescription,\n\t\t\tstartErrorMessage,\n\t\t\tendErrorMessage,\n\t\t\tstartName,\n\t\t\tendName,\n\t\t\tstartValue,\n\t\t\tendValue,\n\t\t\tstartDefaultValue,\n\t\t\tendDefaultValue,\n\t\t\tmin,\n\t\t\tmax,\n\t\t\tstep,\n\t\t\trequired,\n\t\t\tdisabled,\n\t\t\treadOnly,\n\t\t\tautoComplete,\n\t\t\tparts,\n\t\t\tchildren,\n\t\t\tmix,\n\t\t\t...rest\n\t\t} = handle.props;\n\n\t\tif (import.meta.env?.DEV && !children) {\n\t\t\tif (!startLabel) {\n\t\t\t\tconsole.warn(\n\t\t\t\t\t'DateRangePicker: falling back to paired \"input type=date\" fields needs a \"startLabel\" describing the range\\'s start for assistive technology.',\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (!endLabel) {\n\t\t\t\tconsole.warn(\n\t\t\t\t\t'DateRangePicker: falling back to paired \"input type=date\" fields needs an \"endLabel\" describing the range\\'s end for assistive technology.',\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tif (!children) {\n\t\t\treturn (\n\t\t\t\t<div\n\t\t\t\t\t{...rest}\n\t\t\t\t\tdata-slot=\"fields\"\n\t\t\t\t\tmix={mergeMix([attrs({ role: \"group\" }), flex(), gap(2), items(\"start\")], mix)}\n\t\t\t\t>\n\t\t\t\t\t<DateField\n\t\t\t\t\t\tcolor={color}\n\t\t\t\t\t\tlabel={startLabel}\n\t\t\t\t\t\tdescription={startDescription}\n\t\t\t\t\t\terrorMessage={startErrorMessage}\n\t\t\t\t\t\tname={startName}\n\t\t\t\t\t\tvalue={startValue}\n\t\t\t\t\t\tdefaultValue={startDefaultValue}\n\t\t\t\t\t\tmin={min}\n\t\t\t\t\t\tmax={max}\n\t\t\t\t\t\tstep={step}\n\t\t\t\t\t\trequired={required}\n\t\t\t\t\t\tdisabled={disabled}\n\t\t\t\t\t\treadOnly={readOnly}\n\t\t\t\t\t\tautoComplete={autoComplete}\n\t\t\t\t\t\tparts={parts?.start}\n\t\t\t\t\t/>\n\t\t\t\t\t<DateField\n\t\t\t\t\t\tcolor={color}\n\t\t\t\t\t\tlabel={endLabel}\n\t\t\t\t\t\tdescription={endDescription}\n\t\t\t\t\t\terrorMessage={endErrorMessage}\n\t\t\t\t\t\tname={endName}\n\t\t\t\t\t\tvalue={endValue}\n\t\t\t\t\t\tdefaultValue={endDefaultValue}\n\t\t\t\t\t\tmin={min}\n\t\t\t\t\t\tmax={max}\n\t\t\t\t\t\tstep={step}\n\t\t\t\t\t\trequired={required}\n\t\t\t\t\t\tdisabled={disabled}\n\t\t\t\t\t\treadOnly={readOnly}\n\t\t\t\t\t\tautoComplete={autoComplete}\n\t\t\t\t\t\tparts={parts?.end}\n\t\t\t\t\t/>\n\t\t\t\t</div>\n\t\t\t);\n\t\t}\n\n\t\treturn (\n\t\t\t<div {...rest} data-slot=\"date-range-picker\" mix={mergeMix([flex(), flexCol(), gap(1)], mix)}>\n\t\t\t\t{children}\n\t\t\t</div>\n\t\t);\n\t};\n}\n\n/**\n * Renders {@link DateRangePicker}'s control row: identical to\n * {@link DatePicker.Group}'s markup and focus-within outline. `children`\n * composes the range's start and end controls with {@link DateRangePicker.Button}, and the row gains a keyboard focus ring whenever focus lands anywhere inside it.\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 * <DateRangePicker.Group>\n * \t<Input id=\"tripStart\" type=\"date\" name=\"tripStart\" aria-label={t(\"form.trip.start\")} />\n * \t<Input id=\"tripEnd\" type=\"date\" name=\"tripEnd\" aria-label={t(\"form.trip.end\")} />\n * </DateRangePicker.Group>\n */\nDateRangePicker.Group = DatePicker.Group;\n"
12
+ "content": "/**\n * A date range control in one of two layouts: a caption over a\n * {@link DateRangePicker.Group} row joining the start and end inputs into one control,\n * or two independent `DateField`s side by side, each labeled, described and validated on\n * its own. The calendar is the platform's, so the whole range is pickable before any script loads.\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 { mergeMix } from \"@sdxc/u/general\";\nimport { flex, flexCol, gap, items } from \"@sdxc/u/layout\";\nimport { attrs } from \"remix/component\";\n\nimport { DatePicker } from \"@sdxc/ui/date-picker\";\n\n/** Layout {@link DateRangePicker} falls back to when `layout` is omitted. */\nconst DEFAULT_LAYOUT: DateRangePicker.Layout = \"joined\";\n\n/**\n * Prop types for {@link DateRangePicker} and its compound parts.\n * {@link DateRangePicker.Group} aliases {@link DatePicker.Group} directly,\n * since a row of fields reads the same for a range as for a single date.\n */\nexport namespace DateRangePicker {\n\t/**\n\t * `\"joined\"` stacks a caption, the {@link DateRangePicker.Group} row and any supporting\n\t * copy in a column. `\"split\"` lays two independent `DateField`s side by side under a\n\t * `role=\"group\"`, each aligned to its own start edge so one field's message never\n\t * shifts the other's caption.\n\t */\n\texport type Layout = \"joined\" | \"split\";\n\n\t/** Every native `<div>` attribute plus the `mix` passthrough; `children` composes the range. */\n\texport interface Props extends TagProps<\"div\"> {\n\t\t/** How the range lays out its children. Defaults to {@link DEFAULT_LAYOUT}. */\n\t\tlayout?: Layout;\n\t}\n\n\t/**\n\t * Every prop {@link DatePicker.GroupProps} accepts, unchanged. `children`\n\t * composes the range's own start and end controls into one visual row.\n\t */\n\texport interface GroupProps extends DatePicker.GroupProps {}\n}\n\n/**\n * Renders {@link DateRangePicker}'s root in its `layout`, holding the parts the caller\n * writes in the order written.\n *\n * @param handle Runtime handle carrying the root element's props.\n * @returns The render function producing the date range picker's markup.\n * @example\n * <DateRangePicker layout=\"split\">\n * \t<DateField name=\"checkIn\"><DateField.Label>{t(\"form.stay.checkIn\")}</DateField.Label></DateField>\n * \t<DateField name=\"checkOut\"><DateField.Label>{t(\"form.stay.checkOut\")}</DateField.Label></DateField>\n * </DateRangePicker>\n * @example\n * <DateRangePicker>\n * \t<Label htmlFor=\"tripStart\">{t(\"form.trip.label\")}</Label>\n * \t<DateRangePicker.Group>\n * \t\t<Input id=\"tripStart\" type=\"date\" name=\"tripStart\" aria-label={t(\"form.trip.start\")} />\n * \t\t<Input id=\"tripEnd\" type=\"date\" name=\"tripEnd\" aria-label={t(\"form.trip.end\")} />\n * \t</DateRangePicker.Group>\n * </DateRangePicker>\n */\nexport function DateRangePicker(handle: Handle<DateRangePicker.Props>) {\n\treturn () => {\n\t\tlet { layout = DEFAULT_LAYOUT, 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=\"date-range-picker\"\n\t\t\t\tdata-layout={layout}\n\t\t\t\tmix={mergeMix(\n\t\t\t\t\tlayout === \"split\"\n\t\t\t\t\t\t? [attrs({ role: \"group\" }), flex(), gap(2), items(\"start\")]\n\t\t\t\t\t\t: [flex(), flexCol(), gap(1)],\n\t\t\t\t\tmix,\n\t\t\t\t)}\n\t\t\t/>\n\t\t);\n\t};\n}\n\n/**\n * Renders {@link DateRangePicker}'s control row: identical to\n * {@link DatePicker.Group}'s markup and focus-within outline. `children`\n * composes the range's start and end controls with {@link DateRangePicker.Button}, and the row gains a keyboard focus ring whenever focus lands anywhere inside it.\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 * <DateRangePicker.Group>\n * \t<Input id=\"tripStart\" type=\"date\" name=\"tripStart\" aria-label={t(\"form.trip.start\")} />\n * \t<Input id=\"tripEnd\" type=\"date\" name=\"tripEnd\" aria-label={t(\"form.trip.end\")} />\n * </DateRangePicker.Group>\n */\nDateRangePicker.Group = DatePicker.Group;\n"
14
13
  },
15
14
  "test": null
16
15
  }
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "dialog-dismiss",
3
- "changedIn": "2026.11.1",
3
+ "changedIn": "2026.11.29",
4
4
  "dependencies": [],
5
5
  "exports": [
6
6
  "DialogDismiss"
7
7
  ],
8
8
  "source": {
9
9
  "path": "dialog-dismiss.tsx",
10
- "content": "/**\n * Client island that closes the modal `<dialog>` it renders inside on a backdrop press or a\n * followed link, for a navigation sheet or drawer whose links include same-page anchors.\n * It owns no visible markup, so it drops into any dialog's content.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type { EntryComponent } from \"remix/component\";\n\nimport { hidden } from \"@sdxc/u/layout\";\nimport { clientEntry } from \"remix/component\";\n\nimport { dialogDismiss } from \"@sdxc/ui/mixins\";\n\n/**\n * Renders a hidden marker carrying {@link dialogDismiss}. The island loads from the bare\n * `@sdxc/ui/dialog-dismiss` specifier, which the app's browser entry maps to a dynamic\n * import. A page restored from the back-forward cache returns with the dialog closed.\n *\n * @example\n * <SiteHeader brand={<Logo />} items={items} sheet={<DialogDismiss />} />\n */\nexport const DialogDismiss: EntryComponent<Record<never, never>> = clientEntry(\n\t\"@sdxc/ui/dialog-dismiss#DialogDismiss\",\n\tfunction DialogDismiss() {\n\t\treturn () => <span mix={[hidden(), dialogDismiss()]} />;\n\t},\n);\n"
10
+ "content": "/**\n * Client island that closes the modal `<dialog>` it renders inside on a backdrop press or a\n * followed link, for a navigation sheet or drawer whose links include same-page anchors.\n * It owns no visible markup, so it drops into any dialog's content.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type { EntryComponent } from \"remix/component\";\n\nimport { hidden } from \"@sdxc/u/layout\";\nimport { clientEntry } from \"remix/component\";\n\nimport { dialogDismiss } from \"@sdxc/ui/mixins\";\n\n/**\n * Renders a hidden marker carrying {@link dialogDismiss}. The island loads from the bare\n * `@sdxc/ui/dialog-dismiss` specifier, which the app's browser entry maps to a dynamic\n * import. A page restored from the back-forward cache returns with the dialog closed.\n *\n * @example\n * <SiteHeader.Sheet><DialogDismiss /></SiteHeader.Sheet>\n */\nexport const DialogDismiss: EntryComponent<Record<never, never>> = clientEntry(\n\t\"@sdxc/ui/dialog-dismiss#DialogDismiss\",\n\tfunction DialogDismiss() {\n\t\treturn () => <span mix={[hidden(), dialogDismiss()]} />;\n\t},\n);\n"
11
11
  },
12
12
  "test": null
13
13
  }
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "field-parts",
3
+ "changedIn": "2026.11.29",
4
+ "dependencies": [
5
+ "description",
6
+ "field-error",
7
+ "form",
8
+ "group",
9
+ "label"
10
+ ],
11
+ "exports": [
12
+ "FieldScope",
13
+ "FieldLabel",
14
+ "FieldDescription",
15
+ "FieldErrorMessage",
16
+ "FieldPrefix",
17
+ "FieldSuffix",
18
+ "FieldWiringInput",
19
+ "WiredField",
20
+ "wireField"
21
+ ],
22
+ "source": {
23
+ "path": "field-parts.tsx",
24
+ "content": "/**\n * The parts every labeled form field composes: its caption, supporting copy, validation\n * message and leading or trailing addons, plus the scope that hands them the ids their\n * field generated. `TextField`, `DateField`, `TimeField` and `ColorField` attach these as\n * their `.Label`, `.Description`, `.Error`, `.Prefix` and `.Suffix` statics.\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 { mergeMix } from \"@sdxc/u/general\";\nimport { Fragment } from \"remix/component\";\n\nimport type { AriaInvalid, FieldColor } from \"@sdxc/ui/utils\";\n\nimport { fieldStackLayout } from \"@sdxc/ui/styles\";\nimport { resolveFieldWiring } from \"@sdxc/ui/utils\";\n\nimport { Description } from \"@sdxc/ui/description\";\nimport { FieldError } from \"@sdxc/ui/field-error\";\nimport { resolveFieldIssue } from \"@sdxc/ui/form\";\nimport { Group } from \"@sdxc/ui/group\";\nimport { Label } from \"@sdxc/ui/label\";\n\n/** The `data-slot` prefix a field part falls back to when it renders outside a field. */\nconst DEFAULT_SLOT = \"field\";\n\n/**\n * Prop and context types for {@link FieldScope} and the shared field parts.\n */\nexport namespace FieldScope {\n\t/**\n\t * What a field resolves once for every part: the ids tying a caption, a description,\n\t * an error and the addons to the control, and the validation message to show.\n\t */\n\texport interface Context {\n\t\t/** The field's own `data-slot`, prefixed onto each part's `data-slot`. */\n\t\tslot: string;\n\t\t/** The control's `id`, which the caption and the addons point `for` at. */\n\t\tcontrolId?: string;\n\t\t/** The caption's `id`, set only when an addon joins the control so the control names itself by it. */\n\t\tlabelId?: string;\n\t\tdescriptionId?: string;\n\t\terrorId?: string;\n\t\tprefixId?: string;\n\t\tsuffixId?: string;\n\t\t/** The message `.Error` shows when written empty: the caller's own, or the enclosing `Form`'s issue for the field's `name`. */\n\t\tmessage?: RemixNode;\n\t}\n\n\t/** Every native `<div>` attribute plus the context the field resolved for its parts. */\n\texport interface Props extends TagProps<\"div\"> {\n\t\t/** What the parts read; without it they draw unwired, under the default `field` slot. */\n\t\tcontext?: Context;\n\t}\n\n\t/** Every native `<label>` attribute; `for` points at the field's control unless set. */\n\texport interface LabelProps extends TagProps<\"label\"> {}\n\n\t/** Every native `<p>` attribute; the field's control references it through `aria-describedby`. */\n\texport interface DescriptionProps extends TagProps<\"p\"> {}\n\n\t/**\n\t * Every native `<span>` attribute. `children` is the message; left empty, the part shows\n\t * the enclosing `Form`'s issue for the field's `name`, and renders nothing without one.\n\t */\n\texport interface ErrorProps extends TagProps<\"span\"> {}\n\n\t/** Every native `<label>` attribute; `children` is the static text joined to the control. */\n\texport interface AddonProps 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 * The stacked host of a labeled field. It publishes the ids and message its field resolved,\n * so each part wires itself to the control wherever the caller writes it.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props and the resolved context.\n * @returns The render function producing the field's host.\n */\nexport function FieldScope(handle: Handle<FieldScope.Props, FieldScope.Context>) {\n\treturn () => {\n\t\tlet { context = { slot: DEFAULT_SLOT }, mix, ...rest } = handle.props;\n\t\thandle.context.set(context);\n\n\t\treturn <div data-slot={context.slot} {...rest} mix={mergeMix(fieldStackLayout(), mix)} />;\n\t};\n}\n\n/**\n * Reads the nearest field's context, falling back to an unwired one so a part rendered on\n * its own still draws.\n *\n * @param handle The part's runtime handle.\n * @returns The field's context, or one carrying only the default slot.\n */\nfunction readFieldContext(handle: Handle<unknown, any>): FieldScope.Context {\n\treturn (\n\t\t(handle.context.get(FieldScope) as FieldScope.Context | undefined) ?? { slot: DEFAULT_SLOT }\n\t);\n}\n\n/**\n * The field's caption, pointing `for` at the control so a click focuses it and assistive\n * technology announces it as the control's name.\n *\n * @param handle Runtime handle carrying the host `<label>`'s props.\n * @returns The render function producing the caption's markup.\n * @example\n * <TextField.Label>{t(\"form.email.label\")}</TextField.Label>\n */\nexport function FieldLabel(handle: Handle<FieldScope.LabelProps>) {\n\treturn () => {\n\t\tlet context = readFieldContext(handle);\n\n\t\treturn (\n\t\t\t<Label\n\t\t\t\tdata-slot={`${context.slot}-label`}\n\t\t\t\tid={context.labelId}\n\t\t\t\thtmlFor={context.controlId}\n\t\t\t\t{...handle.props}\n\t\t\t\tdata-field-part=\"label\"\n\t\t\t/>\n\t\t);\n\t};\n}\n\n/**\n * Supporting copy for the field, referenced by the control's `aria-describedby` so it is\n * read after the control's name. Written empty, it renders nothing and describes nothing.\n *\n * @param handle Runtime handle carrying the host `<p>`'s props.\n * @returns The render function producing the description's markup, or nothing.\n * @example\n * <TextField.Description>{t(\"form.password.hint\")}</TextField.Description>\n */\nexport function FieldDescription(handle: Handle<FieldScope.DescriptionProps>) {\n\treturn () => {\n\t\tlet context = readFieldContext(handle);\n\t\tif (!hasContent(handle.props.children)) return null;\n\n\t\treturn (\n\t\t\t<Description\n\t\t\t\tdata-slot={`${context.slot}-description`}\n\t\t\t\tid={context.descriptionId}\n\t\t\t\t{...handle.props}\n\t\t\t\tdata-field-part=\"description\"\n\t\t\t/>\n\t\t);\n\t};\n}\n\n/**\n * The field's validation message. Its presence marks the control `aria-invalid` and adds it\n * to the control's `aria-describedby`; written empty, it shows the enclosing `Form`'s issue\n * for the field's `name`, and renders nothing when there is none.\n *\n * @param handle Runtime handle carrying the host `<span>`'s props.\n * @returns The render function producing the message's markup, or nothing.\n * @example\n * <TextField.Error>{t(\"form.username.tooShort\")}</TextField.Error>\n */\nexport function FieldErrorMessage(handle: Handle<FieldScope.ErrorProps>) {\n\treturn () => {\n\t\tlet { children, ...rest } = handle.props;\n\t\tlet context = readFieldContext(handle);\n\t\tlet message = hasContent(children) ? children : context.message;\n\t\tif (!hasContent(message)) return null;\n\n\t\treturn (\n\t\t\t<FieldError\n\t\t\t\tdata-slot={`${context.slot}-error`}\n\t\t\t\tid={context.errorId}\n\t\t\t\t{...rest}\n\t\t\t\tdata-field-part=\"error\"\n\t\t\t>\n\t\t\t\t{message}\n\t\t\t</FieldError>\n\t\t);\n\t};\n}\n\n/**\n * Static text joined to the control's leading edge as one field, such as a currency or a\n * domain. It describes the control, stays out of its name, and focuses it when clicked;\n * written empty, it renders nothing and leaves the control unjoined.\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 * <TextField.Prefix>pulse.dev/</TextField.Prefix>\n */\nexport function FieldPrefix(handle: Handle<FieldScope.AddonProps>) {\n\treturn () => {\n\t\tlet context = readFieldContext(handle);\n\t\tif (!hasContent(handle.props.children)) return null;\n\n\t\treturn (\n\t\t\t<Group.Text\n\t\t\t\tid={context.prefixId}\n\t\t\t\thtmlFor={context.controlId}\n\t\t\t\t{...handle.props}\n\t\t\t\tdata-field-part=\"prefix\"\n\t\t\t/>\n\t\t);\n\t};\n}\n\n/**\n * Static text joined to the control's trailing edge as one field, such as a unit or a\n * domain suffix. It describes the control and focuses it when clicked; written empty, it\n * renders nothing and leaves the control unjoined.\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 * <TextField.Suffix>ms</TextField.Suffix>\n */\nexport function FieldSuffix(handle: Handle<FieldScope.AddonProps>) {\n\treturn () => {\n\t\tlet context = readFieldContext(handle);\n\t\tif (!hasContent(handle.props.children)) return null;\n\n\t\treturn (\n\t\t\t<Group.Text\n\t\t\t\tid={context.suffixId}\n\t\t\t\thtmlFor={context.controlId}\n\t\t\t\t{...handle.props}\n\t\t\t\tdata-field-part=\"suffix\"\n\t\t\t/>\n\t\t);\n\t};\n}\n\n/** What a field reads from its own props to wire its parts to its control. */\nexport interface FieldWiringInput {\n\t/** The field's `data-slot`. */\n\tslot: string;\n\t/** The parts the caller wrote. */\n\tchildren: RemixNode;\n\t/** The control's `name`, which finds the enclosing `Form`'s issue for it. */\n\tname?: string;\n\tcolor?: FieldColor;\n\tautoFocus?: boolean;\n\tariaInvalid?: AriaInvalid;\n}\n\n/** The control attributes and part layout a field derives from {@link wireField}. */\nexport interface WiredField {\n\t/** The context the field's {@link FieldScope} publishes. */\n\tcontext: FieldScope.Context;\n\t/** The id, color, focus and aria attributes the control carries. */\n\tcontrol: {\n\t\tid: string;\n\t\tcolor: FieldColor;\n\t\tautoFocus: boolean | undefined;\n\t\t\"aria-invalid\": \"true\" | \"grammar\" | \"spelling\" | undefined;\n\t\t\"aria-labelledby\": string | undefined;\n\t\t\"aria-describedby\": string | undefined;\n\t};\n\t/**\n\t * Lays the caller's parts out around the control: the control follows the caption, the\n\t * addons join it in a group, every other part keeps the caller's order, and a `Form` issue\n\t * with no `.Error` written gets one at the end.\n\t */\n\tarrange(control: RemixNode): RemixNode[];\n}\n\n/**\n * Resolves a field's wiring from the parts it was given: which ids exist, which message\n * shows, whether the control is invalid and focused, and where each part renders.\n *\n * @param handle The field's runtime handle, whose `id` names the control.\n * @param input The field's slot, parts, name, color, focus and invalid override.\n * @returns The context for the parts, the control's attributes, and the layout.\n */\nexport function wireField(handle: Handle<unknown, any>, input: FieldWiringInput): WiredField {\n\tlet nodes = flattenParts(input.children);\n\tlet errorPart = nodes.find((node) => isElementOf(node, FieldErrorMessage));\n\tlet explicitError = errorPart ? (errorPart.props.children as RemixNode) : undefined;\n\tlet { errorMessage, isFirstInvalid } = resolveFieldIssue(\n\t\thandle,\n\t\tinput.name,\n\t\thasContent(explicitError) ? explicitError : undefined,\n\t);\n\tlet hasDescription = nodes.some((node) => isFilledPart(node, FieldDescription));\n\tlet prefixes = nodes.filter((node) => isFilledPart(node, FieldPrefix));\n\tlet suffixes = nodes.filter((node) => isFilledPart(node, FieldSuffix));\n\tlet { resolvedColor, resolvedInvalid, descriptionId, errorId, describedBy } = resolveFieldWiring(\n\t\thandle.id,\n\t\t{\n\t\t\tcolor: input.color,\n\t\t\terrorMessage,\n\t\t\tdescription: hasDescription,\n\t\t\tariaInvalid: input.ariaInvalid,\n\t\t},\n\t);\n\tlet hasAddon = prefixes.length > 0 || suffixes.length > 0;\n\tlet labelId = hasAddon ? `${handle.id}-label` : undefined;\n\tlet prefixId = prefixes.length > 0 ? `${handle.id}-prefix` : undefined;\n\tlet suffixId = suffixes.length > 0 ? `${handle.id}-suffix` : undefined;\n\n\treturn {\n\t\tcontext: {\n\t\t\tslot: input.slot,\n\t\t\tcontrolId: handle.id,\n\t\t\tlabelId,\n\t\t\tdescriptionId,\n\t\t\terrorId,\n\t\t\tprefixId,\n\t\t\tsuffixId,\n\t\t\tmessage: errorMessage,\n\t\t},\n\t\tcontrol: {\n\t\t\tid: handle.id,\n\t\t\tcolor: resolvedColor,\n\t\t\tautoFocus: input.autoFocus ?? (isFirstInvalid || undefined),\n\t\t\t\"aria-invalid\": resolvedInvalid,\n\t\t\t\"aria-labelledby\": labelId,\n\t\t\t\"aria-describedby\": [prefixId, suffixId, describedBy].filter(Boolean).join(\" \") || undefined,\n\t\t},\n\t\tarrange(control) {\n\t\t\tlet joined = hasAddon ? (\n\t\t\t\t<Group role=\"presentation\">\n\t\t\t\t\t{prefixes}\n\t\t\t\t\t{control}\n\t\t\t\t\t{suffixes}\n\t\t\t\t</Group>\n\t\t\t) : (\n\t\t\t\tcontrol\n\t\t\t);\n\t\t\tlet lastLabel = nodes.reduce<number>(\n\t\t\t\t(found, node, index) => (isElementOf(node, FieldLabel) ? index : found),\n\t\t\t\t-1,\n\t\t\t);\n\t\t\tlet arranged: RemixNode[] = lastLabel === -1 ? [joined] : [];\n\t\t\tnodes.forEach((node, index) => {\n\t\t\t\tif (isElementOf(node, FieldPrefix) || isElementOf(node, FieldSuffix)) return;\n\t\t\t\tarranged.push(node);\n\t\t\t\tif (index === lastLabel) arranged.push(joined);\n\t\t\t});\n\t\t\tif (!errorPart && hasContent(errorMessage)) arranged.push(<FieldErrorMessage />);\n\t\t\treturn arranged;\n\t\t},\n\t};\n}\n\n/**\n * Whether a rendered node is an element of the given component.\n *\n * @param node Any child the caller wrote.\n * @param type The component to match.\n * @returns `true` when `node` is an element whose type is `type`.\n */\nfunction isElementOf(node: unknown, type: unknown): node is { props: Record<string, unknown> } {\n\treturn (\n\t\ttypeof node === \"object\" &&\n\t\tnode !== null &&\n\t\t\"$rmx\" in node &&\n\t\t\"type\" in node &&\n\t\tnode.type === type\n\t);\n}\n\n/**\n * Whether a node is an element of the given part with something to render, so a part\n * written around an empty value wires no id and joins nothing.\n *\n * @param node Any child the caller wrote.\n * @param type The part to match.\n * @returns `true` when `node` is that part and its children draw something.\n */\nfunction isFilledPart(node: unknown, type: unknown): boolean {\n\treturn isElementOf(node, type) && hasContent(node.props.children);\n}\n\n/**\n * The caller's parts as one flat list, through arrays and fragments, so a part written\n * inside `<>…</>` or a mapped list is found and laid out like a direct child.\n *\n * @param node The field's `children`.\n * @returns Every child in document order.\n */\nfunction flattenParts(node: RemixNode): RemixNode[] {\n\tif (Array.isArray(node)) return node.flatMap((child: RemixNode) => flattenParts(child));\n\tif (isElementOf(node, Fragment)) return flattenParts(node.props.children as RemixNode);\n\treturn [node];\n}\n\n/**\n * Whether a node renders anything: `null`, `undefined`, booleans, the empty string and\n * arrays of those render nothing.\n *\n * @param node A message or a part's children.\n * @returns `true` when the node draws something.\n */\nfunction hasContent(node: unknown): boolean {\n\tif (Array.isArray(node)) return node.some((child) => hasContent(child));\n\treturn node !== null && node !== undefined && typeof node !== \"boolean\" && node !== \"\";\n}\n"
25
+ },
26
+ "test": {
27
+ "path": "field-parts.browser.test.tsx",
28
+ "content": "/**\n * Checks the parts every labeled field composes in a real browser: each part wires itself\n * to the control through the ids its field generates, the field lays out whichever parts it\n * is given with no empty element for a missing one, and a part renders alone.\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\";\n\nimport { DateField } from \"@sdxc/ui/date-field\";\nimport { DateRangePicker } from \"@sdxc/ui/date-range-picker\";\nimport { Form } from \"@sdxc/ui/form\";\nimport { TextField } from \"@sdxc/ui/text-field\";\nimport { TimeField } from \"@sdxc/ui/time-field\";\n\nimport \"@sdxc/ui/reset.css\";\nimport \"@sdxc/ui/theme.css\";\n\nlet mounted: RenderResult | undefined;\n\nafterEach(() => {\n\tmounted?.cleanup();\n\tmounted = undefined;\n\tdocument.body.replaceChildren();\n});\n\n/** Mounts `node` in a fresh host and returns the host. */\nfunction mount(node: JSX.Element): HTMLElement {\n\tlet host = document.createElement(\"div\");\n\tdocument.body.appendChild(host);\n\tmounted = render(node, { container: host });\n\treturn host;\n}\n\n/** The `data-field-part` markers of the host's field, in document order. */\nfunction order(host: HTMLElement): string[] {\n\treturn [...host.querySelectorAll<HTMLElement>(\"[data-field-part], input\")].map(\n\t\t(element) => element.dataset.fieldPart ?? \"control\",\n\t);\n}\n\ndescribe(\"TextField parts\", () => {\n\ttest(\"ties the label, description and error to the control\", () => {\n\t\tlet host = mount(\n\t\t\t<TextField name=\"username\">\n\t\t\t\t<TextField.Label>Username</TextField.Label>\n\t\t\t\t<TextField.Description>3 to 20 characters.</TextField.Description>\n\t\t\t\t<TextField.Error>Too short.</TextField.Error>\n\t\t\t</TextField>,\n\t\t);\n\t\tlet input = host.querySelector(\"input\")!;\n\t\tlet label = host.querySelector(\"label\")!;\n\t\tlet description = host.querySelector('[data-slot=\"text-field-description\"]')!;\n\t\tlet error = host.querySelector('[data-slot=\"text-field-error\"]')!;\n\n\t\texpect(label.htmlFor).toBe(input.id);\n\t\texpect(input.labels?.[0]?.textContent).toBe(\"Username\");\n\t\texpect(input.getAttribute(\"aria-describedby\")).toBe(`${description.id} ${error.id}`);\n\t\texpect(input.getAttribute(\"aria-invalid\")).toBe(\"true\");\n\t\texpect(order(host)).toEqual([\"label\", \"control\", \"description\", \"error\"]);\n\t});\n\n\ttest(\"keeps the caller's order for the parts after the control\", () => {\n\t\tlet host = mount(\n\t\t\t<TextField name=\"username\">\n\t\t\t\t<TextField.Error>Too short.</TextField.Error>\n\t\t\t\t<TextField.Label>Username</TextField.Label>\n\t\t\t\t<TextField.Description>3 to 20 characters.</TextField.Description>\n\t\t\t</TextField>,\n\t\t);\n\n\t\texpect(order(host)).toEqual([\"error\", \"label\", \"control\", \"description\"]);\n\t});\n\n\ttest(\"renders only the control and the parts it is given\", () => {\n\t\tlet host = mount(\n\t\t\t<TextField name=\"username\" aria-label=\"Username\">\n\t\t\t\t{null}\n\t\t\t</TextField>,\n\t\t);\n\t\tlet field = host.querySelector('[data-slot=\"text-field\"]')!;\n\t\tlet input = host.querySelector(\"input\")!;\n\n\t\texpect(field.children).toHaveLength(1);\n\t\texpect(input.hasAttribute(\"aria-describedby\")).toBe(false);\n\t\texpect(input.hasAttribute(\"aria-invalid\")).toBe(false);\n\t});\n\n\ttest(\"finds parts written in a fragment\", () => {\n\t\tlet host = mount(\n\t\t\t<TextField name=\"username\">\n\t\t\t\t<>\n\t\t\t\t\t<TextField.Label>Username</TextField.Label>\n\t\t\t\t\t<TextField.Description>Shown on your profile.</TextField.Description>\n\t\t\t\t</>\n\t\t\t</TextField>,\n\t\t);\n\t\tlet input = host.querySelector(\"input\")!;\n\n\t\texpect(input.getAttribute(\"aria-describedby\")).toBe(\n\t\t\thost.querySelector('[data-field-part=\"description\"]')!.id,\n\t\t);\n\t});\n\n\ttest(\"shows the Form's issue for its name with no Error written\", () => {\n\t\tlet host = mount(\n\t\t\t<Form method=\"post\" issues={[{ message: \"Enter a valid email\", path: [\"email\"] }]}>\n\t\t\t\t<TextField name=\"email\">\n\t\t\t\t\t<TextField.Label>Email</TextField.Label>\n\t\t\t\t</TextField>\n\t\t\t</Form>,\n\t\t);\n\t\tlet input = host.querySelector(\"input\")!;\n\t\tlet error = host.querySelector('[data-field-part=\"error\"]')!;\n\n\t\texpect(error.textContent).toBe(\"Enter a valid email\");\n\t\texpect(input.getAttribute(\"aria-describedby\")).toBe(error.id);\n\t\texpect(input.getAttribute(\"aria-invalid\")).toBe(\"true\");\n\t});\n\n\ttest(\"places the Form's issue where an empty Error is written\", () => {\n\t\tlet host = mount(\n\t\t\t<Form method=\"post\" issues={[{ message: \"Enter a valid email\", path: [\"email\"] }]}>\n\t\t\t\t<TextField name=\"email\">\n\t\t\t\t\t<TextField.Error />\n\t\t\t\t\t<TextField.Label>Email</TextField.Label>\n\t\t\t\t</TextField>\n\t\t\t</Form>,\n\t\t);\n\n\t\texpect(order(host)).toEqual([\"error\", \"label\", \"control\"]);\n\t\texpect(host.querySelector('[data-field-part=\"error\"]')!.textContent).toBe(\n\t\t\t\"Enter a valid email\",\n\t\t);\n\t});\n\n\ttest(\"renders an empty Error as nothing outside a Form\", () => {\n\t\tlet host = mount(\n\t\t\t<TextField name=\"email\">\n\t\t\t\t<TextField.Label>Email</TextField.Label>\n\t\t\t\t<TextField.Error>{undefined}</TextField.Error>\n\t\t\t</TextField>,\n\t\t);\n\n\t\texpect(host.querySelector('[data-field-part=\"error\"]')).toBeNull();\n\t\texpect(host.querySelector(\"input\")!.hasAttribute(\"aria-invalid\")).toBe(false);\n\t});\n\n\ttest(\"renders an empty Description or Prefix as nothing, wiring no id\", () => {\n\t\tlet host = mount(\n\t\t\t<TextField name=\"email\">\n\t\t\t\t<TextField.Label>Email</TextField.Label>\n\t\t\t\t<TextField.Prefix>{undefined}</TextField.Prefix>\n\t\t\t\t<TextField.Description>{undefined}</TextField.Description>\n\t\t\t</TextField>,\n\t\t);\n\t\tlet input = host.querySelector(\"input\")!;\n\n\t\texpect(order(host)).toEqual([\"label\", \"control\"]);\n\t\texpect(input.parentElement!.dataset.slot).toBe(\"text-field\");\n\t\texpect(input.hasAttribute(\"aria-describedby\")).toBe(false);\n\t\texpect(input.hasAttribute(\"aria-labelledby\")).toBe(false);\n\t});\n\n\ttest(\"draws a part alone with no field around it\", () => {\n\t\tlet host = mount(\n\t\t\t<div>\n\t\t\t\t<TextField.Label>Alone</TextField.Label>\n\t\t\t\t<TextField.Description>Still styled.</TextField.Description>\n\t\t\t</div>,\n\t\t);\n\n\t\texpect(host.querySelector('[data-slot=\"field-label\"]')!.textContent).toBe(\"Alone\");\n\t\texpect(host.querySelector('[data-slot=\"field-description\"]')!.textContent).toBe(\n\t\t\t\"Still styled.\",\n\t\t);\n\t});\n});\n\ndescribe(\"the other fields share the parts\", () => {\n\ttest(\"DateField and TimeField wire their label and description\", () => {\n\t\tlet host = mount(\n\t\t\t<div>\n\t\t\t\t<DateField name=\"day\">\n\t\t\t\t\t<DateField.Label>Day</DateField.Label>\n\t\t\t\t\t<DateField.Description>Any weekday.</DateField.Description>\n\t\t\t\t</DateField>\n\t\t\t\t<TimeField name=\"time\">\n\t\t\t\t\t<TimeField.Label>Time</TimeField.Label>\n\t\t\t\t\t<TimeField.Description>In your time zone.</TimeField.Description>\n\t\t\t\t</TimeField>\n\t\t\t</div>,\n\t\t);\n\n\t\tfor (let input of host.querySelectorAll(\"input\")) {\n\t\t\tlet field = input.closest(\"[data-field-part], [data-slot$='-field']\")!;\n\t\t\tlet description = field.querySelector('[data-field-part=\"description\"]')!;\n\t\t\texpect(input.labels?.length).toBe(1);\n\t\t\texpect(input.getAttribute(\"aria-describedby\")).toBe(description.id);\n\t\t}\n\t});\n});\n\ndescribe(\"DateRangePicker\", () => {\n\ttest(\"lays two fields side by side as one group in the split layout\", () => {\n\t\tlet host = mount(\n\t\t\t<DateRangePicker layout=\"split\">\n\t\t\t\t<DateField name=\"checkIn\">\n\t\t\t\t\t<DateField.Label>Check in</DateField.Label>\n\t\t\t\t</DateField>\n\t\t\t\t<DateField name=\"checkOut\">\n\t\t\t\t\t<DateField.Label>Check out</DateField.Label>\n\t\t\t\t</DateField>\n\t\t\t</DateRangePicker>,\n\t\t);\n\t\tlet root = host.querySelector<HTMLElement>('[data-slot=\"date-range-picker\"]')!;\n\t\tlet [start, end] = root.querySelectorAll<HTMLElement>('[data-slot=\"date-field\"]');\n\n\t\texpect(root.getAttribute(\"role\")).toBe(\"group\");\n\t\texpect(start!.getBoundingClientRect().top).toBe(end!.getBoundingClientRect().top);\n\t\texpect(start!.getBoundingClientRect().right).toBeLessThan(end!.getBoundingClientRect().left);\n\t});\n});\n"
29
+ }
30
+ }