@drawnagency/primitives 0.1.80 → 0.1.82

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 (102) hide show
  1. package/dist/{chunk-7XWER6YR.js → chunk-22GU6GNP.js} +3 -3
  2. package/dist/{chunk-4TVODHD2.js → chunk-5UDIQLGQ.js} +6 -6
  3. package/dist/{chunk-UNUJPLZV.js → chunk-6NRVX6NQ.js} +1 -1
  4. package/dist/{chunk-KVQFMVXE.js → chunk-DKXISNJ2.js} +2 -2
  5. package/dist/{chunk-RSITF24B.js → chunk-ETJYYUQX.js} +9 -3
  6. package/dist/{chunk-VI26O4E3.js → chunk-FDBZZ4AT.js} +1 -1
  7. package/dist/chunk-FM4M4Q2W.js +72 -0
  8. package/dist/{chunk-EMGLZQCM.js → chunk-MBJUWOM2.js} +1 -1
  9. package/dist/{chunk-2DDWWTRX.js → chunk-Q6LZOH5M.js} +1 -1
  10. package/dist/{chunk-QB5Q23G2.js → chunk-Y54G2XSC.js} +1 -1
  11. package/dist/{chunk-3LNKOLZP.js → chunk-YKOLOZB2.js} +1 -1
  12. package/dist/components/editor/PagesModal.d.ts +2 -0
  13. package/dist/components/editor/PagesModal.d.ts.map +1 -1
  14. package/dist/components/editor/index.js +6 -5
  15. package/dist/components/primitives/index.js +7 -6
  16. package/dist/components/sections/brand-guide.js +7 -6
  17. package/dist/components/sections/register-schemas.js +10 -9
  18. package/dist/components/sections/register.js +10 -9
  19. package/dist/components/shell/DocInspector.d.ts +18 -0
  20. package/dist/components/shell/DocInspector.d.ts.map +1 -0
  21. package/dist/components/shell/DocumentEditorOverlay.d.ts +29 -0
  22. package/dist/components/shell/DocumentEditorOverlay.d.ts.map +1 -0
  23. package/dist/components/shell/DocumentPresentOverlay.d.ts +30 -0
  24. package/dist/components/shell/DocumentPresentOverlay.d.ts.map +1 -0
  25. package/dist/components/shell/EditorShell.d.ts +34 -0
  26. package/dist/components/shell/EditorShell.d.ts.map +1 -1
  27. package/dist/document/assets/fonts/albra-grotesk-bold.woff +0 -0
  28. package/dist/document/assets/fonts/albra-grotesk-regular.woff +0 -0
  29. package/dist/document/assets/fonts/kapra-neue-expanded-medium.woff +0 -0
  30. package/dist/document/assets/fonts/kapra-neue-expanded-regular.woff +0 -0
  31. package/dist/document/components/DocCoverPage.d.ts +11 -0
  32. package/dist/document/components/DocCoverPage.d.ts.map +1 -0
  33. package/dist/document/components/DocPage.d.ts +10 -0
  34. package/dist/document/components/DocPage.d.ts.map +1 -0
  35. package/dist/document/components/DocRail.d.ts +28 -0
  36. package/dist/document/components/DocRail.d.ts.map +1 -0
  37. package/dist/document/components/DocSectionPage.d.ts +12 -0
  38. package/dist/document/components/DocSectionPage.d.ts.map +1 -0
  39. package/dist/document/components/DocViewer.d.ts +18 -0
  40. package/dist/document/components/DocViewer.d.ts.map +1 -0
  41. package/dist/document/components/Wordmark.d.ts +4 -0
  42. package/dist/document/components/Wordmark.d.ts.map +1 -0
  43. package/dist/document/components/measure.d.ts +7 -0
  44. package/dist/document/components/measure.d.ts.map +1 -0
  45. package/dist/document/components/useDocPages.d.ts +12 -0
  46. package/dist/document/components/useDocPages.d.ts.map +1 -0
  47. package/dist/document/engine/blocks.d.ts +2 -0
  48. package/dist/document/engine/blocks.d.ts.map +1 -0
  49. package/dist/document/engine/harvest.d.ts +3 -0
  50. package/dist/document/engine/harvest.d.ts.map +1 -0
  51. package/dist/document/engine/masonry.d.ts +26 -0
  52. package/dist/document/engine/masonry.d.ts.map +1 -0
  53. package/dist/document/engine/paginate.d.ts +43 -0
  54. package/dist/document/engine/paginate.d.ts.map +1 -0
  55. package/dist/document/engine/settings.d.ts +88 -0
  56. package/dist/document/engine/settings.d.ts.map +1 -0
  57. package/dist/document/engine/types.d.ts +44 -0
  58. package/dist/document/engine/types.d.ts.map +1 -0
  59. package/dist/document/index.d.ts +13 -0
  60. package/dist/document/index.d.ts.map +1 -0
  61. package/dist/document/index.js +965 -0
  62. package/dist/document/styles/document.css +217 -0
  63. package/dist/index.js +29 -28
  64. package/dist/lib/document-input.d.ts +25 -0
  65. package/dist/lib/document-input.d.ts.map +1 -0
  66. package/dist/lib/index.js +10 -9
  67. package/dist/lib/pages.d.ts +2 -0
  68. package/dist/lib/pages.d.ts.map +1 -1
  69. package/dist/media/index.js +4 -3
  70. package/dist/schemas/index.js +3 -2
  71. package/dist/schemas/site-config.d.ts +265 -1
  72. package/dist/schemas/site-config.d.ts.map +1 -1
  73. package/package.json +5 -1
  74. package/src/components/editor/PagesModal.tsx +16 -2
  75. package/src/components/shell/DocInspector.tsx +323 -0
  76. package/src/components/shell/DocumentEditorOverlay.tsx +169 -0
  77. package/src/components/shell/DocumentPresentOverlay.tsx +87 -0
  78. package/src/components/shell/EditorShell.tsx +128 -5
  79. package/src/document/assets/fonts/albra-grotesk-bold.woff +0 -0
  80. package/src/document/assets/fonts/albra-grotesk-regular.woff +0 -0
  81. package/src/document/assets/fonts/kapra-neue-expanded-medium.woff +0 -0
  82. package/src/document/assets/fonts/kapra-neue-expanded-regular.woff +0 -0
  83. package/src/document/components/DocCoverPage.tsx +45 -0
  84. package/src/document/components/DocPage.tsx +40 -0
  85. package/src/document/components/DocRail.tsx +164 -0
  86. package/src/document/components/DocSectionPage.tsx +48 -0
  87. package/src/document/components/DocViewer.tsx +285 -0
  88. package/src/document/components/Wordmark.tsx +18 -0
  89. package/src/document/components/measure.tsx +117 -0
  90. package/src/document/components/useDocPages.ts +85 -0
  91. package/src/document/engine/blocks.ts +87 -0
  92. package/src/document/engine/harvest.ts +95 -0
  93. package/src/document/engine/masonry.ts +152 -0
  94. package/src/document/engine/paginate.ts +229 -0
  95. package/src/document/engine/settings.ts +88 -0
  96. package/src/document/engine/types.ts +64 -0
  97. package/src/document/index.ts +18 -0
  98. package/src/document/styles/document.css +217 -0
  99. package/src/lib/document-input.ts +57 -0
  100. package/src/lib/pages.ts +22 -0
  101. package/src/schemas/site-config.ts +22 -7
  102. /package/dist/{chunk-4YEOTFVU.js → chunk-YBVK254P.js} +0 -0
@@ -0,0 +1,323 @@
1
+ import { settingsFor, type DocumentOptions } from "../../document";
2
+ import { Input } from "../shared/Input";
3
+ import { Select } from "../shared/Select";
4
+ import { Checkbox } from "../shared/Checkbox";
5
+ import { RadioGroup } from "../shared/RadioGroup";
6
+ import { ColorPicker } from "../shared/ColorPicker";
7
+ import { FormLabel } from "../shared/FormLabel";
8
+ import { useMediaLibrary } from "./MediaLibraryContext";
9
+ import { Button } from "../shared/Button";
10
+ import type { MediaItem } from "../../media/types";
11
+
12
+ // Smallest generated variant for the inspector thumbnail (same file naming as
13
+ // docImagesFrom in lib/document-input.ts); null when the item can't render.
14
+ function thumbSrc(imageId: string, item: MediaItem | undefined): string | null {
15
+ if (!item || item.kind !== "image") return null;
16
+ if (item.mimeType === "image/svg+xml") return `/api/media/${imageId}/original.svg`;
17
+ const widths = item.variants.map((v) => v.width).sort((a, b) => a - b);
18
+ if (widths.length === 0) return null;
19
+ return `/api/media/${imageId}/${widths[0]}.webp`;
20
+ }
21
+
22
+ export interface DocInspectorProps {
23
+ document: DocumentOptions;
24
+ selection: { kind: "cover" } | { kind: "chunk"; chunkId: string; title: string; depth?: number };
25
+ warnings: string[]; // warningsByChunk for the selected chunk
26
+ onUpdateCover: (patch: Partial<DocumentOptions["cover"]>) => void;
27
+ onUpdateMeta: (patch: Partial<DocumentOptions["meta"]>) => void;
28
+ // Caller merges the patch via sectionSettingsSchema.parse.
29
+ onUpdateSection: (chunkId: string, patch: Record<string, unknown>) => void;
30
+ }
31
+
32
+ // Drawn palette — mirrors the swatch row in the harness inspector.
33
+ const SWATCHES = [
34
+ "#FFFFFF", "#EBEBEB", "#999999", "#333333", "#1F1F1F", // neutrals: white → near-black
35
+ "#009FAD", // teal (brand primary)
36
+ "#3D7F7F", // forest
37
+ "#099A6F", // green
38
+ "#5F81AB", // blue
39
+ "#7C97BB", // sky
40
+ "#6864A0", // violet
41
+ "#D3A978", // beige
42
+ "#EB9500", // gold
43
+ "#F07C00", // orange
44
+ "#A24E16", // brown / rust
45
+ "#A65982", // indigo
46
+ "#E64165", // pink
47
+ ];
48
+
49
+ function ColorControl({ label, value, onPick }: { label: string; value: string; onPick: (v: string) => void }) {
50
+ return (
51
+ <div className="mb-4">
52
+ <FormLabel>{label}</FormLabel>
53
+ <div className="flex flex-wrap items-center gap-1">
54
+ {SWATCHES.map((s) => (
55
+ <button
56
+ key={s}
57
+ type="button"
58
+ aria-label={s}
59
+ onClick={() => onPick(s)}
60
+ style={{ background: s }}
61
+ className={`h-6 w-6 rounded border ${s === value ? "border-primary ring-1 ring-primary" : "border-base-200"}`}
62
+ />
63
+ ))}
64
+ <ColorPicker value={value} onChange={onPick} label="Custom color" className="h-6 w-6" />
65
+ </div>
66
+ </div>
67
+ );
68
+ }
69
+
70
+ export function DocInspector({
71
+ document: doc,
72
+ selection,
73
+ warnings,
74
+ onUpdateCover,
75
+ onUpdateMeta,
76
+ onUpdateSection,
77
+ }: DocInspectorProps) {
78
+ return (
79
+ <aside data-testid="doc-inspector" className="w-64 shrink-0 overflow-y-auto border-l border-base-200 bg-base p-4">
80
+ {selection.kind === "cover" ? (
81
+ <CoverPanel doc={doc} onUpdateCover={onUpdateCover} onUpdateMeta={onUpdateMeta} />
82
+ ) : (
83
+ <ChunkPanel
84
+ key={selection.chunkId}
85
+ chunkId={selection.chunkId}
86
+ title={selection.title}
87
+ depth={selection.depth}
88
+ doc={doc}
89
+ warnings={warnings}
90
+ onUpdateSection={onUpdateSection}
91
+ />
92
+ )}
93
+ </aside>
94
+ );
95
+ }
96
+
97
+ function CoverPanel({
98
+ doc,
99
+ onUpdateCover,
100
+ onUpdateMeta,
101
+ }: {
102
+ doc: DocumentOptions;
103
+ onUpdateCover: (patch: Partial<DocumentOptions["cover"]>) => void;
104
+ onUpdateMeta: (patch: Partial<DocumentOptions["meta"]>) => void;
105
+ }) {
106
+ const { cover, meta } = doc;
107
+ const media = useMediaLibrary();
108
+ return (
109
+ <>
110
+ <h2 className="mb-2 text-xs font-semibold uppercase tracking-wide text-base-contrast-light">Cover</h2>
111
+ <Input label="Title" value={cover.title} onChange={(title) => onUpdateCover({ title })} className="mb-2" />
112
+ <Input label="Label" value={cover.label} onChange={(label) => onUpdateCover({ label })} className="mb-2" />
113
+ <Input label="Date" value={cover.date} onChange={(date) => onUpdateCover({ date })} className="mb-2" />
114
+
115
+ {media ? (
116
+ <div className="mb-4">
117
+ <FormLabel>Cover image</FormLabel>
118
+ {cover.imageId ? (
119
+ (() => {
120
+ const src = thumbSrc(cover.imageId, media.manifest.images[cover.imageId]);
121
+ return src ? (
122
+ <img src={src} alt="Cover image preview" className="mb-2 max-h-24 rounded border border-base-200" />
123
+ ) : null;
124
+ })()
125
+ ) : null}
126
+ <div className="flex gap-2">
127
+ <Button
128
+ variant="secondary"
129
+ size="sm"
130
+ onClick={() => media.openSelectModal((imageId) => onUpdateCover({ imageId }))}
131
+ >
132
+ {cover.imageId ? "Replace image" : "Choose image"}
133
+ </Button>
134
+ {cover.imageId ? (
135
+ <Button variant="ghost" size="sm" onClick={() => onUpdateCover({ imageId: null })}>
136
+ Remove image
137
+ </Button>
138
+ ) : null}
139
+ </div>
140
+ </div>
141
+ ) : null}
142
+
143
+ <ColorControl label="Background" value={cover.bgColor} onPick={(bgColor) => onUpdateCover({ bgColor })} />
144
+ <ColorControl label="Accent" value={cover.accentColor} onPick={(accentColor) => onUpdateCover({ accentColor })} />
145
+
146
+ <h2 className="mb-2 mt-6 text-xs font-semibold uppercase tracking-wide text-base-contrast-light">Document</h2>
147
+ <Input label="Client" value={meta.client} onChange={(client) => onUpdateMeta({ client })} className="mb-2" />
148
+ <Input label="Project" value={meta.project} onChange={(project) => onUpdateMeta({ project })} className="mb-2" />
149
+ <Input label="Date label" value={meta.dateLabel} onChange={(dateLabel) => onUpdateMeta({ dateLabel })} className="mb-2" />
150
+ </>
151
+ );
152
+ }
153
+
154
+ function ChunkPanel({
155
+ chunkId,
156
+ title,
157
+ depth,
158
+ doc,
159
+ warnings,
160
+ onUpdateSection,
161
+ }: {
162
+ chunkId: string;
163
+ title: string;
164
+ depth?: number;
165
+ doc: DocumentOptions;
166
+ warnings: string[];
167
+ onUpdateSection: (chunkId: string, patch: Record<string, unknown>) => void;
168
+ }) {
169
+ const settings = settingsFor(doc.sections, chunkId);
170
+ const layout = settings.imageLayout;
171
+
172
+ return (
173
+ <>
174
+ <h2 className="mb-3 text-xs font-semibold uppercase tracking-wide text-base-contrast-light">{title}</h2>
175
+
176
+ <Checkbox
177
+ className="mb-4"
178
+ checked={!settings.excluded}
179
+ onChange={(checked) => onUpdateSection(chunkId, { excluded: !checked })}
180
+ label="Include in document"
181
+ />
182
+
183
+ {/* Only parent sections own the boundary setting — a sub-page can't
184
+ split further, and its entry would be inert anyway (harvest reads
185
+ splitAt from parent ids only). */}
186
+ {(depth ?? 0) === 0 ? (
187
+ <Select
188
+ className="mb-4"
189
+ label="Split pages at"
190
+ value={settings.splitAt}
191
+ options={[
192
+ { value: "none", label: "Off" },
193
+ { value: "sub_heading", label: "Sub-headings" },
194
+ ]}
195
+ onChange={(splitAt) => onUpdateSection(chunkId, { splitAt })}
196
+ />
197
+ ) : null}
198
+
199
+ {/* Image placement is linked, not independent (Drew, 2026-07-19): text
200
+ left → images right of the column, text top → images below full
201
+ width. One control drives both fields. */}
202
+ <RadioGroup
203
+ className="mb-4"
204
+ label="Text placement"
205
+ value={settings.textPlacement}
206
+ options={[
207
+ { label: "Top", value: "top" },
208
+ { label: "Left column", value: "leftColumn" },
209
+ ]}
210
+ onChange={(textPlacement) =>
211
+ onUpdateSection(chunkId, {
212
+ textPlacement,
213
+ imagePlacement: textPlacement === "leftColumn" ? "right" : "fullWidth",
214
+ })
215
+ }
216
+ />
217
+
218
+ <Checkbox
219
+ className="mb-4"
220
+ checked={settings.dropTextOverflow}
221
+ onChange={(dropTextOverflow) => onUpdateSection(chunkId, { dropTextOverflow })}
222
+ label="Drop text overflow"
223
+ />
224
+
225
+ <Select
226
+ className="mb-4"
227
+ label="Image layout"
228
+ value={layout.mode}
229
+ options={[
230
+ { value: "grid", label: "Grid" },
231
+ { value: "masonry", label: "Masonry" },
232
+ ]}
233
+ onChange={(v) =>
234
+ onUpdateSection(
235
+ chunkId,
236
+ v === "grid"
237
+ ? { imageLayout: { mode: "grid", rows: 2, columns: 4 } }
238
+ : { imageLayout: { mode: "masonry", flow: "rows", columns: 3 } },
239
+ )
240
+ }
241
+ />
242
+
243
+ {layout.mode === "grid" ? (
244
+ <>
245
+ <Select
246
+ className="mb-4"
247
+ label="Rows"
248
+ value={String(layout.rows)}
249
+ options={[1, 2, 3].map((n) => ({ value: String(n), label: String(n) }))}
250
+ onChange={(v) => onUpdateSection(chunkId, { imageLayout: { ...layout, rows: Number(v) } })}
251
+ />
252
+ <Select
253
+ className="mb-4"
254
+ label="Columns"
255
+ value={String(layout.columns)}
256
+ options={[2, 3, 4].map((n) => ({ value: String(n), label: String(n) }))}
257
+ onChange={(v) => onUpdateSection(chunkId, { imageLayout: { ...layout, columns: Number(v) } })}
258
+ />
259
+ <Select
260
+ className="mb-4"
261
+ label="Image fit"
262
+ value={layout.fit}
263
+ options={[
264
+ { value: "cover", label: "Crop" },
265
+ { value: "contain", label: "Contain" },
266
+ ]}
267
+ onChange={(v) => onUpdateSection(chunkId, { imageLayout: { ...layout, fit: v } })}
268
+ />
269
+ </>
270
+ ) : (
271
+ <>
272
+ <Select
273
+ className="mb-4"
274
+ label="Flow"
275
+ value={layout.flow}
276
+ options={[
277
+ { value: "rows", label: "Rows" },
278
+ { value: "columns", label: "Columns" },
279
+ ]}
280
+ onChange={(v) => onUpdateSection(chunkId, { imageLayout: { ...layout, flow: v } })}
281
+ />
282
+ {/* Rows count only drives the rows flow; "auto" keeps the greedy
283
+ target-height fill. Mirrors Columns, which only drives columns. */}
284
+ {layout.flow === "rows" ? (
285
+ <Select
286
+ className="mb-4"
287
+ label="Rows"
288
+ value={String(layout.rows)}
289
+ options={[
290
+ { value: "auto", label: "Auto" },
291
+ ...[1, 2, 3, 4].map((n) => ({ value: String(n), label: String(n) })),
292
+ ]}
293
+ onChange={(v) =>
294
+ onUpdateSection(chunkId, { imageLayout: { ...layout, rows: v === "auto" ? "auto" : Number(v) } })
295
+ }
296
+ />
297
+ ) : null}
298
+ {/* Column count only drives the columns flow (layoutRows never reads
299
+ it) — hide it when irrelevant. */}
300
+ {layout.flow === "columns" ? (
301
+ <Select
302
+ className="mb-4"
303
+ label="Columns"
304
+ value={String(layout.columns)}
305
+ options={[2, 3, 4, 5, 6].map((n) => ({ value: String(n), label: String(n) }))}
306
+ onChange={(v) => onUpdateSection(chunkId, { imageLayout: { ...layout, columns: Number(v) } })}
307
+ />
308
+ ) : null}
309
+ </>
310
+ )}
311
+
312
+ {warnings.length > 0 ? (
313
+ <div className="mt-2">
314
+ {warnings.map((w, i) => (
315
+ <p key={i} className="mb-1 rounded border border-amber-300 bg-amber-50 px-2 py-1 text-xs text-amber-800">
316
+ {w}
317
+ </p>
318
+ ))}
319
+ </div>
320
+ ) : null}
321
+ </>
322
+ );
323
+ }
@@ -0,0 +1,169 @@
1
+ import { useCallback, useEffect, useMemo, useState } from "react";
2
+ import type { Page } from "../../schemas/site-config";
3
+ import type { MediaManifest } from "../../media/types";
4
+ import type { LoadedSection } from "../../lib/loader";
5
+ import {
6
+ DocViewer,
7
+ documentOptionsSchema,
8
+ sectionSettingsSchema,
9
+ settingsFor,
10
+ type Chunk,
11
+ type DocHost,
12
+ type DocumentOptions,
13
+ } from "../../document";
14
+ import { DocInspector, type DocInspectorProps } from "./DocInspector";
15
+ import { buildDraftDocumentInput } from "../../lib/document-input";
16
+ import { Button } from "../shared/Button";
17
+ // The sealed document stylesheet ships with its editor consumer (Task 6 decided
18
+ // the present route imports it from its island; this is the editor's island).
19
+ // Vitest stubs CSS imports, so it stays out of the jsdom test graph regardless.
20
+ import "../../document/styles/document.css";
21
+
22
+ export interface DocumentEditorOverlayProps {
23
+ /** The active page — its `document` block must be enabled for the FAB to mount. */
24
+ page: Page;
25
+ /**
26
+ * The page's draft sections, in `page.order` order. The overlay drops
27
+ * archived ones itself — /present renders only live sections, so a chunk the
28
+ * published document will never show must not influence the proofed layout.
29
+ */
30
+ sections: LoadedSection[];
31
+ manifest: MediaManifest;
32
+ /** Wired by the shell to `setPageDocument` + the local-changes dirty flag. */
33
+ onUpdateDocument: (patch: Partial<DocumentOptions>) => void;
34
+ onClose: () => void;
35
+ }
36
+
37
+ /**
38
+ * Full-viewport editing surface: DocViewer (edit mode, ghosts + selection) on
39
+ * the left, DocInspector (settings for the current selection) on the right.
40
+ *
41
+ * The engine input is rebuilt from the live draft (page + in-memory sections +
42
+ * manifest) on every prop change, so unsaved edits repaginate immediately —
43
+ * the pagination hook's stale-heights guard absorbs the shape changes.
44
+ */
45
+ export function DocumentEditorOverlay({
46
+ page,
47
+ sections,
48
+ manifest,
49
+ onUpdateDocument,
50
+ onClose,
51
+ }: DocumentEditorOverlayProps) {
52
+ // page.document is optional on the type; the caller only mounts this when it
53
+ // is enabled, but parse-with-defaults keeps us total either way.
54
+ const doc = useMemo(() => documentOptionsSchema.parse(page.document ?? {}), [page.document]);
55
+
56
+ const source = useMemo(
57
+ () =>
58
+ buildDraftDocumentInput({
59
+ page,
60
+ sections: sections.filter((s) => s.meta.status !== "archived"),
61
+ manifest,
62
+ }),
63
+ [page, sections, manifest],
64
+ );
65
+
66
+ // Titles (for the inspector header) + per-chunk warnings come straight from
67
+ // DocViewer's single pagination pass via onDocState — no second useDocPages.
68
+ const [docState, setDocState] = useState<{ chunks: Chunk[]; warningsByChunk: Record<string, string[]> }>({
69
+ chunks: [],
70
+ warningsByChunk: {},
71
+ });
72
+ const { chunks, warningsByChunk } = docState;
73
+
74
+ // null = cover selected.
75
+ const [selectedChunkId, setSelectedChunkId] = useState<string | null>(null);
76
+
77
+ // All media bytes come from /api/media (draft branch bytes are served to
78
+ // editor sessions) — the same host shape the present route uses.
79
+ const host: DocHost = useMemo(
80
+ () => ({
81
+ variant: "preview",
82
+ imageSrc: (image, variant) =>
83
+ `/api/media/${image.imageId}/${variant === "print" ? image.printFile : image.previewFile}`,
84
+ }),
85
+ [],
86
+ );
87
+
88
+ // Escape closes (the close button is the other exit). DocViewer owns arrow
89
+ // paging on its own window listener; Escape doesn't collide with it. An
90
+ // Escape aimed at an inspector control is the cancel-the-field gesture, not
91
+ // "leave the editor": text fields blur (so the next Escape closes), and a
92
+ // select is left alone entirely — the browser uses Escape to dismiss its
93
+ // popup and there's no way to tell whether one is open.
94
+ useEffect(() => {
95
+ const onKey = (e: KeyboardEvent) => {
96
+ if (e.key !== "Escape") return;
97
+ const t = e.target as HTMLElement | null;
98
+ if (t && (t.tagName === "INPUT" || t.tagName === "TEXTAREA" || t.isContentEditable)) {
99
+ t.blur();
100
+ return;
101
+ }
102
+ if (t && t.tagName === "SELECT") return;
103
+ e.preventDefault();
104
+ onClose();
105
+ };
106
+ window.addEventListener("keydown", onKey);
107
+ return () => window.removeEventListener("keydown", onKey);
108
+ }, [onClose]);
109
+
110
+ const selection: DocInspectorProps["selection"] = useMemo(() => {
111
+ if (selectedChunkId === null) return { kind: "cover" };
112
+ const chunk = chunks.find((c) => c.id === selectedChunkId);
113
+ return { kind: "chunk", chunkId: selectedChunkId, title: chunk?.title ?? selectedChunkId, depth: chunk?.depth };
114
+ }, [selectedChunkId, chunks]);
115
+
116
+ const warnings = selectedChunkId ? warningsByChunk[selectedChunkId] ?? [] : [];
117
+
118
+ // Merge the inspector's partial patch onto the chunk's CURRENT settings and
119
+ // ship the whole validated block — setPageDocument merges sections shallowly
120
+ // by key, so we must hand it a complete SectionSettings, not a fragment.
121
+ const handleUpdateSection = useCallback(
122
+ (chunkId: string, patch: Record<string, unknown>) => {
123
+ const merged = sectionSettingsSchema.parse({ ...settingsFor(doc.sections, chunkId), ...patch });
124
+ onUpdateDocument({ sections: { [chunkId]: merged } });
125
+ },
126
+ [doc.sections, onUpdateDocument],
127
+ );
128
+
129
+ // Cover/meta are single objects on the document; merge onto the current value
130
+ // so a one-field edit doesn't blank the siblings before setPageDocument runs.
131
+ const handleUpdateCover = useCallback(
132
+ (patch: Partial<DocumentOptions["cover"]>) => onUpdateDocument({ cover: { ...doc.cover, ...patch } }),
133
+ [doc.cover, onUpdateDocument],
134
+ );
135
+ const handleUpdateMeta = useCallback(
136
+ (patch: Partial<DocumentOptions["meta"]>) => onUpdateDocument({ meta: { ...doc.meta, ...patch } }),
137
+ [doc.meta, onUpdateDocument],
138
+ );
139
+
140
+ return (
141
+ <div className="fixed inset-0 z-50 flex flex-col bg-base" role="dialog" aria-modal="true" aria-label="Document editor">
142
+ <div className="flex items-center justify-between border-b border-base-200 bg-base px-4 py-2">
143
+ <span className="text-sm font-medium text-base-contrast">Document · {page.title}</span>
144
+ <Button variant="secondary" size="sm" aria-label="Close document editor" onClick={onClose}>
145
+ Close
146
+ </Button>
147
+ </div>
148
+ <div className="flex min-h-0 flex-1">
149
+ <DocViewer
150
+ source={source}
151
+ document={doc}
152
+ host={host}
153
+ mode="edit"
154
+ selectedChunkId={selectedChunkId}
155
+ onSelectChunk={setSelectedChunkId}
156
+ onDocState={setDocState}
157
+ />
158
+ <DocInspector
159
+ document={doc}
160
+ selection={selection}
161
+ warnings={warnings}
162
+ onUpdateCover={handleUpdateCover}
163
+ onUpdateMeta={handleUpdateMeta}
164
+ onUpdateSection={handleUpdateSection}
165
+ />
166
+ </div>
167
+ </div>
168
+ );
169
+ }
@@ -0,0 +1,87 @@
1
+ import { useEffect, useMemo } from "react";
2
+ import type { Page } from "../../schemas/site-config";
3
+ import type { MediaManifest } from "../../media/types";
4
+ import type { LoadedSection } from "../../lib/loader";
5
+ import { DocViewer, documentOptionsSchema, type DocHost } from "../../document";
6
+ import { buildDraftDocumentInput } from "../../lib/document-input";
7
+ // Same sealed document stylesheet the editor overlay ships (see
8
+ // DocumentEditorOverlay). Vitest stubs CSS imports, so it stays out of the jsdom
9
+ // test graph regardless.
10
+ import "../../document/styles/document.css";
11
+
12
+ export interface DocumentPresentOverlayProps {
13
+ /** The active page — its `document` block supplies cover/meta/section settings. */
14
+ page: Page;
15
+ /**
16
+ * The sections currently on the canvas (already page-ordered and filtered to
17
+ * the branch being previewed). The shell derives these from the same
18
+ * `computeDisplaySections` call the history/branch canvas renders.
19
+ */
20
+ sections: LoadedSection[];
21
+ manifest: MediaManifest;
22
+ onClose: () => void;
23
+ }
24
+
25
+ /**
26
+ * Read-only, full-viewport document PRESENTATION of the content currently being
27
+ * viewed — used when the shell is previewing a non-draft version (the published
28
+ * branch). It is `DocViewer` in `present` mode: no inspector, no update path.
29
+ *
30
+ * Product decision (Drew): history/branch views are the record — we present them
31
+ * but never open the editor over them. Document SETTINGS come from the current
32
+ * draft's `page.document`; the previewed branch's own document index is not
33
+ * carried in the shell's `viewSections`, so cover/meta/exclusions here reflect
34
+ * the draft, not the historical commit. This is an accepted approximation: we
35
+ * are rendering historical *content* with the draft's presentation settings.
36
+ */
37
+ export function DocumentPresentOverlay({
38
+ page,
39
+ sections,
40
+ manifest,
41
+ onClose,
42
+ }: DocumentPresentOverlayProps) {
43
+ // page.document is optional on the type; the caller only mounts this when it
44
+ // is enabled, but parse-with-defaults keeps us total either way.
45
+ const doc = useMemo(() => documentOptionsSchema.parse(page.document ?? {}), [page.document]);
46
+
47
+ const source = useMemo(
48
+ () => buildDraftDocumentInput({ page, sections, manifest }),
49
+ [page, sections, manifest],
50
+ );
51
+
52
+ // All media bytes come from /api/media — the same host shape the present route
53
+ // and the editor overlay use.
54
+ const host: DocHost = useMemo(
55
+ () => ({
56
+ variant: "preview",
57
+ imageSrc: (image, variant) =>
58
+ `/api/media/${image.imageId}/${variant === "print" ? image.printFile : image.previewFile}`,
59
+ }),
60
+ [],
61
+ );
62
+
63
+ // Escape closes, matching the editor overlay. DocViewer owns arrow paging on
64
+ // its own window listener; Escape doesn't collide with it.
65
+ useEffect(() => {
66
+ const onKey = (e: KeyboardEvent) => {
67
+ if (e.key !== "Escape") return;
68
+ e.preventDefault();
69
+ onClose();
70
+ };
71
+ window.addEventListener("keydown", onKey);
72
+ return () => window.removeEventListener("keydown", onKey);
73
+ }, [onClose]);
74
+
75
+ return (
76
+ <div
77
+ className="fixed inset-0 z-50 flex flex-col bg-base"
78
+ role="dialog"
79
+ aria-modal="true"
80
+ aria-label="Document presentation"
81
+ >
82
+ <div className="flex min-h-0 flex-1">
83
+ <DocViewer source={source} document={doc} host={host} mode="present" onClose={onClose} />
84
+ </div>
85
+ </div>
86
+ );
87
+ }