@perkyzz/emvb 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/admin/access/RequireEditor.tsx +7 -7
- package/src/admin/access/role.ts +5 -2
- package/src/admin/content-api.ts +10 -3
- package/src/admin/content-item.ts +1 -1
- package/src/admin/editor/A11yCopilot.tsx +104 -56
- package/src/admin/editor/CommandPalette.tsx +29 -13
- package/src/admin/editor/Editor.tsx +82 -20
- package/src/admin/editor/EditorToasts.tsx +26 -0
- package/src/admin/editor/PerfMeter.tsx +97 -72
- package/src/admin/editor/ShareLink.tsx +107 -72
- package/src/admin/editor/ShortcutsDialog.tsx +27 -16
- package/src/admin/editor/Timeline.tsx +255 -160
- package/src/admin/editor/TopBar.tsx +71 -14
- package/src/admin/editor/canvas/CanvasFrame.tsx +10 -1
- package/src/admin/editor/canvas/CanvasTextEdit.tsx +8 -2
- package/src/admin/editor/canvas/drop-line.ts +11 -3
- package/src/admin/editor/canvas/frame-focus-ring.ts +37 -0
- package/src/admin/editor/canvas/use-canvas-dnd.ts +32 -3
- package/src/admin/editor/canvas/vnode-react.tsx +7 -0
- package/src/admin/editor/collection-previews.ts +10 -0
- package/src/admin/editor/dialogs.tsx +38 -14
- package/src/admin/editor/dnd/drop-target.ts +26 -1
- package/src/admin/editor/edited-noun.ts +15 -0
- package/src/admin/editor/editor-chrome.tsx +59 -7
- package/src/admin/editor/editor-commands.ts +2 -1
- package/src/admin/editor/editor-css.ts +72 -22
- package/src/admin/editor/element-chrome.ts +21 -11
- package/src/admin/editor/feature-css.ts +45 -13
- package/src/admin/editor/icons/IconLibraryDialog.tsx +52 -11
- package/src/admin/editor/icons/library.ts +1 -1
- package/src/admin/editor/icons/use-icon-library.ts +5 -2
- package/src/admin/editor/ime.ts +29 -0
- package/src/admin/editor/palette-items.ts +10 -3
- package/src/admin/editor/panels/AddPanel.tsx +35 -10
- package/src/admin/editor/panels/ClassesSection.tsx +18 -7
- package/src/admin/editor/panels/ColorControl.tsx +130 -23
- package/src/admin/editor/panels/ConditionsEditor.tsx +52 -26
- package/src/admin/editor/panels/ElementPanel.tsx +134 -24
- package/src/admin/editor/panels/LayersPanel.tsx +55 -19
- package/src/admin/editor/panels/PageSettings.tsx +66 -35
- package/src/admin/editor/panels/SiteStylesDrawer.tsx +170 -32
- package/src/admin/editor/panels/TokenScales.tsx +76 -36
- package/src/admin/editor/panels/TriggerSettings.tsx +50 -12
- package/src/admin/editor/panels/TriggersEditor.tsx +2 -1
- package/src/admin/editor/panels/VariableSection.tsx +48 -18
- package/src/admin/editor/panels/color-space.ts +9 -3
- package/src/admin/editor/panels/settings/AdvancedFields.tsx +12 -2
- package/src/admin/editor/panels/settings/AudienceEditor.tsx +51 -35
- package/src/admin/editor/panels/settings/BackgroundControls.tsx +55 -11
- package/src/admin/editor/panels/settings/BackgroundFill.tsx +3 -2
- package/src/admin/editor/panels/settings/BindingsEditor.tsx +15 -18
- package/src/admin/editor/panels/settings/BoxControl.tsx +2 -1
- package/src/admin/editor/panels/settings/ClassChip.tsx +21 -9
- package/src/admin/editor/panels/settings/ClassChipInput.tsx +24 -16
- package/src/admin/editor/panels/settings/DraftTextField.tsx +41 -3
- package/src/admin/editor/panels/settings/EffectsControls.tsx +38 -14
- package/src/admin/editor/panels/settings/FieldBindControl.tsx +46 -28
- package/src/admin/editor/panels/settings/FieldControl.tsx +20 -8
- package/src/admin/editor/panels/settings/FormBindControl.tsx +2 -2
- package/src/admin/editor/panels/settings/HintedSwitch.tsx +33 -0
- package/src/admin/editor/panels/settings/IconControls.tsx +12 -8
- package/src/admin/editor/panels/settings/IconPicker.tsx +2 -0
- package/src/admin/editor/panels/settings/ImageSourcesField.tsx +3 -1
- package/src/admin/editor/panels/settings/ItemList.tsx +15 -2
- package/src/admin/editor/panels/settings/LengthRow.tsx +8 -6
- package/src/admin/editor/panels/settings/MediaPicker.tsx +127 -23
- package/src/admin/editor/panels/settings/MotionControl.tsx +28 -15
- package/src/admin/editor/panels/settings/NumberRow.tsx +9 -3
- package/src/admin/editor/panels/settings/PanelSelect.tsx +50 -0
- package/src/admin/editor/panels/settings/QueryStyleRows.tsx +25 -18
- package/src/admin/editor/panels/settings/RequiredFieldsNotice.tsx +66 -1
- package/src/admin/editor/panels/settings/StyleRow.tsx +10 -3
- package/src/admin/editor/panels/settings/StyleSources.tsx +4 -1
- package/src/admin/editor/panels/settings/VariantEditor.tsx +10 -1
- package/src/admin/editor/panels/settings/box-link-name.ts +6 -2
- package/src/admin/editor/panels/settings/class-suggest.ts +7 -7
- package/src/admin/editor/panels/settings/query-style.ts +38 -9
- package/src/admin/editor/panels/settings/svg-images.ts +13 -0
- package/src/admin/editor/panels/site-list.tsx +20 -6
- package/src/admin/editor/panels/variable-values.ts +11 -4
- package/src/admin/editor/restore-deleted.ts +21 -2
- package/src/admin/editor/section-templates.ts +81 -12
- package/src/admin/editor/shortcuts.ts +17 -2
- package/src/admin/editor/store.ts +7 -0
- package/src/admin/editor/useEditorCommands.ts +61 -15
- package/src/admin/editor/useEditorData.ts +4 -2
- package/src/admin/editor/useEditorShortcuts.ts +17 -7
- package/src/admin/editor/useNodeActions.ts +61 -6
- package/src/admin/editor/useSave.ts +22 -7
- package/src/admin/forms-api.ts +2 -0
- package/src/admin/image-editor/CurvesPanel.tsx +2 -1
- package/src/admin/image-editor/ExportDialog.tsx +48 -18
- package/src/admin/image-editor/ImageEditorDialog.tsx +49 -7
- package/src/admin/image-editor/MetadataPanel.tsx +15 -4
- package/src/admin/image-editor/crop-geometry.ts +3 -2
- package/src/admin/image-editor/image-editor-css.ts +4 -2
- package/src/admin/image-editor/load.ts +9 -2
- package/src/admin/image-editor/parts.tsx +51 -2
- package/src/admin/image-editor/save.ts +23 -7
- package/src/admin/media-api.ts +2 -1
- package/src/admin/pages/AgentsPage.tsx +138 -27
- package/src/admin/pages/CreateDialog.tsx +97 -30
- package/src/admin/pages/NewPageDialog.tsx +21 -3
- package/src/admin/pages/NewThemePartDialog.tsx +11 -3
- package/src/admin/pages/PageList.tsx +14 -6
- package/src/admin/pages/SetupShell.tsx +28 -12
- package/src/admin/pages/ThemePartList.tsx +27 -7
- package/src/admin/pages/list-kit.tsx +106 -24
- package/src/admin/search.ts +15 -0
- package/src/admin/setup/useSetupStatus.ts +1 -1
- package/src/admin/theme-api.ts +13 -3
- package/src/admin/ui.ts +73 -22
- package/src/astro/floats/runtime.ts +21 -0
- package/src/astro/menu/runtime.ts +34 -1
- package/src/astro/popups/runtime.ts +33 -3
- package/src/astro/render.ts +3 -0
- package/src/astro/resolve-theme.ts +53 -11
- package/src/astro/resolve.ts +9 -1
- package/src/astro/tabs/runtime.ts +12 -0
- package/src/astro/theme-posts.ts +2 -2
- package/src/astro/visitor.ts +2 -0
- package/src/constants.ts +1 -1
- package/src/core/a11y/audit.ts +171 -24
- package/src/core/arrange.ts +27 -6
- package/src/core/audience/rules.ts +5 -1
- package/src/core/audience/variants.ts +29 -3
- package/src/core/clipboard.ts +7 -0
- package/src/core/css/generate.ts +31 -6
- package/src/core/data/bindings.ts +8 -1
- package/src/core/design/classes.ts +16 -7
- package/src/core/design/diff.ts +6 -0
- package/src/core/design/merge.ts +90 -2
- package/src/core/design/tokens.ts +16 -2
- package/src/core/design/transfer.ts +33 -6
- package/src/core/design/variables.ts +30 -9
- package/src/core/elements/dynamic-elements.ts +44 -5
- package/src/core/elements/form-elements.ts +55 -16
- package/src/core/elements/index.ts +83 -38
- package/src/core/elements/menu.ts +37 -19
- package/src/core/elements/select-prompt.ts +3 -0
- package/src/core/elements/svg-ids.ts +39 -0
- package/src/core/forms/binding.ts +57 -16
- package/src/core/forms/definition.ts +72 -0
- package/src/core/history/diff.ts +18 -1
- package/src/core/icons/catalog.ts +3 -2
- package/src/core/image-edit/schema.ts +11 -1
- package/src/core/image-edit/summary.ts +6 -3
- package/src/core/index.ts +15 -1
- package/src/core/limits.ts +12 -1
- package/src/core/perf/meter.ts +42 -7
- package/src/core/recipes/index.ts +5 -4
- package/src/core/render/context.ts +8 -0
- package/src/core/render/dynamic-post.ts +69 -12
- package/src/core/render/extras.ts +77 -4
- package/src/core/render/form.ts +140 -6
- package/src/core/render/index.ts +156 -20
- package/src/core/render/loop.ts +43 -7
- package/src/core/render/pagination.ts +18 -4
- package/src/core/render/section.ts +27 -0
- package/src/core/render/tabs.ts +12 -3
- package/src/core/render/vnode.ts +1 -1
- package/src/core/sanitize/css.ts +15 -2
- package/src/core/sanitize/embed-url.ts +42 -5
- package/src/core/sanitize/url.ts +2 -1
- package/src/core/schema/layout.ts +15 -6
- package/src/core/stats.ts +2 -1
- package/src/core/theme/conditions.ts +3 -1
- package/src/core/theme/dynamic.ts +36 -5
- package/src/core/theme/float.ts +9 -2
- package/src/core/theme/pagination.ts +31 -11
- package/src/core/theme/popup-markup.ts +23 -5
- package/src/core/theme/popup-rules.ts +1 -0
- package/src/core/theme/triggers.ts +3 -2
- package/src/core/tree-ops.ts +27 -0
- package/src/mcp/rate-limit.ts +2 -1
- package/src/mcp/read.ts +14 -2
- package/src/mcp/refs.ts +18 -0
- package/src/mcp/write.ts +174 -10
- package/src/server/agent-settings.ts +1 -1
- package/src/server/hooks.ts +5 -3
- package/src/server/icon-routes.ts +30 -9
- package/src/server/mcp-routes.ts +6 -1
|
@@ -7,6 +7,39 @@ import { portableTextToVNodes, type ThemePostFields } from "../theme/dynamic.ts"
|
|
|
7
7
|
import type { RenderMode } from "./context.ts";
|
|
8
8
|
import type { VNode } from "./vnode.ts";
|
|
9
9
|
|
|
10
|
+
/** Scripts written without spaces between words; a space-separated chunk holds many words. */
|
|
11
|
+
const UNSPACED =
|
|
12
|
+
/[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Thai}\p{Script=Lao}\p{Script=Khmer}\p{Script=Myanmar}]/u;
|
|
13
|
+
let wordSegmenter: Intl.Segmenter | undefined;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The first `max` words, then "…". W-660: Japanese, Chinese or Thai text has no spaces between
|
|
17
|
+
* words, so splitting on spaces counted a whole excerpt as one word and never shortened it.
|
|
18
|
+
* Those chunks are split into words; spaced text is counted by spaces as before.
|
|
19
|
+
*/
|
|
20
|
+
function limitWords(text: string, max: number | undefined): string {
|
|
21
|
+
if (!max || max < 1) return text;
|
|
22
|
+
let count = 0;
|
|
23
|
+
for (const chunk of text.matchAll(/\S+/g)) {
|
|
24
|
+
const start = chunk.index ?? 0;
|
|
25
|
+
if (!UNSPACED.test(chunk[0])) {
|
|
26
|
+
count++;
|
|
27
|
+
if (count === max) return finish(text, start + chunk[0].length);
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
wordSegmenter ??= new Intl.Segmenter(undefined, { granularity: "word" });
|
|
31
|
+
for (const piece of wordSegmenter.segment(chunk[0])) {
|
|
32
|
+
if (!piece.isWordLike) continue;
|
|
33
|
+
count++;
|
|
34
|
+
if (count === max) return finish(text, start + piece.index + piece.segment.length);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return text;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const finish = (text: string, end: number) =>
|
|
41
|
+
text.slice(end).trim() === "" ? text : `${text.slice(0, end).trim().replace(/\s+/g, " ")}…`;
|
|
42
|
+
|
|
10
43
|
/**
|
|
11
44
|
* W-196: only an ISO date (`2026-10-06`, optionally with a time) is read as a date. `Date.parse`
|
|
12
45
|
* also takes text like "Spring 2026" (as Jan 1) or "2026-02-30", which would show a wrong date.
|
|
@@ -17,8 +50,10 @@ const parseIsoDate = (raw: string): number => {
|
|
|
17
50
|
const parsed = Date.parse(raw.replace(" ", "T"));
|
|
18
51
|
if (Number.isNaN(parsed)) return Number.NaN;
|
|
19
52
|
const day = new Date(Date.UTC(Number(match[1]), Number(match[2]) - 1, Number(match[3])));
|
|
53
|
+
// W-599: the day as written. A post at 22:00-04:00 was published that day, not the next
|
|
54
|
+
// one in UTC, and a time with no zone isn't moved by the server's zone.
|
|
20
55
|
return day.getUTCDate() === Number(match[3]) && day.getUTCMonth() === Number(match[2]) - 1
|
|
21
|
-
?
|
|
56
|
+
? day.getTime()
|
|
22
57
|
: Number.NaN;
|
|
23
58
|
};
|
|
24
59
|
|
|
@@ -35,16 +70,32 @@ type PostField = {
|
|
|
35
70
|
attrs: Attrs,
|
|
36
71
|
post: ThemePostFields,
|
|
37
72
|
inLoop: boolean,
|
|
73
|
+
lang?: string,
|
|
38
74
|
) => VNode | undefined;
|
|
39
75
|
};
|
|
40
76
|
|
|
41
77
|
type PostDateFormat = (typeof POST_DATE_FORMATS)[number];
|
|
42
78
|
|
|
43
|
-
/**
|
|
44
|
-
function
|
|
79
|
+
/** A BCP 47-shaped language tag Intl can use, else English (W-688). */
|
|
80
|
+
function dateLocale(lang: string | undefined): string {
|
|
81
|
+
if (!lang || !/^[A-Za-z]{2,8}(?:-[A-Za-z0-9]{1,8})*$/.test(lang)) return "en";
|
|
82
|
+
try {
|
|
83
|
+
return Intl.DateTimeFormat.supportedLocalesOf([lang])[0] ?? "en";
|
|
84
|
+
} catch {
|
|
85
|
+
return "en";
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* In UTC on the written day, so the date doesn't move with the server's time zone.
|
|
91
|
+
* W-688: in the page's language ("6 oct. 2026" on a French site); it was always English.
|
|
92
|
+
*/
|
|
93
|
+
function formatPostDate(time: number, format: PostDateFormat, lang?: string): string {
|
|
45
94
|
const date = new Date(time);
|
|
46
95
|
if (format === "numeric") return date.toISOString().slice(0, 10);
|
|
47
|
-
return new Intl.DateTimeFormat(
|
|
96
|
+
return new Intl.DateTimeFormat(dateLocale(lang), { dateStyle: format, timeZone: "UTC" }).format(
|
|
97
|
+
date,
|
|
98
|
+
);
|
|
48
99
|
}
|
|
49
100
|
|
|
50
101
|
const props = <T>(node: LayoutNode) => node.props as T;
|
|
@@ -54,6 +105,9 @@ const POST_FIELDS = new Map<string, PostField>([
|
|
|
54
105
|
"post-title",
|
|
55
106
|
{
|
|
56
107
|
placeholder: (attrs) => ({ tag: "h1", attrs, children: ["Post Title"] }),
|
|
108
|
+
// W-661: an untitled post left an empty heading on the page (a blank entry for screen
|
|
109
|
+
// reader heading lists).
|
|
110
|
+
has: (post) => !!post.title?.trim(),
|
|
57
111
|
render: (node, attrs, post) => {
|
|
58
112
|
const level = props<{ level?: number }>(node).level ?? 1;
|
|
59
113
|
const tag = HEADING_TAGS[Math.min(6, Math.max(1, level)) - 1] ?? "h1";
|
|
@@ -66,10 +120,8 @@ const POST_FIELDS = new Map<string, PostField>([
|
|
|
66
120
|
{
|
|
67
121
|
placeholder: (attrs) => ({ tag: "p", attrs, children: ["Post excerpt…"] }),
|
|
68
122
|
render: (node, attrs, post) => {
|
|
69
|
-
if (!post.excerpt) return undefined;
|
|
70
|
-
const
|
|
71
|
-
const words = post.excerpt.trim().split(/\s+/);
|
|
72
|
-
const text = max && words.length > max ? `${words.slice(0, max).join(" ")}…` : post.excerpt;
|
|
123
|
+
if (!post.excerpt?.trim()) return undefined;
|
|
124
|
+
const text = limitWords(post.excerpt, props<{ maxWords?: number }>(node).maxWords);
|
|
73
125
|
return { tag: "p", attrs, children: [text] };
|
|
74
126
|
},
|
|
75
127
|
},
|
|
@@ -102,7 +154,7 @@ const POST_FIELDS = new Map<string, PostField>([
|
|
|
102
154
|
if (!src) return undefined;
|
|
103
155
|
const alt = props<{ decorative?: boolean }>(node).decorative
|
|
104
156
|
? ""
|
|
105
|
-
: post.featuredImageAlt?.trim() || post.title || "Featured image";
|
|
157
|
+
: post.featuredImageAlt?.trim() || post.title?.trim() || "Featured image";
|
|
106
158
|
// W-440: a Loop's images below the fold loaded all at once; like Image, they wait.
|
|
107
159
|
// A single post's featured image is usually the hero, so it isn't delayed.
|
|
108
160
|
const lazy: Attrs = inLoop ? { loading: "lazy", decoding: "async" } : {};
|
|
@@ -147,12 +199,15 @@ const POST_FIELDS = new Map<string, PostField>([
|
|
|
147
199
|
{
|
|
148
200
|
placeholder: (attrs) => ({ tag: "time", attrs, children: ["Post date"] }),
|
|
149
201
|
has: (post) => !!post.publishedAt?.trim(),
|
|
150
|
-
render: (node, attrs, post) => {
|
|
202
|
+
render: (node, attrs, post, _inLoop, lang) => {
|
|
151
203
|
const raw = post.publishedAt?.trim();
|
|
152
204
|
if (!raw) return undefined;
|
|
153
205
|
const parsed = parseIsoDate(raw);
|
|
154
206
|
const format = props<{ format?: PostDateFormat }>(node).format ?? "medium";
|
|
155
|
-
|
|
207
|
+
// W-700: whole characters, so a long free-text date doesn't end in half an emoji.
|
|
208
|
+
const text = Number.isNaN(parsed)
|
|
209
|
+
? clipText(raw, 80)
|
|
210
|
+
: formatPostDate(parsed, format, lang);
|
|
156
211
|
// W-196: `datetime` must be machine-readable, so a date we can't read only shows as text.
|
|
157
212
|
const timeAttrs = Number.isNaN(parsed) ? attrs : { ...attrs, datetime: raw.slice(0, 80) };
|
|
158
213
|
return { tag: "time", attrs: timeAttrs, children: [text] };
|
|
@@ -181,11 +236,13 @@ export function renderDynamicPost(
|
|
|
181
236
|
post: ThemePostFields | undefined,
|
|
182
237
|
mode: RenderMode,
|
|
183
238
|
inLoop = false,
|
|
239
|
+
/** The page's language, e.g. "fr-CA", for dates (W-688). */
|
|
240
|
+
lang?: string,
|
|
184
241
|
): VNode | undefined {
|
|
185
242
|
const field = POST_FIELDS.get(node.type);
|
|
186
243
|
if (!field) return undefined;
|
|
187
244
|
if (!post || field.has?.(post) === false) {
|
|
188
245
|
return mode === "editor" ? field.placeholder(attrs) : undefined;
|
|
189
246
|
}
|
|
190
|
-
return field.render(node, attrs, post, inLoop);
|
|
247
|
+
return field.render(node, attrs, post, inLoop, lang);
|
|
191
248
|
}
|
|
@@ -46,9 +46,49 @@ function childrenOf(node: LayoutNode): LayoutNode[] {
|
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
/** A link, a button, or a box that is already a link. */
|
|
49
|
+
/**
|
|
50
|
+
* W-668: elements that always render a link, control or embed. A linked box around one of these
|
|
51
|
+
* nested an <a> in an <a> (the browser then splits the box apart) or put a menu, form field,
|
|
52
|
+
* accordion toggle or video player inside a link.
|
|
53
|
+
*/
|
|
54
|
+
const ALWAYS_INTERACTIVE = new Set([
|
|
55
|
+
"link",
|
|
56
|
+
"post-link",
|
|
57
|
+
"button",
|
|
58
|
+
"menu",
|
|
59
|
+
"menu-item",
|
|
60
|
+
"accordion",
|
|
61
|
+
"accordion-item",
|
|
62
|
+
"tabs",
|
|
63
|
+
"video",
|
|
64
|
+
"form",
|
|
65
|
+
"text-input",
|
|
66
|
+
"textarea",
|
|
67
|
+
"select",
|
|
68
|
+
"checkbox",
|
|
69
|
+
"radio",
|
|
70
|
+
"submit",
|
|
71
|
+
"pagination",
|
|
72
|
+
"toc",
|
|
73
|
+
// Post content can hold links of its own.
|
|
74
|
+
"post-content",
|
|
75
|
+
]);
|
|
76
|
+
|
|
49
77
|
function containsInteractive(node: LayoutNode): boolean {
|
|
50
|
-
if (
|
|
51
|
-
|
|
78
|
+
if (ALWAYS_INTERACTIVE.has(node.type)) return true;
|
|
79
|
+
const props = node.props as { partId?: unknown; itemPartId?: unknown };
|
|
80
|
+
// A synced section or Loop Item part is another layout this check can't see into.
|
|
81
|
+
if (node.type === "section" && typeof props.partId === "string" && props.partId.trim())
|
|
82
|
+
return true;
|
|
83
|
+
if (node.type === "loop" && typeof props.itemPartId === "string" && props.itemPartId.trim()) {
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
if (
|
|
87
|
+
BOX.has(node.type) ||
|
|
88
|
+
node.type === "heading" ||
|
|
89
|
+
node.type === "icon" ||
|
|
90
|
+
node.type === "image"
|
|
91
|
+
) {
|
|
52
92
|
const href = (node.props as { href?: unknown }).href;
|
|
53
93
|
if (typeof href === "string" && href.trim()) return true;
|
|
54
94
|
}
|
|
@@ -59,6 +99,26 @@ function containsInteractive(node: LayoutNode): boolean {
|
|
|
59
99
|
* A div box becomes the link. A landmark tag stays a landmark. A link already inside the box
|
|
60
100
|
* keeps the box from becoming a link, so the page never nests anchors.
|
|
61
101
|
*/
|
|
102
|
+
/**
|
|
103
|
+
* W-669: a box with a working Link that still renders as a box because something inside it is a
|
|
104
|
+
* link, control or embed. The editor says so; the Link otherwise did nothing without a word.
|
|
105
|
+
*/
|
|
106
|
+
export function boxLinkHeldBack(node: LayoutNode): boolean {
|
|
107
|
+
if (!BOX.has(node.type)) return false;
|
|
108
|
+
const href = (node.props as { href?: unknown }).href;
|
|
109
|
+
if (typeof href !== "string" || !href.trim() || !sanitizeHref(href)) return false;
|
|
110
|
+
return childrenOf(node).some(containsInteractive);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** W-798: the same test applyBoxLink makes, for checks that see only the layout (the audit). */
|
|
114
|
+
export function boxBecomesLink(node: LayoutNode): boolean {
|
|
115
|
+
if (!BOX.has(node.type)) return false;
|
|
116
|
+
const { href, tag } = node.props as { href?: unknown; tag?: unknown };
|
|
117
|
+
if (tag !== undefined && tag !== "div") return false;
|
|
118
|
+
if (typeof href !== "string" || !href.trim() || !sanitizeHref(href)) return false;
|
|
119
|
+
return !childrenOf(node).some(containsInteractive);
|
|
120
|
+
}
|
|
121
|
+
|
|
62
122
|
export function applyBoxLink(node: LayoutNode, vnode: VNode): VNode {
|
|
63
123
|
if (!BOX.has(node.type) || vnode.tag !== "div") return vnode;
|
|
64
124
|
const { href, newTab } = node.props as { href?: string; newTab?: boolean };
|
|
@@ -66,7 +126,11 @@ export function applyBoxLink(node: LayoutNode, vnode: VNode): VNode {
|
|
|
66
126
|
if (childrenOf(node).some(containsInteractive)) return vnode;
|
|
67
127
|
const safe = sanitizeHref(href);
|
|
68
128
|
if (!safe) return vnode;
|
|
69
|
-
const attrs: Record<string, string> = {
|
|
129
|
+
const attrs: Record<string, string> = {
|
|
130
|
+
...vnode.attrs,
|
|
131
|
+
class: `${vnode.attrs.class ?? ""} emvb-box-link`.trim(),
|
|
132
|
+
href: safe,
|
|
133
|
+
};
|
|
70
134
|
if (newTab) {
|
|
71
135
|
attrs.target = "_blank";
|
|
72
136
|
attrs.rel = "noopener noreferrer";
|
|
@@ -89,7 +153,16 @@ export function applyBackgroundVideo(vnode: VNode, src: string | undefined): VNo
|
|
|
89
153
|
children: [
|
|
90
154
|
{
|
|
91
155
|
tag: "video",
|
|
92
|
-
|
|
156
|
+
// W-801: decoration, not content, so screen readers skip it.
|
|
157
|
+
attrs: {
|
|
158
|
+
class: "emvb-bg-video",
|
|
159
|
+
src,
|
|
160
|
+
muted: "",
|
|
161
|
+
loop: "",
|
|
162
|
+
playsinline: "",
|
|
163
|
+
autoplay: "",
|
|
164
|
+
"aria-hidden": "true",
|
|
165
|
+
},
|
|
93
166
|
children: [],
|
|
94
167
|
},
|
|
95
168
|
...vnode.children,
|
package/src/core/render/form.ts
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
fieldByName,
|
|
3
|
+
fieldsOf,
|
|
4
|
+
type FormDefinitions,
|
|
5
|
+
type PublicFormDefinition,
|
|
6
|
+
type PublicFormField,
|
|
7
|
+
} from "../forms/definition.ts";
|
|
2
8
|
import type { FormNode, LayoutNode } from "../schema/layout.ts";
|
|
9
|
+
import { selectPrompt } from "../elements/select-prompt.ts";
|
|
3
10
|
import type { ThemeDynamicData } from "../theme/dynamic.ts";
|
|
4
11
|
import { nodeChildren } from "../tree-ops.ts";
|
|
5
12
|
import type { RenderContext } from "./context.ts";
|
|
@@ -115,6 +122,7 @@ export function renderForm(
|
|
|
115
122
|
children: [
|
|
116
123
|
page,
|
|
117
124
|
{ tag: "input", attrs: { type: "hidden", name: "formId", value: formId }, children: [] },
|
|
125
|
+
...hiddenFields(ctx.definitions.get(formId)),
|
|
118
126
|
// One id per form element, so the same form placed twice keeps unique ids (W-187), also
|
|
119
127
|
// when one form element renders twice, from a synced section or a loop item (W-249).
|
|
120
128
|
honeypot(ctx.uniqueId(`emvb-hp-${node.id}`)),
|
|
@@ -127,6 +135,24 @@ export function renderForm(
|
|
|
127
135
|
};
|
|
128
136
|
}
|
|
129
137
|
|
|
138
|
+
/**
|
|
139
|
+
* W-595: the definition's hidden fields (a source tag, a campaign id) have no control to place,
|
|
140
|
+
* so the form carries them with their default value, as the forms plugin's own embed does.
|
|
141
|
+
*/
|
|
142
|
+
function hiddenFields(definition: PublicFormDefinition | undefined): VNode[] {
|
|
143
|
+
if (!definition) return [];
|
|
144
|
+
return fieldsOf(definition)
|
|
145
|
+
.filter((field) => field.type === "hidden" && field.name)
|
|
146
|
+
.map((field) => {
|
|
147
|
+
const value = (field as { defaultValue?: unknown }).defaultValue;
|
|
148
|
+
return {
|
|
149
|
+
tag: "input",
|
|
150
|
+
attrs: { type: "hidden", name: field.name, value: typeof value === "string" ? value : "" },
|
|
151
|
+
children: [],
|
|
152
|
+
};
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
|
|
130
156
|
/** Replaces the children of every node matching `match`, anywhere in the tree. */
|
|
131
157
|
function replaceChildren(vnode: VNode, match: (node: VNode) => boolean, children: VNode[]): VNode {
|
|
132
158
|
if (match(vnode)) return { ...vnode, children };
|
|
@@ -217,6 +243,9 @@ function repeatsARiskyGroup(pattern: string): boolean {
|
|
|
217
243
|
}
|
|
218
244
|
if (ch === "(") {
|
|
219
245
|
stack.push({ risky: false });
|
|
246
|
+
// W-594: the `?` of `(?:`, `(?=`, `(?!`, `(?<=`, `(?<!` or `(?<name>` is not a quantifier.
|
|
247
|
+
const prefix = /^\?(?::|=|!|<=|<!|<[A-Za-z_$][\w$]*>)/.exec(pattern.slice(i + 1));
|
|
248
|
+
if (prefix) i += prefix[0].length;
|
|
220
249
|
continue;
|
|
221
250
|
}
|
|
222
251
|
if (ch === ")") {
|
|
@@ -252,7 +281,69 @@ function safeInputPattern(pattern: string): string | undefined {
|
|
|
252
281
|
} catch {
|
|
253
282
|
return undefined;
|
|
254
283
|
}
|
|
255
|
-
return value;
|
|
284
|
+
if (compilesAsPattern(value)) return value;
|
|
285
|
+
const repaired = escapeClassLiterals(value);
|
|
286
|
+
return compilesAsPattern(repaired) ? repaired : undefined;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* W-538: browsers compile `pattern` as `^(?:…)$` with the `v` flag, which refuses a common
|
|
291
|
+
* pattern such as `[A-Za-z0-9_-]+` (a `-` or `(` left bare in a class). The browser then drops
|
|
292
|
+
* the check with a console error, so the field went unchecked.
|
|
293
|
+
*/
|
|
294
|
+
function compilesAsPattern(value: string): boolean {
|
|
295
|
+
try {
|
|
296
|
+
return new RegExp(`^(?:${value})$`, "v").source.length > 0;
|
|
297
|
+
} catch {
|
|
298
|
+
return false;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/** Escapes, inside character classes, the literals `v` mode wants escaped: a loose `-`, ()[]{}/|. */
|
|
303
|
+
function escapeClassLiterals(value: string): string {
|
|
304
|
+
let out = "";
|
|
305
|
+
let inClass = false;
|
|
306
|
+
let classStart = 0;
|
|
307
|
+
for (let i = 0; i < value.length; i += 1) {
|
|
308
|
+
const ch = value[i] as string;
|
|
309
|
+
if (ch === "\\") {
|
|
310
|
+
out += ch + (value[i + 1] ?? "");
|
|
311
|
+
i += 1;
|
|
312
|
+
continue;
|
|
313
|
+
}
|
|
314
|
+
if (!inClass) {
|
|
315
|
+
if (ch === "[") {
|
|
316
|
+
inClass = true;
|
|
317
|
+
out += ch;
|
|
318
|
+
if (value[i + 1] === "^") {
|
|
319
|
+
out += "^";
|
|
320
|
+
i += 1;
|
|
321
|
+
}
|
|
322
|
+
classStart = i + 1;
|
|
323
|
+
continue;
|
|
324
|
+
}
|
|
325
|
+
out += ch;
|
|
326
|
+
continue;
|
|
327
|
+
}
|
|
328
|
+
if (ch === "]") {
|
|
329
|
+
inClass = false;
|
|
330
|
+
out += ch;
|
|
331
|
+
continue;
|
|
332
|
+
}
|
|
333
|
+
if (ch === "-") {
|
|
334
|
+
const loose = i === classStart || value[i + 1] === "]";
|
|
335
|
+
out += loose ? "\\-" : ch;
|
|
336
|
+
continue;
|
|
337
|
+
}
|
|
338
|
+
out += "()[{}/|".includes(ch) ? `\\${ch}` : ch;
|
|
339
|
+
}
|
|
340
|
+
return out;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
function lengthLimit(value: unknown, round: (n: number) => number): string | undefined {
|
|
344
|
+
if (typeof value !== "number" || !Number.isFinite(value)) return undefined;
|
|
345
|
+
const whole = round(value);
|
|
346
|
+
return whole >= 0 ? String(whole) : undefined;
|
|
256
347
|
}
|
|
257
348
|
|
|
258
349
|
/**
|
|
@@ -267,12 +358,19 @@ function withFieldMeta(vnode: VNode, node: LayoutNode, meta: PublicFormField): V
|
|
|
267
358
|
const limits: Record<string, string> = {};
|
|
268
359
|
if (node.type === "text-input" || node.type === "textarea") {
|
|
269
360
|
if (LENGTH_TYPES.has(kind)) {
|
|
270
|
-
|
|
271
|
-
|
|
361
|
+
// W-588: the browser drops a minlength/maxlength that isn't a whole number >= 0, so a
|
|
362
|
+
// fractional limit is rounded inward and a negative or non-finite one is left off.
|
|
363
|
+
const lo = lengthLimit(rules.minLength, Math.ceil);
|
|
364
|
+
const hi = lengthLimit(rules.maxLength, Math.floor);
|
|
365
|
+
if (lo !== undefined) limits.minlength = lo;
|
|
366
|
+
if (hi !== undefined) limits.maxlength = hi;
|
|
272
367
|
}
|
|
273
368
|
if (kind === "number") {
|
|
274
369
|
if (rules.min !== undefined) limits.min = String(rules.min);
|
|
275
370
|
if (rules.max !== undefined) limits.max = String(rules.max);
|
|
371
|
+
// W-578: the forms plugin accepts any number; the browser's default step of 1 refused
|
|
372
|
+
// decimals (and, counted from a fractional min, every whole number).
|
|
373
|
+
limits.step = "any";
|
|
276
374
|
}
|
|
277
375
|
if (node.type === "text-input" && kind !== "number" && kind !== "date" && rules.pattern) {
|
|
278
376
|
const pattern = safeInputPattern(rules.pattern);
|
|
@@ -317,7 +415,7 @@ function withFieldMeta(vnode: VNode, node: LayoutNode, meta: PublicFormField): V
|
|
|
317
415
|
}
|
|
318
416
|
|
|
319
417
|
/** Fills a field from the form it sits in: options, type, limits. Other forms are left alone. */
|
|
320
|
-
|
|
418
|
+
function withDefinedField(
|
|
321
419
|
vnode: VNode,
|
|
322
420
|
node: LayoutNode,
|
|
323
421
|
definitions: FormDefinitions,
|
|
@@ -332,6 +430,38 @@ export function withFieldOptions(
|
|
|
332
430
|
return withFieldMeta(withOptions(vnode, node, meta), node, meta);
|
|
333
431
|
}
|
|
334
432
|
|
|
433
|
+
/** Fills a field from the form it sits in, and carries its show condition (W-596). */
|
|
434
|
+
export function withFieldOptions(
|
|
435
|
+
vnode: VNode,
|
|
436
|
+
node: LayoutNode,
|
|
437
|
+
definitions: FormDefinitions,
|
|
438
|
+
formId?: string,
|
|
439
|
+
): VNode {
|
|
440
|
+
const built = withDefinedField(vnode, node, definitions, formId);
|
|
441
|
+
const field = (node.props as { field?: unknown }).field;
|
|
442
|
+
if (built === vnode || typeof field !== "string" || !formId) return built;
|
|
443
|
+
const meta = fieldByName(definitions.get(formId), field);
|
|
444
|
+
return meta ? withCondition(built, meta) : built;
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
const CONDITION_OPS = new Set(["eq", "neq", "filled", "empty"]);
|
|
448
|
+
|
|
449
|
+
/**
|
|
450
|
+
* W-596: a field the definition shows only on a condition (`other` when Topic is Other) carries
|
|
451
|
+
* it as the plugin's embed does; the forms client then hides and disables it, so its `required`
|
|
452
|
+
* no longer blocks the form while it can't be filled.
|
|
453
|
+
*/
|
|
454
|
+
function withCondition(vnode: VNode, meta: PublicFormField): VNode {
|
|
455
|
+
const raw = (meta as { condition?: unknown }).condition;
|
|
456
|
+
if (!raw || typeof raw !== "object") return vnode;
|
|
457
|
+
const { field, op, value } = raw as Record<string, unknown>;
|
|
458
|
+
if (typeof field !== "string" || !field || typeof op !== "string" || !CONDITION_OPS.has(op)) {
|
|
459
|
+
return vnode;
|
|
460
|
+
}
|
|
461
|
+
const condition = typeof value === "string" ? { field, op, value } : { field, op };
|
|
462
|
+
return { ...vnode, attrs: { ...vnode.attrs, "data-condition": JSON.stringify(condition) } };
|
|
463
|
+
}
|
|
464
|
+
|
|
335
465
|
/** The fieldset that holds a radio group's options. */
|
|
336
466
|
const radioGroup = (child: VNode) =>
|
|
337
467
|
child.tag === "fieldset" && (child.attrs.class ?? "").includes("emvb-radio-group");
|
|
@@ -342,7 +472,11 @@ function withOptions(vnode: VNode, node: LayoutNode, meta: PublicFormField): VNo
|
|
|
342
472
|
if ((node.type !== "select" && node.type !== "radio") || !meta.options?.length) return vnode;
|
|
343
473
|
if (node.type === "select") {
|
|
344
474
|
return replaceChildren(vnode, (child) => child.tag === "select", [
|
|
345
|
-
{
|
|
475
|
+
{
|
|
476
|
+
tag: "option",
|
|
477
|
+
attrs: { value: "" },
|
|
478
|
+
children: [selectPrompt(node.props as { placeholder?: string })],
|
|
479
|
+
},
|
|
346
480
|
...meta.options.map((option): VNode => ({
|
|
347
481
|
tag: "option",
|
|
348
482
|
attrs: { value: option.value },
|