@perkyzz/emvb 0.6.0 → 0.7.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 (183) hide show
  1. package/package.json +1 -1
  2. package/src/admin/access/RequireEditor.tsx +7 -7
  3. package/src/admin/access/role.ts +5 -2
  4. package/src/admin/content-api.ts +10 -3
  5. package/src/admin/content-item.ts +1 -1
  6. package/src/admin/editor/A11yCopilot.tsx +104 -56
  7. package/src/admin/editor/CommandPalette.tsx +29 -13
  8. package/src/admin/editor/Editor.tsx +82 -20
  9. package/src/admin/editor/EditorToasts.tsx +26 -0
  10. package/src/admin/editor/PerfMeter.tsx +97 -72
  11. package/src/admin/editor/ShareLink.tsx +107 -72
  12. package/src/admin/editor/ShortcutsDialog.tsx +27 -16
  13. package/src/admin/editor/Timeline.tsx +255 -160
  14. package/src/admin/editor/TopBar.tsx +71 -14
  15. package/src/admin/editor/canvas/CanvasFrame.tsx +10 -1
  16. package/src/admin/editor/canvas/CanvasTextEdit.tsx +8 -2
  17. package/src/admin/editor/canvas/drop-line.ts +11 -3
  18. package/src/admin/editor/canvas/frame-focus-ring.ts +37 -0
  19. package/src/admin/editor/canvas/use-canvas-dnd.ts +32 -3
  20. package/src/admin/editor/canvas/vnode-react.tsx +7 -0
  21. package/src/admin/editor/collection-previews.ts +10 -0
  22. package/src/admin/editor/dialogs.tsx +38 -14
  23. package/src/admin/editor/dnd/drop-target.ts +26 -1
  24. package/src/admin/editor/edited-noun.ts +15 -0
  25. package/src/admin/editor/editor-chrome.tsx +59 -7
  26. package/src/admin/editor/editor-commands.ts +2 -1
  27. package/src/admin/editor/editor-css.ts +72 -22
  28. package/src/admin/editor/element-chrome.ts +21 -11
  29. package/src/admin/editor/feature-css.ts +45 -13
  30. package/src/admin/editor/icons/IconLibraryDialog.tsx +52 -11
  31. package/src/admin/editor/icons/library.ts +1 -1
  32. package/src/admin/editor/icons/use-icon-library.ts +5 -2
  33. package/src/admin/editor/ime.ts +29 -0
  34. package/src/admin/editor/palette-items.ts +10 -3
  35. package/src/admin/editor/panels/AddPanel.tsx +35 -10
  36. package/src/admin/editor/panels/ClassesSection.tsx +18 -7
  37. package/src/admin/editor/panels/ColorControl.tsx +130 -23
  38. package/src/admin/editor/panels/ConditionsEditor.tsx +52 -26
  39. package/src/admin/editor/panels/ElementPanel.tsx +134 -24
  40. package/src/admin/editor/panels/LayersPanel.tsx +55 -19
  41. package/src/admin/editor/panels/PageSettings.tsx +66 -35
  42. package/src/admin/editor/panels/SiteStylesDrawer.tsx +170 -32
  43. package/src/admin/editor/panels/TokenScales.tsx +76 -36
  44. package/src/admin/editor/panels/TriggerSettings.tsx +50 -12
  45. package/src/admin/editor/panels/TriggersEditor.tsx +2 -1
  46. package/src/admin/editor/panels/VariableSection.tsx +48 -18
  47. package/src/admin/editor/panels/color-space.ts +9 -3
  48. package/src/admin/editor/panels/settings/AdvancedFields.tsx +12 -2
  49. package/src/admin/editor/panels/settings/AudienceEditor.tsx +51 -35
  50. package/src/admin/editor/panels/settings/BackgroundControls.tsx +55 -11
  51. package/src/admin/editor/panels/settings/BackgroundFill.tsx +3 -2
  52. package/src/admin/editor/panels/settings/BindingsEditor.tsx +15 -18
  53. package/src/admin/editor/panels/settings/BoxControl.tsx +2 -1
  54. package/src/admin/editor/panels/settings/ClassChip.tsx +21 -9
  55. package/src/admin/editor/panels/settings/ClassChipInput.tsx +24 -16
  56. package/src/admin/editor/panels/settings/DraftTextField.tsx +41 -3
  57. package/src/admin/editor/panels/settings/EffectsControls.tsx +38 -14
  58. package/src/admin/editor/panels/settings/FieldBindControl.tsx +46 -28
  59. package/src/admin/editor/panels/settings/FieldControl.tsx +20 -8
  60. package/src/admin/editor/panels/settings/FormBindControl.tsx +2 -2
  61. package/src/admin/editor/panels/settings/HintedSwitch.tsx +33 -0
  62. package/src/admin/editor/panels/settings/IconControls.tsx +12 -8
  63. package/src/admin/editor/panels/settings/IconPicker.tsx +2 -0
  64. package/src/admin/editor/panels/settings/ImageSourcesField.tsx +3 -1
  65. package/src/admin/editor/panels/settings/ItemList.tsx +15 -2
  66. package/src/admin/editor/panels/settings/LengthRow.tsx +8 -6
  67. package/src/admin/editor/panels/settings/MediaPicker.tsx +127 -23
  68. package/src/admin/editor/panels/settings/MotionControl.tsx +28 -15
  69. package/src/admin/editor/panels/settings/NumberRow.tsx +9 -3
  70. package/src/admin/editor/panels/settings/PanelSelect.tsx +50 -0
  71. package/src/admin/editor/panels/settings/QueryStyleRows.tsx +25 -18
  72. package/src/admin/editor/panels/settings/RequiredFieldsNotice.tsx +66 -1
  73. package/src/admin/editor/panels/settings/StyleRow.tsx +10 -3
  74. package/src/admin/editor/panels/settings/StyleSources.tsx +4 -1
  75. package/src/admin/editor/panels/settings/VariantEditor.tsx +10 -1
  76. package/src/admin/editor/panels/settings/box-link-name.ts +6 -2
  77. package/src/admin/editor/panels/settings/class-suggest.ts +7 -7
  78. package/src/admin/editor/panels/settings/query-style.ts +38 -9
  79. package/src/admin/editor/panels/settings/svg-images.ts +13 -0
  80. package/src/admin/editor/panels/site-list.tsx +20 -6
  81. package/src/admin/editor/panels/variable-values.ts +11 -4
  82. package/src/admin/editor/restore-deleted.ts +21 -2
  83. package/src/admin/editor/section-templates.ts +81 -12
  84. package/src/admin/editor/shortcuts.ts +17 -2
  85. package/src/admin/editor/store.ts +7 -0
  86. package/src/admin/editor/useEditorCommands.ts +61 -15
  87. package/src/admin/editor/useEditorData.ts +4 -2
  88. package/src/admin/editor/useEditorShortcuts.ts +17 -7
  89. package/src/admin/editor/useNodeActions.ts +61 -6
  90. package/src/admin/editor/useSave.ts +22 -7
  91. package/src/admin/forms-api.ts +2 -0
  92. package/src/admin/image-editor/CurvesPanel.tsx +2 -1
  93. package/src/admin/image-editor/ExportDialog.tsx +48 -18
  94. package/src/admin/image-editor/ImageEditorDialog.tsx +49 -7
  95. package/src/admin/image-editor/MetadataPanel.tsx +15 -4
  96. package/src/admin/image-editor/crop-geometry.ts +3 -2
  97. package/src/admin/image-editor/image-editor-css.ts +4 -2
  98. package/src/admin/image-editor/load.ts +9 -2
  99. package/src/admin/image-editor/parts.tsx +51 -2
  100. package/src/admin/image-editor/save.ts +23 -7
  101. package/src/admin/media-api.ts +2 -1
  102. package/src/admin/pages/AgentsPage.tsx +138 -27
  103. package/src/admin/pages/CreateDialog.tsx +97 -30
  104. package/src/admin/pages/NewPageDialog.tsx +21 -3
  105. package/src/admin/pages/NewThemePartDialog.tsx +11 -3
  106. package/src/admin/pages/PageList.tsx +14 -6
  107. package/src/admin/pages/SetupShell.tsx +28 -12
  108. package/src/admin/pages/ThemePartList.tsx +27 -7
  109. package/src/admin/pages/list-kit.tsx +106 -24
  110. package/src/admin/search.ts +15 -0
  111. package/src/admin/setup/useSetupStatus.ts +1 -1
  112. package/src/admin/theme-api.ts +13 -3
  113. package/src/admin/ui.ts +73 -22
  114. package/src/astro/floats/runtime.ts +21 -0
  115. package/src/astro/menu/runtime.ts +34 -1
  116. package/src/astro/popups/runtime.ts +33 -3
  117. package/src/astro/render.ts +3 -0
  118. package/src/astro/resolve-theme.ts +53 -11
  119. package/src/astro/resolve.ts +9 -1
  120. package/src/astro/tabs/runtime.ts +12 -0
  121. package/src/astro/theme-posts.ts +2 -2
  122. package/src/astro/visitor.ts +2 -0
  123. package/src/constants.ts +1 -1
  124. package/src/core/a11y/audit.ts +171 -24
  125. package/src/core/arrange.ts +27 -6
  126. package/src/core/audience/rules.ts +5 -1
  127. package/src/core/audience/variants.ts +29 -3
  128. package/src/core/clipboard.ts +7 -0
  129. package/src/core/css/generate.ts +31 -6
  130. package/src/core/data/bindings.ts +8 -1
  131. package/src/core/design/classes.ts +16 -7
  132. package/src/core/design/diff.ts +6 -0
  133. package/src/core/design/merge.ts +90 -2
  134. package/src/core/design/tokens.ts +16 -2
  135. package/src/core/design/transfer.ts +33 -6
  136. package/src/core/design/variables.ts +30 -9
  137. package/src/core/elements/dynamic-elements.ts +44 -5
  138. package/src/core/elements/form-elements.ts +55 -16
  139. package/src/core/elements/index.ts +83 -38
  140. package/src/core/elements/menu.ts +37 -19
  141. package/src/core/elements/select-prompt.ts +3 -0
  142. package/src/core/elements/svg-ids.ts +39 -0
  143. package/src/core/forms/binding.ts +57 -16
  144. package/src/core/forms/definition.ts +72 -0
  145. package/src/core/history/diff.ts +18 -1
  146. package/src/core/icons/catalog.ts +3 -2
  147. package/src/core/image-edit/schema.ts +11 -1
  148. package/src/core/image-edit/summary.ts +6 -3
  149. package/src/core/index.ts +15 -1
  150. package/src/core/limits.ts +12 -1
  151. package/src/core/perf/meter.ts +42 -7
  152. package/src/core/recipes/index.ts +5 -4
  153. package/src/core/render/context.ts +8 -0
  154. package/src/core/render/dynamic-post.ts +69 -12
  155. package/src/core/render/extras.ts +77 -4
  156. package/src/core/render/form.ts +140 -6
  157. package/src/core/render/index.ts +156 -20
  158. package/src/core/render/loop.ts +43 -7
  159. package/src/core/render/pagination.ts +18 -4
  160. package/src/core/render/section.ts +27 -0
  161. package/src/core/render/tabs.ts +12 -3
  162. package/src/core/render/vnode.ts +1 -1
  163. package/src/core/sanitize/css.ts +15 -2
  164. package/src/core/sanitize/embed-url.ts +42 -5
  165. package/src/core/sanitize/url.ts +2 -1
  166. package/src/core/schema/layout.ts +15 -6
  167. package/src/core/stats.ts +2 -1
  168. package/src/core/theme/conditions.ts +3 -1
  169. package/src/core/theme/dynamic.ts +36 -5
  170. package/src/core/theme/float.ts +9 -2
  171. package/src/core/theme/pagination.ts +31 -11
  172. package/src/core/theme/popup-markup.ts +23 -5
  173. package/src/core/theme/popup-rules.ts +1 -0
  174. package/src/core/theme/triggers.ts +3 -2
  175. package/src/core/tree-ops.ts +27 -0
  176. package/src/mcp/rate-limit.ts +2 -1
  177. package/src/mcp/read.ts +14 -2
  178. package/src/mcp/refs.ts +18 -0
  179. package/src/mcp/write.ts +174 -10
  180. package/src/server/agent-settings.ts +1 -1
  181. package/src/server/hooks.ts +5 -3
  182. package/src/server/icon-routes.ts +30 -9
  183. package/src/server/mcp-routes.ts +6 -1
@@ -310,14 +310,33 @@ function PanelSheet({
310
310
  label: string;
311
311
  children: React.ReactNode;
312
312
  }) {
313
- const drag = React.useRef<{ pointerId: number; startY: number; startSnap: number } | null>(null);
313
+ const drag = React.useRef<{
314
+ pointerId: number;
315
+ startY: number;
316
+ startSnap: number;
317
+ latest: number | null;
318
+ } | null>(null);
314
319
  const [dragSnap, setDragSnap] = React.useState<number | null>(null);
315
320
  const height = dragSnap ?? snap;
321
+ const onGripKey = (event: React.KeyboardEvent<HTMLDivElement>) => {
322
+ const [peek, expanded] = SNAP_POINTS;
323
+ const key = event.key;
324
+ let next: number | "close" | null = null;
325
+ if (key === "ArrowUp" || key === "PageUp") next = expanded;
326
+ else if (key === "ArrowDown" || key === "PageDown") next = snap > peek ? peek : "close";
327
+ else if (key === "Home") next = peek;
328
+ else if (key === "End") next = expanded;
329
+ if (next === null) return;
330
+ event.preventDefault();
331
+ if (next === "close") onOpenChange(false);
332
+ else onSnapChange(next);
333
+ };
316
334
  const onPointerUp = (event: React.PointerEvent<HTMLDivElement>) => {
317
335
  const d = drag.current;
318
336
  if (!d || d.pointerId !== event.pointerId) return;
319
337
  drag.current = null;
320
- const released = dragSnap ?? snap;
338
+ // W-748: a quick flick can release before React re-renders with the last move.
339
+ const released = d.latest ?? snap;
321
340
  setDragSnap(null);
322
341
  if (released < SNAP_POINTS[0] * 0.6) {
323
342
  onOpenChange(false);
@@ -342,12 +361,26 @@ function PanelSheet({
342
361
  >
343
362
  <div
344
363
  aria-label="Resize panel"
364
+ aria-orientation="horizontal"
365
+ aria-valuemax={100}
366
+ aria-valuemin={0}
367
+ aria-valuenow={Math.round(height * 100)}
368
+ aria-valuetext={
369
+ height === SNAP_POINTS[1] ? "Expanded" : height === SNAP_POINTS[0] ? "Peek" : undefined
370
+ }
345
371
  className="emvb-ie-sheet-grip"
346
372
  role="separator"
373
+ tabIndex={0}
374
+ onKeyDown={onGripKey}
347
375
  onPointerCancel={onPointerUp}
348
376
  onPointerDown={(event) => {
349
377
  event.currentTarget.setPointerCapture?.(event.pointerId);
350
- drag.current = { pointerId: event.pointerId, startY: event.clientY, startSnap: snap };
378
+ drag.current = {
379
+ pointerId: event.pointerId,
380
+ startY: event.clientY,
381
+ startSnap: snap,
382
+ latest: null,
383
+ };
351
384
  }}
352
385
  onPointerMove={(event) => {
353
386
  const d = drag.current;
@@ -355,7 +388,8 @@ function PanelSheet({
355
388
  const container = event.currentTarget.closest(".emvb-ie-compact");
356
389
  const containerHeight = container?.clientHeight || window.innerHeight;
357
390
  const next = d.startSnap - (event.clientY - d.startY) / containerHeight;
358
- setDragSnap(Math.min(0.96, Math.max(0.08, next)));
391
+ d.latest = Math.min(0.96, Math.max(0.08, next));
392
+ setDragSnap(d.latest);
359
393
  }}
360
394
  onPointerUp={onPointerUp}
361
395
  >
@@ -392,6 +426,12 @@ function CompactLayout({ name }: { name: string }) {
392
426
  setPanelOpen(true);
393
427
  setSnap(SNAP_POINTS[0]);
394
428
  };
429
+ const closePanel = () => {
430
+ rootRef.current
431
+ ?.querySelector<HTMLButtonElement>(':scope > nav [aria-pressed="true"]')
432
+ ?.focus();
433
+ setPanelOpen(false);
434
+ };
395
435
  // Keep the photo above the sheet: pad the canvas by the sheet's peek height.
396
436
  const inset = panelOpen && rootHeight ? Math.max(0, rootHeight * SNAP_POINTS[0] - 28) : undefined;
397
437
  const label =
@@ -440,7 +480,7 @@ function CompactLayout({ name }: { name: string }) {
440
480
  <PanelSheet
441
481
  label={label}
442
482
  open={panelOpen}
443
- onOpenChange={setPanelOpen}
483
+ onOpenChange={(next) => (next ? setPanelOpen(true) : closePanel())}
444
484
  snap={snap}
445
485
  onSnapChange={setSnap}
446
486
  >
@@ -458,7 +498,7 @@ function CompactLayout({ name }: { name: string }) {
458
498
  aria-label="Close panel"
459
499
  className="emvb-ie-btn emvb-ie-btn-icon emvb-ie-touch"
460
500
  icon={<XIcon aria-hidden="true" />}
461
- onClick={() => setPanelOpen(false)}
501
+ onClick={closePanel}
462
502
  />
463
503
  </div>
464
504
  {/* Focusable so the keyboard can scroll a panel with no controls (Metadata, W-486). */}
@@ -765,7 +805,9 @@ export default function ImageEditorDialog({
765
805
  >
766
806
  <Dialog className="emvb-image-editor-popup" data-emvb-image-editor-popup="">
767
807
  <style>{UI_CSS + IMAGE_EDITOR_CSS}</style>
768
- <Dialog.Title className="emvb-ie-sr">Edit image</Dialog.Title>
808
+ <Dialog.Title className="emvb-ie-sr" data-emvb-dialog="image-editor-shell">
809
+ Edit image
810
+ </Dialog.Title>
769
811
  <Dialog.Description className="emvb-ie-sr">
770
812
  Crop, rotate and adjust a copy of this picture.
771
813
  </Dialog.Description>
@@ -65,10 +65,20 @@ function tagValue(tag: Tag): string | undefined {
65
65
  return formatValue(tag?.hvalue ?? tag?.value);
66
66
  }
67
67
 
68
+ /** An EXIF string without its trailing spaces or NULs. */
69
+ const clean = (text: string | undefined) => text?.replace(/[\s\0]+$/u, "") || undefined;
70
+
71
+ /**
72
+ * W-698: most cameras repeat the make in the model ("Canon" + "Canon EOS R5"), which read
73
+ * "Canon Canon EOS R5"; the model alone is shown then. EXIF strings may end in spaces or NULs.
74
+ */
68
75
  function camera(make: Tag, model: Tag): string | undefined {
69
- const a = tagValue(make);
70
- const b = tagValue(model);
71
- if (a && b) return `${a} ${b}`;
76
+ const a = clean(tagValue(make));
77
+ const b = clean(tagValue(model));
78
+ if (a && b) {
79
+ const brand = a.split(/\s+/)[0]?.toLowerCase() ?? "";
80
+ return b.toLowerCase().startsWith(brand) ? b : `${a} ${b}`;
81
+ }
72
82
  return a ?? b;
73
83
  }
74
84
 
@@ -99,7 +109,8 @@ export function formatBytes(size: number): string {
99
109
  const units = ["B", "KB", "MB", "GB"] as const;
100
110
  let value = size;
101
111
  let unit = 0;
102
- while (value >= 1024 && unit < units.length - 1) {
112
+ // W-698: a value that rounds up to 1024 moves to the next unit ("1.0 MB", not "1024.0 KB").
113
+ while (unit < units.length - 1 && Number(value.toFixed(unit === 0 ? 0 : 1)) >= 1024) {
103
114
  value /= 1024;
104
115
  unit += 1;
105
116
  }
@@ -134,12 +134,13 @@ export function resizeRect(
134
134
  x = west ? start.x + start.w - w : start.x;
135
135
  y = north ? start.y + start.h - h : start.y;
136
136
  } else if (east || west) {
137
- w = Math.max(min, start.w + (east ? dx : -dx));
137
+ // W-693: the other side keeps the minimum too (a wide ratio made a sliver of a height).
138
+ w = Math.max(min, min * ratio, start.w + (east ? dx : -dx));
138
139
  h = w / ratio;
139
140
  x = west ? start.x + start.w - w : start.x;
140
141
  y = start.y + start.h / 2 - h / 2;
141
142
  } else {
142
- h = Math.max(min, start.h + (south ? dy : -dy));
143
+ h = Math.max(min, min / ratio, start.h + (south ? dy : -dy));
143
144
  w = h * ratio;
144
145
  y = north ? start.y + start.h - h : start.y;
145
146
  x = start.x + start.w / 2 - w / 2;
@@ -248,7 +248,7 @@ export const IMAGE_EDITOR_CSS = `
248
248
  }
249
249
  .emvb-ie-compact-head .emvb-ie-toolbar-end { gap: 4px; }
250
250
  .emvb-ie .emvb-ie-touch { width: 44px; height: 44px; }
251
- .emvb-ie-compact-canvas { flex: 1; min-height: 0; padding: 8px; transition: padding 200ms ease; }
251
+ .emvb-ie-compact-canvas { flex: 1; min-height: 0; padding: 8px; }
252
252
  .emvb-ie-compact-tools {
253
253
  display: flex; flex: none; gap: 4px; overflow-x: auto; scrollbar-width: none;
254
254
  padding: 4px 8px max(4px, env(safe-area-inset-bottom)); border-top: 1px solid var(--color-kumo-hairline);
@@ -268,11 +268,13 @@ export const IMAGE_EDITOR_CSS = `
268
268
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 40; display: flex; flex-direction: column;
269
269
  border-radius: 14px 14px 0 0; border-top: 1px solid var(--color-kumo-line);
270
270
  background: var(--color-kumo-elevated); box-shadow: 0 -8px 24px var(--color-kumo-shadow-drop, rgb(0 0 0 / 0.15));
271
- transition: height 300ms ease-out, transform 300ms ease-out; transform: translateY(100%); pointer-events: none;
271
+ transition: transform 200ms ease-out; transform: translateY(100%); pointer-events: none;
272
272
  }
273
273
  .emvb-ie-sheet[data-open] { transform: none; pointer-events: auto; }
274
274
  .emvb-ie-sheet[data-dragging] { transition: none; }
275
275
  .emvb-ie-sheet-grip { display: flex; align-items: center; justify-content: center; height: 24px; flex: none; cursor: grab; touch-action: none; }
276
+ .emvb-ie-sheet-grip:focus-visible { outline: none; }
277
+ .emvb-ie-sheet-grip:focus-visible > span { outline: 2px solid var(--color-kumo-focus, var(--color-kumo-brand)); outline-offset: 2px; }
276
278
  .emvb-ie-sheet-grip > span { width: 48px; height: 6px; border-radius: 9999px; background: var(--color-kumo-line); }
277
279
  .emvb-ie-sheet-tools { display: flex; align-items: center; gap: 4px; padding: 0 8px 4px; border-bottom: 1px solid var(--color-kumo-hairline); }
278
280
  .emvb-ie-sheet-body { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding-bottom: env(safe-area-inset-bottom); }
@@ -92,9 +92,16 @@ export async function loadEditableSource(
92
92
  return copy.ok ? { ...copy, originalMissing: true } : copy;
93
93
  }
94
94
  if (!response.ok) return { ok: false, reason: "network", message: MESSAGES.network };
95
- const blob = await response.blob();
95
+ let blob: Blob;
96
+ try {
97
+ blob = await response.blob();
98
+ } catch {
99
+ return { ok: false, reason: "network", message: MESSAGES.network };
100
+ }
96
101
  const type =
97
- (response.headers.get("content-type") ?? blob.type ?? "").split(";")[0]?.trim() ?? "";
102
+ // W-592: MIME types are case-insensitive ("IMAGE/JPEG" is a JPEG).
103
+ (response.headers.get("content-type") ?? blob.type ?? "").split(";")[0]?.trim().toLowerCase() ??
104
+ "";
98
105
  if (REFUSED_TYPES.test(type)) return { ok: false, reason: "format", message: MESSAGES.format };
99
106
  if (type && !type.startsWith("image/")) {
100
107
  return { ok: false, reason: "network", message: MESSAGES.network };
@@ -26,6 +26,7 @@ import {
26
26
  import * as React from "react";
27
27
  import { useImageEditor } from "./engine.ts";
28
28
  import { IMAGE_EDITOR_TOOLS, type ImageEditorToolId } from "./tools.ts";
29
+ import { isCommitEnter } from "../editor/ime.ts";
29
30
 
30
31
  export const TOOL_ICONS: Record<ImageEditorToolId, Icon> = {
31
32
  adjust: SlidersHorizontalIcon,
@@ -49,6 +50,41 @@ type IconButtonProps = {
49
50
  className?: string;
50
51
  } & Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, "onClick" | "disabled" | "className">;
51
52
 
53
+ /**
54
+ * W-839: Undo, Redo and Reset disable themselves when they run out (and an icon button loses its
55
+ * tooltip wrapper, so it remounts). Focus then fell to the dialog or the page body. Once the
56
+ * pressed button can no longer hold focus, move it to the nearest enabled button in the toolbar.
57
+ */
58
+ /** Distance from the pressed button; on a tie the earlier button wins (Redo hands back to Undo). */
59
+ const near = (at: number, index: number) => Math.abs(index - at) + (index > at ? 0.5 : 0);
60
+
61
+ function keepToolbarFocus(from: HTMLButtonElement) {
62
+ const bar = from.closest<HTMLElement>('[data-slot="editor-toolbar"], .emvb-ie-compact-head');
63
+ const dialog = from.closest<HTMLElement>('[role="dialog"]');
64
+ if (!bar) return;
65
+ const at = [...bar.querySelectorAll<HTMLButtonElement>("button")].indexOf(from);
66
+ const started = Date.now();
67
+ const settle = () => {
68
+ const active = document.activeElement;
69
+ const lost =
70
+ active === document.body ||
71
+ active === dialog ||
72
+ active === null ||
73
+ (active instanceof HTMLButtonElement && active.disabled);
74
+ if (!lost) {
75
+ if (active === from && Date.now() - started < 600) window.setTimeout(settle, 30);
76
+ return;
77
+ }
78
+ // Positions, not elements: a button that gained or lost its tooltip is a new element.
79
+ const all = [...bar.querySelectorAll<HTMLButtonElement>("button")];
80
+ const open = all
81
+ .map((button, index) => ({ button, index }))
82
+ .filter(({ button }) => !button.disabled && button.getAttribute("aria-disabled") !== "true");
83
+ open.toSorted((a, b) => near(at, a.index) - near(at, b.index))[0]?.button.focus();
84
+ };
85
+ window.setTimeout(settle, 0);
86
+ }
87
+
52
88
  /** A ghost or outline button; icon-only ones get a tooltip below (photocn EditorActionButton). */
53
89
  export function IconButton({
54
90
  label,
@@ -56,8 +92,19 @@ export function IconButton({
56
92
  showLabel = false,
57
93
  variant = "ghost",
58
94
  className,
59
- ...props
95
+ ...rest
60
96
  }: IconButtonProps) {
97
+ const { onClick } = rest;
98
+ const props = {
99
+ ...rest,
100
+ onClick: onClick
101
+ ? (event: React.MouseEvent<HTMLButtonElement>) => {
102
+ const from = event.currentTarget;
103
+ onClick();
104
+ keepToolbarFocus(from);
105
+ }
106
+ : undefined,
107
+ };
61
108
  const classes = `emvb-ie-btn${showLabel ? "" : " emvb-ie-btn-icon"}${className ? ` ${className}` : ""}`;
62
109
  const button = showLabel ? (
63
110
  <Button type="button" variant={variant} size="sm" className={classes} icon={icon} {...props}>
@@ -159,6 +206,8 @@ export function ToolSwitcher() {
159
206
  const buttons = React.useRef<(HTMLButtonElement | null)[]>([]);
160
207
  const index = IMAGE_EDITOR_TOOLS.findIndex((t) => t.id === editor.tool);
161
208
  const onKeyDown = (event: React.KeyboardEvent) => {
209
+ // W-680: Alt+Left is the browser's Back; Ctrl/Cmd keys are shortcuts.
210
+ if (event.altKey || event.ctrlKey || event.metaKey) return;
162
211
  const count = IMAGE_EDITOR_TOOLS.length;
163
212
  const next =
164
213
  event.key === "ArrowRight"
@@ -417,7 +466,7 @@ export function ValueSlider({
417
466
  if (draft !== null) apply(event.currentTarget.value);
418
467
  }}
419
468
  onKeyDown={(event) => {
420
- if (event.key === "Enter") {
469
+ if (isCommitEnter(event)) {
421
470
  event.preventDefault();
422
471
  apply(event.currentTarget.value);
423
472
  } else if (event.key === "Escape") {
@@ -37,7 +37,8 @@ type Size = { width: number; height: number };
37
37
  export function cappedWidth(full: Size, maxSide = DEFAULT_MAX_SIDE): number | null {
38
38
  const longest = Math.max(full.width, full.height);
39
39
  if (longest <= maxSide) return null;
40
- return Math.max(1, Math.round((full.width * maxSide) / longest));
40
+ // W-581: floor, so rounding never pushes the following height past the cap (tall strips).
41
+ return Math.max(1, Math.floor((full.width * maxSide) / longest));
41
42
  }
42
43
 
43
44
  /** Output size for a chosen width (null = full size); the height follows the crop. */
@@ -52,8 +53,12 @@ export function editedFileName(name: string, format: ExportFormat): string {
52
53
  name
53
54
  .replace(/\.[^./]+$/, "")
54
55
  .replace(/-edited$/, "")
55
- .replace(/[^\w.-]+/g, "-")
56
- .replace(/^-+|-+$/g, "") || "image";
56
+ // W-593: letters and digits in any script are kept (pageSlug does the same, W-591).
57
+ .replace(/[^\p{L}\p{M}\p{N}_.-]+/gu, "-")
58
+ // W-539: no leading dots (a hidden file) and at most 100 characters.
59
+ .replace(/^[-.]+|[-.]+$/g, "")
60
+ .slice(0, 100)
61
+ .replace(/[-.]+$/g, "") || "image";
57
62
  return `${base}-edited.${EXT[format]}`;
58
63
  }
59
64
 
@@ -90,12 +95,23 @@ export function buildImageEdit(input: {
90
95
  }): { ok: true; edit: ImageEdit } | { ok: false; message: string } {
91
96
  const { imageProps, output } = input;
92
97
  const prior = ImageEdit.safeParse(imageProps.edit);
98
+ // W-582: a damaged record (e.g. a newer photocn's recipe key) still names the original the
99
+ // editor opened (load.ts reads edit.originalSrc leniently), so keep pointing there.
100
+ const raw = (imageProps.edit ?? {}) as { originalSrc?: unknown; originalMediaId?: unknown };
101
+ const rawSrc = typeof raw.originalSrc === "string" ? raw.originalSrc.trim() : "";
102
+ const rawId = typeof raw.originalMediaId === "string" ? raw.originalMediaId : "";
93
103
  const originalSrc = prior.success
94
104
  ? prior.data.originalSrc
95
- : typeof imageProps.src === "string"
96
- ? imageProps.src
97
- : "";
98
- const priorId = prior.success ? prior.data.originalMediaId : undefined;
105
+ : rawSrc
106
+ ? rawSrc
107
+ : typeof imageProps.src === "string"
108
+ ? imageProps.src
109
+ : "";
110
+ const priorId = prior.success
111
+ ? prior.data.originalMediaId
112
+ : rawSrc && rawId.length >= 1 && rawId.length <= 128
113
+ ? rawId
114
+ : undefined;
99
115
  const originalMediaId =
100
116
  priorId ?? (typeof imageProps.mediaId === "string" ? imageProps.mediaId : undefined);
101
117
  const parsed = ImageEdit.safeParse({
@@ -154,7 +154,8 @@ export function propsFromOriginal(
154
154
  original: Pick<MediaLibraryItem, "id" | "url" | "width" | "height"> | null,
155
155
  ): Record<string, unknown> | null {
156
156
  const edit = current.edit as { originalSrc?: unknown } | undefined;
157
- const originalSrc = typeof edit?.originalSrc === "string" ? edit.originalSrc : "";
157
+ // W-583: trimmed like load.ts, so a blank record is no record.
158
+ const originalSrc = typeof edit?.originalSrc === "string" ? edit.originalSrc.trim() : "";
158
159
  if (!original && !originalSrc) return null;
159
160
  const next: Record<string, unknown> = { ...current };
160
161
  delete next.edit;
@@ -1,6 +1,8 @@
1
- import { Banner, ClipboardText, Empty, Loader, Switch, Table } from "@cloudflare/kumo";
1
+ import { Banner, Button, ClipboardText, Empty, Switch, Table } from "@cloudflare/kumo";
2
2
  import {
3
3
  ArrowSquareOutIcon,
4
+ CheckIcon,
5
+ CopyIcon,
4
6
  GlobeIcon,
5
7
  LockKeyIcon,
6
8
  PlugsConnectedIcon,
@@ -12,12 +14,13 @@ import {
12
14
  type Icon,
13
15
  } from "@phosphor-icons/react";
14
16
  import type { ReactNode } from "react";
15
- import { useEffect, useState } from "react";
17
+ import { useEffect, useRef, useState } from "react";
16
18
  import { defaultFetcher, type Fetcher } from "../api.ts";
17
19
  import { loadAgents, saveAgentSettings, type AgentsState } from "../agents-api.ts";
18
20
  import { useRole } from "../access/role.ts";
19
21
  import { editorUrl } from "../editor/exit.ts";
20
22
  import type { AgentSettings } from "../../mcp/settings.ts";
23
+ import { ListError, ListLoading } from "./list-kit.tsx";
21
24
  import { UI_CSS } from "../ui.ts";
22
25
 
23
26
  const ADMIN_ROLE = 50;
@@ -67,11 +70,24 @@ function SectionHead({
67
70
  }
68
71
 
69
72
  /** AI agents (`/agents`, W-463): the master switch, publishing, how to connect, recent activity. */
73
+ /**
74
+ * W-756: on a phone the setup JSON scrolls sideways, and keyboard users could not reach it to
75
+ * scroll. Focusable, and named so a screen reader says what it is.
76
+ */
77
+ const SCROLLABLE = { tabIndex: 0, role: "group" } as const;
78
+
70
79
  export function AgentsPage({ fetcher = defaultFetcher }: { fetcher?: Fetcher }) {
71
80
  const role = useRole(fetcher);
72
81
  const [state, setState] = useState<AgentsState | null>(null);
73
82
  const [error, setError] = useState<string | null>(null);
74
83
  const [saving, setSaving] = useState(false);
84
+ // W-814: the switches were disabled while saving, which threw keyboard focus to the page body
85
+ // after every toggle. They stay enabled; a change made mid-save is ignored instead.
86
+ const savingNow = useRef(false);
87
+ const [saved, setSaved] = useState(false);
88
+ const [attempt, setAttempt] = useState(0);
89
+ // A failed save keeps the page on screen; only a failed load replaces it (W-624).
90
+ const [saveError, setSaveError] = useState<string | null>(null);
75
91
  const isAdmin = role.state === "ready" && role.role >= ADMIN_ROLE;
76
92
 
77
93
  useEffect(() => {
@@ -79,9 +95,17 @@ export function AgentsPage({ fetcher = defaultFetcher }: { fetcher?: Fetcher })
79
95
  loadAgents(fetcher)
80
96
  .then(setState)
81
97
  .catch((e: unknown) => setError(e instanceof Error ? e.message : String(e)));
82
- }, [fetcher, isAdmin]);
98
+ }, [fetcher, isAdmin, attempt]);
83
99
 
84
- if (role.state === "loading") return <Loader />;
100
+ // UX-011: loading and a failed load get the list pages' named loading card and Retry.
101
+ const shell = (body: ReactNode) => (
102
+ <div className="emvb-pages emvb-agents" data-emvb-agents={error ? "error" : "loading"}>
103
+ <style data-emvb-ui="">{UI_CSS}</style>
104
+ <h1 className="emvb-page-title">AI agents</h1>
105
+ {body}
106
+ </div>
107
+ );
108
+ if (role.state === "loading") return shell(<ListLoading label="Loading AI agent settings…" />);
85
109
  if (!isAdmin) {
86
110
  return (
87
111
  <section data-emvb-access="denied">
@@ -94,26 +118,43 @@ export function AgentsPage({ fetcher = defaultFetcher }: { fetcher?: Fetcher })
94
118
  );
95
119
  }
96
120
  if (error) {
97
- return (
98
- <Banner
99
- variant="error"
100
- icon={<WarningCircleIcon aria-hidden="true" />}
121
+ return shell(
122
+ <ListError
101
123
  title="Couldn't load the AI agent settings"
102
- description={error}
103
- />
124
+ message={error}
125
+ onRetry={() => {
126
+ setError(null);
127
+ setAttempt((n) => n + 1);
128
+ }}
129
+ />,
104
130
  );
105
131
  }
106
- if (!state) return <Loader />;
132
+ if (!state) return shell(<ListLoading label="Loading AI agent settings…" />);
107
133
 
108
134
  const change = async (patch: Partial<AgentSettings>) => {
135
+ if (savingNow.current) return;
136
+ savingNow.current = true;
109
137
  const settings = { ...state.settings, ...patch };
110
138
  setSaving(true);
139
+ setSaved(false);
140
+ setSaveError(null);
111
141
  try {
112
142
  const revision = await saveAgentSettings(fetcher, settings, state.revision);
113
143
  setState({ ...state, settings, revision });
144
+ setSaved(true);
114
145
  } catch (e) {
115
- setError(e instanceof Error ? e.message : String(e));
146
+ const message = e instanceof Error ? e.message : String(e);
147
+ setSaveError(message);
148
+ // Pick up what is saved now and its revision, so the next save isn't refused again (W-630).
149
+ // The page reloads by itself, so say so instead of asking for a reload (W-634).
150
+ await loadAgents(fetcher)
151
+ .then((fresh) => {
152
+ setState(fresh);
153
+ setSaveError(`${message} The latest settings are shown now; make your change again.`);
154
+ })
155
+ .catch(() => undefined);
116
156
  } finally {
157
+ savingNow.current = false;
117
158
  setSaving(false);
118
159
  }
119
160
  };
@@ -133,6 +174,17 @@ export function AgentsPage({ fetcher = defaultFetcher }: { fetcher?: Fetcher })
133
174
  {settings.mcpEnabled ? "Agents on" : "Agents off"}
134
175
  </span>
135
176
  </header>
177
+ <p className="emvb-helper emvb-agents-save" role="status" data-emvb-agents-save="">
178
+ {saving ? "Saving…" : saved ? "Saved." : ""}
179
+ </p>
180
+ {saveError && (
181
+ <Banner
182
+ variant="error"
183
+ icon={<WarningCircleIcon aria-hidden="true" />}
184
+ title="Couldn't save the AI agent settings"
185
+ description={saveError}
186
+ />
187
+ )}
136
188
  <section
137
189
  className="emvb-surface-card emvb-agents-section"
138
190
  aria-labelledby="emvb-agents-access"
@@ -144,7 +196,6 @@ export function AgentsPage({ fetcher = defaultFetcher }: { fetcher?: Fetcher })
144
196
  <Switch
145
197
  label="Let AI agents edit EmVB pages"
146
198
  checked={settings.mcpEnabled}
147
- disabled={saving}
148
199
  onCheckedChange={(checked: boolean) => void change({ mcpEnabled: checked })}
149
200
  />
150
201
  <p>
@@ -154,7 +205,8 @@ export function AgentsPage({ fetcher = defaultFetcher }: { fetcher?: Fetcher })
154
205
  </div>
155
206
  <div className="emvb-agents-field">
156
207
  <h3>MCP endpoint</h3>
157
- <ClipboardText text={state.endpoint} />
208
+ {/* W-812: Kumo's default name, "Copy to clipboard", didn't say what it copies. */}
209
+ <ClipboardText text={state.endpoint} labels={{ copyAction: "Copy endpoint URL" }} />
158
210
  </div>
159
211
  </section>
160
212
  <section
@@ -168,7 +220,7 @@ export function AgentsPage({ fetcher = defaultFetcher }: { fetcher?: Fetcher })
168
220
  <Switch
169
221
  label="Agents may publish pages"
170
222
  checked={settings.publishPages}
171
- disabled={saving || !settings.mcpEnabled}
223
+ disabled={!settings.mcpEnabled}
172
224
  onCheckedChange={(checked: boolean) => void change({ publishPages: checked })}
173
225
  />
174
226
  <p>Off: agents save drafts and a person publishes them.</p>
@@ -177,7 +229,7 @@ export function AgentsPage({ fetcher = defaultFetcher }: { fetcher?: Fetcher })
177
229
  <Switch
178
230
  label="Agents may publish site styles"
179
231
  checked={settings.publishStyles}
180
- disabled={saving || !settings.mcpEnabled}
232
+ disabled={!settings.mcpEnabled}
181
233
  onCheckedChange={(checked: boolean) => void change({ publishStyles: checked })}
182
234
  />
183
235
  <p>Site styles change every page at once, so leave this off unless you need it.</p>
@@ -193,18 +245,28 @@ export function AgentsPage({ fetcher = defaultFetcher }: { fetcher?: Fetcher })
193
245
  </SectionHead>
194
246
  <div className="emvb-agents-snippets">
195
247
  <div className="emvb-agents-snippet">
196
- <h3>
197
- <GlobeIcon aria-hidden="true" size={16} />
198
- Remote (EmDash MCP, sign in with OAuth)
199
- </h3>
200
- <pre data-emvb-snippet="remote">{remoteSnippet(state.endpoint)}</pre>
248
+ <div className="emvb-agents-snippet-head">
249
+ <h3>
250
+ <GlobeIcon aria-hidden="true" size={16} />
251
+ Remote (EmDash MCP, sign in with OAuth)
252
+ </h3>
253
+ <CopySnippet text={remoteSnippet(state.endpoint)} name="remote setup" />
254
+ </div>
255
+ <pre data-emvb-snippet="remote" {...SCROLLABLE} aria-label="Remote setup">
256
+ {remoteSnippet(state.endpoint)}
257
+ </pre>
201
258
  </div>
202
259
  <div className="emvb-agents-snippet">
203
- <h3>
204
- <TerminalWindowIcon aria-hidden="true" size={16} />
205
- Local (stdio)
206
- </h3>
207
- <pre data-emvb-snippet="stdio">{stdioSnippet(site)}</pre>
260
+ <div className="emvb-agents-snippet-head">
261
+ <h3>
262
+ <TerminalWindowIcon aria-hidden="true" size={16} />
263
+ Local (stdio)
264
+ </h3>
265
+ <CopySnippet text={stdioSnippet(site)} name="local setup" />
266
+ </div>
267
+ <pre data-emvb-snippet="stdio" {...SCROLLABLE} aria-label="Local setup">
268
+ {stdioSnippet(site)}
269
+ </pre>
208
270
  </div>
209
271
  </div>
210
272
  </section>
@@ -224,7 +286,8 @@ export function AgentsPage({ fetcher = defaultFetcher }: { fetcher?: Fetcher })
224
286
  />
225
287
  </div>
226
288
  ) : (
227
- <div className="emvb-agents-table">
289
+ <div className="emvb-agents-table" {...SCROLLABLE} aria-label="Recent agent activity">
290
+ {/* W-815: on phones the table scrolls sideways; keyboard users couldn't reach it. */}
228
291
  <Table>
229
292
  <Table.Header>
230
293
  <Table.Row>
@@ -272,3 +335,51 @@ export function AgentsPage({ fetcher = defaultFetcher }: { fetcher?: Fetcher })
272
335
  </div>
273
336
  );
274
337
  }
338
+
339
+ /** UX-089: the setup JSON is meant to be pasted into an agent's config, so it copies in one click. */
340
+ function CopySnippet({ text, name }: { text: string; name: string }) {
341
+ const [copied, setCopied] = useState<"yes" | "no" | null>(null);
342
+ useEffect(() => {
343
+ // W-777: a failed copy stays until the next click; it vanished after 2 s.
344
+ if (copied !== "yes") return;
345
+ const timer = setTimeout(() => setCopied(null), 2000);
346
+ return () => clearTimeout(timer);
347
+ }, [copied]);
348
+ const copy = () => {
349
+ if (!navigator.clipboard?.writeText) {
350
+ setCopied("no");
351
+ return;
352
+ }
353
+ navigator.clipboard.writeText(text).then(
354
+ () => setCopied("yes"),
355
+ () => setCopied("no"),
356
+ );
357
+ };
358
+ return (
359
+ <>
360
+ <Button
361
+ type="button"
362
+ size="sm"
363
+ variant="ghost"
364
+ aria-label={`Copy ${name}`}
365
+ data-emvb-copy-snippet={name}
366
+ onClick={copy}
367
+ >
368
+ {copied === "yes" ? (
369
+ <CheckIcon aria-hidden="true" size={14} />
370
+ ) : (
371
+ <CopyIcon aria-hidden="true" size={14} />
372
+ )}
373
+ {/* W-777: sighted users saw no sign that the copy failed; only the status said so. */}
374
+ {copied === "yes" ? "Copied" : copied === "no" ? "Couldn't copy" : "Copy"}
375
+ </Button>
376
+ <span className="emvb-sr-only" role="status">
377
+ {copied === "yes"
378
+ ? "Copied"
379
+ : copied === "no"
380
+ ? "Couldn't copy. Select the text instead."
381
+ : ""}
382
+ </span>
383
+ </>
384
+ );
385
+ }