@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,742 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ButtonNode,
|
|
3
|
+
ContainerNode,
|
|
4
|
+
DivBlockNode,
|
|
5
|
+
FlexboxNode,
|
|
6
|
+
GridNode,
|
|
7
|
+
SvgNode,
|
|
8
|
+
TabsNode,
|
|
9
|
+
TabPanelNode,
|
|
10
|
+
AccordionNode,
|
|
11
|
+
AccordionItemNode,
|
|
12
|
+
DividerNode,
|
|
13
|
+
HeadingNode,
|
|
14
|
+
IconNode,
|
|
15
|
+
ImageNode,
|
|
16
|
+
LabelNode,
|
|
17
|
+
LinkNode,
|
|
18
|
+
ListNode,
|
|
19
|
+
SpacerNode,
|
|
20
|
+
TextNode,
|
|
21
|
+
VideoNode,
|
|
22
|
+
} from "../schema/layout.ts";
|
|
23
|
+
import { CONTAINER_TAGS, TEXT_TAGS } from "../schema/layout.ts";
|
|
24
|
+
import type { ElementDescriptor } from "../schema/descriptors.ts";
|
|
25
|
+
import { sanitizeHref } from "../sanitize/href.ts";
|
|
26
|
+
import { sanitizeSvgMarkup } from "../sanitize/svg.ts";
|
|
27
|
+
import { sanitizeMediaUrl } from "../sanitize/media-url.ts";
|
|
28
|
+
import { getBundledIcon } from "../icons/catalog.ts";
|
|
29
|
+
import { resolveEmbedUrl } from "../sanitize/embed-url.ts";
|
|
30
|
+
import type { VNode } from "../render/vnode.ts";
|
|
31
|
+
|
|
32
|
+
import type { ElementDefinition } from "./definition.ts";
|
|
33
|
+
import { checkbox, form, radio, selectEl, submit, textInput, textareaEl } from "./form-elements.ts";
|
|
34
|
+
import {
|
|
35
|
+
loop,
|
|
36
|
+
section,
|
|
37
|
+
postContent,
|
|
38
|
+
postExcerpt,
|
|
39
|
+
postImage,
|
|
40
|
+
postLink,
|
|
41
|
+
postTitle,
|
|
42
|
+
postDate,
|
|
43
|
+
postAuthor,
|
|
44
|
+
} from "./dynamic-elements.ts";
|
|
45
|
+
|
|
46
|
+
const HEADING_TAGS = ["h1", "h2", "h3", "h4", "h5", "h6"] as const;
|
|
47
|
+
|
|
48
|
+
const newTabAttrs = (newTab: boolean | undefined): Record<string, string> =>
|
|
49
|
+
newTab ? { target: "_blank", rel: "noopener noreferrer" } : {};
|
|
50
|
+
|
|
51
|
+
const heading: ElementDefinition<HeadingNode> = {
|
|
52
|
+
baseCss: ".emvb-heading{margin:0}",
|
|
53
|
+
defaults: () => ({ type: "heading", props: { text: "Heading", level: 2 } }),
|
|
54
|
+
descriptor: {
|
|
55
|
+
type: "heading",
|
|
56
|
+
name: "Heading",
|
|
57
|
+
group: "content",
|
|
58
|
+
defaultTab: "content",
|
|
59
|
+
fields: [
|
|
60
|
+
{ key: "text", kind: "text", label: "Text" },
|
|
61
|
+
{
|
|
62
|
+
key: "level",
|
|
63
|
+
kind: "select",
|
|
64
|
+
label: "Level",
|
|
65
|
+
options: [1, 2, 3, 4, 5, 6].map((n) => ({ value: n, label: `H${n}` })),
|
|
66
|
+
},
|
|
67
|
+
],
|
|
68
|
+
},
|
|
69
|
+
build: (node, attrs) => ({
|
|
70
|
+
tag: HEADING_TAGS[node.props.level - 1] ?? "h2",
|
|
71
|
+
attrs,
|
|
72
|
+
children: [node.props.text],
|
|
73
|
+
}),
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const BOX_LINK_FIELDS = [
|
|
77
|
+
{
|
|
78
|
+
key: "href",
|
|
79
|
+
kind: "text" as const,
|
|
80
|
+
label: "Link",
|
|
81
|
+
optional: true,
|
|
82
|
+
message: "Makes this box the link when it is a div. A link already inside stays as it is.",
|
|
83
|
+
},
|
|
84
|
+
{ key: "newTab", kind: "boolean" as const, label: "Open in new tab", optional: true },
|
|
85
|
+
];
|
|
86
|
+
|
|
87
|
+
const container: ElementDefinition<ContainerNode> = {
|
|
88
|
+
baseCss: ".emvb-container{display:flex;flex-direction:column;min-width:0}",
|
|
89
|
+
defaults: () => ({ type: "container", props: {}, children: [] }),
|
|
90
|
+
descriptor: {
|
|
91
|
+
type: "container",
|
|
92
|
+
name: "Container",
|
|
93
|
+
group: "layout",
|
|
94
|
+
defaultTab: "style",
|
|
95
|
+
fields: [
|
|
96
|
+
{
|
|
97
|
+
key: "tag",
|
|
98
|
+
kind: "select",
|
|
99
|
+
label: "HTML tag",
|
|
100
|
+
optional: true,
|
|
101
|
+
options: CONTAINER_TAGS.map((tag) => ({ value: tag, label: tag })),
|
|
102
|
+
message: "Pick a landmark or div.",
|
|
103
|
+
},
|
|
104
|
+
...BOX_LINK_FIELDS,
|
|
105
|
+
],
|
|
106
|
+
},
|
|
107
|
+
build: (node, attrs, children) => {
|
|
108
|
+
const tag = node.props.tag ?? "div";
|
|
109
|
+
const safe = (CONTAINER_TAGS as readonly string[]).includes(tag) ? tag : "div";
|
|
110
|
+
return { tag: safe, attrs, children };
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
const spacer: ElementDefinition<SpacerNode> = {
|
|
115
|
+
baseCss: ".emvb-spacer{flex-shrink:0}",
|
|
116
|
+
defaults: () => ({ type: "spacer", props: { height: { value: 24, unit: "px" } } }),
|
|
117
|
+
descriptor: {
|
|
118
|
+
type: "spacer",
|
|
119
|
+
name: "Spacer",
|
|
120
|
+
group: "layout",
|
|
121
|
+
defaultTab: "style",
|
|
122
|
+
fields: [
|
|
123
|
+
{
|
|
124
|
+
key: "height",
|
|
125
|
+
kind: "number",
|
|
126
|
+
label: "Height",
|
|
127
|
+
message: "Height can't be negative. Enter 0 or more.",
|
|
128
|
+
},
|
|
129
|
+
],
|
|
130
|
+
},
|
|
131
|
+
build: (_node, attrs) => ({
|
|
132
|
+
tag: "div",
|
|
133
|
+
attrs: { ...attrs, "aria-hidden": "true" },
|
|
134
|
+
children: [],
|
|
135
|
+
}),
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
const divider: ElementDefinition<DividerNode> = {
|
|
139
|
+
baseCss: ".emvb-divider{border:0;border-top:1px solid currentColor;margin:0}",
|
|
140
|
+
defaults: () => ({ type: "divider", props: {} }),
|
|
141
|
+
descriptor: {
|
|
142
|
+
type: "divider",
|
|
143
|
+
name: "Divider",
|
|
144
|
+
group: "layout",
|
|
145
|
+
defaultTab: "style",
|
|
146
|
+
fields: [],
|
|
147
|
+
},
|
|
148
|
+
build: (_node, attrs) => ({ tag: "hr", attrs, children: [] }),
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
const text: ElementDefinition<TextNode> = {
|
|
152
|
+
baseCss: ".emvb-text{margin:0}",
|
|
153
|
+
defaults: () => ({ type: "text", props: { text: "Text" } }),
|
|
154
|
+
descriptor: {
|
|
155
|
+
type: "text",
|
|
156
|
+
name: "Text",
|
|
157
|
+
group: "content",
|
|
158
|
+
defaultTab: "content",
|
|
159
|
+
fields: [
|
|
160
|
+
{ key: "text", kind: "textarea", label: "Text" },
|
|
161
|
+
{
|
|
162
|
+
key: "tag",
|
|
163
|
+
kind: "select",
|
|
164
|
+
label: "HTML tag",
|
|
165
|
+
optional: true,
|
|
166
|
+
options: TEXT_TAGS.map((tag) => ({ value: tag, label: tag })),
|
|
167
|
+
},
|
|
168
|
+
],
|
|
169
|
+
},
|
|
170
|
+
build: (node, attrs) => {
|
|
171
|
+
const tag = node.props.tag ?? "p";
|
|
172
|
+
const safe = (TEXT_TAGS as readonly string[]).includes(tag) ? tag : "p";
|
|
173
|
+
return { tag: safe, attrs, children: [node.props.text] };
|
|
174
|
+
},
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
const label: ElementDefinition<LabelNode> = {
|
|
178
|
+
baseCss: ".emvb-label{display:inline}",
|
|
179
|
+
defaults: () => ({ type: "label", props: { text: "Label" } }),
|
|
180
|
+
descriptor: {
|
|
181
|
+
type: "label",
|
|
182
|
+
name: "Label",
|
|
183
|
+
group: "content",
|
|
184
|
+
defaultTab: "content",
|
|
185
|
+
fields: [{ key: "text", kind: "text", label: "Text" }],
|
|
186
|
+
},
|
|
187
|
+
build: (node, attrs) => ({ tag: "span", attrs, children: [node.props.text] }),
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
const link: ElementDefinition<LinkNode> = {
|
|
191
|
+
baseCss: ".emvb-link{}",
|
|
192
|
+
defaults: () => ({ type: "link", props: { text: "Link", href: "/" } }),
|
|
193
|
+
descriptor: {
|
|
194
|
+
type: "link",
|
|
195
|
+
name: "Link",
|
|
196
|
+
group: "content",
|
|
197
|
+
defaultTab: "content",
|
|
198
|
+
fields: [
|
|
199
|
+
{ key: "text", kind: "text", label: "Text" },
|
|
200
|
+
{
|
|
201
|
+
key: "href",
|
|
202
|
+
kind: "href",
|
|
203
|
+
label: "URL",
|
|
204
|
+
message: "Use a full URL such as https://example.com or a path such as /pricing.",
|
|
205
|
+
},
|
|
206
|
+
{ key: "newTab", kind: "boolean", label: "Open in a new tab", optional: true },
|
|
207
|
+
],
|
|
208
|
+
},
|
|
209
|
+
build: (node, attrs) => {
|
|
210
|
+
const href = sanitizeHref(node.props.href) ?? "#";
|
|
211
|
+
return {
|
|
212
|
+
tag: "a",
|
|
213
|
+
attrs: { ...attrs, href, ...newTabAttrs(node.props.newTab) },
|
|
214
|
+
children: [node.props.text],
|
|
215
|
+
};
|
|
216
|
+
},
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
const button: ElementDefinition<ButtonNode> = {
|
|
220
|
+
baseCss:
|
|
221
|
+
".emvb-button{display:inline-flex;align-items:center;justify-content:center;margin:0;font:inherit;text-decoration:none;cursor:pointer}",
|
|
222
|
+
defaults: () => ({ type: "button", props: { text: "Button" } }),
|
|
223
|
+
descriptor: {
|
|
224
|
+
type: "button",
|
|
225
|
+
name: "Button",
|
|
226
|
+
group: "content",
|
|
227
|
+
defaultTab: "content",
|
|
228
|
+
fields: [
|
|
229
|
+
{ key: "text", kind: "text", label: "Text" },
|
|
230
|
+
{
|
|
231
|
+
key: "href",
|
|
232
|
+
kind: "href",
|
|
233
|
+
label: "URL",
|
|
234
|
+
optional: true,
|
|
235
|
+
message: "Use a full URL such as https://example.com or a path such as /pricing.",
|
|
236
|
+
},
|
|
237
|
+
{ key: "newTab", kind: "boolean", label: "Open in a new tab", optional: true },
|
|
238
|
+
],
|
|
239
|
+
},
|
|
240
|
+
build: (node, attrs) => {
|
|
241
|
+
const href = node.props.href !== undefined ? sanitizeHref(node.props.href) : undefined;
|
|
242
|
+
if (href) {
|
|
243
|
+
return {
|
|
244
|
+
tag: "a",
|
|
245
|
+
attrs: { ...attrs, href, ...newTabAttrs(node.props.newTab) },
|
|
246
|
+
children: [node.props.text],
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
return {
|
|
250
|
+
tag: "button",
|
|
251
|
+
attrs: { ...attrs, type: "button" },
|
|
252
|
+
children: [node.props.text],
|
|
253
|
+
};
|
|
254
|
+
},
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
const list: ElementDefinition<ListNode> = {
|
|
258
|
+
baseCss: ".emvb-list{margin:0;padding-inline-start:1.25em}.emvb-list li{margin:0}",
|
|
259
|
+
defaults: () => ({ type: "list", props: { items: ["Item"] } }),
|
|
260
|
+
descriptor: {
|
|
261
|
+
type: "list",
|
|
262
|
+
name: "List",
|
|
263
|
+
group: "content",
|
|
264
|
+
defaultTab: "content",
|
|
265
|
+
fields: [
|
|
266
|
+
{ key: "ordered", kind: "boolean", label: "Numbered list", optional: true },
|
|
267
|
+
{ key: "items", kind: "list-items", label: "Items" },
|
|
268
|
+
],
|
|
269
|
+
},
|
|
270
|
+
build: (node, attrs) => ({
|
|
271
|
+
tag: node.props.ordered ? "ol" : "ul",
|
|
272
|
+
attrs,
|
|
273
|
+
children: node.props.items.map((item) => ({ tag: "li", attrs: {}, children: [item] })),
|
|
274
|
+
}),
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
const image: ElementDefinition<ImageNode> = {
|
|
278
|
+
baseCss: ".emvb-image{display:block;max-width:100%;height:auto}",
|
|
279
|
+
defaults: () => ({
|
|
280
|
+
type: "image",
|
|
281
|
+
props: { src: "", alt: "Image", decorative: false },
|
|
282
|
+
}),
|
|
283
|
+
descriptor: {
|
|
284
|
+
type: "image",
|
|
285
|
+
name: "Image",
|
|
286
|
+
group: "content",
|
|
287
|
+
defaultTab: "content",
|
|
288
|
+
fields: [
|
|
289
|
+
{
|
|
290
|
+
key: "src",
|
|
291
|
+
kind: "media",
|
|
292
|
+
label: "Image",
|
|
293
|
+
message:
|
|
294
|
+
"Use a full URL such as https://example.com/photo.jpg or a path such as /uploads/photo.jpg.",
|
|
295
|
+
},
|
|
296
|
+
{ key: "alt", kind: "text", label: "Alt text" },
|
|
297
|
+
{
|
|
298
|
+
key: "decorative",
|
|
299
|
+
kind: "boolean",
|
|
300
|
+
label: "Decorative (empty alt)",
|
|
301
|
+
optional: true,
|
|
302
|
+
},
|
|
303
|
+
{
|
|
304
|
+
key: "width",
|
|
305
|
+
kind: "int",
|
|
306
|
+
label: "Width (px)",
|
|
307
|
+
optional: true,
|
|
308
|
+
message: "Width must be a positive whole number.",
|
|
309
|
+
},
|
|
310
|
+
{
|
|
311
|
+
key: "height",
|
|
312
|
+
kind: "int",
|
|
313
|
+
label: "Height (px)",
|
|
314
|
+
optional: true,
|
|
315
|
+
message: "Height must be a positive whole number.",
|
|
316
|
+
},
|
|
317
|
+
],
|
|
318
|
+
},
|
|
319
|
+
build: (node, attrs) => {
|
|
320
|
+
const src = sanitizeMediaUrl(node.props.src);
|
|
321
|
+
if (!src) {
|
|
322
|
+
return {
|
|
323
|
+
tag: "span",
|
|
324
|
+
attrs: { ...attrs, class: `${attrs.class ?? ""} emvb-image-missing`.trim() },
|
|
325
|
+
children: [],
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
const decorative = node.props.decorative === true;
|
|
329
|
+
const imgAttrs: Record<string, string> = {
|
|
330
|
+
...attrs,
|
|
331
|
+
src,
|
|
332
|
+
alt: decorative ? "" : node.props.alt,
|
|
333
|
+
loading: "lazy",
|
|
334
|
+
decoding: "async",
|
|
335
|
+
};
|
|
336
|
+
if (decorative) imgAttrs.role = "presentation";
|
|
337
|
+
if (node.props.width !== undefined) imgAttrs.width = String(node.props.width);
|
|
338
|
+
if (node.props.height !== undefined) imgAttrs.height = String(node.props.height);
|
|
339
|
+
return { tag: "img", attrs: imgAttrs, children: [] };
|
|
340
|
+
},
|
|
341
|
+
};
|
|
342
|
+
|
|
343
|
+
const icon: ElementDefinition<IconNode> = {
|
|
344
|
+
baseCss:
|
|
345
|
+
".emvb-icon{display:inline-flex;align-items:center;justify-content:center;line-height:0;color:inherit}.emvb-icon svg{display:block;width:1em;height:1em}.emvb-icon-missing{min-width:1em;min-height:1em;background:var(--color-kumo-tint,#eee)}",
|
|
346
|
+
defaults: () => ({
|
|
347
|
+
type: "icon",
|
|
348
|
+
props: { iconId: "star", title: "Star", decorative: false, size: 24 },
|
|
349
|
+
}),
|
|
350
|
+
descriptor: {
|
|
351
|
+
type: "icon",
|
|
352
|
+
name: "Icon",
|
|
353
|
+
group: "content",
|
|
354
|
+
defaultTab: "content",
|
|
355
|
+
fields: [
|
|
356
|
+
{ key: "iconId", kind: "icon", label: "Icon" },
|
|
357
|
+
{ key: "title", kind: "text", label: "Title" },
|
|
358
|
+
{
|
|
359
|
+
key: "decorative",
|
|
360
|
+
kind: "boolean",
|
|
361
|
+
label: "Decorative (hide from assistive tech)",
|
|
362
|
+
optional: true,
|
|
363
|
+
},
|
|
364
|
+
{
|
|
365
|
+
key: "size",
|
|
366
|
+
kind: "int",
|
|
367
|
+
label: "Size (px)",
|
|
368
|
+
optional: true,
|
|
369
|
+
message: "Size must be a positive whole number.",
|
|
370
|
+
},
|
|
371
|
+
],
|
|
372
|
+
},
|
|
373
|
+
build: (node, attrs) => {
|
|
374
|
+
const bundled = getBundledIcon(node.props.iconId);
|
|
375
|
+
if (!bundled) {
|
|
376
|
+
// Never treat iconId as a URL or raw HTML (R-032 / R-033).
|
|
377
|
+
return {
|
|
378
|
+
tag: "span",
|
|
379
|
+
attrs: {
|
|
380
|
+
...attrs,
|
|
381
|
+
class: `${attrs.class ?? ""} emvb-icon-missing`.trim(),
|
|
382
|
+
"aria-hidden": "true",
|
|
383
|
+
},
|
|
384
|
+
children: [],
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
const decorative = node.props.decorative === true;
|
|
388
|
+
const size = node.props.size ?? 24;
|
|
389
|
+
const svgAttrs: Record<string, string> = {
|
|
390
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
391
|
+
width: String(size),
|
|
392
|
+
height: String(size),
|
|
393
|
+
viewBox: "0 0 24 24",
|
|
394
|
+
fill: "none",
|
|
395
|
+
stroke: "currentColor",
|
|
396
|
+
"stroke-width": "2",
|
|
397
|
+
"stroke-linecap": "round",
|
|
398
|
+
"stroke-linejoin": "round",
|
|
399
|
+
focusable: "false",
|
|
400
|
+
};
|
|
401
|
+
if (decorative) {
|
|
402
|
+
svgAttrs["aria-hidden"] = "true";
|
|
403
|
+
} else {
|
|
404
|
+
svgAttrs.role = "img";
|
|
405
|
+
if (node.props.title) svgAttrs["aria-label"] = node.props.title;
|
|
406
|
+
}
|
|
407
|
+
const children: VNode[] = bundled.children.map((child) => ({
|
|
408
|
+
tag: child.tag,
|
|
409
|
+
attrs: { ...child.attrs },
|
|
410
|
+
children: [],
|
|
411
|
+
}));
|
|
412
|
+
return {
|
|
413
|
+
tag: "span",
|
|
414
|
+
attrs,
|
|
415
|
+
children: [{ tag: "svg", attrs: svgAttrs, children }],
|
|
416
|
+
};
|
|
417
|
+
},
|
|
418
|
+
};
|
|
419
|
+
|
|
420
|
+
const video: ElementDefinition<VideoNode> = {
|
|
421
|
+
baseCss:
|
|
422
|
+
".emvb-video{display:block;max-width:100%;border:0}.emvb-video iframe,.emvb-video video{display:block;width:100%;aspect-ratio:16/9;border:0;background:#000}.emvb-video-missing,.emvb-video-preview{display:flex;align-items:center;justify-content:center;min-height:120px;padding:12px;text-align:center;color:var(--text-color-kumo-subtle,#666);background:var(--color-kumo-tint,#eee)}",
|
|
423
|
+
defaults: () => ({
|
|
424
|
+
type: "video",
|
|
425
|
+
props: { url: "", title: "Video" },
|
|
426
|
+
}),
|
|
427
|
+
descriptor: {
|
|
428
|
+
type: "video",
|
|
429
|
+
name: "Video",
|
|
430
|
+
group: "content",
|
|
431
|
+
defaultTab: "content",
|
|
432
|
+
fields: [
|
|
433
|
+
{
|
|
434
|
+
key: "url",
|
|
435
|
+
kind: "href",
|
|
436
|
+
label: "Video URL",
|
|
437
|
+
message:
|
|
438
|
+
"Use a YouTube or Vimeo link, or a media file path such as /_emdash/api/media/file/….",
|
|
439
|
+
},
|
|
440
|
+
{ key: "title", kind: "text", label: "Title" },
|
|
441
|
+
],
|
|
442
|
+
},
|
|
443
|
+
build: (node, attrs) => {
|
|
444
|
+
const target = resolveEmbedUrl(node.props.url);
|
|
445
|
+
if (!target) {
|
|
446
|
+
return {
|
|
447
|
+
tag: "span",
|
|
448
|
+
attrs: {
|
|
449
|
+
...attrs,
|
|
450
|
+
class: `${attrs.class ?? ""} emvb-video-missing`.trim(),
|
|
451
|
+
"aria-hidden": "true",
|
|
452
|
+
},
|
|
453
|
+
children: [],
|
|
454
|
+
};
|
|
455
|
+
}
|
|
456
|
+
if (target.kind === "iframe") {
|
|
457
|
+
return {
|
|
458
|
+
tag: "iframe",
|
|
459
|
+
attrs: {
|
|
460
|
+
...attrs,
|
|
461
|
+
src: target.src,
|
|
462
|
+
title: node.props.title,
|
|
463
|
+
loading: "lazy",
|
|
464
|
+
referrerpolicy: "strict-origin-when-cross-origin",
|
|
465
|
+
allow: "encrypted-media; picture-in-picture; fullscreen",
|
|
466
|
+
},
|
|
467
|
+
children: [],
|
|
468
|
+
};
|
|
469
|
+
}
|
|
470
|
+
return {
|
|
471
|
+
tag: "video",
|
|
472
|
+
attrs: {
|
|
473
|
+
...attrs,
|
|
474
|
+
src: target.src,
|
|
475
|
+
title: node.props.title,
|
|
476
|
+
controls: "",
|
|
477
|
+
preload: "metadata",
|
|
478
|
+
},
|
|
479
|
+
children: [],
|
|
480
|
+
};
|
|
481
|
+
},
|
|
482
|
+
};
|
|
483
|
+
|
|
484
|
+
const DEFAULT_SVG =
|
|
485
|
+
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><path d="M8 12h8"/></svg>';
|
|
486
|
+
|
|
487
|
+
const svgEl: ElementDefinition<SvgNode> = {
|
|
488
|
+
baseCss:
|
|
489
|
+
".emvb-svg{display:inline-flex;align-items:center;justify-content:center;line-height:0;color:inherit}.emvb-svg svg{display:block;width:1em;height:1em}.emvb-svg-missing{min-width:1em;min-height:1em;background:var(--color-kumo-tint,#eee)}",
|
|
490
|
+
defaults: () => ({
|
|
491
|
+
type: "svg",
|
|
492
|
+
props: { markup: DEFAULT_SVG, title: "SVG", decorative: false, size: 48 },
|
|
493
|
+
}),
|
|
494
|
+
descriptor: {
|
|
495
|
+
type: "svg",
|
|
496
|
+
name: "SVG",
|
|
497
|
+
group: "content",
|
|
498
|
+
defaultTab: "content",
|
|
499
|
+
fields: [
|
|
500
|
+
{
|
|
501
|
+
key: "markup",
|
|
502
|
+
kind: "textarea",
|
|
503
|
+
label: "SVG markup",
|
|
504
|
+
message: "Paste safe SVG only (no scripts or external links).",
|
|
505
|
+
},
|
|
506
|
+
{ key: "title", kind: "text", label: "Title", optional: true },
|
|
507
|
+
{
|
|
508
|
+
key: "decorative",
|
|
509
|
+
kind: "boolean",
|
|
510
|
+
label: "Decorative (hide from assistive tech)",
|
|
511
|
+
optional: true,
|
|
512
|
+
},
|
|
513
|
+
{
|
|
514
|
+
key: "size",
|
|
515
|
+
kind: "int",
|
|
516
|
+
label: "Size (px)",
|
|
517
|
+
optional: true,
|
|
518
|
+
message: "Size must be a positive whole number.",
|
|
519
|
+
},
|
|
520
|
+
],
|
|
521
|
+
},
|
|
522
|
+
build: (node, attrs) => {
|
|
523
|
+
const tree = sanitizeSvgMarkup(node.props.markup);
|
|
524
|
+
if (!tree) {
|
|
525
|
+
return {
|
|
526
|
+
tag: "span",
|
|
527
|
+
attrs: {
|
|
528
|
+
...attrs,
|
|
529
|
+
class: `${attrs.class ?? ""} emvb-svg-missing`.trim(),
|
|
530
|
+
"aria-hidden": "true",
|
|
531
|
+
},
|
|
532
|
+
children: [],
|
|
533
|
+
};
|
|
534
|
+
}
|
|
535
|
+
const size = node.props.size ?? 48;
|
|
536
|
+
const decorative = node.props.decorative === true;
|
|
537
|
+
const svgAttrs: Record<string, string> = {
|
|
538
|
+
...tree.attrs,
|
|
539
|
+
xmlns: tree.attrs.xmlns ?? "http://www.w3.org/2000/svg",
|
|
540
|
+
width: String(size),
|
|
541
|
+
height: String(size),
|
|
542
|
+
focusable: "false",
|
|
543
|
+
};
|
|
544
|
+
if (!svgAttrs.fill && !svgAttrs.stroke) {
|
|
545
|
+
svgAttrs.fill = "currentColor";
|
|
546
|
+
}
|
|
547
|
+
if (decorative) {
|
|
548
|
+
svgAttrs["aria-hidden"] = "true";
|
|
549
|
+
} else {
|
|
550
|
+
svgAttrs.role = "img";
|
|
551
|
+
if (node.props.title) svgAttrs["aria-label"] = node.props.title;
|
|
552
|
+
}
|
|
553
|
+
return {
|
|
554
|
+
tag: "span",
|
|
555
|
+
attrs,
|
|
556
|
+
children: [{ tag: "svg", attrs: svgAttrs, children: tree.children }],
|
|
557
|
+
};
|
|
558
|
+
},
|
|
559
|
+
};
|
|
560
|
+
|
|
561
|
+
const tabPanel: ElementDefinition<TabPanelNode> = {
|
|
562
|
+
baseCss: "",
|
|
563
|
+
defaults: () => ({
|
|
564
|
+
type: "tab-panel",
|
|
565
|
+
props: { label: "Tab" },
|
|
566
|
+
children: [],
|
|
567
|
+
}),
|
|
568
|
+
descriptor: {
|
|
569
|
+
type: "tab-panel",
|
|
570
|
+
name: "Tab panel",
|
|
571
|
+
group: "layout",
|
|
572
|
+
defaultTab: "content",
|
|
573
|
+
fields: [{ key: "label", kind: "text", label: "Tab label" }],
|
|
574
|
+
},
|
|
575
|
+
build: (_node, attrs, children) => ({ tag: "div", attrs, children }),
|
|
576
|
+
};
|
|
577
|
+
|
|
578
|
+
const tabs: ElementDefinition<TabsNode> = {
|
|
579
|
+
baseCss:
|
|
580
|
+
".emvb-tabs{display:flex;flex-direction:column;min-width:0;gap:0}.emvb-tab-input{position:absolute;opacity:0;pointer-events:none;width:1px;height:1px}.emvb-tab-list{display:flex;flex-wrap:wrap;gap:0;border-bottom:1px solid currentColor;margin:0;padding:0}.emvb-tab-label{display:inline-block;padding:8px 12px;cursor:pointer;border-bottom:2px solid transparent;margin-bottom:-1px}.emvb-tab-panels{min-width:0}.emvb-tab-panel{display:none;padding-top:12px;min-width:0}.emvb-tabs:has(> .emvb-tab-input:nth-of-type(1):checked) > .emvb-tab-list > .emvb-tab-label:nth-of-type(1){border-bottom-color:currentColor;font-weight:600}.emvb-tabs:has(> .emvb-tab-input:nth-of-type(1):checked) > .emvb-tab-panels > .emvb-tab-panel:nth-of-type(1){display:block}.emvb-tabs:has(> .emvb-tab-input:nth-of-type(2):checked) > .emvb-tab-list > .emvb-tab-label:nth-of-type(2){border-bottom-color:currentColor;font-weight:600}.emvb-tabs:has(> .emvb-tab-input:nth-of-type(2):checked) > .emvb-tab-panels > .emvb-tab-panel:nth-of-type(2){display:block}.emvb-tabs:has(> .emvb-tab-input:nth-of-type(3):checked) > .emvb-tab-list > .emvb-tab-label:nth-of-type(3){border-bottom-color:currentColor;font-weight:600}.emvb-tabs:has(> .emvb-tab-input:nth-of-type(3):checked) > .emvb-tab-panels > .emvb-tab-panel:nth-of-type(3){display:block}.emvb-tabs:has(> .emvb-tab-input:nth-of-type(4):checked) > .emvb-tab-list > .emvb-tab-label:nth-of-type(4){border-bottom-color:currentColor;font-weight:600}.emvb-tabs:has(> .emvb-tab-input:nth-of-type(4):checked) > .emvb-tab-panels > .emvb-tab-panel:nth-of-type(4){display:block}.emvb-tabs:has(> .emvb-tab-input:nth-of-type(5):checked) > .emvb-tab-list > .emvb-tab-label:nth-of-type(5){border-bottom-color:currentColor;font-weight:600}.emvb-tabs:has(> .emvb-tab-input:nth-of-type(5):checked) > .emvb-tab-panels > .emvb-tab-panel:nth-of-type(5){display:block}.emvb-tabs:has(> .emvb-tab-input:nth-of-type(6):checked) > .emvb-tab-list > .emvb-tab-label:nth-of-type(6){border-bottom-color:currentColor;font-weight:600}.emvb-tabs:has(> .emvb-tab-input:nth-of-type(6):checked) > .emvb-tab-panels > .emvb-tab-panel:nth-of-type(6){display:block}.emvb-tabs:has(> .emvb-tab-input:nth-of-type(7):checked) > .emvb-tab-list > .emvb-tab-label:nth-of-type(7){border-bottom-color:currentColor;font-weight:600}.emvb-tabs:has(> .emvb-tab-input:nth-of-type(7):checked) > .emvb-tab-panels > .emvb-tab-panel:nth-of-type(7){display:block}.emvb-tabs:has(> .emvb-tab-input:nth-of-type(8):checked) > .emvb-tab-list > .emvb-tab-label:nth-of-type(8){border-bottom-color:currentColor;font-weight:600}.emvb-tabs:has(> .emvb-tab-input:nth-of-type(8):checked) > .emvb-tab-panels > .emvb-tab-panel:nth-of-type(8){display:block}.emvb-tabs:has(> .emvb-tab-input:nth-of-type(9):checked) > .emvb-tab-list > .emvb-tab-label:nth-of-type(9){border-bottom-color:currentColor;font-weight:600}.emvb-tabs:has(> .emvb-tab-input:nth-of-type(9):checked) > .emvb-tab-panels > .emvb-tab-panel:nth-of-type(9){display:block}.emvb-tabs:has(> .emvb-tab-input:nth-of-type(10):checked) > .emvb-tab-list > .emvb-tab-label:nth-of-type(10){border-bottom-color:currentColor;font-weight:600}.emvb-tabs:has(> .emvb-tab-input:nth-of-type(10):checked) > .emvb-tab-panels > .emvb-tab-panel:nth-of-type(10){display:block}.emvb-tabs:has(> .emvb-tab-input:nth-of-type(11):checked) > .emvb-tab-list > .emvb-tab-label:nth-of-type(11){border-bottom-color:currentColor;font-weight:600}.emvb-tabs:has(> .emvb-tab-input:nth-of-type(11):checked) > .emvb-tab-panels > .emvb-tab-panel:nth-of-type(11){display:block}.emvb-tabs:has(> .emvb-tab-input:nth-of-type(12):checked) > .emvb-tab-list > .emvb-tab-label:nth-of-type(12){border-bottom-color:currentColor;font-weight:600}.emvb-tabs:has(> .emvb-tab-input:nth-of-type(12):checked) > .emvb-tab-panels > .emvb-tab-panel:nth-of-type(12){display:block}",
|
|
581
|
+
defaults: () => ({
|
|
582
|
+
type: "tabs",
|
|
583
|
+
props: {},
|
|
584
|
+
children: [],
|
|
585
|
+
}),
|
|
586
|
+
descriptor: {
|
|
587
|
+
type: "tabs",
|
|
588
|
+
name: "Tabs",
|
|
589
|
+
group: "layout",
|
|
590
|
+
defaultTab: "content",
|
|
591
|
+
fields: [],
|
|
592
|
+
},
|
|
593
|
+
// Real markup is assembled in render (needs panel labels from nodes).
|
|
594
|
+
build: (_node, attrs, children) => ({ tag: "div", attrs, children }),
|
|
595
|
+
};
|
|
596
|
+
|
|
597
|
+
const divBlock: ElementDefinition<DivBlockNode> = {
|
|
598
|
+
baseCss: ".emvb-div-block{display:block;min-width:0}",
|
|
599
|
+
defaults: () => ({ type: "div-block", props: {}, children: [] }),
|
|
600
|
+
descriptor: {
|
|
601
|
+
type: "div-block",
|
|
602
|
+
name: "Div Block",
|
|
603
|
+
group: "layout",
|
|
604
|
+
defaultTab: "style",
|
|
605
|
+
fields: BOX_LINK_FIELDS,
|
|
606
|
+
},
|
|
607
|
+
build: (_node, attrs, children) => ({ tag: "div", attrs, children }),
|
|
608
|
+
};
|
|
609
|
+
|
|
610
|
+
const grid: ElementDefinition<GridNode> = {
|
|
611
|
+
baseCss: ".emvb-grid{display:grid;min-width:0}",
|
|
612
|
+
defaults: () => ({ type: "grid", props: { columns: 3 }, children: [] }),
|
|
613
|
+
descriptor: {
|
|
614
|
+
type: "grid",
|
|
615
|
+
name: "Grid",
|
|
616
|
+
group: "layout",
|
|
617
|
+
defaultTab: "content",
|
|
618
|
+
fields: [
|
|
619
|
+
{
|
|
620
|
+
key: "columns",
|
|
621
|
+
kind: "select",
|
|
622
|
+
label: "Columns",
|
|
623
|
+
options: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12].map((n) => ({
|
|
624
|
+
value: n,
|
|
625
|
+
label: String(n),
|
|
626
|
+
})),
|
|
627
|
+
},
|
|
628
|
+
...BOX_LINK_FIELDS,
|
|
629
|
+
],
|
|
630
|
+
},
|
|
631
|
+
build: (_node, attrs, children) => ({ tag: "div", attrs, children }),
|
|
632
|
+
};
|
|
633
|
+
|
|
634
|
+
const flexbox: ElementDefinition<FlexboxNode> = {
|
|
635
|
+
baseCss:
|
|
636
|
+
".emvb-flexbox{display:flex;flex-direction:row;flex-wrap:wrap;align-items:stretch;min-width:0;gap:16px}",
|
|
637
|
+
defaults: () => ({
|
|
638
|
+
type: "flexbox",
|
|
639
|
+
props: {},
|
|
640
|
+
style: { flexDirection: "row", flexWrap: "wrap", gap: { value: 16, unit: "px" } },
|
|
641
|
+
children: [],
|
|
642
|
+
}),
|
|
643
|
+
descriptor: {
|
|
644
|
+
type: "flexbox",
|
|
645
|
+
name: "Flexbox",
|
|
646
|
+
group: "layout",
|
|
647
|
+
defaultTab: "style",
|
|
648
|
+
fields: BOX_LINK_FIELDS,
|
|
649
|
+
},
|
|
650
|
+
build: (_node, attrs, children) => ({ tag: "div", attrs, children }),
|
|
651
|
+
};
|
|
652
|
+
|
|
653
|
+
const accordion: ElementDefinition<AccordionNode> = {
|
|
654
|
+
baseCss:
|
|
655
|
+
".emvb-accordion{display:flex;flex-direction:column;min-width:0}.emvb-accordion-item{border-bottom:1px solid currentColor}.emvb-accordion-item>summary{cursor:pointer;padding:12px 0;font-weight:600}.emvb-accordion-body{padding:0 0 12px}",
|
|
656
|
+
defaults: () => ({ type: "accordion", props: {}, children: [] }),
|
|
657
|
+
descriptor: {
|
|
658
|
+
type: "accordion",
|
|
659
|
+
name: "Accordion",
|
|
660
|
+
group: "layout",
|
|
661
|
+
defaultTab: "content",
|
|
662
|
+
fields: [],
|
|
663
|
+
},
|
|
664
|
+
build: (_node, attrs, children) => ({ tag: "div", attrs, children }),
|
|
665
|
+
};
|
|
666
|
+
|
|
667
|
+
const accordionItem: ElementDefinition<AccordionItemNode> = {
|
|
668
|
+
baseCss: "",
|
|
669
|
+
defaults: () => ({ type: "accordion-item", props: { summary: "Title" }, children: [] }),
|
|
670
|
+
descriptor: {
|
|
671
|
+
type: "accordion-item",
|
|
672
|
+
name: "Accordion item",
|
|
673
|
+
group: "layout",
|
|
674
|
+
defaultTab: "content",
|
|
675
|
+
fields: [
|
|
676
|
+
{ key: "summary", kind: "text", label: "Title" },
|
|
677
|
+
{ key: "open", kind: "boolean", label: "Open", optional: true },
|
|
678
|
+
],
|
|
679
|
+
},
|
|
680
|
+
build: (node, attrs, children) => {
|
|
681
|
+
const summary: VNode = { tag: "summary", attrs: {}, children: [node.props.summary] };
|
|
682
|
+
const body: VNode = { tag: "div", attrs: { class: "emvb-accordion-body" }, children };
|
|
683
|
+
return {
|
|
684
|
+
tag: "details",
|
|
685
|
+
attrs: node.props.open ? { ...attrs, open: "" } : attrs,
|
|
686
|
+
children: [summary, body],
|
|
687
|
+
};
|
|
688
|
+
},
|
|
689
|
+
};
|
|
690
|
+
|
|
691
|
+
export const ELEMENTS = {
|
|
692
|
+
heading,
|
|
693
|
+
container,
|
|
694
|
+
spacer,
|
|
695
|
+
divider,
|
|
696
|
+
text,
|
|
697
|
+
label,
|
|
698
|
+
link,
|
|
699
|
+
button,
|
|
700
|
+
list,
|
|
701
|
+
image,
|
|
702
|
+
icon,
|
|
703
|
+
video,
|
|
704
|
+
form,
|
|
705
|
+
"text-input": textInput,
|
|
706
|
+
textarea: textareaEl,
|
|
707
|
+
select: selectEl,
|
|
708
|
+
checkbox,
|
|
709
|
+
radio,
|
|
710
|
+
submit,
|
|
711
|
+
"post-title": postTitle,
|
|
712
|
+
"post-excerpt": postExcerpt,
|
|
713
|
+
"post-content": postContent,
|
|
714
|
+
"post-image": postImage,
|
|
715
|
+
"post-link": postLink,
|
|
716
|
+
"post-date": postDate,
|
|
717
|
+
"post-author": postAuthor,
|
|
718
|
+
loop,
|
|
719
|
+
section,
|
|
720
|
+
"div-block": divBlock,
|
|
721
|
+
flexbox,
|
|
722
|
+
grid,
|
|
723
|
+
svg: svgEl,
|
|
724
|
+
tabs,
|
|
725
|
+
"tab-panel": tabPanel,
|
|
726
|
+
accordion,
|
|
727
|
+
"accordion-item": accordionItem,
|
|
728
|
+
} as const;
|
|
729
|
+
|
|
730
|
+
export type ElementType = keyof typeof ELEMENTS;
|
|
731
|
+
|
|
732
|
+
export const ELEMENT_DESCRIPTORS: ElementDescriptor[] = Object.values(ELEMENTS).map(
|
|
733
|
+
(el) => el.descriptor,
|
|
734
|
+
);
|
|
735
|
+
|
|
736
|
+
export function defaultElement<T extends ElementType>(
|
|
737
|
+
type: T,
|
|
738
|
+
id: string,
|
|
739
|
+
): (typeof ELEMENTS)[T] extends ElementDefinition<infer N> ? N : never {
|
|
740
|
+
const base = ELEMENTS[type].defaults() as { type: string };
|
|
741
|
+
return { id, ...base } as never;
|
|
742
|
+
}
|