@perkyzz/emvb 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +57 -2
- package/package.json +72 -4
- package/src/admin/access/RequireEditor.tsx +39 -0
- package/src/admin/access/role.ts +36 -0
- package/src/admin/access/sidebar-shim.ts +108 -0
- package/src/admin/api.ts +48 -0
- package/src/admin/content-api.ts +147 -0
- package/src/admin/editor/Editor.tsx +457 -0
- package/src/admin/editor/EditorOverlay.tsx +54 -0
- package/src/admin/editor/ShortcutsDialog.tsx +30 -0
- package/src/admin/editor/SmallScreenNotice.tsx +20 -0
- package/src/admin/editor/TopBar.tsx +179 -0
- package/src/admin/editor/canvas/CanvasFrame.tsx +355 -0
- package/src/admin/editor/canvas/CanvasTextEdit.tsx +87 -0
- package/src/admin/editor/canvas/DeviceBar.tsx +50 -0
- package/src/admin/editor/canvas/EmptyCanvas.tsx +49 -0
- package/src/admin/editor/canvas/SelectionOverlay.tsx +185 -0
- package/src/admin/editor/canvas/canvas-events.ts +232 -0
- package/src/admin/editor/canvas/state-preview.ts +19 -0
- package/src/admin/editor/canvas/tab-reveal.ts +35 -0
- package/src/admin/editor/canvas/vnode-react.tsx +49 -0
- package/src/admin/editor/clipboard-store.ts +44 -0
- package/src/admin/editor/dialogs.tsx +125 -0
- package/src/admin/editor/dnd/drag-stash.ts +27 -0
- package/src/admin/editor/dnd/drop-target.ts +101 -0
- package/src/admin/editor/dnd/new-element.ts +32 -0
- package/src/admin/editor/editor-css.ts +539 -0
- package/src/admin/editor/exit.ts +27 -0
- package/src/admin/editor/panels/AddPanel.tsx +142 -0
- package/src/admin/editor/panels/ClassesSection.tsx +334 -0
- package/src/admin/editor/panels/ColorControl.tsx +230 -0
- package/src/admin/editor/panels/ConditionsEditor.tsx +201 -0
- package/src/admin/editor/panels/ElementPanel.tsx +629 -0
- package/src/admin/editor/panels/LayersPanel.tsx +336 -0
- package/src/admin/editor/panels/LeftPanel.tsx +77 -0
- package/src/admin/editor/panels/PageSettings.tsx +126 -0
- package/src/admin/editor/panels/SettingsPanel.tsx +101 -0
- package/src/admin/editor/panels/SiteStylesDrawer.tsx +392 -0
- package/src/admin/editor/panels/TriggerSettings.tsx +132 -0
- package/src/admin/editor/panels/TriggersEditor.tsx +197 -0
- package/src/admin/editor/panels/VariableSection.tsx +492 -0
- package/src/admin/editor/panels/settings/BackgroundControls.tsx +320 -0
- package/src/admin/editor/panels/settings/ClassChip.tsx +167 -0
- package/src/admin/editor/panels/settings/ClassChipInput.tsx +349 -0
- package/src/admin/editor/panels/settings/DraftTextField.tsx +201 -0
- package/src/admin/editor/panels/settings/EffectsControls.tsx +347 -0
- package/src/admin/editor/panels/settings/FieldBindControl.tsx +83 -0
- package/src/admin/editor/panels/settings/FieldControl.tsx +150 -0
- package/src/admin/editor/panels/settings/FormBindControl.tsx +97 -0
- package/src/admin/editor/panels/settings/IconPicker.tsx +109 -0
- package/src/admin/editor/panels/settings/LengthRow.tsx +181 -0
- package/src/admin/editor/panels/settings/LoopItemBindControl.tsx +124 -0
- package/src/admin/editor/panels/settings/MediaPicker.tsx +218 -0
- package/src/admin/editor/panels/settings/NumberRow.tsx +154 -0
- package/src/admin/editor/panels/settings/StateSwitcher.tsx +87 -0
- package/src/admin/editor/panels/settings/StyleRow.tsx +480 -0
- package/src/admin/editor/panels/settings/VariableBinding.tsx +167 -0
- package/src/admin/editor/panels/settings/class-suggest.ts +51 -0
- package/src/admin/editor/panels/settings/length-units.ts +83 -0
- package/src/admin/editor/panels/settings/node-props.ts +11 -0
- package/src/admin/editor/panels/settings/style-sections.ts +291 -0
- package/src/admin/editor/panels/site-list.tsx +206 -0
- package/src/admin/editor/panels/variable-values.ts +73 -0
- package/src/admin/editor/section-templates.ts +50 -0
- package/src/admin/editor/shortcuts.ts +20 -0
- package/src/admin/editor/store.ts +212 -0
- package/src/admin/editor/useClipboardActions.ts +136 -0
- package/src/admin/editor/useEditorCommands.ts +142 -0
- package/src/admin/editor/useEditorData.ts +167 -0
- package/src/admin/editor/useEditorShortcuts.ts +148 -0
- package/src/admin/editor/useMediaQuery.ts +20 -0
- package/src/admin/editor/useNodeActions.ts +122 -0
- package/src/admin/editor/useSave.ts +185 -0
- package/src/admin/forms-api.ts +73 -0
- package/src/admin/index.tsx +20 -0
- package/src/admin/media-api.ts +68 -0
- package/src/admin/pages/CreateDialog.tsx +150 -0
- package/src/admin/pages/EditorPage.tsx +57 -0
- package/src/admin/pages/NewPageDialog.tsx +83 -0
- package/src/admin/pages/NewThemePartDialog.tsx +61 -0
- package/src/admin/pages/PageList.tsx +71 -0
- package/src/admin/pages/PagesPage.tsx +25 -0
- package/src/admin/pages/SetupShell.tsx +90 -0
- package/src/admin/pages/ThemeBuilderPage.tsx +25 -0
- package/src/admin/pages/ThemePartList.tsx +202 -0
- package/src/admin/pages/list-kit.tsx +75 -0
- package/src/admin/setup/plan.ts +150 -0
- package/src/admin/setup/run.ts +61 -0
- package/src/admin/setup/spec.ts +100 -0
- package/src/admin/setup/useSetupStatus.ts +62 -0
- package/src/admin/theme-api.ts +186 -0
- package/src/admin/ui.ts +231 -0
- package/src/admin/widgets/LayoutField.tsx +67 -0
- package/src/astro/EmVBPage.astro +37 -0
- package/src/astro/env.d.ts +5 -0
- package/src/astro/forms/EmVBFormsRuntime.astro +9 -0
- package/src/astro/forms/index.ts +1 -0
- package/src/astro/forms-definitions.ts +104 -0
- package/src/astro/index.ts +15 -0
- package/src/astro/popups/EmVBPopupsRuntime.astro +9 -0
- package/src/astro/popups/index.ts +1 -0
- package/src/astro/popups/runtime.ts +246 -0
- package/src/astro/render.ts +74 -0
- package/src/astro/resolve-theme.ts +371 -0
- package/src/astro/resolve.ts +65 -0
- package/src/astro/tabs/EmVBTabsRuntime.astro +10 -0
- package/src/astro/tabs/index.ts +1 -0
- package/src/astro/tabs/runtime.ts +111 -0
- package/src/astro/theme-context.ts +81 -0
- package/src/astro/theme-posts.ts +84 -0
- package/src/constants.ts +12 -0
- package/src/core/arrange.ts +360 -0
- package/src/core/clipboard.ts +422 -0
- package/src/core/css/generate.ts +219 -0
- package/src/core/css/scope.ts +88 -0
- package/src/core/design/cascade.ts +28 -0
- package/src/core/design/classes.ts +138 -0
- package/src/core/design/devices.ts +56 -0
- package/src/core/design/states.ts +49 -0
- package/src/core/design/transfer.ts +33 -0
- package/src/core/design/variables.ts +319 -0
- package/src/core/elements/definition.ts +12 -0
- package/src/core/elements/dynamic-elements.ts +173 -0
- package/src/core/elements/form-elements.ts +204 -0
- package/src/core/elements/index.ts +742 -0
- package/src/core/elements/plain-text.ts +32 -0
- package/src/core/forms/binding.ts +61 -0
- package/src/core/forms/definition.ts +34 -0
- package/src/core/forms/success-layout.ts +63 -0
- package/src/core/icons/catalog.ts +273 -0
- package/src/core/index.ts +316 -0
- package/src/core/limits.ts +7 -0
- package/src/core/migrate/index.ts +76 -0
- package/src/core/render/context.ts +14 -0
- package/src/core/render/dynamic-post.ts +147 -0
- package/src/core/render/extras.ts +79 -0
- package/src/core/render/form.ts +137 -0
- package/src/core/render/index.ts +274 -0
- package/src/core/render/loop.ts +36 -0
- package/src/core/render/section.ts +33 -0
- package/src/core/render/tabs.ts +72 -0
- package/src/core/render/vnode.ts +87 -0
- package/src/core/sanitize/css.ts +591 -0
- package/src/core/sanitize/embed-url.ts +103 -0
- package/src/core/sanitize/escape.ts +10 -0
- package/src/core/sanitize/href.ts +6 -0
- package/src/core/sanitize/media-url.ts +7 -0
- package/src/core/sanitize/svg.ts +293 -0
- package/src/core/sanitize/url.ts +31 -0
- package/src/core/schema/descriptors.ts +33 -0
- package/src/core/schema/design.ts +88 -0
- package/src/core/schema/layout.ts +817 -0
- package/src/core/schema/state-names.ts +4 -0
- package/src/core/schema/style.ts +257 -0
- package/src/core/stats.ts +18 -0
- package/src/core/tabs/presence.ts +16 -0
- package/src/core/theme/conditions.ts +321 -0
- package/src/core/theme/dynamic.ts +133 -0
- package/src/core/theme/parse-doc.ts +36 -0
- package/src/core/theme/part-types.ts +79 -0
- package/src/core/theme/popup-markup.ts +39 -0
- package/src/core/theme/popup-rules.ts +61 -0
- package/src/core/theme/triggers.ts +104 -0
- package/src/core/tree-ops.ts +139 -0
- package/src/core/validate.ts +185 -0
- package/src/index.ts +18 -0
- package/src/server/design-routes.ts +125 -0
- package/src/server/hooks.ts +98 -0
- package/src/server/plugin.ts +39 -0
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { STYLE_LABELS, type StyleKey } from "./style-sections.ts";
|
|
2
|
+
|
|
3
|
+
export type LengthUnit = "px" | "rem" | "em" | "%" | "vw" | "vh";
|
|
4
|
+
export type UnitChoice = LengthUnit | "auto";
|
|
5
|
+
export type LengthLiteral = { value: number; unit: LengthUnit };
|
|
6
|
+
|
|
7
|
+
const BOX: readonly UnitChoice[] = ["px", "%", "rem", "em", "vw", "vh"];
|
|
8
|
+
const BOX_AUTO: readonly UnitChoice[] = [...BOX, "auto"];
|
|
9
|
+
|
|
10
|
+
/** Units each length property offers in its unit menu (DESIGN.md § Inputs). */
|
|
11
|
+
const UNITS: Partial<Record<StyleKey, readonly UnitChoice[]>> = {
|
|
12
|
+
width: BOX_AUTO,
|
|
13
|
+
height: BOX_AUTO,
|
|
14
|
+
marginTop: BOX_AUTO,
|
|
15
|
+
marginRight: BOX_AUTO,
|
|
16
|
+
marginBottom: BOX_AUTO,
|
|
17
|
+
marginLeft: BOX_AUTO,
|
|
18
|
+
top: BOX_AUTO,
|
|
19
|
+
right: BOX_AUTO,
|
|
20
|
+
bottom: BOX_AUTO,
|
|
21
|
+
left: BOX_AUTO,
|
|
22
|
+
fontSize: ["px", "rem", "em", "%", "vw"],
|
|
23
|
+
lineHeight: ["px", "rem", "em", "%"],
|
|
24
|
+
letterSpacing: ["px", "rem", "em"],
|
|
25
|
+
borderWidth: ["px", "rem", "em"],
|
|
26
|
+
borderRadius: ["px", "%", "rem", "em"],
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export const unitsFor = (key: StyleKey): readonly UnitChoice[] => UNITS[key] ?? BOX;
|
|
30
|
+
|
|
31
|
+
const NEGATIVE = new Set<StyleKey>(["top", "right", "bottom", "left"]);
|
|
32
|
+
|
|
33
|
+
export type ParsedLength =
|
|
34
|
+
| { ok: true; value: LengthLiteral | "auto" | undefined }
|
|
35
|
+
| { ok: false; message: string };
|
|
36
|
+
|
|
37
|
+
const DRAFT = /^(-?(?:\d+(?:\.\d*)?|\.\d+))\s*(px|rem|em|%|vw|vh)?$/i;
|
|
38
|
+
|
|
39
|
+
const listed = (units: readonly string[]) =>
|
|
40
|
+
units.length > 1 ? `${units.slice(0, -1).join(", ")} or ${units.at(-1)}` : (units[0] ?? "");
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Parses a length field's text: a number in `unit`, a number with its own unit ("50%",
|
|
44
|
+
* "1.5rem"), `auto` where allowed, or empty for unset.
|
|
45
|
+
*/
|
|
46
|
+
export function parseLengthDraft(draft: string, key: StyleKey, unit: LengthUnit): ParsedLength {
|
|
47
|
+
const text = draft.trim();
|
|
48
|
+
if (text === "") return { ok: true, value: undefined };
|
|
49
|
+
const label = STYLE_LABELS[key];
|
|
50
|
+
const allowed = unitsFor(key);
|
|
51
|
+
if (text.toLowerCase() === "auto") {
|
|
52
|
+
return allowed.includes("auto")
|
|
53
|
+
? { ok: true, value: "auto" }
|
|
54
|
+
: { ok: false, message: `${label} can't be auto. Enter a number.` };
|
|
55
|
+
}
|
|
56
|
+
const match = DRAFT.exec(text);
|
|
57
|
+
const n = match ? Number(match[1]) : Number.NaN;
|
|
58
|
+
if (!match || !Number.isFinite(n)) {
|
|
59
|
+
return { ok: false, message: `Enter a number, such as 16 or 16${unit}.` };
|
|
60
|
+
}
|
|
61
|
+
const typed = (match[2]?.toLowerCase() ?? unit) as LengthUnit;
|
|
62
|
+
if (!allowed.includes(typed)) {
|
|
63
|
+
return {
|
|
64
|
+
ok: false,
|
|
65
|
+
message: `${label} takes ${listed(allowed.filter((u) => u !== "auto"))}.`,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
if (n < 0 && !NEGATIVE.has(key)) {
|
|
69
|
+
return {
|
|
70
|
+
ok: false,
|
|
71
|
+
message: `${label} can't be negative. Enter 0 or more.`,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
if (Math.abs(n) > 10_000) {
|
|
75
|
+
return {
|
|
76
|
+
ok: false,
|
|
77
|
+
message: NEGATIVE.has(key)
|
|
78
|
+
? `${label} can be from -10000 to 10000.`
|
|
79
|
+
: `${label} can be up to 10000. Enter a smaller number.`,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
return { ok: true, value: { value: n, unit: typed } };
|
|
83
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { LayoutNode } from "../../../../core/index.ts";
|
|
2
|
+
|
|
3
|
+
export const propsOf = (node: LayoutNode): Record<string, unknown> =>
|
|
4
|
+
node.props as Record<string, unknown>;
|
|
5
|
+
|
|
6
|
+
export const withProp = (node: LayoutNode, key: string, value: unknown): LayoutNode => {
|
|
7
|
+
const props = { ...propsOf(node) };
|
|
8
|
+
if (value === undefined) delete props[key];
|
|
9
|
+
else props[key] = value;
|
|
10
|
+
return { ...node, props } as LayoutNode;
|
|
11
|
+
};
|
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
import type { StyleProps } from "../../../../core/index.ts";
|
|
2
|
+
|
|
3
|
+
export type StyleSectionId =
|
|
4
|
+
| "layout"
|
|
5
|
+
| "spacing"
|
|
6
|
+
| "size"
|
|
7
|
+
| "position"
|
|
8
|
+
| "typography"
|
|
9
|
+
| "background"
|
|
10
|
+
| "border"
|
|
11
|
+
| "effects"
|
|
12
|
+
| "advanced";
|
|
13
|
+
|
|
14
|
+
export type StyleKey = keyof StyleProps;
|
|
15
|
+
|
|
16
|
+
/** Elementor v4 order (W-088); every list below follows it. */
|
|
17
|
+
const SECTION_ORDER: StyleSectionId[] = [
|
|
18
|
+
"layout",
|
|
19
|
+
"spacing",
|
|
20
|
+
"size",
|
|
21
|
+
"position",
|
|
22
|
+
"typography",
|
|
23
|
+
"background",
|
|
24
|
+
"border",
|
|
25
|
+
"effects",
|
|
26
|
+
"advanced",
|
|
27
|
+
];
|
|
28
|
+
|
|
29
|
+
const TEXT_SECTIONS: StyleSectionId[] = [
|
|
30
|
+
"spacing",
|
|
31
|
+
"size",
|
|
32
|
+
"position",
|
|
33
|
+
"typography",
|
|
34
|
+
"background",
|
|
35
|
+
"border",
|
|
36
|
+
"effects",
|
|
37
|
+
"advanced",
|
|
38
|
+
];
|
|
39
|
+
|
|
40
|
+
/** Which Style sections appear, and which opens by default (IA table). */
|
|
41
|
+
export const STYLE_UI: Record<string, { sections: StyleSectionId[]; defaultOpen: StyleSectionId }> =
|
|
42
|
+
{
|
|
43
|
+
container: {
|
|
44
|
+
sections: [
|
|
45
|
+
"layout",
|
|
46
|
+
"spacing",
|
|
47
|
+
"size",
|
|
48
|
+
"position",
|
|
49
|
+
"background",
|
|
50
|
+
"border",
|
|
51
|
+
"effects",
|
|
52
|
+
"advanced",
|
|
53
|
+
],
|
|
54
|
+
defaultOpen: "layout",
|
|
55
|
+
},
|
|
56
|
+
spacer: { sections: ["layout", "advanced"], defaultOpen: "layout" },
|
|
57
|
+
divider: {
|
|
58
|
+
sections: ["spacing", "size", "position", "border", "effects", "advanced"],
|
|
59
|
+
defaultOpen: "border",
|
|
60
|
+
},
|
|
61
|
+
heading: { sections: TEXT_SECTIONS, defaultOpen: "typography" },
|
|
62
|
+
text: { sections: TEXT_SECTIONS, defaultOpen: "typography" },
|
|
63
|
+
label: { sections: TEXT_SECTIONS, defaultOpen: "typography" },
|
|
64
|
+
link: { sections: TEXT_SECTIONS, defaultOpen: "typography" },
|
|
65
|
+
list: { sections: TEXT_SECTIONS, defaultOpen: "typography" },
|
|
66
|
+
button: { sections: TEXT_SECTIONS, defaultOpen: "background" },
|
|
67
|
+
image: {
|
|
68
|
+
sections: ["spacing", "size", "position", "border", "effects", "advanced"],
|
|
69
|
+
defaultOpen: "size",
|
|
70
|
+
},
|
|
71
|
+
icon: {
|
|
72
|
+
sections: ["spacing", "size", "position", "typography", "effects", "advanced"],
|
|
73
|
+
defaultOpen: "typography",
|
|
74
|
+
},
|
|
75
|
+
video: {
|
|
76
|
+
sections: ["spacing", "size", "position", "border", "effects", "advanced"],
|
|
77
|
+
defaultOpen: "size",
|
|
78
|
+
},
|
|
79
|
+
form: {
|
|
80
|
+
sections: [
|
|
81
|
+
"layout",
|
|
82
|
+
"spacing",
|
|
83
|
+
"size",
|
|
84
|
+
"position",
|
|
85
|
+
"background",
|
|
86
|
+
"border",
|
|
87
|
+
"effects",
|
|
88
|
+
"advanced",
|
|
89
|
+
],
|
|
90
|
+
defaultOpen: "layout",
|
|
91
|
+
},
|
|
92
|
+
"text-input": { sections: TEXT_SECTIONS, defaultOpen: "typography" },
|
|
93
|
+
textarea: { sections: TEXT_SECTIONS, defaultOpen: "typography" },
|
|
94
|
+
select: { sections: TEXT_SECTIONS, defaultOpen: "typography" },
|
|
95
|
+
checkbox: {
|
|
96
|
+
sections: ["layout", "spacing", "size", "position", "typography", "effects", "advanced"],
|
|
97
|
+
defaultOpen: "typography",
|
|
98
|
+
},
|
|
99
|
+
radio: {
|
|
100
|
+
sections: ["layout", "spacing", "size", "position", "typography", "effects", "advanced"],
|
|
101
|
+
defaultOpen: "typography",
|
|
102
|
+
},
|
|
103
|
+
submit: { sections: TEXT_SECTIONS, defaultOpen: "background" },
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
/** Types without an entry (Flexbox, Div Block, SVG, Tabs, dynamic elements) show every section. */
|
|
107
|
+
export const DEFAULT_UI = {
|
|
108
|
+
sections: SECTION_ORDER,
|
|
109
|
+
defaultOpen: "layout" as StyleSectionId,
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
export const SECTION_LABELS: Record<StyleSectionId, string> = {
|
|
113
|
+
layout: "Layout",
|
|
114
|
+
spacing: "Spacing",
|
|
115
|
+
size: "Size",
|
|
116
|
+
position: "Position",
|
|
117
|
+
typography: "Typography",
|
|
118
|
+
background: "Background",
|
|
119
|
+
border: "Border",
|
|
120
|
+
effects: "Effects",
|
|
121
|
+
advanced: "Advanced",
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
/** Style property keys shown in each section (subset of StyleProps). */
|
|
125
|
+
const SECTION_KEYS: Record<StyleSectionId, StyleKey[]> = {
|
|
126
|
+
layout: [
|
|
127
|
+
"flexDirection",
|
|
128
|
+
"flexWrap",
|
|
129
|
+
"justifyContent",
|
|
130
|
+
"alignItems",
|
|
131
|
+
"gap",
|
|
132
|
+
"gridColumnSpan",
|
|
133
|
+
"gridRowSpan",
|
|
134
|
+
],
|
|
135
|
+
spacing: [
|
|
136
|
+
"paddingTop",
|
|
137
|
+
"paddingRight",
|
|
138
|
+
"paddingBottom",
|
|
139
|
+
"paddingLeft",
|
|
140
|
+
"marginTop",
|
|
141
|
+
"marginRight",
|
|
142
|
+
"marginBottom",
|
|
143
|
+
"marginLeft",
|
|
144
|
+
],
|
|
145
|
+
size: [
|
|
146
|
+
"width",
|
|
147
|
+
"height",
|
|
148
|
+
"minWidth",
|
|
149
|
+
"minHeight",
|
|
150
|
+
"maxWidth",
|
|
151
|
+
"maxHeight",
|
|
152
|
+
"overflow",
|
|
153
|
+
"aspectRatio",
|
|
154
|
+
"objectFit",
|
|
155
|
+
],
|
|
156
|
+
position: ["position", "top", "right", "bottom", "left", "zIndex"],
|
|
157
|
+
typography: [
|
|
158
|
+
"fontFamily",
|
|
159
|
+
"fontSize",
|
|
160
|
+
"fontWeight",
|
|
161
|
+
"lineHeight",
|
|
162
|
+
"letterSpacing",
|
|
163
|
+
"textAlign",
|
|
164
|
+
"textTransform",
|
|
165
|
+
"textDecoration",
|
|
166
|
+
"color",
|
|
167
|
+
],
|
|
168
|
+
background: [
|
|
169
|
+
"backgroundColor",
|
|
170
|
+
"backgroundImage",
|
|
171
|
+
"backgroundSize",
|
|
172
|
+
"backgroundPosition",
|
|
173
|
+
"backgroundRepeat",
|
|
174
|
+
"gradient",
|
|
175
|
+
"overlay",
|
|
176
|
+
"backgroundVideo",
|
|
177
|
+
],
|
|
178
|
+
border: ["borderWidth", "borderStyle", "borderColor", "borderRadius"],
|
|
179
|
+
effects: ["opacity", "boxShadow", "filter", "cursor", "entrance", "transition"],
|
|
180
|
+
advanced: [],
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
/** Keys that only make sense on some element types. */
|
|
184
|
+
const ONLY_FOR: Partial<Record<StyleKey, string[]>> = {
|
|
185
|
+
objectFit: ["image", "video"],
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
/** Per-type filters so Spacer and Divider don't get every control. */
|
|
189
|
+
const TYPE_SECTION_KEYS: Record<string, Partial<Record<StyleSectionId, StyleKey[]>>> = {
|
|
190
|
+
spacer: { layout: [] }, // height is a content prop, shown above sections
|
|
191
|
+
divider: { size: ["width"] },
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
const OFFSETS = new Set<StyleKey>(["top", "right", "bottom", "left"]);
|
|
195
|
+
|
|
196
|
+
/** Offsets only do anything once the element is positioned (W-088). */
|
|
197
|
+
export const offsetsApply = (position: StyleProps["position"]) =>
|
|
198
|
+
position !== undefined && position !== "static";
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* The keys a section shows for a type. Offsets need `position` (the value in effect) to be
|
|
202
|
+
* other than static. With `style`, a key that is set there is always shown,
|
|
203
|
+
* even where the type wouldn't offer it, so a stored value can be seen and reset (W-088).
|
|
204
|
+
*/
|
|
205
|
+
export function keysFor(
|
|
206
|
+
type: string,
|
|
207
|
+
section: StyleSectionId,
|
|
208
|
+
style?: StyleProps,
|
|
209
|
+
position?: StyleProps["position"],
|
|
210
|
+
): StyleKey[] {
|
|
211
|
+
const offered = new Set(
|
|
212
|
+
(
|
|
213
|
+
TYPE_SECTION_KEYS[type]?.[section] ??
|
|
214
|
+
SECTION_KEYS[section].filter((key) => ONLY_FOR[key]?.includes(type) ?? true)
|
|
215
|
+
).filter((key) => !OFFSETS.has(key) || offsetsApply(position)),
|
|
216
|
+
);
|
|
217
|
+
return SECTION_KEYS[section].filter((key) => offered.has(key) || style?.[key] !== undefined);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/** The type's sections, plus any other section holding a set value, in section order. */
|
|
221
|
+
export function sectionsFor(
|
|
222
|
+
sections: StyleSectionId[],
|
|
223
|
+
style: StyleProps | undefined,
|
|
224
|
+
): StyleSectionId[] {
|
|
225
|
+
return SECTION_ORDER.filter(
|
|
226
|
+
(id) => sections.includes(id) || SECTION_KEYS[id].some((key) => style?.[key] !== undefined),
|
|
227
|
+
);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
export const STYLE_LABELS: Record<StyleKey, string> = {
|
|
231
|
+
flexDirection: "Direction",
|
|
232
|
+
flexWrap: "Wrap",
|
|
233
|
+
justifyContent: "Justify",
|
|
234
|
+
alignItems: "Align",
|
|
235
|
+
gap: "Gap",
|
|
236
|
+
gridColumnSpan: "Column span",
|
|
237
|
+
gridRowSpan: "Row span",
|
|
238
|
+
width: "Width",
|
|
239
|
+
minWidth: "Min width",
|
|
240
|
+
maxWidth: "Max width",
|
|
241
|
+
height: "Height",
|
|
242
|
+
minHeight: "Min height",
|
|
243
|
+
maxHeight: "Max height",
|
|
244
|
+
overflow: "Overflow",
|
|
245
|
+
aspectRatio: "Aspect ratio",
|
|
246
|
+
objectFit: "Object fit",
|
|
247
|
+
paddingTop: "Padding top",
|
|
248
|
+
paddingRight: "Padding right",
|
|
249
|
+
paddingBottom: "Padding bottom",
|
|
250
|
+
paddingLeft: "Padding left",
|
|
251
|
+
marginTop: "Margin top",
|
|
252
|
+
marginRight: "Margin right",
|
|
253
|
+
marginBottom: "Margin bottom",
|
|
254
|
+
marginLeft: "Margin left",
|
|
255
|
+
position: "Position",
|
|
256
|
+
top: "Top",
|
|
257
|
+
right: "Right",
|
|
258
|
+
bottom: "Bottom",
|
|
259
|
+
left: "Left",
|
|
260
|
+
zIndex: "Z-index",
|
|
261
|
+
fontFamily: "Font family",
|
|
262
|
+
fontSize: "Font size",
|
|
263
|
+
fontWeight: "Weight",
|
|
264
|
+
lineHeight: "Line height",
|
|
265
|
+
letterSpacing: "Letter spacing",
|
|
266
|
+
textAlign: "Align text",
|
|
267
|
+
textTransform: "Transform",
|
|
268
|
+
textDecoration: "Decoration",
|
|
269
|
+
color: "Color",
|
|
270
|
+
backgroundColor: "Background",
|
|
271
|
+
backgroundImage: "Image",
|
|
272
|
+
backgroundVideo: "Video",
|
|
273
|
+
backgroundSize: "Image size",
|
|
274
|
+
backgroundPosition: "Image position",
|
|
275
|
+
backgroundRepeat: "Repeat",
|
|
276
|
+
gradient: "Gradient",
|
|
277
|
+
overlay: "Overlay",
|
|
278
|
+
borderWidth: "Border width",
|
|
279
|
+
borderStyle: "Border style",
|
|
280
|
+
borderColor: "Border color",
|
|
281
|
+
borderRadius: "Radius",
|
|
282
|
+
opacity: "Opacity",
|
|
283
|
+
boxShadow: "Box shadow",
|
|
284
|
+
filter: "Filters",
|
|
285
|
+
cursor: "Cursor",
|
|
286
|
+
entrance: "Entrance",
|
|
287
|
+
transition: "Transition",
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
/** Every StyleProps key that the settings panel must be able to edit. */
|
|
291
|
+
export const CONTROLLED_STYLE_KEYS: StyleKey[] = Object.values(SECTION_KEYS).flat();
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import { Button, DropdownMenu, Input } from "@cloudflare/kumo";
|
|
2
|
+
import { DotsThreeIcon, PlusIcon, type Icon } from "@phosphor-icons/react";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { slugify } from "../../../core/index.ts";
|
|
5
|
+
import { BUTTON, FIELD, SOLID_PRIMARY } from "../../ui.ts";
|
|
6
|
+
|
|
7
|
+
/** A slug of `name` (or `fallback`) that no id in `taken` uses yet: `x`, then `x-2`, `x-3`… */
|
|
8
|
+
export function uniqueId(name: string, fallback: string, taken: Iterable<string>): string {
|
|
9
|
+
const base = slugify(name).slice(0, 34) || fallback;
|
|
10
|
+
const used = new Set(taken);
|
|
11
|
+
let id = base;
|
|
12
|
+
for (let n = 2; used.has(id); n++) id = `${base}-${n}`;
|
|
13
|
+
return id;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** Whether any of `fields` contains the lowercased query `q`. */
|
|
17
|
+
export const matches = (q: string, ...fields: string[]) =>
|
|
18
|
+
fields.some((field) => field.toLowerCase().includes(q));
|
|
19
|
+
|
|
20
|
+
/** A Site styles section heading with its item count and New button. */
|
|
21
|
+
export function SectionHead({
|
|
22
|
+
title,
|
|
23
|
+
count,
|
|
24
|
+
countProps,
|
|
25
|
+
onNew,
|
|
26
|
+
}: {
|
|
27
|
+
title: React.ReactNode;
|
|
28
|
+
count: number;
|
|
29
|
+
countProps?: Record<string, string>;
|
|
30
|
+
onNew: () => void;
|
|
31
|
+
}) {
|
|
32
|
+
return (
|
|
33
|
+
<div className="emvb-site-section-head">
|
|
34
|
+
<h3 className="emvb-field-label">
|
|
35
|
+
{title}
|
|
36
|
+
<span className="emvb-site-count" {...countProps}>
|
|
37
|
+
{count}
|
|
38
|
+
</span>
|
|
39
|
+
</h3>
|
|
40
|
+
<Button
|
|
41
|
+
type="button"
|
|
42
|
+
variant="ghost"
|
|
43
|
+
size="sm"
|
|
44
|
+
className={BUTTON}
|
|
45
|
+
icon={<PlusIcon aria-hidden="true" />}
|
|
46
|
+
onClick={onNew}
|
|
47
|
+
>
|
|
48
|
+
New
|
|
49
|
+
</Button>
|
|
50
|
+
</div>
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** The inline create form at the end of a Site styles list. */
|
|
55
|
+
export function CreateRow({
|
|
56
|
+
rowProps,
|
|
57
|
+
submitLabel,
|
|
58
|
+
onCancel,
|
|
59
|
+
onCreate,
|
|
60
|
+
children,
|
|
61
|
+
}: {
|
|
62
|
+
rowProps: Record<string, string>;
|
|
63
|
+
submitLabel: string;
|
|
64
|
+
onCancel: () => void;
|
|
65
|
+
onCreate: () => void;
|
|
66
|
+
children: React.ReactNode;
|
|
67
|
+
}) {
|
|
68
|
+
return (
|
|
69
|
+
<div className="emvb-site-create emvb-site-elevated" {...rowProps}>
|
|
70
|
+
{children}
|
|
71
|
+
<div className="emvb-dialog-actions">
|
|
72
|
+
<Button type="button" variant="secondary" className={BUTTON} onClick={onCancel}>
|
|
73
|
+
Cancel
|
|
74
|
+
</Button>
|
|
75
|
+
<Button
|
|
76
|
+
type="button"
|
|
77
|
+
variant="primary"
|
|
78
|
+
className={BUTTON}
|
|
79
|
+
style={SOLID_PRIMARY}
|
|
80
|
+
onClick={onCreate}
|
|
81
|
+
>
|
|
82
|
+
{submitLabel}
|
|
83
|
+
</Button>
|
|
84
|
+
</div>
|
|
85
|
+
</div>
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** Search shown once a Site styles list is long enough to need it. */
|
|
90
|
+
export function SiteSearch({
|
|
91
|
+
label,
|
|
92
|
+
value,
|
|
93
|
+
onChange,
|
|
94
|
+
...rest
|
|
95
|
+
}: {
|
|
96
|
+
label: string;
|
|
97
|
+
value: string;
|
|
98
|
+
onChange: (value: string) => void;
|
|
99
|
+
} & Record<`data-${string}`, string>) {
|
|
100
|
+
return (
|
|
101
|
+
<div className="emvb-site-search" {...rest}>
|
|
102
|
+
<Input
|
|
103
|
+
aria-label={label}
|
|
104
|
+
className={FIELD}
|
|
105
|
+
type="search"
|
|
106
|
+
value={value}
|
|
107
|
+
placeholder={`${label}…`}
|
|
108
|
+
onChange={(event) => onChange(event.target.value)}
|
|
109
|
+
onKeyDown={(event) => {
|
|
110
|
+
if (event.key === "Escape" && value) {
|
|
111
|
+
event.stopPropagation();
|
|
112
|
+
onChange("");
|
|
113
|
+
}
|
|
114
|
+
}}
|
|
115
|
+
/>
|
|
116
|
+
</div>
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* The name field that replaces a row's name while renaming: Enter or blur saves once, Escape
|
|
122
|
+
* cancels. `onDone` gets the trimmed new name, or null when nothing changed.
|
|
123
|
+
*/
|
|
124
|
+
export function RenameInput({
|
|
125
|
+
name,
|
|
126
|
+
label,
|
|
127
|
+
onDone,
|
|
128
|
+
}: {
|
|
129
|
+
name: string;
|
|
130
|
+
label: string;
|
|
131
|
+
onDone: (next: string | null) => void;
|
|
132
|
+
}) {
|
|
133
|
+
const ended = React.useRef(false);
|
|
134
|
+
const finish = (next: string | null) => {
|
|
135
|
+
if (ended.current) return;
|
|
136
|
+
ended.current = true;
|
|
137
|
+
const trimmed = next?.trim();
|
|
138
|
+
onDone(trimmed && trimmed !== name ? trimmed : null);
|
|
139
|
+
};
|
|
140
|
+
return (
|
|
141
|
+
<input
|
|
142
|
+
className="emvb-site-rename"
|
|
143
|
+
aria-label={label}
|
|
144
|
+
defaultValue={name}
|
|
145
|
+
maxLength={60}
|
|
146
|
+
// oxlint-disable-next-line jsx-a11y/no-autofocus -- the user asked to rename; focus moves into the field
|
|
147
|
+
autoFocus
|
|
148
|
+
onFocus={(event) => event.currentTarget.select()}
|
|
149
|
+
onKeyDown={(event) => {
|
|
150
|
+
if (event.key === "Enter") finish(event.currentTarget.value);
|
|
151
|
+
else if (event.key === "Escape") {
|
|
152
|
+
event.stopPropagation();
|
|
153
|
+
finish(null);
|
|
154
|
+
}
|
|
155
|
+
}}
|
|
156
|
+
onBlur={(event) => finish(event.currentTarget.value)}
|
|
157
|
+
/>
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export type RowAction = {
|
|
162
|
+
label: string;
|
|
163
|
+
icon: Icon;
|
|
164
|
+
onSelect: () => void;
|
|
165
|
+
/** Run once the menu has closed and handed focus back (Rename moves focus into a field). */
|
|
166
|
+
afterClose?: boolean;
|
|
167
|
+
danger?: boolean;
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
/** A Site styles row's ⋮ menu. A danger action sits last, after a separator. */
|
|
171
|
+
export function RowMenu({ label, actions }: { label: string; actions: RowAction[] }) {
|
|
172
|
+
const pending = React.useRef<(() => void) | null>(null);
|
|
173
|
+
return (
|
|
174
|
+
<DropdownMenu
|
|
175
|
+
onOpenChangeComplete={(open) => {
|
|
176
|
+
const run = pending.current;
|
|
177
|
+
if (open || !run) return;
|
|
178
|
+
pending.current = null;
|
|
179
|
+
requestAnimationFrame(run);
|
|
180
|
+
}}
|
|
181
|
+
>
|
|
182
|
+
<DropdownMenu.Trigger>
|
|
183
|
+
<button type="button" className="emvb-site-menu-btn" aria-label={label}>
|
|
184
|
+
<DotsThreeIcon size={16} weight="bold" aria-hidden="true" />
|
|
185
|
+
</button>
|
|
186
|
+
</DropdownMenu.Trigger>
|
|
187
|
+
<DropdownMenu.Content>
|
|
188
|
+
{actions.map((action) => (
|
|
189
|
+
<React.Fragment key={action.label}>
|
|
190
|
+
{action.danger && <DropdownMenu.Separator />}
|
|
191
|
+
<DropdownMenu.Item
|
|
192
|
+
icon={action.icon}
|
|
193
|
+
variant={action.danger ? "danger" : "default"}
|
|
194
|
+
onClick={() => {
|
|
195
|
+
if (action.afterClose) pending.current = action.onSelect;
|
|
196
|
+
else action.onSelect();
|
|
197
|
+
}}
|
|
198
|
+
>
|
|
199
|
+
{action.label}
|
|
200
|
+
</DropdownMenu.Item>
|
|
201
|
+
</React.Fragment>
|
|
202
|
+
))}
|
|
203
|
+
</DropdownMenu.Content>
|
|
204
|
+
</DropdownMenu>
|
|
205
|
+
);
|
|
206
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { VariableKind } from "../../../core/index.ts";
|
|
2
|
+
|
|
3
|
+
export type Length = { value: number; unit: "px" | "rem" | "em" | "%" };
|
|
4
|
+
|
|
5
|
+
const HEX = /^#(?:[0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$/i;
|
|
6
|
+
const LENGTH = /^(\d+(?:\.\d+)?|\.\d+)\s*(px|rem|em|%)?$/i;
|
|
7
|
+
const MAX_LENGTH = 10_000;
|
|
8
|
+
|
|
9
|
+
export const isLengthKind = (kind: VariableKind) => kind === "fontSize" || kind === "spacing";
|
|
10
|
+
|
|
11
|
+
/** "16", "16px", "1.5rem", "2em" or "50%" as a length (px when no unit); undefined otherwise. */
|
|
12
|
+
export function parseLength(text: string): Length | undefined {
|
|
13
|
+
const match = LENGTH.exec(text.trim());
|
|
14
|
+
if (!match) return undefined;
|
|
15
|
+
const value = Number(match[1]);
|
|
16
|
+
if (!Number.isFinite(value) || value > MAX_LENGTH) return undefined;
|
|
17
|
+
const unit = (match[2]?.toLowerCase() ?? "px") as Length["unit"];
|
|
18
|
+
return { value, unit };
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const formatLength = (length: Length) => `${length.value}${length.unit}`;
|
|
22
|
+
|
|
23
|
+
/** The length in px for previews: rem and em at 16 px, % as the 16 px base. */
|
|
24
|
+
export function lengthPx(length: Length): number {
|
|
25
|
+
if (length.unit === "px") return length.value;
|
|
26
|
+
if (length.unit === "%") return (length.value / 100) * 16;
|
|
27
|
+
return length.value * 16;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** The value the field shows for a stored variable value. */
|
|
31
|
+
export function valueText(value: unknown): string {
|
|
32
|
+
if (typeof value === "string") return value;
|
|
33
|
+
if (value && typeof value === "object" && "value" in value && "unit" in value) {
|
|
34
|
+
return formatLength(value as Length);
|
|
35
|
+
}
|
|
36
|
+
return "";
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const ERRORS: Record<VariableKind, string> = {
|
|
40
|
+
color: "Enter a hex color such as #1a2b3c.",
|
|
41
|
+
font: "Enter a font stack such as Inter, sans-serif.",
|
|
42
|
+
fontSize: "Enter a size such as 16, 16px or 1.5rem.",
|
|
43
|
+
spacing: "Enter a length such as 16, 16px or 1.5rem.",
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
/** The stored value for `text`, or the message that explains how to fix it. */
|
|
47
|
+
export function parseValue(
|
|
48
|
+
kind: VariableKind,
|
|
49
|
+
text: string,
|
|
50
|
+
): { ok: true; value: string | Length } | { ok: false; error: string } {
|
|
51
|
+
const trimmed = text.trim();
|
|
52
|
+
if (isLengthKind(kind)) {
|
|
53
|
+
const length = parseLength(trimmed);
|
|
54
|
+
return length ? { ok: true, value: length } : { ok: false, error: ERRORS[kind] };
|
|
55
|
+
}
|
|
56
|
+
if (kind === "color") {
|
|
57
|
+
return HEX.test(trimmed) ? { ok: true, value: trimmed } : { ok: false, error: ERRORS.color };
|
|
58
|
+
}
|
|
59
|
+
return trimmed && trimmed.length <= 200
|
|
60
|
+
? { ok: true, value: trimmed }
|
|
61
|
+
: { ok: false, error: ERRORS.font };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** A 6-digit hex for `<input type="color">`, which can't show 3, 4 or 8-digit forms. */
|
|
65
|
+
export function pickerHex(hex: string): string {
|
|
66
|
+
const h = hex.trim().toLowerCase();
|
|
67
|
+
if (/^#[0-9a-f]{6}$/.test(h)) return h;
|
|
68
|
+
if (/^#[0-9a-f]{8}$/.test(h)) return h.slice(0, 7);
|
|
69
|
+
if (/^#[0-9a-f]{3,4}$/.test(h)) {
|
|
70
|
+
return `#${Array.from(h.slice(1, 4), (c) => c + c).join("")}`;
|
|
71
|
+
}
|
|
72
|
+
return "#000000";
|
|
73
|
+
}
|