@perkyzz/emvb 1.4.0 → 1.4.2
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 +2 -2
- package/package.json +6 -6
- package/src/admin/content-item.ts +3 -0
- package/src/admin/copy-rich-text.ts +99 -9
- package/src/admin/editor/Editor.tsx +7 -2
- package/src/admin/editor/collection-previews.ts +7 -8
- package/src/admin/editor/extensions/ExtensionPanels.tsx +33 -1
- package/src/admin/editor/extensions-context.tsx +16 -1
- package/src/admin/editor/feature-css.ts +5 -0
- package/src/admin/editor/panels/ConditionsEditor.tsx +18 -0
- package/src/admin/editor/panels/ElementPanel.tsx +2 -2
- package/src/admin/editor/panels/settings/FieldControl.tsx +15 -0
- package/src/admin/editor/panels/settings/FormBindControl.tsx +27 -31
- package/src/admin/editor/panels/settings/ImageFieldControl.tsx +106 -0
- package/src/admin/editor/panels/settings/loop-context.ts +34 -3
- package/src/admin/export-api.ts +2 -0
- package/src/admin/extension-outputs.ts +57 -0
- package/src/admin/import-forms.ts +133 -0
- package/src/admin/pages/ImportElementorDialog.tsx +32 -0
- package/src/admin/pages/ImportForms.tsx +71 -0
- package/src/admin/setup/plan.ts +2 -0
- package/src/admin/ui.ts +7 -0
- package/src/admin/widgets/ConvertToRichText.tsx +3 -2
- package/src/astro/render.ts +11 -0
- package/src/astro/resolve-theme.ts +11 -15
- package/src/astro/resolve.ts +2 -0
- package/src/astro/theme-posts.ts +17 -23
- package/src/astro/visitor.ts +14 -5
- package/src/astro/widgets/sticky.ts +4 -1
- package/src/constants.ts +1 -1
- package/src/core/css/generate.ts +6 -1
- package/src/core/css/trace.ts +8 -0
- package/src/core/data/bindings.ts +7 -4
- package/src/core/elements/dynamic-elements.ts +1 -1
- package/src/core/elements/element-nouns.ts +48 -0
- package/src/core/export/runtimes.generated.ts +1 -1
- package/src/core/export/site.ts +7 -11
- package/src/core/extensions/index.ts +2 -0
- package/src/core/extensions/placeholder.ts +7 -2
- package/src/core/extensions/render-ext.ts +49 -15
- package/src/core/import/elementor/context.ts +29 -0
- package/src/core/import/elementor/index.ts +23 -2
- package/src/core/import/elementor/widgets.ts +137 -17
- package/src/core/index.ts +11 -0
- package/src/core/render/index.ts +30 -2
- package/src/core/schema/layout.ts +4 -1
- package/src/core/theme/media-value.ts +88 -0
- package/src/core/theme/part-wrapper.ts +100 -0
- package/src/core/visitor-cookie.ts +91 -0
- package/src/index.ts +28 -1
- package/src/mcp/agent-defaults.ts +40 -0
- package/src/mcp/extensions.ts +138 -0
- package/src/mcp/read.ts +55 -19
- package/src/mcp/tools.ts +3 -3
- package/src/mcp/write.ts +83 -8
- package/src/server/extension-routes.ts +37 -0
- package/src/server/plugin.ts +7 -1
package/src/index.ts
CHANGED
|
@@ -3,6 +3,11 @@ import { ADMIN_ENTRY, PACKAGE_NAME, PLUGIN_ID, PLUGIN_VERSION } from "./constant
|
|
|
3
3
|
import { canvasCollectionSlugs } from "./core/canvas-collections.ts";
|
|
4
4
|
import { canvasStyleUrls } from "./core/canvas-styles.ts";
|
|
5
5
|
import { loopCollectionSlugs } from "./core/loop-collections.ts";
|
|
6
|
+
import {
|
|
7
|
+
visitorCookieOptions,
|
|
8
|
+
type VisitorCookieConsent,
|
|
9
|
+
type VisitorCookieMode,
|
|
10
|
+
} from "./core/visitor-cookie.ts";
|
|
6
11
|
import {
|
|
7
12
|
listedExtensionManifests,
|
|
8
13
|
rememberExtensions,
|
|
@@ -45,6 +50,20 @@ export type EmVBOptions = {
|
|
|
45
50
|
* any collection, so set it if you keep a collection published but not meant to be listed.
|
|
46
51
|
*/
|
|
47
52
|
loopCollections?: string[];
|
|
53
|
+
/**
|
|
54
|
+
* W-1092 (#34): when EmVB may keep the `emvb_seen` cookie (one year, first-party, HttpOnly)
|
|
55
|
+
* that tells new visitors from returning ones. Only pages with a new/returning Visitors rule
|
|
56
|
+
* ever read or set it. `"always"` (default) sets it on a first visit; `"consent"` only once
|
|
57
|
+
* the request carries `visitorCookieConsent`; `"never"` never. When it isn't allowed, everyone
|
|
58
|
+
* counts as a new visitor and a cookie left from before is cleared.
|
|
59
|
+
*/
|
|
60
|
+
visitorCookie?: VisitorCookieMode;
|
|
61
|
+
/**
|
|
62
|
+
* W-1092: for `visitorCookie: "consent"`, the first-party cookie your consent banner sets, and
|
|
63
|
+
* the value (or values) that mean "accepted". Without `value`, `1`, `true`, `yes`, `granted`,
|
|
64
|
+
* `accepted`, `allow` or `all` count (any case). Missing or invalid, "consent" acts as "never".
|
|
65
|
+
*/
|
|
66
|
+
visitorCookieConsent?: VisitorCookieConsent;
|
|
48
67
|
};
|
|
49
68
|
|
|
50
69
|
/** Descriptor that host sites add to `emdash({ plugins: [...] })` in astro.config. */
|
|
@@ -63,6 +82,13 @@ export function emvb(options: EmVBOptions = {}): PluginDescriptor {
|
|
|
63
82
|
// oxlint-disable-next-line no-console -- build-time notice for the site owner (W-1086)
|
|
64
83
|
console.warn(`[emvb] extension ${warning}`);
|
|
65
84
|
}
|
|
85
|
+
const cookie = visitorCookieOptions(options.visitorCookie, options.visitorCookieConsent);
|
|
86
|
+
if (options.visitorCookie === "consent" && cookie.visitorCookie !== "consent") {
|
|
87
|
+
// oxlint-disable-next-line no-console -- build-time notice for the site owner (W-1092)
|
|
88
|
+
console.warn(
|
|
89
|
+
'[emvb] visitorCookie: "consent" needs visitorCookieConsent: { cookie: "<name>" }; until then the visitor cookie is never set',
|
|
90
|
+
);
|
|
91
|
+
}
|
|
66
92
|
const ids = new Set(accepted.map((m) => m.id));
|
|
67
93
|
const extensions = listedExtensionManifests().filter((m) => ids.has(m.id));
|
|
68
94
|
return {
|
|
@@ -82,6 +108,7 @@ export function emvb(options: EmVBOptions = {}): PluginDescriptor {
|
|
|
82
108
|
...(typeof options.trustGeoHeaders === "boolean"
|
|
83
109
|
? { trustGeoHeaders: options.trustGeoHeaders }
|
|
84
110
|
: {}),
|
|
111
|
+
...cookie,
|
|
85
112
|
},
|
|
86
113
|
};
|
|
87
114
|
}
|
|
@@ -93,7 +120,7 @@ export { createPlugin };
|
|
|
93
120
|
/** W-1086: used by the server entry `emvb()` generates for extensions; not for site code. */
|
|
94
121
|
export { registerBundledExtensions } from "./core/extensions/index.ts";
|
|
95
122
|
|
|
96
|
-
export type { EmVBExtension, ExtensionManifest };
|
|
123
|
+
export type { EmVBExtension, ExtensionManifest, VisitorCookieConsent, VisitorCookieMode };
|
|
97
124
|
export {
|
|
98
125
|
defineExtension,
|
|
99
126
|
EXTENSION_API_VERSION,
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { defaultElement, type ElementType, type LayoutNode } from "../core/index.ts";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* W-1089 (#29): optional props whose Add-panel default is sample content (words, prices, links,
|
|
5
|
+
* a place, a ribbon). People get them as a starting point to edit; an element an agent adds
|
|
6
|
+
* keeps only what the agent set, so a price table with a title and a price doesn't also show
|
|
7
|
+
* "For growing teams.", a crossed-out "Custom domain" and a Featured ribbon. Required props keep
|
|
8
|
+
* their defaults, so the element stays valid.
|
|
9
|
+
*/
|
|
10
|
+
export const AGENT_SAMPLE_PROPS: Readonly<Partial<Record<ElementType, readonly string[]>>> = {
|
|
11
|
+
alert: ["title"],
|
|
12
|
+
testimonial: ["role"],
|
|
13
|
+
counter: ["suffix", "title"],
|
|
14
|
+
progress: ["label"],
|
|
15
|
+
countdown: ["title"],
|
|
16
|
+
map: ["lat", "lng"],
|
|
17
|
+
"price-table": [
|
|
18
|
+
"description",
|
|
19
|
+
"currency",
|
|
20
|
+
"period",
|
|
21
|
+
"features",
|
|
22
|
+
"excluded",
|
|
23
|
+
"buttonText",
|
|
24
|
+
"buttonHref",
|
|
25
|
+
"featured",
|
|
26
|
+
],
|
|
27
|
+
cta: ["text", "buttonText", "href"],
|
|
28
|
+
"flip-box": ["frontText", "backTitle", "backText", "buttonText", "href"],
|
|
29
|
+
headline: ["before", "after", "rotate"],
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/** The element an agent's add starts from: the type's defaults without sample content. */
|
|
33
|
+
export function agentDefaultElement(type: ElementType, id: string): LayoutNode {
|
|
34
|
+
const base = defaultElement(type, id) as LayoutNode & { props?: Record<string, unknown> };
|
|
35
|
+
const sample = AGENT_SAMPLE_PROPS[type];
|
|
36
|
+
if (!sample || !base.props) return base;
|
|
37
|
+
const props = { ...base.props };
|
|
38
|
+
for (const key of sample) delete props[key];
|
|
39
|
+
return { ...base, props } as LayoutNode;
|
|
40
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import {
|
|
2
|
+
listedExtensionManifests,
|
|
3
|
+
liveElement,
|
|
4
|
+
validateExtensionProps,
|
|
5
|
+
type ExtensionPropSchema,
|
|
6
|
+
} from "../core/index.ts";
|
|
7
|
+
import { MAX_TEXT_LENGTH } from "../core/limits.ts";
|
|
8
|
+
import { McpToolError } from "./errors.ts";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* W-1089 (#38): extension elements (`ext:<pkg>/<name>`) for agents' direct tools. Only elements
|
|
12
|
+
* whose extension is registered on this site are listed or accepted, and their props are checked
|
|
13
|
+
* by the extension's own schema: invalid props are refused, never replaced by defaults.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/** The registered extension elements, as their manifests describe them. */
|
|
17
|
+
export function registeredExtensionElements() {
|
|
18
|
+
return listedExtensionManifests().flatMap((manifest) =>
|
|
19
|
+
manifest.elements
|
|
20
|
+
.filter((element) => liveElement(element.type) !== undefined)
|
|
21
|
+
.map((element) => Object.assign({ extensionId: manifest.id }, element)),
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const withDefault = (out: Record<string, unknown>, value: unknown) =>
|
|
26
|
+
value === undefined ? out : Object.assign(out, { default: value });
|
|
27
|
+
|
|
28
|
+
/** JSON Schema for an extension's declarative prop schema, with EmVB's caps (as schema.ts). */
|
|
29
|
+
export function extensionJsonSchema(schema: ExtensionPropSchema): Record<string, unknown> {
|
|
30
|
+
switch (schema.type) {
|
|
31
|
+
case "string":
|
|
32
|
+
return withDefault(
|
|
33
|
+
{
|
|
34
|
+
type: "string",
|
|
35
|
+
maxLength: Math.min(schema.maxLength ?? MAX_TEXT_LENGTH, MAX_TEXT_LENGTH),
|
|
36
|
+
...(schema.minLength ? { minLength: schema.minLength } : {}),
|
|
37
|
+
},
|
|
38
|
+
schema.default,
|
|
39
|
+
);
|
|
40
|
+
case "number":
|
|
41
|
+
return withDefault(
|
|
42
|
+
{
|
|
43
|
+
type: schema.integer ? "integer" : "number",
|
|
44
|
+
...(schema.min !== undefined ? { minimum: schema.min } : {}),
|
|
45
|
+
...(schema.max !== undefined ? { maximum: schema.max } : {}),
|
|
46
|
+
},
|
|
47
|
+
schema.default,
|
|
48
|
+
);
|
|
49
|
+
case "boolean":
|
|
50
|
+
return withDefault({ type: "boolean" }, schema.default);
|
|
51
|
+
case "enum":
|
|
52
|
+
return withDefault({ type: "string", enum: [...schema.values] }, schema.default);
|
|
53
|
+
case "array":
|
|
54
|
+
return withDefault(
|
|
55
|
+
{
|
|
56
|
+
type: "array",
|
|
57
|
+
items: extensionJsonSchema(schema.items),
|
|
58
|
+
maxItems: Math.min(schema.maxItems ?? 32, 32),
|
|
59
|
+
},
|
|
60
|
+
schema.default,
|
|
61
|
+
);
|
|
62
|
+
case "object":
|
|
63
|
+
return {
|
|
64
|
+
type: "object",
|
|
65
|
+
properties: Object.fromEntries(
|
|
66
|
+
Object.entries(schema.properties).map(([key, prop]) => [key, extensionJsonSchema(prop)]),
|
|
67
|
+
),
|
|
68
|
+
...(schema.required?.length ? { required: [...schema.required] } : {}),
|
|
69
|
+
additionalProperties: false,
|
|
70
|
+
};
|
|
71
|
+
default:
|
|
72
|
+
return {};
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** What a prop must be, in words, for a refusal. */
|
|
77
|
+
function expected(schema: ExtensionPropSchema): string {
|
|
78
|
+
switch (schema.type) {
|
|
79
|
+
case "string":
|
|
80
|
+
return `text of at most ${Math.min(schema.maxLength ?? MAX_TEXT_LENGTH, MAX_TEXT_LENGTH)} characters${schema.minLength ? ` and at least ${schema.minLength}` : ""}`;
|
|
81
|
+
case "number":
|
|
82
|
+
return `${schema.integer ? "a whole number" : "a number"}${schema.min !== undefined ? ` from ${schema.min}` : ""}${schema.max !== undefined ? ` up to ${schema.max}` : ""}`;
|
|
83
|
+
case "boolean":
|
|
84
|
+
return "true or false";
|
|
85
|
+
case "enum":
|
|
86
|
+
return `one of ${schema.values.join(", ")}`;
|
|
87
|
+
case "array":
|
|
88
|
+
return `a list of at most ${Math.min(schema.maxItems ?? 32, 32)} items`;
|
|
89
|
+
default:
|
|
90
|
+
return "an object";
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** Each prop that breaks the schema, in words. */
|
|
95
|
+
function propIssues(schema: ExtensionPropSchema, props: Record<string, unknown>): string[] {
|
|
96
|
+
if (schema.type !== "object") return ["its props don't match its schema"];
|
|
97
|
+
const issues: string[] = [];
|
|
98
|
+
for (const [key, value] of Object.entries(props)) {
|
|
99
|
+
const prop = schema.properties[key];
|
|
100
|
+
if (!prop) {
|
|
101
|
+
issues.push(`${key} isn't one of its props (${Object.keys(schema.properties).join(", ")})`);
|
|
102
|
+
} else if (
|
|
103
|
+
!validateExtensionProps({ type: "object", properties: { [key]: prop } }, { [key]: value }).ok
|
|
104
|
+
) {
|
|
105
|
+
issues.push(`${key} must be ${expected(prop)}`);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
for (const key of schema.required ?? []) {
|
|
109
|
+
const prop = schema.properties[key];
|
|
110
|
+
if (props[key] === undefined && !(prop && "default" in prop && prop.default !== undefined))
|
|
111
|
+
issues.push(`${key} is required`);
|
|
112
|
+
}
|
|
113
|
+
return issues;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* The props an extension element may store: checked by its schema, with the schema's defaults
|
|
118
|
+
* for props left out. REFUSED when the extension isn't registered, INVALID_INPUT naming each
|
|
119
|
+
* wrong prop otherwise.
|
|
120
|
+
*/
|
|
121
|
+
export function checkedExtensionProps(type: string, props: unknown): Record<string, unknown> {
|
|
122
|
+
const live = liveElement(type);
|
|
123
|
+
if (!live) {
|
|
124
|
+
throw new McpToolError(
|
|
125
|
+
"REFUSED",
|
|
126
|
+
`Unknown element type ${type}: no extension on this site provides it. Call list_element_types.`,
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
const given = props && typeof props === "object" && !Array.isArray(props) ? props : {};
|
|
130
|
+
const result = validateExtensionProps(live.element.schema, given);
|
|
131
|
+
if (result.ok) return result.props;
|
|
132
|
+
const issues = propIssues(live.element.schema, given as Record<string, unknown>);
|
|
133
|
+
throw new McpToolError(
|
|
134
|
+
"INVALID_INPUT",
|
|
135
|
+
`Invalid props for ${type}: ${(issues.length ? issues : ["they don't match its schema"]).join("; ")}. Call list_element_types with this type for its props.`,
|
|
136
|
+
{ issues },
|
|
137
|
+
);
|
|
138
|
+
}
|
package/src/mcp/read.ts
CHANGED
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
SECTION_RECIPES,
|
|
13
13
|
SECTION_TEMPLATES,
|
|
14
14
|
siteTokens,
|
|
15
|
+
validateExtensionProps,
|
|
15
16
|
validateLayout,
|
|
16
17
|
type DesignSystem,
|
|
17
18
|
type ElementType,
|
|
@@ -26,6 +27,7 @@ import { requiredFieldIssues, requiredFieldIssueText } from "../core/forms/bindi
|
|
|
26
27
|
import { isFormNode } from "../core/schema/layout.ts";
|
|
27
28
|
import { forEachNode, nodeChildren } from "../core/tree-ops.ts";
|
|
28
29
|
import { McpToolError } from "./errors.ts";
|
|
30
|
+
import { extensionJsonSchema, registeredExtensionElements } from "./extensions.ts";
|
|
29
31
|
import type { EmvbPorts, PageRecord } from "./ports.ts";
|
|
30
32
|
|
|
31
33
|
/** A stored layout the tools can work on, or a NOT_FOUND / INVALID_LAYOUT error the agent can read. */
|
|
@@ -157,9 +159,8 @@ const SCHEMAS = new Map(
|
|
|
157
159
|
const sample = (type: string): LayoutNode =>
|
|
158
160
|
Object.assign({}, defaultElement(type as ElementType, "sample"), { id: "sample" }) as LayoutNode;
|
|
159
161
|
|
|
160
|
-
/** Which parent types accept `
|
|
161
|
-
function allowedParents(
|
|
162
|
-
const child = sample(type);
|
|
162
|
+
/** Which parent types accept `child`, by the same rule drag-and-drop and save use (W-354). */
|
|
163
|
+
function allowedParents(child: LayoutNode): string[] {
|
|
163
164
|
return ELEMENT_DESCRIPTORS.map((d) => d.type).filter((parentType) => {
|
|
164
165
|
const parent = sample(parentType);
|
|
165
166
|
if (!isParentNode(parent)) return false;
|
|
@@ -181,6 +182,9 @@ export const ListElementTypesOutput = z.object({
|
|
|
181
182
|
props: z.unknown(),
|
|
182
183
|
example: z.unknown(),
|
|
183
184
|
notes: z.string().optional(),
|
|
185
|
+
/** W-1089 (#38): an extension element's inspector fields and its extension's id. */
|
|
186
|
+
fields: z.unknown().optional(),
|
|
187
|
+
extension: z.string().optional(),
|
|
184
188
|
}),
|
|
185
189
|
),
|
|
186
190
|
});
|
|
@@ -205,29 +209,61 @@ const ELEMENT_NOTES: Record<string, string> = {
|
|
|
205
209
|
"Use one per page band. props.contentWidth caps the inner width (for example 1200 px) while the background spans the screen.",
|
|
206
210
|
};
|
|
207
211
|
|
|
212
|
+
/**
|
|
213
|
+
* W-1089 (#38): the extension elements registered on this site, as `ext:<pkg>/<name>` with the
|
|
214
|
+
* extension's prop schema (as JSON Schema), its inspector fields and its schema defaults.
|
|
215
|
+
*/
|
|
216
|
+
function extensionEntries(type: string | undefined) {
|
|
217
|
+
return registeredExtensionElements()
|
|
218
|
+
.filter((element) => type === undefined || element.type === type)
|
|
219
|
+
.map((element) => {
|
|
220
|
+
const example = {
|
|
221
|
+
id: "sample",
|
|
222
|
+
type: element.type,
|
|
223
|
+
props: validateExtensionProps(element.schema, {}).props,
|
|
224
|
+
} as LayoutNode;
|
|
225
|
+
return {
|
|
226
|
+
type: element.type,
|
|
227
|
+
name: element.label,
|
|
228
|
+
group: element.group,
|
|
229
|
+
container: false,
|
|
230
|
+
allowedParents: allowedParents(example),
|
|
231
|
+
props: extensionJsonSchema(element.schema),
|
|
232
|
+
example: { type: element.type, props: example.props },
|
|
233
|
+
fields: element.fields,
|
|
234
|
+
extension: element.extensionId,
|
|
235
|
+
notes: `An extension element from ${element.extensionId}. Its props are checked by the extension's schema; it holds no children.`,
|
|
236
|
+
};
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
|
|
208
240
|
export function listElementTypes(input: z.infer<typeof ListElementTypesInput>) {
|
|
209
241
|
const descriptors = input.type
|
|
210
242
|
? ELEMENT_DESCRIPTORS.filter((d) => d.type === input.type)
|
|
211
243
|
: ELEMENT_DESCRIPTORS;
|
|
212
|
-
|
|
244
|
+
const extensions = extensionEntries(input.type);
|
|
245
|
+
if (input.type && descriptors.length === 0 && extensions.length === 0) {
|
|
213
246
|
throw new McpToolError("NOT_FOUND", `Unknown element type ${input.type}.`);
|
|
214
247
|
}
|
|
215
248
|
return {
|
|
216
|
-
elements:
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
249
|
+
elements: [
|
|
250
|
+
...descriptors.map((d) => {
|
|
251
|
+
const props = SCHEMAS.get(d.type);
|
|
252
|
+
const example = sample(d.type);
|
|
253
|
+
const entry: Record<string, unknown> = {
|
|
254
|
+
type: d.type,
|
|
255
|
+
name: d.name,
|
|
256
|
+
group: d.group,
|
|
257
|
+
container: isParentNode(example),
|
|
258
|
+
allowedParents: allowedParents(example),
|
|
259
|
+
props: props ? z.toJSONSchema(props, { unrepresentable: "any" }) : {},
|
|
260
|
+
example: { type: example.type, props: (example as { props?: unknown }).props ?? {} },
|
|
261
|
+
};
|
|
262
|
+
if (ELEMENT_NOTES[d.type]) entry["notes"] = ELEMENT_NOTES[d.type];
|
|
263
|
+
return entry;
|
|
264
|
+
}),
|
|
265
|
+
...extensions,
|
|
266
|
+
],
|
|
231
267
|
};
|
|
232
268
|
}
|
|
233
269
|
|
package/src/mcp/tools.ts
CHANGED
|
@@ -64,7 +64,7 @@ const READ_TOOLS: ToolDef[] = [
|
|
|
64
64
|
name: "list_element_types",
|
|
65
65
|
title: "List element types",
|
|
66
66
|
description:
|
|
67
|
-
"Lists every EmVB element type with its props JSON Schema, whether it holds children, which parents accept it and a default example. Never invent element types.",
|
|
67
|
+
"Lists every EmVB element type with its props JSON Schema, whether it holds children, which parents accept it and a default example, plus the extension elements registered on this site (ext:<package>/<name>, with their fields). Never invent element types.",
|
|
68
68
|
input: read.ListElementTypesInput,
|
|
69
69
|
output: read.ListElementTypesOutput,
|
|
70
70
|
readOnly: true,
|
|
@@ -155,7 +155,7 @@ const WRITE_TOOLS: ToolDef[] = [
|
|
|
155
155
|
name: "create_page",
|
|
156
156
|
title: "Create a page",
|
|
157
157
|
description:
|
|
158
|
-
"Creates a new unpublished EmVB page with a starter layout, optionally followed by section recipes (hero, features, …), or from a starter page template (template: see list_templates). Returns the page id and rev.",
|
|
158
|
+
"Creates a new unpublished EmVB page with a starter layout, optionally followed by section recipes (hero, features, …), or from a starter page template (template: see list_templates). Without a template or a hero recipe the page starts with an H1 of its title: titleHeading false leaves it out, and an element with an H1 added later replaces it while it is unchanged. Returns the page id and rev.",
|
|
159
159
|
input: write.CreatePageInput,
|
|
160
160
|
output: write.CreatePageOutput,
|
|
161
161
|
readOnly: false,
|
|
@@ -166,7 +166,7 @@ const WRITE_TOOLS: ToolDef[] = [
|
|
|
166
166
|
name: "add_element",
|
|
167
167
|
title: "Add an element",
|
|
168
168
|
description:
|
|
169
|
-
"Adds an element (with optional children) into parentId at index (default: last). Unset props take the type's defaults; ids are generated. Refused with the editor's reason when the parent can't hold it.",
|
|
169
|
+
"Adds an element (with optional children) into parentId at index (default: last). Unset required props take the type's defaults; optional props you leave out stay unset (no sample text, links or prices); ids are generated. Refused with the editor's reason when the parent can't hold it.",
|
|
170
170
|
input: write.AddElementInput,
|
|
171
171
|
output: write.WriteOutput,
|
|
172
172
|
readOnly: false,
|
package/src/mcp/write.ts
CHANGED
|
@@ -2,7 +2,6 @@ import { z } from "zod";
|
|
|
2
2
|
import { boundedArray } from "../core/bounded-array.ts";
|
|
3
3
|
import {
|
|
4
4
|
byteLength,
|
|
5
|
-
defaultElement,
|
|
6
5
|
findNode,
|
|
7
6
|
MAX_LAYOUT_BYTES,
|
|
8
7
|
nameKey,
|
|
@@ -24,6 +23,7 @@ import {
|
|
|
24
23
|
import { stableJson } from "../core/stable-json.ts";
|
|
25
24
|
import { addNode, moveNode, withFreshIds } from "../core/arrange.ts";
|
|
26
25
|
import { ELEMENT_DESCRIPTORS } from "../core/elements/index.ts";
|
|
26
|
+
import { isExtensionType, liveElement } from "../core/extensions/index.ts";
|
|
27
27
|
import { nodeChildren, pageSlug, removeNode, starterLayout, updateNode } from "../core/tree-ops.ts";
|
|
28
28
|
import { isSafeFontStack } from "../core/sanitize/css.ts";
|
|
29
29
|
import { sanitizeMediaUrl } from "../core/sanitize/media-url.ts";
|
|
@@ -36,8 +36,10 @@ import {
|
|
|
36
36
|
patchNestedStyle,
|
|
37
37
|
upgradeLegacyNode,
|
|
38
38
|
} from "../core/migrate/v18.ts";
|
|
39
|
+
import { agentDefaultElement } from "./agent-defaults.ts";
|
|
40
|
+
import { checkedExtensionProps } from "./extensions.ts";
|
|
39
41
|
import { McpToolError } from "./errors.ts";
|
|
40
|
-
import type { EmvbPorts } from "./ports.ts";
|
|
42
|
+
import type { EmvbPorts, PageRecord } from "./ports.ts";
|
|
41
43
|
import { queued } from "./queue.ts";
|
|
42
44
|
import { nestsDeeperThan, resolveDesignRefs } from "./refs.ts";
|
|
43
45
|
import {
|
|
@@ -103,7 +105,10 @@ export async function mutatePage(
|
|
|
103
105
|
tool: string,
|
|
104
106
|
pageId: string,
|
|
105
107
|
expectedRev: string | undefined,
|
|
106
|
-
apply: (
|
|
108
|
+
apply: (
|
|
109
|
+
layout: Layout,
|
|
110
|
+
page: PageRecord,
|
|
111
|
+
) => { layout: Layout; changed: string[]; summary: string },
|
|
107
112
|
): Promise<WriteResult> {
|
|
108
113
|
return queued(`page:${pageId}`, async () => {
|
|
109
114
|
// The retry must read, write and log in order.
|
|
@@ -132,7 +137,7 @@ export async function mutatePage(
|
|
|
132
137
|
"The stored layout can't be read. Repair it in the editor.",
|
|
133
138
|
);
|
|
134
139
|
}
|
|
135
|
-
const next = apply(current.layout);
|
|
140
|
+
const next = apply(current.layout, page);
|
|
136
141
|
refuseUnsafeImageSources(current.layout, next.layout);
|
|
137
142
|
refuseUnsafeLinks(current.layout, next.layout);
|
|
138
143
|
refuseUnsafeSvg(current.layout, next.layout);
|
|
@@ -306,13 +311,27 @@ const BoundedElementSpec = z.preprocess((value, ctx) => {
|
|
|
306
311
|
return upgradeLegacyNode(value);
|
|
307
312
|
}, ElementSpec);
|
|
308
313
|
|
|
314
|
+
/**
|
|
315
|
+
* W-1089 (#38): a registered extension element, its props checked by the extension's schema.
|
|
316
|
+
* Extension elements hold no children (their render output is built-in elements).
|
|
317
|
+
*/
|
|
318
|
+
function buildExtensionNode(spec: ElementSpecT): LayoutNode {
|
|
319
|
+
const { type, props, children, ...rest } = spec;
|
|
320
|
+
delete (rest as { id?: unknown }).id;
|
|
321
|
+
const checked = checkedExtensionProps(type, props ?? {});
|
|
322
|
+
if (children?.length) refused(`${type} is an extension element and holds no children.`);
|
|
323
|
+
return { ...rest, id: "new", type, props: checked } as LayoutNode;
|
|
324
|
+
}
|
|
325
|
+
|
|
309
326
|
function buildNode(spec: ElementSpecT): LayoutNode {
|
|
327
|
+
if (isExtensionType(spec.type)) return buildExtensionNode(spec);
|
|
310
328
|
if (!KNOWN_TYPES.has(spec.type)) {
|
|
311
329
|
refused(`Unknown element type ${spec.type}. Call list_element_types.`);
|
|
312
330
|
}
|
|
313
331
|
const { type, props, children, ...rest } = spec;
|
|
314
332
|
delete (rest as { id?: unknown }).id;
|
|
315
|
-
|
|
333
|
+
// W-1089 (#29): the type's defaults without the Add panel's sample content.
|
|
334
|
+
const base = agentDefaultElement(type as ElementType, "new") as LayoutNode & {
|
|
316
335
|
props?: Record<string, unknown>;
|
|
317
336
|
};
|
|
318
337
|
const node = { ...base, ...rest, props: { ...base.props, ...props } } as LayoutNode;
|
|
@@ -333,6 +352,11 @@ export const CreatePageInput = z.strictObject({
|
|
|
333
352
|
.optional(),
|
|
334
353
|
/** W-1068: start from a starter page template (see list_templates) instead of recipes. */
|
|
335
354
|
template: z.enum(PAGE_TEMPLATES.map((t) => t.id) as [string, ...string[]]).optional(),
|
|
355
|
+
/**
|
|
356
|
+
* W-1089 (#28): a page without a template or a hero recipe starts with an H1 of its title.
|
|
357
|
+
* `false` leaves it out, for an agent that adds its own H1. Unset keeps it.
|
|
358
|
+
*/
|
|
359
|
+
titleHeading: z.boolean().optional(),
|
|
336
360
|
});
|
|
337
361
|
export const CreatePageOutput = z.object({ pageId: z.string(), slug: z.string(), rev: z.string() });
|
|
338
362
|
|
|
@@ -393,6 +417,9 @@ export async function createPage(ports: EmvbPorts, input: z.infer<typeof CreateP
|
|
|
393
417
|
};
|
|
394
418
|
if (recipes[0] === "hero") layout = { ...layout, root: { ...layout.root, children: [] } };
|
|
395
419
|
}
|
|
420
|
+
if (input.titleHeading === false && !input.template) {
|
|
421
|
+
layout = { ...layout, root: { ...layout.root, children: [] } };
|
|
422
|
+
}
|
|
396
423
|
for (const id of recipes) {
|
|
397
424
|
const node = recipeNode(id, design, layout);
|
|
398
425
|
if (node)
|
|
@@ -429,22 +456,57 @@ export const AddElementInput = z.strictObject({
|
|
|
429
456
|
expectedRev: Rev.optional(),
|
|
430
457
|
});
|
|
431
458
|
|
|
459
|
+
const isH1 = (node: LayoutNode): boolean =>
|
|
460
|
+
(node.type === "heading" || node.type === "headline") && propsOf(node)["level"] === 1;
|
|
461
|
+
const h1Ids = (node: LayoutNode): string[] => [
|
|
462
|
+
...(isH1(node) ? [node.id] : []),
|
|
463
|
+
...nodeChildren(node).flatMap(h1Ids),
|
|
464
|
+
];
|
|
465
|
+
|
|
466
|
+
/**
|
|
467
|
+
* W-1089 (#28): the H1 create_page starts a page with, as long as nobody changed it: a heading
|
|
468
|
+
* straight in the root with the page's title as its only text and nothing else set.
|
|
469
|
+
*/
|
|
470
|
+
function untouchedTitleHeading(layout: Layout, title: string): LayoutNode | undefined {
|
|
471
|
+
return nodeChildren(layout.root).find((node) => {
|
|
472
|
+
if (
|
|
473
|
+
node.type !== "heading" ||
|
|
474
|
+
Object.keys(node).some((k) => !["id", "type", "props"].includes(k))
|
|
475
|
+
)
|
|
476
|
+
return false;
|
|
477
|
+
const props = propsOf(node);
|
|
478
|
+
return (
|
|
479
|
+
Object.keys(props).length === 2 && props["level"] === 1 && props["text"] === title.trim()
|
|
480
|
+
);
|
|
481
|
+
});
|
|
482
|
+
}
|
|
483
|
+
|
|
432
484
|
export async function addElement(ports: EmvbPorts, input: z.infer<typeof AddElementInput>) {
|
|
433
485
|
const element = resolveDesignRefs(input.element, (await ports.getDesign()).design);
|
|
434
|
-
return mutatePage(ports, "add_element", input.pageId, input.expectedRev, (layout) => {
|
|
486
|
+
return mutatePage(ports, "add_element", input.pageId, input.expectedRev, (layout, page) => {
|
|
435
487
|
if (!findNode(layout, input.parentId)) {
|
|
436
488
|
refused(
|
|
437
489
|
`No element with id ${input.parentId} on this page to add into. Call get_layout for the ids.`,
|
|
438
490
|
);
|
|
439
491
|
}
|
|
440
492
|
const node = withFreshIds(layout, buildNode(element));
|
|
441
|
-
|
|
493
|
+
let next = arranged(
|
|
442
494
|
addNode(layout, node, {
|
|
443
495
|
parentId: input.parentId,
|
|
444
496
|
index: input.index ?? Number.MAX_SAFE_INTEGER,
|
|
445
497
|
}),
|
|
446
498
|
);
|
|
447
|
-
|
|
499
|
+
const changed = [node.id];
|
|
500
|
+
let summary = `Added ${node.type} ${node.id}`;
|
|
501
|
+
// W-1089 (#28): an agent that builds the page's own H1 replaces the title heading
|
|
502
|
+
// create_page started it with, instead of leaving two H1s with the title out of place.
|
|
503
|
+
const title = h1Ids(node).length > 0 ? untouchedTitleHeading(layout, page.title) : undefined;
|
|
504
|
+
if (title && h1Ids(layout.root).length === 1 && input.parentId !== title.id) {
|
|
505
|
+
next = removeNode(next, title.id).layout;
|
|
506
|
+
changed.push(title.id);
|
|
507
|
+
summary += `; removed the page's title heading ${title.id} (the new element has the page's H1)`;
|
|
508
|
+
}
|
|
509
|
+
return { layout: next, changed, summary };
|
|
448
510
|
});
|
|
449
511
|
}
|
|
450
512
|
|
|
@@ -584,6 +646,19 @@ export async function updateElement(ports: EmvbPorts, input: z.infer<typeof Upda
|
|
|
584
646
|
if (isRecord(style)) copy[top] = patchNestedStyle(style, { [sub]: undefined });
|
|
585
647
|
} else if (isRecord(copy[top])) delete copy[top][sub];
|
|
586
648
|
}
|
|
649
|
+
// W-1089 (#38): an extension element changes only while its extension is registered, and
|
|
650
|
+
// its props must still pass the extension's schema.
|
|
651
|
+
if (isExtensionType(node.type)) {
|
|
652
|
+
if (!liveElement(node.type)) {
|
|
653
|
+
refused(
|
|
654
|
+
`${node.type} can't be changed: no extension on this site provides it. Remove it or install the extension.`,
|
|
655
|
+
);
|
|
656
|
+
}
|
|
657
|
+
const touchesProps =
|
|
658
|
+
"props" in set ||
|
|
659
|
+
(input.unset ?? []).some((path) => path === "props" || path.startsWith("props."));
|
|
660
|
+
if (touchesProps) copy["props"] = checkedExtensionProps(node.type, copy["props"]);
|
|
661
|
+
}
|
|
587
662
|
return copy as LayoutNode;
|
|
588
663
|
});
|
|
589
664
|
return { layout: next, changed: [input.nodeId], summary: `Updated ${input.nodeId}` };
|
|
@@ -4,7 +4,9 @@ import {
|
|
|
4
4
|
extensionOutputKey,
|
|
5
5
|
isExtensionType,
|
|
6
6
|
liveExtensionOutput,
|
|
7
|
+
resolveExtensionSource,
|
|
7
8
|
withExtensionClasses,
|
|
9
|
+
type ExtensionManifest,
|
|
8
10
|
} from "../core/extensions/index.ts";
|
|
9
11
|
import { MAX_DEPTH, MAX_LAYOUT_BYTES } from "../core/limits.ts";
|
|
10
12
|
|
|
@@ -71,3 +73,38 @@ export const extensionRenderRoute: PluginRoute<z.infer<typeof RenderInput>> = {
|
|
|
71
73
|
}),
|
|
72
74
|
}),
|
|
73
75
|
};
|
|
76
|
+
|
|
77
|
+
/** One source's values for the editor's panels; `values: null` when it can't be read here. */
|
|
78
|
+
type ExtensionSourceValues = { id: string; values: Record<string, string> | null };
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* W-1088 (#36): the values of every source an extension panel names, for the editor's left panel,
|
|
82
|
+
* which lists them read-only. Sources are read-only resolvers; their values are cleaned like bound
|
|
83
|
+
* values. `values: null` when the source's code isn't in this server (an extension without
|
|
84
|
+
* `module` on Workers or a production build), it throws, or it doesn't answer in time.
|
|
85
|
+
*/
|
|
86
|
+
export function extensionSourcesRoute(manifests: readonly ExtensionManifest[]): PluginRoute {
|
|
87
|
+
return {
|
|
88
|
+
permission: "content:edit_any",
|
|
89
|
+
handler: async () => {
|
|
90
|
+
const wanted = new Map<string, { pkg: string; name: string }>();
|
|
91
|
+
for (const manifest of manifests) {
|
|
92
|
+
for (const panel of manifest.panels) {
|
|
93
|
+
if (!panel.source) continue;
|
|
94
|
+
if (!manifest.sources.some((source) => source.name === panel.source)) continue;
|
|
95
|
+
wanted.set(`ext:${manifest.id}/${panel.source}`, {
|
|
96
|
+
pkg: manifest.id,
|
|
97
|
+
name: panel.source,
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
const sources: ExtensionSourceValues[] = await Promise.all(
|
|
102
|
+
[...wanted].map(async ([id, { pkg, name }]) => ({
|
|
103
|
+
id,
|
|
104
|
+
values: (await resolveExtensionSource(pkg, name)) ?? null,
|
|
105
|
+
})),
|
|
106
|
+
);
|
|
107
|
+
return { sources };
|
|
108
|
+
},
|
|
109
|
+
};
|
|
110
|
+
}
|
package/src/server/plugin.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { setLoopCollections } from "../core/loop-collections.ts";
|
|
2
2
|
import { setGeoTrust } from "../core/geo-trust.ts";
|
|
3
|
+
import { setVisitorCookie } from "../core/visitor-cookie.ts";
|
|
3
4
|
import {
|
|
4
5
|
proposalCreateRoute,
|
|
5
6
|
proposalGetRoute,
|
|
@@ -36,7 +37,7 @@ import {
|
|
|
36
37
|
import { canvasStyleUrls } from "../core/canvas-styles.ts";
|
|
37
38
|
import { canvasCollectionSlugs, setCanvasCollections } from "../core/canvas-collections.ts";
|
|
38
39
|
import { manifestsFromOptions } from "../core/extensions/index.ts";
|
|
39
|
-
import { extensionRenderRoute } from "./extension-routes.ts";
|
|
40
|
+
import { extensionRenderRoute, extensionSourcesRoute } from "./extension-routes.ts";
|
|
40
41
|
import { TOOLS } from "../mcp/tools.ts";
|
|
41
42
|
import { mcpRoutes, mcpToolConfig } from "./mcp-routes.ts";
|
|
42
43
|
|
|
@@ -53,9 +54,12 @@ export function createPlugin(
|
|
|
53
54
|
extensions?: unknown;
|
|
54
55
|
trustGeoHeaders?: unknown;
|
|
55
56
|
loopCollections?: unknown;
|
|
57
|
+
visitorCookie?: unknown;
|
|
58
|
+
visitorCookieConsent?: unknown;
|
|
56
59
|
} = {},
|
|
57
60
|
) {
|
|
58
61
|
setGeoTrust(options.trustGeoHeaders);
|
|
62
|
+
setVisitorCookie(options.visitorCookie, options.visitorCookieConsent);
|
|
59
63
|
setLoopCollections(options.loopCollections);
|
|
60
64
|
setCanvasCollections(options.canvasCollections);
|
|
61
65
|
const canvasStyles = canvasStyleUrls(options.canvasStyles);
|
|
@@ -138,6 +142,8 @@ export function createPlugin(
|
|
|
138
142
|
}),
|
|
139
143
|
},
|
|
140
144
|
"editor/extensions/render": extensionRenderRoute,
|
|
145
|
+
// W-1088 (#36): the values of the sources the extension panels name.
|
|
146
|
+
"editor/extensions/sources": extensionSourcesRoute(extensions),
|
|
141
147
|
design: designRoute,
|
|
142
148
|
"design/draft": designDraftRoute,
|
|
143
149
|
"design/save": designSaveRoute,
|