@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
@@ -0,0 +1,141 @@
1
+ import { Banner } from "@cloudflare/kumo";
2
+ import { WarningIcon } from "@phosphor-icons/react";
3
+ import * as React from "react";
4
+ import type { Fetcher } from "../../../api.ts";
5
+ import { loadFormFields, type DefinitionField } from "../../../forms-api.ts";
6
+ import {
7
+ impossibleRangeFields,
8
+ mismatchedControls,
9
+ requiredFieldIssues,
10
+ requiredFieldIssueText,
11
+ type LayoutNode,
12
+ type RequiredFieldIssue,
13
+ } from "../../../../core/index.ts";
14
+
15
+ /** The panel's short line for one issue; the full sentence is its tooltip and the MCP text. */
16
+ function shortReason(issue: RequiredFieldIssue): string {
17
+ if (issue.kind === "missing") return `has no field on this form (${issue.field}).`;
18
+ if (issue.kind === "hidden") {
19
+ return issue.devices.length === 3
20
+ ? "is hidden on every device."
21
+ : `is hidden on ${issue.devices.join(" and ")}.`;
22
+ }
23
+ return `is shown only to some visitors: ${issue.who}.`;
24
+ }
25
+
26
+ /**
27
+ * W-511: on a Form, the required fields visitors can't fill: missing from the form, or hidden on
28
+ * a device. Either way the form can't be sent there, and the visitor sees no reason why.
29
+ */
30
+ export function RequiredFieldsNotice({ node, fetcher }: { node: LayoutNode; fetcher: Fetcher }) {
31
+ const formId = String((node.props as { formId?: unknown }).formId ?? "").trim();
32
+ const [fields, setFields] = React.useState<DefinitionField[] | null>(null);
33
+ React.useEffect(() => {
34
+ let cancelled = false;
35
+ setFields(null);
36
+ if (!formId) return undefined;
37
+ void loadFormFields(fetcher, formId).then((next) => {
38
+ if (!cancelled) setFields(next);
39
+ });
40
+ return () => {
41
+ cancelled = true;
42
+ };
43
+ }, [fetcher, formId]);
44
+ const issues = fields ? requiredFieldIssues(node, fields) : [];
45
+ const ranges = fields ? impossibleRangeFields(fields) : [];
46
+ const kinds = fields ? mismatchedControls(node, fields) : [];
47
+ if (issues.length === 0 && ranges.length === 0 && kinds.length === 0) return null;
48
+ // W-579: a free-text or checkbox control on a field with a list of options sends a value the
49
+ // forms plugin refuses, so the form fails with "has an invalid selection".
50
+ const kindBanner =
51
+ kinds.length > 0 ? (
52
+ <Banner
53
+ variant="alert"
54
+ icon={<WarningIcon aria-hidden="true" />}
55
+ title={
56
+ kinds.length === 1
57
+ ? "A field needs a choice element"
58
+ : `${kinds.length} fields need a choice element`
59
+ }
60
+ description={
61
+ <ul className="emvb-required-notice__list">
62
+ {kinds.map((kind) => (
63
+ <li key={kind.nodeId} data-emvb-kind-issue={kind.fieldType}>
64
+ <strong>{kind.label}</strong> only accepts one of its options in Forms, so typed or
65
+ ticked answers are refused. Use a Select or Radio element for it.
66
+ </li>
67
+ ))}
68
+ </ul>
69
+ }
70
+ />
71
+ ) : null;
72
+ const rangeBanner =
73
+ ranges.length > 0 ? (
74
+ <Banner
75
+ variant="alert"
76
+ icon={<WarningIcon aria-hidden="true" />}
77
+ title={
78
+ ranges.length === 1
79
+ ? "A field's limits can't be met"
80
+ : `${ranges.length} fields' limits can't be met`
81
+ }
82
+ description={
83
+ <ul className="emvb-required-notice__list">
84
+ {ranges.map((range) => (
85
+ <li key={range.name} data-emvb-range-issue={range.kind}>
86
+ <strong>{range.label}</strong>{" "}
87
+ {range.kind === "length"
88
+ ? "has a minimum length above its maximum length"
89
+ : range.kind === "both"
90
+ ? "has a minimum length above its maximum length and a minimum value above its maximum"
91
+ : "has a minimum value above its maximum"}
92
+ , so no answer is accepted. Fix the limits in Forms.
93
+ </li>
94
+ ))}
95
+ </ul>
96
+ }
97
+ />
98
+ ) : null;
99
+ if (issues.length === 0) {
100
+ return (
101
+ <div className="emvb-required-notice" data-emvb-range-fields="">
102
+ {kindBanner}
103
+ {rangeBanner}
104
+ </div>
105
+ );
106
+ }
107
+ const title =
108
+ issues.length === 1
109
+ ? "A required field can't be filled in"
110
+ : `${issues.length} required fields can't be filled in`;
111
+ return (
112
+ <div className="emvb-required-notice" data-emvb-required-fields="">
113
+ {kindBanner}
114
+ {rangeBanner}
115
+ <Banner
116
+ variant="alert"
117
+ icon={<WarningIcon aria-hidden="true" />}
118
+ title={title}
119
+ description={
120
+ <>
121
+ <ul className="emvb-required-notice__list">
122
+ {issues.map((issue) => (
123
+ <li
124
+ key={`${issue.kind}:${issue.field}`}
125
+ data-emvb-required-issue={issue.kind}
126
+ title={requiredFieldIssueText(issue)}
127
+ >
128
+ <strong>{issue.label}</strong> {shortReason(issue)}
129
+ </li>
130
+ ))}
131
+ </ul>
132
+ <span className="emvb-required-notice__hint">
133
+ Visitors who can't fill a required field can't send the form. Show the field to
134
+ everyone, or make it optional in Forms.
135
+ </span>
136
+ </>
137
+ }
138
+ />
139
+ </div>
140
+ );
141
+ }
@@ -167,6 +167,9 @@ const SELECT_OPTIONS: Partial<Record<StyleKey, { value: string; label: string }[
167
167
  ],
168
168
  };
169
169
 
170
+ /** The value of a select row with nothing set; never saved. */
171
+ const UNSET = "__unset";
172
+
170
173
  const isLengthLiteral = (value: unknown): value is { value: number; unit: string } =>
171
174
  typeof value === "object" && value !== null && "value" in value && "unit" in value;
172
175
 
@@ -321,7 +324,8 @@ export function StyleRow({
321
324
  const current =
322
325
  styleKey === "fontWeight" && typeof shown === "number"
323
326
  ? String(shown)
324
- : ((shown as string | undefined) ?? options[0]?.value ?? "");
327
+ : // UX-048: nothing set reads "Default", like the colour field, not the first option.
328
+ ((shown as string | undefined) ?? UNSET);
325
329
  return (
326
330
  <div
327
331
  className="emvb-style-row"
@@ -334,6 +338,7 @@ export function StyleRow({
334
338
  className={FIELD}
335
339
  value={current}
336
340
  onValueChange={(next) => {
341
+ if (next === UNSET) return;
337
342
  if (styleKey === "fontWeight") {
338
343
  const n = Number(next);
339
344
  onPatch({
@@ -343,10 +348,12 @@ export function StyleRow({
343
348
  });
344
349
  return;
345
350
  }
346
- onPatch({ [styleKey]: next === options[0]?.value && !set ? next : next });
351
+ onPatch({ [styleKey]: next });
347
352
  }}
348
353
  renderValue={(v: unknown) =>
349
- options.find((o) => o.value === String(v))?.label ?? String(v)
354
+ v === UNSET
355
+ ? "Default"
356
+ : (options.find((o) => o.value === String(v))?.label ?? String(v))
350
357
  }
351
358
  >
352
359
  {options.map((option) => (
@@ -1,3 +1,4 @@
1
+ import { CaretRightIcon } from "@phosphor-icons/react";
1
2
  import {
2
3
  traceStyle,
3
4
  type DesignSystem,
@@ -57,11 +58,13 @@ export function StyleSources({
57
58
  return (
58
59
  <details className="emvb-sources" data-emvb-style-sources="">
59
60
  <summary>
60
- Where styles come from
61
+ <span className="emvb-sources-label">Where styles come from</span>
61
62
  <span className="emvb-sources-count">
62
63
  {keys.length === 0
63
64
  ? "nothing set"
64
65
  : `${keys.length} set${fromElsewhere > 0 ? `, ${fromElsewhere} inherited` : ""}`}
66
+ {/* UX-037: the flex summary drops the native marker, so draw the section caret. */}
67
+ <CaretRightIcon size={16} aria-hidden="true" className="emvb-sources-caret" />
65
68
  </span>
66
69
  </summary>
67
70
  {keys.length === 0 ? (
@@ -16,11 +16,14 @@ const NO_VARIANT = new Set(["tab-panel", "accordion-item", "loop-empty", "option
16
16
  export function VariantEditor({
17
17
  node,
18
18
  isRoot,
19
+ lone = false,
19
20
  onChange,
20
21
  onArrange,
21
22
  }: {
22
23
  node: LayoutNode;
23
24
  isRoot: boolean;
25
+ /** W-627: the test's other arm is gone, so this one shows to every visitor. */
26
+ lone?: boolean;
24
27
  onChange: (node: LayoutNode) => void;
25
28
  onArrange?: (run: (layout: Layout) => Arranged) => void;
26
29
  }) {
@@ -50,7 +53,13 @@ export function VariantEditor({
50
53
  Variant {v.arm.toUpperCase()} of test <b>{v.test}</b>. The canvas shows every variant;
51
54
  visitors see one.
52
55
  </p>
53
- {v.arm === "b" && (
56
+ {lone && (
57
+ <p className="emvb-helper" data-emvb-variant-lone="">
58
+ Variant {v.arm === "a" ? "B" : "A"} was removed, so every visitor sees this one. End
59
+ the test to tidy it up.
60
+ </p>
61
+ )}
62
+ {v.arm === "b" && !lone && (
54
63
  <label className="emvb-bind-row">
55
64
  <span className="emvb-bind-label">Visitors who see B (%)</span>
56
65
  <input
@@ -1,4 +1,4 @@
1
- import { sanitizeHref, type LayoutNode } from "../../../../core/index.ts";
1
+ import { boxLinkHeldBack, sanitizeHref, type LayoutNode } from "../../../../core/index.ts";
2
2
  import { nodeChildren } from "../../../../core/tree-ops.ts";
3
3
 
4
4
  /** Props whose text names a link for screen readers when the element sits inside it. */
@@ -30,9 +30,13 @@ const hasName = (node: LayoutNode): boolean => {
30
30
  export function unnamedBoxLink(node: LayoutNode): boolean {
31
31
  const href = (node.props as { href?: unknown } | undefined)?.href;
32
32
  if (typeof href !== "string" || !href.trim() || !sanitizeHref(href)) return false;
33
- if (!("children" in node)) return false;
33
+ if (!("children" in node) || boxLinkHeldBack(node)) return false;
34
34
  return !hasName(node);
35
35
  }
36
36
 
37
37
  export const UNNAMED_BOX_LINK_NOTE =
38
38
  "Nothing inside this box has text, so screen readers announce it only as “link”. Add text inside it, or an aria-label under Custom attributes.";
39
+
40
+ /** W-669: why a box's Link isn't on the page. */
41
+ export const HELD_BACK_BOX_LINK_NOTE =
42
+ "This box's Link isn't used: something inside it is already a link, button, menu, form field, accordion or video, and links can't hold those. Put the Link on an element inside instead.";
@@ -1,4 +1,4 @@
1
- import { cleanClassName, type DesignSystem } from "../../../../core/index.ts";
1
+ import { cleanClassName, nameKey, type DesignSystem } from "../../../../core/index.ts";
2
2
 
3
3
  type StyleClass = NonNullable<DesignSystem["classes"]>[number];
4
4
 
@@ -9,7 +9,7 @@ export const MAX_SITE_CLASSES = 100;
9
9
  export const MAX_ELEMENT_CLASSES = 20;
10
10
 
11
11
  const rank = (cls: StyleClass, q: string) => {
12
- const name = cls.name.toLowerCase();
12
+ const name = nameKey(cls.name);
13
13
  if (name === q) return 0;
14
14
  if (name.startsWith(q) || cls.id.startsWith(q)) return 1;
15
15
  return 2;
@@ -25,11 +25,11 @@ export function classOptions(
25
25
  applied: readonly string[],
26
26
  query: string,
27
27
  ): ClassOption[] {
28
- const q = query.trim().toLowerCase();
28
+ const q = nameKey(query);
29
29
  const available = catalog.filter((cls) => !applied.includes(cls.id));
30
30
  const found = q
31
31
  ? available
32
- .filter((cls) => cls.name.toLowerCase().includes(q) || cls.id.includes(q))
32
+ .filter((cls) => nameKey(cls.name).includes(q) || cls.id.includes(q))
33
33
  .map((cls, index) => ({ cls, index, rank: rank(cls, q) }))
34
34
  .toSorted((a, b) => a.rank - b.rank || a.index - b.index)
35
35
  .map(({ cls }) => cls)
@@ -37,7 +37,7 @@ export function classOptions(
37
37
  const options: ClassOption[] = found.map((cls) => ({ kind: "class", cls }));
38
38
  // The new name as it will be saved: at most 60 characters, no control characters (W-220).
39
39
  const name = cleanClassName(query);
40
- const taken = catalog.some((cls) => cls.name.toLowerCase() === name.toLowerCase());
40
+ const taken = catalog.some((cls) => nameKey(cls.name) === nameKey(name));
41
41
  if (name && !taken) options.push({ kind: "create", name });
42
42
  return options;
43
43
  }
@@ -48,6 +48,6 @@ export const appliedByName = (
48
48
  applied: readonly string[],
49
49
  query: string,
50
50
  ) => {
51
- const q = query.trim().toLowerCase();
52
- return catalog.find((cls) => applied.includes(cls.id) && cls.name.toLowerCase() === q);
51
+ const q = nameKey(query);
52
+ return catalog.find((cls) => applied.includes(cls.id) && nameKey(cls.name) === q);
53
53
  };
@@ -17,21 +17,45 @@ export function formatStyleValue(value: unknown): string {
17
17
  ) {
18
18
  return `${record["value"]}${record["unit"]}`;
19
19
  }
20
- if (typeof record["var"] === "string" && Object.keys(record).length === 1) {
20
+ // W-696: a length or font variable carries `from`; it showed as raw JSON.
21
+ if (
22
+ typeof record["var"] === "string" &&
23
+ Object.keys(record).every((k) => k === "var" || k === "from")
24
+ ) {
21
25
  return `var(--${record["var"]})`;
22
26
  }
23
27
  }
24
28
  return JSON.stringify(value);
25
29
  }
26
30
 
31
+ // W-695: numbers read as in the Style tab's length fields: ".5rem", "+2px", "1.5 rem" and "2."
32
+ // were refused here though the Style tab takes them.
33
+ const NUMBER = String.raw`[+-]?(?:\d+(?:\.\d*)?|\.\d+)`;
34
+ const LENGTH = new RegExp(String.raw`^(${NUMBER})\s*([a-z%]+)$`, "i");
35
+ const BARE = new RegExp(`^${NUMBER}$`);
36
+
27
37
  /** Readings of `text` to try, most specific first. */
28
- function candidates(text: string): unknown[] {
38
+ /**
39
+ * W-696: the variable kinds `key` reads, most likely first. A bare `{ var }` is a colour, so
40
+ * "var(--space-4)" on a padding stored a colour reference and the style was silently dropped.
41
+ */
42
+ function varKinds(key: string): (string | undefined)[] {
43
+ if (key === "color" || key === "backgroundColor" || key === "borderColor") return [undefined];
44
+ if (key === "fontFamily") return ["font"];
45
+ if (key === "fontSize") return ["fontSize", "spacing"];
46
+ return ["spacing", "fontSize"];
47
+ }
48
+
49
+ function candidates(text: string, key: string): unknown[] {
29
50
  const out: unknown[] = [];
30
- const length = /^(-?\d+(?:\.\d+)?)([a-z%]+)$/i.exec(text);
51
+ const length = LENGTH.exec(text);
31
52
  if (length) out.push({ value: Number(length[1]), unit: (length[2] as string).toLowerCase() });
32
53
  const variable = /^var\(--([a-z0-9-]{1,40})\)$/.exec(text);
33
- if (variable) out.push({ var: variable[1] });
34
- if (/^-?\d+(?:\.\d+)?$/.test(text)) {
54
+ if (variable) {
55
+ for (const from of varKinds(key))
56
+ out.push(from ? { var: variable[1], from } : { var: variable[1] });
57
+ }
58
+ if (BARE.test(text)) {
35
59
  out.push(Number(text));
36
60
  // W-404: a bare number on a length property means px, as in the Style tab.
37
61
  out.push({ value: Number(text), unit: "px" });
@@ -52,13 +76,18 @@ function candidates(text: string): unknown[] {
52
76
 
53
77
  /** The value `key` would store for `text`, or why it can't (W-398). */
54
78
  export function parseStyleValue(key: string, text: string): { value: unknown } | { error: string } {
55
- const schema = (
56
- StyleProps.shape as Record<string, { safeParse: (v: unknown) => { success: boolean } }>
57
- )[key];
79
+ // W-542: an inherited name ("constructor") is not a style property; it used to throw.
80
+ const shape = StyleProps.shape as Record<
81
+ string,
82
+ { safeParse: (v: unknown) => { success: boolean } }
83
+ >;
84
+ const schema = Object.hasOwn(shape, key) ? shape[key] : undefined;
58
85
  if (!schema) return { error: `${key} isn't a style property.` };
59
86
  const trimmed = text.trim();
60
87
  if (trimmed === "") return { error: "Enter a value." };
61
- for (const candidate of candidates(trimmed)) {
88
+ if (/^[+-]?\d*,\d+\s*[a-z%]*$/i.test(trimmed))
89
+ return { error: "Use a dot for decimals, such as 1.5." };
90
+ for (const candidate of candidates(trimmed, key)) {
62
91
  if (candidate !== undefined && schema.safeParse(candidate).success) return { value: candidate };
63
92
  }
64
93
  return { error: `"${trimmed.slice(0, 40)}" isn't a value ${key} accepts.` };
@@ -12,3 +12,16 @@ export function svgImagesNotice(count: number): string {
12
12
  const what = count === 1 ? "1 external image" : `${count} external images`;
13
13
  return `Left out ${what}. An SVG can only show pictures from the media library or embedded PNG, JPEG, WebP or GIF data.`;
14
14
  }
15
+
16
+ /**
17
+ * W-787: refused markup (a script, an event handler, a style, a link, an outside URL, or just
18
+ * cut off mid-paste) rendered as an empty grey box with no word of why. The note under the field.
19
+ */
20
+ export function svgMarkupRefused(node: LayoutNode): string | undefined {
21
+ if (node.type !== "svg") return undefined;
22
+ const markup = (node.props as { markup?: unknown }).markup;
23
+ if (typeof markup !== "string") return undefined;
24
+ if (markup.trim() === "") return "Paste SVG markup to show a graphic here.";
25
+ if (sanitizeSvgReport(markup).tree) return undefined;
26
+ return "This SVG can't be shown, so visitors see an empty box. Check that it is complete and has no scripts, event handlers (onload…), styles, links or outside URLs.";
27
+ }
@@ -3,10 +3,11 @@ import { DotsThreeIcon, PlusIcon, type Icon } from "@phosphor-icons/react";
3
3
  import * as React from "react";
4
4
  import { slugify } from "../../../core/index.ts";
5
5
  import { BUTTON, FIELD, SOLID_PRIMARY } from "../../ui.ts";
6
+ import { isCancelEscape, isCommitEnter } from "../ime.ts";
6
7
 
7
8
  /** A slug of `name` (or `fallback`) that no id in `taken` uses yet: `x`, then `x-2`, `x-3`… */
8
9
  export function uniqueId(name: string, fallback: string, taken: Iterable<string>): string {
9
- const base = slugify(name).slice(0, 34) || fallback;
10
+ const base = slugify(name).slice(0, 34).replace(/-+$/, "") || fallback;
10
11
  const used = new Set(taken);
11
12
  let id = base;
12
13
  for (let n = 2; used.has(id); n++) id = `${base}-${n}`;
@@ -69,7 +70,17 @@ export function CreateRow({
69
70
  children: React.ReactNode;
70
71
  }) {
71
72
  return (
72
- <div className="emvb-site-create emvb-site-elevated" {...rowProps}>
73
+ <div
74
+ className="emvb-site-create emvb-site-elevated"
75
+ {...rowProps}
76
+ // W-840: Enter in a text field creates, like the create dialogs; it used to do nothing.
77
+ onKeyDown={(event) => {
78
+ const field = event.target as HTMLElement;
79
+ if (field.tagName !== "INPUT" || !isCommitEnter(event)) return;
80
+ event.preventDefault();
81
+ onCreate();
82
+ }}
83
+ >
73
84
  {children}
74
85
  <div className="emvb-dialog-actions">
75
86
  <Button type="button" variant="secondary" className={BUTTON} onClick={onCancel}>
@@ -110,7 +121,7 @@ export function SiteSearch({
110
121
  placeholder={`${label}…`}
111
122
  onChange={(event) => onChange(event.target.value)}
112
123
  onKeyDown={(event) => {
113
- if (event.key === "Escape" && value) {
124
+ if (isCancelEscape(event) && value) {
114
125
  event.stopPropagation();
115
126
  onChange("");
116
127
  }
@@ -126,10 +137,13 @@ export function SiteSearch({
126
137
  */
127
138
  export function RenameInput({
128
139
  name,
140
+ initial,
129
141
  label,
130
142
  onDone,
131
143
  }: {
132
144
  name: string;
145
+ /** Text to start with instead of the name, e.g. a rename whose save failed (W-616). */
146
+ initial?: string;
133
147
  label: string;
134
148
  onDone: (next: string | null) => void;
135
149
  }) {
@@ -144,14 +158,14 @@ export function RenameInput({
144
158
  <input
145
159
  className="emvb-site-rename"
146
160
  aria-label={label}
147
- defaultValue={name}
161
+ defaultValue={initial ?? name}
148
162
  maxLength={60}
149
163
  // oxlint-disable-next-line jsx-a11y/no-autofocus -- the user asked to rename; focus moves into the field
150
164
  autoFocus
151
165
  onFocus={(event) => event.currentTarget.select()}
152
166
  onKeyDown={(event) => {
153
- if (event.key === "Enter") finish(event.currentTarget.value);
154
- else if (event.key === "Escape") {
167
+ if (isCommitEnter(event)) finish(event.currentTarget.value);
168
+ else if (isCancelEscape(event)) {
155
169
  event.stopPropagation();
156
170
  finish(null);
157
171
  }
@@ -1,4 +1,4 @@
1
- import type { VariableKind } from "../../../core/index.ts";
1
+ import { isSafeFontStack, type VariableKind } from "../../../core/index.ts";
2
2
  import { hexInput } from "./color-space.ts";
3
3
 
4
4
  export type Length = { value: number; unit: "px" | "rem" | "em" | "%" };
@@ -38,7 +38,7 @@ export function valueText(value: unknown): string {
38
38
 
39
39
  const ERRORS: Record<VariableKind, string> = {
40
40
  color: "Enter a hex color such as #1a2b3c.",
41
- font: "Enter a font stack such as Inter, sans-serif.",
41
+ font: "Enter a font stack such as Inter, sans-serif (letters, digits, spaces, - and _ in names).",
42
42
  fontSize: "Enter a size such as 16, 16px or 1.5rem.",
43
43
  spacing: "Enter a length such as 16, 16px or 1.5rem.",
44
44
  };
@@ -51,14 +51,21 @@ export function parseValue(
51
51
  const trimmed = text.trim();
52
52
  if (isLengthKind(kind)) {
53
53
  const length = parseLength(trimmed);
54
- return length ? { ok: true, value: length } : { ok: false, error: ERRORS[kind] };
54
+ if (length) return { ok: true, value: length };
55
+ // W-687: as in the style fields (W-262), "1,5rem" gets the reason, not the general hint.
56
+ if (/^\d*,\d+\s*[a-z%]*$/i.test(trimmed)) {
57
+ return { ok: false, error: "Use a dot for decimals, such as 1.5." };
58
+ }
59
+ return { ok: false, error: ERRORS[kind] };
55
60
  }
56
61
  if (kind === "color") {
57
62
  // W-434: "1a2b3c" without "#", as design tools copy it, is accepted.
58
63
  const hex = hexInput(trimmed);
59
64
  return hex ? { ok: true, value: hex } : { ok: false, error: ERRORS.color };
60
65
  }
61
- return trimmed && trimmed.length <= 200
66
+ // W-547: a stack the site CSS can't carry (a `;`, an apostrophe) was saved, then dropped from
67
+ // the page without a word.
68
+ return trimmed && isSafeFontStack(trimmed)
62
69
  ? { ok: true, value: trimmed }
63
70
  : { ok: false, error: ERRORS.font };
64
71
  }
@@ -73,3 +80,17 @@ export function pickerHex(hex: string): string {
73
80
  }
74
81
  return "#000000";
75
82
  }
83
+
84
+ /**
85
+ * The picker's 6-digit colour with the alpha `previous` had: `<input type="color">` has no alpha,
86
+ * so picking a colour made a see-through one solid (W-526).
87
+ */
88
+ export function withPreviousAlpha(picked: string, previous: string): string {
89
+ const p = previous.trim().toLowerCase();
90
+ const alpha = /^#[0-9a-f]{8}$/.test(p)
91
+ ? p.slice(7)
92
+ : /^#[0-9a-f]{4}$/.test(p)
93
+ ? (p[4] ?? "") + (p[4] ?? "")
94
+ : "";
95
+ return alpha && alpha !== "ff" && /^#[0-9a-f]{6}$/i.test(picked) ? picked + alpha : picked;
96
+ }
@@ -1,4 +1,6 @@
1
1
  import type { DesignSystem, Layout, VariableKind } from "../../core/index.ts";
2
+ import { MAX_CLASSES, nameKey } from "../../core/design/classes.ts";
3
+ import { clipText } from "../../core/limits.ts";
2
4
 
3
5
  type Variables = DesignSystem["variables"];
4
6
  type ListKey = keyof Variables;
@@ -43,6 +45,19 @@ export function deletionOf(
43
45
  : undefined;
44
46
  }
45
47
 
48
+ /**
49
+ * W-575: `name`, or "name 2", "name 3"… when another item in `list` has it now (made after the
50
+ * delete). Two classes or two colours with one name can't be told apart in the pickers.
51
+ */
52
+ function freeName(name: string, list: readonly { name: string }[]): string {
53
+ const taken = new Set(list.map((item) => nameKey(item.name)));
54
+ let candidate = name;
55
+ // Names are at most 60 characters; the stem is cut so the number still fits.
56
+ const stem = clipText(name, 56).trim();
57
+ for (let n = 2; taken.has(nameKey(candidate)) && n < 1000; n++) candidate = `${stem} ${n}`;
58
+ return candidate;
59
+ }
60
+
46
61
  /**
47
62
  * W-252: Site styles changes aren't undo steps, but deleting a variable or class also clears its
48
63
  * uses on the page, which is one. Undoing that brought the uses back with nothing defining them.
@@ -61,13 +76,17 @@ export function restoreOnUndo(
61
76
  if (deletion.before !== layout) continue;
62
77
  if (deletion.kind === "class") {
63
78
  if (classes.some((c) => c.id === deletion.cls.id)) continue;
64
- classes.splice(Math.min(deletion.index, classes.length), 0, deletion.cls);
79
+ // W-576: classes made after the delete may have filled the design up to the limit.
80
+ if (classes.length >= MAX_CLASSES) continue;
81
+ const cls = { ...deletion.cls, name: freeName(deletion.cls.name, classes) };
82
+ classes.splice(Math.min(deletion.index, classes.length), 0, cls);
65
83
  classRestored = true;
66
84
  } else {
67
85
  const key = LIST[deletion.variableKind];
68
86
  const list = variables[key] ?? [...(design.variables[key] ?? [])];
69
87
  if (list.some((v) => v.id === deletion.variable.id)) continue;
70
- list.splice(Math.min(deletion.index, list.length), 0, deletion.variable);
88
+ const variable = { ...deletion.variable, name: freeName(deletion.variable.name, list) };
89
+ list.splice(Math.min(deletion.index, list.length), 0, variable);
71
90
  variables[key] = list;
72
91
  }
73
92
  }