@perkyzz/emvb 0.6.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (208) hide show
  1. package/README.md +2 -2
  2. package/THIRD_PARTY_NOTICES.md +1 -1
  3. package/package.json +7 -7
  4. package/src/admin/access/RequireEditor.tsx +7 -7
  5. package/src/admin/access/role.ts +5 -2
  6. package/src/admin/content-api.ts +10 -3
  7. package/src/admin/content-item.ts +1 -1
  8. package/src/admin/editor/A11yCopilot.tsx +104 -56
  9. package/src/admin/editor/CommandPalette.tsx +29 -13
  10. package/src/admin/editor/DialogCloseButton.tsx +16 -0
  11. package/src/admin/editor/Editor.tsx +115 -20
  12. package/src/admin/editor/EditorToasts.tsx +26 -0
  13. package/src/admin/editor/PerfMeter.tsx +92 -73
  14. package/src/admin/editor/SavedSectionDialogs.tsx +169 -0
  15. package/src/admin/editor/ShareLink.tsx +102 -72
  16. package/src/admin/editor/ShortcutsDialog.tsx +37 -18
  17. package/src/admin/editor/Timeline.tsx +250 -160
  18. package/src/admin/editor/TopBar.tsx +71 -14
  19. package/src/admin/editor/canvas/CanvasFrame.tsx +10 -1
  20. package/src/admin/editor/canvas/CanvasTextEdit.tsx +8 -2
  21. package/src/admin/editor/canvas/drop-line.ts +11 -3
  22. package/src/admin/editor/canvas/frame-focus-ring.ts +37 -0
  23. package/src/admin/editor/canvas/use-canvas-dnd.ts +32 -3
  24. package/src/admin/editor/canvas/vnode-react.tsx +7 -0
  25. package/src/admin/editor/collection-previews.ts +10 -0
  26. package/src/admin/editor/dialogs.tsx +41 -28
  27. package/src/admin/editor/dnd/drop-target.ts +26 -1
  28. package/src/admin/editor/edited-noun.ts +15 -0
  29. package/src/admin/editor/editor-chrome.tsx +43 -7
  30. package/src/admin/editor/editor-commands.ts +17 -2
  31. package/src/admin/editor/editor-css.ts +75 -24
  32. package/src/admin/editor/element-chrome.ts +21 -11
  33. package/src/admin/editor/feature-css.ts +56 -14
  34. package/src/admin/editor/focus-when-lost.ts +23 -0
  35. package/src/admin/editor/icons/IconLibraryDialog.tsx +54 -18
  36. package/src/admin/editor/icons/library.ts +1 -1
  37. package/src/admin/editor/icons/use-icon-library.ts +5 -2
  38. package/src/admin/editor/ime.ts +29 -0
  39. package/src/admin/editor/palette-items.ts +27 -3
  40. package/src/admin/editor/panels/AddPanel.tsx +44 -11
  41. package/src/admin/editor/panels/ClassesSection.tsx +18 -7
  42. package/src/admin/editor/panels/ColorControl.tsx +130 -23
  43. package/src/admin/editor/panels/ConditionsEditor.tsx +52 -26
  44. package/src/admin/editor/panels/ElementPanel.tsx +134 -24
  45. package/src/admin/editor/panels/LayersPanel.tsx +61 -20
  46. package/src/admin/editor/panels/LeftPanel.tsx +9 -1
  47. package/src/admin/editor/panels/PageSettings.tsx +66 -35
  48. package/src/admin/editor/panels/SavedSectionsGroup.tsx +246 -0
  49. package/src/admin/editor/panels/SiteStylesDrawer.tsx +224 -42
  50. package/src/admin/editor/panels/TokenScales.tsx +88 -48
  51. package/src/admin/editor/panels/TriggerSettings.tsx +50 -12
  52. package/src/admin/editor/panels/TriggersEditor.tsx +3 -2
  53. package/src/admin/editor/panels/VariableSection.tsx +48 -18
  54. package/src/admin/editor/panels/color-space.ts +23 -29
  55. package/src/admin/editor/panels/settings/AdvancedFields.tsx +12 -2
  56. package/src/admin/editor/panels/settings/AudienceEditor.tsx +87 -74
  57. package/src/admin/editor/panels/settings/BackgroundControls.tsx +55 -11
  58. package/src/admin/editor/panels/settings/BackgroundFill.tsx +3 -2
  59. package/src/admin/editor/panels/settings/BindingsEditor.tsx +15 -18
  60. package/src/admin/editor/panels/settings/BoxControl.tsx +2 -1
  61. package/src/admin/editor/panels/settings/ClassChip.tsx +21 -9
  62. package/src/admin/editor/panels/settings/ClassChipInput.tsx +24 -16
  63. package/src/admin/editor/panels/settings/DraftTextField.tsx +41 -3
  64. package/src/admin/editor/panels/settings/EffectsControls.tsx +38 -14
  65. package/src/admin/editor/panels/settings/FieldBindControl.tsx +46 -28
  66. package/src/admin/editor/panels/settings/FieldControl.tsx +20 -8
  67. package/src/admin/editor/panels/settings/FormBindControl.tsx +2 -2
  68. package/src/admin/editor/panels/settings/HintedSwitch.tsx +33 -0
  69. package/src/admin/editor/panels/settings/IconControls.tsx +33 -13
  70. package/src/admin/editor/panels/settings/IconPicker.tsx +2 -0
  71. package/src/admin/editor/panels/settings/ImageSourcesField.tsx +3 -1
  72. package/src/admin/editor/panels/settings/ItemList.tsx +15 -2
  73. package/src/admin/editor/panels/settings/LengthRow.tsx +8 -6
  74. package/src/admin/editor/panels/settings/LoopItemBindControl.tsx +1 -1
  75. package/src/admin/editor/panels/settings/MediaPicker.tsx +127 -23
  76. package/src/admin/editor/panels/settings/MotionControl.tsx +28 -15
  77. package/src/admin/editor/panels/settings/NumberRow.tsx +9 -3
  78. package/src/admin/editor/panels/settings/PanelSelect.tsx +50 -0
  79. package/src/admin/editor/panels/settings/QueryStyleRows.tsx +25 -18
  80. package/src/admin/editor/panels/settings/RequiredFieldsNotice.tsx +66 -1
  81. package/src/admin/editor/panels/settings/StyleRow.tsx +10 -3
  82. package/src/admin/editor/panels/settings/StyleSources.tsx +4 -1
  83. package/src/admin/editor/panels/settings/VariantEditor.tsx +10 -1
  84. package/src/admin/editor/panels/settings/box-link-name.ts +6 -2
  85. package/src/admin/editor/panels/settings/class-suggest.ts +7 -7
  86. package/src/admin/editor/panels/settings/query-style.ts +38 -9
  87. package/src/admin/editor/panels/settings/svg-images.ts +13 -0
  88. package/src/admin/editor/panels/site-list.tsx +20 -6
  89. package/src/admin/editor/panels/variable-values.ts +11 -4
  90. package/src/admin/editor/restore-deleted.ts +21 -2
  91. package/src/admin/editor/section-templates.ts +81 -12
  92. package/src/admin/editor/shortcuts.ts +31 -2
  93. package/src/admin/editor/store.ts +7 -0
  94. package/src/admin/editor/useEditorCommands.ts +61 -15
  95. package/src/admin/editor/useEditorData.ts +4 -2
  96. package/src/admin/editor/useEditorShortcuts.ts +17 -7
  97. package/src/admin/editor/useNodeActions.ts +61 -6
  98. package/src/admin/editor/useSave.ts +22 -7
  99. package/src/admin/editor/useSavedSections.ts +197 -0
  100. package/src/admin/forms-api.ts +2 -0
  101. package/src/admin/image-editor/Canvas.tsx +61 -17
  102. package/src/admin/image-editor/CurvesPanel.tsx +2 -1
  103. package/src/admin/image-editor/ExportDialog.tsx +48 -18
  104. package/src/admin/image-editor/ImageEditorDialog.tsx +179 -8
  105. package/src/admin/image-editor/MetadataPanel.tsx +15 -4
  106. package/src/admin/image-editor/crop-geometry.ts +3 -2
  107. package/src/admin/image-editor/image-editor-css.ts +15 -10
  108. package/src/admin/image-editor/load.ts +9 -2
  109. package/src/admin/image-editor/parts.tsx +69 -19
  110. package/src/admin/image-editor/save.ts +54 -8
  111. package/src/admin/media-api.ts +2 -1
  112. package/src/admin/pages/AgentsPage.tsx +138 -27
  113. package/src/admin/pages/CreateDialog.tsx +97 -30
  114. package/src/admin/pages/NewPageDialog.tsx +21 -3
  115. package/src/admin/pages/NewThemePartDialog.tsx +11 -3
  116. package/src/admin/pages/PageList.tsx +14 -6
  117. package/src/admin/pages/SetupShell.tsx +28 -12
  118. package/src/admin/pages/ThemePartList.tsx +59 -11
  119. package/src/admin/pages/list-kit.tsx +106 -24
  120. package/src/admin/saved-sections-api.ts +51 -0
  121. package/src/admin/search.ts +15 -0
  122. package/src/admin/setup/useSetupStatus.ts +1 -1
  123. package/src/admin/theme-api.ts +16 -5
  124. package/src/admin/ui.ts +82 -22
  125. package/src/astro/floats/runtime.ts +21 -0
  126. package/src/astro/menu/runtime.ts +34 -1
  127. package/src/astro/popups/runtime.ts +41 -9
  128. package/src/astro/render.ts +3 -0
  129. package/src/astro/resolve-theme.ts +53 -11
  130. package/src/astro/resolve.ts +9 -1
  131. package/src/astro/tabs/runtime.ts +12 -0
  132. package/src/astro/theme-posts.ts +2 -2
  133. package/src/astro/visitor.ts +2 -0
  134. package/src/constants.ts +1 -1
  135. package/src/core/a11y/audit.ts +196 -24
  136. package/src/core/arrange.ts +48 -12
  137. package/src/core/audience/rules.ts +5 -1
  138. package/src/core/audience/variants.ts +29 -3
  139. package/src/core/clipboard.ts +7 -0
  140. package/src/core/css/generate.ts +31 -6
  141. package/src/core/css/print.ts +5 -0
  142. package/src/core/data/bindings.ts +8 -1
  143. package/src/core/design/classes.ts +39 -16
  144. package/src/core/design/devices.ts +7 -13
  145. package/src/core/design/diff.ts +6 -0
  146. package/src/core/design/merge.ts +90 -2
  147. package/src/core/design/states.ts +7 -13
  148. package/src/core/design/tokens.ts +16 -2
  149. package/src/core/design/transfer.ts +33 -6
  150. package/src/core/design/variables.ts +30 -9
  151. package/src/core/elements/dynamic-elements.ts +53 -14
  152. package/src/core/elements/form-elements.ts +55 -16
  153. package/src/core/elements/index.ts +84 -39
  154. package/src/core/elements/menu.ts +40 -19
  155. package/src/core/elements/select-prompt.ts +3 -0
  156. package/src/core/elements/svg-ids.ts +39 -0
  157. package/src/core/forms/binding.ts +57 -16
  158. package/src/core/forms/definition.ts +72 -0
  159. package/src/core/history/diff.ts +18 -1
  160. package/src/core/icons/animation-runs.ts +11 -0
  161. package/src/core/icons/catalog.ts +3 -2
  162. package/src/core/image-edit/schema.ts +11 -1
  163. package/src/core/image-edit/summary.ts +6 -3
  164. package/src/core/index.ts +35 -1
  165. package/src/core/limits.ts +12 -1
  166. package/src/core/migrate/index.ts +3 -0
  167. package/src/core/perf/meter.ts +42 -7
  168. package/src/core/recipes/index.ts +5 -4
  169. package/src/core/render/context.ts +8 -0
  170. package/src/core/render/dynamic-post.ts +69 -12
  171. package/src/core/render/extras.ts +77 -4
  172. package/src/core/render/form.ts +140 -6
  173. package/src/core/render/index.ts +156 -20
  174. package/src/core/render/loop.ts +44 -8
  175. package/src/core/render/pagination.ts +18 -4
  176. package/src/core/render/section.ts +27 -0
  177. package/src/core/render/tabs.ts +12 -3
  178. package/src/core/render/vnode.ts +1 -1
  179. package/src/core/sanitize/css.ts +29 -8
  180. package/src/core/sanitize/embed-url.ts +42 -5
  181. package/src/core/sanitize/url.ts +2 -1
  182. package/src/core/saved-sections.ts +318 -0
  183. package/src/core/schema/design.ts +1 -1
  184. package/src/core/schema/layout.ts +16 -7
  185. package/src/core/schema/style.ts +4 -2
  186. package/src/core/stats.ts +2 -1
  187. package/src/core/theme/conditions.ts +3 -1
  188. package/src/core/theme/dynamic.ts +36 -5
  189. package/src/core/theme/float.ts +12 -2
  190. package/src/core/theme/pagination.ts +50 -29
  191. package/src/core/theme/part-types.ts +4 -4
  192. package/src/core/theme/popup-markup.ts +23 -5
  193. package/src/core/theme/popup-rules.ts +1 -0
  194. package/src/core/theme/triggers.ts +3 -2
  195. package/src/core/tree-ops.ts +27 -0
  196. package/src/mcp/ports.ts +22 -1
  197. package/src/mcp/rate-limit.ts +2 -1
  198. package/src/mcp/read.ts +15 -3
  199. package/src/mcp/refs.ts +18 -0
  200. package/src/mcp/sections.ts +183 -0
  201. package/src/mcp/tools.ts +44 -0
  202. package/src/mcp/write.ts +178 -14
  203. package/src/server/agent-settings.ts +1 -1
  204. package/src/server/hooks.ts +5 -3
  205. package/src/server/icon-routes.ts +30 -9
  206. package/src/server/mcp-routes.ts +8 -1
  207. package/src/server/plugin.ts +14 -0
  208. package/src/server/saved-sections.ts +163 -0
@@ -1,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,
@@ -43,6 +50,8 @@ type LayerActions = {
43
50
  clipboard?: ClipboardActions;
44
51
  /** Sets or clears a node's editor-only name (W-157); without it rows can't be renamed. */
45
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;
46
55
  };
47
56
 
48
57
  type MenuItem = {
@@ -89,6 +98,7 @@ function menuItems(
89
98
  runners: {
90
99
  rename: actions.onRename ? rename : undefined,
91
100
  duplicate: actions.onDuplicate,
101
+ saveSection: actions.onSaveSection,
92
102
  remove: actions.onDelete,
93
103
  moveUp: actions.onMoveUp,
94
104
  moveDown: actions.onMoveDown,
@@ -202,6 +212,7 @@ export function LayersPanel({
202
212
  const live = React.useRef(actions);
203
213
  live.current = actions;
204
214
  const canRename = !!actions.onRename;
215
+ const canSaveSection = !!actions.onSaveSection;
205
216
  const rowActions = React.useMemo<LayerActions>(
206
217
  () => ({
207
218
  onSelect: (id) => live.current.onSelect(id),
@@ -210,8 +221,9 @@ export function LayersPanel({
210
221
  onMoveDown: (id) => live.current.onMoveDown(id),
211
222
  onDelete: (id) => live.current.onDelete(id),
212
223
  onRename: canRename ? (id, label) => live.current.onRename?.(id, label) : undefined,
224
+ onSaveSection: canSaveSection ? (id) => live.current.onSaveSection?.(id) : undefined,
213
225
  }),
214
- [canRename],
226
+ [canRename, canSaveSection],
215
227
  );
216
228
  const onRowMenu = React.useCallback(
217
229
  (id: string, open: boolean) => setMenuId(open ? id : null),
@@ -219,6 +231,28 @@ export function LayersPanel({
219
231
  );
220
232
  const toggle = React.useMemo(() => toggleIn(setCollapsed), []);
221
233
 
234
+ // W-612: an open row menu closes when a press lands outside it, focus leaves the panel's
235
+ // window (a click in the canvas frame), or focus moves out of it (Tab).
236
+ React.useEffect(() => {
237
+ if (!menuId) return;
238
+ const close = () => setMenuId(null);
239
+ const onPress = (event: Event) => {
240
+ if (!inRowMenu(event.target)) close();
241
+ };
242
+ const onFocusOut = (event: FocusEvent) => {
243
+ const to = event.relatedTarget;
244
+ if (inRowMenu(event.target) && to instanceof Element && !inRowMenu(to)) close();
245
+ };
246
+ document.addEventListener("pointerdown", onPress, true);
247
+ document.addEventListener("focusout", onFocusOut);
248
+ window.addEventListener("blur", close);
249
+ return () => {
250
+ document.removeEventListener("pointerdown", onPress, true);
251
+ document.removeEventListener("focusout", onFocusOut);
252
+ window.removeEventListener("blur", close);
253
+ };
254
+ }, [menuId]);
255
+
222
256
  React.useEffect(() => {
223
257
  if (!layout || !selectedId) return;
224
258
  setCollapsed((current) => {
@@ -412,7 +446,7 @@ const LayerRow = React.memo(function LayerRow({
412
446
  <div
413
447
  className="emvb-layer-row"
414
448
  data-emvb-layer={node.id}
415
- style={{ paddingLeft: 8 + depth * 12 }}
449
+ style={{ paddingLeft: layerIndent(depth) }}
416
450
  onClick={() => actions.onSelect(node.id)}
417
451
  >
418
452
  {hasChildren ? (
@@ -510,28 +544,33 @@ const LayerRow = React.memo(function LayerRow({
510
544
  }}
511
545
  onKeyDown={menuKeys}
512
546
  >
513
- ···
547
+ <DotsThreeIcon size={16} weight="bold" aria-hidden="true" />
514
548
  </button>
515
549
  {menuOpen && (
516
550
  <div ref={menuList} className="emvb-layer-menu-list" role="menu" onKeyDown={menuKeys}>
517
551
  {menuItems(node, isRoot, actions, clip, startRename).map(
518
552
  ({ 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>
553
+ <React.Fragment key={label}>
554
+ {/* UX-026: Delete sits apart from the other actions, as in Site styles. */}
555
+ {label === "Delete" && (
556
+ <hr className="emvb-layer-menu-sep" aria-hidden="true" />
557
+ )}
558
+ <button
559
+ type="button"
560
+ role="menuitem"
561
+ className={className}
562
+ disabled={disabled}
563
+ onClick={(event) => {
564
+ event.stopPropagation();
565
+ const tree = event.currentTarget.closest('[role="tree"]');
566
+ onMenu(false);
567
+ run(node.id);
568
+ window.setTimeout(() => focusSelectedRow(tree), 0);
569
+ }}
570
+ >
571
+ {label}
572
+ </button>
573
+ </React.Fragment>
535
574
  ),
536
575
  )}
537
576
  {pasteHint(clip) && (
@@ -584,6 +623,8 @@ function RenameInput({
584
623
  onBlur={() => finish(text)}
585
624
  onKeyDown={(event) => {
586
625
  event.stopPropagation();
626
+ // Enter or Escape that ends an IME composition only finishes the word (W-606).
627
+ if (event.nativeEvent.isComposing || event.keyCode === 229) return;
587
628
  if (event.key === "Enter") finish(text, true);
588
629
  if (event.key === "Escape") finish(null, true);
589
630
  }}
@@ -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>
@@ -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
  }
@@ -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
+ }