@bettercms-ai/kit 3.1.6 → 3.1.8

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 (43) hide show
  1. package/dist/controls/button.js +11 -4
  2. package/dist/controls/button.js.map +1 -1
  3. package/dist/controls/choice.js +2 -2
  4. package/dist/controls/choice.js.map +1 -1
  5. package/dist/controls/code.js +1 -1
  6. package/dist/controls/code.js.map +1 -1
  7. package/dist/controls/color.js +1 -1
  8. package/dist/controls/color.js.map +1 -1
  9. package/dist/controls/icon.js +1 -1
  10. package/dist/controls/icon.js.map +1 -1
  11. package/dist/controls/location.js +1 -1
  12. package/dist/controls/location.js.map +1 -1
  13. package/dist/controls/number.js +4 -4
  14. package/dist/controls/number.js.map +1 -1
  15. package/dist/controls/reference.js +3 -3
  16. package/dist/controls/reference.js.map +1 -1
  17. package/dist/controls/rich-text/editor.d.ts +0 -2
  18. package/dist/controls/rich-text/editor.js +4 -11
  19. package/dist/controls/rich-text/editor.js.map +1 -1
  20. package/dist/controls/rich-text/ops.js +4 -0
  21. package/dist/controls/rich-text/ops.js.map +1 -1
  22. package/dist/controls/table/table-editor.js +1 -1
  23. package/dist/controls/table/table-editor.js.map +1 -1
  24. package/dist/engine/array.d.ts +11 -0
  25. package/dist/engine/array.js +24 -4
  26. package/dist/engine/array.js.map +1 -1
  27. package/dist/index.js +2 -2
  28. package/dist/lib/validate.d.ts +2 -0
  29. package/dist/lib/validate.js +4 -2
  30. package/dist/lib/validate.js.map +1 -1
  31. package/dist/library/entries/advanced.entries.js +4 -0
  32. package/dist/library/entries/advanced.entries.js.map +1 -1
  33. package/dist/library/entries/conversion.entries.js +6 -1
  34. package/dist/library/entries/conversion.entries.js.map +1 -1
  35. package/dist/library/entries/features.entries.js +2 -1
  36. package/dist/library/entries/features.entries.js.map +1 -1
  37. package/dist/library/kit-catalog.json +3 -3
  38. package/dist/styles.css +1 -1
  39. package/dist/theme.css +0 -3
  40. package/dist/tokens.css +6 -12
  41. package/dist/ui/controls.js +9 -9
  42. package/dist/ui/controls.js.map +1 -1
  43. package/package.json +2 -2
@@ -252,6 +252,7 @@ function ButtonScreen({ value, onChange, readOnly, title = "Button" }) {
252
252
  const set = (p) => onChange(nextButton(value, p));
253
253
  const [iconOpen, setIconOpen] = React.useState(false);
254
254
  const labelId = React.useId();
255
+ const noLabel = !readOnly && !(v.label ?? "").trim();
255
256
  const arrowId = React.useId();
256
257
  const fullId = React.useId();
257
258
  return /* @__PURE__ */ jsxs("fieldset", {
@@ -263,15 +264,21 @@ function ButtonScreen({ value, onChange, readOnly, title = "Button" }) {
263
264
  className: "flex min-h-20 items-center justify-center rounded-kit-lg bg-kit-preview-paper px-4 py-5 [filter:var(--kit-paper-filter)]",
264
265
  children: /* @__PURE__ */ jsx(ButtonPreview, { v })
265
266
  }),
266
- /* @__PURE__ */ jsx(Row, {
267
+ /* @__PURE__ */ jsxs(Row, {
267
268
  label: "Label",
268
269
  htmlFor: labelId,
269
- children: /* @__PURE__ */ jsx(Input, {
270
+ children: [/* @__PURE__ */ jsx(Input, {
270
271
  id: labelId,
271
272
  value: v.label ?? "",
272
273
  onChange: (e) => set({ label: e.target.value }),
273
- placeholder: "Shop now"
274
- })
274
+ placeholder: "Shop now",
275
+ "aria-invalid": noLabel || void 0,
276
+ "aria-describedby": noLabel ? `${labelId}-msg` : void 0
277
+ }), noLabel ? /* @__PURE__ */ jsx("p", {
278
+ id: `${labelId}-msg`,
279
+ className: "text-kit-xs text-kit-danger-fg",
280
+ children: "Add a label. Without one the button shows no text on the page."
281
+ }) : null]
275
282
  }),
276
283
  /* @__PURE__ */ jsxs("div", {
277
284
  className: "flex flex-col gap-1.5",
@@ -1 +1 @@
1
- {"version":3,"file":"button.js","names":[],"sources":["../../src/controls/button.tsx"],"sourcesContent":["/**\n * BUTTON — label + link + look as ONE unit (V2 HEAD kit/controls/link.tsx \"Button\", DESIGN §8.8, CPO D43 · D45 · D46).\n *\n * - <ButtonControl> at rest: one FieldUnit, two rows. The label row drills into the button screen (form.navigate → the\n * \"button\" frame); the link row edits the link in place (LinkQuickEdit).\n * - <ButtonScreen> the one button screen (the frame body): preview · label · link (LinkForm) · appearance (style grid,\n * size, leading icon, arrow).\n * - <ButtonStyleGrid>, <ButtonPreview>, <StyleGlyph> — the pieces both draw.\n *\n * Stored shape (prod `button`, adapters/values.ts buttonToProd / buttonFromProd; backend buttonValueProblem). The kit\n * value is the flattened V2 button the adapter hands in. What this control writes keeps that value's keys:\n * - the look goes in the key the value already uses — `style` when it has one, else `variant` (what prod renderers\n * read) — and never both (buttonToProd names an equal pair as lost, so the dock would refuse the write);\n * - `rel: \"follow\"` is never written (prod's rel list is nofollow · sponsored · ugc) and `newTab: false`/`target` only\n * where the stored value had that key (storedLink);\n * - `icon` is a dock icon name (DOCK_ICON_NAMES): the picker offers only icons that are dock names.\n *\n * \"Full width\" writes `fullWidth: true`, and off writes `false` only where the stored value had the key (as Show arrow);\n * every renderer draws it (hosted `bcms-btn-full`, the SDKs' and in-place publishing's `data-full-width`).\n *\n * Deviation from V2, because prod has nothing behind it: an unset look reads \"Default\" (V2 drew Primary, and guessed\n * Outline for a field named \"secondary\"). The preview is V2's: the site palette (--kit-preview-paper / -ink / -primary /\n * -primary-on / -contrast / -contrast-on / -outline, which a host may set to the project's colours) on the paper, and the\n * chrome swatches in the style grid.\n */\nimport * as React from \"react\";\nimport { IconArrowRight, IconChevronDown, IconChevronRight, IconSearch, IconX } from \"@tabler/icons-react\";\nimport { cn } from \"../lib/cn\";\nimport { isObj } from \"../lib/path\";\nimport { KIT_ICONS, KitIcon, iconLabel } from \"../lib/icons\";\nimport { BUTTON_VARIANTS, DOCK_ICON_NAME_SET } from \"../adapters/prod-types\";\nimport { useForm, useKitEnv } from \"../context\";\nimport { FieldUnit } from \"../engine/grouping\";\nimport { Input } from \"../ui/input\";\nimport { Segmented, Switch } from \"../ui/controls\";\nimport { Popover, PopoverAnchor, PopoverContent, PopoverTrigger } from \"../ui/overlay\";\nimport type { ControlProps } from \"../types\";\nimport { LinkForm, LinkLine, LinkQuickEdit, TARGET_KEYS, finalizeLink, findTarget, hasLink, linkText, normLink, storedLink, useLinkTargets, type ButtonStyle, type LinkValue } from \"./link\";\n\nexport const STYLE_ITEMS: { value: ButtonStyle; label: string }[] = [\n { value: \"primary\", label: \"Primary\" },\n { value: \"secondary\", label: \"Secondary\" },\n { value: \"outline\", label: \"Outline\" },\n { value: \"link\", label: \"Text link\" },\n];\nconst SIZE_LABEL = { sm: \"Small\", md: \"Medium\", lg: \"Large\" } as const;\nconst isVariant = (x: unknown): x is string => typeof x === \"string\" && (BUTTON_VARIANTS as readonly string[]).includes(x);\n\n/** The look prod renders: the first valid of variant, style (buttonToProd's rule). */\nexport function lookOf(v: Pick<LinkValue, \"variant\" | \"style\">): string | undefined {\n return [v.variant, v.style].find(isVariant);\n}\n/** \"Brand\" for a stored look outside the four styles; undefined when unset. */\nexport function lookLabel(look: string | undefined): string {\n if (!look) return \"Default\";\n return STYLE_ITEMS.find((s) => s.value === look)?.label ?? look.charAt(0).toUpperCase() + look.slice(1);\n}\n\n/**\n * The next stored button: `raw` (the value as the field holds it) with `patch` applied, keyed like `raw`. A look in the\n * patch (`style`) lands in the key `raw` uses for it.\n */\nexport function nextButton(raw: unknown, patch: Partial<LinkValue>): LinkValue {\n const base: LinkValue = isObj(raw) ? ({ ...(raw as object) } as LinkValue) : { href: \"\" };\n const { style, ...rest } = patch;\n const out: LinkValue = { ...base, ...rest };\n // prod requires both strings (buttonToProd names a missing one as lost, and the dock refuses the write)\n if (typeof out.href !== \"string\") out.href = \"\";\n if (typeof out.label !== \"string\") out.label = \"\";\n if (style !== undefined) {\n const key = isObj(raw) && raw.style !== undefined ? \"style\" : \"variant\";\n delete out.style;\n delete out.variant;\n out[key] = style;\n }\n return storedLink(out, raw);\n}\n\n/** The icons a button can carry: the kit's drawn icons that are also dock names (the backend checks the name). */\nexport const BUTTON_ICONS: string[] = Object.keys(KIT_ICONS).filter((n) => DOCK_ICON_NAME_SET.has(n));\n\n/** D46: four styles never sit in a row of tabs. The option IS the visual, so it is a 2×2 grid of live previews (one\n * radiogroup: Tab enters on the checked style, arrows move and pick). A stored look outside the four is listed too. */\nexport function ButtonStyleGrid({\n v,\n onPick,\n \"aria-label\": ariaLabel,\n size = \"md\",\n}: {\n v: LinkValue;\n onPick: (s: ButtonStyle) => void;\n \"aria-label\": string;\n size?: \"sm\" | \"md\";\n}) {\n const cur = lookOf(v);\n const items: { value: string; label: string }[] = cur && !STYLE_ITEMS.some((s) => s.value === cur) ? [...STYLE_ITEMS, { value: cur, label: lookLabel(cur) }] : STYLE_ITEMS;\n const onKey = (e: React.KeyboardEvent, i: number) => {\n const d = e.key === \"ArrowRight\" || e.key === \"ArrowDown\" ? 1 : e.key === \"ArrowLeft\" || e.key === \"ArrowUp\" ? -1 : 0;\n if (!d) return;\n e.preventDefault();\n const next = items[(i + d + items.length) % items.length];\n onPick(next.value as ButtonStyle);\n const group = (e.currentTarget as HTMLElement).parentElement;\n requestAnimationFrame(() => group?.querySelector<HTMLElement>(`[data-style=\"${next.value}\"]`)?.focus());\n };\n return (\n <div className=\"grid grid-cols-2 gap-1.5\" role=\"radiogroup\" aria-label={ariaLabel}>\n {items.map((s, i) => {\n const on = cur === s.value;\n return (\n <button\n key={s.value}\n type=\"button\"\n role=\"radio\"\n data-style={s.value}\n aria-checked={on}\n tabIndex={on || (!items.some((x) => x.value === cur) && i === 0) ? 0 : -1}\n onKeyDown={(e) => onKey(e, i)}\n onClick={() => onPick(s.value as ButtonStyle)}\n className={cn(\n \"flex min-w-0 items-center gap-2 rounded-kit-md border px-2 transition-colors\",\n size === \"sm\" ? \"h-8 text-kit-xs\" : \"h-9 text-kit-sm\",\n on ? \"border-[var(--kit-emphasis-line)] bg-kit-selected text-kit-fg\" : \"border-kit-line text-kit-fg-2 hover:border-kit-line-strong hover:text-kit-fg\",\n )}\n >\n <ButtonPreview v={{ ...v, style: s.value as ButtonStyle, variant: undefined, label: \"Aa\", icon: undefined, arrow: false }} small chrome />\n <span className=\"truncate\">{s.label}</span>\n </button>\n );\n })}\n </div>\n );\n}\n\n/**\n * The site's button as the site draws it (V2 link.tsx ButtonPreview: the site palette, not app tokens). On the preview\n * paper it keeps the site's own colours in both themes; `chrome` = drawn on app chrome (the style grid), where the\n * dark-ink styles flip so they still read on a dark panel. Prod looks beyond the four: brand as primary, dark as\n * secondary, any other in the muted kit fill.\n */\nexport function ButtonPreview({ v, className, small, chrome }: { v: LinkValue; className?: string; small?: boolean; chrome?: boolean }) {\n const look = lookOf(v) ?? \"primary\";\n const style = look === \"brand\" ? \"primary\" : look === \"dark\" ? \"secondary\" : look;\n const size = small ? \"sm\" : v.size ?? \"md\";\n return (\n <span\n className={cn(\n \"inline-flex max-w-full items-center justify-center gap-1.5 truncate font-medium transition-colors\",\n size === \"sm\" ? \"h-6 rounded-kit-md px-2 text-kit-xs\" : size === \"lg\" ? \"h-10 rounded-kit-lg px-4 text-kit-base\" : \"h-8 rounded-kit-lg px-3 text-kit-sm\",\n style === \"primary\" && \"bg-kit-preview-primary text-kit-preview-primary-on\",\n style === \"secondary\" && (chrome ? \"bg-kit-preview-contrast text-kit-preview-contrast-on\" : \"bg-kit-preview-ink text-kit-preview-paper\"),\n style === \"outline\" && (chrome ? \"border border-kit-preview-outline text-kit-fg\" : \"border border-kit-preview-ink/25 text-kit-preview-ink\"),\n style === \"link\" && \"h-auto px-0 text-kit-preview-primary underline underline-offset-4\",\n !STYLE_ITEMS.some((x) => x.value === style) && \"bg-kit-muted text-kit-fg\",\n v.fullWidth && !small && \"w-full\",\n className,\n )}\n >\n {v.icon ? <KitIcon name={v.icon} className=\"size-3.5 shrink-0\" /> : null}\n <span className=\"truncate\">{v.label || \"Button\"}</span>\n {v.arrow ? <IconArrowRight className=\"size-3.5 shrink-0\" stroke={1.75} /> : null}\n </span>\n );\n}\n\n/** A 16px neutral glyph of the style (filled · outlined · underlined) — brand-free, so the field stays calm. */\nexport function StyleGlyph({ style, className }: { style?: string; className?: string }) {\n return (\n <span aria-hidden className={cn(\"flex size-4 shrink-0 items-center justify-center\", className)}>\n {style === \"link\" ? (\n <span className=\"h-[2px] w-3.5 rounded-full bg-kit-fg-2\" />\n ) : (\n <span className={cn(\"h-2.5 w-4 rounded-[3px]\", style === \"outline\" ? \"border-[1.5px] border-kit-fg-2\" : style === \"secondary\" || style === \"light\" || style === \"tertiary\" ? \"bg-kit-fg-3\" : \"bg-kit-fg\")} />\n )}\n </span>\n );\n}\n\n/** The leading-icon picker over BUTTON_ICONS, \"No icon\" first: V2's IconPickerGrid (icon.tsx) — search box, 8-column\n * grid in a 224px scroll. The tiles stay one radiogroup (the dash's semantics; V2 draws a listbox). */\nexport function ButtonIconPicker({ value, onPick }: { value?: string; onPick: (icon: string | undefined) => void }) {\n const [q, setQ] = React.useState(\"\");\n const query = q.trim().toLowerCase();\n const shown = query ? BUTTON_ICONS.filter((n) => n.includes(query.replace(/\\s+/g, \"-\"))) : BUTTON_ICONS;\n const tile = (on: boolean) =>\n cn(\"flex aspect-square items-center justify-center rounded-kit-md text-kit-fg-2 transition-colors hover:bg-kit-hover hover:text-kit-fg\", on && \"bg-kit-selected text-kit-fg ring-1 ring-inset ring-kit-line-strong\");\n return (\n <div data-icon-picker className=\"flex flex-col gap-2\">\n <label className=\"flex h-8 items-center gap-2 rounded-kit-md bg-kit-muted px-2.5 text-kit-fg-3 focus-within:bg-kit-field-bg focus-within:ring-1 focus-within:ring-kit-line-strong\">\n <IconSearch className=\"size-4 shrink-0\" stroke={1.5} aria-hidden />\n <input\n autoFocus\n value={q}\n onChange={(e) => setQ(e.target.value)}\n placeholder=\"Search icons\"\n aria-label=\"Search icons\"\n className=\"h-full min-w-0 flex-1 bg-transparent text-kit-sm text-kit-fg outline-none placeholder:text-kit-fg-3\"\n />\n </label>\n <div className=\"max-h-56 overflow-y-auto pr-0.5\">\n <div role=\"radiogroup\" aria-label=\"Leading icon\" className=\"grid gap-0.5\" style={{ gridTemplateColumns: \"repeat(8, minmax(0, 1fr))\" }}>\n {query ? null : (\n <button type=\"button\" role=\"radio\" aria-checked={!value} aria-label=\"No icon\" onClick={() => onPick(undefined)} className={tile(!value)}>\n <IconX className=\"size-4\" stroke={1.5} aria-hidden />\n </button>\n )}\n {shown.map((n) => (\n <button key={n} type=\"button\" role=\"radio\" aria-checked={value === n} aria-label={iconLabel(n)} onClick={() => onPick(n)} className={tile(value === n)}>\n <KitIcon name={n} className=\"size-[18px]\" />\n </button>\n ))}\n </div>\n {shown.length === 0 ? <p className=\"py-6 text-center text-kit-sm text-kit-fg-3\">No icons match “{q}”</p> : null}\n </div>\n </div>\n );\n}\n\n/** The ONE button screen: preview · label · link (+ new tab, rel) · appearance (style, size, icon, arrow). */\nexport function ButtonScreen({ value, onChange, readOnly, title = \"Button\" }: { value: unknown; onChange: (v: LinkValue) => void; readOnly?: boolean; title?: string }) {\n const v = normLink(value);\n const set = (p: Partial<LinkValue>) => onChange(nextButton(value, p));\n const [iconOpen, setIconOpen] = React.useState(false);\n const labelId = React.useId();\n const arrowId = React.useId();\n const fullId = React.useId();\n return (\n <fieldset disabled={readOnly} className=\"flex min-w-0 flex-col gap-5\">\n <div data-button-preview=\"\" className=\"flex min-h-20 items-center justify-center rounded-kit-lg bg-kit-preview-paper px-4 py-5 [filter:var(--kit-paper-filter)]\">\n <ButtonPreview v={v} />\n </div>\n <Row label=\"Label\" htmlFor={labelId}>\n <Input id={labelId} value={v.label ?? \"\"} onChange={(e) => set({ label: e.target.value })} placeholder=\"Shop now\" />\n </Row>\n <div className=\"flex flex-col gap-1.5\" role=\"group\" aria-label={`${title} link`}>\n <span className=\"text-kit-sm font-medium text-kit-fg-2\">Link</span>\n <LinkForm\n readOnly={readOnly}\n value={v}\n onChange={(n) => {\n // a script link is never written; LinkForm says why under the target\n const out = finalizeLink(n);\n if (out) set(linkPart(out));\n }}\n />\n </div>\n <div className=\"flex flex-col gap-4 border-t border-kit-line pt-4\">\n <span className=\"text-kit-xs font-medium text-kit-fg-3\">Appearance</span>\n <Row label=\"Style\">\n <ButtonStyleGrid v={v} aria-label={`${title} style`} onPick={(style) => set({ style })} />\n </Row>\n <Row label=\"Size\">\n <Segmented<\"sm\" | \"md\" | \"lg\">\n aria-label={`${title} size`}\n value={v.size ?? \"md\"}\n onChange={(s) => set({ size: s })}\n items={[\n { value: \"sm\", label: \"Small\" },\n { value: \"md\", label: \"Medium\" },\n { value: \"lg\", label: \"Large\" },\n ]}\n className=\"w-full [&>button]:flex-1\"\n />\n </Row>\n <Row label=\"Leading icon\">\n <Popover open={iconOpen} onOpenChange={setIconOpen}>\n <PopoverTrigger\n render={\n <button\n type=\"button\"\n className=\"flex h-8 w-full items-center gap-2 rounded-kit-md border border-kit-field-border bg-kit-field-bg px-2.5 text-left text-kit-sm text-kit-fg hover:border-kit-field-border-hover\"\n />\n }\n >\n {v.icon ? <KitIcon name={v.icon} className=\"size-4 text-kit-fg-2\" /> : <span className=\"size-4 rounded-kit-md border border-dashed border-[var(--kit-emphasis-line)]\" />}\n <span className={cn(\"flex-1 truncate\", !v.icon && \"text-kit-fg-3\")}>{v.icon ? iconLabel(v.icon) : \"No icon\"}</span>\n <IconChevronDown className=\"size-3.5 text-kit-fg-3\" stroke={1.5} />\n </PopoverTrigger>\n <PopoverContent className=\"w-[300px] p-2\">\n <ButtonIconPicker\n value={v.icon}\n onPick={(k) => {\n set({ icon: k });\n setIconOpen(false);\n }}\n />\n </PopoverContent>\n </Popover>\n </Row>\n <div className=\"flex flex-col gap-2\">\n <label htmlFor={arrowId} className=\"flex min-h-7 cursor-pointer items-center justify-between gap-3\">\n <span className=\"text-kit-sm text-kit-fg-2\">Show arrow</span>\n <Switch disabled={readOnly} id={arrowId} size=\"sm\" checked={!!v.arrow} onCheckedChange={(c) => set({ arrow: c ? true : isObj(value) && \"arrow\" in value ? false : undefined })} />\n </label>\n <label htmlFor={fullId} className=\"flex min-h-7 cursor-pointer items-center justify-between gap-3\">\n <span className=\"text-kit-sm text-kit-fg-2\">Full width</span>\n <Switch\n disabled={readOnly}\n id={fullId}\n size=\"sm\"\n checked={v.fullWidth === true}\n onCheckedChange={(c) => set({ fullWidth: c ? true : isObj(value) && \"fullWidth\" in value ? false : undefined })}\n />\n </label>\n </div>\n </div>\n </fieldset>\n );\n}\n\n/** The link half of a link value (what LinkForm / the quick edit own); the label and the look stay the button's. */\nfunction linkPart(n: LinkValue): Partial<LinkValue> {\n const { label: _l, style: _s, variant: _v, size: _z, arrow: _a, icon: _i, fullWidth: _f, ...link } = n;\n // a key the new link no longer has (a picked page drops the typed email) is cleared, not kept from before\n return { ...TARGET_KEYS, email: undefined, phone: undefined, subject: undefined, ...link };\n}\n\nfunction Row({ label, children, htmlFor }: { label: string; children: React.ReactNode; htmlFor?: string }) {\n return (\n <div className=\"flex flex-col gap-1.5\">\n <label htmlFor={htmlFor} className=\"text-kit-sm font-medium text-kit-fg-2\">\n {label}\n </label>\n {children}\n </div>\n );\n}\n\n/**\n * Button field at rest: ONE unit between two hairlines (fieldset-like).\n * [style glyph] Label ……………… Primary · Medium › → drills into the button screen (\"… › Button\")\n * [page icon] Title /path → edits the link in place\n */\nexport function ButtonControl({ value, onChange, readOnly, id, path, field }: ControlProps) {\n const v = normLink(value);\n const form = useForm();\n const { variant } = useKitEnv();\n const [open, setOpen] = React.useState(false);\n const [editingLink, setEditingLink] = React.useState(false);\n const { targets } = useLinkTargets();\n const target = findTarget(targets, v);\n const linkBtn = React.useRef<HTMLButtonElement>(null);\n const look = lookOf(v);\n const openSettings = () => (form ? form.navigate(path) : setOpen(true));\n const h = variant === \"document\" ? \"h-10\" : \"h-9\";\n const head = (\n <button\n id={id}\n type=\"button\"\n onClick={readOnly && !form ? undefined : openSettings}\n aria-label={`${field.title}: ${v.label || \"no label\"}. Open button settings`}\n className={cn(\"group/bhead flex w-full min-w-0 items-center gap-2.5 px-2.5 text-left outline-none transition-colors hover:bg-kit-hover focus-visible:bg-kit-hover\", h)}\n >\n <StyleGlyph style={look} />\n <span className={cn(\"min-w-0 flex-1 truncate text-kit-sm font-medium\", v.label ? \"text-kit-fg\" : \"text-kit-fg-3\")}>{v.label || \"Add a label\"}</span>\n <span className=\"shrink-0 text-kit-xs text-kit-fg-3\">\n {lookLabel(look)}\n {v.size && v.size !== \"md\" ? ` · ${SIZE_LABEL[v.size]}` : \"\"}\n </span>\n <IconChevronRight className=\"size-4 shrink-0 text-kit-fg-3 transition-transform group-hover/bhead:translate-x-0.5\" stroke={1.5} aria-hidden />\n </button>\n );\n const linkRow =\n editingLink && !readOnly ? (\n <div>\n <LinkQuickEdit\n value={v}\n ariaLabel={`${field.title} link`}\n size=\"sm\"\n bare\n onCommit={(n) => onChange(nextButton(value, n ? linkPart(n) : { ...linkPart({ href: \"\" }), type: \"page\", href: \"\" }))}\n onDone={() => {\n setEditingLink(false);\n requestAnimationFrame(() => linkBtn.current?.focus({ preventScroll: true }));\n }}\n />\n </div>\n ) : (\n <button\n ref={linkBtn}\n type=\"button\"\n disabled={readOnly}\n onClick={() => setEditingLink(true)}\n // V2 link.tsx:1263: the name reads the link's own text (its title, else its address), not the picked target's title\n aria-label={hasLink(v) ? `${field.title} link: ${linkText(v)}. Edit link` : `Add a link to ${field.title.toLowerCase()}`}\n className={cn(\"flex w-full min-w-0 items-center px-2.5 text-left outline-none transition-colors hover:bg-kit-hover focus-visible:bg-kit-hover disabled:cursor-default disabled:hover:bg-transparent\", h)}\n >\n <LinkLine v={v} target={target} />\n </button>\n );\n // CPO D43 + D45: label + link are ONE unit — one border, a hairline between the label row and the link row\n const unit = (\n <FieldUnit data-button-unit=\"\" aria-label={field.title} className=\"overflow-hidden\">\n {head}\n {linkRow}\n </FieldUnit>\n );\n if (form) return unit;\n return (\n <Popover open={open} onOpenChange={setOpen}>\n <PopoverAnchor render={unit} />\n <PopoverContent className=\"w-[360px] p-4\" align=\"start\">\n <ButtonScreen value={value} onChange={onChange} readOnly={readOnly} title={field.title} />\n </PopoverContent>\n </Popover>\n );\n}\n\n/* ── Compact button editor for small surfaces (the canvas popover) ──\n * V2 kit/controls/link.tsx ButtonLinkEditor, ported as is: label + the link element (LinkForm, same Type · target ·\n * options as everywhere) as one unit, then the button's Style. Here beside STYLE_ITEMS, which link.tsx cannot import.\n */\nexport function ButtonLinkEditor({\n value,\n onChange,\n onSubmit,\n styles = STYLE_ITEMS,\n labelFirst = true,\n}: {\n value: LinkValue;\n onChange: (v: LinkValue) => void;\n onSubmit?: () => void;\n /** null = a plain text link (nav, footer and legal links): no style row. */\n styles?: { value: ButtonStyle; label: string }[] | null;\n labelFirst?: boolean;\n}) {\n const v = normLink(value);\n const labelId = React.useId();\n const setStyle = (s: ButtonStyle) => onChange({ ...v, style: s, variant: s });\n return (\n <div className=\"flex flex-col gap-3\">\n {labelFirst ? (\n <div className=\"flex flex-col gap-1.5\">\n <label htmlFor={labelId} className=\"text-kit-xs font-medium text-kit-fg-2\">Label</label>\n <Input id={labelId} size=\"sm\" autoFocus value={v.label ?? \"\"} onChange={(e) => onChange({ ...v, label: e.target.value })} onKeyDown={(e) => e.key === \"Enter\" && (e.preventDefault(), onSubmit?.())} placeholder=\"Shop cookware\" />\n </div>\n ) : null}\n <div className=\"flex flex-col gap-2.5\" role=\"group\" aria-label=\"Link\">\n <span className=\"text-kit-xs font-medium text-kit-fg-2\">Link</span>\n <LinkForm value={v} onChange={(n) => onChange({ ...v, ...n, label: v.label, style: v.style, variant: v.variant })} onEnter={() => onSubmit?.()} />\n </div>\n {styles ? (\n <div className=\"flex items-center justify-between gap-3 border-t border-kit-line pt-2.5\">\n <span className=\"text-kit-xs text-kit-fg-2\">Style</span>\n <Segmented size=\"sm\" aria-label=\"Button style\" value={v.style ?? \"primary\"} onChange={(s) => setStyle(s as ButtonStyle)} items={styles} />\n </div>\n ) : null}\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuCA,IAAa,cAAuD;CAClE;EAAE,OAAO;EAAW,OAAO;CAAU;CACrC;EAAE,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;KAAM,WAAU;KAAwC,UAAA;IAAU,CAAA,GAClE,oBAAC,UAAD;KAAU,OAAO;KAAG,WAAW,MAAM,SAAS;MAAE,GAAG;MAAG,GAAG;MAAG,OAAO,EAAE;MAAO,OAAO,EAAE;MAAO,SAAS,EAAE;KAAQ,CAAC;KAAG,eAAe,WAAW;IAAI,CAAA,CAC9I;;GACJ,SACC,qBAAC,OAAD;IAAK,WAAU;IAAf,UAAA,CACE,oBAAC,QAAD;KAAM,WAAU;KAA4B,UAAA;IAAW,CAAA,GACvD,oBAAC,WAAD;KAAW,MAAK;KAAK,cAAW;KAAe,OAAO,EAAE,SAAS;KAAW,WAAW,MAAM,SAAS,CAAgB;KAAG,OAAO;IAAS,CAAA,CACtI;GACH,CAAA,IAAA;EACD;;AAET"}
1
+ {"version":3,"file":"button.js","names":[],"sources":["../../src/controls/button.tsx"],"sourcesContent":["/**\n * BUTTON — label + link + look as ONE unit (V2 HEAD kit/controls/link.tsx \"Button\", DESIGN §8.8, CPO D43 · D45 · D46).\n *\n * - <ButtonControl> at rest: one FieldUnit, two rows. The label row drills into the button screen (form.navigate → the\n * \"button\" frame); the link row edits the link in place (LinkQuickEdit).\n * - <ButtonScreen> the one button screen (the frame body): preview · label · link (LinkForm) · appearance (style grid,\n * size, leading icon, arrow).\n * - <ButtonStyleGrid>, <ButtonPreview>, <StyleGlyph> — the pieces both draw.\n *\n * Stored shape (prod `button`, adapters/values.ts buttonToProd / buttonFromProd; backend buttonValueProblem). The kit\n * value is the flattened V2 button the adapter hands in. What this control writes keeps that value's keys:\n * - the look goes in the key the value already uses — `style` when it has one, else `variant` (what prod renderers\n * read) — and never both (buttonToProd names an equal pair as lost, so the dock would refuse the write);\n * - `rel: \"follow\"` is never written (prod's rel list is nofollow · sponsored · ugc) and `newTab: false`/`target` only\n * where the stored value had that key (storedLink);\n * - `icon` is a dock icon name (DOCK_ICON_NAMES): the picker offers only icons that are dock names.\n *\n * \"Full width\" writes `fullWidth: true`, and off writes `false` only where the stored value had the key (as Show arrow);\n * every renderer draws it (hosted `bcms-btn-full`, the SDKs' and in-place publishing's `data-full-width`).\n *\n * Deviation from V2, because prod has nothing behind it: an unset look reads \"Default\" (V2 drew Primary, and guessed\n * Outline for a field named \"secondary\"). The preview is V2's: the site palette (--kit-preview-paper / -ink / -primary /\n * -primary-on / -contrast / -contrast-on / -outline, which a host may set to the project's colours) on the paper, and the\n * chrome swatches in the style grid.\n */\nimport * as React from \"react\";\nimport { IconArrowRight, IconChevronDown, IconChevronRight, IconSearch, IconX } from \"@tabler/icons-react\";\nimport { cn } from \"../lib/cn\";\nimport { isObj } from \"../lib/path\";\nimport { KIT_ICONS, KitIcon, iconLabel } from \"../lib/icons\";\nimport { BUTTON_VARIANTS, DOCK_ICON_NAME_SET } from \"../adapters/prod-types\";\nimport { useForm, useKitEnv } from \"../context\";\nimport { FieldUnit } from \"../engine/grouping\";\nimport { Input } from \"../ui/input\";\nimport { Segmented, Switch } from \"../ui/controls\";\nimport { Popover, PopoverAnchor, PopoverContent, PopoverTrigger } from \"../ui/overlay\";\nimport type { ControlProps } from \"../types\";\nimport { LinkForm, LinkLine, LinkQuickEdit, TARGET_KEYS, finalizeLink, findTarget, hasLink, linkText, normLink, storedLink, useLinkTargets, type ButtonStyle, type LinkValue } from \"./link\";\n\nexport const STYLE_ITEMS: { value: ButtonStyle; label: string }[] = [\n { value: \"primary\", label: \"Primary\" },\n { value: \"secondary\", label: \"Secondary\" },\n { value: \"outline\", label: \"Outline\" },\n { value: \"link\", label: \"Text link\" },\n];\nconst SIZE_LABEL = { sm: \"Small\", md: \"Medium\", lg: \"Large\" } as const;\nconst isVariant = (x: unknown): x is string => typeof x === \"string\" && (BUTTON_VARIANTS as readonly string[]).includes(x);\n\n/** The look prod renders: the first valid of variant, style (buttonToProd's rule). */\nexport function lookOf(v: Pick<LinkValue, \"variant\" | \"style\">): string | undefined {\n return [v.variant, v.style].find(isVariant);\n}\n/** \"Brand\" for a stored look outside the four styles; undefined when unset. */\nexport function lookLabel(look: string | undefined): string {\n if (!look) return \"Default\";\n return STYLE_ITEMS.find((s) => s.value === look)?.label ?? look.charAt(0).toUpperCase() + look.slice(1);\n}\n\n/**\n * The next stored button: `raw` (the value as the field holds it) with `patch` applied, keyed like `raw`. A look in the\n * patch (`style`) lands in the key `raw` uses for it.\n */\nexport function nextButton(raw: unknown, patch: Partial<LinkValue>): LinkValue {\n const base: LinkValue = isObj(raw) ? ({ ...(raw as object) } as LinkValue) : { href: \"\" };\n const { style, ...rest } = patch;\n const out: LinkValue = { ...base, ...rest };\n // prod requires both strings (buttonToProd names a missing one as lost, and the dock refuses the write)\n if (typeof out.href !== \"string\") out.href = \"\";\n if (typeof out.label !== \"string\") out.label = \"\";\n if (style !== undefined) {\n const key = isObj(raw) && raw.style !== undefined ? \"style\" : \"variant\";\n delete out.style;\n delete out.variant;\n out[key] = style;\n }\n return storedLink(out, raw);\n}\n\n/** The icons a button can carry: the kit's drawn icons that are also dock names (the backend checks the name). */\nexport const BUTTON_ICONS: string[] = Object.keys(KIT_ICONS).filter((n) => DOCK_ICON_NAME_SET.has(n));\n\n/** D46: four styles never sit in a row of tabs. The option IS the visual, so it is a 2×2 grid of live previews (one\n * radiogroup: Tab enters on the checked style, arrows move and pick). A stored look outside the four is listed too. */\nexport function ButtonStyleGrid({\n v,\n onPick,\n \"aria-label\": ariaLabel,\n size = \"md\",\n}: {\n v: LinkValue;\n onPick: (s: ButtonStyle) => void;\n \"aria-label\": string;\n size?: \"sm\" | \"md\";\n}) {\n const cur = lookOf(v);\n const items: { value: string; label: string }[] = cur && !STYLE_ITEMS.some((s) => s.value === cur) ? [...STYLE_ITEMS, { value: cur, label: lookLabel(cur) }] : STYLE_ITEMS;\n const onKey = (e: React.KeyboardEvent, i: number) => {\n const d = e.key === \"ArrowRight\" || e.key === \"ArrowDown\" ? 1 : e.key === \"ArrowLeft\" || e.key === \"ArrowUp\" ? -1 : 0;\n if (!d) return;\n e.preventDefault();\n const next = items[(i + d + items.length) % items.length];\n onPick(next.value as ButtonStyle);\n const group = (e.currentTarget as HTMLElement).parentElement;\n requestAnimationFrame(() => group?.querySelector<HTMLElement>(`[data-style=\"${next.value}\"]`)?.focus());\n };\n return (\n <div className=\"grid grid-cols-2 gap-1.5\" role=\"radiogroup\" aria-label={ariaLabel}>\n {items.map((s, i) => {\n const on = cur === s.value;\n return (\n <button\n key={s.value}\n type=\"button\"\n role=\"radio\"\n data-style={s.value}\n aria-checked={on}\n tabIndex={on || (!items.some((x) => x.value === cur) && i === 0) ? 0 : -1}\n onKeyDown={(e) => onKey(e, i)}\n onClick={() => onPick(s.value as ButtonStyle)}\n className={cn(\n \"flex min-w-0 items-center gap-2 rounded-kit-md border px-2 transition-colors\",\n size === \"sm\" ? \"h-8 text-kit-xs\" : \"h-9 text-kit-sm\",\n on ? \"border-[var(--kit-emphasis-line)] bg-kit-selected text-kit-fg\" : \"border-kit-line text-kit-fg-2 hover:border-kit-line-strong hover:text-kit-fg\",\n )}\n >\n <ButtonPreview v={{ ...v, style: s.value as ButtonStyle, variant: undefined, label: \"Aa\", icon: undefined, arrow: false }} small chrome />\n <span className=\"truncate\">{s.label}</span>\n </button>\n );\n })}\n </div>\n );\n}\n\n/**\n * The site's button as the site draws it (V2 link.tsx ButtonPreview: the site palette, not app tokens). On the preview\n * paper it keeps the site's own colours in both themes; `chrome` = drawn on app chrome (the style grid), where the\n * dark-ink styles flip so they still read on a dark panel. Prod looks beyond the four: brand as primary, dark as\n * secondary, any other in the muted kit fill.\n */\nexport function ButtonPreview({ v, className, small, chrome }: { v: LinkValue; className?: string; small?: boolean; chrome?: boolean }) {\n const look = lookOf(v) ?? \"primary\";\n const style = look === \"brand\" ? \"primary\" : look === \"dark\" ? \"secondary\" : look;\n const size = small ? \"sm\" : v.size ?? \"md\";\n return (\n <span\n className={cn(\n \"inline-flex max-w-full items-center justify-center gap-1.5 truncate font-medium transition-colors\",\n size === \"sm\" ? \"h-6 rounded-kit-md px-2 text-kit-xs\" : size === \"lg\" ? \"h-10 rounded-kit-lg px-4 text-kit-base\" : \"h-8 rounded-kit-lg px-3 text-kit-sm\",\n style === \"primary\" && \"bg-kit-preview-primary text-kit-preview-primary-on\",\n style === \"secondary\" && (chrome ? \"bg-kit-preview-contrast text-kit-preview-contrast-on\" : \"bg-kit-preview-ink text-kit-preview-paper\"),\n style === \"outline\" && (chrome ? \"border border-kit-preview-outline text-kit-fg\" : \"border border-kit-preview-ink/25 text-kit-preview-ink\"),\n style === \"link\" && \"h-auto px-0 text-kit-preview-primary underline underline-offset-4\",\n !STYLE_ITEMS.some((x) => x.value === style) && \"bg-kit-muted text-kit-fg\",\n v.fullWidth && !small && \"w-full\",\n className,\n )}\n >\n {v.icon ? <KitIcon name={v.icon} className=\"size-3.5 shrink-0\" /> : null}\n <span className=\"truncate\">{v.label || \"Button\"}</span>\n {v.arrow ? <IconArrowRight className=\"size-3.5 shrink-0\" stroke={1.75} /> : null}\n </span>\n );\n}\n\n/** A 16px neutral glyph of the style (filled · outlined · underlined) — brand-free, so the field stays calm. */\nexport function StyleGlyph({ style, className }: { style?: string; className?: string }) {\n return (\n <span aria-hidden className={cn(\"flex size-4 shrink-0 items-center justify-center\", className)}>\n {style === \"link\" ? (\n <span className=\"h-[2px] w-3.5 rounded-full bg-kit-fg-2\" />\n ) : (\n <span className={cn(\"h-2.5 w-4 rounded-[3px]\", style === \"outline\" ? \"border-[1.5px] border-kit-fg-2\" : style === \"secondary\" || style === \"light\" || style === \"tertiary\" ? \"bg-kit-fg-3\" : \"bg-kit-fg\")} />\n )}\n </span>\n );\n}\n\n/** The leading-icon picker over BUTTON_ICONS, \"No icon\" first: V2's IconPickerGrid (icon.tsx) — search box, 8-column\n * grid in a 224px scroll. The tiles stay one radiogroup (the dash's semantics; V2 draws a listbox). */\nexport function ButtonIconPicker({ value, onPick }: { value?: string; onPick: (icon: string | undefined) => void }) {\n const [q, setQ] = React.useState(\"\");\n const query = q.trim().toLowerCase();\n const shown = query ? BUTTON_ICONS.filter((n) => n.includes(query.replace(/\\s+/g, \"-\"))) : BUTTON_ICONS;\n const tile = (on: boolean) =>\n cn(\"flex aspect-square items-center justify-center rounded-kit-md text-kit-fg-2 transition-colors hover:bg-kit-hover hover:text-kit-fg\", on && \"bg-kit-selected text-kit-fg ring-1 ring-inset ring-kit-line-strong\");\n return (\n <div data-icon-picker className=\"flex flex-col gap-2\">\n <label className=\"flex h-8 items-center gap-2 rounded-kit-md bg-kit-muted px-2.5 text-kit-fg-3 focus-within:bg-kit-field-bg focus-within:ring-1 focus-within:ring-kit-line-strong\">\n <IconSearch className=\"size-4 shrink-0\" stroke={1.5} aria-hidden />\n <input\n autoFocus\n value={q}\n onChange={(e) => setQ(e.target.value)}\n placeholder=\"Search icons\"\n aria-label=\"Search icons\"\n className=\"h-full min-w-0 flex-1 bg-transparent text-kit-sm text-kit-fg outline-none placeholder:text-kit-fg-3\"\n />\n </label>\n <div className=\"max-h-56 overflow-y-auto pr-0.5\">\n <div role=\"radiogroup\" aria-label=\"Leading icon\" className=\"grid gap-0.5\" style={{ gridTemplateColumns: \"repeat(8, minmax(0, 1fr))\" }}>\n {query ? null : (\n <button type=\"button\" role=\"radio\" aria-checked={!value} aria-label=\"No icon\" onClick={() => onPick(undefined)} className={tile(!value)}>\n <IconX className=\"size-4\" stroke={1.5} aria-hidden />\n </button>\n )}\n {shown.map((n) => (\n <button key={n} type=\"button\" role=\"radio\" aria-checked={value === n} aria-label={iconLabel(n)} onClick={() => onPick(n)} className={tile(value === n)}>\n <KitIcon name={n} className=\"size-[18px]\" />\n </button>\n ))}\n </div>\n {shown.length === 0 ? <p className=\"py-6 text-center text-kit-sm text-kit-fg-3\">No icons match “{q}”</p> : null}\n </div>\n </div>\n );\n}\n\n/** The ONE button screen: preview · label · link (+ new tab, rel) · appearance (style, size, icon, arrow). */\nexport function ButtonScreen({ value, onChange, readOnly, title = \"Button\" }: { value: unknown; onChange: (v: LinkValue) => void; readOnly?: boolean; title?: string }) {\n const v = normLink(value);\n const set = (p: Partial<LinkValue>) => onChange(nextButton(value, p));\n const [iconOpen, setIconOpen] = React.useState(false);\n const labelId = React.useId();\n const noLabel = !readOnly && !(v.label ?? \"\").trim();\n const arrowId = React.useId();\n const fullId = React.useId();\n return (\n <fieldset disabled={readOnly} className=\"flex min-w-0 flex-col gap-5\">\n <div data-button-preview=\"\" className=\"flex min-h-20 items-center justify-center rounded-kit-lg bg-kit-preview-paper px-4 py-5 [filter:var(--kit-paper-filter)]\">\n <ButtonPreview v={v} />\n </div>\n <Row label=\"Label\" htmlFor={labelId}>\n <Input\n id={labelId}\n value={v.label ?? \"\"}\n onChange={(e) => set({ label: e.target.value })}\n placeholder=\"Shop now\"\n aria-invalid={noLabel || undefined}\n aria-describedby={noLabel ? `${labelId}-msg` : undefined}\n />\n {/* DK-018: an empty label leaves the reader nothing to press (the preview's \"Button\" is only a placeholder) */}\n {noLabel ? (\n <p id={`${labelId}-msg`} className=\"text-kit-xs text-kit-danger-fg\">\n Add a label. Without one the button shows no text on the page.\n </p>\n ) : null}\n </Row>\n <div className=\"flex flex-col gap-1.5\" role=\"group\" aria-label={`${title} link`}>\n <span className=\"text-kit-sm font-medium text-kit-fg-2\">Link</span>\n <LinkForm\n readOnly={readOnly}\n value={v}\n onChange={(n) => {\n // a script link is never written; LinkForm says why under the target\n const out = finalizeLink(n);\n if (out) set(linkPart(out));\n }}\n />\n </div>\n <div className=\"flex flex-col gap-4 border-t border-kit-line pt-4\">\n <span className=\"text-kit-xs font-medium text-kit-fg-3\">Appearance</span>\n <Row label=\"Style\">\n <ButtonStyleGrid v={v} aria-label={`${title} style`} onPick={(style) => set({ style })} />\n </Row>\n <Row label=\"Size\">\n <Segmented<\"sm\" | \"md\" | \"lg\">\n aria-label={`${title} size`}\n value={v.size ?? \"md\"}\n onChange={(s) => set({ size: s })}\n items={[\n { value: \"sm\", label: \"Small\" },\n { value: \"md\", label: \"Medium\" },\n { value: \"lg\", label: \"Large\" },\n ]}\n className=\"w-full [&>button]:flex-1\"\n />\n </Row>\n <Row label=\"Leading icon\">\n <Popover open={iconOpen} onOpenChange={setIconOpen}>\n <PopoverTrigger\n render={\n <button\n type=\"button\"\n className=\"flex h-8 w-full items-center gap-2 rounded-kit-md border border-kit-field-border bg-kit-field-bg px-2.5 text-left text-kit-sm text-kit-fg hover:border-kit-field-border-hover\"\n />\n }\n >\n {v.icon ? <KitIcon name={v.icon} className=\"size-4 text-kit-fg-2\" /> : <span className=\"size-4 rounded-kit-md border border-dashed border-[var(--kit-emphasis-line)]\" />}\n <span className={cn(\"flex-1 truncate\", !v.icon && \"text-kit-fg-3\")}>{v.icon ? iconLabel(v.icon) : \"No icon\"}</span>\n <IconChevronDown className=\"size-3.5 text-kit-fg-3\" stroke={1.5} />\n </PopoverTrigger>\n <PopoverContent className=\"w-[300px] p-2\">\n <ButtonIconPicker\n value={v.icon}\n onPick={(k) => {\n set({ icon: k });\n setIconOpen(false);\n }}\n />\n </PopoverContent>\n </Popover>\n </Row>\n <div className=\"flex flex-col gap-2\">\n <label htmlFor={arrowId} className=\"flex min-h-7 cursor-pointer items-center justify-between gap-3\">\n <span className=\"text-kit-sm text-kit-fg-2\">Show arrow</span>\n <Switch disabled={readOnly} id={arrowId} size=\"sm\" checked={!!v.arrow} onCheckedChange={(c) => set({ arrow: c ? true : isObj(value) && \"arrow\" in value ? false : undefined })} />\n </label>\n <label htmlFor={fullId} className=\"flex min-h-7 cursor-pointer items-center justify-between gap-3\">\n <span className=\"text-kit-sm text-kit-fg-2\">Full width</span>\n <Switch\n disabled={readOnly}\n id={fullId}\n size=\"sm\"\n checked={v.fullWidth === true}\n onCheckedChange={(c) => set({ fullWidth: c ? true : isObj(value) && \"fullWidth\" in value ? false : undefined })}\n />\n </label>\n </div>\n </div>\n </fieldset>\n );\n}\n\n/** The link half of a link value (what LinkForm / the quick edit own); the label and the look stay the button's. */\nfunction linkPart(n: LinkValue): Partial<LinkValue> {\n const { label: _l, style: _s, variant: _v, size: _z, arrow: _a, icon: _i, fullWidth: _f, ...link } = n;\n // a key the new link no longer has (a picked page drops the typed email) is cleared, not kept from before\n return { ...TARGET_KEYS, email: undefined, phone: undefined, subject: undefined, ...link };\n}\n\nfunction Row({ label, children, htmlFor }: { label: string; children: React.ReactNode; htmlFor?: string }) {\n return (\n <div className=\"flex flex-col gap-1.5\">\n <label htmlFor={htmlFor} className=\"text-kit-sm font-medium text-kit-fg-2\">\n {label}\n </label>\n {children}\n </div>\n );\n}\n\n/**\n * Button field at rest: ONE unit between two hairlines (fieldset-like).\n * [style glyph] Label ……………… Primary · Medium › → drills into the button screen (\"… › Button\")\n * [page icon] Title /path → edits the link in place\n */\nexport function ButtonControl({ value, onChange, readOnly, id, path, field }: ControlProps) {\n const v = normLink(value);\n const form = useForm();\n const { variant } = useKitEnv();\n const [open, setOpen] = React.useState(false);\n const [editingLink, setEditingLink] = React.useState(false);\n const { targets } = useLinkTargets();\n const target = findTarget(targets, v);\n const linkBtn = React.useRef<HTMLButtonElement>(null);\n const look = lookOf(v);\n const openSettings = () => (form ? form.navigate(path) : setOpen(true));\n const h = variant === \"document\" ? \"h-10\" : \"h-9\";\n const head = (\n <button\n id={id}\n type=\"button\"\n onClick={readOnly && !form ? undefined : openSettings}\n aria-label={`${field.title}: ${v.label || \"no label\"}. Open button settings`}\n className={cn(\"group/bhead flex w-full min-w-0 items-center gap-2.5 px-2.5 text-left outline-none transition-colors hover:bg-kit-hover focus-visible:bg-kit-hover\", h)}\n >\n <StyleGlyph style={look} />\n <span className={cn(\"min-w-0 flex-1 truncate text-kit-sm font-medium\", v.label ? \"text-kit-fg\" : \"text-kit-fg-3\")}>{v.label || \"Add a label\"}</span>\n <span className=\"shrink-0 text-kit-xs text-kit-fg-3\">\n {lookLabel(look)}\n {v.size && v.size !== \"md\" ? ` · ${SIZE_LABEL[v.size]}` : \"\"}\n </span>\n <IconChevronRight className=\"size-4 shrink-0 text-kit-fg-3 transition-transform group-hover/bhead:translate-x-0.5\" stroke={1.5} aria-hidden />\n </button>\n );\n const linkRow =\n editingLink && !readOnly ? (\n <div>\n <LinkQuickEdit\n value={v}\n ariaLabel={`${field.title} link`}\n size=\"sm\"\n bare\n onCommit={(n) => onChange(nextButton(value, n ? linkPart(n) : { ...linkPart({ href: \"\" }), type: \"page\", href: \"\" }))}\n onDone={() => {\n setEditingLink(false);\n requestAnimationFrame(() => linkBtn.current?.focus({ preventScroll: true }));\n }}\n />\n </div>\n ) : (\n <button\n ref={linkBtn}\n type=\"button\"\n disabled={readOnly}\n onClick={() => setEditingLink(true)}\n // V2 link.tsx:1263: the name reads the link's own text (its title, else its address), not the picked target's title\n aria-label={hasLink(v) ? `${field.title} link: ${linkText(v)}. Edit link` : `Add a link to ${field.title.toLowerCase()}`}\n className={cn(\"flex w-full min-w-0 items-center px-2.5 text-left outline-none transition-colors hover:bg-kit-hover focus-visible:bg-kit-hover disabled:cursor-default disabled:hover:bg-transparent\", h)}\n >\n <LinkLine v={v} target={target} />\n </button>\n );\n // CPO D43 + D45: label + link are ONE unit — one border, a hairline between the label row and the link row\n const unit = (\n <FieldUnit data-button-unit=\"\" aria-label={field.title} className=\"overflow-hidden\">\n {head}\n {linkRow}\n </FieldUnit>\n );\n if (form) return unit;\n return (\n <Popover open={open} onOpenChange={setOpen}>\n <PopoverAnchor render={unit} />\n <PopoverContent className=\"w-[360px] p-4\" align=\"start\">\n <ButtonScreen value={value} onChange={onChange} readOnly={readOnly} title={field.title} />\n </PopoverContent>\n </Popover>\n );\n}\n\n/* ── Compact button editor for small surfaces (the canvas popover) ──\n * V2 kit/controls/link.tsx ButtonLinkEditor, ported as is: label + the link element (LinkForm, same Type · target ·\n * options as everywhere) as one unit, then the button's Style. Here beside STYLE_ITEMS, which link.tsx cannot import.\n */\nexport function ButtonLinkEditor({\n value,\n onChange,\n onSubmit,\n styles = STYLE_ITEMS,\n labelFirst = true,\n}: {\n value: LinkValue;\n onChange: (v: LinkValue) => void;\n onSubmit?: () => void;\n /** null = a plain text link (nav, footer and legal links): no style row. */\n styles?: { value: ButtonStyle; label: string }[] | null;\n labelFirst?: boolean;\n}) {\n const v = normLink(value);\n const labelId = React.useId();\n const setStyle = (s: ButtonStyle) => onChange({ ...v, style: s, variant: s });\n return (\n <div className=\"flex flex-col gap-3\">\n {labelFirst ? (\n <div className=\"flex flex-col gap-1.5\">\n <label htmlFor={labelId} className=\"text-kit-xs font-medium text-kit-fg-2\">Label</label>\n <Input id={labelId} size=\"sm\" autoFocus value={v.label ?? \"\"} onChange={(e) => onChange({ ...v, label: e.target.value })} onKeyDown={(e) => e.key === \"Enter\" && (e.preventDefault(), onSubmit?.())} placeholder=\"Shop cookware\" />\n </div>\n ) : null}\n <div className=\"flex flex-col gap-2.5\" role=\"group\" aria-label=\"Link\">\n <span className=\"text-kit-xs font-medium text-kit-fg-2\">Link</span>\n <LinkForm value={v} onChange={(n) => onChange({ ...v, ...n, label: v.label, style: v.style, variant: v.variant })} onEnter={() => onSubmit?.()} />\n </div>\n {styles ? (\n <div className=\"flex items-center justify-between gap-3 border-t border-kit-line pt-2.5\">\n <span className=\"text-kit-xs text-kit-fg-2\">Style</span>\n <Segmented size=\"sm\" aria-label=\"Button style\" value={v.style ?? \"primary\"} onChange={(s) => setStyle(s as ButtonStyle)} items={styles} />\n </div>\n ) : null}\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuCA,IAAa,cAAuD;CAClE;EAAE,OAAO;EAAW,OAAO;CAAU;CACrC;EAAE,OAAO;EAAa,OAAO;CAAY;CACzC;EAAE,OAAO;EAAW,OAAO;CAAU;CACrC;EAAE,OAAO;EAAQ,OAAO;CAAY;AACtC;AACA,IAAM,aAAa;CAAE,IAAI;CAAS,IAAI;CAAU,IAAI;AAAQ;AAC5D,IAAM,aAAa,MAA4B,OAAO,MAAM,YAAa,gBAAsC,SAAS,CAAC;;AAGzH,SAAgB,OAAO,GAA6D;CAClF,OAAO,CAAC,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC,KAAK,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SAAS;MAAE,GAAG;MAAG,GAAG;MAAG,OAAO,EAAE;MAAO,OAAO,EAAE;MAAO,SAAS,EAAE;KAAQ,CAAC;KAAG,eAAe,WAAW;IAAI,CAAA,CAC9I;;GACJ,SACC,qBAAC,OAAD;IAAK,WAAU;IAAf,UAAA,CACE,oBAAC,QAAD;KAAM,WAAU;KAA4B,UAAA;IAAW,CAAA,GACvD,oBAAC,WAAD;KAAW,MAAK;KAAK,cAAW;KAAe,OAAO,EAAE,SAAS;KAAW,WAAW,MAAM,SAAS,CAAgB;KAAG,OAAO;IAAS,CAAA,CACtI;GACH,CAAA,IAAA;EACD;;AAET"}
@@ -319,7 +319,7 @@ function MultiSelectInput({ field, value, onChange, readOnly, id }) {
319
319
  id: readOnly ? id : void 0,
320
320
  role: readOnly ? "group" : void 0,
321
321
  "aria-label": readOnly ? field.title : void 0,
322
- className: "flex min-h-8 flex-wrap items-center gap-1 rounded-kit-md border border-kit-field-border bg-kit-field-bg p-1 transition-colors hover:border-kit-field-border-hover",
322
+ className: "flex min-h-8 flex-wrap items-center gap-1 rounded-kit-md border border-kit-line-strong bg-kit-field-bg p-1 transition-colors hover:border-kit-line-strong",
323
323
  children: [list.map((o) => /* @__PURE__ */ jsxs("span", {
324
324
  className: "inline-flex h-6 items-center gap-1 rounded-kit-md border border-kit-line bg-kit-control-bg pl-2 pr-1 text-kit-sm text-kit-fg shadow-kit-xs",
325
325
  children: [label(o), readOnly ? null : /* @__PURE__ */ jsx("button", {
@@ -410,7 +410,7 @@ function TagsControl({ field, value, onChange, readOnly, id, onBlur }) {
410
410
  className: "flex flex-col gap-1",
411
411
  children: [
412
412
  /* @__PURE__ */ jsxs("div", {
413
- className: "flex min-h-8 flex-wrap items-center gap-1 rounded-kit-md border border-kit-field-border bg-kit-field-bg p-1 transition-colors focus-within:border-kit-field-border-focus focus-within:bg-kit-field-bg hover:border-kit-field-border-hover",
413
+ className: "flex min-h-8 flex-wrap items-center gap-1 rounded-kit-md border border-kit-line-strong bg-kit-field-bg p-1 transition-colors focus-within:border-kit-line-strong focus-within:bg-kit-field-bg hover:border-kit-line-strong",
414
414
  children: [list.map((t, i) => /* @__PURE__ */ jsxs("span", {
415
415
  className: "inline-flex h-6 items-center gap-1 rounded-kit-md bg-kit-selected pl-2 pr-1 text-kit-sm text-kit-fg",
416
416
  children: [t, readOnly ? null : /* @__PURE__ */ jsx("button", {
@@ -1 +1 @@
1
- {"version":3,"file":"choice.js","names":[],"sources":["../../src/controls/choice.tsx"],"sourcesContent":["/**\n * CHOICE — boolean · select · multiselect · tags (V2 HEAD 9829bf1 kit/controls/choice.tsx, DESIGN 8.10–8.12).\n * Rule (production): few options → segmented, many → dropdown, many values → checkboxes, on/off → switch card.\n * D46: `layout: \"segmented\"` is a request, not a promise. With 4+ options, or labels that would wrap or truncate\n * in a 340px inspector (`fitsSegmented`), it renders the dropdown instead, so every schema follows the rule.\n *\n * Values are the ones production stores, untouched by any adapter (schema.ts plans them AS_IS): boolean, the option's\n * string, a string[] of option values, a string[] of tags. Tags are written the way the backend judges them\n * (tagsValueProblem: trimmed, case-insensitively unique, at most TAG_VALUE_MAX_LENGTH characters), and a tag the\n * control will not add says why under the box instead of vanishing.\n *\n * Option icons are all or none per list (the schema adapter's rule): a list draws icons only when every option names an\n * icon that can be drawn, so labels stay aligned and no option gets a stand-in glyph. The host's glyphs come first\n * (KitServices.IconGlyph, the BetterCMS set the site renders: every stored option icon is one of its names); with no\n * host renderer, the kit's own drawn icons.\n */\nimport * as React from \"react\";\nimport { IconCheck, IconPlus, IconX } from \"@tabler/icons-react\";\nimport { Checkbox, Segmented, Switch } from \"../ui/controls\";\nimport { Popover, PopoverContent, PopoverTrigger } from \"../ui/overlay\";\nimport { Select } from \"../ui/select\";\nimport { fitsSegmented } from \"../ui/choice-switch\";\nimport { shortcutHintsOn } from \"../ui/shortcut-hint\";\nimport { cn } from \"../lib/cn\";\nimport { KitIcon, iconKey } from \"../lib/icons\";\nimport type { Option } from \"../schema/types\";\nimport { useKitEnv, useKitServices, type KitServices } from \"../context\";\nimport { dockIconOf } from \"../adapters/icons\";\nimport type { ControlProps } from \"../types\";\nimport { TAG_VALUE_MAX_LENGTH } from \"../adapters/prod-types\";\nimport { UnknownValueNote } from \"./unknown-value\";\n\nconst str = (v: unknown) => (typeof v === \"string\" ? v : v == null ? \"\" : String(v));\nconst opts = (o?: Option[]) => o ?? [];\n\n/**\n * Icons for a list: every option's icon when all of them resolve, otherwise none (never a fallback glyph). `Glyph` is\n * the host's renderer (KitServices.IconGlyph): it draws every BetterCMS icon name (the option's kit name read back\n * through dockIconOf); without it, or when a name is not in that set, the kit's own drawn icons.\n */\nexport function optionIcons(options: Option[], className?: string, Glyph?: KitServices[\"IconGlyph\"]): (React.ReactNode | undefined)[] {\n if (options.length === 0) return [];\n const dock = options.map((o) => dockIconOf(o.icon));\n // a block box, as the kit's own <svg> is under preflight: an inline glyph would sit on a line box and grow the row\n if (Glyph && dock.every((n) => n !== undefined)) return dock.map((n) => <Glyph name={n!} className={cn(\"flex\", className)} />);\n const all = options.every((o) => iconKey(o.icon) !== undefined);\n return options.map((o) => (all ? <KitIcon name={o.icon} className={className} /> : undefined));\n}\n\n/** The limit sentence (DESIGN 8.12), shared by multiselect and tags. */\nfunction LimitLine({ max }: { max: number }) {\n return <span className=\"px-0.5 text-kit-xs text-kit-fg-3\">That's the limit of {max}. Remove one to add another.</span>;\n}\n\n/**\n * Roving focus for a radiogroup of buttons (WAI-ARIA radio group, as Segmented does): Tab lands on the selected option\n * (or the first), arrows move and select, Home / End jump.\n */\nfunction useRadioKeys(values: string[], current: string, onPick: (v: string) => void, readOnly?: boolean) {\n const focusable = values.includes(current) ? current : values[0];\n const onKeyDown = (e: React.KeyboardEvent, i: number) => {\n if (readOnly || !values.length) return;\n const n = values.length;\n const next =\n e.key === \"ArrowRight\" || e.key === \"ArrowDown\"\n ? (i + 1) % n\n : e.key === \"ArrowLeft\" || e.key === \"ArrowUp\"\n ? (i - 1 + n) % n\n : e.key === \"Home\"\n ? 0\n : e.key === \"End\"\n ? n - 1\n : -1;\n if (next < 0) return;\n e.preventDefault();\n onPick(values[next]);\n const group = (e.currentTarget as HTMLElement).closest(\"[role=radiogroup]\");\n group?.querySelector<HTMLElement>(`[data-choice-value=\"${CSS.escape(values[next])}\"]`)?.focus();\n };\n return { tabIndexOf: (v: string) => (v === focusable ? 0 : -1), onKeyDown };\n}\n\n/**\n * Adds or removes one id of the control's own in aria-describedby, leaving the ids FieldShell wires (help, issue)\n * in place (as ScaleSlider does).\n */\nexport function useOwnDescription(ref: React.RefObject<HTMLElement | null>, ownId: string | null) {\n const last = React.useRef<string | null>(null);\n React.useEffect(() => {\n const el = ref.current;\n if (!el) return;\n const ids = (el.getAttribute(\"aria-describedby\") ?? \"\").split(\" \").filter((t) => t && t !== last.current && t !== ownId);\n if (ownId) ids.push(ownId);\n if (ids.length) el.setAttribute(\"aria-describedby\", ids.join(\" \"));\n else el.removeAttribute(\"aria-describedby\");\n last.current = ownId;\n });\n}\n\n/** Boolean switch (used inside the switch card the shell draws). Commits immediately. */\nexport function BooleanControl({ field, value, onChange, readOnly, id }: ControlProps) {\n if (field.layout === \"checkbox\")\n return <Checkbox id={id} checked={Boolean(value)} disabled={readOnly} onCheckedChange={(c) => onChange(c === true)} aria-label={field.title} nativeButton render={<button type=\"button\" />} />;\n /* V2's switch is a native <button role=\"switch\"> (Radix); Base UI draws a <span> unless asked for the button */\n return <Switch id={id} checked={Boolean(value)} disabled={readOnly} onCheckedChange={(c) => onChange(c)} aria-label={field.title} nativeButton render={<button type=\"button\" />} />;\n}\n\n/**\n * A stored value none of the options names any more (renamed or removed) is kept and flagged under the control, with\n * change-to and remove (H4). @see UnknownValueNote\n */\nexport function SelectControl(props: ControlProps) {\n const options = opts(props.field.options);\n const v = str(props.value);\n if (v === \"\" || options.length === 0 || options.some((o) => o.value === v)) return <SelectInput {...props} />;\n return (\n <div className=\"flex min-w-0 flex-col gap-1.5\">\n <SelectInput {...props} />\n <UnknownValueNote\n items={[{ key: v, label: `“${v}”`, options: options.map((o) => ({ value: o.value, label: o.label })) }]}\n onRemap={(_, to) => props.onChange(to)}\n onRemove={() => props.onChange(null)}\n readOnly={props.readOnly}\n />\n </div>\n );\n}\n\nfunction SelectInput({ field, value, onChange, readOnly, id }: ControlProps) {\n const { variant } = useKitEnv();\n const { IconGlyph } = useKitServices();\n const options = opts(field.options);\n const v = str(value);\n const fits = fitsSegmented(options.map((o) => o.label));\n const layout = field.layout ?? (fits ? \"segmented\" : \"dropdown\");\n const pick = (n: string) => {\n if (!readOnly && n !== v) onChange(n);\n };\n const keys = useRadioKeys(\n options.map((o) => o.value),\n v,\n pick,\n readOnly,\n );\n\n if (layout === \"segmented\" && fits) {\n const icons = optionIcons(options, \"size-3.5\", IconGlyph);\n return (\n <Segmented\n aria-label={field.title}\n value={v}\n onChange={pick}\n items={options.map((o, i) => ({ value: o.value, label: o.label, icon: icons[i], disabled: readOnly }))}\n className=\"w-full [&>button]:min-w-0 [&>button]:flex-1\"\n />\n );\n }\n if (layout === \"radio\")\n return (\n <div role=\"radiogroup\" id={id} aria-label={field.title} className=\"flex flex-col gap-0.5\">\n {options.map((o, i) => (\n <button\n key={o.value}\n type=\"button\"\n role=\"radio\"\n data-choice-value={o.value}\n aria-checked={o.value === v}\n tabIndex={keys.tabIndexOf(o.value)}\n disabled={readOnly}\n onClick={() => pick(o.value)}\n onKeyDown={(e) => keys.onKeyDown(e, i)}\n className=\"flex items-start gap-2.5 rounded-kit-md px-1.5 py-1.5 text-left hover:bg-kit-hover\"\n >\n <span className={cn(\"mt-0.5 flex size-4 shrink-0 items-center justify-center rounded-full border transition-colors\", o.value === v ? \"border-kit-accent\" : \"border-kit-line-strong\")}>\n {o.value === v ? <span className=\"size-2 rounded-full bg-kit-accent\" /> : null}\n </span>\n <span className=\"min-w-0\">\n <span className=\"block text-kit-sm text-kit-fg\">{o.label}</span>\n {o.description ? <span className=\"block text-kit-xs text-kit-fg-3\">{o.description}</span> : null}\n </span>\n </button>\n ))}\n </div>\n );\n if (layout === \"cards\" || layout === \"grid\") {\n /* V2 draws the icon itself as the button's first child (no wrapper), coloured by the selected state */\n const iconsOn = optionIcons(options, \"size-4 text-kit-fg\", IconGlyph);\n const iconsOff = optionIcons(options, \"size-4 text-kit-fg-3\", IconGlyph);\n return (\n <div role=\"radiogroup\" id={id} aria-label={field.title} className={cn(\"grid gap-1.5\", variant === \"document\" ? \"grid-cols-3\" : \"grid-cols-2\")}>\n {options.map((o, i) => {\n const on = o.value === v;\n return (\n <button\n key={o.value}\n type=\"button\"\n role=\"radio\"\n data-choice-value={o.value}\n aria-checked={on}\n tabIndex={keys.tabIndexOf(o.value)}\n disabled={readOnly}\n onClick={() => pick(o.value)}\n onKeyDown={(e) => keys.onKeyDown(e, i)}\n className={cn(\n \"relative flex flex-col items-start gap-1.5 rounded-kit-lg border p-2.5 text-left transition-[border-color,box-shadow] duration-150\",\n on ? \"border-[var(--kit-emphasis-line)] bg-kit-control-bg shadow-kit-xs\" : \"border-kit-line hover:border-kit-line-strong\",\n )}\n >\n {(on ? iconsOn : iconsOff)[i] ?? null}\n <span className=\"text-kit-sm font-medium text-kit-fg\">{o.label}</span>\n {o.description ? <span className=\"text-kit-xs leading-4 text-kit-fg-3\">{o.description}</span> : null}\n {on ? <IconCheck aria-hidden className=\"absolute right-2 top-2 size-3.5 text-kit-fg\" stroke={2} /> : null}\n </button>\n );\n })}\n </div>\n );\n }\n const icons = optionIcons(options, undefined, IconGlyph);\n return (\n <Select\n id={id}\n aria-label={field.title}\n size={variant === \"document\" ? \"lg\" : \"md\"}\n value={v || undefined}\n disabled={readOnly}\n onValueChange={pick}\n placeholder={field.placeholder ?? \"Select…\"}\n options={options.map((o, i) => ({ value: o.value, label: o.label, description: o.description, icon: icons[i] }))}\n />\n );\n}\n\n/** As `SelectControl`: each stored choice no option names any more is kept and flagged, with change-to and remove. */\nexport function MultiSelectControl(props: ControlProps) {\n const list = Array.isArray(props.value) ? (props.value as unknown[]).filter((x): x is string => typeof x === \"string\") : [];\n const options = opts(props.field.options);\n const unknown = options.length ? list.filter((x) => !options.some((o) => o.value === x)) : [];\n if (unknown.length === 0) return <MultiSelectInput {...props} />;\n return (\n <div className=\"flex min-w-0 flex-col gap-1.5\">\n <MultiSelectInput {...props} />\n <UnknownValueNote\n items={unknown.map((x) => ({ key: x, label: `“${x}”`, options: options.filter((o) => !list.includes(o.value)).map((o) => ({ value: o.value, label: o.label })) }))}\n onRemap={(from, to) => props.onChange(list.map((x) => (x === from ? to : x)))}\n onRemove={(from) => props.onChange(list.filter((x) => x !== from))}\n readOnly={props.readOnly}\n />\n </div>\n );\n}\n\nfunction MultiSelectInput({ field, value, onChange, readOnly, id }: ControlProps) {\n const list = Array.isArray(value) ? (value as unknown[]).filter((x): x is string => typeof x === \"string\") : [];\n const options = opts(field.options);\n const max = field.validation?.max;\n const full = max != null && list.length >= max;\n const toggle = (o: string) => {\n if (readOnly) return;\n if (list.includes(o)) onChange(list.filter((x) => x !== o));\n else if (!full) onChange([...list, o]);\n };\n const label = (val: string) => options.find((o) => o.value === val)?.label ?? val;\n /* V2 draws the control bare; the limit line (ours: say why the next pick is refused) wraps it only while it shows */\n const withLimit = (body: React.ReactElement) =>\n full && !readOnly ? (\n <div className=\"flex flex-col gap-1\">\n {body}\n <LimitLine max={max!} />\n </div>\n ) : (\n body\n );\n if (field.layout === \"checkbox\" || field.layout === \"list\")\n return withLimit(\n <>\n <div id={id} role=\"group\" aria-label={field.title} className=\"flex flex-col gap-0.5\">\n {options.map((o) => {\n const on = list.includes(o.value);\n return (\n <label key={o.value} className={cn(\"flex cursor-pointer items-center gap-2.5 rounded-kit-md px-1.5 py-1.5 hover:bg-kit-hover\", !on && full && \"cursor-not-allowed hover:bg-transparent\")}>\n <Checkbox checked={on} disabled={readOnly || (!on && full)} onCheckedChange={() => toggle(o.value)} nativeButton render={<button type=\"button\" />} />\n <span className=\"text-kit-sm text-kit-fg\">{o.label}</span>\n </label>\n );\n })}\n </div>\n </>,\n );\n return withLimit(\n <>\n <Popover>\n {/* read-only there is no trigger to carry the field id, so the chip row is the named group */}\n <div\n id={readOnly ? id : undefined}\n role={readOnly ? \"group\" : undefined}\n aria-label={readOnly ? field.title : undefined}\n className=\"flex min-h-8 flex-wrap items-center gap-1 rounded-kit-md border border-kit-field-border bg-kit-field-bg p-1 transition-colors hover:border-kit-field-border-hover\"\n >\n {list.map((o) => (\n <span key={o} className=\"inline-flex h-6 items-center gap-1 rounded-kit-md border border-kit-line bg-kit-control-bg pl-2 pr-1 text-kit-sm text-kit-fg shadow-kit-xs\">\n {label(o)}\n {readOnly ? null : (\n <button type=\"button\" aria-label={`Remove ${label(o)}`} onClick={() => toggle(o)} className=\"flex rounded-kit-md p-0.5 text-kit-fg-3 hover:bg-kit-hover hover:text-kit-fg\">\n <IconX className=\"size-3\" stroke={1.5} />\n </button>\n )}\n </span>\n ))}\n {readOnly ? null : (\n <PopoverTrigger id={id} className=\"inline-flex h-6 items-center gap-1 rounded-kit-md px-1.5 text-kit-sm text-kit-fg-3 hover:bg-kit-hover hover:text-kit-fg\">\n <IconPlus aria-hidden className=\"size-3.5\" stroke={1.5} />\n {list.length ? \"Add\" : field.placeholder ?? \"Choose…\"}\n </PopoverTrigger>\n )}\n </div>\n <PopoverContent className=\"w-60 p-1\">\n <div role=\"group\" aria-label={field.title}>\n {options.map((o) => {\n const on = list.includes(o.value);\n const blocked = !on && full;\n return (\n <button\n key={o.value}\n type=\"button\"\n role=\"checkbox\"\n aria-checked={on}\n disabled={blocked}\n onClick={() => toggle(o.value)}\n className={cn(\"flex h-8 w-full items-center gap-2 rounded-kit-md px-2 text-left text-kit-sm hover:bg-kit-hover\", blocked && \"opacity-40 hover:bg-transparent\")}\n >\n <span className={cn(\"flex size-4 items-center justify-center rounded-kit-md border\", on ? \"border-kit-accent bg-kit-accent text-kit-accent-on\" : \"border-kit-line-strong\")}>\n {on ? <IconCheck aria-hidden className=\"size-3\" stroke={3} /> : null}\n </span>\n {o.label}\n </button>\n );\n })}\n </div>\n {full ? <div className=\"px-2 pb-1 pt-1.5\"><LimitLine max={max!} /></div> : null}\n </PopoverContent>\n </Popover>\n </>,\n );\n}\n\n/** Why a typed tag is not added, or null when it is (the backend's own checks, said in words). */\nexport function tagRefusal(tag: string, list: string[]): string | null {\n if (Array.from(tag).length > TAG_VALUE_MAX_LENGTH) return `A tag can be up to ${TAG_VALUE_MAX_LENGTH} characters.`;\n const folded = tag.toLowerCase();\n const twin = list.find((t) => t.trim().toLowerCase() === folded);\n if (twin !== undefined) return `\"${twin}\" is already a tag.`;\n return null;\n}\n\n/** Chip input. Says so at its limit, and says why a tag was not added, instead of silently dropping it. */\nexport function TagsControl({ field, value, onChange, readOnly, id, onBlur }: ControlProps) {\n const list = Array.isArray(value) ? (value as unknown[]).map((x) => str(x)) : [];\n const [draft, setDraft] = React.useState(\"\");\n const [refusal, setRefusal] = React.useState<string | null>(null);\n const reasonId = React.useId();\n const inputRef = React.useRef<HTMLInputElement>(null);\n useOwnDescription(inputRef, refusal ? reasonId : null);\n const max = field.validation?.max;\n const full = max != null && list.length >= max;\n const add = () => {\n const t = draft.trim().replace(/,$/, \"\").trim();\n if (!t || full) {\n setDraft(\"\");\n setRefusal(null);\n return;\n }\n const why = tagRefusal(t, list);\n if (why) {\n // keep the text so it can be fixed; the reason reads under the box\n setRefusal(why);\n return;\n }\n onChange([...list, t]);\n setDraft(\"\");\n setRefusal(null);\n };\n return (\n <div className=\"flex flex-col gap-1\">\n <div className=\"flex min-h-8 flex-wrap items-center gap-1 rounded-kit-md border border-kit-field-border bg-kit-field-bg p-1 transition-colors focus-within:border-kit-field-border-focus focus-within:bg-kit-field-bg hover:border-kit-field-border-hover\">\n {list.map((t, i) => (\n <span key={`${t}-${i}`} className=\"inline-flex h-6 items-center gap-1 rounded-kit-md bg-kit-selected pl-2 pr-1 text-kit-sm text-kit-fg\">\n {t}\n {readOnly ? null : (\n <button type=\"button\" aria-label={`Remove ${t}`} onClick={() => onChange(list.filter((_, j) => j !== i))} className=\"flex rounded-kit-md p-0.5 text-kit-fg-3 hover:bg-kit-hover hover:text-kit-fg\">\n <IconX className=\"size-3\" stroke={1.5} />\n </button>\n )}\n </span>\n ))}\n {readOnly ? null : (\n <input\n ref={inputRef}\n id={id}\n value={draft}\n disabled={full}\n onChange={(e) => {\n setDraft(e.target.value);\n if (refusal) setRefusal(null);\n }}\n onBlur={() => {\n add();\n onBlur?.();\n }}\n onKeyDown={(e) => {\n if (e.key === \"Enter\" || e.key === \",\") {\n e.preventDefault();\n add();\n } else if (e.key === \"Backspace\" && !draft && list.length) onChange(list.slice(0, -1));\n }}\n placeholder={full ? \"\" : list.length ? \"Add…\" : field.placeholder ?? (shortcutHintsOn() ? \"Type and press Enter\" : \"Add…\")}\n className=\"h-6 min-w-20 flex-1 bg-transparent px-1.5 text-kit-sm text-kit-fg outline-none placeholder:text-kit-fg-3\"\n />\n )}\n </div>\n {refusal && !readOnly ? (\n <span id={reasonId} role=\"status\" aria-live=\"polite\" className=\"px-0.5 text-kit-xs text-kit-fg-3\">\n {refusal}\n </span>\n ) : null}\n {full && !readOnly ? <LimitLine max={max!} /> : null}\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCA,IAAM,OAAO,MAAgB,OAAO,MAAM,WAAW,IAAI,KAAK,OAAO,KAAK,OAAO,CAAC;AAClF,IAAM,QAAQ,MAAiB,KAAK,CAAC;;;;;;AAOrC,SAAgB,YAAY,SAAmB,WAAoB,OAAmE;CACpI,IAAI,QAAQ,WAAW,GAAG,OAAO,CAAC;CAClC,MAAM,OAAO,QAAQ,KAAK,MAAM,WAAW,EAAE,IAAI,CAAC;CAElD,IAAI,SAAS,KAAK,OAAO,MAAM,MAAM,KAAA,CAAS,GAAG,OAAO,KAAK,KAAK,MAAM,oBAAC,OAAD;EAAO,MAAM;EAAI,WAAW,GAAG,QAAQ,SAAS;CAAI,CAAA,CAAC;CAC7H,MAAM,MAAM,QAAQ,O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S,EAAE;EACX,WAAW,IAAI;CACjB;CACA,OACE,qBAAC,OAAD;EAAK,WAAU;EAAf,UAAA;GACE,qBAAC,OAAD;IAAK,WAAU;IAAf,UAAA,CACG,KAAK,KAAK,GAAG,MACZ,qBAAC,QAAD;KAAwB,WAAU;KAAlC,UAAA,CACG,GACA,WAAW,OACV,oBAAC,UAAD;MAAQ,MAAK;MAAS,cAAY,UAAU;MAAK,eAAe,SAAS,KAAK,QAAQ,GAAG,MAAM,MAAM,CAAC,CAAC;MAAG,WAAU;MAClH,UAAA,oBAAC,OAAD;OAAO,WAAU;OAAS,QAAQ;MAAM,CAAA;KAClC,CAAA,CAEN;IAPK,GAAA,GAAG,EAAE,GAAG,GAOb,CACP,GACA,WAAW,OACV,oBAAC,SAAD;KACE,KAAK;KACD;KACJ,OAAO;KACP,UAAU;KACV,WAAW,MAAM;MACf,SAAS,EAAE,OAAO,KAAK;MACvB,IAAI,SAAS,WAAW,IAAI;KAC9B;KACA,cAAc;MACZ,IAAI;MACJ,SAAS;KACX;KACA,YAAY,MAAM;MAChB,IAAI,EAAE,QAAQ,WAAW,EAAE,QAAQ,KAAK;OACtC,EAAE,eAAe;OACjB,IAAI;MACN,OAAO,IAAI,EAAE,QAAQ,eAAe,CAAC,SAAS,KAAK,QAAQ,SAAS,KAAK,MAAM,GAAG,EAAE,CAAC;KACvF;KACA,aAAa,OAAO,KAAK,KAAK,SAAS,SAAS,MAAM,gBAAgB,gBAAgB,IAAI,yBAAyB;KACnH,WAAU;IACX,CAAA,CAEA;;GACJ,WAAW,CAAC,WACX,oBAAC,QAAD;IAAM,IAAI;IAAU,MAAK;IAAS,aAAU;IAAS,WAAU;IAC5D,UAAA;GACG,CAAA,IACJ;GACH,QAAQ,CAAC,WAAW,oBAAC,WAAD,EAAgB,IAAO,CAAA,IAAI;EAC7C;;AAET"}
1
+ {"version":3,"file":"choice.js","names":[],"sources":["../../src/controls/choice.tsx"],"sourcesContent":["/**\n * CHOICE — boolean · select · multiselect · tags (V2 HEAD 9829bf1 kit/controls/choice.tsx, DESIGN 8.10–8.12).\n * Rule (production): few options → segmented, many → dropdown, many values → checkboxes, on/off → switch card.\n * D46: `layout: \"segmented\"` is a request, not a promise. With 4+ options, or labels that would wrap or truncate\n * in a 340px inspector (`fitsSegmented`), it renders the dropdown instead, so every schema follows the rule.\n *\n * Values are the ones production stores, untouched by any adapter (schema.ts plans them AS_IS): boolean, the option's\n * string, a string[] of option values, a string[] of tags. Tags are written the way the backend judges them\n * (tagsValueProblem: trimmed, case-insensitively unique, at most TAG_VALUE_MAX_LENGTH characters), and a tag the\n * control will not add says why under the box instead of vanishing.\n *\n * Option icons are all or none per list (the schema adapter's rule): a list draws icons only when every option names an\n * icon that can be drawn, so labels stay aligned and no option gets a stand-in glyph. The host's glyphs come first\n * (KitServices.IconGlyph, the BetterCMS set the site renders: every stored option icon is one of its names); with no\n * host renderer, the kit's own drawn icons.\n */\nimport * as React from \"react\";\nimport { IconCheck, IconPlus, IconX } from \"@tabler/icons-react\";\nimport { Checkbox, Segmented, Switch } from \"../ui/controls\";\nimport { Popover, PopoverContent, PopoverTrigger } from \"../ui/overlay\";\nimport { Select } from \"../ui/select\";\nimport { fitsSegmented } from \"../ui/choice-switch\";\nimport { shortcutHintsOn } from \"../ui/shortcut-hint\";\nimport { cn } from \"../lib/cn\";\nimport { KitIcon, iconKey } from \"../lib/icons\";\nimport type { Option } from \"../schema/types\";\nimport { useKitEnv, useKitServices, type KitServices } from \"../context\";\nimport { dockIconOf } from \"../adapters/icons\";\nimport type { ControlProps } from \"../types\";\nimport { TAG_VALUE_MAX_LENGTH } from \"../adapters/prod-types\";\nimport { UnknownValueNote } from \"./unknown-value\";\n\nconst str = (v: unknown) => (typeof v === \"string\" ? v : v == null ? \"\" : String(v));\nconst opts = (o?: Option[]) => o ?? [];\n\n/**\n * Icons for a list: every option's icon when all of them resolve, otherwise none (never a fallback glyph). `Glyph` is\n * the host's renderer (KitServices.IconGlyph): it draws every BetterCMS icon name (the option's kit name read back\n * through dockIconOf); without it, or when a name is not in that set, the kit's own drawn icons.\n */\nexport function optionIcons(options: Option[], className?: string, Glyph?: KitServices[\"IconGlyph\"]): (React.ReactNode | undefined)[] {\n if (options.length === 0) return [];\n const dock = options.map((o) => dockIconOf(o.icon));\n // a block box, as the kit's own <svg> is under preflight: an inline glyph would sit on a line box and grow the row\n if (Glyph && dock.every((n) => n !== undefined)) return dock.map((n) => <Glyph name={n!} className={cn(\"flex\", className)} />);\n const all = options.every((o) => iconKey(o.icon) !== undefined);\n return options.map((o) => (all ? <KitIcon name={o.icon} className={className} /> : undefined));\n}\n\n/** The limit sentence (DESIGN 8.12), shared by multiselect and tags. */\nfunction LimitLine({ max }: { max: number }) {\n return <span className=\"px-0.5 text-kit-xs text-kit-fg-3\">That's the limit of {max}. Remove one to add another.</span>;\n}\n\n/**\n * Roving focus for a radiogroup of buttons (WAI-ARIA radio group, as Segmented does): Tab lands on the selected option\n * (or the first), arrows move and select, Home / End jump.\n */\nfunction useRadioKeys(values: string[], current: string, onPick: (v: string) => void, readOnly?: boolean) {\n const focusable = values.includes(current) ? current : values[0];\n const onKeyDown = (e: React.KeyboardEvent, i: number) => {\n if (readOnly || !values.length) return;\n const n = values.length;\n const next =\n e.key === \"ArrowRight\" || e.key === \"ArrowDown\"\n ? (i + 1) % n\n : e.key === \"ArrowLeft\" || e.key === \"ArrowUp\"\n ? (i - 1 + n) % n\n : e.key === \"Home\"\n ? 0\n : e.key === \"End\"\n ? n - 1\n : -1;\n if (next < 0) return;\n e.preventDefault();\n onPick(values[next]);\n const group = (e.currentTarget as HTMLElement).closest(\"[role=radiogroup]\");\n group?.querySelector<HTMLElement>(`[data-choice-value=\"${CSS.escape(values[next])}\"]`)?.focus();\n };\n return { tabIndexOf: (v: string) => (v === focusable ? 0 : -1), onKeyDown };\n}\n\n/**\n * Adds or removes one id of the control's own in aria-describedby, leaving the ids FieldShell wires (help, issue)\n * in place (as ScaleSlider does).\n */\nexport function useOwnDescription(ref: React.RefObject<HTMLElement | null>, ownId: string | null) {\n const last = React.useRef<string | null>(null);\n React.useEffect(() => {\n const el = ref.current;\n if (!el) return;\n const ids = (el.getAttribute(\"aria-describedby\") ?? \"\").split(\" \").filter((t) => t && t !== last.current && t !== ownId);\n if (ownId) ids.push(ownId);\n if (ids.length) el.setAttribute(\"aria-describedby\", ids.join(\" \"));\n else el.removeAttribute(\"aria-describedby\");\n last.current = ownId;\n });\n}\n\n/** Boolean switch (used inside the switch card the shell draws). Commits immediately. */\nexport function BooleanControl({ field, value, onChange, readOnly, id }: ControlProps) {\n if (field.layout === \"checkbox\")\n return <Checkbox id={id} checked={Boolean(value)} disabled={readOnly} onCheckedChange={(c) => onChange(c === true)} aria-label={field.title} nativeButton render={<button type=\"button\" />} />;\n /* V2's switch is a native <button role=\"switch\"> (Radix); Base UI draws a <span> unless asked for the button */\n return <Switch id={id} checked={Boolean(value)} disabled={readOnly} onCheckedChange={(c) => onChange(c)} aria-label={field.title} nativeButton render={<button type=\"button\" />} />;\n}\n\n/**\n * A stored value none of the options names any more (renamed or removed) is kept and flagged under the control, with\n * change-to and remove (H4). @see UnknownValueNote\n */\nexport function SelectControl(props: ControlProps) {\n const options = opts(props.field.options);\n const v = str(props.value);\n if (v === \"\" || options.length === 0 || options.some((o) => o.value === v)) return <SelectInput {...props} />;\n return (\n <div className=\"flex min-w-0 flex-col gap-1.5\">\n <SelectInput {...props} />\n <UnknownValueNote\n items={[{ key: v, label: `“${v}”`, options: options.map((o) => ({ value: o.value, label: o.label })) }]}\n onRemap={(_, to) => props.onChange(to)}\n onRemove={() => props.onChange(null)}\n readOnly={props.readOnly}\n />\n </div>\n );\n}\n\nfunction SelectInput({ field, value, onChange, readOnly, id }: ControlProps) {\n const { variant } = useKitEnv();\n const { IconGlyph } = useKitServices();\n const options = opts(field.options);\n const v = str(value);\n const fits = fitsSegmented(options.map((o) => o.label));\n const layout = field.layout ?? (fits ? \"segmented\" : \"dropdown\");\n const pick = (n: string) => {\n if (!readOnly && n !== v) onChange(n);\n };\n const keys = useRadioKeys(\n options.map((o) => o.value),\n v,\n pick,\n readOnly,\n );\n\n if (layout === \"segmented\" && fits) {\n const icons = optionIcons(options, \"size-3.5\", IconGlyph);\n return (\n <Segmented\n aria-label={field.title}\n value={v}\n onChange={pick}\n items={options.map((o, i) => ({ value: o.value, label: o.label, icon: icons[i], disabled: readOnly }))}\n className=\"w-full [&>button]:min-w-0 [&>button]:flex-1\"\n />\n );\n }\n if (layout === \"radio\")\n return (\n <div role=\"radiogroup\" id={id} aria-label={field.title} className=\"flex flex-col gap-0.5\">\n {options.map((o, i) => (\n <button\n key={o.value}\n type=\"button\"\n role=\"radio\"\n data-choice-value={o.value}\n aria-checked={o.value === v}\n tabIndex={keys.tabIndexOf(o.value)}\n disabled={readOnly}\n onClick={() => pick(o.value)}\n onKeyDown={(e) => keys.onKeyDown(e, i)}\n className=\"flex items-start gap-2.5 rounded-kit-md px-1.5 py-1.5 text-left hover:bg-kit-hover\"\n >\n <span className={cn(\"mt-0.5 flex size-4 shrink-0 items-center justify-center rounded-full border transition-colors\", o.value === v ? \"border-kit-accent\" : \"border-kit-line-strong\")}>\n {o.value === v ? <span className=\"size-2 rounded-full bg-kit-accent\" /> : null}\n </span>\n <span className=\"min-w-0\">\n <span className=\"block text-kit-sm text-kit-fg\">{o.label}</span>\n {o.description ? <span className=\"block text-kit-xs text-kit-fg-3\">{o.description}</span> : null}\n </span>\n </button>\n ))}\n </div>\n );\n if (layout === \"cards\" || layout === \"grid\") {\n /* V2 draws the icon itself as the button's first child (no wrapper), coloured by the selected state */\n const iconsOn = optionIcons(options, \"size-4 text-kit-fg\", IconGlyph);\n const iconsOff = optionIcons(options, \"size-4 text-kit-fg-3\", IconGlyph);\n return (\n <div role=\"radiogroup\" id={id} aria-label={field.title} className={cn(\"grid gap-1.5\", variant === \"document\" ? \"grid-cols-3\" : \"grid-cols-2\")}>\n {options.map((o, i) => {\n const on = o.value === v;\n return (\n <button\n key={o.value}\n type=\"button\"\n role=\"radio\"\n data-choice-value={o.value}\n aria-checked={on}\n tabIndex={keys.tabIndexOf(o.value)}\n disabled={readOnly}\n onClick={() => pick(o.value)}\n onKeyDown={(e) => keys.onKeyDown(e, i)}\n className={cn(\n \"relative flex flex-col items-start gap-1.5 rounded-kit-lg border p-2.5 text-left transition-[border-color,box-shadow] duration-150\",\n on ? \"border-[var(--kit-emphasis-line)] bg-kit-control-bg shadow-kit-xs\" : \"border-kit-line hover:border-kit-line-strong\",\n )}\n >\n {(on ? iconsOn : iconsOff)[i] ?? null}\n <span className=\"text-kit-sm font-medium text-kit-fg\">{o.label}</span>\n {o.description ? <span className=\"text-kit-xs leading-4 text-kit-fg-3\">{o.description}</span> : null}\n {on ? <IconCheck aria-hidden className=\"absolute right-2 top-2 size-3.5 text-kit-fg\" stroke={2} /> : null}\n </button>\n );\n })}\n </div>\n );\n }\n const icons = optionIcons(options, undefined, IconGlyph);\n return (\n <Select\n id={id}\n aria-label={field.title}\n size={variant === \"document\" ? \"lg\" : \"md\"}\n value={v || undefined}\n disabled={readOnly}\n onValueChange={pick}\n placeholder={field.placeholder ?? \"Select…\"}\n options={options.map((o, i) => ({ value: o.value, label: o.label, description: o.description, icon: icons[i] }))}\n />\n );\n}\n\n/** As `SelectControl`: each stored choice no option names any more is kept and flagged, with change-to and remove. */\nexport function MultiSelectControl(props: ControlProps) {\n const list = Array.isArray(props.value) ? (props.value as unknown[]).filter((x): x is string => typeof x === \"string\") : [];\n const options = opts(props.field.options);\n const unknown = options.length ? list.filter((x) => !options.some((o) => o.value === x)) : [];\n if (unknown.length === 0) return <MultiSelectInput {...props} />;\n return (\n <div className=\"flex min-w-0 flex-col gap-1.5\">\n <MultiSelectInput {...props} />\n <UnknownValueNote\n items={unknown.map((x) => ({ key: x, label: `“${x}”`, options: options.filter((o) => !list.includes(o.value)).map((o) => ({ value: o.value, label: o.label })) }))}\n onRemap={(from, to) => props.onChange(list.map((x) => (x === from ? to : x)))}\n onRemove={(from) => props.onChange(list.filter((x) => x !== from))}\n readOnly={props.readOnly}\n />\n </div>\n );\n}\n\nfunction MultiSelectInput({ field, value, onChange, readOnly, id }: ControlProps) {\n const list = Array.isArray(value) ? (value as unknown[]).filter((x): x is string => typeof x === \"string\") : [];\n const options = opts(field.options);\n const max = field.validation?.max;\n const full = max != null && list.length >= max;\n const toggle = (o: string) => {\n if (readOnly) return;\n if (list.includes(o)) onChange(list.filter((x) => x !== o));\n else if (!full) onChange([...list, o]);\n };\n const label = (val: string) => options.find((o) => o.value === val)?.label ?? val;\n /* V2 draws the control bare; the limit line (ours: say why the next pick is refused) wraps it only while it shows */\n const withLimit = (body: React.ReactElement) =>\n full && !readOnly ? (\n <div className=\"flex flex-col gap-1\">\n {body}\n <LimitLine max={max!} />\n </div>\n ) : (\n body\n );\n if (field.layout === \"checkbox\" || field.layout === \"list\")\n return withLimit(\n <>\n <div id={id} role=\"group\" aria-label={field.title} className=\"flex flex-col gap-0.5\">\n {options.map((o) => {\n const on = list.includes(o.value);\n return (\n <label key={o.value} className={cn(\"flex cursor-pointer items-center gap-2.5 rounded-kit-md px-1.5 py-1.5 hover:bg-kit-hover\", !on && full && \"cursor-not-allowed hover:bg-transparent\")}>\n <Checkbox checked={on} disabled={readOnly || (!on && full)} onCheckedChange={() => toggle(o.value)} nativeButton render={<button type=\"button\" />} />\n <span className=\"text-kit-sm text-kit-fg\">{o.label}</span>\n </label>\n );\n })}\n </div>\n </>,\n );\n return withLimit(\n <>\n <Popover>\n {/* read-only there is no trigger to carry the field id, so the chip row is the named group */}\n <div\n id={readOnly ? id : undefined}\n role={readOnly ? \"group\" : undefined}\n aria-label={readOnly ? field.title : undefined}\n className=\"flex min-h-8 flex-wrap items-center gap-1 rounded-kit-md border border-kit-line-strong bg-kit-field-bg p-1 transition-colors hover:border-kit-line-strong\"\n >\n {list.map((o) => (\n <span key={o} className=\"inline-flex h-6 items-center gap-1 rounded-kit-md border border-kit-line bg-kit-control-bg pl-2 pr-1 text-kit-sm text-kit-fg shadow-kit-xs\">\n {label(o)}\n {readOnly ? null : (\n <button type=\"button\" aria-label={`Remove ${label(o)}`} onClick={() => toggle(o)} className=\"flex rounded-kit-md p-0.5 text-kit-fg-3 hover:bg-kit-hover hover:text-kit-fg\">\n <IconX className=\"size-3\" stroke={1.5} />\n </button>\n )}\n </span>\n ))}\n {readOnly ? null : (\n <PopoverTrigger id={id} className=\"inline-flex h-6 items-center gap-1 rounded-kit-md px-1.5 text-kit-sm text-kit-fg-3 hover:bg-kit-hover hover:text-kit-fg\">\n <IconPlus aria-hidden className=\"size-3.5\" stroke={1.5} />\n {list.length ? \"Add\" : field.placeholder ?? \"Choose…\"}\n </PopoverTrigger>\n )}\n </div>\n <PopoverContent className=\"w-60 p-1\">\n <div role=\"group\" aria-label={field.title}>\n {options.map((o) => {\n const on = list.includes(o.value);\n const blocked = !on && full;\n return (\n <button\n key={o.value}\n type=\"button\"\n role=\"checkbox\"\n aria-checked={on}\n disabled={blocked}\n onClick={() => toggle(o.value)}\n className={cn(\"flex h-8 w-full items-center gap-2 rounded-kit-md px-2 text-left text-kit-sm hover:bg-kit-hover\", blocked && \"opacity-40 hover:bg-transparent\")}\n >\n <span className={cn(\"flex size-4 items-center justify-center rounded-kit-md border\", on ? \"border-kit-accent bg-kit-accent text-kit-accent-on\" : \"border-kit-line-strong\")}>\n {on ? <IconCheck aria-hidden className=\"size-3\" stroke={3} /> : null}\n </span>\n {o.label}\n </button>\n );\n })}\n </div>\n {full ? <div className=\"px-2 pb-1 pt-1.5\"><LimitLine max={max!} /></div> : null}\n </PopoverContent>\n </Popover>\n </>,\n );\n}\n\n/** Why a typed tag is not added, or null when it is (the backend's own checks, said in words). */\nexport function tagRefusal(tag: string, list: string[]): string | null {\n if (Array.from(tag).length > TAG_VALUE_MAX_LENGTH) return `A tag can be up to ${TAG_VALUE_MAX_LENGTH} characters.`;\n const folded = tag.toLowerCase();\n const twin = list.find((t) => t.trim().toLowerCase() === folded);\n if (twin !== undefined) return `\"${twin}\" is already a tag.`;\n return null;\n}\n\n/** Chip input. Says so at its limit, and says why a tag was not added, instead of silently dropping it. */\nexport function TagsControl({ field, value, onChange, readOnly, id, onBlur }: ControlProps) {\n const list = Array.isArray(value) ? (value as unknown[]).map((x) => str(x)) : [];\n const [draft, setDraft] = React.useState(\"\");\n const [refusal, setRefusal] = React.useState<string | null>(null);\n const reasonId = React.useId();\n const inputRef = React.useRef<HTMLInputElement>(null);\n useOwnDescription(inputRef, refusal ? reasonId : null);\n const max = field.validation?.max;\n const full = max != null && list.length >= max;\n const add = () => {\n const t = draft.trim().replace(/,$/, \"\").trim();\n if (!t || full) {\n setDraft(\"\");\n setRefusal(null);\n return;\n }\n const why = tagRefusal(t, list);\n if (why) {\n // keep the text so it can be fixed; the reason reads under the box\n setRefusal(why);\n return;\n }\n onChange([...list, t]);\n setDraft(\"\");\n setRefusal(null);\n };\n return (\n <div className=\"flex flex-col gap-1\">\n <div className=\"flex min-h-8 flex-wrap items-center gap-1 rounded-kit-md border border-kit-line-strong bg-kit-field-bg p-1 transition-colors focus-within:border-kit-line-strong focus-within:bg-kit-field-bg hover:border-kit-line-strong\">\n {list.map((t, i) => (\n <span key={`${t}-${i}`} className=\"inline-flex h-6 items-center gap-1 rounded-kit-md bg-kit-selected pl-2 pr-1 text-kit-sm text-kit-fg\">\n {t}\n {readOnly ? null : (\n <button type=\"button\" aria-label={`Remove ${t}`} onClick={() => onChange(list.filter((_, j) => j !== i))} className=\"flex rounded-kit-md p-0.5 text-kit-fg-3 hover:bg-kit-hover hover:text-kit-fg\">\n <IconX className=\"size-3\" stroke={1.5} />\n </button>\n )}\n </span>\n ))}\n {readOnly ? null : (\n <input\n ref={inputRef}\n id={id}\n value={draft}\n disabled={full}\n onChange={(e) => {\n setDraft(e.target.value);\n if (refusal) setRefusal(null);\n }}\n onBlur={() => {\n add();\n onBlur?.();\n }}\n onKeyDown={(e) => {\n if (e.key === \"Enter\" || e.key === \",\") {\n e.preventDefault();\n add();\n } else if (e.key === \"Backspace\" && !draft && list.length) onChange(list.slice(0, -1));\n }}\n placeholder={full ? \"\" : list.length ? \"Add…\" : field.placeholder ?? (shortcutHintsOn() ? \"Type and press Enter\" : \"Add…\")}\n className=\"h-6 min-w-20 flex-1 bg-transparent px-1.5 text-kit-sm text-kit-fg outline-none placeholder:text-kit-fg-3\"\n />\n )}\n </div>\n {refusal && !readOnly ? (\n <span id={reasonId} role=\"status\" aria-live=\"polite\" className=\"px-0.5 text-kit-xs text-kit-fg-3\">\n {refusal}\n </span>\n ) : null}\n {full && !readOnly ? <LimitLine max={max!} /> : null}\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCA,IAAM,OAAO,MAAgB,OAAO,MAAM,WAAW,IAAI,KAAK,OAAO,KAAK,OAAO,CAAC;AAClF,IAAM,QAAQ,MAAiB,KAAK,CAAC;;;;;;AAOrC,SAAgB,YAAY,SAAmB,WAAoB,OAAmE;CACpI,IAAI,QAAQ,WAAW,GAAG,OAAO,CAAC;CAClC,MAAM,OAAO,QAAQ,KAAK,MAAM,WAAW,EAAE,IAAI,CAAC;CAElD,IAAI,SAAS,KAAK,OAAO,MAAM,MAAM,KAAA,CAAS,GAAG,OAAO,KAAK,KAAK,MAAM,oBAAC,OAAD;EAAO,MAAM;EAAI,WAAW,GAAG,QAAQ,SAAS;CAAI,CAAA,CAAC;CAC7H,MAAM,MAAM,QAAQ,OAAO,MAAM,QAAQ,EAAE,IAAI,MAAM,KAAA,CAAS;CAC9D,OAAO,QAAQ,KAAK,MAAO,MAAM,oBAAC,SAAD;EAAS,MAAM,EAAE;EAAiB;CAAY,CAAA,IAAI,KAAA,CAAU;AAC/F;;AAGA,SAAS,UAAU,EAAE,OAAwB;CAC3C,OAAO,qBAAC,QAAD;EAAM,WAAU;EAAhB,UAAA;GAAmD;GAAqB;GAAI;EAAkC;;AACvH;;;;;AAMA,SAAS,aAAa,QAAkB,SAAiB,QAA6B,UAAoB;CACxG,MAAM,YAAY,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;OAAO,WAAU;OAAS,QAAQ;MAAM,CAAA;KAClC,CAAA,CAEN;IAPK,GAAA,GAAG,EAAE,GAAG,GAOb,CACP,GACA,WAAW,OACV,oBAAC,SAAD;KACE,KAAK;KACD;KACJ,OAAO;KACP,UAAU;KACV,WAAW,MAAM;MACf,SAAS,EAAE,OAAO,KAAK;MACvB,IAAI,SAAS,WAAW,IAAI;KAC9B;KACA,cAAc;MACZ,IAAI;MACJ,SAAS;KACX;KACA,YAAY,MAAM;MAChB,IAAI,EAAE,QAAQ,WAAW,EAAE,QAAQ,KAAK;OACtC,EAAE,eAAe;OACjB,IAAI;MACN,OAAO,IAAI,EAAE,QAAQ,eAAe,CAAC,SAAS,KAAK,QAAQ,SAAS,KAAK,MAAM,GAAG,EAAE,CAAC;KACvF;KACA,aAAa,OAAO,KAAK,KAAK,SAAS,SAAS,MAAM,gBAAgB,gBAAgB,IAAI,yBAAyB;KACnH,WAAU;IACX,CAAA,CAEA;;GACJ,WAAW,CAAC,WACX,oBAAC,QAAD;IAAM,IAAI;IAAU,MAAK;IAAS,aAAU;IAAS,WAAU;IAC5D,UAAA;GACG,CAAA,IACJ;GACH,QAAQ,CAAC,WAAW,oBAAC,WAAD,EAAgB,IAAO,CAAA,IAAI;EAC7C;;AAET"}
@@ -210,7 +210,7 @@ function CodeDialogField({ kind, title, description, text, readOnly, id, invalid
210
210
  setRefusal(null);
211
211
  setOpen(true);
212
212
  },
213
- className: cn("group/code flex w-full items-center gap-2 rounded-kit-md border border-kit-field-border bg-kit-subtle px-2.5 py-2 text-left transition-colors hover:border-kit-field-border-hover", invalid && "border-[var(--kit-field-invalid)]"),
213
+ className: cn("group/code flex w-full items-center gap-2 rounded-kit-md border border-kit-line bg-kit-subtle px-2.5 py-2 text-left transition-colors hover:border-kit-line-strong", invalid && "border-[var(--kit-field-invalid)]"),
214
214
  children: [
215
215
  /* @__PURE__ */ jsx(Icon, {
216
216
  className: "size-4 shrink-0 text-kit-fg-3",
@@ -1 +1 @@
1
- {"version":3,"file":"code.js","names":[],"sources":["../../src/controls/code.tsx"],"sourcesContent":["/**\n * CODE — the code field (DESIGN 8.21), V2 controls/misc.tsx (CodeSurface, CodeControl) fitted to what prod stores.\n *\n * Values (backend reference-validation `code`, adapters/values.ts codeToProd):\n * \"<p>hi</p>\" a bare string, kept a string\n * { language?: \"html\", code: \"…\" } the object form; only `code` and `language` are written back\n * The language list sits in the surface header. Picking one writes the object form; a value that never changes its\n * language keeps the shape it was stored in. A value over CODE_MAX_LENGTH characters is refused with the reason.\n *\n * Panel: a one-line summary button that opens a `lg` dialog editing a draft (Cancel / Done). Document: the surface\n * inline. The surface: mono 12/20 textarea with line numbers, Tab inserts two spaces (Shift+Tab leaves the field),\n * Copy, and for JSON a Format action and a live \"Invalid JSON · {reason}\" footer (json.tsx).\n */\nimport * as React from \"react\";\nimport { IconAlertTriangle, IconBraces, IconCode, IconMaximize } from \"@tabler/icons-react\";\nimport { cn } from \"../lib/cn\";\nimport { isObj } from \"../lib/path\";\nimport { useKitEnv, useKitServices } from \"../context\";\nimport { CODE_MAX_LENGTH } from \"../adapters/prod-types\";\nimport type { ControlProps } from \"../types\";\nimport { Button } from \"../ui/button\";\nimport { Modal, ModalBody, ModalContent, ModalFooter, ModalHeader } from \"../ui/overlay\";\nimport { Select } from \"../ui/select\";\n\nconst CODE_LANGUAGES: { value: string; label: string }[] = [\n { value: \"html\", label: \"HTML\" },\n { value: \"css\", label: \"CSS\" },\n { value: \"js\", label: \"JS\" },\n { value: \"ts\", label: \"TS\" },\n { value: \"json\", label: \"JSON\" },\n { value: \"liquid\", label: \"Liquid\" },\n { value: \"markdown\", label: \"Markdown\" },\n { value: \"shell\", label: \"Shell\" },\n];\nconst PLAIN = \"plain\";\n\n/** The picker: Plain text, then the field's allowed languages (or the built-in list), then the stored one if it is outside them. */\nfunction languageOptions(language: string | undefined, allowed: string[] | undefined) {\n const list = allowed ? allowed.map((v) => CODE_LANGUAGES.find((l) => l.value === v) ?? { value: v, label: v }) : CODE_LANGUAGES;\n return [{ value: PLAIN, label: \"Plain text\" }, ...list, ...(language && !list.some((l) => l.value === language) ? [{ value: language, label: language }] : [])];\n}\n\n/** Why a JSON text does not parse (\"\" when it does, or is empty). */\nexport function jsonProblem(text: string): string {\n if (!text.trim()) return \"\";\n try {\n JSON.parse(text);\n return \"\";\n } catch (e) {\n return (e as Error).message.replace(/^JSON\\.parse: /, \"\");\n }\n}\n\n/* ── The surface ──────────────────────────────────────────────────────── */\nexport interface CodeSurfaceProps {\n /** \"json\": the JSON header, Format and the parse footer. \"code\": the language list. */\n kind: \"json\" | \"code\";\n value: string;\n onChange: (v: string) => void;\n /** code: the language shown in the header (\"\" = none) and what picking one does; absent = no list */\n language?: string;\n onLanguage?: (language: string) => void;\n /** code: the only languages the field allows (its config.languages); absent = the built-in list */\n languages?: string[];\n readOnly?: boolean;\n id?: string;\n invalid?: boolean;\n minRows?: number;\n label?: string;\n describedBy?: string;\n /** The host's own findings, a line each (V2 Schema editor WP3). Given, they replace the built-in check: their lines are\n * marked in the gutter and the messages list under the code. */\n diagnostics?: { line?: number; message: string; hint?: string }[];\n /** The host's own header actions, before Format and Copy. */\n actions?: React.ReactNode;\n}\n\nexport function CodeSurface({ kind, value, onChange, language, onLanguage, languages, readOnly, id, invalid, minRows = 8, label, describedBy, diagnostics, actions }: CodeSurfaceProps) {\n const { toast } = useKitServices();\n const lines = Math.max(minRows, value.split(\"\\n\").length);\n const marked = new Set((diagnostics ?? []).map((d) => d.line).filter((n): n is number => !!n));\n const problem = diagnostics ? \"\" : kind === \"json\" ? jsonProblem(value) : value.length > CODE_MAX_LENGTH ? `Code can hold up to ${CODE_MAX_LENGTH.toLocaleString(\"en-US\")} characters; this has ${value.length.toLocaleString(\"en-US\")}.` : \"\";\n const flagged = !!problem || !!diagnostics?.length;\n const footerId = id ? `${id}-problem` : undefined;\n const format = () => {\n try {\n onChange(JSON.stringify(JSON.parse(value), null, 2));\n toast?.success(\"JSON formatted\");\n } catch {\n toast?.(\"Fix the JSON before formatting\");\n }\n };\n const copy = () => {\n void navigator.clipboard?.writeText(value);\n toast?.success(\"Copied\");\n };\n return (\n <div className={cn(\"overflow-hidden rounded-kit-lg border bg-kit-subtle\", invalid || flagged ? \"border-[var(--kit-field-invalid)]\" : \"border-kit-line\")}>\n <div className=\"flex h-8 items-center justify-between border-b border-kit-line px-2\">\n {kind === \"json\" ? (\n <span className=\"px-1 font-kit-mono text-kit-xs text-kit-fg-3\">{label ?? \"JSON\"}</span>\n ) : onLanguage ? (\n <Select\n aria-label=\"Code language\"\n size=\"sm\"\n variant=\"ghost\"\n disabled={readOnly}\n value={language || PLAIN}\n onValueChange={(l) => onLanguage(l === PLAIN ? \"\" : l)}\n options={languageOptions(language, languages)}\n />\n ) : (\n <span className=\"px-1 font-kit-mono text-kit-xs text-kit-fg-3\">Code</span>\n )}\n <div className=\"flex items-center gap-1\">\n {actions}\n {kind === \"json\" ? (\n <button type=\"button\" disabled={readOnly} className=\"rounded-kit-md px-1.5 py-0.5 text-kit-xs text-kit-fg-2 hover:bg-kit-hover hover:text-kit-fg\" onClick={format}>\n Format\n </button>\n ) : null}\n <button type=\"button\" className=\"rounded-kit-md px-1.5 py-0.5 text-kit-xs text-kit-fg-2 hover:bg-kit-hover hover:text-kit-fg\" onClick={copy}>\n Copy\n </button>\n </div>\n </div>\n <div className=\"flex max-h-[60vh] overflow-auto font-kit-mono text-kit-xs leading-5\">\n <div aria-hidden className=\"select-none border-r border-kit-line bg-kit-subtle px-2 py-2 text-right text-kit-fg-4\">\n {Array.from({ length: lines }).map((_, i) => (\n <div key={i} className={marked.has(i + 1) ? \"bg-kit-danger-soft text-kit-danger-fg\" : undefined}>\n {i + 1}\n </div>\n ))}\n </div>\n <textarea\n id={id}\n spellCheck={false}\n autoCapitalize=\"off\"\n autoCorrect=\"off\"\n value={value}\n readOnly={readOnly}\n aria-invalid={invalid || flagged || undefined}\n aria-label={label}\n aria-describedby={[describedBy, flagged ? footerId : undefined].filter(Boolean).join(\" \") || undefined}\n onChange={(e) => onChange(e.target.value)}\n onKeyDown={(e) => {\n if (e.key === \"Tab\" && !e.shiftKey && !readOnly) {\n e.preventDefault();\n const el = e.currentTarget;\n const s = el.selectionStart;\n onChange(value.slice(0, s) + \" \" + value.slice(el.selectionEnd));\n requestAnimationFrame(() => el.setSelectionRange(s + 2, s + 2));\n }\n }}\n style={{ height: lines * 20 + 16 }}\n className=\"min-w-0 flex-1 resize-none bg-kit-field-bg px-3 py-2 text-kit-fg outline-none\"\n />\n </div>\n {problem ? (\n <div id={footerId} className=\"border-t border-kit-danger-line bg-kit-danger-soft px-3 py-1.5 text-kit-xs text-kit-danger-fg\">\n {kind === \"json\" ? `Invalid JSON · ${problem}` : problem}\n </div>\n ) : diagnostics?.length ? (\n <ul id={footerId} className=\"flex flex-col gap-1 border-t border-kit-danger-line bg-kit-danger-soft px-3 py-1.5 text-kit-xs text-kit-danger-fg\">\n {diagnostics.map((d, i) => (\n <li key={i}>\n {d.message}\n {d.hint ? <span className=\"block font-kit-mono text-kit-fg-3\">{d.hint}</span> : null}\n </li>\n ))}\n </ul>\n ) : null}\n </div>\n );\n}\n\n/* ── Panel: summary button + dialog over a draft ─────────────────────── */\nexport function CodeDialogField({\n kind, title, description, text, readOnly, id, invalid, language, languages, onDone,\n}: {\n kind: \"json\" | \"code\";\n title: string;\n description?: string;\n text: string;\n readOnly?: boolean;\n id: string;\n invalid?: boolean;\n language?: string;\n languages?: string[];\n /** commit the draft; returns the reason it can't be saved, or null when saved */\n onDone: (draft: string, language: string | undefined) => string | null;\n}) {\n const { toast } = useKitServices();\n const [open, setOpen] = React.useState(false);\n const [draft, setDraft] = React.useState(text);\n const [lang, setLang] = React.useState(language);\n const [refusal, setRefusal] = React.useState<string | null>(null);\n const first = text.split(\"\\n\").find((l) => l.trim()) ?? \"\";\n const Icon = kind === \"json\" ? IconBraces : IconCode;\n return (\n <>\n <button\n id={id}\n type=\"button\"\n aria-haspopup=\"dialog\"\n aria-invalid={invalid || undefined}\n onClick={() => {\n setDraft(text);\n setLang(language);\n setRefusal(null);\n setOpen(true);\n }}\n className={cn(\n \"group/code flex w-full items-center gap-2 rounded-kit-md border border-kit-field-border bg-kit-subtle px-2.5 py-2 text-left transition-colors hover:border-kit-field-border-hover\",\n invalid && \"border-[var(--kit-field-invalid)]\",\n )}\n >\n <Icon className=\"size-4 shrink-0 text-kit-fg-3\" stroke={1.5} aria-hidden />\n <span className={cn(\"min-w-0 flex-1 truncate font-kit-mono text-kit-xs\", first ? \"text-kit-fg-2\" : \"text-kit-fg-3\")}>{first || \"Empty\"}</span>\n <span className=\"tabular-nums shrink-0 text-kit-2xs text-kit-fg-3\">{text ? `${text.split(\"\\n\").length} lines` : \"\"}</span>\n <IconMaximize className=\"size-3.5 shrink-0 text-kit-fg-3 group-hover/code:text-kit-fg\" stroke={1.5} aria-hidden />\n </button>\n <Modal open={open} onOpenChange={setOpen}>\n <ModalContent size=\"lg\">\n <ModalHeader title={title} description={description ?? (kind === \"json\" ? \"Structured data for developers\" : \"Custom code\")} />\n <ModalBody>\n <CodeSurface kind={kind} value={draft} onChange={setDraft} language={lang ?? \"\"} onLanguage={kind === \"code\" ? setLang : undefined} languages={languages} readOnly={readOnly} minRows={14} label={title} />\n {refusal ? (\n <p role=\"alert\" className=\"mt-2 flex items-start gap-1.5 text-kit-xs text-kit-danger-fg\">\n <IconAlertTriangle className=\"mt-0.5 size-3.5 shrink-0\" stroke={1.5} aria-hidden />\n {refusal}\n </p>\n ) : null}\n </ModalBody>\n <ModalFooter>\n <span data-hint=\"shortcuts\" className=\"text-kit-xs text-kit-fg-3\">\n Esc to close\n </span>\n <span className=\"mr-auto\" aria-hidden />\n <Button variant=\"ghost\" onClick={() => setOpen(false)}>\n Cancel\n </Button>\n <Button\n variant=\"primary\"\n disabled={readOnly}\n onClick={() => {\n const why = onDone(draft, lang);\n if (why) {\n setRefusal(why);\n toast?.(kind === \"json\" ? \"Invalid JSON\" : \"Can't save this code\", { description: \"Fix it before saving.\" });\n return;\n }\n setOpen(false);\n }}\n >\n Done\n </Button>\n </ModalFooter>\n </ModalContent>\n </Modal>\n </>\n );\n}\n\n/* ── The control ──────────────────────────────────────────────────────── */\ntype CodeRead = { ok: true; code: string; language?: string; object: boolean } | { ok: false };\nfunction readCode(v: unknown): CodeRead {\n if (v == null) return { ok: true, code: \"\", object: false };\n if (typeof v === \"string\") return { ok: true, code: v, object: false };\n if (isObj(v) && typeof v.code === \"string\" && (v.language === undefined || typeof v.language === \"string\")) return { ok: true, code: v.code, language: v.language as string | undefined, object: true };\n return { ok: false };\n}\n\n/** The stored shape for edited code: a string stays a string until a language is picked; the object keeps its form. */\nfunction codeValue(prev: CodeRead & { ok: true }, code: string, language: string | undefined): string | { language?: string; code: string } {\n const lang = language ?? prev.language ?? \"\";\n if (!prev.object && !lang) return code;\n return lang ? { language: lang, code } : { code };\n}\nconst tooLong = (code: string) => (code.length > CODE_MAX_LENGTH ? `Code can hold up to ${CODE_MAX_LENGTH.toLocaleString(\"en-US\")} characters; this has ${code.length.toLocaleString(\"en-US\")}.` : null);\n\nexport function CodeControl({ field, value, onChange, readOnly, id, invalid }: ControlProps) {\n const { variant } = useKitEnv();\n const [refused, setRefused] = React.useState<string | null>(null);\n const read = readCode(value);\n if (!read.ok) return <UnreadableValue id={id} title={field.title} kind=\"code\" value={value} />;\n if (variant === \"document\")\n return (\n <div className=\"flex flex-col gap-1.5\">\n <CodeSurface\n kind=\"code\"\n id={id}\n invalid={invalid || !!refused}\n readOnly={readOnly}\n value={read.code}\n language={read.language ?? \"\"}\n languages={field.languages}\n onChange={(code) => {\n const why = tooLong(code);\n setRefused(why);\n if (!why) onChange(codeValue(read, code, undefined));\n }}\n onLanguage={(l) => onChange(codeValue(read, read.code, l))}\n />\n {refused ? (\n <p role=\"alert\" className=\"text-kit-xs text-kit-danger-fg\">\n {refused}\n </p>\n ) : null}\n </div>\n );\n return (\n <CodeDialogField\n kind=\"code\"\n id={id}\n title={field.title}\n description={field.description || undefined}\n text={read.code}\n language={read.language}\n languages={field.languages}\n readOnly={readOnly}\n invalid={invalid}\n onDone={(draft, lang) => {\n const why = tooLong(draft);\n if (why) return why;\n const next = codeValue(read, draft, lang);\n if (draft !== read.code || (lang ?? \"\") !== (read.language ?? \"\")) onChange(next);\n return null;\n }}\n />\n );\n}\n\n/** A stored value the control cannot read: named, shown, kept as it is (never replaced by a stray edit). */\nexport function UnreadableValue({ id, title, kind, value }: { id: string; title: string; kind: string; value: unknown }) {\n let raw: string;\n try {\n raw = typeof value === \"string\" ? value : JSON.stringify(value, null, 2);\n } catch {\n raw = String(value);\n }\n return (\n <output\n id={id}\n tabIndex={0}\n data-slot={`${kind}-unreadable`}\n className=\"flex min-w-0 items-start gap-2 rounded-kit-md border border-dashed border-kit-line-strong bg-kit-subtle px-2.5 py-2 text-kit-xs text-kit-fg-2 outline-none focus-visible:outline-2 focus-visible:outline-kit-focus-ring\"\n >\n <IconAlertTriangle className=\"mt-0.5 size-3.5 shrink-0 text-kit-warning-fg\" stroke={1.5} aria-hidden />\n <span className=\"min-w-0\">\n {title} holds a value this {kind} editor can't read, so it is kept as it is:{\" \"}\n <span className=\"block max-h-24 overflow-auto whitespace-pre-wrap break-all font-kit-mono text-kit-fg\">{raw}</span>\n </span>\n </output>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAwBA,IAAM,iBAAqD;CACzD;EAAE,OAAO;EAAQ,OAAO;CAAO;CAC/B;EAAE,OAAO;EAAO,OAAO;CAAM;CAC7B;EAAE,OAAO;EAAM,OAAO;CAAK;CAC3B;EAAE,OAAO;EAAM,OAAO;CAAK;CAC3B;EAAE,OAAO;EAAQ,OAAO;CAAO;CAC/B;EAAE,OAAO;EAAU,OAAO;CAAS;CACnC;EAAE,OAAO;EAAY,OAAO;CAAW;CACvC;EAAE,OAAO;EAAS,OAAO;CAAQ;AACnC;AACA,IAAM,QAAQ;;AAGd,SAAS,gBAAgB,UAA8B,SAA+B;CACpF,MAAM,OAAO,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;CACJ,IAAI;EACF,MAAM,OAAO,UAAU,WAAW,QAAQ,KAAK,UAAU,OAAO,MAAM,CAAC;CACzE,QAAQ;EACN,MAAM,OAAO,KAAK;CACpB;CACA,OACE,qBAAC,UAAD;EACM;EACJ,UAAU;EACV,aAAW,GAAG,KAAK;EACnB,WAAU;EAJZ,UAAA,CAME,oBAAC,mBAAD;GAAmB,WAAU;GAA+C,QAAQ;GAAK,eAAA;EAAa,CAAA,GACtG,qBAAC,QAAD;GAAM,WAAU;GAAhB,UAAA;IACG;IAAM;IAAqB;IAAK;IAA4C;IAC7E,oBAAC,QAAD;KAAM,WAAU;KAAwF,UAAA;IAAU,CAAA;GAC9G;EACA,CAAA,CAAA;;AAEZ"}
1
+ {"version":3,"file":"code.js","names":[],"sources":["../../src/controls/code.tsx"],"sourcesContent":["/**\n * CODE — the code field (DESIGN 8.21), V2 controls/misc.tsx (CodeSurface, CodeControl) fitted to what prod stores.\n *\n * Values (backend reference-validation `code`, adapters/values.ts codeToProd):\n * \"<p>hi</p>\" a bare string, kept a string\n * { language?: \"html\", code: \"…\" } the object form; only `code` and `language` are written back\n * The language list sits in the surface header. Picking one writes the object form; a value that never changes its\n * language keeps the shape it was stored in. A value over CODE_MAX_LENGTH characters is refused with the reason.\n *\n * Panel: a one-line summary button that opens a `lg` dialog editing a draft (Cancel / Done). Document: the surface\n * inline. The surface: mono 12/20 textarea with line numbers, Tab inserts two spaces (Shift+Tab leaves the field),\n * Copy, and for JSON a Format action and a live \"Invalid JSON · {reason}\" footer (json.tsx).\n */\nimport * as React from \"react\";\nimport { IconAlertTriangle, IconBraces, IconCode, IconMaximize } from \"@tabler/icons-react\";\nimport { cn } from \"../lib/cn\";\nimport { isObj } from \"../lib/path\";\nimport { useKitEnv, useKitServices } from \"../context\";\nimport { CODE_MAX_LENGTH } from \"../adapters/prod-types\";\nimport type { ControlProps } from \"../types\";\nimport { Button } from \"../ui/button\";\nimport { Modal, ModalBody, ModalContent, ModalFooter, ModalHeader } from \"../ui/overlay\";\nimport { Select } from \"../ui/select\";\n\nconst CODE_LANGUAGES: { value: string; label: string }[] = [\n { value: \"html\", label: \"HTML\" },\n { value: \"css\", label: \"CSS\" },\n { value: \"js\", label: \"JS\" },\n { value: \"ts\", label: \"TS\" },\n { value: \"json\", label: \"JSON\" },\n { value: \"liquid\", label: \"Liquid\" },\n { value: \"markdown\", label: \"Markdown\" },\n { value: \"shell\", label: \"Shell\" },\n];\nconst PLAIN = \"plain\";\n\n/** The picker: Plain text, then the field's allowed languages (or the built-in list), then the stored one if it is outside them. */\nfunction languageOptions(language: string | undefined, allowed: string[] | undefined) {\n const list = allowed ? allowed.map((v) => CODE_LANGUAGES.find((l) => l.value === v) ?? { value: v, label: v }) : CODE_LANGUAGES;\n return [{ value: PLAIN, label: \"Plain text\" }, ...list, ...(language && !list.some((l) => l.value === language) ? [{ value: language, label: language }] : [])];\n}\n\n/** Why a JSON text does not parse (\"\" when it does, or is empty). */\nexport function jsonProblem(text: string): string {\n if (!text.trim()) return \"\";\n try {\n JSON.parse(text);\n return \"\";\n } catch (e) {\n return (e as Error).message.replace(/^JSON\\.parse: /, \"\");\n }\n}\n\n/* ── The surface ──────────────────────────────────────────────────────── */\nexport interface CodeSurfaceProps {\n /** \"json\": the JSON header, Format and the parse footer. \"code\": the language list. */\n kind: \"json\" | \"code\";\n value: string;\n onChange: (v: string) => void;\n /** code: the language shown in the header (\"\" = none) and what picking one does; absent = no list */\n language?: string;\n onLanguage?: (language: string) => void;\n /** code: the only languages the field allows (its config.languages); absent = the built-in list */\n languages?: string[];\n readOnly?: boolean;\n id?: string;\n invalid?: boolean;\n minRows?: number;\n label?: string;\n describedBy?: string;\n /** The host's own findings, a line each (V2 Schema editor WP3). Given, they replace the built-in check: their lines are\n * marked in the gutter and the messages list under the code. */\n diagnostics?: { line?: number; message: string; hint?: string }[];\n /** The host's own header actions, before Format and Copy. */\n actions?: React.ReactNode;\n}\n\nexport function CodeSurface({ kind, value, onChange, language, onLanguage, languages, readOnly, id, invalid, minRows = 8, label, describedBy, diagnostics, actions }: CodeSurfaceProps) {\n const { toast } = useKitServices();\n const lines = Math.max(minRows, value.split(\"\\n\").length);\n const marked = new Set((diagnostics ?? []).map((d) => d.line).filter((n): n is number => !!n));\n const problem = diagnostics ? \"\" : kind === \"json\" ? jsonProblem(value) : value.length > CODE_MAX_LENGTH ? `Code can hold up to ${CODE_MAX_LENGTH.toLocaleString(\"en-US\")} characters; this has ${value.length.toLocaleString(\"en-US\")}.` : \"\";\n const flagged = !!problem || !!diagnostics?.length;\n const footerId = id ? `${id}-problem` : undefined;\n const format = () => {\n try {\n onChange(JSON.stringify(JSON.parse(value), null, 2));\n toast?.success(\"JSON formatted\");\n } catch {\n toast?.(\"Fix the JSON before formatting\");\n }\n };\n const copy = () => {\n void navigator.clipboard?.writeText(value);\n toast?.success(\"Copied\");\n };\n return (\n <div className={cn(\"overflow-hidden rounded-kit-lg border bg-kit-subtle\", invalid || flagged ? \"border-[var(--kit-field-invalid)]\" : \"border-kit-line\")}>\n <div className=\"flex h-8 items-center justify-between border-b border-kit-line px-2\">\n {kind === \"json\" ? (\n <span className=\"px-1 font-kit-mono text-kit-xs text-kit-fg-3\">{label ?? \"JSON\"}</span>\n ) : onLanguage ? (\n <Select\n aria-label=\"Code language\"\n size=\"sm\"\n variant=\"ghost\"\n disabled={readOnly}\n value={language || PLAIN}\n onValueChange={(l) => onLanguage(l === PLAIN ? \"\" : l)}\n options={languageOptions(language, languages)}\n />\n ) : (\n <span className=\"px-1 font-kit-mono text-kit-xs text-kit-fg-3\">Code</span>\n )}\n <div className=\"flex items-center gap-1\">\n {actions}\n {kind === \"json\" ? (\n <button type=\"button\" disabled={readOnly} className=\"rounded-kit-md px-1.5 py-0.5 text-kit-xs text-kit-fg-2 hover:bg-kit-hover hover:text-kit-fg\" onClick={format}>\n Format\n </button>\n ) : null}\n <button type=\"button\" className=\"rounded-kit-md px-1.5 py-0.5 text-kit-xs text-kit-fg-2 hover:bg-kit-hover hover:text-kit-fg\" onClick={copy}>\n Copy\n </button>\n </div>\n </div>\n <div className=\"flex max-h-[60vh] overflow-auto font-kit-mono text-kit-xs leading-5\">\n <div aria-hidden className=\"select-none border-r border-kit-line bg-kit-subtle px-2 py-2 text-right text-kit-fg-4\">\n {Array.from({ length: lines }).map((_, i) => (\n <div key={i} className={marked.has(i + 1) ? \"bg-kit-danger-soft text-kit-danger-fg\" : undefined}>\n {i + 1}\n </div>\n ))}\n </div>\n <textarea\n id={id}\n spellCheck={false}\n autoCapitalize=\"off\"\n autoCorrect=\"off\"\n value={value}\n readOnly={readOnly}\n aria-invalid={invalid || flagged || undefined}\n aria-label={label}\n aria-describedby={[describedBy, flagged ? footerId : undefined].filter(Boolean).join(\" \") || undefined}\n onChange={(e) => onChange(e.target.value)}\n onKeyDown={(e) => {\n if (e.key === \"Tab\" && !e.shiftKey && !readOnly) {\n e.preventDefault();\n const el = e.currentTarget;\n const s = el.selectionStart;\n onChange(value.slice(0, s) + \" \" + value.slice(el.selectionEnd));\n requestAnimationFrame(() => el.setSelectionRange(s + 2, s + 2));\n }\n }}\n style={{ height: lines * 20 + 16 }}\n className=\"min-w-0 flex-1 resize-none bg-kit-field-bg px-3 py-2 text-kit-fg outline-none\"\n />\n </div>\n {problem ? (\n <div id={footerId} className=\"border-t border-kit-danger-line bg-kit-danger-soft px-3 py-1.5 text-kit-xs text-kit-danger-fg\">\n {kind === \"json\" ? `Invalid JSON · ${problem}` : problem}\n </div>\n ) : diagnostics?.length ? (\n <ul id={footerId} className=\"flex flex-col gap-1 border-t border-kit-danger-line bg-kit-danger-soft px-3 py-1.5 text-kit-xs text-kit-danger-fg\">\n {diagnostics.map((d, i) => (\n <li key={i}>\n {d.message}\n {d.hint ? <span className=\"block font-kit-mono text-kit-fg-3\">{d.hint}</span> : null}\n </li>\n ))}\n </ul>\n ) : null}\n </div>\n );\n}\n\n/* ── Panel: summary button + dialog over a draft ─────────────────────── */\nexport function CodeDialogField({\n kind, title, description, text, readOnly, id, invalid, language, languages, onDone,\n}: {\n kind: \"json\" | \"code\";\n title: string;\n description?: string;\n text: string;\n readOnly?: boolean;\n id: string;\n invalid?: boolean;\n language?: string;\n languages?: string[];\n /** commit the draft; returns the reason it can't be saved, or null when saved */\n onDone: (draft: string, language: string | undefined) => string | null;\n}) {\n const { toast } = useKitServices();\n const [open, setOpen] = React.useState(false);\n const [draft, setDraft] = React.useState(text);\n const [lang, setLang] = React.useState(language);\n const [refusal, setRefusal] = React.useState<string | null>(null);\n const first = text.split(\"\\n\").find((l) => l.trim()) ?? \"\";\n const Icon = kind === \"json\" ? IconBraces : IconCode;\n return (\n <>\n <button\n id={id}\n type=\"button\"\n aria-haspopup=\"dialog\"\n aria-invalid={invalid || undefined}\n onClick={() => {\n setDraft(text);\n setLang(language);\n setRefusal(null);\n setOpen(true);\n }}\n className={cn(\n \"group/code flex w-full items-center gap-2 rounded-kit-md border border-kit-line bg-kit-subtle px-2.5 py-2 text-left transition-colors hover:border-kit-line-strong\",\n invalid && \"border-[var(--kit-field-invalid)]\",\n )}\n >\n <Icon className=\"size-4 shrink-0 text-kit-fg-3\" stroke={1.5} aria-hidden />\n <span className={cn(\"min-w-0 flex-1 truncate font-kit-mono text-kit-xs\", first ? \"text-kit-fg-2\" : \"text-kit-fg-3\")}>{first || \"Empty\"}</span>\n <span className=\"tabular-nums shrink-0 text-kit-2xs text-kit-fg-3\">{text ? `${text.split(\"\\n\").length} lines` : \"\"}</span>\n <IconMaximize className=\"size-3.5 shrink-0 text-kit-fg-3 group-hover/code:text-kit-fg\" stroke={1.5} aria-hidden />\n </button>\n <Modal open={open} onOpenChange={setOpen}>\n <ModalContent size=\"lg\">\n <ModalHeader title={title} description={description ?? (kind === \"json\" ? \"Structured data for developers\" : \"Custom code\")} />\n <ModalBody>\n <CodeSurface kind={kind} value={draft} onChange={setDraft} language={lang ?? \"\"} onLanguage={kind === \"code\" ? setLang : undefined} languages={languages} readOnly={readOnly} minRows={14} label={title} />\n {refusal ? (\n <p role=\"alert\" className=\"mt-2 flex items-start gap-1.5 text-kit-xs text-kit-danger-fg\">\n <IconAlertTriangle className=\"mt-0.5 size-3.5 shrink-0\" stroke={1.5} aria-hidden />\n {refusal}\n </p>\n ) : null}\n </ModalBody>\n <ModalFooter>\n <span data-hint=\"shortcuts\" className=\"text-kit-xs text-kit-fg-3\">\n Esc to close\n </span>\n <span className=\"mr-auto\" aria-hidden />\n <Button variant=\"ghost\" onClick={() => setOpen(false)}>\n Cancel\n </Button>\n <Button\n variant=\"primary\"\n disabled={readOnly}\n onClick={() => {\n const why = onDone(draft, lang);\n if (why) {\n setRefusal(why);\n toast?.(kind === \"json\" ? \"Invalid JSON\" : \"Can't save this code\", { description: \"Fix it before saving.\" });\n return;\n }\n setOpen(false);\n }}\n >\n Done\n </Button>\n </ModalFooter>\n </ModalContent>\n </Modal>\n </>\n );\n}\n\n/* ── The control ──────────────────────────────────────────────────────── */\ntype CodeRead = { ok: true; code: string; language?: string; object: boolean } | { ok: false };\nfunction readCode(v: unknown): CodeRead {\n if (v == null) return { ok: true, code: \"\", object: false };\n if (typeof v === \"string\") return { ok: true, code: v, object: false };\n if (isObj(v) && typeof v.code === \"string\" && (v.language === undefined || typeof v.language === \"string\")) return { ok: true, code: v.code, language: v.language as string | undefined, object: true };\n return { ok: false };\n}\n\n/** The stored shape for edited code: a string stays a string until a language is picked; the object keeps its form. */\nfunction codeValue(prev: CodeRead & { ok: true }, code: string, language: string | undefined): string | { language?: string; code: string } {\n const lang = language ?? prev.language ?? \"\";\n if (!prev.object && !lang) return code;\n return lang ? { language: lang, code } : { code };\n}\nconst tooLong = (code: string) => (code.length > CODE_MAX_LENGTH ? `Code can hold up to ${CODE_MAX_LENGTH.toLocaleString(\"en-US\")} characters; this has ${code.length.toLocaleString(\"en-US\")}.` : null);\n\nexport function CodeControl({ field, value, onChange, readOnly, id, invalid }: ControlProps) {\n const { variant } = useKitEnv();\n const [refused, setRefused] = React.useState<string | null>(null);\n const read = readCode(value);\n if (!read.ok) return <UnreadableValue id={id} title={field.title} kind=\"code\" value={value} />;\n if (variant === \"document\")\n return (\n <div className=\"flex flex-col gap-1.5\">\n <CodeSurface\n kind=\"code\"\n id={id}\n invalid={invalid || !!refused}\n readOnly={readOnly}\n value={read.code}\n language={read.language ?? \"\"}\n languages={field.languages}\n onChange={(code) => {\n const why = tooLong(code);\n setRefused(why);\n if (!why) onChange(codeValue(read, code, undefined));\n }}\n onLanguage={(l) => onChange(codeValue(read, read.code, l))}\n />\n {refused ? (\n <p role=\"alert\" className=\"text-kit-xs text-kit-danger-fg\">\n {refused}\n </p>\n ) : null}\n </div>\n );\n return (\n <CodeDialogField\n kind=\"code\"\n id={id}\n title={field.title}\n description={field.description || undefined}\n text={read.code}\n language={read.language}\n languages={field.languages}\n readOnly={readOnly}\n invalid={invalid}\n onDone={(draft, lang) => {\n const why = tooLong(draft);\n if (why) return why;\n const next = codeValue(read, draft, lang);\n if (draft !== read.code || (lang ?? \"\") !== (read.language ?? \"\")) onChange(next);\n return null;\n }}\n />\n );\n}\n\n/** A stored value the control cannot read: named, shown, kept as it is (never replaced by a stray edit). */\nexport function UnreadableValue({ id, title, kind, value }: { id: string; title: string; kind: string; value: unknown }) {\n let raw: string;\n try {\n raw = typeof value === \"string\" ? value : JSON.stringify(value, null, 2);\n } catch {\n raw = String(value);\n }\n return (\n <output\n id={id}\n tabIndex={0}\n data-slot={`${kind}-unreadable`}\n className=\"flex min-w-0 items-start gap-2 rounded-kit-md border border-dashed border-kit-line-strong bg-kit-subtle px-2.5 py-2 text-kit-xs text-kit-fg-2 outline-none focus-visible:outline-2 focus-visible:outline-kit-focus-ring\"\n >\n <IconAlertTriangle className=\"mt-0.5 size-3.5 shrink-0 text-kit-warning-fg\" stroke={1.5} aria-hidden />\n <span className=\"min-w-0\">\n {title} holds a value this {kind} editor can't read, so it is kept as it is:{\" \"}\n <span className=\"block max-h-24 overflow-auto whitespace-pre-wrap break-all font-kit-mono text-kit-fg\">{raw}</span>\n </span>\n </output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IACD;;CAET,OACE,oBAAC,iBAAD;EACE,MAAK;EACD;EACJ,OAAO,MAAM;EACb,aAAa,MAAM,eAAe,KAAA;EAClC,MAAM,KAAK;EACX,UAAU,KAAK;EACf,WAAW,MAAM;EACP;EACD;EACT,SAAS,OAAO,SAAS;GACvB,MAAM,MAAM,QAAQ,KAAK;GACzB,IAAI,KAAK,OAAO;GAChB,MAAM,OAAO,UAAU,MAAM,OAAO,IAAI;GACxC,IAAI,UAAU,KAAK,SAAS,QAAQ,SAAS,KAAK,YAAY,KAAK,SAAS,IAAI;GAChF,OAAO;EACT;CACD,CAAA;AAEL;;AAGA,SAAgB,gBAAgB,EAAE,IAAI,OAAO,MAAM,SAAsE;CACvH,IAAI;CACJ,IAAI;EACF,MAAM,OAAO,UAAU,WAAW,QAAQ,KAAK,UAAU,OAAO,MAAM,CAAC;CACzE,QAAQ;EACN,MAAM,OAAO,KAAK;CACpB;CACA,OACE,qBAAC,UAAD;EACM;EACJ,UAAU;EACV,aAAW,GAAG,KAAK;EACnB,WAAU;EAJZ,UAAA,CAME,oBAAC,mBAAD;GAAmB,WAAU;GAA+C,QAAQ;GAAK,eAAA;EAAa,CAAA,GACtG,qBAAC,QAAD;GAAM,WAAU;GAAhB,UAAA;IACG;IAAM;IAAqB;IAAK;IAA4C;IAC7E,oBAAC,QAAD;KAAM,WAAU;KAAwF,UAAA;IAAU,CAAA;GAC9G;EACA,CAAA,CAAA;;AAEZ"}
@@ -43,7 +43,7 @@ function ColorControl({ field, value, onChange, readOnly, id, invalid, onBlur })
43
43
  "aria-label": `Choose a colour for ${field.title}`,
44
44
  render: /* @__PURE__ */ jsx("button", {
45
45
  type: "button",
46
- className: "flex h-8 min-w-0 flex-1 items-center gap-2 rounded-kit-md border border-kit-field-border bg-kit-field-bg pl-1 pr-2.5 text-left text-kit-sm hover:border-kit-field-border-hover data-[popup-open]:border-kit-field-border-focus data-[popup-open]:bg-kit-field-bg"
46
+ className: "flex h-8 min-w-0 flex-1 items-center gap-2 rounded-kit-md border border-kit-line-strong bg-kit-field-bg pl-1 pr-2.5 text-left text-kit-sm hover:border-kit-line-strong data-[popup-open]:border-kit-line-strong data-[popup-open]:bg-kit-field-bg"
47
47
  }),
48
48
  children: [
49
49
  /* @__PURE__ */ jsx("span", {
@@ -1 +1 @@
1
- {"version":3,"file":"color.js","names":[],"sources":["../../src/controls/color.tsx"],"sourcesContent":["/**\n * COLOR — site-palette swatches first, then a custom colour (V2 HEAD 9829bf1 kit/controls/misc.tsx, DESIGN §8.13).\n *\n * Stored shape (prod `color`): a hex string the backend accepts — #RGB, #RRGGBB or #RRGGBBAA — or null when cleared.\n * The hex box keeps what you type as a draft and writes it only once it is a hex colour; while it is not, the box is\n * marked invalid and says why, so a half-typed \"#12\" never reaches the save (the API would refuse it).\n * The palette is the host's (`env.palette`, the project's brand colours); with none, the popover offers the custom\n * picker alone.\n */\nimport * as React from \"react\";\nimport { cn } from \"../lib/cn\";\nimport { useKitEnv } from \"../context\";\nimport { Input } from \"../ui/input\";\nimport { Popover, PopoverContent, PopoverTrigger, Tooltip } from \"../ui/overlay\";\nimport type { ControlProps } from \"../types\";\nimport { str, TEXT_FOCUS } from \"./text\";\n\nexport const HEX_COLOR = /^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/;\n/** #RGB / #RRGGBBAA → #RRGGBB for the native picker, which takes only six digits. */\nexport function pickerHex(v: string): string {\n if (!HEX_COLOR.test(v)) return \"#000000\";\n const h = v.slice(1);\n const six = h.length === 3 ? h.split(\"\").map((c) => c + c).join(\"\") : h.slice(0, 6);\n return `#${six.toLowerCase()}`;\n}\n\nexport function ColorControl({ field, value, onChange, readOnly, id, invalid, onBlur }: ControlProps) {\n const { palette } = useKitEnv();\n const v = str(value);\n const [draft, setDraft] = React.useState<string | null>(null);\n const shown = draft ?? v;\n const bad = draft !== null && draft.trim() !== \"\" && !HEX_COLOR.test(draft.trim());\n const sw = palette.find((p) => p.value.toLowerCase() === v.toLowerCase());\n const errId = React.useId();\n const write = (next: string | null) => {\n setDraft(null);\n onChange(next);\n };\n return (\n <div className=\"flex flex-col gap-1\">\n <div className=\"flex items-center gap-2\">\n <Popover>\n <PopoverTrigger\n disabled={readOnly}\n aria-label={`Choose a colour for ${field.title}`}\n render={\n <button\n type=\"button\"\n className=\"flex h-8 min-w-0 flex-1 items-center gap-2 rounded-kit-md border border-kit-field-border bg-kit-field-bg pl-1 pr-2.5 text-left text-kit-sm hover:border-kit-field-border-hover data-[popup-open]:border-kit-field-border-focus data-[popup-open]:bg-kit-field-bg\"\n />\n }\n >\n <span className=\"size-6 shrink-0 rounded-kit-md border border-kit-swatch-ring shadow-kit-xs\" style={{ background: v || \"transparent\" }} />\n <span className={cn(\"min-w-0 flex-1 truncate\", v ? \"text-kit-fg\" : \"text-kit-fg-3\")}>{sw ? sw.name : v ? \"Custom\" : \"No colour\"}</span>\n {sw?.token ? <span className=\"truncate font-kit-mono text-kit-2xs text-kit-fg-3\">{sw.token}</span> : null}\n </PopoverTrigger>\n <PopoverContent className=\"w-64\">\n {palette.length ? (\n <>\n <div className=\"mb-2 text-kit-xs text-kit-fg-3\">Site palette</div>\n <div className=\"grid grid-cols-5 gap-2\">\n {palette.map((s) => (\n <Tooltip key={s.value} content={`${s.name}${s.token ? ` · ${s.token}` : \"\"}`}>\n <button\n type=\"button\"\n aria-label={s.name}\n aria-pressed={s.value.toLowerCase() === v.toLowerCase()}\n onClick={() => write(s.value)}\n className={cn(\n // 1–2% hover scale, only for a hovering pointer (canvas revamp V463)\n \"relative size-9 rounded-kit-md border border-kit-swatch-ring transition-transform duration-150 ease-out motion-reduce:transition-none can-hover:hover:scale-[1.02]\",\n s.value.toLowerCase() === v.toLowerCase() && \"ring-2 ring-kit-fg ring-offset-2 ring-offset-kit-surface\",\n )}\n style={{ background: s.value }}\n />\n </Tooltip>\n ))}\n </div>\n </>\n ) : null}\n <label className={cn(\"mt-3 flex items-center gap-2 border-t border-kit-line pt-3 text-kit-xs text-kit-fg-3\", !palette.length && \"mt-0 border-t-0 pt-0\")}>\n Custom\n <input\n type=\"color\"\n value={pickerHex(v)}\n onChange={(e) => write(e.target.value.toUpperCase())}\n className=\"h-7 w-full cursor-pointer rounded-kit-md border border-kit-line bg-transparent\"\n />\n </label>\n {v ? (\n <button type=\"button\" onClick={() => write(null)} className=\"mt-2 w-full rounded-kit-md px-1.5 py-1 text-left text-kit-xs text-kit-fg-2 hover:bg-kit-hover hover:text-kit-fg\">\n No colour\n </button>\n ) : null}\n </PopoverContent>\n </Popover>\n <Input\n id={id}\n value={shown}\n readOnly={readOnly}\n aria-invalid={invalid || bad}\n aria-describedby={bad ? errId : undefined}\n placeholder=\"#RRGGBB\"\n spellCheck={false}\n onChange={(e) => {\n const t = e.target.value.trim();\n if (t === \"\") write(null);\n else if (HEX_COLOR.test(t)) write(t);\n else setDraft(e.target.value);\n }}\n onBlur={onBlur}\n className={cn(TEXT_FOCUS, \"w-28 shrink-0 font-kit-mono [&_input]:font-kit-mono\")}\n />\n </div>\n {bad ? (\n <p id={errId} role=\"alert\" className=\"text-kit-xs text-kit-danger-fg\">\n “{draft!.trim()}” isn't a hex color, so it isn't saved. Use #RGB or #RRGGBB.\n </p>\n ) : null}\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAiBA,IAAa,YAAY;;AAEzB,SAAgB,UAAU,GAAmB;CAC3C,IAAI,CAAC,UAAU,KAAK,CAAC,GAAG,OAAO;CAC/B,MAAM,IAAI,EAAE,MAAM,CAAC;CAEnB,OAAO,KADK,EAAE,WAAW,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC,KAAK,MAAM,IAAI,CAAC,CAAC,CAAC,KAAK,EAAE,IAAI,EAAE,MAAM,GAAG,CAAC,EAAA,CACnE,YAAY;AAC7B;AAEA,SAAgB,aAAa,EAAE,OAAO,OAAO,UAAU,UAAU,IAAI,SAAS,UAAwB;CACpG,MAAM,EAAE,YAAY,UAAU;CAC9B,MAAM,IAAI,IAAI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;QACd,gBAAc,EAAE,MAAM,YAAY,MAAM,EAAE,YAAY;QACtD,eAAe,MAAM,EAAE,KAAK;QAC5B,WAAW,GAET,sKACA,EAAE,MAAM,YAAY,MAAM,EAAE,YAAY,KAAK,0DAC/C;QACA,OAAO,EAAE,YAAY,EAAE,MAAM;OAC9B,CAAA;MACM,GAbK,EAAE,KAaP,CACV;KACE,CAAA,CACL,EAAA,CAAA,IACA;KACJ,qBAAC,SAAD;MAAO,WAAW,GAAG,wFAAwF,CAAC,QAAQ,UAAU,sBAAsB;MAAtJ,UAAA,CAAyJ,UAEvJ,oBAAC,SAAD;OACE,MAAK;OACL,OAAO,UAAU,CAAC;OAClB,WAAW,MAAM,MAAM,EAAE,OAAO,MAAM,YAAY,CAAC;OACnD,WAAU;MACX,CAAA,CACI;;KACN,IACC,oBAAC,UAAD;MAAQ,MAAK;MAAS,eAAe,MAAM,IAAI;MAAG,WAAU;MAAkH,UAAA;KAEtK,CAAA,IACN;IACU;GACT,CAAA,CAAA,EAAA,CAAA,GACT,oBAAC,OAAD;IACM;IACJ,OAAO;IACG;IACV,gBAAc,WAAW;IACzB,oBAAkB,MAAM,QAAQ,KAAA;IAChC,aAAY;IACZ,YAAY;IACZ,WAAW,MAAM;KACf,MAAM,IAAI,EAAE,OAAO,MAAM,KAAK;KAC9B,IAAI,MAAM,IAAI,MAAM,IAAI;UACnB,IAAI,UAAU,KAAK,CAAC,GAAG,MAAM,CAAC;UAC9B,SAAS,EAAE,OAAO,KAAK;IAC9B;IACQ;IACR,WAAW,GAAG,YAAY,qDAAqD;GAChF,CAAA,CACE;EACJ,CAAA,GAAA,MACC,qBAAC,KAAD;GAAG,IAAI;GAAO,MAAK;GAAQ,WAAU;GAArC,UAAA;IAAsE;IAClE,MAAO,KAAK;IAAE;GACf;EACD,CAAA,IAAA,IACD;;AAET"}
1
+ {"version":3,"file":"color.js","names":[],"sources":["../../src/controls/color.tsx"],"sourcesContent":["/**\n * COLOR — site-palette swatches first, then a custom colour (V2 HEAD 9829bf1 kit/controls/misc.tsx, DESIGN §8.13).\n *\n * Stored shape (prod `color`): a hex string the backend accepts — #RGB, #RRGGBB or #RRGGBBAA — or null when cleared.\n * The hex box keeps what you type as a draft and writes it only once it is a hex colour; while it is not, the box is\n * marked invalid and says why, so a half-typed \"#12\" never reaches the save (the API would refuse it).\n * The palette is the host's (`env.palette`, the project's brand colours); with none, the popover offers the custom\n * picker alone.\n */\nimport * as React from \"react\";\nimport { cn } from \"../lib/cn\";\nimport { useKitEnv } from \"../context\";\nimport { Input } from \"../ui/input\";\nimport { Popover, PopoverContent, PopoverTrigger, Tooltip } from \"../ui/overlay\";\nimport type { ControlProps } from \"../types\";\nimport { str, TEXT_FOCUS } from \"./text\";\n\nexport const HEX_COLOR = /^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/;\n/** #RGB / #RRGGBBAA → #RRGGBB for the native picker, which takes only six digits. */\nexport function pickerHex(v: string): string {\n if (!HEX_COLOR.test(v)) return \"#000000\";\n const h = v.slice(1);\n const six = h.length === 3 ? h.split(\"\").map((c) => c + c).join(\"\") : h.slice(0, 6);\n return `#${six.toLowerCase()}`;\n}\n\nexport function ColorControl({ field, value, onChange, readOnly, id, invalid, onBlur }: ControlProps) {\n const { palette } = useKitEnv();\n const v = str(value);\n const [draft, setDraft] = React.useState<string | null>(null);\n const shown = draft ?? v;\n const bad = draft !== null && draft.trim() !== \"\" && !HEX_COLOR.test(draft.trim());\n const sw = palette.find((p) => p.value.toLowerCase() === v.toLowerCase());\n const errId = React.useId();\n const write = (next: string | null) => {\n setDraft(null);\n onChange(next);\n };\n return (\n <div className=\"flex flex-col gap-1\">\n <div className=\"flex items-center gap-2\">\n <Popover>\n <PopoverTrigger\n disabled={readOnly}\n aria-label={`Choose a colour for ${field.title}`}\n render={\n <button\n type=\"button\"\n className=\"flex h-8 min-w-0 flex-1 items-center gap-2 rounded-kit-md border border-kit-line-strong bg-kit-field-bg pl-1 pr-2.5 text-left text-kit-sm hover:border-kit-line-strong data-[popup-open]:border-kit-line-strong data-[popup-open]:bg-kit-field-bg\"\n />\n }\n >\n <span className=\"size-6 shrink-0 rounded-kit-md border border-kit-swatch-ring shadow-kit-xs\" style={{ background: v || \"transparent\" }} />\n <span className={cn(\"min-w-0 flex-1 truncate\", v ? \"text-kit-fg\" : \"text-kit-fg-3\")}>{sw ? sw.name : v ? \"Custom\" : \"No colour\"}</span>\n {sw?.token ? <span className=\"truncate font-kit-mono text-kit-2xs text-kit-fg-3\">{sw.token}</span> : null}\n </PopoverTrigger>\n <PopoverContent className=\"w-64\">\n {palette.length ? (\n <>\n <div className=\"mb-2 text-kit-xs text-kit-fg-3\">Site palette</div>\n <div className=\"grid grid-cols-5 gap-2\">\n {palette.map((s) => (\n <Tooltip key={s.value} content={`${s.name}${s.token ? ` · ${s.token}` : \"\"}`}>\n <button\n type=\"button\"\n aria-label={s.name}\n aria-pressed={s.value.toLowerCase() === v.toLowerCase()}\n onClick={() => write(s.value)}\n className={cn(\n // 1–2% hover scale, only for a hovering pointer (canvas revamp V463)\n \"relative size-9 rounded-kit-md border border-kit-swatch-ring transition-transform duration-150 ease-out motion-reduce:transition-none can-hover:hover:scale-[1.02]\",\n s.value.toLowerCase() === v.toLowerCase() && \"ring-2 ring-kit-fg ring-offset-2 ring-offset-kit-surface\",\n )}\n style={{ background: s.value }}\n />\n </Tooltip>\n ))}\n </div>\n </>\n ) : null}\n <label className={cn(\"mt-3 flex items-center gap-2 border-t border-kit-line pt-3 text-kit-xs text-kit-fg-3\", !palette.length && \"mt-0 border-t-0 pt-0\")}>\n Custom\n <input\n type=\"color\"\n value={pickerHex(v)}\n onChange={(e) => write(e.target.value.toUpperCase())}\n className=\"h-7 w-full cursor-pointer rounded-kit-md border border-kit-line bg-transparent\"\n />\n </label>\n {v ? (\n <button type=\"button\" onClick={() => write(null)} className=\"mt-2 w-full rounded-kit-md px-1.5 py-1 text-left text-kit-xs text-kit-fg-2 hover:bg-kit-hover hover:text-kit-fg\">\n No colour\n </button>\n ) : null}\n </PopoverContent>\n </Popover>\n <Input\n id={id}\n value={shown}\n readOnly={readOnly}\n aria-invalid={invalid || bad}\n aria-describedby={bad ? errId : undefined}\n placeholder=\"#RRGGBB\"\n spellCheck={false}\n onChange={(e) => {\n const t = e.target.value.trim();\n if (t === \"\") write(null);\n else if (HEX_COLOR.test(t)) write(t);\n else setDraft(e.target.value);\n }}\n onBlur={onBlur}\n className={cn(TEXT_FOCUS, \"w-28 shrink-0 font-kit-mono [&_input]:font-kit-mono\")}\n />\n </div>\n {bad ? (\n <p id={errId} role=\"alert\" className=\"text-kit-xs text-kit-danger-fg\">\n “{draft!.trim()}” isn't a hex color, so it isn't saved. Use #RGB or #RRGGBB.\n </p>\n ) : null}\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAiBA,IAAa,YAAY;;AAEzB,SAAgB,UAAU,GAAmB;CAC3C,IAAI,CAAC,UAAU,KAAK,CAAC,GAAG,OAAO;CAC/B,MAAM,IAAI,EAAE,MAAM,CAAC;CAEnB,OAAO,KADK,EAAE,WAAW,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC,KAAK,MAAM,IAAI,CAAC,CAAC,CAAC,KAAK,EAAE,IAAI,EAAE,MAAM,GAAG,CAAC,EAAA,CACnE,YAAY;AAC7B;AAEA,SAAgB,aAAa,EAAE,OAAO,OAAO,UAAU,UAAU,IAAI,SAAS,UAAwB;CACpG,MAAM,EAAE,YAAY,UAAU;CAC9B,MAAM,IAAI,IAAI,KAAK;CACnB,MAAM,CAAC,OAAO,YAAY,MAAM,SAAwB,IAAI;CAC5D,MAAM,QAAQ,SAAS;CACvB,MAAM,MAAM,UAAU,QAAQ,MAAM,KAAK,MAAM,MAAM,CAAC,UAAU,KAAK,MAAM,KAAK,CAAC;CACjF,MAAM,KAAK,QAAQ,MAAM,MAAM,EAAE,MAAM,YAAY,MAAM,EAAE,YAAY,CAAC;CACxE,MAAM,QAAQ,MAAM,MAA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