@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
@@ -1,4 +1,4 @@
1
- import { CaretDownIcon, CaretRightIcon } from "@phosphor-icons/react";
1
+ import { CaretDownIcon, CaretRightIcon, DotsThreeIcon } from "@phosphor-icons/react";
2
2
  import * as React from "react";
3
3
  import {
4
4
  firstChild,
@@ -23,6 +23,13 @@ import { dragStash } from "../dnd/drag-stash.ts";
23
23
  import { StateDot } from "./settings/StateSwitcher.tsx";
24
24
  import type { ClipboardActions } from "../useClipboardActions.ts";
25
25
 
26
+ /**
27
+ * UX-052: 12 px per level for the first four levels, then 6 px, so a row ten levels deep still
28
+ * shows its name in the 256 px panel instead of "H…".
29
+ */
30
+ export const layerIndent = (depth: number): number =>
31
+ 8 + 12 * Math.min(depth, 4) + 6 * Math.max(0, depth - 4);
32
+
26
33
  const rows = (
27
34
  node: LayoutNode,
28
35
  depth: number,
@@ -219,6 +226,28 @@ export function LayersPanel({
219
226
  );
220
227
  const toggle = React.useMemo(() => toggleIn(setCollapsed), []);
221
228
 
229
+ // W-612: an open row menu closes when a press lands outside it, focus leaves the panel's
230
+ // window (a click in the canvas frame), or focus moves out of it (Tab).
231
+ React.useEffect(() => {
232
+ if (!menuId) return;
233
+ const close = () => setMenuId(null);
234
+ const onPress = (event: Event) => {
235
+ if (!inRowMenu(event.target)) close();
236
+ };
237
+ const onFocusOut = (event: FocusEvent) => {
238
+ const to = event.relatedTarget;
239
+ if (inRowMenu(event.target) && to instanceof Element && !inRowMenu(to)) close();
240
+ };
241
+ document.addEventListener("pointerdown", onPress, true);
242
+ document.addEventListener("focusout", onFocusOut);
243
+ window.addEventListener("blur", close);
244
+ return () => {
245
+ document.removeEventListener("pointerdown", onPress, true);
246
+ document.removeEventListener("focusout", onFocusOut);
247
+ window.removeEventListener("blur", close);
248
+ };
249
+ }, [menuId]);
250
+
222
251
  React.useEffect(() => {
223
252
  if (!layout || !selectedId) return;
224
253
  setCollapsed((current) => {
@@ -412,7 +441,7 @@ const LayerRow = React.memo(function LayerRow({
412
441
  <div
413
442
  className="emvb-layer-row"
414
443
  data-emvb-layer={node.id}
415
- style={{ paddingLeft: 8 + depth * 12 }}
444
+ style={{ paddingLeft: layerIndent(depth) }}
416
445
  onClick={() => actions.onSelect(node.id)}
417
446
  >
418
447
  {hasChildren ? (
@@ -510,28 +539,33 @@ const LayerRow = React.memo(function LayerRow({
510
539
  }}
511
540
  onKeyDown={menuKeys}
512
541
  >
513
- ···
542
+ <DotsThreeIcon size={16} weight="bold" aria-hidden="true" />
514
543
  </button>
515
544
  {menuOpen && (
516
545
  <div ref={menuList} className="emvb-layer-menu-list" role="menu" onKeyDown={menuKeys}>
517
546
  {menuItems(node, isRoot, actions, clip, startRename).map(
518
547
  ({ label, run, className, disabled }) => (
519
- <button
520
- key={label}
521
- type="button"
522
- role="menuitem"
523
- className={className}
524
- disabled={disabled}
525
- onClick={(event) => {
526
- event.stopPropagation();
527
- const tree = event.currentTarget.closest('[role="tree"]');
528
- onMenu(false);
529
- run(node.id);
530
- window.setTimeout(() => focusSelectedRow(tree), 0);
531
- }}
532
- >
533
- {label}
534
- </button>
548
+ <React.Fragment key={label}>
549
+ {/* UX-026: Delete sits apart from the other actions, as in Site styles. */}
550
+ {label === "Delete" && (
551
+ <hr className="emvb-layer-menu-sep" aria-hidden="true" />
552
+ )}
553
+ <button
554
+ type="button"
555
+ role="menuitem"
556
+ className={className}
557
+ disabled={disabled}
558
+ onClick={(event) => {
559
+ event.stopPropagation();
560
+ const tree = event.currentTarget.closest('[role="tree"]');
561
+ onMenu(false);
562
+ run(node.id);
563
+ window.setTimeout(() => focusSelectedRow(tree), 0);
564
+ }}
565
+ >
566
+ {label}
567
+ </button>
568
+ </React.Fragment>
535
569
  ),
536
570
  )}
537
571
  {pasteHint(clip) && (
@@ -584,6 +618,8 @@ function RenameInput({
584
618
  onBlur={() => finish(text)}
585
619
  onKeyDown={(event) => {
586
620
  event.stopPropagation();
621
+ // Enter or Escape that ends an IME composition only finishes the word (W-606).
622
+ if (event.nativeEvent.isComposing || event.keyCode === 229) return;
587
623
  if (event.key === "Enter") finish(text, true);
588
624
  if (event.key === "Escape") finish(null, true);
589
625
  }}
@@ -1,10 +1,11 @@
1
- import { Button, Collapsible, Input, Select, Switch } from "@cloudflare/kumo";
1
+ import { Button, Collapsible, Input, Select } from "@cloudflare/kumo";
2
2
  import { CaretDownIcon, CaretRightIcon } from "@phosphor-icons/react";
3
3
  import * as React from "react";
4
4
  import {
5
5
  defaultFloatSettings,
6
6
  FLOAT_EDGES,
7
7
  THEME_PART_TYPE_LABELS,
8
+ type ThemePartType,
8
9
  type FloatEdge,
9
10
  type LayoutNode,
10
11
  } from "../../../core/index.ts";
@@ -13,6 +14,7 @@ import { canonicalProblem, type PageDraft } from "../../content-api.ts";
13
14
  import { BUTTON, FIELD } from "../../ui.ts";
14
15
  import type { PagePatch } from "../store.ts";
15
16
  import { ConditionsEditor } from "./ConditionsEditor.tsx";
17
+ import { HintedSwitch } from "./settings/HintedSwitch.tsx";
16
18
  import { MediaPicker } from "./settings/MediaPicker.tsx";
17
19
  import { TriggersEditor } from "./TriggersEditor.tsx";
18
20
 
@@ -21,6 +23,16 @@ const LAYOUTS = [
21
23
  { value: "blank", label: "Blank" },
22
24
  ];
23
25
 
26
+ /** Where each reusable part is used, said in place of display conditions (UX-061). */
27
+ const ITEM_PART_USE: Partial<Record<ThemePartType, string>> = {
28
+ loop_item:
29
+ "Loop elements show this part for each entry they list, so it has no display conditions.",
30
+ section:
31
+ "Theme section elements show this part wherever you place them, so it has no display conditions.",
32
+ page_template:
33
+ "New page offers this layout as a starting point, so it has no display conditions.",
34
+ };
35
+
24
36
  /** Right panel with nothing selected (IA): page settings or theme-part settings. */
25
37
  export function PageSettings({
26
38
  page,
@@ -37,6 +49,7 @@ export function PageSettings({
37
49
  fetcher?: Fetcher;
38
50
  }) {
39
51
  // Hooks run before the theme-part branch, so switching `kind` keeps the hook order (W-092).
52
+ const descriptionId = React.useId();
40
53
  const [seoOpen, setSeoOpen] = React.useState(false);
41
54
  if (kind === "theme-part") {
42
55
  return (
@@ -48,17 +61,27 @@ export function PageSettings({
48
61
  value={page.title}
49
62
  onChange={(event) => onChange({ title: event.target.value })}
50
63
  />
51
- <Input
52
- label="Type"
53
- className={FIELD}
54
- value={THEME_PART_TYPE_LABELS[page.partType ?? "header"]}
55
- disabled
56
- description="Chosen when the part was created."
57
- />
58
- <ConditionsEditor
59
- conditions={page.conditions}
60
- onChange={(conditions) => onChange({ conditions })}
61
- />
64
+ {/* UX-092: the type is fixed, so it reads as a fact, not a field that won't take input. */}
65
+ <div className="emvb-field-group" data-emvb-part-type="">
66
+ <p className="emvb-part-type">
67
+ <span className="emvb-field-label">Type</span>
68
+ <span className="emvb-part-type-value">
69
+ {THEME_PART_TYPE_LABELS[page.partType ?? "header"]}
70
+ </span>
71
+ </p>
72
+ <p className="emvb-helper">Chosen when the part was created.</p>
73
+ </div>
74
+ {ITEM_PART_USE[page.partType ?? "header"] ? (
75
+ // UX-061: item parts never match a page location, so conditions would change nothing.
76
+ <p className="emvb-helper" data-emvb-item-part-note="">
77
+ {ITEM_PART_USE[page.partType ?? "header"]}
78
+ </p>
79
+ ) : (
80
+ <ConditionsEditor
81
+ conditions={page.conditions}
82
+ onChange={(conditions) => onChange({ conditions })}
83
+ />
84
+ )}
62
85
  {page.partType === "popup" && (
63
86
  <TriggersEditor
64
87
  triggers={page.triggers}
@@ -76,8 +99,8 @@ export function PageSettings({
76
99
  }
77
100
 
78
101
  const seoCount = [
79
- page.seoTitle,
80
- page.seoDescription,
102
+ page.seoTitle.trim(),
103
+ page.seoDescription.trim(),
81
104
  page.seoCanonical?.trim(),
82
105
  page.seoNoIndex,
83
106
  page.seoImage?.trim(),
@@ -136,13 +159,25 @@ export function PageSettings({
136
159
  onChange={(event) => onChange({ seoTitle: event.target.value })}
137
160
  />
138
161
  <p className="emvb-helper">Shown in search results and browser tabs.</p>
139
- <Input
140
- label="Meta description"
141
- className={FIELD}
142
- maxLength={500}
143
- value={page.seoDescription}
144
- onChange={(event) => onChange({ seoDescription: event.target.value })}
145
- />
162
+ {/* UX-021: a description runs to about 150 characters, so it gets room and a count. */}
163
+ <div className="emvb-field-group">
164
+ <label className="emvb-field-label" htmlFor={descriptionId}>
165
+ Meta description
166
+ </label>
167
+ <textarea
168
+ id={descriptionId}
169
+ dir="auto"
170
+ className={`${FIELD} emvb-textarea`}
171
+ rows={3}
172
+ maxLength={500}
173
+ aria-describedby={`${descriptionId}-count`}
174
+ value={page.seoDescription}
175
+ onChange={(event) => onChange({ seoDescription: event.target.value })}
176
+ />
177
+ <p className="emvb-helper" id={`${descriptionId}-count`} data-emvb-seo-count="">
178
+ {page.seoDescription.length} characters. Search results show about 150.
179
+ </p>
180
+ </div>
146
181
  {/* W-284: EmDash stores these; the public page prints them (W-274). */}
147
182
  <Input
148
183
  label="Canonical URL"
@@ -190,14 +225,13 @@ export function PageSettings({
190
225
  )}
191
226
  </div>
192
227
  )}
193
- <Switch
228
+ <HintedSwitch
194
229
  label="Hide from search engines"
195
230
  checked={page.seoNoIndex === true}
196
- onCheckedChange={(checked) => onChange({ seoNoIndex: checked === true })}
231
+ onCheckedChange={(checked) => onChange({ seoNoIndex: checked })}
232
+ hint="Search engines are asked not to list this page or follow its links (noindex, nofollow)."
233
+ hintData={{ "data-emvb-noindex-help": "" }}
197
234
  />
198
- <p className="emvb-helper" data-emvb-noindex-help="">
199
- Search engines are asked not to list this page or follow its links (noindex, nofollow).
200
- </p>
201
235
  </Collapsible.Panel>
202
236
  </Collapsible.Root>
203
237
  </div>
@@ -222,11 +256,13 @@ function FloatSettingsFields({
222
256
  onChange: (settings: NonNullable<PageDraft["float"]>) => void;
223
257
  }) {
224
258
  return (
225
- <div data-emvb-panel="float">
259
+ // UX-061: the panel's field rhythm, and the note described by the Place select.
260
+ <div className="emvb-field-group" data-emvb-panel="float">
226
261
  <Select
227
262
  label="Place"
228
263
  className={FIELD}
229
264
  value={settings.edge}
265
+ description="A bar stays on that edge and leaves room for the page. A corner sits over the page."
230
266
  onValueChange={(value) => {
231
267
  const edge = FLOAT_EDGES.find((item) => item === value);
232
268
  if (edge) onChange({ ...settings, edge });
@@ -239,17 +275,12 @@ function FloatSettingsFields({
239
275
  </Select.Option>
240
276
  ))}
241
277
  </Select>
242
- <p className="emvb-helper">
243
- A bar stays on that edge and leaves room for the page. A corner sits over the page.
244
- </p>
245
- <Switch
278
+ <HintedSwitch
246
279
  label="Close button"
247
280
  checked={settings.dismiss}
248
- onCheckedChange={(checked) => onChange({ ...settings, dismiss: checked === true })}
281
+ onCheckedChange={(checked) => onChange({ ...settings, dismiss: checked })}
282
+ hint="Closing hides it until the next visit. Nothing is stored in a cookie."
249
283
  />
250
- <p className="emvb-helper">
251
- Closing hides it until the next visit. Nothing is stored in a cookie.
252
- </p>
253
284
  </div>
254
285
  );
255
286
  }
@@ -1,6 +1,6 @@
1
- import { Button, Select, Tabs } from "@cloudflare/kumo";
1
+ import { Button, Loader, Select, Tabs } from "@cloudflare/kumo";
2
2
  import { deletionOf, type Deletion } from "../restore-deleted.ts";
3
- import { XIcon } from "@phosphor-icons/react";
3
+ import { UploadSimpleIcon, XIcon } from "@phosphor-icons/react";
4
4
  import * as React from "react";
5
5
  import {
6
6
  clearClassRefs,
@@ -26,11 +26,14 @@ import {
26
26
  import { BUTTON, SOLID_DESTRUCTIVE } from "../../ui.ts";
27
27
  import { ClassesSection } from "./ClassesSection.tsx";
28
28
  import { stopEditorShortcuts } from "./settings/ClassChip.tsx";
29
+ import { isCancelEscape } from "../ime.ts";
29
30
  import { StyleRow } from "./settings/StyleRow.tsx";
30
31
  import { FIELD } from "../../ui.ts";
31
32
  import { TokenScales } from "./TokenScales.tsx";
32
33
  import { InlineError } from "./inline-error.tsx";
33
34
  import { VariableSection } from "./VariableSection.tsx";
35
+ import { useMediaQuery } from "../useMediaQuery.ts";
36
+ import { useEditedNoun, type EditedNoun } from "../edited-noun.ts";
34
37
 
35
38
  const STYLE_NOTE = "Style changes stay unpublished until you publish styles.";
36
39
 
@@ -75,6 +78,19 @@ export function SiteStylesDrawer({
75
78
  }: Props) {
76
79
  const [tab, setTab] = React.useState<"variables" | "classes" | "defaults">("variables");
77
80
  const [error, setError] = React.useState<string | null>(null);
81
+ const [publishing, setPublishing] = React.useState(false);
82
+ const publishPending = React.useRef(false);
83
+ // W-829: Publish styles stays focusable while publishing; once it publishes the button goes
84
+ // away, so focus moves on to Export instead of falling to the page body.
85
+ const publishRef = React.useRef<HTMLButtonElement>(null);
86
+ const exportRef = React.useRef<HTMLButtonElement>(null);
87
+ const refocusAfterPublish = React.useRef(false);
88
+ React.useEffect(() => {
89
+ if (unpublished || !refocusAfterPublish.current) return;
90
+ refocusAfterPublish.current = false;
91
+ exportRef.current?.focus();
92
+ }, [unpublished]);
93
+ const reducedMotion = useMediaQuery("(prefers-reduced-motion: reduce)");
78
94
  const [confirm, setConfirm] = React.useState<
79
95
  | { kind: "variable"; variableKind: VariableKind; id: string; name: string }
80
96
  | { kind: "class"; id: string; name: string }
@@ -87,22 +103,31 @@ export function SiteStylesDrawer({
87
103
  renamed: ImportRename[];
88
104
  } | null>(null);
89
105
 
90
- const save = async (next: DesignSystem) => {
106
+ const save = async (next: DesignSystem): Promise<boolean> => {
91
107
  setError(null);
92
108
  try {
93
109
  await onDesignChange(next);
110
+ return true;
94
111
  } catch (err) {
95
112
  setError(err instanceof Error ? err.message : "Couldn't save site styles. Try again.");
113
+ return false;
96
114
  }
97
115
  };
98
116
 
99
117
  const publish = async () => {
100
- if (!onPublishStyles) return;
118
+ if (!onPublishStyles || publishPending.current) return;
119
+ publishPending.current = true;
120
+ refocusAfterPublish.current = document.activeElement === publishRef.current;
121
+ setPublishing(true);
101
122
  setError(null);
102
123
  try {
103
124
  await onPublishStyles();
104
125
  } catch (err) {
126
+ refocusAfterPublish.current = false;
105
127
  setError(err instanceof Error ? err.message : "Couldn't publish site styles. Try again.");
128
+ } finally {
129
+ publishPending.current = false;
130
+ setPublishing(false);
106
131
  }
107
132
  };
108
133
 
@@ -123,11 +148,27 @@ export function SiteStylesDrawer({
123
148
  setPendingImport({ name: file.name, design: result.design, renamed: result.renamed });
124
149
  };
125
150
 
151
+ const changes = unpublished && published ? designChanges(published, design) : [];
152
+ // UX-069, UX-070: Escape and Close give focus back to the button that opened the drawer.
153
+ const closeAndReturn = () => {
154
+ onClose();
155
+ requestAnimationFrame(() =>
156
+ document
157
+ .querySelector<HTMLElement>('[data-emvb-editor] button[aria-label="Site styles"]')
158
+ ?.focus(),
159
+ );
160
+ };
126
161
  return (
127
162
  <div
128
163
  className="emvb-panel-body emvb-site-styles"
129
164
  data-emvb-site-styles=""
130
- onKeyDown={stopEditorShortcuts}
165
+ onKeyDown={(event) => {
166
+ stopEditorShortcuts(event);
167
+ if (closesDrawer(event)) {
168
+ event.preventDefault();
169
+ closeAndReturn();
170
+ }
171
+ }}
131
172
  >
132
173
  <div className="emvb-site-styles-head">
133
174
  <div className="emvb-site-styles-titles">
@@ -147,7 +188,7 @@ export function SiteStylesDrawer({
147
188
  className="emvb-icon-btn"
148
189
  aria-label="Close site styles"
149
190
  icon={<XIcon aria-hidden="true" />}
150
- onClick={onClose}
191
+ onClick={closeAndReturn}
151
192
  />
152
193
  </div>
153
194
  {/* W-115: the actions get their own wrapping row, so the title is never squeezed. */}
@@ -157,21 +198,50 @@ export function SiteStylesDrawer({
157
198
  aria-label="Site styles actions"
158
199
  data-emvb-site-styles-actions=""
159
200
  >
160
- {unpublished && published && (
161
- <ul className="emvb-helper" data-emvb-style-diff="">
162
- {designChanges(published, design).map((change) => (
163
- <li key={`${change.kind}:${change.what}:${change.name}`}>
164
- {designChangeLabel(change)}
165
- </li>
166
- ))}
167
- </ul>
201
+ {/* UX-024: the change list folds under a count, so a long draft can't push the tabs away. */}
202
+ {changes.length > 0 && (
203
+ <details className="emvb-style-diff" data-emvb-style-diff="">
204
+ <summary className="emvb-helper">
205
+ {changes.length === 1
206
+ ? "1 unpublished change"
207
+ : `${changes.length} unpublished changes`}
208
+ </summary>
209
+ <ul className="emvb-helper">
210
+ {changes.map((change) => (
211
+ <li key={`${change.kind}:${change.what}:${change.name}`}>
212
+ {designChangeLabel(change)}
213
+ </li>
214
+ ))}
215
+ </ul>
216
+ </details>
168
217
  )}
169
218
  {unpublished && (
170
- <Button type="button" variant="primary" size="sm" onClick={() => void publish()}>
219
+ <Button
220
+ type="button"
221
+ variant="primary"
222
+ size="sm"
223
+ ref={publishRef}
224
+ icon={
225
+ publishing && !reducedMotion ? (
226
+ <Loader size={14} />
227
+ ) : (
228
+ <UploadSimpleIcon size={14} aria-hidden="true" />
229
+ )
230
+ }
231
+ aria-disabled={publishing}
232
+ aria-busy={publishing}
233
+ onClick={() => void publish()}
234
+ >
171
235
  Publish styles
172
236
  </Button>
173
237
  )}
174
- <Button type="button" variant="secondary" size="sm" onClick={() => exportDesign(design)}>
238
+ <Button
239
+ ref={exportRef}
240
+ type="button"
241
+ variant="secondary"
242
+ size="sm"
243
+ onClick={() => exportDesign(design)}
244
+ >
175
245
  Export
176
246
  </Button>
177
247
  <Button
@@ -270,7 +340,14 @@ export function SiteStylesDrawer({
270
340
  <DefaultsSection design={design} onSave={save} />
271
341
  </div>
272
342
  )}
273
- <p className="emvb-helper emvb-site-styles-footer">{STYLE_NOTE}</p>
343
+ <p
344
+ className="emvb-helper emvb-site-styles-footer"
345
+ role="status"
346
+ aria-label="Site styles status"
347
+ aria-live="polite"
348
+ >
349
+ {publishing ? "Publishing site styles…" : STYLE_NOTE}
350
+ </p>
274
351
  {pendingImport && (
275
352
  <ImportConfirm
276
353
  name={pendingImport.name}
@@ -289,8 +366,15 @@ export function SiteStylesDrawer({
289
366
  confirm={confirm}
290
367
  design={design}
291
368
  layout={layout}
292
- onCancel={() => setConfirm(null)}
369
+ onCancel={() => {
370
+ const row = confirmRow(confirm);
371
+ setConfirm(null);
372
+ requestAnimationFrame(() =>
373
+ row?.querySelector<HTMLButtonElement>(".emvb-site-menu-btn")?.focus(),
374
+ );
375
+ }}
293
376
  onConfirm={async () => {
377
+ const land = landingAfterDelete(confirmRow(confirm));
294
378
  if (layout) {
295
379
  const deletion = deletionOf(
296
380
  design,
@@ -315,6 +399,7 @@ export function SiteStylesDrawer({
315
399
  await save({ ...design, classes });
316
400
  }
317
401
  setConfirm(null);
402
+ requestAnimationFrame(land);
318
403
  }}
319
404
  />
320
405
  )}
@@ -332,14 +417,42 @@ const NOT_CHECKED =
332
417
  "Other pages and theme parts aren't checked; any that use it lose that styling.";
333
418
 
334
419
  /** "2 places on this page and 1 class", or null when nothing uses it. */
335
- function usedIn(pageUses: number, classUses: number): string | null {
420
+ function usedIn(pageUses: number, classUses: number, noun: EditedNoun): string | null {
336
421
  const parts = [
337
- pageUses > 0 ? `${plural(pageUses, "place", "places")} on this page` : "",
422
+ pageUses > 0 ? `${plural(pageUses, "place", "places")} on this ${noun}` : "",
338
423
  classUses > 0 ? plural(classUses, "class", "classes") : "",
339
424
  ].filter(Boolean);
340
425
  return parts.length > 0 ? parts.join(" and ") : null;
341
426
  }
342
427
 
428
+ /** The list row the delete confirmation is about. */
429
+ function confirmRow(confirm: { kind: "variable" | "class"; id: string }): HTMLElement | null {
430
+ const attribute = confirm.kind === "class" ? "data-emvb-class-def" : "data-emvb-var-id";
431
+ return document.querySelector<HTMLElement>(`[${attribute}="${CSS.escape(confirm.id)}"]`);
432
+ }
433
+
434
+ /**
435
+ * W-841: the deleted row and the inline confirmation both go away, and focus fell to the page
436
+ * body. It lands on the next row, else the previous one, else the list's New button.
437
+ */
438
+ function landingAfterDelete(row: HTMLElement | null): () => void {
439
+ const section = row?.closest("section");
440
+ const neighbour = (row?.nextElementSibling ?? row?.previousElementSibling) as HTMLElement | null;
441
+ const key =
442
+ neighbour?.getAttribute("data-emvb-class-def") ?? neighbour?.getAttribute("data-emvb-var-id");
443
+ const attribute = neighbour?.hasAttribute("data-emvb-class-def")
444
+ ? "data-emvb-class-def"
445
+ : "data-emvb-var-id";
446
+ return () => {
447
+ const next = key
448
+ ? section?.querySelector<HTMLElement>(
449
+ `[${attribute}="${CSS.escape(key)}"] .emvb-site-item-main`,
450
+ )
451
+ : null;
452
+ (next ?? section?.querySelector<HTMLButtonElement>(".emvb-site-section-head button"))?.focus();
453
+ };
454
+ }
455
+
343
456
  function DeleteConfirm({
344
457
  confirm,
345
458
  design,
@@ -366,7 +479,8 @@ function DeleteConfirm({
366
479
  findVariableUsagesInDesign(design, confirm.id, confirm.variableKind).map((u) => u.classId),
367
480
  ).size
368
481
  : 0;
369
- const where = usedIn(pageUses, classUses);
482
+ const noun = useEditedNoun();
483
+ const where = usedIn(pageUses, classUses, noun);
370
484
  return (
371
485
  <div className="emvb-site-confirm" data-emvb-site-confirm="" role="alertdialog">
372
486
  <p className="emvb-field-label">Delete {confirm.name}?</p>
@@ -374,8 +488,8 @@ function DeleteConfirm({
374
488
  {where
375
489
  ? `In use in ${where}. Deleting drops those bindings.`
376
490
  : variable
377
- ? "Not used on this page or by any class."
378
- : "Not used on this page."}{" "}
491
+ ? `Not used on this ${noun} or by any class.`
492
+ : `Not used on this ${noun}.`}{" "}
379
493
  {NOT_CHECKED}
380
494
  </p>
381
495
  <div className="emvb-dialog-actions">
@@ -389,21 +503,45 @@ function DeleteConfirm({
389
503
  style={SOLID_DESTRUCTIVE}
390
504
  onClick={onConfirm}
391
505
  >
392
- Delete
506
+ {variable ? "Delete variable" : "Delete class"}
393
507
  </Button>
394
508
  </div>
395
509
  </div>
396
510
  );
397
511
  }
398
512
 
513
+ /**
514
+ * UX-069: Escape closes the drawer from its buttons, tabs and rows. A text field, an open list or
515
+ * menu, or a dialog keeps its own Escape, so typing is never thrown away.
516
+ */
517
+ function closesDrawer(event: React.KeyboardEvent): boolean {
518
+ if (!isCancelEscape(event) || event.defaultPrevented) return false;
519
+ const target = event.target as Element | null;
520
+ if (!target?.closest) return false;
521
+ if (target.closest('input, textarea, select, [contenteditable="true"]')) return false;
522
+ return !target.closest('[role="listbox"], [role="menu"], [role="dialog"], [role="alertdialog"]');
523
+ }
524
+
399
525
  const DEFAULT_KEYS = ["color", "fontSize", "fontWeight", "textAlign"] as const;
400
526
 
527
+ const TAG_NAMES: Record<DefaultStyleTag, string> = {
528
+ h1: "Heading 1 (h1)",
529
+ h2: "Heading 2 (h2)",
530
+ h3: "Heading 3 (h3)",
531
+ h4: "Heading 4 (h4)",
532
+ h5: "Heading 5 (h5)",
533
+ h6: "Heading 6 (h6)",
534
+ p: "Paragraph (p)",
535
+ a: "Link (a)",
536
+ button: "Button",
537
+ };
538
+
401
539
  function DefaultsSection({
402
540
  design,
403
541
  onSave,
404
542
  }: {
405
543
  design: DesignSystem;
406
- onSave: (design: DesignSystem) => Promise<void>;
544
+ onSave: (design: DesignSystem) => Promise<boolean | void>;
407
545
  }) {
408
546
  const [tag, setTag] = React.useState<DefaultStyleTag>("p");
409
547
  const style = design.defaults?.[tag];
@@ -420,18 +558,18 @@ function DefaultsSection({
420
558
  };
421
559
  return (
422
560
  <>
423
- <p className="emvb-helper">
424
- Elements of this tag start here. A class or a local style still wins.
425
- </p>
561
+ {/* UX-058: the note belongs to Tag, so it sits under it; tags read as names. */}
426
562
  <Select
427
563
  label="Tag"
428
564
  className={FIELD}
429
565
  value={tag}
566
+ description="Elements of this tag start here. A class or a local style still wins."
567
+ renderValue={(value: unknown) => TAG_NAMES[value as DefaultStyleTag] ?? String(value)}
430
568
  onValueChange={(value) => setTag(value as DefaultStyleTag)}
431
569
  >
432
570
  {DEFAULT_STYLE_TAGS.map((item) => (
433
571
  <Select.Option key={item} value={item}>
434
- {item}
572
+ {TAG_NAMES[item]}
435
573
  </Select.Option>
436
574
  ))}
437
575
  </Select>
@@ -442,7 +580,7 @@ function DefaultsSection({
442
580
  style={style}
443
581
  design={design}
444
582
  onPatch={patch}
445
- onDesignChange={onSave}
583
+ onDesignChange={async (next) => void (await onSave(next))}
446
584
  />
447
585
  ))}
448
586
  </>
@@ -504,7 +642,7 @@ function ImportConfirm({
504
642
  style={SOLID_DESTRUCTIVE}
505
643
  onClick={onConfirm}
506
644
  >
507
- Replace
645
+ Replace site styles
508
646
  </Button>
509
647
  </div>
510
648
  </div>
@@ -526,7 +664,7 @@ function DirectionSelect({
526
664
  onSave: (next: DesignSystem) => Promise<unknown> | void;
527
665
  }) {
528
666
  return (
529
- <div data-emvb-site-direction="">
667
+ <div className="emvb-field-group" data-emvb-site-direction="">
530
668
  <Select
531
669
  label="Text direction"
532
670
  className={FIELD}