@perkyzz/emvb 0.6.0 → 0.8.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 +2 -2
- package/THIRD_PARTY_NOTICES.md +1 -1
- package/package.json +7 -7
- 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/DialogCloseButton.tsx +16 -0
- package/src/admin/editor/Editor.tsx +115 -20
- package/src/admin/editor/EditorToasts.tsx +26 -0
- package/src/admin/editor/PerfMeter.tsx +92 -73
- package/src/admin/editor/SavedSectionDialogs.tsx +169 -0
- package/src/admin/editor/ShareLink.tsx +102 -72
- package/src/admin/editor/ShortcutsDialog.tsx +37 -18
- package/src/admin/editor/Timeline.tsx +250 -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 +41 -28
- 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 +43 -7
- package/src/admin/editor/editor-commands.ts +17 -2
- package/src/admin/editor/editor-css.ts +75 -24
- package/src/admin/editor/element-chrome.ts +21 -11
- package/src/admin/editor/feature-css.ts +56 -14
- package/src/admin/editor/focus-when-lost.ts +23 -0
- package/src/admin/editor/icons/IconLibraryDialog.tsx +54 -18
- 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 +27 -3
- package/src/admin/editor/panels/AddPanel.tsx +44 -11
- 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 +61 -20
- package/src/admin/editor/panels/LeftPanel.tsx +9 -1
- package/src/admin/editor/panels/PageSettings.tsx +66 -35
- package/src/admin/editor/panels/SavedSectionsGroup.tsx +246 -0
- package/src/admin/editor/panels/SiteStylesDrawer.tsx +224 -42
- package/src/admin/editor/panels/TokenScales.tsx +88 -48
- package/src/admin/editor/panels/TriggerSettings.tsx +50 -12
- package/src/admin/editor/panels/TriggersEditor.tsx +3 -2
- package/src/admin/editor/panels/VariableSection.tsx +48 -18
- package/src/admin/editor/panels/color-space.ts +23 -29
- package/src/admin/editor/panels/settings/AdvancedFields.tsx +12 -2
- package/src/admin/editor/panels/settings/AudienceEditor.tsx +87 -74
- 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 +33 -13
- 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/LoopItemBindControl.tsx +1 -1
- 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 +31 -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/editor/useSavedSections.ts +197 -0
- package/src/admin/forms-api.ts +2 -0
- package/src/admin/image-editor/Canvas.tsx +61 -17
- 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 +179 -8
- 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 +15 -10
- package/src/admin/image-editor/load.ts +9 -2
- package/src/admin/image-editor/parts.tsx +69 -19
- package/src/admin/image-editor/save.ts +54 -8
- 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 +59 -11
- package/src/admin/pages/list-kit.tsx +106 -24
- package/src/admin/saved-sections-api.ts +51 -0
- package/src/admin/search.ts +15 -0
- package/src/admin/setup/useSetupStatus.ts +1 -1
- package/src/admin/theme-api.ts +16 -5
- package/src/admin/ui.ts +82 -22
- package/src/astro/floats/runtime.ts +21 -0
- package/src/astro/menu/runtime.ts +34 -1
- package/src/astro/popups/runtime.ts +41 -9
- 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 +196 -24
- package/src/core/arrange.ts +48 -12
- 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/css/print.ts +5 -0
- package/src/core/data/bindings.ts +8 -1
- package/src/core/design/classes.ts +39 -16
- package/src/core/design/devices.ts +7 -13
- package/src/core/design/diff.ts +6 -0
- package/src/core/design/merge.ts +90 -2
- package/src/core/design/states.ts +7 -13
- 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 +53 -14
- package/src/core/elements/form-elements.ts +55 -16
- package/src/core/elements/index.ts +84 -39
- package/src/core/elements/menu.ts +40 -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/animation-runs.ts +11 -0
- 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 +35 -1
- package/src/core/limits.ts +12 -1
- package/src/core/migrate/index.ts +3 -0
- 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 +44 -8
- 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 +29 -8
- package/src/core/sanitize/embed-url.ts +42 -5
- package/src/core/sanitize/url.ts +2 -1
- package/src/core/saved-sections.ts +318 -0
- package/src/core/schema/design.ts +1 -1
- package/src/core/schema/layout.ts +16 -7
- package/src/core/schema/style.ts +4 -2
- 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 +12 -2
- package/src/core/theme/pagination.ts +50 -29
- package/src/core/theme/part-types.ts +4 -4
- 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/ports.ts +22 -1
- package/src/mcp/rate-limit.ts +2 -1
- package/src/mcp/read.ts +15 -3
- package/src/mcp/refs.ts +18 -0
- package/src/mcp/sections.ts +183 -0
- package/src/mcp/tools.ts +44 -0
- package/src/mcp/write.ts +178 -14
- 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 +8 -1
- package/src/server/plugin.ts +14 -0
- package/src/server/saved-sections.ts +163 -0
|
@@ -28,6 +28,14 @@ function knownTotal(p: ArchivePagination): number | undefined {
|
|
|
28
28
|
: undefined;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
+
/**
|
|
32
|
+
* What leads into the total, dropped with it while the total is unknown: "of", "/" and the like.
|
|
33
|
+
* W-702: more languages ("z", "av", "od", "共"…) and a separator before them ("2, of"); "Strona 2 z"
|
|
34
|
+
* and "第 2 页,共" were left dangling.
|
|
35
|
+
*/
|
|
36
|
+
const TOTAL_LEAD_IN =
|
|
37
|
+
/\s*[,,、·|/–—-]?\s*(?:(?<!\p{L})(?:of|from|out of|sur|de|da|do|von|di|van|av|af|z|ze|od|iš|из|з)|共|中)?\s*[,,、·|/–—-]?\s*$/iu;
|
|
38
|
+
|
|
31
39
|
/**
|
|
32
40
|
* The "Page N of M" text (W-309). `{page}` and `{total}` are filled in; without a known total
|
|
33
41
|
* the text stops before ` of {total}` (or drops `{total}`), so it never shows a wrong count.
|
|
@@ -39,10 +47,7 @@ export function pageCountText(p: ArchivePagination, template: string | undefined
|
|
|
39
47
|
return text.replaceAll("{page}", String(p.page)).replaceAll("{total}", String(total));
|
|
40
48
|
}
|
|
41
49
|
const cut = text.indexOf("{total}");
|
|
42
|
-
const before =
|
|
43
|
-
cut === -1
|
|
44
|
-
? text
|
|
45
|
-
: text.slice(0, cut).replace(/\s*(of|\/|from|sur|de|von|di|van|из)?\s*$/i, "");
|
|
50
|
+
const before = cut === -1 ? text : text.slice(0, cut).replace(TOTAL_LEAD_IN, "");
|
|
46
51
|
// A template that starts with {total} ("{total} pages · page {page}") keeps at least the number.
|
|
47
52
|
return before.replaceAll("{page}", String(p.page)).trim() || String(p.page);
|
|
48
53
|
}
|
|
@@ -104,7 +109,11 @@ export function archivePageTitle(
|
|
|
104
109
|
): string {
|
|
105
110
|
if (page === undefined || page <= 1) return title;
|
|
106
111
|
const wording = template?.trim().includes("{page}") ? template.trim() : PAGED_TITLE;
|
|
107
|
-
|
|
112
|
+
// One pass with a function: `$&` in a title is not a replacement pattern, and a "{page}" in
|
|
113
|
+
// the title stays as written (W-552).
|
|
114
|
+
return wording.replace(/\{(title|page)\}/g, (_, key: string) =>
|
|
115
|
+
key === "title" ? title : String(page),
|
|
116
|
+
);
|
|
108
117
|
}
|
|
109
118
|
|
|
110
119
|
/** One entry of a Pagination bar: a page link, the current page, or a gap (W-222). */
|
|
@@ -113,6 +122,27 @@ export type PaginationItem =
|
|
|
113
122
|
| { kind: "page"; n: number; href: string; current: boolean }
|
|
114
123
|
| { kind: "gap" };
|
|
115
124
|
|
|
125
|
+
const pageItem =
|
|
126
|
+
(p: ArchivePagination) =>
|
|
127
|
+
(n: number): PaginationItem => ({
|
|
128
|
+
kind: "page",
|
|
129
|
+
n,
|
|
130
|
+
href: archivePagePath(p.basePath, n),
|
|
131
|
+
current: n === p.page,
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
/** Previous, then page 1 and a gap (or page 2) before the window that starts at `from`. */
|
|
135
|
+
function leadingItems(p: ArchivePagination, from: number): PaginationItem[] {
|
|
136
|
+
const page = pageItem(p);
|
|
137
|
+
const items: PaginationItem[] = [];
|
|
138
|
+
if (p.page > 1) items.push({ kind: "prev", href: archivePagePath(p.basePath, p.page - 1) });
|
|
139
|
+
if (from > 1) items.push(page(1));
|
|
140
|
+
// W-600: "1 … 3" hides just page 2; show it instead of a gap.
|
|
141
|
+
if (from === 3) items.push(page(2));
|
|
142
|
+
if (from > 3) items.push({ kind: "gap" });
|
|
143
|
+
return items;
|
|
144
|
+
}
|
|
145
|
+
|
|
116
146
|
/**
|
|
117
147
|
* The links a Pagination element shows. Empty when there is only one page. EmDash gives no
|
|
118
148
|
* total count, so the numbers run from 1 to one past the current page (when there is one),
|
|
@@ -122,17 +152,9 @@ export function paginationItems(p: ArchivePagination): PaginationItem[] {
|
|
|
122
152
|
const total = knownTotal(p);
|
|
123
153
|
if (total !== undefined) return totalItems(p, total);
|
|
124
154
|
if (p.page <= 1 && !p.hasMore) return [];
|
|
125
|
-
const
|
|
126
|
-
const page = (n: number): PaginationItem => ({
|
|
127
|
-
kind: "page",
|
|
128
|
-
n,
|
|
129
|
-
href: archivePagePath(p.basePath, n),
|
|
130
|
-
current: n === p.page,
|
|
131
|
-
});
|
|
132
|
-
if (p.page > 1) items.push({ kind: "prev", href: archivePagePath(p.basePath, p.page - 1) });
|
|
155
|
+
const page = pageItem(p);
|
|
133
156
|
const from = Math.max(1, p.page - 2);
|
|
134
|
-
|
|
135
|
-
if (from > 2) items.push({ kind: "gap" });
|
|
157
|
+
const items = leadingItems(p, from);
|
|
136
158
|
for (let n = from; n <= p.page; n++) items.push(page(n));
|
|
137
159
|
if (p.hasMore) {
|
|
138
160
|
items.push(page(p.page + 1));
|
|
@@ -144,32 +166,25 @@ export function paginationItems(p: ArchivePagination): PaginationItem[] {
|
|
|
144
166
|
/** With a known total (W-309): 1, a window around the current page, and the last page. */
|
|
145
167
|
function totalItems(p: ArchivePagination, total: number): PaginationItem[] {
|
|
146
168
|
if (total <= 1) return [];
|
|
147
|
-
const
|
|
148
|
-
const page = (n: number): PaginationItem => ({
|
|
149
|
-
kind: "page",
|
|
150
|
-
n,
|
|
151
|
-
href: archivePagePath(p.basePath, n),
|
|
152
|
-
current: n === p.page,
|
|
153
|
-
});
|
|
154
|
-
if (p.page > 1) items.push({ kind: "prev", href: archivePagePath(p.basePath, p.page - 1) });
|
|
169
|
+
const page = pageItem(p);
|
|
155
170
|
const from = Math.max(1, p.page - 2);
|
|
171
|
+
const items = leadingItems(p, from);
|
|
156
172
|
const to = Math.min(total, p.page + 2);
|
|
157
|
-
if (from > 1) items.push(page(1));
|
|
158
|
-
if (from > 2) items.push({ kind: "gap" });
|
|
159
173
|
for (let n = from; n <= to; n++) items.push(page(n));
|
|
160
|
-
if (to
|
|
174
|
+
if (to === total - 2) items.push(page(total - 1));
|
|
175
|
+
if (to < total - 2) items.push({ kind: "gap" });
|
|
161
176
|
if (to < total) items.push(page(total));
|
|
162
177
|
if (p.page < total) items.push({ kind: "next", href: archivePagePath(p.basePath, p.page + 1) });
|
|
163
178
|
return items;
|
|
164
179
|
}
|
|
165
180
|
|
|
166
|
-
/**
|
|
167
|
-
|
|
181
|
+
/** A text prop of the first Pagination element in an archive layout, if set (W-529, W-532). */
|
|
182
|
+
function paginationText(layout: Layout, key: "titleText" | "archiveTitle"): string | undefined {
|
|
168
183
|
let found: string | undefined;
|
|
169
184
|
const walk = (node: LayoutNode): void => {
|
|
170
185
|
if (found !== undefined) return;
|
|
171
186
|
if (node.type === "pagination") {
|
|
172
|
-
const text = (node.props as
|
|
187
|
+
const text = (node.props as Record<string, unknown>)[key];
|
|
173
188
|
found = typeof text === "string" && text.trim() ? text.trim() : "";
|
|
174
189
|
return;
|
|
175
190
|
}
|
|
@@ -178,3 +193,9 @@ export function paginationTitleText(layout: Layout): string | undefined {
|
|
|
178
193
|
walk(layout.root);
|
|
179
194
|
return found || undefined;
|
|
180
195
|
}
|
|
196
|
+
|
|
197
|
+
/** The first Pagination element's "Page title text" in an archive layout, if set (W-529). */
|
|
198
|
+
export const paginationTitleText = (layout: Layout) => paginationText(layout, "titleText");
|
|
199
|
+
|
|
200
|
+
/** The first Pagination element's "Posts archive title" (replaces "Posts"), if set (W-532). */
|
|
201
|
+
export const paginationArchiveTitle = (layout: Layout) => paginationText(layout, "archiveTitle");
|
|
@@ -45,11 +45,11 @@ export const THEME_PART_TYPE_LABELS: Record<ThemePartType, string> = {
|
|
|
45
45
|
header: "Header",
|
|
46
46
|
footer: "Footer",
|
|
47
47
|
error_404: "Error 404",
|
|
48
|
-
search_results: "Search
|
|
49
|
-
single_page: "Single
|
|
50
|
-
single_post: "Single
|
|
48
|
+
search_results: "Search results",
|
|
49
|
+
single_page: "Single page",
|
|
50
|
+
single_post: "Single post",
|
|
51
51
|
archive: "Archive",
|
|
52
|
-
loop_item: "Loop
|
|
52
|
+
loop_item: "Loop item",
|
|
53
53
|
section: "Section",
|
|
54
54
|
page_template: "Page template",
|
|
55
55
|
popup: "Popup",
|
|
@@ -1,19 +1,31 @@
|
|
|
1
|
+
import { clipText } from "../limits.ts";
|
|
1
2
|
import { escapeAttr } from "../sanitize/escape.ts";
|
|
2
3
|
import type { TriggersDoc } from "./triggers.ts";
|
|
3
4
|
|
|
4
|
-
/**
|
|
5
|
+
/**
|
|
6
|
+
* Minimal chrome styles for public popups (loaded only when popups match). W-758: the close
|
|
7
|
+
* button sticks to the top of a long popup (it scrolled away with the content on phones) and
|
|
8
|
+
* floats, so a long heading wraps beside it instead of running under it.
|
|
9
|
+
*/
|
|
5
10
|
export const POPUP_CHROME_CSS = `
|
|
6
11
|
.emvb-popup{position:fixed;inset:0;z-index:10000;display:flex;align-items:center;justify-content:center;padding:1.5rem;box-sizing:border-box}
|
|
7
12
|
.emvb-popup[hidden]{display:none!important}
|
|
8
13
|
.emvb-popup__backdrop{position:absolute;inset:0;background:rgba(15,23,42,.55)}
|
|
9
14
|
.emvb-popup__dialog{position:relative;z-index:1;max-width:min(36rem,100%);max-height:min(90vh,100%);overflow:auto;background:#fff;color:#0f172a;border-radius:.75rem;box-shadow:0 25px 50px -12px rgba(0,0,0,.35);padding:1.5rem 1.5rem 1.25rem}
|
|
10
|
-
.emvb-popup__close{position:
|
|
15
|
+
.emvb-popup__close{position:sticky;top:-1rem;z-index:1;float:right;margin:-1rem -1rem 0 .5rem;width:2rem;height:2rem;border:0;border-radius:999px;background:inherit;color:inherit;font-size:1.5rem;line-height:1;cursor:pointer}
|
|
11
16
|
.emvb-popup__close:focus-visible{outline:2px solid #2563eb;outline-offset:2px}
|
|
12
17
|
.emvb-popup__content{min-width:12rem}
|
|
13
18
|
`
|
|
14
19
|
.replace(/\n+/g, "")
|
|
15
20
|
.trim();
|
|
16
21
|
|
|
22
|
+
/** Screen reader names for popup and float chrome; unset are "Popup" and "Close" (W-690). */
|
|
23
|
+
export type ChromeLabels = { popup?: string; close?: string };
|
|
24
|
+
|
|
25
|
+
/** A label clipped to 80 characters and escaped for an attribute, or the English fallback. */
|
|
26
|
+
export const chromeLabel = (text: string | undefined, fallback: string) =>
|
|
27
|
+
escapeAttr(clipText(text?.trim() ?? "", 80) || fallback);
|
|
28
|
+
|
|
17
29
|
export type PopupPublicConfig = {
|
|
18
30
|
id: string;
|
|
19
31
|
triggers: TriggersDoc;
|
|
@@ -23,7 +35,13 @@ export type PopupPublicConfig = {
|
|
|
23
35
|
* Wrap rendered popup body HTML with dialog chrome and a JSON config attribute
|
|
24
36
|
* for the optional public runtime (R-031: only loaded when popups are present).
|
|
25
37
|
*/
|
|
26
|
-
export function wrapPopupMarkup(
|
|
38
|
+
export function wrapPopupMarkup(
|
|
39
|
+
id: string,
|
|
40
|
+
bodyHtml: string,
|
|
41
|
+
triggers: TriggersDoc,
|
|
42
|
+
/** W-690: the dialog's fallback name and the close button's name, in the site's language. */
|
|
43
|
+
labels: ChromeLabels = {},
|
|
44
|
+
): string {
|
|
27
45
|
const config: PopupPublicConfig = { id, triggers };
|
|
28
46
|
const configJson = escapeAttr(JSON.stringify(config));
|
|
29
47
|
const safeId = escapeAttr(id);
|
|
@@ -33,8 +51,8 @@ export function wrapPopupMarkup(id: string, bodyHtml: string, triggers: Triggers
|
|
|
33
51
|
`<div class="emvb-popup__backdrop" data-emvb-popup-dismiss tabindex="-1"></div>`,
|
|
34
52
|
// W-282: named "Popup" until the runtime points the name at the content's first heading;
|
|
35
53
|
// naming it after the whole content read every word as the dialog's name.
|
|
36
|
-
`<div class="emvb-popup__dialog" role="dialog" aria-modal="true" aria-label="Popup" tabindex="-1">`,
|
|
37
|
-
`<button type="button" class="emvb-popup__close" data-emvb-popup-dismiss aria-label="Close"><span aria-hidden="true">×</span></button>`,
|
|
54
|
+
`<div class="emvb-popup__dialog" role="dialog" aria-modal="true" aria-label="${chromeLabel(labels.popup, "Popup")}" tabindex="-1">`,
|
|
55
|
+
`<button type="button" class="emvb-popup__close" data-emvb-popup-dismiss aria-label="${chromeLabel(labels.close, "Close")}"><span aria-hidden="true">×</span></button>`,
|
|
38
56
|
`<div class="emvb-popup__content" id="${titleId}">${bodyHtml}</div>`,
|
|
39
57
|
`</div></div>`,
|
|
40
58
|
].join("");
|
|
@@ -4,7 +4,7 @@ import { POPUP_DEVICES, TRIGGER_LIMITS } from "./popup-rules.ts";
|
|
|
4
4
|
|
|
5
5
|
export const TRIGGERS_SCHEMA_VERSION = 1;
|
|
6
6
|
export const MAX_POPUP_TRIGGERS = 8;
|
|
7
|
-
const MAX_CLICK_SELECTOR_LENGTH =
|
|
7
|
+
const MAX_CLICK_SELECTOR_LENGTH = TRIGGER_LIMITS.maxClickSelectorLength;
|
|
8
8
|
const MAX_SHOW_TIMES = 100;
|
|
9
9
|
|
|
10
10
|
/** Open triggers (Elementor-inspired). URL rules / scheduling / A/B deferred (W-081). */
|
|
@@ -97,7 +97,8 @@ export function validateTriggers(raw: unknown): TriggersValidation {
|
|
|
97
97
|
export function isSafeClickSelector(selector: string): boolean {
|
|
98
98
|
const trimmed = selector.trim();
|
|
99
99
|
if (!trimmed || trimmed.length > MAX_CLICK_SELECTOR_LENGTH) return false;
|
|
100
|
-
|
|
100
|
+
// W-613: `>` is the child combinator; the config attribute escapes it, like every quote.
|
|
101
|
+
if (/[<`]/.test(trimmed)) return false;
|
|
101
102
|
if (/javascript:/i.test(trimmed)) return false;
|
|
102
103
|
// Allow common CSS selector chars only.
|
|
103
104
|
return /^[a-zA-Z0-9\s\-_.#[\]=,:()>+~*"'|/]+$/.test(trimmed);
|
package/src/core/tree-ops.ts
CHANGED
|
@@ -183,6 +183,33 @@ export function starterLayout(title: string, random?: () => number): Layout {
|
|
|
183
183
|
};
|
|
184
184
|
}
|
|
185
185
|
|
|
186
|
+
/**
|
|
187
|
+
* W-554: a page's URL slug from its title, made the way EmDash makes entry slugs: NFKC,
|
|
188
|
+
* lowercase, spaces and underscores to hyphens, and letters, digits and marks of any script
|
|
189
|
+
* kept, cut to 80 characters as people see them. Empty when nothing usable is left (EmDash
|
|
190
|
+
* would then name it `untitled-…`). Class and variable ids keep `slugify`'s ASCII.
|
|
191
|
+
*/
|
|
192
|
+
export function pageSlug(text: string, max = 80): string {
|
|
193
|
+
const slug = text
|
|
194
|
+
.normalize("NFKC")
|
|
195
|
+
.toLowerCase()
|
|
196
|
+
.replace(/[\s_]+/gu, "-")
|
|
197
|
+
.replace(/[^\p{L}\p{N}\p{M}-]+/gu, "")
|
|
198
|
+
.replace(/-+/g, "-")
|
|
199
|
+
.replace(/^-+|-+$/g, "");
|
|
200
|
+
if (!/[\p{L}\p{N}]/u.test(slug)) return "";
|
|
201
|
+
let out = "";
|
|
202
|
+
let count = 0;
|
|
203
|
+
for (const { segment } of new Intl.Segmenter(undefined, { granularity: "grapheme" }).segment(
|
|
204
|
+
slug,
|
|
205
|
+
)) {
|
|
206
|
+
if (count >= max) break;
|
|
207
|
+
out += segment;
|
|
208
|
+
count++;
|
|
209
|
+
}
|
|
210
|
+
return out.replace(/-+$/g, "");
|
|
211
|
+
}
|
|
212
|
+
|
|
186
213
|
/** A URL slug from a title: lowercase ASCII letters, digits and single hyphens. */
|
|
187
214
|
export function slugify(text: string): string {
|
|
188
215
|
return text
|
package/src/mcp/ports.ts
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import type { AgentSettings } from "./settings.ts";
|
|
2
2
|
import type { RateClass } from "./rate-limit.ts";
|
|
3
|
-
import type {
|
|
3
|
+
import type {
|
|
4
|
+
DesignSystem,
|
|
5
|
+
Layout,
|
|
6
|
+
Refusal,
|
|
7
|
+
RequiredFieldInfo,
|
|
8
|
+
SavedSection,
|
|
9
|
+
SavedSectionRecord,
|
|
10
|
+
SavedSectionSummary,
|
|
11
|
+
} from "../core/index.ts";
|
|
4
12
|
|
|
5
13
|
/** A page as the tool core sees it: the current draft (or published) data and its revision. */
|
|
6
14
|
export type PageRecord = {
|
|
@@ -82,4 +90,17 @@ export interface EmvbPorts {
|
|
|
82
90
|
formFields?(
|
|
83
91
|
formIds: readonly string[],
|
|
84
92
|
): Promise<ReadonlyMap<string, readonly RequiredFieldInfo[]>>;
|
|
93
|
+
/** W-875: saved sections; without it the saved-section tools answer NOT_SET_UP. */
|
|
94
|
+
savedSections?: SavedSectionsPort;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** Saved sections in plugin storage `emvb_saved_sections` (W-875, D-060). */
|
|
98
|
+
export interface SavedSectionsPort {
|
|
99
|
+
list(): Promise<SavedSectionSummary[]>;
|
|
100
|
+
/** The section read and upgraded; null when there is none; a Refusal when it can't be read. */
|
|
101
|
+
get(id: string): Promise<SavedSection | Refusal | null>;
|
|
102
|
+
/** Stores a new section; a Refusal when the list is full. */
|
|
103
|
+
create(record: SavedSectionRecord): Promise<{ id: string } | Refusal>;
|
|
104
|
+
rename(id: string, name: string): Promise<SavedSectionSummary | Refusal | null>;
|
|
105
|
+
remove(id: string): Promise<boolean>;
|
|
85
106
|
}
|
package/src/mcp/rate-limit.ts
CHANGED
|
@@ -47,10 +47,11 @@ export async function hitRateLimit(
|
|
|
47
47
|
const stored = await store.getVersioned<Window>(key);
|
|
48
48
|
const current = stored && stored.value?.w === w ? stored.value.n : 0;
|
|
49
49
|
if (current >= limit) {
|
|
50
|
+
// W-754: "1 second", not "1 seconds", in the last second of a window.
|
|
50
51
|
const retryAfterSeconds = Math.max(1, Math.ceil((w + windowMs - at) / 1000));
|
|
51
52
|
throw new McpToolError(
|
|
52
53
|
"RATE_LIMITED",
|
|
53
|
-
`Too many ${NOUNS[cls]}: this token may make ${limit} ${per}. Try again in ${retryAfterSeconds} seconds.`,
|
|
54
|
+
`Too many ${NOUNS[cls]}: this token may make ${limit} ${per}. Try again in ${retryAfterSeconds} ${retryAfterSeconds === 1 ? "second" : "seconds"}.`,
|
|
54
55
|
{ retryAfterSeconds, limit, per },
|
|
55
56
|
);
|
|
56
57
|
}
|
package/src/mcp/read.ts
CHANGED
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
type LayoutNode,
|
|
18
18
|
} from "../core/index.ts";
|
|
19
19
|
import { parentChildRefusal } from "../core/arrange.ts";
|
|
20
|
+
import { clipText } from "../core/limits.ts";
|
|
20
21
|
import { KNOWN_NODE_SCHEMAS } from "../core/schema/layout.ts";
|
|
21
22
|
import { requiredFieldIssues, requiredFieldIssueText } from "../core/forms/binding.ts";
|
|
22
23
|
import { isFormNode } from "../core/schema/layout.ts";
|
|
@@ -45,7 +46,7 @@ async function loadPage(
|
|
|
45
46
|
return { page, layout: result.layout };
|
|
46
47
|
}
|
|
47
48
|
|
|
48
|
-
|
|
49
|
+
type OutlineNode = { id: string; type: string; label?: string; children?: OutlineNode[] };
|
|
49
50
|
|
|
50
51
|
/** The tree without props or styles: cheap orientation for an agent (plan § 3 get_layout). */
|
|
51
52
|
function outlineOf(node: LayoutNode): OutlineNode {
|
|
@@ -63,7 +64,7 @@ function summaryText(node: LayoutNode): string | undefined {
|
|
|
63
64
|
const props = (node as { props?: Record<string, unknown> }).props ?? {};
|
|
64
65
|
const text = typeof props["text"] === "string" ? props["text"] : undefined;
|
|
65
66
|
if (!text) return undefined;
|
|
66
|
-
return text.length > 60 ? `${text
|
|
67
|
+
return text.length > 60 ? `${clipText(text, 57)}…` : text;
|
|
67
68
|
}
|
|
68
69
|
|
|
69
70
|
function stats(layout: Layout) {
|
|
@@ -476,11 +477,22 @@ export const ListVersionsOutput = z.object({
|
|
|
476
477
|
),
|
|
477
478
|
});
|
|
478
479
|
|
|
480
|
+
/**
|
|
481
|
+
* W-805: EmDash stores revision times as SQLite UTC text ("2026-10-21 03:17:01") with no zone, so
|
|
482
|
+
* an agent read them as local time. Hand them out as ISO 8601 UTC instead.
|
|
483
|
+
*/
|
|
484
|
+
const utcIso = (at: string) =>
|
|
485
|
+
/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}(\.\d+)?$/.test(at) ? `${at.replace(" ", "T")}Z` : at;
|
|
486
|
+
|
|
479
487
|
export async function listVersions(ports: EmvbPorts, input: z.infer<typeof ListVersionsInput>) {
|
|
480
488
|
const page = await ports.getPage(input.pageId);
|
|
481
489
|
if (!page) throw new McpToolError("NOT_FOUND", `No EmVB page with id ${input.pageId}.`);
|
|
482
490
|
const revisions = await ports.listRevisions(input.pageId, input.limit ?? 20);
|
|
483
491
|
return {
|
|
484
|
-
versions: revisions.map((r) => ({
|
|
492
|
+
versions: revisions.map((r) => ({
|
|
493
|
+
revisionId: r.id,
|
|
494
|
+
at: utcIso(r.createdAt),
|
|
495
|
+
authorId: r.authorId,
|
|
496
|
+
})),
|
|
485
497
|
};
|
|
486
498
|
}
|
package/src/mcp/refs.ts
CHANGED
|
@@ -10,6 +10,21 @@ const KINDS: [keyof DesignSystem["variables"], From][] = [
|
|
|
10
10
|
["spacings", "spacing"],
|
|
11
11
|
];
|
|
12
12
|
|
|
13
|
+
/** True when `value` nests objects or arrays more than `max` levels, checked without recursion. */
|
|
14
|
+
export function nestsDeeperThan(value: unknown, max: number): boolean {
|
|
15
|
+
const stack: [unknown, number][] = [[value, 1]];
|
|
16
|
+
while (stack.length > 0) {
|
|
17
|
+
const [item, depth] = stack.pop() as [unknown, number];
|
|
18
|
+
if (typeof item !== "object" || item === null) continue;
|
|
19
|
+
if (depth > max) return true;
|
|
20
|
+
for (const child of Object.values(item)) stack.push([child, depth + 1]);
|
|
21
|
+
}
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Deeper than any element spec or style the tools accept; refused before the walk below recurses (W-652). */
|
|
26
|
+
const MAX_INPUT_NESTING = 256;
|
|
27
|
+
|
|
13
28
|
const isRecord = (v: unknown): v is Record<string, unknown> =>
|
|
14
29
|
typeof v === "object" && v !== null && !Array.isArray(v);
|
|
15
30
|
|
|
@@ -23,6 +38,9 @@ const isRef = (v: Record<string, unknown>) =>
|
|
|
23
38
|
* Class names in `classes` are checked the same way.
|
|
24
39
|
*/
|
|
25
40
|
export function resolveDesignRefs<T>(value: T, design: DesignSystem): T {
|
|
41
|
+
if (nestsDeeperThan(value, MAX_INPUT_NESTING)) {
|
|
42
|
+
throw new McpToolError("INVALID_INPUT", "This input nests too deeply.");
|
|
43
|
+
}
|
|
26
44
|
const kinds = new Map<string, From[]>();
|
|
27
45
|
for (const [key, from] of KINDS) {
|
|
28
46
|
for (const v of design.variables[key] ?? [])
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import {
|
|
3
|
+
addNode,
|
|
4
|
+
classMergeNotice,
|
|
5
|
+
mergeSectionClasses,
|
|
6
|
+
prepareSavedSection,
|
|
7
|
+
snapshotSection,
|
|
8
|
+
validateDesign,
|
|
9
|
+
validateLayout,
|
|
10
|
+
type SavedSection,
|
|
11
|
+
} from "../core/index.ts";
|
|
12
|
+
import { McpToolError } from "./errors.ts";
|
|
13
|
+
import type { EmvbPorts, SavedSectionsPort } from "./ports.ts";
|
|
14
|
+
import { queued } from "./queue.ts";
|
|
15
|
+
import { mutatePage, NodeIdInput, PageId, Rev, WriteOutput } from "./write.ts";
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Saved-section tools (W-875, D-060). Saves are copies; synced sections are theme parts made in
|
|
19
|
+
* the editor. Inserting brings the section's classes into the site styles draft first (never
|
|
20
|
+
* overwriting a class), then adds the copy to the page, each through its write queue.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
const SectionId = z.string().regex(/^[0-9a-f]{16}$/, "Section ids are 16 hex characters");
|
|
24
|
+
|
|
25
|
+
const portOf = (ports: EmvbPorts): SavedSectionsPort => {
|
|
26
|
+
if (!ports.savedSections) {
|
|
27
|
+
throw new McpToolError("NOT_SET_UP", "Saved sections aren't available on this site.");
|
|
28
|
+
}
|
|
29
|
+
return ports.savedSections;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const SectionSummary = z.object({
|
|
33
|
+
id: z.string(),
|
|
34
|
+
name: z.string(),
|
|
35
|
+
updatedAt: z.string(),
|
|
36
|
+
classCount: z.number(),
|
|
37
|
+
damaged: z.literal(true).optional(),
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
export const ListSavedSectionsInput = z.strictObject({});
|
|
41
|
+
export const ListSavedSectionsOutput = z.object({ sections: z.array(SectionSummary) });
|
|
42
|
+
|
|
43
|
+
export const listSavedSections = async (ports: EmvbPorts) => ({
|
|
44
|
+
sections: await portOf(ports).list(),
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
export const SaveSectionInput = z.strictObject({
|
|
48
|
+
pageId: PageId,
|
|
49
|
+
elementId: NodeIdInput,
|
|
50
|
+
name: z.string().min(1).max(255),
|
|
51
|
+
});
|
|
52
|
+
export const SaveSectionOutput = z.object({
|
|
53
|
+
id: z.string(),
|
|
54
|
+
name: z.string(),
|
|
55
|
+
summary: z.string(),
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
export async function saveSection(ports: EmvbPorts, input: z.infer<typeof SaveSectionInput>) {
|
|
59
|
+
const port = portOf(ports);
|
|
60
|
+
const page = await ports.getPage(input.pageId);
|
|
61
|
+
if (!page) {
|
|
62
|
+
throw new McpToolError("NOT_FOUND", `No EmVB page with id ${input.pageId}. Call list_pages.`);
|
|
63
|
+
}
|
|
64
|
+
const layout = validateLayout(page.layout);
|
|
65
|
+
if (!layout.ok) {
|
|
66
|
+
throw new McpToolError(
|
|
67
|
+
"INVALID_LAYOUT",
|
|
68
|
+
"The stored layout can't be read. Repair it in the editor.",
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
const { design } = await ports.getDesign();
|
|
72
|
+
const now = new Date().toISOString();
|
|
73
|
+
const snap = snapshotSection(layout.layout, input.elementId, design, input.name, now);
|
|
74
|
+
if (!snap.ok) throw new McpToolError("REFUSED", snap.reason);
|
|
75
|
+
const made = await port.create(snap.record);
|
|
76
|
+
if ("ok" in made) throw new McpToolError("REFUSED", made.reason);
|
|
77
|
+
const summary = `Saved ${input.elementId} as the section "${snap.record.name}"`;
|
|
78
|
+
return { id: made.id, name: snap.record.name, summary };
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
async function sectionOf(port: SavedSectionsPort, id: string): Promise<SavedSection> {
|
|
82
|
+
const found = await port.get(id);
|
|
83
|
+
if (!found) {
|
|
84
|
+
throw new McpToolError("NOT_FOUND", `No saved section ${id}. Call list_saved_sections.`);
|
|
85
|
+
}
|
|
86
|
+
if ("ok" in found) throw new McpToolError("REFUSED", found.reason);
|
|
87
|
+
return found;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export const InsertSavedSectionInput = z.strictObject({
|
|
91
|
+
pageId: PageId,
|
|
92
|
+
sectionId: SectionId,
|
|
93
|
+
parentId: NodeIdInput.optional(),
|
|
94
|
+
index: z.number().int().min(0).optional(),
|
|
95
|
+
expectedRev: Rev.optional(),
|
|
96
|
+
});
|
|
97
|
+
export const InsertSavedSectionOutput = WriteOutput.extend({ classes: z.string().nullable() });
|
|
98
|
+
|
|
99
|
+
export async function insertSavedSection(
|
|
100
|
+
ports: EmvbPorts,
|
|
101
|
+
input: z.infer<typeof InsertSavedSectionInput>,
|
|
102
|
+
) {
|
|
103
|
+
const section = await sectionOf(portOf(ports), input.sectionId);
|
|
104
|
+
const place = (root: string) => ({
|
|
105
|
+
parentId: input.parentId ?? root,
|
|
106
|
+
index: input.index ?? Number.MAX_SAFE_INTEGER,
|
|
107
|
+
});
|
|
108
|
+
return queued("styles", async () => {
|
|
109
|
+
const state = await ports.getDesign();
|
|
110
|
+
const page = await ports.getPage(input.pageId);
|
|
111
|
+
if (!page) {
|
|
112
|
+
throw new McpToolError("NOT_FOUND", `No EmVB page with id ${input.pageId}. Call list_pages.`);
|
|
113
|
+
}
|
|
114
|
+
// A stale rev would refuse the page write after the classes were added (W-879).
|
|
115
|
+
if (input.expectedRev !== undefined && page.rev !== input.expectedRev) {
|
|
116
|
+
throw new McpToolError(
|
|
117
|
+
"CONFLICT",
|
|
118
|
+
"The page changed since you read it. Call get_layout again and retry with its rev.",
|
|
119
|
+
{ rev: page.rev },
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
const current = validateLayout(page.layout);
|
|
123
|
+
if (!current.ok) {
|
|
124
|
+
throw new McpToolError(
|
|
125
|
+
"INVALID_LAYOUT",
|
|
126
|
+
"The stored layout can't be read. Repair it in the editor.",
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
// Dry run first, so a refused place never leaves new classes in the styles draft.
|
|
130
|
+
const tried = prepareSavedSection(section, current.layout, state.design);
|
|
131
|
+
if (!tried.ok) throw new McpToolError("REFUSED", tried.reason);
|
|
132
|
+
const fits = addNode(current.layout, tried.node, place(current.layout.root.id));
|
|
133
|
+
if (!fits.ok) throw new McpToolError("REFUSED", fits.reason);
|
|
134
|
+
const merge = mergeSectionClasses(state.design, section.classes);
|
|
135
|
+
if ("ok" in merge) throw new McpToolError("REFUSED", merge.reason);
|
|
136
|
+
const notice = classMergeNotice(merge);
|
|
137
|
+
if (notice) {
|
|
138
|
+
const checked = validateDesign(merge.design);
|
|
139
|
+
if (!checked.ok) throw new McpToolError("REFUSED", "The section's classes can't be added.");
|
|
140
|
+
await ports.saveDesign(checked.design, state.revision);
|
|
141
|
+
await ports.log({ target: "styles", tool: "insert_saved_section", summary: notice });
|
|
142
|
+
}
|
|
143
|
+
const design = merge.design;
|
|
144
|
+
const result = await mutatePage(
|
|
145
|
+
ports,
|
|
146
|
+
"insert_saved_section",
|
|
147
|
+
input.pageId,
|
|
148
|
+
input.expectedRev,
|
|
149
|
+
(layout) => {
|
|
150
|
+
// The merge already in the saved styles: merging again would add "Card 3" (W-875).
|
|
151
|
+
const prepared = prepareSavedSection(section, layout, design, Math.random, merge);
|
|
152
|
+
if (!prepared.ok) throw new McpToolError("REFUSED", prepared.reason);
|
|
153
|
+
const added = addNode(layout, prepared.node, place(layout.root.id));
|
|
154
|
+
if (!added.ok) throw new McpToolError("REFUSED", added.reason);
|
|
155
|
+
return {
|
|
156
|
+
layout: added.layout,
|
|
157
|
+
changed: [prepared.node.id],
|
|
158
|
+
summary: `Added the saved section "${section.name}" as ${prepared.node.id}`,
|
|
159
|
+
};
|
|
160
|
+
},
|
|
161
|
+
);
|
|
162
|
+
return { ...result, classes: notice };
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export const DeleteSavedSectionInput = z.strictObject({ sectionId: SectionId });
|
|
167
|
+
export const DeleteSavedSectionOutput = z.object({ id: z.string(), summary: z.string() });
|
|
168
|
+
|
|
169
|
+
export async function deleteSavedSection(
|
|
170
|
+
ports: EmvbPorts,
|
|
171
|
+
input: z.infer<typeof DeleteSavedSectionInput>,
|
|
172
|
+
) {
|
|
173
|
+
if (!(await portOf(ports).remove(input.sectionId))) {
|
|
174
|
+
throw new McpToolError(
|
|
175
|
+
"NOT_FOUND",
|
|
176
|
+
`No saved section ${input.sectionId}. Call list_saved_sections.`,
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
return {
|
|
180
|
+
id: input.sectionId,
|
|
181
|
+
summary: "Deleted the saved section. Pages that already use a copy keep it.",
|
|
182
|
+
};
|
|
183
|
+
}
|
package/src/mcp/tools.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type { EmvbPorts } from "./ports.ts";
|
|
|
3
3
|
import * as read from "./read.ts";
|
|
4
4
|
import * as write from "./write.ts";
|
|
5
5
|
import * as publish from "./publish.ts";
|
|
6
|
+
import * as sections from "./sections.ts";
|
|
6
7
|
import { McpToolError } from "./errors.ts";
|
|
7
8
|
import { rateClassOf } from "./rate-limit.ts";
|
|
8
9
|
|
|
@@ -122,6 +123,17 @@ const READ_TOOLS: ToolDef[] = [
|
|
|
122
123
|
destructive: false,
|
|
123
124
|
run: (ports, input) => read.listVersions(ports, input),
|
|
124
125
|
}),
|
|
126
|
+
tool({
|
|
127
|
+
name: "list_saved_sections",
|
|
128
|
+
title: "List saved sections",
|
|
129
|
+
description:
|
|
130
|
+
"Lists the site's saved sections (My sections) by id and name, newest first. Insert one with insert_saved_section.",
|
|
131
|
+
input: sections.ListSavedSectionsInput,
|
|
132
|
+
output: sections.ListSavedSectionsOutput,
|
|
133
|
+
readOnly: true,
|
|
134
|
+
destructive: false,
|
|
135
|
+
run: (ports) => sections.listSavedSections(ports),
|
|
136
|
+
}),
|
|
125
137
|
];
|
|
126
138
|
|
|
127
139
|
/** Draft-only write tools (W-457, W-458). Nothing here publishes (D-055). */
|
|
@@ -213,6 +225,38 @@ const WRITE_TOOLS: ToolDef[] = [
|
|
|
213
225
|
destructive: false,
|
|
214
226
|
run: (ports, input) => write.restoreVersion(ports, input),
|
|
215
227
|
}),
|
|
228
|
+
tool({
|
|
229
|
+
name: "save_section",
|
|
230
|
+
title: "Save an element as a section",
|
|
231
|
+
description:
|
|
232
|
+
"Saves a copy of an element and its children, with the classes they use, to My sections under a name. Copies only: synced sections are made in the editor.",
|
|
233
|
+
input: sections.SaveSectionInput,
|
|
234
|
+
output: sections.SaveSectionOutput,
|
|
235
|
+
readOnly: false,
|
|
236
|
+
destructive: false,
|
|
237
|
+
run: (ports, input) => sections.saveSection(ports, input),
|
|
238
|
+
}),
|
|
239
|
+
tool({
|
|
240
|
+
name: "insert_saved_section",
|
|
241
|
+
title: "Insert a saved section",
|
|
242
|
+
description:
|
|
243
|
+
"Adds a copy of a saved section at parentId/index (default: end of the page). Classes it uses are added to the site styles draft when missing; a class with the same name but a different look is added as a numbered copy, never overwritten.",
|
|
244
|
+
input: sections.InsertSavedSectionInput,
|
|
245
|
+
output: sections.InsertSavedSectionOutput,
|
|
246
|
+
readOnly: false,
|
|
247
|
+
destructive: false,
|
|
248
|
+
run: (ports, input) => sections.insertSavedSection(ports, input),
|
|
249
|
+
}),
|
|
250
|
+
tool({
|
|
251
|
+
name: "delete_saved_section",
|
|
252
|
+
title: "Delete a saved section",
|
|
253
|
+
description: "Removes a section from My sections. Pages that already hold a copy keep it.",
|
|
254
|
+
input: sections.DeleteSavedSectionInput,
|
|
255
|
+
output: sections.DeleteSavedSectionOutput,
|
|
256
|
+
readOnly: false,
|
|
257
|
+
destructive: true,
|
|
258
|
+
run: (ports, input) => sections.deleteSavedSection(ports, input),
|
|
259
|
+
}),
|
|
216
260
|
];
|
|
217
261
|
|
|
218
262
|
/** Publish tools (W-464). They refuse unless the admin allowed agent publishing (D-055). */
|