@perkyzz/emvb 0.6.0 → 0.7.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/package.json +1 -1
- package/src/admin/access/RequireEditor.tsx +7 -7
- package/src/admin/access/role.ts +5 -2
- package/src/admin/content-api.ts +10 -3
- package/src/admin/content-item.ts +1 -1
- package/src/admin/editor/A11yCopilot.tsx +104 -56
- package/src/admin/editor/CommandPalette.tsx +29 -13
- package/src/admin/editor/Editor.tsx +82 -20
- package/src/admin/editor/EditorToasts.tsx +26 -0
- package/src/admin/editor/PerfMeter.tsx +97 -72
- package/src/admin/editor/ShareLink.tsx +107 -72
- package/src/admin/editor/ShortcutsDialog.tsx +27 -16
- package/src/admin/editor/Timeline.tsx +255 -160
- package/src/admin/editor/TopBar.tsx +71 -14
- package/src/admin/editor/canvas/CanvasFrame.tsx +10 -1
- package/src/admin/editor/canvas/CanvasTextEdit.tsx +8 -2
- package/src/admin/editor/canvas/drop-line.ts +11 -3
- package/src/admin/editor/canvas/frame-focus-ring.ts +37 -0
- package/src/admin/editor/canvas/use-canvas-dnd.ts +32 -3
- package/src/admin/editor/canvas/vnode-react.tsx +7 -0
- package/src/admin/editor/collection-previews.ts +10 -0
- package/src/admin/editor/dialogs.tsx +38 -14
- package/src/admin/editor/dnd/drop-target.ts +26 -1
- package/src/admin/editor/edited-noun.ts +15 -0
- package/src/admin/editor/editor-chrome.tsx +59 -7
- package/src/admin/editor/editor-commands.ts +2 -1
- package/src/admin/editor/editor-css.ts +72 -22
- package/src/admin/editor/element-chrome.ts +21 -11
- package/src/admin/editor/feature-css.ts +45 -13
- package/src/admin/editor/icons/IconLibraryDialog.tsx +52 -11
- package/src/admin/editor/icons/library.ts +1 -1
- package/src/admin/editor/icons/use-icon-library.ts +5 -2
- package/src/admin/editor/ime.ts +29 -0
- package/src/admin/editor/palette-items.ts +10 -3
- package/src/admin/editor/panels/AddPanel.tsx +35 -10
- package/src/admin/editor/panels/ClassesSection.tsx +18 -7
- package/src/admin/editor/panels/ColorControl.tsx +130 -23
- package/src/admin/editor/panels/ConditionsEditor.tsx +52 -26
- package/src/admin/editor/panels/ElementPanel.tsx +134 -24
- package/src/admin/editor/panels/LayersPanel.tsx +55 -19
- package/src/admin/editor/panels/PageSettings.tsx +66 -35
- package/src/admin/editor/panels/SiteStylesDrawer.tsx +170 -32
- package/src/admin/editor/panels/TokenScales.tsx +76 -36
- package/src/admin/editor/panels/TriggerSettings.tsx +50 -12
- package/src/admin/editor/panels/TriggersEditor.tsx +2 -1
- package/src/admin/editor/panels/VariableSection.tsx +48 -18
- package/src/admin/editor/panels/color-space.ts +9 -3
- package/src/admin/editor/panels/settings/AdvancedFields.tsx +12 -2
- package/src/admin/editor/panels/settings/AudienceEditor.tsx +51 -35
- package/src/admin/editor/panels/settings/BackgroundControls.tsx +55 -11
- package/src/admin/editor/panels/settings/BackgroundFill.tsx +3 -2
- package/src/admin/editor/panels/settings/BindingsEditor.tsx +15 -18
- package/src/admin/editor/panels/settings/BoxControl.tsx +2 -1
- package/src/admin/editor/panels/settings/ClassChip.tsx +21 -9
- package/src/admin/editor/panels/settings/ClassChipInput.tsx +24 -16
- package/src/admin/editor/panels/settings/DraftTextField.tsx +41 -3
- package/src/admin/editor/panels/settings/EffectsControls.tsx +38 -14
- package/src/admin/editor/panels/settings/FieldBindControl.tsx +46 -28
- package/src/admin/editor/panels/settings/FieldControl.tsx +20 -8
- package/src/admin/editor/panels/settings/FormBindControl.tsx +2 -2
- package/src/admin/editor/panels/settings/HintedSwitch.tsx +33 -0
- package/src/admin/editor/panels/settings/IconControls.tsx +12 -8
- package/src/admin/editor/panels/settings/IconPicker.tsx +2 -0
- package/src/admin/editor/panels/settings/ImageSourcesField.tsx +3 -1
- package/src/admin/editor/panels/settings/ItemList.tsx +15 -2
- package/src/admin/editor/panels/settings/LengthRow.tsx +8 -6
- package/src/admin/editor/panels/settings/MediaPicker.tsx +127 -23
- package/src/admin/editor/panels/settings/MotionControl.tsx +28 -15
- package/src/admin/editor/panels/settings/NumberRow.tsx +9 -3
- package/src/admin/editor/panels/settings/PanelSelect.tsx +50 -0
- package/src/admin/editor/panels/settings/QueryStyleRows.tsx +25 -18
- package/src/admin/editor/panels/settings/RequiredFieldsNotice.tsx +66 -1
- package/src/admin/editor/panels/settings/StyleRow.tsx +10 -3
- package/src/admin/editor/panels/settings/StyleSources.tsx +4 -1
- package/src/admin/editor/panels/settings/VariantEditor.tsx +10 -1
- package/src/admin/editor/panels/settings/box-link-name.ts +6 -2
- package/src/admin/editor/panels/settings/class-suggest.ts +7 -7
- package/src/admin/editor/panels/settings/query-style.ts +38 -9
- package/src/admin/editor/panels/settings/svg-images.ts +13 -0
- package/src/admin/editor/panels/site-list.tsx +20 -6
- package/src/admin/editor/panels/variable-values.ts +11 -4
- package/src/admin/editor/restore-deleted.ts +21 -2
- package/src/admin/editor/section-templates.ts +81 -12
- package/src/admin/editor/shortcuts.ts +17 -2
- package/src/admin/editor/store.ts +7 -0
- package/src/admin/editor/useEditorCommands.ts +61 -15
- package/src/admin/editor/useEditorData.ts +4 -2
- package/src/admin/editor/useEditorShortcuts.ts +17 -7
- package/src/admin/editor/useNodeActions.ts +61 -6
- package/src/admin/editor/useSave.ts +22 -7
- package/src/admin/forms-api.ts +2 -0
- package/src/admin/image-editor/CurvesPanel.tsx +2 -1
- package/src/admin/image-editor/ExportDialog.tsx +48 -18
- package/src/admin/image-editor/ImageEditorDialog.tsx +49 -7
- package/src/admin/image-editor/MetadataPanel.tsx +15 -4
- package/src/admin/image-editor/crop-geometry.ts +3 -2
- package/src/admin/image-editor/image-editor-css.ts +4 -2
- package/src/admin/image-editor/load.ts +9 -2
- package/src/admin/image-editor/parts.tsx +51 -2
- package/src/admin/image-editor/save.ts +23 -7
- package/src/admin/media-api.ts +2 -1
- package/src/admin/pages/AgentsPage.tsx +138 -27
- package/src/admin/pages/CreateDialog.tsx +97 -30
- package/src/admin/pages/NewPageDialog.tsx +21 -3
- package/src/admin/pages/NewThemePartDialog.tsx +11 -3
- package/src/admin/pages/PageList.tsx +14 -6
- package/src/admin/pages/SetupShell.tsx +28 -12
- package/src/admin/pages/ThemePartList.tsx +27 -7
- package/src/admin/pages/list-kit.tsx +106 -24
- package/src/admin/search.ts +15 -0
- package/src/admin/setup/useSetupStatus.ts +1 -1
- package/src/admin/theme-api.ts +13 -3
- package/src/admin/ui.ts +73 -22
- package/src/astro/floats/runtime.ts +21 -0
- package/src/astro/menu/runtime.ts +34 -1
- package/src/astro/popups/runtime.ts +33 -3
- package/src/astro/render.ts +3 -0
- package/src/astro/resolve-theme.ts +53 -11
- package/src/astro/resolve.ts +9 -1
- package/src/astro/tabs/runtime.ts +12 -0
- package/src/astro/theme-posts.ts +2 -2
- package/src/astro/visitor.ts +2 -0
- package/src/constants.ts +1 -1
- package/src/core/a11y/audit.ts +171 -24
- package/src/core/arrange.ts +27 -6
- package/src/core/audience/rules.ts +5 -1
- package/src/core/audience/variants.ts +29 -3
- package/src/core/clipboard.ts +7 -0
- package/src/core/css/generate.ts +31 -6
- package/src/core/data/bindings.ts +8 -1
- package/src/core/design/classes.ts +16 -7
- package/src/core/design/diff.ts +6 -0
- package/src/core/design/merge.ts +90 -2
- package/src/core/design/tokens.ts +16 -2
- package/src/core/design/transfer.ts +33 -6
- package/src/core/design/variables.ts +30 -9
- package/src/core/elements/dynamic-elements.ts +44 -5
- package/src/core/elements/form-elements.ts +55 -16
- package/src/core/elements/index.ts +83 -38
- package/src/core/elements/menu.ts +37 -19
- package/src/core/elements/select-prompt.ts +3 -0
- package/src/core/elements/svg-ids.ts +39 -0
- package/src/core/forms/binding.ts +57 -16
- package/src/core/forms/definition.ts +72 -0
- package/src/core/history/diff.ts +18 -1
- package/src/core/icons/catalog.ts +3 -2
- package/src/core/image-edit/schema.ts +11 -1
- package/src/core/image-edit/summary.ts +6 -3
- package/src/core/index.ts +15 -1
- package/src/core/limits.ts +12 -1
- package/src/core/perf/meter.ts +42 -7
- package/src/core/recipes/index.ts +5 -4
- package/src/core/render/context.ts +8 -0
- package/src/core/render/dynamic-post.ts +69 -12
- package/src/core/render/extras.ts +77 -4
- package/src/core/render/form.ts +140 -6
- package/src/core/render/index.ts +156 -20
- package/src/core/render/loop.ts +43 -7
- package/src/core/render/pagination.ts +18 -4
- package/src/core/render/section.ts +27 -0
- package/src/core/render/tabs.ts +12 -3
- package/src/core/render/vnode.ts +1 -1
- package/src/core/sanitize/css.ts +15 -2
- package/src/core/sanitize/embed-url.ts +42 -5
- package/src/core/sanitize/url.ts +2 -1
- package/src/core/schema/layout.ts +15 -6
- package/src/core/stats.ts +2 -1
- package/src/core/theme/conditions.ts +3 -1
- package/src/core/theme/dynamic.ts +36 -5
- package/src/core/theme/float.ts +9 -2
- package/src/core/theme/pagination.ts +31 -11
- package/src/core/theme/popup-markup.ts +23 -5
- package/src/core/theme/popup-rules.ts +1 -0
- package/src/core/theme/triggers.ts +3 -2
- package/src/core/tree-ops.ts +27 -0
- package/src/mcp/rate-limit.ts +2 -1
- package/src/mcp/read.ts +14 -2
- package/src/mcp/refs.ts +18 -0
- package/src/mcp/write.ts +174 -10
- package/src/server/agent-settings.ts +1 -1
- package/src/server/hooks.ts +5 -3
- package/src/server/icon-routes.ts +30 -9
- package/src/server/mcp-routes.ts +6 -1
package/src/mcp/write.ts
CHANGED
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
defaultElement,
|
|
5
5
|
findNode,
|
|
6
6
|
MAX_LAYOUT_BYTES,
|
|
7
|
+
nameKey,
|
|
7
8
|
nestingIssues,
|
|
8
9
|
recipeNode,
|
|
9
10
|
SECTION_RECIPES,
|
|
@@ -15,14 +16,19 @@ import {
|
|
|
15
16
|
type Layout,
|
|
16
17
|
type LayoutNode,
|
|
17
18
|
} from "../core/index.ts";
|
|
19
|
+
import { stableJson } from "../core/stable-json.ts";
|
|
18
20
|
import { addNode, moveNode, withFreshIds } from "../core/arrange.ts";
|
|
19
21
|
import { ELEMENT_DESCRIPTORS } from "../core/elements/index.ts";
|
|
20
|
-
import { nodeChildren,
|
|
22
|
+
import { nodeChildren, pageSlug, removeNode, starterLayout, updateNode } from "../core/tree-ops.ts";
|
|
23
|
+
import { isSafeFontStack } from "../core/sanitize/css.ts";
|
|
21
24
|
import { sanitizeMediaUrl } from "../core/sanitize/media-url.ts";
|
|
25
|
+
import { sanitizeHref } from "../core/sanitize/href.ts";
|
|
26
|
+
import { isSafeSvgMarkup } from "../core/sanitize/svg.ts";
|
|
27
|
+
import { clipText, MAX_DEPTH } from "../core/limits.ts";
|
|
22
28
|
import { McpToolError } from "./errors.ts";
|
|
23
29
|
import type { EmvbPorts } from "./ports.ts";
|
|
24
30
|
import { queued } from "./queue.ts";
|
|
25
|
-
import { resolveDesignRefs } from "./refs.ts";
|
|
31
|
+
import { nestsDeeperThan, resolveDesignRefs } from "./refs.ts";
|
|
26
32
|
import {
|
|
27
33
|
findVariableUsages,
|
|
28
34
|
findVariableUsagesInDesign,
|
|
@@ -111,7 +117,14 @@ async function mutatePage(
|
|
|
111
117
|
}
|
|
112
118
|
const next = apply(current.layout);
|
|
113
119
|
refuseUnsafeImageSources(current.layout, next.layout);
|
|
120
|
+
refuseUnsafeLinks(current.layout, next.layout);
|
|
121
|
+
refuseUnsafeSvg(current.layout, next.layout);
|
|
114
122
|
const layout = checkLayout(next.layout);
|
|
123
|
+
// W-562: a write that changes nothing (an empty set, the same value, a move to its own
|
|
124
|
+
// spot) saved a new version and rev anyway, cluttering the timeline and the agent log.
|
|
125
|
+
if (stableJson(layout) === stableJson(current.layout)) {
|
|
126
|
+
return { pageId, rev: page.rev, changed: [], summary: `Nothing changed (${tool})` };
|
|
127
|
+
}
|
|
115
128
|
try {
|
|
116
129
|
const saved = await ports.savePage(pageId, { layout }, page.rev);
|
|
117
130
|
await ports.log({
|
|
@@ -135,12 +148,85 @@ const refused = (reason: string): never => {
|
|
|
135
148
|
throw new McpToolError("REFUSED", reason);
|
|
136
149
|
};
|
|
137
150
|
|
|
151
|
+
/**
|
|
152
|
+
* W-755: these checks run before the layout is validated, so a write that set `props` to null (or
|
|
153
|
+
* a list) reached them as is and failed as an internal error instead of an invalid layout.
|
|
154
|
+
*/
|
|
155
|
+
const isRecord = (v: unknown): v is Record<string, unknown> =>
|
|
156
|
+
typeof v === "object" && v !== null && !Array.isArray(v);
|
|
157
|
+
|
|
158
|
+
const propsOf = (node: LayoutNode): Record<string, unknown> =>
|
|
159
|
+
isRecord(node.props) ? node.props : {};
|
|
160
|
+
|
|
161
|
+
/** Link props (the element's `href` fields) on each node, keyed by node and prop. */
|
|
162
|
+
function linkValues(root: LayoutNode): Map<string, string> {
|
|
163
|
+
const found = new Map<string, string>();
|
|
164
|
+
const walk = (node: LayoutNode) => {
|
|
165
|
+
const fields = ELEMENT_DESCRIPTORS.find((d) => d.type === node.type)?.fields ?? [];
|
|
166
|
+
const props = propsOf(node);
|
|
167
|
+
for (const field of fields) {
|
|
168
|
+
const value = props[field.key];
|
|
169
|
+
if (field.kind === "href" && typeof value === "string")
|
|
170
|
+
found.set(`${node.id}.${field.key}`, value);
|
|
171
|
+
}
|
|
172
|
+
for (const child of nodeChildren(node)) walk(child);
|
|
173
|
+
};
|
|
174
|
+
walk(root);
|
|
175
|
+
return found;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* W-563: as W-499 for images, a `javascript:` (or other unsafe) link passed validation and the
|
|
180
|
+
* page published the element without it, with nothing telling the agent. Links the write adds
|
|
181
|
+
* or changes must pass the page's link check; ones already stored are left alone.
|
|
182
|
+
*/
|
|
183
|
+
function refuseUnsafeLinks(before: Layout, after: Layout) {
|
|
184
|
+
const old = linkValues(before.root);
|
|
185
|
+
for (const [key, href] of linkValues(after.root)) {
|
|
186
|
+
if (href.trim() === "" || old.get(key) === href || sanitizeHref(href) !== undefined) continue;
|
|
187
|
+
const [id, prop] = key.split(".");
|
|
188
|
+
refused(
|
|
189
|
+
`Element ${id} has the ${prop} ${JSON.stringify(clipText(href, 80))}, which pages can't link to. Use an https:// URL, a path on this site such as /pricing, #section, mailto: or tel:.`,
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/** SVG markup props (an SVG element's `markup`, an icon's `iconSvg`), keyed by node and prop. */
|
|
195
|
+
function svgValues(root: LayoutNode): Map<string, string> {
|
|
196
|
+
const found = new Map<string, string>();
|
|
197
|
+
const walk = (node: LayoutNode) => {
|
|
198
|
+
const props = propsOf(node);
|
|
199
|
+
if (node.type === "svg" && typeof props["markup"] === "string")
|
|
200
|
+
found.set(`${node.id}.markup`, props["markup"]);
|
|
201
|
+
if (typeof props["iconSvg"] === "string") found.set(`${node.id}.iconSvg`, props["iconSvg"]);
|
|
202
|
+
for (const child of nodeChildren(node)) walk(child);
|
|
203
|
+
};
|
|
204
|
+
walk(root);
|
|
205
|
+
return found;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* W-566: SVG with an `onload` handler (or a script, foreignObject, style…) was stored as given and
|
|
210
|
+
* the page then rendered nothing for it, with nothing telling the agent. Markup the write adds or
|
|
211
|
+
* changes must pass the same check the renderer uses; ones already stored are left alone.
|
|
212
|
+
*/
|
|
213
|
+
function refuseUnsafeSvg(before: Layout, after: Layout) {
|
|
214
|
+
const old = svgValues(before.root);
|
|
215
|
+
for (const [key, markup] of svgValues(after.root)) {
|
|
216
|
+
if (markup.trim() === "" || old.get(key) === markup || isSafeSvgMarkup(markup)) continue;
|
|
217
|
+
const [id, prop] = key.split(".");
|
|
218
|
+
refused(
|
|
219
|
+
`Element ${id} has ${prop} the page can't show. Use plain SVG: no scripts, event handlers such as onload, foreignObject, style blocks, links or external images.`,
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
138
224
|
/** Image sources (src and srcset widths) on a node, keyed for comparison. */
|
|
139
225
|
function imageSources(root: LayoutNode): Map<string, string[]> {
|
|
140
226
|
const found = new Map<string, string[]>();
|
|
141
227
|
const walk = (node: LayoutNode) => {
|
|
142
228
|
if (node.type === "image") {
|
|
143
|
-
const props = node
|
|
229
|
+
const props = propsOf(node) as { src?: unknown; sources?: unknown };
|
|
144
230
|
const list = typeof props.src === "string" ? [props.src] : [];
|
|
145
231
|
if (Array.isArray(props.sources)) {
|
|
146
232
|
for (const source of props.sources as { src?: unknown }[]) {
|
|
@@ -185,6 +271,23 @@ const ElementSpec: z.ZodType<ElementSpecT> = z.lazy(() =>
|
|
|
185
271
|
);
|
|
186
272
|
type ElementSpecT = { type: string; props?: Record<string, unknown>; children?: ElementSpecT[] };
|
|
187
273
|
|
|
274
|
+
/**
|
|
275
|
+
* W-652: the recursive spec is checked by recursion, so an element nested a few thousand levels
|
|
276
|
+
* overflowed the stack while the input was validated and the call failed as an internal error.
|
|
277
|
+
* Pages allow 24 levels of elements; anything past a generous bound is refused up front.
|
|
278
|
+
*/
|
|
279
|
+
const BoundedElementSpec = z.preprocess((value, ctx) => {
|
|
280
|
+
if (nestsDeeperThan(value, MAX_DEPTH * 8)) {
|
|
281
|
+
ctx.addIssue({
|
|
282
|
+
code: "custom",
|
|
283
|
+
message: `Elements can be nested at most ${MAX_DEPTH} levels deep.`,
|
|
284
|
+
input: value,
|
|
285
|
+
});
|
|
286
|
+
return z.NEVER;
|
|
287
|
+
}
|
|
288
|
+
return value;
|
|
289
|
+
}, ElementSpec);
|
|
290
|
+
|
|
188
291
|
function buildNode(spec: ElementSpecT): LayoutNode {
|
|
189
292
|
if (!KNOWN_TYPES.has(spec.type)) {
|
|
190
293
|
refused(`Unknown element type ${spec.type}. Call list_element_types.`);
|
|
@@ -237,9 +340,22 @@ function promoteHeroHeading(layout: Layout, title: string): Layout {
|
|
|
237
340
|
);
|
|
238
341
|
}
|
|
239
342
|
|
|
343
|
+
/** Whether any page already has this slug, paging past the first 50 (W-537, at most 1000). */
|
|
344
|
+
async function slugTaken(ports: EmvbPorts, slug: string): Promise<boolean> {
|
|
345
|
+
let cursor: string | undefined;
|
|
346
|
+
for (let i = 0; i < 20; i++) {
|
|
347
|
+
// oxlint-disable-next-line no-await-in-loop -- cursor paging is sequential
|
|
348
|
+
const batch = await ports.listPages({ limit: 50, ...(cursor ? { cursor } : {}) });
|
|
349
|
+
if (batch.pages.some((page) => page.slug === slug)) return true;
|
|
350
|
+
if (!batch.nextCursor) return false;
|
|
351
|
+
cursor = batch.nextCursor;
|
|
352
|
+
}
|
|
353
|
+
return false;
|
|
354
|
+
}
|
|
355
|
+
|
|
240
356
|
export async function createPage(ports: EmvbPorts, input: z.infer<typeof CreatePageInput>) {
|
|
241
357
|
// EmDash derives the slug from the title; refuse a title whose slug is already taken.
|
|
242
|
-
const slug =
|
|
358
|
+
const slug = pageSlug(input.title);
|
|
243
359
|
if (!slug) refused("Give the page a title with letters or digits.");
|
|
244
360
|
const { design } = await ports.getDesign();
|
|
245
361
|
let layout = starterLayout(input.title);
|
|
@@ -265,8 +381,7 @@ export async function createPage(ports: EmvbPorts, input: z.infer<typeof CreateP
|
|
|
265
381
|
}
|
|
266
382
|
if (recipes[0] === "hero") layout = promoteHeroHeading(layout, input.title);
|
|
267
383
|
const checked = checkLayout(layout);
|
|
268
|
-
|
|
269
|
-
if (taken.pages.some((page) => page.slug === slug)) {
|
|
384
|
+
if (await slugTaken(ports, slug)) {
|
|
270
385
|
throw new McpToolError("REFUSED", `The slug "${slug}" is taken. Choose another title.`);
|
|
271
386
|
}
|
|
272
387
|
const created = await ports.createPage({ title: input.title, layout: checked });
|
|
@@ -286,7 +401,7 @@ export const AddElementInput = z.strictObject({
|
|
|
286
401
|
pageId: PageId,
|
|
287
402
|
parentId: NodeIdInput,
|
|
288
403
|
index: z.number().int().min(0).optional(),
|
|
289
|
-
element:
|
|
404
|
+
element: BoundedElementSpec,
|
|
290
405
|
expectedRev: Rev.optional(),
|
|
291
406
|
});
|
|
292
407
|
|
|
@@ -360,9 +475,6 @@ export const UpdateElementInput = z.strictObject({
|
|
|
360
475
|
expectedRev: Rev.optional(),
|
|
361
476
|
});
|
|
362
477
|
|
|
363
|
-
const isRecord = (v: unknown): v is Record<string, unknown> =>
|
|
364
|
-
typeof v === "object" && v !== null && !Array.isArray(v);
|
|
365
|
-
|
|
366
478
|
/**
|
|
367
479
|
* W-510: a new `src` merged into an image's props kept the old picture's extra sizes (the
|
|
368
480
|
* browser went on showing the old picture from srcset), its image-editor record and its media
|
|
@@ -596,6 +708,15 @@ export async function updateSiteStyles(
|
|
|
596
708
|
defaults?: Record<string, unknown>;
|
|
597
709
|
};
|
|
598
710
|
const changes: string[] = [];
|
|
711
|
+
// W-547: a font stack the site CSS can't carry was saved, then dropped from the page.
|
|
712
|
+
for (const font of (input.variables?.fonts ?? []) as { id?: unknown; value?: unknown }[]) {
|
|
713
|
+
if (typeof font.value === "string" && !isSafeFontStack(font.value)) {
|
|
714
|
+
throw new McpToolError(
|
|
715
|
+
"INVALID_INPUT",
|
|
716
|
+
`Font ${String(font.id)}: "${font.value.slice(0, 60)}" can't be used in the site CSS. Use names of letters, digits, spaces, - and _, quoted or not, separated by commas.`,
|
|
717
|
+
);
|
|
718
|
+
}
|
|
719
|
+
}
|
|
599
720
|
for (const kind of VARIABLE_KINDS) {
|
|
600
721
|
const items = input.variables?.[kind] as Item[] | undefined;
|
|
601
722
|
if (items?.length) {
|
|
@@ -603,6 +724,21 @@ export async function updateSiteStyles(
|
|
|
603
724
|
changes.push(`${items.length} ${kind}`);
|
|
604
725
|
}
|
|
605
726
|
}
|
|
727
|
+
// W-564: removing an id the styles don't have "succeeded" with a removed summary.
|
|
728
|
+
const unknown = [
|
|
729
|
+
...(input.removeVariables ?? [])
|
|
730
|
+
.filter(({ kind, id }) => !(draft.variables[kind] ?? []).some((v) => v.id === id))
|
|
731
|
+
.map(({ kind, id }) => `${kind} ${id}`),
|
|
732
|
+
...(input.removeClasses ?? [])
|
|
733
|
+
.filter((id) => !(draft.classes ?? []).some((c) => c.id === id))
|
|
734
|
+
.map((id) => `class ${id}`),
|
|
735
|
+
];
|
|
736
|
+
if (unknown.length > 0) {
|
|
737
|
+
throw new McpToolError(
|
|
738
|
+
"NOT_FOUND",
|
|
739
|
+
`Nothing to remove for ${unknown.join(", ")}. Call get_site_styles for the ids.`,
|
|
740
|
+
);
|
|
741
|
+
}
|
|
606
742
|
if (!input.force && (input.removeVariables?.length || input.removeClasses?.length)) {
|
|
607
743
|
const layouts = await allLayouts(ports);
|
|
608
744
|
const inUse = [
|
|
@@ -648,6 +784,30 @@ export async function updateSiteStyles(
|
|
|
648
784
|
draft["direction"] = input.direction;
|
|
649
785
|
changes.push(`direction ${input.direction}`);
|
|
650
786
|
}
|
|
787
|
+
// W-573: the editor keeps class names, and variable names within a kind, unique (W-277,
|
|
788
|
+
// W-278); an agent's new or renamed one can't take another's name either.
|
|
789
|
+
const clash = (list: Item[] | undefined, touched: unknown[] | undefined, what: string) => {
|
|
790
|
+
const ids = new Set((touched ?? []).map((item) => (item as { id?: unknown }).id));
|
|
791
|
+
const seen = new Map<string, Item>();
|
|
792
|
+
for (const item of list ?? []) {
|
|
793
|
+
const name = (item as { name?: unknown }).name;
|
|
794
|
+
if (typeof name !== "string") continue;
|
|
795
|
+
const key = nameKey(name);
|
|
796
|
+
const other = seen.get(key);
|
|
797
|
+
if (other && (ids.has(item.id) || ids.has(other.id))) {
|
|
798
|
+
const taken = String((other as { name?: unknown }).name);
|
|
799
|
+
throw new McpToolError(
|
|
800
|
+
"INVALID_INPUT",
|
|
801
|
+
`${what} ${item.id} and ${other.id} would both be named "${taken}". Pick another name.`,
|
|
802
|
+
);
|
|
803
|
+
}
|
|
804
|
+
if (!other) seen.set(key, item);
|
|
805
|
+
}
|
|
806
|
+
};
|
|
807
|
+
clash(draft.classes, input.classes, "Classes");
|
|
808
|
+
for (const kind of VARIABLE_KINDS) {
|
|
809
|
+
clash(draft.variables[kind], input.variables?.[kind], `Variables (${kind})`);
|
|
810
|
+
}
|
|
651
811
|
if (changes.length === 0) refused("Nothing to change.");
|
|
652
812
|
const result = validateDesign(draft);
|
|
653
813
|
if (!result.ok) {
|
|
@@ -656,6 +816,10 @@ export async function updateSiteStyles(
|
|
|
656
816
|
`The site styles would be invalid. ${summarizeIssues(result.issues)}`,
|
|
657
817
|
);
|
|
658
818
|
}
|
|
819
|
+
// W-564: the same values again save no new draft revision.
|
|
820
|
+
if (stableJson(result.design) === stableJson(state.design) && state.revision) {
|
|
821
|
+
return { revision: state.revision, summary: "Nothing changed in the site styles draft" };
|
|
822
|
+
}
|
|
659
823
|
const saved = await ports.saveDesign(result.design as DesignSystem, state.revision);
|
|
660
824
|
const summary = `Site styles draft: ${changes.join(", ")}`;
|
|
661
825
|
await ports.log({ target: "styles", tool: "update_site_styles", summary });
|
|
@@ -122,7 +122,7 @@ export const agentsSaveRoute: PluginRoute<z.infer<typeof SaveInput>> = {
|
|
|
122
122
|
ctx.input.settings,
|
|
123
123
|
);
|
|
124
124
|
if (!write.applied) {
|
|
125
|
-
throw PluginRouteError.conflict("The agent settings changed somewhere else.
|
|
125
|
+
throw PluginRouteError.conflict("The agent settings changed somewhere else.");
|
|
126
126
|
}
|
|
127
127
|
const s = ctx.input.settings;
|
|
128
128
|
await appendAgentLog(agentLog(ctx), {
|
package/src/server/hooks.ts
CHANGED
|
@@ -25,7 +25,7 @@ type FieldValidation =
|
|
|
25
25
|
| { ok: false; issues: { code: string; message: string }[] };
|
|
26
26
|
|
|
27
27
|
/** Theme-part fields validated on save, besides the layout (R-061). */
|
|
28
|
-
const THEME_PART_FIELDS: [string, (raw: unknown) => FieldValidation][] = [
|
|
28
|
+
const THEME_PART_FIELDS: [string, (raw: unknown) => FieldValidation, string?][] = [
|
|
29
29
|
[
|
|
30
30
|
"conditions",
|
|
31
31
|
(raw) => {
|
|
@@ -46,6 +46,8 @@ const THEME_PART_FIELDS: [string, (raw: unknown) => FieldValidation][] = [
|
|
|
46
46
|
const result = validateFloatSettings(raw);
|
|
47
47
|
return result.ok ? { ok: true, value: result.settings } : result;
|
|
48
48
|
},
|
|
49
|
+
// W-678: the message read "The theme part float are invalid."
|
|
50
|
+
"float settings",
|
|
49
51
|
],
|
|
50
52
|
];
|
|
51
53
|
|
|
@@ -95,7 +97,7 @@ export async function beforeSave(
|
|
|
95
97
|
}
|
|
96
98
|
|
|
97
99
|
if (event.collection === THEME_PARTS_COLLECTION) {
|
|
98
|
-
for (const [field, validate] of THEME_PART_FIELDS) {
|
|
100
|
+
for (const [field, validate, label = field] of THEME_PART_FIELDS) {
|
|
99
101
|
if (event.content[field] === undefined) continue;
|
|
100
102
|
const result = validate(parseJsonField(event.content[field]));
|
|
101
103
|
if (!result.ok) {
|
|
@@ -104,7 +106,7 @@ export async function beforeSave(
|
|
|
104
106
|
code: result.issues[0]?.code ?? `invalid_${field}`,
|
|
105
107
|
});
|
|
106
108
|
throw new ContentSaveRejectedError(
|
|
107
|
-
`The theme part ${
|
|
109
|
+
`The theme part ${label} are invalid. ${result.issues
|
|
108
110
|
.slice(0, 3)
|
|
109
111
|
.map((i) => i.message)
|
|
110
112
|
.join("; ")}`,
|
|
@@ -29,19 +29,32 @@ type IconStore = {
|
|
|
29
29
|
|
|
30
30
|
const store = (ctx: RouteContext<unknown>) => ctx.storage["icons"] as unknown as IconStore;
|
|
31
31
|
|
|
32
|
-
/**
|
|
33
|
-
|
|
32
|
+
/**
|
|
33
|
+
* The uploads the picker lists, and the most My uploads holds (W-535): past it the oldest
|
|
34
|
+
* uploads dropped off the list and could no longer be seen or deleted.
|
|
35
|
+
*/
|
|
36
|
+
export const UPLOAD_LIST_LIMIT = 100;
|
|
34
37
|
|
|
35
|
-
/**
|
|
36
|
-
|
|
38
|
+
/** An icon's label as typed: trimmed and capped (W-655: a rename may hold a slash, as in "AC/DC"). */
|
|
39
|
+
// W-656: control characters become spaces and invisible or direction-changing marks go, so a
|
|
40
|
+
// name like "evil\u202Egvs.exe" can't show reversed in the picker.
|
|
41
|
+
const iconLabel = (name: string) =>
|
|
37
42
|
clipText(
|
|
38
|
-
name
|
|
39
|
-
.
|
|
40
|
-
|
|
43
|
+
Array.from(name.normalize("NFC"), (ch) => {
|
|
44
|
+
const code = ch.charCodeAt(0);
|
|
45
|
+
return code < 32 || (code >= 127 && code <= 159) ? " " : ch;
|
|
46
|
+
})
|
|
47
|
+
.join("")
|
|
48
|
+
.replace(/[\u200B\u2060\uFEFF\u200E\u200F\u202A-\u202E\u2066-\u2069]/g, "")
|
|
49
|
+
.replace(/ {2,}/g, " ")
|
|
41
50
|
.trim(),
|
|
42
51
|
80,
|
|
43
52
|
).trim() || "Uploaded icon";
|
|
44
53
|
|
|
54
|
+
/** A file name without its folder or extension, as the icon's label. */
|
|
55
|
+
export const uploadName = (name: string) =>
|
|
56
|
+
iconLabel(name.replace(/^.*[\\/]/, "").replace(/\.svg$/i, ""));
|
|
57
|
+
|
|
45
58
|
/**
|
|
46
59
|
* One stored upload safe to send to the editor. Markup that no longer passes the SVG allowlist
|
|
47
60
|
* is left out, so a row written past the upload route cannot carry a script into the picker.
|
|
@@ -52,7 +65,7 @@ export function publicUploadedIcon(id: string, data: UploadedIcon): UploadedIcon
|
|
|
52
65
|
if (!tree) return undefined;
|
|
53
66
|
return {
|
|
54
67
|
id,
|
|
55
|
-
name:
|
|
68
|
+
name: iconLabel(typeof data.name === "string" ? data.name : ""),
|
|
56
69
|
svg: serialize(tree),
|
|
57
70
|
uploadedAt: typeof data.uploadedAt === "string" ? data.uploadedAt : "",
|
|
58
71
|
};
|
|
@@ -87,6 +100,14 @@ export const iconUploadRoute: PluginRoute<z.infer<typeof UploadInput>> = {
|
|
|
87
100
|
handler: async (ctx) => {
|
|
88
101
|
const prepared = prepareUploadedSvg(ctx.input.svg);
|
|
89
102
|
if (!prepared.ok) throw new PluginRouteError("INVALID_SVG", prepared.message, 422);
|
|
103
|
+
const held = await store(ctx).query({ limit: UPLOAD_LIST_LIMIT });
|
|
104
|
+
if (held.items.length >= UPLOAD_LIST_LIMIT) {
|
|
105
|
+
throw new PluginRouteError(
|
|
106
|
+
"UPLOADS_FULL",
|
|
107
|
+
`My uploads holds up to ${UPLOAD_LIST_LIMIT} icons. Delete one you no longer use, then upload again.`,
|
|
108
|
+
409,
|
|
109
|
+
);
|
|
110
|
+
}
|
|
90
111
|
const id = crypto.randomUUID().replaceAll("-", "").slice(0, 16);
|
|
91
112
|
const item: UploadedIcon = {
|
|
92
113
|
name: uploadName(ctx.input.name),
|
|
@@ -113,7 +134,7 @@ export const iconRenameRoute: PluginRoute<z.infer<typeof RenameInput>> = {
|
|
|
113
134
|
handler: async (ctx) => {
|
|
114
135
|
const current = await store(ctx).get(ctx.input.id);
|
|
115
136
|
if (!current) throw new PluginRouteError("NOT_FOUND", "That upload is not in My uploads.", 404);
|
|
116
|
-
const name =
|
|
137
|
+
const name = iconLabel(ctx.input.name.trim().replace(/\.svg$/i, ""));
|
|
117
138
|
// W-390: answer with the same checked markup the list sends; a row that fails the
|
|
118
139
|
// allowlist is not renamed or echoed back.
|
|
119
140
|
const item = publicUploadedIcon(ctx.input.id, { ...current, name });
|
package/src/server/mcp-routes.ts
CHANGED
|
@@ -55,7 +55,11 @@ const parseJson = (raw: unknown) => {
|
|
|
55
55
|
|
|
56
56
|
const summary = (item: Item): PageSummary => ({
|
|
57
57
|
id: item.id,
|
|
58
|
-
|
|
58
|
+
// W-679: a blank title read as "" here while the admin list said "Untitled page".
|
|
59
|
+
title:
|
|
60
|
+
typeof item.data["title"] === "string" && item.data["title"].trim()
|
|
61
|
+
? item.data["title"]
|
|
62
|
+
: "Untitled page",
|
|
59
63
|
slug: item.slug ?? "",
|
|
60
64
|
status: item.status,
|
|
61
65
|
hasDraft: Boolean(item.draftRevisionId && item.draftRevisionId !== item.liveRevisionId),
|
|
@@ -96,6 +100,7 @@ async function loadFormFieldsFromSite(
|
|
|
96
100
|
name: raw.name,
|
|
97
101
|
label: typeof raw.label === "string" ? raw.label : raw.name,
|
|
98
102
|
required: raw.required === true,
|
|
103
|
+
...(typeof raw.type === "string" ? { type: raw.type } : {}),
|
|
99
104
|
});
|
|
100
105
|
}
|
|
101
106
|
}
|