@perkyzz/emvb 1.3.0 → 1.4.1

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 (161) hide show
  1. package/README.md +2 -2
  2. package/package.json +2 -2
  3. package/src/admin/bulk-api.ts +5 -1
  4. package/src/admin/content-item.ts +3 -0
  5. package/src/admin/copy-rich-text.ts +99 -9
  6. package/src/admin/editor/A11yCopilot.tsx +3 -1
  7. package/src/admin/editor/Editor.tsx +28 -3
  8. package/src/admin/editor/Timeline.tsx +1 -8
  9. package/src/admin/editor/canvas/DeviceBar.tsx +7 -2
  10. package/src/admin/editor/canvas/EmptyCanvas.tsx +11 -2
  11. package/src/admin/editor/canvas/use-canvas-dnd.ts +1 -20
  12. package/src/admin/editor/canvas/vnode-react.tsx +2 -0
  13. package/src/admin/editor/co-design.ts +36 -1
  14. package/src/admin/editor/collection-previews.ts +7 -8
  15. package/src/admin/editor/dnd/dragged-source.ts +22 -0
  16. package/src/admin/editor/dnd/layer-drop.ts +141 -0
  17. package/src/admin/editor/dnd/new-element.ts +16 -0
  18. package/src/admin/editor/editor-css.ts +9 -1
  19. package/src/admin/editor/element-chrome.ts +6 -0
  20. package/src/admin/editor/extensions/ExtensionPanels.tsx +33 -1
  21. package/src/admin/editor/extensions-context.tsx +16 -1
  22. package/src/admin/editor/feature-css.ts +27 -0
  23. package/src/admin/editor/inert-links.ts +8 -0
  24. package/src/admin/editor/panels/ColorControl.tsx +2 -2
  25. package/src/admin/editor/panels/ConditionsEditor.tsx +18 -0
  26. package/src/admin/editor/panels/ElementPanel.tsx +2 -2
  27. package/src/admin/editor/panels/FontFaces.tsx +342 -0
  28. package/src/admin/editor/panels/LayersPanel.tsx +56 -6
  29. package/src/admin/editor/panels/LeftPanel.tsx +153 -29
  30. package/src/admin/editor/panels/SettingsPanel.tsx +1 -0
  31. package/src/admin/editor/panels/SiteStylesDrawer.tsx +5 -0
  32. package/src/admin/editor/panels/TemplatesPanel.tsx +205 -0
  33. package/src/admin/editor/panels/TokenScales.tsx +2 -0
  34. package/src/admin/editor/panels/TriggersEditor.tsx +203 -9
  35. package/src/admin/editor/panels/VariableSection.tsx +111 -7
  36. package/src/admin/editor/panels/color-space.ts +71 -6
  37. package/src/admin/editor/panels/settings/AudienceEditor.tsx +3 -0
  38. package/src/admin/editor/panels/settings/FieldControl.tsx +33 -0
  39. package/src/admin/editor/panels/settings/FormBindControl.tsx +27 -31
  40. package/src/admin/editor/panels/settings/ImageFieldControl.tsx +106 -0
  41. package/src/admin/editor/panels/settings/LoopItemBindControl.tsx +9 -3
  42. package/src/admin/editor/panels/settings/StickyControl.tsx +97 -0
  43. package/src/admin/editor/panels/settings/StyleRow.tsx +14 -0
  44. package/src/admin/editor/panels/settings/loop-context.ts +34 -3
  45. package/src/admin/editor/panels/settings/style-sections.ts +19 -2
  46. package/src/admin/editor/panels/url-rules.ts +43 -0
  47. package/src/admin/editor/panels/use-layers-drop.ts +232 -0
  48. package/src/admin/editor/store.ts +4 -2
  49. package/src/admin/editor/useExtensions.ts +3 -1
  50. package/src/admin/editor/useNodeActions.ts +74 -1
  51. package/src/admin/editor/useSave.ts +116 -85
  52. package/src/admin/export-api.ts +27 -2
  53. package/src/admin/extension-outputs.ts +236 -0
  54. package/src/admin/font-files-api.ts +38 -0
  55. package/src/admin/import-forms.ts +133 -0
  56. package/src/admin/pages/ImportButton.tsx +15 -4
  57. package/src/admin/pages/ImportElementorDialog.tsx +53 -187
  58. package/src/admin/pages/ImportForms.tsx +71 -0
  59. package/src/admin/pages/ImportHtmlDialog.tsx +209 -0
  60. package/src/admin/pages/ImportImageCopies.tsx +167 -0
  61. package/src/admin/pages/ImportReport.tsx +63 -0
  62. package/src/admin/pages/NewPageDialog.tsx +54 -32
  63. package/src/admin/pages/PageList.tsx +9 -0
  64. package/src/admin/pages/ThemePartList.tsx +9 -0
  65. package/src/admin/setup/plan.ts +2 -0
  66. package/src/admin/ui.ts +7 -0
  67. package/src/admin/widgets/ConvertToRichText.tsx +3 -2
  68. package/src/astro/EmVBPage.astro +5 -2
  69. package/src/astro/extension-styles.ts +35 -0
  70. package/src/astro/forms/EmVBFormsClient.astro +3 -0
  71. package/src/astro/forms/enhance.ts +107 -0
  72. package/src/astro/popups/runtime.ts +47 -2
  73. package/src/astro/render.ts +25 -4
  74. package/src/astro/resolve-theme.ts +11 -4
  75. package/src/astro/resolve.ts +2 -0
  76. package/src/astro/theme-posts.ts +17 -23
  77. package/src/astro/visitor.ts +14 -5
  78. package/src/astro/widgets/EmVBStickyRuntime.astro +9 -0
  79. package/src/astro/widgets/EmVBThemeRuntime.astro +9 -0
  80. package/src/astro/widgets/EmVBWidgetRuntimes.astro +12 -0
  81. package/src/astro/widgets/alerts.ts +16 -2
  82. package/src/astro/widgets/carousel.ts +65 -24
  83. package/src/astro/widgets/countdown.ts +18 -7
  84. package/src/astro/widgets/extension-runtimes.ts +27 -0
  85. package/src/astro/widgets/headline.ts +14 -5
  86. package/src/astro/widgets/sticky.ts +87 -0
  87. package/src/astro/widgets/theme.ts +52 -0
  88. package/src/constants.ts +1 -1
  89. package/src/core/a11y/audit.ts +150 -2
  90. package/src/core/arrange.ts +19 -1
  91. package/src/core/css/font-face.ts +72 -0
  92. package/src/core/css/generate.ts +41 -2
  93. package/src/core/css/trace.ts +8 -0
  94. package/src/core/data/bindings.ts +7 -4
  95. package/src/core/elements/dynamic-elements.ts +1 -1
  96. package/src/core/elements/element-nouns.ts +48 -0
  97. package/src/core/elements/form-elements.ts +119 -9
  98. package/src/core/elements/icon-svg.ts +14 -0
  99. package/src/core/elements/index.ts +24 -4
  100. package/src/core/elements/input-limits.ts +44 -0
  101. package/src/core/elements/menu.ts +109 -47
  102. package/src/core/elements/site.ts +108 -0
  103. package/src/core/elements/widgets.ts +13 -3
  104. package/src/core/export/runtimes.generated.ts +7 -5
  105. package/src/core/export/site.ts +53 -4
  106. package/src/core/extensions/classes.ts +114 -0
  107. package/src/core/extensions/index.ts +19 -2
  108. package/src/core/extensions/normalize.ts +13 -0
  109. package/src/core/extensions/placeholder.ts +7 -2
  110. package/src/core/extensions/registry.ts +134 -10
  111. package/src/core/extensions/render-ext.ts +115 -36
  112. package/src/core/extensions/safe-nodes.ts +67 -11
  113. package/src/core/extensions/types.ts +48 -1
  114. package/src/core/fonts/files.ts +74 -0
  115. package/src/core/fonts/google.ts +112 -0
  116. package/src/core/fonts/test-font.ts +9 -0
  117. package/src/core/import/elementor/context.ts +42 -4
  118. package/src/core/import/elementor/index.ts +55 -23
  119. package/src/core/import/elementor/widgets.ts +242 -20
  120. package/src/core/import/html/blocks.ts +602 -0
  121. package/src/core/import/html/index.ts +155 -0
  122. package/src/core/import/html/map.ts +958 -0
  123. package/src/core/import/html/parse.ts +430 -0
  124. package/src/core/index.ts +54 -0
  125. package/src/core/migrate/v18.ts +3 -0
  126. package/src/core/public-attributes.ts +17 -0
  127. package/src/core/render/extras.ts +31 -7
  128. package/src/core/render/form.ts +103 -10
  129. package/src/core/render/index.ts +165 -16
  130. package/src/core/render/section.ts +31 -1
  131. package/src/core/render/spacer-basis.ts +102 -0
  132. package/src/core/render/theme-boot.ts +16 -0
  133. package/src/core/render/vnode.ts +1 -1
  134. package/src/core/sanitize/css.ts +68 -3
  135. package/src/core/sanitize/motion.ts +12 -0
  136. package/src/core/schema/design.ts +40 -0
  137. package/src/core/schema/layout.ts +118 -6
  138. package/src/core/schema/style.ts +28 -0
  139. package/src/core/templates/index.ts +218 -0
  140. package/src/core/templates/pages.ts +29 -0
  141. package/src/core/templates/sections.ts +794 -0
  142. package/src/core/templates/types.ts +9 -0
  143. package/src/core/theme/dynamic.ts +9 -6
  144. package/src/core/theme/media-value.ts +88 -0
  145. package/src/core/theme/popup-markup.ts +21 -2
  146. package/src/core/theme/popup-rules.ts +36 -0
  147. package/src/core/theme/triggers.ts +64 -5
  148. package/src/core/translatable.ts +5 -2
  149. package/src/core/visitor-cookie.ts +91 -0
  150. package/src/extension-build.ts +331 -0
  151. package/src/index.ts +53 -4
  152. package/src/mcp/agent-defaults.ts +40 -0
  153. package/src/mcp/brief.ts +191 -0
  154. package/src/mcp/extensions.ts +138 -0
  155. package/src/mcp/prompts.ts +33 -0
  156. package/src/mcp/read.ts +84 -20
  157. package/src/mcp/tools.ts +42 -3
  158. package/src/mcp/write.ts +124 -9
  159. package/src/server/extension-routes.ts +110 -0
  160. package/src/server/font-routes.ts +301 -0
  161. package/src/server/plugin.ts +15 -0
package/README.md CHANGED
@@ -11,7 +11,7 @@
11
11
 
12
12
  [![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)
13
13
 
14
- A visual page builder plugin for [EmDash CMS](https://github.com/emdash-cms/emdash) 1.0–1.4 (built and tested on 1.4.0). Pages are built in a full-screen editor inside the EmDash admin and published as plain HTML and CSS. It runs on Node (SQLite) and Cloudflare Workers (D1).
14
+ A visual page builder plugin for [EmDash CMS](https://github.com/emdash-cms/emdash) 1.4 and 1.5 (built and tested on 1.5.0, tested on 1.4.0). Pages are built in a full-screen editor inside the EmDash admin and published as plain HTML and CSS. It runs on Node (SQLite) and Cloudflare Workers (D1).
15
15
 
16
16
  ![The EmVB editor](https://raw.githubusercontent.com/PerkyZZ999/EmVB/main/site/public/screenshots/editor-1600.webp)
17
17
 
@@ -25,7 +25,7 @@ Library pictures can be cropped, adjusted, filtered and saved as a new media ite
25
25
  npm i @perkyzz/emvb
26
26
  ```
27
27
 
28
- 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. Use the Astro version your EmDash site already has: EmVB is verified on a stock `create-emdash` 1.4.0 site, which installs Astro 7.4.7.
28
+ Peers, which an EmDash 1.4 or 1.5 site already has: `emdash` >=1.4.0 <2, `astro` ^7, `react` and `react-dom` ^19, `@cloudflare/kumo` 2.6.0 (EmDash 1.4) or 2.15.0 (EmDash 1.5) and `@phosphor-icons/react` ^2.1.10. `@emdash-cms/plugin-forms` is optional and enables forms: 0.2.13 on EmDash 1.5, 0.2.9 to 0.2.12 on EmDash 1.4. Use the Astro version your EmDash site already has: each release is installed on stock `create-emdash` sites of EmDash 1.4.0 and 1.5.0.
29
29
 
30
30
  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.
31
31
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@perkyzz/emvb",
3
- "version": "1.3.0",
3
+ "version": "1.4.1",
4
4
  "description": "Visual page builder plugin for EmDash CMS",
5
5
  "keywords": [
6
6
  "astro",
@@ -50,7 +50,7 @@
50
50
  "test:astro": "bun --bun vitest run"
51
51
  },
52
52
  "dependencies": {
53
- "@perkyzz/emvb-icons": "1.3.0",
53
+ "@perkyzz/emvb-icons": "1.4.1",
54
54
  "photocn": "0.1.2",
55
55
  "zod": ">=4.5.4 <5"
56
56
  },
@@ -59,7 +59,11 @@ export async function partsInUse(
59
59
  const layout = item.data?.["layout"];
60
60
  const text = typeof layout === "string" ? layout : JSON.stringify(layout ?? null);
61
61
  for (const id of ids) {
62
- if (!text.includes(`"partId":${JSON.stringify(id)}`)) continue;
62
+ // W-1069: a mega menu item's panel uses its part too.
63
+ const quoted = JSON.stringify(id);
64
+ if (!text.includes(`"partId":${quoted}`) && !text.includes(`"panelPartId":${quoted}`)) {
65
+ continue;
66
+ }
63
67
  used.set(id, [...(used.get(id) ?? []), titleOf(item, "Untitled")]);
64
68
  }
65
69
  }
@@ -6,6 +6,9 @@ export type ContentItem = {
6
6
  draftRevisionId?: string | null;
7
7
  updatedAt?: string;
8
8
  data?: Record<string, unknown>;
9
+ /** W-1091: EmDash i18n: the entry's language, and the group its translations share. */
10
+ locale?: string | null;
11
+ translationGroup?: string | null;
9
12
  seo?: {
10
13
  title?: string | null;
11
14
  description?: string | null;
@@ -4,6 +4,7 @@ import { THEME_PARTS_COLLECTION } from "../constants.ts";
4
4
  import { ApiError, listAllItems, requestJson, type Fetcher } from "./api.ts";
5
5
  import type { ContentItem } from "./content-item.ts";
6
6
  import { loadExportData } from "./export-api.ts";
7
+ import { siteLocales } from "./languages-api.ts";
7
8
  import { readCollection } from "./setup/run.ts";
8
9
 
9
10
  export type RichTextTarget = {
@@ -13,6 +14,13 @@ export type RichTextTarget = {
13
14
  field: string;
14
15
  /** The collection has a `title` field for the page title. */
15
16
  hasTitle: boolean;
17
+ /**
18
+ * W-1091: false when the rich-text field is shared by every language of an entry (EmDash's
19
+ * per-field `translatable`); then only the default language is copied.
20
+ */
21
+ translatable?: boolean;
22
+ /** W-1091: false when the title is shared by every language (a translation must not send it). */
23
+ titleTranslatable?: boolean;
16
24
  };
17
25
 
18
26
  /** Visible collections with a rich-text field: where EmVB pages can be copied as rich text. */
@@ -29,12 +37,15 @@ export async function richTextTargets(fetcher: Fetcher): Promise<RichTextTarget[
29
37
  const rich = fields.filter((f) => f.type === "portableText");
30
38
  const field = rich.find((f) => f.slug === "content") ?? rich[0];
31
39
  if (!field) return null;
40
+ const title = fields.find((f) => f.slug === "title");
32
41
  const target: RichTextTarget = {
33
42
  slug: c.slug,
34
43
  label: c.label?.trim() || c.slug,
35
44
  field: field.slug,
36
- hasTitle: fields.some((f) => f.slug === "title"),
45
+ hasTitle: !!title,
37
46
  };
47
+ if (field.translatable === false) target.translatable = false;
48
+ if (title?.translatable === false) target.titleTranslatable = false;
38
49
  return target;
39
50
  }),
40
51
  );
@@ -42,25 +53,66 @@ export async function richTextTargets(fetcher: Fetcher): Promise<RichTextTarget[
42
53
  }
43
54
 
44
55
  export type CopyResult = {
45
- created: { title: string; id: string }[];
56
+ /** W-1091: `locale` is set when the site has languages; the title then names it. */
57
+ created: { title: string; id: string; locale?: string }[];
46
58
  failed: { title: string; message: string }[];
47
59
  /** Elements left out across all pages, by type. */
48
60
  skipped: Record<string, number>;
49
61
  };
50
62
 
63
+ type Page = Awaited<ReturnType<typeof loadExportData>>["pages"][number];
64
+
65
+ /**
66
+ * W-1091 (#26): the pages in the order they are copied, grouped by translation: in each group the
67
+ * default language first, so the others can be created as its translations. With `onlyDefault`,
68
+ * the other languages are set aside (returned in `rest`).
69
+ */
70
+ function translationOrder(
71
+ pages: readonly Page[],
72
+ defaultLocale: string,
73
+ onlyDefault: boolean,
74
+ ): { copy: Page[]; rest: Page[] } {
75
+ const groups = new Map<string, Page[]>();
76
+ for (const page of pages) {
77
+ const group = page.translationGroup || page.id;
78
+ groups.set(group, [...(groups.get(group) ?? []), page]);
79
+ }
80
+ const copy: Page[] = [];
81
+ const rest: Page[] = [];
82
+ for (const [group, members] of groups) {
83
+ const rank = (p: Page) => (p.locale === defaultLocale ? 0 : p.id === group ? 1 : 2);
84
+ const ordered = members.toSorted(
85
+ (a, b) => rank(a) - rank(b) || (a.locale ?? "").localeCompare(b.locale ?? ""),
86
+ );
87
+ if (onlyDefault) {
88
+ const [first, ...others] = ordered;
89
+ if (first) copy.push(first);
90
+ rest.push(...others);
91
+ } else copy.push(...ordered);
92
+ }
93
+ return { copy, rest };
94
+ }
95
+
51
96
  /**
52
97
  * W-963: published EmVB pages (all or one) become draft entries in another collection, their
53
98
  * words, headings, lists, links and images as rich text. EmVB pages are only read; nothing is
54
99
  * published. A page whose entry can't be created (a slug in use) is reported and the rest go on.
100
+ *
101
+ * W-1091 (#26): on a site with languages each page keeps its own: one entry per language, in that
102
+ * locale, with that language's words, created as a translation of the default language's entry
103
+ * (slugs are unique per language in EmDash, so translations share theirs). When the target's
104
+ * rich-text field is shared across languages, or the site has no languages set up, only one
105
+ * language per page is copied and the others are reported, never written under another locale.
55
106
  */
56
107
  export async function copyPagesAsRichText(
57
108
  fetcher: Fetcher,
58
109
  target: RichTextTarget,
59
110
  onlyPageId?: string | readonly string[],
60
111
  ): Promise<CopyResult> {
61
- const [{ pages }, partItems] = await Promise.all([
112
+ const [{ pages }, partItems, languages] = await Promise.all([
62
113
  loadExportData(fetcher, onlyPageId),
63
114
  listAllItems<ContentItem>(fetcher, `/_emdash/api/content/${THEME_PARTS_COLLECTION}`),
115
+ siteLocales(fetcher).catch(() => null),
64
116
  ]);
65
117
  const sectionTemplates: Record<string, Layout> = {};
66
118
  for (const part of partItems) {
@@ -69,7 +121,33 @@ export async function copyPagesAsRichText(
69
121
  if (checked.ok) sectionTemplates[part.id] = checked.layout;
70
122
  }
71
123
  const result: CopyResult = { created: [], failed: [], skipped: {} };
72
- for (const page of pages) {
124
+ const defaultLocale = languages?.defaultLocale ?? "en";
125
+ const perLanguage = !!languages && target.translatable !== false;
126
+ const { copy, rest } = translationOrder(pages, defaultLocale, !perLanguage);
127
+ // A page's title names its language when the pages have more than one.
128
+ const multilingual = new Set(pages.map((p) => p.locale ?? defaultLocale)).size > 1;
129
+ const named = (page: Page) =>
130
+ multilingual && page.locale ? `${page.title} (${page.locale})` : page.title;
131
+ for (const page of rest) {
132
+ result.failed.push({
133
+ title: named(page),
134
+ message: languages
135
+ ? `${target.label} shares its ${target.field} field across languages, so only the ${defaultLocale} page was copied`
136
+ : "this site has no languages set up, so only one language of each page was copied",
137
+ });
138
+ }
139
+ // Translation group → the entry its first language became.
140
+ const sources = new Map<string, string>();
141
+ for (const page of copy) {
142
+ const group = page.translationGroup || page.id;
143
+ const locale = languages ? page.locale || defaultLocale : undefined;
144
+ if (locale && languages && !languages.locales.includes(locale)) {
145
+ result.failed.push({
146
+ title: named(page),
147
+ message: `its language (${locale}) isn't set up on this site`,
148
+ });
149
+ continue;
150
+ }
73
151
  let raw = page.layout;
74
152
  if (typeof raw === "string") {
75
153
  try {
@@ -80,12 +158,15 @@ export async function copyPagesAsRichText(
80
158
  }
81
159
  const checked = validateLayout(raw);
82
160
  if (!checked.ok) {
83
- result.failed.push({ title: page.title, message: "its layout couldn't be read" });
161
+ result.failed.push({ title: named(page), message: "its layout couldn't be read" });
84
162
  continue;
85
163
  }
86
164
  const converted = layoutToPortableText(checked.layout, { sectionTemplates });
87
165
  for (const [type, n] of Object.entries(converted.skipped))
88
166
  result.skipped[type] = (result.skipped[type] ?? 0) + n;
167
+ const source = sources.get(group);
168
+ // A title shared by every language comes from the entry it translates.
169
+ const sendTitle = target.hasTitle && !(source && target.titleTranslatable === false);
89
170
  try {
90
171
  // oxlint-disable-next-line no-await-in-loop -- one entry at a time; failures are per page
91
172
  const body = await requestJson<{ item: { id: string } }>(
@@ -95,20 +176,29 @@ export async function copyPagesAsRichText(
95
176
  method: "POST",
96
177
  body: {
97
178
  data: {
98
- ...(target.hasTitle ? { title: page.title } : {}),
179
+ ...(sendTitle ? { title: page.title } : {}),
99
180
  [target.field]: converted.body,
100
181
  },
101
182
  ...(page.slug ? { slug: page.slug } : {}),
183
+ ...(locale ? { locale } : {}),
184
+ ...(locale && source ? { translationOf: source } : {}),
102
185
  },
103
186
  },
104
187
  );
105
- result.created.push({ title: page.title, id: body.item.id });
188
+ if (!sources.has(group)) sources.set(group, body.item.id);
189
+ result.created.push({
190
+ title: named(page),
191
+ id: body.item.id,
192
+ ...(locale ? { locale } : {}),
193
+ });
106
194
  } catch (error) {
107
195
  result.failed.push({
108
- title: page.title,
196
+ title: named(page),
109
197
  message:
110
198
  error instanceof ApiError && error.status === 409
111
- ? "its address is already used there"
199
+ ? locale && multilingual
200
+ ? `its address is already used there in ${locale}`
201
+ : "its address is already used there"
112
202
  : error instanceof Error
113
203
  ? error.message
114
204
  : String(error),
@@ -28,7 +28,9 @@ export function A11yScoreButton({ report, onOpen }: { report: A11yReport; onOpen
28
28
  ? "Accessibility: no issues found"
29
29
  : `Accessibility: ${count} issue${count === 1 ? "" : "s"}`
30
30
  }
31
- aria-label={`Accessibility score ${report.score} of 100, ${count} issue${count === 1 ? "" : "s"}`}
31
+ // W-1084: the name starts with the visible "A11y <score>" (WCAG 2.5.3, Label in Name), so a
32
+ // voice-control user can say what they see.
33
+ aria-label={`A11y ${report.score}: accessibility score of 100, ${count} issue${count === 1 ? "" : "s"}`}
32
34
  onClick={onOpen}
33
35
  >
34
36
  A11y <b>{report.score}</b>
@@ -43,7 +43,7 @@ import { EditorOverlay } from "./EditorOverlay.tsx";
43
43
  import { EditorToasts } from "./EditorToasts.tsx";
44
44
  import { useCanvasStyles, useEditorHost } from "./host.ts";
45
45
  import { LiveDataProvider, siteOrigin, useLiveData } from "./live-data.tsx";
46
- import { newElement } from "./dnd/new-element.ts";
46
+ import { newElement, templateIdOf } from "./dnd/new-element.ts";
47
47
  import { editorCommands } from "./editor-commands.ts";
48
48
  import { ELEMENT_NAMES } from "./element-chrome.ts";
49
49
  import { LeftPanel } from "./panels/LeftPanel.tsx";
@@ -63,6 +63,7 @@ import {
63
63
  import { EDITOR_MIN_WIDTH_QUERY, useMediaQuery } from "./useMediaQuery.ts";
64
64
  import { partDraftLabel, usePartTemplates } from "./section-templates.ts";
65
65
  import { useCollectionPreviews, withPartLayouts } from "./collection-previews.ts";
66
+ import { useExtensionOutputs, useExtensionSourceValues } from "../extension-outputs.ts";
66
67
  import { useEditorPresence } from "./presence.ts";
67
68
  import { useCoDesign } from "./useCoDesign.ts";
68
69
  import { useRemoteChange } from "./remote-change.ts";
@@ -161,6 +162,8 @@ function EditorApp({
161
162
  const host = useEditorHost();
162
163
  const canvasStyles = useCanvasStyles(fetcher);
163
164
  const extensionManifests = useExtensionManifests(fetcher);
165
+ // W-1088 (#36): the values of the sources extension panels name, listed read-only.
166
+ const extensionSources = useExtensionSourceValues(fetcher, extensionManifests);
164
167
  const inlinedStyles = useInlinedStyles(canvasStyles);
165
168
  const { exit } = host;
166
169
  const saver = useSave(fetcher, state, dispatch, collection);
@@ -226,6 +229,9 @@ function EditorApp({
226
229
  wrap,
227
230
  addFromPanel,
228
231
  addRecipe,
232
+ layersDrop,
233
+ addTemplate,
234
+ dropTemplate,
229
235
  items: itemActions,
230
236
  } = useNodeActions({ state, latest, dispatch, announce: setAnnouncement, toasts });
231
237
  // W-876: My sections and Save as section (D-060).
@@ -287,6 +293,8 @@ function EditorApp({
287
293
  [state.page.layout, sectionTemplates, loopTemplates],
288
294
  );
289
295
  const collections = useCollectionPreviews(previewLayout, fetcher);
296
+ // W-1086: extension elements render on the server, which has their code; the canvas shows that.
297
+ const extensionOutputs = useExtensionOutputs(coDesign.ghost?.layout ?? previewLayout, fetcher);
290
298
  // W-930: while previewing a proposal the canvas shows its ghost, never the editor's layout changed.
291
299
  const canvasLayout = coDesign.ghost?.layout ?? state.page.layout;
292
300
  const rendered = React.useMemo(
@@ -305,6 +313,7 @@ function EditorApp({
305
313
  collections,
306
314
  },
307
315
  previewDevice: device,
316
+ extensionOutputs,
308
317
  })
309
318
  : null,
310
319
  [
@@ -316,6 +325,8 @@ function EditorApp({
316
325
  live.site,
317
326
  live.params,
318
327
  collections,
328
+ extensionOutputs,
329
+ extensionManifests,
319
330
  ],
320
331
  );
321
332
  // W-911: field mode previews the unsaved layout with the public renderer, in a sandboxed frame.
@@ -334,6 +345,10 @@ function EditorApp({
334
345
  collections,
335
346
  },
336
347
  previewDevice,
348
+ extensionOutputs,
349
+ // W-1088 (#37): visitors get nothing for an extension that can't render; this preview
350
+ // keeps the note so the editor knows something is missing.
351
+ extensionPlaceholders: true,
337
352
  });
338
353
  return previewDocument({
339
354
  html: result.html,
@@ -380,7 +395,8 @@ function EditorApp({
380
395
  if (!node) return "Element";
381
396
  const name = node.editorLabel ?? ELEMENT_NAMES[node.type] ?? node.type;
382
397
  // W-970: a synced section or Loop item drawn from unpublished changes says so on the canvas.
383
- const partId = (node.props as { partId?: unknown } | undefined)?.partId;
398
+ const props = node.props as { partId?: unknown; panelPartId?: unknown } | undefined;
399
+ const partId = props?.partId ?? props?.panelPartId;
384
400
  const status = typeof partId === "string" ? partStatus?.[partId] : undefined;
385
401
  return status && status !== "published" ? `${name} · ${partDraftLabel(status)}` : name;
386
402
  },
@@ -444,7 +460,7 @@ function EditorApp({
444
460
  })[0];
445
461
 
446
462
  return (
447
- <ExtensionsProvider extensions={extensionManifests}>
463
+ <ExtensionsProvider extensions={extensionManifests} sourceValues={extensionSources}>
448
464
  <EditorOverlay
449
465
  label={`EmVB editor: ${state.page.title || "Untitled page"}`}
450
466
  dirty={dirty && !chrome.leaving}
@@ -568,6 +584,8 @@ function EditorApp({
568
584
  onSelect={(id) => dispatch({ type: "select", id })}
569
585
  onAdd={addFromPanel}
570
586
  onRecipe={addRecipe}
587
+ onTemplate={addTemplate}
588
+ design={state.design}
571
589
  formsAvailable={formsAvailable}
572
590
  onDuplicate={duplicate}
573
591
  onMoveUp={(id) => arrange(id, moveUp)}
@@ -577,6 +595,8 @@ function EditorApp({
577
595
  saved={saved}
578
596
  onSaveSection={setSaveAsk}
579
597
  {...(!host.field && collection === PAGES_COLLECTION ? { coDesign } : {})}
598
+ onDropNew={layersDrop.add}
599
+ onMoveTo={layersDrop.move}
580
600
  onRename={(id, label) =>
581
601
  dispatch({
582
602
  type: "update-node",
@@ -630,6 +650,11 @@ function EditorApp({
630
650
  statePreview={statePreview}
631
651
  refusal={refusalShown ? refusal : null}
632
652
  onDropNew={(elementType, parentId, index) => {
653
+ const template = templateIdOf(elementType);
654
+ if (template !== null) {
655
+ dropTemplate(template, parentId, index);
656
+ return;
657
+ }
633
658
  const node = newElement(
634
659
  elementType,
635
660
  undefined,
@@ -19,6 +19,7 @@ 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
21
  import { DialogCloseButton } from "./DialogCloseButton.tsx";
22
+ import { inertLinks } from "./inert-links.ts";
22
23
 
23
24
  type RevisionItem = {
24
25
  id: string;
@@ -160,14 +161,6 @@ const whenParts = (iso: string) => {
160
161
  };
161
162
  };
162
163
 
163
- /**
164
- * W-752: the picture is not a page to browse. A link in it took keyboard focus and Enter loaded the
165
- * site (or the admin, for an in-page anchor) inside the picture. Inside a tag, core escapes `"`
166
- * and `>` in attribute values, so the tag and its href are found exactly; text is left alone.
167
- */
168
- const inertLinks = (html: string) =>
169
- html.replaceAll(/<a\b[^>]*>/g, (tag) => tag.replace(/ href="[^"]*"/, ""));
170
-
171
164
  /** A small, script-free picture of one version with its changed sections outlined (W-315). */
172
165
  function Snapshot({
173
166
  layout,
@@ -26,6 +26,10 @@ const ICONS: Record<EditorDevice, Icon> = {
26
26
  mobile: DeviceMobileIcon,
27
27
  };
28
28
 
29
+ /** The zoom button's text: the fitted scale, or 100% (W-158). */
30
+ const zoomText = (zoom: "fit" | "actual", scale: number) =>
31
+ zoom === "fit" ? `Fit · ${Math.round(scale * 100)}%` : "100%";
32
+
29
33
  /** The device's icon (decorative) and its name, which stays the tab's accessible name (W-127). */
30
34
  function DeviceLabel({ device }: { device: EditorDevice }) {
31
35
  const DeviceIcon = ICONS[device];
@@ -103,11 +107,12 @@ export function DeviceBar({
103
107
  size="sm"
104
108
  className="emvb-zoom"
105
109
  aria-pressed={zoom === "fit"}
106
- aria-label={`Fit to canvas (${Math.round(scale * 100)}%)`}
110
+ // W-1084: the name starts with the visible text (WCAG 2.5.3, Label in Name).
111
+ aria-label={`${zoomText(zoom, scale)}, fit to canvas`}
107
112
  title={zoom === "fit" ? "Scaled to fit. Show at 100%" : "At 100%. Scale to fit"}
108
113
  onClick={() => onZoom(zoom === "fit" ? "actual" : "fit")}
109
114
  >
110
- {zoom === "fit" ? `Fit · ${Math.round(scale * 100)}%` : "100%"}
115
+ {zoomText(zoom, scale)}
111
116
  </Button>
112
117
  )}
113
118
  </div>
@@ -1,7 +1,9 @@
1
1
  import { PlusIcon } from "@phosphor-icons/react";
2
2
  import type * as React from "react";
3
3
  import { NEW_ELEMENT_MIME } from "../dnd/drop-target.ts";
4
- import { newElement } from "../dnd/new-element.ts";
4
+ import { templateSectionNode } from "../../../core/index.ts";
5
+ import { newElement, templateIdOf } from "../dnd/new-element.ts";
6
+ import { isSharedPart } from "../panels/settings/heading-warning.ts";
5
7
  import type { EditorAction, EditorState } from "../store.ts";
6
8
 
7
9
  /** The canvas of a page with no layout yet: a prompt and a drop zone that starts one (R-002). */
@@ -30,7 +32,14 @@ export function EmptyCanvas({
30
32
  queueMicrotask(() => {
31
33
  const layout = latest.current.page.layout;
32
34
  if (!layout) return;
33
- const node = newElement(type);
35
+ // W-1068: a starter template takes the site's styles, as when dropped on a page.
36
+ const template = templateIdOf(type);
37
+ const node =
38
+ template === null
39
+ ? newElement(type)
40
+ : templateSectionNode(template, latest.current.design, layout, {
41
+ noH1: isSharedPart(latest.current.page.partType),
42
+ });
34
43
  if (!node) return;
35
44
  dispatch({ type: "add-node", node, parentId: layout.root.id, index: 0 });
36
45
  });
@@ -13,16 +13,13 @@ import {
13
13
  dropContainer,
14
14
  dropIndex,
15
15
  edgeDrop,
16
- EXISTING_ELEMENT_MIME,
17
16
  flowDirection,
18
17
  idAt,
19
- NEW_ELEMENT_MIME,
20
18
  transferKinds,
21
19
  type Direction,
22
20
  type Rect,
23
21
  } from "../dnd/drop-target.ts";
24
- import { dragStash } from "../dnd/drag-stash.ts";
25
- import { newElement } from "../dnd/new-element.ts";
22
+ import { draggedSource } from "../dnd/dragged-source.ts";
26
23
  import { useCanvasEvents } from "./canvas-events.ts";
27
24
  import { dropLineBox } from "./drop-line.ts";
28
25
  import type { Box, DropTarget, InvalidDrop } from "./SelectionOverlay.tsx";
@@ -60,22 +57,6 @@ const rectOf = (doc: Document, id: string): Rect | null => {
60
57
  return box ? { top: box.top, left: box.left, width: box.width, height: box.height } : null;
61
58
  };
62
59
 
63
- /** What is being dragged over the canvas, or null while the browser still hides it. */
64
- function draggedSource(transfer: DataTransfer | null, existing: boolean): DragSource | null {
65
- if (existing) {
66
- // Chromium may omit getData until drop, so the session stash wins during dragover.
67
- const id =
68
- dragStash.id() ??
69
- (transfer?.getData(EXISTING_ELEMENT_MIME) ||
70
- (transfer as DataTransfer & { emvbId?: string }).emvbId ||
71
- "");
72
- return id ? { kind: "existing", id } : null;
73
- }
74
- const type = transfer?.getData(NEW_ELEMENT_MIME) || dragStash.type() || "";
75
- const node = type ? newElement(type) : null;
76
- return node ? { kind: "new", node } : null;
77
- }
78
-
79
60
  /** Drop line, invalid outline and the canvas drag listeners. */
80
61
  export function useCanvasDnD({
81
62
  doc,
@@ -41,6 +41,8 @@ const BOOLEAN_ATTRS = new Set([
41
41
  "autoplay",
42
42
  "required",
43
43
  "novalidate",
44
+ // W-1065: a form's Previous and Next buttons, shown only by the forms script.
45
+ "hidden",
44
46
  ]);
45
47
 
46
48
  /** SVG tags the core keeps lowercase; the SVG namespace only knows their camelCase names. */
@@ -64,13 +64,48 @@ const BIDI_AND_CONTROLS =
64
64
 
65
65
  const quoted = (text: string | undefined) => (text ? ` “${text}”` : "");
66
66
 
67
+ const childrenOf = (node: unknown): unknown[] => {
68
+ const children = (node as { children?: unknown } | null)?.children;
69
+ return Array.isArray(children) ? children : [];
70
+ };
71
+
72
+ /**
73
+ * W-1064: a whole section arrives as one insert; name it by its first heading, depth first, so a
74
+ * whole-page proposal reads as a list of sections. Bounded like the proposal itself.
75
+ */
76
+ function headingOf(node: unknown): string | undefined {
77
+ const stack = childrenOf(node).toReversed();
78
+ for (let seen = 0; stack.length > 0 && seen < 2000; seen++) {
79
+ const item = stack.pop();
80
+ if ((item as { type?: unknown } | null)?.type === "heading") {
81
+ const text = textOf(item);
82
+ if (text) return text;
83
+ }
84
+ stack.push(...childrenOf(item).toReversed());
85
+ }
86
+ return undefined;
87
+ }
88
+
89
+ /** How many elements an insert adds, so a person sees the size of what they accept. */
90
+ function countNodes(node: unknown): number {
91
+ const stack = [node];
92
+ let count = 0;
93
+ while (stack.length > 0 && count < 2000) {
94
+ count += 1;
95
+ stack.push(...childrenOf(stack.pop()));
96
+ }
97
+ return count;
98
+ }
99
+
67
100
  /** One line a person can read: what the change does, to which element. Agent text is quoted. */
68
101
  export function describeOp(op: Op, layout: Layout | null): string {
69
102
  const target = (id: string) => (layout ? findNode(layout, id) : null);
70
103
  switch (op.kind) {
71
104
  case "insert": {
72
105
  const parent = target(op.parentId);
73
- return `Add ${nameOf(op.node)}${quoted(textOf(op.node))} to ${nameOf(parent)}`;
106
+ const added = `Add ${nameOf(op.node)}${quoted(textOf(op.node) ?? headingOf(op.node))} to ${nameOf(parent)}`;
107
+ const count = countNodes(op.node);
108
+ return count > 1 ? `${added} (${count} elements)` : added;
74
109
  }
75
110
  case "update": {
76
111
  const node = target(op.id);
@@ -1,7 +1,9 @@
1
1
  import * as React from "react";
2
2
  import {
3
3
  collectCollectionLoops,
4
+ entryImageValue,
4
5
  loopPermalink,
6
+ mediaUrlOf,
5
7
  type CollectionLoop,
6
8
  type Layout,
7
9
  type ThemePostFields,
@@ -13,16 +15,13 @@ type ContentItem = { id: string; slug?: string | null; data?: Record<string, unk
13
15
  const text = (value: unknown): string => (typeof value === "string" ? value : "");
14
16
 
15
17
  /** A content API item as Loop fields; the host's mapping covers images and plain fields. */
16
- function previewPost(item: ContentItem, loop: CollectionLoop): ThemePostFields {
18
+ export function previewPost(item: ContentItem, loop: CollectionLoop): ThemePostFields {
17
19
  const data = item.data ?? {};
18
20
  const slug = item.slug || text(data["slug"]);
19
- const image = loop.imageField ? data[loop.imageField] : (data["featured_image"] ?? data["image"]);
20
- const src =
21
- typeof image === "string"
22
- ? image
23
- : image && typeof image === "object" && "src" in image
24
- ? text((image as { src?: unknown }).src)
25
- : "";
21
+ // W-1090 (#32): as published pages read it: a picked upload has no `src`, only a storage key,
22
+ // and unset falls back from featured_image to the entry's first image field.
23
+ const image = entryImageValue(data, loop.imageField);
24
+ const src = typeof image === "string" ? image : (mediaUrlOf(image) ?? "");
26
25
  const fields: Record<string, string> = {};
27
26
  for (const [key, value] of Object.entries(data).slice(0, 100)) {
28
27
  if (typeof value === "string" && value.length <= 2000) fields[key] = value;
@@ -0,0 +1,22 @@
1
+ import type { DragSource } from "../../../core/index.ts";
2
+ import { dragStash } from "./drag-stash.ts";
3
+ import { EXISTING_ELEMENT_MIME, NEW_ELEMENT_MIME } from "./drop-target.ts";
4
+ import { newElement } from "./new-element.ts";
5
+
6
+ /**
7
+ * What is being dragged (canvas and Layers), or null while the browser still hides it.
8
+ * Chromium may omit getData until drop, so the session stash wins during dragover.
9
+ */
10
+ export function draggedSource(transfer: DataTransfer | null, existing: boolean): DragSource | null {
11
+ if (existing) {
12
+ const id =
13
+ dragStash.id() ??
14
+ (transfer?.getData(EXISTING_ELEMENT_MIME) ||
15
+ (transfer as (DataTransfer & { emvbId?: string }) | null)?.emvbId ||
16
+ "");
17
+ return id ? { kind: "existing", id } : null;
18
+ }
19
+ const type = transfer?.getData(NEW_ELEMENT_MIME) || dragStash.type() || "";
20
+ const node = type ? newElement(type) : null;
21
+ return node ? { kind: "new", node } : null;
22
+ }