@perkyzz/emvb 0.8.0 → 0.9.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 (36) hide show
  1. package/README.md +2 -2
  2. package/package.json +4 -4
  3. package/src/admin/editor/Editor.tsx +38 -1
  4. package/src/admin/editor/FieldPreview.tsx +164 -0
  5. package/src/admin/editor/TopBar.tsx +32 -1
  6. package/src/admin/editor/editor-css.ts +3 -0
  7. package/src/admin/editor/host.ts +6 -0
  8. package/src/admin/editor/panels/ElementPanel.tsx +4 -1
  9. package/src/admin/editor/panels/settings/BackgroundControls.tsx +4 -5
  10. package/src/admin/editor/panels/settings/MediaPicker.tsx +5 -5
  11. package/src/admin/editor/panels/settings/length-units.ts +2 -1
  12. package/src/admin/index.tsx +5 -1
  13. package/src/admin/media-api.ts +27 -0
  14. package/src/admin/pages/AgentsPage.tsx +3 -3
  15. package/src/admin/pages/CollectionsPage.tsx +215 -0
  16. package/src/admin/setup/host-collections.ts +100 -0
  17. package/src/admin/widgets/CanvasField.tsx +202 -0
  18. package/src/admin/widgets/convert-body.ts +54 -0
  19. package/src/admin/widgets/field-fetcher.ts +79 -0
  20. package/src/astro/index.ts +2 -0
  21. package/src/astro/page-count.ts +77 -0
  22. package/src/astro/resolve-theme.ts +44 -2
  23. package/src/astro/resolve.ts +40 -4
  24. package/src/astro/responsive-images.ts +99 -0
  25. package/src/constants.ts +1 -1
  26. package/src/core/canvas-collections.ts +20 -0
  27. package/src/core/elements/dynamic-elements.ts +16 -1
  28. package/src/core/index.ts +2 -0
  29. package/src/core/portable-text.ts +127 -0
  30. package/src/core/render/pagination.ts +20 -1
  31. package/src/core/schema/layout.ts +5 -0
  32. package/src/core/theme/pagination.ts +9 -0
  33. package/src/index.ts +11 -1
  34. package/src/server/agent-settings.ts +16 -1
  35. package/src/server/hooks.ts +81 -0
  36. package/src/server/plugin.ts +20 -5
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [![Website](https://img.shields.io/badge/website-emvb.dev-1f6feb)](https://emvb.dev) [![npm](https://img.shields.io/npm/v/@perkyzz/emvb)](https://www.npmjs.com/package/@perkyzz/emvb)
4
4
 
5
- A visual page builder plugin for [EmDash CMS](https://github.com/emdash-cms/emdash) 1.0–1.3. Pages are built in a full-screen editor inside the EmDash admin and published as plain HTML and CSS. It runs on Node (SQLite) and Cloudflare Workers (D1).
5
+ A visual page builder plugin for [EmDash CMS](https://github.com/emdash-cms/emdash) 1.0–1.4 (built and tested on 1.4.0). Pages are built in a full-screen editor inside the EmDash admin and published as plain HTML and CSS. It runs on Node (SQLite) and Cloudflare Workers (D1).
6
6
 
7
7
  ![The EmVB editor](https://raw.githubusercontent.com/PerkyZZ999/EmVB/main/site/public/screenshots/editor-1600.webp)
8
8
 
@@ -67,7 +67,7 @@ Each runtime is a small script mounted only on pages that need it; the rest of t
67
67
 
68
68
  Without the forms plugin, import `EmVBFormsRuntime` from `@perkyzz/emvb/astro/forms` (it renders nothing and does not import the plugin) or leave the element out. The `/client` subpath is the one that calls `initForms`.
69
69
 
70
- A fixed route has no slug parameter. Pass the page's slug: `await resolveEmVBPage(Astro, { slug: "home" })`. Visitor rules can use the same call's `visitor` option (`{ segments: ["member"] }`, and country, device or returning when the site knows better); `resolveThemeParts` takes it too. The [install guide](https://github.com/PerkyZZ999/EmVB/blob/main/docs/guides/install-in-a-host-site.md) shows both, and the `canvasStyles` option that loads your site's stylesheets into the editor canvas: `emvb({ canvasStyles: ["/styles/site.css"] })`.
70
+ A fixed route has no slug parameter. Pass the page's slug: `await resolveEmVBPage(Astro, { slug: "home" })`. Visitor rules can use the same call's `visitor` option (`{ segments: ["member"] }`, and country, device or returning when the site knows better); `resolveThemeParts` takes it too. The [install guide](https://github.com/PerkyZZ999/EmVB/blob/main/docs/guides/install-in-a-host-site.md) shows both, and the `canvasStyles` option that loads your site's stylesheets into the editor canvas: `emvb({ canvasStyles: ["/styles/site.css"] })`. It also covers `canvasCollections`, which lets an `emvb:canvas` JSON field on your own collections hold an EmVB layout, edited in place with **Edit with EmVB** and rendered with `resolveEmVBPage(Astro, { collection: "pages", field: "canvas" })`.
71
71
 
72
72
  Then sign in as an admin, open **Pages VisualBuilder** and click **Set up EmVB** once.
73
73
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@perkyzz/emvb",
3
- "version": "0.8.0",
3
+ "version": "0.9.0",
4
4
  "description": "Visual page builder plugin for EmDash CMS",
5
5
  "keywords": [
6
6
  "astro",
@@ -49,18 +49,18 @@
49
49
  "test:astro": "bun --bun vitest run"
50
50
  },
51
51
  "dependencies": {
52
- "@perkyzz/emvb-icons": "0.2.0",
52
+ "@perkyzz/emvb-icons": "0.9.0",
53
53
  "photocn": "0.1.2",
54
54
  "zod": "~4.5.4"
55
55
  },
56
56
  "devDependencies": {
57
57
  "@cloudflare/kumo": "2.6.0",
58
- "@emdash-cms/plugin-forms": "0.2.11",
58
+ "@emdash-cms/plugin-forms": "0.2.12",
59
59
  "@phosphor-icons/react": "2.1.10",
60
60
  "@types/react": "19.3.0",
61
61
  "@types/react-dom": "19.3.0",
62
62
  "astro": "7.3.5",
63
- "emdash": "1.3.1",
63
+ "emdash": "1.4.0",
64
64
  "react": "19.3.1",
65
65
  "react-dom": "19.3.1",
66
66
  "vitest": "5.0.5"
@@ -67,6 +67,7 @@ import { type ShortcutHandlers, useEditorShortcuts } from "./useEditorShortcuts.
67
67
  import { useNodeActions } from "./useNodeActions.ts";
68
68
  import { useSavedSections } from "./useSavedSections.ts";
69
69
  import { SaveSectionDialog } from "./SavedSectionDialogs.tsx";
70
+ import { FieldPreview, previewDocument, useInlinedStyles } from "./FieldPreview.tsx";
70
71
  import { type PasteRefusal, useClipboardActions } from "./useClipboardActions.ts";
71
72
  import { ListError, LoadingStatus } from "../pages/list-kit.tsx";
72
73
 
@@ -151,6 +152,7 @@ function EditorApp({
151
152
  const dirty = isDirty(state);
152
153
  const host = useEditorHost();
153
154
  const canvasStyles = useCanvasStyles(fetcher);
155
+ const inlinedStyles = useInlinedStyles(canvasStyles);
154
156
  const { exit } = host;
155
157
  const saver = useSave(fetcher, state, dispatch, collection);
156
158
  // W-466: tell the person when an agent (or anyone) changed the page while they were idle.
@@ -290,6 +292,32 @@ function EditorApp({
290
292
  collections,
291
293
  ],
292
294
  );
295
+ // W-911: field mode previews the unsaved layout with the public renderer, in a sandboxed frame.
296
+ const [fieldPreview, setFieldPreview] = React.useState(false);
297
+ const renderFieldPreview = (previewDevice: PopupDevice): string | null => {
298
+ if (!state.page.layout) return null;
299
+ const result = renderPage(state.page.layout, state.design, {
300
+ mode: "public",
301
+ scope: state.id,
302
+ dynamic: {
303
+ ...(Object.keys(sectionTemplates).length > 0 ? { sectionTemplates } : {}),
304
+ ...(Object.keys(loopTemplates).length > 0 ? { loopTemplates } : {}),
305
+ site: live.site,
306
+ params: live.params,
307
+ ...(siteOrigin() ? { origin: siteOrigin() } : {}),
308
+ collections,
309
+ },
310
+ previewDevice,
311
+ });
312
+ return previewDocument({
313
+ html: result.html,
314
+ css: result.css,
315
+ canvasStyles,
316
+ inlined: inlinedStyles,
317
+ origin: window.location.origin,
318
+ ...(result.dir === "ltr" || result.dir === "rtl" ? { dir: result.dir } : {}),
319
+ });
320
+ };
293
321
  const layoutIndex = React.useMemo(
294
322
  () => (state.page.layout ? indexLayout(state.page.layout) : undefined),
295
323
  [state.page.layout],
@@ -423,12 +451,13 @@ function EditorApp({
423
451
  onExit={() => (dirty ? chrome.open("leave") : exit())}
424
452
  onShortcuts={() => chrome.open("shortcuts")}
425
453
  onSiteStyles={() => chrome.open("siteStyles")}
426
- onPreview={(size) => preview(size ?? device)}
454
+ onPreview={(size) => (host.field ? setFieldPreview(true) : preview(size ?? device))}
427
455
  onSave={() => void save()}
428
456
  onPublish={() => void publish()}
429
457
  stylesUnpublished={state.designUnpublished === true}
430
458
  canRevert={canRevert}
431
459
  onRevert={() => chrome.open("revert")}
460
+ {...(host.field ? { onApply: () => host.field?.apply(state.page.layout) } : {})}
432
461
  tools={
433
462
  <>
434
463
  {/* UX-084: undo and redo were keyboard-only; toasts already say "Undo takes it back". */}
@@ -612,6 +641,14 @@ function EditorApp({
612
641
  setAnnouncement={setAnnouncement}
613
642
  saved={saved}
614
643
  />
644
+ {host.field && (
645
+ <FieldPreview
646
+ open={fieldPreview}
647
+ onOpenChange={setFieldPreview}
648
+ device={device}
649
+ render={renderFieldPreview}
650
+ />
651
+ )}
615
652
  <SaveSectionDialog
616
653
  open={saveAsk !== null}
617
654
  onOpenChange={(open) => !open && setSaveAsk(null)}
@@ -0,0 +1,164 @@
1
+ import { Button, Dialog, Tabs } from "@cloudflare/kumo";
2
+ import * as React from "react";
3
+ import { DEVICE_PREVIEW_PX, POPUP_DEVICES, type PopupDevice } from "../../core/index.ts";
4
+ import { escapeAttr } from "../../core/sanitize/escape.ts";
5
+ import { BUTTON, UI_CSS } from "../ui.ts";
6
+
7
+ const DEVICE_NAMES: Record<PopupDevice, string> = {
8
+ desktop: "Desktop",
9
+ tablet: "Tablet",
10
+ mobile: "Mobile",
11
+ };
12
+
13
+ /**
14
+ * W-911: the page as the public renderer writes it, for a sandboxed `srcdoc` frame. The CSS is
15
+ * generated, but a `</style` in it would end the element early, so `<` is CSS-escaped.
16
+ */
17
+ export function previewDocument({
18
+ html,
19
+ css,
20
+ canvasStyles,
21
+ origin,
22
+ dir,
23
+ inlined = {},
24
+ }: {
25
+ html: string;
26
+ css: string;
27
+ canvasStyles: readonly string[];
28
+ origin: string;
29
+ dir?: "ltr" | "rtl";
30
+ /** W-920: stylesheet text by href, read by the editor; a sandboxed frame can't load them. */
31
+ inlined?: Readonly<Record<string, string>>;
32
+ }): string {
33
+ const links = canvasStyles
34
+ .map((href) =>
35
+ inlined[href] === undefined
36
+ ? `<link rel="stylesheet" href="${escapeAttr(href)}">`
37
+ : `<style>${cssText(inlined[href])}</style>`,
38
+ )
39
+ .join("");
40
+ return [
41
+ `<!doctype html><html${dir ? ` dir="${dir}"` : ""}><head><meta charset="utf-8">`,
42
+ `<base href="${escapeAttr(origin)}/">`,
43
+ `<style>html,body{margin:0}</style>`,
44
+ links,
45
+ `<style>${cssText(css)}</style></head><body>${html}</body></html>`,
46
+ ].join("");
47
+ }
48
+
49
+ /** `<` is CSS-escaped so a `</style` in the text can't end the element early. */
50
+ const cssText = (text: string) => text.replace(/</g, "\\3c ");
51
+
52
+ /**
53
+ * W-920: the frame is fully sandboxed (no origin), so dev servers and strict hosts refuse its
54
+ * stylesheet requests and the preview fell back to the browser's default type. Same-origin
55
+ * site stylesheets are read here and inlined; others keep their <link>.
56
+ */
57
+ export function useInlinedStyles(
58
+ hrefs: readonly string[],
59
+ load: (href: string) => Promise<string | null> = loadStyleText,
60
+ ): Readonly<Record<string, string>> {
61
+ const [texts, setTexts] = React.useState<Record<string, string>>({});
62
+ const key = hrefs.join("\n");
63
+ React.useEffect(() => {
64
+ let live = true;
65
+ void Promise.all(hrefs.map(async (href) => [href, await load(href)] as const)).then((pairs) => {
66
+ if (!live) return;
67
+ const next: Record<string, string> = {};
68
+ for (const [href, text] of pairs) if (text !== null) next[href] = text;
69
+ setTexts(next);
70
+ });
71
+ return () => {
72
+ live = false;
73
+ };
74
+ // oxlint-disable-next-line react-hooks/exhaustive-deps -- keyed on the list's contents.
75
+ }, [key, load]);
76
+ return texts;
77
+ }
78
+
79
+ async function loadStyleText(href: string): Promise<string | null> {
80
+ try {
81
+ const url = new URL(href, window.location.href);
82
+ if (url.origin !== window.location.origin) return null;
83
+ const response = await fetch(url, { credentials: "same-origin" });
84
+ if (!response.ok) return null;
85
+ return await response.text();
86
+ } catch {
87
+ return null;
88
+ }
89
+ }
90
+
91
+ /** W-911: field mode has no saved draft to preview, so the unsaved layout is shown here. */
92
+ export function FieldPreview({
93
+ open,
94
+ onOpenChange,
95
+ device: initialDevice,
96
+ render,
97
+ }: {
98
+ open: boolean;
99
+ onOpenChange: (open: boolean) => void;
100
+ device: PopupDevice;
101
+ /** Renders the current layout for a device as a full HTML document. */
102
+ render: (device: PopupDevice) => string | null;
103
+ }) {
104
+ const [device, setDevice] = React.useState<PopupDevice>(initialDevice);
105
+ React.useEffect(() => {
106
+ if (open) setDevice(initialDevice);
107
+ }, [open, initialDevice]);
108
+ const doc = open ? render(device) : null;
109
+ return (
110
+ <Dialog.Root open={open} onOpenChange={onOpenChange}>
111
+ <Dialog size="xl" className="emvb-field-preview p-4">
112
+ <style>{UI_CSS}</style>
113
+ <style>{PREVIEW_CSS}</style>
114
+ <div data-emvb-dialog="field-preview" className="emvb-dialog">
115
+ <div className="emvb-field-preview-head">
116
+ <div>
117
+ <Dialog.Title>Preview</Dialog.Title>
118
+ <Dialog.Description>
119
+ Your unsaved changes, as the site will show them. Apply, then save the entry, to
120
+ keep them.
121
+ </Dialog.Description>
122
+ </div>
123
+ <Tabs
124
+ variant="segmented"
125
+ size="sm"
126
+ className="emvb-device-tabs"
127
+ tabs={POPUP_DEVICES.map((item) => ({ value: item, label: DEVICE_NAMES[item] }))}
128
+ value={device}
129
+ onValueChange={(next) => {
130
+ if ((POPUP_DEVICES as readonly string[]).includes(next))
131
+ setDevice(next as PopupDevice);
132
+ }}
133
+ />
134
+ <Button variant="secondary" className={BUTTON} onClick={() => onOpenChange(false)}>
135
+ Back to editing
136
+ </Button>
137
+ </div>
138
+ <div className="emvb-field-preview-stage">
139
+ {doc === null ? (
140
+ <p className="emvb-helper">There is nothing to preview yet.</p>
141
+ ) : (
142
+ <iframe
143
+ title={`Preview (${DEVICE_NAMES[device]})`}
144
+ data-emvb-field-preview={device}
145
+ // No scripts and no same-origin access: the layout is untrusted (D-011).
146
+ sandbox=""
147
+ srcDoc={doc}
148
+ style={{ width: DEVICE_PREVIEW_PX[device] }}
149
+ />
150
+ )}
151
+ </div>
152
+ </div>
153
+ </Dialog>
154
+ </Dialog.Root>
155
+ );
156
+ }
157
+
158
+ const PREVIEW_CSS = `
159
+ .emvb-field-preview { width: min(1360px, 96vw); max-width: 96vw; }
160
+ .emvb-field-preview-head { display: flex; align-items: center; gap: 16px; justify-content: space-between; flex-wrap: wrap; }
161
+ .emvb-field-preview-head > div:first-child { flex: 1 1 280px; min-width: 0; }
162
+ .emvb-field-preview-stage { display: flex; overflow: auto; height: 72vh; margin-top: 12px; padding: 16px; box-sizing: border-box; border: 1px solid var(--color-kumo-line); border-radius: 8px; background: var(--color-kumo-recessed); }
163
+ .emvb-field-preview-stage iframe { flex: none; margin: 0 auto; max-width: none; height: 100%; border: 0; border-radius: 6px; background: #fff; box-shadow: 0 0 0 1px var(--color-kumo-line), 0 8px 24px rgb(0 0 0 / 0.18); }
164
+ `;
@@ -3,6 +3,8 @@ import * as React from "react";
3
3
  import {
4
4
  ArrowSquareOutIcon,
5
5
  CaretDownIcon,
6
+ CheckIcon,
7
+ EyeIcon,
6
8
  DesktopIcon,
7
9
  DeviceMobileIcon,
8
10
  DeviceTabletIcon,
@@ -79,6 +81,7 @@ export function TopBar({
79
81
  canRevert = false,
80
82
  onRevert,
81
83
  tools,
84
+ onApply,
82
85
  }: {
83
86
  page: TopBarPage | null;
84
87
  dirty: boolean;
@@ -99,6 +102,8 @@ export function TopBar({
99
102
  onRevert?: () => void;
100
103
  /** Extra tools beside Site styles: the page weight and accessibility meters, … (W-310). */
101
104
  tools?: React.ReactNode;
105
+ /** Field mode (W-900): one Apply button replaces Preview, Revert, Save draft and Publish. */
106
+ onApply?: () => void;
102
107
  }) {
103
108
  const reducedMotion = useMediaQuery("(prefers-reduced-motion: reduce)");
104
109
  // W-769: a disabled button drops focus to the page body, so the button that was focused when
@@ -186,7 +191,33 @@ export function TopBar({
186
191
  )}
187
192
  {page && tools}
188
193
  </div>
189
- {page && (
194
+ {page && onApply && (
195
+ // W-911: field mode previews in place; there is no saved draft for a new tab.
196
+ <Button
197
+ variant="secondary"
198
+ className={`${BUTTON} emvb-field-preview-button`}
199
+ icon={<EyeIcon aria-hidden="true" />}
200
+ onClick={() => onPreview()}
201
+ >
202
+ Preview
203
+ </Button>
204
+ )}
205
+ {page && onApply && (
206
+ <Button
207
+ variant="primary"
208
+ className={`${BUTTON} emvb-apply-button`}
209
+ style={SOLID_PRIMARY}
210
+ icon={<CheckIcon size={14} aria-hidden="true" />}
211
+ aria-disabled={busy !== null}
212
+ onClick={() => {
213
+ if (busy !== null) return;
214
+ onApply();
215
+ }}
216
+ >
217
+ Apply
218
+ </Button>
219
+ )}
220
+ {page && !onApply && (
190
221
  <div
191
222
  className="emvb-topbar-actions"
192
223
  style={{
@@ -199,6 +199,9 @@ export const EDITOR_CSS = `${UI_CSS}
199
199
  /* W-244: an unselected segmented option (Desktop | Tablet | Mobile, Normal | Hover | Focus | Active) takes the
200
200
  default text colour: Kumo's subtle grey on the segmented track is 4.0:1. The raised white pill marks the selected one. */
201
201
  .emvb-device-tabs [role="tab"][aria-selected="false"], .emvb-state-tabs [role="tab"][aria-selected="false"] { color: var(--text-color-kumo-default); }
202
+ /* W-905: Kumo animates every property of the active-tab pill, so a light/dark switch faded it
203
+ through white under light text; only its movement should animate. */
204
+ .emvb-device-tabs [role="tablist"] > div, .emvb-state-tabs [role="tablist"] > div { transition-property: translate, transform, width, height, top, left, scale, opacity; }
202
205
  .emvb-device-label { display: inline-flex; align-items: center; gap: 6px; }
203
206
  .emvb-device-hide { display: inline-flex; align-items: center; gap: 6px; color: var(--text-color-kumo-default); font-size: 13px; }
204
207
  .emvb-stage { position: relative; display: flex; flex: 1 1 auto; justify-content: safe center; min-height: 0; width: 100%; overflow: hidden; }
@@ -1,3 +1,4 @@
1
+ import type { Layout } from "../../core/index.ts";
1
2
  import * as React from "react";
2
3
  import { PLUGIN_ID } from "../../constants.ts";
3
4
  import { canvasStyleUrls } from "../../core/canvas-styles.ts";
@@ -25,6 +26,11 @@ export type EditorHost = {
25
26
  * for the host's `emvb({ canvasStyles })`.
26
27
  */
27
28
  canvasStyles?: readonly string[];
29
+ /**
30
+ * Field mode (W-900): the editor edits a host entry's emvb:canvas field. Apply hands the layout
31
+ * back to the entry form instead of saving or publishing anything.
32
+ */
33
+ field?: { apply: (layout: Layout | null) => void };
28
34
  };
29
35
 
30
36
  const defaultEditorHost: EditorHost = {
@@ -325,6 +325,8 @@ const SHOWN_WHEN: Readonly<
325
325
  > = {
326
326
  "loop.columns": (props) => props["display"] === "grid" || props["display"] === "cards",
327
327
  "pagination.countText": (props) => props["showCount"] === true,
328
+ "pagination.lastText": (props) => props["showLast"] === true,
329
+ "pagination.lastLabel": (props) => props["showLast"] === true,
328
330
  // Post Link always links to its post, so its new-tab switch always applies.
329
331
  "post-link.newTab": () => true,
330
332
  // UX-075: each device's tracks show on that device, as Columns does (W-139).
@@ -688,7 +690,8 @@ function KnownElementPanel({
688
690
  if (cls || styleState !== "normal") return null;
689
691
  return section(
690
692
  id,
691
- (node.htmlId ? 1 : 0) + (node.attributes?.length ?? 0),
693
+ // W-914: a per-element direction counts as a set Advanced value too.
694
+ (node.htmlId ? 1 : 0) + (node.dir ? 1 : 0) + (node.attributes?.length ?? 0),
692
695
  <>
693
696
  <HtmlIdField node={node} layout={layout} onChange={onChange} />
694
697
  <DirectionField node={node} onChange={onChange} />
@@ -85,10 +85,6 @@ export function BackgroundImageControl({
85
85
  }
86
86
  }, [fetcher, setBusy]);
87
87
 
88
- React.useEffect(() => {
89
- if (open) void loadLibrary();
90
- }, [open, loadLibrary]);
91
-
92
88
  const applyUrl = (next: string) => {
93
89
  const safe = sanitizeMediaUrl(next);
94
90
  if (!safe || /[()\\\s"'`]/.test(safe)) {
@@ -138,7 +134,10 @@ export function BackgroundImageControl({
138
134
  type="button"
139
135
  className={BUTTON}
140
136
  onClick={() => {
141
- if (!busyRef.current) setOpen(true);
137
+ if (busyRef.current) return;
138
+ // W-906: load in the same update that opens it, so it never paints "No images yet." first.
139
+ setOpen(true);
140
+ void loadLibrary();
142
141
  }}
143
142
  aria-disabled={busy}
144
143
  ref={libraryOpenerRef}
@@ -103,10 +103,6 @@ export function MediaPicker({ node, fetcher, onChange, label = "Image", editable
103
103
  }
104
104
  }, [fetcher, setBusy]);
105
105
 
106
- React.useEffect(() => {
107
- if (open) void loadLibrary();
108
- }, [open, loadLibrary]);
109
-
110
106
  /** Focus Choose from library, or the URL field while the picker is busy (W-741). */
111
107
  const focusOpener = () => {
112
108
  const opener = libraryOpenerRef.current;
@@ -256,7 +252,11 @@ export function MediaPicker({ node, fetcher, onChange, label = "Image", editable
256
252
  type="button"
257
253
  className={BUTTON}
258
254
  onClick={() => {
259
- if (!busyRef.current) setOpen(true);
255
+ if (busyRef.current) return;
256
+ // W-906: load in the same update that opens it; loading from an effect painted the
257
+ // last result ("No images yet.") first, and closing then raced the real load.
258
+ setOpen(true);
259
+ void loadLibrary();
260
260
  }}
261
261
  aria-disabled={busy}
262
262
  ref={libraryOpenerRef}
@@ -20,7 +20,8 @@ const UNITS: Partial<Record<StyleKey, readonly UnitChoice[]>> = {
20
20
  right: BOX_AUTO,
21
21
  bottom: BOX_AUTO,
22
22
  left: BOX_AUTO,
23
- fontSize: ["px", "rem", "em", "%", "vw"],
23
+ // vh since W-910, for hero headings sized to the screen height.
24
+ fontSize: ["px", "rem", "em", "%", "vw", "vh"],
24
25
  // em first, so a typed 1.5 means 1.5 times the font size, not 1.5 px (W-125).
25
26
  lineHeight: ["em", "px", "rem", "%", "x"],
26
27
  letterSpacing: ["px", "rem", "em"],
@@ -4,19 +4,23 @@ import { defaultFetcher } from "./api.ts";
4
4
  import { EditorPage } from "./pages/EditorPage.tsx";
5
5
  import { PagesPage } from "./pages/PagesPage.tsx";
6
6
  import { AgentsPage } from "./pages/AgentsPage.tsx";
7
+ import { CollectionsPage } from "./pages/CollectionsPage.tsx";
7
8
  import { ThemeBuilderPage } from "./pages/ThemeBuilderPage.tsx";
9
+ import { CanvasField } from "./widgets/CanvasField.tsx";
8
10
  import { LayoutField } from "./widgets/LayoutField.tsx";
9
11
 
10
12
  if (typeof document !== "undefined") void installSidebarShim(document, defaultFetcher);
11
13
 
12
- /** `/pages`, `/theme` and `/agents` are declared; `/editor` renders by URL (D-024). */
14
+ /** `/pages`, `/theme`, `/agents` and `/collections` are declared; `/editor` renders by URL (D-024). */
13
15
  export const pages: PluginAdminExports["pages"] = {
14
16
  "/pages": PagesPage,
15
17
  "/theme": ThemeBuilderPage,
16
18
  "/agents": AgentsPage,
19
+ "/collections": CollectionsPage,
17
20
  "/editor": EditorPage,
18
21
  };
19
22
 
20
23
  export const fields: PluginAdminExports["fields"] = {
21
24
  layout: LayoutField,
25
+ canvas: CanvasField,
22
26
  };
@@ -12,6 +12,9 @@ export type MediaLibraryItem = {
12
12
  storageKey: string;
13
13
  status: string;
14
14
  url: string;
15
+ /** EmDash 1.4 library focal point, 0–1 (null or absent when unset). */
16
+ focalX?: number | null;
17
+ focalY?: number | null;
15
18
  };
16
19
 
17
20
  /** Shared EmDash media endpoint — same path on Node local and Cloudflare R2 (R-007). */
@@ -95,6 +98,29 @@ function fitImageSize(
95
98
  next.height = Math.max(1, Math.round(height * scale));
96
99
  }
97
100
 
101
+ const unitCoordinate = (value: unknown): value is number =>
102
+ typeof value === "number" && Number.isFinite(value) && value >= 0 && value <= 1;
103
+
104
+ /**
105
+ * W-915: EmDash 1.4 stores a focal point per library image (0–1). A newly picked picture takes it
106
+ * as the element's focal point (0–100 %); one the editor set on this same picture is kept.
107
+ */
108
+ function libraryFocal(
109
+ next: Record<string, unknown>,
110
+ current: Record<string, unknown>,
111
+ item: MediaLibraryItem,
112
+ ): void {
113
+ const samePicture = current.src === item.url;
114
+ if (samePicture && current.focalX !== undefined) return;
115
+ if (unitCoordinate(item.focalX) && unitCoordinate(item.focalY)) {
116
+ next.focalX = Math.round(item.focalX * 100);
117
+ next.focalY = Math.round(item.focalY * 100);
118
+ } else if (!samePicture) {
119
+ delete next.focalX;
120
+ delete next.focalY;
121
+ }
122
+ }
123
+
98
124
  /** Applies a library item onto an image node's props (id, URL, alt, dimensions). */
99
125
  export function propsFromMedia(
100
126
  current: Record<string, unknown>,
@@ -108,6 +134,7 @@ export function propsFromMedia(
108
134
  delete next.edit;
109
135
  }
110
136
  fitImageSize(next, item.width, item.height);
137
+ libraryFocal(next, current, item);
111
138
  const alt = current.alt;
112
139
  if ((!alt || alt === "Image") && item.alt) next.alt = item.alt;
113
140
  else if (!alt || alt === "Image") next.alt = item.filename.replace(/\.[^.]+$/, "") || "Image";
@@ -45,7 +45,7 @@ const remoteSnippet = (endpoint: string) =>
45
45
  JSON.stringify({ mcpServers: { emvb: { url: endpoint } } }, null, 2);
46
46
 
47
47
  /** A card's heading row: an icon tile, the title and one line on what the card is for (W-477). */
48
- function SectionHead({
48
+ export function SectionHead({
49
49
  id,
50
50
  icon: SectionIcon,
51
51
  title,
@@ -74,7 +74,7 @@ function SectionHead({
74
74
  * W-756: on a phone the setup JSON scrolls sideways, and keyboard users could not reach it to
75
75
  * scroll. Focusable, and named so a screen reader says what it is.
76
76
  */
77
- const SCROLLABLE = { tabIndex: 0, role: "group" } as const;
77
+ export const SCROLLABLE = { tabIndex: 0, role: "group" } as const;
78
78
 
79
79
  export function AgentsPage({ fetcher = defaultFetcher }: { fetcher?: Fetcher }) {
80
80
  const role = useRole(fetcher);
@@ -337,7 +337,7 @@ export function AgentsPage({ fetcher = defaultFetcher }: { fetcher?: Fetcher })
337
337
  }
338
338
 
339
339
  /** UX-089: the setup JSON is meant to be pasted into an agent's config, so it copies in one click. */
340
- function CopySnippet({ text, name }: { text: string; name: string }) {
340
+ export function CopySnippet({ text, name }: { text: string; name: string }) {
341
341
  const [copied, setCopied] = useState<"yes" | "no" | null>(null);
342
342
  useEffect(() => {
343
343
  // W-777: a failed copy stays until the next click; it vanished after 2 s.