@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,629 @@
|
|
|
1
|
+
import { Button, Collapsible, Input, Tabs } from "@cloudflare/kumo";
|
|
2
|
+
import type { Fetcher } from "../../api.ts";
|
|
3
|
+
import {
|
|
4
|
+
CaretDownIcon,
|
|
5
|
+
CaretRightIcon,
|
|
6
|
+
ImageIcon,
|
|
7
|
+
PaintBrushIcon,
|
|
8
|
+
PencilSimpleIcon,
|
|
9
|
+
StarIcon,
|
|
10
|
+
YoutubeLogoIcon,
|
|
11
|
+
SquaresFourIcon,
|
|
12
|
+
TextHIcon,
|
|
13
|
+
WarningCircleIcon,
|
|
14
|
+
TextboxIcon,
|
|
15
|
+
CheckSquareIcon,
|
|
16
|
+
RadioButtonIcon,
|
|
17
|
+
PaperPlaneTiltIcon,
|
|
18
|
+
ClipboardTextIcon,
|
|
19
|
+
NotePencilIcon,
|
|
20
|
+
} from "@phosphor-icons/react";
|
|
21
|
+
import * as React from "react";
|
|
22
|
+
import {
|
|
23
|
+
ELEMENT_DESCRIPTORS,
|
|
24
|
+
findNode,
|
|
25
|
+
isFormNode,
|
|
26
|
+
parentOf,
|
|
27
|
+
type DesignSystem,
|
|
28
|
+
type ElementDescriptor,
|
|
29
|
+
type Layout,
|
|
30
|
+
type LayoutNode,
|
|
31
|
+
patchClassDevices,
|
|
32
|
+
patchClassState,
|
|
33
|
+
patchClassStyle,
|
|
34
|
+
patchDeviceStyle,
|
|
35
|
+
patchStates,
|
|
36
|
+
type DeviceStyles,
|
|
37
|
+
type PopupDevice,
|
|
38
|
+
type ResponsiveDevice,
|
|
39
|
+
classStylesInListOrder,
|
|
40
|
+
resolveCascade,
|
|
41
|
+
STYLE_STATES,
|
|
42
|
+
type StyleProps,
|
|
43
|
+
type StyleStates,
|
|
44
|
+
} from "../../../core/index.ts";
|
|
45
|
+
import { BUTTON, FIELD } from "../../ui.ts";
|
|
46
|
+
import { FieldControl } from "./settings/FieldControl.tsx";
|
|
47
|
+
import { StyleRow } from "./settings/StyleRow.tsx";
|
|
48
|
+
import { ClassChipInput } from "./settings/ClassChipInput.tsx";
|
|
49
|
+
import { StateDot, StateSwitcher, type StyleStateChoice } from "./settings/StateSwitcher.tsx";
|
|
50
|
+
import {
|
|
51
|
+
DEFAULT_UI,
|
|
52
|
+
keysFor,
|
|
53
|
+
offsetsApply,
|
|
54
|
+
SECTION_LABELS,
|
|
55
|
+
sectionsFor,
|
|
56
|
+
STYLE_UI,
|
|
57
|
+
type StyleSectionId,
|
|
58
|
+
} from "./settings/style-sections.ts";
|
|
59
|
+
|
|
60
|
+
export const ELEMENT_NAMES: Record<string, string> = Object.fromEntries(
|
|
61
|
+
ELEMENT_DESCRIPTORS.map((d) => [d.type, d.name]),
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
const enclosingFormId = (layout: Layout, nodeId: string): string | undefined => {
|
|
65
|
+
let current = parentOf(layout, nodeId);
|
|
66
|
+
while (current) {
|
|
67
|
+
const node = findNode(layout, current);
|
|
68
|
+
if (node && isFormNode(node)) return node.props.formId || undefined;
|
|
69
|
+
current = parentOf(layout, current);
|
|
70
|
+
}
|
|
71
|
+
return undefined;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const ICONS: Record<string, typeof TextHIcon> = {
|
|
75
|
+
heading: TextHIcon,
|
|
76
|
+
container: SquaresFourIcon,
|
|
77
|
+
"div-block": SquaresFourIcon,
|
|
78
|
+
flexbox: SquaresFourIcon,
|
|
79
|
+
image: ImageIcon,
|
|
80
|
+
icon: StarIcon,
|
|
81
|
+
svg: StarIcon,
|
|
82
|
+
tabs: SquaresFourIcon,
|
|
83
|
+
"tab-panel": SquaresFourIcon,
|
|
84
|
+
video: YoutubeLogoIcon,
|
|
85
|
+
form: ClipboardTextIcon,
|
|
86
|
+
"text-input": TextboxIcon,
|
|
87
|
+
textarea: NotePencilIcon,
|
|
88
|
+
select: TextboxIcon,
|
|
89
|
+
checkbox: CheckSquareIcon,
|
|
90
|
+
radio: RadioButtonIcon,
|
|
91
|
+
submit: PaperPlaneTiltIcon,
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const withStyle = (node: LayoutNode, patch: Partial<StyleProps>): LayoutNode => {
|
|
95
|
+
const style: Record<string, unknown> = { ...node.style, ...patch };
|
|
96
|
+
for (const key of Object.keys(style)) if (style[key] === undefined) delete style[key];
|
|
97
|
+
return {
|
|
98
|
+
...node,
|
|
99
|
+
style: Object.keys(style).length > 0 ? (style as StyleProps) : undefined,
|
|
100
|
+
};
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
const withDevices = (node: LayoutNode, devices: DeviceStyles | undefined): LayoutNode => {
|
|
104
|
+
const { devices: _old, ...rest } = node;
|
|
105
|
+
return (devices ? { ...rest, devices } : rest) as LayoutNode;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
const withStates = (node: LayoutNode, states: StyleStates | undefined): LayoutNode => {
|
|
109
|
+
const { states: _old, ...rest } = node;
|
|
110
|
+
return (states ? { ...rest, states } : rest) as LayoutNode;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
const sessionSectionKey = (type: string) => `emvb-style-sections:${type}`;
|
|
114
|
+
|
|
115
|
+
const readSections = (type: string, fallback: StyleSectionId[]): Set<StyleSectionId> => {
|
|
116
|
+
try {
|
|
117
|
+
const raw = sessionStorage.getItem(sessionSectionKey(type));
|
|
118
|
+
if (!raw) return new Set(fallback);
|
|
119
|
+
const parsed = JSON.parse(raw) as string[];
|
|
120
|
+
return new Set(parsed.filter((id): id is StyleSectionId => id in SECTION_LABELS));
|
|
121
|
+
} catch {
|
|
122
|
+
return new Set(fallback);
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
const writeSections = (type: string, open: Set<StyleSectionId>) => {
|
|
127
|
+
try {
|
|
128
|
+
sessionStorage.setItem(sessionSectionKey(type), JSON.stringify([...open]));
|
|
129
|
+
} catch {
|
|
130
|
+
/* private mode */
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
const countSet = (type: string, style: StyleProps | undefined, section: StyleSectionId) =>
|
|
135
|
+
keysFor(type, section, style).filter((key) => style?.[key] !== undefined).length;
|
|
136
|
+
|
|
137
|
+
/** Whether any state sets a key of this section (the section header's dot in Normal). */
|
|
138
|
+
const sectionHasStates = (type: string, states: StyleStates | undefined, section: StyleSectionId) =>
|
|
139
|
+
STYLE_STATES.some((state) => countSet(type, states?.[state], section) > 0);
|
|
140
|
+
|
|
141
|
+
/** Sections where a state change moves things around (DESIGN.md § State styles). */
|
|
142
|
+
const JUMPY = new Set<StyleSectionId>(["layout", "size", "position"]);
|
|
143
|
+
|
|
144
|
+
const JUMP_HELP: Record<Exclude<StyleStateChoice, "normal">, string> = {
|
|
145
|
+
hover: "Changing size or position on hover can make the page jump.",
|
|
146
|
+
focus: "Changing size or position on focus can make the page jump.",
|
|
147
|
+
active: "Changing size or position while active can make the page jump.",
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
/** The position in effect: the class's own when editing a class, else classes then local. */
|
|
151
|
+
const positionInEffect = (
|
|
152
|
+
node: LayoutNode,
|
|
153
|
+
design: DesignSystem,
|
|
154
|
+
cls: { style?: StyleProps } | undefined,
|
|
155
|
+
) =>
|
|
156
|
+
cls
|
|
157
|
+
? cls.style?.position
|
|
158
|
+
: resolveCascade(classStylesInListOrder(design.classes, node.classes ?? []), node.style)
|
|
159
|
+
.position;
|
|
160
|
+
|
|
161
|
+
/** Which styles the Style sections edit (W-087): a class applied to the node, or its own. */
|
|
162
|
+
function useStyleTarget(node: LayoutNode, design: DesignSystem) {
|
|
163
|
+
const [editing, setEditing] = React.useState<string | null>(null);
|
|
164
|
+
React.useEffect(() => setEditing(null), [node.id]);
|
|
165
|
+
const cls =
|
|
166
|
+
editing && node.classes?.includes(editing)
|
|
167
|
+
? design.classes?.find((c) => c.id === editing)
|
|
168
|
+
: undefined;
|
|
169
|
+
return { cls, editing: cls ? cls.id : null, setEditing };
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
type Props = {
|
|
173
|
+
node: LayoutNode;
|
|
174
|
+
layout: Layout | null;
|
|
175
|
+
design: DesignSystem;
|
|
176
|
+
rejection: string | null;
|
|
177
|
+
fetcher: Fetcher;
|
|
178
|
+
onChange: (node: LayoutNode) => void;
|
|
179
|
+
onDesignChange: (design: DesignSystem) => Promise<void>;
|
|
180
|
+
/** False when the forms plugin is not installed (W-036). */
|
|
181
|
+
formsAvailable?: boolean;
|
|
182
|
+
onSelect: (id: string | null) => void;
|
|
183
|
+
/** The chosen style state, for the canvas preview (W-089). */
|
|
184
|
+
onStyleState?: (nodeId: string, state: StyleStateChoice) => void;
|
|
185
|
+
/** Tablet and mobile edit overrides. Desktop edits `style` (W-096). */
|
|
186
|
+
device?: PopupDevice;
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
const FORM_TYPES = new Set([
|
|
190
|
+
"form",
|
|
191
|
+
"text-input",
|
|
192
|
+
"textarea",
|
|
193
|
+
"select",
|
|
194
|
+
"checkbox",
|
|
195
|
+
"radio",
|
|
196
|
+
"submit",
|
|
197
|
+
]);
|
|
198
|
+
|
|
199
|
+
const SPACER_HEIGHT = {
|
|
200
|
+
key: "height",
|
|
201
|
+
kind: "number",
|
|
202
|
+
label: "Height",
|
|
203
|
+
message: "Height can't be negative. Enter 0 or more.",
|
|
204
|
+
} as const;
|
|
205
|
+
|
|
206
|
+
const TABS = [
|
|
207
|
+
{
|
|
208
|
+
value: "content",
|
|
209
|
+
label: (
|
|
210
|
+
<>
|
|
211
|
+
<PencilSimpleIcon size={14} aria-hidden="true" />
|
|
212
|
+
Content
|
|
213
|
+
</>
|
|
214
|
+
),
|
|
215
|
+
},
|
|
216
|
+
{
|
|
217
|
+
value: "style",
|
|
218
|
+
label: (
|
|
219
|
+
<>
|
|
220
|
+
<PaintBrushIcon size={14} aria-hidden="true" />
|
|
221
|
+
Style
|
|
222
|
+
</>
|
|
223
|
+
),
|
|
224
|
+
},
|
|
225
|
+
];
|
|
226
|
+
|
|
227
|
+
function Alert({
|
|
228
|
+
children,
|
|
229
|
+
...data
|
|
230
|
+
}: {
|
|
231
|
+
children: React.ReactNode;
|
|
232
|
+
"data-emvb-forms-missing"?: "";
|
|
233
|
+
}) {
|
|
234
|
+
return (
|
|
235
|
+
<p className="emvb-inline-error" role="alert" {...data}>
|
|
236
|
+
<WarningCircleIcon size={16} aria-hidden="true" />
|
|
237
|
+
{children}
|
|
238
|
+
</p>
|
|
239
|
+
);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/** Right panel with an element selected (IA / W-021): descriptor Content + Style sections. */
|
|
243
|
+
export function ElementPanel(props: Props) {
|
|
244
|
+
const descriptor = ELEMENT_DESCRIPTORS.find((d) => d.type === props.node.type);
|
|
245
|
+
if (!descriptor) {
|
|
246
|
+
return (
|
|
247
|
+
<div
|
|
248
|
+
className="emvb-panel-body"
|
|
249
|
+
data-emvb-panel="element"
|
|
250
|
+
data-emvb-element={props.node.type}
|
|
251
|
+
>
|
|
252
|
+
<h2 className="emvb-panel-title">Unknown element</h2>
|
|
253
|
+
<p className="emvb-helper">
|
|
254
|
+
Unknown element "{props.node.type}". It can be moved or deleted, but not edited.
|
|
255
|
+
</p>
|
|
256
|
+
{props.rejection && <Alert>{props.rejection}</Alert>}
|
|
257
|
+
</div>
|
|
258
|
+
);
|
|
259
|
+
}
|
|
260
|
+
return <KnownElementPanel {...props} descriptor={descriptor} />;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/** The open Style sections for an element type, remembered for the session. */
|
|
264
|
+
function useOpenSections(type: string, defaultOpen: StyleSectionId, nodeId: string) {
|
|
265
|
+
const [open, setOpen] = React.useState(() => readSections(type, [defaultOpen]));
|
|
266
|
+
React.useEffect(() => {
|
|
267
|
+
setOpen(readSections(type, [defaultOpen]));
|
|
268
|
+
}, [nodeId, type, defaultOpen]);
|
|
269
|
+
const setSection = (id: StyleSectionId, isOpen: boolean) => {
|
|
270
|
+
setOpen((current) => {
|
|
271
|
+
const next = new Set(current);
|
|
272
|
+
if (isOpen) next.add(id);
|
|
273
|
+
else next.delete(id);
|
|
274
|
+
writeSections(type, next);
|
|
275
|
+
return next;
|
|
276
|
+
});
|
|
277
|
+
};
|
|
278
|
+
return [open, setSection] as const;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
function KnownElementPanel({
|
|
282
|
+
node,
|
|
283
|
+
layout,
|
|
284
|
+
design,
|
|
285
|
+
rejection,
|
|
286
|
+
fetcher,
|
|
287
|
+
formsAvailable = true,
|
|
288
|
+
onChange,
|
|
289
|
+
onDesignChange,
|
|
290
|
+
onSelect,
|
|
291
|
+
onStyleState,
|
|
292
|
+
device = "desktop",
|
|
293
|
+
descriptor,
|
|
294
|
+
}: Props & { descriptor: ElementDescriptor }) {
|
|
295
|
+
const ui = STYLE_UI[node.type] ?? DEFAULT_UI;
|
|
296
|
+
const [tab, setTab] = React.useState(descriptor.defaultTab);
|
|
297
|
+
const [openSections, setSection] = useOpenSections(node.type, ui.defaultOpen, node.id);
|
|
298
|
+
const { cls, editing, setEditing } = useStyleTarget(node, design);
|
|
299
|
+
const [designError, setDesignError] = React.useState<string | null>(null);
|
|
300
|
+
const [styleState, setStyleState] = React.useState<StyleStateChoice>("normal");
|
|
301
|
+
React.useEffect(() => setStyleState("normal"), [node.id]);
|
|
302
|
+
React.useEffect(() => {
|
|
303
|
+
onStyleState?.(node.id, tab === "style" ? styleState : "normal");
|
|
304
|
+
}, [node.id, styleState, tab, onStyleState]);
|
|
305
|
+
const normal = cls ? cls.style : node.style;
|
|
306
|
+
const states = cls ? cls.states : node.states;
|
|
307
|
+
const responsive: ResponsiveDevice | null = device === "desktop" ? null : device;
|
|
308
|
+
const ownerDevices = cls ? cls.devices : node.devices;
|
|
309
|
+
const style = responsive
|
|
310
|
+
? ownerDevices?.[responsive]
|
|
311
|
+
: styleState === "normal"
|
|
312
|
+
? normal
|
|
313
|
+
: states?.[styleState];
|
|
314
|
+
const inherited = responsive
|
|
315
|
+
? {
|
|
316
|
+
...normal,
|
|
317
|
+
...(responsive === "mobile" ? ownerDevices?.tablet : undefined),
|
|
318
|
+
}
|
|
319
|
+
: styleState === "normal"
|
|
320
|
+
? undefined
|
|
321
|
+
: normal;
|
|
322
|
+
const position = positionInEffect(node, design, cls);
|
|
323
|
+
const patchStyle = (patch: Partial<StyleProps>) => {
|
|
324
|
+
if (responsive) {
|
|
325
|
+
if (!cls) {
|
|
326
|
+
onChange(withDevices(node, patchDeviceStyle(node.devices, responsive, patch)));
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
329
|
+
setDesignError(null);
|
|
330
|
+
onDesignChange(patchClassDevices(design, cls.id, responsive, patch)).catch((error: unknown) =>
|
|
331
|
+
setDesignError(
|
|
332
|
+
error instanceof Error ? error.message : "Couldn't save the class. Try again.",
|
|
333
|
+
),
|
|
334
|
+
);
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
const state = styleState;
|
|
338
|
+
if (!cls) {
|
|
339
|
+
onChange(
|
|
340
|
+
state === "normal"
|
|
341
|
+
? withStyle(node, patch)
|
|
342
|
+
: withStates(node, patchStates(node.states, state, patch)),
|
|
343
|
+
);
|
|
344
|
+
return;
|
|
345
|
+
}
|
|
346
|
+
setDesignError(null);
|
|
347
|
+
const next =
|
|
348
|
+
state === "normal"
|
|
349
|
+
? patchClassStyle(design, cls.id, patch)
|
|
350
|
+
: patchClassState(design, cls.id, state, patch);
|
|
351
|
+
onDesignChange(next).catch((error: unknown) =>
|
|
352
|
+
setDesignError(
|
|
353
|
+
error instanceof Error ? error.message : "Couldn't save the class. Try again.",
|
|
354
|
+
),
|
|
355
|
+
);
|
|
356
|
+
};
|
|
357
|
+
React.useEffect(() => {
|
|
358
|
+
setTab(descriptor.defaultTab);
|
|
359
|
+
}, [node.id, node.type, descriptor.defaultTab]);
|
|
360
|
+
|
|
361
|
+
const Icon = ICONS[node.type] ?? SquaresFourIcon;
|
|
362
|
+
const crumbs = breadcrumb(layout, node.id);
|
|
363
|
+
const section = (
|
|
364
|
+
id: StyleSectionId,
|
|
365
|
+
count: number,
|
|
366
|
+
children: React.ReactNode,
|
|
367
|
+
stateMark = false,
|
|
368
|
+
) => (
|
|
369
|
+
<Section
|
|
370
|
+
key={id}
|
|
371
|
+
id={id}
|
|
372
|
+
open={openSections.has(id)}
|
|
373
|
+
count={count}
|
|
374
|
+
stateMark={stateMark}
|
|
375
|
+
onOpenChange={(open) => setSection(id, open)}
|
|
376
|
+
>
|
|
377
|
+
{children}
|
|
378
|
+
</Section>
|
|
379
|
+
);
|
|
380
|
+
|
|
381
|
+
return (
|
|
382
|
+
<div className="emvb-panel-body" data-emvb-panel="element" data-emvb-element={node.type}>
|
|
383
|
+
<div className="emvb-element-header">
|
|
384
|
+
<Icon size={16} aria-hidden="true" />
|
|
385
|
+
<h2 className="emvb-panel-title">{descriptor.name}</h2>
|
|
386
|
+
</div>
|
|
387
|
+
{crumbs.length > 0 && (
|
|
388
|
+
<nav className="emvb-breadcrumb" aria-label="Element path">
|
|
389
|
+
{crumbs.map((crumb, index) => (
|
|
390
|
+
<React.Fragment key={crumb.id ?? "page"}>
|
|
391
|
+
{index > 0 && <span aria-hidden="true"> › </span>}
|
|
392
|
+
<button
|
|
393
|
+
type="button"
|
|
394
|
+
className="emvb-breadcrumb-part"
|
|
395
|
+
onClick={() => onSelect(crumb.id)}
|
|
396
|
+
>
|
|
397
|
+
{crumb.label}
|
|
398
|
+
</button>
|
|
399
|
+
</React.Fragment>
|
|
400
|
+
))}
|
|
401
|
+
</nav>
|
|
402
|
+
)}
|
|
403
|
+
{rejection && <Alert>{rejection}</Alert>}
|
|
404
|
+
{!formsAvailable && FORM_TYPES.has(node.type) && (
|
|
405
|
+
<Alert data-emvb-forms-missing="">
|
|
406
|
+
The forms plugin is not installed. Form elements can't submit until it is added.
|
|
407
|
+
</Alert>
|
|
408
|
+
)}
|
|
409
|
+
<Tabs
|
|
410
|
+
variant="underline"
|
|
411
|
+
className="emvb-tabs"
|
|
412
|
+
tabs={TABS}
|
|
413
|
+
value={tab}
|
|
414
|
+
onValueChange={(value) => setTab(value === "style" ? "style" : "content")}
|
|
415
|
+
/>
|
|
416
|
+
{tab === "content" && (
|
|
417
|
+
<div className="emvb-panel-body" data-emvb-tab="content">
|
|
418
|
+
{descriptor.fields.length === 0 ? (
|
|
419
|
+
<p className="emvb-helper">
|
|
420
|
+
{node.type === "container"
|
|
421
|
+
? "A container holds other elements. Arrange them in Style."
|
|
422
|
+
: "This element has no content settings."}
|
|
423
|
+
</p>
|
|
424
|
+
) : (
|
|
425
|
+
descriptor.fields.map((field) => (
|
|
426
|
+
<FieldControl
|
|
427
|
+
key={field.key}
|
|
428
|
+
field={field}
|
|
429
|
+
node={node}
|
|
430
|
+
onChange={onChange}
|
|
431
|
+
fetcher={fetcher}
|
|
432
|
+
parentFormId={layout ? enclosingFormId(layout, node.id) : undefined}
|
|
433
|
+
/>
|
|
434
|
+
))
|
|
435
|
+
)}
|
|
436
|
+
</div>
|
|
437
|
+
)}
|
|
438
|
+
{tab === "style" && (
|
|
439
|
+
<div className="emvb-panel-body" data-emvb-tab="style">
|
|
440
|
+
<ClassChipInput
|
|
441
|
+
applied={node.classes}
|
|
442
|
+
design={design}
|
|
443
|
+
editing={editing}
|
|
444
|
+
onEdit={setEditing}
|
|
445
|
+
onChange={(classes) => onChange({ ...node, classes })}
|
|
446
|
+
onDesignChange={onDesignChange}
|
|
447
|
+
/>
|
|
448
|
+
{device === "desktop" ? (
|
|
449
|
+
<StateSwitcher
|
|
450
|
+
value={styleState}
|
|
451
|
+
states={states}
|
|
452
|
+
className={cls ? cls.name : null}
|
|
453
|
+
onChange={setStyleState}
|
|
454
|
+
/>
|
|
455
|
+
) : (
|
|
456
|
+
<p className="emvb-helper">
|
|
457
|
+
These override Desktop. State styles apply on every device.
|
|
458
|
+
</p>
|
|
459
|
+
)}
|
|
460
|
+
{designError && <Alert>{designError}</Alert>}
|
|
461
|
+
{!cls && styleState === "normal" && node.type === "spacer" && (
|
|
462
|
+
<FieldControl field={SPACER_HEIGHT} node={node} onChange={onChange} fetcher={fetcher} />
|
|
463
|
+
)}
|
|
464
|
+
{sectionsFor(ui.sections, style).map((id) => {
|
|
465
|
+
if (id === "advanced") {
|
|
466
|
+
if (cls || styleState !== "normal") return null;
|
|
467
|
+
return section(
|
|
468
|
+
id,
|
|
469
|
+
(node.htmlId ? 1 : 0) + (node.attributes?.length ?? 0),
|
|
470
|
+
<>
|
|
471
|
+
<Input
|
|
472
|
+
label="CSS id"
|
|
473
|
+
className={`${FIELD} emvb-mono`}
|
|
474
|
+
value={node.htmlId ?? ""}
|
|
475
|
+
onChange={(event) => {
|
|
476
|
+
const next = event.target.value.trim();
|
|
477
|
+
onChange({ ...node, htmlId: next === "" ? undefined : next });
|
|
478
|
+
}}
|
|
479
|
+
/>
|
|
480
|
+
<AttributesEditor
|
|
481
|
+
attributes={node.attributes}
|
|
482
|
+
onChange={(attributes) => onChange({ ...node, attributes })}
|
|
483
|
+
/>
|
|
484
|
+
</>,
|
|
485
|
+
);
|
|
486
|
+
}
|
|
487
|
+
const keys = keysFor(node.type, id, style, position).filter(
|
|
488
|
+
(key) => styleState === "normal" || (key !== "transition" && key !== "entrance"),
|
|
489
|
+
);
|
|
490
|
+
if (keys.length === 0) return null;
|
|
491
|
+
return section(
|
|
492
|
+
id,
|
|
493
|
+
countSet(node.type, style, id),
|
|
494
|
+
<>
|
|
495
|
+
{styleState !== "normal" && JUMPY.has(id) && (
|
|
496
|
+
<p className="emvb-helper" data-emvb-jump-help="">
|
|
497
|
+
{JUMP_HELP[styleState]}
|
|
498
|
+
</p>
|
|
499
|
+
)}
|
|
500
|
+
{keys.map((key) => (
|
|
501
|
+
<StyleRow
|
|
502
|
+
key={`${styleState}:${key}`}
|
|
503
|
+
styleKey={key}
|
|
504
|
+
style={style}
|
|
505
|
+
inherited={inherited}
|
|
506
|
+
design={design}
|
|
507
|
+
fetcher={fetcher}
|
|
508
|
+
onPatch={patchStyle}
|
|
509
|
+
onDesignChange={onDesignChange}
|
|
510
|
+
/>
|
|
511
|
+
))}
|
|
512
|
+
{id === "position" && !offsetsApply(position) && (
|
|
513
|
+
<p className="emvb-helper" data-emvb-offsets-help="">
|
|
514
|
+
Offsets apply once Position is Relative, Absolute, Fixed or Sticky.
|
|
515
|
+
</p>
|
|
516
|
+
)}
|
|
517
|
+
</>,
|
|
518
|
+
styleState === "normal" && sectionHasStates(node.type, states, id),
|
|
519
|
+
);
|
|
520
|
+
})}
|
|
521
|
+
</div>
|
|
522
|
+
)}
|
|
523
|
+
</div>
|
|
524
|
+
);
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
function Section({
|
|
528
|
+
id,
|
|
529
|
+
open,
|
|
530
|
+
count,
|
|
531
|
+
stateMark,
|
|
532
|
+
onOpenChange,
|
|
533
|
+
children,
|
|
534
|
+
}: {
|
|
535
|
+
id: StyleSectionId;
|
|
536
|
+
open: boolean;
|
|
537
|
+
count: number;
|
|
538
|
+
stateMark: boolean;
|
|
539
|
+
onOpenChange: (open: boolean) => void;
|
|
540
|
+
children: React.ReactNode;
|
|
541
|
+
}) {
|
|
542
|
+
return (
|
|
543
|
+
<Collapsible.Root open={open} onOpenChange={onOpenChange}>
|
|
544
|
+
<Collapsible.Trigger className="emvb-section-header" data-emvb-section={id}>
|
|
545
|
+
<span>
|
|
546
|
+
{SECTION_LABELS[id]}
|
|
547
|
+
{!open && count > 0 && <span className="emvb-count"> · {count}</span>}
|
|
548
|
+
{stateMark && <StateDot />}
|
|
549
|
+
</span>
|
|
550
|
+
{open ? (
|
|
551
|
+
<CaretDownIcon size={16} aria-hidden="true" />
|
|
552
|
+
) : (
|
|
553
|
+
<CaretRightIcon size={16} aria-hidden="true" />
|
|
554
|
+
)}
|
|
555
|
+
</Collapsible.Trigger>
|
|
556
|
+
<Collapsible.Panel className="emvb-section-body">{children}</Collapsible.Panel>
|
|
557
|
+
</Collapsible.Root>
|
|
558
|
+
);
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
function breadcrumb(
|
|
562
|
+
layout: Layout | null,
|
|
563
|
+
id: string,
|
|
564
|
+
): Array<{ id: string | null; label: string }> {
|
|
565
|
+
if (!layout) return [];
|
|
566
|
+
const chain: Array<{ id: string; label: string }> = [];
|
|
567
|
+
let current: string | undefined = id;
|
|
568
|
+
while (current) {
|
|
569
|
+
const node = findNode(layout, current);
|
|
570
|
+
if (!node) break;
|
|
571
|
+
chain.unshift({
|
|
572
|
+
id: node.id,
|
|
573
|
+
label: ELEMENT_NAMES[node.type] ?? node.type,
|
|
574
|
+
});
|
|
575
|
+
current = parentOf(layout, current);
|
|
576
|
+
}
|
|
577
|
+
return [{ id: null, label: "Page" }, ...chain];
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
function AttributesEditor({
|
|
581
|
+
attributes,
|
|
582
|
+
onChange,
|
|
583
|
+
}: {
|
|
584
|
+
attributes: LayoutNode["attributes"];
|
|
585
|
+
onChange: (next: LayoutNode["attributes"]) => void;
|
|
586
|
+
}) {
|
|
587
|
+
const list = attributes ?? [];
|
|
588
|
+
const update = (index: number, patch: { name?: string; value?: string }) => {
|
|
589
|
+
const next = list.map((item, i) => (i === index ? { ...item, ...patch } : item));
|
|
590
|
+
onChange(next);
|
|
591
|
+
};
|
|
592
|
+
return (
|
|
593
|
+
<div className="emvb-field-group" data-emvb-attributes="">
|
|
594
|
+
<span className="emvb-var-field-label">Attributes</span>
|
|
595
|
+
{list.map((item, index) => (
|
|
596
|
+
<div key={index} className="emvb-style-row">
|
|
597
|
+
<Input
|
|
598
|
+
label="Name"
|
|
599
|
+
className={`${FIELD} emvb-mono`}
|
|
600
|
+
value={item.name}
|
|
601
|
+
onChange={(event) => update(index, { name: event.target.value.trim() })}
|
|
602
|
+
/>
|
|
603
|
+
<Input
|
|
604
|
+
label="Value"
|
|
605
|
+
className={FIELD}
|
|
606
|
+
value={item.value}
|
|
607
|
+
onChange={(event) => update(index, { value: event.target.value })}
|
|
608
|
+
/>
|
|
609
|
+
<Button
|
|
610
|
+
type="button"
|
|
611
|
+
variant="ghost"
|
|
612
|
+
onClick={() => onChange(list.filter((_, i) => i !== index))}
|
|
613
|
+
>
|
|
614
|
+
Remove
|
|
615
|
+
</Button>
|
|
616
|
+
</div>
|
|
617
|
+
))}
|
|
618
|
+
<Button
|
|
619
|
+
type="button"
|
|
620
|
+
variant="secondary"
|
|
621
|
+
className={BUTTON}
|
|
622
|
+
onClick={() => onChange([...list, { name: "data-", value: "" }])}
|
|
623
|
+
>
|
|
624
|
+
Add attribute
|
|
625
|
+
</Button>
|
|
626
|
+
<p className="emvb-helper">data-* and aria-* names only. Event handlers are refused.</p>
|
|
627
|
+
</div>
|
|
628
|
+
);
|
|
629
|
+
}
|