@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,960 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ButtonNode,
|
|
3
|
+
ContainerNode,
|
|
4
|
+
DivBlockNode,
|
|
5
|
+
LayoutSectionNode,
|
|
6
|
+
FlexboxNode,
|
|
7
|
+
GridNode,
|
|
8
|
+
SvgNode,
|
|
9
|
+
TabsNode,
|
|
10
|
+
TabPanelNode,
|
|
11
|
+
AccordionNode,
|
|
12
|
+
AccordionItemNode,
|
|
13
|
+
DividerNode,
|
|
14
|
+
HeadingNode,
|
|
15
|
+
IconNode,
|
|
16
|
+
ImageNode,
|
|
17
|
+
LabelNode,
|
|
18
|
+
LinkNode,
|
|
19
|
+
ListNode,
|
|
20
|
+
SpacerNode,
|
|
21
|
+
TextNode,
|
|
22
|
+
VideoNode,
|
|
23
|
+
} from "../schema/layout.ts";
|
|
24
|
+
import { CONTAINER_TAGS, TEXT_TAGS } from "../schema/layout.ts";
|
|
25
|
+
import type { ElementDescriptor } from "../schema/descriptors.ts";
|
|
26
|
+
import { sanitizeHref } from "../sanitize/href.ts";
|
|
27
|
+
import { sanitizeSvgMarkup } from "../sanitize/svg.ts";
|
|
28
|
+
import { sanitizeMediaUrl } from "../sanitize/media-url.ts";
|
|
29
|
+
import { getBundledIcon } from "../icons/catalog.ts";
|
|
30
|
+
import { resolveEmbedUrl } from "../sanitize/embed-url.ts";
|
|
31
|
+
import type { VNode } from "../render/vnode.ts";
|
|
32
|
+
|
|
33
|
+
import type { ElementDefinition } from "./definition.ts";
|
|
34
|
+
import { menu, menuItem } from "./menu.ts";
|
|
35
|
+
import { checkbox, form, radio, selectEl, submit, textInput, textareaEl } from "./form-elements.ts";
|
|
36
|
+
import {
|
|
37
|
+
loop,
|
|
38
|
+
pagination,
|
|
39
|
+
section,
|
|
40
|
+
postContent,
|
|
41
|
+
postExcerpt,
|
|
42
|
+
postImage,
|
|
43
|
+
postLink,
|
|
44
|
+
postTitle,
|
|
45
|
+
postDate,
|
|
46
|
+
postAuthor,
|
|
47
|
+
} from "./dynamic-elements.ts";
|
|
48
|
+
|
|
49
|
+
const HEADING_TAGS = ["h1", "h2", "h3", "h4", "h5", "h6"] as const;
|
|
50
|
+
|
|
51
|
+
const newTabAttrs = (newTab: boolean | undefined): Record<string, string> =>
|
|
52
|
+
newTab ? { target: "_blank", rel: "noopener noreferrer" } : {};
|
|
53
|
+
|
|
54
|
+
const LINK_MESSAGE = "Use a full URL such as https://example.com or a path such as /pricing.";
|
|
55
|
+
|
|
56
|
+
/** Optional Link and new-tab fields for elements that wrap their content in a link (W-141). */
|
|
57
|
+
const INNER_LINK_FIELDS = [
|
|
58
|
+
{ key: "href", kind: "href" as const, label: "Link", optional: true, message: LINK_MESSAGE },
|
|
59
|
+
{ key: "newTab", kind: "boolean" as const, label: "Open in a new tab", optional: true },
|
|
60
|
+
];
|
|
61
|
+
|
|
62
|
+
/** The safe link for an optional href, or undefined when there is none or it is refused. */
|
|
63
|
+
const innerLink = (
|
|
64
|
+
href: string | undefined,
|
|
65
|
+
newTab: boolean | undefined,
|
|
66
|
+
className: string,
|
|
67
|
+
children: VNode["children"],
|
|
68
|
+
extra: Record<string, string> = {},
|
|
69
|
+
): VNode | undefined => {
|
|
70
|
+
const safe = href?.trim() ? sanitizeHref(href) : undefined;
|
|
71
|
+
if (!safe) return undefined;
|
|
72
|
+
return {
|
|
73
|
+
tag: "a",
|
|
74
|
+
attrs: { class: className, href: safe, ...newTabAttrs(newTab), ...extra },
|
|
75
|
+
children,
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const heading: ElementDefinition<HeadingNode> = {
|
|
80
|
+
baseCss: ".emvb-heading{margin:0}.emvb-heading-link{color:inherit;text-decoration:inherit}",
|
|
81
|
+
defaults: () => ({ type: "heading", props: { text: "Heading", level: 2 } }),
|
|
82
|
+
descriptor: {
|
|
83
|
+
type: "heading",
|
|
84
|
+
name: "Heading",
|
|
85
|
+
group: "content",
|
|
86
|
+
defaultTab: "content",
|
|
87
|
+
fields: [
|
|
88
|
+
{ key: "text", kind: "text", label: "Text" },
|
|
89
|
+
{
|
|
90
|
+
key: "level",
|
|
91
|
+
kind: "select",
|
|
92
|
+
label: "Level",
|
|
93
|
+
options: [1, 2, 3, 4, 5, 6].map((n) => ({ value: n, label: `H${n}` })),
|
|
94
|
+
},
|
|
95
|
+
...INNER_LINK_FIELDS,
|
|
96
|
+
],
|
|
97
|
+
},
|
|
98
|
+
build: (node, attrs) => {
|
|
99
|
+
const linked = innerLink(node.props.href, node.props.newTab, "emvb-heading-link", [
|
|
100
|
+
node.props.text,
|
|
101
|
+
]);
|
|
102
|
+
return {
|
|
103
|
+
tag: HEADING_TAGS[node.props.level - 1] ?? "h2",
|
|
104
|
+
attrs,
|
|
105
|
+
children: [linked ?? node.props.text],
|
|
106
|
+
};
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
/** A box link is checked like any link, so a bad URL gets an inline error, not a silent drop (W-176). */
|
|
111
|
+
const BOX_LINK_FIELDS = [
|
|
112
|
+
{ key: "href", kind: "href" as const, label: "Link", optional: true, message: LINK_MESSAGE },
|
|
113
|
+
{ key: "newTab", kind: "boolean" as const, label: "Open in new tab", optional: true },
|
|
114
|
+
];
|
|
115
|
+
|
|
116
|
+
const container: ElementDefinition<ContainerNode> = {
|
|
117
|
+
// W-299: a word longer than the line (a pasted URL) breaks instead of widening the page on a phone.
|
|
118
|
+
baseCss:
|
|
119
|
+
".emvb-container{display:flex;flex-direction:column;min-width:0;overflow-wrap:break-word}",
|
|
120
|
+
defaults: () => ({ type: "container", props: {}, children: [] }),
|
|
121
|
+
descriptor: {
|
|
122
|
+
type: "container",
|
|
123
|
+
name: "Container",
|
|
124
|
+
group: "layout",
|
|
125
|
+
defaultTab: "style",
|
|
126
|
+
fields: [
|
|
127
|
+
{
|
|
128
|
+
key: "tag",
|
|
129
|
+
kind: "select",
|
|
130
|
+
label: "HTML tag",
|
|
131
|
+
optional: true,
|
|
132
|
+
options: CONTAINER_TAGS.map((tag) => ({ value: tag, label: tag })),
|
|
133
|
+
message: "Pick a landmark or div.",
|
|
134
|
+
},
|
|
135
|
+
...BOX_LINK_FIELDS,
|
|
136
|
+
],
|
|
137
|
+
},
|
|
138
|
+
build: (node, attrs, children) => {
|
|
139
|
+
const tag = node.props.tag ?? "div";
|
|
140
|
+
const safe = (CONTAINER_TAGS as readonly string[]).includes(tag) ? tag : "div";
|
|
141
|
+
return { tag: safe, attrs, children };
|
|
142
|
+
},
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
const spacer: ElementDefinition<SpacerNode> = {
|
|
146
|
+
baseCss: ".emvb-spacer{flex-shrink:0}",
|
|
147
|
+
defaults: () => ({ type: "spacer", props: { height: { value: 24, unit: "px" } } }),
|
|
148
|
+
descriptor: {
|
|
149
|
+
type: "spacer",
|
|
150
|
+
name: "Spacer",
|
|
151
|
+
group: "layout",
|
|
152
|
+
defaultTab: "style",
|
|
153
|
+
fields: [
|
|
154
|
+
{
|
|
155
|
+
key: "height",
|
|
156
|
+
kind: "number",
|
|
157
|
+
label: "Height",
|
|
158
|
+
message: "Height can't be negative. Enter 0 or more.",
|
|
159
|
+
},
|
|
160
|
+
],
|
|
161
|
+
},
|
|
162
|
+
build: (_node, attrs) => ({
|
|
163
|
+
tag: "div",
|
|
164
|
+
attrs: { ...attrs, "aria-hidden": "true" },
|
|
165
|
+
children: [],
|
|
166
|
+
}),
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
const divider: ElementDefinition<DividerNode> = {
|
|
170
|
+
// W-266: full width by default; an <hr> has no content width, so in a centred column it was 0 wide.
|
|
171
|
+
baseCss:
|
|
172
|
+
// W-270: a Divider is its top border. Border style on the other sides stays none (the tag in
|
|
173
|
+
// the selector outranks an element's class), so "dashed" draws a dashed line, not a box.
|
|
174
|
+
".emvb-divider{border:0;border-top:1px solid currentColor;margin:0}:where(.emvb-divider){width:100%}hr.emvb-divider{border-right-style:none;border-bottom-style:none;border-left-style:none}",
|
|
175
|
+
defaults: () => ({ type: "divider", props: {} }),
|
|
176
|
+
descriptor: {
|
|
177
|
+
type: "divider",
|
|
178
|
+
name: "Divider",
|
|
179
|
+
group: "layout",
|
|
180
|
+
defaultTab: "style",
|
|
181
|
+
fields: [],
|
|
182
|
+
},
|
|
183
|
+
build: (_node, attrs) => ({ tag: "hr", attrs, children: [] }),
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
const text: ElementDefinition<TextNode> = {
|
|
187
|
+
// W-264: a paragraph's line breaks show (pre-line), in :where() so classes and styles win.
|
|
188
|
+
baseCss: ".emvb-text{margin:0}:where(.emvb-text){white-space:pre-line}",
|
|
189
|
+
defaults: () => ({ type: "text", props: { text: "Text" } }),
|
|
190
|
+
descriptor: {
|
|
191
|
+
type: "text",
|
|
192
|
+
name: "Text",
|
|
193
|
+
group: "content",
|
|
194
|
+
defaultTab: "content",
|
|
195
|
+
fields: [
|
|
196
|
+
{ key: "text", kind: "textarea", label: "Text" },
|
|
197
|
+
{
|
|
198
|
+
key: "tag",
|
|
199
|
+
kind: "select",
|
|
200
|
+
label: "HTML tag",
|
|
201
|
+
optional: true,
|
|
202
|
+
options: TEXT_TAGS.map((tag) => ({ value: tag, label: tag })),
|
|
203
|
+
},
|
|
204
|
+
],
|
|
205
|
+
},
|
|
206
|
+
build: (node, attrs) => {
|
|
207
|
+
const tag = node.props.tag ?? "p";
|
|
208
|
+
const safe = (TEXT_TAGS as readonly string[]).includes(tag) ? tag : "p";
|
|
209
|
+
return { tag: safe, attrs, children: [node.props.text] };
|
|
210
|
+
},
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
const label: ElementDefinition<LabelNode> = {
|
|
214
|
+
baseCss: ".emvb-label{display:inline}",
|
|
215
|
+
defaults: () => ({ type: "label", props: { text: "Label" } }),
|
|
216
|
+
descriptor: {
|
|
217
|
+
type: "label",
|
|
218
|
+
name: "Label",
|
|
219
|
+
group: "content",
|
|
220
|
+
defaultTab: "content",
|
|
221
|
+
fields: [{ key: "text", kind: "text", label: "Text" }],
|
|
222
|
+
},
|
|
223
|
+
build: (node, attrs) => ({ tag: "span", attrs, children: [node.props.text] }),
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
const link: ElementDefinition<LinkNode> = {
|
|
227
|
+
baseCss: ".emvb-link{}",
|
|
228
|
+
defaults: () => ({ type: "link", props: { text: "Link", href: "/" } }),
|
|
229
|
+
descriptor: {
|
|
230
|
+
type: "link",
|
|
231
|
+
name: "Link",
|
|
232
|
+
group: "content",
|
|
233
|
+
defaultTab: "content",
|
|
234
|
+
fields: [
|
|
235
|
+
{ key: "text", kind: "text", label: "Text" },
|
|
236
|
+
{
|
|
237
|
+
key: "href",
|
|
238
|
+
kind: "href",
|
|
239
|
+
label: "URL",
|
|
240
|
+
message: "Use a full URL such as https://example.com or a path such as /pricing.",
|
|
241
|
+
},
|
|
242
|
+
{ key: "newTab", kind: "boolean", label: "Open in a new tab", optional: true },
|
|
243
|
+
],
|
|
244
|
+
},
|
|
245
|
+
build: (node, attrs) => {
|
|
246
|
+
const safe = sanitizeHref(node.props.href);
|
|
247
|
+
// W-276: without a usable URL the link falls back to "#", which mustn't open a new tab.
|
|
248
|
+
return {
|
|
249
|
+
tag: "a",
|
|
250
|
+
attrs: { ...attrs, href: safe ?? "#", ...(safe ? newTabAttrs(node.props.newTab) : {}) },
|
|
251
|
+
children: [node.props.text],
|
|
252
|
+
};
|
|
253
|
+
},
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
const button: ElementDefinition<ButtonNode> = {
|
|
257
|
+
baseCss:
|
|
258
|
+
// The look sits in :where() so site tag defaults, classes and local styles all win (W-148).
|
|
259
|
+
".emvb-button{display:inline-flex;align-items:center;justify-content:center;margin:0;font:inherit;text-decoration:none;cursor:pointer}:where(.emvb-button){color:inherit;background:transparent;border:1px solid currentColor;border-radius:6px;padding:0.625em 1.25em;line-height:1.2}",
|
|
260
|
+
defaults: () => ({ type: "button", props: { text: "Button" } }),
|
|
261
|
+
descriptor: {
|
|
262
|
+
type: "button",
|
|
263
|
+
name: "Button",
|
|
264
|
+
group: "content",
|
|
265
|
+
defaultTab: "content",
|
|
266
|
+
fields: [
|
|
267
|
+
{ key: "text", kind: "text", label: "Text" },
|
|
268
|
+
{
|
|
269
|
+
key: "href",
|
|
270
|
+
kind: "href",
|
|
271
|
+
label: "URL",
|
|
272
|
+
optional: true,
|
|
273
|
+
message: "Use a full URL such as https://example.com or a path such as /pricing.",
|
|
274
|
+
},
|
|
275
|
+
{ key: "newTab", kind: "boolean", label: "Open in a new tab", optional: true },
|
|
276
|
+
],
|
|
277
|
+
},
|
|
278
|
+
build: (node, attrs) => {
|
|
279
|
+
const href = node.props.href !== undefined ? sanitizeHref(node.props.href) : undefined;
|
|
280
|
+
if (href) {
|
|
281
|
+
return {
|
|
282
|
+
tag: "a",
|
|
283
|
+
attrs: { ...attrs, href, ...newTabAttrs(node.props.newTab) },
|
|
284
|
+
children: [node.props.text],
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
return {
|
|
288
|
+
tag: "button",
|
|
289
|
+
attrs: { ...attrs, type: "button" },
|
|
290
|
+
children: [node.props.text],
|
|
291
|
+
};
|
|
292
|
+
},
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
const list: ElementDefinition<ListNode> = {
|
|
296
|
+
baseCss: ".emvb-list{margin:0;padding-inline-start:1.25em}.emvb-list li{margin:0}",
|
|
297
|
+
defaults: () => ({ type: "list", props: { items: ["Item"] } }),
|
|
298
|
+
descriptor: {
|
|
299
|
+
type: "list",
|
|
300
|
+
name: "List",
|
|
301
|
+
group: "content",
|
|
302
|
+
defaultTab: "content",
|
|
303
|
+
fields: [
|
|
304
|
+
{ key: "ordered", kind: "boolean", label: "Numbered list", optional: true },
|
|
305
|
+
{ key: "items", kind: "list-items", label: "Items" },
|
|
306
|
+
],
|
|
307
|
+
},
|
|
308
|
+
build: (node, attrs) => ({
|
|
309
|
+
tag: node.props.ordered ? "ol" : "ul",
|
|
310
|
+
attrs,
|
|
311
|
+
// W-275: blank items would be empty bullets on the page; a list of only blanks has none.
|
|
312
|
+
children: node.props.items
|
|
313
|
+
.filter((item) => item.trim() !== "")
|
|
314
|
+
.map((item) => ({ tag: "li", attrs: {}, children: [item] })),
|
|
315
|
+
}),
|
|
316
|
+
};
|
|
317
|
+
|
|
318
|
+
const image: ElementDefinition<ImageNode> = {
|
|
319
|
+
// W-269: natural size, at most the container's width. A container's default stretch made a
|
|
320
|
+
// 400 px image 1184 px wide (blurry); a Width (px) attribute or a style width still sets it.
|
|
321
|
+
baseCss:
|
|
322
|
+
".emvb-image{display:block;max-width:100%;height:auto}:where(img.emvb-image:not([width])){width:fit-content}",
|
|
323
|
+
defaults: () => ({
|
|
324
|
+
type: "image",
|
|
325
|
+
props: { src: "", alt: "Image", decorative: false },
|
|
326
|
+
}),
|
|
327
|
+
descriptor: {
|
|
328
|
+
type: "image",
|
|
329
|
+
name: "Image",
|
|
330
|
+
group: "content",
|
|
331
|
+
defaultTab: "content",
|
|
332
|
+
fields: [
|
|
333
|
+
{
|
|
334
|
+
key: "src",
|
|
335
|
+
kind: "media",
|
|
336
|
+
label: "Image",
|
|
337
|
+
message:
|
|
338
|
+
"Use a full URL such as https://example.com/photo.jpg or a path such as /uploads/photo.jpg.",
|
|
339
|
+
},
|
|
340
|
+
{ key: "alt", kind: "text", label: "Alt text" },
|
|
341
|
+
{
|
|
342
|
+
key: "decorative",
|
|
343
|
+
kind: "boolean",
|
|
344
|
+
label: "Decorative (empty alt)",
|
|
345
|
+
optional: true,
|
|
346
|
+
},
|
|
347
|
+
// The first big image people see (hero, LCP) shouldn't wait for lazy loading (W-226).
|
|
348
|
+
{ key: "priority", kind: "boolean", label: "Load right away", optional: true },
|
|
349
|
+
{
|
|
350
|
+
key: "width",
|
|
351
|
+
kind: "int",
|
|
352
|
+
label: "Width (px)",
|
|
353
|
+
optional: true,
|
|
354
|
+
message: "Width must be a positive whole number.",
|
|
355
|
+
},
|
|
356
|
+
{
|
|
357
|
+
key: "height",
|
|
358
|
+
kind: "int",
|
|
359
|
+
label: "Height (px)",
|
|
360
|
+
optional: true,
|
|
361
|
+
message: "Height must be a positive whole number.",
|
|
362
|
+
},
|
|
363
|
+
],
|
|
364
|
+
},
|
|
365
|
+
build: (node, attrs) => {
|
|
366
|
+
const src = sanitizeMediaUrl(node.props.src);
|
|
367
|
+
if (!src) {
|
|
368
|
+
return {
|
|
369
|
+
tag: "span",
|
|
370
|
+
attrs: { ...attrs, class: `${attrs.class ?? ""} emvb-image-missing`.trim() },
|
|
371
|
+
children: [],
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
const decorative = node.props.decorative === true;
|
|
375
|
+
const imgAttrs: Record<string, string> = {
|
|
376
|
+
...attrs,
|
|
377
|
+
src,
|
|
378
|
+
alt: decorative ? "" : node.props.alt,
|
|
379
|
+
...(node.props.priority === true
|
|
380
|
+
? { loading: "eager", fetchpriority: "high" }
|
|
381
|
+
: { loading: "lazy", decoding: "async" }),
|
|
382
|
+
};
|
|
383
|
+
if (decorative) imgAttrs.role = "presentation";
|
|
384
|
+
if (node.props.width !== undefined) imgAttrs.width = String(node.props.width);
|
|
385
|
+
if (node.props.height !== undefined) imgAttrs.height = String(node.props.height);
|
|
386
|
+
return { tag: "img", attrs: imgAttrs, children: [] };
|
|
387
|
+
},
|
|
388
|
+
};
|
|
389
|
+
|
|
390
|
+
/** Root stroke widths the Stroke width control can override (W-237); Lucide and Tabler use 2. */
|
|
391
|
+
const ICON_STROKE_WIDTHS = ["1", "1.5", "2", "2.5", "3"] as const;
|
|
392
|
+
|
|
393
|
+
const icon: ElementDefinition<IconNode> = {
|
|
394
|
+
baseCss:
|
|
395
|
+
// W-237: the glyph reads the wrapper's icon custom properties (rotate, flip, shadow, loop,
|
|
396
|
+
// stroke); unset they change nothing. The svg inherits the wrapper's transition for hover.
|
|
397
|
+
".emvb-icon{display:inline-flex;align-items:center;justify-content:center;line-height:0;color:inherit}.emvb-icon-link{display:inline-flex;color:inherit}.emvb-icon svg{display:block;rotate:var(--emvb-icon-rotate,0deg);scale:var(--emvb-icon-flip,1 1);filter:var(--emvb-icon-shadow,none);animation:var(--emvb-icon-animation,none);transition:inherit}" +
|
|
398
|
+
ICON_STROKE_WIDTHS.map(
|
|
399
|
+
(width) =>
|
|
400
|
+
`.emvb-icon-sw${width.replace(".", "_")}{stroke-width:var(--emvb-icon-stroke,${width})}`,
|
|
401
|
+
).join("") +
|
|
402
|
+
"@keyframes emvb-icon-spin{to{transform:rotate(360deg)}}@keyframes emvb-icon-pulse{from{transform:scale(1)}to{transform:scale(1.15)}}@media (prefers-reduced-motion: reduce){.emvb-icon svg{animation:none}}.emvb-icon-missing{min-width:1em;min-height:1em;background:var(--color-kumo-tint,#eee)}",
|
|
403
|
+
defaults: () => ({
|
|
404
|
+
type: "icon",
|
|
405
|
+
props: { iconId: "star", title: "Star", decorative: false, size: 24 },
|
|
406
|
+
}),
|
|
407
|
+
descriptor: {
|
|
408
|
+
type: "icon",
|
|
409
|
+
name: "Icon",
|
|
410
|
+
group: "content",
|
|
411
|
+
defaultTab: "content",
|
|
412
|
+
fields: [
|
|
413
|
+
{ key: "iconId", kind: "icon", label: "Icon" },
|
|
414
|
+
{ key: "title", kind: "text", label: "Title" },
|
|
415
|
+
{
|
|
416
|
+
key: "decorative",
|
|
417
|
+
kind: "boolean",
|
|
418
|
+
label: "Decorative (hide from assistive tech)",
|
|
419
|
+
optional: true,
|
|
420
|
+
},
|
|
421
|
+
{
|
|
422
|
+
key: "size",
|
|
423
|
+
kind: "int",
|
|
424
|
+
label: "Size (px)",
|
|
425
|
+
optional: true,
|
|
426
|
+
message: "Size must be a positive whole number.",
|
|
427
|
+
},
|
|
428
|
+
...INNER_LINK_FIELDS,
|
|
429
|
+
],
|
|
430
|
+
},
|
|
431
|
+
build: (node, attrs) => {
|
|
432
|
+
// W-234: a picked library icon carries its own SVG; the allowlist checks it on every render.
|
|
433
|
+
const picked = node.props.iconSvg ? sanitizeSvgMarkup(node.props.iconSvg) : undefined;
|
|
434
|
+
const bundled = picked ? undefined : getBundledIcon(node.props.iconId);
|
|
435
|
+
if (!picked && !bundled) {
|
|
436
|
+
// Never treat iconId as a URL or raw HTML (R-032 / R-033).
|
|
437
|
+
return {
|
|
438
|
+
tag: "span",
|
|
439
|
+
attrs: {
|
|
440
|
+
...attrs,
|
|
441
|
+
class: `${attrs.class ?? ""} emvb-icon-missing`.trim(),
|
|
442
|
+
"aria-hidden": "true",
|
|
443
|
+
},
|
|
444
|
+
children: [],
|
|
445
|
+
};
|
|
446
|
+
}
|
|
447
|
+
const decorative = node.props.decorative === true;
|
|
448
|
+
const size = node.props.size ?? 24;
|
|
449
|
+
const svgAttrs: Record<string, string> = picked
|
|
450
|
+
? {
|
|
451
|
+
...pickedIconAttrs(picked.attrs),
|
|
452
|
+
width: String(size),
|
|
453
|
+
height: String(size),
|
|
454
|
+
focusable: "false",
|
|
455
|
+
}
|
|
456
|
+
: {
|
|
457
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
458
|
+
width: String(size),
|
|
459
|
+
height: String(size),
|
|
460
|
+
viewBox: "0 0 24 24",
|
|
461
|
+
fill: "none",
|
|
462
|
+
stroke: "currentColor",
|
|
463
|
+
"stroke-width": "2",
|
|
464
|
+
"stroke-linecap": "round",
|
|
465
|
+
"stroke-linejoin": "round",
|
|
466
|
+
focusable: "false",
|
|
467
|
+
};
|
|
468
|
+
if (decorative) {
|
|
469
|
+
svgAttrs["aria-hidden"] = "true";
|
|
470
|
+
} else {
|
|
471
|
+
svgAttrs.role = "img";
|
|
472
|
+
if (node.props.title) svgAttrs["aria-label"] = node.props.title;
|
|
473
|
+
}
|
|
474
|
+
const children: (VNode | string)[] = picked
|
|
475
|
+
? picked.children
|
|
476
|
+
: (bundled?.children ?? []).map((child) => ({
|
|
477
|
+
tag: child.tag,
|
|
478
|
+
attrs: { ...child.attrs },
|
|
479
|
+
children: [],
|
|
480
|
+
}));
|
|
481
|
+
strokeClass(svgAttrs);
|
|
482
|
+
const single = picked !== undefined && node.props.singleColor === true;
|
|
483
|
+
if (single) monochromeRoot(svgAttrs);
|
|
484
|
+
const svg: VNode = {
|
|
485
|
+
tag: "svg",
|
|
486
|
+
attrs: svgAttrs,
|
|
487
|
+
children: single ? monochrome(children) : children,
|
|
488
|
+
};
|
|
489
|
+
// A linked icon is named by its title on the link, so the svg inside is hidden.
|
|
490
|
+
const title = node.props.title?.trim();
|
|
491
|
+
const { role: _role, "aria-label": _label, ...plain } = svgAttrs;
|
|
492
|
+
const hidden: VNode = { ...svg, attrs: { ...plain, "aria-hidden": "true" } };
|
|
493
|
+
const linked = title
|
|
494
|
+
? innerLink(node.props.href, node.props.newTab, "emvb-icon-link", [hidden], {
|
|
495
|
+
"aria-label": title,
|
|
496
|
+
})
|
|
497
|
+
: undefined;
|
|
498
|
+
return { tag: "span", attrs, children: [linked ?? svg] };
|
|
499
|
+
},
|
|
500
|
+
};
|
|
501
|
+
|
|
502
|
+
/**
|
|
503
|
+
* W-237: a stroke icon's root `stroke-width` moves into a class whose CSS reads the wrapper's
|
|
504
|
+
* `--emvb-icon-stroke` with the original width as fallback; any other width stays as it was.
|
|
505
|
+
*/
|
|
506
|
+
function strokeClass(svgAttrs: Record<string, string>): void {
|
|
507
|
+
const width = svgAttrs["stroke-width"];
|
|
508
|
+
if (!width || !(ICON_STROKE_WIDTHS as readonly string[]).includes(width)) return;
|
|
509
|
+
if (!svgAttrs.stroke || svgAttrs.stroke === "none") return;
|
|
510
|
+
delete svgAttrs["stroke-width"];
|
|
511
|
+
const cls = `emvb-icon-sw${width.replace(".", "_")}`;
|
|
512
|
+
svgAttrs.class = svgAttrs.class ? `${svgAttrs.class} ${cls}` : cls;
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
/** Whether an icon's SVG is stroke-drawn with an adjustable width (the panel shows the control). */
|
|
516
|
+
export function iconHasAdjustableStroke(svg: string | undefined): boolean {
|
|
517
|
+
if (!svg) return true; // bundled Lucide
|
|
518
|
+
const picked = sanitizeSvgMarkup(svg);
|
|
519
|
+
if (!picked) return false;
|
|
520
|
+
const attrs = pickedIconAttrs(picked.attrs);
|
|
521
|
+
const before = attrs["stroke-width"];
|
|
522
|
+
strokeClass(attrs);
|
|
523
|
+
return before !== undefined && attrs["stroke-width"] === undefined;
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
/** Paint attributes a multi-colour SVG sets its colours with (W-238). */
|
|
527
|
+
const PAINT_ATTRS = ["fill", "stroke", "stop-color"] as const;
|
|
528
|
+
|
|
529
|
+
const ownColor = (value: string | undefined) =>
|
|
530
|
+
value !== undefined && value !== "none" && value.toLowerCase() !== "currentcolor";
|
|
531
|
+
|
|
532
|
+
/** W-238: every fill, stroke and gradient stop becomes the icon's colour; `none` stays none. */
|
|
533
|
+
function monochrome(nodes: (VNode | string)[]): (VNode | string)[] {
|
|
534
|
+
return nodes.map((child) => {
|
|
535
|
+
if (typeof child === "string") return child;
|
|
536
|
+
const attrs = { ...child.attrs };
|
|
537
|
+
for (const name of PAINT_ATTRS) if (ownColor(attrs[name])) attrs[name] = "currentColor";
|
|
538
|
+
return { ...child, attrs, children: monochrome(child.children) };
|
|
539
|
+
});
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
/** The root too; without a fill, SVG paints black, so it gets the icon's colour. */
|
|
543
|
+
function monochromeRoot(attrs: Record<string, string>): void {
|
|
544
|
+
if (attrs.fill === undefined || ownColor(attrs.fill)) attrs.fill = "currentColor";
|
|
545
|
+
if (ownColor(attrs.stroke)) attrs.stroke = "currentColor";
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
/**
|
|
549
|
+
* Whether an icon's SVG paints with its own colours (W-238): any fill, stroke or stop other than
|
|
550
|
+
* `none`/`currentColor`, or a root without a fill (SVG's default is black). The panel offers
|
|
551
|
+
* Force single colour only then. Bundled Lucide icons follow the icon's colour already.
|
|
552
|
+
*/
|
|
553
|
+
export function iconHasOwnColors(svg: string | undefined): boolean {
|
|
554
|
+
if (!svg) return false;
|
|
555
|
+
const picked = sanitizeSvgMarkup(svg);
|
|
556
|
+
if (!picked) return false;
|
|
557
|
+
if (picked.attrs.fill === undefined || PAINT_ATTRS.some((name) => ownColor(picked.attrs[name])))
|
|
558
|
+
return true;
|
|
559
|
+
const walk = (nodes: (VNode | string)[]): boolean =>
|
|
560
|
+
nodes.some(
|
|
561
|
+
(child) =>
|
|
562
|
+
typeof child !== "string" &&
|
|
563
|
+
(PAINT_ATTRS.some((name) => ownColor(child.attrs[name])) || walk(child.children)),
|
|
564
|
+
);
|
|
565
|
+
return walk(picked.children);
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
/** A picked icon's root attributes minus what the element sets itself (size, name, id). */
|
|
569
|
+
function pickedIconAttrs(attrs: Record<string, string>): Record<string, string> {
|
|
570
|
+
const kept: Record<string, string> = { xmlns: "http://www.w3.org/2000/svg" };
|
|
571
|
+
for (const [name, value] of Object.entries(attrs)) {
|
|
572
|
+
if (name === "width" || name === "height" || name === "id" || name === "role") continue;
|
|
573
|
+
if (name.startsWith("aria-") || name === "focusable") continue;
|
|
574
|
+
kept[name] = value;
|
|
575
|
+
}
|
|
576
|
+
if (!kept.viewBox) kept.viewBox = "0 0 24 24";
|
|
577
|
+
return kept;
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
const video: ElementDefinition<VideoNode> = {
|
|
581
|
+
baseCss:
|
|
582
|
+
// W-266: the iframe or <video> is the .emvb-video element itself, so the 16:9 size sits on it
|
|
583
|
+
// (the old descendant rule matched nothing: players were 300×150). :where() lets styles win.
|
|
584
|
+
".emvb-video{display:block;max-width:100%;border:0}:where(.emvb-video){box-sizing:border-box;width:100%;aspect-ratio:16/9;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)}",
|
|
585
|
+
defaults: () => ({
|
|
586
|
+
type: "video",
|
|
587
|
+
props: { url: "", title: "Video" },
|
|
588
|
+
}),
|
|
589
|
+
descriptor: {
|
|
590
|
+
type: "video",
|
|
591
|
+
name: "Video",
|
|
592
|
+
group: "content",
|
|
593
|
+
defaultTab: "content",
|
|
594
|
+
fields: [
|
|
595
|
+
{
|
|
596
|
+
key: "url",
|
|
597
|
+
kind: "href",
|
|
598
|
+
label: "Video URL",
|
|
599
|
+
message:
|
|
600
|
+
"Use a YouTube or Vimeo link, or a media file path such as /_emdash/api/media/file/….",
|
|
601
|
+
},
|
|
602
|
+
{ key: "title", kind: "text", label: "Title" },
|
|
603
|
+
],
|
|
604
|
+
},
|
|
605
|
+
build: (node, attrs) => {
|
|
606
|
+
const target = resolveEmbedUrl(node.props.url);
|
|
607
|
+
if (!target) {
|
|
608
|
+
return {
|
|
609
|
+
tag: "span",
|
|
610
|
+
attrs: {
|
|
611
|
+
...attrs,
|
|
612
|
+
class: `${attrs.class ?? ""} emvb-video-missing`.trim(),
|
|
613
|
+
"aria-hidden": "true",
|
|
614
|
+
},
|
|
615
|
+
children: [],
|
|
616
|
+
};
|
|
617
|
+
}
|
|
618
|
+
if (target.kind === "iframe") {
|
|
619
|
+
return {
|
|
620
|
+
tag: "iframe",
|
|
621
|
+
attrs: {
|
|
622
|
+
...attrs,
|
|
623
|
+
src: target.src,
|
|
624
|
+
title: node.props.title,
|
|
625
|
+
loading: "lazy",
|
|
626
|
+
referrerpolicy: "strict-origin-when-cross-origin",
|
|
627
|
+
allow: "encrypted-media; picture-in-picture; fullscreen",
|
|
628
|
+
},
|
|
629
|
+
children: [],
|
|
630
|
+
};
|
|
631
|
+
}
|
|
632
|
+
return {
|
|
633
|
+
tag: "video",
|
|
634
|
+
attrs: {
|
|
635
|
+
...attrs,
|
|
636
|
+
src: target.src,
|
|
637
|
+
title: node.props.title,
|
|
638
|
+
controls: "",
|
|
639
|
+
preload: "metadata",
|
|
640
|
+
},
|
|
641
|
+
children: [],
|
|
642
|
+
};
|
|
643
|
+
},
|
|
644
|
+
};
|
|
645
|
+
|
|
646
|
+
const DEFAULT_SVG =
|
|
647
|
+
'<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>';
|
|
648
|
+
|
|
649
|
+
const svgEl: ElementDefinition<SvgNode> = {
|
|
650
|
+
baseCss:
|
|
651
|
+
".emvb-svg{display:inline-flex;align-items:center;justify-content:center;line-height:0;color:inherit}.emvb-svg svg{display:block}.emvb-svg-missing{min-width:1em;min-height:1em;background:var(--color-kumo-tint,#eee)}",
|
|
652
|
+
defaults: () => ({
|
|
653
|
+
type: "svg",
|
|
654
|
+
props: { markup: DEFAULT_SVG, title: "SVG", decorative: false, size: 48 },
|
|
655
|
+
}),
|
|
656
|
+
descriptor: {
|
|
657
|
+
type: "svg",
|
|
658
|
+
name: "SVG",
|
|
659
|
+
group: "content",
|
|
660
|
+
defaultTab: "content",
|
|
661
|
+
fields: [
|
|
662
|
+
{
|
|
663
|
+
key: "markup",
|
|
664
|
+
kind: "textarea",
|
|
665
|
+
label: "SVG markup",
|
|
666
|
+
message: "Paste safe SVG only (no scripts or external links).",
|
|
667
|
+
},
|
|
668
|
+
{ key: "title", kind: "text", label: "Title", optional: true },
|
|
669
|
+
{
|
|
670
|
+
key: "decorative",
|
|
671
|
+
kind: "boolean",
|
|
672
|
+
label: "Decorative (hide from assistive tech)",
|
|
673
|
+
optional: true,
|
|
674
|
+
},
|
|
675
|
+
{
|
|
676
|
+
key: "size",
|
|
677
|
+
kind: "int",
|
|
678
|
+
label: "Size (px)",
|
|
679
|
+
optional: true,
|
|
680
|
+
message: "Size must be a positive whole number.",
|
|
681
|
+
},
|
|
682
|
+
],
|
|
683
|
+
},
|
|
684
|
+
build: (node, attrs) => {
|
|
685
|
+
const tree = sanitizeSvgMarkup(node.props.markup);
|
|
686
|
+
if (!tree) {
|
|
687
|
+
return {
|
|
688
|
+
tag: "span",
|
|
689
|
+
attrs: {
|
|
690
|
+
...attrs,
|
|
691
|
+
class: `${attrs.class ?? ""} emvb-svg-missing`.trim(),
|
|
692
|
+
"aria-hidden": "true",
|
|
693
|
+
},
|
|
694
|
+
children: [],
|
|
695
|
+
};
|
|
696
|
+
}
|
|
697
|
+
const size = node.props.size ?? 48;
|
|
698
|
+
const decorative = node.props.decorative === true;
|
|
699
|
+
const svgAttrs: Record<string, string> = {
|
|
700
|
+
...tree.attrs,
|
|
701
|
+
xmlns: tree.attrs.xmlns ?? "http://www.w3.org/2000/svg",
|
|
702
|
+
width: String(size),
|
|
703
|
+
height: String(size),
|
|
704
|
+
focusable: "false",
|
|
705
|
+
};
|
|
706
|
+
if (!svgAttrs.fill && !svgAttrs.stroke) {
|
|
707
|
+
svgAttrs.fill = "currentColor";
|
|
708
|
+
}
|
|
709
|
+
if (decorative) {
|
|
710
|
+
svgAttrs["aria-hidden"] = "true";
|
|
711
|
+
} else {
|
|
712
|
+
svgAttrs.role = "img";
|
|
713
|
+
if (node.props.title) svgAttrs["aria-label"] = node.props.title;
|
|
714
|
+
}
|
|
715
|
+
return {
|
|
716
|
+
tag: "span",
|
|
717
|
+
attrs,
|
|
718
|
+
children: [{ tag: "svg", attrs: svgAttrs, children: tree.children }],
|
|
719
|
+
};
|
|
720
|
+
},
|
|
721
|
+
};
|
|
722
|
+
|
|
723
|
+
const tabPanel: ElementDefinition<TabPanelNode> = {
|
|
724
|
+
baseCss: "",
|
|
725
|
+
defaults: () => ({
|
|
726
|
+
type: "tab-panel",
|
|
727
|
+
props: { label: "Tab" },
|
|
728
|
+
children: [],
|
|
729
|
+
}),
|
|
730
|
+
descriptor: {
|
|
731
|
+
type: "tab-panel",
|
|
732
|
+
name: "Tab panel",
|
|
733
|
+
group: "layout",
|
|
734
|
+
defaultTab: "content",
|
|
735
|
+
fields: [{ key: "label", kind: "text", label: "Tab label" }],
|
|
736
|
+
},
|
|
737
|
+
build: (_node, attrs, children) => ({ tag: "div", attrs, children }),
|
|
738
|
+
};
|
|
739
|
+
|
|
740
|
+
const tabs: ElementDefinition<TabsNode> = {
|
|
741
|
+
baseCss:
|
|
742
|
+
".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}",
|
|
743
|
+
defaults: () => ({
|
|
744
|
+
type: "tabs",
|
|
745
|
+
props: {},
|
|
746
|
+
children: [],
|
|
747
|
+
}),
|
|
748
|
+
descriptor: {
|
|
749
|
+
type: "tabs",
|
|
750
|
+
name: "Tabs",
|
|
751
|
+
group: "layout",
|
|
752
|
+
defaultTab: "content",
|
|
753
|
+
fields: [],
|
|
754
|
+
},
|
|
755
|
+
// Real markup is assembled in render (needs panel labels from nodes).
|
|
756
|
+
build: (_node, attrs, children) => ({ tag: "div", attrs, children }),
|
|
757
|
+
};
|
|
758
|
+
|
|
759
|
+
const divBlock: ElementDefinition<DivBlockNode> = {
|
|
760
|
+
baseCss: ".emvb-div-block{display:block;min-width:0}",
|
|
761
|
+
defaults: () => ({ type: "div-block", props: {}, children: [] }),
|
|
762
|
+
descriptor: {
|
|
763
|
+
type: "div-block",
|
|
764
|
+
name: "Div Block",
|
|
765
|
+
group: "layout",
|
|
766
|
+
defaultTab: "style",
|
|
767
|
+
fields: BOX_LINK_FIELDS,
|
|
768
|
+
},
|
|
769
|
+
build: (_node, attrs, children) => ({ tag: "div", attrs, children }),
|
|
770
|
+
};
|
|
771
|
+
|
|
772
|
+
/**
|
|
773
|
+
* A layout Section (W-156, D-045): a full-width band (background and padding on it) whose
|
|
774
|
+
* contents sit in a centred inner box at most the content width wide. The width is a custom
|
|
775
|
+
* property set by the renderer; each section resets it so a nested one doesn't inherit it.
|
|
776
|
+
*/
|
|
777
|
+
const layoutSection: ElementDefinition<LayoutSectionNode> = {
|
|
778
|
+
baseCss:
|
|
779
|
+
".emvb-layout-section{--emvb-content-width:1140px;display:block;min-width:0}.emvb-layout-section-inner{box-sizing:border-box;width:100%;max-width:var(--emvb-content-width);margin-inline:auto;min-width:0}",
|
|
780
|
+
defaults: () => ({
|
|
781
|
+
type: "layout-section",
|
|
782
|
+
props: {},
|
|
783
|
+
style: {
|
|
784
|
+
paddingTop: { value: 64, unit: "px" },
|
|
785
|
+
paddingRight: { value: 24, unit: "px" },
|
|
786
|
+
paddingBottom: { value: 64, unit: "px" },
|
|
787
|
+
paddingLeft: { value: 24, unit: "px" },
|
|
788
|
+
},
|
|
789
|
+
children: [],
|
|
790
|
+
}),
|
|
791
|
+
descriptor: {
|
|
792
|
+
type: "layout-section",
|
|
793
|
+
name: "Section",
|
|
794
|
+
group: "layout",
|
|
795
|
+
defaultTab: "content",
|
|
796
|
+
fields: [
|
|
797
|
+
{
|
|
798
|
+
key: "contentWidth",
|
|
799
|
+
kind: "number",
|
|
800
|
+
label: "Content width",
|
|
801
|
+
optional: true,
|
|
802
|
+
message: "Content width can't be negative. Leave it empty for 1140 px.",
|
|
803
|
+
},
|
|
804
|
+
{ key: "fullWidth", kind: "boolean", label: "Full-width content", optional: true },
|
|
805
|
+
{
|
|
806
|
+
key: "tag",
|
|
807
|
+
kind: "select",
|
|
808
|
+
label: "HTML tag",
|
|
809
|
+
optional: true,
|
|
810
|
+
options: CONTAINER_TAGS.map((tag) => ({ value: tag, label: tag })),
|
|
811
|
+
message: "Pick a landmark or div. A section is a section by default.",
|
|
812
|
+
},
|
|
813
|
+
],
|
|
814
|
+
},
|
|
815
|
+
build: (node, attrs, children) => {
|
|
816
|
+
const tag = node.props.tag ?? "section";
|
|
817
|
+
const safe = (CONTAINER_TAGS as readonly string[]).includes(tag) ? tag : "section";
|
|
818
|
+
const inner: VNode = { tag: "div", attrs: { class: "emvb-layout-section-inner" }, children };
|
|
819
|
+
return { tag: safe, attrs, children: [inner] };
|
|
820
|
+
},
|
|
821
|
+
};
|
|
822
|
+
|
|
823
|
+
const grid: ElementDefinition<GridNode> = {
|
|
824
|
+
baseCss: ".emvb-grid{display:grid;min-width:0}",
|
|
825
|
+
defaults: () => ({ type: "grid", props: { columns: 3 }, children: [] }),
|
|
826
|
+
descriptor: {
|
|
827
|
+
type: "grid",
|
|
828
|
+
name: "Grid",
|
|
829
|
+
group: "layout",
|
|
830
|
+
defaultTab: "content",
|
|
831
|
+
fields: [
|
|
832
|
+
{
|
|
833
|
+
key: "columns",
|
|
834
|
+
kind: "select",
|
|
835
|
+
label: "Columns",
|
|
836
|
+
devices: { tablet: "columnsTablet", mobile: "columnsMobile" },
|
|
837
|
+
options: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12].map((n) => ({
|
|
838
|
+
value: n,
|
|
839
|
+
label: String(n),
|
|
840
|
+
})),
|
|
841
|
+
},
|
|
842
|
+
...BOX_LINK_FIELDS,
|
|
843
|
+
],
|
|
844
|
+
},
|
|
845
|
+
build: (_node, attrs, children) => ({ tag: "div", attrs, children }),
|
|
846
|
+
};
|
|
847
|
+
|
|
848
|
+
const flexbox: ElementDefinition<FlexboxNode> = {
|
|
849
|
+
baseCss:
|
|
850
|
+
".emvb-flexbox{display:flex;flex-direction:row;flex-wrap:wrap;align-items:stretch;min-width:0;gap:16px}",
|
|
851
|
+
defaults: () => ({
|
|
852
|
+
type: "flexbox",
|
|
853
|
+
props: {},
|
|
854
|
+
style: { flexDirection: "row", flexWrap: "wrap", gap: { value: 16, unit: "px" } },
|
|
855
|
+
children: [],
|
|
856
|
+
}),
|
|
857
|
+
descriptor: {
|
|
858
|
+
type: "flexbox",
|
|
859
|
+
name: "Flexbox",
|
|
860
|
+
group: "layout",
|
|
861
|
+
defaultTab: "style",
|
|
862
|
+
fields: BOX_LINK_FIELDS,
|
|
863
|
+
},
|
|
864
|
+
build: (_node, attrs, children) => ({ tag: "div", attrs, children }),
|
|
865
|
+
};
|
|
866
|
+
|
|
867
|
+
const accordion: ElementDefinition<AccordionNode> = {
|
|
868
|
+
baseCss:
|
|
869
|
+
".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}",
|
|
870
|
+
defaults: () => ({ type: "accordion", props: {}, children: [] }),
|
|
871
|
+
descriptor: {
|
|
872
|
+
type: "accordion",
|
|
873
|
+
name: "Accordion",
|
|
874
|
+
group: "layout",
|
|
875
|
+
defaultTab: "content",
|
|
876
|
+
fields: [],
|
|
877
|
+
},
|
|
878
|
+
build: (_node, attrs, children) => ({ tag: "div", attrs, children }),
|
|
879
|
+
};
|
|
880
|
+
|
|
881
|
+
const accordionItem: ElementDefinition<AccordionItemNode> = {
|
|
882
|
+
baseCss: "",
|
|
883
|
+
defaults: () => ({ type: "accordion-item", props: { summary: "Title" }, children: [] }),
|
|
884
|
+
descriptor: {
|
|
885
|
+
type: "accordion-item",
|
|
886
|
+
name: "Accordion item",
|
|
887
|
+
group: "layout",
|
|
888
|
+
defaultTab: "content",
|
|
889
|
+
fields: [
|
|
890
|
+
{ key: "summary", kind: "text", label: "Title" },
|
|
891
|
+
{ key: "open", kind: "boolean", label: "Open", optional: true },
|
|
892
|
+
],
|
|
893
|
+
},
|
|
894
|
+
build: (node, attrs, children) => {
|
|
895
|
+
const summary: VNode = { tag: "summary", attrs: {}, children: [node.props.summary] };
|
|
896
|
+
const body: VNode = { tag: "div", attrs: { class: "emvb-accordion-body" }, children };
|
|
897
|
+
return {
|
|
898
|
+
tag: "details",
|
|
899
|
+
attrs: node.props.open ? { ...attrs, open: "" } : attrs,
|
|
900
|
+
children: [summary, body],
|
|
901
|
+
};
|
|
902
|
+
},
|
|
903
|
+
};
|
|
904
|
+
|
|
905
|
+
export const ELEMENTS = {
|
|
906
|
+
heading,
|
|
907
|
+
container,
|
|
908
|
+
"layout-section": layoutSection,
|
|
909
|
+
spacer,
|
|
910
|
+
divider,
|
|
911
|
+
text,
|
|
912
|
+
label,
|
|
913
|
+
link,
|
|
914
|
+
button,
|
|
915
|
+
list,
|
|
916
|
+
image,
|
|
917
|
+
icon,
|
|
918
|
+
video,
|
|
919
|
+
form,
|
|
920
|
+
"text-input": textInput,
|
|
921
|
+
textarea: textareaEl,
|
|
922
|
+
select: selectEl,
|
|
923
|
+
checkbox,
|
|
924
|
+
radio,
|
|
925
|
+
submit,
|
|
926
|
+
"post-title": postTitle,
|
|
927
|
+
"post-excerpt": postExcerpt,
|
|
928
|
+
"post-content": postContent,
|
|
929
|
+
"post-image": postImage,
|
|
930
|
+
"post-link": postLink,
|
|
931
|
+
"post-date": postDate,
|
|
932
|
+
"post-author": postAuthor,
|
|
933
|
+
loop,
|
|
934
|
+
pagination,
|
|
935
|
+
section,
|
|
936
|
+
"div-block": divBlock,
|
|
937
|
+
flexbox,
|
|
938
|
+
grid,
|
|
939
|
+
svg: svgEl,
|
|
940
|
+
tabs,
|
|
941
|
+
"tab-panel": tabPanel,
|
|
942
|
+
accordion,
|
|
943
|
+
"accordion-item": accordionItem,
|
|
944
|
+
menu,
|
|
945
|
+
"menu-item": menuItem,
|
|
946
|
+
} as const;
|
|
947
|
+
|
|
948
|
+
export type ElementType = keyof typeof ELEMENTS;
|
|
949
|
+
|
|
950
|
+
export const ELEMENT_DESCRIPTORS: ElementDescriptor[] = Object.values(ELEMENTS).map(
|
|
951
|
+
(el) => el.descriptor,
|
|
952
|
+
);
|
|
953
|
+
|
|
954
|
+
export function defaultElement<T extends ElementType>(
|
|
955
|
+
type: T,
|
|
956
|
+
id: string,
|
|
957
|
+
): (typeof ELEMENTS)[T] extends ElementDefinition<infer N> ? N : never {
|
|
958
|
+
const base = ELEMENTS[type].defaults() as { type: string };
|
|
959
|
+
return { id, ...base } as never;
|
|
960
|
+
}
|