@perkyzz/emvb 0.1.0 → 0.2.1
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 +6 -4
- 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 +9 -5
- 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 +25 -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 +168 -24
- package/src/astro/tabs/runtime.ts +6 -1
- package/src/astro/theme-context.ts +25 -5
- package/src/astro/theme-posts.ts +19 -1
- 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
|
@@ -3,8 +3,9 @@ import { isSafeFontStack, type DesignSystem, type StyleProps } from "../../../..
|
|
|
3
3
|
import type { Fetcher } from "../../../api.ts";
|
|
4
4
|
import { FIELD } from "../../../ui.ts";
|
|
5
5
|
import { ColorControl } from "../ColorControl.tsx";
|
|
6
|
-
import {
|
|
6
|
+
import { BackgroundFill } from "./BackgroundFill.tsx";
|
|
7
7
|
import { STYLE_LABELS, type StyleKey } from "./style-sections.ts";
|
|
8
|
+
import { ChoiceGroup, LAYOUT_CHOICES } from "./ChoiceGroup.tsx";
|
|
8
9
|
import { LengthRow } from "./LengthRow.tsx";
|
|
9
10
|
import {
|
|
10
11
|
EntranceControl,
|
|
@@ -12,6 +13,14 @@ import {
|
|
|
12
13
|
ShadowControl,
|
|
13
14
|
TransitionControl,
|
|
14
15
|
} from "./EffectsControls.tsx";
|
|
16
|
+
import {
|
|
17
|
+
ICON_SCALE,
|
|
18
|
+
ICON_STROKE,
|
|
19
|
+
IconAnimationControl,
|
|
20
|
+
IconFlipRow,
|
|
21
|
+
IconRotateRow,
|
|
22
|
+
IconShadowControl,
|
|
23
|
+
} from "./IconControls.tsx";
|
|
15
24
|
import { NumberRow, ResetButton, type NumberSpec } from "./NumberRow.tsx";
|
|
16
25
|
import { boundRef, VariableButton, VariableChip } from "./VariableBinding.tsx";
|
|
17
26
|
|
|
@@ -39,7 +48,15 @@ const LENGTH_KEYS = new Set<StyleKey>([
|
|
|
39
48
|
"lineHeight",
|
|
40
49
|
"letterSpacing",
|
|
41
50
|
"borderWidth",
|
|
51
|
+
"borderTopWidth",
|
|
52
|
+
"borderRightWidth",
|
|
53
|
+
"borderBottomWidth",
|
|
54
|
+
"borderLeftWidth",
|
|
42
55
|
"borderRadius",
|
|
56
|
+
"borderTopLeftRadius",
|
|
57
|
+
"borderTopRightRadius",
|
|
58
|
+
"borderBottomRightRadius",
|
|
59
|
+
"borderBottomLeftRadius",
|
|
43
60
|
]);
|
|
44
61
|
|
|
45
62
|
const Z_INDEX: NumberSpec = { min: -9999, max: 9999, integer: true, example: "10" };
|
|
@@ -49,32 +66,6 @@ const OPACITY: NumberSpec = { min: 0, max: 100, scale: 100, example: "50", suffi
|
|
|
49
66
|
const COLOR_KEYS = new Set<StyleKey>(["color", "backgroundColor", "borderColor"]);
|
|
50
67
|
|
|
51
68
|
const SELECT_OPTIONS: Partial<Record<StyleKey, { value: string; label: string }[]>> = {
|
|
52
|
-
flexDirection: [
|
|
53
|
-
{ value: "column", label: "Column" },
|
|
54
|
-
{ value: "row", label: "Row" },
|
|
55
|
-
{ value: "column-reverse", label: "Column reverse" },
|
|
56
|
-
{ value: "row-reverse", label: "Row reverse" },
|
|
57
|
-
],
|
|
58
|
-
flexWrap: [
|
|
59
|
-
{ value: "nowrap", label: "No wrap" },
|
|
60
|
-
{ value: "wrap", label: "Wrap" },
|
|
61
|
-
{ value: "wrap-reverse", label: "Wrap reverse" },
|
|
62
|
-
],
|
|
63
|
-
justifyContent: [
|
|
64
|
-
{ value: "flex-start", label: "Start" },
|
|
65
|
-
{ value: "center", label: "Center" },
|
|
66
|
-
{ value: "flex-end", label: "End" },
|
|
67
|
-
{ value: "space-between", label: "Space between" },
|
|
68
|
-
{ value: "space-around", label: "Space around" },
|
|
69
|
-
{ value: "space-evenly", label: "Space evenly" },
|
|
70
|
-
],
|
|
71
|
-
alignItems: [
|
|
72
|
-
{ value: "stretch", label: "Stretch" },
|
|
73
|
-
{ value: "flex-start", label: "Start" },
|
|
74
|
-
{ value: "center", label: "Center" },
|
|
75
|
-
{ value: "flex-end", label: "End" },
|
|
76
|
-
{ value: "baseline", label: "Baseline" },
|
|
77
|
-
],
|
|
78
69
|
textAlign: [
|
|
79
70
|
{ value: "left", label: "Left" },
|
|
80
71
|
{ value: "center", label: "Center" },
|
|
@@ -160,11 +151,17 @@ const SELECT_OPTIONS: Partial<Record<StyleKey, { value: string; label: string }[
|
|
|
160
151
|
{ value: "repeat-x", label: "Repeat horizontally" },
|
|
161
152
|
{ value: "repeat-y", label: "Repeat vertically" },
|
|
162
153
|
],
|
|
154
|
+
// W-213: the full CSS weight range.
|
|
163
155
|
fontWeight: [
|
|
164
156
|
{ value: "400", label: "Regular" },
|
|
157
|
+
{ value: "100", label: "Thin" },
|
|
158
|
+
{ value: "200", label: "Extra light" },
|
|
159
|
+
{ value: "300", label: "Light" },
|
|
165
160
|
{ value: "500", label: "Medium" },
|
|
166
161
|
{ value: "600", label: "Semibold" },
|
|
167
162
|
{ value: "700", label: "Bold" },
|
|
163
|
+
{ value: "800", label: "Extra bold" },
|
|
164
|
+
{ value: "900", label: "Black" },
|
|
168
165
|
],
|
|
169
166
|
};
|
|
170
167
|
|
|
@@ -172,7 +169,7 @@ const isLengthLiteral = (value: unknown): value is { value: number; unit: string
|
|
|
172
169
|
typeof value === "object" && value !== null && "value" in value && "unit" in value;
|
|
173
170
|
|
|
174
171
|
/** A value as placeholder text: a literal, a keyword, or the variable's name (W-089). */
|
|
175
|
-
function placeholderOf(value: unknown, design: DesignSystem): string | undefined {
|
|
172
|
+
export function placeholderOf(value: unknown, design: DesignSystem): string | undefined {
|
|
176
173
|
if (typeof value === "string" || typeof value === "number") return String(value);
|
|
177
174
|
if (isLengthLiteral(value)) return `${value.value}${value.unit}`;
|
|
178
175
|
if (typeof value === "object" && value !== null && "var" in value) {
|
|
@@ -186,12 +183,24 @@ function placeholderOf(value: unknown, design: DesignSystem): string | undefined
|
|
|
186
183
|
}
|
|
187
184
|
|
|
188
185
|
/** One Style property row: control, set marker, reset (W-021). */
|
|
186
|
+
const FILL_REST = new Set<StyleKey>([
|
|
187
|
+
"backgroundImage",
|
|
188
|
+
"backgroundSize",
|
|
189
|
+
"backgroundPosition",
|
|
190
|
+
"backgroundRepeat",
|
|
191
|
+
"gradient",
|
|
192
|
+
"overlay",
|
|
193
|
+
"backgroundVideo",
|
|
194
|
+
]);
|
|
195
|
+
|
|
189
196
|
export function StyleRow({
|
|
190
197
|
styleKey,
|
|
191
198
|
style,
|
|
192
199
|
inherited,
|
|
193
200
|
design,
|
|
194
201
|
fetcher,
|
|
202
|
+
elementType = "container",
|
|
203
|
+
fillScope,
|
|
195
204
|
onPatch,
|
|
196
205
|
onDesignChange,
|
|
197
206
|
}: {
|
|
@@ -202,6 +211,10 @@ export function StyleRow({
|
|
|
202
211
|
design: DesignSystem;
|
|
203
212
|
/** Present on an element, so a background image can use the media library. */
|
|
204
213
|
fetcher?: Fetcher;
|
|
214
|
+
/** Decides whether Image and Video are offered. A class editor passes a box. */
|
|
215
|
+
elementType?: string;
|
|
216
|
+
/** Which class and device the background fill memory belongs to (W-184). */
|
|
217
|
+
fillScope?: string;
|
|
205
218
|
onPatch: (patch: Partial<StyleProps>) => void;
|
|
206
219
|
onDesignChange: (design: DesignSystem) => Promise<void>;
|
|
207
220
|
}) {
|
|
@@ -216,59 +229,48 @@ export function StyleRow({
|
|
|
216
229
|
<ResetButton label={label} set={set} onReset={() => onPatch({ [styleKey]: undefined })} />
|
|
217
230
|
);
|
|
218
231
|
|
|
219
|
-
if (styleKey === "
|
|
220
|
-
return (
|
|
221
|
-
<BackgroundImageControl
|
|
222
|
-
value={typeof value === "string" ? value : undefined}
|
|
223
|
-
fetcher={fetcher}
|
|
224
|
-
onChange={(next) => onPatch({ backgroundImage: next })}
|
|
225
|
-
reset={reset}
|
|
226
|
-
/>
|
|
227
|
-
);
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
if (styleKey === "backgroundVideo") {
|
|
231
|
-
const video = typeof value === "string" ? value : "";
|
|
232
|
-
return (
|
|
233
|
-
<div className="emvb-style-row" data-emvb-style="backgroundVideo" data-set={set || undefined}>
|
|
234
|
-
<Input
|
|
235
|
-
label="Background video"
|
|
236
|
-
className={FIELD}
|
|
237
|
-
value={video}
|
|
238
|
-
placeholder="https:// or /path"
|
|
239
|
-
onChange={(event) => {
|
|
240
|
-
const next = event.target.value.trim();
|
|
241
|
-
onPatch({ backgroundVideo: next === "" ? undefined : next });
|
|
242
|
-
}}
|
|
243
|
-
/>
|
|
244
|
-
{reset}
|
|
245
|
-
</div>
|
|
246
|
-
);
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
if (styleKey === "gradient") {
|
|
232
|
+
if (styleKey === "backgroundColor") {
|
|
250
233
|
return (
|
|
251
|
-
<
|
|
252
|
-
|
|
234
|
+
<BackgroundFill
|
|
235
|
+
style={style}
|
|
236
|
+
elementType={elementType}
|
|
253
237
|
design={design}
|
|
254
|
-
|
|
238
|
+
fetcher={fetcher}
|
|
239
|
+
sizeOptions={SELECT_OPTIONS.backgroundSize ?? []}
|
|
240
|
+
positionOptions={SELECT_OPTIONS.backgroundPosition ?? []}
|
|
241
|
+
repeatOptions={SELECT_OPTIONS.backgroundRepeat ?? []}
|
|
242
|
+
onPatch={onPatch}
|
|
255
243
|
onDesignChange={onDesignChange}
|
|
256
|
-
|
|
244
|
+
memoryScope={fillScope}
|
|
245
|
+
reset={
|
|
246
|
+
<ResetButton
|
|
247
|
+
label="Background"
|
|
248
|
+
set={
|
|
249
|
+
style?.backgroundColor !== undefined ||
|
|
250
|
+
style?.gradient !== undefined ||
|
|
251
|
+
style?.backgroundImage !== undefined ||
|
|
252
|
+
style?.backgroundVideo !== undefined ||
|
|
253
|
+
style?.overlay !== undefined
|
|
254
|
+
}
|
|
255
|
+
onReset={() =>
|
|
256
|
+
onPatch({
|
|
257
|
+
backgroundColor: undefined,
|
|
258
|
+
backgroundImage: undefined,
|
|
259
|
+
backgroundSize: undefined,
|
|
260
|
+
backgroundPosition: undefined,
|
|
261
|
+
backgroundRepeat: undefined,
|
|
262
|
+
gradient: undefined,
|
|
263
|
+
overlay: undefined,
|
|
264
|
+
backgroundVideo: undefined,
|
|
265
|
+
})
|
|
266
|
+
}
|
|
267
|
+
/>
|
|
268
|
+
}
|
|
257
269
|
/>
|
|
258
270
|
);
|
|
259
271
|
}
|
|
260
272
|
|
|
261
|
-
if (styleKey
|
|
262
|
-
return (
|
|
263
|
-
<OverlayControl
|
|
264
|
-
value={style?.overlay}
|
|
265
|
-
design={design}
|
|
266
|
-
onChange={(next) => onPatch({ overlay: next })}
|
|
267
|
-
onDesignChange={onDesignChange}
|
|
268
|
-
reset={reset}
|
|
269
|
-
/>
|
|
270
|
-
);
|
|
271
|
-
}
|
|
273
|
+
if (FILL_REST.has(styleKey)) return null;
|
|
272
274
|
|
|
273
275
|
if (COLOR_KEYS.has(styleKey)) {
|
|
274
276
|
return (
|
|
@@ -291,6 +293,26 @@ export function StyleRow({
|
|
|
291
293
|
);
|
|
292
294
|
}
|
|
293
295
|
|
|
296
|
+
const choices = LAYOUT_CHOICES[styleKey];
|
|
297
|
+
if (choices) {
|
|
298
|
+
return (
|
|
299
|
+
<div
|
|
300
|
+
className="emvb-style-row"
|
|
301
|
+
data-emvb-style={styleKey}
|
|
302
|
+
data-set={set ? "true" : undefined}
|
|
303
|
+
data-inherited={inheriting}
|
|
304
|
+
>
|
|
305
|
+
<ChoiceGroup
|
|
306
|
+
label={label}
|
|
307
|
+
value={typeof value === "string" ? value : undefined}
|
|
308
|
+
options={choices}
|
|
309
|
+
onChange={(next) => onPatch({ [styleKey]: next })}
|
|
310
|
+
/>
|
|
311
|
+
{reset}
|
|
312
|
+
</div>
|
|
313
|
+
);
|
|
314
|
+
}
|
|
315
|
+
|
|
294
316
|
const options = SELECT_OPTIONS[styleKey];
|
|
295
317
|
if (options) {
|
|
296
318
|
const shown = value ?? normalValue;
|
|
@@ -313,7 +335,9 @@ export function StyleRow({
|
|
|
313
335
|
if (styleKey === "fontWeight") {
|
|
314
336
|
const n = Number(next);
|
|
315
337
|
onPatch({
|
|
316
|
-
fontWeight: Number.isFinite(n)
|
|
338
|
+
fontWeight: Number.isFinite(n)
|
|
339
|
+
? (n as NonNullable<StyleProps["fontWeight"]>)
|
|
340
|
+
: undefined,
|
|
317
341
|
});
|
|
318
342
|
return;
|
|
319
343
|
}
|
|
@@ -400,6 +424,57 @@ export function StyleRow({
|
|
|
400
424
|
);
|
|
401
425
|
}
|
|
402
426
|
|
|
427
|
+
// W-237: the Icon section.
|
|
428
|
+
if (styleKey === "iconRotate") {
|
|
429
|
+
return (
|
|
430
|
+
<IconRotateRow
|
|
431
|
+
value={style?.iconRotate}
|
|
432
|
+
inherited={inherited?.iconRotate}
|
|
433
|
+
onChange={(iconRotate) => onPatch({ iconRotate })}
|
|
434
|
+
/>
|
|
435
|
+
);
|
|
436
|
+
}
|
|
437
|
+
if (styleKey === "iconFlip") {
|
|
438
|
+
return (
|
|
439
|
+
<IconFlipRow
|
|
440
|
+
value={style?.iconFlip}
|
|
441
|
+
inherited={inherited?.iconFlip}
|
|
442
|
+
onChange={(iconFlip) => onPatch({ iconFlip })}
|
|
443
|
+
/>
|
|
444
|
+
);
|
|
445
|
+
}
|
|
446
|
+
if (styleKey === "iconScale" || styleKey === "iconStrokeWidth") {
|
|
447
|
+
return (
|
|
448
|
+
<NumberRow
|
|
449
|
+
rowKey={styleKey}
|
|
450
|
+
label={label}
|
|
451
|
+
value={typeof value === "number" ? value : undefined}
|
|
452
|
+
inherited={typeof normalValue === "number" ? normalValue : undefined}
|
|
453
|
+
spec={styleKey === "iconScale" ? ICON_SCALE : ICON_STROKE}
|
|
454
|
+
onCommit={(next) => onPatch({ [styleKey]: next })}
|
|
455
|
+
/>
|
|
456
|
+
);
|
|
457
|
+
}
|
|
458
|
+
if (styleKey === "iconShadow") {
|
|
459
|
+
return (
|
|
460
|
+
<IconShadowControl
|
|
461
|
+
value={style?.iconShadow}
|
|
462
|
+
design={design}
|
|
463
|
+
onChange={(iconShadow) => onPatch({ iconShadow })}
|
|
464
|
+
onDesignChange={onDesignChange}
|
|
465
|
+
/>
|
|
466
|
+
);
|
|
467
|
+
}
|
|
468
|
+
if (styleKey === "iconAnimation") {
|
|
469
|
+
return (
|
|
470
|
+
<IconAnimationControl
|
|
471
|
+
value={style?.iconAnimation}
|
|
472
|
+
inherited={inherited?.iconAnimation}
|
|
473
|
+
onChange={(iconAnimation) => onPatch({ iconAnimation })}
|
|
474
|
+
/>
|
|
475
|
+
);
|
|
476
|
+
}
|
|
477
|
+
|
|
403
478
|
if (styleKey === "boxShadow") {
|
|
404
479
|
return (
|
|
405
480
|
<ShadowControl
|
|
@@ -451,6 +526,7 @@ export function StyleRow({
|
|
|
451
526
|
design={design}
|
|
452
527
|
set={set}
|
|
453
528
|
placeholder={placeholder}
|
|
529
|
+
slider={styleKey === "gap"}
|
|
454
530
|
onPatch={onPatch}
|
|
455
531
|
reset={reset}
|
|
456
532
|
/>
|
|
@@ -472,9 +548,16 @@ export const IMPLEMENTED_STYLE_KEYS: StyleKey[] = [
|
|
|
472
548
|
"filter",
|
|
473
549
|
"entrance",
|
|
474
550
|
"transition",
|
|
551
|
+
"iconRotate",
|
|
552
|
+
"iconFlip",
|
|
553
|
+
"iconScale",
|
|
554
|
+
"iconStrokeWidth",
|
|
555
|
+
"iconShadow",
|
|
556
|
+
"iconAnimation",
|
|
475
557
|
"backgroundImage",
|
|
476
558
|
"backgroundVideo",
|
|
477
559
|
"gradient",
|
|
478
560
|
"overlay",
|
|
479
561
|
...(Object.keys(SELECT_OPTIONS) as StyleKey[]),
|
|
562
|
+
...(Object.keys(LAYOUT_CHOICES) as StyleKey[]),
|
|
480
563
|
];
|
|
@@ -21,6 +21,10 @@ const SPACING_KEYS = new Set<StyleKey>([
|
|
|
21
21
|
"bottom",
|
|
22
22
|
"left",
|
|
23
23
|
"borderRadius",
|
|
24
|
+
"borderTopLeftRadius",
|
|
25
|
+
"borderTopRightRadius",
|
|
26
|
+
"borderBottomRightRadius",
|
|
27
|
+
"borderBottomLeftRadius",
|
|
24
28
|
]);
|
|
25
29
|
|
|
26
30
|
/** The variable kind a style property takes, or null when it has no variable button. */
|
|
@@ -122,7 +126,7 @@ export function VariableButton({
|
|
|
122
126
|
}
|
|
123
127
|
|
|
124
128
|
/**
|
|
125
|
-
* The variable chip that stands in for a bound value
|
|
129
|
+
* The variable chip that stands in for a bound value: the kind icon, the variable's
|
|
126
130
|
* name and an × that detaches it, keeping the variable's current value as a literal.
|
|
127
131
|
*/
|
|
128
132
|
export function VariableChip({
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { Layout, LayoutNode } from "../../../../core/index.ts";
|
|
2
|
+
import { isReservedAttribute } from "../../../../core/render/extras.ts";
|
|
3
|
+
import { nodeChildren } from "../../../../core/tree-ops.ts";
|
|
4
|
+
|
|
5
|
+
/** Same rules as the layout schema and the renderer (W-105, R-032), checked while typing (W-189). */
|
|
6
|
+
const HTML_ID = /^[A-Za-z][A-Za-z0-9_-]{0,63}$/;
|
|
7
|
+
const ATTR_NAME = /^(?:data|aria)-[a-z][a-z0-9-]{0,40}$/;
|
|
8
|
+
export const MAX_ATTR_VALUE = 200;
|
|
9
|
+
|
|
10
|
+
export type AttributeRow = { name: string; value: string };
|
|
11
|
+
|
|
12
|
+
/** CSS ids on `layout` other than the one on `exceptId`. */
|
|
13
|
+
function otherHtmlIds(layout: Layout | null, exceptId: string): Set<string> {
|
|
14
|
+
const ids = new Set<string>();
|
|
15
|
+
const walk = (node: LayoutNode) => {
|
|
16
|
+
if (node.id !== exceptId && node.htmlId) ids.add(node.htmlId);
|
|
17
|
+
for (const child of nodeChildren(node)) walk(child);
|
|
18
|
+
};
|
|
19
|
+
if (layout) walk(layout.root);
|
|
20
|
+
return ids;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Why a CSS id can't be saved, or null when it can (empty clears it). */
|
|
24
|
+
export function htmlIdError(value: string, layout: Layout | null, nodeId: string): string | null {
|
|
25
|
+
if (value === "") return null;
|
|
26
|
+
if (!HTML_ID.test(value)) {
|
|
27
|
+
return "Start with a letter; use letters, digits, - and _ only (up to 64).";
|
|
28
|
+
}
|
|
29
|
+
if (otherHtmlIds(layout, nodeId).has(value)) return "Another element already uses this CSS id.";
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** A just-added row nobody has typed in yet: not saved, and not flagged. */
|
|
34
|
+
const isFreshRow = (row: AttributeRow) => row.name === "data-" && row.value === "";
|
|
35
|
+
|
|
36
|
+
/** Each row's error (null when it can be saved), in row order. */
|
|
37
|
+
export function attributeErrors(rows: readonly AttributeRow[]): (string | null)[] {
|
|
38
|
+
const seen = new Set<string>();
|
|
39
|
+
return rows.map((row) => {
|
|
40
|
+
if (isFreshRow(row)) return null;
|
|
41
|
+
let error: string | null = null;
|
|
42
|
+
if (!ATTR_NAME.test(row.name)) {
|
|
43
|
+
error = "Use data-* or aria-*, then a lowercase letter, digits or -.";
|
|
44
|
+
} else if (isReservedAttribute(row.name)) {
|
|
45
|
+
error = "This name is reserved for the editor or forms.";
|
|
46
|
+
} else if (seen.has(row.name)) {
|
|
47
|
+
error = "This name is already used on this element.";
|
|
48
|
+
} else if (row.value.length > MAX_ATTR_VALUE) {
|
|
49
|
+
error = `Values are at most ${MAX_ATTR_VALUE} characters.`;
|
|
50
|
+
} else if ([...row.value].some((char) => char.charCodeAt(0) < 32)) {
|
|
51
|
+
error = "Values can't hold line breaks or control characters.";
|
|
52
|
+
}
|
|
53
|
+
seen.add(row.name);
|
|
54
|
+
return error;
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** The rows that may be stored: never one the schema would refuse, so the page stays savable. */
|
|
59
|
+
export function savableAttributes(rows: readonly AttributeRow[]): AttributeRow[] | undefined {
|
|
60
|
+
const errors = attributeErrors(rows);
|
|
61
|
+
const kept = rows.filter((row, i) => !isFreshRow(row) && errors[i] === null);
|
|
62
|
+
return kept.length > 0 ? kept : undefined;
|
|
63
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import type { StyleProps } from "../../../../core/index.ts";
|
|
2
|
+
import { STYLE_UI } from "./style-sections.ts";
|
|
3
|
+
import { NEW_GRADIENT } from "./BackgroundControls.tsx";
|
|
4
|
+
|
|
5
|
+
export type FillMode = "color" | "gradient" | "image" | "video";
|
|
6
|
+
|
|
7
|
+
const BOXES = new Set([
|
|
8
|
+
"container",
|
|
9
|
+
"flexbox",
|
|
10
|
+
"grid",
|
|
11
|
+
"div-block",
|
|
12
|
+
"layout-section",
|
|
13
|
+
"form",
|
|
14
|
+
"section",
|
|
15
|
+
"tab-panel",
|
|
16
|
+
"accordion",
|
|
17
|
+
"accordion-item",
|
|
18
|
+
]);
|
|
19
|
+
|
|
20
|
+
/** Color and gradient everywhere. Image and video on boxes, or when already set. */
|
|
21
|
+
export function fillModes(type: string, style?: StyleProps): FillMode[] {
|
|
22
|
+
const modes: FillMode[] = ["color", "gradient"];
|
|
23
|
+
const box = BOXES.has(type) || !(type in STYLE_UI);
|
|
24
|
+
if (box || type === "button" || type === "submit" || style?.backgroundImage !== undefined)
|
|
25
|
+
modes.push("image");
|
|
26
|
+
if (box || style?.backgroundVideo !== undefined) modes.push("video");
|
|
27
|
+
return modes;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** The fill the page is showing. Video wins, then image, then gradient, then a solid color. */
|
|
31
|
+
export function activeFill(style: StyleProps | undefined): FillMode {
|
|
32
|
+
if (style?.backgroundVideo) return "video";
|
|
33
|
+
if (style?.backgroundImage) return "image";
|
|
34
|
+
if (style?.gradient) return "gradient";
|
|
35
|
+
return "color";
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** More than one fill is stored, so the page paints a stack the type switcher will collapse. */
|
|
39
|
+
export function fillIsMixed(style: StyleProps | undefined): boolean {
|
|
40
|
+
return (
|
|
41
|
+
[
|
|
42
|
+
style?.backgroundColor !== undefined,
|
|
43
|
+
style?.gradient !== undefined,
|
|
44
|
+
style?.backgroundImage !== undefined,
|
|
45
|
+
style?.backgroundVideo !== undefined,
|
|
46
|
+
].filter(Boolean).length > 1
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const CLEARED = {
|
|
51
|
+
backgroundColor: undefined,
|
|
52
|
+
backgroundImage: undefined,
|
|
53
|
+
backgroundSize: undefined,
|
|
54
|
+
backgroundPosition: undefined,
|
|
55
|
+
backgroundRepeat: undefined,
|
|
56
|
+
gradient: undefined,
|
|
57
|
+
overlay: undefined,
|
|
58
|
+
backgroundVideo: undefined,
|
|
59
|
+
} as const;
|
|
60
|
+
|
|
61
|
+
/** Choosing a type removes the other fills. Overlay stays with an image or a video. */
|
|
62
|
+
function switchFill(style: StyleProps | undefined, mode: FillMode): Partial<StyleProps> {
|
|
63
|
+
if (mode === "gradient") return { ...CLEARED, gradient: style?.gradient ?? NEW_GRADIENT };
|
|
64
|
+
if (mode === "image") {
|
|
65
|
+
return {
|
|
66
|
+
...CLEARED,
|
|
67
|
+
backgroundImage: style?.backgroundImage,
|
|
68
|
+
backgroundSize: style?.backgroundSize,
|
|
69
|
+
backgroundPosition: style?.backgroundPosition,
|
|
70
|
+
backgroundRepeat: style?.backgroundRepeat,
|
|
71
|
+
overlay: style?.overlay,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
if (mode === "video") {
|
|
75
|
+
return { ...CLEARED, backgroundVideo: style?.backgroundVideo, overlay: style?.overlay };
|
|
76
|
+
}
|
|
77
|
+
return { ...CLEARED, backgroundColor: style?.backgroundColor };
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** The fields a fill type owns as stored now, or undefined when that type has nothing set. */
|
|
81
|
+
function heldFill(style: StyleProps | undefined, mode: FillMode): Partial<StyleProps> | undefined {
|
|
82
|
+
const main = {
|
|
83
|
+
color: style?.backgroundColor,
|
|
84
|
+
gradient: style?.gradient,
|
|
85
|
+
image: style?.backgroundImage,
|
|
86
|
+
video: style?.backgroundVideo,
|
|
87
|
+
}[mode];
|
|
88
|
+
if (main === undefined) return undefined;
|
|
89
|
+
return Object.fromEntries(
|
|
90
|
+
Object.entries(switchFill(style, mode)).filter(([, value]) => value !== undefined),
|
|
91
|
+
) as Partial<StyleProps>;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** What each fill type last held while this element was being edited (W-184). */
|
|
95
|
+
export type FillMemory = Partial<Record<FillMode, Partial<StyleProps>>>;
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Like `switchFill`, but the type being left is remembered in `memory`, and an empty type being
|
|
99
|
+
* chosen gets back what it last held, so Gradient → Color → Gradient keeps the gradient (W-184).
|
|
100
|
+
*/
|
|
101
|
+
export function switchFillRemembered(
|
|
102
|
+
style: StyleProps | undefined,
|
|
103
|
+
from: FillMode,
|
|
104
|
+
to: FillMode,
|
|
105
|
+
memory: FillMemory,
|
|
106
|
+
): Partial<StyleProps> {
|
|
107
|
+
const held = heldFill(style, from);
|
|
108
|
+
if (held) memory[from] = held;
|
|
109
|
+
const remembered = memory[to];
|
|
110
|
+
if (remembered && heldFill(style, to) === undefined) return { ...CLEARED, ...remembered };
|
|
111
|
+
return switchFill(style, to);
|
|
112
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { sanitizeHref, type LayoutNode } from "../../../../core/index.ts";
|
|
2
|
+
import { nodeChildren } from "../../../../core/tree-ops.ts";
|
|
3
|
+
|
|
4
|
+
/** Props whose text names a link for screen readers when the element sits inside it. */
|
|
5
|
+
const TEXT_PROPS = ["text", "label", "summary", "title", "alt"] as const;
|
|
6
|
+
|
|
7
|
+
/** Elements whose text comes from the post or another layout; assume they name the link. */
|
|
8
|
+
const DYNAMIC = new Set(["section", "loop"]);
|
|
9
|
+
|
|
10
|
+
const hasName = (node: LayoutNode): boolean => {
|
|
11
|
+
if (DYNAMIC.has(node.type) || node.type.startsWith("post-")) return true;
|
|
12
|
+
const attrs = (node as { attributes?: { name: string; value: string }[] }).attributes ?? [];
|
|
13
|
+
if (
|
|
14
|
+
attrs.some((a) => (a.name === "aria-label" || a.name === "aria-labelledby") && a.value.trim())
|
|
15
|
+
) {
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
const props = (node.props ?? {}) as Record<string, unknown>;
|
|
19
|
+
if (TEXT_PROPS.some((key) => typeof props[key] === "string" && props[key].trim() !== "")) {
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
return nodeChildren(node).some(hasName);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* W-261: a box (Container, Div Block, Flexbox, Grid…) with a working Link but nothing inside that
|
|
27
|
+
* names it: no text, no image alt, no icon title, no aria-label. It renders as an `<a>` that
|
|
28
|
+
* screen readers announce only as "link" (axe `link-name`).
|
|
29
|
+
*/
|
|
30
|
+
export function unnamedBoxLink(node: LayoutNode): boolean {
|
|
31
|
+
const href = (node.props as { href?: unknown } | undefined)?.href;
|
|
32
|
+
if (typeof href !== "string" || !href.trim() || !sanitizeHref(href)) return false;
|
|
33
|
+
if (!("children" in node)) return false;
|
|
34
|
+
return !hasName(node);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export const UNNAMED_BOX_LINK_NOTE =
|
|
38
|
+
"Nothing inside this box has text, so screen readers announce it only as “link”. Add text inside it, or an aria-label under Custom attributes.";
|