@perkyzz/emvb 0.1.0 → 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/README.md +4 -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 +8 -4
- package/src/admin/api.ts +27 -0
- package/src/admin/content-api.ts +72 -9
- package/src/admin/editor/Editor.tsx +89 -14
- package/src/admin/editor/EditorOverlay.tsx +12 -0
- package/src/admin/editor/SmallScreenNotice.tsx +4 -3
- package/src/admin/editor/TopBar.tsx +76 -12
- package/src/admin/editor/canvas/CanvasFrame.tsx +224 -43
- package/src/admin/editor/canvas/DeviceBar.tsx +43 -2
- package/src/admin/editor/canvas/SelectionOverlay.tsx +60 -6
- package/src/admin/editor/canvas/canvas-events.ts +20 -7
- package/src/admin/editor/canvas/tab-reveal.ts +66 -0
- package/src/admin/editor/canvas/vnode-react.tsx +21 -1
- package/src/admin/editor/dialogs.tsx +39 -0
- package/src/admin/editor/dnd/drop-target.ts +63 -16
- package/src/admin/editor/dnd/new-element.ts +76 -1
- package/src/admin/editor/editor-css.ts +101 -15
- package/src/admin/editor/host.ts +30 -0
- package/src/admin/editor/icons/IconLibraryDialog.tsx +850 -0
- package/src/admin/editor/icons/library.ts +243 -0
- package/src/admin/editor/icons/set-format.ts +29 -0
- package/src/admin/editor/icons/sets/fontawesome.json +1 -0
- package/src/admin/editor/icons/sets/lucide.json +1 -0
- package/src/admin/editor/icons/sets/remix.json +1 -0
- package/src/admin/editor/icons/sets/tabler.json +1 -0
- package/src/admin/editor/panels/AddPanel.tsx +7 -3
- package/src/admin/editor/panels/ClassesSection.tsx +44 -6
- package/src/admin/editor/panels/ColorControl.tsx +268 -21
- package/src/admin/editor/panels/ElementPanel.tsx +237 -93
- package/src/admin/editor/panels/LayersPanel.tsx +303 -66
- package/src/admin/editor/panels/LeftPanel.tsx +4 -0
- package/src/admin/editor/panels/PageSettings.tsx +134 -5
- package/src/admin/editor/panels/SettingsPanel.tsx +12 -0
- package/src/admin/editor/panels/SiteStylesDrawer.tsx +158 -2
- package/src/admin/editor/panels/TriggersEditor.tsx +19 -2
- package/src/admin/editor/panels/VariableSection.tsx +47 -9
- package/src/admin/editor/panels/color-space.ts +195 -0
- package/src/admin/editor/panels/settings/AdvancedFields.tsx +119 -0
- package/src/admin/editor/panels/settings/BackgroundControls.tsx +153 -55
- package/src/admin/editor/panels/settings/BackgroundFill.tsx +221 -0
- package/src/admin/editor/panels/settings/BoxControl.tsx +271 -0
- package/src/admin/editor/panels/settings/ChoiceGroup.tsx +138 -0
- package/src/admin/editor/panels/settings/ClassChipInput.tsx +104 -2
- package/src/admin/editor/panels/settings/DraftTextField.tsx +44 -3
- package/src/admin/editor/panels/settings/EffectsControls.tsx +23 -16
- package/src/admin/editor/panels/settings/FieldBindControl.tsx +53 -17
- package/src/admin/editor/panels/settings/FieldControl.tsx +129 -9
- package/src/admin/editor/panels/settings/FormBindControl.tsx +14 -5
- package/src/admin/editor/panels/settings/IconControls.tsx +438 -0
- package/src/admin/editor/panels/settings/IconPicker.tsx +133 -72
- package/src/admin/editor/panels/settings/ItemList.tsx +199 -0
- package/src/admin/editor/panels/settings/LengthRow.tsx +97 -61
- package/src/admin/editor/panels/settings/LoopItemBindControl.tsx +10 -4
- package/src/admin/editor/panels/settings/MediaPicker.tsx +4 -2
- package/src/admin/editor/panels/settings/StateSwitcher.tsx +1 -1
- package/src/admin/editor/panels/settings/StyleRow.tsx +158 -75
- package/src/admin/editor/panels/settings/VariableBinding.tsx +5 -1
- package/src/admin/editor/panels/settings/advanced-rules.ts +63 -0
- package/src/admin/editor/panels/settings/background-mode.ts +112 -0
- package/src/admin/editor/panels/settings/box-link-name.ts +38 -0
- package/src/admin/editor/panels/settings/box-sides.ts +153 -0
- package/src/admin/editor/panels/settings/button-url.ts +27 -0
- package/src/admin/editor/panels/settings/class-suggest.ts +5 -3
- package/src/admin/editor/panels/settings/form-names.ts +38 -0
- package/src/admin/editor/panels/settings/heading-warning.ts +25 -0
- package/src/admin/editor/panels/settings/image-alt.ts +25 -0
- package/src/admin/editor/panels/settings/length-units.ts +40 -7
- package/src/admin/editor/panels/settings/loop-context.ts +26 -0
- package/src/admin/editor/panels/settings/style-sections.ts +114 -11
- package/src/admin/editor/panels/settings/svg-images.ts +14 -0
- package/src/admin/editor/panels/site-list.tsx +3 -0
- package/src/admin/editor/restore-deleted.ts +80 -0
- package/src/admin/editor/shortcuts.ts +1 -1
- package/src/admin/editor/store.ts +35 -7
- package/src/admin/editor/useEditorCommands.ts +66 -5
- package/src/admin/editor/useEditorData.ts +29 -3
- package/src/admin/editor/useEditorShortcuts.ts +34 -2
- package/src/admin/editor/useNodeActions.ts +68 -6
- package/src/admin/editor/useSave.ts +60 -3
- package/src/admin/entry-status.ts +19 -0
- package/src/admin/icon-uploads-api.ts +44 -0
- package/src/admin/pages/PageList.tsx +22 -2
- package/src/admin/pages/ThemePartList.tsx +23 -4
- package/src/admin/pages/list-kit.tsx +52 -2
- package/src/admin/setup/spec.ts +7 -0
- package/src/admin/theme-api.ts +61 -14
- package/src/admin/ui.ts +17 -4
- package/src/astro/EmVBPage.astro +28 -2
- package/src/astro/floats/EmVBFloatsRuntime.astro +9 -0
- package/src/astro/floats/index.ts +1 -0
- package/src/astro/floats/runtime.ts +78 -0
- package/src/astro/forms-definitions.ts +22 -0
- package/src/astro/index.ts +1 -0
- package/src/astro/menu/EmVBMenuRuntime.astro +9 -0
- package/src/astro/menu/index.ts +1 -0
- package/src/astro/menu/runtime.ts +37 -0
- package/src/astro/popups/runtime.ts +54 -4
- package/src/astro/render.ts +47 -13
- package/src/astro/resolve-theme.ts +164 -20
- package/src/astro/tabs/runtime.ts +6 -1
- package/src/astro/theme-context.ts +11 -3
- package/src/constants.ts +1 -1
- package/src/core/arrange.ts +98 -10
- package/src/core/clipboard.ts +91 -9
- package/src/core/css/generate.ts +21 -4
- package/src/core/design/classes.ts +95 -9
- package/src/core/design/transfer.ts +101 -2
- package/src/core/design/variables.ts +51 -11
- package/src/core/elements/dynamic-elements.ts +57 -5
- package/src/core/elements/field-id.ts +6 -0
- package/src/core/elements/form-elements.ts +23 -8
- package/src/core/elements/index.ts +267 -49
- package/src/core/elements/menu.ts +190 -0
- package/src/core/forms/definition.ts +11 -0
- package/src/core/index.ts +67 -3
- package/src/core/limits.ts +2 -0
- package/src/core/migrate/index.ts +51 -1
- package/src/core/nesting.ts +51 -0
- package/src/core/render/context.ts +7 -0
- package/src/core/render/dynamic-post.ts +39 -11
- package/src/core/render/extras.ts +22 -3
- package/src/core/render/form.ts +134 -36
- package/src/core/render/index.ts +123 -25
- package/src/core/render/loop.ts +10 -3
- package/src/core/render/pagination.ts +76 -0
- package/src/core/render/section.ts +5 -1
- package/src/core/render/tabs.ts +8 -4
- package/src/core/render/vnode.ts +1 -1
- package/src/core/sanitize/css.ts +197 -17
- package/src/core/sanitize/embed-url.ts +64 -7
- package/src/core/sanitize/svg-upload.ts +203 -0
- package/src/core/sanitize/svg.ts +102 -21
- package/src/core/schema/descriptors.ts +4 -0
- package/src/core/schema/design.ts +7 -2
- package/src/core/schema/layout.ts +210 -19
- package/src/core/schema/style.ts +87 -8
- package/src/core/tabs/presence.ts +9 -0
- package/src/core/theme/conditions.ts +4 -1
- package/src/core/theme/dynamic.ts +10 -0
- package/src/core/theme/float.ts +113 -0
- package/src/core/theme/pagination.ts +97 -0
- package/src/core/theme/part-types.ts +2 -0
- package/src/core/theme/popup-markup.ts +3 -1
- package/src/core/theme/popup-rules.ts +4 -3
- package/src/server/hooks.ts +20 -0
- package/src/server/icon-routes.ts +79 -0
- package/src/server/plugin.ts +5 -1
|
@@ -1,27 +1,40 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Collapsible, Tabs } from "@cloudflare/kumo";
|
|
2
2
|
import type { Fetcher } from "../../api.ts";
|
|
3
3
|
import {
|
|
4
4
|
CaretDownIcon,
|
|
5
5
|
CaretRightIcon,
|
|
6
|
+
CheckSquareIcon,
|
|
7
|
+
ClipboardTextIcon,
|
|
6
8
|
ImageIcon,
|
|
9
|
+
NotePencilIcon,
|
|
7
10
|
PaintBrushIcon,
|
|
11
|
+
PaperPlaneTiltIcon,
|
|
8
12
|
PencilSimpleIcon,
|
|
9
|
-
|
|
10
|
-
|
|
13
|
+
RadioButtonIcon,
|
|
14
|
+
RowsIcon,
|
|
11
15
|
SquaresFourIcon,
|
|
16
|
+
StarIcon,
|
|
12
17
|
TextHIcon,
|
|
13
|
-
WarningCircleIcon,
|
|
14
18
|
TextboxIcon,
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
PaperPlaneTiltIcon,
|
|
18
|
-
ClipboardTextIcon,
|
|
19
|
-
NotePencilIcon,
|
|
19
|
+
WarningCircleIcon,
|
|
20
|
+
YoutubeLogoIcon,
|
|
20
21
|
} from "@phosphor-icons/react";
|
|
21
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";
|
|
22
32
|
import {
|
|
23
33
|
ELEMENT_DESCRIPTORS,
|
|
24
34
|
findNode,
|
|
35
|
+
hasLocalStyles,
|
|
36
|
+
localStylesToClass,
|
|
37
|
+
localToClassRefusal,
|
|
25
38
|
isFormNode,
|
|
26
39
|
parentOf,
|
|
27
40
|
type DesignSystem,
|
|
@@ -37,14 +50,19 @@ import {
|
|
|
37
50
|
type PopupDevice,
|
|
38
51
|
type ResponsiveDevice,
|
|
39
52
|
classStylesInListOrder,
|
|
53
|
+
iconHasAdjustableStroke,
|
|
54
|
+
iconHasOwnColors,
|
|
40
55
|
resolveCascade,
|
|
41
56
|
STYLE_STATES,
|
|
42
57
|
type StyleProps,
|
|
43
58
|
type StyleStates,
|
|
44
59
|
} from "../../../core/index.ts";
|
|
45
|
-
import { BUTTON, FIELD } from "../../ui.ts";
|
|
46
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";
|
|
47
64
|
import { StyleRow } from "./settings/StyleRow.tsx";
|
|
65
|
+
import { AttributesEditor, HtmlIdField } from "./settings/AdvancedFields.tsx";
|
|
48
66
|
import { ClassChipInput } from "./settings/ClassChipInput.tsx";
|
|
49
67
|
import { StateDot, StateSwitcher, type StyleStateChoice } from "./settings/StateSwitcher.tsx";
|
|
50
68
|
import {
|
|
@@ -53,6 +71,7 @@ import {
|
|
|
53
71
|
offsetsApply,
|
|
54
72
|
SECTION_LABELS,
|
|
55
73
|
sectionsFor,
|
|
74
|
+
type StyleKey,
|
|
56
75
|
STYLE_UI,
|
|
57
76
|
type StyleSectionId,
|
|
58
77
|
} from "./settings/style-sections.ts";
|
|
@@ -75,6 +94,7 @@ const ICONS: Record<string, typeof TextHIcon> = {
|
|
|
75
94
|
heading: TextHIcon,
|
|
76
95
|
container: SquaresFourIcon,
|
|
77
96
|
"div-block": SquaresFourIcon,
|
|
97
|
+
"layout-section": RowsIcon,
|
|
78
98
|
flexbox: SquaresFourIcon,
|
|
79
99
|
image: ImageIcon,
|
|
80
100
|
icon: StarIcon,
|
|
@@ -110,11 +130,17 @@ const withStates = (node: LayoutNode, states: StyleStates | undefined): LayoutNo
|
|
|
110
130
|
return (states ? { ...rest, states } : rest) as LayoutNode;
|
|
111
131
|
};
|
|
112
132
|
|
|
113
|
-
const
|
|
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"];
|
|
114
140
|
|
|
115
141
|
const readSections = (type: string, fallback: StyleSectionId[]): Set<StyleSectionId> => {
|
|
116
142
|
try {
|
|
117
|
-
const raw =
|
|
143
|
+
const raw = localStorage.getItem(sectionKey(type));
|
|
118
144
|
if (!raw) return new Set(fallback);
|
|
119
145
|
const parsed = JSON.parse(raw) as string[];
|
|
120
146
|
return new Set(parsed.filter((id): id is StyleSectionId => id in SECTION_LABELS));
|
|
@@ -125,7 +151,7 @@ const readSections = (type: string, fallback: StyleSectionId[]): Set<StyleSectio
|
|
|
125
151
|
|
|
126
152
|
const writeSections = (type: string, open: Set<StyleSectionId>) => {
|
|
127
153
|
try {
|
|
128
|
-
|
|
154
|
+
localStorage.setItem(sectionKey(type), JSON.stringify([...open]));
|
|
129
155
|
} catch {
|
|
130
156
|
/* private mode */
|
|
131
157
|
}
|
|
@@ -138,9 +164,12 @@ const countSet = (type: string, style: StyleProps | undefined, section: StyleSec
|
|
|
138
164
|
const sectionHasStates = (type: string, states: StyleStates | undefined, section: StyleSectionId) =>
|
|
139
165
|
STYLE_STATES.some((state) => countSet(type, states?.[state], section) > 0);
|
|
140
166
|
|
|
141
|
-
/** Sections where a state change moves things around
|
|
167
|
+
/** Sections where a state change moves things around. */
|
|
142
168
|
const JUMPY = new Set<StyleSectionId>(["layout", "size", "position"]);
|
|
143
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
|
+
|
|
144
173
|
const JUMP_HELP: Record<Exclude<StyleStateChoice, "normal">, string> = {
|
|
145
174
|
hover: "Changing size or position on hover can make the page jump.",
|
|
146
175
|
focus: "Changing size or position on focus can make the page jump.",
|
|
@@ -158,6 +187,33 @@ const positionInEffect = (
|
|
|
158
187
|
: resolveCascade(classStylesInListOrder(design.classes, node.classes ?? []), node.style)
|
|
159
188
|
.position;
|
|
160
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
|
+
|
|
161
217
|
/** Which styles the Style sections edit (W-087): a class applied to the node, or its own. */
|
|
162
218
|
function useStyleTarget(node: LayoutNode, design: DesignSystem) {
|
|
163
219
|
const [editing, setEditing] = React.useState<string | null>(null);
|
|
@@ -184,6 +240,21 @@ type Props = {
|
|
|
184
240
|
onStyleState?: (nodeId: string, state: StyleStateChoice) => void;
|
|
185
241
|
/** Tablet and mobile edit overrides. Desktop edits `style` (W-096). */
|
|
186
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.",
|
|
187
258
|
};
|
|
188
259
|
|
|
189
260
|
const FORM_TYPES = new Set([
|
|
@@ -260,11 +331,11 @@ export function ElementPanel(props: Props) {
|
|
|
260
331
|
return <KnownElementPanel {...props} descriptor={descriptor} />;
|
|
261
332
|
}
|
|
262
333
|
|
|
263
|
-
/** The open Style sections for an element type, remembered
|
|
334
|
+
/** The open Style sections for an element type, remembered across visits (W-137). */
|
|
264
335
|
function useOpenSections(type: string, defaultOpen: StyleSectionId, nodeId: string) {
|
|
265
|
-
const [open, setOpen] = React.useState(() => readSections(type, [defaultOpen]));
|
|
336
|
+
const [open, setOpen] = React.useState(() => readSections(type, [defaultOpen, ...OPEN_FIRST]));
|
|
266
337
|
React.useEffect(() => {
|
|
267
|
-
setOpen(readSections(type, [defaultOpen]));
|
|
338
|
+
setOpen(readSections(type, [defaultOpen, ...OPEN_FIRST]));
|
|
268
339
|
}, [nodeId, type, defaultOpen]);
|
|
269
340
|
const setSection = (id: StyleSectionId, isOpen: boolean) => {
|
|
270
341
|
setOpen((current) => {
|
|
@@ -290,6 +361,8 @@ function KnownElementPanel({
|
|
|
290
361
|
onSelect,
|
|
291
362
|
onStyleState,
|
|
292
363
|
device = "desktop",
|
|
364
|
+
items,
|
|
365
|
+
partType,
|
|
293
366
|
descriptor,
|
|
294
367
|
}: Props & { descriptor: ElementDescriptor }) {
|
|
295
368
|
const ui = STYLE_UI[node.type] ?? DEFAULT_UI;
|
|
@@ -320,6 +393,23 @@ function KnownElementPanel({
|
|
|
320
393
|
? undefined
|
|
321
394
|
: normal;
|
|
322
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);
|
|
323
413
|
const patchStyle = (patch: Partial<StyleProps>) => {
|
|
324
414
|
if (responsive) {
|
|
325
415
|
if (!cls) {
|
|
@@ -357,6 +447,8 @@ function KnownElementPanel({
|
|
|
357
447
|
React.useEffect(() => {
|
|
358
448
|
setTab(descriptor.defaultTab);
|
|
359
449
|
}, [node.id, node.type, descriptor.defaultTab]);
|
|
450
|
+
const bodyRef = React.useRef<HTMLDivElement>(null);
|
|
451
|
+
useTabScroll(bodyRef, tab, node.id);
|
|
360
452
|
|
|
361
453
|
const Icon = ICONS[node.type] ?? SquaresFourIcon;
|
|
362
454
|
const crumbs = breadcrumb(layout, node.id);
|
|
@@ -379,7 +471,12 @@ function KnownElementPanel({
|
|
|
379
471
|
);
|
|
380
472
|
|
|
381
473
|
return (
|
|
382
|
-
<div
|
|
474
|
+
<div
|
|
475
|
+
ref={bodyRef}
|
|
476
|
+
className="emvb-panel-body"
|
|
477
|
+
data-emvb-panel="element"
|
|
478
|
+
data-emvb-element={node.type}
|
|
479
|
+
>
|
|
383
480
|
<div className="emvb-element-header">
|
|
384
481
|
<Icon size={16} aria-hidden="true" />
|
|
385
482
|
<h2 className="emvb-panel-title">{descriptor.name}</h2>
|
|
@@ -415,7 +512,9 @@ function KnownElementPanel({
|
|
|
415
512
|
/>
|
|
416
513
|
{tab === "content" && (
|
|
417
514
|
<div className="emvb-panel-body" data-emvb-tab="content">
|
|
418
|
-
{
|
|
515
|
+
{hasItemList(node.type) ? (
|
|
516
|
+
<ItemList node={node} onChange={onChange} onSelect={onSelect} actions={items} />
|
|
517
|
+
) : descriptor.fields.length === 0 ? (
|
|
419
518
|
<p className="emvb-helper">
|
|
420
519
|
{node.type === "container"
|
|
421
520
|
? "A container holds other elements. Arrange them in Style."
|
|
@@ -430,9 +529,45 @@ function KnownElementPanel({
|
|
|
430
529
|
onChange={onChange}
|
|
431
530
|
fetcher={fetcher}
|
|
432
531
|
parentFormId={layout ? enclosingFormId(layout, node.id) : undefined}
|
|
532
|
+
duplicateName={
|
|
533
|
+
field.key === "field" && layout ? duplicateFieldName(layout, node.id) : false
|
|
534
|
+
}
|
|
535
|
+
device={device}
|
|
433
536
|
/>
|
|
434
537
|
))
|
|
435
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
|
+
)}
|
|
436
571
|
</div>
|
|
437
572
|
)}
|
|
438
573
|
{tab === "style" && (
|
|
@@ -444,6 +579,18 @@ function KnownElementPanel({
|
|
|
444
579
|
onEdit={setEditing}
|
|
445
580
|
onChange={(classes) => onChange({ ...node, classes })}
|
|
446
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
|
+
}
|
|
447
594
|
/>
|
|
448
595
|
{device === "desktop" ? (
|
|
449
596
|
<StateSwitcher
|
|
@@ -461,22 +608,14 @@ function KnownElementPanel({
|
|
|
461
608
|
{!cls && styleState === "normal" && node.type === "spacer" && (
|
|
462
609
|
<FieldControl field={SPACER_HEIGHT} node={node} onChange={onChange} fetcher={fetcher} />
|
|
463
610
|
)}
|
|
464
|
-
{sectionsFor(ui.sections, style).map((id) => {
|
|
611
|
+
{sectionsFor(ui.sections, style, node.type).map((id) => {
|
|
465
612
|
if (id === "advanced") {
|
|
466
613
|
if (cls || styleState !== "normal") return null;
|
|
467
614
|
return section(
|
|
468
615
|
id,
|
|
469
616
|
(node.htmlId ? 1 : 0) + (node.attributes?.length ?? 0),
|
|
470
617
|
<>
|
|
471
|
-
<
|
|
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
|
-
/>
|
|
618
|
+
<HtmlIdField node={node} layout={layout} onChange={onChange} />
|
|
480
619
|
<AttributesEditor
|
|
481
620
|
attributes={node.attributes}
|
|
482
621
|
onChange={(attributes) => onChange({ ...node, attributes })}
|
|
@@ -485,7 +624,12 @@ function KnownElementPanel({
|
|
|
485
624
|
);
|
|
486
625
|
}
|
|
487
626
|
const keys = keysFor(node.type, id, style, position).filter(
|
|
488
|
-
(key) =>
|
|
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),
|
|
489
633
|
);
|
|
490
634
|
if (keys.length === 0) return null;
|
|
491
635
|
return section(
|
|
@@ -497,18 +641,69 @@ function KnownElementPanel({
|
|
|
497
641
|
{JUMP_HELP[styleState]}
|
|
498
642
|
</p>
|
|
499
643
|
)}
|
|
500
|
-
{keys.map((key) =>
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
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
|
+
})}
|
|
512
707
|
{id === "position" && !offsetsApply(position) && (
|
|
513
708
|
<p className="emvb-helper" data-emvb-offsets-help="">
|
|
514
709
|
Offsets apply once Position is Relative, Absolute, Fixed or Sticky.
|
|
@@ -576,54 +771,3 @@ function breadcrumb(
|
|
|
576
771
|
}
|
|
577
772
|
return [{ id: null, label: "Page" }, ...chain];
|
|
578
773
|
}
|
|
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
|
-
}
|