@gemboss/ui 0.65.0 → 0.67.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.
- package/CHANGELOG.md +349 -2
- package/README.md +33 -4
- package/catalog/editor.html +21 -13
- package/catalog/index.html +6 -6
- package/gemboss-ui.css +3 -3
- package/package.json +10 -1
- package/parts/components.css +2 -2
- package/parts/core.css +1 -1
- package/parts/shell.css +1 -1
- package/src/assistant/engine.tsx +2 -18
- package/src/auth.tsx +1 -15
- package/src/board-auto-more.tsx +168 -0
- package/src/collections.tsx +10 -1
- package/src/confirm-buttons.ts +37 -0
- package/src/confirm-dialog.css +1 -0
- package/src/confirm-dialog.tsx +128 -0
- package/src/copy-field.css +1 -0
- package/src/copy-field.tsx +48 -0
- package/src/copy-text.ts +20 -0
- package/src/create-shell.css +1 -1
- package/src/create-shell.tsx +7 -4
- package/src/dialog.css +1 -0
- package/src/dialog.tsx +46 -7
- package/src/editor/choice-cards.tsx +71 -0
- package/src/editor/controls.tsx +61 -19
- package/src/editor/field-control.tsx +146 -58
- package/src/editor/field-frame.tsx +20 -10
- package/src/editor/field-spec.ts +43 -8
- package/src/editor/index.ts +16 -5
- package/src/editor/items-field.tsx +185 -0
- package/src/editor/items.ts +126 -0
- package/src/editor/label-side.ts +11 -4
- package/src/editor/panel.tsx +39 -12
- package/src/editor/repeater.tsx +37 -7
- package/src/editor/secret-field.tsx +118 -0
- package/src/editor/switch.tsx +34 -0
- package/src/editor-color.css +1 -1
- package/src/editor-grow.css +1 -0
- package/src/editor-insert.css +1 -1
- package/src/editor-plain.js +1 -1
- package/src/editor-repeater.css +1 -1
- package/src/editor-switch.css +1 -0
- package/src/editor.css +1 -1
- package/src/eye-icon.tsx +14 -0
- package/src/gemboss-field.css +1 -1
- package/src/icons-plain.js +1 -0
- package/src/icons.tsx +9 -0
- package/src/index.ts +7 -1
- package/src/kit-plain.css +1 -1
- package/src/list-page.css +1 -1
- package/src/list-page.tsx +94 -51
- package/src/list-toolbar.css +1 -0
- package/src/list-toolbar.tsx +85 -0
- package/src/menu-keys.ts +3 -1
- package/src/search-dialog.tsx +4 -1
- package/src/segmented.tsx +24 -6
- package/src/service-switcher.tsx +2 -2
- package/src/settings-dialog.tsx +2 -2
- package/src/ui.css +1 -1
package/src/editor/field-spec.ts
CHANGED
|
@@ -21,8 +21,12 @@ export function labelize(s: string): string {
|
|
|
21
21
|
|
|
22
22
|
/** One choice of a select or of chips. `glyph`: drawn as that picture (an app's `glyphs`), its `label` its name (aria and tooltip).
|
|
23
23
|
* `name`: what a short label stands for, announced and in its tooltip (a shadow's "S" is "Subtle"). `G`: the glyph names an app
|
|
24
|
-
* draws, so a typo is a type error there.
|
|
25
|
-
|
|
24
|
+
* draws, so a typo is a type error there. `group`: the heading a list draws it under (`<optgroup>`), one heading for each run of
|
|
25
|
+
* choices that name the same group (an element's styles: This shop · Shared library); chips draw no heading. `disabled`: in a list,
|
|
26
|
+
* shown and not pickable. */
|
|
27
|
+
export type SelectOption<G extends string = string> = { value: string; label?: string; glyph?: G; name?: string; group?: string;
|
|
28
|
+
/** Shown but not pickable (a list's own words for a value that is gone: "Removed from the library"; a group with nothing to offer). */
|
|
29
|
+
disabled?: boolean };
|
|
26
30
|
|
|
27
31
|
/** One field of a kind the kit draws. `id` keys into the flat `values` object the host owns. */
|
|
28
32
|
export type FieldSpec<G extends string = string> =
|
|
@@ -30,11 +34,26 @@ export type FieldSpec<G extends string = string> =
|
|
|
30
34
|
// page's "/pages/").
|
|
31
35
|
| { kind: "text"; id: string; label?: string; placeholder?: string; hint?: string; maxLength?: number; prefix?: string;
|
|
32
36
|
/** The box's own type where it says what it holds: a link (`url`: the phone's link keyboard), a search (`search`: the browser's clear
|
|
33
|
-
* button where it draws one, and Enter keeps the focus in it), an email
|
|
34
|
-
|
|
37
|
+
* button where it draws one, and Enter keeps the focus in it), an email, a day (`date`: the browser's own date picker, its value
|
|
38
|
+
* YYYY-MM-DD). Default a plain text box. A box with a `prefix` stays text. */
|
|
39
|
+
inputType?: "url" | "search" | "email" | "date";
|
|
40
|
+
/** The phone's keyboard for a value kept as typed text: `decimal` a number with its point (a cost typed as "12.50"), `numeric`
|
|
41
|
+
* digits only. Default the text keyboard. A `number` field takes the same, default `numeric` (it keeps a number). */
|
|
42
|
+
inputMode?: "decimal" | "numeric";
|
|
43
|
+
/** An ID or a code, typed as it is written elsewhere (a partner's store ID): no spell check, no capital or correction on a phone, none
|
|
44
|
+
* of the browser's remembered entries. Not `code`: it keeps the text face and its label beside it. */
|
|
45
|
+
verbatim?: boolean;
|
|
46
|
+
/** A line of code or a CSS value that runs long (a condition's expression, a font stack, a border, a shadow): the `code` control, its
|
|
47
|
+
* label above, the value across the field in a monospace line that wraps and grows with it, not spell-checked, so it is read whole
|
|
48
|
+
* (§9.1). Still one line of text: Enter commits, a line break typed or pasted becomes a space. Not with `prefix` or `inputType`,
|
|
49
|
+
* which a line of code has no use for: with `code` they are not drawn. One `code`: #7088's one-line monospace box is this one. */
|
|
50
|
+
code?: boolean }
|
|
35
51
|
// `code`: a stylesheet or a script, in a monospace face, not spell-checked.
|
|
36
52
|
| { kind: "textarea"; id: string; label?: string; rows?: number; placeholder?: string; hint?: string; maxLength?: number; code?: boolean }
|
|
37
|
-
|
|
53
|
+
// `inputMode`: the phone's keypad, as a text box's: default `numeric` (digits alone, which on an iPhone has no point), `decimal` for a
|
|
54
|
+
// number with a fraction (a width of 12.5 in, a box at 31.25 %). Any number box reads a comma typed for its point as one ("31,25" is
|
|
55
|
+
// 31.25: the decimal keypad of a comma locale, vi or de, has no ".").
|
|
56
|
+
| { kind: "number"; id: string; label?: string; min?: number; max?: number; step?: number; suffix?: string; hint?: string; placeholder?: string; inputMode?: "decimal" | "numeric" }
|
|
38
57
|
| { kind: "range"; id: string; label?: string; min: number; max: number; step?: number; suffix?: string }
|
|
39
58
|
// `numeric`: the setting holds a number (a text's own Weight): the option picked is written as one. `clearable`: "Not set" stays a
|
|
40
59
|
// choice once a value is stored, and picking it clears the setting ("" deletes it).
|
|
@@ -44,9 +63,25 @@ export type FieldSpec<G extends string = string> =
|
|
|
44
63
|
| { kind: "toggle"; id: string; label?: string; onLabel?: string; offLabel?: string; hint?: string }
|
|
45
64
|
| { kind: "color"; id: string; label?: string; hint?: string; placeholder?: string }
|
|
46
65
|
| { kind: "image"; id: string; label?: string }
|
|
47
|
-
// A
|
|
48
|
-
//
|
|
49
|
-
|
|
66
|
+
// A LIST OF ROWS (pricing tiers, review cards, a section's benefits), drawn by the kit's Items control (items-field.tsx): each row one line
|
|
67
|
+
// (its picture or its words, a ⋯), dragged or moved with Alt+↑ / ↓, opened to edit its fields in place. The value is the whole list, and
|
|
68
|
+
// each change writes it whole. A row's fields are `fields` (any kind a form draws: a text, a picture, an app's link), else the older
|
|
69
|
+
// `item` keys (a text box each). Kept as stored: a row's other keys, a picture's alt text, a string row (items.ts).
|
|
70
|
+
| { kind: "repeater"; id: string; label?: string; item: Array<{ key: string; label?: string; long?: boolean }>; addLabel?: string; hint?: string;
|
|
71
|
+
/** A row's fields; `from`: older keys a value is stored under (read from the first that holds one, written back there). */
|
|
72
|
+
fields?: Array<RowFieldSpec>;
|
|
73
|
+
/** What one row is ("benefit"): "+ Add benefit", a nameless row "Benefit 3". */
|
|
74
|
+
noun?: string;
|
|
75
|
+
/** The fewest and the most rows the list holds: Remove off at the least, Add and Duplicate off at the most, each saying why. */
|
|
76
|
+
min?: number; max?: number;
|
|
77
|
+
/** The row "+ Add" puts in, so it shows at once (the section's starter words). Default: every field empty, as the list always added. */
|
|
78
|
+
starter?: Record<string, unknown>;
|
|
79
|
+
/** The field that names a row in the list, and the one that is its picture. Default: the first words, the first picture. */
|
|
80
|
+
title?: string; thumb?: string };
|
|
81
|
+
|
|
82
|
+
/** One field of a list's row: any kind a form draws (a kit kind with its own settings, or an app's), and `from`, older keys the value is
|
|
83
|
+
* stored under. Typed loosely on purpose: a row's field may be any FieldSpec, and FieldSpec holds the list (a type cannot hold itself). */
|
|
84
|
+
export type RowFieldSpec = AppFieldSpec & { from?: readonly string[] } & Record<string, unknown>;
|
|
50
85
|
|
|
51
86
|
/** The kinds the kit draws, in FieldSpec's order (a gate reads every one). */
|
|
52
87
|
export const KIT_FIELD_KINDS = ["text", "textarea", "number", "range", "select", "segmented", "toggle", "color", "image", "repeater"] as const;
|
package/src/editor/index.ts
CHANGED
|
@@ -38,8 +38,8 @@ export {
|
|
|
38
38
|
type FieldProps, type InspectorGroupProps, type PanelHeaderProps, type PanelTab, type PanelTabsProps,
|
|
39
39
|
} from "./panel";
|
|
40
40
|
export {
|
|
41
|
-
ChipButton, ColorControl, EdgeBox, fileSizeWords, ImageControl, imageFileName, MediaCard, PickButton, RangeControl, Seg, UnitField, ValueControl,
|
|
42
|
-
type ColorChoice, type ColorControlProps, type EdgeBoxProps, type EdgeSide, type ImageControlProps, type MediaCardProps, type PickButtonProps, type RangeControlProps, type SegOption, type SegProps, type UnitFieldProps, type ValueControlProps,
|
|
41
|
+
Checkbox, ChipButton, ColorControl, EdgeBox, fileSizeWords, ImageControl, imageFileName, MediaCard, PickButton, RangeControl, Seg, UnitField, ValueControl,
|
|
42
|
+
type CheckboxProps, type ColorChoice, type ColorControlProps, type EdgeBoxProps, type EdgeSide, type ImageControlProps, type MediaCardProps, type PickButtonProps, type RangeControlProps, type SegOption, type SegProps, type UnitFieldProps, type ValueControlProps,
|
|
43
43
|
} from "./controls";
|
|
44
44
|
// 27/10/2026: a control takes a value from outside in the render that brings it, not an effect later (new-value.ts).
|
|
45
45
|
export { useOnNewValue } from "./new-value";
|
|
@@ -54,9 +54,16 @@ export {
|
|
|
54
54
|
} from "./layers";
|
|
55
55
|
export { SortableLayerList, type SortableLayerListProps, useRowDrag, dropIndex } from "./sortable";
|
|
56
56
|
// 16/10/2026: a setting that is a list, as rows (drag, duplicate, fold); its own CSS part, editor-repeater.css.
|
|
57
|
-
export { RepeaterList, useKeyedRows, type RepeaterListProps, type KeyedRows } from "./repeater";
|
|
57
|
+
export { RepeaterList, useKeyedRows, type RepeaterListProps, type KeyedRows, type KeyedChange } from "./repeater";
|
|
58
|
+
// 09/11/2026: the Items control every list setting draws (a schema's `repeater`, a section's rows), and how a row is read and written as stored.
|
|
59
|
+
export { ItemsField, type ItemsFieldProps } from "./items-field";
|
|
60
|
+
export { IMAGE_URL_KEYS, itemLimits, rowFieldEditable, rowFields, rowThumb, rowTitle, rowValues, starterRow, storedRows, withRowValue, type ItemsSpec, type RowField } from "./items";
|
|
58
61
|
// 16/10/2026: a closed choice of shapes (an image's ratio, a layout) as picture tiles; its own CSS part, editor-tiles.css.
|
|
59
62
|
export { ChoiceTiles, tileShapeStyle, type ChoiceTile, type ChoiceTilesProps } from "./tiles";
|
|
63
|
+
// 09/11/2026: on / off in place where a field's On / Off does not fit (a part's switch on a canvas tag); its own CSS part, editor-switch.css.
|
|
64
|
+
export { Switch, type SwitchProps } from "./switch";
|
|
65
|
+
// One choice of a few, each a card with its words and a picture (Global styles' form set and style pack): real radios in one group.
|
|
66
|
+
export { ChoiceCards, type ChoiceCard, type ChoiceCardsProps } from "./choice-cards";
|
|
60
67
|
// 31/10/2026: a run of groups where one holding nothing is a chip (Control UI C32 slice 3); its own CSS part, editor-chips.css.
|
|
61
68
|
export { InspectorChips, type InspectorChipsProps } from "./chips";
|
|
62
69
|
// 06/11/2026: the settings FRAME every settings surface draws (one settings frame slice 1): search, the index of clusters, a cluster's
|
|
@@ -73,13 +80,15 @@ export {
|
|
|
73
80
|
kindIn, KIT_FIELD_KINDS, knobClearWrites, knobCleared, knobHolds, knobValue, labelize, labelWidthPx, NARROWEST_COLUMN_PX, ROW_CONTROL_COLUMN_PX, segmentable,
|
|
74
81
|
OWN_FRAME_PLACES, settingMatches, STYLE_FRAME_PLACES, unplacedStyleFields,
|
|
75
82
|
type AnyFieldSpec, type AppFieldSpec, type FieldGroup, type FieldKindRules, type FieldKindRuleSet, type FieldSchema, type FieldSpec, type FieldSpread,
|
|
76
|
-
type FieldWrite, type FrameCluster, type FrameGroup, type FramePlace, type FramePlaces, type FrameWay, type KitFieldKind, type SelectOption,
|
|
83
|
+
type FieldWrite, type RowFieldSpec, type FrameCluster, type FrameGroup, type FramePlace, type FramePlaces, type FrameWay, type KitFieldKind, type SelectOption,
|
|
77
84
|
} from "./field-spec";
|
|
78
85
|
export {
|
|
79
86
|
controlOf, FieldControl, FieldKindsProvider, FieldRenderer, FieldRows, labelBeside,
|
|
80
87
|
type FieldControlProps, type FieldGlyphs, type FieldKind, type FieldKindProps, type FieldKinds, type FieldRowsProps,
|
|
81
88
|
} from "./field-control";
|
|
82
|
-
export { FieldFrame, PartsFrame, usePartHits, type FieldFrameProps, type FramePart } from "./field-frame";
|
|
89
|
+
export { FieldFrame, PartsFrame, usePartHits, type FieldFrameProps, type FrameClusterLabels, type FramePart } from "./field-frame";
|
|
90
|
+
// 09/11/2026: a secret the seller gives (a token, a key): masked, Show / Paste, never copied out, "Saved, ends in …" once stored.
|
|
91
|
+
export { SecretField, secretTail, type SecretFieldProps } from "./secret-field";
|
|
83
92
|
export { ColorChoicesContext, type ColorChoices } from "./color-choices";
|
|
84
93
|
// 24/10/2026: a setting's small panel beside the settings column (top layer; a sheet at phone width); its own CSS part.
|
|
85
94
|
export { Popover, type PopoverProps } from "./popover";
|
|
@@ -87,6 +96,8 @@ export { Popover, type PopoverProps } from "./popover";
|
|
|
87
96
|
export { ColorPicker, type ColorPickerProps } from "./color-picker";
|
|
88
97
|
// 24/10/2026: the body of every "choose one" popup (search, rows, states); its own CSS part, editor-picker.css.
|
|
89
98
|
export { PickerList, type PickerItem, type PickerListProps, type PickerTone } from "./picker";
|
|
99
|
+
// 09/11/2026 (one control set): the pickers' own search box for a host's combobox (the page editor's insert menu).
|
|
100
|
+
export { PickSearch, type PickerSearch } from "./picker";
|
|
90
101
|
// 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.
|
|
91
102
|
export { PickerGrid, type PickerTile, type PickerGridProps } from "./picker-grid";
|
|
92
103
|
export { LayerTree, type LayerTreeProps, type LayerTreeRow } from "./tree";
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
// THE ITEMS CONTROL (09/11/2026; Chris: "one shared control set", fast and handy, clicks before typing). Every list setting is drawn with it:
|
|
3
|
+
// a schema's `repeater` field (FieldControl), a library section's rows (gemboss's page editor), any other list. Built on the kit's list
|
|
4
|
+
// parts (RepeaterList, useKeyedRows), its rows' fields drawn by FieldRows, so a row's labels sit where every other setting's do.
|
|
5
|
+
//
|
|
6
|
+
// · each item one line: its picture or its words, a ⋯ (Move up, Move down, Duplicate, Remove); its grip drags it, Alt+↑ / ↓ moves it;
|
|
7
|
+
// · a click opens that item's fields in place, one item at a time, each label beside its control where it fits (label-side.ts);
|
|
8
|
+
// · "+ Add <item>" puts in the list's starter row, so the item shows at once, and opens it;
|
|
9
|
+
// · Remove asks nothing: every host that draws a list can undo it (the page's history, the theme editor's Undo, a form's Save);
|
|
10
|
+
// · the list's bounds hold: at its most, Add and Duplicate are off and say why; at its least, Remove is.
|
|
11
|
+
//
|
|
12
|
+
// ONE WRITE PER CHANGE: the whole list (`onChange`), as stored, every row's other keys kept (items.ts). A row the host cannot save yet
|
|
13
|
+
// (`rowHolds`: a library section's row with none of the words it needs) stays in its place in the list, said so, and is not written,
|
|
14
|
+
// while every other row is. A refused write puts the stored list back (useKeyedRows).
|
|
15
|
+
import "../editor.css";
|
|
16
|
+
import "../editor-repeater.css";
|
|
17
|
+
import { useEffect, useId, useMemo, useRef, useState, type ReactNode } from "react";
|
|
18
|
+
import { RepeaterList, spelled, useKeyedRows, type KeyedChange } from "./repeater";
|
|
19
|
+
import { FieldRows, type FieldGlyphs, type FieldKinds } from "./field-control";
|
|
20
|
+
import { labelize } from "./field-spec";
|
|
21
|
+
import { blank, itemLimits, rowFieldEditable, rowFields, rowThumb, rowTitle, rowValues, starterRow, storedRows, withRowValue, type ItemsSpec } from "./items";
|
|
22
|
+
|
|
23
|
+
export interface ItemsFieldProps {
|
|
24
|
+
/** The list's spec: its label, its rows' fields, its bounds, its starter row. */
|
|
25
|
+
field: ItemsSpec;
|
|
26
|
+
/** The list as stored (anything that is not a list reads as none). */
|
|
27
|
+
value: unknown;
|
|
28
|
+
/** ONE write: the whole list after the change, and where each row came from (useKeyedRows). `false`, or a Promise answering `false`,
|
|
29
|
+
* puts the stored list back. */
|
|
30
|
+
onChange: (next: unknown[], how: KeyedChange) => false | void | PromiseLike<unknown>;
|
|
31
|
+
/** The list's name as drawn (FieldControl's, with a host's mark); default the spec's label. */
|
|
32
|
+
label?: string;
|
|
33
|
+
disabled?: boolean;
|
|
34
|
+
/** Why one row cannot be saved yet, or null. Such a row stays in the list after the saved ones, said so, and is not written. */
|
|
35
|
+
rowHolds?: (row: unknown, index: number) => string | null;
|
|
36
|
+
/** A row opened (its index) or the open one folded (null): a host that shows that item on its page. */
|
|
37
|
+
onActive?: (index: number | null) => void;
|
|
38
|
+
/** Open item `index` (its place in the STORED list) from outside (an item picked on the canvas), brought into view, its `field` marked
|
|
39
|
+
* (`data-canvas-focus`, the focus left where it is); a new `seq` asks again. `onActive` answers in the same places: a row the store
|
|
40
|
+
* does not hold yet (rowHolds) is no item of the page, so it is heard as null. */
|
|
41
|
+
open?: { index: number; field?: string; seq: number } | null;
|
|
42
|
+
/** Where this list's unsaved rows (rowHolds) are kept, so they outlive this control: a panel drawn again (another part of the item
|
|
43
|
+
* picked) and another control of the same list (the band's Content, a part's Items) show them. Absent: kept by this control alone. */
|
|
44
|
+
keepDraftsAs?: string;
|
|
45
|
+
/** 44px buttons with a mouse too (a surface whose every control is). */
|
|
46
|
+
touch?: boolean;
|
|
47
|
+
/** The controls' ids start with it (a host whose list is mounted twice). */
|
|
48
|
+
idPrefix?: string;
|
|
49
|
+
/** For a row's fields: the shop an app's kinds read, the media library, the app's kinds and glyphs. */
|
|
50
|
+
shopId?: string;
|
|
51
|
+
onPickImage?: (id: string, current: string) => void;
|
|
52
|
+
kinds?: FieldKinds;
|
|
53
|
+
glyphs?: FieldGlyphs;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** JSON in one key order: the store may hand a row back with its keys reordered (Postgres JSONB), and it is still the row written. */
|
|
57
|
+
/** Two values of one field are one value: empty and unset alike, and a stored 5 is the "5" its box gives back (a text box returns words).
|
|
58
|
+
* Without it a field left untouched wrote its own value back as words on every blur, a number turned into text. */
|
|
59
|
+
const sameValue = (a: unknown, b: unknown) => (blank(a) && blank(b)) || a === b
|
|
60
|
+
|| ((typeof a === "string" || typeof a === "number" || typeof a === "boolean") && (typeof b === "string" || typeof b === "number" || typeof b === "boolean") && String(a) === String(b));
|
|
61
|
+
|
|
62
|
+
/** Unsaved rows by list (ItemsField `keepDraftsAs`), for the page's life: the list as the seller left it, held rows in their places. */
|
|
63
|
+
const DRAFTS = new Map<string, unknown[]>();
|
|
64
|
+
|
|
65
|
+
export function ItemsField({ field, value, onChange, label, disabled, rowHolds, onActive, open = null, keepDraftsAs, touch, idPrefix, shopId, onPickImage, kinds, glyphs }: ItemsFieldProps) {
|
|
66
|
+
const fields = useMemo(() => rowFields(field), [field]);
|
|
67
|
+
const stored = useMemo(() => storedRows(value), [value]);
|
|
68
|
+
const uid = useId();
|
|
69
|
+
const heldIn = (rows: readonly unknown[]) => new Set(rowHolds ? rows.flatMap((r, i) => (rowHolds(r, i) !== null ? [i] : [])) : []);
|
|
70
|
+
// ROWS THE HOST CANNOT SAVE YET (rowHolds), IN THEIR PLACES: the list as the seller last left it, drawn while the stored list is that list
|
|
71
|
+
// without them. Any other stored list (an Undo, the chat, a refused write) is drawn as it is, the unsaved rows with it gone.
|
|
72
|
+
const [view, setViewHere] = useState<unknown[] | null>(() => (keepDraftsAs ? DRAFTS.get(keepDraftsAs) ?? null : null));
|
|
73
|
+
const setView = (next: unknown[] | null) => {
|
|
74
|
+
setViewHere(next);
|
|
75
|
+
if (keepDraftsAs) { if (next) DRAFTS.set(keepDraftsAs, next); else DRAFTS.delete(keepDraftsAs); }
|
|
76
|
+
};
|
|
77
|
+
const shown = useMemo(() => {
|
|
78
|
+
if (!view) return stored;
|
|
79
|
+
const held = heldIn(view);
|
|
80
|
+
return spelled(view.filter((_r, i) => !held.has(i))) === spelled(stored) ? view : stored;
|
|
81
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps -- heldIn reads rowHolds
|
|
82
|
+
}, [view, stored, rowHolds]);
|
|
83
|
+
// The rows a write starts from (useKeyedRows' latest), to say where each saved row came from in the saved list's places.
|
|
84
|
+
const lastRows = useRef<readonly unknown[]>(shown);
|
|
85
|
+
const list = useKeyedRows<unknown>(shown, (next, how) => {
|
|
86
|
+
const prev = lastRows.current;
|
|
87
|
+
lastRows.current = next;
|
|
88
|
+
if (!rowHolds) return onChange(next, how);
|
|
89
|
+
const held = heldIn(next), wasHeld = heldIn(prev);
|
|
90
|
+
const saved = next.filter((_r, i) => !held.has(i));
|
|
91
|
+
setView(held.size ? next : null);
|
|
92
|
+
// Only an unsaved row changed (added, typed into but still short, removed): nothing to write.
|
|
93
|
+
if (spelled(saved) === spelled(stored)) return;
|
|
94
|
+
let n = 0;
|
|
95
|
+
const place = prev.map((_r, i) => (wasHeld.has(i) ? -1 : n++));
|
|
96
|
+
const from = how.from.filter((_f, i) => !held.has(i)).map((o) => (o >= 0 ? place[o] ?? -1 : -1));
|
|
97
|
+
const answer = onChange(saved, { from, was: n });
|
|
98
|
+
const drop = () => setView(null);
|
|
99
|
+
if (answer === false) drop();
|
|
100
|
+
else if (answer && typeof (answer as PromiseLike<unknown>).then === "function") (answer as PromiseLike<unknown>).then((ok) => { if (ok === false) drop(); }, drop);
|
|
101
|
+
return answer;
|
|
102
|
+
});
|
|
103
|
+
lastRows.current = list.rows;
|
|
104
|
+
// Add and Duplicate count every row shown (an unsaved one becomes an item once filled); Remove counts the rows the store holds.
|
|
105
|
+
const limits = itemLimits(field, list.rows.length);
|
|
106
|
+
const least = itemLimits(field, list.rows.length - heldIn(list.rows).size);
|
|
107
|
+
const prefix = idPrefix ?? uid;
|
|
108
|
+
// "+ Add": the new item opens, its first field takes the focus, so its words are typed at once. Armed with the count before the Add, so
|
|
109
|
+
// an Add the host refused (no new row) moves no focus later.
|
|
110
|
+
const focusFrom = useRef<number | null>(null);
|
|
111
|
+
useEffect(() => {
|
|
112
|
+
const from = focusFrom.current;
|
|
113
|
+
if (from === null) return;
|
|
114
|
+
focusFrom.current = null;
|
|
115
|
+
if (list.keys.length <= from) return;
|
|
116
|
+
const key = list.keys.at(-1), first = fields.find((f) => rowFieldEditable(list.rows.at(-1), f));
|
|
117
|
+
if (key && first) document.getElementById(`${prefix}-${key}-${first.id}`)?.focus();
|
|
118
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps -- once, after the Add's row is drawn
|
|
119
|
+
}, [list.keys]);
|
|
120
|
+
// AN ITEM PICKED ELSEWHERE (the canvas): its row opened, and the field that shows the part picked marked, as a picked part's field is
|
|
121
|
+
// everywhere in the editor (part-field-focus.ts): marked and in view, never taking the focus from where the seller is.
|
|
122
|
+
// Places: the shown list keeps unsaved rows where they are; the page's items are the stored list's. Item s of the store is the s-th
|
|
123
|
+
// row that is not held; a held row is no item.
|
|
124
|
+
const heldNow = heldIn(list.rows);
|
|
125
|
+
const shownOf = (s: number) => { let n = -1; for (let i = 0; i < list.rows.length; i++) if (!heldNow.has(i) && ++n === s) return i; return -1; };
|
|
126
|
+
const storedOf = (i: number) => (heldNow.has(i) ? null : [...Array(i).keys()].filter((j) => !heldNow.has(j)).length);
|
|
127
|
+
// The row the pick names, read ONCE per pick (its `seq`): moving, removing or adding rows afterwards does not open another one.
|
|
128
|
+
const asked = useRef<{ key: string; seq: number } | null>(null);
|
|
129
|
+
if (open && open.index >= 0 && asked.current?.seq !== open.seq) {
|
|
130
|
+
const key = list.keys[shownOf(open.index)];
|
|
131
|
+
if (key) asked.current = { key, seq: open.seq };
|
|
132
|
+
}
|
|
133
|
+
const openRequest = open && asked.current?.seq === open.seq ? asked.current : null;
|
|
134
|
+
useEffect(() => {
|
|
135
|
+
if (!openRequest || !open?.field) return;
|
|
136
|
+
const id = `${prefix}-${openRequest.key}-${open.field}`;
|
|
137
|
+
// The row opens in the list's own render after this one: its field is looked for a few frames.
|
|
138
|
+
let frame = 0, tries = 0;
|
|
139
|
+
const markIt = () => {
|
|
140
|
+
const fld = document.getElementById(id)?.closest<HTMLElement>(".gemboss-ei-fld");
|
|
141
|
+
if (!fld) { if (++tries < 20) frame = requestAnimationFrame(markIt); return; }
|
|
142
|
+
fld.closest(".gemboss-ei-rep")?.querySelectorAll("[data-canvas-focus]").forEach((el) => el.removeAttribute("data-canvas-focus"));
|
|
143
|
+
fld.setAttribute("data-canvas-focus", "");
|
|
144
|
+
fld.scrollIntoView?.({ block: "nearest" });
|
|
145
|
+
};
|
|
146
|
+
frame = requestAnimationFrame(markIt);
|
|
147
|
+
return () => cancelAnimationFrame(frame);
|
|
148
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps -- once per request
|
|
149
|
+
}, [openRequest]);
|
|
150
|
+
const draftNote = rowHolds ? list.rows.map((r, i) => rowHolds(r, i)).find((w): w is string => !!w) ?? null : null;
|
|
151
|
+
const noun = field.noun;
|
|
152
|
+
const listLabel = label ?? field.label ?? labelize(field.id);
|
|
153
|
+
const hint: ReactNode = field.hint || !limits.canAdd || draftNote ? <>
|
|
154
|
+
{field.hint || !limits.canAdd ? <p className="gemboss-ei-hint">{[limits.full, field.hint].filter(Boolean).join(" ")}</p> : null}
|
|
155
|
+
{draftNote ? <p className="gemboss-ei-hint" role="status" data-list-draft="">Not saved yet. {draftNote}</p> : null}
|
|
156
|
+
</> : undefined;
|
|
157
|
+
return (
|
|
158
|
+
<RepeaterList label={listLabel} hint={hint} keys={list.keys} disabled={disabled} item={noun} addLabel={field.addLabel ? `+ ${field.addLabel.replace(/^[++]\s*/, "")}` : undefined}
|
|
159
|
+
single touch={touch} canAdd={limits.canAdd} canRemove={least.canRemove} removeWhy={least.least ?? undefined}
|
|
160
|
+
rowAttrs={(i) => ({ "data-item-index": i })}
|
|
161
|
+
title={(i) => rowTitle(list.rows[i], field, fields).slice(0, 60)} thumb={(i) => rowThumb(list.rows[i], field, fields)}
|
|
162
|
+
onMove={list.move} onRemove={list.remove} onDuplicate={(i) => { if (limits.canAdd) list.duplicate(i); }}
|
|
163
|
+
onAdd={() => { if (!limits.canAdd) return; focusFrom.current = list.keys.length; list.add(starterRow(field, fields)); }}
|
|
164
|
+
onActive={onActive ? (i) => onActive(i === null ? null : storedOf(i)) : undefined} openRequest={openRequest}
|
|
165
|
+
body={(i) => {
|
|
166
|
+
const key = list.keys[i]!;
|
|
167
|
+
const row = list.rows[i];
|
|
168
|
+
const editable = fields.filter((f) => rowFieldEditable(row, f));
|
|
169
|
+
const kept = fields.filter((f) => !rowFieldEditable(row, f));
|
|
170
|
+
const values = rowValues(row, fields);
|
|
171
|
+
return <>
|
|
172
|
+
<FieldRows fields={editable} values={values} disabled={disabled} idPrefix={`${prefix}-${key}-`}
|
|
173
|
+
shopId={shopId} onPickImage={onPickImage} kinds={kinds} glyphs={glyphs}
|
|
174
|
+
// By the row's KEY, onto its latest version (useKeyedRows.patch): a field that commits late changes the right row after a move.
|
|
175
|
+
onChange={(id, v) => {
|
|
176
|
+
const f = fields.find((x) => x.id === id);
|
|
177
|
+
if (!f || sameValue(v, values[id])) return;
|
|
178
|
+
list.patch(key, (r) => withRowValue(r, f, v, fields) as never);
|
|
179
|
+
}} />
|
|
180
|
+
{/* A value this item's control cannot show (an object where words go): named and kept, never drawn as "[object Object]". */}
|
|
181
|
+
{kept.length ? <p className="gemboss-ei-hint" data-item-kept={kept.map((f) => f.id).join(" ")}>{kept.map((f) => f.label ?? labelize(f.id)).join(", ")}: kept as it is.</p> : null}
|
|
182
|
+
</>;
|
|
183
|
+
}} />
|
|
184
|
+
);
|
|
185
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
// A LIST'S ROWS, READ AND WRITTEN AS THEY ARE STORED (09/11/2026, the Items editor: Chris "one shared control set", every list setting
|
|
2
|
+
// draws the kit's ItemsField). What a row of a list setting is varies by who wrote it: an object of words (a benefit's heading and text),
|
|
3
|
+
// an object with keys this editor does not know (kept), a picture stored as an address or as `{ url, altText }` (a product's images), a
|
|
4
|
+
// plain string where the list is lines. The control edits one field of one row at a time, and a write must leave everything else of the
|
|
5
|
+
// row exactly as stored: page_40e6aa38's gallery lost its alt text and two pictures to a field that rebuilt the value (gemboss #7081).
|
|
6
|
+
//
|
|
7
|
+
// Pure, no React and no runtime import (only `import type`): a node test reads it as it is.
|
|
8
|
+
import type { FieldSpec, RowFieldSpec } from "./field-spec";
|
|
9
|
+
|
|
10
|
+
/** A list setting's spec (FieldSpec `repeater`). */
|
|
11
|
+
export type ItemsSpec = Extract<FieldSpec, { kind: "repeater" }>;
|
|
12
|
+
/** One field of a row: the kit's or an app's kind; `from` names older keys the same value is stored under (read from the first that holds
|
|
13
|
+
* one, written back where it was read). */
|
|
14
|
+
export type RowField = RowFieldSpec;
|
|
15
|
+
|
|
16
|
+
type Rec = Record<string, unknown>;
|
|
17
|
+
const isRecord = (v: unknown): v is Rec => !!v && typeof v === "object" && !Array.isArray(v);
|
|
18
|
+
/** Empty and unset are one value. */
|
|
19
|
+
export const blank = (v: unknown) => v === undefined || v === null || v === "";
|
|
20
|
+
|
|
21
|
+
/** The list a stored value holds: a list as it is, anything else none. */
|
|
22
|
+
export const storedRows = (value: unknown): unknown[] => (Array.isArray(value) ? value : []);
|
|
23
|
+
|
|
24
|
+
/** The fields a row has: the spec's `fields`, else its older `item` keys (a text box each, `long` a text area). */
|
|
25
|
+
export function rowFields(spec: ItemsSpec): RowField[] {
|
|
26
|
+
if (spec.fields?.length) return spec.fields as RowField[];
|
|
27
|
+
return spec.item.map((i): RowField => ({ kind: i.long ? "textarea" : "text", id: i.key, ...(i.label ? { label: i.label } : {}) }));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** The field a string row's words are: the first that holds words (text, a text area), else the first. */
|
|
31
|
+
const wordsField = (fields: readonly RowField[]) => fields.find((f) => f.kind === "text" || f.kind === "textarea") ?? fields[0];
|
|
32
|
+
|
|
33
|
+
/** The keys an image object keeps its address under, in the order a reader takes them (gemboss page-plan-sections mediaList). */
|
|
34
|
+
export const IMAGE_URL_KEYS = ["url", "src", "image", "image_url"] as const;
|
|
35
|
+
const urlKeyOf = (o: Rec) => IMAGE_URL_KEYS.find((k) => typeof o[k] === "string");
|
|
36
|
+
|
|
37
|
+
/** Where a field's value is stored in an object row: the first of its id and its older keys the row holds, else its id. */
|
|
38
|
+
const keyOf = (row: Rec, f: RowField) => [f.id, ...(f.from ?? [])].find((k) => Object.hasOwn(row, k) && !blank(row[k])) ?? f.id;
|
|
39
|
+
|
|
40
|
+
/** A field's value as its control shows it: a picture's address (whatever shape holds it), any other value as stored. */
|
|
41
|
+
function shown(f: RowField, v: unknown): unknown {
|
|
42
|
+
if (f.kind !== "image") return v;
|
|
43
|
+
if (typeof v === "string") return v;
|
|
44
|
+
if (isRecord(v)) { const k = urlKeyOf(v); return k ? v[k] : ""; }
|
|
45
|
+
if (Array.isArray(v)) return shown(f, v.find((x) => !blank(shown(f, x))));
|
|
46
|
+
return "";
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** A row's values by field id, as its controls show them. */
|
|
50
|
+
export function rowValues(row: unknown, fields: readonly RowField[]): Rec {
|
|
51
|
+
if (typeof row === "string") { const w = wordsField(fields); return w ? { [w.id]: row } : {}; }
|
|
52
|
+
if (!isRecord(row)) return {};
|
|
53
|
+
return Object.fromEntries(fields.map((f) => [f.id, shown(f, row[keyOf(row, f)])]));
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Kinds whose control writes a plain value (words, a number, a choice, on / off, a colour, a link). An object there is a value the control
|
|
57
|
+
* cannot show: drawn as text it read "[object Object]", and a save stored those words over it (#7081). */
|
|
58
|
+
const PLAIN = (v: unknown) => v === undefined || v === null || typeof v === "string" || typeof v === "number" || typeof v === "boolean";
|
|
59
|
+
|
|
60
|
+
/** Whether a field of this row can be edited with its control without losing what is stored: a plain value, or a picture's address. */
|
|
61
|
+
export function rowFieldEditable(row: unknown, f: RowField): boolean {
|
|
62
|
+
if (typeof row === "string" || !isRecord(row)) return true;
|
|
63
|
+
const v = row[keyOf(row, f)];
|
|
64
|
+
if (f.kind === "image") return PLAIN(v) || (isRecord(v) && (urlKeyOf(v) !== undefined || !IMAGE_URL_KEYS.some((k) => k in v)));
|
|
65
|
+
return PLAIN(v);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* The row with one field changed, everything else as stored:
|
|
70
|
+
* · an object keeps every other key, the field written under the key it was read from (an older name stays that name);
|
|
71
|
+
* · a picture stored as an object keeps its alt text and the rest, the address written under the key it was read from (`url` else);
|
|
72
|
+
* · a string row stays a string while it is the words that change; another field turns it into an object holding both;
|
|
73
|
+
* · emptying a field the row does not hold changes nothing (empty and unset are one value).
|
|
74
|
+
*/
|
|
75
|
+
export function withRowValue(row: unknown, f: RowField, value: unknown, fields: readonly RowField[]): unknown {
|
|
76
|
+
if (typeof row === "string") {
|
|
77
|
+
const w = wordsField(fields);
|
|
78
|
+
if (w && f.id === w.id) return value === undefined || value === null ? "" : typeof value === "string" ? value : String(value);
|
|
79
|
+
if (blank(value)) return row;
|
|
80
|
+
return w ? { [w.id]: row, [f.id]: value } : { [f.id]: value };
|
|
81
|
+
}
|
|
82
|
+
const base: Rec = isRecord(row) ? row : {};
|
|
83
|
+
const key = keyOf(base, f);
|
|
84
|
+
if (blank(value) && !Object.hasOwn(base, key)) return row;
|
|
85
|
+
const was = base[key];
|
|
86
|
+
if (f.kind === "image" && isRecord(was)) return { ...base, [key]: { ...was, [urlKeyOf(was) ?? "url"]: value } };
|
|
87
|
+
return { ...base, [key]: value };
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** A row's name in the list: its `title` field's words, else the first words it holds. Never an object's text. */
|
|
91
|
+
export function rowTitle(row: unknown, spec: ItemsSpec, fields: readonly RowField[] = rowFields(spec)): string {
|
|
92
|
+
const values = rowValues(row, fields);
|
|
93
|
+
const words = (id: string | undefined) => { const v = id ? values[id] : undefined; return typeof v === "string" ? v.trim() : typeof v === "number" ? String(v) : ""; };
|
|
94
|
+
const own = words(spec.title);
|
|
95
|
+
if (own) return own;
|
|
96
|
+
// Words first: a review's "5" (its rating) is no name when its title is there.
|
|
97
|
+
const wordy = fields.filter((f) => f.kind === "text" || f.kind === "textarea").map((f) => words(f.id)).filter(Boolean);
|
|
98
|
+
return wordy.find((w) => /\p{L}/u.test(w)) ?? wordy[0] ?? "";
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** A row's picture in the list: its `thumb` field, else its first picture. */
|
|
102
|
+
export function rowThumb(row: unknown, spec: ItemsSpec, fields: readonly RowField[] = rowFields(spec)): string | undefined {
|
|
103
|
+
const values = rowValues(row, fields);
|
|
104
|
+
const id = spec.thumb ?? fields.find((f) => f.kind === "image")?.id;
|
|
105
|
+
const v = id ? values[id] : undefined;
|
|
106
|
+
return typeof v === "string" && /^(https?:)?\/\//.test(v.trim()) ? v.trim() : undefined;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** The row "+ Add" puts in: the spec's `starter` (a copy), else every field empty (what the list always added). */
|
|
110
|
+
export function starterRow(spec: ItemsSpec, fields: readonly RowField[] = rowFields(spec)): unknown {
|
|
111
|
+
if (spec.starter !== undefined) return JSON.parse(JSON.stringify(spec.starter));
|
|
112
|
+
return Object.fromEntries(fields.map((f) => [f.id, ""]));
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** What the list's bounds allow with `count` rows, and why a button is off: a full list takes no more (Add, Duplicate), one at its least
|
|
116
|
+
* loses none (Remove). A bound the spec does not set is none. */
|
|
117
|
+
export function itemLimits(spec: Pick<ItemsSpec, "min" | "max">, count: number): { canAdd: boolean; full: string | null; canRemove: boolean; least: string | null } {
|
|
118
|
+
const max = typeof spec.max === "number" && spec.max > 0 ? Math.floor(spec.max) : Infinity;
|
|
119
|
+
const min = typeof spec.min === "number" && spec.min > 0 ? Math.floor(spec.min) : 0;
|
|
120
|
+
const canAdd = count < max;
|
|
121
|
+
const canRemove = count > min;
|
|
122
|
+
return {
|
|
123
|
+
canAdd, full: canAdd ? null : `Holds at most ${max} ${max === 1 ? "item" : "items"}.`,
|
|
124
|
+
canRemove, least: canRemove ? null : `Needs at least ${min} ${min === 1 ? "item" : "items"}.`,
|
|
125
|
+
};
|
|
126
|
+
}
|
package/src/editor/label-side.ts
CHANGED
|
@@ -39,6 +39,12 @@ export const LABEL_SIDE = {
|
|
|
39
39
|
link: "beside",
|
|
40
40
|
/** A date and time. */
|
|
41
41
|
date: "beside",
|
|
42
|
+
/** A secret (an API token, a private key): its masked box with Show and Paste, or once stored "Saved, ends in …" and Replace
|
|
43
|
+
* (SecretField). One line, as a text box; its buttons wrap under the box where the column is narrow, as a link's Choose does. */
|
|
44
|
+
secret: "beside",
|
|
45
|
+
/** Which screens show it: three device pictures (Desktop · Tablet · Mobile, each named in its tooltip and for a screen reader), as a
|
|
46
|
+
* vertical alignment's three pictures are (label-side audit decision E, 09/11/2026). Their words did not fit the control column. */
|
|
47
|
+
screens: "beside",
|
|
42
48
|
// THE PANEL'S WIDTH: the label above, the control under it.
|
|
43
49
|
/** A text of several lines (a description, custom CSS). */
|
|
44
50
|
textarea: "above",
|
|
@@ -54,12 +60,13 @@ export const LABEL_SIDE = {
|
|
|
54
60
|
gradient: "above",
|
|
55
61
|
/** A shape drawn on a picture (a print area). */
|
|
56
62
|
drawing: "above",
|
|
57
|
-
/** A line of code (a condition's expression)
|
|
63
|
+
/** A line of code (a condition's expression), or a CSS value that runs long (a text field's `code`: a font stack, a border): it reads
|
|
64
|
+
* whole across the field, wrapping, not cut in the control column. */
|
|
58
65
|
code: "above",
|
|
66
|
+
/** A sentence in place of a control: a value filled from elsewhere (the section's copy, a product's metafield, a list's content
|
|
67
|
+
* source), or a setting edited in another place. A sentence reads across the field; beside, it is four lines in the control column. */
|
|
68
|
+
note: "above",
|
|
59
69
|
// ABOVE FOR NOW: the decision is here, not in the host, so what is drawn and the table agree until the control is reworked.
|
|
60
|
-
/** Which screens show it (Desktop · Tablet · Mobile): three chips in words, too wide for the row. Three device glyphs beside the
|
|
61
|
-
* label move it to `chips` (slice 2 of the label-side work, decision E). */
|
|
62
|
-
screens: "above",
|
|
63
70
|
/** A font's one button (an "Aa" in the font, its name, CSS): a name needs the width (FontPickerField). It follows `pick` in a later
|
|
64
71
|
* slice (decision C); the element panel's Font is a list (`select`), beside. */
|
|
65
72
|
"font-pick": "above",
|
package/src/editor/panel.tsx
CHANGED
|
@@ -19,6 +19,14 @@ export interface PanelTab<T extends string = string> {
|
|
|
19
19
|
icon?: React.ReactNode;
|
|
20
20
|
/** The id of the panel this tab shows: `aria-controls` (and editor-plain.js shows it, hiding its siblings'). */
|
|
21
21
|
controls?: string;
|
|
22
|
+
/** A second line under the label, muted: what the part holds (09/11/2026, the offer editor's Offer · Who & when · Design, UI book
|
|
23
|
+
* OF-1). For the inspector row. It is the tab's description (`aria-describedby`), not part of its name. Under 300px of row only the
|
|
24
|
+
* labels stay. */
|
|
25
|
+
hint?: React.ReactNode;
|
|
26
|
+
/** The tab's own id, for the panel that names itself by it (`aria-labelledby`). */
|
|
27
|
+
tabId?: string;
|
|
28
|
+
/** Its tooltip (the offer editor's: what in that part needs a look). */
|
|
29
|
+
title?: string;
|
|
22
30
|
}
|
|
23
31
|
|
|
24
32
|
export interface PanelTabsProps<T extends string = string> {
|
|
@@ -35,34 +43,47 @@ export interface PanelTabsProps<T extends string = string> {
|
|
|
35
43
|
label?: string;
|
|
36
44
|
/**
|
|
37
45
|
* Roving focus (default on): only the selected tab is in the Tab order, ←/→ move the selection and the focus with
|
|
38
|
-
* it, wrapping at the ends
|
|
39
|
-
* kept exactly as it was in step 3).
|
|
46
|
+
* it, wrapping at the ends, and Home / End go to the first and the last (09/11/2026, as the offer editor's row did). Off,
|
|
47
|
+
* every tab is a plain stop and keys do nothing (the admin's Configure · Chat row, kept exactly as it was in step 3).
|
|
40
48
|
*/
|
|
41
49
|
roving?: boolean;
|
|
50
|
+
/** No margin of its own: the row sits flush in a box that has its own padding (the offer editor's card), outside the editor's
|
|
51
|
+
* column. The inspector's row otherwise keeps 8px over it and 12px at its sides there. */
|
|
52
|
+
flush?: boolean;
|
|
42
53
|
}
|
|
43
54
|
|
|
44
55
|
/** A row of `role="tab"` buttons. The caller owns the selection and draws the panel under it. */
|
|
45
|
-
export function PanelTabs<T extends string = string>({ tabs, value, onChange, variant = "column", label, roving = true }: PanelTabsProps<T>) {
|
|
56
|
+
export function PanelTabs<T extends string = string>({ tabs, value, onChange, variant = "column", label, roving = true, flush = false }: PanelTabsProps<T>) {
|
|
46
57
|
const inspector = variant === "inspector";
|
|
58
|
+
const hints = tabs.some((t) => t.hint != null);
|
|
59
|
+
const uid = useId();
|
|
47
60
|
const onKeyDown = roving ? (e: React.KeyboardEvent<HTMLDivElement>) => {
|
|
48
|
-
if (e.key !== "ArrowRight" && e.key !== "ArrowLeft") return;
|
|
61
|
+
if (e.key !== "ArrowRight" && e.key !== "ArrowLeft" && e.key !== "Home" && e.key !== "End") return;
|
|
49
62
|
e.preventDefault();
|
|
50
63
|
const i = tabs.findIndex((t) => t.id === value);
|
|
51
|
-
const ni = e.key === "
|
|
64
|
+
const ni = e.key === "Home" ? 0 : e.key === "End" ? tabs.length - 1
|
|
65
|
+
: e.key === "ArrowRight" ? (i + 1) % tabs.length : (i - 1 + tabs.length) % tabs.length;
|
|
52
66
|
onChange(tabs[ni].id);
|
|
53
67
|
// Focus follows the selection (roving tabindex).
|
|
54
68
|
(e.currentTarget.children[ni] as HTMLButtonElement | undefined)?.focus();
|
|
55
69
|
} : undefined;
|
|
56
70
|
return (
|
|
57
|
-
<div className={inspector ? "gemboss-ei-tabs" : "gemboss-ec-tabs"
|
|
71
|
+
<div className={[inspector ? "gemboss-ei-tabs" : "gemboss-ec-tabs", hints ? "has-hints" : "", flush ? "is-flush" : ""].filter(Boolean).join(" ")}
|
|
72
|
+
role="tablist" aria-label={label} onKeyDown={onKeyDown}>
|
|
58
73
|
{tabs.map((t) => {
|
|
59
74
|
const on = t.id === value;
|
|
60
75
|
return (
|
|
61
76
|
// data-value: what a page without React reads back (editor-plain.js), since the label can be anything.
|
|
62
|
-
<button key={t.id} type="button" role="tab" data-value={t.id}
|
|
77
|
+
<button key={t.id} type="button" role="tab" data-value={t.id} id={t.tabId} title={t.title}
|
|
63
78
|
className={inspector ? `gemboss-ei-tab${on ? " on" : ""}` : "gemboss-ec-tab"}
|
|
64
|
-
aria-selected={on} aria-controls={t.controls}
|
|
65
|
-
{
|
|
79
|
+
aria-selected={on} aria-controls={t.controls} aria-describedby={t.hint != null ? `${uid}-${t.id}-hint` : undefined}
|
|
80
|
+
tabIndex={roving ? (on ? 0 : -1) : undefined} onClick={() => onChange(t.id)}>
|
|
81
|
+
{t.icon}{hints ? (
|
|
82
|
+
// Every tab of a row with hints is drawn the same way (one without a hint keeps the column, so the labels line up). The
|
|
83
|
+
// hint describes the tab: hidden from its name, read as its description.
|
|
84
|
+
<span className="gemboss-ei-tab-text"><span>{t.label}</span>
|
|
85
|
+
{t.hint != null ? <span className="gemboss-ei-tab-hint" id={`${uid}-${t.id}-hint`} aria-hidden="true">{t.hint}</span> : null}</span>
|
|
86
|
+
) : t.label}
|
|
66
87
|
</button>
|
|
67
88
|
);
|
|
68
89
|
})}
|
|
@@ -179,6 +200,9 @@ export interface FieldProps {
|
|
|
179
200
|
label?: React.ReactNode;
|
|
180
201
|
/** The control's id, so a click on the label focuses it. */
|
|
181
202
|
htmlFor?: string;
|
|
203
|
+
/** The label's own id, for a control that is a group of boxes it names (`aria-labelledby`): several checkboxes have no one control a
|
|
204
|
+
* `for` can point at (Screens). */
|
|
205
|
+
labelId?: string;
|
|
182
206
|
/** A value shown at the label's right edge, bold and tabular (a range's current value: `.gemboss-ei-rangeval`). */
|
|
183
207
|
labelValue?: React.ReactNode;
|
|
184
208
|
/** The setting's help (`p.gemboss-ei-hint.gemboss-ei-help-text`). In a plugin's form a line under the control; inside an
|
|
@@ -203,6 +227,9 @@ export interface FieldProps {
|
|
|
203
227
|
style?: React.CSSProperties;
|
|
204
228
|
/** Refuse a descendant's pending blur commit on this existing field root, without inserting a DOM wrapper. */
|
|
205
229
|
onBlurCapture?: React.FocusEventHandler<HTMLDivElement>;
|
|
230
|
+
/** The focus leaving a part of the field, after the part's own blur (a text box whose toolbar, chips and link box are in the field too
|
|
231
|
+
* saves its words when the focus leaves all of them: the admin's TextMarksField). */
|
|
232
|
+
onBlur?: React.FocusEventHandler<HTMLDivElement>;
|
|
206
233
|
children?: React.ReactNode;
|
|
207
234
|
}
|
|
208
235
|
|
|
@@ -220,16 +247,16 @@ export interface FieldProps {
|
|
|
220
247
|
* beside it in a group, a drawer or a card alike (05/11/2026, unreleased: the row was laid out only inside a group, so the page settings drawer's
|
|
221
248
|
* three lists stacked under labels that asked to sit beside them).
|
|
222
249
|
*/
|
|
223
|
-
export function Field({ label, htmlFor, labelValue, hint, control, row = false, aside, mark, className, style, onBlurCapture, children }: FieldProps) {
|
|
250
|
+
export function Field({ label, htmlFor, labelId, labelValue, hint, control, row = false, aside, mark, className, style, onBlurCapture, onBlur, children }: FieldProps) {
|
|
224
251
|
const helpId = useId();
|
|
225
252
|
const [helpOpen, setHelpOpen] = useState(false);
|
|
226
253
|
const beside = control ? labelSide(control) === "beside" : row;
|
|
227
254
|
const cls = ["gemboss-ei-fld", beside && label != null ? "gemboss-ei-fld--row" : "", className].filter(Boolean).join(" ");
|
|
228
255
|
const labelNode = label != null ? (
|
|
229
|
-
<label htmlFor={htmlFor}>{label}{labelValue != null ? <span className="gemboss-ei-rangeval">{labelValue}</span> : null}</label>
|
|
256
|
+
<label htmlFor={htmlFor} id={labelId}>{label}{labelValue != null ? <span className="gemboss-ei-rangeval">{labelValue}</span> : null}</label>
|
|
230
257
|
) : null;
|
|
231
258
|
return (
|
|
232
|
-
<div className={cls} style={style} onBlurCapture={onBlurCapture}>
|
|
259
|
+
<div className={cls} style={style} onBlurCapture={onBlurCapture} onBlur={onBlur}>
|
|
233
260
|
{/* A ? is a button, so it sits BESIDE the label, not in it (a label may hold no other labelable element); so does an aside. */}
|
|
234
261
|
{(hint || aside || mark) && labelNode ? (
|
|
235
262
|
<div className="gemboss-ei-lbl">
|