@perkyzz/emvb 0.7.0 → 0.8.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 (71) hide show
  1. package/README.md +2 -2
  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 +33 -0
  6. package/src/admin/editor/PerfMeter.tsx +3 -9
  7. package/src/admin/editor/SavedSectionDialogs.tsx +169 -0
  8. package/src/admin/editor/ShareLink.tsx +2 -7
  9. package/src/admin/editor/ShortcutsDialog.tsx +19 -11
  10. package/src/admin/editor/Timeline.tsx +2 -7
  11. package/src/admin/editor/dialogs.tsx +3 -14
  12. package/src/admin/editor/editor-chrome.tsx +8 -24
  13. package/src/admin/editor/editor-commands.ts +15 -1
  14. package/src/admin/editor/editor-css.ts +3 -2
  15. package/src/admin/editor/feature-css.ts +11 -1
  16. package/src/admin/editor/focus-when-lost.ts +23 -0
  17. package/src/admin/editor/icons/IconLibraryDialog.tsx +2 -7
  18. package/src/admin/editor/palette-items.ts +17 -0
  19. package/src/admin/editor/panels/AddPanel.tsx +9 -1
  20. package/src/admin/editor/panels/LayersPanel.tsx +6 -1
  21. package/src/admin/editor/panels/LeftPanel.tsx +9 -1
  22. package/src/admin/editor/panels/SavedSectionsGroup.tsx +246 -0
  23. package/src/admin/editor/panels/SiteStylesDrawer.tsx +54 -10
  24. package/src/admin/editor/panels/TokenScales.tsx +16 -16
  25. package/src/admin/editor/panels/TriggersEditor.tsx +1 -1
  26. package/src/admin/editor/panels/color-space.ts +14 -26
  27. package/src/admin/editor/panels/settings/AudienceEditor.tsx +36 -39
  28. package/src/admin/editor/panels/settings/IconControls.tsx +21 -5
  29. package/src/admin/editor/panels/settings/LoopItemBindControl.tsx +1 -1
  30. package/src/admin/editor/shortcuts.ts +14 -0
  31. package/src/admin/editor/useSavedSections.ts +197 -0
  32. package/src/admin/image-editor/Canvas.tsx +61 -17
  33. package/src/admin/image-editor/ImageEditorDialog.tsx +130 -1
  34. package/src/admin/image-editor/image-editor-css.ts +11 -8
  35. package/src/admin/image-editor/parts.tsx +18 -17
  36. package/src/admin/image-editor/save.ts +31 -1
  37. package/src/admin/pages/ThemePartList.tsx +32 -4
  38. package/src/admin/saved-sections-api.ts +51 -0
  39. package/src/admin/theme-api.ts +3 -2
  40. package/src/admin/ui.ts +9 -0
  41. package/src/astro/popups/runtime.ts +8 -6
  42. package/src/constants.ts +1 -1
  43. package/src/core/a11y/audit.ts +32 -7
  44. package/src/core/arrange.ts +21 -6
  45. package/src/core/css/print.ts +5 -0
  46. package/src/core/design/classes.ts +23 -9
  47. package/src/core/design/devices.ts +7 -13
  48. package/src/core/design/states.ts +7 -13
  49. package/src/core/elements/dynamic-elements.ts +11 -11
  50. package/src/core/elements/index.ts +1 -1
  51. package/src/core/elements/menu.ts +3 -0
  52. package/src/core/icons/animation-runs.ts +11 -0
  53. package/src/core/index.ts +20 -0
  54. package/src/core/migrate/index.ts +3 -0
  55. package/src/core/render/loop.ts +1 -1
  56. package/src/core/sanitize/css.ts +14 -6
  57. package/src/core/saved-sections.ts +318 -0
  58. package/src/core/schema/design.ts +1 -1
  59. package/src/core/schema/layout.ts +1 -1
  60. package/src/core/schema/style.ts +4 -2
  61. package/src/core/theme/float.ts +3 -0
  62. package/src/core/theme/pagination.ts +25 -24
  63. package/src/core/theme/part-types.ts +4 -4
  64. package/src/mcp/ports.ts +22 -1
  65. package/src/mcp/read.ts +1 -1
  66. package/src/mcp/sections.ts +183 -0
  67. package/src/mcp/tools.ts +44 -0
  68. package/src/mcp/write.ts +4 -4
  69. package/src/server/mcp-routes.ts +2 -0
  70. package/src/server/plugin.ts +14 -0
  71. 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.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).
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
 
@@ -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.8.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.2.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.11",
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.3.1",
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,8 @@ 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";
66
70
  import { type PasteRefusal, useClipboardActions } from "./useClipboardActions.ts";
67
71
  import { ListError, LoadingStatus } from "../pages/list-kit.tsx";
68
72
 
@@ -201,6 +205,16 @@ function EditorApp({
201
205
  addRecipe,
202
206
  items: itemActions,
203
207
  } = useNodeActions({ state, latest, dispatch, announce: setAnnouncement, toasts });
208
+ // W-876: My sections and Save as section (D-060).
209
+ const saved = useSavedSections({
210
+ fetcher,
211
+ latest,
212
+ dispatch,
213
+ changeDesign,
214
+ announce: setAnnouncement,
215
+ toasts,
216
+ });
217
+ const [saveAsk, setSaveAsk] = React.useState<string | null>(null);
204
218
  const [refusal, setRefusal] = React.useState<PasteRefusal | null>(null);
205
219
  const clipboard = useClipboardActions({
206
220
  latest,
@@ -325,6 +339,7 @@ function EditorApp({
325
339
  !!selectedNode && !!state.page.layout && selectedNode.id !== state.page.layout.root.id;
326
340
  const commandRunners = {
327
341
  duplicate,
342
+ saveSection: setSaveAsk,
328
343
  remove,
329
344
  wrap,
330
345
  save: () => void save(),
@@ -487,6 +502,8 @@ function EditorApp({
487
502
  onMoveDown={(id) => arrange(id, moveDown)}
488
503
  onDelete={remove}
489
504
  clipboard={clipboard}
505
+ saved={saved}
506
+ onSaveSection={setSaveAsk}
490
507
  onRename={(id, label) =>
491
508
  dispatch({
492
509
  type: "update-node",
@@ -593,6 +610,15 @@ function EditorApp({
593
610
  finishDelete={finishDelete}
594
611
  playgroundUrl={host.playgroundUrl}
595
612
  setAnnouncement={setAnnouncement}
613
+ saved={saved}
614
+ />
615
+ <SaveSectionDialog
616
+ open={saveAsk !== null}
617
+ onOpenChange={(open) => !open && setSaveAsk(null)}
618
+ defaultName={sectionNameFor(state.page.layout, saveAsk)}
619
+ onSave={(name, mode) =>
620
+ saveAsk ? saved.save(saveAsk, name, mode) : Promise.resolve(null)
621
+ }
596
622
  />
597
623
  </EditorToasts>
598
624
  </EditorOverlay>
@@ -661,3 +687,10 @@ function LoadBody({ data }: { data: EditorData }) {
661
687
  </div>
662
688
  );
663
689
  }
690
+
691
+ /** The Save as section name to start from: the layer's own name, else the element's (W-876). */
692
+ function sectionNameFor(layout: Layout | null, id: string | null): string {
693
+ const node = layout && id ? findNode(layout, id) : undefined;
694
+ if (!node) return "";
695
+ return node.label || (ELEMENT_NAMES[node.type] ?? "Section");
696
+ }
@@ -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>
@@ -18,6 +18,7 @@ import { PLUGIN_ID } from "../../constants.ts";
18
18
  import { ELEMENT_NAMES } from "./element-chrome.ts";
19
19
  import { BUTTON } from "../ui.ts";
20
20
  import { editedNounOf, type EditedNoun } from "./edited-noun.ts";
21
+ import { DialogCloseButton } from "./DialogCloseButton.tsx";
21
22
 
22
23
  type RevisionItem = {
23
24
  id: string;
@@ -469,13 +470,7 @@ export function TimelineDialog({
469
470
  </div>
470
471
  )}
471
472
  <div className="emvb-dialog-actions" ref={actionsRef}>
472
- <Dialog.Close
473
- render={(props) => (
474
- <Button {...props} variant="secondary" className={BUTTON}>
475
- Close
476
- </Button>
477
- )}
478
- />
473
+ <DialogCloseButton>Close</DialogCloseButton>
479
474
  </div>
480
475
  </div>
481
476
  </Dialog>
@@ -2,6 +2,7 @@ import { Button, Dialog, Loader } from "@cloudflare/kumo";
2
2
  import { useMediaQuery } from "./useMediaQuery.ts";
3
3
  import { useEditedNoun } from "./edited-noun.ts";
4
4
  import { BUTTON, SOLID_DESTRUCTIVE, SOLID_PRIMARY, UI_CSS } from "../ui.ts";
5
+ import { DialogCloseButton } from "./DialogCloseButton.tsx";
5
6
 
6
7
  type OpenProps = { open: boolean; onOpenChange: (open: boolean) => void };
7
8
 
@@ -59,13 +60,7 @@ export function RevertDialog({
59
60
  live now. This can't be undone.
60
61
  </Dialog.Description>
61
62
  <div className="emvb-dialog-actions">
62
- <Dialog.Close
63
- render={(props) => (
64
- <Button {...props} variant="secondary" className={BUTTON}>
65
- Cancel
66
- </Button>
67
- )}
68
- />
63
+ <DialogCloseButton>Cancel</DialogCloseButton>
69
64
  <Button
70
65
  variant="destructive"
71
66
  className={BUTTON}
@@ -165,13 +160,7 @@ export function DeleteSubtreeDialog({
165
160
  </Dialog.Title>
166
161
  <Dialog.Description>You can undo this with Restore right after.</Dialog.Description>
167
162
  <div className="emvb-dialog-actions">
168
- <Dialog.Close
169
- render={(props) => (
170
- <Button {...props} variant="secondary" className={BUTTON}>
171
- Cancel
172
- </Button>
173
- )}
174
- />
163
+ <DialogCloseButton>Cancel</DialogCloseButton>
175
164
  <Button
176
165
  variant="destructive"
177
166
  className={BUTTON}
@@ -1,4 +1,6 @@
1
1
  import type { createKumoToastManager } from "@cloudflare/kumo";
2
+ import { focusWhenLost } from "./focus-when-lost.ts";
3
+ import type { SavedSectionActions } from "./useSavedSections.ts";
2
4
  import * as React from "react";
3
5
  import {
4
6
  findNode,
@@ -72,30 +74,6 @@ const CLOSED = {
72
74
 
73
75
  type ChromeKey = keyof typeof CLOSED;
74
76
 
75
- /**
76
- * Focuses the selected layer or the canvas if focus ends up on <body>. A closing dialog keeps
77
- * focus until its close animation ends, so wait (up to 2 s) while focus is still in a dialog;
78
- * other dialog-like layers (toasts) don't hold it up. Returns a cancel.
79
- */
80
- function focusWhenLost(): () => void {
81
- const started = Date.now();
82
- let timer: number | undefined;
83
- const settle = () => {
84
- const now = document.activeElement;
85
- if (now && now !== document.body) {
86
- const inDialog = now.closest('[role="dialog"], [role="alertdialog"]') !== null;
87
- if (inDialog && Date.now() - started < 2000) timer = window.setTimeout(settle, 30);
88
- return;
89
- }
90
- const target =
91
- document.querySelector<HTMLElement>('.emvb-layer-select[aria-current="true"]') ??
92
- document.querySelector<HTMLElement>("iframe[data-emvb-canvas]");
93
- target?.focus({ preventScroll: true });
94
- };
95
- timer = window.setTimeout(settle, 30);
96
- return () => window.clearTimeout(timer);
97
- }
98
-
99
77
  /** Which editor dialog is open. They all start closed. */
100
78
  export function useChromeFlags() {
101
79
  const [flags, setFlags] = React.useState(CLOSED);
@@ -231,6 +209,7 @@ export function EditorDialogs({
231
209
  playgroundUrl,
232
210
  setAnnouncement,
233
211
  parts,
212
+ saved,
234
213
  }: {
235
214
  chrome: ChromeFlags;
236
215
  fetcher: Fetcher;
@@ -255,6 +234,8 @@ export function EditorDialogs({
255
234
  setAnnouncement: (message: string) => void;
256
235
  /** Synced sections and Loop Item parts loaded for the canvas (W-671). */
257
236
  parts?: ThemeDynamicData;
237
+ /** My sections for the palette's Insert group (W-876). */
238
+ saved?: SavedSectionActions;
258
239
  }) {
259
240
  const [leaveSaving, setLeaveSaving] = React.useState(false);
260
241
  return (
@@ -292,6 +273,9 @@ export function EditorDialogs({
292
273
  formsAvailable,
293
274
  insert: addFromPanel,
294
275
  insertRecipe: addRecipe,
276
+ ...(saved
277
+ ? { savedSections: saved.list, insertSaved: (id) => void saved.insert(id) }
278
+ : {}),
295
279
  select: (id) => dispatch({ type: "select", id }),
296
280
  applyClass: (nodeId, classId) =>
297
281
  dispatch({
@@ -42,6 +42,8 @@ export type CommandRunners = {
42
42
  setDevice?: (device: PopupDevice) => void;
43
43
  openShortcuts?: () => void;
44
44
  rename?: () => void;
45
+ /** Opens Save as section for an element (W-876). */
46
+ saveSection?: (id: string) => void;
45
47
  /** Set when the selection is an Image element the image editor can open (W-486). */
46
48
  editImage?: () => void;
47
49
  };
@@ -115,6 +117,12 @@ const SPECS: readonly Spec[] = [
115
117
  surfaces: ["layers", "overlay", "palette"],
116
118
  danger: true,
117
119
  },
120
+ {
121
+ id: "save-section",
122
+ labels: { layers: "Save as section…", palette: "Save selected element as a section…" },
123
+ keywords: "my sections saved reuse synced template block segment",
124
+ surfaces: ["layers", "palette"],
125
+ },
118
126
  { id: "move-up", labels: { layers: "Move up" }, surfaces: ["layers"] },
119
127
  { id: "move-down", labels: { layers: "Move down" }, surfaces: ["layers"] },
120
128
  {
@@ -131,7 +139,7 @@ const SPECS: readonly Spec[] = [
131
139
  },
132
140
  {
133
141
  id: "wrap-div",
134
- labels: { palette: "Wrap in Div Block" },
142
+ labels: { palette: "Wrap in Div block" },
135
143
  keywords: "wrap box",
136
144
  surfaces: ["palette"],
137
145
  },
@@ -196,6 +204,7 @@ const ORDER: Record<CommandSurface, readonly string[]> = {
196
204
  "paste",
197
205
  "paste-inside",
198
206
  "duplicate",
207
+ "save-section",
199
208
  "copy-style",
200
209
  "paste-style",
201
210
  "move-up",
@@ -214,6 +223,7 @@ const ORDER: Record<CommandSurface, readonly string[]> = {
214
223
  "redo",
215
224
  "edit-image",
216
225
  "duplicate",
226
+ "save-section",
217
227
  "delete",
218
228
  "deselect",
219
229
  "site-styles",
@@ -237,6 +247,7 @@ function shown(id: string, input: CommandInput): boolean {
237
247
  const clip = !!input.runners.copy;
238
248
  if (id === "rename") return !!input.runners.rename;
239
249
  if (id === "edit-image") return !!input.runners.editImage;
250
+ if (id === "save-section") return !!input.runners.saveSection && input.canDuplicate;
240
251
  if (id === "paste-inside") return clip && input.isParent;
241
252
  if (id === "paste") return clip && (input.surface !== "layers" || !input.isRoot);
242
253
  if (CLIP_IDS.has(id)) return clip;
@@ -302,6 +313,9 @@ export function runCommand(runners: CommandRunners, id: string, targetId: string
302
313
  case "duplicate":
303
314
  if (targetId) runners.duplicate?.(targetId);
304
315
  return;
316
+ case "save-section":
317
+ if (targetId) runners.saveSection?.(targetId);
318
+ return;
305
319
  case "delete":
306
320
  if (targetId) runners.remove?.(targetId);
307
321
  return;
@@ -239,7 +239,6 @@ iframe[data-emvb-canvas-focus="keyboard"] { outline: 2px solid var(--color-kumo-
239
239
  font-size: 11px;
240
240
  line-height: 14px;
241
241
  font-weight: 600;
242
- letter-spacing: 0.01em;
243
242
  white-space: nowrap;
244
243
  box-shadow: 0 1px 2px var(--color-kumo-shadow-edge), 0 2px 6px var(--color-kumo-shadow-drop);
245
244
  pointer-events: none;
@@ -254,7 +253,9 @@ iframe[data-emvb-canvas-focus="keyboard"] { outline: 2px solid var(--color-kumo-
254
253
  .emvb-small-screen { grid-row: 1 / -1; }
255
254
  .emvb-shortcuts { width: 100%; border-collapse: collapse; font-size: 13px; }
256
255
  .emvb-shortcuts td { padding: 6px 0; border-bottom: 1px solid var(--color-kumo-hairline); }
257
- .emvb-shortcuts td:last-child { text-align: right; font-family: var(--font-mono); color: var(--text-color-kumo-subtle); }
256
+ .emvb-shortcuts td:last-child { text-align: right; white-space: nowrap; font-size: 11px; color: var(--text-color-kumo-subtle); }
257
+ /* W-864: the same key boxes as the command palette's tips. */
258
+ .emvb-shortcuts kbd { display: inline-block; min-width: 18px; margin: 0 2px; padding: 0 4px; border-radius: 4px; box-shadow: inset 0 0 0 1px var(--color-kumo-line); font-family: var(--font-mono); font-size: 11px; line-height: 16px; text-align: center; color: var(--text-color-kumo-default); }
258
259
 
259
260
  .emvb-add-tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
260
261
  .emvb-element-tile {