@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,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
  }
@@ -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
  }
@@ -1,5 +1,10 @@
1
1
  import * as React from "react";
2
- import { collectSectionPartIds, type Layout } from "../../core/index.ts";
2
+ import {
3
+ collectLoopItemPartIds,
4
+ collectSectionPartIds,
5
+ type Layout,
6
+ type ThemePartType,
7
+ } from "../../core/index.ts";
3
8
  import type { Fetcher } from "../api.ts";
4
9
  import { themePartLayout } from "../theme-api.ts";
5
10
 
@@ -40,27 +45,91 @@ export async function loadSectionTemplates(
40
45
  return acc;
41
46
  }
42
47
 
43
- /** Section theme parts referenced by the open layout, so the canvas shows the synced contents. */
44
- export function useSectionTemplates(
45
- layout: Layout | null,
48
+ export interface PartTemplates {
49
+ sectionTemplates: Record<string, Layout>;
50
+ loopTemplates: Record<string, Layout>;
51
+ }
52
+
53
+ const MAX_PARTS = 64;
54
+
55
+ function partRefs(part: Layout): Array<[string, "section" | "loop_item"]> {
56
+ return [
57
+ ...collectSectionPartIds(part).map((id) => [id, "section"] as [string, "section"]),
58
+ ...collectLoopItemPartIds(part).map((id) => [id, "loop_item"] as [string, "loop_item"]),
59
+ ];
60
+ }
61
+
62
+ /**
63
+ * W-658: synced sections and Loop Item parts referenced by the open layout, following parts nested
64
+ * in either kind (a Loop inside a section, a section or Loop inside a loop item). The canvas used to
65
+ * load only sections, so a Loop with a chosen Loop Item showed "Choose a Loop Item" instead of it.
66
+ */
67
+ export async function loadPartTemplates(
46
68
  fetcher: Fetcher,
47
- ): Record<string, Layout> {
48
- const key = layout ? collectSectionPartIds(layout).join("\0") : "";
49
- const [templates, setTemplates] = React.useState<Record<string, Layout>>({});
69
+ layout: Layout,
70
+ read: (id: string, kind: ThemePartType) => Promise<Layout | null> = (id, kind) =>
71
+ themePartLayout(fetcher, id, kind),
72
+ ): Promise<PartTemplates> {
73
+ const out: PartTemplates = { sectionTemplates: {}, loopTemplates: {} };
74
+ const seen = new Set<string>();
75
+ let next = partRefs(layout);
76
+ for (let depth = 0; depth <= MAX_DEPTH && next.length > 0; depth++) {
77
+ const pending = next.filter(([id, kind]) => {
78
+ const key = `${kind}\0${id}`;
79
+ if (seen.has(key) || seen.size >= MAX_PARTS) return false;
80
+ seen.add(key);
81
+ return true;
82
+ });
83
+ // Each depth waits on the one before it: its ids come from the parts just read.
84
+ // oxlint-disable-next-line no-await-in-loop
85
+ const loaded = await Promise.all(
86
+ pending.map(async ([id, kind]) => {
87
+ try {
88
+ return [id, kind, await read(id, kind)] as const;
89
+ } catch {
90
+ return [id, kind, null] as const;
91
+ }
92
+ }),
93
+ );
94
+ next = [];
95
+ for (const [id, kind, part] of loaded) {
96
+ if (!part) continue;
97
+ (kind === "section" ? out.sectionTemplates : out.loopTemplates)[id] = part;
98
+ next.push(...partRefs(part));
99
+ }
100
+ }
101
+ return out;
102
+ }
103
+
104
+ function partKey(layout: Layout | null): string {
105
+ if (!layout) return "";
106
+ const s = collectSectionPartIds(layout);
107
+ const l = collectLoopItemPartIds(layout);
108
+ return s.length + l.length === 0 ? "" : JSON.stringify([s, l]);
109
+ }
110
+
111
+ const NO_PARTS: PartTemplates = { sectionTemplates: {}, loopTemplates: {} };
112
+
113
+ /** Section and Loop Item parts for the canvas (W-658). */
114
+ export function usePartTemplates(layout: Layout | null, fetcher: Fetcher): PartTemplates {
115
+ const key = partKey(layout);
116
+ const layoutRef = React.useRef(layout);
117
+ layoutRef.current = layout;
118
+ const [templates, setTemplates] = React.useState<PartTemplates>(NO_PARTS);
50
119
 
51
120
  React.useEffect(() => {
52
- const ids = key ? key.split("\0") : [];
53
- if (ids.length === 0) {
54
- setTemplates({});
121
+ const current = layoutRef.current;
122
+ if (!key || !current) {
123
+ setTemplates(NO_PARTS);
55
124
  return;
56
125
  }
57
126
  let cancelled = false;
58
- void loadSectionTemplates(fetcher, ids).then(
127
+ void loadPartTemplates(fetcher, current).then(
59
128
  (acc) => {
60
129
  if (!cancelled) setTemplates(acc);
61
130
  },
62
131
  () => {
63
- if (!cancelled) setTemplates({});
132
+ if (!cancelled) setTemplates(NO_PARTS);
64
133
  },
65
134
  );
66
135
  return () => {
@@ -6,19 +6,48 @@ export const SHORTCUTS: readonly { action: string; keys: string }[] = [
6
6
  { action: "Select first child / parent", keys: "Enter / Shift+Enter" },
7
7
  { action: "Clear selection", keys: "Esc" },
8
8
  { action: "Expand or collapse (Layers)", keys: "← / →" },
9
+ // UX-085: F2 renames the focused layer or class chip; the list never said so.
10
+ { action: "Rename (layer or class chip)", keys: "F2" },
9
11
  { action: "Move up / down", keys: "Alt+↑ / Alt+↓" },
10
12
  { action: "Move out / in", keys: "Alt+← / Alt+→" },
11
13
  { action: "Duplicate", keys: "Ctrl/Cmd+D" },
12
14
  { action: "Copy / paste element", keys: "Ctrl/Cmd+C / Ctrl/Cmd+V" },
13
15
  { action: "Paste style", keys: "Ctrl/Cmd+Shift+V" },
14
16
  { action: "Delete", keys: "Delete or Backspace" },
15
- { action: "Undo / redo", keys: "Ctrl/Cmd+Z / Ctrl/Cmd+Shift+Z" },
17
+ // W-775: Ctrl/Cmd+Y redoes too (useEditorShortcuts); the list never said so.
18
+ { action: "Undo / redo", keys: "Ctrl/Cmd+Z / Ctrl/Cmd+Shift+Z or Ctrl/Cmd+Y" },
16
19
  { action: "Save draft", keys: "Ctrl/Cmd+S" },
17
20
  ];
18
21
 
22
+ /** One alternative in a shortcut ("Ctrl/Cmd+Shift+Z"), with the separator before it. */
23
+ export type KeyCombo = { before: string; keys: string[] };
24
+
25
+ /** W-864: "Ctrl/Cmd+Z / Ctrl/Cmd+Y" as combos of single keys, for key boxes. */
26
+ export function keyCombos(keys: string): KeyCombo[] {
27
+ const parts = keys.split(/( \/ | or )/);
28
+ const combos: KeyCombo[] = [];
29
+ for (let i = 0; i < parts.length; i += 2) {
30
+ const combo = parts[i] ?? "";
31
+ combos.push({ before: i === 0 ? "" : (parts[i - 1] ?? ""), keys: combo.split(/\+(?=.)/) });
32
+ }
33
+ return combos;
34
+ }
35
+
36
+ /**
37
+ * W-565: the letter of a Ctrl/Cmd shortcut on any keyboard layout. A Russian, Greek, Hebrew or
38
+ * Arabic layout reports its own letter (Ctrl+Z is "я"), so the key's position stands in when the
39
+ * key isn't a Latin letter. Latin layouts (AZERTY, Dvorak) keep the letter they type.
40
+ */
41
+ export function shortcutKey(event: KeyboardEvent): string {
42
+ const key = event.key.toLowerCase();
43
+ if (/^[a-z]$/.test(key)) return key;
44
+ const position = /^Key([A-Z])$/.exec(event.code ?? "");
45
+ return position?.[1] ? position[1].toLowerCase() : key;
46
+ }
47
+
19
48
  /** Ctrl/Cmd+K opens the host command palette, which would stack over the editor (S0-6). */
20
49
  export const isPaletteShortcut = (event: KeyboardEvent) =>
21
- (event.ctrlKey || event.metaKey) && !event.altKey && event.key.toLowerCase() === "k";
50
+ (event.ctrlKey || event.metaKey) && !event.altKey && shortcutKey(event) === "k";
22
51
 
23
52
  /** Focus is inside an open dialog, where only Save fires. */
24
53
  export const inDialog = (target: EventTarget | null) =>
@@ -59,6 +59,11 @@ export type EditorAction =
59
59
  | { type: "saved"; rev: string; version: number }
60
60
  | { type: "published"; rev: string }
61
61
  | { type: "set-design"; design: DesignSystem; revision: string | null }
62
+ /**
63
+ * W-536: a site styles edit shown before its save lands, so the next edit builds on it. The
64
+ * save's `set-design` (or a refusal) follows.
65
+ */
66
+ | { type: "preview-design"; design: DesignSystem }
62
67
  | { type: "publish-design"; revision: string }
63
68
  /** The site styles as saved elsewhere, after a refused save (W-212). */
64
69
  | {
@@ -224,6 +229,8 @@ export function editorReducer(state: EditorState, action: EditorAction): EditorS
224
229
  };
225
230
  case "published":
226
231
  return { ...state, rev: action.rev, status: "published" };
232
+ case "preview-design":
233
+ return { ...state, design: action.design };
227
234
  case "set-design":
228
235
  return {
229
236
  ...state,