@perkyzz/emvb 0.1.0 → 0.2.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 (153) hide show
  1. package/README.md +4 -2
  2. package/THIRD_PARTY_NOTICES.md +32 -0
  3. package/licenses/fontawesome-free.LICENSE +165 -0
  4. package/licenses/lucide-static.LICENSE +43 -0
  5. package/licenses/remixicon.LICENSE +201 -0
  6. package/licenses/tabler-icons.LICENSE +21 -0
  7. package/package.json +8 -4
  8. package/src/admin/api.ts +27 -0
  9. package/src/admin/content-api.ts +72 -9
  10. package/src/admin/editor/Editor.tsx +89 -14
  11. package/src/admin/editor/EditorOverlay.tsx +12 -0
  12. package/src/admin/editor/SmallScreenNotice.tsx +4 -3
  13. package/src/admin/editor/TopBar.tsx +76 -12
  14. package/src/admin/editor/canvas/CanvasFrame.tsx +224 -43
  15. package/src/admin/editor/canvas/DeviceBar.tsx +43 -2
  16. package/src/admin/editor/canvas/SelectionOverlay.tsx +60 -6
  17. package/src/admin/editor/canvas/canvas-events.ts +20 -7
  18. package/src/admin/editor/canvas/tab-reveal.ts +66 -0
  19. package/src/admin/editor/canvas/vnode-react.tsx +21 -1
  20. package/src/admin/editor/dialogs.tsx +39 -0
  21. package/src/admin/editor/dnd/drop-target.ts +63 -16
  22. package/src/admin/editor/dnd/new-element.ts +76 -1
  23. package/src/admin/editor/editor-css.ts +101 -15
  24. package/src/admin/editor/host.ts +30 -0
  25. package/src/admin/editor/icons/IconLibraryDialog.tsx +850 -0
  26. package/src/admin/editor/icons/library.ts +243 -0
  27. package/src/admin/editor/icons/set-format.ts +29 -0
  28. package/src/admin/editor/icons/sets/fontawesome.json +1 -0
  29. package/src/admin/editor/icons/sets/lucide.json +1 -0
  30. package/src/admin/editor/icons/sets/remix.json +1 -0
  31. package/src/admin/editor/icons/sets/tabler.json +1 -0
  32. package/src/admin/editor/panels/AddPanel.tsx +7 -3
  33. package/src/admin/editor/panels/ClassesSection.tsx +44 -6
  34. package/src/admin/editor/panels/ColorControl.tsx +268 -21
  35. package/src/admin/editor/panels/ElementPanel.tsx +237 -93
  36. package/src/admin/editor/panels/LayersPanel.tsx +303 -66
  37. package/src/admin/editor/panels/LeftPanel.tsx +4 -0
  38. package/src/admin/editor/panels/PageSettings.tsx +134 -5
  39. package/src/admin/editor/panels/SettingsPanel.tsx +12 -0
  40. package/src/admin/editor/panels/SiteStylesDrawer.tsx +158 -2
  41. package/src/admin/editor/panels/TriggersEditor.tsx +19 -2
  42. package/src/admin/editor/panels/VariableSection.tsx +47 -9
  43. package/src/admin/editor/panels/color-space.ts +195 -0
  44. package/src/admin/editor/panels/settings/AdvancedFields.tsx +119 -0
  45. package/src/admin/editor/panels/settings/BackgroundControls.tsx +153 -55
  46. package/src/admin/editor/panels/settings/BackgroundFill.tsx +221 -0
  47. package/src/admin/editor/panels/settings/BoxControl.tsx +271 -0
  48. package/src/admin/editor/panels/settings/ChoiceGroup.tsx +138 -0
  49. package/src/admin/editor/panels/settings/ClassChipInput.tsx +104 -2
  50. package/src/admin/editor/panels/settings/DraftTextField.tsx +44 -3
  51. package/src/admin/editor/panels/settings/EffectsControls.tsx +23 -16
  52. package/src/admin/editor/panels/settings/FieldBindControl.tsx +53 -17
  53. package/src/admin/editor/panels/settings/FieldControl.tsx +129 -9
  54. package/src/admin/editor/panels/settings/FormBindControl.tsx +14 -5
  55. package/src/admin/editor/panels/settings/IconControls.tsx +438 -0
  56. package/src/admin/editor/panels/settings/IconPicker.tsx +133 -72
  57. package/src/admin/editor/panels/settings/ItemList.tsx +199 -0
  58. package/src/admin/editor/panels/settings/LengthRow.tsx +97 -61
  59. package/src/admin/editor/panels/settings/LoopItemBindControl.tsx +10 -4
  60. package/src/admin/editor/panels/settings/MediaPicker.tsx +4 -2
  61. package/src/admin/editor/panels/settings/StateSwitcher.tsx +1 -1
  62. package/src/admin/editor/panels/settings/StyleRow.tsx +158 -75
  63. package/src/admin/editor/panels/settings/VariableBinding.tsx +5 -1
  64. package/src/admin/editor/panels/settings/advanced-rules.ts +63 -0
  65. package/src/admin/editor/panels/settings/background-mode.ts +112 -0
  66. package/src/admin/editor/panels/settings/box-link-name.ts +38 -0
  67. package/src/admin/editor/panels/settings/box-sides.ts +153 -0
  68. package/src/admin/editor/panels/settings/button-url.ts +27 -0
  69. package/src/admin/editor/panels/settings/class-suggest.ts +5 -3
  70. package/src/admin/editor/panels/settings/form-names.ts +38 -0
  71. package/src/admin/editor/panels/settings/heading-warning.ts +25 -0
  72. package/src/admin/editor/panels/settings/image-alt.ts +25 -0
  73. package/src/admin/editor/panels/settings/length-units.ts +40 -7
  74. package/src/admin/editor/panels/settings/loop-context.ts +26 -0
  75. package/src/admin/editor/panels/settings/style-sections.ts +114 -11
  76. package/src/admin/editor/panels/settings/svg-images.ts +14 -0
  77. package/src/admin/editor/panels/site-list.tsx +3 -0
  78. package/src/admin/editor/restore-deleted.ts +80 -0
  79. package/src/admin/editor/shortcuts.ts +1 -1
  80. package/src/admin/editor/store.ts +35 -7
  81. package/src/admin/editor/useEditorCommands.ts +66 -5
  82. package/src/admin/editor/useEditorData.ts +29 -3
  83. package/src/admin/editor/useEditorShortcuts.ts +34 -2
  84. package/src/admin/editor/useNodeActions.ts +68 -6
  85. package/src/admin/editor/useSave.ts +60 -3
  86. package/src/admin/entry-status.ts +19 -0
  87. package/src/admin/icon-uploads-api.ts +44 -0
  88. package/src/admin/pages/PageList.tsx +22 -2
  89. package/src/admin/pages/ThemePartList.tsx +23 -4
  90. package/src/admin/pages/list-kit.tsx +52 -2
  91. package/src/admin/setup/spec.ts +7 -0
  92. package/src/admin/theme-api.ts +61 -14
  93. package/src/admin/ui.ts +17 -4
  94. package/src/astro/EmVBPage.astro +28 -2
  95. package/src/astro/floats/EmVBFloatsRuntime.astro +9 -0
  96. package/src/astro/floats/index.ts +1 -0
  97. package/src/astro/floats/runtime.ts +78 -0
  98. package/src/astro/forms-definitions.ts +22 -0
  99. package/src/astro/index.ts +1 -0
  100. package/src/astro/menu/EmVBMenuRuntime.astro +9 -0
  101. package/src/astro/menu/index.ts +1 -0
  102. package/src/astro/menu/runtime.ts +37 -0
  103. package/src/astro/popups/runtime.ts +54 -4
  104. package/src/astro/render.ts +47 -13
  105. package/src/astro/resolve-theme.ts +164 -20
  106. package/src/astro/tabs/runtime.ts +6 -1
  107. package/src/astro/theme-context.ts +11 -3
  108. package/src/constants.ts +1 -1
  109. package/src/core/arrange.ts +98 -10
  110. package/src/core/clipboard.ts +91 -9
  111. package/src/core/css/generate.ts +21 -4
  112. package/src/core/design/classes.ts +95 -9
  113. package/src/core/design/transfer.ts +101 -2
  114. package/src/core/design/variables.ts +51 -11
  115. package/src/core/elements/dynamic-elements.ts +57 -5
  116. package/src/core/elements/field-id.ts +6 -0
  117. package/src/core/elements/form-elements.ts +23 -8
  118. package/src/core/elements/index.ts +267 -49
  119. package/src/core/elements/menu.ts +190 -0
  120. package/src/core/forms/definition.ts +11 -0
  121. package/src/core/index.ts +67 -3
  122. package/src/core/limits.ts +2 -0
  123. package/src/core/migrate/index.ts +51 -1
  124. package/src/core/nesting.ts +51 -0
  125. package/src/core/render/context.ts +7 -0
  126. package/src/core/render/dynamic-post.ts +39 -11
  127. package/src/core/render/extras.ts +22 -3
  128. package/src/core/render/form.ts +134 -36
  129. package/src/core/render/index.ts +123 -25
  130. package/src/core/render/loop.ts +10 -3
  131. package/src/core/render/pagination.ts +76 -0
  132. package/src/core/render/section.ts +5 -1
  133. package/src/core/render/tabs.ts +8 -4
  134. package/src/core/render/vnode.ts +1 -1
  135. package/src/core/sanitize/css.ts +197 -17
  136. package/src/core/sanitize/embed-url.ts +64 -7
  137. package/src/core/sanitize/svg-upload.ts +203 -0
  138. package/src/core/sanitize/svg.ts +102 -21
  139. package/src/core/schema/descriptors.ts +4 -0
  140. package/src/core/schema/design.ts +7 -2
  141. package/src/core/schema/layout.ts +210 -19
  142. package/src/core/schema/style.ts +87 -8
  143. package/src/core/tabs/presence.ts +9 -0
  144. package/src/core/theme/conditions.ts +4 -1
  145. package/src/core/theme/dynamic.ts +10 -0
  146. package/src/core/theme/float.ts +113 -0
  147. package/src/core/theme/pagination.ts +97 -0
  148. package/src/core/theme/part-types.ts +2 -0
  149. package/src/core/theme/popup-markup.ts +3 -1
  150. package/src/core/theme/popup-rules.ts +4 -3
  151. package/src/server/hooks.ts +20 -0
  152. package/src/server/icon-routes.ts +79 -0
  153. package/src/server/plugin.ts +5 -1
@@ -1,12 +1,14 @@
1
1
  import type {
2
2
  ConditionsDoc,
3
3
  DesignSystem,
4
+ FloatSettings,
4
5
  Layout,
5
6
  ThemePartType,
6
7
  TriggersDoc,
7
8
  } from "../core/index.ts";
8
9
  import { PAGES_COLLECTION, PLUGIN_ID } from "../constants.ts";
9
- import { requestJson, type Fetcher } from "./api.ts";
10
+ import { listAllItems, requestJson, type Fetcher } from "./api.ts";
11
+ import { entryStatus } from "./entry-status.ts";
10
12
 
11
13
  const CONTENT = `/_emdash/api/content/${PAGES_COLLECTION}`;
12
14
 
@@ -14,9 +16,16 @@ type RawItem = {
14
16
  id: string;
15
17
  slug?: string | null;
16
18
  status?: string;
19
+ draftRevisionId?: string | null;
17
20
  updatedAt?: string;
18
21
  data?: Record<string, unknown>;
19
- seo?: { title?: string | null; description?: string | null } | null;
22
+ seo?: {
23
+ title?: string | null;
24
+ description?: string | null;
25
+ canonical?: string | null;
26
+ noIndex?: boolean | null;
27
+ image?: string | null;
28
+ } | null;
20
29
  };
21
30
 
22
31
  export type PageSummary = {
@@ -33,15 +42,12 @@ const titleOf = (item: RawItem) =>
33
42
  : "Untitled page";
34
43
 
35
44
  export async function listPages(fetcher: Fetcher): Promise<PageSummary[]> {
36
- const body = await requestJson<{ items?: RawItem[] }>(
37
- fetcher,
38
- `${CONTENT}?limit=50&orderBy=updatedAt&order=desc`,
39
- );
40
- return (body?.items ?? []).map((item) => ({
45
+ const items = await listAllItems<RawItem>(fetcher, CONTENT);
46
+ return items.map((item) => ({
41
47
  id: item.id,
42
48
  title: titleOf(item),
43
49
  slug: item.slug ?? "",
44
- status: item.status ?? "draft",
50
+ status: entryStatus(item),
45
51
  updatedAt: item.updatedAt ?? "",
46
52
  }));
47
53
  }
@@ -63,14 +69,54 @@ export type PageDraft = {
63
69
  canvasMode: string;
64
70
  seoTitle: string;
65
71
  seoDescription: string;
72
+ /** W-284: absolute http(s) URL, or "" for none. Absent = leave the saved value alone. */
73
+ seoCanonical?: string;
74
+ /** W-284: ask search engines not to index the page. Absent = leave the saved value alone. */
75
+ seoNoIndex?: boolean;
76
+ /**
77
+ * W-287: social (OG) image as EmDash reads it: an absolute URL or a site path (the media
78
+ * library's `/_emdash/api/media/file/…`); "" for none. Absent = leave the saved value alone.
79
+ */
80
+ seoImage?: string;
66
81
  layout: Layout | null;
67
82
  /** Theme parts only (emvb_theme_parts). */
68
83
  partType?: ThemePartType;
69
84
  conditions?: ConditionsDoc;
70
85
  /** Popups only — open triggers + thin advanced rules. */
71
86
  triggers?: TriggersDoc;
87
+ /** Floats only — edge and whether a close button is offered. */
88
+ float?: FloatSettings;
72
89
  };
73
90
 
91
+ /**
92
+ * W-284: EmDash accepts only an absolute http(s) canonical URL (or null) and refuses the whole
93
+ * save otherwise, so the panel flags anything else and the save leaves the stored one alone.
94
+ */
95
+ export function canonicalProblem(value: string): string | null {
96
+ const trimmed = value.trim();
97
+ if (!trimmed) return null;
98
+ try {
99
+ const url = new URL(trimmed);
100
+ if (url.protocol === "https:" || url.protocol === "http:") return null;
101
+ } catch {
102
+ // fall through
103
+ }
104
+ return "Not saved: use a full address starting with https://";
105
+ }
106
+
107
+ function seoBody(draft: PageDraft) {
108
+ const canonical = draft.seoCanonical;
109
+ return {
110
+ title: draft.seoTitle || null,
111
+ description: draft.seoDescription || null,
112
+ ...(canonical !== undefined && !canonicalProblem(canonical)
113
+ ? { canonical: canonical.trim() || null }
114
+ : {}),
115
+ ...(draft.seoNoIndex !== undefined ? { noIndex: draft.seoNoIndex } : {}),
116
+ ...(draft.seoImage !== undefined ? { image: draft.seoImage.trim() || null } : {}),
117
+ };
118
+ }
119
+
74
120
  /** Saves the draft with `_rev`, so a concurrent change fails with 409 instead of being overwritten. */
75
121
  export async function savePage(
76
122
  fetcher: Fetcher,
@@ -86,7 +132,7 @@ export async function savePage(
86
132
  body: {
87
133
  data: { title: draft.title, layout: draft.layout, canvas_mode: draft.canvasMode },
88
134
  slug: draft.slug,
89
- seo: { title: draft.seoTitle || null, description: draft.seoDescription || null },
135
+ seo: seoBody(draft),
90
136
  ...(rev ? { _rev: rev } : {}),
91
137
  },
92
138
  },
@@ -109,6 +155,23 @@ export async function publishEntry(
109
155
  return { rev: body["_rev"], slug: body.item.slug ?? "" };
110
156
  }
111
157
 
158
+ /**
159
+ * Drops the saved draft of entry `id` so it is back to its published version (W-193). EmDash's
160
+ * `discard-draft` checks `rev`, so a draft saved elsewhere meanwhile fails with 409.
161
+ */
162
+ export async function discardDraft(
163
+ fetcher: Fetcher,
164
+ collection: string,
165
+ id: string,
166
+ rev: string | null,
167
+ ): Promise<void> {
168
+ await requestJson<unknown>(
169
+ fetcher,
170
+ `/_emdash/api/content/${encodeURIComponent(collection)}/${encodeURIComponent(id)}/discard-draft`,
171
+ { method: "POST", body: rev === null ? {} : { _rev: rev } },
172
+ );
173
+ }
174
+
112
175
  export const publishPage = (fetcher: Fetcher, id: string, rev: string | null) =>
113
176
  publishEntry(fetcher, CONTENT, id, rev);
114
177
 
@@ -2,26 +2,27 @@ import { Banner, Button, createKumoToastManager, Empty, Loader, Toasty } from "@
2
2
  import { WarningCircleIcon } from "@phosphor-icons/react";
3
3
  import * as React from "react";
4
4
  import {
5
- DEVICE_PREVIEW_PX,
6
5
  findNode,
7
6
  moveDown,
8
7
  moveUp,
9
8
  renderPage,
10
9
  toggleHidden,
11
10
  withPlainText,
11
+ type LayoutNode,
12
12
  type PopupDevice,
13
13
  } from "../../core/index.ts";
14
14
  import { PAGES_COLLECTION, THEME_PARTS_COLLECTION } from "../../constants.ts";
15
15
  import type { Fetcher } from "../api.ts";
16
16
  import { loadFormsCapability } from "../forms-api.ts";
17
- import { CanvasFrame, type CanvasSelection } from "./canvas/CanvasFrame.tsx";
17
+ import { CanvasFrame, type CanvasSelection, type CanvasZoom } from "./canvas/CanvasFrame.tsx";
18
18
  import { DeviceBar } from "./canvas/DeviceBar.tsx";
19
19
  import type { StatePreview } from "./canvas/state-preview.ts";
20
20
  import type { StyleStateChoice } from "./panels/settings/StateSwitcher.tsx";
21
21
  import { EmptyCanvas } from "./canvas/EmptyCanvas.tsx";
22
- import { ConflictDialog, DeleteSubtreeDialog, LeaveDialog } from "./dialogs.tsx";
22
+ import { ConflictDialog, DeleteSubtreeDialog, LeaveDialog, RevertDialog } from "./dialogs.tsx";
23
+ import { discardDraft } from "../content-api.ts";
23
24
  import { EditorOverlay } from "./EditorOverlay.tsx";
24
- import { exitTarget, PAGES_URL } from "./exit.ts";
25
+ import { useEditorHost } from "./host.ts";
25
26
  import { newElement } from "./dnd/new-element.ts";
26
27
  import { ELEMENT_NAMES } from "./panels/ElementPanel.tsx";
27
28
  import { LeftPanel } from "./panels/LeftPanel.tsx";
@@ -39,6 +40,7 @@ import {
39
40
  } from "./useEditorData.ts";
40
41
  import { EDITOR_MIN_WIDTH_QUERY, useMediaQuery } from "./useMediaQuery.ts";
41
42
  import { useSectionTemplates } from "./section-templates.ts";
43
+ import { restoreOnUndo, type Deletion } from "./restore-deleted.ts";
42
44
  import { useEditorCommands } from "./useEditorCommands.ts";
43
45
  import { useSave } from "./useSave.ts";
44
46
  import { type ShortcutHandlers, useEditorShortcuts } from "./useEditorShortcuts.ts";
@@ -46,6 +48,13 @@ import { useNodeActions } from "./useNodeActions.ts";
46
48
  import { type PasteRefusal, useClipboardActions } from "./useClipboardActions.ts";
47
49
 
48
50
  /** The full-screen editor for one EmVB page or theme part (R-001, R-002, R-060). */
51
+
52
+ /** Sets or clears a node's editor-only name (W-157). */
53
+ const withLabel = (node: LayoutNode, label: string | undefined): LayoutNode => {
54
+ const { label: _old, ...rest } = node;
55
+ return (label ? { ...rest, label } : rest) as LayoutNode;
56
+ };
57
+
49
58
  export function Editor({
50
59
  fetcher,
51
60
  entryId,
@@ -79,8 +88,6 @@ export function Editor({
79
88
  /** How long a refused paste stays outlined on the canvas (W-093). */
80
89
  const REFUSAL_MS = 4000;
81
90
 
82
- const exit = () => window.location.assign(exitTarget(document.referrer, window.location.origin));
83
-
84
91
  const initialState = (entry: EditorEntry, design: LoadedDesign): EditorState => ({
85
92
  id: entry.id,
86
93
  page: {
@@ -89,10 +96,14 @@ const initialState = (entry: EditorEntry, design: LoadedDesign): EditorState =>
89
96
  canvasMode: entry.canvasMode,
90
97
  seoTitle: entry.seoTitle,
91
98
  seoDescription: entry.seoDescription,
99
+ seoCanonical: entry.seoCanonical,
100
+ seoNoIndex: entry.seoNoIndex,
101
+ seoImage: entry.seoImage,
92
102
  layout: entry.layout,
93
103
  partType: entry.partType,
94
104
  conditions: entry.conditions,
95
105
  triggers: entry.triggers,
106
+ float: entry.float,
96
107
  },
97
108
  status: entry.status,
98
109
  rev: entry.rev,
@@ -124,10 +135,13 @@ function EditorApp({
124
135
  );
125
136
  const state = history.present;
126
137
  const dirty = isDirty(state);
138
+ const { exit } = useEditorHost();
127
139
  const saver = useSave(fetcher, state, dispatch, collection);
128
140
  const toasts = React.useMemo(() => createKumoToastManager(), []);
129
141
  const [siteStylesOpen, setSiteStylesOpen] = React.useState(false);
130
142
  const [device, setDevice] = React.useState<PopupDevice>("desktop");
143
+ const [zoom, setZoom] = React.useState<CanvasZoom>("fit");
144
+ const [scale, setScale] = React.useState(1);
131
145
  const [statePreview, setStatePreview] = React.useState<StatePreview | null>(null);
132
146
  const onStyleState = React.useCallback((id: string, choice: StyleStateChoice) => {
133
147
  setStatePreview(choice === "normal" ? null : { id, state: choice });
@@ -136,6 +150,7 @@ function EditorApp({
136
150
  const [announcement, setAnnouncement] = React.useState("");
137
151
  const [leaveOpen, setLeaveOpen] = React.useState(false);
138
152
  const [leaving, setLeaving] = React.useState(false);
153
+ const [revertOpen, setRevertOpen] = React.useState(false);
139
154
  const latest = React.useRef(state);
140
155
  latest.current = state;
141
156
  const { busy, save, publish, preview, changeDesign, publishStyles } = useEditorCommands({
@@ -146,6 +161,21 @@ function EditorApp({
146
161
  saver,
147
162
  toasts,
148
163
  });
164
+ // W-252: undoing a Site styles delete brings the variable or class back with its uses.
165
+ const deletions = React.useRef<Deletion[]>([]);
166
+ const changeDesignRef = React.useRef(changeDesign);
167
+ changeDesignRef.current = changeDesign;
168
+ const pageLayout = state.page.layout;
169
+ React.useEffect(() => {
170
+ if (!pageLayout) return;
171
+ const restored = restoreOnUndo(latest.current.design, pageLayout, deletions.current);
172
+ if (!restored) return;
173
+ changeDesignRef.current(restored).catch((error: unknown) => {
174
+ toasts.add({
175
+ title: error instanceof Error ? error.message : "Couldn't restore the deleted site style.",
176
+ });
177
+ });
178
+ }, [pageLayout, toasts]);
149
179
  const {
150
180
  deleteAsk,
151
181
  setDeleteAsk,
@@ -156,6 +186,7 @@ function EditorApp({
156
186
  arrange,
157
187
  duplicate,
158
188
  addFromPanel,
189
+ items: itemActions,
159
190
  } = useNodeActions({ state, latest, dispatch, announce: setAnnouncement, toasts });
160
191
  const [refusal, setRefusal] = React.useState<PasteRefusal | null>(null);
161
192
  const clipboard = useClipboardActions({
@@ -184,7 +215,7 @@ function EditorApp({
184
215
 
185
216
  React.useEffect(() => {
186
217
  if (leaving) exit();
187
- }, [leaving]);
218
+ }, [leaving, exit]);
188
219
 
189
220
  const sectionTemplates = useSectionTemplates(state.page.layout, fetcher);
190
221
  const rendered = React.useMemo(
@@ -217,7 +248,7 @@ function EditorApp({
217
248
  const reload = async () => {
218
249
  saver.closeConflict();
219
250
  try {
220
- const fresh = await loadEntry(fetcher, state.id);
251
+ const fresh = await loadEntry(fetcher, state.id, collection);
221
252
  dispatch({
222
253
  type: "reset",
223
254
  state: initialState(fresh, {
@@ -233,11 +264,29 @@ function EditorApp({
233
264
  }
234
265
  };
235
266
 
267
+ // W-193: a saved draft is dropped on the server; unsaved edits on a published entry only locally.
268
+ const canRevert = state.status === "changed" || (state.status === "published" && dirty);
269
+ const revert = async () => {
270
+ setRevertOpen(false);
271
+ try {
272
+ if (latest.current.status === "changed") {
273
+ await discardDraft(fetcher, collection, latest.current.id, latest.current.rev);
274
+ }
275
+ await reload();
276
+ toasts.add({ title: "Reverted to the published version" });
277
+ } catch (error) {
278
+ toasts.add({
279
+ title: "Couldn't revert",
280
+ description: error instanceof Error ? error.message : String(error),
281
+ });
282
+ }
283
+ };
284
+
236
285
  const selection: CanvasSelection = {
237
286
  selectedId: selectedNode ? state.selectedId : null,
238
287
  labelFor: (id) => {
239
288
  const node = state.page.layout ? findNode(state.page.layout, id) : undefined;
240
- return node ? (ELEMENT_NAMES[node.type] ?? node.type) : "Element";
289
+ return node ? (node.label ?? ELEMENT_NAMES[node.type] ?? node.type) : "Element";
241
290
  },
242
291
  canDelete,
243
292
  canMove,
@@ -265,9 +314,12 @@ function EditorApp({
265
314
  onExit={() => (dirty ? setLeaveOpen(true) : exit())}
266
315
  onShortcuts={() => setShortcutsOpen(true)}
267
316
  onSiteStyles={() => setSiteStylesOpen(true)}
268
- onPreview={preview}
317
+ onPreview={(size) => preview(size ?? device)}
269
318
  onSave={() => void save()}
270
319
  onPublish={() => void publish()}
320
+ stylesUnpublished={state.designUnpublished === true}
321
+ canRevert={canRevert}
322
+ onRevert={() => setRevertOpen(true)}
271
323
  />
272
324
  <div className="emvb-frame">
273
325
  <aside className="emvb-panel emvb-panel-left" aria-label="Add and Layers">
@@ -282,6 +334,13 @@ function EditorApp({
282
334
  onMoveDown={(id) => arrange(id, moveDown)}
283
335
  onDelete={remove}
284
336
  clipboard={clipboard}
337
+ onRename={(id, label) =>
338
+ dispatch({
339
+ type: "update-node",
340
+ id,
341
+ update: (node) => withLabel(node, label),
342
+ })
343
+ }
285
344
  />
286
345
  <div className="emvb-sr-only" aria-live="polite">
287
346
  {announcement}
@@ -297,6 +356,9 @@ function EditorApp({
297
356
  }
298
357
  canHide={!!state.selectedId}
299
358
  onDevice={setDevice}
359
+ zoom={zoom}
360
+ scale={scale}
361
+ onZoom={setZoom}
300
362
  onToggleHidden={() => {
301
363
  const id = state.selectedId;
302
364
  const node =
@@ -319,7 +381,9 @@ function EditorApp({
319
381
  vnode={rendered.vnode}
320
382
  css={rendered.css}
321
383
  layout={state.page.layout}
322
- previewWidth={device === "desktop" ? null : DEVICE_PREVIEW_PX[device]}
384
+ device={device}
385
+ zoom={zoom}
386
+ onScale={setScale}
323
387
  selection={selection}
324
388
  statePreview={statePreview}
325
389
  refusal={refusalShown ? refusal : null}
@@ -352,6 +416,9 @@ function EditorApp({
352
416
  onCloseSiteStyles={() => setSiteStylesOpen(false)}
353
417
  onDesignChange={changeDesign}
354
418
  onPublishStyles={publishStyles}
419
+ onDesignItemDeleted={(deletion) => {
420
+ deletions.current = [...deletions.current.slice(-19), deletion];
421
+ }}
355
422
  fetcher={fetcher}
356
423
  formsAvailable={formsAvailable}
357
424
  rejection={saver.rejection}
@@ -360,6 +427,7 @@ function EditorApp({
360
427
  kind={collection === THEME_PARTS_COLLECTION ? "theme-part" : "page"}
361
428
  onStyleState={onStyleState}
362
429
  device={device}
430
+ items={itemActions}
363
431
  />
364
432
  </div>
365
433
  </>
@@ -380,6 +448,11 @@ function EditorApp({
380
448
  onReload={() => void reload()}
381
449
  onOverwrite={() => void saver.overwrite()}
382
450
  />
451
+ <RevertDialog
452
+ open={revertOpen}
453
+ onOpenChange={setRevertOpen}
454
+ onRevert={() => void revert()}
455
+ />
383
456
  <LeaveDialog
384
457
  open={leaveOpen}
385
458
  onOpenChange={setLeaveOpen}
@@ -399,6 +472,7 @@ function EditorApp({
399
472
  const noop = () => undefined;
400
473
 
401
474
  function LoadState({ data }: { data: EditorData }) {
475
+ const { exit } = useEditorHost();
402
476
  return (
403
477
  <>
404
478
  <TopBar
@@ -418,6 +492,7 @@ function LoadState({ data }: { data: EditorData }) {
418
492
  }
419
493
 
420
494
  function LoadBody({ data }: { data: EditorData }) {
495
+ const { back } = useEditorHost();
421
496
  if (data.state === "not-found" || data.state === "forbidden") {
422
497
  return (
423
498
  <div className="emvb-state" data-emvb-editor-state={data.state}>
@@ -425,12 +500,12 @@ function LoadBody({ data }: { data: EditorData }) {
425
500
  title={data.state === "not-found" ? "Page not found" : "You can't open this page"}
426
501
  description={
427
502
  data.state === "not-found"
428
- ? "It may have been deleted. Choose another page from Visual pages."
503
+ ? `It may have been deleted. Choose another page from ${back.label}.`
429
504
  : "Your role doesn't allow editing this page."
430
505
  }
431
506
  contents={
432
- <Button variant="secondary" onClick={() => window.location.assign(PAGES_URL)}>
433
- Go to Visual pages
507
+ <Button variant="secondary" onClick={back.go}>
508
+ Go to {back.label}
434
509
  </Button>
435
510
  }
436
511
  />
@@ -28,6 +28,18 @@ export function EditorOverlay({
28
28
  return () => window.removeEventListener("keydown", block, true);
29
29
  }, []);
30
30
 
31
+ // W-300: the overlay covers the EmDash admin shell, but Tab still walked its sidebar first.
32
+ // Mark the shell inert while the editor is open; hosts without #admin-root (the playground) are
33
+ // unchanged. Toast portals stay after the overlay so they stay focusable.
34
+ React.useEffect(() => {
35
+ const shell = document.getElementById("admin-root");
36
+ if (!shell) return;
37
+ shell.inert = true;
38
+ return () => {
39
+ shell.inert = false;
40
+ };
41
+ }, []);
42
+
31
43
  React.useEffect(() => {
32
44
  if (!dirty) return;
33
45
  const guard = (event: BeforeUnloadEvent) => {
@@ -1,8 +1,9 @@
1
1
  import { Button, Empty } from "@cloudflare/kumo";
2
2
  import { DesktopIcon } from "@phosphor-icons/react";
3
- import { PAGES_URL } from "./exit.ts";
3
+ import { useEditorHost } from "./host.ts";
4
4
 
5
5
  export function SmallScreenNotice() {
6
+ const { back } = useEditorHost();
6
7
  return (
7
8
  <div className="emvb-state emvb-small-screen" data-emvb-small-screen="">
8
9
  <Empty
@@ -10,8 +11,8 @@ export function SmallScreenNotice() {
10
11
  title="EmVB needs a larger screen"
11
12
  description="The editor works on screens at least 1024 px wide, and 1280 px or wider is best."
12
13
  contents={
13
- <Button variant="secondary" onClick={() => window.location.assign(PAGES_URL)}>
14
- Back to Visual pages
14
+ <Button variant="secondary" onClick={back.go}>
15
+ Back to {back.label}
15
16
  </Button>
16
17
  }
17
18
  />
@@ -1,14 +1,27 @@
1
- import { Button } from "@cloudflare/kumo";
1
+ import { Button, DropdownMenu } from "@cloudflare/kumo";
2
2
  import type * as React from "react";
3
3
  import {
4
4
  ArrowSquareOutIcon,
5
+ CaretDownIcon,
6
+ DesktopIcon,
7
+ DeviceMobileIcon,
8
+ DeviceTabletIcon,
5
9
  KeyboardIcon,
6
10
  PaintBrushIcon,
7
11
  SignOutIcon,
8
12
  WarningCircleIcon,
9
13
  } from "@phosphor-icons/react";
10
14
  import { BUTTON, SOLID_PRIMARY } from "../ui.ts";
15
+ import { statusLabel } from "../entry-status.ts";
11
16
  import type { SaveStatus } from "./useSave.ts";
17
+ import type { PopupDevice } from "../../core/index.ts";
18
+
19
+ /** Preview sizes (W-158): the canvas device widths, in a window of that size. */
20
+ const PREVIEW_SIZES = [
21
+ { device: "desktop", label: "Desktop", icon: DesktopIcon },
22
+ { device: "tablet", label: "Tablet (768 px)", icon: DeviceTabletIcon },
23
+ { device: "mobile", label: "Mobile (390 px)", icon: DeviceMobileIcon },
24
+ ] as const;
12
25
 
13
26
  export type TopBarPage = { title: string; status: string };
14
27
 
@@ -56,6 +69,9 @@ export function TopBar({
56
69
  onPreview,
57
70
  onSave,
58
71
  onPublish,
72
+ stylesUnpublished = false,
73
+ canRevert = false,
74
+ onRevert,
59
75
  }: {
60
76
  page: TopBarPage | null;
61
77
  dirty: boolean;
@@ -64,9 +80,16 @@ export function TopBar({
64
80
  onExit: () => void;
65
81
  onShortcuts: () => void;
66
82
  onSiteStyles?: () => void;
67
- onPreview: () => void;
83
+ /** Opens the preview; with no device, at the device shown on the canvas (W-158). */
84
+ onPreview: (device?: PopupDevice) => void;
68
85
  onSave: () => void;
69
86
  onPublish: () => void;
87
+ /** Site styles have unpublished changes (W-153): the Publish button carries a dot. */
88
+ stylesUnpublished?: boolean;
89
+ /** Something differs from the published version (W-193). */
90
+ canRevert?: boolean;
91
+ /** Shown once the entry has a published version; asks before discarding. */
92
+ onRevert?: () => void;
70
93
  }) {
71
94
  return (
72
95
  <header className="emvb-topbar">
@@ -84,7 +107,7 @@ export function TopBar({
84
107
  <span className="emvb-topbar-title">{page.title || "Untitled page"}</span>
85
108
  <span className="emvb-status" data-status={page.status}>
86
109
  <span className="emvb-status-dot" aria-hidden="true" />
87
- {page.status === "published" ? "Published" : "Draft"}
110
+ {statusLabel(page.status)}
88
111
  </span>
89
112
  </>
90
113
  )}
@@ -142,14 +165,47 @@ export function TopBar({
142
165
  gap: 8,
143
166
  }}
144
167
  >
145
- <Button
146
- variant="secondary"
147
- className={BUTTON}
148
- icon={<ArrowSquareOutIcon aria-hidden="true" />}
149
- onClick={onPreview}
150
- >
151
- Preview
152
- </Button>
168
+ <div className="emvb-preview-split">
169
+ <Button
170
+ variant="secondary"
171
+ className={BUTTON}
172
+ icon={<ArrowSquareOutIcon aria-hidden="true" />}
173
+ onClick={() => onPreview()}
174
+ >
175
+ Preview
176
+ </Button>
177
+ <DropdownMenu>
178
+ <DropdownMenu.Trigger>
179
+ <Button
180
+ variant="secondary"
181
+ shape="square"
182
+ className={`${BUTTON} emvb-preview-sizes`}
183
+ aria-label="Preview size"
184
+ title="Preview size"
185
+ icon={<CaretDownIcon aria-hidden="true" />}
186
+ />
187
+ </DropdownMenu.Trigger>
188
+ <DropdownMenu.Content data-emvb-preview-sizes="">
189
+ {PREVIEW_SIZES.map(({ device, label, icon }) => (
190
+ <DropdownMenu.Item key={device} icon={icon} onClick={() => onPreview(device)}>
191
+ {label}
192
+ </DropdownMenu.Item>
193
+ ))}
194
+ </DropdownMenu.Content>
195
+ </DropdownMenu>
196
+ </div>
197
+ {onRevert && (page.status === "published" || page.status === "changed") && (
198
+ <Button
199
+ variant="ghost"
200
+ className={`${BUTTON} emvb-revert-button`}
201
+ disabled={busy !== null || !canRevert}
202
+ title={canRevert ? "Revert to published" : "No changes since the last publish"}
203
+ aria-label="Revert to published"
204
+ onClick={onRevert}
205
+ >
206
+ Revert
207
+ </Button>
208
+ )}
153
209
  <Button
154
210
  variant="secondary"
155
211
  className={`${BUTTON} emvb-save-button`}
@@ -163,13 +219,21 @@ export function TopBar({
163
219
  </Button>
164
220
  <Button
165
221
  variant="primary"
166
- className={BUTTON}
222
+ className={`${BUTTON} emvb-publish-button`}
167
223
  style={SOLID_PRIMARY}
168
224
  loading={busy === "publish"}
169
225
  disabled={busy !== null}
226
+ aria-label={stylesUnpublished ? "Publish (site styles unpublished)" : undefined}
227
+ title={
228
+ stylesUnpublished
229
+ ? "Site styles have unpublished changes. After publishing the page, you can publish them too."
230
+ : undefined
231
+ }
232
+ data-emvb-styles-pending={stylesUnpublished ? "true" : undefined}
170
233
  onClick={onPublish}
171
234
  >
172
235
  Publish
236
+ {stylesUnpublished && <span className="emvb-styles-dot" aria-hidden="true" />}
173
237
  </Button>
174
238
  </div>
175
239
  )}