@perkyzz/emvb 0.0.0-stage → 0.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/LICENSE +21 -0
- package/README.md +59 -2
- package/THIRD_PARTY_NOTICES.md +32 -0
- package/licenses/fontawesome-free.LICENSE +165 -0
- package/licenses/lucide-static.LICENSE +43 -0
- package/licenses/remixicon.LICENSE +201 -0
- package/licenses/tabler-icons.LICENSE +21 -0
- package/package.json +76 -4
- package/src/admin/access/RequireEditor.tsx +39 -0
- package/src/admin/access/role.ts +36 -0
- package/src/admin/access/sidebar-shim.ts +108 -0
- package/src/admin/api.ts +75 -0
- package/src/admin/content-api.ts +210 -0
- package/src/admin/editor/Editor.tsx +532 -0
- package/src/admin/editor/EditorOverlay.tsx +66 -0
- package/src/admin/editor/ShortcutsDialog.tsx +30 -0
- package/src/admin/editor/SmallScreenNotice.tsx +21 -0
- package/src/admin/editor/TopBar.tsx +243 -0
- package/src/admin/editor/canvas/CanvasFrame.tsx +536 -0
- package/src/admin/editor/canvas/CanvasTextEdit.tsx +87 -0
- package/src/admin/editor/canvas/DeviceBar.tsx +91 -0
- package/src/admin/editor/canvas/EmptyCanvas.tsx +49 -0
- package/src/admin/editor/canvas/SelectionOverlay.tsx +239 -0
- package/src/admin/editor/canvas/canvas-events.ts +245 -0
- package/src/admin/editor/canvas/state-preview.ts +19 -0
- package/src/admin/editor/canvas/tab-reveal.ts +101 -0
- package/src/admin/editor/canvas/vnode-react.tsx +69 -0
- package/src/admin/editor/clipboard-store.ts +44 -0
- package/src/admin/editor/dialogs.tsx +164 -0
- package/src/admin/editor/dnd/drag-stash.ts +27 -0
- package/src/admin/editor/dnd/drop-target.ts +148 -0
- package/src/admin/editor/dnd/new-element.ts +107 -0
- package/src/admin/editor/editor-css.ts +625 -0
- package/src/admin/editor/exit.ts +27 -0
- package/src/admin/editor/host.ts +30 -0
- package/src/admin/editor/icons/IconLibraryDialog.tsx +850 -0
- package/src/admin/editor/icons/library.ts +243 -0
- package/src/admin/editor/icons/set-format.ts +29 -0
- package/src/admin/editor/icons/sets/fontawesome.json +1 -0
- package/src/admin/editor/icons/sets/lucide.json +1 -0
- package/src/admin/editor/icons/sets/remix.json +1 -0
- package/src/admin/editor/icons/sets/tabler.json +1 -0
- package/src/admin/editor/panels/AddPanel.tsx +146 -0
- package/src/admin/editor/panels/ClassesSection.tsx +372 -0
- package/src/admin/editor/panels/ColorControl.tsx +477 -0
- package/src/admin/editor/panels/ConditionsEditor.tsx +201 -0
- package/src/admin/editor/panels/ElementPanel.tsx +773 -0
- package/src/admin/editor/panels/LayersPanel.tsx +573 -0
- package/src/admin/editor/panels/LeftPanel.tsx +81 -0
- package/src/admin/editor/panels/PageSettings.tsx +255 -0
- package/src/admin/editor/panels/SettingsPanel.tsx +113 -0
- package/src/admin/editor/panels/SiteStylesDrawer.tsx +548 -0
- package/src/admin/editor/panels/TriggerSettings.tsx +132 -0
- package/src/admin/editor/panels/TriggersEditor.tsx +214 -0
- package/src/admin/editor/panels/VariableSection.tsx +530 -0
- package/src/admin/editor/panels/color-space.ts +195 -0
- package/src/admin/editor/panels/settings/AdvancedFields.tsx +119 -0
- package/src/admin/editor/panels/settings/BackgroundControls.tsx +418 -0
- package/src/admin/editor/panels/settings/BackgroundFill.tsx +221 -0
- package/src/admin/editor/panels/settings/BoxControl.tsx +271 -0
- package/src/admin/editor/panels/settings/ChoiceGroup.tsx +138 -0
- package/src/admin/editor/panels/settings/ClassChip.tsx +167 -0
- package/src/admin/editor/panels/settings/ClassChipInput.tsx +451 -0
- package/src/admin/editor/panels/settings/DraftTextField.tsx +242 -0
- package/src/admin/editor/panels/settings/EffectsControls.tsx +354 -0
- package/src/admin/editor/panels/settings/FieldBindControl.tsx +119 -0
- package/src/admin/editor/panels/settings/FieldControl.tsx +270 -0
- package/src/admin/editor/panels/settings/FormBindControl.tsx +106 -0
- package/src/admin/editor/panels/settings/IconControls.tsx +438 -0
- package/src/admin/editor/panels/settings/IconPicker.tsx +170 -0
- package/src/admin/editor/panels/settings/ItemList.tsx +199 -0
- package/src/admin/editor/panels/settings/LengthRow.tsx +217 -0
- package/src/admin/editor/panels/settings/LoopItemBindControl.tsx +130 -0
- package/src/admin/editor/panels/settings/MediaPicker.tsx +220 -0
- package/src/admin/editor/panels/settings/NumberRow.tsx +154 -0
- package/src/admin/editor/panels/settings/StateSwitcher.tsx +87 -0
- package/src/admin/editor/panels/settings/StyleRow.tsx +563 -0
- package/src/admin/editor/panels/settings/VariableBinding.tsx +171 -0
- package/src/admin/editor/panels/settings/advanced-rules.ts +63 -0
- package/src/admin/editor/panels/settings/background-mode.ts +112 -0
- package/src/admin/editor/panels/settings/box-link-name.ts +38 -0
- package/src/admin/editor/panels/settings/box-sides.ts +153 -0
- package/src/admin/editor/panels/settings/button-url.ts +27 -0
- package/src/admin/editor/panels/settings/class-suggest.ts +53 -0
- package/src/admin/editor/panels/settings/form-names.ts +38 -0
- package/src/admin/editor/panels/settings/heading-warning.ts +25 -0
- package/src/admin/editor/panels/settings/image-alt.ts +25 -0
- package/src/admin/editor/panels/settings/length-units.ts +116 -0
- package/src/admin/editor/panels/settings/loop-context.ts +26 -0
- package/src/admin/editor/panels/settings/node-props.ts +11 -0
- package/src/admin/editor/panels/settings/style-sections.ts +394 -0
- package/src/admin/editor/panels/settings/svg-images.ts +14 -0
- package/src/admin/editor/panels/site-list.tsx +209 -0
- package/src/admin/editor/panels/variable-values.ts +73 -0
- package/src/admin/editor/restore-deleted.ts +80 -0
- package/src/admin/editor/section-templates.ts +50 -0
- package/src/admin/editor/shortcuts.ts +20 -0
- package/src/admin/editor/store.ts +240 -0
- package/src/admin/editor/useClipboardActions.ts +136 -0
- package/src/admin/editor/useEditorCommands.ts +203 -0
- package/src/admin/editor/useEditorData.ts +193 -0
- package/src/admin/editor/useEditorShortcuts.ts +180 -0
- package/src/admin/editor/useMediaQuery.ts +20 -0
- package/src/admin/editor/useNodeActions.ts +184 -0
- package/src/admin/editor/useSave.ts +242 -0
- package/src/admin/entry-status.ts +19 -0
- package/src/admin/forms-api.ts +73 -0
- package/src/admin/icon-uploads-api.ts +44 -0
- package/src/admin/index.tsx +20 -0
- package/src/admin/media-api.ts +68 -0
- package/src/admin/pages/CreateDialog.tsx +150 -0
- package/src/admin/pages/EditorPage.tsx +57 -0
- package/src/admin/pages/NewPageDialog.tsx +83 -0
- package/src/admin/pages/NewThemePartDialog.tsx +61 -0
- package/src/admin/pages/PageList.tsx +91 -0
- package/src/admin/pages/PagesPage.tsx +25 -0
- package/src/admin/pages/SetupShell.tsx +90 -0
- package/src/admin/pages/ThemeBuilderPage.tsx +25 -0
- package/src/admin/pages/ThemePartList.tsx +221 -0
- package/src/admin/pages/list-kit.tsx +125 -0
- package/src/admin/setup/plan.ts +150 -0
- package/src/admin/setup/run.ts +61 -0
- package/src/admin/setup/spec.ts +107 -0
- package/src/admin/setup/useSetupStatus.ts +62 -0
- package/src/admin/theme-api.ts +233 -0
- package/src/admin/ui.ts +244 -0
- package/src/admin/widgets/LayoutField.tsx +67 -0
- package/src/astro/EmVBPage.astro +63 -0
- package/src/astro/env.d.ts +5 -0
- package/src/astro/floats/EmVBFloatsRuntime.astro +9 -0
- package/src/astro/floats/index.ts +1 -0
- package/src/astro/floats/runtime.ts +78 -0
- package/src/astro/forms/EmVBFormsRuntime.astro +9 -0
- package/src/astro/forms/index.ts +1 -0
- package/src/astro/forms-definitions.ts +126 -0
- package/src/astro/index.ts +16 -0
- package/src/astro/menu/EmVBMenuRuntime.astro +9 -0
- package/src/astro/menu/index.ts +1 -0
- package/src/astro/menu/runtime.ts +37 -0
- package/src/astro/popups/EmVBPopupsRuntime.astro +9 -0
- package/src/astro/popups/index.ts +1 -0
- package/src/astro/popups/runtime.ts +296 -0
- package/src/astro/render.ts +108 -0
- package/src/astro/resolve-theme.ts +515 -0
- package/src/astro/resolve.ts +65 -0
- package/src/astro/tabs/EmVBTabsRuntime.astro +10 -0
- package/src/astro/tabs/index.ts +1 -0
- package/src/astro/tabs/runtime.ts +116 -0
- package/src/astro/theme-context.ts +89 -0
- package/src/astro/theme-posts.ts +84 -0
- package/src/constants.ts +12 -0
- package/src/core/arrange.ts +448 -0
- package/src/core/clipboard.ts +504 -0
- package/src/core/css/generate.ts +236 -0
- package/src/core/css/scope.ts +88 -0
- package/src/core/design/cascade.ts +28 -0
- package/src/core/design/classes.ts +224 -0
- package/src/core/design/devices.ts +56 -0
- package/src/core/design/states.ts +49 -0
- package/src/core/design/transfer.ts +132 -0
- package/src/core/design/variables.ts +359 -0
- package/src/core/elements/definition.ts +12 -0
- package/src/core/elements/dynamic-elements.ts +225 -0
- package/src/core/elements/field-id.ts +6 -0
- package/src/core/elements/form-elements.ts +219 -0
- package/src/core/elements/index.ts +960 -0
- package/src/core/elements/menu.ts +190 -0
- package/src/core/elements/plain-text.ts +32 -0
- package/src/core/forms/binding.ts +61 -0
- package/src/core/forms/definition.ts +45 -0
- package/src/core/forms/success-layout.ts +63 -0
- package/src/core/icons/catalog.ts +273 -0
- package/src/core/index.ts +380 -0
- package/src/core/limits.ts +9 -0
- package/src/core/migrate/index.ts +126 -0
- package/src/core/nesting.ts +51 -0
- package/src/core/render/context.ts +21 -0
- package/src/core/render/dynamic-post.ts +175 -0
- package/src/core/render/extras.ts +98 -0
- package/src/core/render/form.ts +235 -0
- package/src/core/render/index.ts +372 -0
- package/src/core/render/loop.ts +43 -0
- package/src/core/render/pagination.ts +76 -0
- package/src/core/render/section.ts +37 -0
- package/src/core/render/tabs.ts +76 -0
- package/src/core/render/vnode.ts +87 -0
- package/src/core/sanitize/css.ts +771 -0
- package/src/core/sanitize/embed-url.ts +160 -0
- package/src/core/sanitize/escape.ts +10 -0
- package/src/core/sanitize/href.ts +6 -0
- package/src/core/sanitize/media-url.ts +7 -0
- package/src/core/sanitize/svg-upload.ts +203 -0
- package/src/core/sanitize/svg.ts +374 -0
- package/src/core/sanitize/url.ts +31 -0
- package/src/core/schema/descriptors.ts +37 -0
- package/src/core/schema/design.ts +93 -0
- package/src/core/schema/layout.ts +1008 -0
- package/src/core/schema/state-names.ts +4 -0
- package/src/core/schema/style.ts +336 -0
- package/src/core/stats.ts +18 -0
- package/src/core/tabs/presence.ts +25 -0
- package/src/core/theme/conditions.ts +324 -0
- package/src/core/theme/dynamic.ts +143 -0
- package/src/core/theme/float.ts +113 -0
- package/src/core/theme/pagination.ts +97 -0
- package/src/core/theme/parse-doc.ts +36 -0
- package/src/core/theme/part-types.ts +81 -0
- package/src/core/theme/popup-markup.ts +41 -0
- package/src/core/theme/popup-rules.ts +62 -0
- package/src/core/theme/triggers.ts +104 -0
- package/src/core/tree-ops.ts +139 -0
- package/src/core/validate.ts +185 -0
- package/src/index.ts +18 -0
- package/src/server/design-routes.ts +125 -0
- package/src/server/hooks.ts +118 -0
- package/src/server/icon-routes.ts +79 -0
- package/src/server/plugin.ts +43 -0
|
@@ -0,0 +1,1008 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { MAX_TEXT_LENGTH } from "../limits.ts";
|
|
3
|
+
import { DeviceStyles, HiddenOn, Length, StyleProps, StyleStates } from "./style.ts";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 12 since W-160: gradient type, stop locations, and up to 10 stops. v11 gradients
|
|
7
|
+
* (`{ angle, from, to }`) become a linear gradient on read.
|
|
8
|
+
* 11 since W-156 and W-157 (D-045): the layout Section element and an editor-only node label.
|
|
9
|
+
*/
|
|
10
|
+
export const LAYOUT_SCHEMA_VERSION = 12;
|
|
11
|
+
|
|
12
|
+
export const NodeId = z
|
|
13
|
+
.string()
|
|
14
|
+
.regex(/^[A-Za-z0-9_-]{4,24}$/, "Ids are 4-24 letters, digits, _ or -");
|
|
15
|
+
const ClassIds = z.array(z.string().regex(/^[a-z0-9-]{1,40}$/)).max(20);
|
|
16
|
+
/** CSS id attribute (Advanced). Letters first; unique on the page (checked in validateLayout). */
|
|
17
|
+
const HtmlId = z
|
|
18
|
+
.string()
|
|
19
|
+
.regex(
|
|
20
|
+
/^[A-Za-z][A-Za-z0-9_-]{0,63}$/,
|
|
21
|
+
"CSS ids start with a letter and are at most 64 characters",
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
export const CONTAINER_TAGS = [
|
|
25
|
+
"div",
|
|
26
|
+
"section",
|
|
27
|
+
"header",
|
|
28
|
+
"footer",
|
|
29
|
+
"main",
|
|
30
|
+
"article",
|
|
31
|
+
"aside",
|
|
32
|
+
"nav",
|
|
33
|
+
] as const;
|
|
34
|
+
export const TEXT_TAGS = ["p", "div"] as const;
|
|
35
|
+
|
|
36
|
+
/** The editor-only name of a node in Layers (W-157, D-045). Never rendered on the page. */
|
|
37
|
+
const NodeLabel = z.string().trim().min(1).max(80);
|
|
38
|
+
|
|
39
|
+
/** `data-*` and `aria-*` only. Names stay unique on the element (W-105 / R-032). */
|
|
40
|
+
const HtmlAttribute = z.strictObject({
|
|
41
|
+
name: z
|
|
42
|
+
.string()
|
|
43
|
+
.regex(
|
|
44
|
+
/^(?:data|aria)-[a-z][a-z0-9-]{0,40}$/,
|
|
45
|
+
"Use a data-* or aria-* name, starting with a letter",
|
|
46
|
+
),
|
|
47
|
+
value: z.string().max(200),
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
const HtmlAttributes = z.array(HtmlAttribute).max(20);
|
|
51
|
+
|
|
52
|
+
/** A box may be the link. A link inside a link is dropped at render time (W-111). */
|
|
53
|
+
const BoxLink = {
|
|
54
|
+
href: z.string().max(2000).optional(),
|
|
55
|
+
newTab: z.boolean().optional(),
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
/** The fields every element has; `props` is the element's own strict props schema. */
|
|
59
|
+
const nodeFields = <T extends string, P extends z.ZodType>(type: T, props: P) => ({
|
|
60
|
+
id: NodeId,
|
|
61
|
+
type: z.literal(type),
|
|
62
|
+
props,
|
|
63
|
+
style: StyleProps.optional(),
|
|
64
|
+
states: StyleStates.optional(),
|
|
65
|
+
devices: DeviceStyles.optional(),
|
|
66
|
+
hiddenOn: HiddenOn.optional(),
|
|
67
|
+
classes: ClassIds.optional(),
|
|
68
|
+
htmlId: HtmlId.optional(),
|
|
69
|
+
attributes: HtmlAttributes.optional(),
|
|
70
|
+
label: NodeLabel.optional(),
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
const leafNode = <T extends string, P extends z.ZodType>(type: T, props: P) =>
|
|
74
|
+
z.strictObject(nodeFields(type, props));
|
|
75
|
+
|
|
76
|
+
const parentNode = <T extends string, P extends z.ZodType>(type: T, props: P) =>
|
|
77
|
+
z.strictObject({
|
|
78
|
+
...nodeFields(type, props),
|
|
79
|
+
get children(): z.ZodType<LayoutNode[]> {
|
|
80
|
+
return z.array(LayoutNode);
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
export const HeadingNode = leafNode(
|
|
85
|
+
"heading",
|
|
86
|
+
z.strictObject({
|
|
87
|
+
text: z.string().max(MAX_TEXT_LENGTH),
|
|
88
|
+
level: z.number().int().min(1).max(6),
|
|
89
|
+
/** Optional link around the text (W-141), like Elementor's Heading link. */
|
|
90
|
+
href: z.string().max(2000).optional(),
|
|
91
|
+
newTab: z.boolean().optional(),
|
|
92
|
+
}),
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
export const SpacerNode = leafNode(
|
|
96
|
+
"spacer",
|
|
97
|
+
z.strictObject({
|
|
98
|
+
height: Length,
|
|
99
|
+
}),
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
export const DividerNode = leafNode("divider", z.strictObject({}));
|
|
103
|
+
|
|
104
|
+
export const TextNode = leafNode(
|
|
105
|
+
"text",
|
|
106
|
+
z.strictObject({
|
|
107
|
+
text: z.string().max(MAX_TEXT_LENGTH),
|
|
108
|
+
tag: z.enum(TEXT_TAGS).optional(),
|
|
109
|
+
}),
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
export const LabelNode = leafNode(
|
|
113
|
+
"label",
|
|
114
|
+
z.strictObject({
|
|
115
|
+
text: z.string().max(MAX_TEXT_LENGTH),
|
|
116
|
+
}),
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
export const LinkNode = leafNode(
|
|
120
|
+
"link",
|
|
121
|
+
z.strictObject({
|
|
122
|
+
text: z.string().max(MAX_TEXT_LENGTH),
|
|
123
|
+
href: z.string().max(2000),
|
|
124
|
+
newTab: z.boolean().optional(),
|
|
125
|
+
}),
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
export const ButtonNode = leafNode(
|
|
129
|
+
"button",
|
|
130
|
+
z.strictObject({
|
|
131
|
+
text: z.string().max(MAX_TEXT_LENGTH),
|
|
132
|
+
href: z.string().max(2000).optional(),
|
|
133
|
+
newTab: z.boolean().optional(),
|
|
134
|
+
}),
|
|
135
|
+
);
|
|
136
|
+
|
|
137
|
+
export const ListNode = leafNode(
|
|
138
|
+
"list",
|
|
139
|
+
z.strictObject({
|
|
140
|
+
ordered: z.boolean().optional(),
|
|
141
|
+
items: z.array(z.string().max(MAX_TEXT_LENGTH)).max(200),
|
|
142
|
+
}),
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
/** YouTube/Vimeo privacy embed or media-library video (W-026 / R-013). */
|
|
146
|
+
export const VideoNode = leafNode(
|
|
147
|
+
"video",
|
|
148
|
+
z.strictObject({
|
|
149
|
+
url: z.string().max(2000),
|
|
150
|
+
title: z.string().min(1).max(200),
|
|
151
|
+
mediaId: z.string().min(1).max(128).optional(),
|
|
152
|
+
}),
|
|
153
|
+
);
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* An icon (W-025 / A-04). `iconId` names it: a bundled Lucide id ("star") or, from the Icon library
|
|
157
|
+
* (W-234), `<set prefix>:<name>` ("fa-solid:rocket"), so the picker can reopen on it. `iconSvg` is
|
|
158
|
+
* that icon's SVG, stored with the page so public pages load no icon library; it's sanitized on
|
|
159
|
+
* every render. Unknown ids without SVG stay on save; the renderer shows a placeholder.
|
|
160
|
+
* W-239: an uploaded SVG is `upload:<id>` (EmVB's icon uploads); the cap rose from 16 KB to
|
|
161
|
+
* 32 KB for uploaded logos and illustrations: the SVG sanitizer's own limit (and the SVG
|
|
162
|
+
* element's), so a stored icon always renders.
|
|
163
|
+
*/
|
|
164
|
+
export const ICON_SVG_MAX = 32_768;
|
|
165
|
+
export const IconNode = leafNode(
|
|
166
|
+
"icon",
|
|
167
|
+
z.strictObject({
|
|
168
|
+
iconId: z.string().min(1).max(64),
|
|
169
|
+
iconSvg: z.string().max(ICON_SVG_MAX).optional(),
|
|
170
|
+
/** W-238: paint a multi-colour SVG in the icon's colour (fills and strokes → currentColor). */
|
|
171
|
+
singleColor: z.boolean().optional(),
|
|
172
|
+
size: z.number().int().positive().max(512).optional(),
|
|
173
|
+
decorative: z.boolean().optional(),
|
|
174
|
+
title: z.string().max(200).optional(),
|
|
175
|
+
/** Optional link around the icon (W-141); the title names the link. */
|
|
176
|
+
href: z.string().max(2000).optional(),
|
|
177
|
+
newTab: z.boolean().optional(),
|
|
178
|
+
}),
|
|
179
|
+
)
|
|
180
|
+
.refine((node) => node.props.decorative === true || (node.props.title?.length ?? 0) > 0, {
|
|
181
|
+
message: "Title is required unless the icon is marked decorative.",
|
|
182
|
+
path: ["props", "title"],
|
|
183
|
+
})
|
|
184
|
+
.refine((node) => !node.props.href?.trim() || (node.props.title?.trim().length ?? 0) > 0, {
|
|
185
|
+
message: "A linked icon needs a title: it names the link.",
|
|
186
|
+
path: ["props", "title"],
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
/** Image from the media library or a URL (W-024 / R-007). Alt required unless decorative. */
|
|
190
|
+
export const ImageNode = leafNode(
|
|
191
|
+
"image",
|
|
192
|
+
z.strictObject({
|
|
193
|
+
src: z.string().max(2000),
|
|
194
|
+
alt: z.string().max(500),
|
|
195
|
+
decorative: z.boolean().optional(),
|
|
196
|
+
width: z.number().int().positive().max(10000).optional(),
|
|
197
|
+
height: z.number().int().positive().max(10000).optional(),
|
|
198
|
+
mediaId: z.string().min(1).max(128).optional(),
|
|
199
|
+
/** Load right away (eager, high fetch priority) for the hero/LCP image (W-226). */
|
|
200
|
+
priority: z.boolean().optional(),
|
|
201
|
+
}),
|
|
202
|
+
).refine((node) => node.props.decorative === true || node.props.alt.length > 0, {
|
|
203
|
+
message: "Alt text is required unless the image is marked decorative.",
|
|
204
|
+
path: ["props", "alt"],
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
export const ContainerNode = parentNode(
|
|
208
|
+
"container",
|
|
209
|
+
z.strictObject({
|
|
210
|
+
tag: z.enum(CONTAINER_TAGS).optional(),
|
|
211
|
+
...BoxLink,
|
|
212
|
+
}),
|
|
213
|
+
);
|
|
214
|
+
|
|
215
|
+
/** Field name on a forms-plugin form (D-015). */
|
|
216
|
+
/** Form field names (W-202 checks them as you type with the same rule). */
|
|
217
|
+
export const FIELD_NAME_PATTERN = /^[a-zA-Z][a-zA-Z0-9_-]*$/;
|
|
218
|
+
export const MAX_FIELD_NAME = 80;
|
|
219
|
+
const FieldName = z
|
|
220
|
+
.string()
|
|
221
|
+
.min(1)
|
|
222
|
+
.max(MAX_FIELD_NAME)
|
|
223
|
+
.regex(FIELD_NAME_PATTERN, "Field names start with a letter");
|
|
224
|
+
|
|
225
|
+
export const DivBlockNode = parentNode("div-block", z.strictObject({ ...BoxLink }));
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* A layout Section (W-156, D-045): a full-width band whose contents sit in a centred inner box,
|
|
229
|
+
* `contentWidth` wide at most (1140 px when unset), or the full width with `fullWidth`.
|
|
230
|
+
*/
|
|
231
|
+
export const LayoutSectionNode = parentNode(
|
|
232
|
+
"layout-section",
|
|
233
|
+
z.strictObject({
|
|
234
|
+
tag: z.enum(CONTAINER_TAGS).optional(),
|
|
235
|
+
contentWidth: Length.optional(),
|
|
236
|
+
fullWidth: z.boolean().optional(),
|
|
237
|
+
}),
|
|
238
|
+
);
|
|
239
|
+
|
|
240
|
+
export const FlexboxNode = parentNode("flexbox", z.strictObject({ ...BoxLink }));
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Equal columns. Children span with `gridColumnSpan` and `gridRowSpan` on their style. Tablet
|
|
244
|
+
* and mobile may have their own count (W-139); unset follows the next wider device.
|
|
245
|
+
*/
|
|
246
|
+
export const GridNode = parentNode(
|
|
247
|
+
"grid",
|
|
248
|
+
z.strictObject({
|
|
249
|
+
columns: z.number().int().min(1).max(12),
|
|
250
|
+
columnsTablet: z.number().int().min(1).max(12).optional(),
|
|
251
|
+
columnsMobile: z.number().int().min(1).max(12).optional(),
|
|
252
|
+
...BoxLink,
|
|
253
|
+
}),
|
|
254
|
+
);
|
|
255
|
+
|
|
256
|
+
/** Several disclosures. Items are `<details>`, so the public page needs no script (W-106). */
|
|
257
|
+
export const AccordionNode = parentNode("accordion", z.strictObject({}));
|
|
258
|
+
|
|
259
|
+
export const AccordionItemNode = parentNode(
|
|
260
|
+
"accordion-item",
|
|
261
|
+
z.strictObject({
|
|
262
|
+
summary: z.string().min(1).max(200),
|
|
263
|
+
open: z.boolean().optional(),
|
|
264
|
+
}),
|
|
265
|
+
);
|
|
266
|
+
|
|
267
|
+
/** A row or column of menu items. Dropdowns and wide panels are the items' children (W-162). */
|
|
268
|
+
export const MenuNode = parentNode(
|
|
269
|
+
"menu",
|
|
270
|
+
z.strictObject({
|
|
271
|
+
direction: z.enum(["row", "column"]),
|
|
272
|
+
/** Names the navigation landmark. Omitted uses "Menu". */
|
|
273
|
+
label: z.string().max(80).optional(),
|
|
274
|
+
}),
|
|
275
|
+
);
|
|
276
|
+
|
|
277
|
+
/** A link, and, when it has children, the dropdown or wide panel under it. */
|
|
278
|
+
export const MenuItemNode = parentNode(
|
|
279
|
+
"menu-item",
|
|
280
|
+
z.strictObject({
|
|
281
|
+
text: z.string().min(1).max(MAX_TEXT_LENGTH),
|
|
282
|
+
href: z.string().max(2000).optional(),
|
|
283
|
+
newTab: z.boolean().optional(),
|
|
284
|
+
/** The panel stretches across the menu instead of sitting under the item. */
|
|
285
|
+
wide: z.boolean().optional(),
|
|
286
|
+
}),
|
|
287
|
+
);
|
|
288
|
+
|
|
289
|
+
export const SvgNode = leafNode(
|
|
290
|
+
"svg",
|
|
291
|
+
z.strictObject({
|
|
292
|
+
/** Sanitized SVG markup (allowlisted tags/attrs only). */
|
|
293
|
+
markup: z.string().max(32768),
|
|
294
|
+
title: z.string().max(MAX_TEXT_LENGTH).optional(),
|
|
295
|
+
decorative: z.boolean().optional(),
|
|
296
|
+
size: z.number().int().positive().max(2048).optional(),
|
|
297
|
+
}),
|
|
298
|
+
);
|
|
299
|
+
|
|
300
|
+
export const TabPanelNode = parentNode(
|
|
301
|
+
"tab-panel",
|
|
302
|
+
z.strictObject({
|
|
303
|
+
label: z.string().min(1).max(MAX_TEXT_LENGTH),
|
|
304
|
+
}),
|
|
305
|
+
);
|
|
306
|
+
|
|
307
|
+
const TabsNodeSchema = parentNode("tabs", z.strictObject({}));
|
|
308
|
+
|
|
309
|
+
export const FORM_FIELD_TYPES = [
|
|
310
|
+
"text-input",
|
|
311
|
+
"textarea",
|
|
312
|
+
"select",
|
|
313
|
+
"checkbox",
|
|
314
|
+
"radio",
|
|
315
|
+
"submit",
|
|
316
|
+
] as const;
|
|
317
|
+
|
|
318
|
+
export const FormNode = parentNode(
|
|
319
|
+
"form",
|
|
320
|
+
z.strictObject({
|
|
321
|
+
/** Empty until the editor binds a forms-plugin form (W-036). */
|
|
322
|
+
formId: z.string().max(64),
|
|
323
|
+
}),
|
|
324
|
+
);
|
|
325
|
+
|
|
326
|
+
const InputFieldProps = z.strictObject({
|
|
327
|
+
field: FieldName,
|
|
328
|
+
label: z.string().max(200).optional(),
|
|
329
|
+
placeholder: z.string().max(200).optional(),
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
export const TextInputNode = leafNode("text-input", InputFieldProps);
|
|
333
|
+
|
|
334
|
+
export const TextareaNode = leafNode("textarea", InputFieldProps);
|
|
335
|
+
|
|
336
|
+
export const SelectNode = leafNode("select", InputFieldProps);
|
|
337
|
+
|
|
338
|
+
export const CheckboxNode = leafNode(
|
|
339
|
+
"checkbox",
|
|
340
|
+
z.strictObject({
|
|
341
|
+
field: FieldName,
|
|
342
|
+
label: z.string().max(200).optional(),
|
|
343
|
+
}),
|
|
344
|
+
);
|
|
345
|
+
|
|
346
|
+
export const RadioNode = leafNode("radio", InputFieldProps);
|
|
347
|
+
|
|
348
|
+
export const SubmitNode = leafNode(
|
|
349
|
+
"submit",
|
|
350
|
+
z.strictObject({
|
|
351
|
+
label: z.string().min(1).max(80).optional(),
|
|
352
|
+
}),
|
|
353
|
+
);
|
|
354
|
+
|
|
355
|
+
/** Dynamic post title from ThemeDynamicData (S7d). */
|
|
356
|
+
export const PostTitleNode = leafNode(
|
|
357
|
+
"post-title",
|
|
358
|
+
z.strictObject({
|
|
359
|
+
level: z.number().int().min(1).max(6).optional(),
|
|
360
|
+
}),
|
|
361
|
+
);
|
|
362
|
+
|
|
363
|
+
/** Dynamic post excerpt (escaped text). `maxWords` cuts it to that many words, with "…" (W-177). */
|
|
364
|
+
export const PostExcerptNode = leafNode(
|
|
365
|
+
"post-excerpt",
|
|
366
|
+
z.strictObject({ maxWords: z.number().int().positive().max(10_000).optional() }),
|
|
367
|
+
);
|
|
368
|
+
|
|
369
|
+
/** Dynamic post body from Portable Text / string (sanitized via VNode serialize). */
|
|
370
|
+
export const PostContentNode = leafNode("post-content", z.strictObject({}));
|
|
371
|
+
|
|
372
|
+
/** Dynamic featured image when a URL is available. */
|
|
373
|
+
export const PostImageNode = leafNode(
|
|
374
|
+
"post-image",
|
|
375
|
+
z.strictObject({
|
|
376
|
+
decorative: z.boolean().optional(),
|
|
377
|
+
}),
|
|
378
|
+
);
|
|
379
|
+
|
|
380
|
+
/** How a Post Date reads (W-177). Unset is `medium`. `numeric` is YYYY-MM-DD. */
|
|
381
|
+
export const POST_DATE_FORMATS = ["medium", "short", "long", "full", "numeric"] as const;
|
|
382
|
+
|
|
383
|
+
/** Published date from the post, shown as a `<time>` element (W-108). */
|
|
384
|
+
export const PostDateNode = leafNode(
|
|
385
|
+
"post-date",
|
|
386
|
+
z.strictObject({ format: z.enum(POST_DATE_FORMATS).optional() }),
|
|
387
|
+
);
|
|
388
|
+
|
|
389
|
+
/** Author name from the post (W-108). */
|
|
390
|
+
export const PostAuthorNode = leafNode("post-author", z.strictObject({}));
|
|
391
|
+
|
|
392
|
+
/** Permalink link; empty text uses the post title. */
|
|
393
|
+
export const PostLinkNode = leafNode(
|
|
394
|
+
"post-link",
|
|
395
|
+
z.strictObject({
|
|
396
|
+
text: z.string().max(MAX_TEXT_LENGTH).optional(),
|
|
397
|
+
newTab: z.boolean().optional(),
|
|
398
|
+
}),
|
|
399
|
+
);
|
|
400
|
+
|
|
401
|
+
/**
|
|
402
|
+
* Repeats its item template for each post in ThemeDynamicData.posts.
|
|
403
|
+
* When `itemPartId` is set, the host supplies that Loop Item layout in loopTemplates;
|
|
404
|
+
* otherwise children are the inline item template.
|
|
405
|
+
*/
|
|
406
|
+
export const LoopNode = parentNode(
|
|
407
|
+
"loop",
|
|
408
|
+
z.strictObject({
|
|
409
|
+
itemPartId: z.string().max(128).optional(),
|
|
410
|
+
/** Posts per archive page, 1–50 (W-221). Unset = 20. */
|
|
411
|
+
perPage: z.number().int().min(1).max(50).optional(),
|
|
412
|
+
}),
|
|
413
|
+
);
|
|
414
|
+
|
|
415
|
+
/**
|
|
416
|
+
* Previous / page numbers / Next links for an archive (W-222). Renders only on an archive with
|
|
417
|
+
* more than one page; the host supplies `ThemeDynamicData.pagination`.
|
|
418
|
+
*/
|
|
419
|
+
export const PaginationNode = leafNode(
|
|
420
|
+
"pagination",
|
|
421
|
+
z.strictObject({
|
|
422
|
+
prevText: z.string().max(40).optional(),
|
|
423
|
+
nextText: z.string().max(40).optional(),
|
|
424
|
+
}),
|
|
425
|
+
);
|
|
426
|
+
|
|
427
|
+
/**
|
|
428
|
+
* A reusable block. When `partId` is set, the host supplies that Section theme part in
|
|
429
|
+
* `sectionTemplates` and the part's children render in place of `children`.
|
|
430
|
+
*/
|
|
431
|
+
export const SectionNode = parentNode(
|
|
432
|
+
"section",
|
|
433
|
+
z.strictObject({
|
|
434
|
+
partId: z.string().max(128).optional(),
|
|
435
|
+
}),
|
|
436
|
+
);
|
|
437
|
+
|
|
438
|
+
/** Known element type strings (everything else is an UnknownNode). */
|
|
439
|
+
export const KNOWN_ELEMENT_TYPES = [
|
|
440
|
+
"container",
|
|
441
|
+
"heading",
|
|
442
|
+
"spacer",
|
|
443
|
+
"divider",
|
|
444
|
+
"text",
|
|
445
|
+
"label",
|
|
446
|
+
"link",
|
|
447
|
+
"button",
|
|
448
|
+
"list",
|
|
449
|
+
"image",
|
|
450
|
+
"icon",
|
|
451
|
+
"video",
|
|
452
|
+
"form",
|
|
453
|
+
"text-input",
|
|
454
|
+
"textarea",
|
|
455
|
+
"select",
|
|
456
|
+
"checkbox",
|
|
457
|
+
"radio",
|
|
458
|
+
"submit",
|
|
459
|
+
"post-title",
|
|
460
|
+
"post-excerpt",
|
|
461
|
+
"post-content",
|
|
462
|
+
"post-image",
|
|
463
|
+
"post-link",
|
|
464
|
+
"post-date",
|
|
465
|
+
"post-author",
|
|
466
|
+
"loop",
|
|
467
|
+
"pagination",
|
|
468
|
+
"section",
|
|
469
|
+
"div-block",
|
|
470
|
+
"flexbox",
|
|
471
|
+
"grid",
|
|
472
|
+
"svg",
|
|
473
|
+
"tabs",
|
|
474
|
+
"tab-panel",
|
|
475
|
+
"accordion",
|
|
476
|
+
"accordion-item",
|
|
477
|
+
"menu",
|
|
478
|
+
"menu-item",
|
|
479
|
+
"layout-section",
|
|
480
|
+
] as const;
|
|
481
|
+
|
|
482
|
+
const knownTypeSet = new Set<string>(KNOWN_ELEMENT_TYPES);
|
|
483
|
+
|
|
484
|
+
/**
|
|
485
|
+
* A node whose `type` EmVB does not implement yet (W-022 / R-033). Kept on save so a newer
|
|
486
|
+
* plugin version can reclaim it; public pages omit it; the editor shows a placeholder.
|
|
487
|
+
*/
|
|
488
|
+
const UnknownNodeSchema = z.strictObject({
|
|
489
|
+
id: NodeId,
|
|
490
|
+
type: z
|
|
491
|
+
.string()
|
|
492
|
+
.min(1)
|
|
493
|
+
.max(64)
|
|
494
|
+
.refine((value) => !knownTypeSet.has(value), "Unknown element type"),
|
|
495
|
+
props: z.record(z.string(), z.unknown()),
|
|
496
|
+
style: StyleProps.optional(),
|
|
497
|
+
states: StyleStates.optional(),
|
|
498
|
+
classes: ClassIds.optional(),
|
|
499
|
+
htmlId: HtmlId.optional(),
|
|
500
|
+
attributes: HtmlAttributes.optional(),
|
|
501
|
+
label: NodeLabel.optional(),
|
|
502
|
+
get children(): z.ZodType<LayoutNode[] | undefined> {
|
|
503
|
+
return z.array(LayoutNode).optional();
|
|
504
|
+
},
|
|
505
|
+
});
|
|
506
|
+
|
|
507
|
+
const KnownLayoutNode = z.discriminatedUnion("type", [
|
|
508
|
+
ContainerNode,
|
|
509
|
+
DivBlockNode,
|
|
510
|
+
LayoutSectionNode,
|
|
511
|
+
FlexboxNode,
|
|
512
|
+
GridNode,
|
|
513
|
+
SvgNode,
|
|
514
|
+
TabsNodeSchema,
|
|
515
|
+
TabPanelNode,
|
|
516
|
+
HeadingNode,
|
|
517
|
+
SpacerNode,
|
|
518
|
+
DividerNode,
|
|
519
|
+
TextNode,
|
|
520
|
+
LabelNode,
|
|
521
|
+
LinkNode,
|
|
522
|
+
ButtonNode,
|
|
523
|
+
ListNode,
|
|
524
|
+
ImageNode,
|
|
525
|
+
IconNode,
|
|
526
|
+
VideoNode,
|
|
527
|
+
FormNode,
|
|
528
|
+
TextInputNode,
|
|
529
|
+
TextareaNode,
|
|
530
|
+
SelectNode,
|
|
531
|
+
CheckboxNode,
|
|
532
|
+
RadioNode,
|
|
533
|
+
SubmitNode,
|
|
534
|
+
PostTitleNode,
|
|
535
|
+
PostExcerptNode,
|
|
536
|
+
PostContentNode,
|
|
537
|
+
PostImageNode,
|
|
538
|
+
PostLinkNode,
|
|
539
|
+
PostDateNode,
|
|
540
|
+
PostAuthorNode,
|
|
541
|
+
LoopNode,
|
|
542
|
+
PaginationNode,
|
|
543
|
+
SectionNode,
|
|
544
|
+
AccordionNode,
|
|
545
|
+
AccordionItemNode,
|
|
546
|
+
MenuNode,
|
|
547
|
+
MenuItemNode,
|
|
548
|
+
]);
|
|
549
|
+
|
|
550
|
+
export type HeadingNode = z.infer<typeof HeadingNode>;
|
|
551
|
+
export type SpacerNode = z.infer<typeof SpacerNode>;
|
|
552
|
+
export type DividerNode = z.infer<typeof DividerNode>;
|
|
553
|
+
export type TextNode = z.infer<typeof TextNode>;
|
|
554
|
+
export type LabelNode = z.infer<typeof LabelNode>;
|
|
555
|
+
export type LinkNode = z.infer<typeof LinkNode>;
|
|
556
|
+
export type ButtonNode = z.infer<typeof ButtonNode>;
|
|
557
|
+
export type ListNode = z.infer<typeof ListNode>;
|
|
558
|
+
export type ImageNode = z.infer<typeof ImageNode>;
|
|
559
|
+
export type IconNode = z.infer<typeof IconNode>;
|
|
560
|
+
export type VideoNode = z.infer<typeof VideoNode>;
|
|
561
|
+
export type TextInputNode = z.infer<typeof TextInputNode>;
|
|
562
|
+
export type TextareaNode = z.infer<typeof TextareaNode>;
|
|
563
|
+
export type SelectNode = z.infer<typeof SelectNode>;
|
|
564
|
+
export type CheckboxNode = z.infer<typeof CheckboxNode>;
|
|
565
|
+
export type RadioNode = z.infer<typeof RadioNode>;
|
|
566
|
+
export type SubmitNode = z.infer<typeof SubmitNode>;
|
|
567
|
+
export type PostTitleNode = z.infer<typeof PostTitleNode>;
|
|
568
|
+
export type PostExcerptNode = z.infer<typeof PostExcerptNode>;
|
|
569
|
+
export type PostContentNode = z.infer<typeof PostContentNode>;
|
|
570
|
+
export type PostImageNode = z.infer<typeof PostImageNode>;
|
|
571
|
+
export type PostLinkNode = z.infer<typeof PostLinkNode>;
|
|
572
|
+
export type PaginationNode = z.infer<typeof PaginationNode>;
|
|
573
|
+
export type PostDateNode = z.infer<typeof PostDateNode>;
|
|
574
|
+
export type PostAuthorNode = z.infer<typeof PostAuthorNode>;
|
|
575
|
+
|
|
576
|
+
type StyleOf = z.infer<typeof StyleProps>;
|
|
577
|
+
type StatesOf = z.infer<typeof StyleStates>;
|
|
578
|
+
type DevicesOf = z.infer<typeof DeviceStyles>;
|
|
579
|
+
type HiddenOnOf = z.infer<typeof HiddenOn>;
|
|
580
|
+
type ClassesOf = z.infer<typeof ClassIds>;
|
|
581
|
+
type HtmlIdOf = z.infer<typeof HtmlId>;
|
|
582
|
+
type HtmlAttributeOf = z.infer<typeof HtmlAttribute>;
|
|
583
|
+
type IdOf = z.infer<typeof NodeId>;
|
|
584
|
+
|
|
585
|
+
/** Manual recursive types so UnknownNode does not poison `z.infer` of the tree. */
|
|
586
|
+
export type UnknownNode = {
|
|
587
|
+
id: IdOf;
|
|
588
|
+
type: string;
|
|
589
|
+
props: Record<string, unknown>;
|
|
590
|
+
style?: StyleOf;
|
|
591
|
+
states?: StatesOf;
|
|
592
|
+
devices?: DevicesOf;
|
|
593
|
+
hiddenOn?: HiddenOnOf;
|
|
594
|
+
classes?: ClassesOf;
|
|
595
|
+
htmlId?: HtmlIdOf;
|
|
596
|
+
attributes?: HtmlAttributeOf[];
|
|
597
|
+
label?: string;
|
|
598
|
+
children?: LayoutNode[];
|
|
599
|
+
};
|
|
600
|
+
|
|
601
|
+
export type ContainerNode = {
|
|
602
|
+
id: IdOf;
|
|
603
|
+
type: "container";
|
|
604
|
+
props: { tag?: (typeof CONTAINER_TAGS)[number]; href?: string; newTab?: boolean };
|
|
605
|
+
style?: StyleOf;
|
|
606
|
+
states?: StatesOf;
|
|
607
|
+
devices?: DevicesOf;
|
|
608
|
+
hiddenOn?: HiddenOnOf;
|
|
609
|
+
classes?: ClassesOf;
|
|
610
|
+
htmlId?: HtmlIdOf;
|
|
611
|
+
attributes?: HtmlAttributeOf[];
|
|
612
|
+
label?: string;
|
|
613
|
+
children: LayoutNode[];
|
|
614
|
+
};
|
|
615
|
+
|
|
616
|
+
export type DivBlockNode = {
|
|
617
|
+
id: IdOf;
|
|
618
|
+
type: "div-block";
|
|
619
|
+
props: { href?: string; newTab?: boolean };
|
|
620
|
+
style?: StyleOf;
|
|
621
|
+
states?: StatesOf;
|
|
622
|
+
devices?: DevicesOf;
|
|
623
|
+
hiddenOn?: HiddenOnOf;
|
|
624
|
+
classes?: ClassesOf;
|
|
625
|
+
htmlId?: HtmlIdOf;
|
|
626
|
+
attributes?: HtmlAttributeOf[];
|
|
627
|
+
label?: string;
|
|
628
|
+
children: LayoutNode[];
|
|
629
|
+
};
|
|
630
|
+
|
|
631
|
+
export type LayoutSectionNode = {
|
|
632
|
+
id: IdOf;
|
|
633
|
+
type: "layout-section";
|
|
634
|
+
props: {
|
|
635
|
+
tag?: (typeof CONTAINER_TAGS)[number];
|
|
636
|
+
contentWidth?: z.infer<typeof Length>;
|
|
637
|
+
fullWidth?: boolean;
|
|
638
|
+
};
|
|
639
|
+
style?: StyleOf;
|
|
640
|
+
states?: StatesOf;
|
|
641
|
+
devices?: DevicesOf;
|
|
642
|
+
hiddenOn?: HiddenOnOf;
|
|
643
|
+
classes?: ClassesOf;
|
|
644
|
+
htmlId?: HtmlIdOf;
|
|
645
|
+
attributes?: HtmlAttributeOf[];
|
|
646
|
+
label?: string;
|
|
647
|
+
children: LayoutNode[];
|
|
648
|
+
};
|
|
649
|
+
|
|
650
|
+
export type GridNode = {
|
|
651
|
+
id: IdOf;
|
|
652
|
+
type: "grid";
|
|
653
|
+
props: {
|
|
654
|
+
columns: number;
|
|
655
|
+
columnsTablet?: number;
|
|
656
|
+
columnsMobile?: number;
|
|
657
|
+
href?: string;
|
|
658
|
+
newTab?: boolean;
|
|
659
|
+
};
|
|
660
|
+
style?: StyleOf;
|
|
661
|
+
states?: StatesOf;
|
|
662
|
+
devices?: DevicesOf;
|
|
663
|
+
hiddenOn?: HiddenOnOf;
|
|
664
|
+
classes?: ClassesOf;
|
|
665
|
+
htmlId?: HtmlIdOf;
|
|
666
|
+
attributes?: HtmlAttributeOf[];
|
|
667
|
+
label?: string;
|
|
668
|
+
children: LayoutNode[];
|
|
669
|
+
};
|
|
670
|
+
|
|
671
|
+
export type FlexboxNode = {
|
|
672
|
+
id: IdOf;
|
|
673
|
+
type: "flexbox";
|
|
674
|
+
props: { href?: string; newTab?: boolean };
|
|
675
|
+
style?: StyleOf;
|
|
676
|
+
states?: StatesOf;
|
|
677
|
+
devices?: DevicesOf;
|
|
678
|
+
hiddenOn?: HiddenOnOf;
|
|
679
|
+
classes?: ClassesOf;
|
|
680
|
+
htmlId?: HtmlIdOf;
|
|
681
|
+
attributes?: HtmlAttributeOf[];
|
|
682
|
+
label?: string;
|
|
683
|
+
children: LayoutNode[];
|
|
684
|
+
};
|
|
685
|
+
|
|
686
|
+
export type SvgNode = {
|
|
687
|
+
id: IdOf;
|
|
688
|
+
type: "svg";
|
|
689
|
+
props: {
|
|
690
|
+
markup: string;
|
|
691
|
+
title?: string;
|
|
692
|
+
decorative?: boolean;
|
|
693
|
+
size?: number;
|
|
694
|
+
};
|
|
695
|
+
style?: StyleOf;
|
|
696
|
+
states?: StatesOf;
|
|
697
|
+
devices?: DevicesOf;
|
|
698
|
+
hiddenOn?: HiddenOnOf;
|
|
699
|
+
classes?: ClassesOf;
|
|
700
|
+
htmlId?: HtmlIdOf;
|
|
701
|
+
attributes?: HtmlAttributeOf[];
|
|
702
|
+
label?: string;
|
|
703
|
+
};
|
|
704
|
+
|
|
705
|
+
export type TabPanelNode = {
|
|
706
|
+
id: IdOf;
|
|
707
|
+
type: "tab-panel";
|
|
708
|
+
props: { label: string };
|
|
709
|
+
style?: StyleOf;
|
|
710
|
+
states?: StatesOf;
|
|
711
|
+
devices?: DevicesOf;
|
|
712
|
+
hiddenOn?: HiddenOnOf;
|
|
713
|
+
classes?: ClassesOf;
|
|
714
|
+
htmlId?: HtmlIdOf;
|
|
715
|
+
attributes?: HtmlAttributeOf[];
|
|
716
|
+
label?: string;
|
|
717
|
+
children: LayoutNode[];
|
|
718
|
+
};
|
|
719
|
+
|
|
720
|
+
export type TabsNode = {
|
|
721
|
+
id: IdOf;
|
|
722
|
+
type: "tabs";
|
|
723
|
+
props: { href?: string; newTab?: boolean };
|
|
724
|
+
style?: StyleOf;
|
|
725
|
+
states?: StatesOf;
|
|
726
|
+
devices?: DevicesOf;
|
|
727
|
+
hiddenOn?: HiddenOnOf;
|
|
728
|
+
classes?: ClassesOf;
|
|
729
|
+
htmlId?: HtmlIdOf;
|
|
730
|
+
attributes?: HtmlAttributeOf[];
|
|
731
|
+
label?: string;
|
|
732
|
+
children: LayoutNode[];
|
|
733
|
+
};
|
|
734
|
+
|
|
735
|
+
export type FormNode = {
|
|
736
|
+
id: IdOf;
|
|
737
|
+
type: "form";
|
|
738
|
+
props: { formId: string };
|
|
739
|
+
style?: StyleOf;
|
|
740
|
+
states?: StatesOf;
|
|
741
|
+
devices?: DevicesOf;
|
|
742
|
+
hiddenOn?: HiddenOnOf;
|
|
743
|
+
classes?: ClassesOf;
|
|
744
|
+
htmlId?: HtmlIdOf;
|
|
745
|
+
attributes?: HtmlAttributeOf[];
|
|
746
|
+
label?: string;
|
|
747
|
+
children: LayoutNode[];
|
|
748
|
+
};
|
|
749
|
+
|
|
750
|
+
export type LoopNode = {
|
|
751
|
+
id: IdOf;
|
|
752
|
+
type: "loop";
|
|
753
|
+
props: { itemPartId?: string; perPage?: number };
|
|
754
|
+
style?: StyleOf;
|
|
755
|
+
states?: StatesOf;
|
|
756
|
+
devices?: DevicesOf;
|
|
757
|
+
hiddenOn?: HiddenOnOf;
|
|
758
|
+
classes?: ClassesOf;
|
|
759
|
+
htmlId?: HtmlIdOf;
|
|
760
|
+
attributes?: HtmlAttributeOf[];
|
|
761
|
+
label?: string;
|
|
762
|
+
children: LayoutNode[];
|
|
763
|
+
};
|
|
764
|
+
|
|
765
|
+
export type SectionNode = {
|
|
766
|
+
id: IdOf;
|
|
767
|
+
type: "section";
|
|
768
|
+
props: { partId?: string };
|
|
769
|
+
style?: StyleOf;
|
|
770
|
+
states?: StatesOf;
|
|
771
|
+
devices?: DevicesOf;
|
|
772
|
+
hiddenOn?: HiddenOnOf;
|
|
773
|
+
classes?: ClassesOf;
|
|
774
|
+
htmlId?: HtmlIdOf;
|
|
775
|
+
attributes?: HtmlAttributeOf[];
|
|
776
|
+
label?: string;
|
|
777
|
+
children: LayoutNode[];
|
|
778
|
+
};
|
|
779
|
+
|
|
780
|
+
export type AccordionNode = {
|
|
781
|
+
id: IdOf;
|
|
782
|
+
type: "accordion";
|
|
783
|
+
props: Record<string, never>;
|
|
784
|
+
style?: StyleOf;
|
|
785
|
+
states?: StatesOf;
|
|
786
|
+
devices?: DevicesOf;
|
|
787
|
+
hiddenOn?: HiddenOnOf;
|
|
788
|
+
classes?: ClassesOf;
|
|
789
|
+
htmlId?: HtmlIdOf;
|
|
790
|
+
attributes?: HtmlAttributeOf[];
|
|
791
|
+
label?: string;
|
|
792
|
+
children: LayoutNode[];
|
|
793
|
+
};
|
|
794
|
+
|
|
795
|
+
export type MenuNode = {
|
|
796
|
+
id: IdOf;
|
|
797
|
+
type: "menu";
|
|
798
|
+
props: { direction: "row" | "column"; label?: string };
|
|
799
|
+
style?: StyleOf;
|
|
800
|
+
states?: StatesOf;
|
|
801
|
+
devices?: DevicesOf;
|
|
802
|
+
hiddenOn?: HiddenOnOf;
|
|
803
|
+
classes?: ClassesOf;
|
|
804
|
+
htmlId?: HtmlIdOf;
|
|
805
|
+
attributes?: HtmlAttributeOf[];
|
|
806
|
+
label?: string;
|
|
807
|
+
children: LayoutNode[];
|
|
808
|
+
};
|
|
809
|
+
|
|
810
|
+
export type MenuItemNode = {
|
|
811
|
+
id: IdOf;
|
|
812
|
+
type: "menu-item";
|
|
813
|
+
props: { text: string; href?: string; newTab?: boolean; wide?: boolean };
|
|
814
|
+
style?: StyleOf;
|
|
815
|
+
states?: StatesOf;
|
|
816
|
+
devices?: DevicesOf;
|
|
817
|
+
hiddenOn?: HiddenOnOf;
|
|
818
|
+
classes?: ClassesOf;
|
|
819
|
+
htmlId?: HtmlIdOf;
|
|
820
|
+
attributes?: HtmlAttributeOf[];
|
|
821
|
+
label?: string;
|
|
822
|
+
children: LayoutNode[];
|
|
823
|
+
};
|
|
824
|
+
|
|
825
|
+
export type AccordionItemNode = {
|
|
826
|
+
id: IdOf;
|
|
827
|
+
type: "accordion-item";
|
|
828
|
+
props: { summary: string; open?: boolean };
|
|
829
|
+
style?: StyleOf;
|
|
830
|
+
states?: StatesOf;
|
|
831
|
+
devices?: DevicesOf;
|
|
832
|
+
hiddenOn?: HiddenOnOf;
|
|
833
|
+
classes?: ClassesOf;
|
|
834
|
+
htmlId?: HtmlIdOf;
|
|
835
|
+
attributes?: HtmlAttributeOf[];
|
|
836
|
+
label?: string;
|
|
837
|
+
children: LayoutNode[];
|
|
838
|
+
};
|
|
839
|
+
|
|
840
|
+
export type LayoutNode =
|
|
841
|
+
| ContainerNode
|
|
842
|
+
| DivBlockNode
|
|
843
|
+
| LayoutSectionNode
|
|
844
|
+
| FlexboxNode
|
|
845
|
+
| GridNode
|
|
846
|
+
| SvgNode
|
|
847
|
+
| TabsNode
|
|
848
|
+
| TabPanelNode
|
|
849
|
+
| FormNode
|
|
850
|
+
| LoopNode
|
|
851
|
+
| SectionNode
|
|
852
|
+
| HeadingNode
|
|
853
|
+
| SpacerNode
|
|
854
|
+
| DividerNode
|
|
855
|
+
| TextNode
|
|
856
|
+
| LabelNode
|
|
857
|
+
| LinkNode
|
|
858
|
+
| ButtonNode
|
|
859
|
+
| ListNode
|
|
860
|
+
| ImageNode
|
|
861
|
+
| IconNode
|
|
862
|
+
| VideoNode
|
|
863
|
+
| TextInputNode
|
|
864
|
+
| TextareaNode
|
|
865
|
+
| SelectNode
|
|
866
|
+
| CheckboxNode
|
|
867
|
+
| RadioNode
|
|
868
|
+
| SubmitNode
|
|
869
|
+
| PostTitleNode
|
|
870
|
+
| PostExcerptNode
|
|
871
|
+
| PostContentNode
|
|
872
|
+
| PostImageNode
|
|
873
|
+
| PostLinkNode
|
|
874
|
+
| PostDateNode
|
|
875
|
+
| PostAuthorNode
|
|
876
|
+
| PaginationNode
|
|
877
|
+
| AccordionNode
|
|
878
|
+
| AccordionItemNode
|
|
879
|
+
| MenuNode
|
|
880
|
+
| MenuItemNode
|
|
881
|
+
| UnknownNode;
|
|
882
|
+
|
|
883
|
+
/**
|
|
884
|
+
* Prefer the known-type schema when `type` is registered so path-specific Zod issues stay
|
|
885
|
+
* intact; only fall through to UnknownNode for types EmVB does not implement (W-022 / R-033).
|
|
886
|
+
* A plain `z.union` would collapse every known-type failure into `invalid_union`.
|
|
887
|
+
*/
|
|
888
|
+
const LayoutNode: z.ZodType<LayoutNode> = z.lazy(() =>
|
|
889
|
+
z.unknown().transform((input, ctx) => {
|
|
890
|
+
if (!input || typeof input !== "object" || Array.isArray(input)) {
|
|
891
|
+
ctx.addIssue({ code: "invalid_type", expected: "object", path: [] });
|
|
892
|
+
return z.NEVER;
|
|
893
|
+
}
|
|
894
|
+
const type = (input as { type?: unknown }).type;
|
|
895
|
+
if (typeof type !== "string") {
|
|
896
|
+
// `input` is the type itself; without it Zod describes the whole node ("received object").
|
|
897
|
+
ctx.addIssue({ code: "invalid_type", expected: "string", input: type, path: ["type"] });
|
|
898
|
+
return z.NEVER;
|
|
899
|
+
}
|
|
900
|
+
const result = knownTypeSet.has(type)
|
|
901
|
+
? KnownLayoutNode.safeParse(input)
|
|
902
|
+
: UnknownNodeSchema.safeParse(input);
|
|
903
|
+
if (!result.success) {
|
|
904
|
+
for (const issue of result.error.issues) {
|
|
905
|
+
ctx.addIssue({
|
|
906
|
+
code: "custom",
|
|
907
|
+
path: issue.path,
|
|
908
|
+
message: issue.message,
|
|
909
|
+
params: { zodCode: issue.code },
|
|
910
|
+
});
|
|
911
|
+
}
|
|
912
|
+
return z.NEVER;
|
|
913
|
+
}
|
|
914
|
+
return result.data as LayoutNode;
|
|
915
|
+
}),
|
|
916
|
+
);
|
|
917
|
+
|
|
918
|
+
export const Layout = z.strictObject({
|
|
919
|
+
schemaVersion: z.literal(LAYOUT_SCHEMA_VERSION),
|
|
920
|
+
root: ContainerNode,
|
|
921
|
+
});
|
|
922
|
+
|
|
923
|
+
export type Layout = {
|
|
924
|
+
schemaVersion: typeof LAYOUT_SCHEMA_VERSION;
|
|
925
|
+
root: ContainerNode;
|
|
926
|
+
};
|
|
927
|
+
|
|
928
|
+
export const isContainerNode = (node: LayoutNode): node is ContainerNode =>
|
|
929
|
+
node.type === "container";
|
|
930
|
+
|
|
931
|
+
export const isFormNode = (node: LayoutNode): node is FormNode => node.type === "form";
|
|
932
|
+
|
|
933
|
+
export const isLoopNode = (node: LayoutNode): node is LoopNode => node.type === "loop";
|
|
934
|
+
|
|
935
|
+
export const isSectionNode = (node: LayoutNode): node is SectionNode => node.type === "section";
|
|
936
|
+
|
|
937
|
+
export const isDivBlockNode = (node: LayoutNode): node is DivBlockNode => node.type === "div-block";
|
|
938
|
+
|
|
939
|
+
export const isFlexboxNode = (node: LayoutNode): node is FlexboxNode => node.type === "flexbox";
|
|
940
|
+
|
|
941
|
+
/** Layout parents that accept general children (not form-only / tabs-only). */
|
|
942
|
+
export const isTabsNode = (node: LayoutNode): node is TabsNode => node.type === "tabs";
|
|
943
|
+
|
|
944
|
+
export const isTabPanelNode = (node: LayoutNode): node is TabPanelNode => node.type === "tab-panel";
|
|
945
|
+
|
|
946
|
+
/** Layout parents that accept general children (forms may land here). */
|
|
947
|
+
export const isLayoutParentNode = (
|
|
948
|
+
node: LayoutNode,
|
|
949
|
+
): node is
|
|
950
|
+
| ContainerNode
|
|
951
|
+
| DivBlockNode
|
|
952
|
+
| LayoutSectionNode
|
|
953
|
+
| FlexboxNode
|
|
954
|
+
| GridNode
|
|
955
|
+
| TabPanelNode
|
|
956
|
+
| SectionNode
|
|
957
|
+
| AccordionItemNode
|
|
958
|
+
| MenuItemNode =>
|
|
959
|
+
node.type === "container" ||
|
|
960
|
+
node.type === "div-block" ||
|
|
961
|
+
node.type === "layout-section" ||
|
|
962
|
+
node.type === "flexbox" ||
|
|
963
|
+
node.type === "grid" ||
|
|
964
|
+
node.type === "tab-panel" ||
|
|
965
|
+
node.type === "section" ||
|
|
966
|
+
node.type === "accordion-item" ||
|
|
967
|
+
node.type === "menu-item";
|
|
968
|
+
|
|
969
|
+
/** Nodes that may hold children. */
|
|
970
|
+
export const isParentNode = (
|
|
971
|
+
node: LayoutNode,
|
|
972
|
+
): node is
|
|
973
|
+
| ContainerNode
|
|
974
|
+
| DivBlockNode
|
|
975
|
+
| LayoutSectionNode
|
|
976
|
+
| FlexboxNode
|
|
977
|
+
| GridNode
|
|
978
|
+
| FormNode
|
|
979
|
+
| LoopNode
|
|
980
|
+
| SectionNode
|
|
981
|
+
| TabsNode
|
|
982
|
+
| TabPanelNode
|
|
983
|
+
| AccordionNode
|
|
984
|
+
| AccordionItemNode
|
|
985
|
+
| MenuNode
|
|
986
|
+
| MenuItemNode =>
|
|
987
|
+
node.type === "container" ||
|
|
988
|
+
node.type === "div-block" ||
|
|
989
|
+
node.type === "layout-section" ||
|
|
990
|
+
node.type === "flexbox" ||
|
|
991
|
+
node.type === "grid" ||
|
|
992
|
+
node.type === "form" ||
|
|
993
|
+
node.type === "loop" ||
|
|
994
|
+
node.type === "section" ||
|
|
995
|
+
node.type === "tabs" ||
|
|
996
|
+
node.type === "tab-panel" ||
|
|
997
|
+
node.type === "accordion" ||
|
|
998
|
+
node.type === "accordion-item" ||
|
|
999
|
+
node.type === "menu" ||
|
|
1000
|
+
node.type === "menu-item";
|
|
1001
|
+
|
|
1002
|
+
export const isFormFieldType = (type: string): boolean =>
|
|
1003
|
+
(FORM_FIELD_TYPES as readonly string[]).includes(type);
|
|
1004
|
+
|
|
1005
|
+
export const isHeadingNode = (node: LayoutNode): node is HeadingNode => node.type === "heading";
|
|
1006
|
+
|
|
1007
|
+
export const isUnknownNode = (node: LayoutNode): node is UnknownNode =>
|
|
1008
|
+
!knownTypeSet.has(node.type);
|