@perkyzz/emvb 0.6.0 → 0.8.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 (208) hide show
  1. package/README.md +2 -2
  2. package/THIRD_PARTY_NOTICES.md +1 -1
  3. package/package.json +7 -7
  4. package/src/admin/access/RequireEditor.tsx +7 -7
  5. package/src/admin/access/role.ts +5 -2
  6. package/src/admin/content-api.ts +10 -3
  7. package/src/admin/content-item.ts +1 -1
  8. package/src/admin/editor/A11yCopilot.tsx +104 -56
  9. package/src/admin/editor/CommandPalette.tsx +29 -13
  10. package/src/admin/editor/DialogCloseButton.tsx +16 -0
  11. package/src/admin/editor/Editor.tsx +115 -20
  12. package/src/admin/editor/EditorToasts.tsx +26 -0
  13. package/src/admin/editor/PerfMeter.tsx +92 -73
  14. package/src/admin/editor/SavedSectionDialogs.tsx +169 -0
  15. package/src/admin/editor/ShareLink.tsx +102 -72
  16. package/src/admin/editor/ShortcutsDialog.tsx +37 -18
  17. package/src/admin/editor/Timeline.tsx +250 -160
  18. package/src/admin/editor/TopBar.tsx +71 -14
  19. package/src/admin/editor/canvas/CanvasFrame.tsx +10 -1
  20. package/src/admin/editor/canvas/CanvasTextEdit.tsx +8 -2
  21. package/src/admin/editor/canvas/drop-line.ts +11 -3
  22. package/src/admin/editor/canvas/frame-focus-ring.ts +37 -0
  23. package/src/admin/editor/canvas/use-canvas-dnd.ts +32 -3
  24. package/src/admin/editor/canvas/vnode-react.tsx +7 -0
  25. package/src/admin/editor/collection-previews.ts +10 -0
  26. package/src/admin/editor/dialogs.tsx +41 -28
  27. package/src/admin/editor/dnd/drop-target.ts +26 -1
  28. package/src/admin/editor/edited-noun.ts +15 -0
  29. package/src/admin/editor/editor-chrome.tsx +43 -7
  30. package/src/admin/editor/editor-commands.ts +17 -2
  31. package/src/admin/editor/editor-css.ts +75 -24
  32. package/src/admin/editor/element-chrome.ts +21 -11
  33. package/src/admin/editor/feature-css.ts +56 -14
  34. package/src/admin/editor/focus-when-lost.ts +23 -0
  35. package/src/admin/editor/icons/IconLibraryDialog.tsx +54 -18
  36. package/src/admin/editor/icons/library.ts +1 -1
  37. package/src/admin/editor/icons/use-icon-library.ts +5 -2
  38. package/src/admin/editor/ime.ts +29 -0
  39. package/src/admin/editor/palette-items.ts +27 -3
  40. package/src/admin/editor/panels/AddPanel.tsx +44 -11
  41. package/src/admin/editor/panels/ClassesSection.tsx +18 -7
  42. package/src/admin/editor/panels/ColorControl.tsx +130 -23
  43. package/src/admin/editor/panels/ConditionsEditor.tsx +52 -26
  44. package/src/admin/editor/panels/ElementPanel.tsx +134 -24
  45. package/src/admin/editor/panels/LayersPanel.tsx +61 -20
  46. package/src/admin/editor/panels/LeftPanel.tsx +9 -1
  47. package/src/admin/editor/panels/PageSettings.tsx +66 -35
  48. package/src/admin/editor/panels/SavedSectionsGroup.tsx +246 -0
  49. package/src/admin/editor/panels/SiteStylesDrawer.tsx +224 -42
  50. package/src/admin/editor/panels/TokenScales.tsx +88 -48
  51. package/src/admin/editor/panels/TriggerSettings.tsx +50 -12
  52. package/src/admin/editor/panels/TriggersEditor.tsx +3 -2
  53. package/src/admin/editor/panels/VariableSection.tsx +48 -18
  54. package/src/admin/editor/panels/color-space.ts +23 -29
  55. package/src/admin/editor/panels/settings/AdvancedFields.tsx +12 -2
  56. package/src/admin/editor/panels/settings/AudienceEditor.tsx +87 -74
  57. package/src/admin/editor/panels/settings/BackgroundControls.tsx +55 -11
  58. package/src/admin/editor/panels/settings/BackgroundFill.tsx +3 -2
  59. package/src/admin/editor/panels/settings/BindingsEditor.tsx +15 -18
  60. package/src/admin/editor/panels/settings/BoxControl.tsx +2 -1
  61. package/src/admin/editor/panels/settings/ClassChip.tsx +21 -9
  62. package/src/admin/editor/panels/settings/ClassChipInput.tsx +24 -16
  63. package/src/admin/editor/panels/settings/DraftTextField.tsx +41 -3
  64. package/src/admin/editor/panels/settings/EffectsControls.tsx +38 -14
  65. package/src/admin/editor/panels/settings/FieldBindControl.tsx +46 -28
  66. package/src/admin/editor/panels/settings/FieldControl.tsx +20 -8
  67. package/src/admin/editor/panels/settings/FormBindControl.tsx +2 -2
  68. package/src/admin/editor/panels/settings/HintedSwitch.tsx +33 -0
  69. package/src/admin/editor/panels/settings/IconControls.tsx +33 -13
  70. package/src/admin/editor/panels/settings/IconPicker.tsx +2 -0
  71. package/src/admin/editor/panels/settings/ImageSourcesField.tsx +3 -1
  72. package/src/admin/editor/panels/settings/ItemList.tsx +15 -2
  73. package/src/admin/editor/panels/settings/LengthRow.tsx +8 -6
  74. package/src/admin/editor/panels/settings/LoopItemBindControl.tsx +1 -1
  75. package/src/admin/editor/panels/settings/MediaPicker.tsx +127 -23
  76. package/src/admin/editor/panels/settings/MotionControl.tsx +28 -15
  77. package/src/admin/editor/panels/settings/NumberRow.tsx +9 -3
  78. package/src/admin/editor/panels/settings/PanelSelect.tsx +50 -0
  79. package/src/admin/editor/panels/settings/QueryStyleRows.tsx +25 -18
  80. package/src/admin/editor/panels/settings/RequiredFieldsNotice.tsx +66 -1
  81. package/src/admin/editor/panels/settings/StyleRow.tsx +10 -3
  82. package/src/admin/editor/panels/settings/StyleSources.tsx +4 -1
  83. package/src/admin/editor/panels/settings/VariantEditor.tsx +10 -1
  84. package/src/admin/editor/panels/settings/box-link-name.ts +6 -2
  85. package/src/admin/editor/panels/settings/class-suggest.ts +7 -7
  86. package/src/admin/editor/panels/settings/query-style.ts +38 -9
  87. package/src/admin/editor/panels/settings/svg-images.ts +13 -0
  88. package/src/admin/editor/panels/site-list.tsx +20 -6
  89. package/src/admin/editor/panels/variable-values.ts +11 -4
  90. package/src/admin/editor/restore-deleted.ts +21 -2
  91. package/src/admin/editor/section-templates.ts +81 -12
  92. package/src/admin/editor/shortcuts.ts +31 -2
  93. package/src/admin/editor/store.ts +7 -0
  94. package/src/admin/editor/useEditorCommands.ts +61 -15
  95. package/src/admin/editor/useEditorData.ts +4 -2
  96. package/src/admin/editor/useEditorShortcuts.ts +17 -7
  97. package/src/admin/editor/useNodeActions.ts +61 -6
  98. package/src/admin/editor/useSave.ts +22 -7
  99. package/src/admin/editor/useSavedSections.ts +197 -0
  100. package/src/admin/forms-api.ts +2 -0
  101. package/src/admin/image-editor/Canvas.tsx +61 -17
  102. package/src/admin/image-editor/CurvesPanel.tsx +2 -1
  103. package/src/admin/image-editor/ExportDialog.tsx +48 -18
  104. package/src/admin/image-editor/ImageEditorDialog.tsx +179 -8
  105. package/src/admin/image-editor/MetadataPanel.tsx +15 -4
  106. package/src/admin/image-editor/crop-geometry.ts +3 -2
  107. package/src/admin/image-editor/image-editor-css.ts +15 -10
  108. package/src/admin/image-editor/load.ts +9 -2
  109. package/src/admin/image-editor/parts.tsx +69 -19
  110. package/src/admin/image-editor/save.ts +54 -8
  111. package/src/admin/media-api.ts +2 -1
  112. package/src/admin/pages/AgentsPage.tsx +138 -27
  113. package/src/admin/pages/CreateDialog.tsx +97 -30
  114. package/src/admin/pages/NewPageDialog.tsx +21 -3
  115. package/src/admin/pages/NewThemePartDialog.tsx +11 -3
  116. package/src/admin/pages/PageList.tsx +14 -6
  117. package/src/admin/pages/SetupShell.tsx +28 -12
  118. package/src/admin/pages/ThemePartList.tsx +59 -11
  119. package/src/admin/pages/list-kit.tsx +106 -24
  120. package/src/admin/saved-sections-api.ts +51 -0
  121. package/src/admin/search.ts +15 -0
  122. package/src/admin/setup/useSetupStatus.ts +1 -1
  123. package/src/admin/theme-api.ts +16 -5
  124. package/src/admin/ui.ts +82 -22
  125. package/src/astro/floats/runtime.ts +21 -0
  126. package/src/astro/menu/runtime.ts +34 -1
  127. package/src/astro/popups/runtime.ts +41 -9
  128. package/src/astro/render.ts +3 -0
  129. package/src/astro/resolve-theme.ts +53 -11
  130. package/src/astro/resolve.ts +9 -1
  131. package/src/astro/tabs/runtime.ts +12 -0
  132. package/src/astro/theme-posts.ts +2 -2
  133. package/src/astro/visitor.ts +2 -0
  134. package/src/constants.ts +1 -1
  135. package/src/core/a11y/audit.ts +196 -24
  136. package/src/core/arrange.ts +48 -12
  137. package/src/core/audience/rules.ts +5 -1
  138. package/src/core/audience/variants.ts +29 -3
  139. package/src/core/clipboard.ts +7 -0
  140. package/src/core/css/generate.ts +31 -6
  141. package/src/core/css/print.ts +5 -0
  142. package/src/core/data/bindings.ts +8 -1
  143. package/src/core/design/classes.ts +39 -16
  144. package/src/core/design/devices.ts +7 -13
  145. package/src/core/design/diff.ts +6 -0
  146. package/src/core/design/merge.ts +90 -2
  147. package/src/core/design/states.ts +7 -13
  148. package/src/core/design/tokens.ts +16 -2
  149. package/src/core/design/transfer.ts +33 -6
  150. package/src/core/design/variables.ts +30 -9
  151. package/src/core/elements/dynamic-elements.ts +53 -14
  152. package/src/core/elements/form-elements.ts +55 -16
  153. package/src/core/elements/index.ts +84 -39
  154. package/src/core/elements/menu.ts +40 -19
  155. package/src/core/elements/select-prompt.ts +3 -0
  156. package/src/core/elements/svg-ids.ts +39 -0
  157. package/src/core/forms/binding.ts +57 -16
  158. package/src/core/forms/definition.ts +72 -0
  159. package/src/core/history/diff.ts +18 -1
  160. package/src/core/icons/animation-runs.ts +11 -0
  161. package/src/core/icons/catalog.ts +3 -2
  162. package/src/core/image-edit/schema.ts +11 -1
  163. package/src/core/image-edit/summary.ts +6 -3
  164. package/src/core/index.ts +35 -1
  165. package/src/core/limits.ts +12 -1
  166. package/src/core/migrate/index.ts +3 -0
  167. package/src/core/perf/meter.ts +42 -7
  168. package/src/core/recipes/index.ts +5 -4
  169. package/src/core/render/context.ts +8 -0
  170. package/src/core/render/dynamic-post.ts +69 -12
  171. package/src/core/render/extras.ts +77 -4
  172. package/src/core/render/form.ts +140 -6
  173. package/src/core/render/index.ts +156 -20
  174. package/src/core/render/loop.ts +44 -8
  175. package/src/core/render/pagination.ts +18 -4
  176. package/src/core/render/section.ts +27 -0
  177. package/src/core/render/tabs.ts +12 -3
  178. package/src/core/render/vnode.ts +1 -1
  179. package/src/core/sanitize/css.ts +29 -8
  180. package/src/core/sanitize/embed-url.ts +42 -5
  181. package/src/core/sanitize/url.ts +2 -1
  182. package/src/core/saved-sections.ts +318 -0
  183. package/src/core/schema/design.ts +1 -1
  184. package/src/core/schema/layout.ts +16 -7
  185. package/src/core/schema/style.ts +4 -2
  186. package/src/core/stats.ts +2 -1
  187. package/src/core/theme/conditions.ts +3 -1
  188. package/src/core/theme/dynamic.ts +36 -5
  189. package/src/core/theme/float.ts +12 -2
  190. package/src/core/theme/pagination.ts +50 -29
  191. package/src/core/theme/part-types.ts +4 -4
  192. package/src/core/theme/popup-markup.ts +23 -5
  193. package/src/core/theme/popup-rules.ts +1 -0
  194. package/src/core/theme/triggers.ts +3 -2
  195. package/src/core/tree-ops.ts +27 -0
  196. package/src/mcp/ports.ts +22 -1
  197. package/src/mcp/rate-limit.ts +2 -1
  198. package/src/mcp/read.ts +15 -3
  199. package/src/mcp/refs.ts +18 -0
  200. package/src/mcp/sections.ts +183 -0
  201. package/src/mcp/tools.ts +44 -0
  202. package/src/mcp/write.ts +178 -14
  203. package/src/server/agent-settings.ts +1 -1
  204. package/src/server/hooks.ts +5 -3
  205. package/src/server/icon-routes.ts +30 -9
  206. package/src/server/mcp-routes.ts +8 -1
  207. package/src/server/plugin.ts +14 -0
  208. package/src/server/saved-sections.ts +163 -0
@@ -2,6 +2,7 @@ import { createPortal } from "react-dom";
2
2
  import { isMultilineText, type Layout, type PopupDevice, type VNode } from "../../../core/index.ts";
3
3
  import type { PasteRefusal } from "../useClipboardActions.ts";
4
4
  import { CanvasTextEdit } from "./CanvasTextEdit.tsx";
5
+ import { useFrameFocusRing } from "./frame-focus-ring.ts";
5
6
  import { type CanvasZoom } from "./canvas-scale.ts";
6
7
  import { SelectionOverlay, type Box, type InvalidDrop } from "./SelectionOverlay.tsx";
7
8
  import type { StatePreview } from "./state-preview.ts";
@@ -38,6 +39,9 @@ const EDITOR_CANVAS_CSS =
38
39
  `:where(${DROP_BOXES}){min-height:48px}` +
39
40
  `:is(${DROP_BOXES}){outline:1px dashed #94a3b8;outline-offset:-1px;display:flex;align-items:center;justify-content:center}` +
40
41
  `:is(${DROP_BOXES})::after{content:"Drop elements here";${HINT}}` +
42
+ // UX-019: an empty page fills the canvas, so the whole stage takes a drop and says how to start.
43
+ ":where(.emvb-root:empty){min-height:100vh}" +
44
+ '.emvb-root:empty::after{content:"Drag an element here from Add to start building";font-size:18px}' +
41
45
  `:where(${DROP_BODIES}){min-height:48px}` +
42
46
  `:is(${DROP_BODIES}){outline:1px dashed #94a3b8;outline-offset:-1px}` +
43
47
  `:is(${DROP_BODIES})::after{content:"Drop elements here";display:block;line-height:48px;text-align:center;${HINT}}` +
@@ -131,6 +135,7 @@ export function CanvasFrame({
131
135
  onScale,
132
136
  refusal,
133
137
  });
138
+ const focusRing = useFrameFocusRing();
134
139
  const { dropLine, dropTarget, invalid } = useCanvasDnD({
135
140
  doc: session.doc,
136
141
  frame: session.frame,
@@ -185,7 +190,11 @@ export function CanvasFrame({
185
190
  data-emvb-canvas=""
186
191
  srcDoc={SRCDOC}
187
192
  sandbox="allow-same-origin"
188
- onLoad={onLoad}
193
+ data-emvb-canvas-focus={focusRing.ring ? "keyboard" : undefined}
194
+ onLoad={(event) => {
195
+ focusRing.watch(event);
196
+ onLoad();
197
+ }}
189
198
  />
190
199
  {editingId && editingText !== null && editingBox && editingEl?.nodeType === 1 && (
191
200
  <CanvasTextEdit
@@ -1,6 +1,7 @@
1
1
  import * as React from "react";
2
2
  import { commitPlainText } from "../../../core/index.ts";
3
3
  import type { Box } from "./SelectionOverlay.tsx";
4
+ import { isCancelEscape, isCommitEnter } from "../ime.ts";
4
5
 
5
6
  /** Edits one element's plain text over its canvas box (W-097). The iframe stays script-free. */
6
7
  export function CanvasTextEdit({
@@ -30,6 +31,11 @@ export function CanvasTextEdit({
30
31
  letterSpacing: computed?.letterSpacing,
31
32
  lineHeight: computed?.lineHeight,
32
33
  padding: computed?.padding,
34
+ // W-560: an RTL heading edited left to right jumped to the other side and reordered mixed
35
+ // text; an uppercase one showed its lower-case letters.
36
+ direction: computed?.direction as React.CSSProperties["direction"],
37
+ textTransform: computed?.textTransform as React.CSSProperties["textTransform"],
38
+ wordSpacing: computed?.wordSpacing,
33
39
  };
34
40
  }, [element]);
35
41
  const ref = React.useRef<HTMLTextAreaElement>(null);
@@ -74,10 +80,10 @@ export function CanvasTextEdit({
74
80
  onBlur={() => finish(commitPlainText(draft, multiline))}
75
81
  onKeyDown={(event) => {
76
82
  event.stopPropagation();
77
- if (event.key === "Escape") {
83
+ if (isCancelEscape(event)) {
78
84
  event.preventDefault();
79
85
  finish(null);
80
- } else if (event.key === "Enter" && !multiline) {
86
+ } else if (isCommitEnter(event) && !multiline) {
81
87
  event.preventDefault();
82
88
  finish(commitPlainText(draft, false));
83
89
  }
@@ -9,15 +9,23 @@ export function dropLineBox(
9
9
  index: number,
10
10
  ): Box {
11
11
  const row = direction.startsWith("row");
12
+ // W-559: in a reversed flow (row-reverse, or a row in RTL) the first child is at the far end.
13
+ const reverse = direction.endsWith("reverse");
12
14
  const [start, size] = row ? (["left", "width"] as const) : (["top", "height"] as const);
15
+ const end = (rect: Rect) => rect[start] + rect[size];
13
16
  const first = children[0];
14
17
  const last = children.at(-1);
15
18
  const before = index > 0 ? children[index - 1] : undefined;
16
19
  const after = index < children.length ? children[index] : undefined;
17
20
  let at = container[start];
18
- if (first && index <= 0) at = first[start];
19
- else if (last && index >= children.length) at = last[start] + last[size];
20
- else if (before && after) at = (before[start] + before[size] + after[start]) / 2;
21
+ if (first && index <= 0) at = reverse ? end(first) : first[start];
22
+ else if (last && index >= children.length) at = reverse ? last[start] : end(last);
23
+ else if (before && after) {
24
+ at =
25
+ before[start] <= after[start]
26
+ ? (end(before) + after[start]) / 2
27
+ : (end(after) + before[start]) / 2;
28
+ }
21
29
  return row
22
30
  ? { top: container.top, left: at - 1, width: 2, height: container.height }
23
31
  : { top: at - 1, left: container.left, width: container.width, height: 2 };
@@ -0,0 +1,37 @@
1
+ import { useRef, useState, type SyntheticEvent } from "react";
2
+
3
+ /**
4
+ * W-809: the canvas iframe is a Tab stop (its document takes the canvas shortcuts), but a focused
5
+ * iframe matches neither :focus nor :focus-visible in Chrome, so CSS alone never drew a ring
6
+ * (WCAG 2.4.7), and the iframe element gets no focus event either. The frame's own window
7
+ * reports its focus here instead. A pointer press inside the page marks
8
+ * the focus as a click, which gets no ring, as :focus-visible would decide.
9
+ */
10
+ export function useFrameFocusRing() {
11
+ const [ring, setRing] = useState(false);
12
+ const pointer = useRef(false);
13
+ const onPointer = () => {
14
+ pointer.current = true;
15
+ setRing(false);
16
+ };
17
+ const onFocus = () => {
18
+ setRing(!pointer.current);
19
+ pointer.current = false;
20
+ };
21
+ const onBlur = () => {
22
+ pointer.current = false;
23
+ setRing(false);
24
+ };
25
+ return {
26
+ ring,
27
+ /** Call on the frame's load: listens to its window's focus and to presses in its page. */
28
+ watch: (event: SyntheticEvent<HTMLIFrameElement>) => {
29
+ const win = event.currentTarget.contentWindow;
30
+ const doc = event.currentTarget.contentDocument;
31
+ win?.addEventListener("focus", onFocus);
32
+ win?.addEventListener("blur", onBlur);
33
+ doc?.addEventListener("pointerdown", onPointer, true);
34
+ doc?.addEventListener("mousedown", onPointer, true);
35
+ },
36
+ };
37
+ }
@@ -3,6 +3,7 @@ import {
3
3
  canDrop,
4
4
  findNode,
5
5
  isParentNode,
6
+ parentOf,
6
7
  REASONS,
7
8
  type DragSource,
8
9
  type Layout,
@@ -13,9 +14,11 @@ import {
13
14
  dropIndex,
14
15
  edgeDrop,
15
16
  EXISTING_ELEMENT_MIME,
17
+ flowDirection,
16
18
  idAt,
17
19
  NEW_ELEMENT_MIME,
18
20
  transferKinds,
21
+ type Direction,
19
22
  type Rect,
20
23
  } from "../dnd/drop-target.ts";
21
24
  import { dragStash } from "../dnd/drag-stash.ts";
@@ -25,11 +28,30 @@ import { dropLineBox } from "./drop-line.ts";
25
28
  import type { Box, DropTarget, InvalidDrop } from "./SelectionOverlay.tsx";
26
29
  import { boxOf, type CanvasSelection } from "./use-canvas-session.ts";
27
30
 
28
- const directionOf = (node: LayoutNode) =>
31
+ const ownDirection = (node: LayoutNode) =>
29
32
  (isParentNode(node) ? node.style?.flexDirection : undefined) ?? "column";
30
33
 
31
34
  const childrenOf = (node: LayoutNode): LayoutNode[] => (isParentNode(node) ? node.children : []);
32
35
 
36
+ /**
37
+ * W-559: the direction the canvas shows for `node`'s children, read from the element that
38
+ * actually lays them out (a Section's inner box, a Menu's list), so classes, tablet and mobile
39
+ * styles, grids and RTL count. Its own style when nothing is rendered.
40
+ */
41
+ const directionOf = (doc: Document, node: LayoutNode): Direction => {
42
+ const find = (id: string) => doc.querySelector(`[data-emvb-id="${CSS.escape(id)}"]`);
43
+ const first = childrenOf(node)[0];
44
+ const box = (first && find(first.id)?.parentElement) || find(node.id);
45
+ const view = doc.defaultView;
46
+ return box && view ? flowDirection(view.getComputedStyle(box)) : ownDirection(node);
47
+ };
48
+
49
+ const parentShown = (doc: Document, layout: Layout, id: string): Direction | undefined => {
50
+ const parentId = parentOf(layout, id);
51
+ const parent = parentId ? findNode(layout, parentId) : undefined;
52
+ return parent ? directionOf(doc, parent) : undefined;
53
+ };
54
+
33
55
  /** Refusals that end the walk to an accepting ancestor, so the user sees why (W-128). */
34
56
  const STOPS = new Set<string>([REASONS.intoItself, REASONS.tooDeep, REASONS.tooMany]);
35
57
 
@@ -118,10 +140,17 @@ export function useCanvasDnD({
118
140
  const hoveredBox = rectOf(currentDoc, hovered.id);
119
141
  const edge =
120
142
  hoveredBox && hovered.id !== current.root.id
121
- ? edgeDrop(current, hovered, hoveredBox, point, (parent) => verdict(parent).ok)
143
+ ? edgeDrop(
144
+ current,
145
+ hovered,
146
+ hoveredBox,
147
+ point,
148
+ (parent) => verdict(parent).ok,
149
+ parentShown(currentDoc, current, hovered.id),
150
+ )
122
151
  : null;
123
152
  const container = (edge && findNode(current, edge.parentId)) || hovered;
124
- const direction = directionOf(container);
153
+ const direction = directionOf(currentDoc, container);
125
154
  const kids = childrenOf(container);
126
155
  const rects = kids.map((child) => {
127
156
  const rect = rectOf(currentDoc, child.id);
@@ -13,6 +13,13 @@ const REACT_ATTR: Record<string, string> = {
13
13
  minlength: "minLength",
14
14
  maxlength: "maxLength",
15
15
  novalidate: "noValidate",
16
+ // W-804: React warned "Invalid DOM property" for these and the canvas logged an error per image
17
+ // or background video (a priority image's fetchpriority, srcset, a post date's datetime).
18
+ fetchpriority: "fetchPriority",
19
+ srcset: "srcSet",
20
+ playsinline: "playsInline",
21
+ autoplay: "autoPlay",
22
+ datetime: "dateTime",
16
23
  // The canvas never updates a radio from props, so a tab chosen there stays chosen (QA-5).
17
24
  checked: "defaultChecked",
18
25
  };
@@ -70,6 +70,16 @@ const ORDER: Record<string, string> = {
70
70
  title: "orderBy=title&order=asc",
71
71
  };
72
72
 
73
+ /**
74
+ * W-667: the page plus the synced sections and Loop Item parts it shows, so a collection Loop
75
+ * inside one of those gets real entries on the canvas like it does on the published page.
76
+ */
77
+ export function withPartLayouts(layout: Layout | null, parts: readonly Layout[]): Layout | null {
78
+ if (!layout || parts.length === 0) return layout;
79
+ const children = [...layout.root.children, ...parts.flatMap((part) => part.root.children)];
80
+ return { ...layout, root: { ...layout.root, children } };
81
+ }
82
+
73
83
  /**
74
84
  * Real entries for collection Loops on the canvas (W-308), read through the content API. A
75
85
  * collection the role can't read, or that doesn't exist, keeps the sample entries.
@@ -1,5 +1,8 @@
1
- import { Button, Dialog } from "@cloudflare/kumo";
1
+ import { Button, Dialog, Loader } from "@cloudflare/kumo";
2
+ import { useMediaQuery } from "./useMediaQuery.ts";
3
+ import { useEditedNoun } from "./edited-noun.ts";
2
4
  import { BUTTON, SOLID_DESTRUCTIVE, SOLID_PRIMARY, UI_CSS } from "../ui.ts";
5
+ import { DialogCloseButton } from "./DialogCloseButton.tsx";
3
6
 
4
7
  type OpenProps = { open: boolean; onOpenChange: (open: boolean) => void };
5
8
 
@@ -10,14 +13,15 @@ export function ConflictDialog({
10
13
  onReload,
11
14
  onOverwrite,
12
15
  }: OpenProps & { onReload: () => void; onOverwrite: () => void }) {
16
+ const noun = useEditedNoun();
13
17
  return (
14
18
  <Dialog.Root open={open} onOpenChange={onOpenChange}>
15
19
  <Dialog size="base" className="p-6">
16
20
  <style>{UI_CSS}</style>
17
21
  <div data-emvb-dialog="conflict" className="emvb-dialog">
18
- <Dialog.Title>This page was changed somewhere else</Dialog.Title>
22
+ <Dialog.Title>This {noun} was changed somewhere else</Dialog.Title>
19
23
  <Dialog.Description>
20
- Someone saved this page after you opened it. Reload to get their version and lose your
24
+ Someone saved this {noun} after you opened it. Reload to get their version and lose your
21
25
  unsaved changes, or overwrite their version with yours.
22
26
  </Dialog.Description>
23
27
  <div className="emvb-dialog-actions">
@@ -30,7 +34,7 @@ export function ConflictDialog({
30
34
  style={SOLID_DESTRUCTIVE}
31
35
  onClick={onOverwrite}
32
36
  >
33
- Overwrite
37
+ Overwrite their version
34
38
  </Button>
35
39
  </div>
36
40
  </div>
@@ -56,20 +60,14 @@ export function RevertDialog({
56
60
  live now. This can't be undone.
57
61
  </Dialog.Description>
58
62
  <div className="emvb-dialog-actions">
59
- <Dialog.Close
60
- render={(props) => (
61
- <Button {...props} variant="secondary" className={BUTTON}>
62
- Cancel
63
- </Button>
64
- )}
65
- />
63
+ <DialogCloseButton>Cancel</DialogCloseButton>
66
64
  <Button
67
65
  variant="destructive"
68
66
  className={BUTTON}
69
67
  style={SOLID_DESTRUCTIVE}
70
68
  onClick={onRevert}
71
69
  >
72
- Revert
70
+ Revert to published
73
71
  </Button>
74
72
  </div>
75
73
  </div>
@@ -84,18 +82,35 @@ export function LeaveDialog({
84
82
  onOpenChange,
85
83
  onDiscard,
86
84
  onSaveAndLeave,
87
- }: OpenProps & { onDiscard: () => void; onSaveAndLeave: () => void }) {
85
+ saving = false,
86
+ }: OpenProps & {
87
+ onDiscard: () => void;
88
+ onSaveAndLeave: () => void;
89
+ /** W-834: Save and leave is saving; the dialog shows it and ignores presses and closing. */
90
+ saving?: boolean;
91
+ }) {
92
+ const noun = useEditedNoun();
93
+ const reducedMotion = useMediaQuery("(prefers-reduced-motion: reduce)");
94
+ const unlessSaving = (run: () => void) => () => {
95
+ if (!saving) run();
96
+ };
88
97
  return (
89
- <Dialog.Root open={open} onOpenChange={onOpenChange}>
98
+ <Dialog.Root
99
+ open={open}
100
+ onOpenChange={(next) => {
101
+ if (!next && saving) return;
102
+ onOpenChange(next);
103
+ }}
104
+ >
90
105
  <Dialog size="base" className="p-6">
91
106
  <style>{UI_CSS}</style>
92
107
  <div data-emvb-dialog="leave" className="emvb-dialog">
93
108
  <Dialog.Title>Leave without saving?</Dialog.Title>
94
- <Dialog.Description>You have unsaved changes on this page.</Dialog.Description>
109
+ <Dialog.Description>You have unsaved changes on this {noun}.</Dialog.Description>
95
110
  <div className="emvb-dialog-actions">
96
111
  <Dialog.Close
97
112
  render={(props) => (
98
- <Button {...props} variant="secondary" className={BUTTON}>
113
+ <Button {...props} variant="secondary" className={BUTTON} aria-disabled={saving}>
99
114
  Keep editing
100
115
  </Button>
101
116
  )}
@@ -103,7 +118,8 @@ export function LeaveDialog({
103
118
  <Button
104
119
  variant="secondary"
105
120
  className={`${BUTTON} emvb-danger-text`}
106
- onClick={onDiscard}
121
+ aria-disabled={saving}
122
+ onClick={unlessSaving(onDiscard)}
107
123
  >
108
124
  Discard changes
109
125
  </Button>
@@ -111,9 +127,12 @@ export function LeaveDialog({
111
127
  variant="primary"
112
128
  className={BUTTON}
113
129
  style={SOLID_PRIMARY}
114
- onClick={onSaveAndLeave}
130
+ icon={saving && !reducedMotion ? <Loader size={14} /> : undefined}
131
+ aria-disabled={saving}
132
+ aria-busy={saving}
133
+ onClick={unlessSaving(onSaveAndLeave)}
115
134
  >
116
- Save and leave
135
+ {saving ? "Saving…" : "Save and leave"}
117
136
  </Button>
118
137
  </div>
119
138
  </div>
@@ -139,22 +158,16 @@ export function DeleteSubtreeDialog({
139
158
  <Dialog.Title>
140
159
  Delete {label} and the {inside} element{inside === 1 ? "" : "s"} inside it?
141
160
  </Dialog.Title>
142
- <Dialog.Description>This can be undone with Restore after delete.</Dialog.Description>
161
+ <Dialog.Description>You can undo this with Restore right after.</Dialog.Description>
143
162
  <div className="emvb-dialog-actions">
144
- <Dialog.Close
145
- render={(props) => (
146
- <Button {...props} variant="secondary" className={BUTTON}>
147
- Cancel
148
- </Button>
149
- )}
150
- />
163
+ <DialogCloseButton>Cancel</DialogCloseButton>
151
164
  <Button
152
165
  variant="destructive"
153
166
  className={BUTTON}
154
167
  style={SOLID_DESTRUCTIVE}
155
168
  onClick={onConfirm}
156
169
  >
157
- Delete
170
+ Delete {count} elements
158
171
  </Button>
159
172
  </div>
160
173
  </div>
@@ -58,6 +58,29 @@ function lines(rects: Rect[], row: boolean): number[][] {
58
58
  return result;
59
59
  }
60
60
 
61
+ /** The computed style a container's children flow by (see `flowDirection`). */
62
+ export type FlowStyle = { display: string; flexDirection: string; direction: string };
63
+
64
+ /**
65
+ * W-559: how a container's children run on the canvas, from its computed style, so classes,
66
+ * tablet and mobile styles and grids count, not just the element's own `flexDirection`. A row in
67
+ * an RTL page runs right to left, which the drop maths treats as a reversed row.
68
+ */
69
+ export function flowDirection(style: FlowStyle): Direction {
70
+ const display = style.display;
71
+ let direction: Direction = display.includes("flex")
72
+ ? ((["row", "row-reverse", "column", "column-reverse"] as const).find(
73
+ (d) => d === style.flexDirection,
74
+ ) ?? "row")
75
+ : display.includes("grid")
76
+ ? "row"
77
+ : "column";
78
+ if (style.direction === "rtl" && direction.startsWith("row")) {
79
+ direction = direction === "row" ? "row-reverse" : "row";
80
+ }
81
+ return direction;
82
+ }
83
+
61
84
  /**
62
85
  * The insertion index for a pointer over a flex container, given its children's rects in document
63
86
  * order: before the first child whose middle (along the main axis) is past the pointer.
@@ -130,11 +153,13 @@ export function edgeDrop(
130
153
  rect: Rect,
131
154
  point: Point,
132
155
  accepts: Accepts = anyParent,
156
+ /** The parent's direction as shown (`flowDirection`); else its own style's. */
157
+ shown?: Direction,
133
158
  ): { parentId: string; index: number } | null {
134
159
  const parentId = parentOf(layout, container.id);
135
160
  const parent = parentId ? findNode(layout, parentId) : undefined;
136
161
  if (!parent || !isParentNode(parent) || !accepts(parent)) return null;
137
- const direction = parent.style?.flexDirection ?? "column";
162
+ const direction = shown ?? parent.style?.flexDirection ?? "column";
138
163
  const row = direction.startsWith("row");
139
164
  const span = along(rect, row);
140
165
  const zone = Math.min(EDGE_ZONE, (span.end - span.start) / 4);
@@ -0,0 +1,15 @@
1
+ import * as React from "react";
2
+ import { THEME_PARTS_COLLECTION } from "../../constants.ts";
3
+
4
+ /**
5
+ * UX-087: what the editor has open, in words. Pages and theme parts share the editor, so copy
6
+ * such as "unsaved changes on this page" names the right thing.
7
+ */
8
+ export type EditedNoun = "page" | "theme part";
9
+
10
+ export const EditedNounContext = React.createContext<EditedNoun>("page");
11
+
12
+ export const editedNounOf = (collection: string): EditedNoun =>
13
+ collection === THEME_PARTS_COLLECTION ? "theme part" : "page";
14
+
15
+ export const useEditedNoun = (): EditedNoun => React.useContext(EditedNounContext);
@@ -1,4 +1,6 @@
1
1
  import type { createKumoToastManager } from "@cloudflare/kumo";
2
+ import { focusWhenLost } from "./focus-when-lost.ts";
3
+ import type { SavedSectionActions } from "./useSavedSections.ts";
2
4
  import * as React from "react";
3
5
  import {
4
6
  findNode,
@@ -7,6 +9,7 @@ import {
7
9
  type ElementType,
8
10
  type LayoutNode,
9
11
  type PopupDevice,
12
+ type ThemeDynamicData,
10
13
  } from "../../core/index.ts";
11
14
  import type { Fetcher } from "../api.ts";
12
15
  import { discardDraft } from "../content-api.ts";
@@ -79,6 +82,18 @@ export function useChromeFlags() {
79
82
  const close = (key: ChromeKey) => setFlags((current) => ({ ...current, [key]: false }));
80
83
  const setOpen = (key: ChromeKey) => (next: boolean) =>
81
84
  setFlags((current) => ({ ...current, [key]: next }));
85
+ // W-831: a dialog opened from the command palette has no trigger left to return focus to (the
86
+ // palette is gone), so closing it dropped focus to <body>. When one closes and nothing took
87
+ // focus, go to the selected layer, else the canvas, as the palette does after a command.
88
+ const previous = React.useRef(flags);
89
+ React.useEffect(() => {
90
+ const was = previous.current;
91
+ previous.current = flags;
92
+ const closed = (Object.keys(flags) as ChromeKey[]).some(
93
+ (key) => key !== "palette" && was[key] && !flags[key],
94
+ );
95
+ return closed ? focusWhenLost() : undefined;
96
+ }, [flags]);
82
97
  return { flags, leaving, setLeaving, open, close, setOpen };
83
98
  }
84
99
 
@@ -193,6 +208,8 @@ export function EditorDialogs({
193
208
  finishDelete,
194
209
  playgroundUrl,
195
210
  setAnnouncement,
211
+ parts,
212
+ saved,
196
213
  }: {
197
214
  chrome: ChromeFlags;
198
215
  fetcher: Fetcher;
@@ -215,7 +232,12 @@ export function EditorDialogs({
215
232
  finishDelete: (id: string) => void;
216
233
  playgroundUrl?: string;
217
234
  setAnnouncement: (message: string) => void;
235
+ /** Synced sections and Loop Item parts loaded for the canvas (W-671). */
236
+ parts?: ThemeDynamicData;
237
+ /** My sections for the palette's Insert group (W-876). */
238
+ saved?: SavedSectionActions;
218
239
  }) {
240
+ const [leaveSaving, setLeaveSaving] = React.useState(false);
219
241
  return (
220
242
  <>
221
243
  <DeleteSubtreeDialog
@@ -223,7 +245,13 @@ export function EditorDialogs({
223
245
  onOpenChange={(open) => !open && setDeleteAsk(null)}
224
246
  label={deleteAsk?.label ?? "Element"}
225
247
  count={deleteAsk?.count ?? 0}
226
- onConfirm={() => deleteAsk && finishDelete(deleteAsk.id)}
248
+ onConfirm={() => {
249
+ if (!deleteAsk) return;
250
+ finishDelete(deleteAsk.id);
251
+ // W-835: the dialog hands focus back to the deleted row, which is gone; go to the
252
+ // newly selected layer (or the canvas) instead of <body>.
253
+ focusWhenLost();
254
+ }}
227
255
  />
228
256
  <PaletteImageEditor
229
257
  open={chrome.flags.imageEditor}
@@ -245,6 +273,9 @@ export function EditorDialogs({
245
273
  formsAvailable,
246
274
  insert: addFromPanel,
247
275
  insertRecipe: addRecipe,
276
+ ...(saved
277
+ ? { savedSections: saved.list, insertSaved: (id) => void saved.insert(id) }
278
+ : {}),
248
279
  select: (id) => dispatch({ type: "select", id }),
249
280
  applyClass: (nodeId, classId) =>
250
281
  dispatch({
@@ -317,6 +348,7 @@ export function EditorDialogs({
317
348
  onOpenChange={chrome.setOpen("perf")}
318
349
  layout={state.page.layout}
319
350
  design={state.design}
351
+ parts={parts}
320
352
  onSelect={(id) => dispatch({ type: "select", id })}
321
353
  />
322
354
  <ConflictDialog
@@ -344,12 +376,16 @@ export function EditorDialogs({
344
376
  open={chrome.flags.leave}
345
377
  onOpenChange={chrome.setOpen("leave")}
346
378
  onDiscard={() => chrome.setLeaving(true)}
347
- onSaveAndLeave={() =>
348
- void save().then((rev) => {
349
- chrome.close("leave");
350
- if (rev) chrome.setLeaving(true);
351
- })
352
- }
379
+ saving={leaveSaving}
380
+ onSaveAndLeave={() => {
381
+ setLeaveSaving(true);
382
+ void save()
383
+ .then((rev) => {
384
+ chrome.close("leave");
385
+ if (rev) chrome.setLeaving(true);
386
+ })
387
+ .finally(() => setLeaveSaving(false));
388
+ }}
353
389
  />
354
390
  </>
355
391
  );
@@ -42,6 +42,8 @@ export type CommandRunners = {
42
42
  setDevice?: (device: PopupDevice) => void;
43
43
  openShortcuts?: () => void;
44
44
  rename?: () => void;
45
+ /** Opens Save as section for an element (W-876). */
46
+ saveSection?: (id: string) => void;
45
47
  /** Set when the selection is an Image element the image editor can open (W-486). */
46
48
  editImage?: () => void;
47
49
  };
@@ -115,6 +117,12 @@ const SPECS: readonly Spec[] = [
115
117
  surfaces: ["layers", "overlay", "palette"],
116
118
  danger: true,
117
119
  },
120
+ {
121
+ id: "save-section",
122
+ labels: { layers: "Save as section…", palette: "Save selected element as a section…" },
123
+ keywords: "my sections saved reuse synced template block segment",
124
+ surfaces: ["layers", "palette"],
125
+ },
118
126
  { id: "move-up", labels: { layers: "Move up" }, surfaces: ["layers"] },
119
127
  { id: "move-down", labels: { layers: "Move down" }, surfaces: ["layers"] },
120
128
  {
@@ -131,7 +139,7 @@ const SPECS: readonly Spec[] = [
131
139
  },
132
140
  {
133
141
  id: "wrap-div",
134
- labels: { palette: "Wrap in Div Block" },
142
+ labels: { palette: "Wrap in Div block" },
135
143
  keywords: "wrap box",
136
144
  surfaces: ["palette"],
137
145
  },
@@ -196,6 +204,7 @@ const ORDER: Record<CommandSurface, readonly string[]> = {
196
204
  "paste",
197
205
  "paste-inside",
198
206
  "duplicate",
207
+ "save-section",
199
208
  "copy-style",
200
209
  "paste-style",
201
210
  "move-up",
@@ -214,6 +223,7 @@ const ORDER: Record<CommandSurface, readonly string[]> = {
214
223
  "redo",
215
224
  "edit-image",
216
225
  "duplicate",
226
+ "save-section",
217
227
  "delete",
218
228
  "deselect",
219
229
  "site-styles",
@@ -237,6 +247,7 @@ function shown(id: string, input: CommandInput): boolean {
237
247
  const clip = !!input.runners.copy;
238
248
  if (id === "rename") return !!input.runners.rename;
239
249
  if (id === "edit-image") return !!input.runners.editImage;
250
+ if (id === "save-section") return !!input.runners.saveSection && input.canDuplicate;
240
251
  if (id === "paste-inside") return clip && input.isParent;
241
252
  if (id === "paste") return clip && (input.surface !== "layers" || !input.isRoot);
242
253
  if (CLIP_IDS.has(id)) return clip;
@@ -248,7 +259,8 @@ function shown(id: string, input: CommandInput): boolean {
248
259
  function blocked(id: string, input: CommandInput): boolean {
249
260
  if (id === "paste" || id === "paste-inside") return !!input.runners.pasteBlocked;
250
261
  if (id === "paste-style") return !!input.runners.pasteStyleBlocked;
251
- if (id === "hide-on-device") return !input.targetId;
262
+ // W-567: the root is the page itself and the page never hides it.
263
+ if (id === "hide-on-device") return !input.targetId || !!input.isRoot;
252
264
  return false;
253
265
  }
254
266
 
@@ -301,6 +313,9 @@ export function runCommand(runners: CommandRunners, id: string, targetId: string
301
313
  case "duplicate":
302
314
  if (targetId) runners.duplicate?.(targetId);
303
315
  return;
316
+ case "save-section":
317
+ if (targetId) runners.saveSection?.(targetId);
318
+ return;
304
319
  case "delete":
305
320
  if (targetId) runners.remove?.(targetId);
306
321
  return;