@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
|
@@ -0,0 +1,438 @@
|
|
|
1
|
+
import { Button, Select, Switch } from "@cloudflare/kumo";
|
|
2
|
+
import {
|
|
3
|
+
FlipHorizontalIcon,
|
|
4
|
+
FlipVerticalIcon,
|
|
5
|
+
PlusIcon,
|
|
6
|
+
ProhibitIcon,
|
|
7
|
+
} from "@phosphor-icons/react";
|
|
8
|
+
import * as React from "react";
|
|
9
|
+
import type { DesignSystem, StyleProps } from "../../../../core/index.ts";
|
|
10
|
+
import { BUTTON, FIELD } from "../../../ui.ts";
|
|
11
|
+
import { ColorControl } from "../ColorControl.tsx";
|
|
12
|
+
import { radioGroupKeys } from "./ChoiceGroup.tsx";
|
|
13
|
+
import { NumberField, ResetButton, type NumberSpec } from "./NumberRow.tsx";
|
|
14
|
+
|
|
15
|
+
/** W-237: the Icon section's own controls (glyph rotation, flip, drop shadow, loop). */
|
|
16
|
+
|
|
17
|
+
type Flip = NonNullable<StyleProps["iconFlip"]>;
|
|
18
|
+
type IconShadow = NonNullable<StyleProps["iconShadow"]>;
|
|
19
|
+
type IconAnimation = NonNullable<StyleProps["iconAnimation"]>;
|
|
20
|
+
|
|
21
|
+
const ICON_ROTATE: NumberSpec = {
|
|
22
|
+
min: -360,
|
|
23
|
+
max: 360,
|
|
24
|
+
integer: true,
|
|
25
|
+
example: "45",
|
|
26
|
+
suffix: "°",
|
|
27
|
+
placeholder: "0",
|
|
28
|
+
};
|
|
29
|
+
export const ICON_SCALE: NumberSpec = {
|
|
30
|
+
min: 0.1,
|
|
31
|
+
max: 4,
|
|
32
|
+
example: "1.2",
|
|
33
|
+
suffix: "×",
|
|
34
|
+
placeholder: "1",
|
|
35
|
+
};
|
|
36
|
+
export const ICON_STROKE: NumberSpec = { min: 0.25, max: 6, example: "1.5", placeholder: "2" };
|
|
37
|
+
|
|
38
|
+
/** Rotation in degrees: a number field over a -360…360 slider. */
|
|
39
|
+
export function IconRotateRow({
|
|
40
|
+
value,
|
|
41
|
+
inherited,
|
|
42
|
+
onChange,
|
|
43
|
+
}: {
|
|
44
|
+
value: number | undefined;
|
|
45
|
+
inherited?: number;
|
|
46
|
+
onChange: (next: number | undefined) => void;
|
|
47
|
+
}) {
|
|
48
|
+
const set = value !== undefined;
|
|
49
|
+
return (
|
|
50
|
+
<div
|
|
51
|
+
className="emvb-style-row"
|
|
52
|
+
data-emvb-style="iconRotate"
|
|
53
|
+
data-set={set ? "true" : undefined}
|
|
54
|
+
data-inherited={!set && inherited !== undefined ? "true" : undefined}
|
|
55
|
+
>
|
|
56
|
+
<div className="emvb-length-stack">
|
|
57
|
+
<NumberField
|
|
58
|
+
fieldKey="iconRotate"
|
|
59
|
+
label="Rotate"
|
|
60
|
+
value={value}
|
|
61
|
+
spec={ICON_ROTATE}
|
|
62
|
+
inherited={inherited}
|
|
63
|
+
onCommit={onChange}
|
|
64
|
+
/>
|
|
65
|
+
<input
|
|
66
|
+
className="emvb-gap-slider"
|
|
67
|
+
type="range"
|
|
68
|
+
min={-360}
|
|
69
|
+
max={360}
|
|
70
|
+
step={1}
|
|
71
|
+
aria-label="Rotate slider"
|
|
72
|
+
value={value ?? inherited ?? 0}
|
|
73
|
+
onChange={(event) => onChange(Number(event.target.value))}
|
|
74
|
+
/>
|
|
75
|
+
</div>
|
|
76
|
+
<ResetButton label="Rotate" set={set} onReset={() => onChange(undefined)} />
|
|
77
|
+
</div>
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const flipParts = (flip: Flip | undefined) => ({
|
|
82
|
+
h: flip === "horizontal" || flip === "both",
|
|
83
|
+
v: flip === "vertical" || flip === "both",
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
/** Two toggles stored as one value; both off saves `none` so a device can undo Desktop's flip. */
|
|
87
|
+
export function IconFlipRow({
|
|
88
|
+
value,
|
|
89
|
+
inherited,
|
|
90
|
+
onChange,
|
|
91
|
+
}: {
|
|
92
|
+
value: Flip | undefined;
|
|
93
|
+
inherited?: Flip;
|
|
94
|
+
onChange: (next: Flip | undefined) => void;
|
|
95
|
+
}) {
|
|
96
|
+
const set = value !== undefined;
|
|
97
|
+
const { h, v } = flipParts(value ?? inherited);
|
|
98
|
+
const pick = (nextH: boolean, nextV: boolean) =>
|
|
99
|
+
onChange(nextH && nextV ? "both" : nextH ? "horizontal" : nextV ? "vertical" : "none");
|
|
100
|
+
return (
|
|
101
|
+
<div
|
|
102
|
+
className="emvb-style-row"
|
|
103
|
+
data-emvb-style="iconFlip"
|
|
104
|
+
data-set={set ? "true" : undefined}
|
|
105
|
+
data-inherited={!set && inherited !== undefined ? "true" : undefined}
|
|
106
|
+
>
|
|
107
|
+
<div className="emvb-choice">
|
|
108
|
+
<span className="emvb-choice-label">Flip</span>
|
|
109
|
+
<div className="emvb-choice-group" role="group" aria-label="Flip">
|
|
110
|
+
<button
|
|
111
|
+
type="button"
|
|
112
|
+
aria-pressed={h}
|
|
113
|
+
aria-label="Flip horizontal"
|
|
114
|
+
title="Flip horizontal"
|
|
115
|
+
data-emvb-flip="horizontal"
|
|
116
|
+
onClick={() => pick(!h, v)}
|
|
117
|
+
>
|
|
118
|
+
<FlipHorizontalIcon size={16} aria-hidden="true" />
|
|
119
|
+
</button>
|
|
120
|
+
<button
|
|
121
|
+
type="button"
|
|
122
|
+
aria-pressed={v}
|
|
123
|
+
aria-label="Flip vertical"
|
|
124
|
+
title="Flip vertical"
|
|
125
|
+
data-emvb-flip="vertical"
|
|
126
|
+
onClick={() => pick(h, !v)}
|
|
127
|
+
>
|
|
128
|
+
<FlipVerticalIcon size={16} aria-hidden="true" />
|
|
129
|
+
</button>
|
|
130
|
+
</div>
|
|
131
|
+
</div>
|
|
132
|
+
<ResetButton label="Flip" set={set} onReset={() => onChange(undefined)} />
|
|
133
|
+
</div>
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** Add drop shadow starts at 0 2 4, 25 % black: soft, and it follows the glyph's outline. */
|
|
138
|
+
const NEW_ICON_SHADOW: IconShadow = { x: 0, y: 2, blur: 4, color: "#00000040" };
|
|
139
|
+
const SHADOW_OFFSET: NumberSpec = { min: -100, max: 100, example: "2" };
|
|
140
|
+
const ICON_SHADOW_FIELDS: ReadonlyArray<[key: "x" | "y" | "blur", label: string, NumberSpec]> = [
|
|
141
|
+
["x", "Horizontal", SHADOW_OFFSET],
|
|
142
|
+
["y", "Vertical", SHADOW_OFFSET],
|
|
143
|
+
["blur", "Blur", { min: 0, max: 100, example: "4" }],
|
|
144
|
+
];
|
|
145
|
+
|
|
146
|
+
export function IconShadowControl({
|
|
147
|
+
value,
|
|
148
|
+
design,
|
|
149
|
+
onChange,
|
|
150
|
+
onDesignChange,
|
|
151
|
+
}: {
|
|
152
|
+
value: IconShadow | undefined;
|
|
153
|
+
design: DesignSystem;
|
|
154
|
+
onChange: (next: IconShadow | undefined) => void;
|
|
155
|
+
onDesignChange: (design: DesignSystem) => Promise<void>;
|
|
156
|
+
}) {
|
|
157
|
+
const patch = (part: Partial<IconShadow>) => {
|
|
158
|
+
if (!value) return;
|
|
159
|
+
const next: Record<string, unknown> = { ...value, ...part };
|
|
160
|
+
for (const key of Object.keys(next)) if (next[key] === undefined) delete next[key];
|
|
161
|
+
onChange(next as IconShadow);
|
|
162
|
+
};
|
|
163
|
+
return (
|
|
164
|
+
<div
|
|
165
|
+
className="emvb-style-row"
|
|
166
|
+
data-emvb-style="iconShadow"
|
|
167
|
+
data-set={value ? "true" : undefined}
|
|
168
|
+
>
|
|
169
|
+
<div className="emvb-field-group emvb-shadow">
|
|
170
|
+
<span className="emvb-var-field-label">Drop shadow</span>
|
|
171
|
+
{value ? (
|
|
172
|
+
<>
|
|
173
|
+
<ColorControl
|
|
174
|
+
label="Drop shadow color"
|
|
175
|
+
value={value.color}
|
|
176
|
+
design={design}
|
|
177
|
+
onChange={(color) => patch({ color })}
|
|
178
|
+
onDesignChange={onDesignChange}
|
|
179
|
+
/>
|
|
180
|
+
<div className="emvb-shadow-grid">
|
|
181
|
+
{ICON_SHADOW_FIELDS.map(([key, label, spec]) => (
|
|
182
|
+
<NumberField
|
|
183
|
+
key={key}
|
|
184
|
+
fieldKey={`iconShadow.${key}`}
|
|
185
|
+
label={label}
|
|
186
|
+
value={value[key]}
|
|
187
|
+
spec={spec}
|
|
188
|
+
onCommit={(n) => patch({ [key]: n ?? 0 })}
|
|
189
|
+
/>
|
|
190
|
+
))}
|
|
191
|
+
</div>
|
|
192
|
+
</>
|
|
193
|
+
) : (
|
|
194
|
+
<Button
|
|
195
|
+
type="button"
|
|
196
|
+
variant="secondary"
|
|
197
|
+
className={`${BUTTON} emvb-add-shadow`}
|
|
198
|
+
icon={<PlusIcon aria-hidden="true" />}
|
|
199
|
+
onClick={() => onChange(NEW_ICON_SHADOW)}
|
|
200
|
+
>
|
|
201
|
+
Add drop shadow
|
|
202
|
+
</Button>
|
|
203
|
+
)}
|
|
204
|
+
</div>
|
|
205
|
+
<ResetButton
|
|
206
|
+
label="Drop shadow"
|
|
207
|
+
set={value !== undefined}
|
|
208
|
+
onReset={() => onChange(undefined)}
|
|
209
|
+
/>
|
|
210
|
+
</div>
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
const DURATION: NumberSpec = {
|
|
215
|
+
min: 200,
|
|
216
|
+
max: 10_000,
|
|
217
|
+
integer: true,
|
|
218
|
+
example: "2000",
|
|
219
|
+
suffix: "ms",
|
|
220
|
+
};
|
|
221
|
+
type Looping = Extract<IconAnimation, { duration: number }>;
|
|
222
|
+
const DEFAULT_DURATION: Record<Looping["type"], number> = { spin: 2000, pulse: 1000 };
|
|
223
|
+
|
|
224
|
+
const looping = (a: IconAnimation | undefined): Looping | undefined =>
|
|
225
|
+
a && a.type !== "none" ? a : undefined;
|
|
226
|
+
|
|
227
|
+
/** A looping spin or pulse (Normal only); visitors who prefer reduced motion see it still. */
|
|
228
|
+
const ANIMATION_LABELS: Record<string, string> = { none: "None", spin: "Spin", pulse: "Pulse" };
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* W-248: on Tablet or Mobile, `inherited` is the animation from a wider device. With nothing set
|
|
232
|
+
* here the select shows it, and None stores `{ type: "none" }` so the device can stop it.
|
|
233
|
+
*/
|
|
234
|
+
export function IconAnimationControl({
|
|
235
|
+
value,
|
|
236
|
+
inherited,
|
|
237
|
+
onChange,
|
|
238
|
+
}: {
|
|
239
|
+
value: IconAnimation | undefined;
|
|
240
|
+
inherited?: IconAnimation;
|
|
241
|
+
onChange: (next: IconAnimation | undefined) => void;
|
|
242
|
+
}) {
|
|
243
|
+
const own = looping(value);
|
|
244
|
+
const from = looping(inherited);
|
|
245
|
+
const shown = value?.type ?? inherited?.type ?? "none";
|
|
246
|
+
const [type, setType] = React.useState<string>(shown);
|
|
247
|
+
React.useEffect(() => setType(shown), [shown]);
|
|
248
|
+
return (
|
|
249
|
+
<div
|
|
250
|
+
className="emvb-style-row"
|
|
251
|
+
data-emvb-style="iconAnimation"
|
|
252
|
+
data-set={value ? "true" : undefined}
|
|
253
|
+
data-inherited={!value && from ? "true" : undefined}
|
|
254
|
+
>
|
|
255
|
+
<div className="emvb-field-group">
|
|
256
|
+
<Select
|
|
257
|
+
label="Animation"
|
|
258
|
+
className={FIELD}
|
|
259
|
+
value={type}
|
|
260
|
+
renderValue={(v: unknown) => ANIMATION_LABELS[String(v)] ?? "None"}
|
|
261
|
+
onValueChange={(next) => {
|
|
262
|
+
const picked = String(next);
|
|
263
|
+
setType(picked);
|
|
264
|
+
if (picked === "spin" || picked === "pulse") {
|
|
265
|
+
const duration = own?.duration ?? from?.duration ?? DEFAULT_DURATION[picked];
|
|
266
|
+
onChange({ type: picked, duration });
|
|
267
|
+
} else onChange(from ? { type: "none" } : undefined);
|
|
268
|
+
}}
|
|
269
|
+
>
|
|
270
|
+
<Select.Option value="none">None</Select.Option>
|
|
271
|
+
<Select.Option value="spin">Spin</Select.Option>
|
|
272
|
+
<Select.Option value="pulse">Pulse</Select.Option>
|
|
273
|
+
</Select>
|
|
274
|
+
{own && (
|
|
275
|
+
<NumberField
|
|
276
|
+
fieldKey="iconAnimation.duration"
|
|
277
|
+
label="Duration"
|
|
278
|
+
value={own.duration}
|
|
279
|
+
spec={DURATION}
|
|
280
|
+
onCommit={(n) => onChange({ ...own, duration: n ?? DEFAULT_DURATION[own.type] })}
|
|
281
|
+
/>
|
|
282
|
+
)}
|
|
283
|
+
{own && <p className="emvb-helper">Off for visitors who prefer reduced motion.</p>}
|
|
284
|
+
{!value && from && (
|
|
285
|
+
<p className="emvb-helper">
|
|
286
|
+
Inherited from a wider device ({ANIMATION_LABELS[from.type]}, {from.duration} ms). Pick
|
|
287
|
+
None to stop it on this one.
|
|
288
|
+
</p>
|
|
289
|
+
)}
|
|
290
|
+
{value?.type === "none" && from && (
|
|
291
|
+
<p className="emvb-helper">Stopped on this device. Reset to inherit it again.</p>
|
|
292
|
+
)}
|
|
293
|
+
</div>
|
|
294
|
+
<ResetButton
|
|
295
|
+
label="Animation"
|
|
296
|
+
set={value !== undefined}
|
|
297
|
+
onReset={() => onChange(undefined)}
|
|
298
|
+
/>
|
|
299
|
+
</div>
|
|
300
|
+
);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/** W-238: Force single colour, a content prop shown under Colour for multi-colour SVGs. */
|
|
304
|
+
export function IconSingleColorRow({
|
|
305
|
+
checked,
|
|
306
|
+
onChange,
|
|
307
|
+
}: {
|
|
308
|
+
checked: boolean;
|
|
309
|
+
onChange: (next: boolean) => void;
|
|
310
|
+
}) {
|
|
311
|
+
return (
|
|
312
|
+
<div className="emvb-field-group" data-emvb-icon-single-color="">
|
|
313
|
+
<Switch label="Force single color" checked={checked} onCheckedChange={onChange} />
|
|
314
|
+
<p className="emvb-helper">
|
|
315
|
+
{checked
|
|
316
|
+
? "Every part of this SVG uses the icon color, so details drawn over filled shapes can disappear."
|
|
317
|
+
: "This SVG keeps its own colors. Turn on to paint it in the icon color."}
|
|
318
|
+
</p>
|
|
319
|
+
</div>
|
|
320
|
+
);
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
type IconShape = "none" | "circle" | "rounded" | "square";
|
|
324
|
+
|
|
325
|
+
const SHAPE_PADDING = { value: 12, unit: "px" } as const;
|
|
326
|
+
/** A light neutral, so the default icon colour (the text colour) reads on it. */
|
|
327
|
+
const SHAPE_BACKGROUND = "#f1f5f9";
|
|
328
|
+
const SHAPE_RADIUS: Record<Exclude<IconShape, "none">, StyleProps["borderRadius"]> = {
|
|
329
|
+
circle: { value: 50, unit: "%" },
|
|
330
|
+
rounded: { value: 12, unit: "px" },
|
|
331
|
+
square: { value: 0, unit: "px" },
|
|
332
|
+
};
|
|
333
|
+
const PADDINGS = ["paddingTop", "paddingRight", "paddingBottom", "paddingLeft"] as const;
|
|
334
|
+
const CORNERS = [
|
|
335
|
+
"borderTopLeftRadius",
|
|
336
|
+
"borderTopRightRadius",
|
|
337
|
+
"borderBottomRightRadius",
|
|
338
|
+
"borderBottomLeftRadius",
|
|
339
|
+
] as const;
|
|
340
|
+
|
|
341
|
+
/** The shape the styles in effect make: a background or border, and the corner radius. */
|
|
342
|
+
function iconShapeOf(style: StyleProps | undefined): IconShape {
|
|
343
|
+
if (!style || (style.backgroundColor === undefined && style.borderWidth === undefined))
|
|
344
|
+
return "none";
|
|
345
|
+
const radius = style.borderRadius;
|
|
346
|
+
if (radius && typeof radius === "object" && "value" in radius) {
|
|
347
|
+
if (radius.unit === "%" && radius.value >= 50) return "circle";
|
|
348
|
+
if (radius.value === 0) return "square";
|
|
349
|
+
return "rounded";
|
|
350
|
+
}
|
|
351
|
+
return radius === undefined ? "square" : "rounded";
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* The patch a shape choice makes (Elementor's Shape: None, Circle, Rounded, Square). A shape
|
|
356
|
+
* keeps a background or border already set, and adds 12 px padding only where none is set.
|
|
357
|
+
* None clears the background, radius and padding it would have added.
|
|
358
|
+
*/
|
|
359
|
+
function iconShapePatch(shape: IconShape, style: StyleProps | undefined): Partial<StyleProps> {
|
|
360
|
+
const patch: Partial<StyleProps> = {};
|
|
361
|
+
for (const corner of CORNERS) if (style?.[corner] !== undefined) patch[corner] = undefined;
|
|
362
|
+
if (shape === "none") {
|
|
363
|
+
patch.backgroundColor = undefined;
|
|
364
|
+
patch.borderRadius = undefined;
|
|
365
|
+
for (const side of PADDINGS) patch[side] = undefined;
|
|
366
|
+
return patch;
|
|
367
|
+
}
|
|
368
|
+
if (style?.backgroundColor === undefined && style?.borderWidth === undefined)
|
|
369
|
+
patch.backgroundColor = SHAPE_BACKGROUND;
|
|
370
|
+
patch.borderRadius = SHAPE_RADIUS[shape];
|
|
371
|
+
if (PADDINGS.every((side) => style?.[side] === undefined))
|
|
372
|
+
for (const side of PADDINGS) patch[side] = SHAPE_PADDING;
|
|
373
|
+
return patch;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
const SHAPES: { value: IconShape; label: string }[] = [
|
|
377
|
+
{ value: "none", label: "None" },
|
|
378
|
+
{ value: "circle", label: "Circle" },
|
|
379
|
+
{ value: "rounded", label: "Rounded square" },
|
|
380
|
+
{ value: "square", label: "Square" },
|
|
381
|
+
];
|
|
382
|
+
|
|
383
|
+
/** Background shape presets; colour, padding and border stay editable in their sections. */
|
|
384
|
+
export function IconShapeRow({
|
|
385
|
+
style,
|
|
386
|
+
inherited,
|
|
387
|
+
onPatch,
|
|
388
|
+
}: {
|
|
389
|
+
style: StyleProps | undefined;
|
|
390
|
+
inherited?: StyleProps;
|
|
391
|
+
onPatch: (patch: Partial<StyleProps>) => void;
|
|
392
|
+
}) {
|
|
393
|
+
const effective = { ...inherited, ...style };
|
|
394
|
+
const current = iconShapeOf(effective);
|
|
395
|
+
const keys = radioGroupKeys(
|
|
396
|
+
SHAPES.map((shape) => shape.value),
|
|
397
|
+
current,
|
|
398
|
+
(value) => onPatch(iconShapePatch(value as IconShape, effective)),
|
|
399
|
+
);
|
|
400
|
+
return (
|
|
401
|
+
<div className="emvb-style-row" data-emvb-icon-shape={current}>
|
|
402
|
+
<div className="emvb-choice">
|
|
403
|
+
<span className="emvb-choice-label" id="emvb-icon-shape-label">
|
|
404
|
+
Shape
|
|
405
|
+
</span>
|
|
406
|
+
<div
|
|
407
|
+
className="emvb-choice-group"
|
|
408
|
+
role="radiogroup"
|
|
409
|
+
aria-labelledby="emvb-icon-shape-label"
|
|
410
|
+
onKeyDown={keys.onKeyDown}
|
|
411
|
+
>
|
|
412
|
+
{SHAPES.map((shape) => (
|
|
413
|
+
<button
|
|
414
|
+
key={shape.value}
|
|
415
|
+
type="button"
|
|
416
|
+
role="radio"
|
|
417
|
+
aria-checked={current === shape.value}
|
|
418
|
+
aria-label={shape.label}
|
|
419
|
+
title={shape.label}
|
|
420
|
+
data-emvb-choice={shape.value}
|
|
421
|
+
tabIndex={keys.tabIndexOf(shape.value)}
|
|
422
|
+
onClick={() => onPatch(iconShapePatch(shape.value, effective))}
|
|
423
|
+
>
|
|
424
|
+
{shape.value === "none" ? (
|
|
425
|
+
<ProhibitIcon size={16} aria-hidden="true" />
|
|
426
|
+
) : (
|
|
427
|
+
<span className="emvb-shape-swatch" data-shape={shape.value} aria-hidden="true" />
|
|
428
|
+
)}
|
|
429
|
+
</button>
|
|
430
|
+
))}
|
|
431
|
+
</div>
|
|
432
|
+
<p className="emvb-helper">
|
|
433
|
+
Color, padding and border: Background, Spacing and Border below.
|
|
434
|
+
</p>
|
|
435
|
+
</div>
|
|
436
|
+
</div>
|
|
437
|
+
);
|
|
438
|
+
}
|
|
@@ -1,8 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Button } from "@cloudflare/kumo";
|
|
2
2
|
import * as React from "react";
|
|
3
|
-
import {
|
|
3
|
+
import { getBundledIcon, sanitizeSvgMarkup, type LayoutNode } from "../../../../core/index.ts";
|
|
4
4
|
import { serialize, type VNode } from "../../../../core/render/vnode.ts";
|
|
5
|
-
import {
|
|
5
|
+
import type { Fetcher } from "../../../api.ts";
|
|
6
|
+
import { BUTTON } from "../../../ui.ts";
|
|
7
|
+
import { IconLibraryDialog } from "../../icons/IconLibraryDialog.tsx";
|
|
8
|
+
import {
|
|
9
|
+
ICON_SETS,
|
|
10
|
+
locateIcon,
|
|
11
|
+
UPLOADS,
|
|
12
|
+
UPLOADS_CATEGORY,
|
|
13
|
+
type LibraryIcon,
|
|
14
|
+
} from "../../icons/library.ts";
|
|
6
15
|
|
|
7
16
|
const propsOf = (node: LayoutNode): Record<string, unknown> =>
|
|
8
17
|
node.props as Record<string, unknown>;
|
|
@@ -12,98 +21,150 @@ const withProps = (node: LayoutNode, patch: Record<string, unknown>): LayoutNode
|
|
|
12
21
|
return { ...node, props } as LayoutNode;
|
|
13
22
|
};
|
|
14
23
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
if (!icon) return "";
|
|
18
|
-
const children: VNode[] = icon.children.map((child) => ({
|
|
19
|
-
tag: child.tag,
|
|
20
|
-
attrs: { ...child.attrs },
|
|
21
|
-
children: [],
|
|
22
|
-
}));
|
|
23
|
-
return serialize({
|
|
24
|
+
const preview = (tree: VNode): string =>
|
|
25
|
+
serialize({
|
|
24
26
|
tag: "svg",
|
|
25
27
|
attrs: {
|
|
26
|
-
|
|
28
|
+
viewBox: "0 0 24 24",
|
|
29
|
+
...tree.attrs,
|
|
27
30
|
width: "20",
|
|
28
31
|
height: "20",
|
|
29
|
-
|
|
32
|
+
"aria-hidden": "true",
|
|
33
|
+
focusable: "false",
|
|
34
|
+
},
|
|
35
|
+
children: tree.children,
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
/** The 20px preview of the stored icon: its saved SVG, else the bundled glyph. */
|
|
39
|
+
export function currentIconPreview(iconId: string, iconSvg: unknown): string {
|
|
40
|
+
const picked = typeof iconSvg === "string" && iconSvg ? sanitizeSvgMarkup(iconSvg) : undefined;
|
|
41
|
+
if (picked) return preview(picked);
|
|
42
|
+
const bundled = getBundledIcon(iconId);
|
|
43
|
+
if (!bundled) return "";
|
|
44
|
+
return preview({
|
|
45
|
+
tag: "svg",
|
|
46
|
+
attrs: {
|
|
47
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
30
48
|
fill: "none",
|
|
31
49
|
stroke: "currentColor",
|
|
32
50
|
"stroke-width": "2",
|
|
33
51
|
"stroke-linecap": "round",
|
|
34
52
|
"stroke-linejoin": "round",
|
|
35
|
-
"aria-hidden": "true",
|
|
36
53
|
},
|
|
37
|
-
children
|
|
54
|
+
children: bundled.children.map((child) => ({
|
|
55
|
+
tag: child.tag,
|
|
56
|
+
attrs: { ...child.attrs },
|
|
57
|
+
children: [],
|
|
58
|
+
})),
|
|
38
59
|
});
|
|
39
60
|
}
|
|
40
61
|
|
|
41
|
-
/**
|
|
62
|
+
/** "fa-solid:arrow-right" → "Arrow right"; a bundled id gives its own label. */
|
|
63
|
+
export function iconNameLabel(iconId: string): string {
|
|
64
|
+
const bundled = getBundledIcon(iconId);
|
|
65
|
+
if (bundled) return bundled.label;
|
|
66
|
+
const name = iconId.slice(iconId.indexOf(":") + 1).replaceAll("-", " ");
|
|
67
|
+
return name.charAt(0).toUpperCase() + name.slice(1);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** "Font Awesome · Solid" for a stored id, or undefined when the id names no known set. */
|
|
71
|
+
function sourceLabel(iconId: string): string | undefined {
|
|
72
|
+
const at = locateIcon(iconId);
|
|
73
|
+
if (!at) return undefined;
|
|
74
|
+
if (at.set === UPLOADS) return UPLOADS_CATEGORY.label;
|
|
75
|
+
const set = ICON_SETS.find((item) => item.id === at.set);
|
|
76
|
+
if (!set) return undefined;
|
|
77
|
+
const style = set.styles.find((item) => item.id === at.style);
|
|
78
|
+
return style && style.label !== set.label ? `${set.label} · ${style.label}` : set.label;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* The Icon element's icon field (W-025 / W-236): the current icon and a button that opens the
|
|
83
|
+
* icon library. Inserting stores the set-prefixed id (so the library reopens on it) and the
|
|
84
|
+
* icon's SVG (so the published page needs no icon set).
|
|
85
|
+
*/
|
|
42
86
|
export function IconPicker({
|
|
43
87
|
node,
|
|
88
|
+
fetcher,
|
|
44
89
|
onChange,
|
|
45
90
|
}: {
|
|
46
91
|
node: LayoutNode;
|
|
92
|
+
/** Enables My uploads in the library (W-239). */
|
|
93
|
+
fetcher?: Fetcher;
|
|
47
94
|
onChange: (node: LayoutNode) => void;
|
|
48
95
|
}) {
|
|
49
|
-
const
|
|
50
|
-
const
|
|
51
|
-
const
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
96
|
+
const props = propsOf(node);
|
|
97
|
+
const current = typeof props.iconId === "string" ? props.iconId : "";
|
|
98
|
+
const [open, setOpen] = React.useState(false);
|
|
99
|
+
const field = React.useRef<HTMLDivElement | null>(null);
|
|
100
|
+
// However the library closes (Insert, Close, Escape), focus comes back to Choose. Done once the
|
|
101
|
+
// dialog has finished closing: during its exit animation the focus trap still holds focus.
|
|
102
|
+
const refocus = () =>
|
|
103
|
+
field.current?.querySelector<HTMLButtonElement>("[data-emvb-icon-open]")?.focus();
|
|
104
|
+
const markup = currentIconPreview(current, props.iconSvg);
|
|
105
|
+
// An upload's id is random; its title names it (set from the file name on insert).
|
|
106
|
+
const name =
|
|
107
|
+
current && locateIcon(current)?.set === UPLOADS
|
|
108
|
+
? (typeof props.title === "string" && props.title) || UPLOADS_CATEGORY.label
|
|
109
|
+
: current
|
|
110
|
+
? iconNameLabel(current)
|
|
111
|
+
: undefined;
|
|
112
|
+
const source = current ? sourceLabel(current) : undefined;
|
|
113
|
+
|
|
114
|
+
const insert = (icon: LibraryIcon) => {
|
|
115
|
+
const title = typeof props.title === "string" ? props.title : "";
|
|
116
|
+
const previous = name?.toLowerCase();
|
|
117
|
+
const patch: Record<string, unknown> = { iconId: icon.id, iconSvg: icon.markup };
|
|
118
|
+
// Keep the title in step with the glyph while it is still a default or the old icon's name
|
|
119
|
+
// (new Icon elements ship title "Star" with iconId "star"); a written title stays.
|
|
120
|
+
if (!title || title === "Icon" || title.toLowerCase() === previous) patch.title = icon.label;
|
|
121
|
+
onChange(withProps(node, patch));
|
|
122
|
+
};
|
|
55
123
|
|
|
56
124
|
return (
|
|
57
|
-
<div className="emvb-field-group" data-emvb-field="iconId" data-emvb-icon-picker="">
|
|
58
|
-
<
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
125
|
+
<div ref={field} className="emvb-field-group" data-emvb-field="iconId" data-emvb-icon-picker="">
|
|
126
|
+
<span className="emvb-field-label">Icon</span>
|
|
127
|
+
<div className="emvb-icon-current" data-emvb-icon-current={current}>
|
|
128
|
+
<button
|
|
129
|
+
type="button"
|
|
130
|
+
className="emvb-icon-current-preview"
|
|
131
|
+
aria-label={`Change icon (now ${name ?? "none"})`}
|
|
132
|
+
onClick={() => setOpen(true)}
|
|
133
|
+
>
|
|
134
|
+
{markup ? (
|
|
135
|
+
<span aria-hidden="true" dangerouslySetInnerHTML={{ __html: markup }} />
|
|
136
|
+
) : (
|
|
137
|
+
<span aria-hidden="true">?</span>
|
|
138
|
+
)}
|
|
139
|
+
</button>
|
|
140
|
+
<span className="emvb-icon-current-text">
|
|
141
|
+
<strong>{name ?? "No icon"}</strong>
|
|
142
|
+
<span>
|
|
143
|
+
{markup
|
|
144
|
+
? (source ?? "Saved SVG")
|
|
145
|
+
: current
|
|
146
|
+
? "Not found — choose another"
|
|
147
|
+
: "Choose one"}
|
|
148
|
+
</span>
|
|
149
|
+
</span>
|
|
150
|
+
<Button
|
|
151
|
+
variant="secondary"
|
|
152
|
+
size="sm"
|
|
153
|
+
className={BUTTON}
|
|
154
|
+
data-emvb-icon-open=""
|
|
155
|
+
onClick={() => setOpen(true)}
|
|
156
|
+
>
|
|
157
|
+
Choose…
|
|
158
|
+
</Button>
|
|
159
|
+
</div>
|
|
160
|
+
<IconLibraryDialog
|
|
161
|
+
open={open}
|
|
162
|
+
onOpenChange={setOpen}
|
|
163
|
+
onClosed={refocus}
|
|
164
|
+
currentId={current || undefined}
|
|
165
|
+
fetcher={fetcher}
|
|
166
|
+
onInsert={insert}
|
|
64
167
|
/>
|
|
65
|
-
{matched.length === 0 ? (
|
|
66
|
-
<p className="emvb-helper">No icons match "{query.trim()}".</p>
|
|
67
|
-
) : (
|
|
68
|
-
<ul className="emvb-icon-grid" role="listbox" aria-label="Icons">
|
|
69
|
-
{matched.map((icon) => {
|
|
70
|
-
const selected = icon.id === current;
|
|
71
|
-
return (
|
|
72
|
-
<li key={icon.id}>
|
|
73
|
-
<button
|
|
74
|
-
type="button"
|
|
75
|
-
role="option"
|
|
76
|
-
aria-selected={selected}
|
|
77
|
-
className="emvb-icon-tile"
|
|
78
|
-
data-emvb-icon-id={icon.id}
|
|
79
|
-
data-selected={selected ? "true" : undefined}
|
|
80
|
-
onClick={() => {
|
|
81
|
-
const title = propsOf(node).title;
|
|
82
|
-
const previous = getBundledIcon(current)?.label;
|
|
83
|
-
const patch: Record<string, unknown> = { iconId: icon.id };
|
|
84
|
-
// Keep title in sync with the glyph when it still matches the prior
|
|
85
|
-
// default/label (defaults ship title "Star" with iconId "star").
|
|
86
|
-
if (
|
|
87
|
-
!title ||
|
|
88
|
-
title === "Icon" ||
|
|
89
|
-
(previous !== undefined && title === previous)
|
|
90
|
-
) {
|
|
91
|
-
patch.title = icon.label;
|
|
92
|
-
}
|
|
93
|
-
onChange(withProps(node, patch));
|
|
94
|
-
}}
|
|
95
|
-
>
|
|
96
|
-
<span
|
|
97
|
-
className="emvb-icon-preview"
|
|
98
|
-
dangerouslySetInnerHTML={{ __html: previewSvg(icon.id) }}
|
|
99
|
-
/>
|
|
100
|
-
<span>{icon.label}</span>
|
|
101
|
-
</button>
|
|
102
|
-
</li>
|
|
103
|
-
);
|
|
104
|
-
})}
|
|
105
|
-
</ul>
|
|
106
|
-
)}
|
|
107
168
|
</div>
|
|
108
169
|
);
|
|
109
170
|
}
|