@perkyzz/emvb 0.3.0 → 0.4.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 +1 -1
- package/package.json +3 -1
- package/src/admin/access/role.ts +9 -3
- package/src/admin/api.ts +17 -7
- package/src/admin/content-api.ts +7 -51
- package/src/admin/content-item.ts +22 -0
- package/src/admin/design-api.ts +30 -0
- package/src/admin/editor/A11yCopilot.tsx +1 -1
- package/src/admin/editor/Editor.tsx +106 -332
- package/src/admin/editor/EditorOverlay.tsx +3 -1
- package/src/admin/editor/PerfMeter.tsx +1 -1
- package/src/admin/editor/ShortcutsDialog.tsx +4 -1
- package/src/admin/editor/Timeline.tsx +16 -3
- package/src/admin/editor/canvas/CanvasFrame.tsx +51 -368
- package/src/admin/editor/canvas/DeviceBar.tsx +4 -1
- package/src/admin/editor/canvas/SelectionOverlay.tsx +86 -46
- package/src/admin/editor/canvas/canvas-scale.ts +20 -0
- package/src/admin/editor/canvas/drop-line.ts +24 -0
- package/src/admin/editor/canvas/use-canvas-dnd.ts +207 -0
- package/src/admin/editor/canvas/use-canvas-session.ts +216 -0
- package/src/admin/editor/collection-previews.ts +28 -5
- package/src/admin/editor/editor-chrome.tsx +346 -0
- package/src/admin/editor/editor-commands.ts +360 -0
- package/src/admin/editor/element-chrome.ts +89 -0
- package/src/admin/editor/feature-css.ts +15 -15
- package/src/admin/editor/host.ts +33 -0
- package/src/admin/editor/icons/IconLibraryDialog.tsx +64 -218
- package/src/admin/editor/icons/library.ts +29 -19
- package/src/admin/editor/icons/use-icon-library.ts +315 -0
- package/src/admin/editor/palette-items.ts +36 -5
- package/src/admin/editor/palette.ts +3 -2
- package/src/admin/editor/panels/AddPanel.tsx +2 -67
- package/src/admin/editor/panels/ColorControl.tsx +2 -10
- package/src/admin/editor/panels/ElementPanel.tsx +40 -99
- package/src/admin/editor/panels/LayersPanel.tsx +34 -62
- package/src/admin/editor/panels/SettingsPanel.tsx +1 -0
- package/src/admin/editor/panels/SiteStylesDrawer.tsx +16 -10
- package/src/admin/editor/panels/VariableSection.tsx +1 -10
- package/src/admin/editor/panels/inline-error.tsx +11 -0
- package/src/admin/editor/panels/settings/AdvancedFields.tsx +87 -1
- package/src/admin/editor/panels/settings/AudienceEditor.tsx +73 -3
- package/src/admin/editor/panels/settings/DraftTextField.tsx +4 -0
- package/src/admin/editor/panels/settings/FormBindControl.tsx +8 -4
- package/src/admin/editor/panels/settings/ItemList.tsx +34 -1
- package/src/admin/editor/panels/settings/StyleRow.tsx +14 -2
- package/src/admin/editor/panels/settings/form-names.ts +7 -11
- package/src/admin/editor/panels/settings/length-units.ts +15 -4
- package/src/admin/editor/panels/settings/style-sections.ts +5 -1
- package/src/admin/editor/panels/style-target.ts +105 -0
- package/src/admin/editor/section-templates.ts +43 -21
- package/src/admin/editor/shortcuts.ts +4 -0
- package/src/admin/editor/store.ts +10 -1
- package/src/admin/editor/useClipboardActions.ts +1 -1
- package/src/admin/editor/useEditorCommands.ts +61 -13
- package/src/admin/editor/useEditorData.ts +7 -1
- package/src/admin/editor/useEditorShortcuts.ts +23 -15
- package/src/admin/editor/useNodeActions.ts +6 -1
- package/src/admin/forms-api.ts +17 -6
- package/src/admin/icon-uploads-api.ts +18 -0
- package/src/admin/theme-api.ts +5 -18
- package/src/astro/content-port.ts +24 -0
- package/src/astro/forms/EmVBFormsClient.astro +11 -0
- package/src/astro/forms/EmVBFormsRuntime.astro +6 -7
- package/src/astro/forms/client.ts +1 -0
- package/src/astro/forms-definitions.ts +24 -11
- package/src/astro/index.ts +1 -0
- package/src/astro/render-session.ts +85 -0
- package/src/astro/request-data.ts +20 -8
- package/src/astro/resolve-theme.ts +166 -76
- package/src/astro/resolve.ts +57 -16
- package/src/astro/theme-posts.ts +16 -5
- package/src/astro/visitor.ts +67 -5
- package/src/constants.ts +1 -1
- package/src/core/arrange.ts +63 -38
- package/src/core/audience/rules.ts +22 -2
- package/src/core/canvas-styles.ts +24 -0
- package/src/core/clipboard.ts +11 -32
- package/src/core/css/generate.ts +9 -0
- package/src/core/css/print.ts +12 -0
- package/src/core/css/scope.ts +3 -3
- package/src/core/css-keywords.ts +83 -0
- package/src/core/data/bindings.ts +4 -6
- package/src/core/design/classes.ts +13 -15
- package/src/core/design/diff.ts +55 -0
- package/src/core/design/merge.ts +127 -0
- package/src/core/design/variables.ts +25 -21
- package/src/core/elements/dynamic-elements.ts +30 -0
- package/src/core/elements/form-elements.ts +1 -0
- package/src/core/elements/index.ts +183 -7
- package/src/core/forms/binding.ts +4 -13
- package/src/core/index.ts +10 -0
- package/src/core/local-style.ts +27 -0
- package/src/core/migrate/index.ts +9 -4
- package/src/core/nesting.ts +4 -23
- package/src/core/perf/scripts.ts +9 -6
- package/src/core/record.ts +3 -0
- package/src/core/render/context.ts +2 -0
- package/src/core/render/dynamic-post.ts +1 -2
- package/src/core/render/form.ts +133 -10
- package/src/core/render/index.ts +155 -13
- package/src/core/render/vnode.ts +12 -2
- package/src/core/sanitize/css.ts +90 -77
- package/src/core/sanitize/svg.ts +8 -3
- package/src/core/sanitize/url.ts +10 -1
- package/src/core/schema/design.ts +5 -7
- package/src/core/schema/layout.ts +153 -181
- package/src/core/schema/style.ts +53 -63
- package/src/core/share/link.ts +68 -28
- package/src/core/tabs/presence.ts +7 -17
- package/src/core/theme/dynamic.ts +200 -39
- package/src/core/theme/float.ts +1 -1
- package/src/core/tree-ops.ts +57 -0
- package/src/index.ts +14 -2
- package/src/server/design-routes.ts +4 -1
- package/src/server/icon-routes.ts +68 -16
- package/src/server/plugin.ts +8 -2
- package/src/admin/editor/icons/sets/fontawesome.json +0 -1
- package/src/admin/editor/icons/sets/lucide.json +0 -1
- package/src/admin/editor/icons/sets/remix.json +0 -1
- package/src/admin/editor/icons/sets/tabler.json +0 -1
|
@@ -9,7 +9,6 @@ import {
|
|
|
9
9
|
TextAaIcon,
|
|
10
10
|
TextTIcon,
|
|
11
11
|
TrashIcon,
|
|
12
|
-
WarningCircleIcon,
|
|
13
12
|
type Icon,
|
|
14
13
|
} from "@phosphor-icons/react";
|
|
15
14
|
import * as React from "react";
|
|
@@ -27,6 +26,7 @@ import {
|
|
|
27
26
|
type VariableKind,
|
|
28
27
|
} from "../../../core/index.ts";
|
|
29
28
|
import { FIELD } from "../../ui.ts";
|
|
29
|
+
import { InlineError } from "./inline-error.tsx";
|
|
30
30
|
import {
|
|
31
31
|
CreateRow,
|
|
32
32
|
matches,
|
|
@@ -79,15 +79,6 @@ const MAX_BAR = 64;
|
|
|
79
79
|
|
|
80
80
|
type Item = { id: string; name: string; value: string | Length };
|
|
81
81
|
|
|
82
|
-
function InlineError({ children }: { children: string }) {
|
|
83
|
-
return (
|
|
84
|
-
<p className="emvb-inline-error" role="alert">
|
|
85
|
-
<WarningCircleIcon size={16} aria-hidden="true" />
|
|
86
|
-
{children}
|
|
87
|
-
</p>
|
|
88
|
-
);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
82
|
/** The kind's visual sample in the row: a swatch, "Ag" in the font, "Aa" at the size. */
|
|
92
83
|
function Preview({ kind, value }: { kind: VariableKind; value: string | Length }) {
|
|
93
84
|
if (kind === "color" && typeof value === "string") {
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { WarningCircleIcon } from "@phosphor-icons/react";
|
|
2
|
+
|
|
3
|
+
/** A one-line alert under a field. */
|
|
4
|
+
export function InlineError({ children }: { children: string }) {
|
|
5
|
+
return (
|
|
6
|
+
<p className="emvb-inline-error" role="alert">
|
|
7
|
+
<WarningCircleIcon size={16} aria-hidden="true" />
|
|
8
|
+
{children}
|
|
9
|
+
</p>
|
|
10
|
+
);
|
|
11
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Button, Input } from "@cloudflare/kumo";
|
|
1
|
+
import { Button, Input, Select } from "@cloudflare/kumo";
|
|
2
2
|
import * as React from "react";
|
|
3
3
|
import type { Layout, LayoutNode } from "../../../../core/index.ts";
|
|
4
4
|
import { BUTTON, FIELD } from "../../../ui.ts";
|
|
@@ -47,6 +47,92 @@ export function HtmlIdField({
|
|
|
47
47
|
);
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
+
/** Text direction for this element only (W-341). Unset follows the site. */
|
|
51
|
+
export function DirectionField({
|
|
52
|
+
node,
|
|
53
|
+
onChange,
|
|
54
|
+
}: {
|
|
55
|
+
node: LayoutNode;
|
|
56
|
+
onChange: (node: LayoutNode) => void;
|
|
57
|
+
}) {
|
|
58
|
+
return (
|
|
59
|
+
<Select
|
|
60
|
+
label="Text direction"
|
|
61
|
+
className={FIELD}
|
|
62
|
+
data-emvb-dir=""
|
|
63
|
+
value={node.dir ?? "site"}
|
|
64
|
+
onValueChange={(value) => {
|
|
65
|
+
const dir = value === "ltr" || value === "rtl" || value === "auto" ? value : undefined;
|
|
66
|
+
onChange({ ...node, dir });
|
|
67
|
+
}}
|
|
68
|
+
>
|
|
69
|
+
<Select.Option value="site">Site default</Select.Option>
|
|
70
|
+
<Select.Option value="ltr">Left to right</Select.Option>
|
|
71
|
+
<Select.Option value="rtl">Right to left</Select.Option>
|
|
72
|
+
<Select.Option value="auto">Auto</Select.Option>
|
|
73
|
+
</Select>
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** Marks a box as a container-query container (W-346). */
|
|
78
|
+
export function ContainerQueryFields({
|
|
79
|
+
node,
|
|
80
|
+
onChange,
|
|
81
|
+
}: {
|
|
82
|
+
node: LayoutNode;
|
|
83
|
+
onChange: (node: LayoutNode) => void;
|
|
84
|
+
}) {
|
|
85
|
+
const min = node.query?.min ?? "";
|
|
86
|
+
return (
|
|
87
|
+
<div className="emvb-field-group" data-emvb-container="">
|
|
88
|
+
<label className="emvb-check">
|
|
89
|
+
<input
|
|
90
|
+
type="checkbox"
|
|
91
|
+
checked={node.container === true}
|
|
92
|
+
onChange={(event) =>
|
|
93
|
+
onChange({ ...node, container: event.target.checked ? true : undefined })
|
|
94
|
+
}
|
|
95
|
+
/>
|
|
96
|
+
Query container
|
|
97
|
+
</label>
|
|
98
|
+
<Input
|
|
99
|
+
label="Styles from container width (px)"
|
|
100
|
+
className={FIELD}
|
|
101
|
+
type="number"
|
|
102
|
+
min={1}
|
|
103
|
+
max={3840}
|
|
104
|
+
value={min === "" ? "" : String(min)}
|
|
105
|
+
onChange={(event) => {
|
|
106
|
+
const next = event.target.value.trim();
|
|
107
|
+
if (next === "") {
|
|
108
|
+
const { query: _query, ...rest } = node;
|
|
109
|
+
onChange(rest);
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
const width = Number(next);
|
|
113
|
+
if (!Number.isInteger(width) || width < 1 || width > 3840) return;
|
|
114
|
+
onChange({ ...node, query: { min: width, style: node.query?.style ?? {} } });
|
|
115
|
+
}}
|
|
116
|
+
/>
|
|
117
|
+
<Button
|
|
118
|
+
type="button"
|
|
119
|
+
variant="secondary"
|
|
120
|
+
className={BUTTON}
|
|
121
|
+
onClick={() => {
|
|
122
|
+
const width = node.query?.min ?? 480;
|
|
123
|
+
onChange({ ...node, query: { min: width, style: node.style ?? {} } });
|
|
124
|
+
}}
|
|
125
|
+
>
|
|
126
|
+
Use current style at that width
|
|
127
|
+
</Button>
|
|
128
|
+
<p className="emvb-helper">
|
|
129
|
+
Query container makes this box the size children measure. The copied style is what applies
|
|
130
|
+
inside @container once the container is at least that wide, not the viewport.
|
|
131
|
+
</p>
|
|
132
|
+
</div>
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
|
|
50
136
|
const sameRows = (a: readonly AttributeRow[] | undefined, b: readonly AttributeRow[] | undefined) =>
|
|
51
137
|
JSON.stringify(a ?? []) === JSON.stringify(b ?? []);
|
|
52
138
|
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
AUDIENCE_DEVICES,
|
|
4
|
+
AUDIENCE_SEGMENT,
|
|
5
|
+
type Audience,
|
|
6
|
+
type LayoutNode,
|
|
7
|
+
} from "../../../../core/index.ts";
|
|
3
8
|
|
|
4
9
|
const DAYS = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
|
|
5
10
|
const COUNTRY = /^[A-Z]{2}$/;
|
|
@@ -15,11 +20,21 @@ export function parseCountries(text: string): string[] {
|
|
|
15
20
|
return [...new Set(codes)].slice(0, 50);
|
|
16
21
|
}
|
|
17
22
|
|
|
23
|
+
/** "Member, pro vip" → ["member", "pro", "vip"]; names that aren't segments are left out (W-329). */
|
|
24
|
+
export function parseSegments(text: string): string[] {
|
|
25
|
+
const names = text
|
|
26
|
+
.toLowerCase()
|
|
27
|
+
.split(/[\s,;]+/)
|
|
28
|
+
.filter((name) => AUDIENCE_SEGMENT.test(name));
|
|
29
|
+
return [...new Set(names)].slice(0, 20);
|
|
30
|
+
}
|
|
31
|
+
|
|
18
32
|
/** Drops empty rules so the stored audience stays valid (W-313). */
|
|
19
33
|
function tidy(audience: Audience): Audience | undefined {
|
|
20
34
|
const next: Audience = { ...audience };
|
|
21
35
|
if (next.countries?.length === 0) delete next.countries;
|
|
22
36
|
if (next.devices?.length === 0) delete next.devices;
|
|
37
|
+
if (next.segments?.length === 0) delete next.segments;
|
|
23
38
|
if (next.days?.length === 0) delete next.days;
|
|
24
39
|
if (!next.timeZone) delete next.timeZone;
|
|
25
40
|
if (!next.hide) delete next.hide;
|
|
@@ -27,7 +42,8 @@ function tidy(audience: Audience): Audience | undefined {
|
|
|
27
42
|
}
|
|
28
43
|
|
|
29
44
|
const ruleCount = (a: Audience) =>
|
|
30
|
-
[a.countries, a.devices, a.visitor, a.hours, a.days].filter((r) => r !== undefined)
|
|
45
|
+
[a.countries, a.devices, a.visitor, a.segments, a.hours, a.days].filter((r) => r !== undefined)
|
|
46
|
+
.length;
|
|
31
47
|
|
|
32
48
|
/**
|
|
33
49
|
* Visitors (W-313): show or hide this element by country, device, new or returning visitor,
|
|
@@ -43,8 +59,11 @@ export function AudienceEditor({
|
|
|
43
59
|
onChange: (node: LayoutNode) => void;
|
|
44
60
|
}) {
|
|
45
61
|
const [countryText, setCountryText] = React.useState(node.audience?.countries?.join(", ") ?? "");
|
|
62
|
+
const [segmentText, setSegmentText] = React.useState(node.audience?.segments?.join(", ") ?? "");
|
|
63
|
+
const [segmentError, setSegmentError] = React.useState<string | null>(null);
|
|
46
64
|
React.useEffect(() => {
|
|
47
65
|
setCountryText(node.audience?.countries?.join(", ") ?? "");
|
|
66
|
+
setSegmentText(node.audience?.segments?.join(", ") ?? "");
|
|
48
67
|
}, [node.id]);
|
|
49
68
|
if (isRoot) return null;
|
|
50
69
|
const audience = node.audience;
|
|
@@ -132,6 +151,57 @@ export function AudienceEditor({
|
|
|
132
151
|
<option value="returning">Returning visitor</option>
|
|
133
152
|
</select>
|
|
134
153
|
</label>
|
|
154
|
+
<label className="emvb-bind-row">
|
|
155
|
+
<span className="emvb-bind-label">Segments (from your site)</span>
|
|
156
|
+
<input
|
|
157
|
+
className="emvb-native-input"
|
|
158
|
+
value={segmentText}
|
|
159
|
+
placeholder="member, plan:pro"
|
|
160
|
+
data-emvb-audience-segments=""
|
|
161
|
+
aria-invalid={segmentError ? true : undefined}
|
|
162
|
+
aria-describedby={segmentError ? `${id}-segment-error` : undefined}
|
|
163
|
+
onChange={(event) => {
|
|
164
|
+
setSegmentText(event.currentTarget.value);
|
|
165
|
+
setSegmentError(null);
|
|
166
|
+
}}
|
|
167
|
+
onBlur={() => {
|
|
168
|
+
const raw = segmentText.trim();
|
|
169
|
+
if (raw === "") {
|
|
170
|
+
setSegmentText("");
|
|
171
|
+
setSegmentError(null);
|
|
172
|
+
set({ ...base, segments: [] });
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
const tokens = raw
|
|
176
|
+
.toLowerCase()
|
|
177
|
+
.split(/[\s,;]+/)
|
|
178
|
+
.filter((name) => name.length > 0);
|
|
179
|
+
const bad = tokens.find((name) => !AUDIENCE_SEGMENT.test(name));
|
|
180
|
+
if (bad) {
|
|
181
|
+
setSegmentError(`${bad} isn't a segment name. Use letters, numbers, and : _ -`);
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
const segments = parseSegments(segmentText);
|
|
185
|
+
setSegmentError(null);
|
|
186
|
+
setSegmentText(segments.join(", "));
|
|
187
|
+
set({ ...base, segments });
|
|
188
|
+
}}
|
|
189
|
+
/>
|
|
190
|
+
{segmentError && (
|
|
191
|
+
<span
|
|
192
|
+
className="emvb-helper"
|
|
193
|
+
id={`${id}-segment-error`}
|
|
194
|
+
data-emvb-audience-segment-error=""
|
|
195
|
+
>
|
|
196
|
+
{segmentError}
|
|
197
|
+
</span>
|
|
198
|
+
)}
|
|
199
|
+
</label>
|
|
200
|
+
{mode === "only" && ruleCount(base) === 0 && (
|
|
201
|
+
<p className="emvb-helper" data-emvb-audience-empty="">
|
|
202
|
+
Add a country, device, segment, or time. Until then, everyone sees this.
|
|
203
|
+
</p>
|
|
204
|
+
)}
|
|
135
205
|
<div className="emvb-bind-row">
|
|
136
206
|
<span className="emvb-bind-label">Hours (24 h, empty = all day)</span>
|
|
137
207
|
<input
|
|
@@ -206,7 +276,7 @@ export function AudienceEditor({
|
|
|
206
276
|
<p className="emvb-helper" data-emvb-audience-help="">
|
|
207
277
|
{ruleCount(base) === 0
|
|
208
278
|
? "Add a rule: with none, every visitor matches."
|
|
209
|
-
: "The server checks these on each visit, with no script. A rule it can't check (no country from the host) doesn't match. The canvas shows this element to you either way."}
|
|
279
|
+
: "The server checks these on each visit, with no script. A rule it can't check (no country from the host, or segments your site doesn't pass) doesn't match. The canvas shows this element to you either way."}
|
|
210
280
|
</p>
|
|
211
281
|
</>
|
|
212
282
|
)}
|
|
@@ -98,6 +98,10 @@ export function DraftTextField({
|
|
|
98
98
|
.split("\n")
|
|
99
99
|
.map((line) => line.trimEnd())
|
|
100
100
|
.filter((line) => line.length > 0);
|
|
101
|
+
if (items.length === 0 && field.optional) {
|
|
102
|
+
onChange(withProp(node, field.key, undefined));
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
101
105
|
onChange(withProp(node, field.key, items.length > 0 ? items : [""]));
|
|
102
106
|
};
|
|
103
107
|
return (
|
|
@@ -11,6 +11,9 @@ import { useAdminLinks } from "../../host.ts";
|
|
|
11
11
|
|
|
12
12
|
const MANUAL = "__manual__";
|
|
13
13
|
|
|
14
|
+
/** W-326: a paused form is marked, since the page then shows it isn't accepting responses. */
|
|
15
|
+
const formLabel = (form: FormListItem) => (form.paused ? `${form.name} (paused)` : form.name);
|
|
16
|
+
|
|
14
17
|
/**
|
|
15
18
|
* Form id binder (W-036 / D-015): admins pick from forms/list; others enter the id.
|
|
16
19
|
*/
|
|
@@ -58,14 +61,15 @@ export function FormBindControl({
|
|
|
58
61
|
if (!next || next === MANUAL) return;
|
|
59
62
|
onChange(next);
|
|
60
63
|
}}
|
|
61
|
-
renderValue={(current: unknown) =>
|
|
62
|
-
capability.forms.find((
|
|
63
|
-
|
|
64
|
+
renderValue={(current: unknown) => {
|
|
65
|
+
const form = capability.forms.find((item) => item.id === current);
|
|
66
|
+
return form ? formLabel(form) : placeholder;
|
|
67
|
+
}}
|
|
64
68
|
>
|
|
65
69
|
<Select.Option value={MANUAL}>{placeholder}</Select.Option>
|
|
66
70
|
{capability.forms.map((form: FormListItem) => (
|
|
67
71
|
<Select.Option key={form.id} value={form.id}>
|
|
68
|
-
{form
|
|
72
|
+
{formLabel(form)}
|
|
69
73
|
</Select.Option>
|
|
70
74
|
))}
|
|
71
75
|
</Select>
|
|
@@ -47,6 +47,21 @@ export const hasItemList = (type: string) => type in KINDS;
|
|
|
47
47
|
const childrenOf = (node: LayoutNode): LayoutNode[] =>
|
|
48
48
|
"children" in node && Array.isArray(node.children) ? (node.children as LayoutNode[]) : [];
|
|
49
49
|
|
|
50
|
+
/** One reorder of `kids`, moving `fromId` to `toIndex`. Same place or an unknown id changes nothing. */
|
|
51
|
+
export function reorderItems(
|
|
52
|
+
kids: LayoutNode[],
|
|
53
|
+
fromId: string,
|
|
54
|
+
toIndex: number,
|
|
55
|
+
): LayoutNode[] | undefined {
|
|
56
|
+
const from = kids.findIndex((item) => item.id === fromId);
|
|
57
|
+
if (from < 0 || from === toIndex) return undefined;
|
|
58
|
+
const next = kids.slice();
|
|
59
|
+
const [moved] = next.splice(from, 1);
|
|
60
|
+
if (!moved) return undefined;
|
|
61
|
+
next.splice(toIndex, 0, moved);
|
|
62
|
+
return next;
|
|
63
|
+
}
|
|
64
|
+
|
|
50
65
|
/** Fallback when no editor actions are wired (isolated panels): plain edits of the parent. */
|
|
51
66
|
function localActions(node: LayoutNode, onChange: (node: LayoutNode) => void): ItemActions {
|
|
52
67
|
const kids = childrenOf(node);
|
|
@@ -115,7 +130,25 @@ export function ItemList({
|
|
|
115
130
|
{kids.map((child, index) => {
|
|
116
131
|
const n = index + 1;
|
|
117
132
|
return (
|
|
118
|
-
<li
|
|
133
|
+
<li
|
|
134
|
+
key={child.id}
|
|
135
|
+
className="emvb-item-row"
|
|
136
|
+
data-emvb-item={child.id}
|
|
137
|
+
draggable
|
|
138
|
+
onDragStart={(event) => {
|
|
139
|
+
event.dataTransfer.setData("text/plain", child.id);
|
|
140
|
+
event.dataTransfer.effectAllowed = "move";
|
|
141
|
+
}}
|
|
142
|
+
onDragOver={(event) => {
|
|
143
|
+
event.preventDefault();
|
|
144
|
+
event.dataTransfer.dropEffect = "move";
|
|
145
|
+
}}
|
|
146
|
+
onDrop={(event) => {
|
|
147
|
+
event.preventDefault();
|
|
148
|
+
const next = reorderItems(kids, event.dataTransfer.getData("text/plain"), index);
|
|
149
|
+
if (next) onChange({ ...node, children: next } as LayoutNode);
|
|
150
|
+
}}
|
|
151
|
+
>
|
|
119
152
|
<DraftTextField
|
|
120
153
|
field={kind.field(n)}
|
|
121
154
|
node={child}
|
|
@@ -62,6 +62,7 @@ const LENGTH_KEYS = new Set<StyleKey>([
|
|
|
62
62
|
|
|
63
63
|
const Z_INDEX: NumberSpec = { min: -9999, max: 9999, integer: true, example: "10" };
|
|
64
64
|
const GRID_SPAN: NumberSpec = { min: 1, max: 12, integer: true, example: "2" };
|
|
65
|
+
const GRID_LINE: NumberSpec = { min: 1, max: 13, integer: true, example: "1" };
|
|
65
66
|
const OPACITY: NumberSpec = { min: 0, max: 100, scale: 100, example: "50", suffix: "%" };
|
|
66
67
|
|
|
67
68
|
const COLOR_KEYS = new Set<StyleKey>(["color", "backgroundColor", "borderColor"]);
|
|
@@ -410,9 +411,18 @@ export function StyleRow({
|
|
|
410
411
|
styleKey === "zIndex" ||
|
|
411
412
|
styleKey === "opacity" ||
|
|
412
413
|
styleKey === "gridColumnSpan" ||
|
|
413
|
-
styleKey === "gridRowSpan"
|
|
414
|
+
styleKey === "gridRowSpan" ||
|
|
415
|
+
styleKey === "gridColumnStart" ||
|
|
416
|
+
styleKey === "gridRowStart"
|
|
414
417
|
) {
|
|
415
|
-
const spec =
|
|
418
|
+
const spec =
|
|
419
|
+
styleKey === "zIndex"
|
|
420
|
+
? Z_INDEX
|
|
421
|
+
: styleKey === "opacity"
|
|
422
|
+
? OPACITY
|
|
423
|
+
: styleKey === "gridColumnStart" || styleKey === "gridRowStart"
|
|
424
|
+
? GRID_LINE
|
|
425
|
+
: GRID_SPAN;
|
|
416
426
|
return (
|
|
417
427
|
<NumberRow
|
|
418
428
|
rowKey={styleKey}
|
|
@@ -553,7 +563,9 @@ export const IMPLEMENTED_STYLE_KEYS: StyleKey[] = [
|
|
|
553
563
|
"fontFamily",
|
|
554
564
|
"zIndex",
|
|
555
565
|
"gridColumnSpan",
|
|
566
|
+
"gridColumnStart",
|
|
556
567
|
"gridRowSpan",
|
|
568
|
+
"gridRowStart",
|
|
557
569
|
"opacity",
|
|
558
570
|
"boxShadow",
|
|
559
571
|
"filter",
|
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
isFormNode,
|
|
4
|
-
parentOf,
|
|
5
|
-
type Layout,
|
|
6
|
-
type LayoutNode,
|
|
7
|
-
} from "../../../../core/index.ts";
|
|
1
|
+
import { isFormNode, type Layout, type LayoutNode } from "../../../../core/index.ts";
|
|
2
|
+
import { indexLayout } from "../../../../core/tree-ops.ts";
|
|
8
3
|
|
|
9
4
|
const fieldOf = (node: LayoutNode): string => {
|
|
10
5
|
const value = (node.props as Record<string, unknown> | undefined)?.field;
|
|
@@ -16,12 +11,13 @@ const fieldOf = (node: LayoutNode): string => {
|
|
|
16
11
|
* one value would overwrite the other. Controls outside any form are not checked.
|
|
17
12
|
*/
|
|
18
13
|
export function duplicateFieldName(layout: Layout, nodeId: string): boolean {
|
|
19
|
-
const
|
|
14
|
+
const index = indexLayout(layout);
|
|
15
|
+
const self = index.byId.get(nodeId);
|
|
20
16
|
const name = self ? fieldOf(self) : "";
|
|
21
17
|
if (!name) return false;
|
|
22
|
-
let current = parentOf(
|
|
18
|
+
let current = index.parentOf.get(nodeId);
|
|
23
19
|
while (current) {
|
|
24
|
-
const form =
|
|
20
|
+
const form = index.byId.get(current);
|
|
25
21
|
if (form && isFormNode(form)) {
|
|
26
22
|
let count = 0;
|
|
27
23
|
const walk = (node: LayoutNode) => {
|
|
@@ -32,7 +28,7 @@ export function duplicateFieldName(layout: Layout, nodeId: string): boolean {
|
|
|
32
28
|
walk(form);
|
|
33
29
|
return count > 1;
|
|
34
30
|
}
|
|
35
|
-
current = parentOf(
|
|
31
|
+
current = index.parentOf.get(current);
|
|
36
32
|
}
|
|
37
33
|
return false;
|
|
38
34
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { STYLE_LABELS, type StyleKey } from "./style-sections.ts";
|
|
2
2
|
|
|
3
|
-
export type LengthUnit = "px" | "rem" | "em" | "%" | "vw" | "vh";
|
|
3
|
+
export type LengthUnit = "px" | "rem" | "em" | "%" | "vw" | "vh" | "ch";
|
|
4
4
|
/** `x` is a unitless number, for Line height only (W-213). */
|
|
5
5
|
export type UnitChoice = LengthUnit | "auto" | "x";
|
|
6
6
|
export type LengthLiteral = { value: number; unit: LengthUnit };
|
|
7
7
|
|
|
8
|
-
const BOX: readonly UnitChoice[] = ["px", "%", "rem", "em", "vw", "vh"];
|
|
8
|
+
const BOX: readonly UnitChoice[] = ["px", "%", "rem", "em", "vw", "vh", "ch"];
|
|
9
9
|
const BOX_AUTO: readonly UnitChoice[] = [...BOX, "auto"];
|
|
10
10
|
|
|
11
11
|
/** Units each length property offers in its unit menu (DESIGN.md § Inputs). */
|
|
@@ -38,13 +38,24 @@ const UNITS: Partial<Record<StyleKey, readonly UnitChoice[]>> = {
|
|
|
38
38
|
|
|
39
39
|
export const unitsFor = (key: StyleKey): readonly UnitChoice[] => UNITS[key] ?? BOX;
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
/** Keys that take a negative number; margins since W-331. */
|
|
42
|
+
const NEGATIVE = new Set<StyleKey>([
|
|
43
|
+
"top",
|
|
44
|
+
"right",
|
|
45
|
+
"bottom",
|
|
46
|
+
"left",
|
|
47
|
+
"letterSpacing",
|
|
48
|
+
"marginTop",
|
|
49
|
+
"marginRight",
|
|
50
|
+
"marginBottom",
|
|
51
|
+
"marginLeft",
|
|
52
|
+
]);
|
|
42
53
|
|
|
43
54
|
export type ParsedLength =
|
|
44
55
|
| { ok: true; value: LengthLiteral | "auto" | number | undefined }
|
|
45
56
|
| { ok: false; message: string };
|
|
46
57
|
|
|
47
|
-
const DRAFT = /^([+-]?(?:\d+(?:\.\d*)?|\.\d+))\s*(px|rem|em|%|vw|vh)?$/i;
|
|
58
|
+
const DRAFT = /^([+-]?(?:\d+(?:\.\d*)?|\.\d+))\s*(px|rem|em|%|vw|vh|ch)?$/i;
|
|
48
59
|
/** A number with a unit EmVB doesn't take ("100dvh", "12pt"), or a comma decimal ("1,5") (W-262). */
|
|
49
60
|
const OTHER_UNIT = /^[+-]?(?:\d+(?:\.\d*)?|\.\d+)\s*[a-z%]+$/i;
|
|
50
61
|
const COMMA_DECIMAL = /^[+-]?\d*,\d+\s*[a-z%]*$/i;
|
|
@@ -148,7 +148,9 @@ const SECTION_KEYS: Record<StyleSectionId, StyleKey[]> = {
|
|
|
148
148
|
"alignItems",
|
|
149
149
|
"gap",
|
|
150
150
|
"gridColumnSpan",
|
|
151
|
+
"gridColumnStart",
|
|
151
152
|
"gridRowSpan",
|
|
153
|
+
"gridRowStart",
|
|
152
154
|
],
|
|
153
155
|
spacing: [
|
|
154
156
|
"paddingTop",
|
|
@@ -228,7 +230,7 @@ const ONLY_FOR: Partial<Record<StyleKey, string[]>> = {
|
|
|
228
230
|
),
|
|
229
231
|
};
|
|
230
232
|
|
|
231
|
-
const SPANS: StyleKey[] = ["gridColumnSpan", "gridRowSpan"];
|
|
233
|
+
const SPANS: StyleKey[] = ["gridColumnSpan", "gridColumnStart", "gridRowSpan", "gridRowStart"];
|
|
232
234
|
|
|
233
235
|
/**
|
|
234
236
|
* Direction, wrap, justify, align and gap only where the element's own box is a flex or grid
|
|
@@ -323,7 +325,9 @@ export const STYLE_LABELS: Record<StyleKey, string> = {
|
|
|
323
325
|
alignItems: "Align",
|
|
324
326
|
gap: "Gap",
|
|
325
327
|
gridColumnSpan: "Column span",
|
|
328
|
+
gridColumnStart: "Column start",
|
|
326
329
|
gridRowSpan: "Row span",
|
|
330
|
+
gridRowStart: "Row start",
|
|
327
331
|
width: "Width",
|
|
328
332
|
minWidth: "Min width",
|
|
329
333
|
maxWidth: "Max width",
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import {
|
|
2
|
+
patchClassDevices,
|
|
3
|
+
patchClassState,
|
|
4
|
+
patchClassStyle,
|
|
5
|
+
patchDeviceStyle,
|
|
6
|
+
patchStates,
|
|
7
|
+
type DesignSystem,
|
|
8
|
+
type DeviceStyles,
|
|
9
|
+
type LayoutNode,
|
|
10
|
+
type PopupDevice,
|
|
11
|
+
type StyleProps,
|
|
12
|
+
type StyleStateName,
|
|
13
|
+
type StyleStates,
|
|
14
|
+
} from "../../../core/index.ts";
|
|
15
|
+
import type { StyleStateChoice } from "./settings/StateSwitcher.tsx";
|
|
16
|
+
|
|
17
|
+
export type StyleSlot =
|
|
18
|
+
| { owner: "element" | "class"; slot: "style" }
|
|
19
|
+
| { owner: "element" | "class"; slot: "state"; state: StyleStateName }
|
|
20
|
+
| { owner: "element" | "class"; slot: "device"; device: "tablet" | "mobile" };
|
|
21
|
+
|
|
22
|
+
/** Which style object a patch writes: the element's own, a class, a state, or a device. */
|
|
23
|
+
export function styleTarget({
|
|
24
|
+
classId,
|
|
25
|
+
device,
|
|
26
|
+
state,
|
|
27
|
+
}: {
|
|
28
|
+
classId: string | null;
|
|
29
|
+
device: PopupDevice;
|
|
30
|
+
state: StyleStateChoice;
|
|
31
|
+
}): StyleSlot {
|
|
32
|
+
const owner = classId ? "class" : "element";
|
|
33
|
+
if (device !== "desktop") return { owner, slot: "device", device };
|
|
34
|
+
if (state === "normal") return { owner, slot: "style" };
|
|
35
|
+
return { owner, slot: "state", state };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const withStyle = (node: LayoutNode, patch: Partial<StyleProps>): LayoutNode => {
|
|
39
|
+
const style: Record<string, unknown> = { ...node.style, ...patch };
|
|
40
|
+
for (const key of Object.keys(style)) if (style[key] === undefined) delete style[key];
|
|
41
|
+
return {
|
|
42
|
+
...node,
|
|
43
|
+
style: Object.keys(style).length > 0 ? (style as StyleProps) : undefined,
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const withDevices = (node: LayoutNode, devices: DeviceStyles | undefined): LayoutNode => {
|
|
48
|
+
const { devices: _old, ...rest } = node;
|
|
49
|
+
return (devices ? { ...rest, devices } : rest) as LayoutNode;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const withStates = (node: LayoutNode, states: StyleStates | undefined): LayoutNode => {
|
|
53
|
+
const { states: _old, ...rest } = node;
|
|
54
|
+
return (states ? { ...rest, states } : rest) as LayoutNode;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export type StyleWrite =
|
|
58
|
+
| { kind: "node"; node: LayoutNode }
|
|
59
|
+
| { kind: "design"; design: DesignSystem };
|
|
60
|
+
|
|
61
|
+
/** Apply a style patch to the slot `styleTarget` names. */
|
|
62
|
+
export function applyStylePatch({
|
|
63
|
+
node,
|
|
64
|
+
design,
|
|
65
|
+
classId,
|
|
66
|
+
device,
|
|
67
|
+
state,
|
|
68
|
+
patch,
|
|
69
|
+
}: {
|
|
70
|
+
node: LayoutNode;
|
|
71
|
+
design: DesignSystem;
|
|
72
|
+
classId: string | null;
|
|
73
|
+
device: PopupDevice;
|
|
74
|
+
state: StyleStateChoice;
|
|
75
|
+
patch: Partial<StyleProps>;
|
|
76
|
+
}): StyleWrite {
|
|
77
|
+
const target = styleTarget({ classId, device, state });
|
|
78
|
+
if (target.slot === "device") {
|
|
79
|
+
if (!classId) {
|
|
80
|
+
return {
|
|
81
|
+
kind: "node",
|
|
82
|
+
node: withDevices(node, patchDeviceStyle(node.devices, target.device, patch)),
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
return {
|
|
86
|
+
kind: "design",
|
|
87
|
+
design: patchClassDevices(design, classId, target.device, patch),
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
if (!classId) {
|
|
91
|
+
return {
|
|
92
|
+
kind: "node",
|
|
93
|
+
node:
|
|
94
|
+
state === "normal"
|
|
95
|
+
? withStyle(node, patch)
|
|
96
|
+
: withStates(node, patchStates(node.states, state, patch)),
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
const cls = { id: classId };
|
|
100
|
+
const next =
|
|
101
|
+
state === "normal"
|
|
102
|
+
? patchClassStyle(design, cls.id, patch)
|
|
103
|
+
: patchClassState(design, cls.id, state, patch);
|
|
104
|
+
return { kind: "design", design: next };
|
|
105
|
+
}
|