@perkyzz/emvb 0.3.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 (163) hide show
  1. package/README.md +22 -4
  2. package/THIRD_PARTY_NOTICES.md +1 -1
  3. package/package.json +5 -2
  4. package/src/admin/access/role.ts +9 -3
  5. package/src/admin/agents-api.ts +39 -0
  6. package/src/admin/api.ts +17 -7
  7. package/src/admin/content-api.ts +7 -51
  8. package/src/admin/content-item.ts +22 -0
  9. package/src/admin/design-api.ts +30 -0
  10. package/src/admin/editor/A11yCopilot.tsx +1 -1
  11. package/src/admin/editor/CommandPalette.tsx +43 -2
  12. package/src/admin/editor/Editor.tsx +133 -332
  13. package/src/admin/editor/EditorOverlay.tsx +3 -1
  14. package/src/admin/editor/PerfMeter.tsx +1 -1
  15. package/src/admin/editor/ShortcutsDialog.tsx +4 -1
  16. package/src/admin/editor/Timeline.tsx +124 -9
  17. package/src/admin/editor/canvas/CanvasFrame.tsx +51 -368
  18. package/src/admin/editor/canvas/DeviceBar.tsx +4 -1
  19. package/src/admin/editor/canvas/SelectionOverlay.tsx +86 -46
  20. package/src/admin/editor/canvas/canvas-scale.ts +20 -0
  21. package/src/admin/editor/canvas/drop-line.ts +24 -0
  22. package/src/admin/editor/canvas/use-canvas-dnd.ts +207 -0
  23. package/src/admin/editor/canvas/use-canvas-session.ts +216 -0
  24. package/src/admin/editor/collection-previews.ts +28 -5
  25. package/src/admin/editor/editor-chrome.tsx +346 -0
  26. package/src/admin/editor/editor-commands.ts +360 -0
  27. package/src/admin/editor/editor-css.ts +4 -0
  28. package/src/admin/editor/element-chrome.ts +89 -0
  29. package/src/admin/editor/feature-css.ts +37 -18
  30. package/src/admin/editor/host.ts +33 -0
  31. package/src/admin/editor/icons/IconLibraryDialog.tsx +64 -218
  32. package/src/admin/editor/icons/library.ts +29 -19
  33. package/src/admin/editor/icons/use-icon-library.ts +315 -0
  34. package/src/admin/editor/palette-items.ts +36 -5
  35. package/src/admin/editor/palette.ts +9 -4
  36. package/src/admin/editor/panels/AddPanel.tsx +2 -67
  37. package/src/admin/editor/panels/ColorControl.tsx +21 -18
  38. package/src/admin/editor/panels/ElementPanel.tsx +40 -99
  39. package/src/admin/editor/panels/LayersPanel.tsx +34 -62
  40. package/src/admin/editor/panels/SettingsPanel.tsx +1 -0
  41. package/src/admin/editor/panels/SiteStylesDrawer.tsx +16 -10
  42. package/src/admin/editor/panels/TokenScales.tsx +4 -2
  43. package/src/admin/editor/panels/VariableSection.tsx +1 -10
  44. package/src/admin/editor/panels/color-space.ts +12 -1
  45. package/src/admin/editor/panels/inline-error.tsx +11 -0
  46. package/src/admin/editor/panels/settings/AdvancedFields.tsx +143 -1
  47. package/src/admin/editor/panels/settings/AudienceEditor.tsx +115 -7
  48. package/src/admin/editor/panels/settings/DraftTextField.tsx +42 -9
  49. package/src/admin/editor/panels/settings/FieldControl.tsx +6 -0
  50. package/src/admin/editor/panels/settings/FormBindControl.tsx +8 -4
  51. package/src/admin/editor/panels/settings/IconPicker.tsx +21 -1
  52. package/src/admin/editor/panels/settings/ImageSourcesField.tsx +111 -0
  53. package/src/admin/editor/panels/settings/ItemList.tsx +34 -1
  54. package/src/admin/editor/panels/settings/MediaPicker.tsx +2 -3
  55. package/src/admin/editor/panels/settings/QueryStyleRows.tsx +178 -0
  56. package/src/admin/editor/panels/settings/StyleRow.tsx +14 -2
  57. package/src/admin/editor/panels/settings/advanced-rules.ts +3 -0
  58. package/src/admin/editor/panels/settings/form-names.ts +7 -11
  59. package/src/admin/editor/panels/settings/length-units.ts +15 -4
  60. package/src/admin/editor/panels/settings/link-rules.ts +19 -0
  61. package/src/admin/editor/panels/settings/number-input.ts +11 -0
  62. package/src/admin/editor/panels/settings/query-style.ts +65 -0
  63. package/src/admin/editor/panels/settings/style-sections.ts +5 -1
  64. package/src/admin/editor/panels/style-target.ts +105 -0
  65. package/src/admin/editor/panels/variable-values.ts +4 -2
  66. package/src/admin/editor/remote-change.ts +67 -0
  67. package/src/admin/editor/section-templates.ts +43 -21
  68. package/src/admin/editor/shortcuts.ts +4 -0
  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 +23 -15
  74. package/src/admin/editor/useNodeActions.ts +6 -1
  75. package/src/admin/forms-api.ts +17 -6
  76. package/src/admin/icon-uploads-api.ts +18 -0
  77. package/src/admin/index.tsx +3 -1
  78. package/src/admin/media-api.ts +20 -0
  79. package/src/admin/pages/AgentsPage.tsx +274 -0
  80. package/src/admin/theme-api.ts +5 -18
  81. package/src/admin/ui.ts +28 -0
  82. package/src/astro/content-port.ts +24 -0
  83. package/src/astro/floats/runtime.ts +10 -0
  84. package/src/astro/forms/EmVBFormsClient.astro +11 -0
  85. package/src/astro/forms/EmVBFormsRuntime.astro +6 -7
  86. package/src/astro/forms/client.ts +1 -0
  87. package/src/astro/forms-definitions.ts +24 -11
  88. package/src/astro/index.ts +1 -0
  89. package/src/astro/popups/runtime.ts +15 -0
  90. package/src/astro/render-session.ts +85 -0
  91. package/src/astro/request-data.ts +20 -8
  92. package/src/astro/resolve-theme.ts +166 -76
  93. package/src/astro/resolve.ts +57 -16
  94. package/src/astro/tabs/runtime.ts +60 -1
  95. package/src/astro/theme-posts.ts +16 -5
  96. package/src/astro/visitor.ts +67 -5
  97. package/src/constants.ts +1 -1
  98. package/src/core/a11y/audit.ts +202 -26
  99. package/src/core/arrange.ts +71 -38
  100. package/src/core/audience/rules.ts +22 -2
  101. package/src/core/canvas-styles.ts +24 -0
  102. package/src/core/clipboard.ts +11 -32
  103. package/src/core/css/generate.ts +18 -1
  104. package/src/core/css/print.ts +12 -0
  105. package/src/core/css/scope.ts +3 -3
  106. package/src/core/css-keywords.ts +83 -0
  107. package/src/core/data/bindings.ts +4 -6
  108. package/src/core/design/classes.ts +13 -15
  109. package/src/core/design/diff.ts +55 -0
  110. package/src/core/design/merge.ts +127 -0
  111. package/src/core/design/variables.ts +25 -21
  112. package/src/core/elements/dynamic-elements.ts +30 -0
  113. package/src/core/elements/form-elements.ts +20 -3
  114. package/src/core/elements/index.ts +211 -7
  115. package/src/core/forms/binding.ts +4 -13
  116. package/src/core/index.ts +10 -0
  117. package/src/core/local-style.ts +27 -0
  118. package/src/core/migrate/index.ts +9 -4
  119. package/src/core/nesting.ts +4 -23
  120. package/src/core/perf/scripts.ts +9 -6
  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 +22 -7
  124. package/src/core/render/form.ts +145 -15
  125. package/src/core/render/index.ts +195 -14
  126. package/src/core/render/pagination.ts +21 -2
  127. package/src/core/render/vnode.ts +12 -2
  128. package/src/core/sanitize/css.ts +90 -77
  129. package/src/core/sanitize/embed-url.ts +7 -1
  130. package/src/core/sanitize/href.ts +13 -1
  131. package/src/core/sanitize/svg.ts +8 -3
  132. package/src/core/sanitize/url.ts +10 -1
  133. package/src/core/schema/descriptors.ts +4 -1
  134. package/src/core/schema/design.ts +5 -7
  135. package/src/core/schema/layout.ts +160 -181
  136. package/src/core/schema/style.ts +53 -63
  137. package/src/core/share/link.ts +72 -29
  138. package/src/core/tabs/presence.ts +7 -17
  139. package/src/core/theme/dynamic.ts +205 -39
  140. package/src/core/theme/float.ts +1 -1
  141. package/src/core/tree-ops.ts +57 -0
  142. package/src/index.ts +14 -2
  143. package/src/mcp/errors.ts +44 -0
  144. package/src/mcp/index.ts +4 -0
  145. package/src/mcp/ports.ts +78 -0
  146. package/src/mcp/prompts.ts +76 -0
  147. package/src/mcp/publish.ts +60 -0
  148. package/src/mcp/queue.ts +19 -0
  149. package/src/mcp/rate-limit.ts +80 -0
  150. package/src/mcp/read.ts +419 -0
  151. package/src/mcp/refs.ts +84 -0
  152. package/src/mcp/settings.ts +18 -0
  153. package/src/mcp/tools.ts +265 -0
  154. package/src/mcp/write.ts +582 -0
  155. package/src/server/agent-settings.ts +134 -0
  156. package/src/server/design-routes.ts +75 -18
  157. package/src/server/icon-routes.ts +72 -16
  158. package/src/server/mcp-routes.ts +265 -0
  159. package/src/server/plugin.ts +40 -4
  160. package/src/admin/editor/icons/sets/fontawesome.json +0 -1
  161. package/src/admin/editor/icons/sets/lucide.json +0 -1
  162. package/src/admin/editor/icons/sets/remix.json +0 -1
  163. package/src/admin/editor/icons/sets/tabler.json +0 -1
@@ -0,0 +1,274 @@
1
+ import { Banner, ClipboardText, Empty, Loader, Switch, Table } from "@cloudflare/kumo";
2
+ import {
3
+ ArrowSquareOutIcon,
4
+ GlobeIcon,
5
+ LockKeyIcon,
6
+ PlugsConnectedIcon,
7
+ RobotIcon,
8
+ ShieldCheckIcon,
9
+ TerminalWindowIcon,
10
+ UploadSimpleIcon,
11
+ WarningCircleIcon,
12
+ type Icon,
13
+ } from "@phosphor-icons/react";
14
+ import type { ReactNode } from "react";
15
+ import { useEffect, useState } from "react";
16
+ import { defaultFetcher, type Fetcher } from "../api.ts";
17
+ import { loadAgents, saveAgentSettings, type AgentsState } from "../agents-api.ts";
18
+ import { useRole } from "../access/role.ts";
19
+ import { editorUrl } from "../editor/exit.ts";
20
+ import type { AgentSettings } from "../../mcp/settings.ts";
21
+ import { UI_CSS } from "../ui.ts";
22
+
23
+ const ADMIN_ROLE = 50;
24
+
25
+ /** The stdio bridge config a person pastes into their MCP client (plan § 4). */
26
+ const stdioSnippet = (site: string) =>
27
+ JSON.stringify(
28
+ {
29
+ mcpServers: {
30
+ emvb: {
31
+ command: "npx",
32
+ args: ["-y", "@perkyzz/emvb-mcp", "--site", site],
33
+ env: { EMVB_TOKEN: "<your EmDash API token>" },
34
+ },
35
+ },
36
+ },
37
+ null,
38
+ 2,
39
+ );
40
+
41
+ const remoteSnippet = (endpoint: string) =>
42
+ JSON.stringify({ mcpServers: { emvb: { url: endpoint } } }, null, 2);
43
+
44
+ /** A card's heading row: an icon tile, the title and one line on what the card is for (W-477). */
45
+ function SectionHead({
46
+ id,
47
+ icon: SectionIcon,
48
+ title,
49
+ children,
50
+ }: {
51
+ id: string;
52
+ icon: Icon;
53
+ title: string;
54
+ children: ReactNode;
55
+ }) {
56
+ return (
57
+ <div className="emvb-agents-head">
58
+ <span className="emvb-agents-icon" aria-hidden="true">
59
+ <SectionIcon size={18} />
60
+ </span>
61
+ <div>
62
+ <h2 id={id}>{title}</h2>
63
+ <p>{children}</p>
64
+ </div>
65
+ </div>
66
+ );
67
+ }
68
+
69
+ /** AI agents (`/agents`, W-463): the master switch, publishing, how to connect, recent activity. */
70
+ export function AgentsPage({ fetcher = defaultFetcher }: { fetcher?: Fetcher }) {
71
+ const role = useRole(fetcher);
72
+ const [state, setState] = useState<AgentsState | null>(null);
73
+ const [error, setError] = useState<string | null>(null);
74
+ const [saving, setSaving] = useState(false);
75
+ const isAdmin = role.state === "ready" && role.role >= ADMIN_ROLE;
76
+
77
+ useEffect(() => {
78
+ if (!isAdmin) return;
79
+ loadAgents(fetcher)
80
+ .then(setState)
81
+ .catch((e: unknown) => setError(e instanceof Error ? e.message : String(e)));
82
+ }, [fetcher, isAdmin]);
83
+
84
+ if (role.state === "loading") return <Loader />;
85
+ if (!isAdmin) {
86
+ return (
87
+ <section data-emvb-access="denied">
88
+ <Empty
89
+ icon={<LockKeyIcon aria-hidden="true" />}
90
+ title="Only administrators can manage AI agents"
91
+ description="Ask an administrator to change these settings."
92
+ />
93
+ </section>
94
+ );
95
+ }
96
+ if (error) {
97
+ return (
98
+ <Banner
99
+ variant="error"
100
+ icon={<WarningCircleIcon aria-hidden="true" />}
101
+ title="Couldn't load the AI agent settings"
102
+ description={error}
103
+ />
104
+ );
105
+ }
106
+ if (!state) return <Loader />;
107
+
108
+ const change = async (patch: Partial<AgentSettings>) => {
109
+ const settings = { ...state.settings, ...patch };
110
+ setSaving(true);
111
+ try {
112
+ const revision = await saveAgentSettings(fetcher, settings, state.revision);
113
+ setState({ ...state, settings, revision });
114
+ } catch (e) {
115
+ setError(e instanceof Error ? e.message : String(e));
116
+ } finally {
117
+ setSaving(false);
118
+ }
119
+ };
120
+ const site = new URL(state.endpoint).origin;
121
+ const { settings } = state;
122
+
123
+ return (
124
+ <div className="emvb-pages emvb-agents" data-emvb-agents="ready">
125
+ <style>{UI_CSS}</style>
126
+ <header className="emvb-agents-header">
127
+ <div>
128
+ <h1 className="emvb-page-title">AI agents</h1>
129
+ <p>Let AI assistants build and edit EmVB pages through MCP. They only change drafts.</p>
130
+ </div>
131
+ <span className="emvb-agents-status" data-on={settings.mcpEnabled ? "true" : "false"}>
132
+ <span aria-hidden="true" />
133
+ {settings.mcpEnabled ? "Agents on" : "Agents off"}
134
+ </span>
135
+ </header>
136
+ <section
137
+ className="emvb-surface-card emvb-agents-section"
138
+ aria-labelledby="emvb-agents-access"
139
+ >
140
+ <SectionHead id="emvb-agents-access" icon={ShieldCheckIcon} title="Access">
141
+ The master switch. Turning it off refuses every agent call at once.
142
+ </SectionHead>
143
+ <div className="emvb-agents-option">
144
+ <Switch
145
+ label="Let AI agents edit EmVB pages"
146
+ checked={settings.mcpEnabled}
147
+ disabled={saving}
148
+ onCheckedChange={(checked: boolean) => void change({ mcpEnabled: checked })}
149
+ />
150
+ <p>
151
+ Agents only change drafts. Every change shows in the page's version timeline and can be
152
+ restored.
153
+ </p>
154
+ </div>
155
+ <div className="emvb-agents-field">
156
+ <h3>MCP endpoint</h3>
157
+ <ClipboardText text={state.endpoint} />
158
+ </div>
159
+ </section>
160
+ <section
161
+ className="emvb-surface-card emvb-agents-section"
162
+ aria-labelledby="emvb-agents-publish"
163
+ >
164
+ <SectionHead id="emvb-agents-publish" icon={UploadSimpleIcon} title="Publishing">
165
+ Published changes go live immediately. Each one is still in the version timeline.
166
+ </SectionHead>
167
+ <div className="emvb-agents-option">
168
+ <Switch
169
+ label="Agents may publish pages"
170
+ checked={settings.publishPages}
171
+ disabled={saving || !settings.mcpEnabled}
172
+ onCheckedChange={(checked: boolean) => void change({ publishPages: checked })}
173
+ />
174
+ <p>Off: agents save drafts and a person publishes them.</p>
175
+ </div>
176
+ <div className="emvb-agents-option">
177
+ <Switch
178
+ label="Agents may publish site styles"
179
+ checked={settings.publishStyles}
180
+ disabled={saving || !settings.mcpEnabled}
181
+ onCheckedChange={(checked: boolean) => void change({ publishStyles: checked })}
182
+ />
183
+ <p>Site styles change every page at once, so leave this off unless you need it.</p>
184
+ </div>
185
+ </section>
186
+ <section
187
+ className="emvb-surface-card emvb-agents-section"
188
+ aria-labelledby="emvb-agents-connect"
189
+ >
190
+ <SectionHead id="emvb-agents-connect" icon={PlugsConnectedIcon} title="How to connect">
191
+ Create a token in EmDash → API tokens with the scope <code>mcp:tools:emvb</code> for a
192
+ user who is an editor or above. Never give an agent an admin token.
193
+ </SectionHead>
194
+ <div className="emvb-agents-snippets">
195
+ <div className="emvb-agents-snippet">
196
+ <h3>
197
+ <GlobeIcon aria-hidden="true" size={16} />
198
+ Remote (EmDash MCP, sign in with OAuth)
199
+ </h3>
200
+ <pre data-emvb-snippet="remote">{remoteSnippet(state.endpoint)}</pre>
201
+ </div>
202
+ <div className="emvb-agents-snippet">
203
+ <h3>
204
+ <TerminalWindowIcon aria-hidden="true" size={16} />
205
+ Local (stdio)
206
+ </h3>
207
+ <pre data-emvb-snippet="stdio">{stdioSnippet(site)}</pre>
208
+ </div>
209
+ </div>
210
+ </section>
211
+ <section
212
+ className="emvb-surface-card emvb-agents-section"
213
+ aria-labelledby="emvb-agents-activity"
214
+ >
215
+ <SectionHead id="emvb-agents-activity" icon={RobotIcon} title="Recent agent activity">
216
+ The latest changes agents made, newest first.
217
+ </SectionHead>
218
+ {state.activity.length === 0 ? (
219
+ <div data-emvb-agents-empty="">
220
+ <Empty
221
+ icon={<RobotIcon aria-hidden="true" />}
222
+ title="No agent changes yet"
223
+ description="When an agent edits a page, it shows up here with a link to the editor."
224
+ />
225
+ </div>
226
+ ) : (
227
+ <div className="emvb-agents-table">
228
+ <Table>
229
+ <Table.Header>
230
+ <Table.Row>
231
+ <Table.Head>When</Table.Head>
232
+ <Table.Head>Who</Table.Head>
233
+ <Table.Head>Change</Table.Head>
234
+ <Table.Head>Page</Table.Head>
235
+ </Table.Row>
236
+ </Table.Header>
237
+ <Table.Body>
238
+ {state.activity.map((entry) => (
239
+ <Table.Row key={entry.id}>
240
+ <Table.Cell>
241
+ <span className="emvb-agents-when">
242
+ {new Date(entry.at).toLocaleString()}
243
+ </span>
244
+ </Table.Cell>
245
+ <Table.Cell>
246
+ <span className="emvb-agents-who">
247
+ <span className="emvb-timeline-agent">
248
+ <RobotIcon aria-hidden="true" size={12} />
249
+ {entry.client ?? "Agent"}
250
+ </span>
251
+ {entry.userId ?? "unknown"}
252
+ </span>
253
+ </Table.Cell>
254
+ <Table.Cell>{entry.summary}</Table.Cell>
255
+ <Table.Cell>
256
+ {entry.pageId ? (
257
+ <a className="emvb-agents-link" href={editorUrl(entry.pageId)}>
258
+ Open in editor
259
+ <ArrowSquareOutIcon aria-hidden="true" size={14} />
260
+ </a>
261
+ ) : (
262
+ "—"
263
+ )}
264
+ </Table.Cell>
265
+ </Table.Row>
266
+ ))}
267
+ </Table.Body>
268
+ </Table>
269
+ </div>
270
+ )}
271
+ </section>
272
+ </div>
273
+ );
274
+ }
@@ -15,20 +15,12 @@ import {
15
15
  } from "../core/index.ts";
16
16
  import { THEME_PARTS_COLLECTION } from "../constants.ts";
17
17
  import { listAllItems, requestJson, type Fetcher } from "./api.ts";
18
+ import { titleOf, type ContentItem } from "./content-item.ts";
18
19
  import { publishEntry } from "./content-api.ts";
19
20
  import { entryStatus } from "./entry-status.ts";
20
21
 
21
22
  const CONTENT = `/_emdash/api/content/${THEME_PARTS_COLLECTION}`;
22
23
 
23
- type RawItem = {
24
- id: string;
25
- slug?: string | null;
26
- status?: string;
27
- draftRevisionId?: string | null;
28
- updatedAt?: string;
29
- data?: Record<string, unknown>;
30
- };
31
-
32
24
  export type ThemePartSummary = {
33
25
  id: string;
34
26
  title: string;
@@ -48,12 +40,7 @@ export type ThemePartDraft = {
48
40
  layout: Layout | null;
49
41
  };
50
42
 
51
- const titleOf = (item: RawItem) =>
52
- typeof item.data?.["title"] === "string" && item.data["title"]
53
- ? item.data["title"]
54
- : "Untitled theme part";
55
-
56
- function partTypeOf(item: RawItem): ThemePartType {
43
+ function partTypeOf(item: ContentItem): ThemePartType {
57
44
  return parseThemePartType(item.data?.["part_type"]) ?? "header";
58
45
  }
59
46
 
@@ -132,10 +119,10 @@ export function summarizeConditions(raw: unknown): string {
132
119
  }
133
120
 
134
121
  export async function listThemeParts(fetcher: Fetcher): Promise<ThemePartSummary[]> {
135
- const items = await listAllItems<RawItem>(fetcher, CONTENT);
122
+ const items = await listAllItems<ContentItem>(fetcher, CONTENT);
136
123
  return items.map((item) => ({
137
124
  id: item.id,
138
- title: titleOf(item),
125
+ title: titleOf(item, "Untitled theme part"),
139
126
  partType: partTypeOf(item),
140
127
  status: entryStatus(item),
141
128
  updatedAt: item.updatedAt ?? "",
@@ -164,7 +151,7 @@ export async function createThemePart(
164
151
  fetcher: Fetcher,
165
152
  input: { title: string; slug: string; partType: ThemePartType },
166
153
  ): Promise<string> {
167
- const body = await requestJson<{ item: RawItem }>(fetcher, CONTENT, {
154
+ const body = await requestJson<{ item: ContentItem }>(fetcher, CONTENT, {
168
155
  method: "POST",
169
156
  body: {
170
157
  data: {
package/src/admin/ui.ts CHANGED
@@ -91,6 +91,34 @@ export const UI_CSS = `
91
91
  backdrop-filter: blur(var(--emvb-glass-blur, 6px));
92
92
  box-shadow: var(--emvb-elevation-s);
93
93
  }
94
+ /* Live MCP test: the AI agents page reads as cards with clear headings, not bare browser defaults. */
95
+ .emvb-agents { max-width: 960px; }
96
+ .emvb-agents-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
97
+ .emvb-agents-header p { margin: 4px 0 0; font-size: 14px; line-height: 20px; color: var(--text-color-kumo-subtle); }
98
+ .emvb-agents-status { display: inline-flex; flex: none; align-items: center; gap: 6px; margin-top: 6px; padding: 2px 10px; border: 1px solid var(--color-kumo-line); border-radius: 999px; background: var(--color-kumo-base); color: var(--text-color-kumo-default); font-size: 12px; line-height: 20px; font-weight: 600; }
99
+ .emvb-agents-status > span { width: 8px; height: 8px; border-radius: 999px; background: var(--text-color-kumo-subtle); }
100
+ .emvb-agents-status[data-on="true"] > span { background: var(--text-color-kumo-success); }
101
+ .emvb-agents-section { gap: 16px; padding: 20px; }
102
+ .emvb-agents-head { display: flex; align-items: flex-start; gap: 12px; }
103
+ .emvb-agents-icon { display: grid; flex: none; place-items: center; width: 36px; height: 36px; border-radius: 10px; background: var(--color-kumo-tint); color: var(--text-color-kumo-default); }
104
+ .emvb-agents-section h2 { margin: 0; font-size: 16px; line-height: 24px; font-weight: 600; color: var(--text-color-kumo-default); }
105
+ .emvb-agents-section h3 { display: flex; align-items: center; gap: 6px; margin: 0; font-size: 13px; line-height: 20px; font-weight: 600; color: var(--text-color-kumo-default); }
106
+ .emvb-agents-section p { margin: 0; font-size: 14px; line-height: 20px; color: var(--text-color-kumo-subtle); }
107
+ .emvb-agents-section code { padding: 1px 5px; border-radius: 4px; background: var(--color-kumo-tint); font-family: var(--font-mono); font-size: 12px; }
108
+ .emvb-agents-option { display: grid; gap: 4px; padding-top: 16px; border-top: 1px solid var(--color-kumo-line); }
109
+ .emvb-agents-option > p { padding-inline-start: 44px; font-size: 13px; }
110
+ .emvb-agents-field { display: grid; gap: 6px; }
111
+ .emvb-agents-snippets { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 12px; }
112
+ .emvb-agents-snippet { display: grid; align-content: start; gap: 8px; min-width: 0; padding: 12px; border: 1px solid var(--color-kumo-line); border-radius: 8px; }
113
+ .emvb-agents-section pre { margin: 0; padding: 12px; overflow-x: auto; border-radius: 6px; background: var(--color-kumo-recessed, rgba(127,127,127,.08)); font-family: var(--font-mono); font-size: 12px; line-height: 18px; }
114
+ .emvb-agents-table { overflow-x: auto; margin-inline: -20px; margin-bottom: -20px; border-top: 1px solid var(--color-kumo-line); }
115
+ .emvb-agents-table table { width: 100%; }
116
+ .emvb-agents-when { color: var(--text-color-kumo-subtle); font-variant-numeric: tabular-nums; white-space: nowrap; }
117
+ .emvb-agents-who { display: inline-flex; align-items: center; gap: 8px; white-space: nowrap; }
118
+ .emvb-agents-link { display: inline-flex; align-items: center; gap: 4px; color: var(--text-color-kumo-link, var(--text-color-kumo-brand)); font-weight: 500; white-space: nowrap; }
119
+ .emvb-agents-link:hover { text-decoration: underline; }
120
+ .emvb-agents-link:focus-visible { outline: 2px solid var(--color-kumo-brand); outline-offset: 2px; border-radius: 4px; }
121
+ .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; }
94
122
  .emvb-surface-card[data-emvb-list] { gap: 0; padding: 0; overflow: hidden; }
95
123
  .emvb-surface-card[data-emvb-list] table { width: 100%; }
96
124
  .emvb-surface-card .emvb-empty-shell,
@@ -0,0 +1,24 @@
1
+ import { decodeSlug, getEmDashCollection, getEmDashEntry, getSiteSettings, getTerm } from "emdash";
2
+ import { getPublicPluginApiRouteHandler } from "emdash/plugin-utils";
3
+
4
+ /**
5
+ * How the Astro adapter reads EmDash content (W-359). The default calls EmDash.
6
+ * Tests pass a fake. This is not a host export.
7
+ */
8
+ export type ContentPort = {
9
+ decodeSlug: typeof decodeSlug;
10
+ getEntry: typeof getEmDashEntry;
11
+ getCollection: typeof getEmDashCollection;
12
+ getTerm: typeof getTerm;
13
+ getSiteSettings: typeof getSiteSettings;
14
+ pluginHandler: typeof getPublicPluginApiRouteHandler;
15
+ };
16
+
17
+ export const emdashContent: ContentPort = {
18
+ decodeSlug,
19
+ getEntry: getEmDashEntry,
20
+ getCollection: getEmDashCollection,
21
+ getTerm,
22
+ getSiteSettings,
23
+ pluginHandler: getPublicPluginApiRouteHandler,
24
+ };
@@ -59,6 +59,10 @@ function hide(el: HTMLElement): void {
59
59
 
60
60
  /** Hide floats already closed this visit, then keep bars stacked. */
61
61
  export function initFloats(): void {
62
+ // W-407: a second call (a host loading the script twice) added a second click handler.
63
+ const marked = document.documentElement;
64
+ if (marked.dataset["emvbFloatsReady"] === "1") return;
65
+ marked.dataset["emvbFloatsReady"] = "1";
62
66
  for (const el of bars()) {
63
67
  const id = el.getAttribute("data-emvb-float");
64
68
  if (id && closed(id)) el.hidden = true;
@@ -75,4 +79,10 @@ export function initFloats(): void {
75
79
  hide(float);
76
80
  });
77
81
  window.addEventListener("resize", placeFloats);
82
+ // W-407: a bar's height also changes without a window resize (web fonts arriving, text
83
+ // wrapping once styles load), which left the reserved padding short and the bar over content.
84
+ if (typeof ResizeObserver === "function") {
85
+ const observer = new ResizeObserver(() => placeFloats());
86
+ for (const el of bars()) observer.observe(el);
87
+ }
78
88
  }
@@ -0,0 +1,11 @@
1
+ ---
2
+ // The forms plugin's client script (D-015). Rendered only by hosts that import
3
+ // `@perkyzz/emvb/astro/forms/client` and have `@emdash-cms/plugin-forms` installed.
4
+ // It loads on pages that contain a form (R-031); other pages never render this component.
5
+ ---
6
+
7
+ <script>
8
+ import { initForms } from "@emdash-cms/plugin-forms/client";
9
+
10
+ initForms();
11
+ </script>
@@ -1,9 +1,8 @@
1
1
  ---
2
- // The forms plugin's client (D-015). Hosts render this only when a page `needsFormsRuntime`,
3
- // so pages without forms stay zero-JS (R-031). Form elements arrive in S5.
2
+ /**
3
+ * Safe forms slot (W-332). This file does not import `@emdash-cms/plugin-forms`.
4
+ * A host without that plugin can import `@perkyzz/emvb/astro/forms` and the build still succeeds.
5
+ * Hosts that have the plugin import `@perkyzz/emvb/astro/forms/client` instead, which calls
6
+ * `initForms`. Rendering this component does nothing.
7
+ */
4
8
  ---
5
-
6
- <script>
7
- import { initForms } from "@emdash-cms/plugin-forms/client";
8
- initForms();
9
- </script>
@@ -0,0 +1 @@
1
+ export { default as EmVBFormsRuntime } from "./EmVBFormsClient.astro";
@@ -3,29 +3,31 @@ import {
3
3
  isFormNode,
4
4
  type FormDefinitions,
5
5
  type Layout,
6
- type LayoutNode,
7
6
  type PublicFormDefinition,
8
7
  type PublicFormField,
9
8
  } from "../core/index.ts";
10
- import { nodeChildren } from "../core/tree-ops.ts";
9
+ import { isRecord } from "../core/record.ts";
10
+ import { forEachNode } from "../core/tree-ops.ts";
11
11
 
12
12
  const FORMS_PLUGIN = "emdash-forms";
13
13
 
14
- function walk(node: LayoutNode, visit: (node: LayoutNode) => void): void {
15
- visit(node);
16
- for (const child of nodeChildren(node)) walk(child, visit);
17
- }
18
-
19
14
  export function formIdsInLayout(layout: Layout): string[] {
20
15
  const ids = new Set<string>();
21
- walk(layout.root, (node) => {
16
+ forEachNode(layout.root, (node) => {
22
17
  if (isFormNode(node) && node.props.formId) ids.add(node.props.formId);
23
18
  });
24
19
  return [...ids];
25
20
  }
26
21
 
27
- const isRecord = (value: unknown): value is Record<string, unknown> =>
28
- !!value && typeof value === "object" && !Array.isArray(value);
22
+ /** Form ids in a page and in the synced sections and loop items it renders. */
23
+ export function formIdsInLayouts(layouts: readonly (Layout | null | undefined)[]): string[] {
24
+ const ids = new Set<string>();
25
+ for (const layout of layouts) {
26
+ if (!layout) continue;
27
+ for (const id of formIdsInLayout(layout)) ids.add(id);
28
+ }
29
+ return [...ids];
30
+ }
29
31
 
30
32
  const isOption = (value: unknown): value is { label: string; value: string } =>
31
33
  isRecord(value) && typeof value.label === "string" && typeof value.value === "string";
@@ -95,6 +97,17 @@ function asDefinition(payload: unknown): PublicFormDefinition | null {
95
97
  return { ...(def as PublicFormDefinition), pages, settings };
96
98
  }
97
99
 
100
+ /**
101
+ * W-326: the forms plugin answers a paused form's definition with `FORM_PAUSED` (410), so the
102
+ * page can say the form isn't accepting responses instead of rendering empty fields.
103
+ */
104
+ function asPaused(payload: unknown, formId: string): PublicFormDefinition | null {
105
+ if (!isRecord(payload) || payload.success !== false) return null;
106
+ const error = isRecord(payload.error) ? payload.error : {};
107
+ if (error.code !== "FORM_PAUSED" && payload.status !== 410) return null;
108
+ return { name: "", slug: formId, status: "paused", pages: [], settings: {} };
109
+ }
110
+
98
111
  /** Loads public form definitions in-process (D-015). Missing forms are omitted. */
99
112
  export async function loadFormDefinitions(
100
113
  handler: PublicPluginApiRouteHandler | undefined,
@@ -115,7 +128,7 @@ export async function loadFormDefinitions(
115
128
  },
116
129
  );
117
130
  const response = await handler(FORMS_PLUGIN, "POST", "/definition", request);
118
- const def = asDefinition(response);
131
+ const def = asDefinition(response) ?? asPaused(response, formId);
119
132
  if (def) map.set(formId, def);
120
133
  } catch {
121
134
  // Forms plugin missing or form unknown — render without definition options.
@@ -1,5 +1,6 @@
1
1
  export { default as EmVBPage } from "./EmVBPage.astro";
2
2
  export { resolveEmVBPage, type ResolvedEmVBPage } from "./resolve.ts";
3
+ export type { HostVisitor } from "./visitor.ts";
3
4
  export {
4
5
  resolveThemeParts,
5
6
  type RenderedThemePart,
@@ -177,6 +177,21 @@ function bindA11y(ctrl: Controller): void {
177
177
  ctrl.close();
178
178
  }
179
179
  });
180
+ // W-406: when the focused control disappears (a form swapped for its thank-you message), focus
181
+ // falls to <body>; Escape and Tab then never reached the dialog, so the popup couldn't be closed
182
+ // from the keyboard and Tab walked the page behind it.
183
+ document.addEventListener("keydown", (event) => {
184
+ if (!ctrl.opened || event.defaultPrevented || !ctrl.root.isConnected) return;
185
+ const active = document.activeElement;
186
+ if (active && active !== document.body && active !== document.documentElement) return;
187
+ if (event.key === "Tab") {
188
+ event.preventDefault();
189
+ (focusables(ctrl.dialog)[0] ?? ctrl.dialog).focus();
190
+ } else if (event.key === "Escape") {
191
+ event.preventDefault();
192
+ ctrl.close();
193
+ }
194
+ });
180
195
  ctrl.dialog.addEventListener("keydown", (event) => {
181
196
  if (event.key === "Escape") {
182
197
  event.preventDefault();
@@ -0,0 +1,85 @@
1
+ import type { PublicPluginApiRouteHandler } from "emdash/plugin-utils";
2
+ import type { DesignSystem, FormDefinitions, Layout, PublicFormDefinition } from "../core/index.ts";
3
+ import { loadFormDefinitions } from "./forms-definitions.ts";
4
+ import { loadDesign, readLayout } from "./render.ts";
5
+
6
+ /**
7
+ * One request's shared reads (W-360). Keyed by the Astro object the host passes to both
8
+ * `resolveEmVBPage` and `resolveThemeParts`. A different object is a different request.
9
+ */
10
+ type Session = {
11
+ design?: Promise<DesignSystem>;
12
+ site?: Promise<unknown>;
13
+ parts?: Promise<unknown>;
14
+ forms: Map<string, Promise<PublicFormDefinition | null>>;
15
+ layouts: Map<string, Layout | null>;
16
+ };
17
+
18
+ const sessions = new WeakMap<object, Session>();
19
+
20
+ function sessionOf(request: object): Session {
21
+ let session = sessions.get(request);
22
+ if (!session) {
23
+ session = { forms: new Map(), layouts: new Map() };
24
+ sessions.set(request, session);
25
+ }
26
+ return session;
27
+ }
28
+
29
+ export function designFor(
30
+ request: object,
31
+ handler: PublicPluginApiRouteHandler | undefined,
32
+ base: URL,
33
+ ): Promise<DesignSystem> {
34
+ const session = sessionOf(request);
35
+ session.design ??= loadDesign(handler, base);
36
+ return session.design;
37
+ }
38
+
39
+ /** Each form id is loaded once per request, including when several parts use it. */
40
+ export function formsFor(
41
+ request: object,
42
+ handler: PublicPluginApiRouteHandler | undefined,
43
+ base: URL,
44
+ formIds: readonly string[],
45
+ ): Promise<FormDefinitions> {
46
+ const session = sessionOf(request);
47
+ return Promise.all(
48
+ formIds.map(async (formId) => {
49
+ let pending = session.forms.get(formId);
50
+ if (!pending) {
51
+ pending = loadFormDefinitions(handler, base, [formId]).then(
52
+ (map) => map.get(formId) ?? null,
53
+ );
54
+ session.forms.set(formId, pending);
55
+ }
56
+ return [formId, await pending] as const;
57
+ }),
58
+ ).then((rows) => {
59
+ const map = new Map<string, PublicFormDefinition>();
60
+ for (const [id, definition] of rows) if (definition) map.set(id, definition);
61
+ return map;
62
+ });
63
+ }
64
+
65
+ export function siteFor<T>(request: object, load: () => Promise<T>): Promise<T> {
66
+ const session = sessionOf(request);
67
+ session.site ??= load();
68
+ return session.site as Promise<T>;
69
+ }
70
+
71
+ export function partsFor<T>(request: object, load: () => Promise<T>): Promise<T> {
72
+ const session = sessionOf(request);
73
+ session.parts ??= load();
74
+ return session.parts as Promise<T>;
75
+ }
76
+
77
+ /** A theme part's layout, parsed once per request. */
78
+ export function layoutFor(request: object | undefined, id: string, raw: unknown): Layout | null {
79
+ if (!request) return readLayout(raw);
80
+ const layouts = sessionOf(request).layouts;
81
+ if (layouts.has(id)) return layouts.get(id) ?? null;
82
+ const layout = readLayout(raw);
83
+ layouts.set(id, layout);
84
+ return layout;
85
+ }