@perkyzz/emvb 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +57 -2
- package/package.json +72 -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 +48 -0
- package/src/admin/content-api.ts +147 -0
- package/src/admin/editor/Editor.tsx +457 -0
- package/src/admin/editor/EditorOverlay.tsx +54 -0
- package/src/admin/editor/ShortcutsDialog.tsx +30 -0
- package/src/admin/editor/SmallScreenNotice.tsx +20 -0
- package/src/admin/editor/TopBar.tsx +179 -0
- package/src/admin/editor/canvas/CanvasFrame.tsx +355 -0
- package/src/admin/editor/canvas/CanvasTextEdit.tsx +87 -0
- package/src/admin/editor/canvas/DeviceBar.tsx +50 -0
- package/src/admin/editor/canvas/EmptyCanvas.tsx +49 -0
- package/src/admin/editor/canvas/SelectionOverlay.tsx +185 -0
- package/src/admin/editor/canvas/canvas-events.ts +232 -0
- package/src/admin/editor/canvas/state-preview.ts +19 -0
- package/src/admin/editor/canvas/tab-reveal.ts +35 -0
- package/src/admin/editor/canvas/vnode-react.tsx +49 -0
- package/src/admin/editor/clipboard-store.ts +44 -0
- package/src/admin/editor/dialogs.tsx +125 -0
- package/src/admin/editor/dnd/drag-stash.ts +27 -0
- package/src/admin/editor/dnd/drop-target.ts +101 -0
- package/src/admin/editor/dnd/new-element.ts +32 -0
- package/src/admin/editor/editor-css.ts +539 -0
- package/src/admin/editor/exit.ts +27 -0
- package/src/admin/editor/panels/AddPanel.tsx +142 -0
- package/src/admin/editor/panels/ClassesSection.tsx +334 -0
- package/src/admin/editor/panels/ColorControl.tsx +230 -0
- package/src/admin/editor/panels/ConditionsEditor.tsx +201 -0
- package/src/admin/editor/panels/ElementPanel.tsx +629 -0
- package/src/admin/editor/panels/LayersPanel.tsx +336 -0
- package/src/admin/editor/panels/LeftPanel.tsx +77 -0
- package/src/admin/editor/panels/PageSettings.tsx +126 -0
- package/src/admin/editor/panels/SettingsPanel.tsx +101 -0
- package/src/admin/editor/panels/SiteStylesDrawer.tsx +392 -0
- package/src/admin/editor/panels/TriggerSettings.tsx +132 -0
- package/src/admin/editor/panels/TriggersEditor.tsx +197 -0
- package/src/admin/editor/panels/VariableSection.tsx +492 -0
- package/src/admin/editor/panels/settings/BackgroundControls.tsx +320 -0
- package/src/admin/editor/panels/settings/ClassChip.tsx +167 -0
- package/src/admin/editor/panels/settings/ClassChipInput.tsx +349 -0
- package/src/admin/editor/panels/settings/DraftTextField.tsx +201 -0
- package/src/admin/editor/panels/settings/EffectsControls.tsx +347 -0
- package/src/admin/editor/panels/settings/FieldBindControl.tsx +83 -0
- package/src/admin/editor/panels/settings/FieldControl.tsx +150 -0
- package/src/admin/editor/panels/settings/FormBindControl.tsx +97 -0
- package/src/admin/editor/panels/settings/IconPicker.tsx +109 -0
- package/src/admin/editor/panels/settings/LengthRow.tsx +181 -0
- package/src/admin/editor/panels/settings/LoopItemBindControl.tsx +124 -0
- package/src/admin/editor/panels/settings/MediaPicker.tsx +218 -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 +480 -0
- package/src/admin/editor/panels/settings/VariableBinding.tsx +167 -0
- package/src/admin/editor/panels/settings/class-suggest.ts +51 -0
- package/src/admin/editor/panels/settings/length-units.ts +83 -0
- package/src/admin/editor/panels/settings/node-props.ts +11 -0
- package/src/admin/editor/panels/settings/style-sections.ts +291 -0
- package/src/admin/editor/panels/site-list.tsx +206 -0
- package/src/admin/editor/panels/variable-values.ts +73 -0
- package/src/admin/editor/section-templates.ts +50 -0
- package/src/admin/editor/shortcuts.ts +20 -0
- package/src/admin/editor/store.ts +212 -0
- package/src/admin/editor/useClipboardActions.ts +136 -0
- package/src/admin/editor/useEditorCommands.ts +142 -0
- package/src/admin/editor/useEditorData.ts +167 -0
- package/src/admin/editor/useEditorShortcuts.ts +148 -0
- package/src/admin/editor/useMediaQuery.ts +20 -0
- package/src/admin/editor/useNodeActions.ts +122 -0
- package/src/admin/editor/useSave.ts +185 -0
- package/src/admin/forms-api.ts +73 -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 +71 -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 +202 -0
- package/src/admin/pages/list-kit.tsx +75 -0
- package/src/admin/setup/plan.ts +150 -0
- package/src/admin/setup/run.ts +61 -0
- package/src/admin/setup/spec.ts +100 -0
- package/src/admin/setup/useSetupStatus.ts +62 -0
- package/src/admin/theme-api.ts +186 -0
- package/src/admin/ui.ts +231 -0
- package/src/admin/widgets/LayoutField.tsx +67 -0
- package/src/astro/EmVBPage.astro +37 -0
- package/src/astro/env.d.ts +5 -0
- package/src/astro/forms/EmVBFormsRuntime.astro +9 -0
- package/src/astro/forms/index.ts +1 -0
- package/src/astro/forms-definitions.ts +104 -0
- package/src/astro/index.ts +15 -0
- package/src/astro/popups/EmVBPopupsRuntime.astro +9 -0
- package/src/astro/popups/index.ts +1 -0
- package/src/astro/popups/runtime.ts +246 -0
- package/src/astro/render.ts +74 -0
- package/src/astro/resolve-theme.ts +371 -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 +111 -0
- package/src/astro/theme-context.ts +81 -0
- package/src/astro/theme-posts.ts +84 -0
- package/src/constants.ts +12 -0
- package/src/core/arrange.ts +360 -0
- package/src/core/clipboard.ts +422 -0
- package/src/core/css/generate.ts +219 -0
- package/src/core/css/scope.ts +88 -0
- package/src/core/design/cascade.ts +28 -0
- package/src/core/design/classes.ts +138 -0
- package/src/core/design/devices.ts +56 -0
- package/src/core/design/states.ts +49 -0
- package/src/core/design/transfer.ts +33 -0
- package/src/core/design/variables.ts +319 -0
- package/src/core/elements/definition.ts +12 -0
- package/src/core/elements/dynamic-elements.ts +173 -0
- package/src/core/elements/form-elements.ts +204 -0
- package/src/core/elements/index.ts +742 -0
- package/src/core/elements/plain-text.ts +32 -0
- package/src/core/forms/binding.ts +61 -0
- package/src/core/forms/definition.ts +34 -0
- package/src/core/forms/success-layout.ts +63 -0
- package/src/core/icons/catalog.ts +273 -0
- package/src/core/index.ts +316 -0
- package/src/core/limits.ts +7 -0
- package/src/core/migrate/index.ts +76 -0
- package/src/core/render/context.ts +14 -0
- package/src/core/render/dynamic-post.ts +147 -0
- package/src/core/render/extras.ts +79 -0
- package/src/core/render/form.ts +137 -0
- package/src/core/render/index.ts +274 -0
- package/src/core/render/loop.ts +36 -0
- package/src/core/render/section.ts +33 -0
- package/src/core/render/tabs.ts +72 -0
- package/src/core/render/vnode.ts +87 -0
- package/src/core/sanitize/css.ts +591 -0
- package/src/core/sanitize/embed-url.ts +103 -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.ts +293 -0
- package/src/core/sanitize/url.ts +31 -0
- package/src/core/schema/descriptors.ts +33 -0
- package/src/core/schema/design.ts +88 -0
- package/src/core/schema/layout.ts +817 -0
- package/src/core/schema/state-names.ts +4 -0
- package/src/core/schema/style.ts +257 -0
- package/src/core/stats.ts +18 -0
- package/src/core/tabs/presence.ts +16 -0
- package/src/core/theme/conditions.ts +321 -0
- package/src/core/theme/dynamic.ts +133 -0
- package/src/core/theme/parse-doc.ts +36 -0
- package/src/core/theme/part-types.ts +79 -0
- package/src/core/theme/popup-markup.ts +39 -0
- package/src/core/theme/popup-rules.ts +61 -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 +98 -0
- package/src/server/plugin.ts +39 -0
|
@@ -0,0 +1,817 @@
|
|
|
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
|
+
/** 9 since W-103 (D-042). v8 → v9 changes nothing, so an older EmVB shows "saved by a newer EmVB". */
|
|
6
|
+
export const LAYOUT_SCHEMA_VERSION = 9;
|
|
7
|
+
|
|
8
|
+
export const NodeId = z
|
|
9
|
+
.string()
|
|
10
|
+
.regex(/^[A-Za-z0-9_-]{4,24}$/, "Ids are 4-24 letters, digits, _ or -");
|
|
11
|
+
const ClassIds = z.array(z.string().regex(/^[a-z0-9-]{1,40}$/)).max(20);
|
|
12
|
+
/** CSS id attribute (Advanced). Letters first; unique on the page (checked in validateLayout). */
|
|
13
|
+
const HtmlId = z
|
|
14
|
+
.string()
|
|
15
|
+
.regex(
|
|
16
|
+
/^[A-Za-z][A-Za-z0-9_-]{0,63}$/,
|
|
17
|
+
"CSS ids start with a letter and are at most 64 characters",
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
export const CONTAINER_TAGS = [
|
|
21
|
+
"div",
|
|
22
|
+
"section",
|
|
23
|
+
"header",
|
|
24
|
+
"footer",
|
|
25
|
+
"main",
|
|
26
|
+
"article",
|
|
27
|
+
"aside",
|
|
28
|
+
"nav",
|
|
29
|
+
] as const;
|
|
30
|
+
export const TEXT_TAGS = ["p", "div"] as const;
|
|
31
|
+
|
|
32
|
+
/** `data-*` and `aria-*` only. Names stay unique on the element (W-105 / R-032). */
|
|
33
|
+
const HtmlAttribute = z.strictObject({
|
|
34
|
+
name: z
|
|
35
|
+
.string()
|
|
36
|
+
.regex(
|
|
37
|
+
/^(?:data|aria)-[a-z][a-z0-9-]{0,40}$/,
|
|
38
|
+
"Use a data-* or aria-* name, starting with a letter",
|
|
39
|
+
),
|
|
40
|
+
value: z.string().max(200),
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const HtmlAttributes = z.array(HtmlAttribute).max(20);
|
|
44
|
+
|
|
45
|
+
/** A box may be the link. A link inside a link is dropped at render time (W-111). */
|
|
46
|
+
const BoxLink = {
|
|
47
|
+
href: z.string().max(2000).optional(),
|
|
48
|
+
newTab: z.boolean().optional(),
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
/** The fields every element has; `props` is the element's own strict props schema. */
|
|
52
|
+
const nodeFields = <T extends string, P extends z.ZodType>(type: T, props: P) => ({
|
|
53
|
+
id: NodeId,
|
|
54
|
+
type: z.literal(type),
|
|
55
|
+
props,
|
|
56
|
+
style: StyleProps.optional(),
|
|
57
|
+
states: StyleStates.optional(),
|
|
58
|
+
devices: DeviceStyles.optional(),
|
|
59
|
+
hiddenOn: HiddenOn.optional(),
|
|
60
|
+
classes: ClassIds.optional(),
|
|
61
|
+
htmlId: HtmlId.optional(),
|
|
62
|
+
attributes: HtmlAttributes.optional(),
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
const leafNode = <T extends string, P extends z.ZodType>(type: T, props: P) =>
|
|
66
|
+
z.strictObject(nodeFields(type, props));
|
|
67
|
+
|
|
68
|
+
const parentNode = <T extends string, P extends z.ZodType>(type: T, props: P) =>
|
|
69
|
+
z.strictObject({
|
|
70
|
+
...nodeFields(type, props),
|
|
71
|
+
get children(): z.ZodType<LayoutNode[]> {
|
|
72
|
+
return z.array(LayoutNode);
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
export const HeadingNode = leafNode(
|
|
77
|
+
"heading",
|
|
78
|
+
z.strictObject({
|
|
79
|
+
text: z.string().max(MAX_TEXT_LENGTH),
|
|
80
|
+
level: z.number().int().min(1).max(6),
|
|
81
|
+
}),
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
export const SpacerNode = leafNode(
|
|
85
|
+
"spacer",
|
|
86
|
+
z.strictObject({
|
|
87
|
+
height: Length,
|
|
88
|
+
}),
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
export const DividerNode = leafNode("divider", z.strictObject({}));
|
|
92
|
+
|
|
93
|
+
export const TextNode = leafNode(
|
|
94
|
+
"text",
|
|
95
|
+
z.strictObject({
|
|
96
|
+
text: z.string().max(MAX_TEXT_LENGTH),
|
|
97
|
+
tag: z.enum(TEXT_TAGS).optional(),
|
|
98
|
+
}),
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
export const LabelNode = leafNode(
|
|
102
|
+
"label",
|
|
103
|
+
z.strictObject({
|
|
104
|
+
text: z.string().max(MAX_TEXT_LENGTH),
|
|
105
|
+
}),
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
export const LinkNode = leafNode(
|
|
109
|
+
"link",
|
|
110
|
+
z.strictObject({
|
|
111
|
+
text: z.string().max(MAX_TEXT_LENGTH),
|
|
112
|
+
href: z.string().max(2000),
|
|
113
|
+
newTab: z.boolean().optional(),
|
|
114
|
+
}),
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
export const ButtonNode = leafNode(
|
|
118
|
+
"button",
|
|
119
|
+
z.strictObject({
|
|
120
|
+
text: z.string().max(MAX_TEXT_LENGTH),
|
|
121
|
+
href: z.string().max(2000).optional(),
|
|
122
|
+
newTab: z.boolean().optional(),
|
|
123
|
+
}),
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
export const ListNode = leafNode(
|
|
127
|
+
"list",
|
|
128
|
+
z.strictObject({
|
|
129
|
+
ordered: z.boolean().optional(),
|
|
130
|
+
items: z.array(z.string().max(MAX_TEXT_LENGTH)).max(200),
|
|
131
|
+
}),
|
|
132
|
+
);
|
|
133
|
+
|
|
134
|
+
/** YouTube/Vimeo privacy embed or media-library video (W-026 / R-013). */
|
|
135
|
+
export const VideoNode = leafNode(
|
|
136
|
+
"video",
|
|
137
|
+
z.strictObject({
|
|
138
|
+
url: z.string().max(2000),
|
|
139
|
+
title: z.string().min(1).max(200),
|
|
140
|
+
mediaId: z.string().min(1).max(128).optional(),
|
|
141
|
+
}),
|
|
142
|
+
);
|
|
143
|
+
|
|
144
|
+
/** Bundled Lucide icon by id (W-025 / A-04). Unknown ids stay on save; renderer shows a placeholder. */
|
|
145
|
+
export const IconNode = leafNode(
|
|
146
|
+
"icon",
|
|
147
|
+
z.strictObject({
|
|
148
|
+
iconId: z.string().min(1).max(64),
|
|
149
|
+
size: z.number().int().positive().max(512).optional(),
|
|
150
|
+
decorative: z.boolean().optional(),
|
|
151
|
+
title: z.string().max(200).optional(),
|
|
152
|
+
}),
|
|
153
|
+
).refine((node) => node.props.decorative === true || (node.props.title?.length ?? 0) > 0, {
|
|
154
|
+
message: "Title is required unless the icon is marked decorative.",
|
|
155
|
+
path: ["props", "title"],
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
/** Image from the media library or a URL (W-024 / R-007). Alt required unless decorative. */
|
|
159
|
+
export const ImageNode = leafNode(
|
|
160
|
+
"image",
|
|
161
|
+
z.strictObject({
|
|
162
|
+
src: z.string().max(2000),
|
|
163
|
+
alt: z.string().max(500),
|
|
164
|
+
decorative: z.boolean().optional(),
|
|
165
|
+
width: z.number().int().positive().max(10000).optional(),
|
|
166
|
+
height: z.number().int().positive().max(10000).optional(),
|
|
167
|
+
mediaId: z.string().min(1).max(128).optional(),
|
|
168
|
+
}),
|
|
169
|
+
).refine((node) => node.props.decorative === true || node.props.alt.length > 0, {
|
|
170
|
+
message: "Alt text is required unless the image is marked decorative.",
|
|
171
|
+
path: ["props", "alt"],
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
export const ContainerNode = parentNode(
|
|
175
|
+
"container",
|
|
176
|
+
z.strictObject({
|
|
177
|
+
tag: z.enum(CONTAINER_TAGS).optional(),
|
|
178
|
+
...BoxLink,
|
|
179
|
+
}),
|
|
180
|
+
);
|
|
181
|
+
|
|
182
|
+
/** Field name on a forms-plugin form (D-015). */
|
|
183
|
+
const FieldName = z
|
|
184
|
+
.string()
|
|
185
|
+
.min(1)
|
|
186
|
+
.max(80)
|
|
187
|
+
.regex(/^[a-zA-Z][a-zA-Z0-9_-]*$/, "Field names start with a letter");
|
|
188
|
+
|
|
189
|
+
export const DivBlockNode = parentNode("div-block", z.strictObject({ ...BoxLink }));
|
|
190
|
+
|
|
191
|
+
export const FlexboxNode = parentNode("flexbox", z.strictObject({ ...BoxLink }));
|
|
192
|
+
|
|
193
|
+
/** Equal columns. Children span with `gridColumnSpan` and `gridRowSpan` on their style. */
|
|
194
|
+
export const GridNode = parentNode(
|
|
195
|
+
"grid",
|
|
196
|
+
z.strictObject({
|
|
197
|
+
columns: z.number().int().min(1).max(12),
|
|
198
|
+
...BoxLink,
|
|
199
|
+
}),
|
|
200
|
+
);
|
|
201
|
+
|
|
202
|
+
/** Several disclosures. Items are `<details>`, so the public page needs no script (W-106). */
|
|
203
|
+
export const AccordionNode = parentNode("accordion", z.strictObject({}));
|
|
204
|
+
|
|
205
|
+
export const AccordionItemNode = parentNode(
|
|
206
|
+
"accordion-item",
|
|
207
|
+
z.strictObject({
|
|
208
|
+
summary: z.string().min(1).max(200),
|
|
209
|
+
open: z.boolean().optional(),
|
|
210
|
+
}),
|
|
211
|
+
);
|
|
212
|
+
|
|
213
|
+
export const SvgNode = leafNode(
|
|
214
|
+
"svg",
|
|
215
|
+
z.strictObject({
|
|
216
|
+
/** Sanitized SVG markup (allowlisted tags/attrs only). */
|
|
217
|
+
markup: z.string().max(32768),
|
|
218
|
+
title: z.string().max(MAX_TEXT_LENGTH).optional(),
|
|
219
|
+
decorative: z.boolean().optional(),
|
|
220
|
+
size: z.number().int().positive().max(2048).optional(),
|
|
221
|
+
}),
|
|
222
|
+
);
|
|
223
|
+
|
|
224
|
+
export const TabPanelNode = parentNode(
|
|
225
|
+
"tab-panel",
|
|
226
|
+
z.strictObject({
|
|
227
|
+
label: z.string().min(1).max(MAX_TEXT_LENGTH),
|
|
228
|
+
}),
|
|
229
|
+
);
|
|
230
|
+
|
|
231
|
+
const TabsNodeSchema = parentNode("tabs", z.strictObject({}));
|
|
232
|
+
|
|
233
|
+
export const FORM_FIELD_TYPES = [
|
|
234
|
+
"text-input",
|
|
235
|
+
"textarea",
|
|
236
|
+
"select",
|
|
237
|
+
"checkbox",
|
|
238
|
+
"radio",
|
|
239
|
+
"submit",
|
|
240
|
+
] as const;
|
|
241
|
+
|
|
242
|
+
export const FormNode = parentNode(
|
|
243
|
+
"form",
|
|
244
|
+
z.strictObject({
|
|
245
|
+
/** Empty until the editor binds a forms-plugin form (W-036). */
|
|
246
|
+
formId: z.string().max(64),
|
|
247
|
+
}),
|
|
248
|
+
);
|
|
249
|
+
|
|
250
|
+
const InputFieldProps = z.strictObject({
|
|
251
|
+
field: FieldName,
|
|
252
|
+
label: z.string().max(200).optional(),
|
|
253
|
+
placeholder: z.string().max(200).optional(),
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
export const TextInputNode = leafNode("text-input", InputFieldProps);
|
|
257
|
+
|
|
258
|
+
export const TextareaNode = leafNode("textarea", InputFieldProps);
|
|
259
|
+
|
|
260
|
+
export const SelectNode = leafNode("select", InputFieldProps);
|
|
261
|
+
|
|
262
|
+
export const CheckboxNode = leafNode(
|
|
263
|
+
"checkbox",
|
|
264
|
+
z.strictObject({
|
|
265
|
+
field: FieldName,
|
|
266
|
+
label: z.string().max(200).optional(),
|
|
267
|
+
}),
|
|
268
|
+
);
|
|
269
|
+
|
|
270
|
+
export const RadioNode = leafNode("radio", InputFieldProps);
|
|
271
|
+
|
|
272
|
+
export const SubmitNode = leafNode(
|
|
273
|
+
"submit",
|
|
274
|
+
z.strictObject({
|
|
275
|
+
label: z.string().min(1).max(80).optional(),
|
|
276
|
+
}),
|
|
277
|
+
);
|
|
278
|
+
|
|
279
|
+
/** Dynamic post title from ThemeDynamicData (S7d). */
|
|
280
|
+
export const PostTitleNode = leafNode(
|
|
281
|
+
"post-title",
|
|
282
|
+
z.strictObject({
|
|
283
|
+
level: z.number().int().min(1).max(6).optional(),
|
|
284
|
+
}),
|
|
285
|
+
);
|
|
286
|
+
|
|
287
|
+
/** Dynamic post excerpt (escaped text). */
|
|
288
|
+
export const PostExcerptNode = leafNode("post-excerpt", z.strictObject({}));
|
|
289
|
+
|
|
290
|
+
/** Dynamic post body from Portable Text / string (sanitized via VNode serialize). */
|
|
291
|
+
export const PostContentNode = leafNode("post-content", z.strictObject({}));
|
|
292
|
+
|
|
293
|
+
/** Dynamic featured image when a URL is available. */
|
|
294
|
+
export const PostImageNode = leafNode(
|
|
295
|
+
"post-image",
|
|
296
|
+
z.strictObject({
|
|
297
|
+
decorative: z.boolean().optional(),
|
|
298
|
+
}),
|
|
299
|
+
);
|
|
300
|
+
|
|
301
|
+
/** Published date from the post, shown as a `<time>` element (W-108). */
|
|
302
|
+
export const PostDateNode = leafNode("post-date", z.strictObject({}));
|
|
303
|
+
|
|
304
|
+
/** Author name from the post (W-108). */
|
|
305
|
+
export const PostAuthorNode = leafNode("post-author", z.strictObject({}));
|
|
306
|
+
|
|
307
|
+
/** Permalink link; empty text uses the post title. */
|
|
308
|
+
export const PostLinkNode = leafNode(
|
|
309
|
+
"post-link",
|
|
310
|
+
z.strictObject({
|
|
311
|
+
text: z.string().max(MAX_TEXT_LENGTH).optional(),
|
|
312
|
+
newTab: z.boolean().optional(),
|
|
313
|
+
}),
|
|
314
|
+
);
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* Repeats its item template for each post in ThemeDynamicData.posts.
|
|
318
|
+
* When `itemPartId` is set, the host supplies that Loop Item layout in loopTemplates;
|
|
319
|
+
* otherwise children are the inline item template.
|
|
320
|
+
*/
|
|
321
|
+
export const LoopNode = parentNode(
|
|
322
|
+
"loop",
|
|
323
|
+
z.strictObject({
|
|
324
|
+
itemPartId: z.string().max(128).optional(),
|
|
325
|
+
}),
|
|
326
|
+
);
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* A reusable block. When `partId` is set, the host supplies that Section theme part in
|
|
330
|
+
* `sectionTemplates` and the part's children render in place of `children`.
|
|
331
|
+
*/
|
|
332
|
+
export const SectionNode = parentNode(
|
|
333
|
+
"section",
|
|
334
|
+
z.strictObject({
|
|
335
|
+
partId: z.string().max(128).optional(),
|
|
336
|
+
}),
|
|
337
|
+
);
|
|
338
|
+
|
|
339
|
+
/** Known element type strings (everything else is an UnknownNode). */
|
|
340
|
+
export const KNOWN_ELEMENT_TYPES = [
|
|
341
|
+
"container",
|
|
342
|
+
"heading",
|
|
343
|
+
"spacer",
|
|
344
|
+
"divider",
|
|
345
|
+
"text",
|
|
346
|
+
"label",
|
|
347
|
+
"link",
|
|
348
|
+
"button",
|
|
349
|
+
"list",
|
|
350
|
+
"image",
|
|
351
|
+
"icon",
|
|
352
|
+
"video",
|
|
353
|
+
"form",
|
|
354
|
+
"text-input",
|
|
355
|
+
"textarea",
|
|
356
|
+
"select",
|
|
357
|
+
"checkbox",
|
|
358
|
+
"radio",
|
|
359
|
+
"submit",
|
|
360
|
+
"post-title",
|
|
361
|
+
"post-excerpt",
|
|
362
|
+
"post-content",
|
|
363
|
+
"post-image",
|
|
364
|
+
"post-link",
|
|
365
|
+
"post-date",
|
|
366
|
+
"post-author",
|
|
367
|
+
"loop",
|
|
368
|
+
"section",
|
|
369
|
+
"div-block",
|
|
370
|
+
"flexbox",
|
|
371
|
+
"grid",
|
|
372
|
+
"svg",
|
|
373
|
+
"tabs",
|
|
374
|
+
"tab-panel",
|
|
375
|
+
"accordion",
|
|
376
|
+
"accordion-item",
|
|
377
|
+
] as const;
|
|
378
|
+
|
|
379
|
+
const knownTypeSet = new Set<string>(KNOWN_ELEMENT_TYPES);
|
|
380
|
+
|
|
381
|
+
/**
|
|
382
|
+
* A node whose `type` EmVB does not implement yet (W-022 / R-033). Kept on save so a newer
|
|
383
|
+
* plugin version can reclaim it; public pages omit it; the editor shows a placeholder.
|
|
384
|
+
*/
|
|
385
|
+
const UnknownNodeSchema = z.strictObject({
|
|
386
|
+
id: NodeId,
|
|
387
|
+
type: z
|
|
388
|
+
.string()
|
|
389
|
+
.min(1)
|
|
390
|
+
.max(64)
|
|
391
|
+
.refine((value) => !knownTypeSet.has(value), "Unknown element type"),
|
|
392
|
+
props: z.record(z.string(), z.unknown()),
|
|
393
|
+
style: StyleProps.optional(),
|
|
394
|
+
states: StyleStates.optional(),
|
|
395
|
+
classes: ClassIds.optional(),
|
|
396
|
+
htmlId: HtmlId.optional(),
|
|
397
|
+
attributes: HtmlAttributes.optional(),
|
|
398
|
+
get children(): z.ZodType<LayoutNode[] | undefined> {
|
|
399
|
+
return z.array(LayoutNode).optional();
|
|
400
|
+
},
|
|
401
|
+
});
|
|
402
|
+
|
|
403
|
+
const KnownLayoutNode = z.discriminatedUnion("type", [
|
|
404
|
+
ContainerNode,
|
|
405
|
+
DivBlockNode,
|
|
406
|
+
FlexboxNode,
|
|
407
|
+
GridNode,
|
|
408
|
+
SvgNode,
|
|
409
|
+
TabsNodeSchema,
|
|
410
|
+
TabPanelNode,
|
|
411
|
+
HeadingNode,
|
|
412
|
+
SpacerNode,
|
|
413
|
+
DividerNode,
|
|
414
|
+
TextNode,
|
|
415
|
+
LabelNode,
|
|
416
|
+
LinkNode,
|
|
417
|
+
ButtonNode,
|
|
418
|
+
ListNode,
|
|
419
|
+
ImageNode,
|
|
420
|
+
IconNode,
|
|
421
|
+
VideoNode,
|
|
422
|
+
FormNode,
|
|
423
|
+
TextInputNode,
|
|
424
|
+
TextareaNode,
|
|
425
|
+
SelectNode,
|
|
426
|
+
CheckboxNode,
|
|
427
|
+
RadioNode,
|
|
428
|
+
SubmitNode,
|
|
429
|
+
PostTitleNode,
|
|
430
|
+
PostExcerptNode,
|
|
431
|
+
PostContentNode,
|
|
432
|
+
PostImageNode,
|
|
433
|
+
PostLinkNode,
|
|
434
|
+
PostDateNode,
|
|
435
|
+
PostAuthorNode,
|
|
436
|
+
LoopNode,
|
|
437
|
+
SectionNode,
|
|
438
|
+
AccordionNode,
|
|
439
|
+
AccordionItemNode,
|
|
440
|
+
]);
|
|
441
|
+
|
|
442
|
+
export type HeadingNode = z.infer<typeof HeadingNode>;
|
|
443
|
+
export type SpacerNode = z.infer<typeof SpacerNode>;
|
|
444
|
+
export type DividerNode = z.infer<typeof DividerNode>;
|
|
445
|
+
export type TextNode = z.infer<typeof TextNode>;
|
|
446
|
+
export type LabelNode = z.infer<typeof LabelNode>;
|
|
447
|
+
export type LinkNode = z.infer<typeof LinkNode>;
|
|
448
|
+
export type ButtonNode = z.infer<typeof ButtonNode>;
|
|
449
|
+
export type ListNode = z.infer<typeof ListNode>;
|
|
450
|
+
export type ImageNode = z.infer<typeof ImageNode>;
|
|
451
|
+
export type IconNode = z.infer<typeof IconNode>;
|
|
452
|
+
export type VideoNode = z.infer<typeof VideoNode>;
|
|
453
|
+
export type TextInputNode = z.infer<typeof TextInputNode>;
|
|
454
|
+
export type TextareaNode = z.infer<typeof TextareaNode>;
|
|
455
|
+
export type SelectNode = z.infer<typeof SelectNode>;
|
|
456
|
+
export type CheckboxNode = z.infer<typeof CheckboxNode>;
|
|
457
|
+
export type RadioNode = z.infer<typeof RadioNode>;
|
|
458
|
+
export type SubmitNode = z.infer<typeof SubmitNode>;
|
|
459
|
+
export type PostTitleNode = z.infer<typeof PostTitleNode>;
|
|
460
|
+
export type PostExcerptNode = z.infer<typeof PostExcerptNode>;
|
|
461
|
+
export type PostContentNode = z.infer<typeof PostContentNode>;
|
|
462
|
+
export type PostImageNode = z.infer<typeof PostImageNode>;
|
|
463
|
+
export type PostLinkNode = z.infer<typeof PostLinkNode>;
|
|
464
|
+
export type PostDateNode = z.infer<typeof PostDateNode>;
|
|
465
|
+
export type PostAuthorNode = z.infer<typeof PostAuthorNode>;
|
|
466
|
+
|
|
467
|
+
type StyleOf = z.infer<typeof StyleProps>;
|
|
468
|
+
type StatesOf = z.infer<typeof StyleStates>;
|
|
469
|
+
type DevicesOf = z.infer<typeof DeviceStyles>;
|
|
470
|
+
type HiddenOnOf = z.infer<typeof HiddenOn>;
|
|
471
|
+
type ClassesOf = z.infer<typeof ClassIds>;
|
|
472
|
+
type HtmlIdOf = z.infer<typeof HtmlId>;
|
|
473
|
+
type HtmlAttributeOf = z.infer<typeof HtmlAttribute>;
|
|
474
|
+
type IdOf = z.infer<typeof NodeId>;
|
|
475
|
+
|
|
476
|
+
/** Manual recursive types so UnknownNode does not poison `z.infer` of the tree. */
|
|
477
|
+
export type UnknownNode = {
|
|
478
|
+
id: IdOf;
|
|
479
|
+
type: string;
|
|
480
|
+
props: Record<string, unknown>;
|
|
481
|
+
style?: StyleOf;
|
|
482
|
+
states?: StatesOf;
|
|
483
|
+
devices?: DevicesOf;
|
|
484
|
+
hiddenOn?: HiddenOnOf;
|
|
485
|
+
classes?: ClassesOf;
|
|
486
|
+
htmlId?: HtmlIdOf;
|
|
487
|
+
attributes?: HtmlAttributeOf[];
|
|
488
|
+
children?: LayoutNode[];
|
|
489
|
+
};
|
|
490
|
+
|
|
491
|
+
export type ContainerNode = {
|
|
492
|
+
id: IdOf;
|
|
493
|
+
type: "container";
|
|
494
|
+
props: { tag?: (typeof CONTAINER_TAGS)[number]; href?: string; newTab?: boolean };
|
|
495
|
+
style?: StyleOf;
|
|
496
|
+
states?: StatesOf;
|
|
497
|
+
devices?: DevicesOf;
|
|
498
|
+
hiddenOn?: HiddenOnOf;
|
|
499
|
+
classes?: ClassesOf;
|
|
500
|
+
htmlId?: HtmlIdOf;
|
|
501
|
+
attributes?: HtmlAttributeOf[];
|
|
502
|
+
children: LayoutNode[];
|
|
503
|
+
};
|
|
504
|
+
|
|
505
|
+
export type DivBlockNode = {
|
|
506
|
+
id: IdOf;
|
|
507
|
+
type: "div-block";
|
|
508
|
+
props: { href?: string; newTab?: boolean };
|
|
509
|
+
style?: StyleOf;
|
|
510
|
+
states?: StatesOf;
|
|
511
|
+
devices?: DevicesOf;
|
|
512
|
+
hiddenOn?: HiddenOnOf;
|
|
513
|
+
classes?: ClassesOf;
|
|
514
|
+
htmlId?: HtmlIdOf;
|
|
515
|
+
attributes?: HtmlAttributeOf[];
|
|
516
|
+
children: LayoutNode[];
|
|
517
|
+
};
|
|
518
|
+
|
|
519
|
+
export type GridNode = {
|
|
520
|
+
id: IdOf;
|
|
521
|
+
type: "grid";
|
|
522
|
+
props: { columns: number; href?: string; newTab?: boolean };
|
|
523
|
+
style?: StyleOf;
|
|
524
|
+
states?: StatesOf;
|
|
525
|
+
devices?: DevicesOf;
|
|
526
|
+
hiddenOn?: HiddenOnOf;
|
|
527
|
+
classes?: ClassesOf;
|
|
528
|
+
htmlId?: HtmlIdOf;
|
|
529
|
+
attributes?: HtmlAttributeOf[];
|
|
530
|
+
children: LayoutNode[];
|
|
531
|
+
};
|
|
532
|
+
|
|
533
|
+
export type FlexboxNode = {
|
|
534
|
+
id: IdOf;
|
|
535
|
+
type: "flexbox";
|
|
536
|
+
props: { href?: string; newTab?: boolean };
|
|
537
|
+
style?: StyleOf;
|
|
538
|
+
states?: StatesOf;
|
|
539
|
+
devices?: DevicesOf;
|
|
540
|
+
hiddenOn?: HiddenOnOf;
|
|
541
|
+
classes?: ClassesOf;
|
|
542
|
+
htmlId?: HtmlIdOf;
|
|
543
|
+
attributes?: HtmlAttributeOf[];
|
|
544
|
+
children: LayoutNode[];
|
|
545
|
+
};
|
|
546
|
+
|
|
547
|
+
export type SvgNode = {
|
|
548
|
+
id: IdOf;
|
|
549
|
+
type: "svg";
|
|
550
|
+
props: {
|
|
551
|
+
markup: string;
|
|
552
|
+
title?: string;
|
|
553
|
+
decorative?: boolean;
|
|
554
|
+
size?: number;
|
|
555
|
+
};
|
|
556
|
+
style?: StyleOf;
|
|
557
|
+
states?: StatesOf;
|
|
558
|
+
devices?: DevicesOf;
|
|
559
|
+
hiddenOn?: HiddenOnOf;
|
|
560
|
+
classes?: ClassesOf;
|
|
561
|
+
htmlId?: HtmlIdOf;
|
|
562
|
+
attributes?: HtmlAttributeOf[];
|
|
563
|
+
};
|
|
564
|
+
|
|
565
|
+
export type TabPanelNode = {
|
|
566
|
+
id: IdOf;
|
|
567
|
+
type: "tab-panel";
|
|
568
|
+
props: { label: string };
|
|
569
|
+
style?: StyleOf;
|
|
570
|
+
states?: StatesOf;
|
|
571
|
+
devices?: DevicesOf;
|
|
572
|
+
hiddenOn?: HiddenOnOf;
|
|
573
|
+
classes?: ClassesOf;
|
|
574
|
+
htmlId?: HtmlIdOf;
|
|
575
|
+
attributes?: HtmlAttributeOf[];
|
|
576
|
+
children: LayoutNode[];
|
|
577
|
+
};
|
|
578
|
+
|
|
579
|
+
export type TabsNode = {
|
|
580
|
+
id: IdOf;
|
|
581
|
+
type: "tabs";
|
|
582
|
+
props: { href?: string; newTab?: boolean };
|
|
583
|
+
style?: StyleOf;
|
|
584
|
+
states?: StatesOf;
|
|
585
|
+
devices?: DevicesOf;
|
|
586
|
+
hiddenOn?: HiddenOnOf;
|
|
587
|
+
classes?: ClassesOf;
|
|
588
|
+
htmlId?: HtmlIdOf;
|
|
589
|
+
attributes?: HtmlAttributeOf[];
|
|
590
|
+
children: LayoutNode[];
|
|
591
|
+
};
|
|
592
|
+
|
|
593
|
+
export type FormNode = {
|
|
594
|
+
id: IdOf;
|
|
595
|
+
type: "form";
|
|
596
|
+
props: { formId: string };
|
|
597
|
+
style?: StyleOf;
|
|
598
|
+
states?: StatesOf;
|
|
599
|
+
devices?: DevicesOf;
|
|
600
|
+
hiddenOn?: HiddenOnOf;
|
|
601
|
+
classes?: ClassesOf;
|
|
602
|
+
htmlId?: HtmlIdOf;
|
|
603
|
+
attributes?: HtmlAttributeOf[];
|
|
604
|
+
children: LayoutNode[];
|
|
605
|
+
};
|
|
606
|
+
|
|
607
|
+
export type LoopNode = {
|
|
608
|
+
id: IdOf;
|
|
609
|
+
type: "loop";
|
|
610
|
+
props: { itemPartId?: string };
|
|
611
|
+
style?: StyleOf;
|
|
612
|
+
states?: StatesOf;
|
|
613
|
+
devices?: DevicesOf;
|
|
614
|
+
hiddenOn?: HiddenOnOf;
|
|
615
|
+
classes?: ClassesOf;
|
|
616
|
+
htmlId?: HtmlIdOf;
|
|
617
|
+
attributes?: HtmlAttributeOf[];
|
|
618
|
+
children: LayoutNode[];
|
|
619
|
+
};
|
|
620
|
+
|
|
621
|
+
export type SectionNode = {
|
|
622
|
+
id: IdOf;
|
|
623
|
+
type: "section";
|
|
624
|
+
props: { partId?: string };
|
|
625
|
+
style?: StyleOf;
|
|
626
|
+
states?: StatesOf;
|
|
627
|
+
devices?: DevicesOf;
|
|
628
|
+
hiddenOn?: HiddenOnOf;
|
|
629
|
+
classes?: ClassesOf;
|
|
630
|
+
htmlId?: HtmlIdOf;
|
|
631
|
+
attributes?: HtmlAttributeOf[];
|
|
632
|
+
children: LayoutNode[];
|
|
633
|
+
};
|
|
634
|
+
|
|
635
|
+
export type AccordionNode = {
|
|
636
|
+
id: IdOf;
|
|
637
|
+
type: "accordion";
|
|
638
|
+
props: Record<string, never>;
|
|
639
|
+
style?: StyleOf;
|
|
640
|
+
states?: StatesOf;
|
|
641
|
+
devices?: DevicesOf;
|
|
642
|
+
hiddenOn?: HiddenOnOf;
|
|
643
|
+
classes?: ClassesOf;
|
|
644
|
+
htmlId?: HtmlIdOf;
|
|
645
|
+
attributes?: HtmlAttributeOf[];
|
|
646
|
+
children: LayoutNode[];
|
|
647
|
+
};
|
|
648
|
+
|
|
649
|
+
export type AccordionItemNode = {
|
|
650
|
+
id: IdOf;
|
|
651
|
+
type: "accordion-item";
|
|
652
|
+
props: { summary: string; open?: boolean };
|
|
653
|
+
style?: StyleOf;
|
|
654
|
+
states?: StatesOf;
|
|
655
|
+
devices?: DevicesOf;
|
|
656
|
+
hiddenOn?: HiddenOnOf;
|
|
657
|
+
classes?: ClassesOf;
|
|
658
|
+
htmlId?: HtmlIdOf;
|
|
659
|
+
attributes?: HtmlAttributeOf[];
|
|
660
|
+
children: LayoutNode[];
|
|
661
|
+
};
|
|
662
|
+
|
|
663
|
+
export type LayoutNode =
|
|
664
|
+
| ContainerNode
|
|
665
|
+
| DivBlockNode
|
|
666
|
+
| FlexboxNode
|
|
667
|
+
| GridNode
|
|
668
|
+
| SvgNode
|
|
669
|
+
| TabsNode
|
|
670
|
+
| TabPanelNode
|
|
671
|
+
| FormNode
|
|
672
|
+
| LoopNode
|
|
673
|
+
| SectionNode
|
|
674
|
+
| HeadingNode
|
|
675
|
+
| SpacerNode
|
|
676
|
+
| DividerNode
|
|
677
|
+
| TextNode
|
|
678
|
+
| LabelNode
|
|
679
|
+
| LinkNode
|
|
680
|
+
| ButtonNode
|
|
681
|
+
| ListNode
|
|
682
|
+
| ImageNode
|
|
683
|
+
| IconNode
|
|
684
|
+
| VideoNode
|
|
685
|
+
| TextInputNode
|
|
686
|
+
| TextareaNode
|
|
687
|
+
| SelectNode
|
|
688
|
+
| CheckboxNode
|
|
689
|
+
| RadioNode
|
|
690
|
+
| SubmitNode
|
|
691
|
+
| PostTitleNode
|
|
692
|
+
| PostExcerptNode
|
|
693
|
+
| PostContentNode
|
|
694
|
+
| PostImageNode
|
|
695
|
+
| PostLinkNode
|
|
696
|
+
| PostDateNode
|
|
697
|
+
| PostAuthorNode
|
|
698
|
+
| AccordionNode
|
|
699
|
+
| AccordionItemNode
|
|
700
|
+
| UnknownNode;
|
|
701
|
+
|
|
702
|
+
/**
|
|
703
|
+
* Prefer the known-type schema when `type` is registered so path-specific Zod issues stay
|
|
704
|
+
* intact; only fall through to UnknownNode for types EmVB does not implement (W-022 / R-033).
|
|
705
|
+
* A plain `z.union` would collapse every known-type failure into `invalid_union`.
|
|
706
|
+
*/
|
|
707
|
+
const LayoutNode: z.ZodType<LayoutNode> = z.lazy(() =>
|
|
708
|
+
z.unknown().transform((input, ctx) => {
|
|
709
|
+
if (!input || typeof input !== "object" || Array.isArray(input)) {
|
|
710
|
+
ctx.addIssue({ code: "invalid_type", expected: "object", path: [] });
|
|
711
|
+
return z.NEVER;
|
|
712
|
+
}
|
|
713
|
+
const type = (input as { type?: unknown }).type;
|
|
714
|
+
if (typeof type !== "string") {
|
|
715
|
+
// `input` is the type itself; without it Zod describes the whole node ("received object").
|
|
716
|
+
ctx.addIssue({ code: "invalid_type", expected: "string", input: type, path: ["type"] });
|
|
717
|
+
return z.NEVER;
|
|
718
|
+
}
|
|
719
|
+
const result = knownTypeSet.has(type)
|
|
720
|
+
? KnownLayoutNode.safeParse(input)
|
|
721
|
+
: UnknownNodeSchema.safeParse(input);
|
|
722
|
+
if (!result.success) {
|
|
723
|
+
for (const issue of result.error.issues) {
|
|
724
|
+
ctx.addIssue({
|
|
725
|
+
code: "custom",
|
|
726
|
+
path: issue.path,
|
|
727
|
+
message: issue.message,
|
|
728
|
+
params: { zodCode: issue.code },
|
|
729
|
+
});
|
|
730
|
+
}
|
|
731
|
+
return z.NEVER;
|
|
732
|
+
}
|
|
733
|
+
return result.data as LayoutNode;
|
|
734
|
+
}),
|
|
735
|
+
);
|
|
736
|
+
|
|
737
|
+
export const Layout = z.strictObject({
|
|
738
|
+
schemaVersion: z.literal(LAYOUT_SCHEMA_VERSION),
|
|
739
|
+
root: ContainerNode,
|
|
740
|
+
});
|
|
741
|
+
|
|
742
|
+
export type Layout = {
|
|
743
|
+
schemaVersion: typeof LAYOUT_SCHEMA_VERSION;
|
|
744
|
+
root: ContainerNode;
|
|
745
|
+
};
|
|
746
|
+
|
|
747
|
+
export const isContainerNode = (node: LayoutNode): node is ContainerNode =>
|
|
748
|
+
node.type === "container";
|
|
749
|
+
|
|
750
|
+
export const isFormNode = (node: LayoutNode): node is FormNode => node.type === "form";
|
|
751
|
+
|
|
752
|
+
export const isLoopNode = (node: LayoutNode): node is LoopNode => node.type === "loop";
|
|
753
|
+
|
|
754
|
+
export const isSectionNode = (node: LayoutNode): node is SectionNode => node.type === "section";
|
|
755
|
+
|
|
756
|
+
export const isDivBlockNode = (node: LayoutNode): node is DivBlockNode => node.type === "div-block";
|
|
757
|
+
|
|
758
|
+
export const isFlexboxNode = (node: LayoutNode): node is FlexboxNode => node.type === "flexbox";
|
|
759
|
+
|
|
760
|
+
/** Layout parents that accept general children (not form-only / tabs-only). */
|
|
761
|
+
export const isTabsNode = (node: LayoutNode): node is TabsNode => node.type === "tabs";
|
|
762
|
+
|
|
763
|
+
export const isTabPanelNode = (node: LayoutNode): node is TabPanelNode => node.type === "tab-panel";
|
|
764
|
+
|
|
765
|
+
/** Layout parents that accept general children (forms may land here). */
|
|
766
|
+
export const isLayoutParentNode = (
|
|
767
|
+
node: LayoutNode,
|
|
768
|
+
): node is
|
|
769
|
+
| ContainerNode
|
|
770
|
+
| DivBlockNode
|
|
771
|
+
| FlexboxNode
|
|
772
|
+
| GridNode
|
|
773
|
+
| TabPanelNode
|
|
774
|
+
| SectionNode
|
|
775
|
+
| AccordionItemNode =>
|
|
776
|
+
node.type === "container" ||
|
|
777
|
+
node.type === "div-block" ||
|
|
778
|
+
node.type === "flexbox" ||
|
|
779
|
+
node.type === "grid" ||
|
|
780
|
+
node.type === "tab-panel" ||
|
|
781
|
+
node.type === "section" ||
|
|
782
|
+
node.type === "accordion-item";
|
|
783
|
+
|
|
784
|
+
/** Nodes that may hold children. */
|
|
785
|
+
export const isParentNode = (
|
|
786
|
+
node: LayoutNode,
|
|
787
|
+
): node is
|
|
788
|
+
| ContainerNode
|
|
789
|
+
| DivBlockNode
|
|
790
|
+
| FlexboxNode
|
|
791
|
+
| GridNode
|
|
792
|
+
| FormNode
|
|
793
|
+
| LoopNode
|
|
794
|
+
| SectionNode
|
|
795
|
+
| TabsNode
|
|
796
|
+
| TabPanelNode
|
|
797
|
+
| AccordionNode
|
|
798
|
+
| AccordionItemNode =>
|
|
799
|
+
node.type === "container" ||
|
|
800
|
+
node.type === "div-block" ||
|
|
801
|
+
node.type === "flexbox" ||
|
|
802
|
+
node.type === "grid" ||
|
|
803
|
+
node.type === "form" ||
|
|
804
|
+
node.type === "loop" ||
|
|
805
|
+
node.type === "section" ||
|
|
806
|
+
node.type === "tabs" ||
|
|
807
|
+
node.type === "tab-panel" ||
|
|
808
|
+
node.type === "accordion" ||
|
|
809
|
+
node.type === "accordion-item";
|
|
810
|
+
|
|
811
|
+
export const isFormFieldType = (type: string): boolean =>
|
|
812
|
+
(FORM_FIELD_TYPES as readonly string[]).includes(type);
|
|
813
|
+
|
|
814
|
+
export const isHeadingNode = (node: LayoutNode): node is HeadingNode => node.type === "heading";
|
|
815
|
+
|
|
816
|
+
export const isUnknownNode = (node: LayoutNode): node is UnknownNode =>
|
|
817
|
+
!knownTypeSet.has(node.type);
|