@perkyzz/emvb 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +59 -2
- package/THIRD_PARTY_NOTICES.md +32 -0
- package/licenses/fontawesome-free.LICENSE +165 -0
- package/licenses/lucide-static.LICENSE +43 -0
- package/licenses/remixicon.LICENSE +201 -0
- package/licenses/tabler-icons.LICENSE +21 -0
- package/package.json +76 -4
- package/src/admin/access/RequireEditor.tsx +39 -0
- package/src/admin/access/role.ts +36 -0
- package/src/admin/access/sidebar-shim.ts +108 -0
- package/src/admin/api.ts +75 -0
- package/src/admin/content-api.ts +210 -0
- package/src/admin/editor/Editor.tsx +532 -0
- package/src/admin/editor/EditorOverlay.tsx +66 -0
- package/src/admin/editor/ShortcutsDialog.tsx +30 -0
- package/src/admin/editor/SmallScreenNotice.tsx +21 -0
- package/src/admin/editor/TopBar.tsx +243 -0
- package/src/admin/editor/canvas/CanvasFrame.tsx +536 -0
- package/src/admin/editor/canvas/CanvasTextEdit.tsx +87 -0
- package/src/admin/editor/canvas/DeviceBar.tsx +91 -0
- package/src/admin/editor/canvas/EmptyCanvas.tsx +49 -0
- package/src/admin/editor/canvas/SelectionOverlay.tsx +239 -0
- package/src/admin/editor/canvas/canvas-events.ts +245 -0
- package/src/admin/editor/canvas/state-preview.ts +19 -0
- package/src/admin/editor/canvas/tab-reveal.ts +101 -0
- package/src/admin/editor/canvas/vnode-react.tsx +69 -0
- package/src/admin/editor/clipboard-store.ts +44 -0
- package/src/admin/editor/dialogs.tsx +164 -0
- package/src/admin/editor/dnd/drag-stash.ts +27 -0
- package/src/admin/editor/dnd/drop-target.ts +148 -0
- package/src/admin/editor/dnd/new-element.ts +107 -0
- package/src/admin/editor/editor-css.ts +625 -0
- package/src/admin/editor/exit.ts +27 -0
- package/src/admin/editor/host.ts +30 -0
- package/src/admin/editor/icons/IconLibraryDialog.tsx +850 -0
- package/src/admin/editor/icons/library.ts +243 -0
- package/src/admin/editor/icons/set-format.ts +29 -0
- package/src/admin/editor/icons/sets/fontawesome.json +1 -0
- package/src/admin/editor/icons/sets/lucide.json +1 -0
- package/src/admin/editor/icons/sets/remix.json +1 -0
- package/src/admin/editor/icons/sets/tabler.json +1 -0
- package/src/admin/editor/panels/AddPanel.tsx +146 -0
- package/src/admin/editor/panels/ClassesSection.tsx +372 -0
- package/src/admin/editor/panels/ColorControl.tsx +477 -0
- package/src/admin/editor/panels/ConditionsEditor.tsx +201 -0
- package/src/admin/editor/panels/ElementPanel.tsx +773 -0
- package/src/admin/editor/panels/LayersPanel.tsx +573 -0
- package/src/admin/editor/panels/LeftPanel.tsx +81 -0
- package/src/admin/editor/panels/PageSettings.tsx +255 -0
- package/src/admin/editor/panels/SettingsPanel.tsx +113 -0
- package/src/admin/editor/panels/SiteStylesDrawer.tsx +548 -0
- package/src/admin/editor/panels/TriggerSettings.tsx +132 -0
- package/src/admin/editor/panels/TriggersEditor.tsx +214 -0
- package/src/admin/editor/panels/VariableSection.tsx +530 -0
- package/src/admin/editor/panels/color-space.ts +195 -0
- package/src/admin/editor/panels/settings/AdvancedFields.tsx +119 -0
- package/src/admin/editor/panels/settings/BackgroundControls.tsx +418 -0
- package/src/admin/editor/panels/settings/BackgroundFill.tsx +221 -0
- package/src/admin/editor/panels/settings/BoxControl.tsx +271 -0
- package/src/admin/editor/panels/settings/ChoiceGroup.tsx +138 -0
- package/src/admin/editor/panels/settings/ClassChip.tsx +167 -0
- package/src/admin/editor/panels/settings/ClassChipInput.tsx +451 -0
- package/src/admin/editor/panels/settings/DraftTextField.tsx +242 -0
- package/src/admin/editor/panels/settings/EffectsControls.tsx +354 -0
- package/src/admin/editor/panels/settings/FieldBindControl.tsx +119 -0
- package/src/admin/editor/panels/settings/FieldControl.tsx +270 -0
- package/src/admin/editor/panels/settings/FormBindControl.tsx +106 -0
- package/src/admin/editor/panels/settings/IconControls.tsx +438 -0
- package/src/admin/editor/panels/settings/IconPicker.tsx +170 -0
- package/src/admin/editor/panels/settings/ItemList.tsx +199 -0
- package/src/admin/editor/panels/settings/LengthRow.tsx +217 -0
- package/src/admin/editor/panels/settings/LoopItemBindControl.tsx +130 -0
- package/src/admin/editor/panels/settings/MediaPicker.tsx +220 -0
- package/src/admin/editor/panels/settings/NumberRow.tsx +154 -0
- package/src/admin/editor/panels/settings/StateSwitcher.tsx +87 -0
- package/src/admin/editor/panels/settings/StyleRow.tsx +563 -0
- package/src/admin/editor/panels/settings/VariableBinding.tsx +171 -0
- package/src/admin/editor/panels/settings/advanced-rules.ts +63 -0
- package/src/admin/editor/panels/settings/background-mode.ts +112 -0
- package/src/admin/editor/panels/settings/box-link-name.ts +38 -0
- package/src/admin/editor/panels/settings/box-sides.ts +153 -0
- package/src/admin/editor/panels/settings/button-url.ts +27 -0
- package/src/admin/editor/panels/settings/class-suggest.ts +53 -0
- package/src/admin/editor/panels/settings/form-names.ts +38 -0
- package/src/admin/editor/panels/settings/heading-warning.ts +25 -0
- package/src/admin/editor/panels/settings/image-alt.ts +25 -0
- package/src/admin/editor/panels/settings/length-units.ts +116 -0
- package/src/admin/editor/panels/settings/loop-context.ts +26 -0
- package/src/admin/editor/panels/settings/node-props.ts +11 -0
- package/src/admin/editor/panels/settings/style-sections.ts +394 -0
- package/src/admin/editor/panels/settings/svg-images.ts +14 -0
- package/src/admin/editor/panels/site-list.tsx +209 -0
- package/src/admin/editor/panels/variable-values.ts +73 -0
- package/src/admin/editor/restore-deleted.ts +80 -0
- package/src/admin/editor/section-templates.ts +50 -0
- package/src/admin/editor/shortcuts.ts +20 -0
- package/src/admin/editor/store.ts +240 -0
- package/src/admin/editor/useClipboardActions.ts +136 -0
- package/src/admin/editor/useEditorCommands.ts +203 -0
- package/src/admin/editor/useEditorData.ts +193 -0
- package/src/admin/editor/useEditorShortcuts.ts +180 -0
- package/src/admin/editor/useMediaQuery.ts +20 -0
- package/src/admin/editor/useNodeActions.ts +184 -0
- package/src/admin/editor/useSave.ts +242 -0
- package/src/admin/entry-status.ts +19 -0
- package/src/admin/forms-api.ts +73 -0
- package/src/admin/icon-uploads-api.ts +44 -0
- package/src/admin/index.tsx +20 -0
- package/src/admin/media-api.ts +68 -0
- package/src/admin/pages/CreateDialog.tsx +150 -0
- package/src/admin/pages/EditorPage.tsx +57 -0
- package/src/admin/pages/NewPageDialog.tsx +83 -0
- package/src/admin/pages/NewThemePartDialog.tsx +61 -0
- package/src/admin/pages/PageList.tsx +91 -0
- package/src/admin/pages/PagesPage.tsx +25 -0
- package/src/admin/pages/SetupShell.tsx +90 -0
- package/src/admin/pages/ThemeBuilderPage.tsx +25 -0
- package/src/admin/pages/ThemePartList.tsx +221 -0
- package/src/admin/pages/list-kit.tsx +125 -0
- package/src/admin/setup/plan.ts +150 -0
- package/src/admin/setup/run.ts +61 -0
- package/src/admin/setup/spec.ts +107 -0
- package/src/admin/setup/useSetupStatus.ts +62 -0
- package/src/admin/theme-api.ts +233 -0
- package/src/admin/ui.ts +244 -0
- package/src/admin/widgets/LayoutField.tsx +67 -0
- package/src/astro/EmVBPage.astro +63 -0
- package/src/astro/env.d.ts +5 -0
- package/src/astro/floats/EmVBFloatsRuntime.astro +9 -0
- package/src/astro/floats/index.ts +1 -0
- package/src/astro/floats/runtime.ts +78 -0
- package/src/astro/forms/EmVBFormsRuntime.astro +9 -0
- package/src/astro/forms/index.ts +1 -0
- package/src/astro/forms-definitions.ts +126 -0
- package/src/astro/index.ts +16 -0
- package/src/astro/menu/EmVBMenuRuntime.astro +9 -0
- package/src/astro/menu/index.ts +1 -0
- package/src/astro/menu/runtime.ts +37 -0
- package/src/astro/popups/EmVBPopupsRuntime.astro +9 -0
- package/src/astro/popups/index.ts +1 -0
- package/src/astro/popups/runtime.ts +296 -0
- package/src/astro/render.ts +108 -0
- package/src/astro/resolve-theme.ts +515 -0
- package/src/astro/resolve.ts +65 -0
- package/src/astro/tabs/EmVBTabsRuntime.astro +10 -0
- package/src/astro/tabs/index.ts +1 -0
- package/src/astro/tabs/runtime.ts +116 -0
- package/src/astro/theme-context.ts +89 -0
- package/src/astro/theme-posts.ts +84 -0
- package/src/constants.ts +12 -0
- package/src/core/arrange.ts +448 -0
- package/src/core/clipboard.ts +504 -0
- package/src/core/css/generate.ts +236 -0
- package/src/core/css/scope.ts +88 -0
- package/src/core/design/cascade.ts +28 -0
- package/src/core/design/classes.ts +224 -0
- package/src/core/design/devices.ts +56 -0
- package/src/core/design/states.ts +49 -0
- package/src/core/design/transfer.ts +132 -0
- package/src/core/design/variables.ts +359 -0
- package/src/core/elements/definition.ts +12 -0
- package/src/core/elements/dynamic-elements.ts +225 -0
- package/src/core/elements/field-id.ts +6 -0
- package/src/core/elements/form-elements.ts +219 -0
- package/src/core/elements/index.ts +960 -0
- package/src/core/elements/menu.ts +190 -0
- package/src/core/elements/plain-text.ts +32 -0
- package/src/core/forms/binding.ts +61 -0
- package/src/core/forms/definition.ts +45 -0
- package/src/core/forms/success-layout.ts +63 -0
- package/src/core/icons/catalog.ts +273 -0
- package/src/core/index.ts +380 -0
- package/src/core/limits.ts +9 -0
- package/src/core/migrate/index.ts +126 -0
- package/src/core/nesting.ts +51 -0
- package/src/core/render/context.ts +21 -0
- package/src/core/render/dynamic-post.ts +175 -0
- package/src/core/render/extras.ts +98 -0
- package/src/core/render/form.ts +235 -0
- package/src/core/render/index.ts +372 -0
- package/src/core/render/loop.ts +43 -0
- package/src/core/render/pagination.ts +76 -0
- package/src/core/render/section.ts +37 -0
- package/src/core/render/tabs.ts +76 -0
- package/src/core/render/vnode.ts +87 -0
- package/src/core/sanitize/css.ts +771 -0
- package/src/core/sanitize/embed-url.ts +160 -0
- package/src/core/sanitize/escape.ts +10 -0
- package/src/core/sanitize/href.ts +6 -0
- package/src/core/sanitize/media-url.ts +7 -0
- package/src/core/sanitize/svg-upload.ts +203 -0
- package/src/core/sanitize/svg.ts +374 -0
- package/src/core/sanitize/url.ts +31 -0
- package/src/core/schema/descriptors.ts +37 -0
- package/src/core/schema/design.ts +93 -0
- package/src/core/schema/layout.ts +1008 -0
- package/src/core/schema/state-names.ts +4 -0
- package/src/core/schema/style.ts +336 -0
- package/src/core/stats.ts +18 -0
- package/src/core/tabs/presence.ts +25 -0
- package/src/core/theme/conditions.ts +324 -0
- package/src/core/theme/dynamic.ts +143 -0
- package/src/core/theme/float.ts +113 -0
- package/src/core/theme/pagination.ts +97 -0
- package/src/core/theme/parse-doc.ts +36 -0
- package/src/core/theme/part-types.ts +81 -0
- package/src/core/theme/popup-markup.ts +41 -0
- package/src/core/theme/popup-rules.ts +62 -0
- package/src/core/theme/triggers.ts +104 -0
- package/src/core/tree-ops.ts +139 -0
- package/src/core/validate.ts +185 -0
- package/src/index.ts +18 -0
- package/src/server/design-routes.ts +125 -0
- package/src/server/hooks.ts +118 -0
- package/src/server/icon-routes.ts +79 -0
- package/src/server/plugin.ts +43 -0
|
@@ -0,0 +1,773 @@
|
|
|
1
|
+
import { Collapsible, Tabs } from "@cloudflare/kumo";
|
|
2
|
+
import type { Fetcher } from "../../api.ts";
|
|
3
|
+
import {
|
|
4
|
+
CaretDownIcon,
|
|
5
|
+
CaretRightIcon,
|
|
6
|
+
CheckSquareIcon,
|
|
7
|
+
ClipboardTextIcon,
|
|
8
|
+
ImageIcon,
|
|
9
|
+
NotePencilIcon,
|
|
10
|
+
PaintBrushIcon,
|
|
11
|
+
PaperPlaneTiltIcon,
|
|
12
|
+
PencilSimpleIcon,
|
|
13
|
+
RadioButtonIcon,
|
|
14
|
+
RowsIcon,
|
|
15
|
+
SquaresFourIcon,
|
|
16
|
+
StarIcon,
|
|
17
|
+
TextHIcon,
|
|
18
|
+
TextboxIcon,
|
|
19
|
+
WarningCircleIcon,
|
|
20
|
+
YoutubeLogoIcon,
|
|
21
|
+
} from "@phosphor-icons/react";
|
|
22
|
+
import * as React from "react";
|
|
23
|
+
import type { ThemePartType } from "../../../core/theme/part-types.ts";
|
|
24
|
+
import { sharedPartH1 } from "./settings/heading-warning.ts";
|
|
25
|
+
import { UNNAMED_BOX_LINK_NOTE, unnamedBoxLink } from "./settings/box-link-name.ts";
|
|
26
|
+
import { imageAltNote } from "./settings/image-alt.ts";
|
|
27
|
+
import { loopContextNote } from "./settings/loop-context.ts";
|
|
28
|
+
import { buttonUrlNote } from "./settings/button-url.ts";
|
|
29
|
+
import { svgImagesLeftOut, svgImagesNotice } from "./settings/svg-images.ts";
|
|
30
|
+
import { duplicateFieldName } from "./settings/form-names.ts";
|
|
31
|
+
import { hasItemList, ItemList, type ItemActions } from "./settings/ItemList.tsx";
|
|
32
|
+
import {
|
|
33
|
+
ELEMENT_DESCRIPTORS,
|
|
34
|
+
findNode,
|
|
35
|
+
hasLocalStyles,
|
|
36
|
+
localStylesToClass,
|
|
37
|
+
localToClassRefusal,
|
|
38
|
+
isFormNode,
|
|
39
|
+
parentOf,
|
|
40
|
+
type DesignSystem,
|
|
41
|
+
type ElementDescriptor,
|
|
42
|
+
type Layout,
|
|
43
|
+
type LayoutNode,
|
|
44
|
+
patchClassDevices,
|
|
45
|
+
patchClassState,
|
|
46
|
+
patchClassStyle,
|
|
47
|
+
patchDeviceStyle,
|
|
48
|
+
patchStates,
|
|
49
|
+
type DeviceStyles,
|
|
50
|
+
type PopupDevice,
|
|
51
|
+
type ResponsiveDevice,
|
|
52
|
+
classStylesInListOrder,
|
|
53
|
+
iconHasAdjustableStroke,
|
|
54
|
+
iconHasOwnColors,
|
|
55
|
+
resolveCascade,
|
|
56
|
+
STYLE_STATES,
|
|
57
|
+
type StyleProps,
|
|
58
|
+
type StyleStates,
|
|
59
|
+
} from "../../../core/index.ts";
|
|
60
|
+
import { FieldControl } from "./settings/FieldControl.tsx";
|
|
61
|
+
import { BoxControl } from "./settings/BoxControl.tsx";
|
|
62
|
+
import { boxGroupOf } from "./settings/box-sides.ts";
|
|
63
|
+
import { IconShapeRow, IconSingleColorRow } from "./settings/IconControls.tsx";
|
|
64
|
+
import { StyleRow } from "./settings/StyleRow.tsx";
|
|
65
|
+
import { AttributesEditor, HtmlIdField } from "./settings/AdvancedFields.tsx";
|
|
66
|
+
import { ClassChipInput } from "./settings/ClassChipInput.tsx";
|
|
67
|
+
import { StateDot, StateSwitcher, type StyleStateChoice } from "./settings/StateSwitcher.tsx";
|
|
68
|
+
import {
|
|
69
|
+
DEFAULT_UI,
|
|
70
|
+
keysFor,
|
|
71
|
+
offsetsApply,
|
|
72
|
+
SECTION_LABELS,
|
|
73
|
+
sectionsFor,
|
|
74
|
+
type StyleKey,
|
|
75
|
+
STYLE_UI,
|
|
76
|
+
type StyleSectionId,
|
|
77
|
+
} from "./settings/style-sections.ts";
|
|
78
|
+
|
|
79
|
+
export const ELEMENT_NAMES: Record<string, string> = Object.fromEntries(
|
|
80
|
+
ELEMENT_DESCRIPTORS.map((d) => [d.type, d.name]),
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
const enclosingFormId = (layout: Layout, nodeId: string): string | undefined => {
|
|
84
|
+
let current = parentOf(layout, nodeId);
|
|
85
|
+
while (current) {
|
|
86
|
+
const node = findNode(layout, current);
|
|
87
|
+
if (node && isFormNode(node)) return node.props.formId || undefined;
|
|
88
|
+
current = parentOf(layout, current);
|
|
89
|
+
}
|
|
90
|
+
return undefined;
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const ICONS: Record<string, typeof TextHIcon> = {
|
|
94
|
+
heading: TextHIcon,
|
|
95
|
+
container: SquaresFourIcon,
|
|
96
|
+
"div-block": SquaresFourIcon,
|
|
97
|
+
"layout-section": RowsIcon,
|
|
98
|
+
flexbox: SquaresFourIcon,
|
|
99
|
+
image: ImageIcon,
|
|
100
|
+
icon: StarIcon,
|
|
101
|
+
svg: StarIcon,
|
|
102
|
+
tabs: SquaresFourIcon,
|
|
103
|
+
"tab-panel": SquaresFourIcon,
|
|
104
|
+
video: YoutubeLogoIcon,
|
|
105
|
+
form: ClipboardTextIcon,
|
|
106
|
+
"text-input": TextboxIcon,
|
|
107
|
+
textarea: NotePencilIcon,
|
|
108
|
+
select: TextboxIcon,
|
|
109
|
+
checkbox: CheckSquareIcon,
|
|
110
|
+
radio: RadioButtonIcon,
|
|
111
|
+
submit: PaperPlaneTiltIcon,
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
const withStyle = (node: LayoutNode, patch: Partial<StyleProps>): LayoutNode => {
|
|
115
|
+
const style: Record<string, unknown> = { ...node.style, ...patch };
|
|
116
|
+
for (const key of Object.keys(style)) if (style[key] === undefined) delete style[key];
|
|
117
|
+
return {
|
|
118
|
+
...node,
|
|
119
|
+
style: Object.keys(style).length > 0 ? (style as StyleProps) : undefined,
|
|
120
|
+
};
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
const withDevices = (node: LayoutNode, devices: DeviceStyles | undefined): LayoutNode => {
|
|
124
|
+
const { devices: _old, ...rest } = node;
|
|
125
|
+
return (devices ? { ...rest, devices } : rest) as LayoutNode;
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
const withStates = (node: LayoutNode, states: StyleStates | undefined): LayoutNode => {
|
|
129
|
+
const { states: _old, ...rest } = node;
|
|
130
|
+
return (states ? { ...rest, states } : rest) as LayoutNode;
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
const sectionKey = (type: string) => `emvb-style-sections:${type}`;
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Open the first time an element type is selected, where it has them (W-137): the sections most
|
|
137
|
+
* edits need. After that the open and closed sections are remembered per type, across visits.
|
|
138
|
+
*/
|
|
139
|
+
const OPEN_FIRST: StyleSectionId[] = ["typography", "spacing", "background", "border"];
|
|
140
|
+
|
|
141
|
+
const readSections = (type: string, fallback: StyleSectionId[]): Set<StyleSectionId> => {
|
|
142
|
+
try {
|
|
143
|
+
const raw = localStorage.getItem(sectionKey(type));
|
|
144
|
+
if (!raw) return new Set(fallback);
|
|
145
|
+
const parsed = JSON.parse(raw) as string[];
|
|
146
|
+
return new Set(parsed.filter((id): id is StyleSectionId => id in SECTION_LABELS));
|
|
147
|
+
} catch {
|
|
148
|
+
return new Set(fallback);
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
const writeSections = (type: string, open: Set<StyleSectionId>) => {
|
|
153
|
+
try {
|
|
154
|
+
localStorage.setItem(sectionKey(type), JSON.stringify([...open]));
|
|
155
|
+
} catch {
|
|
156
|
+
/* private mode */
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
const countSet = (type: string, style: StyleProps | undefined, section: StyleSectionId) =>
|
|
161
|
+
keysFor(type, section, style).filter((key) => style?.[key] !== undefined).length;
|
|
162
|
+
|
|
163
|
+
/** Whether any state sets a key of this section (the section header's dot in Normal). */
|
|
164
|
+
const sectionHasStates = (type: string, states: StyleStates | undefined, section: StyleSectionId) =>
|
|
165
|
+
STYLE_STATES.some((state) => countSet(type, states?.[state], section) > 0);
|
|
166
|
+
|
|
167
|
+
/** Sections where a state change moves things around. */
|
|
168
|
+
const JUMPY = new Set<StyleSectionId>(["layout", "size", "position"]);
|
|
169
|
+
|
|
170
|
+
/** Set on Normal only (W-089, W-101, W-237); a state's Style tab leaves them out. */
|
|
171
|
+
const NORMAL_ONLY_KEYS = new Set<StyleKey>(["transition", "entrance", "iconAnimation"]);
|
|
172
|
+
|
|
173
|
+
const JUMP_HELP: Record<Exclude<StyleStateChoice, "normal">, string> = {
|
|
174
|
+
hover: "Changing size or position on hover can make the page jump.",
|
|
175
|
+
focus: "Changing size or position on focus can make the page jump.",
|
|
176
|
+
active: "Changing size or position while active can make the page jump.",
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
/** The position in effect: the class's own when editing a class, else classes then local. */
|
|
180
|
+
const positionInEffect = (
|
|
181
|
+
node: LayoutNode,
|
|
182
|
+
design: DesignSystem,
|
|
183
|
+
cls: { style?: StyleProps } | undefined,
|
|
184
|
+
) =>
|
|
185
|
+
cls
|
|
186
|
+
? cls.style?.position
|
|
187
|
+
: resolveCascade(classStylesInListOrder(design.classes, node.classes ?? []), node.style)
|
|
188
|
+
.position;
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Where the panel was scrolled, per tab, for the session (W-152). A new selection or a tab switch
|
|
192
|
+
* shows the tab where it was left, rather than wherever the shorter or longer content clamps it.
|
|
193
|
+
*/
|
|
194
|
+
const tabScroll: Record<string, number> = {};
|
|
195
|
+
|
|
196
|
+
function useTabScroll(ref: React.RefObject<HTMLElement | null>, tab: string, nodeId: string) {
|
|
197
|
+
React.useLayoutEffect(() => {
|
|
198
|
+
const scroller = ref.current?.closest<HTMLElement>(".emvb-panel");
|
|
199
|
+
if (!scroller) return;
|
|
200
|
+
const restore = () => {
|
|
201
|
+
scroller.scrollTop = tabScroll[tab] ?? 0;
|
|
202
|
+
};
|
|
203
|
+
restore();
|
|
204
|
+
// Sections may grow a frame later; put the position back once they have.
|
|
205
|
+
const frame = requestAnimationFrame(restore);
|
|
206
|
+
const save = () => {
|
|
207
|
+
tabScroll[tab] = scroller.scrollTop;
|
|
208
|
+
};
|
|
209
|
+
scroller.addEventListener("scroll", save, { passive: true });
|
|
210
|
+
return () => {
|
|
211
|
+
cancelAnimationFrame(frame);
|
|
212
|
+
scroller.removeEventListener("scroll", save);
|
|
213
|
+
};
|
|
214
|
+
}, [ref, tab, nodeId]);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/** Which styles the Style sections edit (W-087): a class applied to the node, or its own. */
|
|
218
|
+
function useStyleTarget(node: LayoutNode, design: DesignSystem) {
|
|
219
|
+
const [editing, setEditing] = React.useState<string | null>(null);
|
|
220
|
+
React.useEffect(() => setEditing(null), [node.id]);
|
|
221
|
+
const cls =
|
|
222
|
+
editing && node.classes?.includes(editing)
|
|
223
|
+
? design.classes?.find((c) => c.id === editing)
|
|
224
|
+
: undefined;
|
|
225
|
+
return { cls, editing: cls ? cls.id : null, setEditing };
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
type Props = {
|
|
229
|
+
node: LayoutNode;
|
|
230
|
+
layout: Layout | null;
|
|
231
|
+
design: DesignSystem;
|
|
232
|
+
rejection: string | null;
|
|
233
|
+
fetcher: Fetcher;
|
|
234
|
+
onChange: (node: LayoutNode) => void;
|
|
235
|
+
onDesignChange: (design: DesignSystem) => Promise<void>;
|
|
236
|
+
/** False when the forms plugin is not installed (W-036). */
|
|
237
|
+
formsAvailable?: boolean;
|
|
238
|
+
onSelect: (id: string | null) => void;
|
|
239
|
+
/** The chosen style state, for the canvas preview (W-089). */
|
|
240
|
+
onStyleState?: (nodeId: string, state: StyleStateChoice) => void;
|
|
241
|
+
/** Tablet and mobile edit overrides. Desktop edits `style` (W-096). */
|
|
242
|
+
device?: PopupDevice;
|
|
243
|
+
/** Add, move and delete for Accordion items and Tabs panels (W-130). */
|
|
244
|
+
items?: ItemActions;
|
|
245
|
+
/** The theme part being edited, if any, for the H1 warning (W-208). */
|
|
246
|
+
partType?: ThemePartType;
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
/** What an item's content is, since it has no content field of its own (W-130). */
|
|
250
|
+
const ITEM_NOTES: Record<string, string> = {
|
|
251
|
+
"accordion-item":
|
|
252
|
+
"The item's content is the elements in its body. Select this item, then add elements, or drag them into its body on the canvas.",
|
|
253
|
+
"tab-panel":
|
|
254
|
+
"The tab's content is the elements in its panel. Select this tab, then add elements, or drag them into its panel on the canvas.",
|
|
255
|
+
menu: "Add Menu items. An item that holds other elements opens a dropdown. Wide panel stretches that dropdown across the menu.",
|
|
256
|
+
"menu-item":
|
|
257
|
+
"The label is the link. Elements inside this item are its dropdown. Wide panel stretches the dropdown across the menu.",
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
const FORM_TYPES = new Set([
|
|
261
|
+
"form",
|
|
262
|
+
"text-input",
|
|
263
|
+
"textarea",
|
|
264
|
+
"select",
|
|
265
|
+
"checkbox",
|
|
266
|
+
"radio",
|
|
267
|
+
"submit",
|
|
268
|
+
]);
|
|
269
|
+
|
|
270
|
+
const SPACER_HEIGHT = {
|
|
271
|
+
key: "height",
|
|
272
|
+
kind: "number",
|
|
273
|
+
label: "Height",
|
|
274
|
+
message: "Height can't be negative. Enter 0 or more.",
|
|
275
|
+
} as const;
|
|
276
|
+
|
|
277
|
+
const TABS = [
|
|
278
|
+
{
|
|
279
|
+
value: "content",
|
|
280
|
+
label: (
|
|
281
|
+
<>
|
|
282
|
+
<PencilSimpleIcon size={14} aria-hidden="true" />
|
|
283
|
+
Content
|
|
284
|
+
</>
|
|
285
|
+
),
|
|
286
|
+
},
|
|
287
|
+
{
|
|
288
|
+
value: "style",
|
|
289
|
+
label: (
|
|
290
|
+
<>
|
|
291
|
+
<PaintBrushIcon size={14} aria-hidden="true" />
|
|
292
|
+
Style
|
|
293
|
+
</>
|
|
294
|
+
),
|
|
295
|
+
},
|
|
296
|
+
];
|
|
297
|
+
|
|
298
|
+
function Alert({
|
|
299
|
+
children,
|
|
300
|
+
...data
|
|
301
|
+
}: {
|
|
302
|
+
children: React.ReactNode;
|
|
303
|
+
"data-emvb-forms-missing"?: "";
|
|
304
|
+
}) {
|
|
305
|
+
return (
|
|
306
|
+
<p className="emvb-inline-error" role="alert" {...data}>
|
|
307
|
+
<WarningCircleIcon size={16} aria-hidden="true" />
|
|
308
|
+
{children}
|
|
309
|
+
</p>
|
|
310
|
+
);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/** Right panel with an element selected (IA / W-021): descriptor Content + Style sections. */
|
|
314
|
+
export function ElementPanel(props: Props) {
|
|
315
|
+
const descriptor = ELEMENT_DESCRIPTORS.find((d) => d.type === props.node.type);
|
|
316
|
+
if (!descriptor) {
|
|
317
|
+
return (
|
|
318
|
+
<div
|
|
319
|
+
className="emvb-panel-body"
|
|
320
|
+
data-emvb-panel="element"
|
|
321
|
+
data-emvb-element={props.node.type}
|
|
322
|
+
>
|
|
323
|
+
<h2 className="emvb-panel-title">Unknown element</h2>
|
|
324
|
+
<p className="emvb-helper">
|
|
325
|
+
Unknown element "{props.node.type}". It can be moved or deleted, but not edited.
|
|
326
|
+
</p>
|
|
327
|
+
{props.rejection && <Alert>{props.rejection}</Alert>}
|
|
328
|
+
</div>
|
|
329
|
+
);
|
|
330
|
+
}
|
|
331
|
+
return <KnownElementPanel {...props} descriptor={descriptor} />;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/** The open Style sections for an element type, remembered across visits (W-137). */
|
|
335
|
+
function useOpenSections(type: string, defaultOpen: StyleSectionId, nodeId: string) {
|
|
336
|
+
const [open, setOpen] = React.useState(() => readSections(type, [defaultOpen, ...OPEN_FIRST]));
|
|
337
|
+
React.useEffect(() => {
|
|
338
|
+
setOpen(readSections(type, [defaultOpen, ...OPEN_FIRST]));
|
|
339
|
+
}, [nodeId, type, defaultOpen]);
|
|
340
|
+
const setSection = (id: StyleSectionId, isOpen: boolean) => {
|
|
341
|
+
setOpen((current) => {
|
|
342
|
+
const next = new Set(current);
|
|
343
|
+
if (isOpen) next.add(id);
|
|
344
|
+
else next.delete(id);
|
|
345
|
+
writeSections(type, next);
|
|
346
|
+
return next;
|
|
347
|
+
});
|
|
348
|
+
};
|
|
349
|
+
return [open, setSection] as const;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
function KnownElementPanel({
|
|
353
|
+
node,
|
|
354
|
+
layout,
|
|
355
|
+
design,
|
|
356
|
+
rejection,
|
|
357
|
+
fetcher,
|
|
358
|
+
formsAvailable = true,
|
|
359
|
+
onChange,
|
|
360
|
+
onDesignChange,
|
|
361
|
+
onSelect,
|
|
362
|
+
onStyleState,
|
|
363
|
+
device = "desktop",
|
|
364
|
+
items,
|
|
365
|
+
partType,
|
|
366
|
+
descriptor,
|
|
367
|
+
}: Props & { descriptor: ElementDescriptor }) {
|
|
368
|
+
const ui = STYLE_UI[node.type] ?? DEFAULT_UI;
|
|
369
|
+
const [tab, setTab] = React.useState(descriptor.defaultTab);
|
|
370
|
+
const [openSections, setSection] = useOpenSections(node.type, ui.defaultOpen, node.id);
|
|
371
|
+
const { cls, editing, setEditing } = useStyleTarget(node, design);
|
|
372
|
+
const [designError, setDesignError] = React.useState<string | null>(null);
|
|
373
|
+
const [styleState, setStyleState] = React.useState<StyleStateChoice>("normal");
|
|
374
|
+
React.useEffect(() => setStyleState("normal"), [node.id]);
|
|
375
|
+
React.useEffect(() => {
|
|
376
|
+
onStyleState?.(node.id, tab === "style" ? styleState : "normal");
|
|
377
|
+
}, [node.id, styleState, tab, onStyleState]);
|
|
378
|
+
const normal = cls ? cls.style : node.style;
|
|
379
|
+
const states = cls ? cls.states : node.states;
|
|
380
|
+
const responsive: ResponsiveDevice | null = device === "desktop" ? null : device;
|
|
381
|
+
const ownerDevices = cls ? cls.devices : node.devices;
|
|
382
|
+
const style = responsive
|
|
383
|
+
? ownerDevices?.[responsive]
|
|
384
|
+
: styleState === "normal"
|
|
385
|
+
? normal
|
|
386
|
+
: states?.[styleState];
|
|
387
|
+
const inherited = responsive
|
|
388
|
+
? {
|
|
389
|
+
...normal,
|
|
390
|
+
...(responsive === "mobile" ? ownerDevices?.tablet : undefined),
|
|
391
|
+
}
|
|
392
|
+
: styleState === "normal"
|
|
393
|
+
? undefined
|
|
394
|
+
: normal;
|
|
395
|
+
const position = positionInEffect(node, design, cls);
|
|
396
|
+
const iconSvg =
|
|
397
|
+
node.type === "icon" && typeof node.props.iconSvg === "string" ? node.props.iconSvg : undefined;
|
|
398
|
+
const strokeAdjustable = node.type === "icon" && !cls ? iconHasAdjustableStroke(iconSvg) : true;
|
|
399
|
+
const singleColorOffered =
|
|
400
|
+
node.type === "icon" &&
|
|
401
|
+
!cls &&
|
|
402
|
+
!responsive &&
|
|
403
|
+
styleState === "normal" &&
|
|
404
|
+
(node.props.singleColor === true || iconHasOwnColors(iconSvg));
|
|
405
|
+
// W-296: elsewhere (Hover, Focus, a device) Colour does nothing on such an SVG until Force single
|
|
406
|
+
// colour is on, and that switch only lives in Normal on Desktop, so say so there.
|
|
407
|
+
const colorIgnoredHere =
|
|
408
|
+
node.type === "icon" &&
|
|
409
|
+
!cls &&
|
|
410
|
+
!singleColorOffered &&
|
|
411
|
+
node.props.singleColor !== true &&
|
|
412
|
+
iconHasOwnColors(iconSvg);
|
|
413
|
+
const patchStyle = (patch: Partial<StyleProps>) => {
|
|
414
|
+
if (responsive) {
|
|
415
|
+
if (!cls) {
|
|
416
|
+
onChange(withDevices(node, patchDeviceStyle(node.devices, responsive, patch)));
|
|
417
|
+
return;
|
|
418
|
+
}
|
|
419
|
+
setDesignError(null);
|
|
420
|
+
onDesignChange(patchClassDevices(design, cls.id, responsive, patch)).catch((error: unknown) =>
|
|
421
|
+
setDesignError(
|
|
422
|
+
error instanceof Error ? error.message : "Couldn't save the class. Try again.",
|
|
423
|
+
),
|
|
424
|
+
);
|
|
425
|
+
return;
|
|
426
|
+
}
|
|
427
|
+
const state = styleState;
|
|
428
|
+
if (!cls) {
|
|
429
|
+
onChange(
|
|
430
|
+
state === "normal"
|
|
431
|
+
? withStyle(node, patch)
|
|
432
|
+
: withStates(node, patchStates(node.states, state, patch)),
|
|
433
|
+
);
|
|
434
|
+
return;
|
|
435
|
+
}
|
|
436
|
+
setDesignError(null);
|
|
437
|
+
const next =
|
|
438
|
+
state === "normal"
|
|
439
|
+
? patchClassStyle(design, cls.id, patch)
|
|
440
|
+
: patchClassState(design, cls.id, state, patch);
|
|
441
|
+
onDesignChange(next).catch((error: unknown) =>
|
|
442
|
+
setDesignError(
|
|
443
|
+
error instanceof Error ? error.message : "Couldn't save the class. Try again.",
|
|
444
|
+
),
|
|
445
|
+
);
|
|
446
|
+
};
|
|
447
|
+
React.useEffect(() => {
|
|
448
|
+
setTab(descriptor.defaultTab);
|
|
449
|
+
}, [node.id, node.type, descriptor.defaultTab]);
|
|
450
|
+
const bodyRef = React.useRef<HTMLDivElement>(null);
|
|
451
|
+
useTabScroll(bodyRef, tab, node.id);
|
|
452
|
+
|
|
453
|
+
const Icon = ICONS[node.type] ?? SquaresFourIcon;
|
|
454
|
+
const crumbs = breadcrumb(layout, node.id);
|
|
455
|
+
const section = (
|
|
456
|
+
id: StyleSectionId,
|
|
457
|
+
count: number,
|
|
458
|
+
children: React.ReactNode,
|
|
459
|
+
stateMark = false,
|
|
460
|
+
) => (
|
|
461
|
+
<Section
|
|
462
|
+
key={id}
|
|
463
|
+
id={id}
|
|
464
|
+
open={openSections.has(id)}
|
|
465
|
+
count={count}
|
|
466
|
+
stateMark={stateMark}
|
|
467
|
+
onOpenChange={(open) => setSection(id, open)}
|
|
468
|
+
>
|
|
469
|
+
{children}
|
|
470
|
+
</Section>
|
|
471
|
+
);
|
|
472
|
+
|
|
473
|
+
return (
|
|
474
|
+
<div
|
|
475
|
+
ref={bodyRef}
|
|
476
|
+
className="emvb-panel-body"
|
|
477
|
+
data-emvb-panel="element"
|
|
478
|
+
data-emvb-element={node.type}
|
|
479
|
+
>
|
|
480
|
+
<div className="emvb-element-header">
|
|
481
|
+
<Icon size={16} aria-hidden="true" />
|
|
482
|
+
<h2 className="emvb-panel-title">{descriptor.name}</h2>
|
|
483
|
+
</div>
|
|
484
|
+
{crumbs.length > 0 && (
|
|
485
|
+
<nav className="emvb-breadcrumb" aria-label="Element path">
|
|
486
|
+
{crumbs.map((crumb, index) => (
|
|
487
|
+
<React.Fragment key={crumb.id ?? "page"}>
|
|
488
|
+
{index > 0 && <span aria-hidden="true"> › </span>}
|
|
489
|
+
<button
|
|
490
|
+
type="button"
|
|
491
|
+
className="emvb-breadcrumb-part"
|
|
492
|
+
onClick={() => onSelect(crumb.id)}
|
|
493
|
+
>
|
|
494
|
+
{crumb.label}
|
|
495
|
+
</button>
|
|
496
|
+
</React.Fragment>
|
|
497
|
+
))}
|
|
498
|
+
</nav>
|
|
499
|
+
)}
|
|
500
|
+
{rejection && <Alert>{rejection}</Alert>}
|
|
501
|
+
{!formsAvailable && FORM_TYPES.has(node.type) && (
|
|
502
|
+
<Alert data-emvb-forms-missing="">
|
|
503
|
+
The forms plugin is not installed. Form elements can't submit until it is added.
|
|
504
|
+
</Alert>
|
|
505
|
+
)}
|
|
506
|
+
<Tabs
|
|
507
|
+
variant="underline"
|
|
508
|
+
className="emvb-tabs"
|
|
509
|
+
tabs={TABS}
|
|
510
|
+
value={tab}
|
|
511
|
+
onValueChange={(value) => setTab(value === "style" ? "style" : "content")}
|
|
512
|
+
/>
|
|
513
|
+
{tab === "content" && (
|
|
514
|
+
<div className="emvb-panel-body" data-emvb-tab="content">
|
|
515
|
+
{hasItemList(node.type) ? (
|
|
516
|
+
<ItemList node={node} onChange={onChange} onSelect={onSelect} actions={items} />
|
|
517
|
+
) : descriptor.fields.length === 0 ? (
|
|
518
|
+
<p className="emvb-helper">
|
|
519
|
+
{node.type === "container"
|
|
520
|
+
? "A container holds other elements. Arrange them in Style."
|
|
521
|
+
: "This element has no content settings."}
|
|
522
|
+
</p>
|
|
523
|
+
) : (
|
|
524
|
+
descriptor.fields.map((field) => (
|
|
525
|
+
<FieldControl
|
|
526
|
+
key={field.key}
|
|
527
|
+
field={field}
|
|
528
|
+
node={node}
|
|
529
|
+
onChange={onChange}
|
|
530
|
+
fetcher={fetcher}
|
|
531
|
+
parentFormId={layout ? enclosingFormId(layout, node.id) : undefined}
|
|
532
|
+
duplicateName={
|
|
533
|
+
field.key === "field" && layout ? duplicateFieldName(layout, node.id) : false
|
|
534
|
+
}
|
|
535
|
+
device={device}
|
|
536
|
+
/>
|
|
537
|
+
))
|
|
538
|
+
)}
|
|
539
|
+
{ITEM_NOTES[node.type] && <p className="emvb-helper">{ITEM_NOTES[node.type]}</p>}
|
|
540
|
+
{svgImagesLeftOut(node) > 0 && (
|
|
541
|
+
<p className="emvb-helper" data-emvb-svg-images>
|
|
542
|
+
{svgImagesNotice(svgImagesLeftOut(node))}
|
|
543
|
+
</p>
|
|
544
|
+
)}
|
|
545
|
+
{sharedPartH1(node, partType) && (
|
|
546
|
+
<p className="emvb-helper" data-emvb-shared-h1>
|
|
547
|
+
This part shows on pages that already have their own H1, so they would get two. Use H2
|
|
548
|
+
or lower here unless this part is the page's only main heading.
|
|
549
|
+
</p>
|
|
550
|
+
)}
|
|
551
|
+
{buttonUrlNote(node) && (
|
|
552
|
+
<p className="emvb-helper" data-emvb-button-url>
|
|
553
|
+
{buttonUrlNote(node)}
|
|
554
|
+
</p>
|
|
555
|
+
)}
|
|
556
|
+
{loopContextNote(node, partType) && (
|
|
557
|
+
<p className="emvb-helper" data-emvb-loop-note>
|
|
558
|
+
{loopContextNote(node, partType)}
|
|
559
|
+
</p>
|
|
560
|
+
)}
|
|
561
|
+
{imageAltNote(node) && (
|
|
562
|
+
<p className="emvb-helper" data-emvb-alt-note>
|
|
563
|
+
{imageAltNote(node)}
|
|
564
|
+
</p>
|
|
565
|
+
)}
|
|
566
|
+
{unnamedBoxLink(node) && (
|
|
567
|
+
<p className="emvb-helper" data-emvb-unnamed-link>
|
|
568
|
+
{UNNAMED_BOX_LINK_NOTE}
|
|
569
|
+
</p>
|
|
570
|
+
)}
|
|
571
|
+
</div>
|
|
572
|
+
)}
|
|
573
|
+
{tab === "style" && (
|
|
574
|
+
<div className="emvb-panel-body" data-emvb-tab="style">
|
|
575
|
+
<ClassChipInput
|
|
576
|
+
applied={node.classes}
|
|
577
|
+
design={design}
|
|
578
|
+
editing={editing}
|
|
579
|
+
onEdit={setEditing}
|
|
580
|
+
onChange={(classes) => onChange({ ...node, classes })}
|
|
581
|
+
onDesignChange={onDesignChange}
|
|
582
|
+
onSaveLocal={
|
|
583
|
+
editing === null && hasLocalStyles(node)
|
|
584
|
+
? async (name) => {
|
|
585
|
+
const refusal = localToClassRefusal(design, node);
|
|
586
|
+
if (refusal) throw new Error(refusal);
|
|
587
|
+
const moved = localStylesToClass(design, node, name);
|
|
588
|
+
if (!moved) throw new Error("Couldn't save the class. Try again.");
|
|
589
|
+
await onDesignChange(moved.design);
|
|
590
|
+
onChange(moved.node);
|
|
591
|
+
}
|
|
592
|
+
: undefined
|
|
593
|
+
}
|
|
594
|
+
/>
|
|
595
|
+
{device === "desktop" ? (
|
|
596
|
+
<StateSwitcher
|
|
597
|
+
value={styleState}
|
|
598
|
+
states={states}
|
|
599
|
+
className={cls ? cls.name : null}
|
|
600
|
+
onChange={setStyleState}
|
|
601
|
+
/>
|
|
602
|
+
) : (
|
|
603
|
+
<p className="emvb-helper">
|
|
604
|
+
These override Desktop. State styles apply on every device.
|
|
605
|
+
</p>
|
|
606
|
+
)}
|
|
607
|
+
{designError && <Alert>{designError}</Alert>}
|
|
608
|
+
{!cls && styleState === "normal" && node.type === "spacer" && (
|
|
609
|
+
<FieldControl field={SPACER_HEIGHT} node={node} onChange={onChange} fetcher={fetcher} />
|
|
610
|
+
)}
|
|
611
|
+
{sectionsFor(ui.sections, style, node.type).map((id) => {
|
|
612
|
+
if (id === "advanced") {
|
|
613
|
+
if (cls || styleState !== "normal") return null;
|
|
614
|
+
return section(
|
|
615
|
+
id,
|
|
616
|
+
(node.htmlId ? 1 : 0) + (node.attributes?.length ?? 0),
|
|
617
|
+
<>
|
|
618
|
+
<HtmlIdField node={node} layout={layout} onChange={onChange} />
|
|
619
|
+
<AttributesEditor
|
|
620
|
+
attributes={node.attributes}
|
|
621
|
+
onChange={(attributes) => onChange({ ...node, attributes })}
|
|
622
|
+
/>
|
|
623
|
+
</>,
|
|
624
|
+
);
|
|
625
|
+
}
|
|
626
|
+
const keys = keysFor(node.type, id, style, position).filter(
|
|
627
|
+
(key) =>
|
|
628
|
+
(styleState === "normal" || !NORMAL_ONLY_KEYS.has(key)) &&
|
|
629
|
+
// W-237: Stroke width only for stroke-drawn icons (or once set, so it can be reset).
|
|
630
|
+
(key !== "iconStrokeWidth" ||
|
|
631
|
+
strokeAdjustable ||
|
|
632
|
+
style?.iconStrokeWidth !== undefined),
|
|
633
|
+
);
|
|
634
|
+
if (keys.length === 0) return null;
|
|
635
|
+
return section(
|
|
636
|
+
id,
|
|
637
|
+
countSet(node.type, style, id),
|
|
638
|
+
<>
|
|
639
|
+
{styleState !== "normal" && JUMPY.has(id) && (
|
|
640
|
+
<p className="emvb-helper" data-emvb-jump-help="">
|
|
641
|
+
{JUMP_HELP[styleState]}
|
|
642
|
+
</p>
|
|
643
|
+
)}
|
|
644
|
+
{keys.map((key) => {
|
|
645
|
+
const group = boxGroupOf(key);
|
|
646
|
+
if (group) {
|
|
647
|
+
// One four-box control per group, where its first key would be (W-138).
|
|
648
|
+
if (keys.find((k) => boxGroupOf(k) === group) !== key) return null;
|
|
649
|
+
return (
|
|
650
|
+
<BoxControl
|
|
651
|
+
key={`${node.id}:${cls?.id ?? "local"}:${responsive ?? "desktop"}:${styleState}:${group.id}`}
|
|
652
|
+
group={group}
|
|
653
|
+
style={style}
|
|
654
|
+
inherited={inherited}
|
|
655
|
+
design={design}
|
|
656
|
+
onPatch={patchStyle}
|
|
657
|
+
/>
|
|
658
|
+
);
|
|
659
|
+
}
|
|
660
|
+
const row = (
|
|
661
|
+
<StyleRow
|
|
662
|
+
key={`${styleState}:${key}`}
|
|
663
|
+
styleKey={key}
|
|
664
|
+
style={style}
|
|
665
|
+
inherited={inherited}
|
|
666
|
+
design={design}
|
|
667
|
+
fetcher={fetcher}
|
|
668
|
+
elementType={cls ? "container" : node.type}
|
|
669
|
+
fillScope={`${cls?.id ?? "local"}:${responsive ?? "desktop"}`}
|
|
670
|
+
onPatch={patchStyle}
|
|
671
|
+
onDesignChange={onDesignChange}
|
|
672
|
+
/>
|
|
673
|
+
);
|
|
674
|
+
if (id !== "icon" || key !== "color") return row;
|
|
675
|
+
// W-238: under Colour, Force single colour (a content prop, so Normal on
|
|
676
|
+
// Desktop only) and the background Shape presets.
|
|
677
|
+
return (
|
|
678
|
+
<React.Fragment key={`${styleState}:${key}`}>
|
|
679
|
+
{row}
|
|
680
|
+
{singleColorOffered && (
|
|
681
|
+
<IconSingleColorRow
|
|
682
|
+
checked={node.props.singleColor === true}
|
|
683
|
+
onChange={(checked) => {
|
|
684
|
+
const { singleColor: _was, ...props } = node.props as Record<
|
|
685
|
+
string,
|
|
686
|
+
unknown
|
|
687
|
+
>;
|
|
688
|
+
onChange({
|
|
689
|
+
...node,
|
|
690
|
+
props: checked ? { ...props, singleColor: true } : props,
|
|
691
|
+
} as LayoutNode);
|
|
692
|
+
}}
|
|
693
|
+
/>
|
|
694
|
+
)}
|
|
695
|
+
{colorIgnoredHere && (
|
|
696
|
+
<p className="emvb-helper" data-emvb-icon-color-ignored="">
|
|
697
|
+
This SVG keeps its own colors, so this color shows only once Force single
|
|
698
|
+
color is on (Normal state, Desktop).
|
|
699
|
+
</p>
|
|
700
|
+
)}
|
|
701
|
+
{styleState === "normal" && (
|
|
702
|
+
<IconShapeRow style={style} inherited={inherited} onPatch={patchStyle} />
|
|
703
|
+
)}
|
|
704
|
+
</React.Fragment>
|
|
705
|
+
);
|
|
706
|
+
})}
|
|
707
|
+
{id === "position" && !offsetsApply(position) && (
|
|
708
|
+
<p className="emvb-helper" data-emvb-offsets-help="">
|
|
709
|
+
Offsets apply once Position is Relative, Absolute, Fixed or Sticky.
|
|
710
|
+
</p>
|
|
711
|
+
)}
|
|
712
|
+
</>,
|
|
713
|
+
styleState === "normal" && sectionHasStates(node.type, states, id),
|
|
714
|
+
);
|
|
715
|
+
})}
|
|
716
|
+
</div>
|
|
717
|
+
)}
|
|
718
|
+
</div>
|
|
719
|
+
);
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
function Section({
|
|
723
|
+
id,
|
|
724
|
+
open,
|
|
725
|
+
count,
|
|
726
|
+
stateMark,
|
|
727
|
+
onOpenChange,
|
|
728
|
+
children,
|
|
729
|
+
}: {
|
|
730
|
+
id: StyleSectionId;
|
|
731
|
+
open: boolean;
|
|
732
|
+
count: number;
|
|
733
|
+
stateMark: boolean;
|
|
734
|
+
onOpenChange: (open: boolean) => void;
|
|
735
|
+
children: React.ReactNode;
|
|
736
|
+
}) {
|
|
737
|
+
return (
|
|
738
|
+
<Collapsible.Root open={open} onOpenChange={onOpenChange}>
|
|
739
|
+
<Collapsible.Trigger className="emvb-section-header" data-emvb-section={id}>
|
|
740
|
+
<span>
|
|
741
|
+
{SECTION_LABELS[id]}
|
|
742
|
+
{!open && count > 0 && <span className="emvb-count"> · {count}</span>}
|
|
743
|
+
{stateMark && <StateDot />}
|
|
744
|
+
</span>
|
|
745
|
+
{open ? (
|
|
746
|
+
<CaretDownIcon size={16} aria-hidden="true" />
|
|
747
|
+
) : (
|
|
748
|
+
<CaretRightIcon size={16} aria-hidden="true" />
|
|
749
|
+
)}
|
|
750
|
+
</Collapsible.Trigger>
|
|
751
|
+
<Collapsible.Panel className="emvb-section-body">{children}</Collapsible.Panel>
|
|
752
|
+
</Collapsible.Root>
|
|
753
|
+
);
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
function breadcrumb(
|
|
757
|
+
layout: Layout | null,
|
|
758
|
+
id: string,
|
|
759
|
+
): Array<{ id: string | null; label: string }> {
|
|
760
|
+
if (!layout) return [];
|
|
761
|
+
const chain: Array<{ id: string; label: string }> = [];
|
|
762
|
+
let current: string | undefined = id;
|
|
763
|
+
while (current) {
|
|
764
|
+
const node = findNode(layout, current);
|
|
765
|
+
if (!node) break;
|
|
766
|
+
chain.unshift({
|
|
767
|
+
id: node.id,
|
|
768
|
+
label: ELEMENT_NAMES[node.type] ?? node.type,
|
|
769
|
+
});
|
|
770
|
+
current = parentOf(layout, current);
|
|
771
|
+
}
|
|
772
|
+
return [{ id: null, label: "Page" }, ...chain];
|
|
773
|
+
}
|