@perkyzz/emvb 0.5.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 (212) hide show
  1. package/README.md +4 -0
  2. package/THIRD_PARTY_NOTICES.md +23 -1
  3. package/licenses/exif-js.LICENSE +21 -0
  4. package/licenses/fflate.LICENSE +21 -0
  5. package/licenses/glfx.js.LICENSE +19 -0
  6. package/licenses/mini-photo-editor.LICENSE +21 -0
  7. package/licenses/photocn.LICENSE +21 -0
  8. package/package.json +2 -1
  9. package/src/admin/access/RequireEditor.tsx +7 -7
  10. package/src/admin/access/role.ts +5 -2
  11. package/src/admin/content-api.ts +10 -3
  12. package/src/admin/content-item.ts +1 -1
  13. package/src/admin/editor/A11yCopilot.tsx +104 -56
  14. package/src/admin/editor/CommandPalette.tsx +29 -13
  15. package/src/admin/editor/Editor.tsx +88 -20
  16. package/src/admin/editor/EditorToasts.tsx +26 -0
  17. package/src/admin/editor/PerfMeter.tsx +97 -72
  18. package/src/admin/editor/ShareLink.tsx +107 -72
  19. package/src/admin/editor/ShortcutsDialog.tsx +27 -16
  20. package/src/admin/editor/Timeline.tsx +255 -160
  21. package/src/admin/editor/TopBar.tsx +71 -14
  22. package/src/admin/editor/canvas/CanvasFrame.tsx +10 -1
  23. package/src/admin/editor/canvas/CanvasTextEdit.tsx +8 -2
  24. package/src/admin/editor/canvas/drop-line.ts +11 -3
  25. package/src/admin/editor/canvas/frame-focus-ring.ts +37 -0
  26. package/src/admin/editor/canvas/use-canvas-dnd.ts +32 -3
  27. package/src/admin/editor/canvas/vnode-react.tsx +7 -0
  28. package/src/admin/editor/collection-previews.ts +16 -1
  29. package/src/admin/editor/dialogs.tsx +38 -14
  30. package/src/admin/editor/dnd/drop-target.ts +26 -1
  31. package/src/admin/editor/edited-noun.ts +15 -0
  32. package/src/admin/editor/editor-chrome.tsx +108 -7
  33. package/src/admin/editor/editor-commands.ts +15 -1
  34. package/src/admin/editor/editor-css.ts +75 -22
  35. package/src/admin/editor/element-chrome.ts +21 -11
  36. package/src/admin/editor/feature-css.ts +45 -13
  37. package/src/admin/editor/icons/IconLibraryDialog.tsx +52 -11
  38. package/src/admin/editor/icons/library.ts +1 -1
  39. package/src/admin/editor/icons/use-icon-library.ts +5 -2
  40. package/src/admin/editor/ime.ts +29 -0
  41. package/src/admin/editor/palette-items.ts +10 -3
  42. package/src/admin/editor/panels/AddPanel.tsx +35 -10
  43. package/src/admin/editor/panels/ClassesSection.tsx +18 -7
  44. package/src/admin/editor/panels/ColorControl.tsx +135 -27
  45. package/src/admin/editor/panels/ConditionsEditor.tsx +52 -26
  46. package/src/admin/editor/panels/ElementPanel.tsx +134 -24
  47. package/src/admin/editor/panels/LayersPanel.tsx +68 -22
  48. package/src/admin/editor/panels/PageSettings.tsx +66 -35
  49. package/src/admin/editor/panels/SiteStylesDrawer.tsx +170 -32
  50. package/src/admin/editor/panels/TokenScales.tsx +76 -36
  51. package/src/admin/editor/panels/TriggerSettings.tsx +50 -12
  52. package/src/admin/editor/panels/TriggersEditor.tsx +2 -1
  53. package/src/admin/editor/panels/VariableSection.tsx +53 -21
  54. package/src/admin/editor/panels/color-space.ts +9 -3
  55. package/src/admin/editor/panels/settings/AdvancedFields.tsx +12 -2
  56. package/src/admin/editor/panels/settings/AudienceEditor.tsx +51 -35
  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 +38 -15
  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 +12 -8
  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/MediaPicker.tsx +274 -20
  75. package/src/admin/editor/panels/settings/MotionControl.tsx +28 -15
  76. package/src/admin/editor/panels/settings/NumberRow.tsx +9 -3
  77. package/src/admin/editor/panels/settings/PanelSelect.tsx +50 -0
  78. package/src/admin/editor/panels/settings/QueryStyleRows.tsx +25 -18
  79. package/src/admin/editor/panels/settings/RequiredFieldsNotice.tsx +141 -0
  80. package/src/admin/editor/panels/settings/StyleRow.tsx +10 -3
  81. package/src/admin/editor/panels/settings/StyleSources.tsx +4 -1
  82. package/src/admin/editor/panels/settings/VariantEditor.tsx +10 -1
  83. package/src/admin/editor/panels/settings/box-link-name.ts +6 -2
  84. package/src/admin/editor/panels/settings/class-suggest.ts +7 -7
  85. package/src/admin/editor/panels/settings/query-style.ts +38 -9
  86. package/src/admin/editor/panels/settings/svg-images.ts +13 -0
  87. package/src/admin/editor/panels/site-list.tsx +20 -6
  88. package/src/admin/editor/panels/variable-values.ts +25 -4
  89. package/src/admin/editor/restore-deleted.ts +21 -2
  90. package/src/admin/editor/section-templates.ts +81 -12
  91. package/src/admin/editor/shortcuts.ts +17 -2
  92. package/src/admin/editor/store.ts +14 -3
  93. package/src/admin/editor/useEditorCommands.ts +61 -15
  94. package/src/admin/editor/useEditorData.ts +4 -2
  95. package/src/admin/editor/useEditorShortcuts.ts +17 -7
  96. package/src/admin/editor/useNodeActions.ts +61 -6
  97. package/src/admin/editor/useSave.ts +22 -7
  98. package/src/admin/forms-api.ts +2 -0
  99. package/src/admin/image-editor/BlurFocus.tsx +112 -0
  100. package/src/admin/image-editor/Canvas.tsx +261 -0
  101. package/src/admin/image-editor/CropOverlay.tsx +390 -0
  102. package/src/admin/image-editor/CurvesPanel.tsx +395 -0
  103. package/src/admin/image-editor/ExportDialog.tsx +384 -0
  104. package/src/admin/image-editor/ImageEditButton.tsx +83 -0
  105. package/src/admin/image-editor/ImageEditorDialog.tsx +828 -0
  106. package/src/admin/image-editor/MetadataPanel.tsx +194 -0
  107. package/src/admin/image-editor/announce.tsx +65 -0
  108. package/src/admin/image-editor/crop-geometry.ts +162 -0
  109. package/src/admin/image-editor/curve-math.ts +177 -0
  110. package/src/admin/image-editor/data-url-fetch.ts +59 -0
  111. package/src/admin/image-editor/engine.ts +55 -0
  112. package/src/admin/image-editor/exif.ts +82 -0
  113. package/src/admin/image-editor/flatten.ts +54 -0
  114. package/src/admin/image-editor/gpu-fit.ts +81 -0
  115. package/src/admin/image-editor/image-editor-css.ts +400 -0
  116. package/src/admin/image-editor/load.ts +116 -0
  117. package/src/admin/image-editor/panels.tsx +287 -0
  118. package/src/admin/image-editor/parts.tsx +614 -0
  119. package/src/admin/image-editor/save.ts +141 -0
  120. package/src/admin/image-editor/tone-panels.tsx +338 -0
  121. package/src/admin/image-editor/tools.ts +59 -0
  122. package/src/admin/image-editor/worker.ts +111 -0
  123. package/src/admin/media-api.ts +114 -3
  124. package/src/admin/pages/AgentsPage.tsx +138 -27
  125. package/src/admin/pages/CreateDialog.tsx +97 -30
  126. package/src/admin/pages/NewPageDialog.tsx +21 -3
  127. package/src/admin/pages/NewThemePartDialog.tsx +11 -3
  128. package/src/admin/pages/PageList.tsx +14 -6
  129. package/src/admin/pages/SetupShell.tsx +28 -12
  130. package/src/admin/pages/ThemePartList.tsx +27 -7
  131. package/src/admin/pages/list-kit.tsx +106 -24
  132. package/src/admin/search.ts +15 -0
  133. package/src/admin/setup/useSetupStatus.ts +1 -1
  134. package/src/admin/theme-api.ts +13 -3
  135. package/src/admin/ui.ts +78 -22
  136. package/src/astro/EmVBPage.astro +11 -2
  137. package/src/astro/floats/runtime.ts +21 -0
  138. package/src/astro/menu/runtime.ts +34 -1
  139. package/src/astro/popups/runtime.ts +33 -3
  140. package/src/astro/render.ts +6 -0
  141. package/src/astro/resolve-theme.ts +67 -14
  142. package/src/astro/resolve.ts +9 -1
  143. package/src/astro/tabs/runtime.ts +12 -0
  144. package/src/astro/theme-posts.ts +2 -2
  145. package/src/astro/visitor.ts +6 -3
  146. package/src/constants.ts +1 -1
  147. package/src/core/a11y/audit.ts +171 -24
  148. package/src/core/arrange.ts +29 -6
  149. package/src/core/audience/rules.ts +5 -1
  150. package/src/core/audience/variants.ts +29 -3
  151. package/src/core/clipboard.ts +7 -0
  152. package/src/core/css/generate.ts +31 -6
  153. package/src/core/data/bindings.ts +19 -6
  154. package/src/core/design/classes.ts +20 -9
  155. package/src/core/design/diff.ts +9 -1
  156. package/src/core/design/merge.ts +93 -3
  157. package/src/core/design/tokens.ts +16 -2
  158. package/src/core/design/transfer.ts +46 -8
  159. package/src/core/design/variables.ts +32 -10
  160. package/src/core/elements/dynamic-elements.ts +53 -6
  161. package/src/core/elements/form-elements.ts +68 -30
  162. package/src/core/elements/index.ts +83 -38
  163. package/src/core/elements/menu.ts +37 -19
  164. package/src/core/elements/plain-text.ts +2 -2
  165. package/src/core/elements/select-prompt.ts +3 -0
  166. package/src/core/elements/svg-ids.ts +39 -0
  167. package/src/core/forms/binding.ts +190 -2
  168. package/src/core/forms/definition.ts +72 -0
  169. package/src/core/history/diff.ts +49 -4
  170. package/src/core/icons/catalog.ts +3 -2
  171. package/src/core/image-edit/schema.ts +155 -0
  172. package/src/core/image-edit/summary.ts +61 -0
  173. package/src/core/index.ts +29 -1
  174. package/src/core/limits.ts +21 -0
  175. package/src/core/migrate/index.ts +3 -1
  176. package/src/core/perf/meter.ts +51 -8
  177. package/src/core/recipes/index.ts +5 -4
  178. package/src/core/render/context.ts +8 -0
  179. package/src/core/render/dynamic-post.ts +71 -13
  180. package/src/core/render/extras.ts +77 -4
  181. package/src/core/render/form.ts +164 -12
  182. package/src/core/render/index.ts +179 -22
  183. package/src/core/render/loop.ts +43 -7
  184. package/src/core/render/pagination.ts +18 -4
  185. package/src/core/render/section.ts +27 -0
  186. package/src/core/render/tabs.ts +12 -3
  187. package/src/core/render/vnode.ts +1 -1
  188. package/src/core/sanitize/css.ts +15 -2
  189. package/src/core/sanitize/embed-url.ts +42 -5
  190. package/src/core/sanitize/url.ts +2 -1
  191. package/src/core/schema/layout.ts +26 -7
  192. package/src/core/share/link.ts +5 -2
  193. package/src/core/stable-json.ts +15 -0
  194. package/src/core/stats.ts +2 -1
  195. package/src/core/theme/conditions.ts +3 -1
  196. package/src/core/theme/dynamic.ts +57 -23
  197. package/src/core/theme/float.ts +9 -2
  198. package/src/core/theme/pagination.ts +57 -10
  199. package/src/core/theme/popup-markup.ts +23 -5
  200. package/src/core/theme/popup-rules.ts +11 -5
  201. package/src/core/theme/triggers.ts +3 -2
  202. package/src/core/tree-ops.ts +27 -0
  203. package/src/mcp/ports.ts +8 -1
  204. package/src/mcp/rate-limit.ts +2 -1
  205. package/src/mcp/read.ts +82 -3
  206. package/src/mcp/refs.ts +18 -0
  207. package/src/mcp/tools.ts +1 -1
  208. package/src/mcp/write.ts +271 -25
  209. package/src/server/agent-settings.ts +29 -4
  210. package/src/server/hooks.ts +5 -3
  211. package/src/server/icon-routes.ts +33 -9
  212. package/src/server/mcp-routes.ts +74 -11
@@ -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}
@@ -8,6 +8,7 @@ import {
8
8
  type DesignSystem,
9
9
  } from "../../../core/index.ts";
10
10
  import { fieldNumber } from "./settings/number-input.ts";
11
+ import { PanelSelect } from "./settings/PanelSelect.tsx";
11
12
 
12
13
  // W-436: the fields are labelled "(px)", so "18px" is 18.
13
14
  const num = (text: string): number | undefined => {
@@ -25,14 +26,22 @@ export function TokenScales({
25
26
  onSave,
26
27
  }: {
27
28
  design: DesignSystem;
28
- onSave: (design: DesignSystem) => Promise<void>;
29
+ /** Resolves false when the save failed (the drawer shows why). */
30
+ onSave: (design: DesignSystem) => Promise<boolean | void>;
29
31
  }) {
32
+ const id = React.useId();
30
33
  const [kind, setKind] = React.useState<"type" | "space">("type");
31
34
  const [base, setBase] = React.useState("18");
32
35
  const [minBase, setMinBase] = React.useState("16");
33
36
  const [fluid, setFluid] = React.useState(true);
34
37
  const [ratio, setRatio] = React.useState(String(SCALE_RATIOS[2].value));
35
38
  const [done, setDone] = React.useState<string | null>(null);
39
+ // W-609, W-626: an "added" message is about the scale as it was; any change clears it.
40
+ const edit =
41
+ (setter: (value: string) => void) => (event: React.ChangeEvent<HTMLInputElement>) => {
42
+ setter(event.currentTarget.value);
43
+ setDone(null);
44
+ };
36
45
  const input = {
37
46
  base: num(base) ?? Number.NaN,
38
47
  ...(fluid && num(minBase) !== undefined ? { minBase: num(minBase) } : {}),
@@ -46,6 +55,9 @@ export function TokenScales({
46
55
  })
47
56
  : spaceScale(input);
48
57
  const range = design.fluidRange;
58
+ const [lo, hi] = kind === "type" ? [8, 64] : [2, 64];
59
+ const minValue = num(minBase);
60
+ const minOff = fluid && !(minValue !== undefined && minValue >= lo && minValue <= hi);
49
61
  const list = kind === "type" ? "fontSizes" : "spacings";
50
62
  const updating = tokens.filter((t) =>
51
63
  (design.variables[list] ?? []).some((v) => v.id === t.id),
@@ -58,18 +70,24 @@ export function TokenScales({
58
70
  screens with CSS clamp(), no breakpoints.
59
71
  </p>
60
72
  <div className="emvb-tokens-grid">
61
- <label>
62
- <span className="emvb-bind-label">Scale</span>
63
- <select
64
- className="emvb-native-select"
73
+ <div className="emvb-tokens-field">
74
+ <span className="emvb-bind-label" id={`${id}-kind`}>
75
+ Scale
76
+ </span>
77
+ <PanelSelect
78
+ labelledBy={`${id}-kind`}
65
79
  value={kind}
66
- data-emvb-tokens-kind=""
67
- onChange={(event) => setKind(event.currentTarget.value === "space" ? "space" : "type")}
68
- >
69
- <option value="type">Type scale</option>
70
- <option value="space">Spacing scale</option>
71
- </select>
72
- </label>
80
+ data={{ "data-emvb-tokens-kind": "" }}
81
+ options={[
82
+ { value: "type", label: "Type scale" },
83
+ { value: "space", label: "Spacing scale" },
84
+ ]}
85
+ onChange={(value) => {
86
+ setKind(value === "space" ? "space" : "type");
87
+ setDone(null);
88
+ }}
89
+ />
90
+ </div>
73
91
  <label>
74
92
  <span className="emvb-bind-label">{kind === "type" ? "Body size" : "Base gap"} (px)</span>
75
93
  <input
@@ -77,47 +95,56 @@ export function TokenScales({
77
95
  inputMode="decimal"
78
96
  value={base}
79
97
  data-emvb-tokens-base=""
80
- onChange={(event) => setBase(event.currentTarget.value)}
98
+ onChange={edit(setBase)}
81
99
  />
82
100
  </label>
83
101
  {kind === "type" && (
84
- <label>
85
- <span className="emvb-bind-label">Ratio</span>
86
- <select
87
- className="emvb-native-select"
102
+ <div className="emvb-tokens-field" data-emvb-tokens-row="full">
103
+ <span className="emvb-bind-label" id={`${id}-ratio`}>
104
+ Ratio
105
+ </span>
106
+ <PanelSelect
107
+ labelledBy={`${id}-ratio`}
88
108
  value={ratio}
89
- data-emvb-tokens-ratio=""
90
- onChange={(event) => setRatio(event.currentTarget.value)}
91
- >
92
- {SCALE_RATIOS.map((r) => (
93
- <option key={r.value} value={String(r.value)}>
94
- {r.label}
95
- </option>
96
- ))}
97
- </select>
98
- </label>
109
+ data={{ "data-emvb-tokens-ratio": "" }}
110
+ options={SCALE_RATIOS.map((r) => ({ value: String(r.value), label: r.label }))}
111
+ onChange={(value) => {
112
+ setRatio(value);
113
+ setDone(null);
114
+ }}
115
+ />
116
+ </div>
99
117
  )}
100
118
  <label className="emvb-tokens-fluid">
101
119
  <input
102
120
  type="checkbox"
103
121
  checked={fluid}
104
122
  data-emvb-tokens-fluid=""
105
- onChange={(event) => setFluid(event.currentTarget.checked)}
123
+ onChange={(event) => {
124
+ setFluid(event.currentTarget.checked);
125
+ setDone(null);
126
+ }}
106
127
  />{" "}
107
128
  Fluid
108
129
  </label>
109
130
  {fluid && (
110
- <label>
131
+ <label data-emvb-tokens-row="full">
111
132
  <span className="emvb-bind-label">On small screens (px)</span>
112
133
  <input
113
134
  className="emvb-native-input"
114
135
  inputMode="decimal"
115
136
  value={minBase}
116
137
  data-emvb-tokens-min=""
117
- onChange={(event) => setMinBase(event.currentTarget.value)}
138
+ onChange={edit(setMinBase)}
139
+ aria-invalid={minOff ? true : undefined}
118
140
  />
119
141
  </label>
120
142
  )}
143
+ {minOff && (
144
+ <p className="emvb-helper" data-emvb-tokens-min-error="">
145
+ {`Use a small-screen size from ${lo} to ${hi} px. Until then the sizes aren't fluid.`}
146
+ </p>
147
+ )}
121
148
  </div>
122
149
  {tokens.length === 0 ? (
123
150
  <p className="emvb-helper" role="alert">
@@ -132,13 +159,17 @@ export function TokenScales({
132
159
  style={
133
160
  kind === "type"
134
161
  ? { fontSize: `${Math.min(t.value.value, 40)}px` }
135
- : { width: `${Math.min(t.value.value, 120)}px` }
162
+ : { width: `${Math.min(t.value.value, 64)}px` }
136
163
  }
137
164
  >
138
165
  {kind === "type" ? "Aa" : ""}
139
166
  </span>
140
167
  <span>{t.name}</span>
141
- <code className="emvb-mono">
168
+ {/* UX-032: clamp() values ellipsize; the tooltip gives the whole value. */}
169
+ <code
170
+ className="emvb-mono"
171
+ title={t.fluid ? fluidClamp(t.fluid.min, t.fluid.max, range) : `${t.value.value}px`}
172
+ >
142
173
  {t.fluid ? fluidClamp(t.fluid.min, t.fluid.max, range) : `${t.value.value}px`}
143
174
  </code>
144
175
  </li>
@@ -151,11 +182,20 @@ export function TokenScales({
151
182
  disabled={tokens.length === 0}
152
183
  data-emvb-tokens-apply=""
153
184
  onClick={() => {
154
- void onSave(applyTokens(design, list, tokens)).then(() =>
185
+ const next = applyTokens(design, list, tokens);
186
+ const label = kind === "type" ? "Font sizes" : "Spacing";
187
+ // W-609: count what landed under the list's limit, not what was generated.
188
+ const added = (next.variables[list] ?? []).length - (design.variables[list] ?? []).length;
189
+ const left = tokens.length - updating - added;
190
+ void onSave(next).then((ok) => {
191
+ if (ok === false) return;
155
192
  setDone(
156
- `${tokens.length - updating} added${updating ? `, ${updating} updated` : ""} in ${kind === "type" ? "Font sizes" : "Spacing"}.`,
157
- ),
158
- );
193
+ `${added} added${updating ? `, ${updating} updated` : ""} in ${label}.` +
194
+ (left > 0
195
+ ? ` ${left} didn't fit: ${label} holds up to ${list === "fontSizes" ? 50 : 100}.`
196
+ : ""),
197
+ );
198
+ });
159
199
  }}
160
200
  >
161
201
  {updating > 0 ? "Update the scale in site styles" : "Add the scale to site styles"}
@@ -1,7 +1,14 @@
1
1
  import { Input } from "@cloudflare/kumo";
2
2
  import * as React from "react";
3
- import { clampScrollPercent, type PopupOpenTrigger, TRIGGER_LIMITS } from "../../../core/index.ts";
3
+ import {
4
+ clampScrollPercent,
5
+ isSafeClickSelector,
6
+ type PopupOpenTrigger,
7
+ TRIGGER_LIMITS,
8
+ } from "../../../core/index.ts";
4
9
  import { FIELD } from "../../ui.ts";
10
+ import { isCommitEnter } from "../ime.ts";
11
+ import { InlineError } from "./inline-error.tsx";
5
12
 
6
13
  const clamp = (n: number, min: number, max: number) => Math.min(max, Math.max(min, n));
7
14
 
@@ -28,7 +35,8 @@ function NumberField({
28
35
  }) {
29
36
  const [draft, setDraft] = React.useState(String(value));
30
37
  const commit = () => {
31
- const next = normalize(draft);
38
+ // The popup schema stores whole numbers only, so 1500.6 ms commits as 1501 (W-607).
39
+ const next = Math.round(normalize(draft));
32
40
  setDraft(String(next));
33
41
  if (next !== value) onCommit(next);
34
42
  };
@@ -44,14 +52,34 @@ function NumberField({
44
52
  onChange={(event) => setDraft(event.target.value)}
45
53
  onBlur={commit}
46
54
  onKeyDown={(event) => {
47
- if (event.key === "Enter") commit();
55
+ if (isCommitEnter(event)) commit();
48
56
  }}
49
57
  />
50
58
  );
51
59
  }
52
60
 
61
+ /**
62
+ * W-613: why a click selector can't be saved (or never matches), shown under the field instead
63
+ * of failing the popup's save.
64
+ */
65
+ function selectorError(selector: string): string | null {
66
+ if (!selector.trim()) return "Enter a CSS selector, such as .open-popup.";
67
+ if (!isSafeClickSelector(selector)) {
68
+ return "Use a simple CSS selector: letters, numbers, spaces and . # [ ] = : ( ) > + ~ * , \" ' | / - _";
69
+ }
70
+ try {
71
+ document.createDocumentFragment().querySelector(selector);
72
+ } catch {
73
+ return "This isn't a valid CSS selector, so no click would open the popup.";
74
+ }
75
+ return null;
76
+ }
77
+
78
+ // W-776: under a second the time reads in ms; 30 ms read "0 s after the page loads".
53
79
  const seconds = (ms: number) =>
54
- `${(ms / 1000).toLocaleString("en", { maximumFractionDigits: 1 })} s`;
80
+ ms > 0 && ms < 1000
81
+ ? `${ms} ms`
82
+ : `${(ms / 1000).toLocaleString("en", { maximumFractionDigits: 1 })} s`;
55
83
 
56
84
  /** The per-type settings row inside a popup trigger (S7b / W-081). */
57
85
  export function TriggerSettings({
@@ -90,15 +118,25 @@ export function TriggerSettings({
90
118
  );
91
119
  }
92
120
  if (trigger.type === "click") {
121
+ const error = selectorError(trigger.selector);
93
122
  return (
94
- <Input
95
- label="CSS selector"
96
- className={`${FIELD} emvb-mono`}
97
- value={trigger.selector}
98
- placeholder=".open-popup"
99
- description="Clicking any element that matches opens the popup."
100
- onChange={(event) => onChange({ type: "click", selector: event.target.value })}
101
- />
123
+ <>
124
+ <Input
125
+ label="CSS selector"
126
+ className={`${FIELD} emvb-mono`}
127
+ value={trigger.selector}
128
+ placeholder=".open-popup"
129
+ maxLength={TRIGGER_LIMITS.maxClickSelectorLength}
130
+ aria-invalid={error ? true : undefined}
131
+ description="Clicking any element that matches opens the popup."
132
+ onChange={(event) => onChange({ type: "click", selector: event.target.value })}
133
+ />
134
+ {error && (
135
+ <div data-emvb-trigger-selector-error="">
136
+ <InlineError>{error}</InlineError>
137
+ </div>
138
+ )}
139
+ </>
102
140
  );
103
141
  }
104
142
  if (trigger.type === "exit_intent") {