@perkyzz/emvb 0.7.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 (97) hide show
  1. package/README.md +3 -3
  2. package/THIRD_PARTY_NOTICES.md +1 -1
  3. package/package.json +7 -7
  4. package/src/admin/editor/DialogCloseButton.tsx +16 -0
  5. package/src/admin/editor/Editor.tsx +71 -1
  6. package/src/admin/editor/FieldPreview.tsx +164 -0
  7. package/src/admin/editor/PerfMeter.tsx +3 -9
  8. package/src/admin/editor/SavedSectionDialogs.tsx +169 -0
  9. package/src/admin/editor/ShareLink.tsx +2 -7
  10. package/src/admin/editor/ShortcutsDialog.tsx +19 -11
  11. package/src/admin/editor/Timeline.tsx +2 -7
  12. package/src/admin/editor/TopBar.tsx +32 -1
  13. package/src/admin/editor/dialogs.tsx +3 -14
  14. package/src/admin/editor/editor-chrome.tsx +8 -24
  15. package/src/admin/editor/editor-commands.ts +15 -1
  16. package/src/admin/editor/editor-css.ts +6 -2
  17. package/src/admin/editor/feature-css.ts +11 -1
  18. package/src/admin/editor/focus-when-lost.ts +23 -0
  19. package/src/admin/editor/host.ts +6 -0
  20. package/src/admin/editor/icons/IconLibraryDialog.tsx +2 -7
  21. package/src/admin/editor/palette-items.ts +17 -0
  22. package/src/admin/editor/panels/AddPanel.tsx +9 -1
  23. package/src/admin/editor/panels/ElementPanel.tsx +4 -1
  24. package/src/admin/editor/panels/LayersPanel.tsx +6 -1
  25. package/src/admin/editor/panels/LeftPanel.tsx +9 -1
  26. package/src/admin/editor/panels/SavedSectionsGroup.tsx +246 -0
  27. package/src/admin/editor/panels/SiteStylesDrawer.tsx +54 -10
  28. package/src/admin/editor/panels/TokenScales.tsx +16 -16
  29. package/src/admin/editor/panels/TriggersEditor.tsx +1 -1
  30. package/src/admin/editor/panels/color-space.ts +14 -26
  31. package/src/admin/editor/panels/settings/AudienceEditor.tsx +36 -39
  32. package/src/admin/editor/panels/settings/BackgroundControls.tsx +4 -5
  33. package/src/admin/editor/panels/settings/IconControls.tsx +21 -5
  34. package/src/admin/editor/panels/settings/LoopItemBindControl.tsx +1 -1
  35. package/src/admin/editor/panels/settings/MediaPicker.tsx +5 -5
  36. package/src/admin/editor/panels/settings/length-units.ts +2 -1
  37. package/src/admin/editor/shortcuts.ts +14 -0
  38. package/src/admin/editor/useSavedSections.ts +197 -0
  39. package/src/admin/image-editor/Canvas.tsx +61 -17
  40. package/src/admin/image-editor/ImageEditorDialog.tsx +130 -1
  41. package/src/admin/image-editor/image-editor-css.ts +11 -8
  42. package/src/admin/image-editor/parts.tsx +18 -17
  43. package/src/admin/image-editor/save.ts +31 -1
  44. package/src/admin/index.tsx +5 -1
  45. package/src/admin/media-api.ts +27 -0
  46. package/src/admin/pages/AgentsPage.tsx +3 -3
  47. package/src/admin/pages/CollectionsPage.tsx +215 -0
  48. package/src/admin/pages/ThemePartList.tsx +32 -4
  49. package/src/admin/saved-sections-api.ts +51 -0
  50. package/src/admin/setup/host-collections.ts +100 -0
  51. package/src/admin/theme-api.ts +3 -2
  52. package/src/admin/ui.ts +9 -0
  53. package/src/admin/widgets/CanvasField.tsx +202 -0
  54. package/src/admin/widgets/convert-body.ts +54 -0
  55. package/src/admin/widgets/field-fetcher.ts +79 -0
  56. package/src/astro/index.ts +2 -0
  57. package/src/astro/page-count.ts +77 -0
  58. package/src/astro/popups/runtime.ts +8 -6
  59. package/src/astro/resolve-theme.ts +44 -2
  60. package/src/astro/resolve.ts +40 -4
  61. package/src/astro/responsive-images.ts +99 -0
  62. package/src/constants.ts +1 -1
  63. package/src/core/a11y/audit.ts +32 -7
  64. package/src/core/arrange.ts +21 -6
  65. package/src/core/canvas-collections.ts +20 -0
  66. package/src/core/css/print.ts +5 -0
  67. package/src/core/design/classes.ts +23 -9
  68. package/src/core/design/devices.ts +7 -13
  69. package/src/core/design/states.ts +7 -13
  70. package/src/core/elements/dynamic-elements.ts +27 -12
  71. package/src/core/elements/index.ts +1 -1
  72. package/src/core/elements/menu.ts +3 -0
  73. package/src/core/icons/animation-runs.ts +11 -0
  74. package/src/core/index.ts +22 -0
  75. package/src/core/migrate/index.ts +3 -0
  76. package/src/core/portable-text.ts +127 -0
  77. package/src/core/render/loop.ts +1 -1
  78. package/src/core/render/pagination.ts +20 -1
  79. package/src/core/sanitize/css.ts +14 -6
  80. package/src/core/saved-sections.ts +318 -0
  81. package/src/core/schema/design.ts +1 -1
  82. package/src/core/schema/layout.ts +6 -1
  83. package/src/core/schema/style.ts +4 -2
  84. package/src/core/theme/float.ts +3 -0
  85. package/src/core/theme/pagination.ts +34 -24
  86. package/src/core/theme/part-types.ts +4 -4
  87. package/src/index.ts +11 -1
  88. package/src/mcp/ports.ts +22 -1
  89. package/src/mcp/read.ts +1 -1
  90. package/src/mcp/sections.ts +183 -0
  91. package/src/mcp/tools.ts +44 -0
  92. package/src/mcp/write.ts +4 -4
  93. package/src/server/agent-settings.ts +16 -1
  94. package/src/server/hooks.ts +81 -0
  95. package/src/server/mcp-routes.ts +2 -0
  96. package/src/server/plugin.ts +34 -5
  97. package/src/server/saved-sections.ts +163 -0
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.2. 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
 
@@ -16,7 +16,7 @@ Library pictures can be cropped, adjusted, filtered and saved as a new media ite
16
16
  npm i @perkyzz/emvb
17
17
  ```
18
18
 
19
- Peers, which an EmDash 1.x site already has: `emdash` ^1.0.0, `astro` ^7, `react` and `react-dom` ^19, `@cloudflare/kumo` 2.6.0 and `@phosphor-icons/react` ^2.1.10. `@emdash-cms/plugin-forms` ^0.2.9 is optional and enables forms.
19
+ Peers, which an EmDash 1.x site already has: `emdash` ^1.0.0, `astro` ^7, `react` and `react-dom` ^19, `@cloudflare/kumo` 2.6.0 and `@phosphor-icons/react` ^2.1.10. `@emdash-cms/plugin-forms` ^0.2.9 is optional and enables forms. EmVB currently supports Astro 7 up to 7.3.5: Astro 7.3.6 and later depend on zod ^4.6.5, while EmDash pins zod to exactly 4.5.4, and the second copy of zod breaks type checking of EmDash plugin routes. Keep your site on `astro` 7.3.5 for now; this will be widened once EmDash moves its zod pin.
20
20
 
21
21
  Dependencies installed with it: `zod` and [`@perkyzz/emvb-icons`](https://www.npmjs.com/package/@perkyzz/emvb-icons), the icon sets for the editor's Icon library. Only the editor loads them; a placed icon is saved into the page as SVG.
22
22
 
@@ -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
 
@@ -10,7 +10,7 @@ When an editor picks an icon, its SVG is stored with the page and shown inline o
10
10
 
11
11
  ## Lucide
12
12
 
13
- - Package: `lucide-static` 1.52.0, <https://lucide.dev>
13
+ - Package: `lucide-static` 1.61.0, <https://lucide.dev>
14
14
  - License: ISC, Copyright (c) 2026 Lucide Icons and Contributors. Icons derived from Feather: MIT, Copyright (c) 2013-present Cole Bemis. Full text: [`licenses/lucide-static.LICENSE`](licenses/lucide-static.LICENSE).
15
15
  - The 26 icons EmVB bundled before the library (`src/core/icons/catalog.ts`) are also Lucide icons, under the same license.
16
16
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@perkyzz/emvb",
3
- "version": "0.7.0",
3
+ "version": "0.9.0",
4
4
  "description": "Visual page builder plugin for EmDash CMS",
5
5
  "keywords": [
6
6
  "astro",
@@ -49,21 +49,21 @@
49
49
  "test:astro": "bun --bun vitest run"
50
50
  },
51
51
  "dependencies": {
52
- "@perkyzz/emvb-icons": "0.1.1",
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.9",
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.2.0",
64
- "react": "19.3.0",
65
- "react-dom": "19.3.0",
66
- "vitest": "5.0.2"
63
+ "emdash": "1.4.0",
64
+ "react": "19.3.1",
65
+ "react-dom": "19.3.1",
66
+ "vitest": "5.0.5"
67
67
  },
68
68
  "peerDependencies": {
69
69
  "@cloudflare/kumo": "2.6.0",
@@ -0,0 +1,16 @@
1
+ import { Button, Dialog } from "@cloudflare/kumo";
2
+ import type * as React from "react";
3
+ import { BUTTON } from "../ui.ts";
4
+
5
+ /** The secondary Close or Cancel button that closes a Kumo dialog (UX-009). */
6
+ export function DialogCloseButton({ children }: { children: React.ReactNode }) {
7
+ return (
8
+ <Dialog.Close
9
+ render={(props) => (
10
+ <Button {...props} variant="secondary" className={BUTTON}>
11
+ {children}
12
+ </Button>
13
+ )}
14
+ />
15
+ );
16
+ }
@@ -11,10 +11,12 @@ import {
11
11
  import * as React from "react";
12
12
  import {
13
13
  auditPage,
14
+ findNode,
14
15
  moveDown,
15
16
  moveUp,
16
17
  renderPage,
17
18
  withPlainText,
19
+ type Layout,
18
20
  type LayoutNode,
19
21
  type PopupDevice,
20
22
  } from "../../core/index.ts";
@@ -63,6 +65,9 @@ import { editableSource } from "../image-editor/load.ts";
63
65
  import { useSave } from "./useSave.ts";
64
66
  import { type ShortcutHandlers, useEditorShortcuts } from "./useEditorShortcuts.ts";
65
67
  import { useNodeActions } from "./useNodeActions.ts";
68
+ import { useSavedSections } from "./useSavedSections.ts";
69
+ import { SaveSectionDialog } from "./SavedSectionDialogs.tsx";
70
+ import { FieldPreview, previewDocument, useInlinedStyles } from "./FieldPreview.tsx";
66
71
  import { type PasteRefusal, useClipboardActions } from "./useClipboardActions.ts";
67
72
  import { ListError, LoadingStatus } from "../pages/list-kit.tsx";
68
73
 
@@ -147,6 +152,7 @@ function EditorApp({
147
152
  const dirty = isDirty(state);
148
153
  const host = useEditorHost();
149
154
  const canvasStyles = useCanvasStyles(fetcher);
155
+ const inlinedStyles = useInlinedStyles(canvasStyles);
150
156
  const { exit } = host;
151
157
  const saver = useSave(fetcher, state, dispatch, collection);
152
158
  // W-466: tell the person when an agent (or anyone) changed the page while they were idle.
@@ -201,6 +207,16 @@ function EditorApp({
201
207
  addRecipe,
202
208
  items: itemActions,
203
209
  } = useNodeActions({ state, latest, dispatch, announce: setAnnouncement, toasts });
210
+ // W-876: My sections and Save as section (D-060).
211
+ const saved = useSavedSections({
212
+ fetcher,
213
+ latest,
214
+ dispatch,
215
+ changeDesign,
216
+ announce: setAnnouncement,
217
+ toasts,
218
+ });
219
+ const [saveAsk, setSaveAsk] = React.useState<string | null>(null);
204
220
  const [refusal, setRefusal] = React.useState<PasteRefusal | null>(null);
205
221
  const clipboard = useClipboardActions({
206
222
  latest,
@@ -276,6 +292,32 @@ function EditorApp({
276
292
  collections,
277
293
  ],
278
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
+ };
279
321
  const layoutIndex = React.useMemo(
280
322
  () => (state.page.layout ? indexLayout(state.page.layout) : undefined),
281
323
  [state.page.layout],
@@ -325,6 +367,7 @@ function EditorApp({
325
367
  !!selectedNode && !!state.page.layout && selectedNode.id !== state.page.layout.root.id;
326
368
  const commandRunners = {
327
369
  duplicate,
370
+ saveSection: setSaveAsk,
328
371
  remove,
329
372
  wrap,
330
373
  save: () => void save(),
@@ -408,12 +451,13 @@ function EditorApp({
408
451
  onExit={() => (dirty ? chrome.open("leave") : exit())}
409
452
  onShortcuts={() => chrome.open("shortcuts")}
410
453
  onSiteStyles={() => chrome.open("siteStyles")}
411
- onPreview={(size) => preview(size ?? device)}
454
+ onPreview={(size) => (host.field ? setFieldPreview(true) : preview(size ?? device))}
412
455
  onSave={() => void save()}
413
456
  onPublish={() => void publish()}
414
457
  stylesUnpublished={state.designUnpublished === true}
415
458
  canRevert={canRevert}
416
459
  onRevert={() => chrome.open("revert")}
460
+ {...(host.field ? { onApply: () => host.field?.apply(state.page.layout) } : {})}
417
461
  tools={
418
462
  <>
419
463
  {/* UX-084: undo and redo were keyboard-only; toasts already say "Undo takes it back". */}
@@ -487,6 +531,8 @@ function EditorApp({
487
531
  onMoveDown={(id) => arrange(id, moveDown)}
488
532
  onDelete={remove}
489
533
  clipboard={clipboard}
534
+ saved={saved}
535
+ onSaveSection={setSaveAsk}
490
536
  onRename={(id, label) =>
491
537
  dispatch({
492
538
  type: "update-node",
@@ -593,6 +639,23 @@ function EditorApp({
593
639
  finishDelete={finishDelete}
594
640
  playgroundUrl={host.playgroundUrl}
595
641
  setAnnouncement={setAnnouncement}
642
+ saved={saved}
643
+ />
644
+ {host.field && (
645
+ <FieldPreview
646
+ open={fieldPreview}
647
+ onOpenChange={setFieldPreview}
648
+ device={device}
649
+ render={renderFieldPreview}
650
+ />
651
+ )}
652
+ <SaveSectionDialog
653
+ open={saveAsk !== null}
654
+ onOpenChange={(open) => !open && setSaveAsk(null)}
655
+ defaultName={sectionNameFor(state.page.layout, saveAsk)}
656
+ onSave={(name, mode) =>
657
+ saveAsk ? saved.save(saveAsk, name, mode) : Promise.resolve(null)
658
+ }
596
659
  />
597
660
  </EditorToasts>
598
661
  </EditorOverlay>
@@ -661,3 +724,10 @@ function LoadBody({ data }: { data: EditorData }) {
661
724
  </div>
662
725
  );
663
726
  }
727
+
728
+ /** The Save as section name to start from: the layer's own name, else the element's (W-876). */
729
+ function sectionNameFor(layout: Layout | null, id: string | null): string {
730
+ const node = layout && id ? findNode(layout, id) : undefined;
731
+ if (!node) return "";
732
+ return node.label || (ELEMENT_NAMES[node.type] ?? "Section");
733
+ }
@@ -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
+ `;
@@ -1,4 +1,4 @@
1
- import { Button, Dialog } from "@cloudflare/kumo";
1
+ import { Dialog } from "@cloudflare/kumo";
2
2
  import * as React from "react";
3
3
  import {
4
4
  measurePage,
@@ -10,8 +10,8 @@ import {
10
10
  type ThemeDynamicData,
11
11
  } from "../../core/index.ts";
12
12
  import { ELEMENT_NAMES } from "./element-chrome.ts";
13
- import { BUTTON } from "../ui.ts";
14
13
  import { useEditedNoun } from "./edited-noun.ts";
14
+ import { DialogCloseButton } from "./DialogCloseButton.tsx";
15
15
 
16
16
  const KINDS: { kind: PerfKind; label: string }[] = [
17
17
  { kind: "html", label: "HTML" },
@@ -131,13 +131,7 @@ export function PerfMeterDialog({
131
131
  </>
132
132
  )}
133
133
  <div className="emvb-dialog-actions">
134
- <Dialog.Close
135
- render={(props) => (
136
- <Button {...props} variant="secondary" className={BUTTON}>
137
- Close
138
- </Button>
139
- )}
140
- />
134
+ <DialogCloseButton>Close</DialogCloseButton>
141
135
  </div>
142
136
  </div>
143
137
  </Dialog>
@@ -0,0 +1,169 @@
1
+ import { Button, Dialog, Input, Radio } from "@cloudflare/kumo";
2
+ import * as React from "react";
3
+ import { SAVED_SECTION_NAME_MAX } from "../../core/index.ts";
4
+ import { BUTTON, FIELD, SOLID_DESTRUCTIVE, SOLID_PRIMARY, UI_CSS } from "../ui.ts";
5
+ import { DialogCloseButton } from "./DialogCloseButton.tsx";
6
+ import { focusWhenLost } from "./focus-when-lost.ts";
7
+ import type { SaveMode } from "./useSavedSections.ts";
8
+
9
+ /**
10
+ * Save as section… (W-876, D-060): a name, and Copy (My sections, independent copies) or Synced
11
+ * (a Section theme part edited in one place). Stays open with the reason when the save fails.
12
+ */
13
+ export function SaveSectionDialog({
14
+ open,
15
+ onOpenChange,
16
+ defaultName,
17
+ onSave,
18
+ }: {
19
+ open: boolean;
20
+ onOpenChange: (open: boolean) => void;
21
+ defaultName: string;
22
+ onSave: (name: string, mode: SaveMode) => Promise<string | null>;
23
+ }) {
24
+ const [name, setName] = React.useState(defaultName);
25
+ const [mode, setMode] = React.useState<SaveMode>("copy");
26
+ const [error, setError] = React.useState<string | null>(null);
27
+ const [busy, setBusy] = React.useState(false);
28
+ // W-883: opened from a Layers row menu or the palette, the dialog has no opener left to give
29
+ // focus back to, so Escape or Cancel dropped it on the page body.
30
+ const wasOpen = React.useRef(open);
31
+ React.useEffect(() => {
32
+ const was = wasOpen.current;
33
+ wasOpen.current = open;
34
+ return was && !open ? focusWhenLost() : undefined;
35
+ }, [open]);
36
+ React.useEffect(() => {
37
+ if (!open) return;
38
+ setName(defaultName);
39
+ setMode("copy");
40
+ setError(null);
41
+ }, [open, defaultName]);
42
+ const submit = async () => {
43
+ if (busy) return;
44
+ if (!name.trim()) {
45
+ setError("Give the section a name.");
46
+ return;
47
+ }
48
+ setBusy(true);
49
+ const failed = await onSave(name, mode);
50
+ setBusy(false);
51
+ if (failed) setError(failed);
52
+ else onOpenChange(false);
53
+ };
54
+ return (
55
+ <Dialog.Root open={open} onOpenChange={(next) => (!busy || next) && onOpenChange(next)}>
56
+ <Dialog size="base" className="p-6">
57
+ <style>{UI_CSS}</style>
58
+ <form
59
+ data-emvb-dialog="save-section"
60
+ className="emvb-dialog"
61
+ onSubmit={(event) => {
62
+ event.preventDefault();
63
+ void submit();
64
+ }}
65
+ >
66
+ <Dialog.Title>Save as section</Dialog.Title>
67
+ <Dialog.Description>
68
+ Reuse this element and everything inside it on any page.
69
+ </Dialog.Description>
70
+ <Input
71
+ label="Name"
72
+ className={FIELD}
73
+ autoFocus
74
+ readOnly={busy}
75
+ maxLength={SAVED_SECTION_NAME_MAX}
76
+ value={name}
77
+ aria-invalid={error ? true : undefined}
78
+ error={error ?? undefined}
79
+ onChange={(event) => {
80
+ setName(event.target.value);
81
+ setError(null);
82
+ }}
83
+ />
84
+ <Radio.Group
85
+ legend="Kind"
86
+ appearance="card"
87
+ value={mode}
88
+ onValueChange={(value) => setMode(value as SaveMode)}
89
+ disabled={busy}
90
+ className="emvb-save-kind"
91
+ >
92
+ <Radio.Item
93
+ value="copy"
94
+ label="Copy"
95
+ description="Adds to My sections. Each insert is its own copy you edit on that page."
96
+ />
97
+ <Radio.Item
98
+ value="synced"
99
+ label="Synced"
100
+ description="Makes a Section theme part. Edit it once in Theme Builder and every page that uses it changes."
101
+ />
102
+ </Radio.Group>
103
+ <p className="emvb-sr-only" role="status" aria-live="polite">
104
+ {busy ? "Saving section…" : ""}
105
+ </p>
106
+ <div className="emvb-dialog-actions">
107
+ <DialogCloseButton>Cancel</DialogCloseButton>
108
+ <Button
109
+ type="submit"
110
+ variant="primary"
111
+ className={BUTTON}
112
+ style={SOLID_PRIMARY}
113
+ aria-disabled={busy || undefined}
114
+ data-emvb-save-section-submit=""
115
+ >
116
+ {mode === "synced" ? "Make synced section" : "Save section"}
117
+ </Button>
118
+ </div>
119
+ </form>
120
+ </Dialog>
121
+ </Dialog.Root>
122
+ );
123
+ }
124
+
125
+ /** Delete from My sections, after a confirm. Pages that hold a copy keep it. */
126
+ export function DeleteSavedSectionDialog({
127
+ name,
128
+ onOpenChange,
129
+ onDelete,
130
+ onClosed,
131
+ }: {
132
+ /** The section to delete; null when closed. */
133
+ name: string | null;
134
+ onOpenChange: (open: boolean) => void;
135
+ onDelete: () => void;
136
+ /** Runs after the close animation, so the caller can move focus once the dialog has gone. */
137
+ onClosed: () => void;
138
+ }) {
139
+ return (
140
+ <Dialog.Root
141
+ open={name !== null}
142
+ onOpenChange={onOpenChange}
143
+ onOpenChangeComplete={(open) => {
144
+ if (!open) onClosed();
145
+ }}
146
+ >
147
+ <Dialog size="base" className="p-6">
148
+ <style>{UI_CSS}</style>
149
+ <div data-emvb-dialog="delete-saved-section" className="emvb-dialog">
150
+ <Dialog.Title>Delete “{name}”?</Dialog.Title>
151
+ <Dialog.Description>
152
+ It leaves My sections. Pages that already use a copy keep it.
153
+ </Dialog.Description>
154
+ <div className="emvb-dialog-actions">
155
+ <DialogCloseButton>Cancel</DialogCloseButton>
156
+ <Button
157
+ variant="destructive"
158
+ className={BUTTON}
159
+ style={SOLID_DESTRUCTIVE}
160
+ onClick={onDelete}
161
+ >
162
+ Delete section
163
+ </Button>
164
+ </div>
165
+ </div>
166
+ </Dialog>
167
+ </Dialog.Root>
168
+ );
169
+ }
@@ -9,6 +9,7 @@ import {
9
9
  type LayoutNode,
10
10
  } from "../../core/index.ts";
11
11
  import { BUTTON, FIELD } from "../ui.ts";
12
+ import { DialogCloseButton } from "./DialogCloseButton.tsx";
12
13
 
13
14
  const MEDIA_KEYS = ["src", "poster", "backgroundImage", "backgroundVideo"];
14
15
  const siteOnly = (value: unknown) =>
@@ -175,13 +176,7 @@ export function ShareLinkDialog({
175
176
  : "Copy didn't work here: select the link and copy it."}
176
177
  </span>
177
178
  )}
178
- <Dialog.Close
179
- render={(props) => (
180
- <Button {...props} variant="secondary" className={BUTTON}>
181
- Close
182
- </Button>
183
- )}
184
- />
179
+ <DialogCloseButton>Close</DialogCloseButton>
185
180
  <Button
186
181
  variant="primary"
187
182
  className={BUTTON}
@@ -1,6 +1,7 @@
1
- import { Button, Dialog } from "@cloudflare/kumo";
2
- import { SHORTCUTS } from "./shortcuts.ts";
3
- import { BUTTON } from "../ui.ts";
1
+ import * as React from "react";
2
+ import { Dialog } from "@cloudflare/kumo";
3
+ import { keyCombos, SHORTCUTS } from "./shortcuts.ts";
4
+ import { DialogCloseButton } from "./DialogCloseButton.tsx";
4
5
 
5
6
  export function ShortcutsDialog({
6
7
  open,
@@ -19,7 +20,20 @@ export function ShortcutsDialog({
19
20
  {SHORTCUTS.map(({ action, keys }) => (
20
21
  <tr key={action}>
21
22
  <td>{action}</td>
22
- <td>{keys}</td>
23
+ {/* W-864: key boxes, as the command palette's tips; the text still reads "Ctrl/Cmd+K". */}
24
+ <td>
25
+ {keyCombos(keys).map(({ before, keys: combo }, i) => (
26
+ <React.Fragment key={i}>
27
+ {before}
28
+ {combo.map((key, k) => (
29
+ <React.Fragment key={k}>
30
+ {k > 0 ? "+" : null}
31
+ <kbd>{key}</kbd>
32
+ </React.Fragment>
33
+ ))}
34
+ </React.Fragment>
35
+ ))}
36
+ </td>
23
37
  </tr>
24
38
  ))}
25
39
  </tbody>
@@ -29,13 +43,7 @@ export function ShortcutsDialog({
29
43
  a dialog, only Ctrl/Cmd+S fires.
30
44
  </p>
31
45
  <div className="emvb-dialog-actions">
32
- <Dialog.Close
33
- render={(props) => (
34
- <Button {...props} variant="secondary" className={BUTTON}>
35
- Close
36
- </Button>
37
- )}
38
- />
46
+ <DialogCloseButton>Close</DialogCloseButton>
39
47
  </div>
40
48
  </div>
41
49
  </Dialog>