@perkyzz/emvb 1.2.0 → 1.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 (150) hide show
  1. package/README.md +2 -2
  2. package/THIRD_PARTY_NOTICES.md +2 -2
  3. package/package.json +4 -4
  4. package/src/admin/bulk-api.ts +5 -1
  5. package/src/admin/editor/A11yCopilot.tsx +3 -1
  6. package/src/admin/editor/Editor.tsx +22 -2
  7. package/src/admin/editor/Timeline.tsx +1 -8
  8. package/src/admin/editor/canvas/DeviceBar.tsx +7 -2
  9. package/src/admin/editor/canvas/EmptyCanvas.tsx +11 -2
  10. package/src/admin/editor/canvas/use-canvas-dnd.ts +1 -20
  11. package/src/admin/editor/canvas/vnode-react.tsx +5 -0
  12. package/src/admin/editor/co-design.ts +36 -1
  13. package/src/admin/editor/dnd/dragged-source.ts +22 -0
  14. package/src/admin/editor/dnd/layer-drop.ts +141 -0
  15. package/src/admin/editor/dnd/new-element.ts +76 -0
  16. package/src/admin/editor/editor-css.ts +9 -1
  17. package/src/admin/editor/element-chrome.ts +34 -0
  18. package/src/admin/editor/feature-css.ts +22 -0
  19. package/src/admin/editor/inert-links.ts +8 -0
  20. package/src/admin/editor/panels/ColorControl.tsx +2 -2
  21. package/src/admin/editor/panels/FontFaces.tsx +342 -0
  22. package/src/admin/editor/panels/LayersPanel.tsx +56 -6
  23. package/src/admin/editor/panels/LeftPanel.tsx +153 -29
  24. package/src/admin/editor/panels/SettingsPanel.tsx +1 -0
  25. package/src/admin/editor/panels/SiteStylesDrawer.tsx +5 -0
  26. package/src/admin/editor/panels/TemplatesPanel.tsx +205 -0
  27. package/src/admin/editor/panels/TokenScales.tsx +2 -0
  28. package/src/admin/editor/panels/TriggersEditor.tsx +203 -9
  29. package/src/admin/editor/panels/VariableSection.tsx +111 -7
  30. package/src/admin/editor/panels/color-space.ts +71 -6
  31. package/src/admin/editor/panels/settings/AudienceEditor.tsx +3 -0
  32. package/src/admin/editor/panels/settings/FieldControl.tsx +18 -0
  33. package/src/admin/editor/panels/settings/ItemList.tsx +33 -0
  34. package/src/admin/editor/panels/settings/LoopItemBindControl.tsx +9 -3
  35. package/src/admin/editor/panels/settings/StickyControl.tsx +97 -0
  36. package/src/admin/editor/panels/settings/StyleRow.tsx +14 -0
  37. package/src/admin/editor/panels/settings/style-sections.ts +19 -2
  38. package/src/admin/editor/panels/url-rules.ts +43 -0
  39. package/src/admin/editor/panels/use-layers-drop.ts +232 -0
  40. package/src/admin/editor/store.ts +4 -2
  41. package/src/admin/editor/useExtensions.ts +3 -1
  42. package/src/admin/editor/useNodeActions.ts +74 -1
  43. package/src/admin/editor/useSave.ts +116 -85
  44. package/src/admin/export-api.ts +25 -2
  45. package/src/admin/extension-outputs.ts +179 -0
  46. package/src/admin/font-files-api.ts +38 -0
  47. package/src/admin/pages/ImportButton.tsx +15 -4
  48. package/src/admin/pages/ImportElementorDialog.tsx +22 -188
  49. package/src/admin/pages/ImportHtmlDialog.tsx +209 -0
  50. package/src/admin/pages/ImportImageCopies.tsx +167 -0
  51. package/src/admin/pages/ImportReport.tsx +63 -0
  52. package/src/admin/pages/NewPageDialog.tsx +54 -32
  53. package/src/admin/pages/PageList.tsx +9 -0
  54. package/src/admin/pages/ThemePartList.tsx +9 -0
  55. package/src/astro/EmVBPage.astro +5 -2
  56. package/src/astro/extension-styles.ts +35 -0
  57. package/src/astro/forms/EmVBFormsClient.astro +3 -0
  58. package/src/astro/forms/enhance.ts +107 -0
  59. package/src/astro/popups/runtime.ts +47 -2
  60. package/src/astro/render.ts +19 -4
  61. package/src/astro/request-data.ts +6 -0
  62. package/src/astro/resolve-theme.ts +11 -4
  63. package/src/astro/resolve.ts +9 -0
  64. package/src/astro/widgets/EmVBCountdownRuntime.astro +8 -0
  65. package/src/astro/widgets/EmVBCounterRuntime.astro +8 -0
  66. package/src/astro/widgets/EmVBHeadlineRuntime.astro +9 -0
  67. package/src/astro/widgets/EmVBMapRuntime.astro +8 -0
  68. package/src/astro/widgets/EmVBShareRuntime.astro +9 -0
  69. package/src/astro/widgets/EmVBStickyRuntime.astro +9 -0
  70. package/src/astro/widgets/EmVBThemeRuntime.astro +9 -0
  71. package/src/astro/widgets/EmVBWidgetRuntimes.astro +22 -0
  72. package/src/astro/widgets/alerts.ts +16 -2
  73. package/src/astro/widgets/carousel.ts +65 -24
  74. package/src/astro/widgets/countdown.ts +91 -0
  75. package/src/astro/widgets/counter.ts +98 -0
  76. package/src/astro/widgets/extension-runtimes.ts +27 -0
  77. package/src/astro/widgets/headline.ts +99 -0
  78. package/src/astro/widgets/map.ts +37 -0
  79. package/src/astro/widgets/share.ts +21 -0
  80. package/src/astro/widgets/sticky.ts +87 -0
  81. package/src/astro/widgets/theme.ts +52 -0
  82. package/src/constants.ts +1 -1
  83. package/src/core/a11y/audit.ts +177 -6
  84. package/src/core/arrange.ts +71 -1
  85. package/src/core/canvas-collections.ts +28 -0
  86. package/src/core/css/font-face.ts +72 -0
  87. package/src/core/css/generate.ts +35 -1
  88. package/src/core/elements/counter-format.ts +15 -0
  89. package/src/core/elements/form-elements.ts +119 -9
  90. package/src/core/elements/icon-svg.ts +14 -0
  91. package/src/core/elements/index.ts +54 -4
  92. package/src/core/elements/input-limits.ts +44 -0
  93. package/src/core/elements/marketing.ts +1490 -0
  94. package/src/core/elements/menu.ts +109 -47
  95. package/src/core/elements/site.ts +108 -0
  96. package/src/core/elements/widgets.ts +40 -5
  97. package/src/core/export/runtimes.generated.ts +10 -3
  98. package/src/core/export/site.ts +55 -4
  99. package/src/core/extensions/classes.ts +114 -0
  100. package/src/core/extensions/index.ts +17 -2
  101. package/src/core/extensions/normalize.ts +13 -0
  102. package/src/core/extensions/registry.ts +134 -10
  103. package/src/core/extensions/render-ext.ts +66 -21
  104. package/src/core/extensions/safe-nodes.ts +67 -11
  105. package/src/core/extensions/types.ts +48 -1
  106. package/src/core/fonts/files.ts +74 -0
  107. package/src/core/fonts/google.ts +112 -0
  108. package/src/core/fonts/test-font.ts +9 -0
  109. package/src/core/import/elementor/context.ts +13 -4
  110. package/src/core/import/elementor/index.ts +32 -21
  111. package/src/core/import/elementor/widgets.ts +532 -293
  112. package/src/core/import/html/blocks.ts +602 -0
  113. package/src/core/import/html/index.ts +155 -0
  114. package/src/core/import/html/map.ts +958 -0
  115. package/src/core/import/html/parse.ts +430 -0
  116. package/src/core/index.ts +45 -0
  117. package/src/core/limits.ts +6 -0
  118. package/src/core/migrate/v18.ts +3 -0
  119. package/src/core/public-attributes.ts +17 -0
  120. package/src/core/render/extras.ts +31 -7
  121. package/src/core/render/form.ts +103 -10
  122. package/src/core/render/index.ts +172 -16
  123. package/src/core/render/section.ts +31 -1
  124. package/src/core/render/spacer-basis.ts +102 -0
  125. package/src/core/render/theme-boot.ts +16 -0
  126. package/src/core/render/vnode.ts +1 -1
  127. package/src/core/sanitize/css.ts +68 -3
  128. package/src/core/sanitize/motion.ts +12 -0
  129. package/src/core/schema/design.ts +40 -0
  130. package/src/core/schema/layout.ts +534 -22
  131. package/src/core/schema/style.ts +28 -0
  132. package/src/core/templates/index.ts +218 -0
  133. package/src/core/templates/pages.ts +29 -0
  134. package/src/core/templates/sections.ts +794 -0
  135. package/src/core/templates/types.ts +9 -0
  136. package/src/core/theme/dynamic.ts +11 -6
  137. package/src/core/theme/popup-markup.ts +21 -2
  138. package/src/core/theme/popup-rules.ts +36 -0
  139. package/src/core/theme/triggers.ts +64 -5
  140. package/src/core/translatable.ts +5 -2
  141. package/src/extension-build.ts +331 -0
  142. package/src/index.ts +25 -3
  143. package/src/mcp/brief.ts +191 -0
  144. package/src/mcp/prompts.ts +33 -0
  145. package/src/mcp/read.ts +29 -1
  146. package/src/mcp/tools.ts +40 -1
  147. package/src/mcp/write.ts +41 -1
  148. package/src/server/extension-routes.ts +73 -0
  149. package/src/server/font-routes.ts +301 -0
  150. package/src/server/plugin.ts +11 -1
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
 
@@ -10,7 +10,7 @@ When an editor picks an icon, its SVG is stored with the page and shown inline o
10
10
 
11
11
  ## Lucide
12
12
 
13
- - Package: `lucide-static` 1.61.0, <https://lucide.dev>
13
+ - Package: `lucide-static` 1.73.0, <https://lucide.dev>
14
14
  - License: ISC, Copyright (c) 2026 Lucide Icons and Contributors. Icons derived from Feather: MIT, Copyright (c) 2013-present Cole Bemis. Full text: [`licenses/lucide-static.LICENSE`](licenses/lucide-static.LICENSE).
15
15
  - The 26 icons EmVB bundled before the library (`src/core/icons/catalog.ts`) are also Lucide icons, under the same license.
16
16
 
@@ -24,7 +24,7 @@ When an editor picks an icon, its SVG is stored with the page and shown inline o
24
24
 
25
25
  ## Tabler Icons
26
26
 
27
- - Package: `@tabler/icons` 3.49.0, <https://tabler.io/icons>
27
+ - Package: `@tabler/icons` 3.52.0, <https://tabler.io/icons>
28
28
  - License: MIT, Copyright (c) 2020-2026 Paweł Kuna. Full text: [`licenses/tabler-icons.LICENSE`](licenses/tabler-icons.LICENSE).
29
29
  - Changes: the invisible 24×24 bounding path (`M0 0h24v24H0z`) is left out.
30
30
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@perkyzz/emvb",
3
- "version": "1.2.0",
3
+ "version": "1.4.0",
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.2.0",
53
+ "@perkyzz/emvb-icons": "1.4.0",
54
54
  "photocn": "0.1.2",
55
55
  "zod": ">=4.5.4 <5"
56
56
  },
@@ -60,11 +60,11 @@
60
60
  "@phosphor-icons/react": "2.1.10",
61
61
  "@types/react": "19.3.0",
62
62
  "@types/react-dom": "19.3.0",
63
- "astro": "7.4.11",
63
+ "astro": "7.4.12",
64
64
  "emdash": "1.5.0",
65
65
  "react": "19.3.1",
66
66
  "react-dom": "19.3.1",
67
- "vitest": "5.0.5"
67
+ "vitest": "5.1.0"
68
68
  },
69
69
  "peerDependencies": {
70
70
  "@cloudflare/kumo": "2.6.0 || 2.15.0",
@@ -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
  }
@@ -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 } 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";
@@ -226,6 +227,9 @@ function EditorApp({
226
227
  wrap,
227
228
  addFromPanel,
228
229
  addRecipe,
230
+ layersDrop,
231
+ addTemplate,
232
+ dropTemplate,
229
233
  items: itemActions,
230
234
  } = useNodeActions({ state, latest, dispatch, announce: setAnnouncement, toasts });
231
235
  // W-876: My sections and Save as section (D-060).
@@ -287,6 +291,8 @@ function EditorApp({
287
291
  [state.page.layout, sectionTemplates, loopTemplates],
288
292
  );
289
293
  const collections = useCollectionPreviews(previewLayout, fetcher);
294
+ // W-1086: extension elements render on the server, which has their code; the canvas shows that.
295
+ const extensionOutputs = useExtensionOutputs(coDesign.ghost?.layout ?? previewLayout, fetcher);
290
296
  // W-930: while previewing a proposal the canvas shows its ghost, never the editor's layout changed.
291
297
  const canvasLayout = coDesign.ghost?.layout ?? state.page.layout;
292
298
  const rendered = React.useMemo(
@@ -305,6 +311,7 @@ function EditorApp({
305
311
  collections,
306
312
  },
307
313
  previewDevice: device,
314
+ extensionOutputs,
308
315
  })
309
316
  : null,
310
317
  [
@@ -316,6 +323,8 @@ function EditorApp({
316
323
  live.site,
317
324
  live.params,
318
325
  collections,
326
+ extensionOutputs,
327
+ extensionManifests,
319
328
  ],
320
329
  );
321
330
  // W-911: field mode previews the unsaved layout with the public renderer, in a sandboxed frame.
@@ -334,6 +343,7 @@ function EditorApp({
334
343
  collections,
335
344
  },
336
345
  previewDevice,
346
+ extensionOutputs,
337
347
  });
338
348
  return previewDocument({
339
349
  html: result.html,
@@ -380,7 +390,8 @@ function EditorApp({
380
390
  if (!node) return "Element";
381
391
  const name = node.editorLabel ?? ELEMENT_NAMES[node.type] ?? node.type;
382
392
  // 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;
393
+ const props = node.props as { partId?: unknown; panelPartId?: unknown } | undefined;
394
+ const partId = props?.partId ?? props?.panelPartId;
384
395
  const status = typeof partId === "string" ? partStatus?.[partId] : undefined;
385
396
  return status && status !== "published" ? `${name} · ${partDraftLabel(status)}` : name;
386
397
  },
@@ -568,6 +579,8 @@ function EditorApp({
568
579
  onSelect={(id) => dispatch({ type: "select", id })}
569
580
  onAdd={addFromPanel}
570
581
  onRecipe={addRecipe}
582
+ onTemplate={addTemplate}
583
+ design={state.design}
571
584
  formsAvailable={formsAvailable}
572
585
  onDuplicate={duplicate}
573
586
  onMoveUp={(id) => arrange(id, moveUp)}
@@ -577,6 +590,8 @@ function EditorApp({
577
590
  saved={saved}
578
591
  onSaveSection={setSaveAsk}
579
592
  {...(!host.field && collection === PAGES_COLLECTION ? { coDesign } : {})}
593
+ onDropNew={layersDrop.add}
594
+ onMoveTo={layersDrop.move}
580
595
  onRename={(id, label) =>
581
596
  dispatch({
582
597
  type: "update-node",
@@ -630,6 +645,11 @@ function EditorApp({
630
645
  statePreview={statePreview}
631
646
  refusal={refusalShown ? refusal : null}
632
647
  onDropNew={(elementType, parentId, index) => {
648
+ const template = templateIdOf(elementType);
649
+ if (template !== null) {
650
+ dropTemplate(template, parentId, index);
651
+ return;
652
+ }
633
653
  const node = newElement(
634
654
  elementType,
635
655
  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,
@@ -20,6 +20,9 @@ const REACT_ATTR: Record<string, string> = {
20
20
  playsinline: "playsInline",
21
21
  autoplay: "autoPlay",
22
22
  datetime: "dateTime",
23
+ // W-1048: Hotspots open their notes with the Popover API.
24
+ popovertarget: "popoverTarget",
25
+ popovertargetaction: "popoverTargetAction",
23
26
  // The canvas never updates a radio from props, so a tab chosen there stays chosen (QA-5).
24
27
  checked: "defaultChecked",
25
28
  };
@@ -38,6 +41,8 @@ const BOOLEAN_ATTRS = new Set([
38
41
  "autoplay",
39
42
  "required",
40
43
  "novalidate",
44
+ // W-1065: a form's Previous and Next buttons, shown only by the forms script.
45
+ "hidden",
41
46
  ]);
42
47
 
43
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);
@@ -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
+ }
@@ -0,0 +1,141 @@
1
+ import {
2
+ canDrop,
3
+ findNode,
4
+ isParentNode,
5
+ parentOf,
6
+ type DragSource,
7
+ type Layout,
8
+ } from "../../../core/index.ts";
9
+
10
+ /** W-1080: hovering a collapsed row this long during a drag opens it. */
11
+ export const EXPAND_DELAY_MS = 600;
12
+ /** W-1080: hovering the Layers tab this long during a drag from Add switches to it. */
13
+ export const TAB_SPRING_MS = 500;
14
+
15
+ /** Which part of a Layers row the pointer is over. */
16
+ export type LayerZone = "before" | "inside" | "after";
17
+
18
+ /**
19
+ * A row's top quarter drops before it and its bottom quarter after it; the middle half drops
20
+ * inside an element that holds others. Rows that hold nothing split in two. The page row always
21
+ * takes the drop inside.
22
+ */
23
+ export function layerZone(
24
+ offsetY: number,
25
+ height: number,
26
+ holdsOthers: boolean,
27
+ isRoot: boolean,
28
+ ): LayerZone {
29
+ if (isRoot) return "inside";
30
+ const part = height > 0 ? offsetY / height : 0.5;
31
+ if (!holdsOthers) return part < 0.5 ? "before" : "after";
32
+ return part < 0.25 ? "before" : part > 0.75 ? "after" : "inside";
33
+ }
34
+
35
+ /** The deepest level whose indent the pointer has passed (`x` from the row's left edge). */
36
+ export function depthAtX(x: number, indent: (depth: number) => number, maxDepth: number): number {
37
+ let depth = 0;
38
+ while (depth < maxDepth && x >= indent(depth + 1)) depth += 1;
39
+ return depth;
40
+ }
41
+
42
+ /** The row being hovered, as Layers shows it. */
43
+ export type LayerRowView = {
44
+ id: string;
45
+ depth: number;
46
+ /** Expanded with its children shown below it. */
47
+ open: boolean;
48
+ };
49
+
50
+ export type LayerPlace = {
51
+ parentId: string;
52
+ index: number;
53
+ /** The depth the drop line is drawn at (the new element's depth). */
54
+ depth: number;
55
+ /** Line above or below the hovered row; null when the row itself is highlighted (inside). */
56
+ edge: "top" | "bottom" | null;
57
+ };
58
+
59
+ const siblingsOf = (layout: Layout, id: string) => {
60
+ const parentId = parentOf(layout, id);
61
+ const parent = parentId ? findNode(layout, parentId) : undefined;
62
+ return parent && isParentNode(parent)
63
+ ? { parent, index: parent.children.findIndex((child) => child.id === id) }
64
+ : null;
65
+ };
66
+
67
+ /**
68
+ * Where a drop on `row` in `zone` goes. "after" an open element goes first inside it (the line
69
+ * sits between it and its first child). "after" the last child can climb out `outdent` levels,
70
+ * as the pointer moves left, to drop after its parent instead. Null when the row is gone.
71
+ */
72
+ export function layerPlace(
73
+ layout: Layout,
74
+ row: LayerRowView,
75
+ zone: LayerZone,
76
+ outdent = 0,
77
+ ): LayerPlace | null {
78
+ const node = findNode(layout, row.id);
79
+ if (!node) return null;
80
+ if (zone === "inside" || row.id === layout.root.id) {
81
+ if (!isParentNode(node)) return null;
82
+ return { parentId: node.id, index: node.children.length, depth: row.depth + 1, edge: null };
83
+ }
84
+ if (zone === "before") {
85
+ const at = siblingsOf(layout, row.id);
86
+ return at ? { parentId: at.parent.id, index: at.index, depth: row.depth, edge: "top" } : null;
87
+ }
88
+ if (row.open && isParentNode(node) && node.children.length > 0) {
89
+ return { parentId: node.id, index: 0, depth: row.depth + 1, edge: "bottom" };
90
+ }
91
+ let depth = row.depth;
92
+ let at = siblingsOf(layout, row.id);
93
+ while (at && outdent > 0 && at.index === at.parent.children.length - 1) {
94
+ const up = siblingsOf(layout, at.parent.id);
95
+ if (!up) break;
96
+ depth -= 1;
97
+ outdent -= 1;
98
+ at = up;
99
+ }
100
+ if (!at) return null;
101
+ return { parentId: at.parent.id, index: at.index + 1, depth, edge: "bottom" };
102
+ }
103
+
104
+ export type LayerDrop =
105
+ | { ok: true; place: LayerPlace }
106
+ | { ok: false; reason: string; place: LayerPlace };
107
+
108
+ /**
109
+ * A Layers drop, checked with the canvas's own rule (`canDrop`): into itself or a descendant,
110
+ * a parent that refuses the child, full Tabs and the like are refused with the canvas's reason.
111
+ * An unknown source (the browser hides it until drop) is allowed provisionally; the drop checks
112
+ * again.
113
+ */
114
+ export function resolveLayerDrop(
115
+ layout: Layout,
116
+ row: LayerRowView,
117
+ zone: LayerZone,
118
+ source: DragSource | null,
119
+ outdent = 0,
120
+ ): LayerDrop | null {
121
+ const place = layerPlace(layout, row, zone, outdent);
122
+ if (!place) return null;
123
+ if (!source) return { ok: true, place };
124
+ const allowed = canDrop(layout, source, place.parentId);
125
+ return allowed.ok ? { ok: true, place } : { ok: false, reason: allowed.reason, place };
126
+ }
127
+
128
+ /** Pixels to scroll the panel by for a pointer near its top or bottom edge during a drag. */
129
+ export function autoScrollStep(
130
+ pointerY: number,
131
+ top: number,
132
+ bottom: number,
133
+ edge = 32,
134
+ max = 14,
135
+ ): number {
136
+ if (bottom - top < edge * 3) return 0;
137
+ const speed = (into: number) => Math.ceil(max * Math.min(1, into / edge));
138
+ if (pointerY < top + edge) return -speed(top + edge - pointerY);
139
+ if (pointerY > bottom - edge) return speed(pointerY - (bottom - edge));
140
+ return 0;
141
+ }
@@ -1,5 +1,7 @@
1
1
  import {
2
2
  defaultElement,
3
+ emptyDesign,
4
+ templateSectionNode,
3
5
  updateNode,
4
6
  ELEMENTS,
5
7
  isExtensionType,
@@ -112,11 +114,62 @@ export function newCarouselSlide(n: number, random?: () => number): LayoutNode {
112
114
  };
113
115
  }
114
116
 
117
+ /** W-1043: the rows a new Price list starts with, then its Add item cycles through them. */
118
+ const STARTER_PRICES = [
119
+ ["Espresso", "$3", "A double shot, served short."],
120
+ ["Cappuccino", "$4.50", "Espresso, steamed milk and foam."],
121
+ ["Croissant", "$3.75", "Baked every morning."],
122
+ ] as const;
123
+
124
+ /** W-1043: a Price list item for a new Price list or its Add item. */
125
+ export function newPriceListItem(n: number, random?: () => number): LayoutNode {
126
+ const [title, price, description] =
127
+ STARTER_PRICES[(n - 1) % STARTER_PRICES.length] ?? STARTER_PRICES[0];
128
+ return { id: newNodeId(random), type: "price-list-item", props: { title, price, description } };
129
+ }
130
+
131
+ /** W-1047: the services new Share links cycle through. */
132
+ const STARTER_SHARES = ["facebook", "x", "linkedin", "email", "whatsapp", "bluesky"] as const;
133
+
134
+ /** W-1047: a Share link for new Share buttons or their Add link. */
135
+ export function newShareLink(n: number, random?: () => number): LayoutNode {
136
+ const network = STARTER_SHARES[(n - 1) % STARTER_SHARES.length] ?? STARTER_SHARES[0];
137
+ return { id: newNodeId(random), type: "share-link", props: { network } };
138
+ }
139
+
140
+ /** W-1048: where new Hotspots land, so markers added one after another don't overlap. */
141
+ const STARTER_SPOTS = [
142
+ [25, 35],
143
+ [60, 25],
144
+ [45, 70],
145
+ [80, 60],
146
+ [15, 80],
147
+ ] as const;
148
+
149
+ /** W-1048: a Hotspot for a new Hotspots picture or its Add marker. */
150
+ export function newHotspot(n: number, random?: () => number): LayoutNode {
151
+ const [x, y] = STARTER_SPOTS[(n - 1) % STARTER_SPOTS.length] ?? STARTER_SPOTS[0];
152
+ return {
153
+ id: newNodeId(random),
154
+ type: "hotspot",
155
+ props: { title: `Point ${n}`, text: `What point ${n} shows.`, x, y },
156
+ };
157
+ }
158
+
115
159
  /** W-1019: an empty Gallery image for a Gallery's Add picture; its panel picks the picture. */
116
160
  export function newGalleryImage(random?: () => number): LayoutNode {
117
161
  return { id: newNodeId(random), type: "gallery-image", props: { src: "", alt: "Image" } };
118
162
  }
119
163
 
164
+ const TEMPLATE_PREFIX = "template:";
165
+
166
+ /** W-1068: the drag type of a starter section template, carried like a new element's type. */
167
+ export const templateDragType = (id: string) => `${TEMPLATE_PREFIX}${id}`;
168
+
169
+ /** The template id a drag type names, or null for an element type. */
170
+ export const templateIdOf = (type: string): string | null =>
171
+ type.startsWith(TEMPLATE_PREFIX) ? type.slice(TEMPLATE_PREFIX.length) : null;
172
+
120
173
  /**
121
174
  * Default node for a new element from the Add panel. Only new inserts get starter children;
122
175
  * saved Accordions and Tabs with no items keep working as they are (W-130).
@@ -126,6 +179,11 @@ export function newElement(
126
179
  random?: () => number,
127
180
  extensionDefaults?: Record<string, unknown>,
128
181
  ): LayoutNode | null {
182
+ // W-1068: a dragged starter template. Drops build it again with the site's styles.
183
+ const template = templateIdOf(type);
184
+ if (template !== null) {
185
+ return templateSectionNode(template, emptyDesign(), null, random ? { random } : {}) ?? null;
186
+ }
129
187
  // W-927: extension elements are stored as UnknownNodes with namespaced types.
130
188
  if (isExtensionType(type)) {
131
189
  return {
@@ -180,6 +238,24 @@ export function newElement(
180
238
  children: [1, 2, 3].map((n) => newCarouselSlide(n, random)),
181
239
  };
182
240
  }
241
+ if (type === "hotspots") {
242
+ return {
243
+ ...defaultElement("hotspots", newNodeId(random)),
244
+ children: [1, 2, 3].map((n) => newHotspot(n, random)),
245
+ };
246
+ }
247
+ if (type === "share-buttons") {
248
+ return {
249
+ ...defaultElement("share-buttons", newNodeId(random)),
250
+ children: [1, 2, 3, 4].map((n) => newShareLink(n, random)),
251
+ };
252
+ }
253
+ if (type === "price-list") {
254
+ return {
255
+ ...defaultElement("price-list", newNodeId(random)),
256
+ children: [1, 2, 3].map((n) => newPriceListItem(n, random)),
257
+ };
258
+ }
183
259
  if (type === "social-icons") {
184
260
  return {
185
261
  ...defaultElement("social-icons", newNodeId(random)),