@perkyzz/emvb 0.7.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 (71) 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/editor/DialogCloseButton.tsx +16 -0
  5. package/src/admin/editor/Editor.tsx +33 -0
  6. package/src/admin/editor/PerfMeter.tsx +3 -9
  7. package/src/admin/editor/SavedSectionDialogs.tsx +169 -0
  8. package/src/admin/editor/ShareLink.tsx +2 -7
  9. package/src/admin/editor/ShortcutsDialog.tsx +19 -11
  10. package/src/admin/editor/Timeline.tsx +2 -7
  11. package/src/admin/editor/dialogs.tsx +3 -14
  12. package/src/admin/editor/editor-chrome.tsx +8 -24
  13. package/src/admin/editor/editor-commands.ts +15 -1
  14. package/src/admin/editor/editor-css.ts +3 -2
  15. package/src/admin/editor/feature-css.ts +11 -1
  16. package/src/admin/editor/focus-when-lost.ts +23 -0
  17. package/src/admin/editor/icons/IconLibraryDialog.tsx +2 -7
  18. package/src/admin/editor/palette-items.ts +17 -0
  19. package/src/admin/editor/panels/AddPanel.tsx +9 -1
  20. package/src/admin/editor/panels/LayersPanel.tsx +6 -1
  21. package/src/admin/editor/panels/LeftPanel.tsx +9 -1
  22. package/src/admin/editor/panels/SavedSectionsGroup.tsx +246 -0
  23. package/src/admin/editor/panels/SiteStylesDrawer.tsx +54 -10
  24. package/src/admin/editor/panels/TokenScales.tsx +16 -16
  25. package/src/admin/editor/panels/TriggersEditor.tsx +1 -1
  26. package/src/admin/editor/panels/color-space.ts +14 -26
  27. package/src/admin/editor/panels/settings/AudienceEditor.tsx +36 -39
  28. package/src/admin/editor/panels/settings/IconControls.tsx +21 -5
  29. package/src/admin/editor/panels/settings/LoopItemBindControl.tsx +1 -1
  30. package/src/admin/editor/shortcuts.ts +14 -0
  31. package/src/admin/editor/useSavedSections.ts +197 -0
  32. package/src/admin/image-editor/Canvas.tsx +61 -17
  33. package/src/admin/image-editor/ImageEditorDialog.tsx +130 -1
  34. package/src/admin/image-editor/image-editor-css.ts +11 -8
  35. package/src/admin/image-editor/parts.tsx +18 -17
  36. package/src/admin/image-editor/save.ts +31 -1
  37. package/src/admin/pages/ThemePartList.tsx +32 -4
  38. package/src/admin/saved-sections-api.ts +51 -0
  39. package/src/admin/theme-api.ts +3 -2
  40. package/src/admin/ui.ts +9 -0
  41. package/src/astro/popups/runtime.ts +8 -6
  42. package/src/constants.ts +1 -1
  43. package/src/core/a11y/audit.ts +32 -7
  44. package/src/core/arrange.ts +21 -6
  45. package/src/core/css/print.ts +5 -0
  46. package/src/core/design/classes.ts +23 -9
  47. package/src/core/design/devices.ts +7 -13
  48. package/src/core/design/states.ts +7 -13
  49. package/src/core/elements/dynamic-elements.ts +11 -11
  50. package/src/core/elements/index.ts +1 -1
  51. package/src/core/elements/menu.ts +3 -0
  52. package/src/core/icons/animation-runs.ts +11 -0
  53. package/src/core/index.ts +20 -0
  54. package/src/core/migrate/index.ts +3 -0
  55. package/src/core/render/loop.ts +1 -1
  56. package/src/core/sanitize/css.ts +14 -6
  57. package/src/core/saved-sections.ts +318 -0
  58. package/src/core/schema/design.ts +1 -1
  59. package/src/core/schema/layout.ts +1 -1
  60. package/src/core/schema/style.ts +4 -2
  61. package/src/core/theme/float.ts +3 -0
  62. package/src/core/theme/pagination.ts +25 -24
  63. package/src/core/theme/part-types.ts +4 -4
  64. package/src/mcp/ports.ts +22 -1
  65. package/src/mcp/read.ts +1 -1
  66. package/src/mcp/sections.ts +183 -0
  67. package/src/mcp/tools.ts +44 -0
  68. package/src/mcp/write.ts +4 -4
  69. package/src/server/mcp-routes.ts +2 -0
  70. package/src/server/plugin.ts +14 -0
  71. package/src/server/saved-sections.ts +163 -0
@@ -22,12 +22,14 @@ export const FEATURE_CSS = `
22
22
  .emvb-bind-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 6px; align-items: center; }
23
23
  .emvb-bind-row > .emvb-bind-label { grid-column: 1 / -1; font-size: 12px; color: var(--text-color-kumo-subtle); }
24
24
  .emvb-bind-row > .emvb-panel-select:last-child { grid-column: 1 / -1; }
25
+ /* W-867: a row with one text field (Countries, Segments, Time zone) gives it the full width, as its selects. */
26
+ .emvb-bind-row > .emvb-bind-label + .emvb-field:last-child { grid-column: 1 / -1; }
25
27
  .emvb-bind-live { grid-column: 1 / -1; margin: 0; font-size: 12px; color: var(--text-color-kumo-default); overflow-wrap: anywhere; }
26
28
  .emvb-bind-live > b { font-weight: 600; }
27
29
  .emvb-bind-outside { grid-column: 1 / -1; display: grid; gap: 4px; }
28
30
  .emvb-bind-outside > label { display: flex; gap: 6px; align-items: center; font-size: 12px; }
29
31
  .emvb-bind-warning { margin: 0; padding: 6px 8px; border-radius: 6px; font-size: 12px; background: var(--color-kumo-warning-tint); color: var(--text-color-kumo-default); }
30
- .emvb-js-badge { margin-left: auto; padding: 0 4px; border-radius: 4px; font-size: 10px; font-weight: 700; line-height: 16px; background: var(--color-kumo-warning-tint); color: var(--text-color-kumo-default); }
32
+ .emvb-js-badge { margin-left: auto; padding: 0 4px; border-radius: 4px; font-size: 10px; font-weight: 600; line-height: 16px; background: var(--color-kumo-warning-tint); color: var(--text-color-kumo-default); }
31
33
  .emvb-element-tile { position: relative; }
32
34
  .emvb-element-tile > .emvb-js-badge { position: absolute; top: 4px; right: 4px; }
33
35
  .emvb-perf-bars { display: grid; gap: 8px; margin: 12px 0; padding: 0; list-style: none; }
@@ -148,6 +150,14 @@ export const FEATURE_CSS = `
148
150
  .emvb-recipe-tile:hover, .emvb-recipe-tile:focus-visible { border-color: var(--color-kumo-brand); }
149
151
  .emvb-recipe-name { font-weight: 600; font-size: 13px; }
150
152
  .emvb-recipe-desc { font-size: 12px; color: var(--text-color-kumo-subtle); }
153
+ /* W-876: My sections, names only (D-060). */
154
+ .emvb-saved-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
155
+ .emvb-saved-row { display: flex; align-items: center; gap: 2px; min-width: 0; }
156
+ .emvb-saved-name { flex: 1 1 auto; min-width: 0; text-align: start; padding: 6px 10px; border-radius: 8px; border: 1px solid var(--color-kumo-line); background: var(--color-kumo-base, transparent); cursor: pointer; font: inherit; font-size: 13px; color: inherit; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
157
+ .emvb-saved-name:hover:not(:disabled), .emvb-saved-name:focus-visible { border-color: var(--color-kumo-brand); }
158
+ .emvb-saved-name:disabled { cursor: not-allowed; color: var(--text-color-kumo-subtle); }
159
+ .emvb-saved-row .emvb-saved-rename { flex: 1 1 auto; }
160
+ .emvb-saved-error { display: grid; gap: 6px; justify-items: start; }
151
161
  .emvb-motion-effect { display: grid; grid-template-columns: 1fr 1fr auto; gap: 6px; align-items: end; }
152
162
  .emvb-motion-name { grid-column: 1 / -1; font-size: 12px; font-weight: 600; }
153
163
  /* UX-092: the fixed theme part type, its label and value on one line */
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Focuses the selected layer or the canvas if focus ends up on <body>. A closing dialog keeps
3
+ * focus until its close animation ends, so wait (up to 2 s) while focus is still in a dialog;
4
+ * other dialog-like layers (toasts) don't hold it up. Returns a cancel.
5
+ */
6
+ export function focusWhenLost(): () => void {
7
+ const started = Date.now();
8
+ let timer: number | undefined;
9
+ const settle = () => {
10
+ const now = document.activeElement;
11
+ if (now && now !== document.body) {
12
+ const inDialog = now.closest('[role="dialog"], [role="alertdialog"]') !== null;
13
+ if (inDialog && Date.now() - started < 2000) timer = window.setTimeout(settle, 30);
14
+ return;
15
+ }
16
+ const target =
17
+ document.querySelector<HTMLElement>('.emvb-layer-select[aria-current="true"]') ??
18
+ document.querySelector<HTMLElement>("iframe[data-emvb-canvas]");
19
+ target?.focus({ preventScroll: true });
20
+ };
21
+ timer = window.setTimeout(settle, 30);
22
+ return () => window.clearTimeout(timer);
23
+ }
@@ -12,6 +12,7 @@ import { BUTTON, SOLID_PRIMARY, UI_CSS } from "../../ui.ts";
12
12
  import { ALL_ICONS, ICON_SETS, UPLOADS, type LibraryIcon, type loadIconSet } from "./library.ts";
13
13
  import { fmt, useIconLibrary } from "./use-icon-library.ts";
14
14
  import { isCommitEnter } from "../ime.ts";
15
+ import { DialogCloseButton } from "../DialogCloseButton.tsx";
15
16
 
16
17
  /** Grid geometry, in px. Tiles stretch to fill the row; this is their narrowest. */
17
18
  const TILE_MIN_WIDTH = 96;
@@ -535,13 +536,7 @@ function IconLibrary({
535
536
  </Button>
536
537
  </>
537
538
  )}
538
- <Dialog.Close
539
- render={(props) => (
540
- <Button {...props} variant="secondary" className={BUTTON}>
541
- Close
542
- </Button>
543
- )}
544
- />
539
+ <DialogCloseButton>Close</DialogCloseButton>
545
540
  <Button
546
541
  variant="primary"
547
542
  className={`${BUTTON} ${SOLID_PRIMARY}`}
@@ -18,6 +18,9 @@ export type PaletteActions = {
18
18
  insert: (type: ElementType) => void;
19
19
  /** Adds a section recipe (W-320). */
20
20
  insertRecipe?: (id: string) => void;
21
+ /** My sections (W-876), inserted by id. */
22
+ savedSections?: readonly { id: string; name: string; damaged?: true }[];
23
+ insertSaved?: (id: string) => void;
21
24
  select: (id: string) => void;
22
25
  applyClass: (nodeId: string, classId: string) => void;
23
26
  actions: { id: string; label: string; hint?: string; keywords?: string; run: () => void }[];
@@ -94,6 +97,20 @@ export function paletteItems(ctx: PaletteActions): PaletteItem[] {
94
97
  });
95
98
  }
96
99
  }
100
+ const insertSaved = ctx.insertSaved;
101
+ if (insertSaved) {
102
+ for (const section of ctx.savedSections ?? []) {
103
+ if (section.damaged) continue;
104
+ items.push({
105
+ id: `saved:${section.id}`,
106
+ group: "Insert",
107
+ label: `Insert ${section.name}`,
108
+ hint: "My sections",
109
+ keywords: "my sections saved section block template segment",
110
+ run: () => insertSaved(section.id),
111
+ });
112
+ }
113
+ }
97
114
  if (ctx.layout) {
98
115
  let count = 0;
99
116
  const walk = (node: LayoutNode, depth: number): void => {
@@ -12,6 +12,8 @@ import { BUTTON, FIELD } from "../../ui.ts";
12
12
  import { isCancelEscape } from "../ime.ts";
13
13
  import { matchesSearch } from "../../search.ts";
14
14
  import { dragStash } from "../dnd/drag-stash.ts";
15
+ import type { SavedSectionActions } from "../useSavedSections.ts";
16
+ import { matchingSections, SavedSectionsGroup } from "./SavedSectionsGroup.tsx";
15
17
 
16
18
  const GROUPS = [
17
19
  { id: "layout", label: "Layout" },
@@ -23,12 +25,15 @@ const GROUPS = [
23
25
  export function AddPanel({
24
26
  onAdd,
25
27
  onRecipe,
28
+ saved,
26
29
  defaultQuery = "",
27
30
  formsAvailable = true,
28
31
  }: {
29
32
  onAdd: (type: ElementType) => void;
30
33
  /** Adds a section recipe (W-320); without it, recipes are not offered. */
31
34
  onRecipe?: (id: string) => void;
35
+ /** My sections (W-876); without it the group is not shown. */
36
+ saved?: SavedSectionActions;
32
37
  /** Test-only initial search string. */
33
38
  defaultQuery?: string;
34
39
  /** Hide the Form group when the forms plugin is missing (W-036). */
@@ -68,7 +73,9 @@ export function AddPanel({
68
73
  }}
69
74
  placeholder="Search elements…"
70
75
  />
71
- {matched.length === 0 && recipes.length === 0 ? (
76
+ {matched.length === 0 &&
77
+ recipes.length === 0 &&
78
+ (!saved || matchingSections(saved, query).length === 0) ? (
72
79
  <div className="emvb-add-nomatch" data-emvb-add-nomatch="">
73
80
  <p className="emvb-helper" role="status">
74
81
  No elements match &quot;{query.trim()}&quot;.
@@ -146,6 +153,7 @@ export function AddPanel({
146
153
  </div>
147
154
  </div>
148
155
  )}
156
+ {saved && <SavedSectionsGroup saved={saved} query={query} />}
149
157
  </div>
150
158
  );
151
159
  }
@@ -50,6 +50,8 @@ type LayerActions = {
50
50
  clipboard?: ClipboardActions;
51
51
  /** Sets or clears a node's editor-only name (W-157); without it rows can't be renamed. */
52
52
  onRename?: (id: string, label: string | undefined) => void;
53
+ /** Opens Save as section (W-876); without it the menu has no such item. */
54
+ onSaveSection?: (id: string) => void;
53
55
  };
54
56
 
55
57
  type MenuItem = {
@@ -96,6 +98,7 @@ function menuItems(
96
98
  runners: {
97
99
  rename: actions.onRename ? rename : undefined,
98
100
  duplicate: actions.onDuplicate,
101
+ saveSection: actions.onSaveSection,
99
102
  remove: actions.onDelete,
100
103
  moveUp: actions.onMoveUp,
101
104
  moveDown: actions.onMoveDown,
@@ -209,6 +212,7 @@ export function LayersPanel({
209
212
  const live = React.useRef(actions);
210
213
  live.current = actions;
211
214
  const canRename = !!actions.onRename;
215
+ const canSaveSection = !!actions.onSaveSection;
212
216
  const rowActions = React.useMemo<LayerActions>(
213
217
  () => ({
214
218
  onSelect: (id) => live.current.onSelect(id),
@@ -217,8 +221,9 @@ export function LayersPanel({
217
221
  onMoveDown: (id) => live.current.onMoveDown(id),
218
222
  onDelete: (id) => live.current.onDelete(id),
219
223
  onRename: canRename ? (id, label) => live.current.onRename?.(id, label) : undefined,
224
+ onSaveSection: canSaveSection ? (id) => live.current.onSaveSection?.(id) : undefined,
220
225
  }),
221
- [canRename],
226
+ [canRename, canSaveSection],
222
227
  );
223
228
  const onRowMenu = React.useCallback(
224
229
  (id: string, open: boolean) => setMenuId(open ? id : null),
@@ -4,6 +4,7 @@ import type { ElementType, Layout } from "../../../core/index.ts";
4
4
  import { AddPanel } from "./AddPanel.tsx";
5
5
  import { LayersPanel } from "./LayersPanel.tsx";
6
6
  import type { ClipboardActions } from "../useClipboardActions.ts";
7
+ import type { SavedSectionActions } from "../useSavedSections.ts";
7
8
 
8
9
  const SESSION_KEY = "emvb-left-tab";
9
10
 
@@ -14,12 +15,14 @@ export function LeftPanel({
14
15
  onSelect,
15
16
  onAdd,
16
17
  onRecipe,
18
+ saved,
17
19
  onDuplicate,
18
20
  onMoveUp,
19
21
  onMoveDown,
20
22
  onDelete,
21
23
  clipboard,
22
24
  onRename,
25
+ onSaveSection,
23
26
  formsAvailable = true,
24
27
  }: {
25
28
  layout: Layout | null;
@@ -28,6 +31,8 @@ export function LeftPanel({
28
31
  onAdd: (type: ElementType) => void;
29
32
  /** Adds a section recipe (W-320). */
30
33
  onRecipe?: (id: string) => void;
34
+ /** My sections (W-876). */
35
+ saved?: SavedSectionActions;
31
36
  onDuplicate: (id: string) => void;
32
37
  onMoveUp: (id: string) => void;
33
38
  onMoveDown: (id: string) => void;
@@ -35,6 +40,8 @@ export function LeftPanel({
35
40
  clipboard?: ClipboardActions;
36
41
  /** Layers rename (W-157). */
37
42
  onRename?: (id: string, label: string | undefined) => void;
43
+ /** Save as section in the row menu (W-876). */
44
+ onSaveSection?: (id: string) => void;
38
45
  formsAvailable?: boolean;
39
46
  }) {
40
47
  const [tab, setTab] = React.useState(() => {
@@ -65,7 +72,7 @@ export function LeftPanel({
65
72
  onValueChange={changeTab}
66
73
  />
67
74
  {tab === "add" ? (
68
- <AddPanel onAdd={onAdd} onRecipe={onRecipe} formsAvailable={formsAvailable} />
75
+ <AddPanel onAdd={onAdd} onRecipe={onRecipe} saved={saved} formsAvailable={formsAvailable} />
69
76
  ) : (
70
77
  <LayersPanel
71
78
  layout={layout}
@@ -77,6 +84,7 @@ export function LeftPanel({
77
84
  onDelete={onDelete}
78
85
  clipboard={clipboard}
79
86
  onRename={onRename}
87
+ onSaveSection={onSaveSection}
80
88
  />
81
89
  )}
82
90
  </div>
@@ -0,0 +1,246 @@
1
+ import { Button, Input } from "@cloudflare/kumo";
2
+ import { PencilSimpleIcon, TrashIcon } from "@phosphor-icons/react";
3
+ import * as React from "react";
4
+ import { SAVED_SECTION_NAME_MAX } from "../../../core/index.ts";
5
+ import { matchesSearch } from "../../search.ts";
6
+ import { BUTTON, FIELD } from "../../ui.ts";
7
+ import { DeleteSavedSectionDialog } from "../SavedSectionDialogs.tsx";
8
+ import type { SavedSectionActions } from "../useSavedSections.ts";
9
+
10
+ /** Saved sections that match the Add panel's search. */
11
+ export const matchingSections = (saved: SavedSectionActions, query: string) =>
12
+ saved.list.filter((item) => matchesSearch(query, item.name, "my saved section"));
13
+
14
+ const focusIn = (root: HTMLElement | null, selector: string) =>
15
+ root?.querySelector<HTMLElement>(selector)?.focus({ preventScroll: false });
16
+
17
+ /**
18
+ * "My sections" in the Add panel (W-876): names only (D-060), filtered by the panel's search.
19
+ * A name inserts a copy; rename edits in place; delete asks first, then focus goes to the next
20
+ * section, the one before, the group heading when the list is empty, or the search field when
21
+ * the search no longer matches any section.
22
+ */
23
+ export function SavedSectionsGroup({
24
+ saved,
25
+ query,
26
+ }: {
27
+ saved: SavedSectionActions;
28
+ query: string;
29
+ }) {
30
+ const groupRef = React.useRef<HTMLDivElement>(null);
31
+ const [renaming, setRenaming] = React.useState<string | null>(null);
32
+ const [renameError, setRenameError] = React.useState<string | null>(null);
33
+ const [asking, setAsking] = React.useState<string | null>(null);
34
+ const [deleteError, setDeleteError] = React.useState<string | null>(null);
35
+ /** Where focus goes once the delete dialog has closed. */
36
+ const focusAfter = React.useRef<string | null>(null);
37
+ /** A control to focus once the render that brings it back has committed. */
38
+ const [focusNext, setFocusNext] = React.useState<string | null>(null);
39
+ React.useEffect(() => {
40
+ if (!focusNext) return;
41
+ focusIn(groupRef.current, focusNext);
42
+ setFocusNext(null);
43
+ }, [focusNext]);
44
+ const items = matchingSections(saved, query);
45
+ if (query.trim() && items.length === 0) return null;
46
+ const askedName = saved.list.find((item) => item.id === asking)?.name ?? null;
47
+
48
+ const finishRename = async (id: string, value: string | null) => {
49
+ const current = saved.list.find((item) => item.id === id);
50
+ if (value === null || !current || value.trim() === current.name) {
51
+ setRenaming(null);
52
+ setRenameError(null);
53
+ setFocusNext(`[data-emvb-saved-rename="${id}"]`);
54
+ return;
55
+ }
56
+ const failed = await saved.rename(id, value);
57
+ if (failed) {
58
+ setRenameError(failed);
59
+ return;
60
+ }
61
+ setRenaming(null);
62
+ setRenameError(null);
63
+ setFocusNext(`[data-emvb-saved-section="${id}"]`);
64
+ };
65
+
66
+ const confirmDelete = async () => {
67
+ const id = asking;
68
+ if (!id) return;
69
+ const at = items.findIndex((item) => item.id === id);
70
+ const next = items[at + 1] ?? items[at - 1];
71
+ const panel = groupRef.current?.closest<HTMLElement>('[data-emvb-panel="add"]');
72
+ const failed = await saved.remove(id);
73
+ if (!failed && !next && query.trim()) {
74
+ // The search matches nothing here now, so the group (and its dialog) goes away: put focus
75
+ // back in the search field rather than on the page body.
76
+ setAsking(null);
77
+ const search = () => panel?.querySelector<HTMLElement>('input[type="search"]');
78
+ requestAnimationFrame(() => setTimeout(() => search()?.focus(), 0));
79
+ return;
80
+ }
81
+ if (failed) {
82
+ setDeleteError(failed);
83
+ focusAfter.current = `[data-emvb-saved-delete="${id}"]`;
84
+ } else {
85
+ setDeleteError(null);
86
+ focusAfter.current = next
87
+ ? `[data-emvb-saved-section="${next.id}"]`
88
+ : "[data-emvb-saved-title]";
89
+ }
90
+ setAsking(null);
91
+ };
92
+
93
+ return (
94
+ <div className="emvb-add-group" data-emvb-saved-sections="" ref={groupRef}>
95
+ <h3 className="emvb-add-group-title" tabIndex={-1} data-emvb-saved-title="">
96
+ My sections
97
+ </h3>
98
+ {!saved.loaded ? (
99
+ <p className="emvb-helper" role="status">
100
+ Loading My sections…
101
+ </p>
102
+ ) : saved.loadError ? (
103
+ <div className="emvb-saved-error">
104
+ <p className="emvb-inline-error" role="alert">
105
+ {saved.loadError}
106
+ </p>
107
+ <Button type="button" variant="secondary" className={BUTTON} onClick={saved.refresh}>
108
+ Try again
109
+ </Button>
110
+ </div>
111
+ ) : items.length === 0 ? (
112
+ <p className="emvb-helper" data-emvb-saved-empty="">
113
+ Save an element as a section from its ··· menu in Layers, or with Save as section in the
114
+ command palette.
115
+ </p>
116
+ ) : (
117
+ <ul className="emvb-saved-list" aria-label="My sections">
118
+ {items.map((item) => (
119
+ <li key={item.id} className="emvb-saved-row">
120
+ {renaming === item.id ? (
121
+ <RenameField
122
+ initial={item.name}
123
+ error={renameError}
124
+ onDone={(value) => void finishRename(item.id, value)}
125
+ />
126
+ ) : (
127
+ <>
128
+ <button
129
+ type="button"
130
+ className="emvb-saved-name"
131
+ data-emvb-saved-section={item.id}
132
+ disabled={item.damaged}
133
+ title={
134
+ item.damaged ? "This saved section can't be read" : `Insert ${item.name}`
135
+ }
136
+ onClick={() => void saved.insert(item.id)}
137
+ >
138
+ {item.name}
139
+ {item.damaged && <span className="emvb-helper"> (can&apos;t be read)</span>}
140
+ </button>
141
+ <Button
142
+ type="button"
143
+ variant="ghost"
144
+ shape="square"
145
+ size="sm"
146
+ className="emvb-icon-btn"
147
+ aria-label={`Rename ${item.name}`}
148
+ title="Rename"
149
+ data-emvb-saved-rename={item.id}
150
+ disabled={item.damaged}
151
+ icon={<PencilSimpleIcon aria-hidden="true" />}
152
+ onClick={() => {
153
+ setRenameError(null);
154
+ setRenaming(item.id);
155
+ }}
156
+ />
157
+ <Button
158
+ type="button"
159
+ variant="ghost"
160
+ shape="square"
161
+ size="sm"
162
+ className="emvb-icon-btn"
163
+ aria-label={`Delete ${item.name}`}
164
+ title="Delete"
165
+ data-emvb-saved-delete={item.id}
166
+ icon={<TrashIcon aria-hidden="true" />}
167
+ onClick={() => setAsking(item.id)}
168
+ />
169
+ </>
170
+ )}
171
+ </li>
172
+ ))}
173
+ </ul>
174
+ )}
175
+ {deleteError && (
176
+ <p className="emvb-inline-error" role="alert">
177
+ {deleteError}
178
+ </p>
179
+ )}
180
+ <DeleteSavedSectionDialog
181
+ name={askedName}
182
+ onOpenChange={(open) => {
183
+ if (open) return;
184
+ // Cancel or Escape: back to the row's Delete button.
185
+ if (asking && !focusAfter.current) {
186
+ focusAfter.current = `[data-emvb-saved-delete="${asking}"]`;
187
+ }
188
+ setAsking(null);
189
+ }}
190
+ onDelete={() => void confirmDelete()}
191
+ onClosed={() => {
192
+ const target = focusAfter.current;
193
+ focusAfter.current = null;
194
+ if (target) focusIn(groupRef.current, target);
195
+ }}
196
+ />
197
+ </div>
198
+ );
199
+ }
200
+
201
+ /** The inline name field: Enter or leaving saves, Escape cancels. */
202
+ function RenameField({
203
+ initial,
204
+ error,
205
+ onDone,
206
+ }: {
207
+ initial: string;
208
+ error: string | null;
209
+ onDone: (value: string | null) => void;
210
+ }) {
211
+ const [text, setText] = React.useState(initial);
212
+ const done = React.useRef(false);
213
+ const finish = (value: string | null) => {
214
+ if (done.current) return;
215
+ done.current = true;
216
+ onDone(value);
217
+ // A refused name stays open for another try.
218
+ requestAnimationFrame(() => {
219
+ done.current = false;
220
+ });
221
+ };
222
+ return (
223
+ <Input
224
+ aria-label="Section name"
225
+ className={`${FIELD} emvb-saved-rename`}
226
+ data-emvb-saved-rename-field=""
227
+ autoFocus
228
+ maxLength={SAVED_SECTION_NAME_MAX}
229
+ value={text}
230
+ error={error ?? undefined}
231
+ aria-invalid={error ? true : undefined}
232
+ onFocus={(event) => event.currentTarget.select()}
233
+ onChange={(event) => setText(event.target.value)}
234
+ onBlur={() => finish(text)}
235
+ onKeyDown={(event) => {
236
+ event.stopPropagation();
237
+ if (event.nativeEvent.isComposing || event.keyCode === 229) return;
238
+ if (event.key === "Enter") {
239
+ event.preventDefault();
240
+ finish(text);
241
+ }
242
+ if (event.key === "Escape") finish(null);
243
+ }}
244
+ />
245
+ );
246
+ }
@@ -175,9 +175,9 @@ export function SiteStylesDrawer({
175
175
  <h2 className="emvb-panel-title">Site styles</h2>
176
176
  <p className="emvb-helper emvb-site-styles-subtitle" data-emvb-manager-label="">
177
177
  {tab === "variables"
178
- ? "Variables Manager"
178
+ ? "Variables manager"
179
179
  : tab === "classes"
180
- ? "Classes Manager"
180
+ ? "Classes manager"
181
181
  : "Defaults"}
182
182
  </p>
183
183
  </div>
@@ -481,10 +481,26 @@ function DeleteConfirm({
481
481
  : 0;
482
482
  const noun = useEditedNoun();
483
483
  const where = usedIn(pageUses, classUses, noun);
484
+ // W-849: the confirmation opened below the list with focus left on the closed row menu, so a
485
+ // keyboard or screen reader user didn't reach it. It takes focus on Cancel, the safe answer.
486
+ const cancelRef = React.useRef<HTMLButtonElement>(null);
487
+ const titleId = React.useId();
488
+ const bodyId = React.useId();
489
+ React.useEffect(() => {
490
+ cancelRef.current?.focus();
491
+ }, [confirm.kind, confirm.id]);
484
492
  return (
485
- <div className="emvb-site-confirm" data-emvb-site-confirm="" role="alertdialog">
486
- <p className="emvb-field-label">Delete {confirm.name}?</p>
487
- <p className="emvb-helper">
493
+ <div
494
+ className="emvb-site-confirm"
495
+ data-emvb-site-confirm=""
496
+ role="alertdialog"
497
+ aria-labelledby={titleId}
498
+ aria-describedby={bodyId}
499
+ >
500
+ <p className="emvb-field-label" id={titleId}>
501
+ Delete {confirm.name}?
502
+ </p>
503
+ <p className="emvb-helper" id={bodyId}>
488
504
  {where
489
505
  ? `In use in ${where}. Deleting drops those bindings.`
490
506
  : variable
@@ -493,7 +509,13 @@ function DeleteConfirm({
493
509
  {NOT_CHECKED}
494
510
  </p>
495
511
  <div className="emvb-dialog-actions">
496
- <Button type="button" variant="secondary" className={BUTTON} onClick={onCancel}>
512
+ <Button
513
+ ref={cancelRef}
514
+ type="button"
515
+ variant="secondary"
516
+ className={BUTTON}
517
+ onClick={onCancel}
518
+ >
497
519
  Cancel
498
520
  </Button>
499
521
  <Button
@@ -608,10 +630,26 @@ function ImportConfirm({
608
630
  losses.classes > 0 ? plural(losses.classes, "class", "classes") : "",
609
631
  losses.variables > 0 ? plural(losses.variables, "variable", "variables") : "",
610
632
  ].filter(Boolean);
633
+ // W-854: like the delete confirmation (W-849), it takes focus on Cancel, the safe answer, so a
634
+ // keyboard or screen reader user reaches it after picking the file.
635
+ const cancelRef = React.useRef<HTMLButtonElement>(null);
636
+ const titleId = React.useId();
637
+ const bodyId = React.useId();
638
+ React.useEffect(() => {
639
+ cancelRef.current?.focus();
640
+ }, [name]);
611
641
  return (
612
- <div className="emvb-site-confirm" data-emvb-import-confirm="" role="alertdialog">
613
- <p className="emvb-field-label">Replace site styles with {name}?</p>
614
- <p className="emvb-helper">
642
+ <div
643
+ className="emvb-site-confirm"
644
+ data-emvb-import-confirm=""
645
+ role="alertdialog"
646
+ aria-labelledby={titleId}
647
+ aria-describedby={bodyId}
648
+ >
649
+ <p className="emvb-field-label" id={titleId}>
650
+ Replace site styles with {name}?
651
+ </p>
652
+ <p className="emvb-helper" id={bodyId}>
615
653
  {lost.length > 0
616
654
  ? `${lost.join(" and ")} that the file doesn't have will be removed. `
617
655
  : "Every class and variable is replaced by the file's. "}
@@ -632,7 +670,13 @@ function ImportConfirm({
632
670
  </p>
633
671
  )}
634
672
  <div className="emvb-dialog-actions">
635
- <Button type="button" variant="secondary" className={BUTTON} onClick={onCancel}>
673
+ <Button
674
+ ref={cancelRef}
675
+ type="button"
676
+ variant="secondary"
677
+ className={BUTTON}
678
+ onClick={onCancel}
679
+ >
636
680
  Cancel
637
681
  </Button>
638
682
  <Button
@@ -1,3 +1,4 @@
1
+ import { Checkbox, Input } from "@cloudflare/kumo";
1
2
  import * as React from "react";
2
3
  import {
3
4
  applyTokens,
@@ -8,6 +9,7 @@ import {
8
9
  type DesignSystem,
9
10
  } from "../../../core/index.ts";
10
11
  import { fieldNumber } from "./settings/number-input.ts";
12
+ import { FIELD } from "../../ui.ts";
11
13
  import { PanelSelect } from "./settings/PanelSelect.tsx";
12
14
 
13
15
  // W-436: the fields are labelled "(px)", so "18px" is 18.
@@ -90,8 +92,8 @@ export function TokenScales({
90
92
  </div>
91
93
  <label>
92
94
  <span className="emvb-bind-label">{kind === "type" ? "Body size" : "Base gap"} (px)</span>
93
- <input
94
- className="emvb-native-input"
95
+ <Input
96
+ className={FIELD}
95
97
  inputMode="decimal"
96
98
  value={base}
97
99
  data-emvb-tokens-base=""
@@ -115,23 +117,21 @@ export function TokenScales({
115
117
  />
116
118
  </div>
117
119
  )}
118
- <label className="emvb-tokens-fluid">
119
- <input
120
- type="checkbox"
121
- checked={fluid}
122
- data-emvb-tokens-fluid=""
123
- onChange={(event) => {
124
- setFluid(event.currentTarget.checked);
125
- setDone(null);
126
- }}
127
- />{" "}
128
- Fluid
129
- </label>
120
+ <Checkbox
121
+ className="emvb-tokens-fluid"
122
+ label="Fluid"
123
+ checked={fluid}
124
+ data-emvb-tokens-fluid=""
125
+ onCheckedChange={(checked) => {
126
+ setFluid(checked);
127
+ setDone(null);
128
+ }}
129
+ />
130
130
  {fluid && (
131
131
  <label data-emvb-tokens-row="full">
132
132
  <span className="emvb-bind-label">On small screens (px)</span>
133
- <input
134
- className="emvb-native-input"
133
+ <Input
134
+ className={FIELD}
135
135
  inputMode="decimal"
136
136
  value={minBase}
137
137
  data-emvb-tokens-min=""
@@ -66,7 +66,7 @@ function ShowTimesField({
66
66
  type="number"
67
67
  min={1}
68
68
  max={100}
69
- description="Leave empty for no limit. Counted per visitor's browser, up to 100."
69
+ description="Leave empty for no limit. Counted per visitor's browser, up to 100. A click trigger always opens."
70
70
  value={draft}
71
71
  onChange={(event) => setDraft(event.target.value)}
72
72
  onBlur={commit}