@perkyzz/emvb 1.0.0 → 1.2.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 +9 -0
- package/THIRD_PARTY_NOTICES.md +1 -0
- package/package.json +10 -9
- package/src/admin/agents-api.ts +5 -1
- package/src/admin/bulk-api.ts +67 -0
- package/src/admin/content-api.ts +39 -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 +2 -0
- package/src/admin/editor/Editor.tsx +24 -7
- package/src/admin/editor/ScheduleDialog.tsx +167 -0
- package/src/admin/editor/Timeline.tsx +6 -2
- package/src/admin/editor/TopBar.tsx +60 -8
- package/src/admin/editor/canvas/CanvasFrame.tsx +7 -2
- package/src/admin/editor/canvas/DeviceBar.tsx +22 -9
- 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/dnd/new-element.ts +68 -0
- package/src/admin/editor/editor-chrome.tsx +16 -5
- package/src/admin/editor/editor-commands.ts +10 -4
- package/src/admin/editor/editor-css.ts +2 -1
- package/src/admin/editor/element-chrome.ts +22 -0
- package/src/admin/editor/panels/ElementPanel.tsx +34 -17
- package/src/admin/editor/panels/SettingsPanel.tsx +2 -2
- package/src/admin/editor/panels/settings/DraftTextField.tsx +33 -1
- package/src/admin/editor/panels/settings/EffectsControls.tsx +79 -1
- package/src/admin/editor/panels/settings/FieldBindControl.tsx +6 -1
- package/src/admin/editor/panels/settings/FieldControl.tsx +10 -1
- package/src/admin/editor/panels/settings/IconControls.tsx +11 -0
- package/src/admin/editor/panels/settings/IconPicker.tsx +4 -1
- package/src/admin/editor/panels/settings/ItemList.tsx +36 -2
- package/src/admin/editor/panels/settings/LengthRow.tsx +36 -3
- package/src/admin/editor/panels/settings/LoopItemBindControl.tsx +18 -0
- package/src/admin/editor/panels/settings/StyleRow.tsx +7 -0
- package/src/admin/editor/panels/settings/advanced-rules.ts +3 -0
- package/src/admin/editor/panels/settings/length-units.ts +15 -3
- package/src/admin/editor/panels/settings/style-sections.ts +1 -0
- package/src/admin/editor/panels/style-target.ts +17 -4
- package/src/admin/editor/section-templates.ts +26 -4
- package/src/admin/editor/store.ts +15 -3
- package/src/admin/editor/useEditorCommands.ts +7 -5
- package/src/admin/editor/useEditorData.ts +4 -0
- package/src/admin/editor/useNodeActions.ts +4 -2
- package/src/admin/editor/useSave.ts +47 -3
- package/src/admin/export-api.ts +238 -0
- package/src/admin/index.tsx +6 -1
- package/src/admin/menus-api.ts +113 -0
- package/src/admin/pages/ExportDialog.tsx +395 -0
- package/src/admin/pages/ImportElementorDialog.tsx +25 -1
- package/src/admin/pages/PageList.tsx +67 -2
- package/src/admin/pages/ThemePartList.tsx +37 -1
- package/src/admin/pages/bulk.tsx +303 -0
- package/src/admin/search.ts +20 -0
- package/src/admin/theme-api.ts +4 -0
- package/src/admin/ui.ts +11 -2
- 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/EmVBPage.astro +3 -0
- package/src/astro/render.ts +47 -22
- package/src/astro/request-data.ts +3 -0
- package/src/astro/resolve-theme.ts +88 -51
- package/src/astro/tabs/runtime.ts +16 -6
- package/src/astro/visitor.ts +23 -4
- package/src/astro/widgets/EmVBAlertsRuntime.astro +8 -0
- package/src/astro/widgets/EmVBCarouselRuntime.astro +8 -0
- package/src/astro/widgets/EmVBLightboxRuntime.astro +8 -0
- package/src/astro/widgets/EmVBWidgetRuntimes.astro +19 -0
- package/src/astro/widgets/alerts.ts +37 -0
- package/src/astro/widgets/carousel.ts +167 -0
- package/src/astro/widgets/index.ts +1 -0
- package/src/astro/widgets/lightbox.ts +123 -0
- package/src/constants.ts +1 -1
- package/src/core/a11y/audit.ts +103 -3
- package/src/core/arrange.ts +57 -1
- package/src/core/bounded-array.ts +16 -13
- package/src/core/contract.ts +26 -3
- package/src/core/css/generate.ts +83 -21
- package/src/core/css/scope.ts +10 -2
- package/src/core/css/trace.ts +33 -8
- package/src/core/design/classes.ts +25 -5
- package/src/core/design/devices.ts +78 -2
- package/src/core/design/variables.ts +14 -1
- package/src/core/elements/icon-svg.ts +135 -0
- package/src/core/elements/index.ts +33 -127
- package/src/core/elements/widgets.ts +907 -0
- package/src/core/export/runtimes.generated.ts +12 -0
- package/src/core/export/site.ts +579 -0
- package/src/core/export/zip.ts +95 -0
- package/src/core/extensions/schema.ts +2 -1
- package/src/core/geo-trust.ts +18 -0
- package/src/core/history/diff.ts +25 -0
- package/src/core/icons/social.generated.ts +29 -0
- package/src/core/image-edit/schema.ts +2 -1
- package/src/core/import/elementor/atomic.ts +22 -9
- package/src/core/import/elementor/context.ts +18 -0
- package/src/core/import/elementor/index.ts +72 -11
- package/src/core/import/elementor/style.ts +21 -1
- package/src/core/import/elementor/widgets.ts +394 -133
- package/src/core/index.ts +14 -0
- package/src/core/issue-cap.ts +19 -0
- package/src/core/json-schema.ts +8 -1
- package/src/core/limits.ts +6 -0
- package/src/core/loop-collections.ts +33 -0
- package/src/core/perf/meter.ts +37 -19
- package/src/core/portable-text-export.ts +243 -0
- package/src/core/proposals.ts +8 -2
- package/src/core/public-attributes.ts +30 -0
- package/src/core/render/index.ts +115 -13
- package/src/core/render/tabs.ts +18 -11
- package/src/core/render/vnode.ts +44 -6
- package/src/core/sanitize/css.ts +26 -0
- package/src/core/sanitize/svg-upload.ts +276 -23
- package/src/core/sanitize/svg.ts +3 -3
- package/src/core/schema/descriptors.ts +4 -0
- package/src/core/schema/design.ts +8 -7
- package/src/core/schema/layout.ts +406 -18
- package/src/core/schema/style.ts +49 -1
- package/src/core/search-text.ts +70 -0
- package/src/core/shadowing-ids.ts +41 -0
- package/src/core/theme/conditions.ts +2 -1
- package/src/core/theme/float.ts +1 -0
- package/src/core/theme/parse-doc.ts +10 -5
- package/src/core/theme/popup-rules.ts +16 -0
- package/src/core/theme/triggers.ts +3 -2
- package/src/core/validate.ts +3 -2
- package/src/index.ts +23 -2
- package/src/mcp/ports.ts +18 -7
- package/src/mcp/proposals.ts +36 -11
- package/src/mcp/read.ts +2 -3
- package/src/mcp/tools.ts +1 -1
- package/src/server/agent-settings.ts +12 -1
- package/src/server/hooks.ts +41 -6
- package/src/server/icon-routes.ts +52 -12
- package/src/server/mcp-routes.ts +11 -5
- package/src/server/plugin.ts +27 -2
- package/src/server/presence.ts +5 -1
- package/src/server/proposals.ts +16 -4
- package/src/server/requests.ts +60 -11
- package/src/server/site-origin.ts +13 -0
- package/src/server/targets.ts +26 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** S-03: at most this many issues come back from one validation. */
|
|
2
|
+
const MAX_REPORTED_ISSUES = 50;
|
|
3
|
+
|
|
4
|
+
type Issue = { path: string; code: string; message: string };
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The first issues, mapped, then one "…and N more" in place of the rest, so a document full of
|
|
8
|
+
* bad items can't make a response, a log line or the editor's list grow with it.
|
|
9
|
+
*/
|
|
10
|
+
export function capIssues<I>(
|
|
11
|
+
issues: readonly I[],
|
|
12
|
+
map: (issue: I) => Issue,
|
|
13
|
+
path: string,
|
|
14
|
+
): Issue[] {
|
|
15
|
+
if (issues.length <= MAX_REPORTED_ISSUES) return issues.map(map);
|
|
16
|
+
const kept = issues.slice(0, MAX_REPORTED_ISSUES - 1).map(map);
|
|
17
|
+
const more = issues.length - kept.length;
|
|
18
|
+
return [...kept, { path, code: "too_many_issues", message: `…and ${more} more problems.` }];
|
|
19
|
+
}
|
package/src/core/json-schema.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { DESIGN_SCHEMA_VERSION, DesignSystem } from "./schema/design.ts";
|
|
3
3
|
import { CONTRACT_VERSION, KNOWN_NODE_SCHEMAS, LAYOUT_SCHEMA_VERSION } from "./schema/layout.ts";
|
|
4
|
-
import { DeviceStyles, StyleProps, StyleStates } from "./schema/style.ts";
|
|
4
|
+
import { DeviceStyles, OwnStyle, StyleProps, StyleStates, WideStyle } from "./schema/style.ts";
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* JSON Schema (2020-12) exports of the stored formats (W-925, contract 1.0). They describe the
|
|
@@ -46,8 +46,15 @@ function styleDefs(): { defs: Json; shared: Map<string, string> } {
|
|
|
46
46
|
states: withRefs(states, inner),
|
|
47
47
|
devices: withRefs(devices, inner),
|
|
48
48
|
};
|
|
49
|
+
// W-959: an element's or class's own style carries `wide`, the Wide screen record.
|
|
50
|
+
const wide = toJson(WideStyle);
|
|
51
|
+
const own = toJson(OwnStyle);
|
|
52
|
+
defs["wideStyle"] = wide;
|
|
53
|
+
defs["ownStyle"] = withRefs(own, new Map([[JSON.stringify(wide), "wideStyle"]]));
|
|
49
54
|
const shared = new Map([
|
|
50
55
|
...inner,
|
|
56
|
+
[JSON.stringify(own), "ownStyle"],
|
|
57
|
+
[JSON.stringify(wide), "wideStyle"],
|
|
51
58
|
[JSON.stringify(states), "states"],
|
|
52
59
|
[JSON.stringify(devices), "devices"],
|
|
53
60
|
]);
|
package/src/core/limits.ts
CHANGED
|
@@ -7,6 +7,12 @@ export const MAX_NODES = 2000;
|
|
|
7
7
|
export const MAX_TEXT_LENGTH = 2000;
|
|
8
8
|
/** Tabs show at most this many panels; the CSS-only switcher has a rule per tab. */
|
|
9
9
|
export const MAX_TABS = 12;
|
|
10
|
+
/** W-1024: most links one Social icons element holds. */
|
|
11
|
+
export const MAX_SOCIAL_LINKS = 20;
|
|
12
|
+
/** W-1019: most pictures one Gallery holds. */
|
|
13
|
+
export const MAX_GALLERY_IMAGES = 60;
|
|
14
|
+
/** W-1018: most slides one Carousel holds. */
|
|
15
|
+
export const MAX_CAROUSEL_SLIDES = 20;
|
|
10
16
|
|
|
11
17
|
/**
|
|
12
18
|
* W-509: `text` cut to at most `max` UTF-16 units, as schema limits count, without leaving half
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* S-11 (W-1000): `emvb({ loopCollections })`, the collections Loops may list on the public site.
|
|
3
|
+
* Unset, every collection with published entries can be listed (as before 1.1.2). Kept on
|
|
4
|
+
* globalThis for the same reason as the geo-header setting (core/geo-trust.ts).
|
|
5
|
+
*/
|
|
6
|
+
const KEY = Symbol.for("emvb.loopCollections");
|
|
7
|
+
const SLUG = /^[a-z][a-z0-9_]{0,62}$/;
|
|
8
|
+
const MAX = 100;
|
|
9
|
+
|
|
10
|
+
type Holder = { [KEY]?: readonly string[] };
|
|
11
|
+
|
|
12
|
+
/** The allowlist from the option: collection slugs, or undefined when the option isn't a list. */
|
|
13
|
+
export function loopCollectionSlugs(input: unknown): string[] | undefined {
|
|
14
|
+
if (!Array.isArray(input)) return undefined;
|
|
15
|
+
const out: string[] = [];
|
|
16
|
+
for (const item of input) {
|
|
17
|
+
if (typeof item !== "string") continue;
|
|
18
|
+
const slug = item.trim();
|
|
19
|
+
if (SLUG.test(slug) && !out.includes(slug)) out.push(slug);
|
|
20
|
+
if (out.length === MAX) break;
|
|
21
|
+
}
|
|
22
|
+
return out;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function setLoopCollections(input: unknown): void {
|
|
26
|
+
(globalThis as Holder)[KEY] = loopCollectionSlugs(input);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** True when a Loop may list `collection` on this site. */
|
|
30
|
+
export function loopCollectionAllowed(collection: string): boolean {
|
|
31
|
+
const allowed = (globalThis as Holder)[KEY];
|
|
32
|
+
return allowed === undefined || allowed.includes(collection);
|
|
33
|
+
}
|
package/src/core/perf/meter.ts
CHANGED
|
@@ -74,15 +74,16 @@ const isPlayerEmbed = (node: LayoutNode): boolean => {
|
|
|
74
74
|
return typeof url === "string" && resolveEmbedUrl(url)?.kind === "iframe";
|
|
75
75
|
};
|
|
76
76
|
|
|
77
|
+
type Weight = { images: number; bytes: number; embeds: number };
|
|
78
|
+
const zero = (): Weight => ({ images: 0, bytes: 0, embeds: 0 });
|
|
79
|
+
const add = (a: Weight, b: Weight) => {
|
|
80
|
+
a.images += b.images;
|
|
81
|
+
a.bytes += b.bytes;
|
|
82
|
+
a.embeds += b.embeds;
|
|
83
|
+
};
|
|
84
|
+
|
|
77
85
|
/** Images and embeds under a node, with their estimated weight. */
|
|
78
|
-
function media(
|
|
79
|
-
node: LayoutNode,
|
|
80
|
-
bgClasses: Set<string>,
|
|
81
|
-
dynamic?: ThemeDynamicData,
|
|
82
|
-
): { images: number; bytes: number; embeds: number } {
|
|
83
|
-
let images = 0;
|
|
84
|
-
let bytes = 0;
|
|
85
|
-
let embeds = 0;
|
|
86
|
+
function media(node: LayoutNode, bgClasses: Set<string>, dynamic?: ThemeDynamicData): Weight {
|
|
86
87
|
const seen = new Set<Layout>();
|
|
87
88
|
/** W-671: a synced section or Loop Item part the canvas loaded is weighed with the page. */
|
|
88
89
|
const part = (n: LayoutNode): Layout | undefined => {
|
|
@@ -97,30 +98,47 @@ function media(
|
|
|
97
98
|
seen.add(found);
|
|
98
99
|
return found;
|
|
99
100
|
};
|
|
100
|
-
|
|
101
|
+
// W-973: a visitor sees one arm of an A/B test, so only the heavier arm's media count.
|
|
102
|
+
const arms = new Map<string, Map<string, Weight>>();
|
|
103
|
+
const walk = (n: LayoutNode): Weight => {
|
|
104
|
+
const own = zero();
|
|
101
105
|
const template = part(n);
|
|
102
|
-
if (template) walk(template.root);
|
|
106
|
+
if (template) add(own, walk(template.root));
|
|
103
107
|
if (n.type === "image" || n.type === "post-image") {
|
|
104
108
|
const src = (n.props as { src?: unknown }).src;
|
|
105
109
|
if (n.type === "post-image" || (typeof src === "string" && src.trim())) {
|
|
106
|
-
images += 1;
|
|
107
|
-
bytes += imageBytes(n);
|
|
110
|
+
own.images += 1;
|
|
111
|
+
own.bytes += imageBytes(n);
|
|
108
112
|
}
|
|
109
113
|
}
|
|
110
114
|
if (hasBackgroundImage(n, bgClasses)) {
|
|
111
|
-
images += 1;
|
|
112
|
-
bytes += IMAGE_GUESS;
|
|
115
|
+
own.images += 1;
|
|
116
|
+
own.bytes += IMAGE_GUESS;
|
|
113
117
|
}
|
|
114
118
|
// W-508: only a YouTube or Vimeo player is a third-party embed; a media-library video loads
|
|
115
119
|
// its metadata only, and a missing or refused URL renders nothing.
|
|
116
120
|
if (n.type === "video" && isPlayerEmbed(n)) {
|
|
117
|
-
embeds += 1;
|
|
118
|
-
bytes += EMBED_BYTES;
|
|
121
|
+
own.embeds += 1;
|
|
122
|
+
own.bytes += EMBED_BYTES;
|
|
119
123
|
}
|
|
120
|
-
if (isParentNode(n)) for (const child of n.children) walk(child);
|
|
124
|
+
if (isParentNode(n)) for (const child of n.children) add(own, walk(child));
|
|
125
|
+
const variant = n.variant;
|
|
126
|
+
if (variant) {
|
|
127
|
+
const test = arms.get(variant.test) ?? new Map<string, Weight>();
|
|
128
|
+
const arm = test.get(variant.arm) ?? zero();
|
|
129
|
+
add(arm, own);
|
|
130
|
+
test.set(variant.arm, arm);
|
|
131
|
+
arms.set(variant.test, test);
|
|
132
|
+
return zero();
|
|
133
|
+
}
|
|
134
|
+
return own;
|
|
121
135
|
};
|
|
122
|
-
walk(node);
|
|
123
|
-
|
|
136
|
+
const total = walk(node);
|
|
137
|
+
for (const test of arms.values()) {
|
|
138
|
+
const heaviest = [...test.values()].reduce((a, b) => (b.bytes > a.bytes ? b : a), zero());
|
|
139
|
+
add(total, heaviest);
|
|
140
|
+
}
|
|
141
|
+
return total;
|
|
124
142
|
}
|
|
125
143
|
|
|
126
144
|
const kb = (bytes: number) => `${Math.round(bytes / 1000)} KB`;
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
// oxlint-disable no-underscore-dangle -- Portable Text names its fields _type, _key and _ref.
|
|
2
|
+
import type { Layout, LayoutNode, TextMark } from "./schema/layout.ts";
|
|
3
|
+
import { nodeChildren } from "./tree-ops.ts";
|
|
4
|
+
import { sanitizeUrl } from "./sanitize/url.ts";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* W-963: the reverse of Convert to EmVB. A layout becomes EmDash rich text (Portable Text): the
|
|
8
|
+
* words, headings, lists, links and images, in reading order, without the design. What can't be
|
|
9
|
+
* rich text (forms, embeds, icons, dividers, loops) is counted by type, never guessed at.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
type Span = { _type: "span"; _key: string; text: string; marks: string[] };
|
|
13
|
+
type LinkDef = { _type: "link"; _key: string; href: string; blank?: true };
|
|
14
|
+
export type PortableTextBlock =
|
|
15
|
+
| {
|
|
16
|
+
_type: "block";
|
|
17
|
+
_key: string;
|
|
18
|
+
style: string;
|
|
19
|
+
children: Span[];
|
|
20
|
+
markDefs: LinkDef[];
|
|
21
|
+
listItem?: "bullet" | "number";
|
|
22
|
+
level?: number;
|
|
23
|
+
}
|
|
24
|
+
| {
|
|
25
|
+
_type: "image";
|
|
26
|
+
_key: string;
|
|
27
|
+
asset: { url: string; _ref?: string };
|
|
28
|
+
alt?: string;
|
|
29
|
+
width?: number;
|
|
30
|
+
height?: number;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export type PortableTextExport = {
|
|
34
|
+
body: PortableTextBlock[];
|
|
35
|
+
/** Elements that became blocks. */
|
|
36
|
+
converted: number;
|
|
37
|
+
/** Elements left out, by element type (`form: 2`). */
|
|
38
|
+
skipped: Record<string, number>;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const LINK_SCHEMES: ReadonlySet<string> = new Set(["https:", "http:", "mailto:", "tel:"]);
|
|
42
|
+
const IMAGE_SCHEMES: ReadonlySet<string> = new Set(["https:", "http:"]);
|
|
43
|
+
|
|
44
|
+
/** Boxes whose children are read in order; they add nothing of their own. */
|
|
45
|
+
const BOXES = new Set([
|
|
46
|
+
"container",
|
|
47
|
+
"flexbox",
|
|
48
|
+
"grid",
|
|
49
|
+
"div",
|
|
50
|
+
"div-block",
|
|
51
|
+
"layout-section",
|
|
52
|
+
"accordion",
|
|
53
|
+
"tabs",
|
|
54
|
+
]);
|
|
55
|
+
|
|
56
|
+
/** Leaves with no words (or nothing that rich text can hold), left out without a count. */
|
|
57
|
+
const QUIET = new Set(["spacer"]);
|
|
58
|
+
|
|
59
|
+
/** A relative site path is kept as is; anything else must be a safe absolute URL. */
|
|
60
|
+
function safeHref(raw: string | undefined, schemes = LINK_SCHEMES): string | undefined {
|
|
61
|
+
const href = raw?.trim();
|
|
62
|
+
if (!href) return undefined;
|
|
63
|
+
if (href.startsWith("/") && !href.startsWith("//")) return href;
|
|
64
|
+
if (href.startsWith("#")) return href;
|
|
65
|
+
return sanitizeUrl(href, schemes);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function layoutToPortableText(
|
|
69
|
+
layout: Layout,
|
|
70
|
+
options: {
|
|
71
|
+
/** Synced section layouts by part id, so their words come across too. */
|
|
72
|
+
sectionTemplates?: Readonly<Record<string, Layout>>;
|
|
73
|
+
/** Stable keys for tests. */
|
|
74
|
+
key?: () => string;
|
|
75
|
+
} = {},
|
|
76
|
+
): PortableTextExport {
|
|
77
|
+
let counter = 0;
|
|
78
|
+
const key = options.key ?? (() => `k${(counter++).toString(36)}`);
|
|
79
|
+
const body: PortableTextBlock[] = [];
|
|
80
|
+
const skipped: Record<string, number> = {};
|
|
81
|
+
let converted = 0;
|
|
82
|
+
const skip = (type: string) => {
|
|
83
|
+
skipped[type] = (skipped[type] ?? 0) + 1;
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const block = (
|
|
87
|
+
text: string,
|
|
88
|
+
style = "normal",
|
|
89
|
+
marks: readonly TextMark[] = [],
|
|
90
|
+
whole?: { href: string; newTab?: boolean },
|
|
91
|
+
) => {
|
|
92
|
+
const markDefs: LinkDef[] = [];
|
|
93
|
+
const linkKey = (href: string, newTab?: boolean) => {
|
|
94
|
+
const def: LinkDef = { _type: "link", _key: key(), href, ...(newTab ? { blank: true } : {}) };
|
|
95
|
+
markDefs.push(def);
|
|
96
|
+
return def._key;
|
|
97
|
+
};
|
|
98
|
+
const wholeKey = whole ? linkKey(whole.href, whole.newTab) : undefined;
|
|
99
|
+
const usable = marks.filter((m) => m.end > m.start && m.start < text.length);
|
|
100
|
+
const cuts = new Set([0, text.length]);
|
|
101
|
+
for (const m of usable) {
|
|
102
|
+
cuts.add(Math.min(m.start, text.length));
|
|
103
|
+
cuts.add(Math.min(m.end, text.length));
|
|
104
|
+
}
|
|
105
|
+
const points = [...cuts].toSorted((a, b) => a - b);
|
|
106
|
+
const markKeys = new Map<TextMark, string>();
|
|
107
|
+
const children: Span[] = [];
|
|
108
|
+
for (let i = 0; i < points.length - 1; i += 1) {
|
|
109
|
+
const from = points[i] ?? 0;
|
|
110
|
+
const to = points[i + 1] ?? 0;
|
|
111
|
+
if (to <= from) continue;
|
|
112
|
+
const names: string[] = wholeKey ? [wholeKey] : [];
|
|
113
|
+
for (const m of usable) {
|
|
114
|
+
if (m.start > from || m.end < to) continue;
|
|
115
|
+
if (m.bold) names.push("strong");
|
|
116
|
+
if (m.italic) names.push("em");
|
|
117
|
+
const href = wholeKey ? undefined : safeHref(m.href);
|
|
118
|
+
if (href) {
|
|
119
|
+
let k = markKeys.get(m);
|
|
120
|
+
if (!k) {
|
|
121
|
+
k = linkKey(href, m.newTab);
|
|
122
|
+
markKeys.set(m, k);
|
|
123
|
+
}
|
|
124
|
+
names.push(k);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
children.push({ _type: "span", _key: key(), text: text.slice(from, to), marks: names });
|
|
128
|
+
}
|
|
129
|
+
if (children.length === 0) children.push({ _type: "span", _key: key(), text: "", marks: [] });
|
|
130
|
+
body.push({ _type: "block", _key: key(), style, children, markDefs });
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
const visit = (node: LayoutNode, seen: ReadonlySet<string>) => {
|
|
134
|
+
// An A/B test's B element repeats what A says; A is kept.
|
|
135
|
+
if (node.variant?.arm === "b") {
|
|
136
|
+
skip("A/B test variant");
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
const props = (node.props ?? {}) as Record<string, unknown>;
|
|
140
|
+
const text = typeof props["text"] === "string" ? props["text"].trim() : "";
|
|
141
|
+
const marks = Array.isArray(props["marks"]) ? (props["marks"] as TextMark[]) : [];
|
|
142
|
+
switch (node.type) {
|
|
143
|
+
case "heading": {
|
|
144
|
+
if (!text) return;
|
|
145
|
+
const href = safeHref(props["href"] as string | undefined);
|
|
146
|
+
block(
|
|
147
|
+
text,
|
|
148
|
+
`h${Number(props["level"]) || 2}`,
|
|
149
|
+
href ? [] : marks,
|
|
150
|
+
href ? { href, newTab: props["newTab"] === true } : undefined,
|
|
151
|
+
);
|
|
152
|
+
converted++;
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
case "text":
|
|
156
|
+
case "label":
|
|
157
|
+
case "span": {
|
|
158
|
+
if (!text) return;
|
|
159
|
+
block(text, "normal", marks);
|
|
160
|
+
converted++;
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
case "link":
|
|
164
|
+
case "button": {
|
|
165
|
+
if (!text) return;
|
|
166
|
+
const href = safeHref(props["href"] as string | undefined);
|
|
167
|
+
block(text, "normal", [], href ? { href, newTab: props["newTab"] === true } : undefined);
|
|
168
|
+
converted++;
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
case "list": {
|
|
172
|
+
const items = Array.isArray(props["items"]) ? props["items"] : [];
|
|
173
|
+
const ordered =
|
|
174
|
+
props["ordered"] === true ||
|
|
175
|
+
(typeof props["marker"] === "string" &&
|
|
176
|
+
!["disc", "circle", "square", "none"].includes(props["marker"]));
|
|
177
|
+
let any = false;
|
|
178
|
+
for (const item of items) {
|
|
179
|
+
if (typeof item !== "string" || !item.trim()) continue;
|
|
180
|
+
block(item.trim());
|
|
181
|
+
const last = body.at(-1);
|
|
182
|
+
if (last?._type === "block") {
|
|
183
|
+
last.listItem = ordered ? "number" : "bullet";
|
|
184
|
+
last.level = 1;
|
|
185
|
+
}
|
|
186
|
+
any = true;
|
|
187
|
+
}
|
|
188
|
+
if (any) converted++;
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
case "image": {
|
|
192
|
+
const src = safeHref(props["src"] as string | undefined, IMAGE_SCHEMES);
|
|
193
|
+
if (!src) {
|
|
194
|
+
skip("image");
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
const alt = typeof props["alt"] === "string" ? props["alt"] : "";
|
|
198
|
+
const mediaId = typeof props["mediaId"] === "string" ? props["mediaId"] : undefined;
|
|
199
|
+
body.push({
|
|
200
|
+
_type: "image",
|
|
201
|
+
_key: key(),
|
|
202
|
+
asset: { url: src, ...(mediaId ? { _ref: mediaId } : {}) },
|
|
203
|
+
...(alt && props["decorative"] !== true ? { alt } : {}),
|
|
204
|
+
...(typeof props["width"] === "number" ? { width: props["width"] } : {}),
|
|
205
|
+
...(typeof props["height"] === "number" ? { height: props["height"] } : {}),
|
|
206
|
+
});
|
|
207
|
+
converted++;
|
|
208
|
+
if (typeof props["caption"] === "string" && props["caption"].trim())
|
|
209
|
+
block(props["caption"].trim());
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
case "accordion-item":
|
|
213
|
+
case "tab-panel": {
|
|
214
|
+
const title = node.type === "accordion-item" ? props["summary"] : props["label"];
|
|
215
|
+
if (typeof title === "string" && title.trim()) {
|
|
216
|
+
block(title.trim(), "h3");
|
|
217
|
+
converted++;
|
|
218
|
+
}
|
|
219
|
+
for (const child of nodeChildren(node)) visit(child, seen);
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
case "part-ref": {
|
|
223
|
+
const partId = typeof props["partId"] === "string" ? props["partId"] : "";
|
|
224
|
+
const synced = options.sectionTemplates?.[partId];
|
|
225
|
+
if (synced && !seen.has(partId)) {
|
|
226
|
+
visit(synced.root, new Set([...seen, partId]));
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
for (const child of nodeChildren(node)) visit(child, seen);
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
default: {
|
|
233
|
+
if (BOXES.has(node.type)) {
|
|
234
|
+
for (const child of nodeChildren(node)) visit(child, seen);
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
if (!QUIET.has(node.type)) skip(node.type);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
};
|
|
241
|
+
visit(layout.root, new Set());
|
|
242
|
+
return { body, converted, skipped };
|
|
243
|
+
}
|
package/src/core/proposals.ts
CHANGED
|
@@ -21,7 +21,8 @@ import { proposalSafetyRefusal } from "./proposals-safety.ts";
|
|
|
21
21
|
const Revision = z.string().min(1).max(256);
|
|
22
22
|
export const ProposalTarget = z.strictObject({
|
|
23
23
|
collection: z.string().regex(/^[a-z][a-z0-9_-]{0,127}$/),
|
|
24
|
-
|
|
24
|
+
// S-01: EmDash ids are ULIDs; anything else (newlines included) is refused.
|
|
25
|
+
id: z.string().regex(/^[A-Za-z0-9_-]{1,128}$/),
|
|
25
26
|
});
|
|
26
27
|
const Value = z.record(z.string(), z.unknown());
|
|
27
28
|
const Position = { parentId: NodeId, index: z.number().int().min(0).max(2000) };
|
|
@@ -54,7 +55,12 @@ export type ProposalBase = {
|
|
|
54
55
|
designRevision: string | null;
|
|
55
56
|
design: unknown;
|
|
56
57
|
};
|
|
57
|
-
export type ProposalRecord = {
|
|
58
|
+
export type ProposalRecord = {
|
|
59
|
+
proposal: Proposal;
|
|
60
|
+
createdAt: string;
|
|
61
|
+
/** S-09 (W-998): who proposed it; records from before 1.1.2 have none. */
|
|
62
|
+
createdBy?: string;
|
|
63
|
+
};
|
|
58
64
|
export type ProposalRefusal = Refusal & {
|
|
59
65
|
code: "INVALID_PROPOSAL" | "STALE_BASE" | "NOT_FOUND" | "PROPOSALS_FULL";
|
|
60
66
|
opIndex?: number;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `data-emvb-*` attributes public HTML may carry: hooks a public runtime or host reads, never
|
|
3
|
+
* editor state. docs/system/layout-format.md ("Rendered output") lists the same names; a test
|
|
4
|
+
* keeps the two in step. Editor attributes such as `data-emvb-id` never reach public output.
|
|
5
|
+
*/
|
|
6
|
+
export const PUBLIC_DATA_ATTRIBUTES: readonly string[] = [
|
|
7
|
+
"data-emvb-theme-part",
|
|
8
|
+
"data-emvb-loop-item",
|
|
9
|
+
"data-emvb-popup",
|
|
10
|
+
"data-emvb-popup-config",
|
|
11
|
+
"data-emvb-popup-dismiss",
|
|
12
|
+
"data-emvb-float",
|
|
13
|
+
"data-emvb-float-dismiss",
|
|
14
|
+
"data-emvb-float-edge",
|
|
15
|
+
];
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The `data-emvb-*` attribute names on the tags of `html` (not inside `<style>` or `<script>`)
|
|
19
|
+
* that aren't public hooks, each once.
|
|
20
|
+
*/
|
|
21
|
+
export function editorAttributesIn(html: string): string[] {
|
|
22
|
+
const tags = html.replace(/<(style|script)\b[^>]*>[\s\S]*?<\/\1>/gi, "");
|
|
23
|
+
const found = new Set<string>();
|
|
24
|
+
for (const tag of tags.match(/<[a-z][^>]*>/gi) ?? []) {
|
|
25
|
+
for (const [, name] of tag.matchAll(/\s(data-emvb-[a-z0-9-]+)(?=[\s=>/])/gi)) {
|
|
26
|
+
if (name && !PUBLIC_DATA_ATTRIBUTES.includes(name)) found.add(name);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return [...found];
|
|
30
|
+
}
|