@perkyzz/emvb 0.3.0 → 0.4.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 (121) hide show
  1. package/README.md +4 -2
  2. package/THIRD_PARTY_NOTICES.md +1 -1
  3. package/package.json +3 -1
  4. package/src/admin/access/role.ts +9 -3
  5. package/src/admin/api.ts +17 -7
  6. package/src/admin/content-api.ts +7 -51
  7. package/src/admin/content-item.ts +22 -0
  8. package/src/admin/design-api.ts +30 -0
  9. package/src/admin/editor/A11yCopilot.tsx +1 -1
  10. package/src/admin/editor/Editor.tsx +106 -332
  11. package/src/admin/editor/EditorOverlay.tsx +3 -1
  12. package/src/admin/editor/PerfMeter.tsx +1 -1
  13. package/src/admin/editor/ShortcutsDialog.tsx +4 -1
  14. package/src/admin/editor/Timeline.tsx +16 -3
  15. package/src/admin/editor/canvas/CanvasFrame.tsx +51 -368
  16. package/src/admin/editor/canvas/DeviceBar.tsx +4 -1
  17. package/src/admin/editor/canvas/SelectionOverlay.tsx +86 -46
  18. package/src/admin/editor/canvas/canvas-scale.ts +20 -0
  19. package/src/admin/editor/canvas/drop-line.ts +24 -0
  20. package/src/admin/editor/canvas/use-canvas-dnd.ts +207 -0
  21. package/src/admin/editor/canvas/use-canvas-session.ts +216 -0
  22. package/src/admin/editor/collection-previews.ts +28 -5
  23. package/src/admin/editor/editor-chrome.tsx +346 -0
  24. package/src/admin/editor/editor-commands.ts +360 -0
  25. package/src/admin/editor/element-chrome.ts +89 -0
  26. package/src/admin/editor/feature-css.ts +15 -15
  27. package/src/admin/editor/host.ts +33 -0
  28. package/src/admin/editor/icons/IconLibraryDialog.tsx +64 -218
  29. package/src/admin/editor/icons/library.ts +29 -19
  30. package/src/admin/editor/icons/use-icon-library.ts +315 -0
  31. package/src/admin/editor/palette-items.ts +36 -5
  32. package/src/admin/editor/palette.ts +3 -2
  33. package/src/admin/editor/panels/AddPanel.tsx +2 -67
  34. package/src/admin/editor/panels/ColorControl.tsx +2 -10
  35. package/src/admin/editor/panels/ElementPanel.tsx +40 -99
  36. package/src/admin/editor/panels/LayersPanel.tsx +34 -62
  37. package/src/admin/editor/panels/SettingsPanel.tsx +1 -0
  38. package/src/admin/editor/panels/SiteStylesDrawer.tsx +16 -10
  39. package/src/admin/editor/panels/VariableSection.tsx +1 -10
  40. package/src/admin/editor/panels/inline-error.tsx +11 -0
  41. package/src/admin/editor/panels/settings/AdvancedFields.tsx +87 -1
  42. package/src/admin/editor/panels/settings/AudienceEditor.tsx +73 -3
  43. package/src/admin/editor/panels/settings/DraftTextField.tsx +4 -0
  44. package/src/admin/editor/panels/settings/FormBindControl.tsx +8 -4
  45. package/src/admin/editor/panels/settings/ItemList.tsx +34 -1
  46. package/src/admin/editor/panels/settings/StyleRow.tsx +14 -2
  47. package/src/admin/editor/panels/settings/form-names.ts +7 -11
  48. package/src/admin/editor/panels/settings/length-units.ts +15 -4
  49. package/src/admin/editor/panels/settings/style-sections.ts +5 -1
  50. package/src/admin/editor/panels/style-target.ts +105 -0
  51. package/src/admin/editor/section-templates.ts +43 -21
  52. package/src/admin/editor/shortcuts.ts +4 -0
  53. package/src/admin/editor/store.ts +10 -1
  54. package/src/admin/editor/useClipboardActions.ts +1 -1
  55. package/src/admin/editor/useEditorCommands.ts +61 -13
  56. package/src/admin/editor/useEditorData.ts +7 -1
  57. package/src/admin/editor/useEditorShortcuts.ts +23 -15
  58. package/src/admin/editor/useNodeActions.ts +6 -1
  59. package/src/admin/forms-api.ts +17 -6
  60. package/src/admin/icon-uploads-api.ts +18 -0
  61. package/src/admin/theme-api.ts +5 -18
  62. package/src/astro/content-port.ts +24 -0
  63. package/src/astro/forms/EmVBFormsClient.astro +11 -0
  64. package/src/astro/forms/EmVBFormsRuntime.astro +6 -7
  65. package/src/astro/forms/client.ts +1 -0
  66. package/src/astro/forms-definitions.ts +24 -11
  67. package/src/astro/index.ts +1 -0
  68. package/src/astro/render-session.ts +85 -0
  69. package/src/astro/request-data.ts +20 -8
  70. package/src/astro/resolve-theme.ts +166 -76
  71. package/src/astro/resolve.ts +57 -16
  72. package/src/astro/theme-posts.ts +16 -5
  73. package/src/astro/visitor.ts +67 -5
  74. package/src/constants.ts +1 -1
  75. package/src/core/arrange.ts +63 -38
  76. package/src/core/audience/rules.ts +22 -2
  77. package/src/core/canvas-styles.ts +24 -0
  78. package/src/core/clipboard.ts +11 -32
  79. package/src/core/css/generate.ts +9 -0
  80. package/src/core/css/print.ts +12 -0
  81. package/src/core/css/scope.ts +3 -3
  82. package/src/core/css-keywords.ts +83 -0
  83. package/src/core/data/bindings.ts +4 -6
  84. package/src/core/design/classes.ts +13 -15
  85. package/src/core/design/diff.ts +55 -0
  86. package/src/core/design/merge.ts +127 -0
  87. package/src/core/design/variables.ts +25 -21
  88. package/src/core/elements/dynamic-elements.ts +30 -0
  89. package/src/core/elements/form-elements.ts +1 -0
  90. package/src/core/elements/index.ts +183 -7
  91. package/src/core/forms/binding.ts +4 -13
  92. package/src/core/index.ts +10 -0
  93. package/src/core/local-style.ts +27 -0
  94. package/src/core/migrate/index.ts +9 -4
  95. package/src/core/nesting.ts +4 -23
  96. package/src/core/perf/scripts.ts +9 -6
  97. package/src/core/record.ts +3 -0
  98. package/src/core/render/context.ts +2 -0
  99. package/src/core/render/dynamic-post.ts +1 -2
  100. package/src/core/render/form.ts +133 -10
  101. package/src/core/render/index.ts +155 -13
  102. package/src/core/render/vnode.ts +12 -2
  103. package/src/core/sanitize/css.ts +90 -77
  104. package/src/core/sanitize/svg.ts +8 -3
  105. package/src/core/sanitize/url.ts +10 -1
  106. package/src/core/schema/design.ts +5 -7
  107. package/src/core/schema/layout.ts +153 -181
  108. package/src/core/schema/style.ts +53 -63
  109. package/src/core/share/link.ts +68 -28
  110. package/src/core/tabs/presence.ts +7 -17
  111. package/src/core/theme/dynamic.ts +200 -39
  112. package/src/core/theme/float.ts +1 -1
  113. package/src/core/tree-ops.ts +57 -0
  114. package/src/index.ts +14 -2
  115. package/src/server/design-routes.ts +4 -1
  116. package/src/server/icon-routes.ts +68 -16
  117. package/src/server/plugin.ts +8 -2
  118. package/src/admin/editor/icons/sets/fontawesome.json +0 -1
  119. package/src/admin/editor/icons/sets/lucide.json +0 -1
  120. package/src/admin/editor/icons/sets/remix.json +0 -1
  121. package/src/admin/editor/icons/sets/tabler.json +0 -1
@@ -5,6 +5,41 @@ import { themePartLayout } from "../theme-api.ts";
5
5
 
6
6
  const MAX_DEPTH = 8;
7
7
 
8
+ /**
9
+ * Loads section parts one depth at a time. Siblings load together. A part that fails is left out;
10
+ * the ones that loaded stay.
11
+ */
12
+ export async function loadSectionTemplates(
13
+ fetcher: Fetcher,
14
+ ids: readonly string[],
15
+ read: (id: string) => Promise<Layout | null> = (id) => themePartLayout(fetcher, id, "section"),
16
+ ): Promise<Record<string, Layout>> {
17
+ const acc: Record<string, Layout> = {};
18
+ const walk = async (next: readonly string[], depth: number): Promise<void> => {
19
+ if (depth > MAX_DEPTH) return;
20
+ const pending = next.filter((id) => !acc[id]);
21
+ if (pending.length === 0) return;
22
+ const loaded = await Promise.all(
23
+ pending.map(async (id) => {
24
+ try {
25
+ return [id, await read(id)] as const;
26
+ } catch {
27
+ return [id, null] as const;
28
+ }
29
+ }),
30
+ );
31
+ const nested: string[] = [];
32
+ for (const [id, part] of loaded) {
33
+ if (!part || acc[id]) continue;
34
+ acc[id] = part;
35
+ nested.push(...collectSectionPartIds(part));
36
+ }
37
+ await walk(nested, depth + 1);
38
+ };
39
+ await walk(ids, 0);
40
+ return acc;
41
+ }
42
+
8
43
  /** Section theme parts referenced by the open layout, so the canvas shows the synced contents. */
9
44
  export function useSectionTemplates(
10
45
  layout: Layout | null,
@@ -20,27 +55,14 @@ export function useSectionTemplates(
20
55
  return;
21
56
  }
22
57
  let cancelled = false;
23
- const load = async () => {
24
- const acc: Record<string, Layout> = {};
25
- const walk = async (next: string[], depth: number) => {
26
- if (depth > MAX_DEPTH) return;
27
- for (const id of next) {
28
- if (acc[id]) continue;
29
- // Each nested section id comes from the part just loaded.
30
- // oxlint-disable-next-line no-await-in-loop
31
- const part = await themePartLayout(fetcher, id, "section");
32
- if (!part) continue;
33
- acc[id] = part;
34
- // oxlint-disable-next-line no-await-in-loop
35
- await walk(collectSectionPartIds(part), depth + 1);
36
- }
37
- };
38
- await walk(ids, 0);
39
- if (!cancelled) setTemplates(acc);
40
- };
41
- void load().catch(() => {
42
- if (!cancelled) setTemplates({});
43
- });
58
+ void loadSectionTemplates(fetcher, ids).then(
59
+ (acc) => {
60
+ if (!cancelled) setTemplates(acc);
61
+ },
62
+ () => {
63
+ if (!cancelled) setTemplates({});
64
+ },
65
+ );
44
66
  return () => {
45
67
  cancelled = true;
46
68
  };
@@ -19,3 +19,7 @@ export const SHORTCUTS: readonly { action: string; keys: string }[] = [
19
19
  /** Ctrl/Cmd+K opens the host command palette, which would stack over the editor (S0-6). */
20
20
  export const isPaletteShortcut = (event: KeyboardEvent) =>
21
21
  (event.ctrlKey || event.metaKey) && !event.altKey && event.key.toLowerCase() === "k";
22
+
23
+ /** Focus is inside an open dialog, where only Save fires. */
24
+ export const inDialog = (target: EventTarget | null) =>
25
+ !!(target as HTMLElement | null)?.closest?.('[role="dialog"], [role="alertdialog"]');
@@ -29,6 +29,8 @@ export type EditorState = {
29
29
  publishedRevision?: string | null;
30
30
  /** True after a style edit that has not been published. */
31
31
  designUnpublished?: boolean;
32
+ /** Published design, so Publish styles can list what will change (W-340). */
33
+ publishedDesign?: DesignSystem;
32
34
  selectedId: string | null;
33
35
  /** Bumped on every page edit. A save only clears `dirty` if nothing changed while it ran. */
34
36
  version: number;
@@ -65,6 +67,7 @@ export type EditorAction =
65
67
  revision: string | null;
66
68
  publishedRevision: string | null;
67
69
  unpublished: boolean;
70
+ published?: DesignSystem;
68
71
  }
69
72
  | { type: "reset"; state: EditorState };
70
73
 
@@ -225,7 +228,12 @@ export function editorReducer(state: EditorState, action: EditorAction): EditorS
225
228
  designUnpublished: true,
226
229
  };
227
230
  case "publish-design":
228
- return { ...state, designUnpublished: false, publishedRevision: action.revision };
231
+ return {
232
+ ...state,
233
+ designUnpublished: false,
234
+ publishedRevision: action.revision,
235
+ publishedDesign: state.design,
236
+ };
229
237
  case "load-design":
230
238
  return {
231
239
  ...state,
@@ -233,6 +241,7 @@ export function editorReducer(state: EditorState, action: EditorAction): EditorS
233
241
  designRevision: action.revision,
234
242
  publishedRevision: action.publishedRevision,
235
243
  designUnpublished: action.unpublished,
244
+ ...(action.published ? { publishedDesign: action.published } : {}),
236
245
  };
237
246
  case "reset":
238
247
  return action.state;
@@ -19,7 +19,7 @@ import {
19
19
  type PasteMode,
20
20
  } from "../../core/index.ts";
21
21
  import { readClipboardText, useClipboardText, writeClipboardText } from "./clipboard-store.ts";
22
- import { ELEMENT_NAMES } from "./panels/ElementPanel.tsx";
22
+ import { ELEMENT_NAMES } from "./element-chrome.ts";
23
23
  import type { EditorAction, EditorState } from "./store.ts";
24
24
 
25
25
  const NOTICE_TIMEOUT_MS = 4000;
@@ -1,6 +1,11 @@
1
1
  import * as React from "react";
2
2
  import type { createKumoToastManager } from "@cloudflare/kumo";
3
- import { DEVICE_PREVIEW_PX, type DesignSystem, type PopupDevice } from "../../core/index.ts";
3
+ import {
4
+ DEVICE_PREVIEW_PX,
5
+ mergeDesign,
6
+ type DesignSystem,
7
+ type PopupDevice,
8
+ } from "../../core/index.ts";
4
9
  import { PAGES_COLLECTION, THEME_PARTS_COLLECTION } from "../../constants.ts";
5
10
  import { ApiError, type Fetcher } from "../api.ts";
6
11
  import { previewUrl, publishDesign, saveDesign } from "../content-api.ts";
@@ -138,27 +143,68 @@ export function useEditorCommands({
138
143
  previewWindowFeatures(device),
139
144
  );
140
145
 
141
- const changeDesign = async (next: DesignSystem) => {
146
+ // W-325: design saves run one at a time, each against the newest revision, like page saves.
147
+ // Two quick edits used to both send the revision the editor started with, so the second one
148
+ // was refused with a 409 by the first. `written` remembers the revision a save produced until
149
+ // the store catches up (the ref updates on the next render).
150
+ const designQueue = React.useRef<Promise<unknown>>(Promise.resolve());
151
+ const written = React.useRef<{ from: string | null; to: string } | null>(null);
152
+ const baseRevision = () => {
153
+ const current = latest.current.designRevision;
154
+ const last = written.current;
155
+ return last && last.from === current ? last.to : current;
156
+ };
157
+ const queueDesign = <T>(task: () => Promise<T>): Promise<T> => {
158
+ const run = designQueue.current.then(task, task);
159
+ designQueue.current = run.catch(() => undefined);
160
+ return run;
161
+ };
162
+
163
+ const changeDesign = (next: DesignSystem) => queueDesign(() => saveDesignNow(next));
164
+
165
+ const saveDesignNow = async (next: DesignSystem) => {
142
166
  try {
143
- const revision = await saveDesign(fetcher, next, latest.current.designRevision);
167
+ const from = latest.current.designRevision;
168
+ const revision = await saveDesign(fetcher, next, baseRevision());
169
+ written.current = { from, to: revision };
144
170
  dispatch({ type: "set-design", design: next, revision });
145
171
  } catch (error) {
172
+ written.current = null;
146
173
  if (error instanceof ApiError && error.status === 409) {
147
- // W-212: take the styles saved elsewhere (another editor tab, say), so the next change
148
- // can save, instead of every change failing until a reload that drops page edits.
174
+ // W-333: replay this tab's edit onto the styles saved elsewhere when those keys
175
+ // were not also changed there. A real clash still loads the server copy (W-212).
149
176
  try {
150
177
  const fresh = await loadDesign(fetcher);
151
- dispatch({ type: "load-design", ...fresh });
152
- } catch {
178
+ const merged = mergeDesign(latest.current.design, next, fresh.design);
179
+ const names = merged.conflicts.map((conflict) => conflict.name).join(", ");
180
+ if (merged.conflicts.length > 0) {
181
+ dispatch({ type: "load-design", ...fresh });
182
+ throw new Error(
183
+ `Site styles were changed in another tab or window (${names}). The latest styles are loaded now: make your change again.`,
184
+ { cause: error },
185
+ );
186
+ }
187
+ const unchanged = JSON.stringify(merged.design) === JSON.stringify(fresh.design);
188
+ if (unchanged) {
189
+ dispatch({ type: "load-design", ...fresh });
190
+ return;
191
+ }
192
+ const revision = await saveDesign(fetcher, merged.design, fresh.revision);
193
+ written.current = { from: latest.current.designRevision, to: revision };
194
+ dispatch({ type: "set-design", design: merged.design, revision });
195
+ return;
196
+ } catch (retry) {
197
+ if (
198
+ retry instanceof Error &&
199
+ retry.message.includes("The latest styles are loaded now")
200
+ ) {
201
+ throw retry;
202
+ }
153
203
  throw new Error(
154
204
  "Site styles were changed somewhere else. Reload the editor and try again.",
155
- { cause: error },
205
+ { cause: retry },
156
206
  );
157
207
  }
158
- throw new Error(
159
- "Site styles were changed in another tab or window. The latest styles are loaded now: make your change again.",
160
- { cause: error },
161
- );
162
208
  }
163
209
  throw new Error(
164
210
  error instanceof ApiError
@@ -169,7 +215,9 @@ export function useEditorCommands({
169
215
  }
170
216
  };
171
217
 
172
- const publishStyles = async () => {
218
+ const publishStyles = () => queueDesign(publishStylesNow);
219
+
220
+ const publishStylesNow = async () => {
173
221
  try {
174
222
  const revision = await publishDesign(fetcher, latest.current.publishedRevision ?? null);
175
223
  dispatch({ type: "publish-design", revision });
@@ -43,6 +43,8 @@ export type EditorEntry = {
43
43
 
44
44
  export type LoadedDesign = {
45
45
  design: DesignSystem;
46
+ /** The published design, for the Publish styles diff (W-340). Absent on an older response. */
47
+ published?: DesignSystem;
46
48
  revision: string | null;
47
49
  publishedRevision: string | null;
48
50
  unpublished: boolean;
@@ -148,13 +150,17 @@ function readLayout(raw: unknown): Layout | null {
148
150
  export async function loadDesign(fetcher: Fetcher): Promise<LoadedDesign> {
149
151
  const body = await requestJson<{
150
152
  design?: unknown;
153
+ published?: unknown;
151
154
  revision?: string | null;
152
155
  publishedRevision?: string | null;
153
156
  unpublished?: boolean;
154
157
  }>(fetcher, `/_emdash/api/plugins/${PLUGIN_ID}/design/draft`);
155
158
  const result = validateDesign(body?.design);
159
+ const published = validateDesign(body?.published);
160
+ const design = result.ok ? result.design : emptyDesign();
156
161
  return {
157
- design: result.ok ? result.design : emptyDesign(),
162
+ design,
163
+ ...(published.ok ? { published: published.design } : {}),
158
164
  revision: body?.revision ?? null,
159
165
  publishedRevision: body?.publishedRevision ?? null,
160
166
  unpublished: body?.unpublished === true,
@@ -11,8 +11,9 @@ import {
11
11
  parentOf,
12
12
  previousInOrder,
13
13
  } from "../../core/index.ts";
14
+ import { runCommand, type CommandRunners } from "./editor-commands.ts";
14
15
  import type { EditorState, HistoryAction } from "./store.ts";
15
- import { isPaletteShortcut } from "./shortcuts.ts";
16
+ import { inDialog, isPaletteShortcut } from "./shortcuts.ts";
16
17
 
17
18
  const isTextField = (target: EventTarget | null) => {
18
19
  const element = target as HTMLElement | null;
@@ -24,9 +25,6 @@ const isTextField = (target: EventTarget | null) => {
24
25
  );
25
26
  };
26
27
 
27
- const inDialog = (target: EventTarget | null) =>
28
- !!(target as HTMLElement | null)?.closest?.('[role="dialog"], [role="alertdialog"]');
29
-
30
28
  /**
31
29
  * Element shortcuts (traverse, arrange, delete, duplicate, copy, paste, Escape) act only from the
32
30
  * canvas, Layers, or with nothing focused, never from the settings panel, its tabs and section
@@ -99,9 +97,10 @@ export type ShortcutHandlers = {
99
97
 
100
98
  /**
101
99
  * Window-level editor shortcuts (W-020): save, undo and redo (W-095), duplicate, copy and paste
102
- * (W-093), delete, escape, arrange and traverse. Inside text fields and dialogs only Save works, so
103
- * typing, native undo, copy and paste keep working there. Element shortcuts also need focus on
104
- * the canvas, Layers, or nothing (W-132); Save, undo and redo work from the panels too.
100
+ * (W-093), delete, escape, arrange and traverse. Inside text fields only Save and the palette work,
101
+ * and inside dialogs only Save, so typing, native undo, copy and paste keep working there. Element
102
+ * shortcuts also need focus on the canvas, Layers, or nothing (W-132); Save, undo and redo work
103
+ * from the panels too.
105
104
  */
106
105
  export function useEditorShortcuts({
107
106
  latest,
@@ -113,6 +112,16 @@ export function useEditorShortcuts({
113
112
  handlers: React.RefObject<ShortcutHandlers>;
114
113
  }): (event: KeyboardEvent) => void {
115
114
  const onKeyDown = React.useCallback((event: KeyboardEvent) => {
115
+ const runners = (): CommandRunners => ({
116
+ save: () => handlers.current.save(),
117
+ remove: handlers.current.remove,
118
+ duplicate: handlers.current.duplicate,
119
+ copy: handlers.current.copy,
120
+ paste: handlers.current.paste,
121
+ pasteStyle: handlers.current.pasteStyle,
122
+ undo: () => dispatch({ type: "undo" }),
123
+ redo: () => dispatch({ type: "redo" }),
124
+ });
116
125
  if (isPaletteShortcut(event)) {
117
126
  event.preventDefault();
118
127
  handlers.current.palette?.();
@@ -120,18 +129,18 @@ export function useEditorShortcuts({
120
129
  }
121
130
  if ((event.ctrlKey || event.metaKey) && event.key.toLowerCase() === "s") {
122
131
  event.preventDefault();
123
- void handlers.current.save();
132
+ runCommand(runners(), "save", null);
124
133
  return;
125
134
  }
126
135
  if (isTextField(event.target) || inDialog(event.target)) return;
127
136
  if ((event.ctrlKey || event.metaKey) && !event.altKey && event.key.toLowerCase() === "z") {
128
137
  event.preventDefault();
129
- dispatch(event.shiftKey ? { type: "redo" } : { type: "undo" });
138
+ runCommand(runners(), event.shiftKey ? "redo" : "undo", null);
130
139
  return;
131
140
  }
132
141
  if ((event.ctrlKey || event.metaKey) && !event.altKey && event.key.toLowerCase() === "y") {
133
142
  event.preventDefault();
134
- dispatch({ type: "redo" });
143
+ runCommand(runners(), "redo", null);
135
144
  return;
136
145
  }
137
146
  if (!onCanvasOrLayers(event.target)) return;
@@ -139,20 +148,19 @@ export function useEditorShortcuts({
139
148
  const selected = latest.current.selectedId;
140
149
  if ((event.ctrlKey || event.metaKey) && event.key.toLowerCase() === "d" && selected) {
141
150
  event.preventDefault();
142
- handlers.current.duplicate(selected);
151
+ runCommand(runners(), "duplicate", selected);
143
152
  return;
144
153
  }
145
154
  const clipKey =
146
155
  (event.ctrlKey || event.metaKey) && !event.altKey ? event.key.toLowerCase() : "";
147
156
  if (clipKey === "c" && !event.shiftKey && selected && !hasTextSelection(event.target)) {
148
157
  event.preventDefault();
149
- handlers.current.copy(selected);
158
+ runCommand(runners(), "copy", selected);
150
159
  return;
151
160
  }
152
161
  if (clipKey === "v" && layout) {
153
162
  event.preventDefault();
154
- if (event.shiftKey) handlers.current.pasteStyle(selected);
155
- else handlers.current.paste(selected);
163
+ runCommand(runners(), event.shiftKey ? "paste-style" : "paste", selected);
156
164
  return;
157
165
  }
158
166
  if (event.key === "Escape" && selected) {
@@ -161,7 +169,7 @@ export function useEditorShortcuts({
161
169
  }
162
170
  if ((event.key === "Delete" || event.key === "Backspace") && selected) {
163
171
  event.preventDefault();
164
- handlers.current.remove(selected);
172
+ runCommand(runners(), "delete", selected);
165
173
  return;
166
174
  }
167
175
  if (!layout || !selected) return;
@@ -5,6 +5,8 @@ import {
5
5
  addNodeNear,
6
6
  addSectionNear,
7
7
  duplicateNode,
8
+ wrapNode,
9
+ type WrapType,
8
10
  ELEMENT_DESCRIPTORS,
9
11
  findNode,
10
12
  moveDown,
@@ -18,7 +20,7 @@ import {
18
20
  type LayoutNode,
19
21
  } from "../../core/index.ts";
20
22
  import { newElement } from "./dnd/new-element.ts";
21
- import { ELEMENT_NAMES } from "./panels/ElementPanel.tsx";
23
+ import { ELEMENT_NAMES } from "./element-chrome.ts";
22
24
  import type { ItemActions } from "./panels/settings/ItemList.tsx";
23
25
  import type { EditorAction, EditorState } from "./store.ts";
24
26
 
@@ -109,6 +111,8 @@ export function useNodeActions({
109
111
  };
110
112
 
111
113
  const duplicate = (id: string) => arrange(id, duplicateNode);
114
+ const wrap = (id: string, type: WrapType) =>
115
+ arrange(id, (layout, nodeId) => wrapNode(layout, nodeId, type));
112
116
 
113
117
  /** Accordion and Tabs item list (W-130): the parent stays selected so the list stays open. */
114
118
  const items: ItemActions = {
@@ -200,6 +204,7 @@ export function useNodeActions({
200
204
  remove,
201
205
  arrange,
202
206
  duplicate,
207
+ wrap,
203
208
  addFromPanel,
204
209
  addRecipe,
205
210
  items,
@@ -1,6 +1,12 @@
1
1
  import { ApiError, requestJson, type Fetcher } from "./api.ts";
2
2
 
3
- export type FormListItem = { id: string; name: string; slug: string };
3
+ export type FormListItem = {
4
+ id: string;
5
+ name: string;
6
+ slug: string;
7
+ /** The forms plugin's "paused" status: the form isn't accepting responses (W-326). */
8
+ paused?: boolean;
9
+ };
4
10
 
5
11
  export type FormsCapability =
6
12
  | { status: "ready"; forms: FormListItem[]; canList: true }
@@ -29,6 +35,8 @@ async function formsPluginAnswers(fetcher: Fetcher): Promise<boolean> {
29
35
  await requestJson(fetcher, DEFINITION, { method: "POST", body: { id: "__emvb_probe__" } });
30
36
  return true;
31
37
  } catch (error) {
38
+ // A 200 with no body still means the route answered. An empty list is handled above.
39
+ if (error instanceof ApiError && error.code === "MISSING_DATA") return true;
32
40
  return probeFoundPlugin(error);
33
41
  }
34
42
  }
@@ -36,11 +44,14 @@ async function formsPluginAnswers(fetcher: Fetcher): Promise<boolean> {
36
44
  /** Probe forms plugin + list (admin). Editors get manual-id fallback (D-015). */
37
45
  export async function loadFormsCapability(fetcher: Fetcher): Promise<FormsCapability> {
38
46
  try {
39
- const data = await requestJson<{ items: FormListItem[] }>(fetcher, LIST, {
40
- method: "POST",
41
- body: {},
42
- });
43
- const forms = (data.items ?? []).map(({ id, name, slug }) => ({ id, name, slug }));
47
+ const data = await requestJson<{ items: (FormListItem & { status?: unknown })[] }>(
48
+ fetcher,
49
+ LIST,
50
+ { method: "POST", body: {} },
51
+ );
52
+ const forms = (data.items ?? []).map(({ id, name, slug, status }) =>
53
+ status === "paused" ? { id, name, slug, paused: true } : { id, name, slug },
54
+ );
44
55
  return { status: "ready", canList: true, forms };
45
56
  } catch (error) {
46
57
  if (error instanceof ApiError && (error.status === 401 || error.status === 403)) {
@@ -42,3 +42,21 @@ export async function uploadIconFile(
42
42
  { method: "POST", body: { name: file.name, svg } },
43
43
  );
44
44
  }
45
+
46
+ /** Renames an upload in My uploads. Icons already on a page keep the SVG they stored. */
47
+ export async function renameUploadedIcon(
48
+ fetcher: Fetcher,
49
+ id: string,
50
+ name: string,
51
+ ): Promise<UploadedIconItem> {
52
+ const data = await requestJson<{ item: UploadedIconItem }>(fetcher, `${BASE}/icons/rename`, {
53
+ method: "POST",
54
+ body: { id, name },
55
+ });
56
+ return data.item;
57
+ }
58
+
59
+ /** Removes an upload from My uploads. Placed icons are unchanged. */
60
+ export async function deleteUploadedIcon(fetcher: Fetcher, id: string): Promise<void> {
61
+ await requestJson(fetcher, `${BASE}/icons/delete`, { method: "POST", body: { id } });
62
+ }
@@ -15,20 +15,12 @@ import {
15
15
  } from "../core/index.ts";
16
16
  import { THEME_PARTS_COLLECTION } from "../constants.ts";
17
17
  import { listAllItems, requestJson, type Fetcher } from "./api.ts";
18
+ import { titleOf, type ContentItem } from "./content-item.ts";
18
19
  import { publishEntry } from "./content-api.ts";
19
20
  import { entryStatus } from "./entry-status.ts";
20
21
 
21
22
  const CONTENT = `/_emdash/api/content/${THEME_PARTS_COLLECTION}`;
22
23
 
23
- type RawItem = {
24
- id: string;
25
- slug?: string | null;
26
- status?: string;
27
- draftRevisionId?: string | null;
28
- updatedAt?: string;
29
- data?: Record<string, unknown>;
30
- };
31
-
32
24
  export type ThemePartSummary = {
33
25
  id: string;
34
26
  title: string;
@@ -48,12 +40,7 @@ export type ThemePartDraft = {
48
40
  layout: Layout | null;
49
41
  };
50
42
 
51
- const titleOf = (item: RawItem) =>
52
- typeof item.data?.["title"] === "string" && item.data["title"]
53
- ? item.data["title"]
54
- : "Untitled theme part";
55
-
56
- function partTypeOf(item: RawItem): ThemePartType {
43
+ function partTypeOf(item: ContentItem): ThemePartType {
57
44
  return parseThemePartType(item.data?.["part_type"]) ?? "header";
58
45
  }
59
46
 
@@ -132,10 +119,10 @@ export function summarizeConditions(raw: unknown): string {
132
119
  }
133
120
 
134
121
  export async function listThemeParts(fetcher: Fetcher): Promise<ThemePartSummary[]> {
135
- const items = await listAllItems<RawItem>(fetcher, CONTENT);
122
+ const items = await listAllItems<ContentItem>(fetcher, CONTENT);
136
123
  return items.map((item) => ({
137
124
  id: item.id,
138
- title: titleOf(item),
125
+ title: titleOf(item, "Untitled theme part"),
139
126
  partType: partTypeOf(item),
140
127
  status: entryStatus(item),
141
128
  updatedAt: item.updatedAt ?? "",
@@ -164,7 +151,7 @@ export async function createThemePart(
164
151
  fetcher: Fetcher,
165
152
  input: { title: string; slug: string; partType: ThemePartType },
166
153
  ): Promise<string> {
167
- const body = await requestJson<{ item: RawItem }>(fetcher, CONTENT, {
154
+ const body = await requestJson<{ item: ContentItem }>(fetcher, CONTENT, {
168
155
  method: "POST",
169
156
  body: {
170
157
  data: {
@@ -0,0 +1,24 @@
1
+ import { decodeSlug, getEmDashCollection, getEmDashEntry, getSiteSettings, getTerm } from "emdash";
2
+ import { getPublicPluginApiRouteHandler } from "emdash/plugin-utils";
3
+
4
+ /**
5
+ * How the Astro adapter reads EmDash content (W-359). The default calls EmDash.
6
+ * Tests pass a fake. This is not a host export.
7
+ */
8
+ export type ContentPort = {
9
+ decodeSlug: typeof decodeSlug;
10
+ getEntry: typeof getEmDashEntry;
11
+ getCollection: typeof getEmDashCollection;
12
+ getTerm: typeof getTerm;
13
+ getSiteSettings: typeof getSiteSettings;
14
+ pluginHandler: typeof getPublicPluginApiRouteHandler;
15
+ };
16
+
17
+ export const emdashContent: ContentPort = {
18
+ decodeSlug,
19
+ getEntry: getEmDashEntry,
20
+ getCollection: getEmDashCollection,
21
+ getTerm,
22
+ getSiteSettings,
23
+ pluginHandler: getPublicPluginApiRouteHandler,
24
+ };
@@ -0,0 +1,11 @@
1
+ ---
2
+ // The forms plugin's client script (D-015). Rendered only by hosts that import
3
+ // `@perkyzz/emvb/astro/forms/client` and have `@emdash-cms/plugin-forms` installed.
4
+ // It loads on pages that contain a form (R-031); other pages never render this component.
5
+ ---
6
+
7
+ <script>
8
+ import { initForms } from "@emdash-cms/plugin-forms/client";
9
+
10
+ initForms();
11
+ </script>
@@ -1,9 +1,8 @@
1
1
  ---
2
- // The forms plugin's client (D-015). Hosts render this only when a page `needsFormsRuntime`,
3
- // so pages without forms stay zero-JS (R-031). Form elements arrive in S5.
2
+ /**
3
+ * Safe forms slot (W-332). This file does not import `@emdash-cms/plugin-forms`.
4
+ * A host without that plugin can import `@perkyzz/emvb/astro/forms` and the build still succeeds.
5
+ * Hosts that have the plugin import `@perkyzz/emvb/astro/forms/client` instead, which calls
6
+ * `initForms`. Rendering this component does nothing.
7
+ */
4
8
  ---
5
-
6
- <script>
7
- import { initForms } from "@emdash-cms/plugin-forms/client";
8
- initForms();
9
- </script>
@@ -0,0 +1 @@
1
+ export { default as EmVBFormsRuntime } from "./EmVBFormsClient.astro";
@@ -3,29 +3,31 @@ import {
3
3
  isFormNode,
4
4
  type FormDefinitions,
5
5
  type Layout,
6
- type LayoutNode,
7
6
  type PublicFormDefinition,
8
7
  type PublicFormField,
9
8
  } from "../core/index.ts";
10
- import { nodeChildren } from "../core/tree-ops.ts";
9
+ import { isRecord } from "../core/record.ts";
10
+ import { forEachNode } from "../core/tree-ops.ts";
11
11
 
12
12
  const FORMS_PLUGIN = "emdash-forms";
13
13
 
14
- function walk(node: LayoutNode, visit: (node: LayoutNode) => void): void {
15
- visit(node);
16
- for (const child of nodeChildren(node)) walk(child, visit);
17
- }
18
-
19
14
  export function formIdsInLayout(layout: Layout): string[] {
20
15
  const ids = new Set<string>();
21
- walk(layout.root, (node) => {
16
+ forEachNode(layout.root, (node) => {
22
17
  if (isFormNode(node) && node.props.formId) ids.add(node.props.formId);
23
18
  });
24
19
  return [...ids];
25
20
  }
26
21
 
27
- const isRecord = (value: unknown): value is Record<string, unknown> =>
28
- !!value && typeof value === "object" && !Array.isArray(value);
22
+ /** Form ids in a page and in the synced sections and loop items it renders. */
23
+ export function formIdsInLayouts(layouts: readonly (Layout | null | undefined)[]): string[] {
24
+ const ids = new Set<string>();
25
+ for (const layout of layouts) {
26
+ if (!layout) continue;
27
+ for (const id of formIdsInLayout(layout)) ids.add(id);
28
+ }
29
+ return [...ids];
30
+ }
29
31
 
30
32
  const isOption = (value: unknown): value is { label: string; value: string } =>
31
33
  isRecord(value) && typeof value.label === "string" && typeof value.value === "string";
@@ -95,6 +97,17 @@ function asDefinition(payload: unknown): PublicFormDefinition | null {
95
97
  return { ...(def as PublicFormDefinition), pages, settings };
96
98
  }
97
99
 
100
+ /**
101
+ * W-326: the forms plugin answers a paused form's definition with `FORM_PAUSED` (410), so the
102
+ * page can say the form isn't accepting responses instead of rendering empty fields.
103
+ */
104
+ function asPaused(payload: unknown, formId: string): PublicFormDefinition | null {
105
+ if (!isRecord(payload) || payload.success !== false) return null;
106
+ const error = isRecord(payload.error) ? payload.error : {};
107
+ if (error.code !== "FORM_PAUSED" && payload.status !== 410) return null;
108
+ return { name: "", slug: formId, status: "paused", pages: [], settings: {} };
109
+ }
110
+
98
111
  /** Loads public form definitions in-process (D-015). Missing forms are omitted. */
99
112
  export async function loadFormDefinitions(
100
113
  handler: PublicPluginApiRouteHandler | undefined,
@@ -115,7 +128,7 @@ export async function loadFormDefinitions(
115
128
  },
116
129
  );
117
130
  const response = await handler(FORMS_PLUGIN, "POST", "/definition", request);
118
- const def = asDefinition(response);
131
+ const def = asDefinition(response) ?? asPaused(response, formId);
119
132
  if (def) map.set(formId, def);
120
133
  } catch {
121
134
  // Forms plugin missing or form unknown — render without definition options.
@@ -1,5 +1,6 @@
1
1
  export { default as EmVBPage } from "./EmVBPage.astro";
2
2
  export { resolveEmVBPage, type ResolvedEmVBPage } from "./resolve.ts";
3
+ export type { HostVisitor } from "./visitor.ts";
3
4
  export {
4
5
  resolveThemeParts,
5
6
  type RenderedThemePart,