@perkyzz/emvb 0.8.0 → 1.0.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.
- package/README.md +3 -3
- package/package.json +4 -4
- package/src/admin/agents-api.ts +45 -0
- package/src/admin/editor/A11yCopilot.tsx +1 -1
- package/src/admin/editor/Editor.tsx +325 -239
- package/src/admin/editor/FieldPreview.tsx +164 -0
- package/src/admin/editor/Timeline.tsx +2 -1
- package/src/admin/editor/TopBar.tsx +36 -3
- package/src/admin/editor/canvas/CanvasFrame.tsx +2 -2
- package/src/admin/editor/canvas/DeviceBar.tsx +17 -9
- package/src/admin/editor/canvas/canvas-scale.ts +2 -2
- package/src/admin/editor/canvas/use-canvas-session.ts +2 -2
- package/src/admin/editor/co-design.ts +190 -0
- package/src/admin/editor/dnd/new-element.ts +26 -4
- package/src/admin/editor/editor-chrome.tsx +3 -3
- package/src/admin/editor/editor-commands.ts +8 -3
- package/src/admin/editor/editor-css.ts +3 -0
- package/src/admin/editor/element-chrome.ts +3 -1
- package/src/admin/editor/extension-manifests.ts +20 -0
- package/src/admin/editor/extensions/ExtensionPanels.tsx +26 -0
- package/src/admin/editor/extensions-context.tsx +27 -0
- package/src/admin/editor/feature-css.ts +17 -0
- package/src/admin/editor/host.ts +6 -0
- package/src/admin/editor/palette-items.ts +2 -2
- package/src/admin/editor/panels/AddPanel.tsx +31 -1
- package/src/admin/editor/panels/AgentRequestBox.tsx +116 -0
- package/src/admin/editor/panels/ClassesSection.tsx +9 -6
- package/src/admin/editor/panels/CoDesignPanel.tsx +170 -0
- package/src/admin/editor/panels/ColorControl.tsx +2 -2
- package/src/admin/editor/panels/ElementPanel.tsx +53 -15
- package/src/admin/editor/panels/LanguagesSection.tsx +152 -0
- package/src/admin/editor/panels/LayersPanel.tsx +10 -6
- package/src/admin/editor/panels/LeftPanel.tsx +33 -5
- package/src/admin/editor/panels/PageSettings.tsx +4 -0
- package/src/admin/editor/panels/SettingsPanel.tsx +21 -2
- package/src/admin/editor/panels/SiteStylesDrawer.tsx +7 -7
- package/src/admin/editor/panels/settings/BackgroundControls.tsx +76 -20
- package/src/admin/editor/panels/settings/BackgroundFill.tsx +8 -6
- package/src/admin/editor/panels/settings/BoxControl.tsx +5 -5
- package/src/admin/editor/panels/settings/EffectsControls.tsx +104 -9
- package/src/admin/editor/panels/settings/FieldControl.tsx +9 -3
- package/src/admin/editor/panels/settings/IconControls.tsx +14 -11
- package/src/admin/editor/panels/settings/LengthRow.tsx +27 -16
- package/src/admin/editor/panels/settings/LoopControl.tsx +269 -0
- package/src/admin/editor/panels/settings/LoopItemBindControl.tsx +1 -1
- package/src/admin/editor/panels/settings/MediaPicker.tsx +5 -5
- package/src/admin/editor/panels/settings/MotionControl.tsx +12 -11
- package/src/admin/editor/panels/settings/QueryStyleRows.tsx +7 -4
- package/src/admin/editor/panels/settings/StyleRow.tsx +113 -13
- package/src/admin/editor/panels/settings/TextMarksControl.tsx +247 -0
- package/src/admin/editor/panels/settings/VariableBinding.tsx +2 -2
- package/src/admin/editor/panels/settings/background-mode.ts +14 -11
- package/src/admin/editor/panels/settings/box-link-name.ts +1 -1
- package/src/admin/editor/panels/settings/box-sides.ts +22 -14
- package/src/admin/editor/panels/settings/heading-warning.ts +5 -1
- package/src/admin/editor/panels/settings/length-units.ts +55 -2
- package/src/admin/editor/panels/settings/query-style.ts +3 -3
- package/src/admin/editor/panels/settings/style-sections.ts +51 -10
- package/src/admin/editor/panels/style-target.ts +9 -7
- package/src/admin/editor/presence.ts +60 -0
- package/src/admin/editor/store.ts +6 -2
- package/src/admin/editor/useCoDesign.ts +177 -0
- package/src/admin/editor/useEditorCommands.ts +4 -4
- package/src/admin/editor/useExtensions.ts +45 -0
- package/src/admin/editor/useNodeActions.ts +15 -6
- package/src/admin/editor/useProposals.ts +81 -0
- package/src/admin/index.tsx +5 -1
- package/src/admin/languages-api.ts +61 -0
- package/src/admin/media-api.ts +27 -0
- package/src/admin/pages/AgentSetup.tsx +148 -0
- package/src/admin/pages/AgentsPage.tsx +11 -28
- package/src/admin/pages/CollectionsPage.tsx +215 -0
- package/src/admin/pages/CreateDialog.tsx +15 -0
- package/src/admin/pages/ImportButton.tsx +18 -0
- package/src/admin/pages/ImportElementorDialog.tsx +669 -0
- package/src/admin/pages/ImportPageLinks.tsx +86 -0
- package/src/admin/pages/PageList.tsx +15 -1
- package/src/admin/pages/ThemePartList.tsx +15 -1
- package/src/admin/pages/section-head.tsx +27 -0
- package/src/admin/proposals-api.ts +91 -0
- package/src/admin/setup/host-collections.ts +100 -0
- package/src/admin/ui.ts +39 -2
- package/src/admin/widgets/CanvasField.tsx +202 -0
- package/src/admin/widgets/convert-body.ts +54 -0
- package/src/admin/widgets/field-fetcher.ts +79 -0
- package/src/astro/content-port.ts +14 -1
- package/src/astro/index.ts +2 -0
- package/src/astro/page-count.ts +77 -0
- package/src/astro/resolve-theme.ts +58 -3
- package/src/astro/resolve.ts +128 -5
- package/src/astro/responsive-images.ts +99 -0
- package/src/constants.ts +1 -1
- package/src/core/a11y/audit.ts +44 -14
- package/src/core/arrange.ts +5 -1
- package/src/core/bounded-array.ts +31 -0
- package/src/core/canvas-collections.ts +20 -0
- package/src/core/clipboard.ts +9 -0
- package/src/core/contract.ts +285 -0
- package/src/core/css/generate.ts +89 -20
- package/src/core/css/trace.ts +18 -9
- package/src/core/css-keywords.ts +51 -1
- package/src/core/design/cascade.ts +12 -9
- package/src/core/design/classes.ts +4 -5
- package/src/core/design/devices.ts +13 -13
- package/src/core/design/states.ts +5 -3
- package/src/core/design/transfer.ts +5 -0
- package/src/core/design/variables.ts +17 -4
- package/src/core/elements/dynamic-elements.ts +19 -4
- package/src/core/elements/index.ts +73 -9
- package/src/core/extensions/define.ts +13 -0
- package/src/core/extensions/index.ts +41 -0
- package/src/core/extensions/namespace.ts +82 -0
- package/src/core/extensions/normalize.ts +141 -0
- package/src/core/extensions/placeholder.ts +41 -0
- package/src/core/extensions/registry.ts +94 -0
- package/src/core/extensions/render-ext.ts +118 -0
- package/src/core/extensions/safe-nodes.ts +93 -0
- package/src/core/extensions/schema.ts +112 -0
- package/src/core/extensions/types.ts +159 -0
- package/src/core/forms/binding.ts +1 -1
- package/src/core/history/diff.ts +1 -1
- package/src/core/import/elementor/atomic.ts +1595 -0
- package/src/core/import/elementor/classes.ts +127 -0
- package/src/core/import/elementor/context.ts +429 -0
- package/src/core/import/elementor/counter-steps.ts +72 -0
- package/src/core/import/elementor/css.ts +445 -0
- package/src/core/import/elementor/html.ts +500 -0
- package/src/core/import/elementor/index.ts +949 -0
- package/src/core/import/elementor/inline-marks.ts +81 -0
- package/src/core/import/elementor/snapshots.ts +48 -0
- package/src/core/import/elementor/style.ts +409 -0
- package/src/core/import/elementor/values.ts +241 -0
- package/src/core/import/elementor/widgets.ts +1897 -0
- package/src/core/index.ts +84 -0
- package/src/core/json-schema.ts +107 -0
- package/src/core/limits.ts +19 -0
- package/src/core/migrate/index.ts +6 -1
- package/src/core/migrate/v18.ts +222 -0
- package/src/core/perf/meter.ts +5 -5
- package/src/core/portable-text.ts +127 -0
- package/src/core/proposals-safety.ts +102 -0
- package/src/core/proposals.ts +357 -0
- package/src/core/recipes/index.ts +2 -2
- package/src/core/render/extras.ts +3 -3
- package/src/core/render/index.ts +140 -20
- package/src/core/render/loop.ts +1 -1
- package/src/core/render/pagination.ts +20 -1
- package/src/core/render/section.ts +4 -4
- package/src/core/render/vnode.ts +1 -1
- package/src/core/sanitize/css.ts +125 -10
- package/src/core/sanitize/motion.ts +116 -0
- package/src/core/saved-sections.ts +6 -0
- package/src/core/schema/descriptors.ts +3 -1
- package/src/core/schema/design.ts +2 -1
- package/src/core/schema/layout.ts +87 -14
- package/src/core/schema/style.ts +251 -114
- package/src/core/text-marks.ts +227 -0
- package/src/core/theme/dynamic.ts +9 -4
- package/src/core/theme/float.ts +1 -0
- package/src/core/theme/pagination.ts +9 -0
- package/src/core/theme/popup-rules.ts +17 -1
- package/src/core/translatable.ts +34 -0
- package/src/core/validate.ts +13 -1
- package/src/index.ts +35 -1
- package/src/mcp/errors.ts +3 -1
- package/src/mcp/ports.ts +67 -0
- package/src/mcp/prompts.ts +1 -11
- package/src/mcp/proposals.ts +281 -0
- package/src/mcp/read.ts +10 -9
- package/src/mcp/tools.ts +71 -3
- package/src/mcp/write.ts +66 -11
- package/src/server/agent-settings.ts +21 -2
- package/src/server/hooks.ts +81 -0
- package/src/server/mcp-routes.ts +15 -0
- package/src/server/plugin.ts +53 -5
- package/src/server/presence.ts +78 -0
- package/src/server/proposals.ts +261 -0
- package/src/server/requests.ts +196 -0
- package/src/server/tools-served.ts +45 -0
package/src/admin/index.tsx
CHANGED
|
@@ -4,19 +4,23 @@ import { defaultFetcher } from "./api.ts";
|
|
|
4
4
|
import { EditorPage } from "./pages/EditorPage.tsx";
|
|
5
5
|
import { PagesPage } from "./pages/PagesPage.tsx";
|
|
6
6
|
import { AgentsPage } from "./pages/AgentsPage.tsx";
|
|
7
|
+
import { CollectionsPage } from "./pages/CollectionsPage.tsx";
|
|
7
8
|
import { ThemeBuilderPage } from "./pages/ThemeBuilderPage.tsx";
|
|
9
|
+
import { CanvasField } from "./widgets/CanvasField.tsx";
|
|
8
10
|
import { LayoutField } from "./widgets/LayoutField.tsx";
|
|
9
11
|
|
|
10
12
|
if (typeof document !== "undefined") void installSidebarShim(document, defaultFetcher);
|
|
11
13
|
|
|
12
|
-
/** `/pages`, `/theme` and `/
|
|
14
|
+
/** `/pages`, `/theme`, `/agents` and `/collections` are declared; `/editor` renders by URL (D-024). */
|
|
13
15
|
export const pages: PluginAdminExports["pages"] = {
|
|
14
16
|
"/pages": PagesPage,
|
|
15
17
|
"/theme": ThemeBuilderPage,
|
|
16
18
|
"/agents": AgentsPage,
|
|
19
|
+
"/collections": CollectionsPage,
|
|
17
20
|
"/editor": EditorPage,
|
|
18
21
|
};
|
|
19
22
|
|
|
20
23
|
export const fields: PluginAdminExports["fields"] = {
|
|
21
24
|
layout: LayoutField,
|
|
25
|
+
canvas: CanvasField,
|
|
22
26
|
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { Layout } from "../core/schema/layout.ts";
|
|
2
|
+
import { requestJson, type Fetcher } from "./api.ts";
|
|
3
|
+
|
|
4
|
+
/** W-936: the site's languages, from EmDash's manifest; null when the site has no i18n. */
|
|
5
|
+
export async function siteLocales(
|
|
6
|
+
fetcher: Fetcher,
|
|
7
|
+
): Promise<{ defaultLocale: string; locales: string[] } | null> {
|
|
8
|
+
const data = await requestJson<{ i18n?: { defaultLocale?: string; locales?: string[] } }>(
|
|
9
|
+
fetcher,
|
|
10
|
+
"/_emdash/api/manifest",
|
|
11
|
+
);
|
|
12
|
+
const locales = data.i18n?.locales ?? [];
|
|
13
|
+
if (locales.length < 2 || !data.i18n?.defaultLocale) return null;
|
|
14
|
+
return { defaultLocale: data.i18n.defaultLocale, locales };
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export type Translation = { id: string; locale: string; slug: string; status: string };
|
|
18
|
+
|
|
19
|
+
/** Every language of an entry (EmDash's translation group), this one included. */
|
|
20
|
+
export async function listTranslations(
|
|
21
|
+
fetcher: Fetcher,
|
|
22
|
+
collection: string,
|
|
23
|
+
id: string,
|
|
24
|
+
): Promise<Translation[]> {
|
|
25
|
+
const data = await requestJson<{ translations?: Translation[] }>(
|
|
26
|
+
fetcher,
|
|
27
|
+
`/_emdash/api/content/${collection}/${encodeURIComponent(id)}/translations`,
|
|
28
|
+
);
|
|
29
|
+
return data.translations ?? [];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Creates the `locale` draft of an entry (D-068: a row per locale, linked by `translationOf`)
|
|
34
|
+
* holding a copy of the layout to translate. Returns the new entry's id.
|
|
35
|
+
*/
|
|
36
|
+
export async function createTranslation(
|
|
37
|
+
fetcher: Fetcher,
|
|
38
|
+
input: {
|
|
39
|
+
collection: string;
|
|
40
|
+
sourceId: string;
|
|
41
|
+
locale: string;
|
|
42
|
+
title: string;
|
|
43
|
+
slug: string;
|
|
44
|
+
layout: Layout;
|
|
45
|
+
},
|
|
46
|
+
): Promise<string> {
|
|
47
|
+
const data = await requestJson<{ item: { id: string } }>(
|
|
48
|
+
fetcher,
|
|
49
|
+
`/_emdash/api/content/${input.collection}`,
|
|
50
|
+
{
|
|
51
|
+
method: "POST",
|
|
52
|
+
body: {
|
|
53
|
+
data: { title: input.title, layout: input.layout },
|
|
54
|
+
slug: input.slug,
|
|
55
|
+
locale: input.locale,
|
|
56
|
+
translationOf: input.sourceId,
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
);
|
|
60
|
+
return data.item.id;
|
|
61
|
+
}
|
package/src/admin/media-api.ts
CHANGED
|
@@ -12,6 +12,9 @@ export type MediaLibraryItem = {
|
|
|
12
12
|
storageKey: string;
|
|
13
13
|
status: string;
|
|
14
14
|
url: string;
|
|
15
|
+
/** EmDash 1.4 library focal point, 0–1 (null or absent when unset). */
|
|
16
|
+
focalX?: number | null;
|
|
17
|
+
focalY?: number | null;
|
|
15
18
|
};
|
|
16
19
|
|
|
17
20
|
/** Shared EmDash media endpoint — same path on Node local and Cloudflare R2 (R-007). */
|
|
@@ -95,6 +98,29 @@ function fitImageSize(
|
|
|
95
98
|
next.height = Math.max(1, Math.round(height * scale));
|
|
96
99
|
}
|
|
97
100
|
|
|
101
|
+
const unitCoordinate = (value: unknown): value is number =>
|
|
102
|
+
typeof value === "number" && Number.isFinite(value) && value >= 0 && value <= 1;
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* W-915: EmDash 1.4 stores a focal point per library image (0–1). A newly picked picture takes it
|
|
106
|
+
* as the element's focal point (0–100 %); one the editor set on this same picture is kept.
|
|
107
|
+
*/
|
|
108
|
+
function libraryFocal(
|
|
109
|
+
next: Record<string, unknown>,
|
|
110
|
+
current: Record<string, unknown>,
|
|
111
|
+
item: MediaLibraryItem,
|
|
112
|
+
): void {
|
|
113
|
+
const samePicture = current.src === item.url;
|
|
114
|
+
if (samePicture && current.focalX !== undefined) return;
|
|
115
|
+
if (unitCoordinate(item.focalX) && unitCoordinate(item.focalY)) {
|
|
116
|
+
next.focalX = Math.round(item.focalX * 100);
|
|
117
|
+
next.focalY = Math.round(item.focalY * 100);
|
|
118
|
+
} else if (!samePicture) {
|
|
119
|
+
delete next.focalX;
|
|
120
|
+
delete next.focalY;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
98
124
|
/** Applies a library item onto an image node's props (id, URL, alt, dimensions). */
|
|
99
125
|
export function propsFromMedia(
|
|
100
126
|
current: Record<string, unknown>,
|
|
@@ -108,6 +134,7 @@ export function propsFromMedia(
|
|
|
108
134
|
delete next.edit;
|
|
109
135
|
}
|
|
110
136
|
fitImageSize(next, item.width, item.height);
|
|
137
|
+
libraryFocal(next, current, item);
|
|
111
138
|
const alt = current.alt;
|
|
112
139
|
if ((!alt || alt === "Image") && item.alt) next.alt = item.alt;
|
|
113
140
|
else if (!alt || alt === "Image") next.alt = item.filename.replace(/\.[^.]+$/, "") || "Image";
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { Button } from "@cloudflare/kumo";
|
|
2
|
+
import {
|
|
3
|
+
ArrowsClockwiseIcon,
|
|
4
|
+
CheckCircleIcon,
|
|
5
|
+
ListChecksIcon,
|
|
6
|
+
QuestionIcon,
|
|
7
|
+
WarningCircleIcon,
|
|
8
|
+
} from "@phosphor-icons/react";
|
|
9
|
+
import type { ReactNode } from "react";
|
|
10
|
+
import { useEffect, useState } from "react";
|
|
11
|
+
import type { Fetcher } from "../api.ts";
|
|
12
|
+
import { checkAgentSetup, type AgentSetup } from "../agents-api.ts";
|
|
13
|
+
import { SectionHead } from "./section-head.tsx";
|
|
14
|
+
|
|
15
|
+
type Step = { key: string; state: "done" | "todo" | "unknown"; title: string; detail: ReactNode };
|
|
16
|
+
|
|
17
|
+
const ICONS = {
|
|
18
|
+
done: <CheckCircleIcon size={18} weight="fill" aria-hidden="true" />,
|
|
19
|
+
todo: <WarningCircleIcon size={18} weight="fill" aria-hidden="true" />,
|
|
20
|
+
unknown: <QuestionIcon size={18} aria-hidden="true" />,
|
|
21
|
+
};
|
|
22
|
+
const STATUS = { done: "Done", todo: "To do", unknown: "Couldn't check" };
|
|
23
|
+
|
|
24
|
+
/** W-932: the steps a site needs before an agent can connect, each checked where it can be. */
|
|
25
|
+
function setupSteps(setup: AgentSetup | null, agentsOn: boolean): Step[] {
|
|
26
|
+
const endpoint = setup?.endpoint ?? "unknown";
|
|
27
|
+
const tools = setup?.tools ?? "unknown";
|
|
28
|
+
return [
|
|
29
|
+
{
|
|
30
|
+
key: "endpoint",
|
|
31
|
+
state: endpoint === "on" ? "done" : endpoint === "off" ? "todo" : "unknown",
|
|
32
|
+
title: "EmDash's MCP endpoint is on",
|
|
33
|
+
detail:
|
|
34
|
+
endpoint === "off" ? (
|
|
35
|
+
<>
|
|
36
|
+
Add <code>mcp: true</code> to <code>emdash()</code> in <code>astro.config.mjs</code> and
|
|
37
|
+
redeploy.
|
|
38
|
+
</>
|
|
39
|
+
) : (
|
|
40
|
+
"Agents connect to EmDash's own endpoint; EmVB adds its tools there."
|
|
41
|
+
),
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
key: "tools",
|
|
45
|
+
state: tools === "served" ? "done" : tools === "off" ? "todo" : "unknown",
|
|
46
|
+
title: "EmVB's tools are approved",
|
|
47
|
+
detail:
|
|
48
|
+
tools === "approved" ? (
|
|
49
|
+
<>
|
|
50
|
+
Approved, but no agent has used this version's tools yet. EmDash hides them again
|
|
51
|
+
whenever an EmVB update changes them: if your agent doesn't see EmVB's tools, approve
|
|
52
|
+
them again in <a href="/_emdash/admin/plugins-manager">Plugins</a>.
|
|
53
|
+
</>
|
|
54
|
+
) : tools === "off" ? (
|
|
55
|
+
<>
|
|
56
|
+
Approve them for Pages VisualBuilder in{" "}
|
|
57
|
+
<a href="/_emdash/admin/plugins-manager">Plugins</a>.
|
|
58
|
+
</>
|
|
59
|
+
) : tools === "served" ? (
|
|
60
|
+
"An agent has used this version's tools."
|
|
61
|
+
) : (
|
|
62
|
+
"EmDash lists EmVB's tools to agents only after an admin approves them."
|
|
63
|
+
),
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
key: "access",
|
|
67
|
+
state: agentsOn ? "done" : "todo",
|
|
68
|
+
title: "Agent access is on",
|
|
69
|
+
detail: agentsOn
|
|
70
|
+
? "Turn it off below to refuse every agent call at once."
|
|
71
|
+
: "Turn on “Let AI agents edit EmVB pages” below.",
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
key: "token",
|
|
75
|
+
state: "unknown",
|
|
76
|
+
title: "A token for the agent",
|
|
77
|
+
detail: (
|
|
78
|
+
<>
|
|
79
|
+
In <a href="/_emdash/admin/settings/api-tokens">API tokens</a>, create one with the scope{" "}
|
|
80
|
+
<code>mcp:tools:emvb</code> for an editor, not an admin. EmVB never sees or stores it.
|
|
81
|
+
</>
|
|
82
|
+
),
|
|
83
|
+
},
|
|
84
|
+
];
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export function AgentSetupCard({
|
|
88
|
+
fetcher,
|
|
89
|
+
agentsOn,
|
|
90
|
+
toolsServed = false,
|
|
91
|
+
}: {
|
|
92
|
+
fetcher: Fetcher;
|
|
93
|
+
agentsOn: boolean;
|
|
94
|
+
toolsServed?: boolean;
|
|
95
|
+
}) {
|
|
96
|
+
const [setup, setSetup] = useState<AgentSetup | null>(null);
|
|
97
|
+
const [attempt, setAttempt] = useState(0);
|
|
98
|
+
useEffect(() => {
|
|
99
|
+
let cancelled = false;
|
|
100
|
+
setSetup(null);
|
|
101
|
+
checkAgentSetup(fetcher, toolsServed).then(
|
|
102
|
+
(next) => !cancelled && setSetup(next),
|
|
103
|
+
() => !cancelled && setSetup({ endpoint: "unknown", tools: "unknown" }),
|
|
104
|
+
);
|
|
105
|
+
return () => {
|
|
106
|
+
cancelled = true;
|
|
107
|
+
};
|
|
108
|
+
}, [fetcher, toolsServed, attempt]);
|
|
109
|
+
const steps = setupSteps(setup, agentsOn);
|
|
110
|
+
return (
|
|
111
|
+
<section
|
|
112
|
+
className="emvb-surface-card emvb-agents-section"
|
|
113
|
+
aria-labelledby="emvb-agents-setup"
|
|
114
|
+
aria-busy={setup === null || undefined}
|
|
115
|
+
data-emvb-agent-setup={setup === null ? "checking" : "ready"}
|
|
116
|
+
>
|
|
117
|
+
<SectionHead id="emvb-agents-setup" icon={ListChecksIcon} title="Setup">
|
|
118
|
+
What this site needs before an agent can connect. People then ask their agent from the
|
|
119
|
+
editor's Agent tab and review what it proposes.
|
|
120
|
+
</SectionHead>
|
|
121
|
+
<ol className="emvb-agents-steps">
|
|
122
|
+
{steps.map((step) => (
|
|
123
|
+
<li key={step.key} data-emvb-setup-step={step.key} data-state={step.state}>
|
|
124
|
+
<span className="emvb-agents-step-icon">{ICONS[step.state]}</span>
|
|
125
|
+
<div>
|
|
126
|
+
<h3>
|
|
127
|
+
{step.title}
|
|
128
|
+
<span className="emvb-sr-only">: {STATUS[step.state]}</span>
|
|
129
|
+
</h3>
|
|
130
|
+
<p>{step.detail}</p>
|
|
131
|
+
</div>
|
|
132
|
+
</li>
|
|
133
|
+
))}
|
|
134
|
+
</ol>
|
|
135
|
+
<div>
|
|
136
|
+
<Button
|
|
137
|
+
size="sm"
|
|
138
|
+
variant="secondary"
|
|
139
|
+
icon={<ArrowsClockwiseIcon aria-hidden="true" />}
|
|
140
|
+
onClick={() => setAttempt((n) => n + 1)}
|
|
141
|
+
data-emvb-setup-recheck=""
|
|
142
|
+
>
|
|
143
|
+
Check again
|
|
144
|
+
</Button>
|
|
145
|
+
</div>
|
|
146
|
+
</section>
|
|
147
|
+
);
|
|
148
|
+
}
|
|
@@ -11,7 +11,6 @@ import {
|
|
|
11
11
|
TerminalWindowIcon,
|
|
12
12
|
UploadSimpleIcon,
|
|
13
13
|
WarningCircleIcon,
|
|
14
|
-
type Icon,
|
|
15
14
|
} from "@phosphor-icons/react";
|
|
16
15
|
import type { ReactNode } from "react";
|
|
17
16
|
import { useEffect, useRef, useState } from "react";
|
|
@@ -22,6 +21,10 @@ import { editorUrl } from "../editor/exit.ts";
|
|
|
22
21
|
import type { AgentSettings } from "../../mcp/settings.ts";
|
|
23
22
|
import { ListError, ListLoading } from "./list-kit.tsx";
|
|
24
23
|
import { UI_CSS } from "../ui.ts";
|
|
24
|
+
import { AgentSetupCard } from "./AgentSetup.tsx";
|
|
25
|
+
import { SectionHead } from "./section-head.tsx";
|
|
26
|
+
|
|
27
|
+
export { SectionHead };
|
|
25
28
|
|
|
26
29
|
const ADMIN_ROLE = 50;
|
|
27
30
|
|
|
@@ -44,37 +47,12 @@ const stdioSnippet = (site: string) =>
|
|
|
44
47
|
const remoteSnippet = (endpoint: string) =>
|
|
45
48
|
JSON.stringify({ mcpServers: { emvb: { url: endpoint } } }, null, 2);
|
|
46
49
|
|
|
47
|
-
/** A card's heading row: an icon tile, the title and one line on what the card is for (W-477). */
|
|
48
|
-
function SectionHead({
|
|
49
|
-
id,
|
|
50
|
-
icon: SectionIcon,
|
|
51
|
-
title,
|
|
52
|
-
children,
|
|
53
|
-
}: {
|
|
54
|
-
id: string;
|
|
55
|
-
icon: Icon;
|
|
56
|
-
title: string;
|
|
57
|
-
children: ReactNode;
|
|
58
|
-
}) {
|
|
59
|
-
return (
|
|
60
|
-
<div className="emvb-agents-head">
|
|
61
|
-
<span className="emvb-agents-icon" aria-hidden="true">
|
|
62
|
-
<SectionIcon size={18} />
|
|
63
|
-
</span>
|
|
64
|
-
<div>
|
|
65
|
-
<h2 id={id}>{title}</h2>
|
|
66
|
-
<p>{children}</p>
|
|
67
|
-
</div>
|
|
68
|
-
</div>
|
|
69
|
-
);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
50
|
/** AI agents (`/agents`, W-463): the master switch, publishing, how to connect, recent activity. */
|
|
73
51
|
/**
|
|
74
52
|
* W-756: on a phone the setup JSON scrolls sideways, and keyboard users could not reach it to
|
|
75
53
|
* scroll. Focusable, and named so a screen reader says what it is.
|
|
76
54
|
*/
|
|
77
|
-
const SCROLLABLE = { tabIndex: 0, role: "group" } as const;
|
|
55
|
+
export const SCROLLABLE = { tabIndex: 0, role: "group" } as const;
|
|
78
56
|
|
|
79
57
|
export function AgentsPage({ fetcher = defaultFetcher }: { fetcher?: Fetcher }) {
|
|
80
58
|
const role = useRole(fetcher);
|
|
@@ -185,6 +163,11 @@ export function AgentsPage({ fetcher = defaultFetcher }: { fetcher?: Fetcher })
|
|
|
185
163
|
description={saveError}
|
|
186
164
|
/>
|
|
187
165
|
)}
|
|
166
|
+
<AgentSetupCard
|
|
167
|
+
fetcher={fetcher}
|
|
168
|
+
agentsOn={settings.mcpEnabled}
|
|
169
|
+
toolsServed={state.toolsServed === true}
|
|
170
|
+
/>
|
|
188
171
|
<section
|
|
189
172
|
className="emvb-surface-card emvb-agents-section"
|
|
190
173
|
aria-labelledby="emvb-agents-access"
|
|
@@ -337,7 +320,7 @@ export function AgentsPage({ fetcher = defaultFetcher }: { fetcher?: Fetcher })
|
|
|
337
320
|
}
|
|
338
321
|
|
|
339
322
|
/** UX-089: the setup JSON is meant to be pasted into an agent's config, so it copies in one click. */
|
|
340
|
-
function CopySnippet({ text, name }: { text: string; name: string }) {
|
|
323
|
+
export function CopySnippet({ text, name }: { text: string; name: string }) {
|
|
341
324
|
const [copied, setCopied] = useState<"yes" | "no" | null>(null);
|
|
342
325
|
useEffect(() => {
|
|
343
326
|
// W-777: a failed copy stays until the next click; it vanished after 2 s.
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { Badge, Banner, Button, Empty, Loader, Table } from "@cloudflare/kumo";
|
|
2
|
+
import {
|
|
3
|
+
CodeIcon,
|
|
4
|
+
DatabaseIcon,
|
|
5
|
+
LockKeyIcon,
|
|
6
|
+
PlusIcon,
|
|
7
|
+
WarningCircleIcon,
|
|
8
|
+
} from "@phosphor-icons/react";
|
|
9
|
+
import type { ReactNode } from "react";
|
|
10
|
+
import { useEffect, useState } from "react";
|
|
11
|
+
import { useRole } from "../access/role.ts";
|
|
12
|
+
import { defaultFetcher, type Fetcher } from "../api.ts";
|
|
13
|
+
import {
|
|
14
|
+
addCanvasField,
|
|
15
|
+
canvasCollectionsSnippet,
|
|
16
|
+
loadHostCollections,
|
|
17
|
+
type HostCollectionRow,
|
|
18
|
+
} from "../setup/host-collections.ts";
|
|
19
|
+
import { BUTTON, UI_CSS } from "../ui.ts";
|
|
20
|
+
import { CopySnippet, SCROLLABLE, SectionHead } from "./AgentsPage.tsx";
|
|
21
|
+
import { ListError, ListLoading } from "./list-kit.tsx";
|
|
22
|
+
|
|
23
|
+
const ADMIN_ROLE = 50;
|
|
24
|
+
|
|
25
|
+
const PAGE_CSS = `
|
|
26
|
+
.emvb-collections-table td:last-child, .emvb-collections-table th:last-child { text-align: end; }
|
|
27
|
+
.emvb-collections-slug { display: block; font-size: 12px; color: var(--text-color-kumo-subtle); font-family: var(--font-mono); }
|
|
28
|
+
`;
|
|
29
|
+
|
|
30
|
+
function shell(body: ReactNode, status = "ready") {
|
|
31
|
+
return (
|
|
32
|
+
<div className="emvb-pages emvb-agents" data-emvb-collections={status}>
|
|
33
|
+
<style data-emvb-ui="">{UI_CSS}</style>
|
|
34
|
+
<style>{PAGE_CSS}</style>
|
|
35
|
+
<div className="emvb-agents-header">
|
|
36
|
+
<div>
|
|
37
|
+
<h1 className="emvb-page-title">Host collections</h1>
|
|
38
|
+
<p>
|
|
39
|
+
Let entries in your own collections hold an EmVB layout, edited with Edit with EmVB.
|
|
40
|
+
</p>
|
|
41
|
+
</div>
|
|
42
|
+
</div>
|
|
43
|
+
{body}
|
|
44
|
+
</div>
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function FieldBadge({ row }: { row: HostCollectionRow }) {
|
|
49
|
+
if (row.field === "ready") return <Badge variant="blue">Has {row.fieldSlug}</Badge>;
|
|
50
|
+
if (row.field === "taken") return <Badge variant="neutral">"canvas" is another field</Badge>;
|
|
51
|
+
return <Badge variant="neutral">No canvas field</Badge>;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Host collections (`/collections`, W-913): which collections can hold an EmVB layout, a button
|
|
56
|
+
* that adds the `emvb:canvas` field through EmDash's schema API, and the `canvasCollections`
|
|
57
|
+
* snippet. That option lives in astro.config and is read at start-up, so setup can't change it.
|
|
58
|
+
*/
|
|
59
|
+
export function CollectionsPage({ fetcher = defaultFetcher }: { fetcher?: Fetcher }) {
|
|
60
|
+
const role = useRole(fetcher);
|
|
61
|
+
const isAdmin = role.state === "ready" && role.role >= ADMIN_ROLE;
|
|
62
|
+
const [state, setState] = useState<Awaited<ReturnType<typeof loadHostCollections>> | null>(null);
|
|
63
|
+
const [error, setError] = useState<string | null>(null);
|
|
64
|
+
const [attempt, setAttempt] = useState(0);
|
|
65
|
+
const [adding, setAdding] = useState<string | null>(null);
|
|
66
|
+
const [addError, setAddError] = useState<string | null>(null);
|
|
67
|
+
|
|
68
|
+
useEffect(() => {
|
|
69
|
+
if (!isAdmin) return;
|
|
70
|
+
let cancelled = false;
|
|
71
|
+
loadHostCollections(fetcher)
|
|
72
|
+
.then((next) => !cancelled && setState(next))
|
|
73
|
+
.catch((e: unknown) => !cancelled && setError(e instanceof Error ? e.message : String(e)));
|
|
74
|
+
return () => {
|
|
75
|
+
cancelled = true;
|
|
76
|
+
};
|
|
77
|
+
}, [fetcher, isAdmin, attempt]);
|
|
78
|
+
|
|
79
|
+
if (role.state === "loading")
|
|
80
|
+
return shell(<ListLoading label="Loading collections…" />, "loading");
|
|
81
|
+
if (!isAdmin) {
|
|
82
|
+
return (
|
|
83
|
+
<section data-emvb-access="denied">
|
|
84
|
+
<Empty
|
|
85
|
+
icon={<LockKeyIcon aria-hidden="true" />}
|
|
86
|
+
title="Only administrators can set up host collections"
|
|
87
|
+
description="Ask an administrator to add the canvas field."
|
|
88
|
+
/>
|
|
89
|
+
</section>
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
if (error) {
|
|
93
|
+
return shell(
|
|
94
|
+
<ListError
|
|
95
|
+
title="Couldn't load the collections"
|
|
96
|
+
message={error}
|
|
97
|
+
onRetry={() => {
|
|
98
|
+
setError(null);
|
|
99
|
+
setAttempt((n) => n + 1);
|
|
100
|
+
}}
|
|
101
|
+
/>,
|
|
102
|
+
"error",
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
if (!state) return shell(<ListLoading label="Loading collections…" />, "loading");
|
|
106
|
+
|
|
107
|
+
const add = async (slug: string) => {
|
|
108
|
+
setAdding(slug);
|
|
109
|
+
setAddError(null);
|
|
110
|
+
try {
|
|
111
|
+
await addCanvasField(fetcher, slug);
|
|
112
|
+
setState(await loadHostCollections(fetcher));
|
|
113
|
+
} catch (e) {
|
|
114
|
+
setAddError(e instanceof Error ? e.message : String(e));
|
|
115
|
+
} finally {
|
|
116
|
+
setAdding(null);
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
const snippet = canvasCollectionsSnippet(state.rows, state.canvasStyles);
|
|
120
|
+
const unlisted = state.rows.filter((r) => r.field === "ready" && !r.listed);
|
|
121
|
+
|
|
122
|
+
return shell(
|
|
123
|
+
<>
|
|
124
|
+
{addError && (
|
|
125
|
+
<Banner variant="error" icon={<WarningCircleIcon aria-hidden="true" />}>
|
|
126
|
+
The field wasn't added: {addError}
|
|
127
|
+
</Banner>
|
|
128
|
+
)}
|
|
129
|
+
<section className="emvb-surface-card emvb-agents-section" aria-labelledby="emvb-hc-list">
|
|
130
|
+
<SectionHead id="emvb-hc-list" icon={DatabaseIcon} title="Collections">
|
|
131
|
+
Adding the field changes the collection's schema; existing entries keep their content and
|
|
132
|
+
show it until a layout is added.
|
|
133
|
+
</SectionHead>
|
|
134
|
+
{state.rows.length === 0 ? (
|
|
135
|
+
<p>This site has no collections of its own yet.</p>
|
|
136
|
+
) : (
|
|
137
|
+
// W-921: on phones the table scrolls inside the card, not the whole admin page.
|
|
138
|
+
<div className="emvb-agents-table" {...SCROLLABLE} aria-label="Collections">
|
|
139
|
+
<Table className="emvb-collections-table">
|
|
140
|
+
<Table.Header>
|
|
141
|
+
<Table.Row>
|
|
142
|
+
<Table.Head>Collection</Table.Head>
|
|
143
|
+
<Table.Head>Field</Table.Head>
|
|
144
|
+
<Table.Head>In canvasCollections</Table.Head>
|
|
145
|
+
<Table.Head>
|
|
146
|
+
<span className="sr-only">Action</span>
|
|
147
|
+
</Table.Head>
|
|
148
|
+
</Table.Row>
|
|
149
|
+
</Table.Header>
|
|
150
|
+
<Table.Body>
|
|
151
|
+
{state.rows.map((row) => (
|
|
152
|
+
<Table.Row key={row.slug} data-emvb-collection={row.slug}>
|
|
153
|
+
<Table.Cell>
|
|
154
|
+
{row.label}
|
|
155
|
+
<span className="emvb-collections-slug">{row.slug}</span>
|
|
156
|
+
</Table.Cell>
|
|
157
|
+
<Table.Cell>
|
|
158
|
+
<FieldBadge row={row} />
|
|
159
|
+
</Table.Cell>
|
|
160
|
+
<Table.Cell>{row.listed ? "Yes" : "Not yet"}</Table.Cell>
|
|
161
|
+
<Table.Cell>
|
|
162
|
+
{row.field === "missing" && (
|
|
163
|
+
<Button
|
|
164
|
+
size="sm"
|
|
165
|
+
variant="secondary"
|
|
166
|
+
className={BUTTON}
|
|
167
|
+
icon={
|
|
168
|
+
adding === row.slug ? (
|
|
169
|
+
<Loader size={14} />
|
|
170
|
+
) : (
|
|
171
|
+
<PlusIcon aria-hidden="true" />
|
|
172
|
+
)
|
|
173
|
+
}
|
|
174
|
+
disabled={adding !== null}
|
|
175
|
+
aria-label={`Add canvas field to ${row.label}`}
|
|
176
|
+
onClick={() => void add(row.slug)}
|
|
177
|
+
>
|
|
178
|
+
Add canvas field
|
|
179
|
+
</Button>
|
|
180
|
+
)}
|
|
181
|
+
</Table.Cell>
|
|
182
|
+
</Table.Row>
|
|
183
|
+
))}
|
|
184
|
+
</Table.Body>
|
|
185
|
+
</Table>
|
|
186
|
+
</div>
|
|
187
|
+
)}
|
|
188
|
+
</section>
|
|
189
|
+
<section className="emvb-surface-card emvb-agents-section" aria-labelledby="emvb-hc-config">
|
|
190
|
+
<SectionHead id="emvb-hc-config" icon={CodeIcon} title="Site config">
|
|
191
|
+
<code>canvasCollections</code> is an option of <code>emvb()</code> in astro.config, read
|
|
192
|
+
when the site starts, so EmVB can't set it from here. Paste this, then restart or redeploy
|
|
193
|
+
the site.
|
|
194
|
+
</SectionHead>
|
|
195
|
+
{unlisted.length > 0 && (
|
|
196
|
+
<Banner variant="default" data-emvb-unlisted="">
|
|
197
|
+
{unlisted.map((r) => r.label).join(", ")} {unlisted.length === 1 ? "has" : "have"} the
|
|
198
|
+
field but {unlisted.length === 1 ? "isn't" : "aren't"} listed yet: layouts there aren't
|
|
199
|
+
checked on save or rendered until the site config lists{" "}
|
|
200
|
+
{unlisted.length === 1 ? "it" : "them"}.
|
|
201
|
+
</Banner>
|
|
202
|
+
)}
|
|
203
|
+
<div className="emvb-agents-snippet">
|
|
204
|
+
<div className="emvb-agents-snippet-head">
|
|
205
|
+
<h3>astro.config.mjs</h3>
|
|
206
|
+
<CopySnippet text={snippet} name="canvasCollections config" />
|
|
207
|
+
</div>
|
|
208
|
+
<pre data-emvb-snippet="canvas-collections" {...SCROLLABLE} aria-label="Site config">
|
|
209
|
+
{snippet}
|
|
210
|
+
</pre>
|
|
211
|
+
</div>
|
|
212
|
+
</section>
|
|
213
|
+
</>,
|
|
214
|
+
);
|
|
215
|
+
}
|
|
@@ -26,6 +26,7 @@ function createFailure(failure: unknown, noun: string, slug: string): FieldError
|
|
|
26
26
|
/**
|
|
27
27
|
* The New page / New theme part form (IA): title, a slug that follows `slugPrefix` + title until
|
|
28
28
|
* edited, then `create` returns the editor URL to open. `children` go above the title.
|
|
29
|
+
* `suggestedTitle` (W-945: an imported template's title) fills the title until the person types one.
|
|
29
30
|
*/
|
|
30
31
|
export function CreateDialog({
|
|
31
32
|
name,
|
|
@@ -39,6 +40,7 @@ export function CreateDialog({
|
|
|
39
40
|
open,
|
|
40
41
|
onOpenChange,
|
|
41
42
|
children,
|
|
43
|
+
suggestedTitle,
|
|
42
44
|
}: {
|
|
43
45
|
name: string;
|
|
44
46
|
heading: string;
|
|
@@ -51,6 +53,7 @@ export function CreateDialog({
|
|
|
51
53
|
open: boolean;
|
|
52
54
|
onOpenChange: (open: boolean) => void;
|
|
53
55
|
children?: React.ReactNode;
|
|
56
|
+
suggestedTitle?: string;
|
|
54
57
|
}) {
|
|
55
58
|
const [title, setTitle] = React.useState("");
|
|
56
59
|
const [slug, setSlug] = React.useState("");
|
|
@@ -82,6 +85,18 @@ export function CreateDialog({
|
|
|
82
85
|
}
|
|
83
86
|
}, [slugPrefix]);
|
|
84
87
|
|
|
88
|
+
// W-945: a new suggestion replaces the title only while it is empty or the last suggestion.
|
|
89
|
+
const lastSuggestion = React.useRef<string | undefined>(undefined);
|
|
90
|
+
React.useEffect(() => {
|
|
91
|
+
if (!suggestedTitle) return;
|
|
92
|
+
const current = titleRef.current;
|
|
93
|
+
const previous = lastSuggestion.current;
|
|
94
|
+
lastSuggestion.current = suggestedTitle;
|
|
95
|
+
if (current && current !== previous) return;
|
|
96
|
+
setTitle(suggestedTitle);
|
|
97
|
+
if (!slugEditedRef.current) setSlug(pageSlug(`${slugPrefix}${suggestedTitle}`));
|
|
98
|
+
}, [suggestedTitle, slugPrefix]);
|
|
99
|
+
|
|
85
100
|
const submit = async () => {
|
|
86
101
|
if (pending.current) return;
|
|
87
102
|
const cleanTitle = title.trim();
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Button } from "@cloudflare/kumo";
|
|
2
|
+
import { FileArrowUpIcon } from "@phosphor-icons/react";
|
|
3
|
+
import { BUTTON } from "../ui.ts";
|
|
4
|
+
|
|
5
|
+
/** Opens Import from Elementor (W-945), next to the list's New button. */
|
|
6
|
+
export function ImportButton({ onClick }: { onClick: () => void }) {
|
|
7
|
+
return (
|
|
8
|
+
<Button
|
|
9
|
+
variant="secondary"
|
|
10
|
+
className={BUTTON}
|
|
11
|
+
icon={<FileArrowUpIcon aria-hidden="true" />}
|
|
12
|
+
onClick={onClick}
|
|
13
|
+
data-emvb-import-elementor=""
|
|
14
|
+
>
|
|
15
|
+
Import from Elementor
|
|
16
|
+
</Button>
|
|
17
|
+
);
|
|
18
|
+
}
|