@perkyzz/emvb 0.9.0 → 1.1.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 +10 -1
- package/package.json +2 -2
- package/src/admin/agents-api.ts +45 -0
- package/src/admin/bulk-api.ts +67 -0
- package/src/admin/content-api.ts +10 -6
- package/src/admin/copy-rich-text.ts +119 -0
- package/src/admin/dialog-tab-wrap.ts +78 -0
- package/src/admin/editor/A11yCopilot.tsx +3 -1
- package/src/admin/editor/Editor.tsx +311 -250
- package/src/admin/editor/Timeline.tsx +8 -3
- package/src/admin/editor/TopBar.tsx +29 -7
- package/src/admin/editor/canvas/CanvasFrame.tsx +7 -2
- package/src/admin/editor/canvas/DeviceBar.tsx +31 -10
- package/src/admin/editor/canvas/canvas-scale.ts +3 -3
- package/src/admin/editor/canvas/use-canvas-session.ts +2 -2
- package/src/admin/editor/co-design.ts +190 -0
- package/src/admin/editor/dnd/new-element.ts +48 -4
- package/src/admin/editor/editor-chrome.tsx +8 -6
- package/src/admin/editor/editor-commands.ts +15 -4
- package/src/admin/editor/editor-css.ts +2 -1
- package/src/admin/editor/element-chrome.ts +3 -1
- package/src/admin/editor/extension-manifests.ts +20 -0
- package/src/admin/editor/extensions/ExtensionPanels.tsx +26 -0
- package/src/admin/editor/extensions-context.tsx +27 -0
- package/src/admin/editor/feature-css.ts +17 -0
- package/src/admin/editor/palette-items.ts +2 -2
- package/src/admin/editor/panels/AddPanel.tsx +31 -1
- package/src/admin/editor/panels/AgentRequestBox.tsx +116 -0
- package/src/admin/editor/panels/ClassesSection.tsx +9 -6
- package/src/admin/editor/panels/CoDesignPanel.tsx +170 -0
- package/src/admin/editor/panels/ColorControl.tsx +2 -2
- package/src/admin/editor/panels/ElementPanel.tsx +68 -20
- package/src/admin/editor/panels/LanguagesSection.tsx +152 -0
- package/src/admin/editor/panels/LayersPanel.tsx +10 -6
- package/src/admin/editor/panels/LeftPanel.tsx +33 -5
- package/src/admin/editor/panels/PageSettings.tsx +4 -0
- package/src/admin/editor/panels/SettingsPanel.tsx +21 -2
- package/src/admin/editor/panels/SiteStylesDrawer.tsx +7 -7
- package/src/admin/editor/panels/settings/BackgroundControls.tsx +72 -15
- package/src/admin/editor/panels/settings/BackgroundFill.tsx +8 -6
- package/src/admin/editor/panels/settings/BoxControl.tsx +5 -5
- package/src/admin/editor/panels/settings/EffectsControls.tsx +183 -10
- package/src/admin/editor/panels/settings/FieldControl.tsx +9 -3
- package/src/admin/editor/panels/settings/IconControls.tsx +25 -11
- package/src/admin/editor/panels/settings/LengthRow.tsx +63 -19
- package/src/admin/editor/panels/settings/LoopControl.tsx +269 -0
- package/src/admin/editor/panels/settings/LoopItemBindControl.tsx +19 -1
- package/src/admin/editor/panels/settings/MotionControl.tsx +12 -11
- package/src/admin/editor/panels/settings/QueryStyleRows.tsx +7 -4
- package/src/admin/editor/panels/settings/StyleRow.tsx +120 -13
- package/src/admin/editor/panels/settings/TextMarksControl.tsx +247 -0
- package/src/admin/editor/panels/settings/VariableBinding.tsx +2 -2
- package/src/admin/editor/panels/settings/background-mode.ts +14 -11
- package/src/admin/editor/panels/settings/box-link-name.ts +1 -1
- package/src/admin/editor/panels/settings/box-sides.ts +22 -14
- package/src/admin/editor/panels/settings/heading-warning.ts +5 -1
- package/src/admin/editor/panels/settings/length-units.ts +68 -4
- package/src/admin/editor/panels/settings/query-style.ts +3 -3
- package/src/admin/editor/panels/settings/style-sections.ts +52 -10
- package/src/admin/editor/panels/style-target.ts +22 -7
- package/src/admin/editor/presence.ts +60 -0
- package/src/admin/editor/section-templates.ts +26 -4
- package/src/admin/editor/store.ts +14 -4
- package/src/admin/editor/useCoDesign.ts +177 -0
- package/src/admin/editor/useEditorCommands.ts +7 -5
- package/src/admin/editor/useExtensions.ts +45 -0
- package/src/admin/editor/useNodeActions.ts +18 -7
- package/src/admin/editor/useProposals.ts +81 -0
- package/src/admin/export-api.ts +221 -0
- package/src/admin/index.tsx +6 -1
- package/src/admin/languages-api.ts +61 -0
- package/src/admin/pages/AgentSetup.tsx +148 -0
- package/src/admin/pages/AgentsPage.tsx +9 -26
- package/src/admin/pages/CreateDialog.tsx +15 -0
- package/src/admin/pages/ExportDialog.tsx +395 -0
- package/src/admin/pages/ImportButton.tsx +18 -0
- package/src/admin/pages/ImportElementorDialog.tsx +669 -0
- package/src/admin/pages/ImportPageLinks.tsx +86 -0
- package/src/admin/pages/PageList.tsx +82 -3
- package/src/admin/pages/ThemePartList.tsx +52 -2
- package/src/admin/pages/bulk.tsx +303 -0
- package/src/admin/pages/section-head.tsx +27 -0
- package/src/admin/proposals-api.ts +91 -0
- package/src/admin/search.ts +20 -0
- package/src/admin/theme-api.ts +4 -0
- package/src/admin/ui.ts +50 -4
- package/src/admin/widgets/CanvasField.tsx +8 -0
- package/src/admin/widgets/ConvertToRichText.tsx +136 -0
- package/src/admin/widgets/ExportEntryHtml.tsx +92 -0
- package/src/admin/widgets/convert-body.ts +73 -2
- package/src/astro/content-port.ts +14 -1
- package/src/astro/render.ts +6 -6
- package/src/astro/resolve-theme.ts +25 -8
- package/src/astro/resolve.ts +89 -2
- package/src/astro/tabs/runtime.ts +16 -6
- package/src/constants.ts +1 -1
- package/src/core/a11y/audit.ts +45 -14
- package/src/core/arrange.ts +5 -1
- package/src/core/bounded-array.ts +31 -0
- package/src/core/clipboard.ts +9 -0
- package/src/core/contract.ts +305 -0
- package/src/core/css/generate.ts +151 -20
- package/src/core/css/scope.ts +10 -2
- package/src/core/css/trace.ts +47 -13
- package/src/core/css-keywords.ts +51 -1
- package/src/core/design/cascade.ts +12 -9
- package/src/core/design/classes.ts +28 -9
- package/src/core/design/devices.ts +89 -13
- package/src/core/design/states.ts +5 -3
- package/src/core/design/transfer.ts +5 -0
- package/src/core/design/variables.ts +31 -5
- package/src/core/elements/dynamic-elements.ts +3 -3
- package/src/core/elements/index.ts +73 -9
- package/src/core/export/runtimes.generated.ts +9 -0
- package/src/core/export/site.ts +562 -0
- package/src/core/export/zip.ts +95 -0
- package/src/core/extensions/define.ts +13 -0
- package/src/core/extensions/index.ts +41 -0
- package/src/core/extensions/namespace.ts +82 -0
- package/src/core/extensions/normalize.ts +141 -0
- package/src/core/extensions/placeholder.ts +41 -0
- package/src/core/extensions/registry.ts +94 -0
- package/src/core/extensions/render-ext.ts +118 -0
- package/src/core/extensions/safe-nodes.ts +93 -0
- package/src/core/extensions/schema.ts +112 -0
- package/src/core/extensions/types.ts +159 -0
- package/src/core/forms/binding.ts +1 -1
- package/src/core/history/diff.ts +26 -1
- package/src/core/import/elementor/atomic.ts +1608 -0
- package/src/core/import/elementor/classes.ts +127 -0
- package/src/core/import/elementor/context.ts +429 -0
- package/src/core/import/elementor/counter-steps.ts +72 -0
- package/src/core/import/elementor/css.ts +445 -0
- package/src/core/import/elementor/html.ts +500 -0
- package/src/core/import/elementor/index.ts +967 -0
- package/src/core/import/elementor/inline-marks.ts +81 -0
- package/src/core/import/elementor/snapshots.ts +48 -0
- package/src/core/import/elementor/style.ts +429 -0
- package/src/core/import/elementor/values.ts +241 -0
- package/src/core/import/elementor/widgets.ts +1897 -0
- package/src/core/index.ts +96 -0
- package/src/core/json-schema.ts +114 -0
- package/src/core/limits.ts +19 -0
- package/src/core/migrate/index.ts +6 -1
- package/src/core/migrate/v18.ts +222 -0
- package/src/core/perf/meter.ts +42 -24
- package/src/core/portable-text-export.ts +243 -0
- package/src/core/proposals-safety.ts +102 -0
- package/src/core/proposals.ts +357 -0
- package/src/core/public-attributes.ts +30 -0
- package/src/core/recipes/index.ts +2 -2
- package/src/core/render/extras.ts +3 -3
- package/src/core/render/index.ts +222 -23
- package/src/core/render/loop.ts +1 -1
- package/src/core/render/section.ts +4 -4
- package/src/core/render/tabs.ts +18 -11
- package/src/core/render/vnode.ts +1 -1
- package/src/core/sanitize/css.ts +151 -10
- package/src/core/sanitize/motion.ts +116 -0
- package/src/core/saved-sections.ts +6 -0
- package/src/core/schema/descriptors.ts +3 -1
- package/src/core/schema/design.ts +4 -3
- package/src/core/schema/layout.ts +92 -16
- package/src/core/schema/style.ts +296 -112
- package/src/core/search-text.ts +70 -0
- package/src/core/text-marks.ts +227 -0
- package/src/core/theme/dynamic.ts +9 -4
- package/src/core/theme/float.ts +2 -0
- package/src/core/theme/popup-rules.ts +33 -1
- package/src/core/translatable.ts +34 -0
- package/src/core/validate.ts +13 -1
- package/src/index.ts +24 -0
- package/src/mcp/errors.ts +3 -1
- package/src/mcp/ports.ts +67 -0
- package/src/mcp/prompts.ts +1 -11
- package/src/mcp/proposals.ts +281 -0
- package/src/mcp/read.ts +10 -10
- package/src/mcp/tools.ts +71 -3
- package/src/mcp/write.ts +66 -11
- package/src/server/agent-settings.ts +5 -1
- package/src/server/icon-routes.ts +52 -12
- package/src/server/mcp-routes.ts +15 -0
- package/src/server/plugin.ts +35 -2
- package/src/server/presence.ts +78 -0
- package/src/server/proposals.ts +261 -0
- package/src/server/requests.ts +196 -0
- package/src/server/tools-served.ts +45 -0
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* W-950: bold, italic, colour and links on part of a Heading's or Text's words. The text stays
|
|
3
|
+
* plain (search, translation and agents read it as before); `marks` are ranges over it.
|
|
4
|
+
*/
|
|
5
|
+
import type { VNode } from "./render/vnode.ts";
|
|
6
|
+
import { cssColor } from "./sanitize/css.ts";
|
|
7
|
+
import { sanitizeHref } from "./sanitize/href.ts";
|
|
8
|
+
import type { LayoutNode, TextMark } from "./schema/layout.ts";
|
|
9
|
+
|
|
10
|
+
/** Distinct colours one element can use in its marks; a mark past them keeps the text colour. */
|
|
11
|
+
const MAX_MARK_COLORS = 8;
|
|
12
|
+
|
|
13
|
+
/** A mark's colour as CSS, or undefined when unset or refused. */
|
|
14
|
+
const colorOf = (mark: TextMark) => (mark.color === undefined ? undefined : cssColor(mark.color));
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The element's mark colours, in first-use order: each becomes `--emvb-mark-<n>` on the element
|
|
18
|
+
* and `.emvb-mark-c<n>` on its words.
|
|
19
|
+
*/
|
|
20
|
+
export function markColors(marks: readonly TextMark[] | undefined): string[] {
|
|
21
|
+
const out: string[] = [];
|
|
22
|
+
for (const mark of marks ?? []) {
|
|
23
|
+
const css = colorOf(mark);
|
|
24
|
+
if (css && !out.includes(css) && out.length < MAX_MARK_COLORS) out.push(css);
|
|
25
|
+
}
|
|
26
|
+
return out;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
type Run = {
|
|
30
|
+
text: string;
|
|
31
|
+
bold: boolean;
|
|
32
|
+
italic: boolean;
|
|
33
|
+
color?: number;
|
|
34
|
+
href?: string;
|
|
35
|
+
newTab: boolean;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* The text as nodes: words in marks wrapped in `<strong>`, `<em>`, a colour span and `<a>`
|
|
40
|
+
* (consecutive words with the same link share one). Ranges are clipped to the text, links are
|
|
41
|
+
* checked like any link, and `links: false` (an element that is a link itself) leaves them out.
|
|
42
|
+
*/
|
|
43
|
+
export function markedChildren(
|
|
44
|
+
text: string,
|
|
45
|
+
marks: readonly TextMark[] | undefined,
|
|
46
|
+
links = true,
|
|
47
|
+
): (VNode | string)[] {
|
|
48
|
+
if (!marks || marks.length === 0) return [text];
|
|
49
|
+
const colors = markColors(marks);
|
|
50
|
+
const clipped = marks.flatMap((mark) => {
|
|
51
|
+
const start = Math.max(0, Math.min(mark.start, text.length));
|
|
52
|
+
const end = Math.min(mark.end, text.length);
|
|
53
|
+
return end > start ? [{ ...mark, start, end }] : [];
|
|
54
|
+
});
|
|
55
|
+
if (clipped.length === 0) return [text];
|
|
56
|
+
const cuts = [...new Set([0, text.length, ...clipped.flatMap((m) => [m.start, m.end])])].toSorted(
|
|
57
|
+
(a, b) => a - b,
|
|
58
|
+
);
|
|
59
|
+
const runs: Run[] = [];
|
|
60
|
+
for (let i = 0; i < cuts.length - 1; i++) {
|
|
61
|
+
const from = cuts[i] as number;
|
|
62
|
+
const to = cuts[i + 1] as number;
|
|
63
|
+
const on = clipped.filter((m) => m.start <= from && m.end >= to);
|
|
64
|
+
const colored = on.findLast((m) => colorOf(m) !== undefined);
|
|
65
|
+
const colorIndex = colored ? colors.indexOf(colorOf(colored) as string) : -1;
|
|
66
|
+
const linked = links ? on.find((m) => m.href && sanitizeHref(m.href)) : undefined;
|
|
67
|
+
runs.push({
|
|
68
|
+
text: text.slice(from, to),
|
|
69
|
+
bold: on.some((m) => m.bold),
|
|
70
|
+
italic: on.some((m) => m.italic),
|
|
71
|
+
...(colorIndex >= 0 ? { color: colorIndex } : {}),
|
|
72
|
+
...(linked ? { href: sanitizeHref(linked.href as string) } : {}),
|
|
73
|
+
newTab: linked?.newTab === true,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
const out: (VNode | string)[] = [];
|
|
77
|
+
let link: VNode | undefined;
|
|
78
|
+
for (const run of runs) {
|
|
79
|
+
let piece: VNode | string = run.text;
|
|
80
|
+
if (run.color !== undefined)
|
|
81
|
+
piece = { tag: "span", attrs: { class: `emvb-mark-c${run.color}` }, children: [piece] };
|
|
82
|
+
if (run.italic) piece = { tag: "em", attrs: {}, children: [piece] };
|
|
83
|
+
if (run.bold) piece = { tag: "strong", attrs: {}, children: [piece] };
|
|
84
|
+
if (!run.href) {
|
|
85
|
+
link = undefined;
|
|
86
|
+
out.push(piece);
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
const same =
|
|
90
|
+
link && link.attrs["href"] === run.href && (link.attrs["target"] === "_blank") === run.newTab;
|
|
91
|
+
if (link && same) {
|
|
92
|
+
link.children.push(piece);
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
link = {
|
|
96
|
+
tag: "a",
|
|
97
|
+
attrs: {
|
|
98
|
+
class: "emvb-mark-link",
|
|
99
|
+
href: run.href,
|
|
100
|
+
...(run.newTab ? { target: "_blank", rel: "noopener noreferrer" } : {}),
|
|
101
|
+
},
|
|
102
|
+
children: [piece],
|
|
103
|
+
};
|
|
104
|
+
out.push(link);
|
|
105
|
+
}
|
|
106
|
+
return out;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** The CSS for mark colours; sent only on pages whose elements set one. */
|
|
110
|
+
export const MARK_CSS = Array.from(
|
|
111
|
+
{ length: MAX_MARK_COLORS },
|
|
112
|
+
(_, n) => `.emvb-mark-c${n}{color:var(--emvb-mark-${n})}`,
|
|
113
|
+
).join("");
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* W-950: marks follow an edit of the text. The edit is the changed middle between the unchanged
|
|
117
|
+
* start and end: marks after it move, marks inside it shrink, and a mark left empty is dropped.
|
|
118
|
+
*/
|
|
119
|
+
export function shiftMarks(before: string, after: string, marks: readonly TextMark[]): TextMark[] {
|
|
120
|
+
if (before === after) return [...marks];
|
|
121
|
+
let head = 0;
|
|
122
|
+
while (head < before.length && head < after.length && before[head] === after[head]) head++;
|
|
123
|
+
let tail = 0;
|
|
124
|
+
while (
|
|
125
|
+
tail < before.length - head &&
|
|
126
|
+
tail < after.length - head &&
|
|
127
|
+
before[before.length - 1 - tail] === after[after.length - 1 - tail]
|
|
128
|
+
)
|
|
129
|
+
tail++;
|
|
130
|
+
const removedEnd = before.length - tail;
|
|
131
|
+
const delta = after.length - before.length;
|
|
132
|
+
// Text typed right after a mark stays out of it, and so does text typed right before one.
|
|
133
|
+
const move = (at: number, isEnd: boolean) => {
|
|
134
|
+
if (isEnd ? at <= head : at < head) return at;
|
|
135
|
+
if (at >= removedEnd) return at + delta;
|
|
136
|
+
// Inside the replaced part: a start goes to its end, an end to its start.
|
|
137
|
+
return isEnd ? head : head + (after.length - tail - head);
|
|
138
|
+
};
|
|
139
|
+
return marks.flatMap((mark) => {
|
|
140
|
+
const start = move(mark.start, false);
|
|
141
|
+
const end = Math.max(start, move(mark.end, true));
|
|
142
|
+
return end > start ? [{ ...mark, start, end }] : [];
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/** The formats a mark can carry; a link's `newTab` goes with its `href`. */
|
|
147
|
+
export type MarkFormat = "bold" | "italic" | "color" | "href";
|
|
148
|
+
|
|
149
|
+
const FORMAT_KEYS: Record<MarkFormat, readonly (keyof TextMark)[]> = {
|
|
150
|
+
bold: ["bold"],
|
|
151
|
+
italic: ["italic"],
|
|
152
|
+
color: ["color"],
|
|
153
|
+
href: ["href", "newTab"],
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
const hasAnyFormat = (mark: TextMark) =>
|
|
157
|
+
mark.bold === true || mark.italic === true || mark.color !== undefined || mark.href !== undefined;
|
|
158
|
+
|
|
159
|
+
/** True when every character from `start` to `end` has `format`. */
|
|
160
|
+
export function hasFormat(
|
|
161
|
+
marks: readonly TextMark[] | undefined,
|
|
162
|
+
start: number,
|
|
163
|
+
end: number,
|
|
164
|
+
format: MarkFormat,
|
|
165
|
+
): boolean {
|
|
166
|
+
if (end <= start) return false;
|
|
167
|
+
for (let at = start; at < end; at++) {
|
|
168
|
+
if (!(marks ?? []).some((m) => m.start <= at && m.end > at && m[format] !== undefined))
|
|
169
|
+
return false;
|
|
170
|
+
}
|
|
171
|
+
return true;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/** `format` taken off the characters from `start` to `end`; marks around them are split. */
|
|
175
|
+
export function unsetFormat(
|
|
176
|
+
marks: readonly TextMark[] | undefined,
|
|
177
|
+
start: number,
|
|
178
|
+
end: number,
|
|
179
|
+
format: MarkFormat,
|
|
180
|
+
): TextMark[] {
|
|
181
|
+
return (marks ?? []).flatMap((mark) => {
|
|
182
|
+
if (mark[format] === undefined || mark.end <= start || mark.start >= end) return [mark];
|
|
183
|
+
const parts: TextMark[] = [];
|
|
184
|
+
if (mark.start < start) parts.push({ ...mark, end: start });
|
|
185
|
+
const middle: TextMark = {
|
|
186
|
+
...mark,
|
|
187
|
+
start: Math.max(mark.start, start),
|
|
188
|
+
end: Math.min(mark.end, end),
|
|
189
|
+
};
|
|
190
|
+
for (const key of FORMAT_KEYS[format]) delete middle[key];
|
|
191
|
+
if (hasAnyFormat(middle)) parts.push(middle);
|
|
192
|
+
if (mark.end > end) parts.push({ ...mark, start: end });
|
|
193
|
+
return parts;
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/** The characters from `start` to `end` get `format` (replacing any they had). */
|
|
198
|
+
export function setFormat(
|
|
199
|
+
marks: readonly TextMark[] | undefined,
|
|
200
|
+
start: number,
|
|
201
|
+
end: number,
|
|
202
|
+
format: Partial<Pick<TextMark, "bold" | "italic" | "color" | "href" | "newTab">>,
|
|
203
|
+
): TextMark[] {
|
|
204
|
+
let next = [...(marks ?? [])];
|
|
205
|
+
for (const key of Object.keys(format) as (keyof typeof format)[]) {
|
|
206
|
+
if (key !== "newTab") next = unsetFormat(next, start, end, key);
|
|
207
|
+
}
|
|
208
|
+
return [...next, { start, end, ...format }];
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* W-950: after an edit that changed a Heading's or Text's words but not its marks, the marks
|
|
213
|
+
* follow the words (`shiftMarks`); a node left with none drops `marks`.
|
|
214
|
+
*/
|
|
215
|
+
export function withShiftedMarks(before: LayoutNode, after: LayoutNode): LayoutNode {
|
|
216
|
+
if (after.type !== "heading" && after.type !== "text") return after;
|
|
217
|
+
const was = before.props as { text?: unknown; marks?: TextMark[] };
|
|
218
|
+
const now = after.props as { text?: unknown; marks?: TextMark[] };
|
|
219
|
+
if (!now.marks || now.marks !== was.marks) return after;
|
|
220
|
+
if (typeof was.text !== "string" || typeof now.text !== "string" || was.text === now.text)
|
|
221
|
+
return after;
|
|
222
|
+
const marks = shiftMarks(was.text, now.text, now.marks);
|
|
223
|
+
const props: Record<string, unknown> = { ...after.props };
|
|
224
|
+
if (marks.length > 0) props["marks"] = marks;
|
|
225
|
+
else delete props["marks"];
|
|
226
|
+
return { ...after, props } as LayoutNode;
|
|
227
|
+
}
|
|
@@ -61,6 +61,11 @@ export type ThemeDynamicData = {
|
|
|
61
61
|
collections?: Readonly<Record<string, ThemePostFields[]>>;
|
|
62
62
|
/** Site settings bound fields can read (W-307), e.g. `title`, `tagline`, `url`. */
|
|
63
63
|
site?: Readonly<Record<string, string>>;
|
|
64
|
+
/**
|
|
65
|
+
* W-937: this page in each of its published languages, for the Language switcher: `href` is
|
|
66
|
+
* where that language's version lives, `current` marks the page being shown.
|
|
67
|
+
*/
|
|
68
|
+
translations?: readonly { locale: string; href: string; current: boolean }[];
|
|
64
69
|
/** The request's URL parameters, first value per name (W-307). */
|
|
65
70
|
params?: Readonly<Record<string, string>>;
|
|
66
71
|
/** The page's own origin, e.g. `https://example.com`: URL-parameter links stay on it (W-307). */
|
|
@@ -250,7 +255,7 @@ function pruneEmptyLists(nodes: VNode[]): VNode[] {
|
|
|
250
255
|
return keep;
|
|
251
256
|
}
|
|
252
257
|
|
|
253
|
-
/** Collect `loop.
|
|
258
|
+
/** Collect `loop.partId` values so hosts can load Loop Item templates. */
|
|
254
259
|
export function collectLoopItemPartIds(layout: Layout): string[] {
|
|
255
260
|
const ids = new Set<string>();
|
|
256
261
|
forEachNode(
|
|
@@ -258,8 +263,8 @@ export function collectLoopItemPartIds(layout: Layout): string[] {
|
|
|
258
263
|
(node) => {
|
|
259
264
|
if (node.type !== "loop") return;
|
|
260
265
|
const id =
|
|
261
|
-
typeof (node.props as {
|
|
262
|
-
? (node.props as {
|
|
266
|
+
typeof (node.props as { partId?: unknown }).partId === "string"
|
|
267
|
+
? (node.props as { partId: string }).partId.trim()
|
|
263
268
|
: "";
|
|
264
269
|
if (id) ids.add(id);
|
|
265
270
|
},
|
|
@@ -361,7 +366,7 @@ export function collectCollectionLoops(layout: Layout): CollectionLoop[] {
|
|
|
361
366
|
export function collectSectionPartIds(layout: Layout): string[] {
|
|
362
367
|
const ids = new Set<string>();
|
|
363
368
|
const walk = (node: LayoutNode): void => {
|
|
364
|
-
if (node.type === "
|
|
369
|
+
if (node.type === "part-ref") {
|
|
365
370
|
const id =
|
|
366
371
|
typeof (node.props as { partId?: unknown }).partId === "string"
|
|
367
372
|
? (node.props as { partId: string }).partId.trim()
|
package/src/core/theme/float.ts
CHANGED
|
@@ -90,6 +90,8 @@ export function floatHasOwnSurface(layout: Layout, design: DesignSystem): boolea
|
|
|
90
90
|
return [root, ...classes].some(
|
|
91
91
|
(item) =>
|
|
92
92
|
paintsBackground(item.style) ||
|
|
93
|
+
paintsBackground(item.style?.wide) ||
|
|
94
|
+
paintsBackground(item.devices?.laptop) ||
|
|
93
95
|
paintsBackground(item.devices?.tablet) ||
|
|
94
96
|
paintsBackground(item.devices?.mobile),
|
|
95
97
|
);
|
|
@@ -12,12 +12,34 @@ export const TRIGGER_LIMITS = {
|
|
|
12
12
|
export const POPUP_DEVICES = ["desktop", "tablet", "mobile"] as const;
|
|
13
13
|
export type PopupDevice = (typeof POPUP_DEVICES)[number];
|
|
14
14
|
|
|
15
|
+
/**
|
|
16
|
+
* W-956: the devices a page is edited, previewed and hidden on: Laptop sits between Desktop and
|
|
17
|
+
* Tablet. Popup targeting and visitor rules keep Desktop, Tablet and Mobile (a laptop is desktop).
|
|
18
|
+
*/
|
|
19
|
+
export const DEVICES = ["desktop", "laptop", "tablet", "mobile"] as const;
|
|
20
|
+
export type Device = (typeof DEVICES)[number];
|
|
21
|
+
|
|
22
|
+
/** Device override layers, widest first; each narrower one wins over the wider ones. */
|
|
23
|
+
export const STYLE_DEVICES = ["laptop", "tablet", "mobile"] as const;
|
|
24
|
+
export type StyleDevice = (typeof STYLE_DEVICES)[number];
|
|
25
|
+
|
|
15
26
|
/**
|
|
16
27
|
* Widths that agree with `deviceForWidth` (W-096). The canvas lays the page out at 1280 on
|
|
17
28
|
* desktop (at least), 768 on tablet and 390 on mobile, scaled to fit (W-158, D-046); Preview opens
|
|
18
29
|
* the same widths. Public CSS uses the matching max-width queries.
|
|
19
30
|
*/
|
|
20
|
-
export const DEVICE_PREVIEW_PX = { desktop: 1280, tablet: 768, mobile: 390 } as const;
|
|
31
|
+
export const DEVICE_PREVIEW_PX = { desktop: 1280, laptop: 1200, tablet: 768, mobile: 390 } as const;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* W-959 (1.1): the devices the editor shows, Wide screen first. Wide screen is not a `hiddenOn`
|
|
35
|
+
* value (1.0 would refuse it): its values and hide live in the own style's `wide` record.
|
|
36
|
+
*/
|
|
37
|
+
export const EDITOR_DEVICES = ["wide", ...DEVICES] as const;
|
|
38
|
+
export type EditorDevice = (typeof EDITOR_DEVICES)[number];
|
|
39
|
+
|
|
40
|
+
/** W-959: Wide screen starts at 2400 px (Elementor's widescreen); the canvas lays it out at 2560. */
|
|
41
|
+
export const WIDE_MIN_PX = 2400;
|
|
42
|
+
export const WIDE_PREVIEW_PX = 2560;
|
|
21
43
|
|
|
22
44
|
/**
|
|
23
45
|
* Public CSS queries. Bounds match `deviceForWidth`: below 768 mobile, below 1025 tablet.
|
|
@@ -26,11 +48,21 @@ export const DEVICE_PREVIEW_PX = { desktop: 1280, tablet: 768, mobile: 390 } as
|
|
|
26
48
|
* hidden on both showed. The max bounds sit just under the next device's min (as Bootstrap does).
|
|
27
49
|
*/
|
|
28
50
|
export const DEVICE_MEDIA = {
|
|
51
|
+
/** W-956: laptops are 1025 to 1366 px wide. */
|
|
52
|
+
laptop: "(max-width: 1366.98px)",
|
|
29
53
|
tablet: "(max-width: 1024.98px)",
|
|
30
54
|
mobile: "(max-width: 767.98px)",
|
|
55
|
+
/** Hidden on Desktop and Laptop: every page saved before W-956 that hid on Desktop. */
|
|
31
56
|
hideDesktop: "(min-width: 1025px)",
|
|
57
|
+
hideDesktopOnly: "(min-width: 1367px)",
|
|
58
|
+
hideLaptop: "(min-width: 1025px) and (max-width: 1366.98px)",
|
|
32
59
|
hideTablet: "(min-width: 768px) and (max-width: 1024.98px)",
|
|
33
60
|
hideMobile: "(max-width: 767.98px)",
|
|
61
|
+
/** W-959: Wide screen, 2400 px and up. */
|
|
62
|
+
wide: "(min-width: 2400px)",
|
|
63
|
+
/** An element hidden on Desktop that Wide screen shows again (`wide.hidden: false`). */
|
|
64
|
+
hideDesktopNotWide: "(min-width: 1025px) and (max-width: 2399.98px)",
|
|
65
|
+
hideDesktopOnlyNotWide: "(min-width: 1367px) and (max-width: 2399.98px)",
|
|
34
66
|
} as const;
|
|
35
67
|
|
|
36
68
|
/** A scroll percent as a number from 0 to 100; anything unreadable is 0. */
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { ELEMENT_DESCRIPTORS } from "./elements/index.ts";
|
|
2
|
+
import type { Layout, LayoutNode } from "./schema/layout.ts";
|
|
3
|
+
import { forEachNode } from "./tree-ops.ts";
|
|
4
|
+
|
|
5
|
+
/** Text fields that name things rather than say things: never offered for translation. */
|
|
6
|
+
const NOT_TEXT = new Set(["formId", "field"]);
|
|
7
|
+
|
|
8
|
+
export type TranslatableString = { nodeId: string; key: string; text: string };
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* W-936: the words a translator changes on a page: every text, textarea and list-item field of
|
|
12
|
+
* every element (alt text, captions, labels and placeholders included), in page order. Ids,
|
|
13
|
+
* links and form bindings are left out.
|
|
14
|
+
*/
|
|
15
|
+
export function translatableStrings(layout: Layout): TranslatableString[] {
|
|
16
|
+
const out: TranslatableString[] = [];
|
|
17
|
+
forEachNode(layout.root as LayoutNode, (node) => {
|
|
18
|
+
const fields = ELEMENT_DESCRIPTORS.find((d) => d.type === node.type)?.fields ?? [];
|
|
19
|
+
const props = (node.props ?? {}) as Record<string, unknown>;
|
|
20
|
+
for (const field of fields) {
|
|
21
|
+
if (NOT_TEXT.has(field.key)) continue;
|
|
22
|
+
const value = props[field.key];
|
|
23
|
+
if ((field.kind === "text" || field.kind === "textarea") && typeof value === "string") {
|
|
24
|
+
if (value.trim()) out.push({ nodeId: node.id, key: field.key, text: value });
|
|
25
|
+
} else if (field.kind === "list-items" && Array.isArray(value)) {
|
|
26
|
+
value.forEach((item, i) => {
|
|
27
|
+
if (typeof item === "string" && item.trim())
|
|
28
|
+
out.push({ nodeId: node.id, key: `${field.key}.${i}`, text: item });
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
return out;
|
|
34
|
+
}
|
package/src/core/validate.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { z } from "zod";
|
|
2
|
+
import { restoreExtras, splitDesignExtras, splitLayoutExtras } from "./contract.ts";
|
|
2
3
|
import { MAX_DEPTH, MAX_DESIGN_BYTES, MAX_LAYOUT_BYTES, MAX_NODES } from "./limits.ts";
|
|
3
4
|
import {
|
|
4
5
|
upgradeLayout,
|
|
@@ -142,9 +143,16 @@ export function validateDesign(
|
|
|
142
143
|
if (sizeIssue) return { ok: false, issues: [sizeIssue] };
|
|
143
144
|
const upgraded = upgradeLayout(input, migrations, DESIGN_SCHEMA_VERSION);
|
|
144
145
|
if (!upgraded.ok) return { ok: false, issues: [upgradeIssue(upgraded)] };
|
|
146
|
+
// D-065: keys a newer 1.x wrote are set aside, checked, and put back after the strict parse.
|
|
147
|
+
const extras = splitDesignExtras(upgraded.doc);
|
|
148
|
+
if (extras.issues.length > 0) return { ok: false, issues: extras.issues };
|
|
145
149
|
const parsed = DesignSystem.safeParse(upgraded.doc);
|
|
146
150
|
if (!parsed.success) return { ok: false, issues: parsed.error.issues.map(toIssue) };
|
|
147
|
-
return {
|
|
151
|
+
return {
|
|
152
|
+
ok: true,
|
|
153
|
+
design: restoreExtras(parsed.data, extras.extras),
|
|
154
|
+
upgradedFrom: upgraded.from,
|
|
155
|
+
};
|
|
148
156
|
}
|
|
149
157
|
|
|
150
158
|
/**
|
|
@@ -161,6 +169,9 @@ export function validateLayout(
|
|
|
161
169
|
if (!upgraded.ok) return { ok: false, issues: [upgradeIssue(upgraded)] };
|
|
162
170
|
const structure = checkStructure(upgraded.doc["root"]);
|
|
163
171
|
if (structure) return { ok: false, issues: [structure] };
|
|
172
|
+
// D-065: keys a newer 1.x wrote are set aside, checked, and put back after the strict parse.
|
|
173
|
+
const extras = splitLayoutExtras(upgraded.doc);
|
|
174
|
+
if (extras.issues.length > 0) return { ok: false, issues: extras.issues };
|
|
164
175
|
const parsed = Layout.safeParse(upgraded.doc);
|
|
165
176
|
if (!parsed.success) {
|
|
166
177
|
return {
|
|
@@ -171,6 +182,7 @@ export function validateLayout(
|
|
|
171
182
|
const layout = parsed.data as Layout;
|
|
172
183
|
const dupes = duplicateIds(layout);
|
|
173
184
|
if (dupes.length > 0) return { ok: false, issues: dupes };
|
|
185
|
+
restoreExtras(layout, extras.extras);
|
|
174
186
|
return { ok: true, layout, upgradedFrom: upgraded.from };
|
|
175
187
|
}
|
|
176
188
|
|
package/src/index.ts
CHANGED
|
@@ -2,6 +2,11 @@ import type { PluginDescriptor } from "emdash";
|
|
|
2
2
|
import { ADMIN_ENTRY, PACKAGE_NAME, PLUGIN_ID, PLUGIN_VERSION } from "./constants.ts";
|
|
3
3
|
import { canvasCollectionSlugs } from "./core/canvas-collections.ts";
|
|
4
4
|
import { canvasStyleUrls } from "./core/canvas-styles.ts";
|
|
5
|
+
import {
|
|
6
|
+
rememberExtensions,
|
|
7
|
+
type EmVBExtension,
|
|
8
|
+
type ExtensionManifest,
|
|
9
|
+
} from "./core/extensions/index.ts";
|
|
5
10
|
import { createPlugin } from "./server/plugin.ts";
|
|
6
11
|
|
|
7
12
|
/** Options a host site passes to `emvb()` in astro.config. */
|
|
@@ -17,12 +22,19 @@ export type EmVBOptions = {
|
|
|
17
22
|
* field (W-897). EmVB validates and guards that field on save and publish for these only.
|
|
18
23
|
*/
|
|
19
24
|
canvasCollections?: string[];
|
|
25
|
+
/**
|
|
26
|
+
* Build-time Extensions API v1 packages (W-927, D-066). Only the site owner adds these.
|
|
27
|
+
* Live render/resolve functions are kept in-process; a serializable manifest is what
|
|
28
|
+
* EmDash passes into `createPlugin`.
|
|
29
|
+
*/
|
|
30
|
+
extensions?: EmVBExtension[];
|
|
20
31
|
};
|
|
21
32
|
|
|
22
33
|
/** Descriptor that host sites add to `emdash({ plugins: [...] })` in astro.config. */
|
|
23
34
|
export function emvb(options: EmVBOptions = {}): PluginDescriptor {
|
|
24
35
|
const canvasStyles = canvasStyleUrls(options.canvasStyles);
|
|
25
36
|
const canvasCollections = canvasCollectionSlugs(options.canvasCollections);
|
|
37
|
+
const extensions = rememberExtensions(options.extensions);
|
|
26
38
|
return {
|
|
27
39
|
id: PLUGIN_ID,
|
|
28
40
|
version: PLUGIN_VERSION,
|
|
@@ -32,9 +44,21 @@ export function emvb(options: EmVBOptions = {}): PluginDescriptor {
|
|
|
32
44
|
options: {
|
|
33
45
|
...(canvasStyles.length > 0 ? { canvasStyles } : {}),
|
|
34
46
|
...(canvasCollections.length > 0 ? { canvasCollections } : {}),
|
|
47
|
+
...(extensions.length > 0 ? { extensions } : {}),
|
|
35
48
|
},
|
|
36
49
|
};
|
|
37
50
|
}
|
|
38
51
|
|
|
39
52
|
export { createPlugin };
|
|
40
53
|
export default createPlugin;
|
|
54
|
+
|
|
55
|
+
export type { EmVBExtension, ExtensionManifest };
|
|
56
|
+
export {
|
|
57
|
+
defineExtension,
|
|
58
|
+
EXTENSION_API_VERSION,
|
|
59
|
+
type ExtensionElement,
|
|
60
|
+
type ExtensionPanel,
|
|
61
|
+
type ExtensionSource,
|
|
62
|
+
type ExtensionPropSchema,
|
|
63
|
+
type ExtensionField,
|
|
64
|
+
} from "./core/extensions/index.ts";
|
package/src/mcp/errors.ts
CHANGED
|
@@ -10,7 +10,8 @@ export type McpErrorCode =
|
|
|
10
10
|
| "TOO_LARGE"
|
|
11
11
|
| "REFUSED"
|
|
12
12
|
| "NOT_SET_UP"
|
|
13
|
-
| "RATE_LIMITED"
|
|
13
|
+
| "RATE_LIMITED"
|
|
14
|
+
| "PAGE_OPEN";
|
|
14
15
|
|
|
15
16
|
const STATUS: Record<McpErrorCode, number> = {
|
|
16
17
|
INVALID_INPUT: 400,
|
|
@@ -24,6 +25,7 @@ const STATUS: Record<McpErrorCode, number> = {
|
|
|
24
25
|
REFUSED: 422,
|
|
25
26
|
NOT_SET_UP: 409,
|
|
26
27
|
RATE_LIMITED: 429,
|
|
28
|
+
PAGE_OPEN: 409,
|
|
27
29
|
};
|
|
28
30
|
|
|
29
31
|
/**
|
package/src/mcp/ports.ts
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
Proposal,
|
|
3
|
+
ProposalRecord,
|
|
4
|
+
ProposalRefusal,
|
|
5
|
+
applyProposal,
|
|
6
|
+
} from "../core/proposals.ts";
|
|
1
7
|
import type { AgentSettings } from "./settings.ts";
|
|
2
8
|
import type { RateClass } from "./rate-limit.ts";
|
|
3
9
|
import type {
|
|
@@ -45,6 +51,9 @@ export type AgentLogEntry = {
|
|
|
45
51
|
pageId?: string;
|
|
46
52
|
rev?: string;
|
|
47
53
|
revisionId?: string;
|
|
54
|
+
/** W-933 audit: which proposal, and how many changes it carried. */
|
|
55
|
+
proposalId?: string;
|
|
56
|
+
changes?: number;
|
|
48
57
|
summary: string;
|
|
49
58
|
};
|
|
50
59
|
|
|
@@ -92,6 +101,43 @@ export interface EmvbPorts {
|
|
|
92
101
|
): Promise<ReadonlyMap<string, readonly RequiredFieldInfo[]>>;
|
|
93
102
|
/** W-875: saved sections; without it the saved-section tools answer NOT_SET_UP. */
|
|
94
103
|
savedSections?: SavedSectionsPort;
|
|
104
|
+
/** W-929: reviewable agent proposals (D-064); without it the proposal tools answer NOT_SET_UP. */
|
|
105
|
+
proposals?: ProposalsPort;
|
|
106
|
+
/**
|
|
107
|
+
* W-929 (D-064): true while the page is open in the EmVB editor. Direct page writes are then
|
|
108
|
+
* refused with PAGE_OPEN and the agent proposes instead. Without this port nothing is refused.
|
|
109
|
+
*/
|
|
110
|
+
pageOpen?(id: string): Promise<boolean>;
|
|
111
|
+
/** W-931: the editor's requests for agents (prompt relay); without it get_requests is NOT_SET_UP. */
|
|
112
|
+
requests?: RequestsPort;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** W-931: a person's request for their agent, written in the editor's Agent tab. */
|
|
116
|
+
export type AgentRequest = {
|
|
117
|
+
id: string;
|
|
118
|
+
target: Proposal["target"];
|
|
119
|
+
prompt: string;
|
|
120
|
+
createdAt: string;
|
|
121
|
+
status: "open" | "answered";
|
|
122
|
+
proposalId?: string;
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
export interface RequestsPort {
|
|
126
|
+
/** Every request for the page, newest first (the editor's list). */
|
|
127
|
+
list(target: Proposal["target"]): Promise<AgentRequest[]>;
|
|
128
|
+
/** Open, unexpired requests, oldest first (what an agent should answer). */
|
|
129
|
+
open(target?: Proposal["target"]): Promise<AgentRequest[]>;
|
|
130
|
+
create(
|
|
131
|
+
target: Proposal["target"],
|
|
132
|
+
prompt: string,
|
|
133
|
+
userId: string | null,
|
|
134
|
+
): Promise<{ ok: true; request: AgentRequest } | { ok: false; reason: string }>;
|
|
135
|
+
cancel(id: string): Promise<boolean>;
|
|
136
|
+
/** Marks an open request for `target` answered by a proposal; false when it isn't one. */
|
|
137
|
+
answer(id: string, target: Proposal["target"], proposalId: string): Promise<boolean>;
|
|
138
|
+
/** An agent checked for requests now (the editor's "connected" status). */
|
|
139
|
+
seen(): Promise<void>;
|
|
140
|
+
lastSeen(): Promise<string | null>;
|
|
95
141
|
}
|
|
96
142
|
|
|
97
143
|
/** Saved sections in plugin storage `emvb_saved_sections` (W-875, D-060). */
|
|
@@ -104,3 +150,24 @@ export interface SavedSectionsPort {
|
|
|
104
150
|
rename(id: string, name: string): Promise<SavedSectionSummary | Refusal | null>;
|
|
105
151
|
remove(id: string): Promise<boolean>;
|
|
106
152
|
}
|
|
153
|
+
|
|
154
|
+
/** W-928: storage and checked previews only; never writes or publishes content. */
|
|
155
|
+
export interface ProposalsPort {
|
|
156
|
+
create(
|
|
157
|
+
proposal: unknown,
|
|
158
|
+
): Promise<{ ok: true; id: string; record: ProposalRecord } | ProposalRefusal>;
|
|
159
|
+
get(
|
|
160
|
+
id: string,
|
|
161
|
+
): Promise<{ ok: true; id: string; record: ProposalRecord } | ProposalRefusal | null>;
|
|
162
|
+
list(target: Proposal["target"]): Promise<{ id: string; record: ProposalRecord }[]>;
|
|
163
|
+
withdraw(id: string): Promise<boolean>;
|
|
164
|
+
/** W-929: the revisions a new proposal for `target` must name; null when there is no such page. */
|
|
165
|
+
base(target: Proposal["target"]): Promise<{
|
|
166
|
+
revision: string;
|
|
167
|
+
designRevision: string | null;
|
|
168
|
+
} | null>;
|
|
169
|
+
prepare(
|
|
170
|
+
id: string,
|
|
171
|
+
selected?: readonly number[],
|
|
172
|
+
): Promise<ReturnType<typeof applyProposal> | null>;
|
|
173
|
+
}
|
package/src/mcp/prompts.ts
CHANGED
|
@@ -1,14 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import { DesignSystem } from "../core/schema/design.ts";
|
|
3
|
-
import { Layout } from "../core/schema/layout.ts";
|
|
4
|
-
|
|
5
|
-
/** JSON Schema (2020-12) of a stored layout, for `emvb://schema/layout` (W-467). */
|
|
6
|
-
export const layoutJsonSchema = () =>
|
|
7
|
-
z.toJSONSchema(Layout, { io: "input", unrepresentable: "any" });
|
|
8
|
-
|
|
9
|
-
/** JSON Schema of the design system (site styles), for `emvb://schema/design`. */
|
|
10
|
-
export const designJsonSchema = () =>
|
|
11
|
-
z.toJSONSchema(DesignSystem, { io: "input", unrepresentable: "any" });
|
|
1
|
+
export { designJsonSchema, layoutJsonSchema } from "../core/json-schema.ts";
|
|
12
2
|
|
|
13
3
|
export type PromptDef = {
|
|
14
4
|
name: string;
|