@perkyzz/emvb 0.1.0 → 0.2.1
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/README.md +6 -4
- 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 +9 -5
- package/src/admin/api.ts +27 -0
- package/src/admin/content-api.ts +72 -9
- package/src/admin/editor/Editor.tsx +89 -14
- package/src/admin/editor/EditorOverlay.tsx +12 -0
- package/src/admin/editor/SmallScreenNotice.tsx +4 -3
- package/src/admin/editor/TopBar.tsx +76 -12
- package/src/admin/editor/canvas/CanvasFrame.tsx +224 -43
- package/src/admin/editor/canvas/DeviceBar.tsx +43 -2
- package/src/admin/editor/canvas/SelectionOverlay.tsx +60 -6
- package/src/admin/editor/canvas/canvas-events.ts +20 -7
- package/src/admin/editor/canvas/tab-reveal.ts +66 -0
- package/src/admin/editor/canvas/vnode-react.tsx +21 -1
- package/src/admin/editor/dialogs.tsx +39 -0
- package/src/admin/editor/dnd/drop-target.ts +63 -16
- package/src/admin/editor/dnd/new-element.ts +76 -1
- package/src/admin/editor/editor-css.ts +101 -15
- 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 +7 -3
- package/src/admin/editor/panels/ClassesSection.tsx +44 -6
- package/src/admin/editor/panels/ColorControl.tsx +268 -21
- package/src/admin/editor/panels/ElementPanel.tsx +237 -93
- package/src/admin/editor/panels/LayersPanel.tsx +303 -66
- package/src/admin/editor/panels/LeftPanel.tsx +4 -0
- package/src/admin/editor/panels/PageSettings.tsx +134 -5
- package/src/admin/editor/panels/SettingsPanel.tsx +12 -0
- package/src/admin/editor/panels/SiteStylesDrawer.tsx +158 -2
- package/src/admin/editor/panels/TriggersEditor.tsx +19 -2
- package/src/admin/editor/panels/VariableSection.tsx +47 -9
- 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 +153 -55
- 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/ClassChipInput.tsx +104 -2
- package/src/admin/editor/panels/settings/DraftTextField.tsx +44 -3
- package/src/admin/editor/panels/settings/EffectsControls.tsx +25 -16
- package/src/admin/editor/panels/settings/FieldBindControl.tsx +53 -17
- package/src/admin/editor/panels/settings/FieldControl.tsx +129 -9
- package/src/admin/editor/panels/settings/FormBindControl.tsx +14 -5
- package/src/admin/editor/panels/settings/IconControls.tsx +438 -0
- package/src/admin/editor/panels/settings/IconPicker.tsx +133 -72
- package/src/admin/editor/panels/settings/ItemList.tsx +199 -0
- package/src/admin/editor/panels/settings/LengthRow.tsx +97 -61
- package/src/admin/editor/panels/settings/LoopItemBindControl.tsx +10 -4
- package/src/admin/editor/panels/settings/MediaPicker.tsx +4 -2
- package/src/admin/editor/panels/settings/StateSwitcher.tsx +1 -1
- package/src/admin/editor/panels/settings/StyleRow.tsx +158 -75
- package/src/admin/editor/panels/settings/VariableBinding.tsx +5 -1
- 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 +5 -3
- 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 +40 -7
- package/src/admin/editor/panels/settings/loop-context.ts +26 -0
- package/src/admin/editor/panels/settings/style-sections.ts +114 -11
- package/src/admin/editor/panels/settings/svg-images.ts +14 -0
- package/src/admin/editor/panels/site-list.tsx +3 -0
- package/src/admin/editor/restore-deleted.ts +80 -0
- package/src/admin/editor/shortcuts.ts +1 -1
- package/src/admin/editor/store.ts +35 -7
- package/src/admin/editor/useEditorCommands.ts +66 -5
- package/src/admin/editor/useEditorData.ts +29 -3
- package/src/admin/editor/useEditorShortcuts.ts +34 -2
- package/src/admin/editor/useNodeActions.ts +68 -6
- package/src/admin/editor/useSave.ts +60 -3
- package/src/admin/entry-status.ts +19 -0
- package/src/admin/icon-uploads-api.ts +44 -0
- package/src/admin/pages/PageList.tsx +22 -2
- package/src/admin/pages/ThemePartList.tsx +23 -4
- package/src/admin/pages/list-kit.tsx +52 -2
- package/src/admin/setup/spec.ts +7 -0
- package/src/admin/theme-api.ts +61 -14
- package/src/admin/ui.ts +17 -4
- package/src/astro/EmVBPage.astro +28 -2
- 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-definitions.ts +22 -0
- package/src/astro/index.ts +1 -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/runtime.ts +54 -4
- package/src/astro/render.ts +47 -13
- package/src/astro/resolve-theme.ts +168 -24
- package/src/astro/tabs/runtime.ts +6 -1
- package/src/astro/theme-context.ts +25 -5
- package/src/astro/theme-posts.ts +19 -1
- package/src/constants.ts +1 -1
- package/src/core/arrange.ts +98 -10
- package/src/core/clipboard.ts +91 -9
- package/src/core/css/generate.ts +21 -4
- package/src/core/design/classes.ts +95 -9
- package/src/core/design/transfer.ts +101 -2
- package/src/core/design/variables.ts +51 -11
- package/src/core/elements/dynamic-elements.ts +57 -5
- package/src/core/elements/field-id.ts +6 -0
- package/src/core/elements/form-elements.ts +23 -8
- package/src/core/elements/index.ts +267 -49
- package/src/core/elements/menu.ts +190 -0
- package/src/core/forms/definition.ts +11 -0
- package/src/core/index.ts +67 -3
- package/src/core/limits.ts +2 -0
- package/src/core/migrate/index.ts +51 -1
- package/src/core/nesting.ts +51 -0
- package/src/core/render/context.ts +7 -0
- package/src/core/render/dynamic-post.ts +39 -11
- package/src/core/render/extras.ts +22 -3
- package/src/core/render/form.ts +134 -36
- package/src/core/render/index.ts +123 -25
- package/src/core/render/loop.ts +10 -3
- package/src/core/render/pagination.ts +76 -0
- package/src/core/render/section.ts +5 -1
- package/src/core/render/tabs.ts +8 -4
- package/src/core/render/vnode.ts +1 -1
- package/src/core/sanitize/css.ts +197 -17
- package/src/core/sanitize/embed-url.ts +64 -7
- package/src/core/sanitize/svg-upload.ts +203 -0
- package/src/core/sanitize/svg.ts +102 -21
- package/src/core/schema/descriptors.ts +4 -0
- package/src/core/schema/design.ts +7 -2
- package/src/core/schema/layout.ts +210 -19
- package/src/core/schema/style.ts +87 -8
- package/src/core/tabs/presence.ts +9 -0
- package/src/core/theme/conditions.ts +4 -1
- package/src/core/theme/dynamic.ts +10 -0
- package/src/core/theme/float.ts +113 -0
- package/src/core/theme/pagination.ts +97 -0
- package/src/core/theme/part-types.ts +2 -0
- package/src/core/theme/popup-markup.ts +3 -1
- package/src/core/theme/popup-rules.ts +4 -3
- package/src/server/hooks.ts +20 -0
- package/src/server/icon-routes.ts +79 -0
- package/src/server/plugin.ts +5 -1
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import type { MenuItemNode, MenuNode } from "../schema/layout.ts";
|
|
2
|
+
import { sanitizeHref } from "../sanitize/href.ts";
|
|
3
|
+
import type { VNode } from "../render/vnode.ts";
|
|
4
|
+
import type { ElementDefinition } from "./definition.ts";
|
|
5
|
+
|
|
6
|
+
const newTabAttrs = (newTab: boolean | undefined): Record<string, string> =>
|
|
7
|
+
newTab ? { target: "_blank", rel: "noopener noreferrer" } : {};
|
|
8
|
+
|
|
9
|
+
/** Names the item's own disclosure. Nested panels already carry their parent item's name. */
|
|
10
|
+
function stampGroup(children: VNode["children"], name: string): VNode["children"] {
|
|
11
|
+
return children.map((child) => {
|
|
12
|
+
if (typeof child === "string" || child.tag !== "li") return child;
|
|
13
|
+
return {
|
|
14
|
+
...child,
|
|
15
|
+
children: child.children.map((bar) => {
|
|
16
|
+
if (typeof bar === "string" || bar.tag !== "div") return bar;
|
|
17
|
+
return {
|
|
18
|
+
...bar,
|
|
19
|
+
children: bar.children.map((inner) => {
|
|
20
|
+
if (typeof inner === "string" || inner.tag !== "details") return inner;
|
|
21
|
+
return { ...inner, attrs: { ...inner.attrs, name } };
|
|
22
|
+
}),
|
|
23
|
+
};
|
|
24
|
+
}),
|
|
25
|
+
};
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Runs of menu items become a list. Other elements stay in the panel beside that list. */
|
|
30
|
+
function groupItems(children: VNode["children"]): VNode["children"] {
|
|
31
|
+
const out: VNode["children"] = [];
|
|
32
|
+
let batch: VNode[] = [];
|
|
33
|
+
const flush = () => {
|
|
34
|
+
if (batch.length === 0) return;
|
|
35
|
+
out.push({
|
|
36
|
+
tag: "ul",
|
|
37
|
+
attrs: { class: "emvb-menu__list emvb-menu__list--sub" },
|
|
38
|
+
children: batch,
|
|
39
|
+
});
|
|
40
|
+
batch = [];
|
|
41
|
+
};
|
|
42
|
+
for (const child of children) {
|
|
43
|
+
if (typeof child !== "string" && child.tag === "li") batch.push(child);
|
|
44
|
+
else {
|
|
45
|
+
flush();
|
|
46
|
+
out.push(child);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
flush();
|
|
50
|
+
return out;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const MENU_CSS = [
|
|
54
|
+
// The list inherits the menu's flex styles, so Layout's direction, alignment and gap move the items.
|
|
55
|
+
".emvb-menu{position:relative;display:flex;flex-direction:row;flex-wrap:wrap;align-items:center;gap:.25rem 1.25rem}",
|
|
56
|
+
".emvb-menu>.emvb-menu__list{display:flex;flex:1 1 auto;flex-direction:inherit;flex-wrap:inherit;align-items:inherit;justify-content:inherit;gap:inherit;min-width:0;margin:0;padding:0;list-style:none}",
|
|
57
|
+
".emvb-menu--column{flex-direction:column;align-items:stretch;gap:.15rem}",
|
|
58
|
+
".emvb-menu__list--sub{display:flex;flex-direction:column;align-items:stretch;gap:.15rem;margin:0;padding:0;list-style:none}",
|
|
59
|
+
".emvb-menu-item{position:relative}",
|
|
60
|
+
".emvb-menu-item--wide{position:static}",
|
|
61
|
+
".emvb-menu-item__bar{display:flex;align-items:center;gap:.15rem}",
|
|
62
|
+
".emvb-menu-item__link,.emvb-menu-item__label{color:inherit;text-decoration:none}",
|
|
63
|
+
".emvb-menu-item__toggle{display:inline-flex;align-items:center;justify-content:center;width:1.75rem;height:1.75rem;padding:0;cursor:pointer;list-style:none}",
|
|
64
|
+
".emvb-menu-item__toggle::-webkit-details-marker{display:none}",
|
|
65
|
+
".emvb-menu-item__toggle::before{content:'';width:.4rem;height:.4rem;border-right:1.5px solid currentColor;border-bottom:1.5px solid currentColor;transform:rotate(45deg) translateY(-1px)}",
|
|
66
|
+
".emvb-menu-panel{display:none;position:absolute;z-index:30;top:100%;inset-inline-start:0;min-width:12rem;padding:.75rem;background:canvas;color:canvastext;border:1px solid #00000014;box-shadow:0 12px 32px #00000029}",
|
|
67
|
+
".emvb-menu-item__disclosure[open]>.emvb-menu-panel{display:block}",
|
|
68
|
+
"@media (hover:hover) and (pointer:fine){.emvb-menu-item:hover>.emvb-menu-item__bar>.emvb-menu-item__disclosure>.emvb-menu-panel,.emvb-menu-item:focus-within>.emvb-menu-item__bar>.emvb-menu-item__disclosure>.emvb-menu-panel{display:block}}",
|
|
69
|
+
// W-267: a closed <details> hides its content (::details-content is content-visibility:hidden),
|
|
70
|
+
// so the hover rule above showed nothing until the details' content is made visible too. Its own
|
|
71
|
+
// rule: a browser without ::details-content drops only this one. Hover only: keyboard users open
|
|
72
|
+
// a dropdown with its toggle, and Tab doesn't walk through every closed dropdown's links.
|
|
73
|
+
"@media (hover:hover) and (pointer:fine){.emvb-menu-item:hover>.emvb-menu-item__bar>.emvb-menu-item__disclosure::details-content{content-visibility:visible}}",
|
|
74
|
+
".emvb-menu-panel--wide{inset-inline:0;min-width:0}",
|
|
75
|
+
".emvb-menu--column .emvb-menu-panel{top:0;inset-inline-start:100%}",
|
|
76
|
+
".emvb-menu--column .emvb-menu-panel--wide{inset-inline:auto;inset-inline-start:100%;min-width:18rem}",
|
|
77
|
+
].join("");
|
|
78
|
+
|
|
79
|
+
export const menu: ElementDefinition<MenuNode> = {
|
|
80
|
+
baseCss: MENU_CSS,
|
|
81
|
+
defaults: () => ({ type: "menu", props: { direction: "row" }, children: [] }),
|
|
82
|
+
descriptor: {
|
|
83
|
+
type: "menu",
|
|
84
|
+
name: "Menu",
|
|
85
|
+
group: "content",
|
|
86
|
+
defaultTab: "content",
|
|
87
|
+
fields: [
|
|
88
|
+
{
|
|
89
|
+
key: "label",
|
|
90
|
+
kind: "text",
|
|
91
|
+
label: "Name",
|
|
92
|
+
optional: true,
|
|
93
|
+
message: "Names the menu for assistive technology. Leave it blank to use Menu.",
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
key: "direction",
|
|
97
|
+
kind: "select",
|
|
98
|
+
label: "Direction",
|
|
99
|
+
options: [
|
|
100
|
+
{ value: "row", label: "Horizontal" },
|
|
101
|
+
{ value: "column", label: "Vertical" },
|
|
102
|
+
],
|
|
103
|
+
},
|
|
104
|
+
],
|
|
105
|
+
},
|
|
106
|
+
build: (node, attrs, children) => {
|
|
107
|
+
const column = node.props.direction === "column";
|
|
108
|
+
const classes = [attrs.class, column ? "emvb-menu--column" : ""].filter(Boolean).join(" ");
|
|
109
|
+
// W-198: a Menu with nothing in it is no navigation landmark; a plain box keeps its styles.
|
|
110
|
+
if (children.length === 0) {
|
|
111
|
+
return {
|
|
112
|
+
tag: "div",
|
|
113
|
+
attrs: { ...attrs, class: classes, "data-emvb-menu-empty": "" },
|
|
114
|
+
children: [],
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
const label = node.props.label?.trim() || "Menu";
|
|
118
|
+
return {
|
|
119
|
+
tag: "nav",
|
|
120
|
+
attrs: { ...attrs, class: classes, "aria-label": label },
|
|
121
|
+
children: [
|
|
122
|
+
{
|
|
123
|
+
tag: "ul",
|
|
124
|
+
attrs: { class: "emvb-menu__list" },
|
|
125
|
+
children: stampGroup(children, `emvb-menu-${node.id}`),
|
|
126
|
+
},
|
|
127
|
+
],
|
|
128
|
+
};
|
|
129
|
+
},
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
export const menuItem: ElementDefinition<MenuItemNode> = {
|
|
133
|
+
baseCss: "",
|
|
134
|
+
defaults: () => ({ type: "menu-item", props: { text: "Item", href: "/" }, children: [] }),
|
|
135
|
+
descriptor: {
|
|
136
|
+
type: "menu-item",
|
|
137
|
+
name: "Menu item",
|
|
138
|
+
group: "content",
|
|
139
|
+
defaultTab: "content",
|
|
140
|
+
fields: [
|
|
141
|
+
{ key: "text", kind: "text", label: "Label" },
|
|
142
|
+
{
|
|
143
|
+
key: "href",
|
|
144
|
+
kind: "href",
|
|
145
|
+
label: "Link",
|
|
146
|
+
optional: true,
|
|
147
|
+
message: "Use a full URL such as https://example.com or a path such as /pricing.",
|
|
148
|
+
},
|
|
149
|
+
{ key: "newTab", kind: "boolean", label: "Open in a new tab", optional: true },
|
|
150
|
+
{ key: "wide", kind: "boolean", label: "Wide panel", optional: true },
|
|
151
|
+
],
|
|
152
|
+
},
|
|
153
|
+
build: (node, attrs, children) => {
|
|
154
|
+
const wide = node.props.wide === true;
|
|
155
|
+
const classes = [attrs.class, wide ? "emvb-menu-item--wide" : ""].filter(Boolean).join(" ");
|
|
156
|
+
const href = node.props.href?.trim() ? sanitizeHref(node.props.href) : undefined;
|
|
157
|
+
const label: VNode = href
|
|
158
|
+
? {
|
|
159
|
+
tag: "a",
|
|
160
|
+
attrs: { class: "emvb-menu-item__link", href, ...newTabAttrs(node.props.newTab) },
|
|
161
|
+
children: [node.props.text],
|
|
162
|
+
}
|
|
163
|
+
: { tag: "span", attrs: { class: "emvb-menu-item__label" }, children: [node.props.text] };
|
|
164
|
+
const bar: VNode["children"] = [label];
|
|
165
|
+
if (children.length > 0) {
|
|
166
|
+
const panelClass = wide ? "emvb-menu-panel emvb-menu-panel--wide" : "emvb-menu-panel";
|
|
167
|
+
bar.push({
|
|
168
|
+
tag: "details",
|
|
169
|
+
attrs: { class: "emvb-menu-item__disclosure" },
|
|
170
|
+
children: [
|
|
171
|
+
{
|
|
172
|
+
tag: "summary",
|
|
173
|
+
attrs: { class: "emvb-menu-item__toggle", "aria-label": `Open ${node.props.text}` },
|
|
174
|
+
children: [],
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
tag: "div",
|
|
178
|
+
attrs: { class: panelClass },
|
|
179
|
+
children: groupItems(stampGroup(children, `emvb-menu-${node.id}`)),
|
|
180
|
+
},
|
|
181
|
+
],
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
return {
|
|
185
|
+
tag: "li",
|
|
186
|
+
attrs: { ...attrs, class: classes },
|
|
187
|
+
children: [{ tag: "div", attrs: { class: "emvb-menu-item__bar" }, children: bar }],
|
|
188
|
+
};
|
|
189
|
+
},
|
|
190
|
+
};
|
|
@@ -6,6 +6,17 @@ export type PublicFormField = {
|
|
|
6
6
|
required: boolean;
|
|
7
7
|
options?: ReadonlyArray<{ label: string; value: string }>;
|
|
8
8
|
placeholder?: string;
|
|
9
|
+
/** Constraints the forms plugin's own embed puts on the control (W-297). */
|
|
10
|
+
validation?: PublicFieldValidation;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
/** The constraint subset the renderer can apply; anything else is ignored. */
|
|
14
|
+
export type PublicFieldValidation = {
|
|
15
|
+
minLength?: number;
|
|
16
|
+
maxLength?: number;
|
|
17
|
+
min?: number;
|
|
18
|
+
max?: number;
|
|
19
|
+
pattern?: string;
|
|
9
20
|
};
|
|
10
21
|
|
|
11
22
|
export type PublicFormDefinition = {
|
package/src/core/index.ts
CHANGED
|
@@ -36,6 +36,8 @@ export {
|
|
|
36
36
|
isParentNode,
|
|
37
37
|
isFormFieldType,
|
|
38
38
|
FORM_FIELD_TYPES,
|
|
39
|
+
FIELD_NAME_PATTERN,
|
|
40
|
+
MAX_FIELD_NAME,
|
|
39
41
|
isHeadingNode,
|
|
40
42
|
isUnknownNode,
|
|
41
43
|
FormNode,
|
|
@@ -52,6 +54,7 @@ export {
|
|
|
52
54
|
PostContentNode,
|
|
53
55
|
PostImageNode,
|
|
54
56
|
PostLinkNode,
|
|
57
|
+
PaginationNode,
|
|
55
58
|
} from "./schema/layout.ts";
|
|
56
59
|
export {
|
|
57
60
|
type FieldKind,
|
|
@@ -63,6 +66,8 @@ export {
|
|
|
63
66
|
ELEMENTS,
|
|
64
67
|
ELEMENT_DESCRIPTORS,
|
|
65
68
|
defaultElement,
|
|
69
|
+
iconHasAdjustableStroke,
|
|
70
|
+
iconHasOwnColors,
|
|
66
71
|
type ElementType,
|
|
67
72
|
} from "./elements/index.ts";
|
|
68
73
|
export {
|
|
@@ -100,6 +105,7 @@ export {
|
|
|
100
105
|
type LayoutValidation,
|
|
101
106
|
type DesignValidation,
|
|
102
107
|
} from "./validate.ts";
|
|
108
|
+
export { nestingIssues } from "./nesting.ts";
|
|
103
109
|
export {
|
|
104
110
|
DESIGN_SCHEMA_VERSION,
|
|
105
111
|
DEFAULT_STYLE_TAGS,
|
|
@@ -111,11 +117,15 @@ export {
|
|
|
111
117
|
type DefaultStyleTag,
|
|
112
118
|
} from "./schema/design.ts";
|
|
113
119
|
export {
|
|
120
|
+
MAX_VARIABLES,
|
|
121
|
+
variableListFull,
|
|
114
122
|
findVariableUsages,
|
|
115
123
|
findVariableUsagesInDesign,
|
|
116
124
|
clearVariableRefs,
|
|
117
125
|
removeVariable,
|
|
118
126
|
renameVariable,
|
|
127
|
+
variableNameTaken,
|
|
128
|
+
variableNameTakenMessage,
|
|
119
129
|
duplicateVariable,
|
|
120
130
|
deleteVariable,
|
|
121
131
|
refMatchesKind,
|
|
@@ -138,6 +148,8 @@ export {
|
|
|
138
148
|
export { FORMS_SUBMIT_PATH } from "./render/index.ts";
|
|
139
149
|
|
|
140
150
|
export {
|
|
151
|
+
cleanClassName,
|
|
152
|
+
MAX_CLASSES,
|
|
141
153
|
moveClassId,
|
|
142
154
|
addClassId,
|
|
143
155
|
removeClassId,
|
|
@@ -146,11 +158,25 @@ export {
|
|
|
146
158
|
duplicateClass,
|
|
147
159
|
moveDesignClass,
|
|
148
160
|
renameClass,
|
|
161
|
+
classNameTaken,
|
|
162
|
+
classNameTakenMessage,
|
|
149
163
|
patchClassStyle,
|
|
150
164
|
replaceClassId,
|
|
165
|
+
hasLocalStyles,
|
|
166
|
+
localToClassRefusal,
|
|
167
|
+
localStylesToClass,
|
|
151
168
|
} from "./design/classes.ts";
|
|
152
169
|
export { hasStateStyles, patchClassState, patchStates } from "./design/states.ts";
|
|
153
|
-
export {
|
|
170
|
+
export {
|
|
171
|
+
designFromJson,
|
|
172
|
+
designToJson,
|
|
173
|
+
importLosses,
|
|
174
|
+
MAX_DESIGN_FILE_BYTES,
|
|
175
|
+
type DesignImport,
|
|
176
|
+
type ImportRename,
|
|
177
|
+
uniqueImportNames,
|
|
178
|
+
type ImportLosses,
|
|
179
|
+
} from "./design/transfer.ts";
|
|
154
180
|
export {
|
|
155
181
|
patchClassDevices,
|
|
156
182
|
patchDeviceStyle,
|
|
@@ -168,7 +194,20 @@ export { escapeAttr, escapeText } from "./sanitize/escape.ts";
|
|
|
168
194
|
export { sanitizeHref } from "./sanitize/href.ts";
|
|
169
195
|
export { isSafeFontStack } from "./sanitize/css.ts";
|
|
170
196
|
export { sanitizeMediaUrl } from "./sanitize/media-url.ts";
|
|
171
|
-
export {
|
|
197
|
+
export {
|
|
198
|
+
sanitizeSvgMarkup,
|
|
199
|
+
sanitizeSvgReport,
|
|
200
|
+
isSafeSvgMarkup,
|
|
201
|
+
isAllowedSvgImageHref,
|
|
202
|
+
type SvgReport,
|
|
203
|
+
} from "./sanitize/svg.ts";
|
|
204
|
+
export {
|
|
205
|
+
prepareUploadedSvg,
|
|
206
|
+
UPLOAD_SVG_MAX_BYTES,
|
|
207
|
+
type PreparedSvg,
|
|
208
|
+
type UploadedIcon,
|
|
209
|
+
type UploadedIconItem,
|
|
210
|
+
} from "./sanitize/svg-upload.ts";
|
|
172
211
|
export { resolveEmbedUrl, type EmbedTarget } from "./sanitize/embed-url.ts";
|
|
173
212
|
export { summarizeLayout, type LayoutSummary } from "./stats.ts";
|
|
174
213
|
export {
|
|
@@ -185,6 +224,7 @@ export {
|
|
|
185
224
|
export {
|
|
186
225
|
REASONS,
|
|
187
226
|
addNode,
|
|
227
|
+
addNodeNear,
|
|
188
228
|
canDrop,
|
|
189
229
|
duplicateNode,
|
|
190
230
|
firstChild,
|
|
@@ -201,6 +241,7 @@ export {
|
|
|
201
241
|
subtreeSize,
|
|
202
242
|
withFreshIds,
|
|
203
243
|
layoutFromPageTemplate,
|
|
244
|
+
CSS_ID_KEPT,
|
|
204
245
|
type Allowed,
|
|
205
246
|
type Arranged,
|
|
206
247
|
type DragSource,
|
|
@@ -278,6 +319,18 @@ export {
|
|
|
278
319
|
|
|
279
320
|
export { POPUP_CHROME_CSS, wrapPopupMarkup, type PopupPublicConfig } from "./theme/popup-markup.ts";
|
|
280
321
|
|
|
322
|
+
export {
|
|
323
|
+
FLOAT_EDGES,
|
|
324
|
+
defaultFloatSettings,
|
|
325
|
+
validateFloatSettings,
|
|
326
|
+
FLOAT_CHROME_CSS,
|
|
327
|
+
floatHasOwnSurface,
|
|
328
|
+
wrapFloatMarkup,
|
|
329
|
+
type FloatEdge,
|
|
330
|
+
type FloatSettings,
|
|
331
|
+
type FloatValidation,
|
|
332
|
+
} from "./theme/float.ts";
|
|
333
|
+
|
|
281
334
|
export {
|
|
282
335
|
SAMPLE_POST,
|
|
283
336
|
portableTextToVNodes,
|
|
@@ -288,8 +341,19 @@ export {
|
|
|
288
341
|
type ThemePostFields,
|
|
289
342
|
type ThemeDynamicData,
|
|
290
343
|
} from "./theme/dynamic.ts";
|
|
344
|
+
export {
|
|
345
|
+
archivePagePath,
|
|
346
|
+
archivePageTitle,
|
|
347
|
+
DEFAULT_PER_PAGE,
|
|
348
|
+
loopPerPage,
|
|
349
|
+
MAX_ARCHIVE_PAGE,
|
|
350
|
+
paginationItems,
|
|
351
|
+
splitArchivePage,
|
|
352
|
+
type ArchivePagination,
|
|
353
|
+
type PaginationItem,
|
|
354
|
+
} from "./theme/pagination.ts";
|
|
291
355
|
|
|
292
|
-
export { layoutHasTabs } from "./tabs/presence.ts";
|
|
356
|
+
export { layoutHasMenuDropdown, layoutHasTabs } from "./tabs/presence.ts";
|
|
293
357
|
export {
|
|
294
358
|
CLIPBOARD_FORMAT,
|
|
295
359
|
CLIPBOARD_VERSION,
|
package/src/core/limits.ts
CHANGED
|
@@ -8,10 +8,54 @@ export type Migration = (doc: Record<string, unknown>) => Record<string, unknown
|
|
|
8
8
|
* v4 → v5 (D-036) per-device styles, v5 → v6 (D-038) synced sections,
|
|
9
9
|
* v6 → v7 (D-039) CSS Grid, v7 → v8 (D-041) entrance animations, and v8 → v9
|
|
10
10
|
* (D-042) attributes, accordion, richer entrances, post date and author, background video,
|
|
11
|
-
* a link on a box, and tag defaults
|
|
11
|
+
* a link on a box, and tag defaults, and v9 → v10 (D-044, D-039) per-side border widths,
|
|
12
|
+
* per-corner radii and grid columns per device, and v10 → v11 (D-045) the layout Section and node
|
|
13
|
+
* labels, and v11 → v12 (W-160) rewrites a gradient `{ angle, from, to }` into
|
|
14
|
+
* `{ type: "linear", angle, stops }`. Every other value is unchanged.
|
|
12
15
|
*/
|
|
13
16
|
const unchanged: Migration = (doc) => doc;
|
|
14
17
|
|
|
18
|
+
const isRecord = (value: unknown): value is Record<string, unknown> =>
|
|
19
|
+
typeof value === "object" && value !== null && !Array.isArray(value);
|
|
20
|
+
|
|
21
|
+
/** v11 two-stop gradient → v12 stops. A gradient that already has `stops` is left as it is. */
|
|
22
|
+
function convertGradient(value: unknown): unknown {
|
|
23
|
+
if (!isRecord(value) || Array.isArray(value["stops"])) return value;
|
|
24
|
+
if (!("from" in value) || !("to" in value)) return value;
|
|
25
|
+
const angle = value["angle"];
|
|
26
|
+
return {
|
|
27
|
+
type: "linear",
|
|
28
|
+
angle: typeof angle === "number" ? angle : 180,
|
|
29
|
+
stops: [
|
|
30
|
+
{ color: value["from"], at: 0 },
|
|
31
|
+
{ color: value["to"], at: 100 },
|
|
32
|
+
],
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function walkGradients(value: unknown): unknown {
|
|
37
|
+
if (Array.isArray(value)) {
|
|
38
|
+
let changed = false;
|
|
39
|
+
const next = value.map((item) => {
|
|
40
|
+
const child = walkGradients(item);
|
|
41
|
+
if (child !== item) changed = true;
|
|
42
|
+
return child;
|
|
43
|
+
});
|
|
44
|
+
return changed ? next : value;
|
|
45
|
+
}
|
|
46
|
+
if (!isRecord(value)) return value;
|
|
47
|
+
let changed = false;
|
|
48
|
+
const next: Record<string, unknown> = {};
|
|
49
|
+
for (const [key, child] of Object.entries(value)) {
|
|
50
|
+
const converted = key === "gradient" ? convertGradient(child) : walkGradients(child);
|
|
51
|
+
if (converted !== child) changed = true;
|
|
52
|
+
next[key] = converted;
|
|
53
|
+
}
|
|
54
|
+
return changed ? next : value;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const gradients: Migration = (doc) => walkGradients(doc) as Record<string, unknown>;
|
|
58
|
+
|
|
15
59
|
/** `LAYOUT_MIGRATIONS[n]` upgrades a version-n layout to version n + 1. Migrations must be pure. */
|
|
16
60
|
export const LAYOUT_MIGRATIONS: Readonly<Record<number, Migration>> = {
|
|
17
61
|
1: unchanged,
|
|
@@ -22,6 +66,9 @@ export const LAYOUT_MIGRATIONS: Readonly<Record<number, Migration>> = {
|
|
|
22
66
|
6: unchanged,
|
|
23
67
|
7: unchanged,
|
|
24
68
|
8: unchanged,
|
|
69
|
+
9: unchanged,
|
|
70
|
+
10: unchanged,
|
|
71
|
+
11: gradients,
|
|
25
72
|
};
|
|
26
73
|
|
|
27
74
|
/** `DESIGN_MIGRATIONS[n]` upgrades a version-n design document to version n + 1. */
|
|
@@ -34,6 +81,9 @@ export const DESIGN_MIGRATIONS: Readonly<Record<number, Migration>> = {
|
|
|
34
81
|
6: unchanged,
|
|
35
82
|
7: unchanged,
|
|
36
83
|
8: unchanged,
|
|
84
|
+
9: unchanged,
|
|
85
|
+
10: unchanged,
|
|
86
|
+
11: gradients,
|
|
37
87
|
};
|
|
38
88
|
|
|
39
89
|
export type UpgradeResult =
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { REASONS } from "./arrange.ts";
|
|
2
|
+
import { isFormFieldType, isFormNode, type Layout, type LayoutNode } from "./schema/layout.ts";
|
|
3
|
+
import { nodeChildren } from "./tree-ops.ts";
|
|
4
|
+
import type { LayoutIssue } from "./validate.ts";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Elements in a parent the editor would never let them into: a menu item outside a Menu, a tab
|
|
8
|
+
* panel outside Tabs, a form field outside a form, a form in a form, and so on (W-225). The
|
|
9
|
+
* same rules and messages as drag and drop (arrange.ts DROP_RULES). The editor can't build
|
|
10
|
+
* these trees, but the content API accepted them and they render broken markup (an orphan
|
|
11
|
+
* `<li>`, a panel no tab opens). Not part of validateLayout, so stored pages still render and
|
|
12
|
+
* a copied field can still be pasted; the save hook refuses them instead.
|
|
13
|
+
*/
|
|
14
|
+
export function nestingIssues(layout: Layout, max = 5): LayoutIssue[] {
|
|
15
|
+
const issues: LayoutIssue[] = [];
|
|
16
|
+
const add = (path: string, node: LayoutNode, reason: string) => {
|
|
17
|
+
if (issues.length < max) {
|
|
18
|
+
issues.push({ path, code: "nesting", message: `${reason} (${node.type} ${node.id})` });
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
const walk = (node: LayoutNode, path: string, inForm: boolean): void => {
|
|
22
|
+
const kids = nodeChildren(node);
|
|
23
|
+
for (const [i, child] of kids.entries()) {
|
|
24
|
+
if (issues.length >= max) return;
|
|
25
|
+
const at = `${path}.children[${i}]`;
|
|
26
|
+
const reason = misplaced(node, child, inForm);
|
|
27
|
+
if (reason) add(at, child, reason);
|
|
28
|
+
walk(child, at, inForm || isFormNode(child));
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
walk(layout.root, "root", isFormNode(layout.root));
|
|
32
|
+
return issues;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function misplaced(parent: LayoutNode, child: LayoutNode, inForm: boolean): string | undefined {
|
|
36
|
+
if (child.type === "tab-panel" && parent.type !== "tabs") return REASONS.tabOutsideTabs;
|
|
37
|
+
if (parent.type === "tabs" && child.type !== "tab-panel") return REASONS.onlyTabPanels;
|
|
38
|
+
if (child.type === "accordion-item" && parent.type !== "accordion") {
|
|
39
|
+
return REASONS.itemOutsideAccordion;
|
|
40
|
+
}
|
|
41
|
+
if (parent.type === "accordion" && child.type !== "accordion-item") {
|
|
42
|
+
return REASONS.onlyAccordionItems;
|
|
43
|
+
}
|
|
44
|
+
if (child.type === "menu-item" && parent.type !== "menu" && parent.type !== "menu-item") {
|
|
45
|
+
return REASONS.itemOutsideMenu;
|
|
46
|
+
}
|
|
47
|
+
if (parent.type === "menu" && child.type !== "menu-item") return REASONS.onlyMenuItems;
|
|
48
|
+
if (isFormNode(child) && inForm) return REASONS.nestedForm;
|
|
49
|
+
if (isFormFieldType(child.type) && !inForm) return REASONS.fieldOutsideForm;
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
@@ -11,4 +11,11 @@ export type RenderContext = {
|
|
|
11
11
|
definitions: FormDefinitions;
|
|
12
12
|
/** Renders child nodes against the given dynamic data, dropping those that render nothing. */
|
|
13
13
|
children: (nodes: LayoutNode[], dynamic: ThemeDynamicData | undefined) => VNode[];
|
|
14
|
+
/**
|
|
15
|
+
* An HTML id unique in this render (W-249): `base` the first time, then `base-r2`, `base-r3`.
|
|
16
|
+
* The same synced section placed twice, or a loop item repeated per post, renders the same
|
|
17
|
+
* element ids again; Tabs, form fields and the honeypot use this so labels and radio groups
|
|
18
|
+
* stay with their own copy.
|
|
19
|
+
*/
|
|
20
|
+
uniqueId: (base: string) => string;
|
|
14
21
|
};
|
|
@@ -1,10 +1,25 @@
|
|
|
1
|
-
import type { LayoutNode } from "../schema/layout.ts";
|
|
1
|
+
import type { LayoutNode, POST_DATE_FORMATS } from "../schema/layout.ts";
|
|
2
2
|
import { sanitizeHref } from "../sanitize/href.ts";
|
|
3
3
|
import { sanitizeMediaUrl } from "../sanitize/media-url.ts";
|
|
4
4
|
import { portableTextToVNodes, type ThemePostFields } from "../theme/dynamic.ts";
|
|
5
5
|
import type { RenderMode } from "./context.ts";
|
|
6
6
|
import type { VNode } from "./vnode.ts";
|
|
7
7
|
|
|
8
|
+
/**
|
|
9
|
+
* W-196: only an ISO date (`2026-10-06`, optionally with a time) is read as a date. `Date.parse`
|
|
10
|
+
* also takes text like "Spring 2026" (as Jan 1) or "2026-02-30", which would show a wrong date.
|
|
11
|
+
*/
|
|
12
|
+
const parseIsoDate = (raw: string): number => {
|
|
13
|
+
const match = /^(\d{4})-(\d{2})-(\d{2})(?:[T ][\d:.]+(?:Z|[+-]\d{2}:?\d{2})?)?$/.exec(raw);
|
|
14
|
+
if (!match) return Number.NaN;
|
|
15
|
+
const parsed = Date.parse(raw.replace(" ", "T"));
|
|
16
|
+
if (Number.isNaN(parsed)) return Number.NaN;
|
|
17
|
+
const day = new Date(Date.UTC(Number(match[1]), Number(match[2]) - 1, Number(match[3])));
|
|
18
|
+
return day.getUTCDate() === Number(match[3]) && day.getUTCMonth() === Number(match[2]) - 1
|
|
19
|
+
? parsed
|
|
20
|
+
: Number.NaN;
|
|
21
|
+
};
|
|
22
|
+
|
|
8
23
|
type Attrs = Record<string, string>;
|
|
9
24
|
|
|
10
25
|
type PostField = {
|
|
@@ -18,6 +33,15 @@ type PostField = {
|
|
|
18
33
|
|
|
19
34
|
const HEADING_TAGS = ["h1", "h2", "h3", "h4", "h5", "h6"] as const;
|
|
20
35
|
|
|
36
|
+
type PostDateFormat = (typeof POST_DATE_FORMATS)[number];
|
|
37
|
+
|
|
38
|
+
/** In UTC, so the date doesn't move with the server's time zone. */
|
|
39
|
+
function formatPostDate(time: number, format: PostDateFormat): string {
|
|
40
|
+
const date = new Date(time);
|
|
41
|
+
if (format === "numeric") return date.toISOString().slice(0, 10);
|
|
42
|
+
return new Intl.DateTimeFormat("en", { dateStyle: format, timeZone: "UTC" }).format(date);
|
|
43
|
+
}
|
|
44
|
+
|
|
21
45
|
const props = <T>(node: LayoutNode) => node.props as T;
|
|
22
46
|
|
|
23
47
|
const POST_FIELDS = new Map<string, PostField>([
|
|
@@ -36,8 +60,13 @@ const POST_FIELDS = new Map<string, PostField>([
|
|
|
36
60
|
"post-excerpt",
|
|
37
61
|
{
|
|
38
62
|
placeholder: (attrs) => ({ tag: "p", attrs, children: ["Post excerpt…"] }),
|
|
39
|
-
render: (
|
|
40
|
-
|
|
63
|
+
render: (node, attrs, post) => {
|
|
64
|
+
if (!post.excerpt) return undefined;
|
|
65
|
+
const max = props<{ maxWords?: number }>(node).maxWords;
|
|
66
|
+
const words = post.excerpt.trim().split(/\s+/);
|
|
67
|
+
const text = max && words.length > max ? `${words.slice(0, max).join(" ")}…` : post.excerpt;
|
|
68
|
+
return { tag: "p", attrs, children: [text] };
|
|
69
|
+
},
|
|
41
70
|
},
|
|
42
71
|
],
|
|
43
72
|
[
|
|
@@ -103,16 +132,15 @@ const POST_FIELDS = new Map<string, PostField>([
|
|
|
103
132
|
{
|
|
104
133
|
placeholder: (attrs) => ({ tag: "time", attrs, children: ["Post date"] }),
|
|
105
134
|
has: (post) => !!post.publishedAt?.trim(),
|
|
106
|
-
render: (
|
|
135
|
+
render: (node, attrs, post) => {
|
|
107
136
|
const raw = post.publishedAt?.trim();
|
|
108
137
|
if (!raw) return undefined;
|
|
109
|
-
const parsed =
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
return { tag: "time", attrs: { ...attrs, datetime: raw.slice(0, 80) }, children: [text] };
|
|
138
|
+
const parsed = parseIsoDate(raw);
|
|
139
|
+
const format = props<{ format?: PostDateFormat }>(node).format ?? "medium";
|
|
140
|
+
const text = Number.isNaN(parsed) ? raw.slice(0, 80) : formatPostDate(parsed, format);
|
|
141
|
+
// W-196: `datetime` must be machine-readable, so a date we can't read only shows as text.
|
|
142
|
+
const timeAttrs = Number.isNaN(parsed) ? attrs : { ...attrs, datetime: raw.slice(0, 80) };
|
|
143
|
+
return { tag: "time", attrs: timeAttrs, children: [text] };
|
|
116
144
|
},
|
|
117
145
|
},
|
|
118
146
|
],
|
|
@@ -6,14 +6,33 @@ import type { VNode } from "./vnode.ts";
|
|
|
6
6
|
const ATTR_NAME = /^(?:data|aria)-[a-z][a-z0-9-]{0,40}$/;
|
|
7
7
|
const BOX = new Set(["container", "div-block", "flexbox", "grid"]);
|
|
8
8
|
|
|
9
|
-
/**
|
|
9
|
+
/**
|
|
10
|
+
* Names the EmDash forms client reads (`[data-ec-form]`, `[data-page]`, `[data-error-for]`…). One of
|
|
11
|
+
* them on an element would make the client treat it as a form, a form page or an error slot (W-191).
|
|
12
|
+
*/
|
|
13
|
+
const FORMS_RUNTIME_ATTRS = new Set([
|
|
14
|
+
"data-condition",
|
|
15
|
+
"data-error-for",
|
|
16
|
+
"data-form-id",
|
|
17
|
+
"data-form-status",
|
|
18
|
+
"data-page",
|
|
19
|
+
"data-sitekey",
|
|
20
|
+
"data-submit-label",
|
|
21
|
+
"data-was-required",
|
|
22
|
+
]);
|
|
23
|
+
|
|
24
|
+
/** Custom attribute names EmVB keeps for itself: the editor's and the forms client's. */
|
|
25
|
+
export const isReservedAttribute = (name: string): boolean =>
|
|
26
|
+
name.startsWith("data-emvb") || name.startsWith("data-ec-") || FORMS_RUNTIME_ATTRS.has(name);
|
|
27
|
+
|
|
28
|
+
/** `data-*` and `aria-*` from Advanced, minus the reserved names (`isReservedAttribute`). */
|
|
10
29
|
export function customAttributes(node: LayoutNode): Record<string, string> {
|
|
11
30
|
const list = node.attributes;
|
|
12
31
|
if (!list) return {};
|
|
13
32
|
const attrs: Record<string, string> = {};
|
|
14
33
|
const seen = new Set<string>();
|
|
15
34
|
for (const item of list) {
|
|
16
|
-
if (!ATTR_NAME.test(item.name) || item.name
|
|
35
|
+
if (!ATTR_NAME.test(item.name) || isReservedAttribute(item.name)) continue;
|
|
17
36
|
if (seen.has(item.name) || item.value.length > 200) continue;
|
|
18
37
|
if ([...item.value].some((char) => char.charCodeAt(0) < 32)) continue;
|
|
19
38
|
seen.add(item.name);
|
|
@@ -29,7 +48,7 @@ function childrenOf(node: LayoutNode): LayoutNode[] {
|
|
|
29
48
|
/** A link, a button, or a box that is already a link. */
|
|
30
49
|
function containsInteractive(node: LayoutNode): boolean {
|
|
31
50
|
if (node.type === "link" || node.type === "post-link" || node.type === "button") return true;
|
|
32
|
-
if (BOX.has(node.type)) {
|
|
51
|
+
if (BOX.has(node.type) || node.type === "heading" || node.type === "icon") {
|
|
33
52
|
const href = (node.props as { href?: unknown }).href;
|
|
34
53
|
if (typeof href === "string" && href.trim()) return true;
|
|
35
54
|
}
|