@perkyzz/emvb 1.3.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 (134) 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/editor/A11yCopilot.tsx +3 -1
  5. package/src/admin/editor/Editor.tsx +22 -2
  6. package/src/admin/editor/Timeline.tsx +1 -8
  7. package/src/admin/editor/canvas/DeviceBar.tsx +7 -2
  8. package/src/admin/editor/canvas/EmptyCanvas.tsx +11 -2
  9. package/src/admin/editor/canvas/use-canvas-dnd.ts +1 -20
  10. package/src/admin/editor/canvas/vnode-react.tsx +2 -0
  11. package/src/admin/editor/co-design.ts +36 -1
  12. package/src/admin/editor/dnd/dragged-source.ts +22 -0
  13. package/src/admin/editor/dnd/layer-drop.ts +141 -0
  14. package/src/admin/editor/dnd/new-element.ts +16 -0
  15. package/src/admin/editor/editor-css.ts +9 -1
  16. package/src/admin/editor/element-chrome.ts +6 -0
  17. package/src/admin/editor/feature-css.ts +22 -0
  18. package/src/admin/editor/inert-links.ts +8 -0
  19. package/src/admin/editor/panels/ColorControl.tsx +2 -2
  20. package/src/admin/editor/panels/FontFaces.tsx +342 -0
  21. package/src/admin/editor/panels/LayersPanel.tsx +56 -6
  22. package/src/admin/editor/panels/LeftPanel.tsx +153 -29
  23. package/src/admin/editor/panels/SettingsPanel.tsx +1 -0
  24. package/src/admin/editor/panels/SiteStylesDrawer.tsx +5 -0
  25. package/src/admin/editor/panels/TemplatesPanel.tsx +205 -0
  26. package/src/admin/editor/panels/TokenScales.tsx +2 -0
  27. package/src/admin/editor/panels/TriggersEditor.tsx +203 -9
  28. package/src/admin/editor/panels/VariableSection.tsx +111 -7
  29. package/src/admin/editor/panels/color-space.ts +71 -6
  30. package/src/admin/editor/panels/settings/AudienceEditor.tsx +3 -0
  31. package/src/admin/editor/panels/settings/FieldControl.tsx +18 -0
  32. package/src/admin/editor/panels/settings/LoopItemBindControl.tsx +9 -3
  33. package/src/admin/editor/panels/settings/StickyControl.tsx +97 -0
  34. package/src/admin/editor/panels/settings/StyleRow.tsx +14 -0
  35. package/src/admin/editor/panels/settings/style-sections.ts +19 -2
  36. package/src/admin/editor/panels/url-rules.ts +43 -0
  37. package/src/admin/editor/panels/use-layers-drop.ts +232 -0
  38. package/src/admin/editor/store.ts +4 -2
  39. package/src/admin/editor/useExtensions.ts +3 -1
  40. package/src/admin/editor/useNodeActions.ts +74 -1
  41. package/src/admin/editor/useSave.ts +116 -85
  42. package/src/admin/export-api.ts +25 -2
  43. package/src/admin/extension-outputs.ts +179 -0
  44. package/src/admin/font-files-api.ts +38 -0
  45. package/src/admin/pages/ImportButton.tsx +15 -4
  46. package/src/admin/pages/ImportElementorDialog.tsx +22 -188
  47. package/src/admin/pages/ImportHtmlDialog.tsx +209 -0
  48. package/src/admin/pages/ImportImageCopies.tsx +167 -0
  49. package/src/admin/pages/ImportReport.tsx +63 -0
  50. package/src/admin/pages/NewPageDialog.tsx +54 -32
  51. package/src/admin/pages/PageList.tsx +9 -0
  52. package/src/admin/pages/ThemePartList.tsx +9 -0
  53. package/src/astro/EmVBPage.astro +5 -2
  54. package/src/astro/extension-styles.ts +35 -0
  55. package/src/astro/forms/EmVBFormsClient.astro +3 -0
  56. package/src/astro/forms/enhance.ts +107 -0
  57. package/src/astro/popups/runtime.ts +47 -2
  58. package/src/astro/render.ts +19 -4
  59. package/src/astro/resolve-theme.ts +11 -4
  60. package/src/astro/widgets/EmVBStickyRuntime.astro +9 -0
  61. package/src/astro/widgets/EmVBThemeRuntime.astro +9 -0
  62. package/src/astro/widgets/EmVBWidgetRuntimes.astro +12 -0
  63. package/src/astro/widgets/alerts.ts +16 -2
  64. package/src/astro/widgets/carousel.ts +65 -24
  65. package/src/astro/widgets/countdown.ts +18 -7
  66. package/src/astro/widgets/extension-runtimes.ts +27 -0
  67. package/src/astro/widgets/headline.ts +14 -5
  68. package/src/astro/widgets/sticky.ts +87 -0
  69. package/src/astro/widgets/theme.ts +52 -0
  70. package/src/constants.ts +1 -1
  71. package/src/core/a11y/audit.ts +150 -2
  72. package/src/core/arrange.ts +19 -1
  73. package/src/core/css/font-face.ts +72 -0
  74. package/src/core/css/generate.ts +35 -1
  75. package/src/core/elements/form-elements.ts +119 -9
  76. package/src/core/elements/icon-svg.ts +14 -0
  77. package/src/core/elements/index.ts +24 -4
  78. package/src/core/elements/input-limits.ts +44 -0
  79. package/src/core/elements/menu.ts +109 -47
  80. package/src/core/elements/site.ts +108 -0
  81. package/src/core/elements/widgets.ts +13 -3
  82. package/src/core/export/runtimes.generated.ts +7 -5
  83. package/src/core/export/site.ts +50 -4
  84. package/src/core/extensions/classes.ts +114 -0
  85. package/src/core/extensions/index.ts +17 -2
  86. package/src/core/extensions/normalize.ts +13 -0
  87. package/src/core/extensions/registry.ts +134 -10
  88. package/src/core/extensions/render-ext.ts +66 -21
  89. package/src/core/extensions/safe-nodes.ts +67 -11
  90. package/src/core/extensions/types.ts +48 -1
  91. package/src/core/fonts/files.ts +74 -0
  92. package/src/core/fonts/google.ts +112 -0
  93. package/src/core/fonts/test-font.ts +9 -0
  94. package/src/core/import/elementor/context.ts +13 -4
  95. package/src/core/import/elementor/index.ts +32 -21
  96. package/src/core/import/elementor/widgets.ts +114 -12
  97. package/src/core/import/html/blocks.ts +602 -0
  98. package/src/core/import/html/index.ts +155 -0
  99. package/src/core/import/html/map.ts +958 -0
  100. package/src/core/import/html/parse.ts +430 -0
  101. package/src/core/index.ts +45 -0
  102. package/src/core/migrate/v18.ts +3 -0
  103. package/src/core/public-attributes.ts +17 -0
  104. package/src/core/render/extras.ts +31 -7
  105. package/src/core/render/form.ts +103 -10
  106. package/src/core/render/index.ts +151 -15
  107. package/src/core/render/section.ts +31 -1
  108. package/src/core/render/spacer-basis.ts +102 -0
  109. package/src/core/render/theme-boot.ts +16 -0
  110. package/src/core/render/vnode.ts +1 -1
  111. package/src/core/sanitize/css.ts +68 -3
  112. package/src/core/sanitize/motion.ts +12 -0
  113. package/src/core/schema/design.ts +40 -0
  114. package/src/core/schema/layout.ts +114 -5
  115. package/src/core/schema/style.ts +28 -0
  116. package/src/core/templates/index.ts +218 -0
  117. package/src/core/templates/pages.ts +29 -0
  118. package/src/core/templates/sections.ts +794 -0
  119. package/src/core/templates/types.ts +9 -0
  120. package/src/core/theme/dynamic.ts +9 -6
  121. package/src/core/theme/popup-markup.ts +21 -2
  122. package/src/core/theme/popup-rules.ts +36 -0
  123. package/src/core/theme/triggers.ts +64 -5
  124. package/src/core/translatable.ts +5 -2
  125. package/src/extension-build.ts +331 -0
  126. package/src/index.ts +25 -3
  127. package/src/mcp/brief.ts +191 -0
  128. package/src/mcp/prompts.ts +33 -0
  129. package/src/mcp/read.ts +29 -1
  130. package/src/mcp/tools.ts +40 -1
  131. package/src/mcp/write.ts +41 -1
  132. package/src/server/extension-routes.ts +73 -0
  133. package/src/server/font-routes.ts +301 -0
  134. package/src/server/plugin.ts +9 -0
@@ -0,0 +1,97 @@
1
+ import type * as React from "react";
2
+ import type { DesignSystem, FlatStyleProps } from "../../../../core/index.ts";
3
+ import { ColorControl } from "../ColorControl.tsx";
4
+ import { HintedSwitch } from "./HintedSwitch.tsx";
5
+ import { NumberField, type NumberSpec } from "./NumberRow.tsx";
6
+
7
+ type Sticky = NonNullable<FlatStyleProps["stickyMotion"]>;
8
+ type Effects = Extract<Sticky, { hide?: unknown }>;
9
+
10
+ const DISTANCE: NumberSpec = { min: 10, max: 2000, integer: true, example: "120", suffix: "px" };
11
+ const PADDING: NumberSpec = { min: 0, max: 400, integer: true, example: "8", suffix: "px" };
12
+
13
+ /** The effects, or undefined when none is left (an empty record would be refused). */
14
+ function tidy(next: Effects): Sticky | undefined {
15
+ const { distance, background, shadow, padding, hide } = next;
16
+ const kept: Effects = {
17
+ ...(distance !== undefined ? { distance } : {}),
18
+ ...(background !== undefined ? { background } : {}),
19
+ ...(shadow ? { shadow } : {}),
20
+ ...(padding !== undefined ? { padding } : {}),
21
+ ...(hide ? { hide } : {}),
22
+ };
23
+ const any =
24
+ kept.background !== undefined || kept.shadow || kept.padding !== undefined || kept.hide;
25
+ return any ? kept : undefined;
26
+ }
27
+
28
+ /**
29
+ * W-1070: "When the page scrolls" in Position: how a sticky header looks once the page has
30
+ * scrolled, and whether it slides away while scrolling down.
31
+ */
32
+ export function StickyControl({
33
+ value,
34
+ design,
35
+ onChange,
36
+ onDesignChange,
37
+ reset,
38
+ }: {
39
+ value: Sticky | undefined;
40
+ design: DesignSystem;
41
+ onChange: (next: Sticky | undefined) => void;
42
+ onDesignChange: (design: DesignSystem) => Promise<void>;
43
+ reset: React.ReactNode;
44
+ }) {
45
+ const current: Effects = value && !("type" in value) ? value : {};
46
+ const set = (patch: Partial<Effects>) => onChange(tidy({ ...current, ...patch }));
47
+ const padding = current.padding;
48
+ const paddingPx =
49
+ padding && typeof padding === "object" && "unit" in padding && padding.unit === "px"
50
+ ? padding.value
51
+ : undefined;
52
+ return (
53
+ <div className="emvb-style-row emvb-sticky-control" data-emvb-style="stickyMotion">
54
+ <p className="emvb-field-label">When the page scrolls</p>
55
+ <HintedSwitch
56
+ label="Hide while scrolling down"
57
+ checked={current.hide === true}
58
+ onCheckedChange={(hide) => set({ hide })}
59
+ hint="It slides back as soon as the visitor scrolls up, and stays while focus is in it."
60
+ />
61
+ <ColorControl
62
+ label="Background once scrolled"
63
+ value={current.background}
64
+ design={design}
65
+ onChange={(background) => set({ background })}
66
+ onDesignChange={onDesignChange}
67
+ />
68
+ <HintedSwitch
69
+ label="Shadow once scrolled"
70
+ checked={current.shadow === true}
71
+ onCheckedChange={(shadow) => set({ shadow })}
72
+ />
73
+ <NumberField
74
+ fieldKey="stickyPadding"
75
+ label="Top and bottom padding once scrolled"
76
+ value={paddingPx}
77
+ spec={PADDING}
78
+ onCommit={(px) =>
79
+ set({ padding: px === undefined ? undefined : { value: px, unit: "px" } })
80
+ }
81
+ />
82
+ <NumberField
83
+ fieldKey="stickyDistance"
84
+ label="Changes over the first"
85
+ value={current.distance}
86
+ spec={DISTANCE}
87
+ inherited={120}
88
+ onCommit={(distance) => set({ distance })}
89
+ />
90
+ <p className="emvb-helper">
91
+ Browsers without scroll-driven animations, and visitors who prefer reduced motion, see it as
92
+ it is.
93
+ </p>
94
+ {reset}
95
+ </div>
96
+ );
97
+ }
@@ -1,6 +1,7 @@
1
1
  import { Input, Select } from "@cloudflare/kumo";
2
2
  import { MotionControl } from "./MotionControl.tsx";
3
3
  import { LoopControl } from "./LoopControl.tsx";
4
+ import { StickyControl } from "./StickyControl.tsx";
4
5
  import { isSafeFontStack, type DesignSystem, type FlatStyleProps } from "../../../../core/index.ts";
5
6
  import type { Fetcher } from "../../../api.ts";
6
7
  import { FIELD } from "../../../ui.ts";
@@ -590,6 +591,18 @@ export function StyleRow({
590
591
  );
591
592
  }
592
593
 
594
+ if (styleKey === "stickyMotion") {
595
+ return (
596
+ <StickyControl
597
+ value={style?.stickyMotion}
598
+ design={design}
599
+ onChange={(stickyMotion) => onPatch({ stickyMotion })}
600
+ onDesignChange={onDesignChange}
601
+ reset={reset}
602
+ />
603
+ );
604
+ }
605
+
593
606
  if (styleKey === "loopMotion") {
594
607
  return (
595
608
  <LoopControl
@@ -683,6 +696,7 @@ export const IMPLEMENTED_STYLE_KEYS: StyleKey[] = [
683
696
  "entrance",
684
697
  "scrollMotion",
685
698
  "loopMotion",
699
+ "stickyMotion",
686
700
  // W-974: set by the Height rows' dvh/svh units (LengthRow), never a row of its own.
687
701
  "viewportUnits",
688
702
  "transition",
@@ -179,7 +179,17 @@ const SECTION_KEYS: Record<StyleSectionId, StyleKey[]> = {
179
179
  "flexShrink",
180
180
  "flexBasis",
181
181
  ],
182
- position: ["position", "top", "right", "bottom", "left", "zIndex", "alignSelf", "order"],
182
+ position: [
183
+ "position",
184
+ "top",
185
+ "right",
186
+ "bottom",
187
+ "left",
188
+ "zIndex",
189
+ "alignSelf",
190
+ "order",
191
+ "stickyMotion",
192
+ ],
183
193
  typography: [
184
194
  "fontFamily",
185
195
  "fontSize",
@@ -300,6 +310,10 @@ const TYPE_SECTION_KEYS: Record<string, Partial<Record<StyleSectionId, StyleKey[
300
310
 
301
311
  const OFFSETS = new Set<StyleKey>(["top", "right", "bottom", "left"]);
302
312
 
313
+ /** W-1070: "When the page scrolls" is for elements that stay in view: sticky or fixed. */
314
+ const pinned = (position: FlatStyleProps["position"]) =>
315
+ position === "sticky" || position === "fixed";
316
+
303
317
  /** Offsets only do anything once the element is positioned (W-088). */
304
318
  export const offsetsApply = (position: FlatStyleProps["position"]) =>
305
319
  position !== undefined && position !== "static";
@@ -319,7 +333,9 @@ export function keysFor(
319
333
  (
320
334
  TYPE_SECTION_KEYS[type]?.[section] ??
321
335
  SECTION_KEYS[section].filter((key) => ONLY_FOR[key]?.includes(type) ?? true)
322
- ).filter((key) => !OFFSETS.has(key) || offsetsApply(position)),
336
+ )
337
+ .filter((key) => !OFFSETS.has(key) || offsetsApply(position))
338
+ .filter((key) => key !== "stickyMotion" || pinned(position)),
323
339
  );
324
340
  const keys = SECTION_KEYS[section].filter(
325
341
  (key) => offered.has(key) || style?.[key] !== undefined,
@@ -427,6 +443,7 @@ export const STYLE_LABELS: Record<StyleKey, string> = {
427
443
  entrance: "Entrance",
428
444
  scrollMotion: "Scroll motion",
429
445
  loopMotion: "Loop",
446
+ stickyMotion: "When the page scrolls",
430
447
  viewportUnits: "Viewport units",
431
448
  iconRotate: "Rotate",
432
449
  iconFlip: "Flip",
@@ -0,0 +1,43 @@
1
+ import { MAX_URL_PARAM_RULES, URL_PARAM_NAME, type UrlParamRule } from "../../../core/index.ts";
2
+
3
+ /**
4
+ * W-1081: a popup's URL rules as the editor writes them, one per line: `utm_source=newsletter`
5
+ * (that value), `coupon` (there at all), `!preview` or `!lang=fr` (not there).
6
+ */
7
+ export function formatUrlRules(rules: readonly UrlParamRule[] | null | undefined): string {
8
+ return (rules ?? [])
9
+ .map((r) => `${r.absent ? "!" : ""}${r.name}${r.value === undefined ? "" : `=${r.value}`}`)
10
+ .join("\n");
11
+ }
12
+
13
+ export type ParsedUrlRules = { ok: true; rules: UrlParamRule[] } | { ok: false; message: string };
14
+
15
+ export function parseUrlRules(text: string): ParsedUrlRules {
16
+ const lines = text
17
+ .split("\n")
18
+ .map((line) => line.trim())
19
+ .filter(Boolean);
20
+ if (lines.length > MAX_URL_PARAM_RULES)
21
+ return { ok: false, message: `Use at most ${MAX_URL_PARAM_RULES} rules.` };
22
+ const rules: UrlParamRule[] = [];
23
+ for (const line of lines) {
24
+ const absent = line.startsWith("!");
25
+ const body = absent ? line.slice(1).trim() : line;
26
+ const at = body.indexOf("=");
27
+ const name = (at === -1 ? body : body.slice(0, at)).trim();
28
+ if (!URL_PARAM_NAME.test(name))
29
+ return {
30
+ ok: false,
31
+ message: `"${line}" isn't a rule: write a name such as utm_source, then =value if you like.`,
32
+ };
33
+ const value = at === -1 ? undefined : body.slice(at + 1).trim();
34
+ if (value !== undefined && value.length > 200)
35
+ return { ok: false, message: "A value can be at most 200 characters." };
36
+ rules.push({
37
+ name,
38
+ ...(value === undefined ? {} : { value }),
39
+ ...(absent ? { absent: true } : {}),
40
+ });
41
+ }
42
+ return { ok: true, rules };
43
+ }
@@ -0,0 +1,232 @@
1
+ import * as React from "react";
2
+ import { findNode, isParentNode, type Layout } from "../../../core/index.ts";
3
+ import { dragStash } from "../dnd/drag-stash.ts";
4
+ import { draggedSource } from "../dnd/dragged-source.ts";
5
+ import { EXISTING_ELEMENT_MIME, NEW_ELEMENT_MIME, transferKinds } from "../dnd/drop-target.ts";
6
+ import {
7
+ autoScrollStep,
8
+ depthAtX,
9
+ EXPAND_DELAY_MS,
10
+ layerZone,
11
+ resolveLayerDrop,
12
+ type LayerDrop,
13
+ } from "../dnd/layer-drop.ts";
14
+
15
+ /** What Layers shows during a drag (W-1080). */
16
+ type LayersDropShown = {
17
+ /** The row outlined: the container a drop goes inside, or the refused row. */
18
+ mark: { id: string; kind: "inside" | "invalid" } | null;
19
+ /** The insertion line, in list pixels; `start` is from the inline-start edge (right in RTL). */
20
+ line: { top: number; start: number } | null;
21
+ /** Why the drop is refused, next to the refused row. */
22
+ refusal: { top: number; start: number; reason: string } | null;
23
+ };
24
+
25
+ const sameShown = (a: LayersDropShown | null, b: LayersDropShown | null) =>
26
+ JSON.stringify(a) === JSON.stringify(b);
27
+
28
+ /** Layers reads right to left when the admin does; indents then grow from the right edge. */
29
+ const isRtl = (el: Element) =>
30
+ getComputedStyle(el).direction === "rtl" || el.closest("[dir]")?.getAttribute("dir") === "rtl";
31
+
32
+ export type LayersDropCallbacks = {
33
+ /** Adds a new element from the Add panel at the drop. */
34
+ onDropNew?: (type: string, parentId: string, index: number) => void;
35
+ /** Moves an element (dragged from Layers or the canvas) to the drop. */
36
+ onMoveTo?: (id: string, parentId: string, index: number) => void;
37
+ };
38
+
39
+ type Live = {
40
+ layout: Layout | null;
41
+ depths: Map<string, number>;
42
+ collapsed: Set<string>;
43
+ expand: (id: string) => void;
44
+ } & LayersDropCallbacks;
45
+
46
+ const rowOf = (target: EventTarget | null): HTMLElement | null =>
47
+ target instanceof Element ? target.closest<HTMLElement>("[data-emvb-layer]") : null;
48
+
49
+ /** The element that scrolls Layers: the left panel itself. */
50
+ const scrollerOf = (list: HTMLElement): HTMLElement | null =>
51
+ list.closest<HTMLElement>(".emvb-panel") ?? list.parentElement;
52
+
53
+ /**
54
+ * W-1080: drag Add tiles, Layers rows or canvas elements onto the Layers list. Between rows draws a
55
+ * line at the new element's depth, the middle of a row that holds others outlines it, a refused
56
+ * drop outlines the row in danger with the canvas's reason. A collapsed row opens after
57
+ * `EXPAND_DELAY_MS`; the panel scrolls near its edges. The drop runs the canvas's own
58
+ * add and move (one undo step each).
59
+ */
60
+ export function useLayersDrop(
61
+ live: Live,
62
+ indent: (depth: number) => number,
63
+ listRef: React.RefObject<HTMLUListElement | null>,
64
+ ) {
65
+ const [shown, setShownState] = React.useState<LayersDropShown | null>(null);
66
+ // dragover fires every few milliseconds; only a changed line or outline re-renders Layers.
67
+ const setShown = React.useCallback(
68
+ (next: LayersDropShown | null) =>
69
+ setShownState((current) => (sameShown(current, next) ? current : next)),
70
+ [],
71
+ );
72
+ const latest = React.useRef(live);
73
+ React.useLayoutEffect(() => {
74
+ latest.current = live;
75
+ });
76
+ const expandTimer = React.useRef<{ id: string; timer: ReturnType<typeof setTimeout> } | null>(
77
+ null,
78
+ );
79
+ const scroll = React.useRef<{ step: number; frame: number | null }>({ step: 0, frame: null });
80
+
81
+ const stopTimers = React.useCallback(() => {
82
+ if (expandTimer.current) clearTimeout(expandTimer.current.timer);
83
+ expandTimer.current = null;
84
+ scroll.current.step = 0;
85
+ if (scroll.current.frame !== null) cancelAnimationFrame(scroll.current.frame);
86
+ scroll.current.frame = null;
87
+ }, []);
88
+ const clear = React.useCallback(() => {
89
+ stopTimers();
90
+ setShown(null);
91
+ }, [stopTimers, setShown]);
92
+
93
+ React.useEffect(() => stopTimers, [stopTimers]);
94
+ React.useEffect(() => {
95
+ if (!shown) return;
96
+ // Entering anything outside Layers (the canvas, the Add tab) clears it. dragleave can't: it
97
+ // also fires moving between a row's own children.
98
+ const enter = (event: DragEvent) => {
99
+ const panel = listRef.current?.parentElement;
100
+ if (!(event.target instanceof Node) || !panel?.contains(event.target)) clear();
101
+ };
102
+ window.addEventListener("dragend", clear);
103
+ window.addEventListener("drop", clear);
104
+ document.addEventListener("dragenter", enter);
105
+ return () => {
106
+ window.removeEventListener("dragend", clear);
107
+ window.removeEventListener("drop", clear);
108
+ document.removeEventListener("dragenter", enter);
109
+ };
110
+ }, [shown, clear, listRef]);
111
+
112
+ const enabled = !!(live.onDropNew || live.onMoveTo);
113
+
114
+ const resolve = (
115
+ event: React.DragEvent,
116
+ ): { drop: LayerDrop; row: HTMLElement; depth: number; existing: boolean } | null => {
117
+ const { layout, depths, collapsed } = latest.current;
118
+ const list = listRef.current;
119
+ if (!layout || !list) return null;
120
+ const kinds = transferKinds(event.dataTransfer);
121
+ if (!kinds.neu && !kinds.existing) return null;
122
+ const row =
123
+ rowOf(event.target) ??
124
+ list.querySelector<HTMLElement>(`[data-emvb-layer="${CSS.escape(layout.root.id)}"]`);
125
+ const id = row?.getAttribute("data-emvb-layer");
126
+ const node = id ? findNode(layout, id) : undefined;
127
+ if (!row || !id || !node) return null;
128
+ const depth = depths.get(id) ?? 0;
129
+ const holds = isParentNode(node);
130
+ const open = holds && !collapsed.has(id) && node.children.length > 0;
131
+ const rect = row.getBoundingClientRect();
132
+ const onRow = rowOf(event.target) !== null;
133
+ const zone = onRow
134
+ ? layerZone(event.clientY - rect.top, rect.height, holds, id === layout.root.id)
135
+ : "inside";
136
+ // The pointer's distance from the row's inline-start edge, where the indent is.
137
+ const fromStart = isRtl(row) ? rect.right - event.clientX : event.clientX - rect.left;
138
+ const outdent = depth - depthAtX(fromStart, indent, depth);
139
+ const source = draggedSource(event.dataTransfer, kinds.existing);
140
+ const drop = resolveLayerDrop(layout, { id, depth, open }, zone, source, outdent);
141
+ return drop ? { drop, row, depth, existing: kinds.existing } : null;
142
+ };
143
+
144
+ const autoScroll = (clientY: number) => {
145
+ const list = listRef.current;
146
+ const scroller = list ? scrollerOf(list) : null;
147
+ if (!scroller) return;
148
+ const box = scroller.getBoundingClientRect();
149
+ scroll.current.step = autoScrollStep(clientY, box.top, box.bottom);
150
+ if (scroll.current.step === 0 || scroll.current.frame !== null) return;
151
+ const tick = () => {
152
+ if (scroll.current.step === 0) {
153
+ scroll.current.frame = null;
154
+ return;
155
+ }
156
+ scroller.scrollTop += scroll.current.step;
157
+ scroll.current.frame = requestAnimationFrame(tick);
158
+ };
159
+ scroll.current.frame = requestAnimationFrame(tick);
160
+ };
161
+
162
+ const autoExpand = (id: string) => {
163
+ const { layout, collapsed } = latest.current;
164
+ const node = layout ? findNode(layout, id) : undefined;
165
+ const closed = !!node && isParentNode(node) && node.children.length > 0 && collapsed.has(id);
166
+ if (expandTimer.current?.id === id && closed) return;
167
+ if (expandTimer.current) clearTimeout(expandTimer.current.timer);
168
+ expandTimer.current = closed
169
+ ? {
170
+ id,
171
+ timer: setTimeout(() => {
172
+ expandTimer.current = null;
173
+ latest.current.expand(id);
174
+ }, EXPAND_DELAY_MS),
175
+ }
176
+ : null;
177
+ };
178
+
179
+ const onDragOver = (event: React.DragEvent<HTMLElement>) => {
180
+ if (!enabled) return;
181
+ const found = resolve(event);
182
+ if (!found) return;
183
+ event.preventDefault();
184
+ autoScroll(event.clientY);
185
+ const { drop, row, depth, existing } = found;
186
+ autoExpand(row.getAttribute("data-emvb-layer") ?? "");
187
+ const top = row.offsetTop;
188
+ if (!drop.ok) {
189
+ event.dataTransfer.dropEffect = "none";
190
+ setShown({
191
+ mark: { id: row.getAttribute("data-emvb-layer") ?? "", kind: "invalid" },
192
+ line: null,
193
+ refusal: { top: top + row.offsetHeight + 2, start: indent(depth), reason: drop.reason },
194
+ });
195
+ return;
196
+ }
197
+ event.dataTransfer.dropEffect = existing ? "move" : "copy";
198
+ const { place } = drop;
199
+ setShown({
200
+ mark: place.edge === null ? { id: place.parentId, kind: "inside" } : null,
201
+ line:
202
+ place.edge === null
203
+ ? null
204
+ : {
205
+ top: place.edge === "top" ? top - 1 : top + row.offsetHeight - 1,
206
+ start: indent(place.depth),
207
+ },
208
+ refusal: null,
209
+ });
210
+ };
211
+
212
+ const onDrop = (event: React.DragEvent<HTMLElement>) => {
213
+ if (!enabled) return;
214
+ const found = resolve(event);
215
+ if (!found) return;
216
+ event.preventDefault();
217
+ const transfer = event.dataTransfer;
218
+ const id = transfer.getData(EXISTING_ELEMENT_MIME) || dragStash.id() || "";
219
+ const type = transfer.getData(NEW_ELEMENT_MIME) || dragStash.type() || "";
220
+ dragStash.clear();
221
+ clear();
222
+ if (!found.drop.ok) return;
223
+ const { parentId, index } = found.drop.place;
224
+ if (found.existing) {
225
+ if (id) latest.current.onMoveTo?.(id, parentId, index);
226
+ } else if (type) latest.current.onDropNew?.(type, parentId, index);
227
+ };
228
+
229
+ // dragenter takes the same path: the spec makes a cancelled dragenter the drop target, and a
230
+ // browser may send only dragenter while the pointer crosses rows.
231
+ return { shown, handlers: enabled ? { onDragEnter: onDragOver, onDragOver, onDrop } : {} };
232
+ }
@@ -54,7 +54,8 @@ export type EditorAction =
54
54
  | { type: "select"; id: string | null }
55
55
  | { type: "update-node"; id: string; update: (node: LayoutNode) => LayoutNode }
56
56
  | { type: "delete-node"; id: string }
57
- | { type: "restore" }
57
+ /** Restores the deletion of `id`, only while it is still the last one (W-1053). */
58
+ | { type: "restore"; id: string }
58
59
  | { type: "add-root-container" }
59
60
  | { type: "add-node"; node: LayoutNode; parentId: string; index: number }
60
61
  | { type: "move-node"; id: string; parentId: string; index: number }
@@ -205,7 +206,8 @@ export function editorReducer(state: EditorState, action: EditorAction): EditorS
205
206
  }
206
207
  case "restore": {
207
208
  const removed = state.lastDeleted;
208
- if (!removed || !state.page.layout) return state;
209
+ // W-1053: a Restore left over from a deletion that Undo already took back does nothing.
210
+ if (!removed || removed.node.id !== action.id || !state.page.layout) return state;
209
211
  const layout = insertNode(state.page.layout, removed.parentId, removed.index, removed.node);
210
212
  return withLayout(state, layout, removed.node.id, null);
211
213
  }
@@ -1,6 +1,6 @@
1
1
  import * as React from "react";
2
2
  import { PLUGIN_ID } from "../../constants.ts";
3
- import type { ExtensionManifest } from "../../core/index.ts";
3
+ import { rememberExtensionManifests, type ExtensionManifest } from "../../core/index.ts";
4
4
  import { requestJson, type Fetcher } from "../api.ts";
5
5
  import { setAdminExtensionManifests } from "./extension-manifests.ts";
6
6
 
@@ -27,6 +27,8 @@ export function useExtensionManifests(fetcher: Fetcher): readonly ExtensionManif
27
27
  ok.push(m);
28
28
  }
29
29
  setAdminExtensionManifests(ok);
30
+ // W-1086: class allowlists and stylesheets for the canvas renderer.
31
+ rememberExtensionManifests(ok);
30
32
  setLoaded(ok);
31
33
  })
32
34
  .catch(() => undefined);
@@ -4,6 +4,7 @@ import {
4
4
  addNode,
5
5
  addNodeNear,
6
6
  addSectionNear,
7
+ canDrop,
7
8
  duplicateNode,
8
9
  wrapNode,
9
10
  type WrapType,
@@ -12,11 +13,13 @@ import {
12
13
  LAYOUT_SCHEMA_VERSION,
13
14
  moveDown,
14
15
  moveIn,
16
+ moveNode,
15
17
  moveOut,
16
18
  newNodeId,
17
19
  moveUp,
18
20
  parentOf,
19
21
  recipeNode,
22
+ templateSectionNode,
20
23
  withFreshIds,
21
24
  subtreeSize,
22
25
  type Arranged,
@@ -28,6 +31,7 @@ import { adminExtensionDefaults } from "./extension-manifests.ts";
28
31
  import { newElement, withLoopPostTitleLevel, withPageHeadingLevel } from "./dnd/new-element.ts";
29
32
  import { ELEMENT_NAMES } from "./element-chrome.ts";
30
33
  import type { ItemActions } from "./panels/settings/ItemList.tsx";
34
+ import { isSharedPart } from "./panels/settings/heading-warning.ts";
31
35
  import type { EditorAction, EditorState } from "./store.ts";
32
36
 
33
37
  const MOVES = new Set<unknown>([moveUp, moveDown, moveIn, moveOut]);
@@ -84,6 +88,15 @@ export function useNodeActions({
84
88
  count: number;
85
89
  } | null>(null);
86
90
  const lastToast = React.useRef<string | null>(null);
91
+ // W-1053: once Undo brings the deleted element back, its toast has nothing left to restore.
92
+ const restoreToast = React.useRef<{ toast: string; node: string } | null>(null);
93
+ const pageLayout = state.page.layout;
94
+ React.useEffect(() => {
95
+ const open = restoreToast.current;
96
+ if (!open || !pageLayout || !findNode(pageLayout, open.node)) return;
97
+ toasts.close(open.toast);
98
+ restoreToast.current = null;
99
+ }, [pageLayout, toasts]);
87
100
 
88
101
  const canDelete = (id: string) => !!state.page.layout && state.page.layout.root.id !== id;
89
102
  const canMove = canDelete;
@@ -107,7 +120,7 @@ export function useNodeActions({
107
120
  children: "Restore",
108
121
  variant: "secondary",
109
122
  onClick: () => {
110
- dispatch({ type: "restore" });
123
+ dispatch({ type: "restore", id });
111
124
  toasts.close(toastId);
112
125
  // The toast is closing with focus in it; the restored element's row takes it.
113
126
  keepFocusInLayers(true);
@@ -116,6 +129,7 @@ export function useNodeActions({
116
129
  ],
117
130
  });
118
131
  lastToast.current = toastId;
132
+ restoreToast.current = { toast: toastId, node: id };
119
133
  };
120
134
 
121
135
  const remove = (id: string) => {
@@ -255,7 +269,64 @@ export function useNodeActions({
255
269
  place(layout, withFreshIds(layout, node), `${node.editorLabel ?? "Section"} section`, true);
256
270
  };
257
271
 
272
+ /**
273
+ * W-1080: a drop on Layers runs the canvas's own add and move (one undo step), selects what
274
+ * landed and says where, as a keyboard move does. A refusal is announced.
275
+ */
276
+ const layersDrop = {
277
+ move: (id: string, parentId: string, index: number) => {
278
+ const layout = latest.current.page.layout;
279
+ if (!layout) return;
280
+ const result = moveNode(layout, id, parentId, index);
281
+ if (!result.ok) {
282
+ announce(result.reason);
283
+ return;
284
+ }
285
+ if (result.layout === layout) return;
286
+ dispatch({ type: "move-node", id, parentId, index });
287
+ announce(movedTo(result.layout, id));
288
+ },
289
+ add: (type: string, parentId: string, index: number) => {
290
+ const layout = latest.current.page.layout;
291
+ const node = newElement(type, undefined, adminExtensionDefaults(type));
292
+ if (!layout || !node) return;
293
+ const allowed = canDrop(layout, { kind: "new", node }, parentId);
294
+ if (!allowed.ok) {
295
+ announce(allowed.reason);
296
+ return;
297
+ }
298
+ dispatch({ type: "add-node", node, parentId, index });
299
+ const parent = findNode(layout, parentId);
300
+ const where = parentId === layout.root.id ? "Page" : ELEMENT_NAMES[parent?.type ?? ""];
301
+ announce(`${ELEMENT_NAMES[node.type] ?? "Element"} added inside ${where ?? "Container"}`);
302
+ },
303
+ };
304
+
305
+ /**
306
+ * W-1068: a starter template's section, in the site's styles, placed like a recipe (click) or
307
+ * where it was dropped. Either is one ordinary layout edit, so one Undo takes it back.
308
+ */
309
+ const buildTemplate = (id: string, layout: Layout) =>
310
+ templateSectionNode(id, latest.current.design, layout, {
311
+ noH1: isSharedPart(latest.current.page.partType),
312
+ });
313
+ const addTemplate = (id: string) => {
314
+ const layout = latest.current.page.layout ?? startingLayout();
315
+ const node = buildTemplate(id, layout);
316
+ if (!node) return;
317
+ place(layout, node, `${node.editorLabel ?? "Template"} section`, true);
318
+ };
319
+ const dropTemplate = (id: string, parentId: string, index: number) => {
320
+ const layout = latest.current.page.layout;
321
+ if (!layout) return;
322
+ const node = buildTemplate(id, layout);
323
+ if (!node) return;
324
+ dispatch({ type: "add-node", node, parentId, index });
325
+ announce(`${node.editorLabel ?? "Template"} section added`);
326
+ };
327
+
258
328
  return {
329
+ layersDrop,
259
330
  deleteAsk,
260
331
  setDeleteAsk,
261
332
  canDelete,
@@ -267,6 +338,8 @@ export function useNodeActions({
267
338
  wrap,
268
339
  addFromPanel,
269
340
  addRecipe,
341
+ addTemplate,
342
+ dropTemplate,
270
343
  items,
271
344
  };
272
345
  }