@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
@@ -1,5 +1,5 @@
1
- import { Badge, Button, DropdownMenu, Input } from "@cloudflare/kumo";
2
- import { DotsThreeIcon, MagicWandIcon } from "@phosphor-icons/react";
1
+ import { Badge, Banner, Button, DropdownMenu, Input } from "@cloudflare/kumo";
2
+ import { DotsThreeIcon, MagicWandIcon, WarningCircleIcon } from "@phosphor-icons/react";
3
3
  import * as React from "react";
4
4
  import {
5
5
  ImageEdit,
@@ -25,6 +25,7 @@ import {
25
25
  } from "../../../image-editor/ImageEditButton.tsx";
26
26
  import { editableSource } from "../../../image-editor/load.ts";
27
27
  import { BUTTON, FIELD } from "../../../ui.ts";
28
+ import { isCommitEnter } from "../../ime.ts";
28
29
 
29
30
  const propsOf = (node: LayoutNode): Record<string, unknown> =>
30
31
  node.props as Record<string, unknown>;
@@ -56,13 +57,32 @@ export function MediaPicker({ node, fetcher, onChange, label = "Image", editable
56
57
  const src = typeof props.src === "string" ? props.src : "";
57
58
  const [open, setOpen] = React.useState(false);
58
59
  const [items, setItems] = React.useState<MediaLibraryItem[]>([]);
59
- const [busy, setBusy] = React.useState(false);
60
+ const [libraryError, setLibraryError] = React.useState<string | null>(null);
61
+ const [busy, setBusyState] = React.useState(false);
62
+ // W-819: the source buttons stay focusable while busy (aria-disabled, presses ignored), so
63
+ // keyboard focus no longer drops to the page body during an upload; the ref answers at once.
64
+ const busyRef = React.useRef(false);
65
+ const setBusy = React.useCallback((next: boolean) => {
66
+ busyRef.current = next;
67
+ setBusyState(next);
68
+ }, []);
60
69
  const [error, setError] = React.useState<string | null>(null);
61
70
  const [urlDraft, setUrlDraft] = React.useState(src);
62
71
  const fileRef = React.useRef<HTMLInputElement>(null);
72
+ const libraryCloseRef = React.useRef<HTMLButtonElement>(null);
73
+ const libraryOpenerRef = React.useRef<HTMLButtonElement>(null);
74
+ const urlInputRef = React.useRef<HTMLInputElement>(null);
63
75
  // W-486: a library picture opened from its card's Edit… (null when the editor is closed).
64
76
  const [editing, setEditing] = React.useState<MediaLibraryItem | null>(null);
65
77
  const [editorOpen, setEditorOpen] = React.useState(false);
78
+ const currentNode = React.useRef<LayoutNode | null>(node);
79
+
80
+ React.useEffect(() => {
81
+ currentNode.current = node;
82
+ return () => {
83
+ currentNode.current = null;
84
+ };
85
+ }, [node]);
66
86
 
67
87
  React.useEffect(() => {
68
88
  setUrlDraft(src);
@@ -70,21 +90,36 @@ export function MediaPicker({ node, fetcher, onChange, label = "Image", editable
70
90
 
71
91
  const loadLibrary = React.useCallback(async () => {
72
92
  setBusy(true);
73
- setError(null);
93
+ setLibraryError(null);
74
94
  try {
75
95
  setItems(await listImages(fetcher, { limit: 40 }));
76
96
  } catch (caught) {
77
- setError(caught instanceof Error ? caught.message : "Couldn't load the media library.");
97
+ setLibraryError(
98
+ caught instanceof Error ? caught.message : "Couldn't load the media library.",
99
+ );
78
100
  setItems([]);
79
101
  } finally {
80
102
  setBusy(false);
81
103
  }
82
- }, [fetcher]);
104
+ }, [fetcher, setBusy]);
83
105
 
84
106
  React.useEffect(() => {
85
107
  if (open) void loadLibrary();
86
108
  }, [open, loadLibrary]);
87
109
 
110
+ /** Focus Choose from library, or the URL field while the picker is busy (W-741). */
111
+ const focusOpener = () => {
112
+ const opener = libraryOpenerRef.current;
113
+ const target = busyRef.current ? urlInputRef.current : opener;
114
+ target?.focus();
115
+ };
116
+ const closeLibrary = () => {
117
+ setOpen(false);
118
+ focusOpener();
119
+ };
120
+
121
+ const libraryRef = React.useRef<HTMLDivElement>(null);
122
+
88
123
  const edit = ImageEdit.safeParse(props.edit);
89
124
  /** W-487: say why a picture can't be edited instead of offering a button that fails. */
90
125
  const editCheck = src ? editableSource(props, window.location.origin) : null;
@@ -112,6 +147,13 @@ export function MediaPicker({ node, fetcher, onChange, label = "Image", editable
112
147
  setOpen(false);
113
148
  };
114
149
 
150
+ const imageTarget = () => {
151
+ const current = currentNode.current;
152
+ if (!current || current.id !== node.id) return null;
153
+ const latestProps = propsOf(current);
154
+ return latestProps.src === props.src && latestProps.edit === props.edit ? current : null;
155
+ };
156
+
115
157
  /** W-485: back to the untouched original; the edited copy is not deleted. */
116
158
  const resetToOriginal = async () => {
117
159
  if (!edit.success) return;
@@ -122,13 +164,16 @@ export function MediaPicker({ node, fetcher, onChange, label = "Image", editable
122
164
  // W-492: a failed lookup is an error, not "no original"; a deleted original can't be reset
123
165
  // to (its recorded URL is gone too), so the element keeps the edited copy.
124
166
  const original = id ? await getMedia(fetcher, id) : null;
167
+ const target = imageTarget();
168
+ if (!target) return;
125
169
  if (id && !original) {
126
170
  setError(ORIGINAL_DELETED);
127
171
  return;
128
172
  }
129
- const next = propsFromOriginal(props, original);
130
- if (next) onChange(withProps(node, next));
173
+ const next = propsFromOriginal(propsOf(target), original);
174
+ if (next) onChange(withProps(target, next));
131
175
  } catch (caught) {
176
+ if (!imageTarget()) return;
132
177
  setError(
133
178
  `Couldn't reach the media library to find the original.${caught instanceof Error && caught.message ? ` ${caught.message}` : ""}`,
134
179
  );
@@ -137,10 +182,11 @@ export function MediaPicker({ node, fetcher, onChange, label = "Image", editable
137
182
  }
138
183
  };
139
184
 
140
- const applyItem = (item: MediaLibraryItem) => {
141
- onChange(withProps(node, propsFromMedia(propsOf(node), item)));
185
+ const applyItem = (item: MediaLibraryItem, target: LayoutNode = node) => {
186
+ onChange(withProps(target, propsFromMedia(propsOf(target), item)));
142
187
  setOpen(false);
143
188
  setError(null);
189
+ focusOpener();
144
190
  };
145
191
 
146
192
  const onUpload = async (file: File | undefined) => {
@@ -152,8 +198,10 @@ export function MediaPicker({ node, fetcher, onChange, label = "Image", editable
152
198
  () => ({}) as { width?: number; height?: number },
153
199
  );
154
200
  const item = await uploadImage(fetcher, file, dims);
155
- applyItem(item);
201
+ const target = imageTarget();
202
+ if (target) applyItem(item, target);
156
203
  } catch (caught) {
204
+ if (!imageTarget()) return;
157
205
  setError(caught instanceof Error ? caught.message : "Upload failed.");
158
206
  } finally {
159
207
  setBusy(false);
@@ -207,8 +255,11 @@ export function MediaPicker({ node, fetcher, onChange, label = "Image", editable
207
255
  <Button
208
256
  type="button"
209
257
  className={BUTTON}
210
- onClick={() => setOpen(true)}
211
- disabled={busy}
258
+ onClick={() => {
259
+ if (!busyRef.current) setOpen(true);
260
+ }}
261
+ aria-disabled={busy}
262
+ ref={libraryOpenerRef}
212
263
  data-emvb-media-library=""
213
264
  >
214
265
  Choose from library
@@ -217,8 +268,10 @@ export function MediaPicker({ node, fetcher, onChange, label = "Image", editable
217
268
  type="button"
218
269
  className={BUTTON}
219
270
  variant="secondary"
220
- onClick={() => fileRef.current?.click()}
221
- disabled={busy}
271
+ onClick={() => {
272
+ if (!busyRef.current) fileRef.current?.click();
273
+ }}
274
+ aria-disabled={busy}
222
275
  data-emvb-media-upload-btn=""
223
276
  >
224
277
  Upload
@@ -231,8 +284,10 @@ export function MediaPicker({ node, fetcher, onChange, label = "Image", editable
231
284
  type="button"
232
285
  className={BUTTON}
233
286
  variant="ghost"
234
- onClick={() => void resetToOriginal()}
235
- disabled={busy}
287
+ onClick={() => {
288
+ if (!busyRef.current) void resetToOriginal();
289
+ }}
290
+ aria-disabled={busy}
236
291
  data-emvb-image-reset-original=""
237
292
  >
238
293
  Reset to original
@@ -243,6 +298,9 @@ export function MediaPicker({ node, fetcher, onChange, label = "Image", editable
243
298
  type="file"
244
299
  accept="image/png,image/jpeg,image/gif,image/webp,image/avif"
245
300
  className="emvb-sr-only"
301
+ // UX-050: the Upload button is the control; this input only opens the file dialog.
302
+ tabIndex={-1}
303
+ aria-hidden="true"
246
304
  data-emvb-media-upload=""
247
305
  onChange={(event) => void onUpload(event.target.files?.[0])}
248
306
  />
@@ -253,6 +311,7 @@ export function MediaPicker({ node, fetcher, onChange, label = "Image", editable
253
311
  </p>
254
312
  ) : null}
255
313
  <Input
314
+ ref={urlInputRef}
256
315
  label="Or paste a URL"
257
316
  className={FIELD}
258
317
  value={urlDraft}
@@ -261,15 +320,24 @@ export function MediaPicker({ node, fetcher, onChange, label = "Image", editable
261
320
  onChange={(event) => setUrlDraft(event.target.value)}
262
321
  onBlur={() => commitUrl(false)}
263
322
  onKeyDown={(event) => {
264
- if (event.key === "Enter") commitUrl(true);
323
+ if (isCommitEnter(event)) commitUrl(true);
265
324
  }}
266
325
  />
267
326
  {open && (
268
327
  <div
269
328
  className="emvb-media-dialog"
329
+ ref={libraryRef}
270
330
  role="dialog"
271
331
  aria-label="Media library"
272
332
  data-emvb-media-dialog=""
333
+ onKeyDown={(event) => {
334
+ // W-817: Escape left the library open; it closes it like Close does. The editor's
335
+ // own Escape (deselect) must not also run.
336
+ if (event.key !== "Escape" || event.defaultPrevented) return;
337
+ event.preventDefault();
338
+ event.stopPropagation();
339
+ closeLibrary();
340
+ }}
273
341
  >
274
342
  <div className="emvb-media-dialog-head">
275
343
  <h3 className="emvb-panel-title">Media library</h3>
@@ -277,13 +345,41 @@ export function MediaPicker({ node, fetcher, onChange, label = "Image", editable
277
345
  type="button"
278
346
  className={BUTTON}
279
347
  variant="secondary"
280
- onClick={() => setOpen(false)}
348
+ ref={libraryCloseRef}
349
+ autoFocus
350
+ onClick={closeLibrary}
281
351
  >
282
352
  Close
283
353
  </Button>
284
354
  </div>
285
- {busy && <p className="emvb-helper">Loading…</p>}
286
- {!busy && items.length === 0 && (
355
+ {busy && (
356
+ <p className="emvb-helper" role="status">
357
+ Loading…
358
+ </p>
359
+ )}
360
+ {!busy && libraryError && (
361
+ <Banner
362
+ role="alert"
363
+ variant="error"
364
+ icon={<WarningCircleIcon aria-hidden="true" />}
365
+ title="Couldn't load the media library"
366
+ description={libraryError}
367
+ action={
368
+ <Button
369
+ type="button"
370
+ variant="secondary"
371
+ className={BUTTON}
372
+ onClick={() => {
373
+ libraryCloseRef.current?.focus();
374
+ void loadLibrary();
375
+ }}
376
+ >
377
+ Retry
378
+ </Button>
379
+ }
380
+ />
381
+ )}
382
+ {!busy && !libraryError && items.length === 0 && (
287
383
  <p className="emvb-helper">No images yet. Upload one to get started.</p>
288
384
  )}
289
385
  <ul className="emvb-media-grid">
@@ -295,7 +391,11 @@ export function MediaPicker({ node, fetcher, onChange, label = "Image", editable
295
391
  data-emvb-media-id={item.id}
296
392
  onClick={() => applyItem(item)}
297
393
  >
298
- <img src={item.url} alt={item.alt ?? item.filename} />
394
+ {/* W-762: the file name is already the label, so no alt repeats it. */}
395
+ <img
396
+ src={item.url}
397
+ alt={item.alt && item.alt !== item.filename ? item.alt : ""}
398
+ />
299
399
  <span>{item.filename}</span>
300
400
  </button>
301
401
  {editable && canEdit(item) ? (
@@ -339,7 +439,11 @@ export function MediaPicker({ node, fetcher, onChange, label = "Image", editable
339
439
  onOpenChange={setEditorOpen}
340
440
  imageProps={editingProps}
341
441
  onSave={saveLibraryCopy}
342
- onClosed={() => setEditing(null)}
442
+ onClosed={() => {
443
+ setEditing(null);
444
+ // W-745: a saved copy closes the library, so the card menu that opened the editor is gone.
445
+ if (!libraryRef.current) focusOpener();
446
+ }}
343
447
  />
344
448
  ) : null}
345
449
  </div>
@@ -1,4 +1,4 @@
1
- import { Button } from "@cloudflare/kumo";
1
+ import { Button, DropdownMenu } from "@cloudflare/kumo";
2
2
  import { PlusIcon, XIcon } from "@phosphor-icons/react";
3
3
  import type * as React from "react";
4
4
  import {
@@ -200,19 +200,32 @@ export function MotionControl({
200
200
  </div>
201
201
  ))}
202
202
  {unused.length > 0 && (
203
- <TransitionSelect
204
- label="Add effect"
205
- value={"" as MotionEffect | ""}
206
- options={[
207
- { value: "" as const, label: "Choose…" },
208
- ...unused.map((t) => ({ value: t, label: EFFECT_LABELS[t].label })),
209
- ]}
210
- onChange={(type) => {
211
- if (!type) return;
212
- const n = EFFECT_LABELS[type].neutral;
213
- setEffects([...playing.effects, { type, from: n, to: n }]);
214
- }}
215
- />
203
+ // UX-078: adding is an action, so it is a button with a menu, not a select.
204
+ <DropdownMenu>
205
+ <DropdownMenu.Trigger>
206
+ <Button
207
+ type="button"
208
+ variant="secondary"
209
+ className={`${BUTTON} emvb-add-effect`}
210
+ icon={<PlusIcon aria-hidden="true" />}
211
+ >
212
+ Add effect
213
+ </Button>
214
+ </DropdownMenu.Trigger>
215
+ <DropdownMenu.Content data-emvb-add-effect="">
216
+ {unused.map((type) => (
217
+ <DropdownMenu.Item
218
+ key={type}
219
+ onClick={() => {
220
+ const n = EFFECT_LABELS[type].neutral;
221
+ setEffects([...playing.effects, { type, from: n, to: n }]);
222
+ }}
223
+ >
224
+ {EFFECT_LABELS[type].label}
225
+ </DropdownMenu.Item>
226
+ ))}
227
+ </DropdownMenu.Content>
228
+ </DropdownMenu>
216
229
  )}
217
230
  <p className="emvb-helper">
218
231
  Plays as visitors scroll, in browsers that support scroll-driven animations. Visitors
@@ -242,7 +255,7 @@ export function MotionControl({
242
255
  className={BUTTON}
243
256
  onClick={() => onChange({ type: "none" })}
244
257
  >
245
- Turn off here
258
+ Turn off scroll motion
246
259
  </Button>
247
260
  )}
248
261
  </div>
@@ -2,6 +2,7 @@ import { Button, Input } from "@cloudflare/kumo";
2
2
  import { ArrowCounterClockwiseIcon } from "@phosphor-icons/react";
3
3
  import * as React from "react";
4
4
  import { BUTTON, FIELD } from "../../../ui.ts";
5
+ import { isCommitEnter } from "../../ime.ts";
5
6
 
6
7
  /** Range and scale of a plain number field; `scale` converts stored to shown (opacity 0–1 → %). */
7
8
  export type NumberSpec = {
@@ -57,10 +58,15 @@ export function NumberField({
57
58
  }) {
58
59
  const [draft, setDraft] = React.useState(shown(value, spec));
59
60
  const [error, setError] = React.useState<string | null>(null);
61
+ // W-604: keyed on the spec's contents, not its identity; callers that build a spec per render
62
+ // (Transition's Delay, Motion's fields) reset the draft whenever the panel re-rendered.
63
+ const specKey = JSON.stringify(spec);
64
+ const specRef = React.useRef(spec);
65
+ specRef.current = spec;
60
66
  React.useEffect(() => {
61
- setDraft(shown(value, spec));
67
+ setDraft(shown(value, specRef.current));
62
68
  setError(null);
63
- }, [value, spec]);
69
+ }, [value, specKey]);
64
70
 
65
71
  const commit = () => {
66
72
  const parsed = parseNumberDraft(draft, label, spec);
@@ -85,7 +91,7 @@ export function NumberField({
85
91
  onChange={(event) => setDraft(event.target.value)}
86
92
  onBlur={commit}
87
93
  onKeyDown={(event) => {
88
- if (event.key === "Enter") commit();
94
+ if (isCommitEnter(event)) commit();
89
95
  }}
90
96
  />
91
97
  );
@@ -0,0 +1,50 @@
1
+ import { Select } from "@cloudflare/kumo";
2
+ import { FIELD } from "../../../ui.ts";
3
+
4
+ type PanelOption = { value: string; label: string };
5
+
6
+ type Props = {
7
+ value: string;
8
+ options: readonly PanelOption[];
9
+ onChange: (value: string) => void;
10
+ /** Names the trigger when the row has no visible label of its own. */
11
+ label?: string;
12
+ /** The id of the row's visible label. */
13
+ labelledBy?: string;
14
+ className?: string;
15
+ /** Data attributes for the wrapper, which also carries the current value as `data-value`. */
16
+ data?: Record<`data-${string}`, string>;
17
+ };
18
+
19
+ /** A 28 px Kumo Select for panel rows that used a native select (UX-005). */
20
+ export function PanelSelect({
21
+ value,
22
+ options,
23
+ onChange,
24
+ label,
25
+ labelledBy,
26
+ className,
27
+ data,
28
+ }: Props) {
29
+ return (
30
+ <span
31
+ className={className ? `emvb-panel-select ${className}` : "emvb-panel-select"}
32
+ data-value={value}
33
+ {...data}
34
+ >
35
+ <Select
36
+ className={FIELD}
37
+ value={value}
38
+ {...(labelledBy ? { "aria-labelledby": labelledBy } : { "aria-label": label })}
39
+ onValueChange={(next) => onChange(String(next))}
40
+ renderValue={(v: unknown) => options.find((o) => o.value === String(v))?.label ?? String(v)}
41
+ >
42
+ {options.map((option) => (
43
+ <Select.Option key={option.value} value={option.value}>
44
+ <span data-emvb-option={option.value}>{option.label}</span>
45
+ </Select.Option>
46
+ ))}
47
+ </Select>
48
+ </span>
49
+ );
50
+ }
@@ -3,6 +3,11 @@ import type { LayoutNode } from "../../../../core/index.ts";
3
3
  import { FIELD } from "../../../ui.ts";
4
4
  import { savableNode } from "./DraftTextField.tsx";
5
5
  import { formatStyleValue, parseStyleValue, QUERY_STYLE_KEYS } from "./query-style.ts";
6
+ import { isCommitEnter } from "../../ime.ts";
7
+ import { PanelSelect } from "./PanelSelect.tsx";
8
+ import { STYLE_LABELS } from "./style-sections.ts";
9
+
10
+ const CHOOSE = "choose";
6
11
 
7
12
  type QueryStyle = NonNullable<LayoutNode["query"]>["style"];
8
13
 
@@ -15,6 +20,9 @@ function withQueryStyle(node: LayoutNode, style: Record<string, unknown>): Layou
15
20
  }
16
21
 
17
22
  /** One stored property: its value commits on blur or Enter; Remove deletes it. */
23
+ const styleName = (key: string): string =>
24
+ (STYLE_LABELS as Record<string, string | undefined>)[key] ?? key;
25
+
18
26
  function QueryStyleRow({
19
27
  node,
20
28
  styleKey,
@@ -54,7 +62,7 @@ function QueryStyleRow({
54
62
  return (
55
63
  <div className="emvb-query-row" data-emvb-query-key={styleKey}>
56
64
  <label className="emvb-field-label" htmlFor={id}>
57
- {styleKey}
65
+ {styleName(styleKey)}
58
66
  </label>
59
67
  <input
60
68
  id={id}
@@ -65,7 +73,7 @@ function QueryStyleRow({
65
73
  onChange={(event) => setDraft(event.target.value)}
66
74
  onBlur={commit}
67
75
  onKeyDown={(event) => {
68
- if (event.key === "Enter") commit();
76
+ if (isCommitEnter(event)) commit();
69
77
  }}
70
78
  />
71
79
  <button
@@ -133,22 +141,21 @@ export function QueryStyleRows({
133
141
  <QueryStyleRow key={key} node={node} styleKey={key} onChange={onChange} />
134
142
  ))}
135
143
  <div className="emvb-query-add" data-emvb-query-add="">
136
- <label className="emvb-field-label" htmlFor={keyId}>
144
+ <span className="emvb-field-label" id={`${keyId}-label`}>
137
145
  Property
138
- </label>
139
- <select
140
- id={keyId}
141
- className={FIELD}
142
- value={newKey}
143
- onChange={(event) => setNewKey(event.target.value)}
144
- >
145
- <option value="">Choose…</option>
146
- {free.map((key) => (
147
- <option key={key} value={key}>
148
- {key}
149
- </option>
150
- ))}
151
- </select>
146
+ </span>
147
+ <PanelSelect
148
+ labelledBy={`${keyId}-label`}
149
+ value={newKey || CHOOSE}
150
+ options={[
151
+ { value: CHOOSE, label: "Choose…" },
152
+ // UX-079: the Style tab's names ("Padding top"), not the raw keys.
153
+ ...free
154
+ .map((key) => ({ value: key, label: styleName(key) }))
155
+ .toSorted((a, b) => a.label.localeCompare(b.label)),
156
+ ]}
157
+ onChange={(value) => setNewKey(value === CHOOSE ? "" : value)}
158
+ />
152
159
  <label className="emvb-field-label" htmlFor={valueId}>
153
160
  Value
154
161
  </label>
@@ -161,7 +168,7 @@ export function QueryStyleRows({
161
168
  aria-describedby={error ? `${valueId}-error` : undefined}
162
169
  onChange={(event) => setNewValue(event.target.value)}
163
170
  onKeyDown={(event) => {
164
- if (event.key === "Enter") add();
171
+ if (isCommitEnter(event)) add();
165
172
  }}
166
173
  />
167
174
  <button type="button" className="emvb-link-button" onClick={add}>
@@ -4,6 +4,8 @@ import * as React from "react";
4
4
  import type { Fetcher } from "../../../api.ts";
5
5
  import { loadFormFields, type DefinitionField } from "../../../forms-api.ts";
6
6
  import {
7
+ impossibleRangeFields,
8
+ mismatchedControls,
7
9
  requiredFieldIssues,
8
10
  requiredFieldIssueText,
9
11
  type LayoutNode,
@@ -40,13 +42,76 @@ export function RequiredFieldsNotice({ node, fetcher }: { node: LayoutNode; fetc
40
42
  };
41
43
  }, [fetcher, formId]);
42
44
  const issues = fields ? requiredFieldIssues(node, fields) : [];
43
- if (issues.length === 0) return null;
45
+ const ranges = fields ? impossibleRangeFields(fields) : [];
46
+ const kinds = fields ? mismatchedControls(node, fields) : [];
47
+ if (issues.length === 0 && ranges.length === 0 && kinds.length === 0) return null;
48
+ // W-579: a free-text or checkbox control on a field with a list of options sends a value the
49
+ // forms plugin refuses, so the form fails with "has an invalid selection".
50
+ const kindBanner =
51
+ kinds.length > 0 ? (
52
+ <Banner
53
+ variant="alert"
54
+ icon={<WarningIcon aria-hidden="true" />}
55
+ title={
56
+ kinds.length === 1
57
+ ? "A field needs a choice element"
58
+ : `${kinds.length} fields need a choice element`
59
+ }
60
+ description={
61
+ <ul className="emvb-required-notice__list">
62
+ {kinds.map((kind) => (
63
+ <li key={kind.nodeId} data-emvb-kind-issue={kind.fieldType}>
64
+ <strong>{kind.label}</strong> only accepts one of its options in Forms, so typed or
65
+ ticked answers are refused. Use a Select or Radio element for it.
66
+ </li>
67
+ ))}
68
+ </ul>
69
+ }
70
+ />
71
+ ) : null;
72
+ const rangeBanner =
73
+ ranges.length > 0 ? (
74
+ <Banner
75
+ variant="alert"
76
+ icon={<WarningIcon aria-hidden="true" />}
77
+ title={
78
+ ranges.length === 1
79
+ ? "A field's limits can't be met"
80
+ : `${ranges.length} fields' limits can't be met`
81
+ }
82
+ description={
83
+ <ul className="emvb-required-notice__list">
84
+ {ranges.map((range) => (
85
+ <li key={range.name} data-emvb-range-issue={range.kind}>
86
+ <strong>{range.label}</strong>{" "}
87
+ {range.kind === "length"
88
+ ? "has a minimum length above its maximum length"
89
+ : range.kind === "both"
90
+ ? "has a minimum length above its maximum length and a minimum value above its maximum"
91
+ : "has a minimum value above its maximum"}
92
+ , so no answer is accepted. Fix the limits in Forms.
93
+ </li>
94
+ ))}
95
+ </ul>
96
+ }
97
+ />
98
+ ) : null;
99
+ if (issues.length === 0) {
100
+ return (
101
+ <div className="emvb-required-notice" data-emvb-range-fields="">
102
+ {kindBanner}
103
+ {rangeBanner}
104
+ </div>
105
+ );
106
+ }
44
107
  const title =
45
108
  issues.length === 1
46
109
  ? "A required field can't be filled in"
47
110
  : `${issues.length} required fields can't be filled in`;
48
111
  return (
49
112
  <div className="emvb-required-notice" data-emvb-required-fields="">
113
+ {kindBanner}
114
+ {rangeBanner}
50
115
  <Banner
51
116
  variant="alert"
52
117
  icon={<WarningIcon aria-hidden="true" />}
@@ -167,6 +167,9 @@ const SELECT_OPTIONS: Partial<Record<StyleKey, { value: string; label: string }[
167
167
  ],
168
168
  };
169
169
 
170
+ /** The value of a select row with nothing set; never saved. */
171
+ const UNSET = "__unset";
172
+
170
173
  const isLengthLiteral = (value: unknown): value is { value: number; unit: string } =>
171
174
  typeof value === "object" && value !== null && "value" in value && "unit" in value;
172
175
 
@@ -321,7 +324,8 @@ export function StyleRow({
321
324
  const current =
322
325
  styleKey === "fontWeight" && typeof shown === "number"
323
326
  ? String(shown)
324
- : ((shown as string | undefined) ?? options[0]?.value ?? "");
327
+ : // UX-048: nothing set reads "Default", like the colour field, not the first option.
328
+ ((shown as string | undefined) ?? UNSET);
325
329
  return (
326
330
  <div
327
331
  className="emvb-style-row"
@@ -334,6 +338,7 @@ export function StyleRow({
334
338
  className={FIELD}
335
339
  value={current}
336
340
  onValueChange={(next) => {
341
+ if (next === UNSET) return;
337
342
  if (styleKey === "fontWeight") {
338
343
  const n = Number(next);
339
344
  onPatch({
@@ -343,10 +348,12 @@ export function StyleRow({
343
348
  });
344
349
  return;
345
350
  }
346
- onPatch({ [styleKey]: next === options[0]?.value && !set ? next : next });
351
+ onPatch({ [styleKey]: next });
347
352
  }}
348
353
  renderValue={(v: unknown) =>
349
- options.find((o) => o.value === String(v))?.label ?? String(v)
354
+ v === UNSET
355
+ ? "Default"
356
+ : (options.find((o) => o.value === String(v))?.label ?? String(v))
350
357
  }
351
358
  >
352
359
  {options.map((option) => (