@perkyzz/emvb 0.2.1 → 0.4.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 (150) hide show
  1. package/README.md +4 -2
  2. package/THIRD_PARTY_NOTICES.md +1 -1
  3. package/package.json +3 -1
  4. package/src/admin/access/role.ts +9 -3
  5. package/src/admin/api.ts +17 -7
  6. package/src/admin/content-api.ts +7 -51
  7. package/src/admin/content-item.ts +22 -0
  8. package/src/admin/design-api.ts +30 -0
  9. package/src/admin/editor/A11yCopilot.tsx +126 -0
  10. package/src/admin/editor/CommandPalette.tsx +118 -0
  11. package/src/admin/editor/Editor.tsx +188 -152
  12. package/src/admin/editor/EditorOverlay.tsx +9 -1
  13. package/src/admin/editor/PerfMeter.tsx +121 -0
  14. package/src/admin/editor/ShareLink.tsx +164 -0
  15. package/src/admin/editor/ShortcutsDialog.tsx +4 -1
  16. package/src/admin/editor/Timeline.tsx +287 -0
  17. package/src/admin/editor/TopBar.tsx +4 -0
  18. package/src/admin/editor/canvas/CanvasFrame.tsx +62 -370
  19. package/src/admin/editor/canvas/DeviceBar.tsx +4 -1
  20. package/src/admin/editor/canvas/SelectionOverlay.tsx +87 -47
  21. package/src/admin/editor/canvas/canvas-scale.ts +20 -0
  22. package/src/admin/editor/canvas/drop-line.ts +24 -0
  23. package/src/admin/editor/canvas/use-canvas-dnd.ts +207 -0
  24. package/src/admin/editor/canvas/use-canvas-session.ts +216 -0
  25. package/src/admin/editor/collection-previews.ts +114 -0
  26. package/src/admin/editor/editor-chrome.tsx +346 -0
  27. package/src/admin/editor/editor-commands.ts +360 -0
  28. package/src/admin/editor/editor-css.ts +5 -3
  29. package/src/admin/editor/element-chrome.ts +89 -0
  30. package/src/admin/editor/feature-css.ts +105 -0
  31. package/src/admin/editor/host.ts +35 -0
  32. package/src/admin/editor/icons/IconLibraryDialog.tsx +64 -218
  33. package/src/admin/editor/icons/library.ts +29 -19
  34. package/src/admin/editor/icons/use-icon-library.ts +315 -0
  35. package/src/admin/editor/live-data.tsx +71 -0
  36. package/src/admin/editor/palette-items.ts +136 -0
  37. package/src/admin/editor/palette.ts +68 -0
  38. package/src/admin/editor/panels/AddPanel.tsx +48 -68
  39. package/src/admin/editor/panels/ClassesSection.tsx +5 -1
  40. package/src/admin/editor/panels/ColorControl.tsx +2 -10
  41. package/src/admin/editor/panels/ElementPanel.tsx +74 -102
  42. package/src/admin/editor/panels/LayersPanel.tsx +72 -63
  43. package/src/admin/editor/panels/LeftPanel.tsx +4 -1
  44. package/src/admin/editor/panels/SettingsPanel.tsx +13 -0
  45. package/src/admin/editor/panels/SiteStylesDrawer.tsx +18 -10
  46. package/src/admin/editor/panels/TokenScales.tsx +168 -0
  47. package/src/admin/editor/panels/VariableSection.tsx +10 -14
  48. package/src/admin/editor/panels/inline-error.tsx +11 -0
  49. package/src/admin/editor/panels/settings/AdvancedFields.tsx +87 -1
  50. package/src/admin/editor/panels/settings/AudienceEditor.tsx +285 -0
  51. package/src/admin/editor/panels/settings/BindingsEditor.tsx +221 -0
  52. package/src/admin/editor/panels/settings/ClassChipInput.tsx +1 -1
  53. package/src/admin/editor/panels/settings/DraftTextField.tsx +4 -0
  54. package/src/admin/editor/panels/settings/EffectsControls.tsx +2 -2
  55. package/src/admin/editor/panels/settings/FormBindControl.tsx +8 -4
  56. package/src/admin/editor/panels/settings/ItemList.tsx +34 -1
  57. package/src/admin/editor/panels/settings/MotionControl.tsx +252 -0
  58. package/src/admin/editor/panels/settings/StateSwitcher.tsx +1 -1
  59. package/src/admin/editor/panels/settings/StyleRow.tsx +26 -2
  60. package/src/admin/editor/panels/settings/StyleSources.tsx +94 -0
  61. package/src/admin/editor/panels/settings/VariableBinding.tsx +1 -1
  62. package/src/admin/editor/panels/settings/VariantEditor.tsx +83 -0
  63. package/src/admin/editor/panels/settings/form-names.ts +7 -11
  64. package/src/admin/editor/panels/settings/length-units.ts +16 -5
  65. package/src/admin/editor/panels/settings/style-sections.ts +7 -2
  66. package/src/admin/editor/panels/style-target.ts +105 -0
  67. package/src/admin/editor/section-templates.ts +43 -21
  68. package/src/admin/editor/shortcuts.ts +6 -1
  69. package/src/admin/editor/store.ts +10 -1
  70. package/src/admin/editor/useClipboardActions.ts +1 -1
  71. package/src/admin/editor/useEditorCommands.ts +61 -13
  72. package/src/admin/editor/useEditorData.ts +7 -1
  73. package/src/admin/editor/useEditorShortcuts.ts +30 -14
  74. package/src/admin/editor/useNodeActions.ts +44 -16
  75. package/src/admin/forms-api.ts +17 -6
  76. package/src/admin/icon-uploads-api.ts +18 -0
  77. package/src/admin/theme-api.ts +5 -18
  78. package/src/admin/ui.ts +4 -4
  79. package/src/astro/content-port.ts +24 -0
  80. package/src/astro/forms/EmVBFormsClient.astro +11 -0
  81. package/src/astro/forms/EmVBFormsRuntime.astro +6 -7
  82. package/src/astro/forms/client.ts +1 -0
  83. package/src/astro/forms-definitions.ts +24 -11
  84. package/src/astro/index.ts +1 -0
  85. package/src/astro/render-session.ts +85 -0
  86. package/src/astro/request-data.ts +109 -0
  87. package/src/astro/resolve-theme.ts +184 -64
  88. package/src/astro/resolve.ts +63 -16
  89. package/src/astro/theme-posts.ts +48 -5
  90. package/src/astro/visitor.ts +204 -0
  91. package/src/constants.ts +1 -1
  92. package/src/core/a11y/audit.ts +282 -0
  93. package/src/core/arrange.ts +150 -34
  94. package/src/core/audience/rules.ts +124 -0
  95. package/src/core/audience/variants.ts +51 -0
  96. package/src/core/canvas-styles.ts +24 -0
  97. package/src/core/clipboard.ts +11 -32
  98. package/src/core/css/generate.ts +29 -2
  99. package/src/core/css/print.ts +12 -0
  100. package/src/core/css/scope.ts +3 -3
  101. package/src/core/css/trace.ts +169 -0
  102. package/src/core/css-keywords.ts +83 -0
  103. package/src/core/data/bindings.ts +255 -0
  104. package/src/core/design/classes.ts +13 -15
  105. package/src/core/design/diff.ts +55 -0
  106. package/src/core/design/merge.ts +127 -0
  107. package/src/core/design/tokens.ts +127 -0
  108. package/src/core/design/variables.ts +25 -21
  109. package/src/core/elements/dynamic-elements.ts +117 -2
  110. package/src/core/elements/form-elements.ts +1 -0
  111. package/src/core/elements/index.ts +185 -7
  112. package/src/core/forms/binding.ts +4 -13
  113. package/src/core/history/diff.ts +152 -0
  114. package/src/core/index.ts +121 -0
  115. package/src/core/local-style.ts +27 -0
  116. package/src/core/migrate/index.ts +12 -4
  117. package/src/core/nesting.ts +4 -22
  118. package/src/core/perf/meter.ts +160 -0
  119. package/src/core/perf/scripts.ts +61 -0
  120. package/src/core/recipes/index.ts +433 -0
  121. package/src/core/record.ts +3 -0
  122. package/src/core/render/context.ts +2 -0
  123. package/src/core/render/dynamic-post.ts +1 -2
  124. package/src/core/render/form.ts +133 -10
  125. package/src/core/render/index.ts +206 -17
  126. package/src/core/render/loop.ts +54 -7
  127. package/src/core/render/pagination.ts +9 -1
  128. package/src/core/render/vnode.ts +12 -2
  129. package/src/core/sanitize/css.ts +129 -80
  130. package/src/core/sanitize/motion.ts +129 -0
  131. package/src/core/sanitize/svg.ts +8 -3
  132. package/src/core/sanitize/url.ts +10 -1
  133. package/src/core/schema/design.ts +29 -8
  134. package/src/core/schema/layout.ts +291 -169
  135. package/src/core/schema/motion.ts +14 -0
  136. package/src/core/schema/style.ts +101 -66
  137. package/src/core/share/link.ts +187 -0
  138. package/src/core/tabs/presence.ts +7 -17
  139. package/src/core/theme/dynamic.ts +242 -32
  140. package/src/core/theme/float.ts +1 -1
  141. package/src/core/theme/pagination.ts +56 -0
  142. package/src/core/tree-ops.ts +57 -0
  143. package/src/index.ts +14 -2
  144. package/src/server/design-routes.ts +4 -1
  145. package/src/server/icon-routes.ts +68 -16
  146. package/src/server/plugin.ts +8 -2
  147. package/src/admin/editor/icons/sets/fontawesome.json +0 -1
  148. package/src/admin/editor/icons/sets/lucide.json +0 -1
  149. package/src/admin/editor/icons/sets/remix.json +0 -1
  150. package/src/admin/editor/icons/sets/tabler.json +0 -1
@@ -0,0 +1,164 @@
1
+ import { Button, Dialog, Input, Switch } from "@cloudflare/kumo";
2
+ import * as React from "react";
3
+ import {
4
+ encodeSharedPage,
5
+ LONG_LINK_CHARS,
6
+ shareUrl,
7
+ type DesignSystem,
8
+ type Layout,
9
+ type LayoutNode,
10
+ } from "../../core/index.ts";
11
+ import { BUTTON, FIELD } from "../ui.ts";
12
+
13
+ const MEDIA_KEYS = ["src", "poster", "backgroundImage", "backgroundVideo"];
14
+ const siteOnly = (value: unknown) =>
15
+ typeof value === "string" && value.trim() !== "" && !/^(https?:)?\/\//i.test(value.trim());
16
+
17
+ /** Media on the page whose address only works on this site (W-321): a path, not a full URL. */
18
+ export function siteOnlyMedia(layout: Layout): number {
19
+ let count = 0;
20
+ const visit = (node: LayoutNode) => {
21
+ const props = node.props as Record<string, unknown>;
22
+ const style = (node.style ?? {}) as Record<string, unknown>;
23
+ for (const key of MEDIA_KEYS) {
24
+ const raw = props[key] ?? style[key];
25
+ const url = typeof raw === "object" && raw !== null ? (raw as { url?: unknown }).url : raw;
26
+ if (siteOnly(url)) count += 1;
27
+ }
28
+ const kids = (node as { children?: LayoutNode[] }).children;
29
+ if (Array.isArray(kids)) for (const child of kids) visit(child);
30
+ };
31
+ visit(layout.root);
32
+ return count;
33
+ }
34
+
35
+ /**
36
+ * Shareable playground link (W-321): this page (as it is now, saved or not) and optionally the
37
+ * Site styles, packed into a link that opens it on emvb.dev/playground. Nothing is uploaded: the
38
+ * page travels in the link's `#` part, which browsers never send to a server.
39
+ */
40
+ export function ShareLinkDialog({
41
+ open,
42
+ onOpenChange,
43
+ layout,
44
+ design,
45
+ title,
46
+ base,
47
+ }: {
48
+ open: boolean;
49
+ onOpenChange: (open: boolean) => void;
50
+ layout: Layout | null;
51
+ design: DesignSystem;
52
+ title: string;
53
+ /** Playground address; emvb.dev's by default. */
54
+ base?: string;
55
+ }) {
56
+ const [withStyles, setWithStyles] = React.useState(true);
57
+ const [link, setLink] = React.useState<string | null>(null);
58
+ const [error, setError] = React.useState<string | null>(null);
59
+ const [copied, setCopied] = React.useState<"yes" | "no" | null>(null);
60
+
61
+ React.useEffect(() => {
62
+ if (!open || !layout) return;
63
+ let cancelled = false;
64
+ setLink(null);
65
+ setError(null);
66
+ setCopied(null);
67
+ encodeSharedPage({ title, layout, ...(withStyles ? { design } : {}) }).then(
68
+ (encoded) => {
69
+ if (!cancelled) setLink(shareUrl(encoded, base));
70
+ },
71
+ (reason: unknown) => {
72
+ if (!cancelled) setError(reason instanceof Error ? reason.message : String(reason));
73
+ },
74
+ );
75
+ return () => {
76
+ cancelled = true;
77
+ };
78
+ }, [open, layout, design, title, withStyles, base]);
79
+
80
+ const copy = () => {
81
+ if (!link) return;
82
+ if (!navigator.clipboard?.writeText) {
83
+ setCopied("no");
84
+ return;
85
+ }
86
+ navigator.clipboard.writeText(link).then(
87
+ () => setCopied("yes"),
88
+ () => setCopied("no"),
89
+ );
90
+ };
91
+
92
+ const siteMedia = layout ? siteOnlyMedia(layout) : 0;
93
+ return (
94
+ <Dialog.Root open={open} onOpenChange={onOpenChange}>
95
+ <Dialog size="base" className="p-6 emvb-share" data-emvb-share="">
96
+ <Dialog.Title>Share as a playground link</Dialog.Title>
97
+ <Dialog.Description>
98
+ Anyone with the link can open a copy of this page in the EmVB playground and edit it in
99
+ their own browser. The page travels inside the link; nothing is uploaded.
100
+ </Dialog.Description>
101
+ <Switch
102
+ label="Include Site styles (colours, fonts, sizes, classes)"
103
+ checked={withStyles}
104
+ onCheckedChange={(checked) => setWithStyles(checked === true)}
105
+ />
106
+ {error ? (
107
+ <p className="emvb-helper" role="alert">
108
+ Couldn't build the link: {error}
109
+ </p>
110
+ ) : (
111
+ <Input
112
+ label="Link"
113
+ className={FIELD}
114
+ readOnly
115
+ value={link ?? "Building the link…"}
116
+ data-emvb-share-link=""
117
+ onFocus={(event) => event.currentTarget.select()}
118
+ />
119
+ )}
120
+ {link && (
121
+ <p className="emvb-helper" data-emvb-share-size="">
122
+ {link.length.toLocaleString("en")} characters
123
+ {link.length > LONG_LINK_CHARS
124
+ ? ". That's long: some chat apps cut links this size, so paste it somewhere that keeps it whole."
125
+ : "."}
126
+ </p>
127
+ )}
128
+ {siteMedia > 0 && (
129
+ <p className="emvb-helper" data-emvb-share-media="">
130
+ {siteMedia === 1 ? "1 image or video uses" : `${siteMedia} images or videos use`} an
131
+ address on this site only, so the playground shows {siteMedia === 1 ? "it" : "them"}{" "}
132
+ empty.
133
+ </p>
134
+ )}
135
+ <p className="emvb-helper">
136
+ Unsaved changes are included. Posts, forms and uploads stay on this site.
137
+ </p>
138
+ <div className="emvb-dialog-actions">
139
+ {copied && (
140
+ <span role="status" className="emvb-helper">
141
+ {copied === "yes" ? "Copied." : "Copy didn't work here: select the link and copy it."}
142
+ </span>
143
+ )}
144
+ <Dialog.Close
145
+ render={(props) => (
146
+ <Button {...props} variant="secondary" className={BUTTON}>
147
+ Close
148
+ </Button>
149
+ )}
150
+ />
151
+ <Button
152
+ variant="primary"
153
+ className={BUTTON}
154
+ disabled={!link}
155
+ onClick={copy}
156
+ data-emvb-share-copy=""
157
+ >
158
+ Copy link
159
+ </Button>
160
+ </div>
161
+ </Dialog>
162
+ </Dialog.Root>
163
+ );
164
+ }
@@ -22,7 +22,10 @@ export function ShortcutsDialog({
22
22
  ))}
23
23
  </tbody>
24
24
  </table>
25
- <p>Shortcuts don't fire while a text field has focus, except Ctrl/Cmd+S.</p>
25
+ <p>
26
+ Shortcuts don't fire while a text field has focus, except Ctrl/Cmd+S and Ctrl/Cmd+K. In a
27
+ dialog, only Ctrl/Cmd+S fires.
28
+ </p>
26
29
  <Dialog.Close render={(props) => <Button {...props}>Close</Button>} />
27
30
  </Dialog>
28
31
  </Dialog.Root>
@@ -0,0 +1,287 @@
1
+ import { Button, Dialog } from "@cloudflare/kumo";
2
+ import * as React from "react";
3
+ import {
4
+ canvasStyleUrls,
5
+ changedIds,
6
+ diffSections,
7
+ escapeAttr,
8
+ renderPage,
9
+ restoreSection,
10
+ validateLayout,
11
+ type DesignSystem,
12
+ type Layout,
13
+ type SectionChange,
14
+ } from "../../core/index.ts";
15
+ import { ApiError, requestJson, type Fetcher } from "../api.ts";
16
+ import { ELEMENT_NAMES } from "./element-chrome.ts";
17
+
18
+ type RevisionItem = {
19
+ id: string;
20
+ createdAt: string;
21
+ authorId?: string | null;
22
+ data?: Record<string, unknown>;
23
+ };
24
+
25
+ type TimelineVersion = { id: string; at: string; layout: Layout | null };
26
+
27
+ /** A revision's layout, or null when it has none or it doesn't validate (W-315). */
28
+ export function revisionLayout(data: Record<string, unknown> | undefined): Layout | null {
29
+ let raw: unknown = data?.["layout"];
30
+ if (typeof raw === "string") {
31
+ try {
32
+ raw = JSON.parse(raw) as unknown;
33
+ } catch {
34
+ return null;
35
+ }
36
+ }
37
+ if (!raw || typeof raw !== "object") return null;
38
+ const result = validateLayout(raw);
39
+ return result.ok ? result.layout : null;
40
+ }
41
+
42
+ /** A host without EmDash revisions for this collection answers 404. */
43
+ export const NO_REVISIONS =
44
+ "This site doesn't keep saved versions of this page, so there's no timeline to show.";
45
+
46
+ function useRevisions(fetcher: Fetcher, collection: string, entryId: string, open: boolean) {
47
+ const [state, setState] = React.useState<
48
+ | { kind: "loading" }
49
+ | { kind: "error"; message: string }
50
+ | { kind: "ready"; versions: TimelineVersion[] }
51
+ >({ kind: "loading" });
52
+ React.useEffect(() => {
53
+ if (!open) return;
54
+ let cancelled = false;
55
+ setState({ kind: "loading" });
56
+ requestJson<{ items?: RevisionItem[] }>(
57
+ fetcher,
58
+ `/_emdash/api/content/${encodeURIComponent(collection)}/${encodeURIComponent(entryId)}/revisions?limit=50`,
59
+ )
60
+ .then((body) => {
61
+ if (cancelled) return;
62
+ const versions = (body?.items ?? [])
63
+ .map((item) => ({ id: item.id, at: item.createdAt, layout: revisionLayout(item.data) }))
64
+ .toSorted((a, b) => (a.at < b.at ? 1 : -1));
65
+ setState({ kind: "ready", versions });
66
+ })
67
+ .catch((error: unknown) => {
68
+ if (!cancelled) {
69
+ setState({
70
+ kind: "error",
71
+ message:
72
+ error instanceof ApiError && error.status === 404
73
+ ? NO_REVISIONS
74
+ : `Couldn't load versions: ${error instanceof Error ? error.message : String(error)}`,
75
+ });
76
+ }
77
+ });
78
+ return () => {
79
+ cancelled = true;
80
+ };
81
+ }, [fetcher, collection, entryId, open]);
82
+ return state;
83
+ }
84
+
85
+ const KIND_LABELS: Record<SectionChange["kind"], string> = {
86
+ added: "Added since",
87
+ removed: "Removed since",
88
+ changed: "Changed",
89
+ moved: "Moved",
90
+ same: "Unchanged",
91
+ };
92
+
93
+ const DIFF_CSS = {
94
+ added: "outline:3px solid #16a34a;outline-offset:-3px",
95
+ removed: "outline:3px solid #dc2626;outline-offset:-3px",
96
+ changed: "outline:3px solid #d97706;outline-offset:-3px",
97
+ };
98
+
99
+ const when = (iso: string) => {
100
+ const date = new Date(iso);
101
+ return Number.isNaN(date.getTime()) ? iso : date.toLocaleString();
102
+ };
103
+
104
+ /** A small, script-free picture of one version with its changed sections outlined (W-315). */
105
+ function Snapshot({
106
+ layout,
107
+ design,
108
+ ids,
109
+ title,
110
+ canvasStyles = [],
111
+ }: {
112
+ layout: Layout;
113
+ design: DesignSystem;
114
+ ids: Partial<Record<"added" | "removed" | "changed", string[]>>;
115
+ title: string;
116
+ /** Host stylesheets, before EmVB's CSS, the same order as the canvas (W-351). */
117
+ canvasStyles?: readonly string[];
118
+ }) {
119
+ const doc = React.useMemo(() => {
120
+ const { html, css } = renderPage(layout, design, { mode: "editor" });
121
+ const outline = (Object.entries(ids) as [keyof typeof DIFF_CSS, string[]][])
122
+ .flatMap(([kind, list]) => list.map((id) => `[data-emvb-id="${id}"]{${DIFF_CSS[kind]}}`))
123
+ .join("");
124
+ const links = canvasStyleUrls([...canvasStyles])
125
+ .map((href) => `<link rel="stylesheet" href="${escapeAttr(href)}" data-emvb-canvas-style="">`)
126
+ .join("");
127
+ return `<!doctype html><html><head>${links}<style>html{zoom:.35}body{margin:0}${css}${outline}</style></head><body>${html}</body></html>`;
128
+ }, [layout, design, ids, canvasStyles]);
129
+ return <iframe className="emvb-timeline-frame" title={title} sandbox="" srcDoc={doc} />;
130
+ }
131
+
132
+ /**
133
+ * Version timeline (W-315): every saved version of the page, a side-by-side picture against the
134
+ * current page with what changed outlined, and restore for one section or the whole version.
135
+ * Restoring is an ordinary edit: undo takes it back, and nothing is saved until you save.
136
+ */
137
+ export function TimelineDialog({
138
+ open,
139
+ onOpenChange,
140
+ fetcher,
141
+ collection,
142
+ entryId,
143
+ current,
144
+ design,
145
+ onApply,
146
+ canvasStyles = [],
147
+ }: {
148
+ open: boolean;
149
+ onOpenChange: (open: boolean) => void;
150
+ fetcher: Fetcher;
151
+ collection: string;
152
+ entryId: string;
153
+ current: Layout | null;
154
+ design: DesignSystem;
155
+ onApply: (layout: Layout, note: string) => void;
156
+ /** Host stylesheets the canvas already loads (W-351). */
157
+ canvasStyles?: readonly string[];
158
+ }) {
159
+ const revisions = useRevisions(fetcher, collection, entryId, open);
160
+ const [pickedId, setPickedId] = React.useState<string | null>(null);
161
+ const [error, setError] = React.useState<string | null>(null);
162
+ const versions = revisions.kind === "ready" ? revisions.versions : [];
163
+ const picked = versions.find((v) => v.id === pickedId) ?? versions[0];
164
+ const changes = React.useMemo(
165
+ () => (picked?.layout && current ? diffSections(picked.layout, current) : []),
166
+ [picked, current],
167
+ );
168
+ const ids = React.useMemo(() => changedIds(changes), [changes]);
169
+ return (
170
+ <Dialog.Root open={open} onOpenChange={onOpenChange}>
171
+ <Dialog size="xl" className="p-6 emvb-timeline" data-emvb-timeline="">
172
+ <Dialog.Title>Version timeline</Dialog.Title>
173
+ {revisions.kind === "loading" && <p className="emvb-helper">Loading versions…</p>}
174
+ {revisions.kind === "error" && (
175
+ <p className="emvb-helper" role="alert">
176
+ {revisions.message}
177
+ </p>
178
+ )}
179
+ {revisions.kind === "ready" && versions.length === 0 && (
180
+ <p className="emvb-helper" data-emvb-timeline-empty="">
181
+ No saved versions yet. Each save adds one.
182
+ </p>
183
+ )}
184
+ {picked && current && (
185
+ <div className="emvb-timeline-body">
186
+ <ol className="emvb-timeline-list" aria-label="Saved versions">
187
+ {versions.map((v) => (
188
+ <li key={v.id}>
189
+ <button
190
+ type="button"
191
+ className="emvb-timeline-version"
192
+ aria-current={v.id === picked.id ? "true" : undefined}
193
+ data-emvb-version={v.id}
194
+ onClick={() => setPickedId(v.id)}
195
+ >
196
+ {when(v.at)}
197
+ {!v.layout && " (no layout)"}
198
+ </button>
199
+ </li>
200
+ ))}
201
+ </ol>
202
+ <div className="emvb-timeline-main">
203
+ {picked.layout ? (
204
+ <>
205
+ <div className="emvb-timeline-frames">
206
+ <figure>
207
+ <figcaption>{when(picked.at)}</figcaption>
208
+ <Snapshot
209
+ layout={picked.layout}
210
+ design={design}
211
+ ids={{ removed: ids.removed, changed: ids.changed }}
212
+ title="Saved version"
213
+ canvasStyles={canvasStyles}
214
+ />
215
+ </figure>
216
+ <figure>
217
+ <figcaption>Now</figcaption>
218
+ <Snapshot
219
+ layout={current}
220
+ design={design}
221
+ ids={{ added: ids.added, changed: ids.changed }}
222
+ title="Current page"
223
+ canvasStyles={canvasStyles}
224
+ />
225
+ </figure>
226
+ </div>
227
+ <ul className="emvb-timeline-changes" data-emvb-timeline-changes="">
228
+ {changes.map((change) => (
229
+ <li key={`${change.kind}:${change.id}`} data-kind={change.kind}>
230
+ <span className="emvb-timeline-kind">{KIND_LABELS[change.kind]}</span>{" "}
231
+ {change.label || ELEMENT_NAMES[change.type] || change.type}
232
+ {change.kind === "changed" &&
233
+ ` · ${change.edits} element${change.edits === 1 ? "" : "s"}`}
234
+ {(change.kind === "changed" || change.kind === "removed") && (
235
+ <button
236
+ type="button"
237
+ className="emvb-link-button"
238
+ data-emvb-restore-section={change.id}
239
+ onClick={() => {
240
+ if (!picked.layout) return;
241
+ const result = restoreSection(current, picked.layout, change.id);
242
+ if (!result.ok) {
243
+ setError(result.reason);
244
+ return;
245
+ }
246
+ setError(null);
247
+ onApply(result.layout, "Section restored");
248
+ }}
249
+ >
250
+ Restore this section
251
+ </button>
252
+ )}
253
+ </li>
254
+ ))}
255
+ </ul>
256
+ {error && (
257
+ <p className="emvb-helper" role="alert">
258
+ {error}
259
+ </p>
260
+ )}
261
+ <p className="emvb-helper">
262
+ Restoring changes the page here; undo takes it back, and nothing is saved until
263
+ you save.
264
+ </p>
265
+ <Button
266
+ variant="secondary"
267
+ data-emvb-restore-version=""
268
+ onClick={() => {
269
+ if (!picked.layout) return;
270
+ onApply(picked.layout, "Version restored");
271
+ onOpenChange(false);
272
+ }}
273
+ >
274
+ Restore this whole version
275
+ </Button>
276
+ </>
277
+ ) : (
278
+ <p className="emvb-helper">This version has no page layout to compare.</p>
279
+ )}
280
+ </div>
281
+ </div>
282
+ )}
283
+ <Dialog.Close render={(props) => <Button {...props}>Close</Button>} />
284
+ </Dialog>
285
+ </Dialog.Root>
286
+ );
287
+ }
@@ -72,6 +72,7 @@ export function TopBar({
72
72
  stylesUnpublished = false,
73
73
  canRevert = false,
74
74
  onRevert,
75
+ tools,
75
76
  }: {
76
77
  page: TopBarPage | null;
77
78
  dirty: boolean;
@@ -90,6 +91,8 @@ export function TopBar({
90
91
  canRevert?: boolean;
91
92
  /** Shown once the entry has a published version; asks before discarding. */
92
93
  onRevert?: () => void;
94
+ /** Extra tools beside Site styles: the page weight and accessibility meters, … (W-310). */
95
+ tools?: React.ReactNode;
93
96
  }) {
94
97
  return (
95
98
  <header className="emvb-topbar">
@@ -153,6 +156,7 @@ export function TopBar({
153
156
  onClick={onSiteStyles}
154
157
  />
155
158
  )}
159
+ {page && tools}
156
160
  </div>
157
161
  {page && (
158
162
  <div