@perkyzz/emvb 0.4.0 → 0.5.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 (67) hide show
  1. package/README.md +19 -3
  2. package/package.json +4 -3
  3. package/src/admin/agents-api.ts +39 -0
  4. package/src/admin/editor/CommandPalette.tsx +43 -2
  5. package/src/admin/editor/Editor.tsx +27 -0
  6. package/src/admin/editor/Timeline.tsx +108 -6
  7. package/src/admin/editor/editor-css.ts +4 -0
  8. package/src/admin/editor/feature-css.ts +22 -3
  9. package/src/admin/editor/palette.ts +6 -2
  10. package/src/admin/editor/panels/ColorControl.tsx +19 -8
  11. package/src/admin/editor/panels/ElementPanel.tsx +1 -1
  12. package/src/admin/editor/panels/TokenScales.tsx +4 -2
  13. package/src/admin/editor/panels/color-space.ts +12 -1
  14. package/src/admin/editor/panels/settings/AdvancedFields.tsx +84 -28
  15. package/src/admin/editor/panels/settings/AudienceEditor.tsx +42 -4
  16. package/src/admin/editor/panels/settings/DraftTextField.tsx +38 -9
  17. package/src/admin/editor/panels/settings/FieldControl.tsx +6 -0
  18. package/src/admin/editor/panels/settings/IconPicker.tsx +21 -1
  19. package/src/admin/editor/panels/settings/ImageSourcesField.tsx +111 -0
  20. package/src/admin/editor/panels/settings/MediaPicker.tsx +2 -3
  21. package/src/admin/editor/panels/settings/QueryStyleRows.tsx +178 -0
  22. package/src/admin/editor/panels/settings/advanced-rules.ts +3 -0
  23. package/src/admin/editor/panels/settings/link-rules.ts +19 -0
  24. package/src/admin/editor/panels/settings/number-input.ts +11 -0
  25. package/src/admin/editor/panels/settings/query-style.ts +65 -0
  26. package/src/admin/editor/panels/variable-values.ts +4 -2
  27. package/src/admin/editor/remote-change.ts +67 -0
  28. package/src/admin/index.tsx +3 -1
  29. package/src/admin/media-api.ts +20 -0
  30. package/src/admin/pages/AgentsPage.tsx +274 -0
  31. package/src/admin/ui.ts +28 -0
  32. package/src/astro/floats/runtime.ts +10 -0
  33. package/src/astro/popups/runtime.ts +15 -0
  34. package/src/astro/tabs/runtime.ts +60 -1
  35. package/src/constants.ts +1 -1
  36. package/src/core/a11y/audit.ts +202 -26
  37. package/src/core/arrange.ts +11 -3
  38. package/src/core/css/generate.ts +9 -1
  39. package/src/core/elements/form-elements.ts +19 -3
  40. package/src/core/elements/index.ts +39 -11
  41. package/src/core/render/dynamic-post.ts +21 -5
  42. package/src/core/render/form.ts +12 -5
  43. package/src/core/render/index.ts +50 -11
  44. package/src/core/render/pagination.ts +21 -2
  45. package/src/core/sanitize/embed-url.ts +7 -1
  46. package/src/core/sanitize/href.ts +13 -1
  47. package/src/core/schema/descriptors.ts +4 -1
  48. package/src/core/schema/layout.ts +10 -3
  49. package/src/core/share/link.ts +4 -1
  50. package/src/core/theme/dynamic.ts +12 -7
  51. package/src/mcp/errors.ts +44 -0
  52. package/src/mcp/index.ts +4 -0
  53. package/src/mcp/ports.ts +78 -0
  54. package/src/mcp/prompts.ts +76 -0
  55. package/src/mcp/publish.ts +60 -0
  56. package/src/mcp/queue.ts +19 -0
  57. package/src/mcp/rate-limit.ts +80 -0
  58. package/src/mcp/read.ts +419 -0
  59. package/src/mcp/refs.ts +84 -0
  60. package/src/mcp/settings.ts +18 -0
  61. package/src/mcp/tools.ts +265 -0
  62. package/src/mcp/write.ts +582 -0
  63. package/src/server/agent-settings.ts +134 -0
  64. package/src/server/design-routes.ts +71 -17
  65. package/src/server/icon-routes.ts +5 -1
  66. package/src/server/mcp-routes.ts +265 -0
  67. package/src/server/plugin.ts +32 -2
package/README.md CHANGED
@@ -12,7 +12,9 @@ A visual page builder plugin for [EmDash CMS](https://github.com/emdash-cms/emda
12
12
  npm i @perkyzz/emvb
13
13
  ```
14
14
 
15
- Peers, which an EmDash 1.x site already has: `emdash` ^1.0.0, `astro` ^7, `react` and `react-dom` ^19, `@cloudflare/kumo` 2.6.0 and `@phosphor-icons/react` ^2.1.10. `@emdash-cms/plugin-forms` is optional and enables forms.
15
+ Peers, which an EmDash 1.x site already has: `emdash` ^1.0.0, `astro` ^7, `react` and `react-dom` ^19, `@cloudflare/kumo` 2.6.0 and `@phosphor-icons/react` ^2.1.10. `@emdash-cms/plugin-forms` ^0.2.9 is optional and enables forms.
16
+
17
+ Dependencies installed with it: `zod` and [`@perkyzz/emvb-icons`](https://www.npmjs.com/package/@perkyzz/emvb-icons), the icon sets for the editor's Icon library. Only the editor loads them; a placed icon is saved into the page as SVG.
16
18
 
17
19
  ## Register the plugin
18
20
 
@@ -39,6 +41,8 @@ import { getEmDashEntry, decodeSlug } from "emdash";
39
41
  import { EmVBPage, resolveEmVBPage } from "@perkyzz/emvb/astro";
40
42
  // With @emdash-cms/plugin-forms installed and registered:
41
43
  import { EmVBFormsRuntime } from "@perkyzz/emvb/astro/forms/client";
44
+ import { EmVBMenuRuntime } from "@perkyzz/emvb/astro/menu";
45
+ import { EmVBTabsRuntime } from "@perkyzz/emvb/astro/tabs";
42
46
 
43
47
  const emvb = await resolveEmVBPage(Astro);
44
48
  if (!emvb && !(await getEmDashEntry("pages", decodeSlug(Astro.params.slug)))) {
@@ -46,15 +50,27 @@ if (!emvb && !(await getEmDashEntry("pages", decodeSlug(Astro.params.slug)))) {
46
50
  }
47
51
  ---
48
52
 
49
- {emvb && <EmVBPage page={emvb}>{emvb.needsFormsRuntime && <EmVBFormsRuntime />}</EmVBPage>}
53
+ {emvb && (
54
+ <EmVBPage page={emvb}>
55
+ {emvb.needsFormsRuntime && <EmVBFormsRuntime />}
56
+ {emvb.needsTabsRuntime && <EmVBTabsRuntime />}
57
+ {emvb.needsMenuRuntime && <EmVBMenuRuntime />}
58
+ </EmVBPage>
59
+ )}
50
60
  ```
51
61
 
62
+ Each runtime is a small script mounted only on pages that need it; the rest of the page is plain HTML and CSS. Theme parts (`resolveThemeParts`) also report popups and floats, served from `@perkyzz/emvb/astro/popups` and `@perkyzz/emvb/astro/floats`.
63
+
52
64
  Without the forms plugin, import `EmVBFormsRuntime` from `@perkyzz/emvb/astro/forms` (it renders nothing and does not import the plugin) or leave the element out. The `/client` subpath is the one that calls `initForms`.
53
65
 
54
- A fixed route has no slug parameter. Pass the page's slug: `await resolveEmVBPage(Astro, { slug: "home" })`. Visitor rules can use the same call's `visitor` option (`{ segments: ["member"] }`, and country, device or returning when the site knows better); `resolveThemeParts` takes it too. The [install guide](https://github.com/PerkyZZ999/EmVB/blob/main/docs/guides/install-in-a-host-site.md) shows both.
66
+ A fixed route has no slug parameter. Pass the page's slug: `await resolveEmVBPage(Astro, { slug: "home" })`. Visitor rules can use the same call's `visitor` option (`{ segments: ["member"] }`, and country, device or returning when the site knows better); `resolveThemeParts` takes it too. The [install guide](https://github.com/PerkyZZ999/EmVB/blob/main/docs/guides/install-in-a-host-site.md) shows both, and the `canvasStyles` option that loads your site's stylesheets into the editor canvas: `emvb({ canvasStyles: ["/styles/site.css"] })`.
55
67
 
56
68
  Then sign in as an admin, open **Pages VisualBuilder** and click **Set up EmVB** once.
57
69
 
70
+ ## AI agents (MCP)
71
+
72
+ On EmDash 1.2+ with `emdash({ mcp: true, … })`, AI agents can build and edit draft EmVB pages. An admin turns them on in **Pages VisualBuilder → AI agents** (off by default) and approves the EmVB tools on EmDash's Plugins screen. Agents connect to EmDash's own endpoint (`/_emdash/api/mcp`) or through the local bridge, `npx -y @perkyzz/emvb-mcp --site https://your.site` with the token in `EMVB_TOKEN`. Tokens need the `mcp:tools:emvb` scope and an editor (not an admin) user. Agents only change drafts unless an admin allows publishing; each token may make 300 reads and 60 changes a minute and 10 publishes an hour. Every agent change shows in the version timeline with an **Agent** badge. See the [MCP guide](https://github.com/PerkyZZ999/EmVB/blob/main/docs/guides/mcp.md).
73
+
58
74
  Website: <https://emvb.dev>. The full guide, the demos and the source are on GitHub: <https://github.com/PerkyZZ999/EmVB>.
59
75
 
60
76
  ## License
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@perkyzz/emvb",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "Visual page builder plugin for EmDash CMS",
5
5
  "keywords": [
6
6
  "astro",
@@ -39,7 +39,8 @@
39
39
  "./astro/popups": "./src/astro/popups/index.ts",
40
40
  "./astro/floats": "./src/astro/floats/index.ts",
41
41
  "./astro/tabs": "./src/astro/tabs/index.ts",
42
- "./astro/menu": "./src/astro/menu/index.ts"
42
+ "./astro/menu": "./src/astro/menu/index.ts",
43
+ "./mcp": "./src/mcp/index.ts"
43
44
  },
44
45
  "publishConfig": {
45
46
  "access": "public"
@@ -48,7 +49,7 @@
48
49
  "test:astro": "bun --bun vitest run"
49
50
  },
50
51
  "dependencies": {
51
- "@perkyzz/emvb-icons": "0.1.0",
52
+ "@perkyzz/emvb-icons": "0.1.1",
52
53
  "zod": "~4.5.4"
53
54
  },
54
55
  "devDependencies": {
@@ -0,0 +1,39 @@
1
+ import { PLUGIN_ID } from "../constants.ts";
2
+ import type { AgentSettings } from "../mcp/settings.ts";
3
+ import { requestJson, type Fetcher } from "./api.ts";
4
+
5
+ export type AgentActivity = {
6
+ id: string;
7
+ at: string;
8
+ tool: string;
9
+ target: "page" | "styles" | "settings";
10
+ pageId?: string;
11
+ revisionId?: string;
12
+ summary: string;
13
+ userId: string | null;
14
+ client?: string;
15
+ };
16
+
17
+ export type AgentsState = {
18
+ settings: AgentSettings;
19
+ revision: string | null;
20
+ endpoint: string;
21
+ activity: AgentActivity[];
22
+ };
23
+
24
+ const base = `/_emdash/api/plugins/${PLUGIN_ID}`;
25
+
26
+ export const loadAgents = (fetcher: Fetcher) => requestJson<AgentsState>(fetcher, `${base}/agents`);
27
+
28
+ /** Saves the agent settings; the returned revision is the one the next save must send. */
29
+ export async function saveAgentSettings(
30
+ fetcher: Fetcher,
31
+ settings: AgentSettings,
32
+ revision: string | null,
33
+ ): Promise<string> {
34
+ const body = await requestJson<{ revision: string }>(fetcher, `${base}/agents/save`, {
35
+ method: "POST",
36
+ body: { settings, revision },
37
+ });
38
+ return body.revision;
39
+ }
@@ -18,6 +18,44 @@ export function CommandPalette({
18
18
  const [query, setQuery] = React.useState("");
19
19
  const [active, setActive] = React.useState(0);
20
20
  const listRef = React.useRef<HTMLUListElement>(null);
21
+ // W-399: opened from a shortcut there is no trigger to return to, so focus fell to <body> on
22
+ // close. Remember what had focus and go back to it when nothing else took focus.
23
+ const wasOpen = React.useRef(false);
24
+ const returnTo = React.useRef<HTMLElement | null>(null);
25
+ if (open && !wasOpen.current && typeof document !== "undefined") {
26
+ const focused = document.activeElement;
27
+ returnTo.current = focused instanceof HTMLElement && focused !== document.body ? focused : null;
28
+ }
29
+ wasOpen.current = open;
30
+ /** After a command, the selected layer first (it may have changed); after Esc, where we were. */
31
+ const restoreFocus = (afterCommand = false) => {
32
+ // The dialog lets go of focus only once its close animation ends, so wait for that.
33
+ const started = Date.now();
34
+ const settle = () => {
35
+ const now = document.activeElement;
36
+ // Kumo's Dialog doesn't pass data attributes through; find the palette by its input.
37
+ const stillOpen = document.querySelector("[data-emvb-palette-input]") !== null;
38
+ const inPalette = now?.closest('[role="dialog"]')?.querySelector("[data-emvb-palette-input]");
39
+ if (now && now !== document.body && !inPalette) return;
40
+ if (stillOpen && Date.now() - started < 2000) {
41
+ setTimeout(settle, 30);
42
+ return;
43
+ }
44
+ const selected = document.querySelector<HTMLElement>(
45
+ '.emvb-layer-select[aria-current="true"]',
46
+ );
47
+ const back = returnTo.current?.isConnected ? returnTo.current : null;
48
+ const target =
49
+ (afterCommand ? (selected ?? back) : (back ?? selected)) ??
50
+ document.querySelector<HTMLElement>("iframe[data-emvb-canvas]");
51
+ target?.focus({ preventScroll: true });
52
+ };
53
+ setTimeout(settle, 30);
54
+ };
55
+ const close = (next: boolean) => {
56
+ onOpenChange(next);
57
+ if (!next) restoreFocus();
58
+ };
21
59
  React.useEffect(() => {
22
60
  if (open) {
23
61
  setQuery("");
@@ -35,7 +73,10 @@ export function CommandPalette({
35
73
  if (!item) return;
36
74
  onOpenChange(false);
37
75
  // After the dialog closes, so focus moves where the command wants it.
38
- setTimeout(item.run, 0);
76
+ setTimeout(() => {
77
+ item.run();
78
+ restoreFocus(true);
79
+ }, 0);
39
80
  };
40
81
  const onKeyDown = (event: React.KeyboardEvent) => {
41
82
  if (event.key === "ArrowDown" || event.key === "ArrowUp") {
@@ -51,7 +92,7 @@ export function CommandPalette({
51
92
  };
52
93
  let lastGroup = "";
53
94
  return (
54
- <Dialog.Root open={open} onOpenChange={onOpenChange}>
95
+ <Dialog.Root open={open} onOpenChange={close}>
55
96
  <Dialog size="base" className="emvb-palette" data-emvb-palette="">
56
97
  <Dialog.Title className="sr-only">Command palette</Dialog.Title>
57
98
  <input
@@ -1,7 +1,9 @@
1
1
  import { Banner, Button, createKumoToastManager, Empty, Loader, Toasty } from "@cloudflare/kumo";
2
2
  import {
3
+ ArrowsClockwiseIcon,
3
4
  ClockCounterClockwiseIcon,
4
5
  GaugeIcon,
6
+ RobotIcon,
5
7
  ShareNetworkIcon,
6
8
  WarningCircleIcon,
7
9
  } from "@phosphor-icons/react";
@@ -50,6 +52,7 @@ import {
50
52
  import { EDITOR_MIN_WIDTH_QUERY, useMediaQuery } from "./useMediaQuery.ts";
51
53
  import { useSectionTemplates } from "./section-templates.ts";
52
54
  import { useCollectionPreviews } from "./collection-previews.ts";
55
+ import { useRemoteChange } from "./remote-change.ts";
53
56
  import { A11yScoreButton } from "./A11yCopilot.tsx";
54
57
  import { restoreOnUndo, type Deletion } from "./restore-deleted.ts";
55
58
  import { useEditorCommands } from "./useEditorCommands.ts";
@@ -123,6 +126,8 @@ function EditorApp({
123
126
  const canvasStyles = useCanvasStyles(fetcher);
124
127
  const { exit } = host;
125
128
  const saver = useSave(fetcher, state, dispatch, collection);
129
+ // W-466: tell the person when an agent (or anyone) changed the page while they were idle.
130
+ const remoteChange = useRemoteChange(fetcher, collection, entry.id, state.rev, !dirty);
126
131
  const toasts = React.useMemo(() => createKumoToastManager(), []);
127
132
  const chrome = useChromeFlags();
128
133
  const [device, setDevice] = React.useState<PopupDevice>("desktop");
@@ -328,6 +333,28 @@ function EditorApp({
328
333
  onPalette={() => chrome.open("palette")}
329
334
  >
330
335
  <Toasty toastManager={toasts}>
336
+ {remoteChange && (
337
+ <div className="emvb-remote-change" role="status" data-emvb-remote-change={remoteChange}>
338
+ <span className="emvb-remote-change-icon" aria-hidden="true">
339
+ {remoteChange === "agent" ? (
340
+ <RobotIcon size={16} />
341
+ ) : (
342
+ <ArrowsClockwiseIcon size={16} />
343
+ )}
344
+ </span>
345
+ <span className="emvb-remote-change-text">
346
+ <strong>
347
+ {remoteChange === "agent"
348
+ ? "An AI agent changed this page."
349
+ : "This page was changed somewhere else."}
350
+ </strong>{" "}
351
+ <span>Reload to see the latest draft. Its changes are in the version timeline.</span>
352
+ </span>
353
+ <Button size="sm" variant="primary" onClick={() => window.location.reload()}>
354
+ Reload
355
+ </Button>
356
+ </div>
357
+ )}
331
358
  {wideEnough ? (
332
359
  <>
333
360
  <TopBar
@@ -1,4 +1,5 @@
1
1
  import { Button, Dialog } from "@cloudflare/kumo";
2
+ import { RobotIcon, SquaresFourIcon, UserIcon, type Icon } from "@phosphor-icons/react";
2
3
  import * as React from "react";
3
4
  import {
4
5
  canvasStyleUrls,
@@ -13,6 +14,7 @@ import {
13
14
  type SectionChange,
14
15
  } from "../../core/index.ts";
15
16
  import { ApiError, requestJson, type Fetcher } from "../api.ts";
17
+ import { PLUGIN_ID } from "../../constants.ts";
16
18
  import { ELEMENT_NAMES } from "./element-chrome.ts";
17
19
 
18
20
  type RevisionItem = {
@@ -22,7 +24,33 @@ type RevisionItem = {
22
24
  data?: Record<string, unknown>;
23
25
  };
24
26
 
25
- type TimelineVersion = { id: string; at: string; layout: Layout | null };
27
+ type TimelineVersion = {
28
+ id: string;
29
+ at: string;
30
+ layout: Layout | null;
31
+ /** Set when an AI agent saved this version (W-460). */
32
+ agent?: { tool: string; summary: string };
33
+ };
34
+
35
+ type AgentVersion = { revisionId: string; tool: string; summary: string };
36
+
37
+ /** Which versions an agent saved; none when the site has no agent log (older EmVB). */
38
+ const agentVersions = (fetcher: Fetcher, entryId: string) =>
39
+ requestJson<{ versions: AgentVersion[] }>(
40
+ fetcher,
41
+ `/_emdash/api/plugins/${PLUGIN_ID}/agents/page`,
42
+ {
43
+ method: "POST",
44
+ body: { pageId: entryId },
45
+ },
46
+ ).then(
47
+ (body) => new Map((body.versions ?? []).map((v) => [v.revisionId, v])),
48
+ () => new Map<string, AgentVersion>(),
49
+ );
50
+
51
+ type Who = "all" | "people" | "agents";
52
+ const WHO_LABELS: Record<Who, string> = { all: "All", people: "People", agents: "Agents" };
53
+ const WHO_ICONS: Record<Who, Icon> = { all: SquaresFourIcon, people: UserIcon, agents: RobotIcon };
26
54
 
27
55
  /** A revision's layout, or null when it has none or it doesn't validate (W-315). */
28
56
  export function revisionLayout(data: Record<string, unknown> | undefined): Layout | null {
@@ -57,10 +85,20 @@ function useRevisions(fetcher: Fetcher, collection: string, entryId: string, ope
57
85
  fetcher,
58
86
  `/_emdash/api/content/${encodeURIComponent(collection)}/${encodeURIComponent(entryId)}/revisions?limit=50`,
59
87
  )
60
- .then((body) => {
88
+ .then(async (body) => ({ body, agents: await agentVersions(fetcher, entryId) }))
89
+ .then(({ body, agents }) => {
61
90
  if (cancelled) return;
62
91
  const versions = (body?.items ?? [])
63
- .map((item) => ({ id: item.id, at: item.createdAt, layout: revisionLayout(item.data) }))
92
+ .map((item): TimelineVersion => {
93
+ const agent = agents.get(item.id);
94
+ const version: TimelineVersion = {
95
+ id: item.id,
96
+ at: item.createdAt,
97
+ layout: revisionLayout(item.data),
98
+ };
99
+ if (agent) version.agent = { tool: agent.tool, summary: agent.summary };
100
+ return version;
101
+ })
64
102
  .toSorted((a, b) => (a.at < b.at ? 1 : -1));
65
103
  setState({ kind: "ready", versions });
66
104
  })
@@ -101,6 +139,20 @@ const when = (iso: string) => {
101
139
  return Number.isNaN(date.getTime()) ? iso : date.toLocaleString();
102
140
  };
103
141
 
142
+ /** A version's day and time on two short lines, so the list doesn't wrap mid-time (W-477). */
143
+ const whenParts = (iso: string) => {
144
+ const date = new Date(iso);
145
+ if (Number.isNaN(date.getTime())) return { day: iso, time: "" };
146
+ return {
147
+ day: date.toLocaleDateString(undefined, { month: "short", day: "numeric", year: "numeric" }),
148
+ time: date.toLocaleTimeString(undefined, {
149
+ hour: "numeric",
150
+ minute: "2-digit",
151
+ second: "2-digit",
152
+ }),
153
+ };
154
+ };
155
+
104
156
  /** A small, script-free picture of one version with its changed sections outlined (W-315). */
105
157
  function Snapshot({
106
158
  layout,
@@ -159,7 +211,12 @@ export function TimelineDialog({
159
211
  const revisions = useRevisions(fetcher, collection, entryId, open);
160
212
  const [pickedId, setPickedId] = React.useState<string | null>(null);
161
213
  const [error, setError] = React.useState<string | null>(null);
162
- const versions = revisions.kind === "ready" ? revisions.versions : [];
214
+ const [who, setWho] = React.useState<Who>("all");
215
+ const all = revisions.kind === "ready" ? revisions.versions : [];
216
+ const hasAgents = all.some((v) => v.agent);
217
+ const versions = all.filter((v) =>
218
+ who === "all" ? true : who === "agents" ? Boolean(v.agent) : !v.agent,
219
+ );
163
220
  const picked = versions.find((v) => v.id === pickedId) ?? versions[0];
164
221
  const changes = React.useMemo(
165
222
  () => (picked?.layout && current ? diffSections(picked.layout, current) : []),
@@ -181,6 +238,36 @@ export function TimelineDialog({
181
238
  No saved versions yet. Each save adds one.
182
239
  </p>
183
240
  )}
241
+ {hasAgents && (
242
+ <div className="emvb-timeline-who" role="group" aria-label="Show versions by">
243
+ {(Object.keys(WHO_LABELS) as Who[]).map((key) => {
244
+ const WhoIcon = WHO_ICONS[key];
245
+ const count =
246
+ key === "all"
247
+ ? all.length
248
+ : all.filter((v) => (key === "agents" ? v.agent : !v.agent)).length;
249
+ return (
250
+ <button
251
+ key={key}
252
+ type="button"
253
+ className="emvb-timeline-who-option"
254
+ aria-pressed={who === key}
255
+ data-emvb-timeline-who={key}
256
+ onClick={() => {
257
+ setWho(key);
258
+ setPickedId(null);
259
+ }}
260
+ >
261
+ <WhoIcon aria-hidden="true" size={14} />
262
+ {WHO_LABELS[key]}
263
+ <span className="emvb-timeline-count" aria-label={`, ${count}`}>
264
+ {count}
265
+ </span>
266
+ </button>
267
+ );
268
+ })}
269
+ </div>
270
+ )}
184
271
  {picked && current && (
185
272
  <div className="emvb-timeline-body">
186
273
  <ol className="emvb-timeline-list" aria-label="Saved versions">
@@ -193,8 +280,23 @@ export function TimelineDialog({
193
280
  data-emvb-version={v.id}
194
281
  onClick={() => setPickedId(v.id)}
195
282
  >
196
- {when(v.at)}
197
- {!v.layout && " (no layout)"}
283
+ <span className="emvb-timeline-when">
284
+ <span>{whenParts(v.at).day}</span>
285
+ <span className="emvb-timeline-time">
286
+ {whenParts(v.at).time}
287
+ {!v.layout && " (no layout)"}
288
+ </span>
289
+ </span>
290
+ {v.agent && (
291
+ <span
292
+ className="emvb-timeline-agent"
293
+ data-emvb-agent-version=""
294
+ title={v.agent.summary}
295
+ >
296
+ <RobotIcon aria-hidden="true" size={12} />
297
+ Agent
298
+ </span>
299
+ )}
198
300
  </button>
199
301
  </li>
200
302
  ))}
@@ -87,6 +87,10 @@ export const EDITOR_CSS = `${UI_CSS}
87
87
  .emvb-panel-title { margin: 0; font-size: 14px; line-height: 18px; font-weight: 600; }
88
88
  .emvb-panel-body, .emvb-field-group, .emvb-new-variable, .emvb-section-body { display: flex; flex-direction: column; gap: 10px; }
89
89
  .emvb-field-group, .emvb-new-variable { gap: 8px; }
90
+ .emvb-query-style, .emvb-query-add { display: flex; flex-direction: column; gap: 6px; }
91
+ .emvb-query-row { display: grid; grid-template-columns: 1fr auto; gap: 4px 8px; align-items: center; }
92
+ .emvb-query-row > label, .emvb-query-row > .emvb-helper { grid-column: 1 / -1; }
93
+ .emvb-query-style { border-left: 2px solid var(--emvb-border, #d4d4d8); padding-left: 8px; }
90
94
  .emvb-section-header { display: flex; align-items: center; justify-content: space-between; width: 100%; height: var(--emvb-control); margin-top: 4px; padding: 0; border: 0; border-top: 1px solid var(--color-kumo-hairline); background: none; color: var(--text-color-kumo-strong, var(--text-color-kumo-default)); font: inherit; font-size: 12px; font-weight: 600; letter-spacing: 0.01em; cursor: pointer; }
91
95
  .emvb-section-header:focus-visible, .emvb-layer-row:focus-visible, .emvb-empty-prompt:focus-visible { outline: 2px solid var(--color-kumo-brand); outline-offset: 2px; }
92
96
  .emvb-count { margin-left: 4px; font-size: 12px; line-height: 16px; font-weight: 400; color: var(--text-color-kumo-subtle); }
@@ -53,10 +53,29 @@ export const FEATURE_CSS = `
53
53
  .emvb-palette-empty { padding: 12px; color: var(--text-color-kumo-subtle); font-size: 13px; }
54
54
  .emvb-palette-tips { margin: 0; padding: 6px 12px; border-top: 1px solid var(--color-kumo-line); font-size: 11px; color: var(--text-color-kumo-subtle); }
55
55
  .sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
56
- .emvb-timeline-body { display: grid; grid-template-columns: 200px 1fr; gap: 16px; margin: 12px 0; min-height: 0; }
56
+ .emvb-timeline-body { display: grid; grid-template-columns: 220px 1fr; gap: 16px; margin: 12px 0; min-height: 0; }
57
57
  .emvb-timeline-list { margin: 0; padding: 0; list-style: none; max-height: 60vh; overflow-y: auto; }
58
- .emvb-timeline-version { width: 100%; padding: 6px 8px; border: 0; border-radius: 6px; background: transparent; color: inherit; font: inherit; font-size: 12px; text-align: start; cursor: pointer; }
59
- .emvb-timeline-version[aria-current="true"] { background: var(--color-kumo-tint); font-weight: 600; }
58
+ .emvb-timeline-list { display: grid; gap: 2px; padding-inline-end: 4px; }
59
+ .emvb-timeline-version { display: flex; align-items: center; justify-content: space-between; gap: 8px; width: 100%; padding: 6px 10px; border: 0; border-radius: 8px; background: transparent; color: var(--text-color-kumo-default); font: inherit; font-size: 13px; line-height: 18px; text-align: start; cursor: pointer; }
60
+ .emvb-timeline-version:hover { background: var(--color-kumo-tint); }
61
+ .emvb-timeline-version:focus-visible { outline: 2px solid var(--color-kumo-brand); outline-offset: -2px; }
62
+ .emvb-timeline-when { display: grid; min-width: 0; }
63
+ .emvb-timeline-time { color: var(--text-color-kumo-subtle); font-size: 12px; font-weight: 400; font-variant-numeric: tabular-nums; }
64
+ .emvb-timeline-version[aria-current="true"] { background: var(--color-kumo-base); box-shadow: var(--shadow-sm); outline: 1px solid var(--color-kumo-line); font-weight: 600; }
65
+ .emvb-timeline-agent { display: inline-flex; flex: none; align-items: center; gap: 3px; padding: 1px 7px 1px 5px; border: 1px solid var(--color-kumo-line); border-radius: 999px; background: var(--color-kumo-base); color: var(--text-color-kumo-default); font-size: 11px; line-height: 16px; font-weight: 600; }
66
+ /* W-477: a themed card under the top bar, centred over the canvas so it never hides the inspector. */
67
+ .emvb-remote-change { position: fixed; inset-block-start: 96px; inset-inline-start: 50%; transform: translateX(-50%); z-index: 50; display: flex; align-items: center; gap: 12px; max-width: min(560px, calc(100vw - 32px)); padding: 10px 10px 10px 12px; border: 1px solid var(--color-kumo-line); border-radius: 12px; background: var(--color-kumo-base); color: var(--text-color-kumo-default); box-shadow: var(--shadow-lg); font-size: 13px; line-height: 18px; }
68
+ .emvb-remote-change-icon { display: grid; flex: none; place-items: center; width: 32px; height: 32px; border-radius: 999px; background: var(--color-kumo-tint); color: var(--text-color-kumo-brand, var(--text-color-kumo-default)); }
69
+ .emvb-remote-change-text { display: grid; min-width: 0; }
70
+ .emvb-remote-change-text strong { font-weight: 600; }
71
+ .emvb-remote-change-text span { color: var(--text-color-kumo-subtle); }
72
+ /* W-477: All | People | Agents as the editor's segmented control (Kumo Tabs "segmented" look). */
73
+ .emvb-timeline-who { display: inline-flex; gap: 2px; margin-block: 12px 4px; padding: 2px; border-radius: 8px; background: var(--color-kumo-recessed); }
74
+ .emvb-timeline-who-option { display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 10px; border: 0; border-radius: 6px; background: transparent; color: var(--text-color-kumo-default); font: inherit; font-size: 13px; cursor: pointer; }
75
+ .emvb-timeline-who-option:hover { background: var(--color-kumo-tint); }
76
+ .emvb-timeline-who-option:focus-visible { outline: 2px solid var(--color-kumo-brand); outline-offset: 1px; }
77
+ .emvb-timeline-who-option[aria-pressed="true"] { background: var(--color-kumo-base); box-shadow: var(--shadow-sm); outline: 1px solid var(--color-kumo-line); font-weight: 500; }
78
+ .emvb-timeline-count { min-width: 18px; padding: 0 5px; border-radius: 999px; background: var(--color-kumo-tint); color: var(--text-color-kumo-subtle); font-size: 11px; line-height: 16px; text-align: center; font-variant-numeric: tabular-nums; }
60
79
  .emvb-timeline-frames { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
61
80
  .emvb-timeline-frames figure { margin: 0; }
62
81
  .emvb-timeline-frames figcaption { font-size: 12px; color: var(--text-color-kumo-subtle); margin-bottom: 4px; }
@@ -22,13 +22,17 @@ const PREFIXES: Record<string, PaletteGroup> = {
22
22
  ".": "Apply class",
23
23
  };
24
24
 
25
+ /** W-420: accents and case don't matter, so "cafe" finds "Café" and "strasse" finds "Straße". */
26
+ const fold = (value: string) =>
27
+ value.normalize("NFD").replace(/\p{M}/gu, "").toLowerCase().replace(/ß/g, "ss");
28
+
25
29
  /**
26
30
  * How well `query` matches `text` (W-314): null when its letters don't all appear in order.
27
31
  * Higher is better: a prefix beats a word start, which beats a scattered match.
28
32
  */
29
33
  export function fuzzyScore(query: string, text: string): number | null {
30
- const q = query.trim().toLowerCase();
31
- const t = text.toLowerCase();
34
+ const q = fold(query.trim());
35
+ const t = fold(text);
32
36
  if (!q) return 0;
33
37
  if (t.startsWith(q)) return 1000 - t.length;
34
38
  const at = t.indexOf(q);
@@ -15,6 +15,7 @@ import {
15
15
  formatOklch,
16
16
  formatRgb,
17
17
  oklchClipped,
18
+ hexInput,
18
19
  parseHex,
19
20
  parseOklch,
20
21
  parseRgb,
@@ -225,15 +226,22 @@ function CustomColor({
225
226
  const [error, setError] = React.useState<{ field: Notation; message: string } | null>(null);
226
227
  const picker = React.useRef<HTMLInputElement | null>(null);
227
228
  const commit = (next: string) => {
228
- const hex = next.trim();
229
- if (hex === value || hex === "") {
229
+ const typed = next.trim();
230
+ if (typed === value || typed === "") {
230
231
  setError(null);
231
232
  return;
232
233
  }
233
- if (!HEX.test(hex)) {
234
+ const hex = hexInput(typed);
235
+ if (!hex) {
234
236
  setError({ field: "hex", message: BAD_HEX });
235
237
  return;
236
238
  }
239
+ if (hex === value) {
240
+ setError(null);
241
+ setDraft(hex);
242
+ return;
243
+ }
244
+ setDraft(hex);
237
245
  setError(null);
238
246
  onCommit(hex);
239
247
  };
@@ -379,14 +387,16 @@ function VariableValue({
379
387
  const [draft, setDraft] = React.useState(value);
380
388
  const [error, setError] = React.useState<string | null>(null);
381
389
  const commit = async () => {
382
- if (draft === value) return;
383
- if (!HEX.test(draft)) {
390
+ const hex = hexInput(draft);
391
+ if (hex === value) return;
392
+ if (!hex) {
384
393
  setError(BAD_HEX);
385
394
  return;
386
395
  }
387
396
  setError(null);
397
+ setDraft(hex);
388
398
  try {
389
- await onCommit(draft);
399
+ await onCommit(hex);
390
400
  } catch (failure) {
391
401
  setError(errorText(failure));
392
402
  }
@@ -426,11 +436,12 @@ function NewVariable({
426
436
  const [busy, setBusy] = React.useState(false);
427
437
  const create = async () => {
428
438
  if (!name.trim()) return setError("Enter a name for the variable.");
429
- if (!HEX.test(hex)) return setError(BAD_HEX);
439
+ const typed = hexInput(hex);
440
+ if (!typed) return setError(BAD_HEX);
430
441
  setError(null);
431
442
  setBusy(true);
432
443
  try {
433
- await onCreate(name.trim(), hex);
444
+ await onCreate(name.trim(), typed);
434
445
  } catch (failure) {
435
446
  setError(errorText(failure));
436
447
  setBusy(false);
@@ -586,7 +586,7 @@ function KnownElementPanel({
586
586
  <>
587
587
  <HtmlIdField node={node} layout={layout} onChange={onChange} />
588
588
  <DirectionField node={node} onChange={onChange} />
589
- {"children" in node && <ContainerQueryFields node={node} onChange={onChange} />}
589
+ <ContainerQueryFields node={node} onChange={onChange} />
590
590
  <AttributesEditor
591
591
  attributes={node.attributes}
592
592
  onChange={(attributes) => onChange({ ...node, attributes })}
@@ -7,10 +7,12 @@ import {
7
7
  typeScale,
8
8
  type DesignSystem,
9
9
  } from "../../../core/index.ts";
10
+ import { fieldNumber } from "./settings/number-input.ts";
10
11
 
12
+ // W-436: the fields are labelled "(px)", so "18px" is 18.
11
13
  const num = (text: string): number | undefined => {
12
- const n = Number(text);
13
- return text.trim() !== "" && Number.isFinite(n) ? n : undefined;
14
+ const n = fieldNumber(text, "px");
15
+ return Number.isFinite(n) ? n : undefined;
14
16
  };
15
17
 
16
18
  /**
@@ -30,6 +30,16 @@ export function parseHex(hex: string): Rgba | null {
30
30
  return { r, g, b, a };
31
31
  }
32
32
 
33
+ /**
34
+ * W-434: a typed or pasted hex as stored, or undefined. Spaces are trimmed and a missing "#" is
35
+ * added, since design tools (Figma among them) copy "1A2B3C" without it.
36
+ */
37
+ export function hexInput(text: string): string | undefined {
38
+ const trimmed = text.trim();
39
+ const hex = trimmed.startsWith("#") ? trimmed : `#${trimmed}`;
40
+ return HEX.test(hex) ? hex : undefined;
41
+ }
42
+
33
43
  /** 6 digits when opaque, 8 when not. */
34
44
  export function toHex({ r, g, b, a }: Rgba): string {
35
45
  const hex = [r, g, b].map((n) => channel(n).toString(16).padStart(2, "0")).join("");
@@ -52,7 +62,8 @@ export function parseRgb(text: string): Rgba | null {
52
62
  .trim()
53
63
  .replace(/^rgba?\(/i, "")
54
64
  .replace(/\)$/, "")
55
- .split(/[\s,]+/)
65
+ // W-435: CSS's own "rgb(0 0 0 / 50%)", as DevTools copies it, puts a slash before alpha.
66
+ .split(/[\s,/]+/)
56
67
  .filter(Boolean);
57
68
  if (parts.length !== 3 && parts.length !== 4) return null;
58
69
  const nums = parts.slice(0, 3).map((part) => Number(part));