@gemboss/ui 0.55.1 → 0.56.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 (49) hide show
  1. package/CHANGELOG.md +372 -0
  2. package/README.md +10 -8
  3. package/catalog/editor.html +58 -34
  4. package/catalog/index.html +5 -5
  5. package/gemboss-ui.css +3 -3
  6. package/package.json +5 -1
  7. package/parts/components.css +2 -2
  8. package/parts/core.css +1 -1
  9. package/parts/shell.css +1 -1
  10. package/src/assistant/host.tsx +49 -2
  11. package/src/assistant/provider.tsx +18 -7
  12. package/src/assistant-chat.css +1 -1
  13. package/src/assistant-plain.js +1 -1
  14. package/src/assistant.css +1 -1
  15. package/src/chat.css +1 -1
  16. package/src/collections.css +1 -1
  17. package/src/collections.tsx +11 -2
  18. package/src/create-shell.css +1 -1
  19. package/src/create-shell.tsx +24 -9
  20. package/src/editor/color-picker.tsx +8 -4
  21. package/src/editor/controls.tsx +404 -58
  22. package/src/editor/index.ts +5 -3
  23. package/src/editor/layers.tsx +1 -1
  24. package/src/editor/new-value.ts +27 -0
  25. package/src/editor/panel.tsx +22 -9
  26. package/src/editor/repeater.tsx +66 -29
  27. package/src/editor/swatch.ts +7 -0
  28. package/src/editor/tiles.tsx +5 -3
  29. package/src/editor-color.css +1 -1
  30. package/src/editor-plain.js +1 -1
  31. package/src/editor-repeater.css +1 -1
  32. package/src/editor-tiles.css +1 -1
  33. package/src/editor.css +1 -1
  34. package/src/gem-holo.css +1 -0
  35. package/src/gem-holo.tsx +31 -0
  36. package/src/gemboss-field.css +1 -1
  37. package/src/gems.css +1 -0
  38. package/src/index.ts +3 -1
  39. package/src/kit-plain.css +1 -1
  40. package/src/list-page.tsx +6 -3
  41. package/src/menu.tsx +3 -1
  42. package/src/page-tabs.tsx +14 -0
  43. package/src/pager-extras.css +1 -1
  44. package/src/screens-arriving.ts +65 -0
  45. package/src/segmented.tsx +28 -4
  46. package/src/stage.css +1 -1
  47. package/src/stage.tsx +11 -4
  48. package/src/starting-point.tsx +25 -9
  49. package/src/ui.css +1 -1
@@ -12,13 +12,15 @@
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
14
  import "../editor-color.css"; // the swatch button (ColorControl); the picker's own rules are in it too
15
- import { useEffect, useId, useRef, useState } from "react";
15
+ import { forwardRef, useEffect, useId, useLayoutEffect, useRef, useState } from "react";
16
16
  import type React from "react";
17
17
  import { cssUrl } from "./css-url";
18
18
  import { ColorPicker } from "./color-picker";
19
+ import { useOnNewValue } from "./new-value";
19
20
  import { Popover } from "./popover";
20
- import { opacityOf, parseColor, swatchState, swatchWhy, withOpacity } from "./swatch";
21
+ import { opacityOf, parseColor, swatchState, swatchWhy, themeColorName, withOpacity } from "./swatch";
21
22
  import { Segmented } from "../segmented";
23
+ import { Menu, MenuItem } from "../menu";
22
24
 
23
25
  const blurOnEnter = (e: React.KeyboardEvent<HTMLInputElement>) => {
24
26
  if (e.key === "Enter") { e.preventDefault(); (e.target as HTMLInputElement).blur(); }
@@ -44,6 +46,8 @@ export interface SegProps<T extends string = string> {
44
46
  label?: string;
45
47
  /** On the group (the admin narrows two-option rows with a max-width). */
46
48
  style?: React.CSSProperties;
49
+ /** Options per row: more wrap into rows (Segmented's `wrap`). ValueControl sets it past six chips. */
50
+ wrap?: number;
47
51
  }
48
52
 
49
53
  /**
@@ -51,9 +55,9 @@ export interface SegProps<T extends string = string> {
51
55
  * other switch in the editors (0.20.0; it was a grey track with a raised white tab of its own). `gemboss-ei-seg` stays on
52
56
  * the group as the hook editor-plain.js finds, and each button carries its `data-value`.
53
57
  */
54
- export function Seg<T extends string = string>({ options, value, onChange, disabled, label, style }: SegProps<T>) {
58
+ export function Seg<T extends string = string>({ options, value, onChange, disabled, label, style, wrap }: SegProps<T>) {
55
59
  return (
56
- <Segmented<T> fill className="gemboss-ei-seg" style={style} ariaLabel={label ?? ""} value={(value ?? "") as T | ""} onChange={onChange} disabled={disabled}
60
+ <Segmented<T> fill wrap={wrap} className="gemboss-ei-seg" style={style} ariaLabel={label ?? ""} value={(value ?? "") as T | ""} onChange={onChange} disabled={disabled}
57
61
  options={options.map((o) => ({ value: o.value, label: o.label ?? o.value, ...(o.name ? { ariaLabel: o.name, title: o.name } : {}) }))} />
58
62
  );
59
63
  }
@@ -65,7 +69,8 @@ export interface ValueControlProps {
65
69
  id?: string;
66
70
  /** The field's name: the chips are announced as "<label> presets". */
67
71
  label: string;
68
- /** The named values, smallest first, each `value` as the box would hold it ("" = none). Shown as "name · number". */
72
+ /** The named values in the order shown (smallest first for a number; text styles H1 first, as GemPages names them), each `value`
73
+ * as the box would hold it ("" = none). No `value` may be `custom`: that is the Custom chip's. */
69
74
  presets: ReadonlyArray<{ value: string; label: string; title?: string }>;
70
75
  /** What the box holds now: the stored value or the text being typed. */
71
76
  text: string;
@@ -90,38 +95,108 @@ export interface ValueControlProps {
90
95
  /** The keyboard a phone shows: "decimal" (default) has no minus key on iOS, so a value that goes below 0 asks for "text". */
91
96
  inputMode?: "decimal" | "text";
92
97
  disabled?: boolean;
98
+ /** CUSTOM, a last chip that holds the box (Chris 26/10/2026: the full type scale H1–H6, P1–P3 + Custom, as GemPages v7): where the
99
+ * chips are the way, the box and the slider show only while `open`, and then the chip is lit and no named value is. The caller
100
+ * decides `open` (the chip picked, or a value of its own held) and what the box holds when it opens; `onOpen` is the chip
101
+ * pressed. Without it the box always shows, as before. */
102
+ custom?: { label: string; open: boolean; onOpen: () => void };
93
103
  }
94
104
 
105
+ /** The Custom chip's value (its `data-value`): never a value the box holds, which is a number or a step's name. */
106
+ const CUSTOM_CHIP = "custom";
107
+ /** What the chips light for a box value none of them is: no chip's value. Seg lights the "" chip for no value at all (an unset choice
108
+ * IS its empty option), and a value of its own is not unset: Max width 500 lit "None", Delay 0.3 s lit "0" (Control UI C09, §0). */
109
+ const NO_CHIP = "\u0000";
110
+ /** Chips the narrowest settings column (266px, the theme inspector's) holds in one row (Small · Body · H4–H1, 17/10/2026): past it
111
+ * they wrap into two rows. */
112
+ const ONE_ROW = 6;
113
+
95
114
  /**
96
115
  * `.gemboss-ei-value` (0.38.0): a setting you can click, drag or type (Chris 15/10/2026: "vừa bấm được vừa nhập được, lười thì
97
- * bấm"). The named values first, as the kit's segmented control (one lights when the box holds it; a value of its own lights
98
- * none), then the number box with its unit and, for a bounded range, a slider. The caller owns the value: it turns chips, keys
99
- * and moves into saves.
116
+ * bấm"). The number box with its unit and, for a bounded range, a slider, then the named values as the kit's segmented control
117
+ * (one lights when the box holds it; a value of its own lights none). The caller owns the value: it turns chips, keys and moves
118
+ * into saves. With `custom`, the box and the slider sit behind a last chip, Custom (26/10/2026).
119
+ * TWO ROWS, not three (28/10/2026): in a label-beside Field the box and the slider take the label's line and the chips the full
120
+ * width under it (editor.css). Label, chips, then box and slider each on their own line made it 94px, and the four settings drawn
121
+ * so (line height, letter spacing, max width, min height) were ~39% of a Settings panel's height (control audit 27/10/2026).
100
122
  */
101
- export function ValueControl({ id, label, presets, text, placeholder, suffix, slider, onPreset, onText, onCommit, onSlide, onKeyDown, note, inputMode = "decimal", disabled }: ValueControlProps) {
102
- const lit = presets.find((p) => p.value === text.trim())?.value;
123
+ export function ValueControl({ id, label, presets, text, placeholder, suffix, slider, onPreset, onText, onCommit, onSlide, onKeyDown, note, inputMode = "decimal", disabled, custom }: ValueControlProps) {
124
+ const lit = custom?.open ? CUSTOM_CHIP : presets.find((p) => p.value === text.trim())?.value ?? (text.trim() === "" ? undefined : NO_CHIP);
125
+ // Chips in words ("Narrow · Medium", "Light · Regular") size from their words (editor.css); a row of numbers keeps equal cells, and
126
+ // so does one with a single word among numbers or steps (Border width's "None", the type ramp's "Custom" after H1–P3).
127
+ const worded = presets.filter((p) => /[a-z]{3,}/i.test(p.label)).length >= 2;
128
+ // A chip named in words carries its number ("Medium, 720 px"): said by a screen reader, shown on hover.
129
+ const chips = presets.map((p) => ({ value: p.value, label: p.label, ...(p.title ? { name: `${p.label}, ${p.title}` } : {}) }));
130
+ if (custom) chips.push({ value: CUSTOM_CHIP, label: custom.label });
131
+ // Two even rows past six (nine: H1–H5, then H6 · P1 · P2 · Custom, the last two cells wide), each chip still 44px under a finger.
132
+ const wrap = chips.length > ONE_ROW ? Math.ceil(chips.length / 2) : undefined;
103
133
  return (
104
134
  // A chip pressed right after typing keeps the box's focus: its blur would save what was typed, the save locks the field, and
105
135
  // the chip's click landed on a disabled chip (the spacing box's own guard, review of slice 5). The chip is the choice.
106
- <div className="gemboss-ei-value" onMouseDown={(e) => { if ((e.target as HTMLElement).closest('[role="group"] button')) e.preventDefault(); }}>
107
- {presets.length ? <Seg label={`${label} presets`} value={lit} disabled={disabled} onChange={onPreset}
108
- options={presets.map((p) => ({ value: p.value, label: p.label }))} /> : null}
109
- <div className="gemboss-ei-value-row">
136
+ <div className={worded ? "gemboss-ei-value gemboss-ei-value--words" : "gemboss-ei-value"} onMouseDown={(e) => { if ((e.target as HTMLElement).closest('[role="group"] button')) e.preventDefault(); }}>
137
+ {!custom || custom.open ? <div className="gemboss-ei-value-row">
110
138
  <UnitField className="gemboss-ei-value-box" unit={suffix} id={id} inputMode={inputMode} value={text} placeholder={placeholder}
111
139
  disabled={disabled} aria-label={label} onChange={(e) => onText(e.target.value)} onBlur={onCommit}
112
140
  onKeyDown={(e) => { onKeyDown?.(e); if (!e.defaultPrevented) blurOnEnter(e); }} />
113
141
  {slider && onSlide ? <RangeControl min={slider.min} max={slider.max} step={slider.step} value={slider.value} disabled={disabled} onChange={onSlide} /> : null}
114
- </div>
142
+ </div> : null}
143
+ {chips.length ? <Seg label={`${label} presets`} value={lit} disabled={disabled} wrap={wrap}
144
+ onChange={(v) => { if (custom && v === CUSTOM_CHIP) custom.onOpen(); else onPreset(v); }} options={chips} /> : null}
115
145
  {note ? <p className="gemboss-ei-hint" role="status">{note}</p> : null}
116
146
  </div>
117
147
  );
118
148
  }
119
149
 
150
+ // ── PickButton ────────────────────────────────────────────────────────────
151
+
152
+ export interface PickButtonProps {
153
+ /** The button's id (the Field's `htmlFor`). */
154
+ id?: string;
155
+ /** The field's name: the button is announced as "<label>: <value>". */
156
+ label: string;
157
+ /** What is chosen now, in words ("None", "Star", "Inter"). */
158
+ value: string;
159
+ /** A small picture of it (an icon, a swatch), before the words. */
160
+ picture?: React.ReactNode;
161
+ /** Whether the popover it opens is open. */
162
+ expanded: boolean;
163
+ disabled?: boolean;
164
+ /** A write it made is still on its way: the press does nothing and says it is busy, but the button keeps the focus (a disabled
165
+ * button drops it to the page, and the seller's place in the panel with it). */
166
+ waiting?: boolean;
167
+ /** The id of a line that says more about what is chosen (a font Google Fonts does not have): `aria-describedby`. */
168
+ describedBy?: string;
169
+ /** More classes, for where the row sits (the theme editor's bar sizes its page picker under a finger). */
170
+ className?: string;
171
+ /** A hover hint, where no label beside the button says what it chooses (the bar's page picker). */
172
+ title?: string;
173
+ onClick: (e: React.MouseEvent<HTMLButtonElement>) => void;
174
+ }
175
+
176
+ /**
177
+ * A choice made in a popover, shown in its row as ONE line (27/10/2026): what is chosen (a picture and its name) and a ▾, in the kit's
178
+ * pressable box (`.gemboss-control`, the field's box for a button: 32px under a mouse, 44px under a finger). A choice of many (twenty icons) drawn open in the row made
179
+ * the setting the tallest of its panel for one rarely changed value (the button's Icon: 386px); the grid opens in the kit's Popover
180
+ * from here, as ColorControl's swatch opens the picker.
181
+ */
182
+ export const PickButton = forwardRef<HTMLButtonElement, PickButtonProps>(function PickButton({ id, label, value, picture, expanded, disabled, waiting, describedBy, className, title, onClick }, ref) {
183
+ return (
184
+ <button ref={ref} id={id} type="button" className={`gemboss-control gemboss-ei-pickbtn${className ? ` ${className}` : ""}`} aria-haspopup="dialog" aria-expanded={expanded}
185
+ aria-label={`${label}: ${value}`} aria-busy={waiting || undefined} aria-describedby={describedBy} disabled={disabled} title={title} onClick={(e) => { if (!waiting) onClick(e); }}>
186
+ {picture ? <span className="gemboss-ei-pickbtn-pic" aria-hidden>{picture}</span> : null}
187
+ <span className="gemboss-ei-pickbtn-text">{value}</span>
188
+ <span className="gemboss-ei-pickbtn-chev" aria-hidden>▾</span>
189
+ </button>
190
+ );
191
+ });
192
+
120
193
  // ── UnitField ───────────────────────────────────────────────────────────────────────────────────────────────────────
121
194
 
122
195
  export interface UnitFieldProps extends Omit<React.InputHTMLAttributes<HTMLInputElement>, "className" | "style"> {
123
196
  /** The unit after the value, inside the box ("px", "ms", "%"). Empty draws none. */
124
197
  unit?: string;
198
+ /** What comes before the value, inside the box (a page's "/pages/", as Polaris TextField's `prefix`). Empty draws none. */
199
+ prefix?: string;
125
200
  /** Classes on the box, e.g. `gemboss-ei-inp` for a row's full-width control, `gemboss-ei-value-box` in ValueControl. */
126
201
  className?: string;
127
202
  /** Style on the box (a fixed width where a row lays out several controls). */
@@ -135,9 +210,10 @@ export interface UnitFieldProps extends Omit<React.InputHTMLAttributes<HTMLInput
135
210
  * so a click or a tap anywhere in it, the unit included, focuses the input (one 44px target under a finger), as the kit's other
136
211
  * field groups do. One owner for the shape: FieldRenderer's number, ValueControl's box and the theme inspector's design rows.
137
212
  */
138
- export function UnitField({ unit, className, style, ...input }: UnitFieldProps) {
213
+ export function UnitField({ unit, prefix, className, style, ...input }: UnitFieldProps) {
139
214
  return (
140
215
  <label className={`gemboss-field gemboss-field--group${className ? ` ${className}` : ""}`} style={style}>
216
+ {prefix ? <span className="gemboss-ei-prefix">{prefix}</span> : null}
141
217
  <input {...input} className="gemboss-field__bare" />
142
218
  {unit ? <span className="gemboss-field__suffix">{unit}</span> : null}
143
219
  </label>
@@ -183,7 +259,7 @@ export interface ColorChoice { value: string; label: string; swatch: string; gro
183
259
  */
184
260
  export function ColorControl({ id, value, onChange, disabled, label, placeholder, choices, allowNone = true, describedBy, onDraft }: ColorControlProps) {
185
261
  const [draft, setDraft] = useState(value);
186
- useEffect(() => { setDraft(value); }, [value]);
262
+ useOnNewValue(() => setDraft(value), [value]);
187
263
  // 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
264
  // 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
265
  // 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
@@ -202,6 +278,18 @@ export function ColorControl({ id, value, onChange, disabled, label, placeholder
202
278
  const rowRef = useRef<HTMLDivElement>(null);
203
279
  const swatchRef = useRef<HTMLButtonElement>(null);
204
280
  const [picking, setPicking] = useState(false);
281
+ // A THEME COLOUR IS SAID BY ITS NAME (Control UI C13, 29/10/2026): the box read `var(--gem-color-accent)`; it reads "Accent · Theme"
282
+ // (Builder.io's "● Brand Yellow", Wix's and Shopify's palettes), so a seller knows the colour follows the theme. The name is the
283
+ // theme chip's when one matches (a chip without a group is a theme one, as the picker files it), else the token's own
284
+ // (themeColorName: no palette needed, any case). It is drawn OVER the box while the box is not focused; the box's own value never
285
+ // changes (a value swapped on focus raced a select-all, and the typing was appended to it). A save that disables the box gives the
286
+ // name back (no blur comes from a disabled box).
287
+ const [typing, setTyping] = useState(false);
288
+ useOnNewValue(() => { if (disabled) setTyping(false); }, [disabled]);
289
+ const tokenLabel = themeColorName(draft);
290
+ const themeLabel = tokenLabel ? (chosen && chosen.group !== "recent" ? chosen.label : tokenLabel) : null;
291
+ // Focused, the token is selected whole, so what is typed replaces it; again on a click's mouseup, which would put the caret back.
292
+ const selectOnUp = useRef(false);
205
293
  // Why the swatch is off, said under it, read with it (a tooltip alone reached neither a finger nor the keys). The COMMITTED
206
294
  // value's reason, and kept while the panel saves (it disables every field): taken from the draft or dropped while saving, the
207
295
  // 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.
@@ -229,15 +317,24 @@ export function ColorControl({ id, value, onChange, disabled, label, placeholder
229
317
  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
318
  half-typed colour (it closed at "#" and opened at "#123", taking the focus and the rest of the typing). */}
231
319
  <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}
320
+ <ColorPicker value={draft} base={chosen ? chosen.swatch : draft} label={label} choices={choices} allowNone={allowNone} noneLabel={placeholder}
233
321
  onChange={(next) => { setDraft(next); onChange(next); }} />
234
322
  </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} />
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. */}
323
+ <span className="gemboss-ei-color-box">
324
+ <input id={id} className="gemboss-field gemboss-ei-inp" placeholder={placeholder ?? "Not set"} value={draft} disabled={disabled} aria-describedby={describedBy}
325
+ title={themeLabel ? `${themeLabel} (theme colour)` : undefined} data-theme-colour={themeLabel && !typing ? "" : undefined}
326
+ onFocus={(e) => { setTyping(true); if (themeLabel) { const box = e.currentTarget; selectOnUp.current = true; requestAnimationFrame(() => box.select()); } }}
327
+ onMouseUp={(e) => { if (selectOnUp.current) { selectOnUp.current = false; e.preventDefault(); e.currentTarget.select(); } }}
328
+ onChange={(e) => { setDraft(e.target.value); onDraft?.(e.target.value); }}
329
+ onBlur={() => { setTyping(false); selectOnUp.current = false; onChange(draft); }}
330
+ onKeyDown={(e) => { selectOnUp.current = false; blurOnEnter(e); }} />
331
+ {themeLabel && !typing ? <span className="gemboss-ei-color-name" aria-hidden="true">{themeLabel}<span> · Theme</span></span> : null}
332
+ </span>
333
+ {/* A fixed narrow box beside the wide one: its width is editor-color.css's (64px, 72px at a phone's 16px type, where "100%" did
334
+ not fit 64: Control UI C10). */}
238
335
  {opacity !== null ? (
239
336
  // `data-alpha`: the hook editor-plain.js finds it by (the same box on a page without React).
240
- <input className="gemboss-field gemboss-ei-inp" data-alpha="" aria-label={`${label} opacity`} inputMode="numeric" style={{ flex: "0 0 64px" }}
337
+ <input className="gemboss-field gemboss-ei-inp" data-alpha="" aria-label={`${label} opacity`} inputMode="numeric"
241
338
  value={alphaDraft ?? `${opacity}%`} disabled={disabled}
242
339
  onChange={(e) => setAlphaDraft(e.target.value)} onBlur={(e) => commitAlpha(e.target.value)} onKeyDown={blurOnEnter} />
243
340
  ) : null}
@@ -274,36 +371,44 @@ export type EdgeSide = "t" | "r" | "b" | "l";
274
371
  const SIDES: readonly EdgeSide[] = ["t", "r", "b", "l"];
275
372
  const SIDE_NAME: Record<EdgeSide, string> = { t: "top", r: "right", b: "bottom", l: "left" };
276
373
 
277
- export interface EdgeBoxProps {
278
- /** The field's name; each box is announced as "<label> top / right / bottom / left". */
374
+ export interface EdgeBoxProps<K extends string = EdgeSide> {
375
+ /** The field's name; each box is announced as "<label> top / right / bottom / left" (or its box's `name`). */
279
376
  label: string;
280
377
  /** What each box shows. A number, the raw text being typed, or empty. */
281
- values: Partial<Record<EdgeSide, string | number>>;
282
- /** Per side; default "0". The admin shows the inherited desktop value here while editing the phone override. */
283
- placeholders?: Partial<Record<EdgeSide, string>>;
378
+ values: Partial<Record<K, string | number>>;
379
+ /** Per box; default "0". The admin shows the inherited desktop value here while editing the phone override. */
380
+ placeholders?: Partial<Record<K, string>>;
284
381
  /** Every keystroke in one box. */
285
- onChange: (side: EdgeSide, raw: string) => void;
382
+ onChange: (side: K, raw: string) => void;
286
383
  /** A box lost focus (Enter blurs): commit what the boxes hold. */
287
384
  onCommit: () => void;
288
385
  disabled?: boolean;
289
386
  /** `gemboss-field--narrow` on each box (the field family's tight lane). Default true. */
290
387
  narrow?: boolean;
291
- /** Ids for the boxes, per side. */
292
- ids?: Partial<Record<EdgeSide, string>>;
388
+ /** Ids for the boxes, per box. */
389
+ ids?: Partial<Record<K, string>>;
293
390
  /**
294
- * A side's letter dragged sideways (Figma's and Webflow's scrub, 0.37.0): `dx`, the pixels moved since the press, and the keys
295
- * held now, for the caller to turn into a value. A mouse or a pen only: a finger on the letter scrolls the panel as before, and
296
- * the box takes the number (its 44px under a finger is the control there). Present, each letter is a 24px drag row.
391
+ * The boxes, when they are not the four sides (Control UI C02): one for all sides, vertical · horizontal, top · bottom. Each with
392
+ * its key, the mark beside its number (a letter or an arrow) and its name for a screen reader. Omitted: T · R · B · L.
297
393
  */
298
- onScrub?: (side: EdgeSide, dx: number, keys: { shiftKey: boolean; altKey: boolean }) => void;
394
+ boxes?: ReadonlyArray<{ key: K; mark: string; name: string }>;
395
+ /**
396
+ * A box's mark dragged sideways (Figma's and Webflow's scrub, 0.37.0): `dx`, the pixels moved since the press, and the keys
397
+ * held now, for the caller to turn into a value. A mouse or a pen only: a finger on the mark scrolls the panel as before, and
398
+ * the box takes the number (its 44px under a finger is the control there). Present, each mark is a 24px drag row.
399
+ */
400
+ onScrub?: (side: K, dx: number, keys: { shiftKey: boolean; altKey: boolean }) => void;
299
401
  /** The drag let go: `moved` when it changed anything (the caller saves once, one Undo step); not moved, it was a click. */
300
- onScrubEnd?: (side: EdgeSide, moved: boolean) => void;
402
+ onScrubEnd?: (side: K, moved: boolean) => void;
301
403
  }
302
404
 
303
- /** `.gemboss-ei-edgebox`: four px boxes, T · R · B · L, mono and centred. */
304
- export function EdgeBox({ label, values, placeholders, onChange, onCommit, disabled, narrow = true, ids, onScrub, onScrubEnd }: EdgeBoxProps) {
405
+ const SIDE_BOXES = SIDES.map((s) => ({ key: s, mark: s.toUpperCase(), name: SIDE_NAME[s] }));
406
+
407
+ /** `.gemboss-ei-edgebox`: px boxes, T · R · B · L by default (or the caller's `boxes`), mono and centred. */
408
+ export function EdgeBox<K extends string = EdgeSide>({ label, values, placeholders, onChange, onCommit, disabled, narrow = true, ids, boxes, onScrub, onScrubEnd }: EdgeBoxProps<K>) {
305
409
  const cls = narrow ? "gemboss-field gemboss-field--narrow gemboss-ei-inp" : "gemboss-field gemboss-ei-inp";
306
- const drag = useRef<{ side: EdgeSide; id: number; x: number; moved: boolean } | null>(null);
410
+ const drag = useRef<{ side: K; id: number; x: number; moved: boolean } | null>(null);
411
+ const shown = boxes ?? (SIDE_BOXES as unknown as ReadonlyArray<{ key: K; mark: string; name: string }>);
307
412
  const end = (e: React.PointerEvent<HTMLSpanElement>) => {
308
413
  const d = drag.current;
309
414
  if (!d || d.id !== e.pointerId) return;
@@ -312,15 +417,15 @@ export function EdgeBox({ label, values, placeholders, onChange, onCommit, disab
312
417
  };
313
418
  return (
314
419
  <div className="gemboss-ei-edgebox">
315
- {SIDES.map((s) => (
420
+ {shown.map(({ key: s, mark, name }) => (
316
421
  <div className="gemboss-ei-edge" key={s}>
317
422
  <input className={cls} inputMode="numeric" placeholder={placeholders?.[s] ?? "0"}
318
- aria-label={`${label} ${SIDE_NAME[s]}`} id={ids?.[s]} value={values[s] ?? ""} disabled={disabled}
423
+ aria-label={`${label} ${name}`} id={ids?.[s]} value={values[s] ?? ""} disabled={disabled}
319
424
  onChange={(e) => onChange(s, e.target.value)} onBlur={onCommit} onKeyDown={blurOnEnter} />
320
425
  {onScrub ? (
321
426
  // Rendered while disabled too: a field that locks in the middle of a drag (another save landing) must not drop the
322
427
  // drag's handlers, or it never ends and nothing is saved (review of 3a). A drag only refuses to START when disabled.
323
- <span className="gemboss-ei-edge-scrub" title={`Drag to change ${SIDE_NAME[s]}`} aria-disabled={disabled || undefined}
428
+ <span className="gemboss-ei-edge-scrub" title={`Drag to change ${name}`} aria-disabled={disabled || undefined}
324
429
  onPointerDown={(e) => {
325
430
  if (disabled || e.pointerType === "touch" || e.button !== 0) return;
326
431
  e.preventDefault();
@@ -338,8 +443,8 @@ export function EdgeBox({ label, values, placeholders, onChange, onCommit, disab
338
443
  }}
339
444
  onPointerUp={end} onPointerCancel={end}
340
445
  // Its own capture only (the event bubbles from nothing here, but the check is the fleet's rule).
341
- onLostPointerCapture={(e) => { if (e.target === e.currentTarget) end(e); }}>{s.toUpperCase()}</span>
342
- ) : <span>{s.toUpperCase()}</span>}
446
+ onLostPointerCapture={(e) => { if (e.target === e.currentTarget) end(e); }}>{mark}</span>
447
+ ) : <span>{mark}</span>}
343
448
  </div>
344
449
  ))}
345
450
  </div>
@@ -348,25 +453,25 @@ export function EdgeBox({ label, values, placeholders, onChange, onCommit, disab
348
453
 
349
454
  // ── ImageControl ────────────────────────────────────────────────────────────────────────────────────────────────────
350
455
 
351
- /** A field's own button (an image slot's Library / Generate / Clear, a link's Choose, a panel's "+ Add"): the kit's `.ui-btn`, a Polaris
456
+ /** A field's own button (an image slot's Library / Generate / Remove, a link's Choose, a panel's "+ Add"): the kit's `.ui-btn`, a Polaris
352
457
  * secondary button (28px, 12px / 550, radius 8; 44px under a finger). It was a dashed pill (`.gemboss-ei-addchip`, 27px, 11px / 600,
353
458
  * radius 999): control standard U3, research pickers-2026-10-16 §13b. */
354
- export function ChipButton({ disabled, expanded, onClick, children }: {
459
+ export const ChipButton = forwardRef<HTMLButtonElement, {
355
460
  disabled?: boolean;
356
461
  /** `aria-expanded`, for a chip that opens something under it (the Library grid). */
357
462
  expanded?: boolean;
358
463
  onClick?: React.MouseEventHandler<HTMLButtonElement>;
359
464
  children: React.ReactNode;
360
- }) {
361
- return <button type="button" className="ui-btn" disabled={disabled} aria-expanded={expanded} onClick={onClick}>{children}</button>;
362
- }
465
+ }>(function ChipButton({ disabled, expanded, onClick, children }, ref) {
466
+ return <button ref={ref} type="button" className="ui-btn" disabled={disabled} aria-expanded={expanded} onClick={onClick}>{children}</button>;
467
+ });
363
468
 
364
469
  export interface ImageControlProps {
365
470
  /** The URL box's id. */
366
471
  id?: string;
367
472
  /** The committed URL: what the thumbnail shows. */
368
473
  value: string;
369
- /** A committed URL: on blur / Enter when the box differs from `value`, and "" from Clear. */
474
+ /** A committed URL: on blur / Enter when the box differs from `value`, a dropped file's, and "" from Remove. */
370
475
  onChange: (url: string) => void;
371
476
  disabled?: boolean;
372
477
  placeholder?: string;
@@ -376,27 +481,268 @@ export interface ImageControlProps {
376
481
  */
377
482
  draft?: string;
378
483
  onDraftChange?: (text: string) => void;
379
- /** Chips before Clear (`ChipButton`): Library, Generate. */
380
- actions?: React.ReactNode;
381
- /** Draw Clear while there is a value. Default true. */
484
+ /** Chips before Remove (`ChipButton`): Library, Generate. On an image card, the one chip beside its ⋯ (Replace); a function of
485
+ * whether it holds an image, as it shows, to name it ("Select image" / "Replace"). */
486
+ actions?: React.ReactNode | ((holds: boolean) => React.ReactNode);
487
+ /** An image card's ⋯ rows between "Paste a URL" and Remove (`MenuItem`s: Generate, Edit in Media Studio), while it holds an image
488
+ * (MediaCard `more`); and its chips while it is empty, after "Paste a URL" (`whileEmpty`: ✨ Generate). The card decides which. */
489
+ more?: React.ReactNode;
490
+ whileEmpty?: React.ReactNode;
491
+ /** An image card's ⋯ name, with the field's ("More actions for Image"). */
492
+ menuLabel?: string;
493
+ /** Draw Remove while there is a value (an image card: a row of its ⋯). Default true. */
382
494
  clearable?: boolean;
495
+ /**
496
+ * A file dropped on the control: the caller puts it where images live (the store's library) and answers with its URL, or why
497
+ * not. With it, an empty control is a place to drop an image and the URL box waits behind "Paste a URL" (Control UI C19).
498
+ * Without it, the control takes no drop and shows its URL box as before: a drop place that does nothing is no drop place.
499
+ */
500
+ onFile?: (file: File) => Promise<{ url: string } | { error: string }>;
501
+ /** The caller's name for an image URL, where it knows one (the library keeps an upload's own file name, its URL a content hash);
502
+ * else the card reads it from the URL (`imageFileName`). Asked for the image the card shows (a URL picked or dropped, at once). */
503
+ nameOf?: (url: string) => string | undefined;
504
+ /** The caller's size in bytes for an image URL, where it knows one (a library's record): read after its pixels, "· 188 KB". */
505
+ bytesOf?: (url: string) => number | undefined;
383
506
  }
384
507
 
385
- /** `.gemboss-ei-img`: a 52px thumbnail (— when empty) beside the URL box and its chips. */
386
- export function ImageControl({ id, value, onChange, disabled, placeholder, draft, onDraftChange, actions, clearable = true }: ImageControlProps) {
508
+ /** A file's size in a seller's words, as the Mac's Finder says it (1 KB = 1,000 bytes): "512 bytes", "188 KB", "2.5 MB". A size
509
+ * that rounds up to the next unit says that unit ("1.0 MB", not "1000 KB"); none, or not a size, says nothing. */
510
+ export function fileSizeWords(bytes: number): string {
511
+ if (!Number.isFinite(bytes) || bytes <= 0) return "";
512
+ const b = Math.round(bytes);
513
+ if (b < 1000) return `${b} bytes`;
514
+ const kb = Math.round(b / 1000);
515
+ if (kb < 1000) return `${kb} KB`;
516
+ const mb = b / 1e6;
517
+ return mb < 999.95 ? `${mb.toFixed(1)} MB` : `${(b / 1e9).toFixed(1)} GB`;
518
+ }
519
+
520
+ // The card's "Paste a URL" after Enter / Escape is placed in a layout effect, before a host's hold (which keeps the control that has
521
+ // the focus, in its own layout effect) looks at it. A layout effect does nothing on a server.
522
+ const useIsoLayoutEffect = typeof window === "undefined" ? useEffect : useLayoutEffect;
523
+
524
+ export interface MediaCardProps {
525
+ /** The 56px picture: an address, drawn as its background; or `picture`, a node (a video's first frame). Neither draws "—". */
526
+ thumbUrl?: string | null;
527
+ picture?: React.ReactNode;
528
+ /** The media's name (its file, its title) and what it is ("640 × 400 · 188 KB", "File · 0:18"). `name` undefined: nothing is
529
+ * set, and `empty` is said in their place (an empty name with media set still draws the row). */
530
+ name?: React.ReactNode;
531
+ /** The name's tooltip: the whole address. */
532
+ title?: string;
533
+ meta?: React.ReactNode;
534
+ /** `meta` read out when it changes ("Uploading…"). */
535
+ metaLive?: boolean;
536
+ empty: React.ReactNode;
537
+ /** The box behind the paste chip: its chip ("Paste a URL"), its id, its name and placeholder, and what it holds. */
538
+ pasteLabel: string;
539
+ boxId?: string;
540
+ boxLabel: string;
541
+ placeholder: string;
542
+ text: string;
543
+ onText: (next: string) => void;
544
+ /** Whether the box is open; the caller holds it (a refused write may open it again with what was typed). */
545
+ open: boolean;
546
+ onOpenChange: (open: boolean) => void;
547
+ /** Enter, or leaving the box: true when what was typed is taken (the box closes, wherever the focus went), false when it is
548
+ * refused (it stays open). */
549
+ onKeep: () => boolean;
550
+ /** The box takes the focus when it opens (default). False when it is opened again for the seller, who has gone elsewhere. */
551
+ boxAutoFocus?: boolean;
552
+ /** Escape: the box closes and the caller puts what it holds back. */
553
+ onLeave: () => void;
554
+ /** The box's own description and refusal: the caller's note under the card. */
555
+ boxDescribedBy?: string;
556
+ boxInvalid?: boolean;
557
+ /** Chips before the paste chip (Choose, Replace) and after it (a one-click fix). `before` may be drawn from whether the card holds
558
+ * media, by what it shows ("Select image" / "Replace"), so it never disagrees with the card. */
559
+ before?: React.ReactNode | ((holds: boolean) => React.ReactNode);
560
+ after?: React.ReactNode;
561
+ /** THE CARD'S ⋯ (Control UI C19 / C20, 30/10/2026): once it holds media, the paste chip and the rest go in one menu, so the card
562
+ * is its picture, its name and one chip (Choose / Replace) and ⋯. Its rows: "Paste a URL" (the box), `more` (the caller's
563
+ * `MenuItem`s: Generate, Edit in Media Studio), then Remove (`onRemove`, also offered when a link is set that plays nothing).
564
+ * While the box is open there is no ⋯ (opening it would take the focus from the box, which writes what was typed): Remove is a
565
+ * chip beside the box then, pressed without closing it (review of C19). */
566
+ more?: React.ReactNode;
567
+ /** Chips while the card is empty, after the paste chip: its other ways in (✨ Generate). Holding media, they are `more`'s rows. */
568
+ whileEmpty?: React.ReactNode;
569
+ onRemove?: () => void;
570
+ /** The ⋯'s name, said with the field's ("More actions for Image"). */
571
+ menuLabel?: string;
572
+ disabled?: boolean;
573
+ /** A file dragged over it (the caller decides whether it takes files): outlined. */
574
+ over?: boolean;
575
+ drop?: Pick<React.HTMLAttributes<HTMLDivElement>, "onDragOver" | "onDragLeave" | "onDrop">;
576
+ /** Under the chips: the caller's notes, a refusal. */
577
+ children?: React.ReactNode;
578
+ }
579
+
580
+ /**
581
+ * `.gemboss-ei-img` as A MEDIA CARD (Control UI C19 for an image, C20 for a video): a 56px picture beside the media's name and what it
582
+ * is; empty, what to do; the address box behind a "Paste a …" chip (a second way in, not the first thing seen). The one owner of the
583
+ * card's look and of its box (§9.3): it opens focused; Enter, or leaving it (for a chip of the card too, since 30/10/2026: it stayed
584
+ * open holding a link already written), keeps what was typed and closes it, unless the caller refuses it (it stays, with what was
585
+ * typed); Escape leaves things as they were; Enter and Escape put the focus back on the chip.
586
+ * While the box is open the chips do not take the focus on press: the box's blur would close it, the row would move up under the
587
+ * pointer, and the press be lost.
588
+ */
589
+ export function MediaCard({
590
+ thumbUrl, picture, name, title, meta, metaLive, empty, pasteLabel, boxId, boxLabel, placeholder, text, onText, open, onOpenChange, onKeep, onLeave,
591
+ boxAutoFocus = true, boxDescribedBy, boxInvalid, before, after, more, whileEmpty, onRemove, menuLabel = "More actions", disabled, over, drop, children,
592
+ }: MediaCardProps) {
593
+ const pasteRef = useRef<HTMLButtonElement>(null);
594
+ const actsRef = useRef<HTMLDivElement>(null);
595
+ const [backToPaste, setBackToPaste] = useState(false);
596
+ // Enter and Escape give the focus back to the way in: the paste chip, or the ⋯ once the card holds media (the chip is in it).
597
+ useIsoLayoutEffect(() => {
598
+ if (!backToPaste) return;
599
+ (pasteRef.current ?? actsRef.current?.querySelector<HTMLElement>(".gemboss-ei-img-more > summary"))?.focus();
600
+ setBackToPaste(false);
601
+ }, [backToPaste]);
602
+ const holds = name !== undefined;
603
+ // The box opens holding the address in use, selected: a paste replaces it (the caret at its end put the new address after the
604
+ // old one, and that was written: measured 30/10/2026).
605
+ const boxRef = useRef<HTMLInputElement>(null);
606
+ useIsoLayoutEffect(() => { if (open && boxAutoFocus) boxRef.current?.select(); }, [open]);
607
+ const close = (refocus: boolean) => { onOpenChange(false); if (refocus) setBackToPaste(true); };
608
+ return (
609
+ <div className="gemboss-ei-img" data-over={over ? "" : undefined} {...drop}>
610
+ <div className="gemboss-ei-img-thumb" style={thumbUrl ? { backgroundImage: cssUrl(thumbUrl) } : undefined} aria-hidden>
611
+ {picture ?? (thumbUrl ? null : "—")}
612
+ </div>
613
+ <div className="gemboss-ei-img-ctl">
614
+ {name !== undefined ? (
615
+ <div className="gemboss-ei-img-info">
616
+ <span className="gemboss-ei-img-name" title={title}>{name}</span>
617
+ <span className="gemboss-ei-img-meta" aria-live={metaLive ? "polite" : undefined}>{meta}</span>
618
+ </div>
619
+ ) : (
620
+ <div className="gemboss-ei-img-drop" aria-live={metaLive ? "polite" : undefined}>{empty}</div>
621
+ )}
622
+ {open ? (
623
+ <input ref={boxRef} id={boxId} className="gemboss-field gemboss-ei-inp" placeholder={placeholder} value={text} disabled={disabled} autoFocus={boxAutoFocus}
624
+ aria-label={boxLabel} aria-invalid={boxInvalid || undefined} aria-describedby={boxDescribedBy}
625
+ onChange={(e) => onText(e.target.value)}
626
+ // Left (Tab to a chip, a click elsewhere): kept, and closed unless refused.
627
+ onBlur={() => { if (onKeep()) close(false); }}
628
+ onKeyDown={(e) => {
629
+ if (e.key === "Enter") { e.preventDefault(); if (onKeep()) close(true); }
630
+ else if (e.key === "Escape") { e.preventDefault(); e.stopPropagation(); onLeave(); close(true); }
631
+ }} />
632
+ ) : null}
633
+ <div ref={actsRef} className="gemboss-ei-img-actions" onMouseDown={open ? (e) => { if ((e.target as Element).closest("button")) e.preventDefault(); } : undefined}>
634
+ {typeof before === "function" ? before(holds) : before}
635
+ {!open && !holds ? <ChipButton ref={pasteRef} disabled={disabled} onClick={() => onOpenChange(true)}>{pasteLabel}</ChipButton> : null}
636
+ {!holds ? whileEmpty : null}
637
+ {after}
638
+ {open && onRemove ? <ChipButton disabled={disabled} onClick={() => { onRemove(); setBackToPaste(true); }}>Remove</ChipButton> : null}
639
+ {/* While the box is open there is no ⋯: opening it takes the focus from the box, whose blur writes what was typed. */}
640
+ {!open && (holds || onRemove) ? (
641
+ <Menu label={menuLabel} className="gemboss-ei-img-more" disabled={disabled}>
642
+ {holds ? <MenuItem onClick={() => onOpenChange(true)}>{pasteLabel}</MenuItem> : null}
643
+ {more}
644
+ {/* The ⋯ goes with the media: the focus goes to the card's way in (its paste chip), else stays on the ⋯. */}
645
+ {onRemove ? <MenuItem danger onClick={() => { onRemove(); setBackToPaste(true); }}>Remove</MenuItem> : null}
646
+ </Menu>
647
+ ) : null}
648
+ </div>
649
+ {children}
650
+ </div>
651
+ </div>
652
+ );
653
+ }
654
+
655
+ /** The name a seller knows an image by: its file's, from the URL (no query, decoded); an embedded one is said so. */
656
+ export function imageFileName(url: string): string {
657
+ const u = url.trim();
658
+ if (/^data:/i.test(u)) return "Embedded image";
659
+ const path = u.split(/[?#]/)[0] ?? "";
660
+ const last = path.split("/").filter(Boolean).pop() ?? u;
661
+ try { return decodeURIComponent(last); } catch { return last; }
662
+ }
663
+ /**
664
+ * `.gemboss-ei-img`: an image and its chips. With `onFile` it is AN IMAGE CARD (Control UI C19): a 56px thumbnail beside the image's
665
+ * file name (`nameOf`, else the URL's), its size in pixels and, where the caller knows it (`bytesOf`), in bytes; empty, a place to drop an image (uploaded and used at once); the URL box behind "Paste a URL"
666
+ * (a second way in, not the first thing seen). Without `onFile`: the thumbnail, the URL box always, the chips (as before 0.55).
667
+ * Remove empties it. `.gemboss-ei-img-thumb` and the URL box in `.gemboss-ei-img-ctl` stay where editor-plain.js finds them.
668
+ */
669
+ export function ImageControl({ id, value, onChange, disabled, placeholder, draft, onDraftChange, actions, more, whileEmpty, menuLabel = "More image actions", clearable = true, onFile, nameOf, bytesOf }: ImageControlProps) {
670
+ // Every choice (a value from outside, a URL kept, Remove) is counted: an upload that answers after another choice is dropped, not
671
+ // put over it.
672
+ const choice = useRef(0);
387
673
  const [own, setOwn] = useState(value);
388
- useEffect(() => { setOwn(value); }, [value]);
674
+ useOnNewValue(() => { setOwn(value); choice.current += 1; }, [value]);
389
675
  const text = draft ?? own;
390
676
  const setText = (next: string) => { if (draft === undefined) setOwn(next); onDraftChange?.(next); };
677
+ const card = !!onFile;
678
+ const [pasting, setPasting] = useState(false);
679
+ const [over, setOver] = useState(false);
680
+ const [busy, setBusy] = useState(false);
681
+ const [error, setError] = useState("");
682
+ // The image the card shows: a URL picked, dropped or generated is shown at once, before `value` comes back.
683
+ const shown = card && !pasting ? text : value;
684
+ // Its size in pixels, as the browser reads it (no CORS needed for the dimensions), once it has loaded; or that it does not load. A
685
+ // refusal said under the card is about the image it was shown with: another image clears it.
686
+ const [size, setSize] = useState<{ w: number; h: number } | "broken" | null>(null);
687
+ useEffect(() => {
688
+ setSize(null); setError("");
689
+ if (!card || !shown || typeof Image === "undefined") return undefined;
690
+ let live = true;
691
+ const img = new Image();
692
+ img.onload = () => { if (live) setSize(img.naturalWidth ? { w: img.naturalWidth, h: img.naturalHeight } : "broken"); };
693
+ img.onerror = () => { if (live) setSize("broken"); };
694
+ img.src = shown;
695
+ return () => { live = false; img.onload = null; img.onerror = null; img.src = ""; };
696
+ }, [card, shown]);
697
+ // Read when the event comes, not from the render the handler was made in (a drop right after an upload answered).
698
+ const uploading = useRef(false);
699
+ const take = async (file: File | undefined) => {
700
+ if (!file || !onFile || disabled || uploading.current) return;
701
+ const mine = ++choice.current;
702
+ uploading.current = true; setBusy(true); setError("");
703
+ const r = await onFile(file);
704
+ uploading.current = false; setBusy(false);
705
+ if (choice.current !== mine) return;
706
+ if ("url" in r) { setText(r.url); onChange(r.url); setPasting(false); } else setError(r.error);
707
+ };
708
+ const keep = () => { if (text !== value) { choice.current += 1; onChange(text); } };
709
+ const hasFiles = (e: React.DragEvent) => Array.from(e.dataTransfer.types).includes("Files");
710
+ // A file over a card that cannot take it now (disabled, an upload running) is still held here: let through, the browser would open
711
+ // it and leave the editor.
712
+ const takes = () => !disabled && !uploading.current;
713
+ // AN IMAGE CARD draws through MediaCard, the card's one owner (its box, its focus, its chips): the image's own part is here, what
714
+ // a drop and an upload do, and its name and size.
715
+ if (card) {
716
+ return (
717
+ <MediaCard thumbUrl={shown || null} name={shown ? nameOf?.(shown) || imageFileName(shown) : undefined} title={shown} metaLive
718
+ meta={busy ? "Uploading…" : size === "broken" ? "Can't load this image"
719
+ : [size ? `${size.w} × ${size.h}` : "", fileSizeWords(bytesOf?.(shown) ?? 0)].filter(Boolean).join(" · ")}
720
+ empty={busy ? "Uploading…" : "Drop an image here"}
721
+ pasteLabel="Paste a URL" boxId={id} boxLabel="Image URL" placeholder={placeholder ?? "Paste image URL…"}
722
+ text={text} onText={setText} open={pasting} onOpenChange={(o) => { if (o) setError(""); setPasting(o); }}
723
+ onKeep={() => { keep(); return true; }} onLeave={() => setText(value)}
724
+ disabled={disabled} before={actions} more={more} whileEmpty={whileEmpty} menuLabel={menuLabel}
725
+ onRemove={clearable && shown ? () => { choice.current += 1; setText(""); onChange(""); setPasting(false); } : undefined}
726
+ over={over}
727
+ drop={{
728
+ onDragOver: (e) => { if (!hasFiles(e)) return; e.preventDefault(); if (takes()) setOver(true); else e.dataTransfer.dropEffect = "none"; },
729
+ onDragLeave: (e) => { if (!e.currentTarget.contains(e.relatedTarget as Node | null)) setOver(false); },
730
+ onDrop: (e) => { if (!hasFiles(e)) return; e.preventDefault(); setOver(false); if (takes()) void take(e.dataTransfer.files[0]); },
731
+ }}>
732
+ {error ? <p className="gemboss-ei-hint" role="alert">{error}</p> : null}
733
+ </MediaCard>
734
+ );
735
+ }
736
+ // Without `onFile`: the thumbnail, the URL box always, the chips (as before 0.55).
391
737
  return (
392
738
  <div className="gemboss-ei-img">
393
739
  <div className="gemboss-ei-img-thumb" style={value ? { backgroundImage: cssUrl(value) } : undefined} aria-hidden>{value ? null : "—"}</div>
394
740
  <div className="gemboss-ei-img-ctl">
395
741
  <input id={id} className="gemboss-field gemboss-ei-inp" placeholder={placeholder ?? "Paste image URL…"} value={text} disabled={disabled}
396
- onChange={(e) => setText(e.target.value)} onBlur={() => { if (text !== value) onChange(text); }} onKeyDown={blurOnEnter} />
742
+ onChange={(e) => setText(e.target.value)} onBlur={keep} onKeyDown={blurOnEnter} />
397
743
  <div className="gemboss-ei-img-actions">
398
- {actions}
399
- {clearable && value ? <ChipButton disabled={disabled} onClick={() => { setText(""); onChange(""); }}>Clear</ChipButton> : null}
744
+ {typeof actions === "function" ? actions(!!value) : actions}
745
+ {clearable && value ? <ChipButton disabled={disabled} onClick={() => { choice.current += 1; setText(""); onChange(""); }}>Remove</ChipButton> : null}
400
746
  </div>
401
747
  </div>
402
748
  </div>