@gemboss/ui 0.48.0 → 0.51.0

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 (84) hide show
  1. package/CHANGELOG.md +457 -0
  2. package/README.md +280 -12
  3. package/catalog/editor.html +25 -12
  4. package/catalog/index.html +641 -99
  5. package/gemboss-ui.css +3 -3
  6. package/package.json +29 -2
  7. package/parts/components.css +3 -3
  8. package/parts/core.css +1 -1
  9. package/parts/shell.css +2 -2
  10. package/src/app-shell.css +1 -1
  11. package/src/assistant/chat.tsx +50 -6
  12. package/src/assistant/host.tsx +19 -7
  13. package/src/assistant/index.ts +1 -1
  14. package/src/assistant/sessions.tsx +2 -1
  15. package/src/assistant-chat.css +1 -1
  16. package/src/assistant.css +1 -1
  17. package/src/auth-extras.css +1 -0
  18. package/src/auth-footer.css +1 -0
  19. package/src/auth-footer.tsx +71 -0
  20. package/src/auth-signin-plain.js +1 -0
  21. package/src/auth-sso-plain.js +1 -1
  22. package/src/auth-steps.css +1 -0
  23. package/src/auth-steps.tsx +179 -0
  24. package/src/auth.css +1 -1
  25. package/src/auth.tsx +239 -14
  26. package/src/briefing-card.css +1 -1
  27. package/src/collections.css +1 -1
  28. package/src/create-shell.css +1 -0
  29. package/src/create-shell.tsx +221 -0
  30. package/src/dialog.tsx +3 -0
  31. package/src/editor/color-picker.tsx +183 -0
  32. package/src/editor/controls.tsx +49 -33
  33. package/src/editor/index.ts +8 -0
  34. package/src/editor/picker-grid.tsx +186 -0
  35. package/src/editor/picker.tsx +275 -0
  36. package/src/editor/popover.tsx +160 -0
  37. package/src/editor/swatch.ts +2 -1
  38. package/src/editor-color.css +1 -0
  39. package/src/editor-insert.css +1 -0
  40. package/src/editor-picker-grid.css +1 -0
  41. package/src/editor-picker.css +1 -0
  42. package/src/editor-plain.js +1 -1
  43. package/src/editor-popover.css +1 -0
  44. package/src/editor.css +1 -1
  45. package/src/empty-stage.css +1 -0
  46. package/src/empty-stage.tsx +31 -0
  47. package/src/icons.tsx +6 -0
  48. package/src/index-table.tsx +7 -4
  49. package/src/index.ts +19 -2
  50. package/src/kit-plain.css +1 -1
  51. package/src/kit-plain.js +1 -1
  52. package/src/language-switcher.tsx +10 -41
  53. package/src/list-page.css +1 -0
  54. package/src/list-page.tsx +239 -0
  55. package/src/menu-extras.css +1 -0
  56. package/src/menu-keys.ts +199 -0
  57. package/src/menu-layer.ts +2 -1
  58. package/src/menu-plain.js +1 -0
  59. package/src/menu.css +1 -0
  60. package/src/menu.tsx +83 -35
  61. package/src/pager-extras.css +1 -0
  62. package/src/pager.css +1 -0
  63. package/src/pager.tsx +88 -0
  64. package/src/portal.css +1 -1
  65. package/src/segmented.tsx +12 -2
  66. package/src/selection.tsx +3 -1
  67. package/src/session-rail-plain.js +1 -1
  68. package/src/settings-dialog.tsx +29 -2
  69. package/src/shell.css +1 -1
  70. package/src/stage-path.css +1 -0
  71. package/src/stage-path.tsx +89 -0
  72. package/src/stage.css +1 -0
  73. package/src/stage.tsx +52 -0
  74. package/src/starting-point.css +1 -0
  75. package/src/starting-point.tsx +93 -0
  76. package/src/status-list.css +1 -0
  77. package/src/status-list.tsx +65 -0
  78. package/src/status-matrix.css +1 -0
  79. package/src/status-matrix.tsx +131 -0
  80. package/src/team-chat.css +1 -1
  81. package/src/theme.tsx +13 -3
  82. package/src/translation-row.css +1 -0
  83. package/src/translation-row.tsx +113 -0
  84. package/src/ui.css +1 -1
@@ -0,0 +1,221 @@
1
+ "use client";
2
+
3
+ /**
4
+ * The create shell (23/10/2026, drawings A1, A3 and A4 of the canvas Chris approved): ONE shape for making anything new — a page,
5
+ * a funnel, a section. They were three shells with three filter styles and three button words. Now each picker is drawn from the
6
+ * same pieces, inside the frame it already opens in:
7
+ *
8
+ * <CreateIcon kind="page" /> the header's icon tile (iris on its soft tint)
9
+ * <CreateStepper steps current /> Choose → Make it yours → Gem builds it
10
+ * <CreateRail> the left column
11
+ * <CreateDoors doors /> the three doors: ask the assistant, the library, blank (at most three)
12
+ * <CreateFilter label options value /> a question as chips: "Who it is for", "What it does"
13
+ * </CreateRail>
14
+ * <CreateGrid> the cards
15
+ * <CreateCard picture audience eyebrow title line inside action />
16
+ * </CreateGrid>
17
+ * <CreateParts parts /> <CreatePath steps /> pictures for a card, on the Stage (stage.tsx)
18
+ *
19
+ * Who a thing is for is one of three temperatures, each with its colour (iris cold, amber warm, coral ready); the colours are a
20
+ * dot and an eyebrow, never a button. Buttons stay ink.
21
+ */
22
+ import "./create-shell.css";
23
+ import type { ReactNode } from "react";
24
+ import { Stage, StageTile } from "./stage";
25
+
26
+ const cx = (...p: Array<string | false | null | undefined>) => p.filter(Boolean).join(" ");
27
+
28
+ /** Who a page, funnel or section is for: how warm the shopper is when they meet it. `any`: no one temperature. */
29
+ export type CreateAudience = "cold" | "warm" | "ready" | "any";
30
+
31
+ /** Each temperature's dot and eyebrow, written whole: a class a stylesheet can be checked against, never built at runtime. */
32
+ const DOT: Record<CreateAudience, string> = {
33
+ cold: "ui-create-dot ui-create-dot--cold", warm: "ui-create-dot ui-create-dot--warm", ready: "ui-create-dot ui-create-dot--ready", any: "ui-create-dot",
34
+ };
35
+ const EYEBROW: Record<CreateAudience, string> = {
36
+ cold: "ui-create-card__eyebrow ui-create-card__eyebrow--cold", warm: "ui-create-card__eyebrow ui-create-card__eyebrow--warm",
37
+ ready: "ui-create-card__eyebrow ui-create-card__eyebrow--ready", any: "ui-create-card__eyebrow",
38
+ };
39
+
40
+ /** The words for each temperature: the filter's chip, and the card's eyebrow. */
41
+ export const CREATE_AUDIENCE: Record<CreateAudience, { chip: string; eyebrow: string }> = {
42
+ cold: { chip: "Cold, from ads", eyebrow: "Cold" },
43
+ warm: { chip: "Warm, knows you", eyebrow: "Warm" },
44
+ ready: { chip: "Ready to buy", eyebrow: "Ready" },
45
+ any: { chip: "Anyone", eyebrow: "Anyone" },
46
+ };
47
+
48
+ export function CreateIcon({ kind }: { kind: "page" | "funnel" | "section" }) {
49
+ const path = kind === "funnel" ? "M3 5h14l-5 6v5l-4-2v-3z"
50
+ : kind === "section" ? "M3 4h14v4H3zM3 10h14v6H3z"
51
+ : "M5 2.5h10a2 2 0 0 1 2 2v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-11a2 2 0 0 1 2-2zM7 7h6M7 10h6M7 13h3";
52
+ return (
53
+ <span className="ui-create-icon" aria-hidden="true">
54
+ <svg width="18" height="18" viewBox="0 0 20 20"><path d={path} fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round" /></svg>
55
+ </span>
56
+ );
57
+ }
58
+
59
+ /** Where the person is in making it: the steps done (✓), the one they are on, the ones to come. `current` counts from 0. */
60
+ export function CreateStepper({ steps, current }: { steps: readonly string[]; current: number }) {
61
+ return (
62
+ <ol className="ui-create-steps" aria-label="Steps">
63
+ {steps.map((s, i) => (
64
+ <li key={s} className={cx("ui-create-step", i < current && "ui-create-step--done", i === current && "ui-create-step--on")} aria-current={i === current ? "step" : undefined}>
65
+ <span className="ui-create-step__n" aria-hidden="true">{i < current ? "✓" : i + 1}</span>
66
+ {s}
67
+ </li>
68
+ ))}
69
+ </ol>
70
+ );
71
+ }
72
+
73
+ export function CreateRail({ children, foot }: { children?: ReactNode; foot?: ReactNode }) {
74
+ return (
75
+ <div className="ui-create-rail">
76
+ {children}
77
+ {foot ? <p className="ui-create-rail__foot">{foot}</p> : null}
78
+ </div>
79
+ );
80
+ }
81
+
82
+ export type CreateDoorArt = "ask" | "library" | "blank";
83
+ export interface CreateDoor {
84
+ key: string;
85
+ art: CreateDoorArt;
86
+ title: string;
87
+ line: string;
88
+ /** The door that is open. */
89
+ on?: boolean;
90
+ onClick: () => void;
91
+ disabled?: boolean;
92
+ }
93
+
94
+ function DoorGlyph({ art }: { art: CreateDoorArt }) {
95
+ if (art === "ask") return <svg width="16" height="16" viewBox="0 0 20 20"><path d="M4 5h12v8H9l-4 3v-3H4z" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinejoin="round" /></svg>;
96
+ if (art === "library") {
97
+ return (
98
+ <svg width="16" height="16" viewBox="0 0 20 20">
99
+ <rect x="3" y="3" width="6" height="6" rx="1.5" fill="currentColor" />
100
+ <path d="M11 3h6v6h-6zM3 11h6v6H3zM11 11h6v6h-6z" fill="none" stroke="currentColor" strokeWidth="1.4" strokeLinejoin="round" />
101
+ </svg>
102
+ );
103
+ }
104
+ return <svg width="16" height="16" viewBox="0 0 20 20"><path d="M10 5v10M5 10h10" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" /></svg>;
105
+ }
106
+
107
+ /** "Start with": the ways in, one of them open. At most three (Chris's rule for any choice). */
108
+ export function CreateDoors({ doors, label = "Start with" }: { doors: readonly CreateDoor[]; label?: string }) {
109
+ return (
110
+ <div className="ui-create-group" role="group" aria-label={label}>
111
+ <span className="ui-create-label">{label}</span>
112
+ {doors.slice(0, 3).map((d) => (
113
+ <button key={d.key} type="button" className={cx("ui-create-door", d.on && "ui-create-door--on")} aria-pressed={d.on ? true : false} disabled={d.disabled} onClick={d.onClick}>
114
+ <span className="ui-create-door__art" aria-hidden="true"><DoorGlyph art={d.art} /></span>
115
+ <span className="ui-create-door__col"><b>{d.title}</b><span>{d.line}</span></span>
116
+ </button>
117
+ ))}
118
+ </div>
119
+ );
120
+ }
121
+
122
+ export interface CreateFilterOption<K extends string> { key: K; label: string; audience?: CreateAudience; count?: number }
123
+
124
+ /** One question as chips, "Any" first. A chip with an audience carries its colour's dot. */
125
+ export function CreateFilter<K extends string>({ label, options, value, onChange, anyLabel = "Any" }: {
126
+ label: string; options: ReadonlyArray<CreateFilterOption<K>>; value: K | "any"; onChange: (v: K | "any") => void; anyLabel?: string;
127
+ }) {
128
+ return (
129
+ <div className="ui-create-group" role="group" aria-label={label}>
130
+ <span className="ui-create-label">{label}</span>
131
+ <div className="ui-create-chips">
132
+ <button type="button" className={cx("ui-create-chip", value === "any" && "ui-create-chip--on")} aria-pressed={value === "any"} onClick={() => onChange("any")}>{anyLabel}</button>
133
+ {options.map((o) => (
134
+ <button key={o.key} type="button" className={cx("ui-create-chip", value === o.key && "ui-create-chip--on")} aria-pressed={value === o.key} onClick={() => onChange(o.key)}>
135
+ {o.audience && o.audience !== "any" ? <span className={DOT[o.audience]} aria-hidden="true" /> : null}
136
+ {o.label}
137
+ {typeof o.count === "number" ? <span className="ui-create-chip__n">{o.count}</span> : null}
138
+ </button>
139
+ ))}
140
+ </div>
141
+ </div>
142
+ );
143
+ }
144
+
145
+ export function CreateGrid({ children, label }: { children?: ReactNode; label?: string }) {
146
+ return <div className="ui-create-grid" role="list" aria-label={label}>{children}</div>;
147
+ }
148
+
149
+ /**
150
+ * One way to start: a picture on the Stage, who it is for (its colour's dot and word, then what it does), its name, one line,
151
+ * what is inside, and the picker's own button. `on`: the one picked (or Gem's pick); `badge` sits on the picture.
152
+ */
153
+ export function CreateCard({ picture, audience, eyebrow, title, line, inside, note, badge, on, action, dashed, className, data }: {
154
+ picture: ReactNode;
155
+ audience?: CreateAudience;
156
+ /** What it does, after the temperature: "One product", "Deciding to trust". */
157
+ eyebrow?: string;
158
+ title: ReactNode;
159
+ line?: ReactNode;
160
+ inside?: ReactNode;
161
+ /** One sentence for a slot the card leaves empty, and why ("Holds no product; products go on a landing page."). */
162
+ note?: ReactNode;
163
+ badge?: string;
164
+ on?: boolean;
165
+ /** The picker's button (or buttons): what choosing it does stays the picker's. */
166
+ action?: ReactNode;
167
+ /** A blank start: the card is drawn with a dashed edge. */
168
+ dashed?: boolean;
169
+ className?: string;
170
+ /** `data-*` attributes for the card's root (a picker's own handle on it: `data-create-card`). */
171
+ data?: Record<`data-${string}`, string>;
172
+ }) {
173
+ const aud = audience ?? "any";
174
+ const words = [audience ? CREATE_AUDIENCE[aud].eyebrow : null, eyebrow].filter(Boolean).join(" · ");
175
+ return (
176
+ <div className={cx("ui-create-card", on && "ui-create-card--on", dashed && "ui-create-card--dashed", className)} role="listitem" {...data}>
177
+ <div className="ui-create-card__pic">
178
+ {picture}
179
+ {badge ? <span className="ui-create-card__badge">{badge}</span> : null}
180
+ </div>
181
+ <div className="ui-create-card__body">
182
+ {words ? <span className={EYEBROW[aud]}><span className={DOT[aud]} aria-hidden="true" />{words}</span> : null}
183
+ <h3 className="ui-create-card__title">{title}</h3>
184
+ {line ? <p className="ui-create-card__line">{line}</p> : null}
185
+ {inside ? <p className="ui-create-card__inside">{inside}</p> : null}
186
+ {note ? <p className="ui-create-card__note">{note}</p> : null}
187
+ {action ? <div className="ui-create-card__act">{action}</div> : null}
188
+ </div>
189
+ </div>
190
+ );
191
+ }
192
+
193
+ /** A card's picture of what is inside, in order: glass tiles on the Stage, the first one lit. */
194
+ export function CreateParts({ parts, max = 4 }: { parts: readonly string[]; max?: number }) {
195
+ const shown = parts.slice(0, max);
196
+ return (
197
+ <Stage className="ui-create-pic">
198
+ {shown.map((p, i) => <StageTile key={`${i}-${p}`} on={i === 0}><em>{String(i + 1).padStart(2, "0")}</em>{p}</StageTile>)}
199
+ {parts.length > shown.length ? <span className="ui-create-pic__more">+{parts.length - shown.length} more</span> : null}
200
+ </Stage>
201
+ );
202
+ }
203
+
204
+ /** A card's picture of a path: each step a tile, an arrow between. A step may carry a real picture (a product photo). */
205
+ export function CreatePath({ steps }: { steps: ReadonlyArray<{ label: string; image?: string | null }> }) {
206
+ return (
207
+ <Stage className="ui-create-pic ui-create-pic--path">
208
+ <div className="ui-create-path">
209
+ {steps.map((s, i) => (
210
+ <span key={`${i}-${s.label}`} className="ui-create-path__step">
211
+ {i > 0 ? <span className="ui-create-path__arrow">→</span> : null}
212
+ <span className="ui-create-path__tile">
213
+ {s.image ? <img src={s.image} alt="" loading="lazy" referrerPolicy="no-referrer" /> : null}
214
+ <span>{s.label}</span>
215
+ </span>
216
+ </span>
217
+ ))}
218
+ </div>
219
+ </Stage>
220
+ );
221
+ }
package/src/dialog.tsx CHANGED
@@ -25,6 +25,8 @@ const cx = (...p: Array<string | false | null | undefined>) => p.filter(Boolean)
25
25
  *
26
26
  * - The backdrop closes it only when the press STARTED there too: a text selection dragged from the panel and released
27
27
  * over the scrim lands its click on the dialog (the common ancestor), and must not close it (review #4062).
28
+ * - `[data-autofocus]` inside it gets the focus on opening, as in the kit's Popover (a picker's search box: `search.autoFocus`);
29
+ * without one the browser's rule applies, the first control, which is the head's ✕.
28
30
  * - `focusPanel`: after opening, focus the dialog itself (it needs `tabIndex={-1}`) instead of its first control, so a
29
31
  * second Enter does not follow the head's first link (Sheet's "Open full profile").
30
32
  * - Unmounted while open (a route that drew it went away), focus still goes back to the opener.
@@ -54,6 +56,7 @@ export function useModalDialog(open: boolean, onClose: () => void, { focusPanel
54
56
  d.showModal();
55
57
  shown.current = true;
56
58
  if (focusPanel) d.focus({ preventScroll: true });
59
+ else d.querySelector<HTMLElement>("[data-autofocus]")?.focus({ preventScroll: true });
57
60
  }
58
61
  if (!open && d.open) d.close();
59
62
  }, [open, focusPanel]);
@@ -0,0 +1,183 @@
1
+ "use client";
2
+ // COLOR PICKER (24/10/2026, Chris: the colour picker should be standard and look right; "ưu tiên ui ux dễ dùng"). The panel a
3
+ // colour field's swatch opens (ColorControl → Popover). Before it the swatch opened the OPERATING SYSTEM's picker: a different
4
+ // window on every machine, no opacity, none of the theme's colours. Learnt from GemPages (an in-app square, hue and opacity, an
5
+ // eyedropper, recent colours) and NOT copied where it is worse (its square is hidden on desktop until a second click, and works
6
+ // with a mouse only; it offers no theme colours):
7
+ // · the square (saturation × brightness) works with the pointer AND the keys: ← → saturation, ↑ ↓ brightness, Shift for 10;
8
+ // · hue and opacity are native ranges (keys, screen readers, a finger: free), opacity over a checkerboard in the colour;
9
+ // · the hex box takes a colour as typed (3 or 6 digits, with or without #); the eyedropper picks one from the screen where
10
+ // the browser has `EyeDropper` (Chrome, Edge);
11
+ // · the theme's colours (they write `var(--gem-color-<role>)`: the page keeps following the theme), the recent ones, and None;
12
+ // · a pick keeps the value's transparency and its way of writing (`pickSwatch`, as the native swatch did); while a drag lasts
13
+ // it writes at most every 80 ms and once when it ends, so the canvas follows without a write per pixel.
14
+ // Its own part (`editor-color.css`).
15
+ import "../editor.css"; // the colour chips (.gemboss-ei-sw) are the editor's
16
+ import "../editor-color.css";
17
+ import React, { useEffect, useRef, useState } from "react";
18
+ import { Icon } from "../icons";
19
+ import { hexOf, opacityOf, parseColor, pickSwatch, withOpacity, type Rgba } from "./swatch";
20
+ import type { ColorChoice } from "./controls";
21
+
22
+ export interface ColorPickerProps {
23
+ /** The field's value now (what the theme chips and None compare with). */
24
+ value: string;
25
+ /** The colour picks start from: the value, or the colour a theme chip it holds paints. Empty opens on white. */
26
+ base?: string;
27
+ /** Called with each new value (throttled while a drag lasts, then once at its end). */
28
+ onChange: (value: string) => void;
29
+ /** The field's name, for the controls' names ("Background hue"). */
30
+ label: string;
31
+ choices?: readonly ColorChoice[];
32
+ /** A "None" chip that empties the field (Not set). */
33
+ allowNone?: boolean;
34
+ }
35
+
36
+ type Hsv = { h: number; s: number; v: number };
37
+ const clamp = (n: number, lo: number, hi: number) => Math.min(hi, Math.max(lo, n));
38
+
39
+ function hsvOf({ r, g, b }: Rgba, keepHue = 0): Hsv {
40
+ const R = r / 255, G = g / 255, B = b / 255, max = Math.max(R, G, B), min = Math.min(R, G, B), d = max - min;
41
+ let h = keepHue;
42
+ if (d) h = max === R ? ((G - B) / d) % 6 : max === G ? (B - R) / d + 2 : (R - G) / d + 4;
43
+ if (d) h = (h * 60 + 360) % 360;
44
+ return { h, s: max ? (d / max) * 100 : 0, v: max * 100 };
45
+ }
46
+ function rgbOf({ h, s, v }: Hsv) {
47
+ const S = s / 100, V = v / 100, c = V * S, x = c * (1 - Math.abs(((h / 60) % 2) - 1)), m = V - c;
48
+ const [r, g, b] = h < 60 ? [c, x, 0] : h < 120 ? [x, c, 0] : h < 180 ? [0, c, x] : h < 240 ? [0, x, c] : h < 300 ? [x, 0, c] : [c, 0, x];
49
+ return { r: (r + m) * 255, g: (g + m) * 255, b: (b + m) * 255 };
50
+ }
51
+
52
+ export function ColorPicker({ value, base, onChange, label, choices, allowNone = true }: ColorPickerProps) {
53
+ const from = base ?? value;
54
+ const parsed = parseColor(from);
55
+ const rgba: Rgba = parsed ?? { r: 255, g: 255, b: 255, a: 1 };
56
+ // The hue is kept here: a grey or a black has none, and dragging to one must not throw the square back to red.
57
+ const [hsv, setHsv] = useState<Hsv>(() => hsvOf(rgba));
58
+ // A value from outside (a chip, the text box, Undo) moves the square; our own echo does not, nor anything while a drag lasts
59
+ // (a throttled write comes back older than the pointer, and the square would jump back to it).
60
+ const emitted = useRef<string | null>(null);
61
+ const dragging = useRef(false);
62
+ useEffect(() => {
63
+ if (dragging.current || from === emitted.current) return;
64
+ setHsv((now) => hsvOf(rgba, now.h));
65
+ }, [from]); // eslint-disable-line react-hooks/exhaustive-deps
66
+
67
+ // Writes: a key or a click at once; a drag at most every 80 ms, and always its last one.
68
+ const last = useRef(0);
69
+ const trailing = useRef<ReturnType<typeof setTimeout> | null>(null);
70
+ const send = (next: string) => { emitted.current = next; last.current = Date.now(); onChange(next); };
71
+ const emit = (next: string, final = !dragging.current) => {
72
+ if (trailing.current) { clearTimeout(trailing.current); trailing.current = null; }
73
+ const now = Date.now();
74
+ if (final || now - last.current >= 80) { send(next); return; }
75
+ trailing.current = setTimeout(() => { trailing.current = null; send(next); }, 80 - (now - last.current));
76
+ };
77
+ useEffect(() => () => { if (trailing.current) clearTimeout(trailing.current); }, []);
78
+ const write = (h: Hsv, final?: boolean) => { setHsv(h); emit(pickSwatch(from, hexOf(rgbOf(h))), final); };
79
+ // A bar pressed and let go without moving writes nothing: a plain click rewrote a theme token as its hex, and hsl / oklch / #f00
80
+ // as rgb (review of #5296). `moved` says the bar's value changed during this press.
81
+ const moved = useRef(false);
82
+ const dragStart = () => { dragging.current = true; moved.current = false; };
83
+ const dragEnd = () => { dragging.current = false; };
84
+ // The opacity bar's value while it is held: a controlled range only moves when a (throttled) write lands, so between writes React
85
+ // put it back, and the release read that old value and wrote it over the one the pointer left (review of #5296).
86
+ const [alphaHeld, setAlphaHeld] = useState<number | null>(null);
87
+
88
+ // The square: pointer, then keys.
89
+ const area = useRef<HTMLDivElement>(null);
90
+ const fromPointer = (e: React.PointerEvent, final?: boolean) => {
91
+ const r = area.current!.getBoundingClientRect();
92
+ write({ h: hsv.h, s: clamp(((e.clientX - r.left) / r.width) * 100, 0, 100), v: clamp(100 - ((e.clientY - r.top) / r.height) * 100, 0, 100) }, final);
93
+ };
94
+ const areaKey = (e: React.KeyboardEvent) => {
95
+ const step = e.shiftKey ? 10 : 1;
96
+ const d = { ArrowLeft: [-step, 0], ArrowRight: [step, 0], ArrowUp: [0, step], ArrowDown: [0, -step] }[e.key];
97
+ if (!d) return;
98
+ e.preventDefault();
99
+ write({ h: hsv.h, s: clamp(hsv.s + d[0]!, 0, 100), v: clamp(hsv.v + d[1]!, 0, 100) }, true);
100
+ };
101
+
102
+ const alpha = opacityOf(from);
103
+ const pure = `hsl(${Math.round(hsv.h)} 100% 50%)`;
104
+ const now = hexOf(rgbOf(hsv));
105
+ const [hexDraft, setHexDraft] = useState<string | null>(null);
106
+ const commitHex = (raw: string) => {
107
+ setHexDraft(null);
108
+ const t = raw.trim().replace(/^#?/, "#");
109
+ if (!/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.test(t)) return;
110
+ const next = pickSwatch(from, t);
111
+ const c = parseColor(next);
112
+ if (c) setHsv((h) => hsvOf(c, h.h));
113
+ emit(next, true);
114
+ };
115
+ const canDrop = typeof window !== "undefined" && "EyeDropper" in window;
116
+ const dropper = async () => {
117
+ try {
118
+ const picked = await new (window as unknown as { EyeDropper: new () => { open: () => Promise<{ sRGBHex: string }> } }).EyeDropper().open();
119
+ const next = pickSwatch(from, picked.sRGBHex);
120
+ const c = parseColor(next);
121
+ if (c) setHsv((h) => hsvOf(c, h.h));
122
+ emit(next, true);
123
+ } catch { /* closed with Escape: nothing picked */ }
124
+ };
125
+ const theme = (choices ?? []).filter((c) => c.group !== "recent");
126
+ const recent = (choices ?? []).filter((c) => c.group === "recent");
127
+ const chips = (list: readonly ColorChoice[], name: string) => list.length ? (
128
+ <div className="gemboss-ei-cp-group">
129
+ <span className="gemboss-ei-cp-label">{name}</span>
130
+ <div className="gemboss-ei-cp-chips" role="group" aria-label={`${label}: ${name.toLowerCase()}`}>
131
+ {list.map((c) => {
132
+ const on = c.value === value.trim();
133
+ return <button key={c.value} type="button" className={`gemboss-ei-sw${on ? " on" : ""}`} title={c.label} aria-label={c.label} aria-pressed={on}
134
+ style={{ background: c.swatch }} onClick={() => { emitted.current = null; onChange(c.value); }} />;
135
+ })}
136
+ </div>
137
+ </div>
138
+ ) : null;
139
+
140
+ return (
141
+ <div className="gemboss-ei-cp" style={{ "--cp-hue": pure, "--cp-now": now } as React.CSSProperties}>
142
+ <div ref={area} className="gemboss-ei-cp-area" role="slider" tabIndex={0} data-autofocus=""
143
+ aria-label={`${label}: saturation and brightness`} aria-valuemin={0} aria-valuemax={100} aria-valuenow={Math.round(hsv.s)}
144
+ aria-valuetext={`Saturation ${Math.round(hsv.s)}%, brightness ${Math.round(hsv.v)}%`}
145
+ onPointerDown={(e) => { e.currentTarget.setPointerCapture(e.pointerId); e.currentTarget.focus(); dragStart(); fromPointer(e); }}
146
+ onPointerMove={(e) => { if (e.currentTarget.hasPointerCapture(e.pointerId)) fromPointer(e); }}
147
+ onPointerUp={(e) => { if (e.currentTarget.hasPointerCapture(e.pointerId)) { dragEnd(); fromPointer(e, true); } }}
148
+ onPointerCancel={dragEnd}
149
+ onKeyDown={areaKey}>
150
+ <span className="gemboss-ei-cp-thumb" style={{ left: `${hsv.s}%`, top: `${100 - hsv.v}%` }} />
151
+ </div>
152
+ <input type="range" className="gemboss-ei-cp-hue" min={0} max={359} step={1} value={Math.round(hsv.h)} aria-label={`${label} hue`}
153
+ onPointerDown={dragStart} onChange={(e) => { moved.current = true; write({ ...hsv, h: Number(e.target.value) }); }}
154
+ onPointerUp={() => { dragEnd(); if (moved.current) emit(pickSwatch(from, now), true); }} onPointerCancel={dragEnd} />
155
+ <input type="range" className="gemboss-ei-cp-alpha" min={0} max={100} step={1} value={alphaHeld ?? alpha ?? 100} aria-label={`${label} opacity`}
156
+ disabled={alpha === null} onPointerDown={dragStart}
157
+ onChange={(e) => { const n = Number(e.target.value); moved.current = true; if (dragging.current) setAlphaHeld(n); emit(withOpacity(from, n)); }}
158
+ onPointerUp={() => { dragEnd(); const n = alphaHeld; setAlphaHeld(null); if (moved.current && n !== null) emit(withOpacity(from, n), true); }}
159
+ onPointerCancel={() => { dragEnd(); setAlphaHeld(null); }} />
160
+ <div className="gemboss-ei-cp-row">
161
+ <span className="gemboss-ei-cp-now" aria-hidden />
162
+ <input className="gemboss-field gemboss-ei-cp-hex" aria-label={`${label} hex`} spellCheck={false} autoComplete="off"
163
+ value={hexDraft ?? (parsed ? now.toUpperCase() : "")} placeholder="#FFFFFF"
164
+ // Only what was typed is written: a blur with nothing typed since (the popover handing the focus back) writes nothing.
165
+ onChange={(e) => setHexDraft(e.target.value)} onBlur={() => { if (hexDraft !== null) commitHex(hexDraft); }}
166
+ onKeyDown={(e) => { if (e.key === "Enter" && !e.nativeEvent.isComposing && hexDraft !== null) { e.preventDefault(); commitHex(hexDraft); } }} />
167
+ <span className="gemboss-ei-cp-pct" aria-hidden>{alpha === null ? "" : `${alpha}%`}</span>
168
+ {canDrop ? (
169
+ <button type="button" className="gemboss-ei-cp-drop" aria-label="Pick a color from the screen" title="Pick a color from the screen" onClick={dropper}>
170
+ <Icon name="eyedropper" size={16} />
171
+ </button>
172
+ ) : null}
173
+ </div>
174
+ {chips(theme, "Theme")}
175
+ {chips(recent, "Recent")}
176
+ {allowNone ? (
177
+ <button type="button" className="gemboss-ei-cp-none" aria-pressed={!value.trim()} onClick={() => { emitted.current = null; onChange(""); }}>
178
+ <span className="gemboss-ei-cp-none-sw" aria-hidden />None
179
+ </button>
180
+ ) : null}
181
+ </div>
182
+ );
183
+ }
@@ -11,10 +11,13 @@
11
11
  // · the edge box hands each keystroke to the caller (`onChange(side, raw)`) and says when to commit (`onCommit`, on
12
12
  // blur): the caller decides what an empty edge means, and the admin has three answers to that on purpose.
13
13
  import "../editor.css"; // its own stylesheet travels with it (0.23.0): a surface that never renders it never loads it
14
+ import "../editor-color.css"; // the swatch button (ColorControl); the picker's own rules are in it too
14
15
  import { useEffect, useId, useRef, useState } from "react";
15
16
  import type React from "react";
16
17
  import { cssUrl } from "./css-url";
17
- import { opacityOf, pickSwatch, swatchState, swatchWhy, withOpacity } from "./swatch";
18
+ import { ColorPicker } from "./color-picker";
19
+ import { Popover } from "./popover";
20
+ import { opacityOf, parseColor, swatchState, swatchWhy, withOpacity } from "./swatch";
18
21
  import { Segmented } from "../segmented";
19
22
 
20
23
  const blurOnEnter = (e: React.KeyboardEvent<HTMLInputElement>) => {
@@ -156,32 +159,49 @@ export interface ColorControlProps {
156
159
  /** Colours offered as chips while the field is in use (the focus inside it): the theme's colours by role, each with the colour
157
160
  * the page draws for it, then the ones used lately. A click writes `value`. None: no chips (the theme inspector, no page). */
158
161
  choices?: readonly ColorChoice[];
162
+ /** The picker's None, which empties the field (default true). False where an empty value is not one (a gradient's stop). */
163
+ allowNone?: boolean;
164
+ /** An id the text box is also described by (a field's "not saved" line), beside the swatch's own reason. */
165
+ describedBy?: string;
166
+ /** The text box as it is typed, each keystroke, before its commit (blur / Enter). A host that keeps unsaved edits (a claims
167
+ * queue, a flush when the panel switches) holds the typing with it: kept only here, a value landing from elsewhere replaced
168
+ * the half-typed one unseen, and a switch that unmounts the box without a blur dropped it (review of #5323). */
169
+ onDraft?: (text: string) => void;
159
170
  }
160
171
 
161
- /** One chip: what it writes (`var(--gem-color-accent)`, `#3366ff`), what it is called, and the colour it paints. */
162
- export interface ColorChoice { value: string; label: string; swatch: string }
172
+ /** One chip: what it writes (`var(--gem-color-accent)`, `#3366ff`), what it is called, and the colour it paints. `group`: where the
173
+ * picker shows it ("Theme" or "Recent"); unset is a theme colour. */
174
+ export interface ColorChoice { value: string; label: string; swatch: string; group?: "theme" | "recent" }
163
175
 
164
176
  /**
165
- * `.gemboss-ei-color`: a native swatch beside a text box, and the colour's opacity in percent. The swatch shows any one colour
166
- * (`swatchState`: hex, rgb, hsl, oklch) and a pick keeps the value's transparency and way of writing (`pickSwatch`); it is
167
- * DISABLED (with the reason under it) for what is not one colour, a token or a gradient: `<input type="color">` would show
168
- * black for it and overwrite it with black on the first touch. The opacity box shows for a colour only (A4, 21/10/2026: 17% of
169
- * the colours on real pages carry an alpha, which no control could change).
177
+ * `.gemboss-ei-color`: a swatch beside a text box, and the colour's opacity in percent. The swatch shows any one colour
178
+ * (`swatchState`: hex, rgb, hsl, oklch) over a checkerboard, and opens the kit's colour picker beside the settings column
179
+ * (`Popover` + `ColorPicker`, 24/10/2026: it opened the operating system's picker, a different window on every machine with no
180
+ * opacity and no theme colours); a pick keeps the value's transparency and way of writing (`pickSwatch`). It is DISABLED (with
181
+ * the reason under it) for what is not one colour, a token or a gradient: a pick would overwrite it. The opacity box shows for
182
+ * a colour only (A4, 21/10/2026: 17% of the colours on real pages carry an alpha, which no control could change).
170
183
  */
171
- export function ColorControl({ id, value, onChange, disabled, label, placeholder, choices }: ColorControlProps) {
184
+ export function ColorControl({ id, value, onChange, disabled, label, placeholder, choices, allowNone = true, describedBy, onDraft }: ColorControlProps) {
172
185
  const [draft, setDraft] = useState(value);
173
186
  useEffect(() => { setDraft(value); }, [value]);
174
- // THE THEME'S COLOURS, CLICKED (A4b, 21/10/2026; Chris: "bấm trước gõ sau"): while the field is in use its chips show under it,
175
- // and go when the focus leaves it, so a panel of colour fields is no longer for them. A theme colour the field holds shows on
176
- // the swatch as the colour the page draws for it, and a pick there writes that colour as your own.
177
- const [inUse, setInUse] = useState(false);
187
+ // THE THEME'S COLOURS, CLICKED (A4b, 21/10/2026; Chris: "bấm trước gõ sau"): in the picker the swatch opens, under Theme and
188
+ // Recent, two clicks as before. Not any more as chips under the row while it had the focus (24/10/2026): they went when the focus
189
+ // left, so a press on the row below moved up under the pointer and its click was lost (review of #5296, measured: 38px). A theme
190
+ // colour the field holds shows on the swatch as the colour the page draws for it, and a pick there writes that colour as your own.
178
191
  const chosen = choices?.find((c) => c.value === draft.trim()) ?? null;
179
192
  const shown = chosen ? swatchState(chosen.swatch) : null;
180
193
  // NOT SET IS NOT BLACK (control standard §13b U7, Chris 20/10/2026): an empty colour drew the swatch black beside "Not set", so a
181
194
  // seller read a colour nobody chose. Empty, the swatch is white with the slash a colour picker draws for "none" (editor.css
182
195
  // `[data-empty]`), and opens on white.
183
196
  const empty = !draft.trim();
184
- const { swatch, usable } = shown?.usable ? shown : swatchState(draft, "#ffffff");
197
+ const { usable } = shown?.usable ? shown : swatchState(draft);
198
+ // What the swatch paints: the colour with its opacity (the checkerboard shows through). Nothing for what it cannot show (a
199
+ // gradient, an unknown token): the native swatch painted those black, a colour nobody chose (SwatchState's rule).
200
+ const parsed = usable ? parseColor(chosen ? chosen.swatch : draft) : null;
201
+ const paint = parsed ? `rgba(${Math.round(parsed.r)}, ${Math.round(parsed.g)}, ${Math.round(parsed.b)}, ${parsed.a})` : null;
202
+ const rowRef = useRef<HTMLDivElement>(null);
203
+ const swatchRef = useRef<HTMLButtonElement>(null);
204
+ const [picking, setPicking] = useState(false);
185
205
  // Why the swatch is off, said under it, read with it (a tooltip alone reached neither a finger nor the keys). The COMMITTED
186
206
  // value's reason, and kept while the panel saves (it disables every field): taken from the draft or dropped while saving, the
187
207
  // line came and went on every write and while a hex was typed (review of #4636). A draft that is a whole hex has none.
@@ -198,14 +218,22 @@ export function ColorControl({ id, value, onChange, disabled, label, placeholder
198
218
  if (next !== draft) { setDraft(next); onChange(next); }
199
219
  };
200
220
  return (
201
- <div className="gemboss-ei-color" onFocus={() => setInUse(true)}
202
- onBlur={(e) => { if (!e.currentTarget.contains(e.relatedTarget as Node | null)) setInUse(false); }}>
203
- <input type="color" className="gemboss-ei-swatch" aria-label={`${label} swatch`} value={swatch} data-empty={empty ? "" : undefined}
204
- disabled={disabled || !usable}
221
+ <div ref={rowRef} className="gemboss-ei-color">
222
+ <button ref={swatchRef} type="button" className="gemboss-ei-swatch" aria-label={`${label} swatch`} aria-haspopup="dialog" aria-expanded={picking}
223
+ data-empty={empty ? "" : undefined} disabled={disabled || !usable}
205
224
  title={usable ? undefined : swatchWhy(draft) ?? undefined} aria-describedby={why ? whyId : undefined}
206
- onChange={(e) => { const next = pickSwatch(chosen ? chosen.swatch : draft, e.target.value); setDraft(next); onChange(next); }} />
207
- <input id={id} className="gemboss-field gemboss-ei-inp" placeholder={placeholder ?? "Not set"} value={draft} disabled={disabled}
208
- onChange={(e) => setDraft(e.target.value)} onBlur={() => onChange(draft)} onKeyDown={blurOnEnter} />
225
+ onClick={() => setPicking((p) => !p)}>
226
+ <span className="gemboss-ei-swatch-fill" style={paint ? { "--sw": paint } as React.CSSProperties : undefined} />
227
+ </button>
228
+ {/* Open from the swatch's click until it is closed: not shut by a save in flight (the panels disable every field while one
229
+ runs, which closed it on each pick and opened it again with the focus: review of #5296), nor by the text box holding a
230
+ half-typed colour (it closed at "#" and opened at "#123", taking the focus and the rest of the typing). */}
231
+ <Popover open={picking} anchor={rowRef.current} returnTo={swatchRef.current} title={label} onClose={() => setPicking(false)}>
232
+ <ColorPicker value={draft} base={chosen ? chosen.swatch : draft} label={label} choices={choices} allowNone={allowNone}
233
+ onChange={(next) => { setDraft(next); onChange(next); }} />
234
+ </Popover>
235
+ <input id={id} className="gemboss-field gemboss-ei-inp" placeholder={placeholder ?? "Not set"} value={draft} disabled={disabled} aria-describedby={describedBy}
236
+ onChange={(e) => { setDraft(e.target.value); onDraft?.(e.target.value); }} onBlur={() => onChange(draft)} onKeyDown={blurOnEnter} />
209
237
  {/* A fixed narrow box beside the wide one (the row's own rule makes every .gemboss-ei-inp flex: 1): inline, not a new rule. */}
210
238
  {opacity !== null ? (
211
239
  // `data-alpha`: the hook editor-plain.js finds it by (the same box on a page without React).
@@ -213,18 +241,6 @@ export function ColorControl({ id, value, onChange, disabled, label, placeholder
213
241
  value={alphaDraft ?? `${opacity}%`} disabled={disabled}
214
242
  onChange={(e) => setAlphaDraft(e.target.value)} onBlur={(e) => commitAlpha(e.target.value)} onKeyDown={blurOnEnter} />
215
243
  ) : null}
216
- {inUse && choices?.length ? (
217
- // The kit's colour chips (.gemboss-ei-swatches / .gemboss-ei-sw, the theme inspector's Background row), on a line of their own.
218
- <div className="gemboss-ei-swatches" role="group" aria-label={`${label} colors`} style={{ flexBasis: "100%", flexWrap: "wrap" }}>
219
- {choices.map((c) => {
220
- const on = c.value === draft.trim();
221
- return (
222
- <button key={c.value} type="button" className={`gemboss-ei-sw${on ? " on" : ""}`} title={c.label} aria-label={c.label} aria-pressed={on}
223
- style={{ background: c.swatch }} disabled={disabled} onClick={() => { setDraft(c.value); onChange(c.value); }} />
224
- );
225
- })}
226
- </div>
227
- ) : null}
228
244
  {why ? <p id={whyId} className="gemboss-ei-color-why">{why}</p> : null}
229
245
  </div>
230
246
  );
@@ -53,4 +53,12 @@ export { SortableLayerList, type SortableLayerListProps, useRowDrag, dropIndex }
53
53
  export { RepeaterList, useKeyedRows, type RepeaterListProps, type KeyedRows } from "./repeater";
54
54
  // 16/10/2026: a closed choice of shapes (an image's ratio, a layout) as picture tiles; its own CSS part, editor-tiles.css.
55
55
  export { ChoiceTiles, type ChoiceTile, type ChoiceTilesProps } from "./tiles";
56
+ // 24/10/2026: a setting's small panel beside the settings column (top layer; a sheet at phone width); its own CSS part.
57
+ export { Popover, type PopoverProps } from "./popover";
58
+ // 24/10/2026: the colour picker ColorControl's swatch opens (square, hue, opacity, hex, eyedropper, theme/recent/None).
59
+ export { ColorPicker, type ColorPickerProps } from "./color-picker";
60
+ // 24/10/2026: the body of every "choose one" popup (search, rows, states); its own CSS part, editor-picker.css.
61
+ export { PickerList, type PickerItem, type PickerListProps, type PickerTone } from "./picker";
62
+ // 24/10/2026: the same search and states for things chosen by their picture (the shop's images, an icon library); its own CSS part.
63
+ export { PickerGrid, type PickerTile, type PickerGridProps } from "./picker-grid";
56
64
  export { LayerTree, type LayerTreeProps, type LayerTreeRow } from "./tree";