@gemboss/ui 0.61.0 → 0.64.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 (45) hide show
  1. package/CHANGELOG.md +153 -0
  2. package/README.md +163 -2
  3. package/catalog/editor.html +1 -1
  4. package/catalog/index.html +3 -3
  5. package/gemboss-ui.css +3 -3
  6. package/package.json +15 -1
  7. package/parts/components.css +3 -3
  8. package/parts/core.css +1 -1
  9. package/parts/shell.css +1 -1
  10. package/src/app-nav.css +1 -0
  11. package/src/app-nav.tsx +236 -0
  12. package/src/assistant/chat.tsx +67 -4
  13. package/src/assistant/dictation.ts +292 -0
  14. package/src/assistant/index.ts +4 -1
  15. package/src/audiences-table.css +1 -0
  16. package/src/audiences-table.tsx +167 -0
  17. package/src/chat-voice.css +1 -0
  18. package/src/editor/frame-context.ts +9 -0
  19. package/src/editor/index.ts +8 -0
  20. package/src/editor/inspector-frame.tsx +285 -0
  21. package/src/editor/label-side.ts +79 -0
  22. package/src/editor/panel.tsx +23 -6
  23. package/src/editor/repeater.tsx +9 -3
  24. package/src/editor-inspector-frame.css +1 -0
  25. package/src/editor.css +1 -1
  26. package/src/email-editor/editor.tsx +434 -0
  27. package/src/email-editor/index.ts +16 -0
  28. package/src/email-editor/model.ts +357 -0
  29. package/src/email-editor/preview.tsx +208 -0
  30. package/src/email-editor.css +1 -0
  31. package/src/gem-at-work.css +1 -0
  32. package/src/gem-at-work.ts +1165 -0
  33. package/src/index.ts +17 -1
  34. package/src/kit-plain.css +1 -1
  35. package/src/rail-mini.css +1 -0
  36. package/src/report-charts.css +1 -0
  37. package/src/shell.tsx +36 -8
  38. package/src/skill-feedback.css +1 -0
  39. package/src/skill-feedback.tsx +67 -0
  40. package/src/skill-history.css +1 -0
  41. package/src/skill-history.tsx +116 -0
  42. package/src/skill-pages.css +1 -0
  43. package/src/skill-pages.tsx +204 -0
  44. package/src/skill-tabs-group.tsx +45 -0
  45. package/src/skill-view.tsx +7 -1
@@ -0,0 +1,434 @@
1
+ "use client";
2
+ // THE EMAIL EDITOR (05/11/2026, Chris approved canvas JQkjqVVb "Email editor": "editor thư theo bố cục Page editor"). The page
3
+ // editor's layout, as every editor's (memory editor-layout-left-column, Chris 03–04/11/2026): the bar on top, ONE resizable
4
+ // left column with Chat · Sections · Settings (the chat a tab, mounted once and kept across tabs), the mail on the stage, no
5
+ // right inspector. A block is added with "+" (under the picked block, at the end, in Sections), moved with ↑ ↓ or Alt+↑ ↓; nothing
6
+ // is dragged onto the mail.
7
+ //
8
+ // IN THE KIT so GemReach's admin can take it instead of its own (admin/src/pages/EmailEditor.tsx) and both edit one body: the
9
+ // blocks are GemReach's (model.ts). The editor holds no data logic: the draft comes in and goes out through `onChange`, Save and
10
+ // "Send me a test" are the surface's, the chat is the surface's (a slot). What it owns is what any email editor would: which tab,
11
+ // which block, the device, dark, the column's width, the picker.
12
+ import "../editor.css"; // the column, the fields (gemboss-ec, gemboss-ei-inp) are the editors' own look
13
+ import "../email-editor.css";
14
+ import { useEffect, useId, useMemo, useState } from "react";
15
+ import type React from "react";
16
+ import { EditorBack, EditorFrame, EditorSaveState, EditorTopbar, type EditorPane } from "../editor/frame";
17
+ import { EditorPaneTabs } from "../editor/panes";
18
+ import { Field, PanelHeader, PanelTabs } from "../editor/panel";
19
+ import { Seg } from "../editor/controls";
20
+ import { PickerGrid } from "../editor/picker-grid";
21
+ import { Segmented } from "../segmented";
22
+ import { ToggleBar } from "../toggle-bar";
23
+ import { StatusList } from "../status-list";
24
+ import { EmailPreview, type EmailDevice } from "./preview";
25
+ import {
26
+ ADD_KINDS, BLOCK_HINT, BLOCK_NAME, blockLine, blockTag, checksLine, emailChecks, insertBlock, insertPlace, isPersonalLink, moveBlock,
27
+ newBlock, PERSONAL_LINK, PERSONAL_LINK_HOURS, PRODUCTS_SOURCE_NAME, removeBlock,
28
+ type AddKind, type EmailBlock, type EmailBrand, type EmailCheck, type EmailDraft, type EmailPreviewPerson, type EmailPreviewProduct, type ProductsSource,
29
+ } from "./model";
30
+
31
+ type Tab = "chat" | "sections" | "settings";
32
+
33
+ export interface EmailEditorProps {
34
+ draft: EmailDraft;
35
+ onChange: (next: EmailDraft) => void;
36
+ brand: EmailBrand;
37
+ /**
38
+ * The way out, first in the bar: where the editor was opened from ("Night Serum funnel"), and how to go back there (`href`,
39
+ * drawn with `as`, a router link; or `onClick`). The arrow is named "Back to <place>" for a screen reader.
40
+ */
41
+ back: { place: string; href?: string; onClick?: () => void; as?: React.ElementType };
42
+ /** The Chat tab's content (the surface's assistant, wired to its own model). Absent: no Chat tab. */
43
+ chat?: React.ReactNode;
44
+ /** The people the preview can be drawn for; the first is shown first. */
45
+ people?: readonly EmailPreviewPerson[];
46
+ /** The products a `products` block shows for the person in the preview, by person id. */
47
+ productsFor?: (personId: string, source: ProductsSource) => readonly EmailPreviewProduct[];
48
+ /** What the mail's personal link opens ("Refill page, built for each buyer"): the funnel decides it, the button says it. */
49
+ opens?: string;
50
+ /** The server's checks (GemReach's preview route). Absent: the editor's own (model.ts `emailChecks`). */
51
+ checks?: readonly EmailCheck[];
52
+ saveState?: "idle" | "saving" | "saved";
53
+ /** True while the draft has changes Save has not written. */
54
+ dirty?: boolean;
55
+ onSave: () => void;
56
+ onSendTest: () => void;
57
+ /** Words for "Send me a test" while it runs or after it ran ("Sent to you@store.com"). */
58
+ testNote?: React.ReactNode;
59
+ /** Where the column's width is remembered in this browser. */
60
+ widthKey?: string;
61
+ }
62
+
63
+ const SPLIT = { initial: 360, min: 300 };
64
+
65
+ /** The left column's width: drag the seam or use ←/→ (16px, Shift 64), Home / End, remembered per browser (README "Resizable panels"). */
66
+ function useSplit(key: string) {
67
+ const [width, setWidth] = useState(SPLIT.initial);
68
+ const [max, setMax] = useState(560);
69
+ useEffect(() => {
70
+ const room = () => setMax(Math.max(SPLIT.min, Math.min(640, window.innerWidth - 480)));
71
+ room();
72
+ try { const n = Number(window.localStorage.getItem(key)); if (n >= SPLIT.min) setWidth(n); } catch { /* storage off */ }
73
+ window.addEventListener("resize", room);
74
+ return () => window.removeEventListener("resize", room);
75
+ }, [key]);
76
+ const clamp = (n: number) => Math.max(SPLIT.min, Math.min(max, n));
77
+ const keep = (n: number) => { setWidth(n); try { window.localStorage.setItem(key, String(n)); } catch { /* storage off */ } };
78
+ const onPointerDown = (e: React.PointerEvent<HTMLDivElement>) => {
79
+ if (e.button !== 0) return;
80
+ e.preventDefault();
81
+ const x0 = e.clientX, w0 = width;
82
+ document.body.classList.add("ui-resizing");
83
+ const move = (ev: PointerEvent) => keep(clamp(w0 + ev.clientX - x0));
84
+ const up = () => {
85
+ document.body.classList.remove("ui-resizing");
86
+ window.removeEventListener("pointermove", move); window.removeEventListener("pointerup", up);
87
+ window.removeEventListener("pointercancel", up); window.removeEventListener("blur", up);
88
+ };
89
+ window.addEventListener("pointermove", move); window.addEventListener("pointerup", up);
90
+ window.addEventListener("pointercancel", up); window.addEventListener("blur", up);
91
+ };
92
+ const onKeyDown = (e: React.KeyboardEvent<HTMLDivElement>) => {
93
+ if (e.altKey || e.metaKey || e.ctrlKey) return;
94
+ const step = e.shiftKey ? 64 : 16;
95
+ const to = e.key === "ArrowLeft" ? width - step : e.key === "ArrowRight" ? width + step : e.key === "Home" ? SPLIT.min : e.key === "End" ? max : null;
96
+ if (to === null) return;
97
+ e.preventDefault();
98
+ keep(clamp(to));
99
+ };
100
+ return { width: clamp(width), min: SPLIT.min, max, onPointerDown, onKeyDown, label: "Resize the editor column" };
101
+ }
102
+
103
+ /** A picture for each kind in the "+" picker (drawn glyphs at a readable size, never a shrunk copy of the block). */
104
+ const GLYPH: Record<AddKind, string> = {
105
+ header: "M4 9h16M7 5h10v8H7z",
106
+ image: "M4 5h16v14H4zM4 15l5-5 4 4 3-3 4 4M15 9h.01",
107
+ hero: "M5 6h14M5 11h10M5 15h14M5 19h9",
108
+ products: "M4 6h7v7H4zM13 6h7v7h-7zM4 16h7M13 16h7",
109
+ button: "M4 8h16v8H4zM9 12h6",
110
+ review: "M12 4l2.4 5 5.6.6-4.2 3.8 1.2 5.5L12 16.2 7 19l1.2-5.5L4 9.6 9.6 9z",
111
+ footer: "M4 17h16M7 20h10M4 5h16v8H4z",
112
+ };
113
+ const glyph = (k: AddKind) => (
114
+ <svg width="26" height="26" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true"><path d={GLYPH[k]} /></svg>
115
+ );
116
+
117
+ export function EmailEditor({
118
+ draft, onChange, brand, back, chat, people = [], productsFor, opens, checks: serverChecks, saveState = "idle", dirty = false,
119
+ onSave, onSendTest, testNote, widthKey = "gb.email-editor.left",
120
+ }: EmailEditorProps) {
121
+ const [tab, showTab] = useState<Tab>("sections");
122
+ // Opened once, the chat stays mounted under the other tabs (below): said where the tab changes, never in an effect a render late.
123
+ const [chatOpened, setChatOpened] = useState(false);
124
+ const setTab = (t: Tab) => { if (t === "chat") setChatOpened(true); showTab(t); };
125
+ const [selected, setSelected] = useState<number | null>(null);
126
+ const [device, setDevice] = useState<EmailDevice>("desktop");
127
+ const [dark, setDark] = useState(false);
128
+ const [adding, setAdding] = useState<number | null>(null);
129
+ const [personId, setPersonId] = useState(people[0]?.id ?? "");
130
+ const [pane, setPane] = useState<EditorPane>("preview");
131
+ const [checksOpen, setChecksOpen] = useState(false);
132
+ const split = useSplit(widthKey);
133
+ const person = people.find((p) => p.id === personId) ?? people[0];
134
+ const data = person?.data ?? draft.sample_data;
135
+ const body = draft.body;
136
+ const sel = selected !== null && selected < body.length ? selected : null;
137
+ const block = sel !== null ? body[sel]! : null;
138
+ const checks = useMemo(() => serverChecks ?? emailChecks(draft, brand, data), [serverChecks, draft, brand, data]);
139
+ const line = checksLine(checks);
140
+ const productsSource = body.find((b): b is Extract<EmailBlock, { type: "products" }> => b.type === "products")?.source ?? "order";
141
+ const products = person && productsFor ? productsFor(person.id, productsSource) : undefined;
142
+
143
+ const setBody = (next: EmailBlock[]) => onChange({ ...draft, body: next });
144
+ const patchBlock = (i: number, patch: Partial<EmailBlock>) => setBody(body.map((b, j) => (j === i ? ({ ...b, ...patch } as EmailBlock) : b)));
145
+ const select = (i: number | null, open: Tab | null = "settings") => {
146
+ setSelected(i);
147
+ setAdding(null);
148
+ if (open) setTab(open);
149
+ if (open && open !== "chat") setPane("chat");
150
+ };
151
+ const openAdd = (at: number) => { setAdding(at); setTab("sections"); setPane("chat"); };
152
+ const add = (kind: AddKind) => {
153
+ const at = adding ?? body.length;
154
+ const next = insertBlock(body, at, newBlock(kind));
155
+ setBody(next);
156
+ const landed = next.findIndex((b, i) => b !== body[i] && b.type === kind);
157
+ select(landed >= 0 ? landed : Math.min(at, next.length - 1));
158
+ };
159
+ const move = (from: number, to: number) => {
160
+ if (to < 0 || to >= body.length) return;
161
+ setBody(moveBlock(body, from, to));
162
+ setSelected(to);
163
+ };
164
+ const remove = (i: number) => { setBody(removeBlock(body, i)); setSelected(null); };
165
+ // Alt + ↑ / ↓ moves the picked block from anywhere in the editor but a text box (where Alt + arrows are the caret's).
166
+ useEffect(() => {
167
+ const onKey = (e: KeyboardEvent) => {
168
+ if (!e.altKey || sel === null || (e.key !== "ArrowUp" && e.key !== "ArrowDown")) return;
169
+ const t = e.target as HTMLElement | null;
170
+ if (t && (t.tagName === "INPUT" || t.tagName === "TEXTAREA" || t.isContentEditable)) return;
171
+ e.preventDefault();
172
+ move(sel, e.key === "ArrowUp" ? sel - 1 : sel + 1);
173
+ };
174
+ window.addEventListener("keydown", onKey);
175
+ return () => window.removeEventListener("keydown", onKey);
176
+ });
177
+
178
+ const tabs = [
179
+ ...(chat ? [{ id: "chat" as const, label: "Chat" }] : []),
180
+ { id: "sections" as const, label: "Sections" },
181
+ { id: "settings" as const, label: "Settings" },
182
+ ];
183
+
184
+ const sections = (
185
+ <div className="gb-emailed-pane">
186
+ {adding !== null ? (
187
+ <div className="gb-emailed-pick">
188
+ <div className="gb-emailed-pick-head">
189
+ <b>Add a block</b>
190
+ <span>{insertPlace(body, adding)}</span>
191
+ <button type="button" className="ui-btn ui-btn--ghost ui-btn--sm" onClick={() => setAdding(null)}>Cancel</button>
192
+ </div>
193
+ <PickerGrid label="Blocks" size="icon" tiles={ADD_KINDS.map((k) => ({ key: k, title: BLOCK_NAME[k], subtitle: BLOCK_HINT[k], picture: glyph(k) }))}
194
+ onSelect={(k) => add(k as AddKind)} onActivate={(k) => add(k as AddKind)} />
195
+ </div>
196
+ ) : null}
197
+ <ol className="gb-emailed-blocks" aria-label="Blocks in this email">
198
+ {body.map((b, i) => {
199
+ const tag = blockTag(b);
200
+ const on = sel === i;
201
+ return (
202
+ <li key={i} className={`gb-emailed-row${on ? " is-sel" : ""}${b.hidden ? " is-hidden" : ""}`}>
203
+ <button type="button" className="gb-emailed-row-main" aria-current={on ? "true" : undefined} onClick={() => select(i, null)}
204
+ onDoubleClick={() => select(i)}>
205
+ <span className="gb-emailed-row-t">
206
+ <b>{BLOCK_NAME[b.type]}</b>
207
+ <span>{blockLine(b, opens)}</span>
208
+ </span>
209
+ {tag ? <span className="gb-emailed-tag">{tag}</span> : null}
210
+ </button>
211
+ {on ? (
212
+ <span className="gb-emailed-row-acts">
213
+ <button type="button" aria-label={`Move ${BLOCK_NAME[b.type]} up`} title="Move up (Alt+↑)" disabled={i === 0} onClick={() => move(i, i - 1)}>↑</button>
214
+ <button type="button" aria-label={`Move ${BLOCK_NAME[b.type]} down`} title="Move down (Alt+↓)" disabled={i === body.length - 1} onClick={() => move(i, i + 1)}>↓</button>
215
+ <button type="button" aria-label={`Delete ${BLOCK_NAME[b.type]}`} title="Delete" onClick={() => remove(i)}>✕</button>
216
+ </span>
217
+ ) : null}
218
+ </li>
219
+ );
220
+ })}
221
+ </ol>
222
+ <button type="button" className="gb-emailed-addend" onClick={() => openAdd(sel !== null ? sel + 1 : body.length)}>
223
+ + Add a block{sel !== null ? <span> below {BLOCK_NAME[body[sel]!.type]}</span> : null}
224
+ </button>
225
+ {block ? (
226
+ <div className="gb-emailed-sum">
227
+ <b>{BLOCK_NAME[block.type]} · selected</b>
228
+ <BlockSummary b={block} opens={opens} />
229
+ <button type="button" className="ui-btn ui-btn--sm" onClick={() => setTab("settings")}>Edit settings</button>
230
+ </div>
231
+ ) : null}
232
+ </div>
233
+ );
234
+
235
+ const settings = block && sel !== null ? (
236
+ <div className="gb-emailed-pane">
237
+ <PanelHeader title={BLOCK_NAME[block.type]} subtitle={blockTag(block) ?? undefined} onClose={() => select(null)} closeLabel="Back to the email's settings" />
238
+ <BlockSettings key={sel} b={block} opens={opens} variables={draft.variables ?? []} onPatch={(p) => patchBlock(sel, p)} />
239
+ <button type="button" className="gb-emailed-addend" onClick={() => openAdd(sel + 1)}>+ Add a block below {BLOCK_NAME[block.type]}</button>
240
+ </div>
241
+ ) : (
242
+ <div className="gb-emailed-pane">
243
+ <PanelHeader title="Email" subtitle={`${draft.status === "draft" ? "Draft" : draft.status === "approved" ? "Approved" : "Retired"} · v${draft.version}`} />
244
+ <EmailSettings draft={draft} onChange={onChange} people={people} personId={person?.id ?? ""} onPerson={setPersonId} />
245
+ </div>
246
+ );
247
+
248
+ const status = draft.status === "draft" ? "Draft" : draft.status === "approved" ? "Approved" : "Retired";
249
+ const Back = back.as ?? (back.href ? "a" : "button");
250
+ return (
251
+ <EditorFrame
252
+ className="gb-emailed"
253
+ top={<EditorTopbar
254
+ variant="page"
255
+ back={<EditorBack as={Back} {...(back.href ? { href: back.href } : {})} onClick={back.onClick} label={`Back to ${back.place}`} />}
256
+ left={<>
257
+ <span className="gb-emailed-crumb" title={back.place}>{back.place}</span>
258
+ <span className="gb-emailed-slash" aria-hidden="true">/</span>
259
+ <b className="gb-emailed-name" title={draft.name}>{draft.name}</b>
260
+ <span className="gb-emailed-chip">{status} · v{draft.version}</span>
261
+ </>}
262
+ center={<span className="gb-emailed-view">
263
+ <Segmented<EmailDevice> ariaLabel="Preview size" value={device} onChange={setDevice}
264
+ options={[{ value: "desktop", label: "Desktop" }, { value: "mobile", label: "Mobile" }]} />
265
+ <ToggleBar<"dark"> ariaLabel="Preview colours" pressed={dark ? ["dark"] : []} onToggle={() => setDark((v) => !v)}
266
+ options={[{ value: "dark", label: "Dark", title: "How the email reads in a dark inbox" }]} />
267
+ </span>}
268
+ right={<>
269
+ <EditorSaveState state={saveState} idleText={dirty ? "Not saved" : undefined} />
270
+ <button type="button" className="ui-btn" onClick={onSendTest}>Send me a test</button>
271
+ <button type="button" className="ui-btn ui-btn--primary" onClick={onSave} disabled={saveState === "saving"}>Save</button>
272
+ </>}
273
+ />}
274
+ split={split}
275
+ mobilePane={pane}
276
+ left={<div className="gemboss-ec gb-emailed-col">
277
+ <PanelTabs<Tab> label="Editor" tabs={tabs} value={tab} onChange={(t) => { setTab(t); setAdding(null); }} />
278
+ {/* THE CHAT STAYS MOUNTED once opened: a turn running in it goes on while Sections or Settings is shown. */}
279
+ {chat && (tab === "chat" || chatOpened) ? <div className="gb-emailed-chat" hidden={tab !== "chat"}>{chat}</div> : null}
280
+ {tab === "sections" ? sections : tab === "settings" ? settings : null}
281
+ </div>}
282
+ previewClassName="gb-emailed-stage"
283
+ preview={<div className="gb-emailed-scroll" onClick={() => select(null, null)}>
284
+ <div className="gb-emailed-meta" onClick={(e) => e.stopPropagation()}>
285
+ {testNote ? <span className="gb-emailed-note" role="status">{testNote}</span> : null}
286
+ <button type="button" className={line.ok ? "gb-emailed-checks is-ok" : "gb-emailed-checks"} aria-expanded={checksOpen}
287
+ onClick={() => setChecksOpen((v) => !v)}>{line.text}</button>
288
+ {people.length ? (
289
+ <span className="gb-emailed-as">Preview as: {person?.label}</span>
290
+ ) : null}
291
+ </div>
292
+ {checksOpen ? (
293
+ <div className="gb-emailed-checklist" onClick={(e) => e.stopPropagation()}>
294
+ <StatusList label="Checks" items={[...checks].sort((a, b) => Number(a.ok) - Number(b.ok)).map((c) => ({
295
+ key: c.id, label: c.label, text: c.ok ? "Passes" : c.detail ?? "Needs a look", tone: c.ok ? "ok" : "warning",
296
+ }))} />
297
+ </div>
298
+ ) : null}
299
+ {/* The envelope reads as picked only where its settings are shown (Settings, no block picked); -1 picks nothing. */}
300
+ <EmailPreview draft={draft} brand={brand} data={data} products={products} device={device} dark={dark} selected={sel ?? (tab === "settings" ? null : -1)}
301
+ onSelect={(i) => select(i)} onAddAfter={(i) => openAdd(i + 1)} />
302
+ <button type="button" className="gb-emailed-addend gb-emailed-addmail" onClick={(e) => { e.stopPropagation(); openAdd(body.length); }}>+ Add a block at the end</button>
303
+ </div>}
304
+ >
305
+ <EditorPaneTabs value={pane} onChange={setPane} labels={{ chat: "Edit", preview: "Email" }} />
306
+ </EditorFrame>
307
+ );
308
+ }
309
+
310
+ /** The picked block in a few lines, under the list (the board's "Button · selected"). */
311
+ function BlockSummary({ b, opens }: { b: EmailBlock; opens?: string }) {
312
+ if (b.type === "button") {
313
+ return <>
314
+ <span>Text: <b>{b.text}</b></span>
315
+ {isPersonalLink(b.url) ? <>
316
+ <span>Opens: <b>{opens ?? "A page built for each person"}</b></span>
317
+ <span className="gb-emailed-muted">Each person gets their own signed link. It expires in {PERSONAL_LINK_HOURS} hours and carries no email address.</span>
318
+ </> : <span>Opens: <b>{b.url || "no link yet"}</b></span>}
319
+ </>;
320
+ }
321
+ if (b.type === "products") return <span>{PRODUCTS_SOURCE_NAME[b.source]} · {b.count ?? 2} products, filled for each person when the email is built.</span>;
322
+ if (b.type === "review") return <span>Asks through GemReview, on a page signed for this buyer.</span>;
323
+ return <span>{blockLine(b, opens)}</span>;
324
+ }
325
+
326
+ // ── settings ────────────────────────────────────────────────────────────────────────────────────────────────────────────
327
+
328
+ function TextField({ label, value, onChange, hint, area = false, placeholder }: {
329
+ label: string; value: string; onChange: (v: string) => void; hint?: React.ReactNode; area?: boolean; placeholder?: string;
330
+ }) {
331
+ const id = useId();
332
+ return (
333
+ <Field label={label} htmlFor={id} hint={hint}>
334
+ {area
335
+ ? <textarea id={id} className="gemboss-field gemboss-ei-inp gb-emailed-area" rows={4} value={value} placeholder={placeholder} onChange={(e) => onChange(e.target.value)} />
336
+ : <input id={id} className="gemboss-field gemboss-ei-inp" value={value} placeholder={placeholder} onChange={(e) => onChange(e.target.value)} />}
337
+ </Field>
338
+ );
339
+ }
340
+
341
+ const ALIGN = [{ value: "left", label: "Left" }, { value: "center", label: "Center" }, { value: "right", label: "Right" }] as const;
342
+
343
+ function BlockSettings({ b, opens, variables, onPatch }: { b: EmailBlock; opens?: string; variables: readonly string[]; onPatch: (p: Partial<EmailBlock>) => void }) {
344
+ const p = onPatch as (patch: Record<string, unknown>) => void;
345
+ const insert = (key: "text" | "title", now: string) => variables.length ? (
346
+ <div className="gb-emailed-vars" role="group" aria-label="Insert a variable">
347
+ {variables.map((v) => (
348
+ <button key={v} type="button" className="ui-chip" onClick={() => p({ [key]: `${now}${now && !now.endsWith(" ") ? " " : ""}{{${v}}}` })}>{`{{${v}}}`}</button>
349
+ ))}
350
+ </div>
351
+ ) : null;
352
+ switch (b.type) {
353
+ case "header":
354
+ return <div className="gb-emailed-form">
355
+ <Field label="Align" row><Seg label="Align" value={b.align ?? "center"} onChange={(v) => p({ align: v })} options={ALIGN} /></Field>
356
+ <TextField label="Link" value={b.href ?? ""} onChange={(v) => p({ href: v || undefined })} placeholder="The store's home page" />
357
+ <p className="gb-emailed-muted">The logo comes from the brand kit.</p>
358
+ </div>;
359
+ case "image":
360
+ return <div className="gb-emailed-form">
361
+ <TextField label="Image address" value={b.src} onChange={(v) => p({ src: v })} placeholder="https://…" />
362
+ <TextField label="What it shows" value={b.alt ?? ""} onChange={(v) => p({ alt: v })} hint="Read aloud, and shown when an inbox hides pictures." />
363
+ <TextField label="Link" value={b.href ?? ""} onChange={(v) => p({ href: v || undefined })} placeholder="None" />
364
+ </div>;
365
+ case "hero":
366
+ return <div className="gb-emailed-form">
367
+ <TextField label="Heading" value={b.title} onChange={(v) => p({ title: v })} />
368
+ <TextField label="Text" value={b.text ?? ""} onChange={(v) => p({ text: v })} area hint="Variables like {{first_name}} are filled for each person." />
369
+ {insert("text", b.text ?? "")}
370
+ <Field label="Align" row><Seg label="Align" value={b.align ?? "left"} onChange={(v) => p({ align: v })} options={ALIGN} /></Field>
371
+ </div>;
372
+ case "heading": case "paragraph":
373
+ return <div className="gb-emailed-form">
374
+ <TextField label={b.type === "heading" ? "Heading" : "Text"} value={b.text} onChange={(v) => p({ text: v })} area={b.type === "paragraph"} />
375
+ {insert("text", b.text)}
376
+ </div>;
377
+ case "products":
378
+ return <div className="gb-emailed-form">
379
+ <Field label="Products from"><Seg<ProductsSource> label="Products from" value={b.source} onChange={(v) => p({ source: v })}
380
+ options={(["order", "cart", "viewed"] as const).map((v) => ({ value: v, label: PRODUCTS_SOURCE_NAME[v] }))} /></Field>
381
+ <Field label="How many" row><Seg label="How many" value={String(b.count ?? 2)} onChange={(v) => p({ count: Number(v) })}
382
+ options={["1", "2", "3", "4"].map((v) => ({ value: v, label: v }))} /></Field>
383
+ <TextField label="Title above them" value={b.title ?? ""} onChange={(v) => p({ title: v || undefined })} placeholder="None" />
384
+ <p className="gb-emailed-muted">Filled for each person when the email is built: what they bought, what is in their cart, or what they looked at.</p>
385
+ </div>;
386
+ case "button": {
387
+ const personal = isPersonalLink(b.url);
388
+ return <div className="gb-emailed-form">
389
+ <TextField label="Text" value={b.text} onChange={(v) => p({ text: v })} hint="Short: phones fit about 25 characters on one line." />
390
+ <Field label="Opens"><Seg<"personal" | "link"> label="Opens" value={personal ? "personal" : "link"}
391
+ onChange={(v) => p({ url: v === "personal" ? PERSONAL_LINK : "" })}
392
+ options={[{ value: "personal", label: "Personal link" }, { value: "link", label: "A link" }]} /></Field>
393
+ {personal ? (
394
+ <div className="gb-emailed-personal">
395
+ <span className="gb-emailed-tag">Personal link</span>
396
+ <b>{opens ?? "A page built for each person"}</b>
397
+ <span>Each person gets their own signed link. It expires in {PERSONAL_LINK_HOURS} hours and carries no email address.</span>
398
+ </div>
399
+ ) : <TextField label="Link" value={b.url} onChange={(v) => p({ url: v })} placeholder="https://…" />}
400
+ <Field label="Align" row><Seg label="Align" value={b.align ?? "center"} onChange={(v) => p({ align: v })} options={ALIGN} /></Field>
401
+ </div>;
402
+ }
403
+ case "review":
404
+ return <div className="gb-emailed-form">
405
+ <TextField label="Question" value={b.title} onChange={(v) => p({ title: v })} />
406
+ <TextField label="Text" value={b.text ?? ""} onChange={(v) => p({ text: v })} area />
407
+ <TextField label="Button" value={b.button} onChange={(v) => p({ button: v })} />
408
+ <p className="gb-emailed-muted">GemReview opens a page signed for this buyer: stars, a few words, a photo if they like.</p>
409
+ </div>;
410
+ case "footer":
411
+ return <div className="gb-emailed-form">
412
+ <TextField label="A line above the address" value={b.text ?? ""} onChange={(v) => p({ text: v || undefined })} placeholder="None" />
413
+ <p className="gb-emailed-muted">The store's postal address, Unsubscribe and Email preferences are on every email. Unsubscribe works in one click.</p>
414
+ </div>;
415
+ default:
416
+ return <p className="gb-emailed-muted">This block is edited in GemReach for now.</p>;
417
+ }
418
+ }
419
+
420
+ function EmailSettings({ draft, onChange, people, personId, onPerson }: {
421
+ draft: EmailDraft; onChange: (d: EmailDraft) => void; people: readonly EmailPreviewPerson[]; personId: string; onPerson: (id: string) => void;
422
+ }) {
423
+ return (
424
+ <div className="gb-emailed-form">
425
+ <TextField label="Name" value={draft.name} onChange={(v) => onChange({ ...draft, name: v })} hint="Only you see it: on the funnel and in lists." />
426
+ <TextField label="Subject" value={draft.subject} onChange={(v) => onChange({ ...draft, subject: v })} hint="Phones cut it at about 60 characters." />
427
+ <TextField label="Preview line" value={draft.preheader} onChange={(v) => onChange({ ...draft, preheader: v })} hint="The grey line after the subject in the inbox." />
428
+ <Field label="From"><span className="gb-emailed-from">{draft.from.name} &lt;{draft.from.email}&gt;</span></Field>
429
+ {people.length > 1 ? (
430
+ <Field label="Preview as"><Seg label="Preview as" value={personId} onChange={onPerson} options={people.map((x) => ({ value: x.id, label: x.label.split(" · ")[0]!, name: x.label }))} /></Field>
431
+ ) : null}
432
+ </div>
433
+ );
434
+ }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * `@gemboss/ui/email-editor` (05/11/2026): the email editor, its preview and its model, on an entry of their own so only a screen
3
+ * that edits an email pays for them (like `@gemboss/ui/editor`). The look is `@gemboss/ui/email-editor.css`, which the components
4
+ * import themselves. The model is GemReach's block list (README "Email editor").
5
+ */
6
+ export { EmailEditor, type EmailEditorProps } from "./editor";
7
+ export { EmailPreview, type EmailDevice, type EmailPreviewProps } from "./preview";
8
+ export {
9
+ ADD_KINDS, BLOCK_HINT, BLOCK_NAME, BUILT_IN_VARIABLES, GEMREACH_BLOCK_TYPES, PERSONAL_LINK, PERSONAL_LINK_HOURS, PRODUCTS_SOURCE_NAME,
10
+ PROPOSED_BLOCK_TYPES, REVIEW_LINK,
11
+ blockLine, blockTag, checksLine, contrast, emailChecks, fillVariables, insertBlock, insertPlace, isPersonalLink, moveBlock, newBlock,
12
+ removeBlock, stringsOf, usedVariables, variablesIn,
13
+ type AddKind, type Align, type EmailBlock, type EmailBlockStyle, type EmailBlockType, type EmailBrand, type EmailCheck, type EmailColumn,
14
+ type EmailDraft, type EmailPreviewPerson, type EmailPreviewProduct, type GemReachBlock, type ProductsBlock, type ProductsSource,
15
+ type ReviewBlock, type Spacing,
16
+ } from "./model";