@perkyzz/emvb 0.2.1 → 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 +126 -0
- package/src/admin/editor/CommandPalette.tsx +118 -0
- package/src/admin/editor/Editor.tsx +188 -152
- package/src/admin/editor/EditorOverlay.tsx +9 -1
- package/src/admin/editor/PerfMeter.tsx +121 -0
- package/src/admin/editor/ShareLink.tsx +164 -0
- package/src/admin/editor/ShortcutsDialog.tsx +4 -1
- package/src/admin/editor/Timeline.tsx +287 -0
- package/src/admin/editor/TopBar.tsx +4 -0
- package/src/admin/editor/canvas/CanvasFrame.tsx +62 -370
- package/src/admin/editor/canvas/DeviceBar.tsx +4 -1
- package/src/admin/editor/canvas/SelectionOverlay.tsx +87 -47
- 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 +114 -0
- package/src/admin/editor/editor-chrome.tsx +346 -0
- package/src/admin/editor/editor-commands.ts +360 -0
- package/src/admin/editor/editor-css.ts +5 -3
- package/src/admin/editor/element-chrome.ts +89 -0
- package/src/admin/editor/feature-css.ts +105 -0
- package/src/admin/editor/host.ts +35 -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/live-data.tsx +71 -0
- package/src/admin/editor/palette-items.ts +136 -0
- package/src/admin/editor/palette.ts +68 -0
- package/src/admin/editor/panels/AddPanel.tsx +48 -68
- package/src/admin/editor/panels/ClassesSection.tsx +5 -1
- package/src/admin/editor/panels/ColorControl.tsx +2 -10
- package/src/admin/editor/panels/ElementPanel.tsx +74 -102
- package/src/admin/editor/panels/LayersPanel.tsx +72 -63
- package/src/admin/editor/panels/LeftPanel.tsx +4 -1
- package/src/admin/editor/panels/SettingsPanel.tsx +13 -0
- package/src/admin/editor/panels/SiteStylesDrawer.tsx +18 -10
- package/src/admin/editor/panels/TokenScales.tsx +168 -0
- package/src/admin/editor/panels/VariableSection.tsx +10 -14
- 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 +285 -0
- package/src/admin/editor/panels/settings/BindingsEditor.tsx +221 -0
- package/src/admin/editor/panels/settings/ClassChipInput.tsx +1 -1
- package/src/admin/editor/panels/settings/DraftTextField.tsx +4 -0
- package/src/admin/editor/panels/settings/EffectsControls.tsx +2 -2
- 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/MotionControl.tsx +252 -0
- package/src/admin/editor/panels/settings/StateSwitcher.tsx +1 -1
- package/src/admin/editor/panels/settings/StyleRow.tsx +26 -2
- package/src/admin/editor/panels/settings/StyleSources.tsx +94 -0
- package/src/admin/editor/panels/settings/VariableBinding.tsx +1 -1
- package/src/admin/editor/panels/settings/VariantEditor.tsx +83 -0
- package/src/admin/editor/panels/settings/form-names.ts +7 -11
- package/src/admin/editor/panels/settings/length-units.ts +16 -5
- package/src/admin/editor/panels/settings/style-sections.ts +7 -2
- 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 +6 -1
- 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 +30 -14
- package/src/admin/editor/useNodeActions.ts +44 -16
- 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/admin/ui.ts +4 -4
- 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 +109 -0
- package/src/astro/resolve-theme.ts +184 -64
- package/src/astro/resolve.ts +63 -16
- package/src/astro/theme-posts.ts +48 -5
- package/src/astro/visitor.ts +204 -0
- package/src/constants.ts +1 -1
- package/src/core/a11y/audit.ts +282 -0
- package/src/core/arrange.ts +150 -34
- package/src/core/audience/rules.ts +124 -0
- package/src/core/audience/variants.ts +51 -0
- package/src/core/canvas-styles.ts +24 -0
- package/src/core/clipboard.ts +11 -32
- package/src/core/css/generate.ts +29 -2
- package/src/core/css/print.ts +12 -0
- package/src/core/css/scope.ts +3 -3
- package/src/core/css/trace.ts +169 -0
- package/src/core/css-keywords.ts +83 -0
- package/src/core/data/bindings.ts +255 -0
- 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/tokens.ts +127 -0
- package/src/core/design/variables.ts +25 -21
- package/src/core/elements/dynamic-elements.ts +117 -2
- package/src/core/elements/form-elements.ts +1 -0
- package/src/core/elements/index.ts +185 -7
- package/src/core/forms/binding.ts +4 -13
- package/src/core/history/diff.ts +152 -0
- package/src/core/index.ts +121 -0
- package/src/core/local-style.ts +27 -0
- package/src/core/migrate/index.ts +12 -4
- package/src/core/nesting.ts +4 -22
- package/src/core/perf/meter.ts +160 -0
- package/src/core/perf/scripts.ts +61 -0
- package/src/core/recipes/index.ts +433 -0
- 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 +206 -17
- package/src/core/render/loop.ts +54 -7
- package/src/core/render/pagination.ts +9 -1
- package/src/core/render/vnode.ts +12 -2
- package/src/core/sanitize/css.ts +129 -80
- package/src/core/sanitize/motion.ts +129 -0
- package/src/core/sanitize/svg.ts +8 -3
- package/src/core/sanitize/url.ts +10 -1
- package/src/core/schema/design.ts +29 -8
- package/src/core/schema/layout.ts +291 -169
- package/src/core/schema/motion.ts +14 -0
- package/src/core/schema/style.ts +101 -66
- package/src/core/share/link.ts +187 -0
- package/src/core/tabs/presence.ts +7 -17
- package/src/core/theme/dynamic.ts +242 -32
- package/src/core/theme/float.ts +1 -1
- package/src/core/theme/pagination.ts +56 -0
- 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
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import {
|
|
3
|
+
BIND_SOURCES,
|
|
4
|
+
BIND_SOURCE_LABELS,
|
|
5
|
+
POST_BIND_KEYS,
|
|
6
|
+
SITE_BIND_KEYS,
|
|
7
|
+
bindableFields,
|
|
8
|
+
boundValue,
|
|
9
|
+
resolveBinding,
|
|
10
|
+
withBinding,
|
|
11
|
+
type BindSource,
|
|
12
|
+
type Binding,
|
|
13
|
+
type LayoutNode,
|
|
14
|
+
type ThemePostFields,
|
|
15
|
+
} from "../../../../core/index.ts";
|
|
16
|
+
import { siteOrigin, useLiveData } from "../../live-data.tsx";
|
|
17
|
+
|
|
18
|
+
const KEY = /^[A-Za-z][A-Za-z0-9_.-]{0,63}$/;
|
|
19
|
+
const STATIC = "static";
|
|
20
|
+
|
|
21
|
+
/** Suggested keys for a source; any other key can be typed. */
|
|
22
|
+
function suggestions(source: BindSource, site: Readonly<Record<string, string>>): string[] {
|
|
23
|
+
if (source === "post") return POST_BIND_KEYS.map((k) => k.key);
|
|
24
|
+
if (source === "site") {
|
|
25
|
+
return [...new Set([...SITE_BIND_KEYS.map((k) => k.key), ...Object.keys(site)])];
|
|
26
|
+
}
|
|
27
|
+
return [];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const firstKey = (source: BindSource) =>
|
|
31
|
+
source === "post" ? "title" : source === "site" ? "title" : "ref";
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Dynamic data (W-307): bind a text, image or link field to a post field, a site setting or a
|
|
35
|
+
* URL parameter. The field's typed value is the fallback, and the live value shows here and on
|
|
36
|
+
* the canvas while you edit.
|
|
37
|
+
*/
|
|
38
|
+
export function BindingsEditor({
|
|
39
|
+
node,
|
|
40
|
+
onChange,
|
|
41
|
+
post,
|
|
42
|
+
}: {
|
|
43
|
+
node: LayoutNode;
|
|
44
|
+
onChange: (node: LayoutNode) => void;
|
|
45
|
+
/** The post the canvas shows (a sample outside a post template). */
|
|
46
|
+
post?: ThemePostFields;
|
|
47
|
+
}) {
|
|
48
|
+
const fields = bindableFields(node.type);
|
|
49
|
+
const live = useLiveData();
|
|
50
|
+
if (fields.length === 0) return null;
|
|
51
|
+
const listId = `emvb-bind-keys-${node.id}`;
|
|
52
|
+
return (
|
|
53
|
+
<section className="emvb-bind" data-emvb-bindings="" aria-labelledby={`${listId}-title`}>
|
|
54
|
+
<h3 className="emvb-bind-title" id={`${listId}-title`}>
|
|
55
|
+
Dynamic data
|
|
56
|
+
</h3>
|
|
57
|
+
<p className="emvb-helper">
|
|
58
|
+
Show live data instead of the typed value. The typed value is used when there is none.
|
|
59
|
+
</p>
|
|
60
|
+
{fields.map((field) => {
|
|
61
|
+
const binding = node.bind?.[field.key];
|
|
62
|
+
const source = binding?.source;
|
|
63
|
+
const data = { post, site: live.site, params: live.params, origin: siteOrigin() };
|
|
64
|
+
const value = binding ? boundValue(field, binding, data, field.kind === "text") : undefined;
|
|
65
|
+
// W-307: a value that exists but is refused (another site, or an unsafe URL).
|
|
66
|
+
const refused =
|
|
67
|
+
binding !== undefined &&
|
|
68
|
+
value === undefined &&
|
|
69
|
+
resolveBinding(binding, data) !== undefined;
|
|
70
|
+
const offSiteOption = binding?.source === "param" && field.kind !== "text";
|
|
71
|
+
const selectId = `${listId}-${field.key}`;
|
|
72
|
+
return (
|
|
73
|
+
<div className="emvb-bind-row" key={field.key} data-emvb-bind-field={field.key}>
|
|
74
|
+
{/* "Text source", not "Text": the field's own input is already named "Text". */}
|
|
75
|
+
<label className="emvb-bind-label" htmlFor={selectId}>
|
|
76
|
+
{`${field.label} source`}
|
|
77
|
+
</label>
|
|
78
|
+
<select
|
|
79
|
+
id={selectId}
|
|
80
|
+
className="emvb-native-select"
|
|
81
|
+
value={source ?? STATIC}
|
|
82
|
+
onChange={(event) => {
|
|
83
|
+
const next = event.target.value;
|
|
84
|
+
if (next === STATIC) onChange(withBinding(node, field.key, undefined));
|
|
85
|
+
else {
|
|
86
|
+
const src = next as BindSource;
|
|
87
|
+
onChange(withBinding(node, field.key, { source: src, key: firstKey(src) }));
|
|
88
|
+
}
|
|
89
|
+
}}
|
|
90
|
+
>
|
|
91
|
+
<option value={STATIC}>Typed value</option>
|
|
92
|
+
{BIND_SOURCES.map((s) => (
|
|
93
|
+
<option key={s} value={s}>
|
|
94
|
+
{BIND_SOURCE_LABELS[s]}
|
|
95
|
+
</option>
|
|
96
|
+
))}
|
|
97
|
+
</select>
|
|
98
|
+
{binding ? (
|
|
99
|
+
<BindKeyInput
|
|
100
|
+
fieldLabel={field.label}
|
|
101
|
+
binding={binding}
|
|
102
|
+
listId={`${selectId}-keys`}
|
|
103
|
+
options={suggestions(binding.source, live.site)}
|
|
104
|
+
onCommit={(key) => onChange(withBinding(node, field.key, { ...binding, key }))}
|
|
105
|
+
/>
|
|
106
|
+
) : (
|
|
107
|
+
<span />
|
|
108
|
+
)}
|
|
109
|
+
{binding && (
|
|
110
|
+
<p className="emvb-bind-live" data-emvb-bind-live="">
|
|
111
|
+
{refused ? (
|
|
112
|
+
<>
|
|
113
|
+
{offSiteOption && !binding.outside
|
|
114
|
+
? "Not a link on this site, so the typed value shows."
|
|
115
|
+
: "Not a usable URL, so the typed value shows."}
|
|
116
|
+
</>
|
|
117
|
+
) : value === undefined ? (
|
|
118
|
+
<>No value here, so the typed value shows.</>
|
|
119
|
+
) : (
|
|
120
|
+
<>
|
|
121
|
+
Live: <b>{value}</b>
|
|
122
|
+
</>
|
|
123
|
+
)}
|
|
124
|
+
</p>
|
|
125
|
+
)}
|
|
126
|
+
{binding && offSiteOption && (
|
|
127
|
+
<div className="emvb-bind-outside" data-emvb-bind-outside="">
|
|
128
|
+
<label>
|
|
129
|
+
<input
|
|
130
|
+
type="checkbox"
|
|
131
|
+
checked={binding.outside === true}
|
|
132
|
+
onChange={(event) => {
|
|
133
|
+
const { outside: _old, ...rest } = binding;
|
|
134
|
+
const next = event.target.checked ? { ...rest, outside: true } : rest;
|
|
135
|
+
onChange(withBinding(node, field.key, next));
|
|
136
|
+
}}
|
|
137
|
+
/>
|
|
138
|
+
{`Allow outside sites for ${field.label}`}
|
|
139
|
+
</label>
|
|
140
|
+
{binding.outside ? (
|
|
141
|
+
<p className="emvb-bind-warning" role="note">
|
|
142
|
+
Phishing risk: anyone can share a link to this page that sends visitors to any
|
|
143
|
+
site or shows any image under your address. Only allow this if you trust where
|
|
144
|
+
those links come from.
|
|
145
|
+
</p>
|
|
146
|
+
) : (
|
|
147
|
+
<p className="emvb-helper">
|
|
148
|
+
Only links and images on this site are used. Others show the typed value.
|
|
149
|
+
</p>
|
|
150
|
+
)}
|
|
151
|
+
</div>
|
|
152
|
+
)}
|
|
153
|
+
</div>
|
|
154
|
+
);
|
|
155
|
+
})}
|
|
156
|
+
{Object.values(node.bind ?? {}).some((b) => b.source === "param") && <PreviewQuery />}
|
|
157
|
+
</section>
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function BindKeyInput({
|
|
162
|
+
fieldLabel,
|
|
163
|
+
binding,
|
|
164
|
+
listId,
|
|
165
|
+
options,
|
|
166
|
+
onCommit,
|
|
167
|
+
}: {
|
|
168
|
+
fieldLabel: string;
|
|
169
|
+
binding: Binding;
|
|
170
|
+
listId: string;
|
|
171
|
+
options: string[];
|
|
172
|
+
onCommit: (key: string) => void;
|
|
173
|
+
}) {
|
|
174
|
+
const [draft, setDraft] = React.useState(binding.key);
|
|
175
|
+
React.useEffect(() => setDraft(binding.key), [binding.key]);
|
|
176
|
+
const valid = KEY.test(draft);
|
|
177
|
+
const commit = () => {
|
|
178
|
+
if (valid && draft !== binding.key) onCommit(draft);
|
|
179
|
+
if (!valid) setDraft(binding.key);
|
|
180
|
+
};
|
|
181
|
+
return (
|
|
182
|
+
<>
|
|
183
|
+
<input
|
|
184
|
+
className="emvb-native-input"
|
|
185
|
+
aria-label={`${fieldLabel} ${binding.source === "param" ? "parameter name" : "field name"}`}
|
|
186
|
+
aria-invalid={valid ? undefined : true}
|
|
187
|
+
list={options.length > 0 ? listId : undefined}
|
|
188
|
+
value={draft}
|
|
189
|
+
onChange={(event) => setDraft(event.target.value)}
|
|
190
|
+
onBlur={commit}
|
|
191
|
+
onKeyDown={(event) => {
|
|
192
|
+
if (event.key === "Enter") commit();
|
|
193
|
+
}}
|
|
194
|
+
/>
|
|
195
|
+
{options.length > 0 && (
|
|
196
|
+
<datalist id={listId}>
|
|
197
|
+
{options.map((option) => (
|
|
198
|
+
<option key={option} value={option} />
|
|
199
|
+
))}
|
|
200
|
+
</datalist>
|
|
201
|
+
)}
|
|
202
|
+
</>
|
|
203
|
+
);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/** The URL parameters the canvas previews with; they never reach the published page. */
|
|
207
|
+
function PreviewQuery() {
|
|
208
|
+
const live = useLiveData();
|
|
209
|
+
return (
|
|
210
|
+
<label className="emvb-bind-row" data-emvb-preview-query="">
|
|
211
|
+
<span className="emvb-bind-label">Preview URL parameters (editor only)</span>
|
|
212
|
+
<input
|
|
213
|
+
className="emvb-native-input"
|
|
214
|
+
style={{ gridColumn: "1 / -1" }}
|
|
215
|
+
placeholder="plan=pro&name=Ada"
|
|
216
|
+
value={live.query}
|
|
217
|
+
onChange={(event) => live.setQuery(event.target.value)}
|
|
218
|
+
/>
|
|
219
|
+
</label>
|
|
220
|
+
);
|
|
221
|
+
}
|
|
@@ -43,7 +43,7 @@ const optionKey = (option: ClassOption) =>
|
|
|
43
43
|
option.kind === "class" ? option.cls.id : `create-${option.name}`;
|
|
44
44
|
|
|
45
45
|
/**
|
|
46
|
-
* The Style tab's Classes field (W-087): a Local chip, one chip per
|
|
46
|
+
* The Style tab's Classes field (W-087, DESIGN.md "class chip input"): a Local chip, one chip per
|
|
47
47
|
* applied class in cascade order, and a combobox that suggests classes or creates one.
|
|
48
48
|
*/
|
|
49
49
|
export function ClassChipInput({
|
|
@@ -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,7 +11,7 @@ type Filter = NonNullable<StyleProps["filter"]>;
|
|
|
11
11
|
type Transition = NonNullable<StyleProps["transition"]>;
|
|
12
12
|
type Entrance = NonNullable<StyleProps["entrance"]>;
|
|
13
13
|
|
|
14
|
-
/** Add shadow starts at 0 4 12 0, 18 % black. */
|
|
14
|
+
/** DESIGN.md: Add shadow starts at 0 4 12 0, 18 % black. */
|
|
15
15
|
const NEW_SHADOW: Shadow = { x: 0, y: 4, blur: 12, spread: 0, color: "#0000002e" };
|
|
16
16
|
|
|
17
17
|
const OFFSET: NumberSpec = { min: -1000, max: 1000, example: "4" };
|
|
@@ -174,7 +174,7 @@ const APPLIES_TO: ReadonlyArray<{ value: Transition["property"]; label: string }
|
|
|
174
174
|
{ value: "filter", label: "Filters" },
|
|
175
175
|
];
|
|
176
176
|
|
|
177
|
-
function TransitionSelect<T extends string>({
|
|
177
|
+
export function TransitionSelect<T extends string>({
|
|
178
178
|
label,
|
|
179
179
|
value,
|
|
180
180
|
options,
|
|
@@ -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}
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
import { Button } from "@cloudflare/kumo";
|
|
2
|
+
import { PlusIcon, XIcon } from "@phosphor-icons/react";
|
|
3
|
+
import type * as React from "react";
|
|
4
|
+
import {
|
|
5
|
+
MOTION_EFFECTS,
|
|
6
|
+
MOTION_LIMITS,
|
|
7
|
+
type MotionEffect,
|
|
8
|
+
type StyleProps,
|
|
9
|
+
} from "../../../../core/index.ts";
|
|
10
|
+
import { BUTTON } from "../../../ui.ts";
|
|
11
|
+
import { TransitionSelect } from "./EffectsControls.tsx";
|
|
12
|
+
import { NumberField, type NumberSpec } from "./NumberRow.tsx";
|
|
13
|
+
|
|
14
|
+
type Motion = NonNullable<StyleProps["scrollMotion"]>;
|
|
15
|
+
type Playing = Extract<Motion, { effects: unknown }>;
|
|
16
|
+
type Effect = Playing["effects"][number];
|
|
17
|
+
|
|
18
|
+
const EFFECT_LABELS: Record<MotionEffect, { label: string; unit: string; neutral: number }> = {
|
|
19
|
+
fade: { label: "Opacity", unit: "%", neutral: 100 },
|
|
20
|
+
"move-x": { label: "Move sideways", unit: "px", neutral: 0 },
|
|
21
|
+
"move-y": { label: "Move up/down", unit: "px", neutral: 0 },
|
|
22
|
+
scale: { label: "Scale", unit: "%", neutral: 100 },
|
|
23
|
+
rotate: { label: "Rotate", unit: "°", neutral: 0 },
|
|
24
|
+
blur: { label: "Blur", unit: "px", neutral: 0 },
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const RANGES: { value: Playing["range"]; label: string }[] = [
|
|
28
|
+
{ value: "enter", label: "As it comes into view" },
|
|
29
|
+
{ value: "cross", label: "While it crosses the screen" },
|
|
30
|
+
{ value: "exit", label: "As it leaves the screen" },
|
|
31
|
+
{ value: "page", label: "Over the whole page scroll" },
|
|
32
|
+
];
|
|
33
|
+
|
|
34
|
+
/** Ready-made motions (W-319). Each is a plain value: pick one, then tune it. */
|
|
35
|
+
export const MOTION_PRESETS: { id: string; label: string; value: Playing }[] = [
|
|
36
|
+
{
|
|
37
|
+
id: "fade-in",
|
|
38
|
+
label: "Fade in",
|
|
39
|
+
value: { range: "enter", effects: [{ type: "fade", from: 0, to: 100 }] },
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
id: "rise",
|
|
43
|
+
label: "Rise in",
|
|
44
|
+
value: {
|
|
45
|
+
range: "enter",
|
|
46
|
+
effects: [
|
|
47
|
+
{ type: "fade", from: 0, to: 100 },
|
|
48
|
+
{ type: "move-y", from: 60, to: 0 },
|
|
49
|
+
],
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
id: "slide-left",
|
|
54
|
+
label: "Slide in from the side",
|
|
55
|
+
value: {
|
|
56
|
+
range: "enter",
|
|
57
|
+
effects: [
|
|
58
|
+
{ type: "fade", from: 0, to: 100 },
|
|
59
|
+
{ type: "move-x", from: -80, to: 0 },
|
|
60
|
+
],
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
id: "zoom",
|
|
65
|
+
label: "Zoom in",
|
|
66
|
+
value: { range: "enter", effects: [{ type: "scale", from: 80, to: 100 }] },
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
id: "parallax",
|
|
70
|
+
label: "Parallax",
|
|
71
|
+
value: { range: "cross", effects: [{ type: "move-y", from: 80, to: -80 }] },
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
id: "spin",
|
|
75
|
+
label: "Turn while scrolling",
|
|
76
|
+
value: { range: "cross", effects: [{ type: "rotate", from: -10, to: 10 }] },
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
id: "blur-in",
|
|
80
|
+
label: "Sharpen in",
|
|
81
|
+
value: { range: "enter", effects: [{ type: "blur", from: 12, to: 0 }] },
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
id: "fade-out",
|
|
85
|
+
label: "Fade out on leave",
|
|
86
|
+
value: { range: "exit", effects: [{ type: "fade", from: 100, to: 0 }] },
|
|
87
|
+
},
|
|
88
|
+
];
|
|
89
|
+
|
|
90
|
+
const specFor = (type: MotionEffect): NumberSpec => {
|
|
91
|
+
const [min, max] = MOTION_LIMITS[type];
|
|
92
|
+
return {
|
|
93
|
+
min,
|
|
94
|
+
max,
|
|
95
|
+
integer: true,
|
|
96
|
+
example: String(EFFECT_LABELS[type].neutral),
|
|
97
|
+
suffix: EFFECT_LABELS[type].unit,
|
|
98
|
+
};
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
/** The preset a value matches exactly, or "custom". */
|
|
102
|
+
export function presetOf(value: Playing): string {
|
|
103
|
+
const key = JSON.stringify(value);
|
|
104
|
+
return MOTION_PRESETS.find((p) => JSON.stringify(p.value) === key)?.id ?? "custom";
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Scroll motion (W-319, Normal only): a preset, when it plays and each effect's start and end.
|
|
109
|
+
* Plays with CSS scroll-driven animations; never for visitors who prefer reduced motion.
|
|
110
|
+
*/
|
|
111
|
+
export function MotionControl({
|
|
112
|
+
value,
|
|
113
|
+
onChange,
|
|
114
|
+
reset,
|
|
115
|
+
}: {
|
|
116
|
+
value: Motion | undefined;
|
|
117
|
+
onChange: (next: Motion | undefined) => void;
|
|
118
|
+
reset: React.ReactNode;
|
|
119
|
+
}) {
|
|
120
|
+
const playing = value && "effects" in value ? value : undefined;
|
|
121
|
+
const setEffects = (effects: Effect[]) => {
|
|
122
|
+
if (!playing) return;
|
|
123
|
+
onChange(effects.length > 0 ? { ...playing, effects } : undefined);
|
|
124
|
+
};
|
|
125
|
+
const unused = MOTION_EFFECTS.filter((t) => !playing?.effects.some((e) => e.type === t));
|
|
126
|
+
const presetOptions = [
|
|
127
|
+
...MOTION_PRESETS.map((p) => ({ value: p.id, label: p.label })),
|
|
128
|
+
...(playing && presetOf(playing) === "custom" ? [{ value: "custom", label: "Custom" }] : []),
|
|
129
|
+
];
|
|
130
|
+
return (
|
|
131
|
+
<div
|
|
132
|
+
className="emvb-style-row"
|
|
133
|
+
data-emvb-style="scrollMotion"
|
|
134
|
+
data-set={value ? "true" : undefined}
|
|
135
|
+
>
|
|
136
|
+
<div className="emvb-field-group emvb-transition emvb-motion">
|
|
137
|
+
<span className="emvb-var-field-label">Scroll motion</span>
|
|
138
|
+
{value && !playing && (
|
|
139
|
+
<p className="emvb-helper" data-emvb-motion-off="">
|
|
140
|
+
Off on this screen.
|
|
141
|
+
</p>
|
|
142
|
+
)}
|
|
143
|
+
{playing && (
|
|
144
|
+
<>
|
|
145
|
+
<TransitionSelect
|
|
146
|
+
label="Motion"
|
|
147
|
+
value={presetOf(playing)}
|
|
148
|
+
options={presetOptions}
|
|
149
|
+
onChange={(id) => {
|
|
150
|
+
const preset = MOTION_PRESETS.find((p) => p.id === id);
|
|
151
|
+
if (preset) onChange(structuredClone(preset.value));
|
|
152
|
+
}}
|
|
153
|
+
/>
|
|
154
|
+
<TransitionSelect
|
|
155
|
+
label="Plays"
|
|
156
|
+
value={playing.range}
|
|
157
|
+
options={RANGES}
|
|
158
|
+
onChange={(range) => onChange({ ...playing, range })}
|
|
159
|
+
/>
|
|
160
|
+
{playing.effects.map((effect, index) => (
|
|
161
|
+
<div className="emvb-motion-effect" key={effect.type} data-emvb-motion={effect.type}>
|
|
162
|
+
<span className="emvb-motion-name">{EFFECT_LABELS[effect.type].label}</span>
|
|
163
|
+
<NumberField
|
|
164
|
+
fieldKey={`scrollMotion.${effect.type}.from`}
|
|
165
|
+
label="From"
|
|
166
|
+
value={effect.from}
|
|
167
|
+
spec={specFor(effect.type)}
|
|
168
|
+
onCommit={(n) =>
|
|
169
|
+
setEffects(
|
|
170
|
+
playing.effects.with(index, {
|
|
171
|
+
...effect,
|
|
172
|
+
from: n ?? EFFECT_LABELS[effect.type].neutral,
|
|
173
|
+
}),
|
|
174
|
+
)
|
|
175
|
+
}
|
|
176
|
+
/>
|
|
177
|
+
<NumberField
|
|
178
|
+
fieldKey={`scrollMotion.${effect.type}.to`}
|
|
179
|
+
label="To"
|
|
180
|
+
value={effect.to}
|
|
181
|
+
spec={specFor(effect.type)}
|
|
182
|
+
onCommit={(n) =>
|
|
183
|
+
setEffects(
|
|
184
|
+
playing.effects.with(index, {
|
|
185
|
+
...effect,
|
|
186
|
+
to: n ?? EFFECT_LABELS[effect.type].neutral,
|
|
187
|
+
}),
|
|
188
|
+
)
|
|
189
|
+
}
|
|
190
|
+
/>
|
|
191
|
+
<Button
|
|
192
|
+
type="button"
|
|
193
|
+
variant="ghost"
|
|
194
|
+
shape="square"
|
|
195
|
+
className={BUTTON}
|
|
196
|
+
aria-label={`Remove ${EFFECT_LABELS[effect.type].label}`}
|
|
197
|
+
icon={<XIcon aria-hidden="true" />}
|
|
198
|
+
onClick={() => setEffects(playing.effects.filter((_, i) => i !== index))}
|
|
199
|
+
/>
|
|
200
|
+
</div>
|
|
201
|
+
))}
|
|
202
|
+
{unused.length > 0 && (
|
|
203
|
+
<TransitionSelect
|
|
204
|
+
label="Add effect"
|
|
205
|
+
value={"" as MotionEffect | ""}
|
|
206
|
+
options={[
|
|
207
|
+
{ value: "" as const, label: "Choose…" },
|
|
208
|
+
...unused.map((t) => ({ value: t, label: EFFECT_LABELS[t].label })),
|
|
209
|
+
]}
|
|
210
|
+
onChange={(type) => {
|
|
211
|
+
if (!type) return;
|
|
212
|
+
const n = EFFECT_LABELS[type].neutral;
|
|
213
|
+
setEffects([...playing.effects, { type, from: n, to: n }]);
|
|
214
|
+
}}
|
|
215
|
+
/>
|
|
216
|
+
)}
|
|
217
|
+
<p className="emvb-helper">
|
|
218
|
+
Plays as visitors scroll, in browsers that support scroll-driven animations. Visitors
|
|
219
|
+
who ask for reduced motion see it still.
|
|
220
|
+
</p>
|
|
221
|
+
</>
|
|
222
|
+
)}
|
|
223
|
+
{!value && (
|
|
224
|
+
<Button
|
|
225
|
+
type="button"
|
|
226
|
+
variant="secondary"
|
|
227
|
+
className={`${BUTTON} emvb-add-shadow`}
|
|
228
|
+
icon={<PlusIcon aria-hidden="true" />}
|
|
229
|
+
onClick={() =>
|
|
230
|
+
onChange(
|
|
231
|
+
structuredClone((MOTION_PRESETS[1] as (typeof MOTION_PRESETS)[number]).value),
|
|
232
|
+
)
|
|
233
|
+
}
|
|
234
|
+
>
|
|
235
|
+
Add scroll motion
|
|
236
|
+
</Button>
|
|
237
|
+
)}
|
|
238
|
+
{playing && (
|
|
239
|
+
<Button
|
|
240
|
+
type="button"
|
|
241
|
+
variant="ghost"
|
|
242
|
+
className={BUTTON}
|
|
243
|
+
onClick={() => onChange({ type: "none" })}
|
|
244
|
+
>
|
|
245
|
+
Turn off here
|
|
246
|
+
</Button>
|
|
247
|
+
)}
|
|
248
|
+
</div>
|
|
249
|
+
{reset}
|
|
250
|
+
</div>
|
|
251
|
+
);
|
|
252
|
+
}
|
|
@@ -18,7 +18,7 @@ const isChoice = (value: string): value is StyleStateChoice =>
|
|
|
18
18
|
(CHOICES as string[]).includes(value);
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
|
-
* The dot shown where state styles exist. Decorative on the state tabs,
|
|
21
|
+
* The dot shown where state styles exist (DESIGN.md § State styles). Decorative on the state tabs,
|
|
22
22
|
* so their names stay "Hover", "Focus" and "Active".
|
|
23
23
|
*/
|
|
24
24
|
export function StateDot({ decorative = false }: { decorative?: boolean }) {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Input, Select } from "@cloudflare/kumo";
|
|
2
|
+
import { MotionControl } from "./MotionControl.tsx";
|
|
2
3
|
import { isSafeFontStack, type DesignSystem, type StyleProps } from "../../../../core/index.ts";
|
|
3
4
|
import type { Fetcher } from "../../../api.ts";
|
|
4
5
|
import { FIELD } from "../../../ui.ts";
|
|
@@ -61,6 +62,7 @@ const LENGTH_KEYS = new Set<StyleKey>([
|
|
|
61
62
|
|
|
62
63
|
const Z_INDEX: NumberSpec = { min: -9999, max: 9999, integer: true, example: "10" };
|
|
63
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" };
|
|
64
66
|
const OPACITY: NumberSpec = { min: 0, max: 100, scale: 100, example: "50", suffix: "%" };
|
|
65
67
|
|
|
66
68
|
const COLOR_KEYS = new Set<StyleKey>(["color", "backgroundColor", "borderColor"]);
|
|
@@ -409,9 +411,18 @@ export function StyleRow({
|
|
|
409
411
|
styleKey === "zIndex" ||
|
|
410
412
|
styleKey === "opacity" ||
|
|
411
413
|
styleKey === "gridColumnSpan" ||
|
|
412
|
-
styleKey === "gridRowSpan"
|
|
414
|
+
styleKey === "gridRowSpan" ||
|
|
415
|
+
styleKey === "gridColumnStart" ||
|
|
416
|
+
styleKey === "gridRowStart"
|
|
413
417
|
) {
|
|
414
|
-
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;
|
|
415
426
|
return (
|
|
416
427
|
<NumberRow
|
|
417
428
|
rowKey={styleKey}
|
|
@@ -497,6 +508,16 @@ export function StyleRow({
|
|
|
497
508
|
);
|
|
498
509
|
}
|
|
499
510
|
|
|
511
|
+
if (styleKey === "scrollMotion") {
|
|
512
|
+
return (
|
|
513
|
+
<MotionControl
|
|
514
|
+
value={style?.scrollMotion}
|
|
515
|
+
onChange={(scrollMotion) => onPatch({ scrollMotion })}
|
|
516
|
+
reset={reset}
|
|
517
|
+
/>
|
|
518
|
+
);
|
|
519
|
+
}
|
|
520
|
+
|
|
500
521
|
if (styleKey === "transition") {
|
|
501
522
|
return (
|
|
502
523
|
<TransitionControl
|
|
@@ -542,11 +563,14 @@ export const IMPLEMENTED_STYLE_KEYS: StyleKey[] = [
|
|
|
542
563
|
"fontFamily",
|
|
543
564
|
"zIndex",
|
|
544
565
|
"gridColumnSpan",
|
|
566
|
+
"gridColumnStart",
|
|
545
567
|
"gridRowSpan",
|
|
568
|
+
"gridRowStart",
|
|
546
569
|
"opacity",
|
|
547
570
|
"boxShadow",
|
|
548
571
|
"filter",
|
|
549
572
|
"entrance",
|
|
573
|
+
"scrollMotion",
|
|
550
574
|
"transition",
|
|
551
575
|
"iconRotate",
|
|
552
576
|
"iconFlip",
|