@perkyzz/emvb 0.7.0 → 0.9.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 +3 -3
- package/THIRD_PARTY_NOTICES.md +1 -1
- package/package.json +7 -7
- package/src/admin/editor/DialogCloseButton.tsx +16 -0
- package/src/admin/editor/Editor.tsx +71 -1
- package/src/admin/editor/FieldPreview.tsx +164 -0
- package/src/admin/editor/PerfMeter.tsx +3 -9
- package/src/admin/editor/SavedSectionDialogs.tsx +169 -0
- package/src/admin/editor/ShareLink.tsx +2 -7
- package/src/admin/editor/ShortcutsDialog.tsx +19 -11
- package/src/admin/editor/Timeline.tsx +2 -7
- package/src/admin/editor/TopBar.tsx +32 -1
- package/src/admin/editor/dialogs.tsx +3 -14
- package/src/admin/editor/editor-chrome.tsx +8 -24
- package/src/admin/editor/editor-commands.ts +15 -1
- package/src/admin/editor/editor-css.ts +6 -2
- package/src/admin/editor/feature-css.ts +11 -1
- package/src/admin/editor/focus-when-lost.ts +23 -0
- package/src/admin/editor/host.ts +6 -0
- package/src/admin/editor/icons/IconLibraryDialog.tsx +2 -7
- package/src/admin/editor/palette-items.ts +17 -0
- package/src/admin/editor/panels/AddPanel.tsx +9 -1
- package/src/admin/editor/panels/ElementPanel.tsx +4 -1
- package/src/admin/editor/panels/LayersPanel.tsx +6 -1
- package/src/admin/editor/panels/LeftPanel.tsx +9 -1
- package/src/admin/editor/panels/SavedSectionsGroup.tsx +246 -0
- package/src/admin/editor/panels/SiteStylesDrawer.tsx +54 -10
- package/src/admin/editor/panels/TokenScales.tsx +16 -16
- package/src/admin/editor/panels/TriggersEditor.tsx +1 -1
- package/src/admin/editor/panels/color-space.ts +14 -26
- package/src/admin/editor/panels/settings/AudienceEditor.tsx +36 -39
- package/src/admin/editor/panels/settings/BackgroundControls.tsx +4 -5
- package/src/admin/editor/panels/settings/IconControls.tsx +21 -5
- package/src/admin/editor/panels/settings/LoopItemBindControl.tsx +1 -1
- package/src/admin/editor/panels/settings/MediaPicker.tsx +5 -5
- package/src/admin/editor/panels/settings/length-units.ts +2 -1
- package/src/admin/editor/shortcuts.ts +14 -0
- package/src/admin/editor/useSavedSections.ts +197 -0
- package/src/admin/image-editor/Canvas.tsx +61 -17
- package/src/admin/image-editor/ImageEditorDialog.tsx +130 -1
- package/src/admin/image-editor/image-editor-css.ts +11 -8
- package/src/admin/image-editor/parts.tsx +18 -17
- package/src/admin/image-editor/save.ts +31 -1
- package/src/admin/index.tsx +5 -1
- package/src/admin/media-api.ts +27 -0
- package/src/admin/pages/AgentsPage.tsx +3 -3
- package/src/admin/pages/CollectionsPage.tsx +215 -0
- package/src/admin/pages/ThemePartList.tsx +32 -4
- package/src/admin/saved-sections-api.ts +51 -0
- package/src/admin/setup/host-collections.ts +100 -0
- package/src/admin/theme-api.ts +3 -2
- package/src/admin/ui.ts +9 -0
- package/src/admin/widgets/CanvasField.tsx +202 -0
- package/src/admin/widgets/convert-body.ts +54 -0
- package/src/admin/widgets/field-fetcher.ts +79 -0
- package/src/astro/index.ts +2 -0
- package/src/astro/page-count.ts +77 -0
- package/src/astro/popups/runtime.ts +8 -6
- package/src/astro/resolve-theme.ts +44 -2
- package/src/astro/resolve.ts +40 -4
- package/src/astro/responsive-images.ts +99 -0
- package/src/constants.ts +1 -1
- package/src/core/a11y/audit.ts +32 -7
- package/src/core/arrange.ts +21 -6
- package/src/core/canvas-collections.ts +20 -0
- package/src/core/css/print.ts +5 -0
- package/src/core/design/classes.ts +23 -9
- package/src/core/design/devices.ts +7 -13
- package/src/core/design/states.ts +7 -13
- package/src/core/elements/dynamic-elements.ts +27 -12
- package/src/core/elements/index.ts +1 -1
- package/src/core/elements/menu.ts +3 -0
- package/src/core/icons/animation-runs.ts +11 -0
- package/src/core/index.ts +22 -0
- package/src/core/migrate/index.ts +3 -0
- package/src/core/portable-text.ts +127 -0
- package/src/core/render/loop.ts +1 -1
- package/src/core/render/pagination.ts +20 -1
- package/src/core/sanitize/css.ts +14 -6
- package/src/core/saved-sections.ts +318 -0
- package/src/core/schema/design.ts +1 -1
- package/src/core/schema/layout.ts +6 -1
- package/src/core/schema/style.ts +4 -2
- package/src/core/theme/float.ts +3 -0
- package/src/core/theme/pagination.ts +34 -24
- package/src/core/theme/part-types.ts +4 -4
- package/src/index.ts +11 -1
- package/src/mcp/ports.ts +22 -1
- package/src/mcp/read.ts +1 -1
- package/src/mcp/sections.ts +183 -0
- package/src/mcp/tools.ts +44 -0
- package/src/mcp/write.ts +4 -4
- package/src/server/agent-settings.ts +16 -1
- package/src/server/hooks.ts +81 -0
- package/src/server/mcp-routes.ts +2 -0
- package/src/server/plugin.ts +34 -5
- package/src/server/saved-sections.ts +163 -0
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import { Button, Input } from "@cloudflare/kumo";
|
|
2
|
+
import { PencilSimpleIcon, TrashIcon } from "@phosphor-icons/react";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { SAVED_SECTION_NAME_MAX } from "../../../core/index.ts";
|
|
5
|
+
import { matchesSearch } from "../../search.ts";
|
|
6
|
+
import { BUTTON, FIELD } from "../../ui.ts";
|
|
7
|
+
import { DeleteSavedSectionDialog } from "../SavedSectionDialogs.tsx";
|
|
8
|
+
import type { SavedSectionActions } from "../useSavedSections.ts";
|
|
9
|
+
|
|
10
|
+
/** Saved sections that match the Add panel's search. */
|
|
11
|
+
export const matchingSections = (saved: SavedSectionActions, query: string) =>
|
|
12
|
+
saved.list.filter((item) => matchesSearch(query, item.name, "my saved section"));
|
|
13
|
+
|
|
14
|
+
const focusIn = (root: HTMLElement | null, selector: string) =>
|
|
15
|
+
root?.querySelector<HTMLElement>(selector)?.focus({ preventScroll: false });
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* "My sections" in the Add panel (W-876): names only (D-060), filtered by the panel's search.
|
|
19
|
+
* A name inserts a copy; rename edits in place; delete asks first, then focus goes to the next
|
|
20
|
+
* section, the one before, the group heading when the list is empty, or the search field when
|
|
21
|
+
* the search no longer matches any section.
|
|
22
|
+
*/
|
|
23
|
+
export function SavedSectionsGroup({
|
|
24
|
+
saved,
|
|
25
|
+
query,
|
|
26
|
+
}: {
|
|
27
|
+
saved: SavedSectionActions;
|
|
28
|
+
query: string;
|
|
29
|
+
}) {
|
|
30
|
+
const groupRef = React.useRef<HTMLDivElement>(null);
|
|
31
|
+
const [renaming, setRenaming] = React.useState<string | null>(null);
|
|
32
|
+
const [renameError, setRenameError] = React.useState<string | null>(null);
|
|
33
|
+
const [asking, setAsking] = React.useState<string | null>(null);
|
|
34
|
+
const [deleteError, setDeleteError] = React.useState<string | null>(null);
|
|
35
|
+
/** Where focus goes once the delete dialog has closed. */
|
|
36
|
+
const focusAfter = React.useRef<string | null>(null);
|
|
37
|
+
/** A control to focus once the render that brings it back has committed. */
|
|
38
|
+
const [focusNext, setFocusNext] = React.useState<string | null>(null);
|
|
39
|
+
React.useEffect(() => {
|
|
40
|
+
if (!focusNext) return;
|
|
41
|
+
focusIn(groupRef.current, focusNext);
|
|
42
|
+
setFocusNext(null);
|
|
43
|
+
}, [focusNext]);
|
|
44
|
+
const items = matchingSections(saved, query);
|
|
45
|
+
if (query.trim() && items.length === 0) return null;
|
|
46
|
+
const askedName = saved.list.find((item) => item.id === asking)?.name ?? null;
|
|
47
|
+
|
|
48
|
+
const finishRename = async (id: string, value: string | null) => {
|
|
49
|
+
const current = saved.list.find((item) => item.id === id);
|
|
50
|
+
if (value === null || !current || value.trim() === current.name) {
|
|
51
|
+
setRenaming(null);
|
|
52
|
+
setRenameError(null);
|
|
53
|
+
setFocusNext(`[data-emvb-saved-rename="${id}"]`);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const failed = await saved.rename(id, value);
|
|
57
|
+
if (failed) {
|
|
58
|
+
setRenameError(failed);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
setRenaming(null);
|
|
62
|
+
setRenameError(null);
|
|
63
|
+
setFocusNext(`[data-emvb-saved-section="${id}"]`);
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const confirmDelete = async () => {
|
|
67
|
+
const id = asking;
|
|
68
|
+
if (!id) return;
|
|
69
|
+
const at = items.findIndex((item) => item.id === id);
|
|
70
|
+
const next = items[at + 1] ?? items[at - 1];
|
|
71
|
+
const panel = groupRef.current?.closest<HTMLElement>('[data-emvb-panel="add"]');
|
|
72
|
+
const failed = await saved.remove(id);
|
|
73
|
+
if (!failed && !next && query.trim()) {
|
|
74
|
+
// The search matches nothing here now, so the group (and its dialog) goes away: put focus
|
|
75
|
+
// back in the search field rather than on the page body.
|
|
76
|
+
setAsking(null);
|
|
77
|
+
const search = () => panel?.querySelector<HTMLElement>('input[type="search"]');
|
|
78
|
+
requestAnimationFrame(() => setTimeout(() => search()?.focus(), 0));
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
if (failed) {
|
|
82
|
+
setDeleteError(failed);
|
|
83
|
+
focusAfter.current = `[data-emvb-saved-delete="${id}"]`;
|
|
84
|
+
} else {
|
|
85
|
+
setDeleteError(null);
|
|
86
|
+
focusAfter.current = next
|
|
87
|
+
? `[data-emvb-saved-section="${next.id}"]`
|
|
88
|
+
: "[data-emvb-saved-title]";
|
|
89
|
+
}
|
|
90
|
+
setAsking(null);
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
return (
|
|
94
|
+
<div className="emvb-add-group" data-emvb-saved-sections="" ref={groupRef}>
|
|
95
|
+
<h3 className="emvb-add-group-title" tabIndex={-1} data-emvb-saved-title="">
|
|
96
|
+
My sections
|
|
97
|
+
</h3>
|
|
98
|
+
{!saved.loaded ? (
|
|
99
|
+
<p className="emvb-helper" role="status">
|
|
100
|
+
Loading My sections…
|
|
101
|
+
</p>
|
|
102
|
+
) : saved.loadError ? (
|
|
103
|
+
<div className="emvb-saved-error">
|
|
104
|
+
<p className="emvb-inline-error" role="alert">
|
|
105
|
+
{saved.loadError}
|
|
106
|
+
</p>
|
|
107
|
+
<Button type="button" variant="secondary" className={BUTTON} onClick={saved.refresh}>
|
|
108
|
+
Try again
|
|
109
|
+
</Button>
|
|
110
|
+
</div>
|
|
111
|
+
) : items.length === 0 ? (
|
|
112
|
+
<p className="emvb-helper" data-emvb-saved-empty="">
|
|
113
|
+
Save an element as a section from its ··· menu in Layers, or with Save as section in the
|
|
114
|
+
command palette.
|
|
115
|
+
</p>
|
|
116
|
+
) : (
|
|
117
|
+
<ul className="emvb-saved-list" aria-label="My sections">
|
|
118
|
+
{items.map((item) => (
|
|
119
|
+
<li key={item.id} className="emvb-saved-row">
|
|
120
|
+
{renaming === item.id ? (
|
|
121
|
+
<RenameField
|
|
122
|
+
initial={item.name}
|
|
123
|
+
error={renameError}
|
|
124
|
+
onDone={(value) => void finishRename(item.id, value)}
|
|
125
|
+
/>
|
|
126
|
+
) : (
|
|
127
|
+
<>
|
|
128
|
+
<button
|
|
129
|
+
type="button"
|
|
130
|
+
className="emvb-saved-name"
|
|
131
|
+
data-emvb-saved-section={item.id}
|
|
132
|
+
disabled={item.damaged}
|
|
133
|
+
title={
|
|
134
|
+
item.damaged ? "This saved section can't be read" : `Insert ${item.name}`
|
|
135
|
+
}
|
|
136
|
+
onClick={() => void saved.insert(item.id)}
|
|
137
|
+
>
|
|
138
|
+
{item.name}
|
|
139
|
+
{item.damaged && <span className="emvb-helper"> (can't be read)</span>}
|
|
140
|
+
</button>
|
|
141
|
+
<Button
|
|
142
|
+
type="button"
|
|
143
|
+
variant="ghost"
|
|
144
|
+
shape="square"
|
|
145
|
+
size="sm"
|
|
146
|
+
className="emvb-icon-btn"
|
|
147
|
+
aria-label={`Rename ${item.name}`}
|
|
148
|
+
title="Rename"
|
|
149
|
+
data-emvb-saved-rename={item.id}
|
|
150
|
+
disabled={item.damaged}
|
|
151
|
+
icon={<PencilSimpleIcon aria-hidden="true" />}
|
|
152
|
+
onClick={() => {
|
|
153
|
+
setRenameError(null);
|
|
154
|
+
setRenaming(item.id);
|
|
155
|
+
}}
|
|
156
|
+
/>
|
|
157
|
+
<Button
|
|
158
|
+
type="button"
|
|
159
|
+
variant="ghost"
|
|
160
|
+
shape="square"
|
|
161
|
+
size="sm"
|
|
162
|
+
className="emvb-icon-btn"
|
|
163
|
+
aria-label={`Delete ${item.name}`}
|
|
164
|
+
title="Delete"
|
|
165
|
+
data-emvb-saved-delete={item.id}
|
|
166
|
+
icon={<TrashIcon aria-hidden="true" />}
|
|
167
|
+
onClick={() => setAsking(item.id)}
|
|
168
|
+
/>
|
|
169
|
+
</>
|
|
170
|
+
)}
|
|
171
|
+
</li>
|
|
172
|
+
))}
|
|
173
|
+
</ul>
|
|
174
|
+
)}
|
|
175
|
+
{deleteError && (
|
|
176
|
+
<p className="emvb-inline-error" role="alert">
|
|
177
|
+
{deleteError}
|
|
178
|
+
</p>
|
|
179
|
+
)}
|
|
180
|
+
<DeleteSavedSectionDialog
|
|
181
|
+
name={askedName}
|
|
182
|
+
onOpenChange={(open) => {
|
|
183
|
+
if (open) return;
|
|
184
|
+
// Cancel or Escape: back to the row's Delete button.
|
|
185
|
+
if (asking && !focusAfter.current) {
|
|
186
|
+
focusAfter.current = `[data-emvb-saved-delete="${asking}"]`;
|
|
187
|
+
}
|
|
188
|
+
setAsking(null);
|
|
189
|
+
}}
|
|
190
|
+
onDelete={() => void confirmDelete()}
|
|
191
|
+
onClosed={() => {
|
|
192
|
+
const target = focusAfter.current;
|
|
193
|
+
focusAfter.current = null;
|
|
194
|
+
if (target) focusIn(groupRef.current, target);
|
|
195
|
+
}}
|
|
196
|
+
/>
|
|
197
|
+
</div>
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/** The inline name field: Enter or leaving saves, Escape cancels. */
|
|
202
|
+
function RenameField({
|
|
203
|
+
initial,
|
|
204
|
+
error,
|
|
205
|
+
onDone,
|
|
206
|
+
}: {
|
|
207
|
+
initial: string;
|
|
208
|
+
error: string | null;
|
|
209
|
+
onDone: (value: string | null) => void;
|
|
210
|
+
}) {
|
|
211
|
+
const [text, setText] = React.useState(initial);
|
|
212
|
+
const done = React.useRef(false);
|
|
213
|
+
const finish = (value: string | null) => {
|
|
214
|
+
if (done.current) return;
|
|
215
|
+
done.current = true;
|
|
216
|
+
onDone(value);
|
|
217
|
+
// A refused name stays open for another try.
|
|
218
|
+
requestAnimationFrame(() => {
|
|
219
|
+
done.current = false;
|
|
220
|
+
});
|
|
221
|
+
};
|
|
222
|
+
return (
|
|
223
|
+
<Input
|
|
224
|
+
aria-label="Section name"
|
|
225
|
+
className={`${FIELD} emvb-saved-rename`}
|
|
226
|
+
data-emvb-saved-rename-field=""
|
|
227
|
+
autoFocus
|
|
228
|
+
maxLength={SAVED_SECTION_NAME_MAX}
|
|
229
|
+
value={text}
|
|
230
|
+
error={error ?? undefined}
|
|
231
|
+
aria-invalid={error ? true : undefined}
|
|
232
|
+
onFocus={(event) => event.currentTarget.select()}
|
|
233
|
+
onChange={(event) => setText(event.target.value)}
|
|
234
|
+
onBlur={() => finish(text)}
|
|
235
|
+
onKeyDown={(event) => {
|
|
236
|
+
event.stopPropagation();
|
|
237
|
+
if (event.nativeEvent.isComposing || event.keyCode === 229) return;
|
|
238
|
+
if (event.key === "Enter") {
|
|
239
|
+
event.preventDefault();
|
|
240
|
+
finish(text);
|
|
241
|
+
}
|
|
242
|
+
if (event.key === "Escape") finish(null);
|
|
243
|
+
}}
|
|
244
|
+
/>
|
|
245
|
+
);
|
|
246
|
+
}
|
|
@@ -175,9 +175,9 @@ export function SiteStylesDrawer({
|
|
|
175
175
|
<h2 className="emvb-panel-title">Site styles</h2>
|
|
176
176
|
<p className="emvb-helper emvb-site-styles-subtitle" data-emvb-manager-label="">
|
|
177
177
|
{tab === "variables"
|
|
178
|
-
? "Variables
|
|
178
|
+
? "Variables manager"
|
|
179
179
|
: tab === "classes"
|
|
180
|
-
? "Classes
|
|
180
|
+
? "Classes manager"
|
|
181
181
|
: "Defaults"}
|
|
182
182
|
</p>
|
|
183
183
|
</div>
|
|
@@ -481,10 +481,26 @@ function DeleteConfirm({
|
|
|
481
481
|
: 0;
|
|
482
482
|
const noun = useEditedNoun();
|
|
483
483
|
const where = usedIn(pageUses, classUses, noun);
|
|
484
|
+
// W-849: the confirmation opened below the list with focus left on the closed row menu, so a
|
|
485
|
+
// keyboard or screen reader user didn't reach it. It takes focus on Cancel, the safe answer.
|
|
486
|
+
const cancelRef = React.useRef<HTMLButtonElement>(null);
|
|
487
|
+
const titleId = React.useId();
|
|
488
|
+
const bodyId = React.useId();
|
|
489
|
+
React.useEffect(() => {
|
|
490
|
+
cancelRef.current?.focus();
|
|
491
|
+
}, [confirm.kind, confirm.id]);
|
|
484
492
|
return (
|
|
485
|
-
<div
|
|
486
|
-
|
|
487
|
-
|
|
493
|
+
<div
|
|
494
|
+
className="emvb-site-confirm"
|
|
495
|
+
data-emvb-site-confirm=""
|
|
496
|
+
role="alertdialog"
|
|
497
|
+
aria-labelledby={titleId}
|
|
498
|
+
aria-describedby={bodyId}
|
|
499
|
+
>
|
|
500
|
+
<p className="emvb-field-label" id={titleId}>
|
|
501
|
+
Delete {confirm.name}?
|
|
502
|
+
</p>
|
|
503
|
+
<p className="emvb-helper" id={bodyId}>
|
|
488
504
|
{where
|
|
489
505
|
? `In use in ${where}. Deleting drops those bindings.`
|
|
490
506
|
: variable
|
|
@@ -493,7 +509,13 @@ function DeleteConfirm({
|
|
|
493
509
|
{NOT_CHECKED}
|
|
494
510
|
</p>
|
|
495
511
|
<div className="emvb-dialog-actions">
|
|
496
|
-
<Button
|
|
512
|
+
<Button
|
|
513
|
+
ref={cancelRef}
|
|
514
|
+
type="button"
|
|
515
|
+
variant="secondary"
|
|
516
|
+
className={BUTTON}
|
|
517
|
+
onClick={onCancel}
|
|
518
|
+
>
|
|
497
519
|
Cancel
|
|
498
520
|
</Button>
|
|
499
521
|
<Button
|
|
@@ -608,10 +630,26 @@ function ImportConfirm({
|
|
|
608
630
|
losses.classes > 0 ? plural(losses.classes, "class", "classes") : "",
|
|
609
631
|
losses.variables > 0 ? plural(losses.variables, "variable", "variables") : "",
|
|
610
632
|
].filter(Boolean);
|
|
633
|
+
// W-854: like the delete confirmation (W-849), it takes focus on Cancel, the safe answer, so a
|
|
634
|
+
// keyboard or screen reader user reaches it after picking the file.
|
|
635
|
+
const cancelRef = React.useRef<HTMLButtonElement>(null);
|
|
636
|
+
const titleId = React.useId();
|
|
637
|
+
const bodyId = React.useId();
|
|
638
|
+
React.useEffect(() => {
|
|
639
|
+
cancelRef.current?.focus();
|
|
640
|
+
}, [name]);
|
|
611
641
|
return (
|
|
612
|
-
<div
|
|
613
|
-
|
|
614
|
-
|
|
642
|
+
<div
|
|
643
|
+
className="emvb-site-confirm"
|
|
644
|
+
data-emvb-import-confirm=""
|
|
645
|
+
role="alertdialog"
|
|
646
|
+
aria-labelledby={titleId}
|
|
647
|
+
aria-describedby={bodyId}
|
|
648
|
+
>
|
|
649
|
+
<p className="emvb-field-label" id={titleId}>
|
|
650
|
+
Replace site styles with {name}?
|
|
651
|
+
</p>
|
|
652
|
+
<p className="emvb-helper" id={bodyId}>
|
|
615
653
|
{lost.length > 0
|
|
616
654
|
? `${lost.join(" and ")} that the file doesn't have will be removed. `
|
|
617
655
|
: "Every class and variable is replaced by the file's. "}
|
|
@@ -632,7 +670,13 @@ function ImportConfirm({
|
|
|
632
670
|
</p>
|
|
633
671
|
)}
|
|
634
672
|
<div className="emvb-dialog-actions">
|
|
635
|
-
<Button
|
|
673
|
+
<Button
|
|
674
|
+
ref={cancelRef}
|
|
675
|
+
type="button"
|
|
676
|
+
variant="secondary"
|
|
677
|
+
className={BUTTON}
|
|
678
|
+
onClick={onCancel}
|
|
679
|
+
>
|
|
636
680
|
Cancel
|
|
637
681
|
</Button>
|
|
638
682
|
<Button
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Checkbox, Input } from "@cloudflare/kumo";
|
|
1
2
|
import * as React from "react";
|
|
2
3
|
import {
|
|
3
4
|
applyTokens,
|
|
@@ -8,6 +9,7 @@ import {
|
|
|
8
9
|
type DesignSystem,
|
|
9
10
|
} from "../../../core/index.ts";
|
|
10
11
|
import { fieldNumber } from "./settings/number-input.ts";
|
|
12
|
+
import { FIELD } from "../../ui.ts";
|
|
11
13
|
import { PanelSelect } from "./settings/PanelSelect.tsx";
|
|
12
14
|
|
|
13
15
|
// W-436: the fields are labelled "(px)", so "18px" is 18.
|
|
@@ -90,8 +92,8 @@ export function TokenScales({
|
|
|
90
92
|
</div>
|
|
91
93
|
<label>
|
|
92
94
|
<span className="emvb-bind-label">{kind === "type" ? "Body size" : "Base gap"} (px)</span>
|
|
93
|
-
<
|
|
94
|
-
className=
|
|
95
|
+
<Input
|
|
96
|
+
className={FIELD}
|
|
95
97
|
inputMode="decimal"
|
|
96
98
|
value={base}
|
|
97
99
|
data-emvb-tokens-base=""
|
|
@@ -115,23 +117,21 @@ export function TokenScales({
|
|
|
115
117
|
/>
|
|
116
118
|
</div>
|
|
117
119
|
)}
|
|
118
|
-
<
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
Fluid
|
|
129
|
-
</label>
|
|
120
|
+
<Checkbox
|
|
121
|
+
className="emvb-tokens-fluid"
|
|
122
|
+
label="Fluid"
|
|
123
|
+
checked={fluid}
|
|
124
|
+
data-emvb-tokens-fluid=""
|
|
125
|
+
onCheckedChange={(checked) => {
|
|
126
|
+
setFluid(checked);
|
|
127
|
+
setDone(null);
|
|
128
|
+
}}
|
|
129
|
+
/>
|
|
130
130
|
{fluid && (
|
|
131
131
|
<label data-emvb-tokens-row="full">
|
|
132
132
|
<span className="emvb-bind-label">On small screens (px)</span>
|
|
133
|
-
<
|
|
134
|
-
className=
|
|
133
|
+
<Input
|
|
134
|
+
className={FIELD}
|
|
135
135
|
inputMode="decimal"
|
|
136
136
|
value={minBase}
|
|
137
137
|
data-emvb-tokens-min=""
|
|
@@ -66,7 +66,7 @@ function ShowTimesField({
|
|
|
66
66
|
type="number"
|
|
67
67
|
min={1}
|
|
68
68
|
max={100}
|
|
69
|
-
description="Leave empty for no limit. Counted per visitor's browser, up to 100."
|
|
69
|
+
description="Leave empty for no limit. Counted per visitor's browser, up to 100. A click trigger always opens."
|
|
70
70
|
value={draft}
|
|
71
71
|
onChange={(event) => setDraft(event.target.value)}
|
|
72
72
|
onBlur={commit}
|
|
@@ -72,19 +72,8 @@ export function parseRgb(text: string): Rgba | null {
|
|
|
72
72
|
.map((part) => (part.endsWith("%") ? (Number(part.slice(0, -1)) / 100) * 255 : Number(part)));
|
|
73
73
|
if (nums.some((n) => !Number.isFinite(n) || n < 0 || n > 255)) return null;
|
|
74
74
|
for (let i = 0; i < 3; i += 1) nums[i] = Math.round(nums[i] ?? 0);
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
if (alpha !== undefined) {
|
|
78
|
-
if (alpha.endsWith("%")) {
|
|
79
|
-
const pct = Number(alpha.slice(0, -1));
|
|
80
|
-
if (!Number.isFinite(pct) || pct < 0 || pct > 100) return null;
|
|
81
|
-
a = pct / 100;
|
|
82
|
-
} else {
|
|
83
|
-
const n = Number(alpha);
|
|
84
|
-
if (!Number.isFinite(n) || n < 0 || n > 1) return null;
|
|
85
|
-
a = n;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
75
|
+
const a = parseAlpha(parts[3]);
|
|
76
|
+
if (a === null) return null;
|
|
88
77
|
return { r: nums[0] ?? 0, g: nums[1] ?? 0, b: nums[2] ?? 0, a };
|
|
89
78
|
}
|
|
90
79
|
|
|
@@ -195,18 +184,17 @@ function readOklch(text: string): Oklch | null {
|
|
|
195
184
|
if (!Number.isFinite(l) || l < 0 || l > 100) return null;
|
|
196
185
|
if (!Number.isFinite(c) || c < 0 || c > 0.5) return null;
|
|
197
186
|
if (!Number.isFinite(h) || h < 0 || h > 360) return null;
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
if (alpha !== undefined) {
|
|
201
|
-
if (alpha.endsWith("%")) {
|
|
202
|
-
const pct = Number(alpha.slice(0, -1));
|
|
203
|
-
if (!Number.isFinite(pct) || pct < 0 || pct > 100) return null;
|
|
204
|
-
a = pct / 100;
|
|
205
|
-
} else {
|
|
206
|
-
const n = Number(alpha);
|
|
207
|
-
if (!Number.isFinite(n) || n < 0 || n > 1) return null;
|
|
208
|
-
a = n;
|
|
209
|
-
}
|
|
210
|
-
}
|
|
187
|
+
const a = parseAlpha(parts[3]);
|
|
188
|
+
if (a === null) return null;
|
|
211
189
|
return { l, c, h, a };
|
|
212
190
|
}
|
|
191
|
+
|
|
192
|
+
/** A CSS alpha (0–1 or 0%–100%); 1 when absent, null when out of range or not a number. */
|
|
193
|
+
function parseAlpha(alpha: string | undefined): number | null {
|
|
194
|
+
if (alpha === undefined) return 1;
|
|
195
|
+
const pct = alpha.endsWith("%");
|
|
196
|
+
const n = Number(pct ? alpha.slice(0, -1) : alpha);
|
|
197
|
+
const max = pct ? 100 : 1;
|
|
198
|
+
if (!Number.isFinite(n) || n < 0 || n > max) return null;
|
|
199
|
+
return pct ? n / 100 : n;
|
|
200
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Checkbox, Input } from "@cloudflare/kumo";
|
|
1
2
|
import * as React from "react";
|
|
2
3
|
import {
|
|
3
4
|
AUDIENCE_DEVICES,
|
|
@@ -5,6 +6,7 @@ import {
|
|
|
5
6
|
type Audience,
|
|
6
7
|
type LayoutNode,
|
|
7
8
|
} from "../../../../core/index.ts";
|
|
9
|
+
import { FIELD } from "../../../ui.ts";
|
|
8
10
|
import { PanelSelect } from "./PanelSelect.tsx";
|
|
9
11
|
|
|
10
12
|
const DAYS = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
|
|
@@ -133,8 +135,8 @@ export function AudienceEditor({
|
|
|
133
135
|
<>
|
|
134
136
|
<label className="emvb-bind-row">
|
|
135
137
|
<span className="emvb-bind-label">Countries (two-letter codes)</span>
|
|
136
|
-
<
|
|
137
|
-
className=
|
|
138
|
+
<Input
|
|
139
|
+
className={FIELD}
|
|
138
140
|
value={countryText}
|
|
139
141
|
placeholder="CA, US"
|
|
140
142
|
data-emvb-audience-countries=""
|
|
@@ -149,21 +151,18 @@ export function AudienceEditor({
|
|
|
149
151
|
<fieldset className="emvb-aud-checks">
|
|
150
152
|
<legend className="emvb-bind-label">Devices</legend>
|
|
151
153
|
{AUDIENCE_DEVICES.map((device) => (
|
|
152
|
-
<
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
{device[0]?.toUpperCase()}
|
|
165
|
-
{device.slice(1)}
|
|
166
|
-
</label>
|
|
154
|
+
<Checkbox
|
|
155
|
+
key={device}
|
|
156
|
+
label={`${device[0]?.toUpperCase() ?? ""}${device.slice(1)}`}
|
|
157
|
+
checked={base.devices?.includes(device) ?? false}
|
|
158
|
+
data-emvb-audience-device={device}
|
|
159
|
+
onCheckedChange={(checked) => {
|
|
160
|
+
const now = new Set(base.devices ?? []);
|
|
161
|
+
if (checked) now.add(device);
|
|
162
|
+
else now.delete(device);
|
|
163
|
+
set({ ...base, devices: AUDIENCE_DEVICES.filter((d) => now.has(d)) });
|
|
164
|
+
}}
|
|
165
|
+
/>
|
|
167
166
|
))}
|
|
168
167
|
</fieldset>
|
|
169
168
|
<div className="emvb-bind-row">
|
|
@@ -187,8 +186,8 @@ export function AudienceEditor({
|
|
|
187
186
|
</div>
|
|
188
187
|
<label className="emvb-bind-row">
|
|
189
188
|
<span className="emvb-bind-label">Segments (from your site)</span>
|
|
190
|
-
<
|
|
191
|
-
className=
|
|
189
|
+
<Input
|
|
190
|
+
className={FIELD}
|
|
192
191
|
value={segmentText}
|
|
193
192
|
placeholder="member, plan:pro"
|
|
194
193
|
data-emvb-audience-segments=""
|
|
@@ -241,8 +240,8 @@ export function AudienceEditor({
|
|
|
241
240
|
)}
|
|
242
241
|
<div className="emvb-bind-row">
|
|
243
242
|
<span className="emvb-bind-label">Hours (24 h, empty = all day)</span>
|
|
244
|
-
<
|
|
245
|
-
className=
|
|
243
|
+
<Input
|
|
244
|
+
className={FIELD}
|
|
246
245
|
type="number"
|
|
247
246
|
min={0}
|
|
248
247
|
max={23}
|
|
@@ -259,8 +258,8 @@ export function AudienceEditor({
|
|
|
259
258
|
set({ ...rest, hours: { from, to } });
|
|
260
259
|
}}
|
|
261
260
|
/>
|
|
262
|
-
<
|
|
263
|
-
className=
|
|
261
|
+
<Input
|
|
262
|
+
className={FIELD}
|
|
264
263
|
type="number"
|
|
265
264
|
min={0}
|
|
266
265
|
max={24}
|
|
@@ -280,27 +279,25 @@ export function AudienceEditor({
|
|
|
280
279
|
<fieldset className="emvb-aud-checks">
|
|
281
280
|
<legend className="emvb-bind-label">Days (none = every day)</legend>
|
|
282
281
|
{DAYS.map((day, index) => (
|
|
283
|
-
<
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
{day}
|
|
296
|
-
</label>
|
|
282
|
+
<Checkbox
|
|
283
|
+
key={day}
|
|
284
|
+
label={day}
|
|
285
|
+
checked={base.days?.includes(index) ?? false}
|
|
286
|
+
data-emvb-audience-day={index}
|
|
287
|
+
onCheckedChange={(checked) => {
|
|
288
|
+
const now = new Set(base.days ?? []);
|
|
289
|
+
if (checked) now.add(index);
|
|
290
|
+
else now.delete(index);
|
|
291
|
+
set({ ...base, days: DAYS.map((_d, i) => i).filter((i) => now.has(i)) });
|
|
292
|
+
}}
|
|
293
|
+
/>
|
|
297
294
|
))}
|
|
298
295
|
</fieldset>
|
|
299
296
|
{(base.hours || base.days) && (
|
|
300
297
|
<label className="emvb-bind-row">
|
|
301
298
|
<span className="emvb-bind-label">Time zone</span>
|
|
302
|
-
<
|
|
303
|
-
className=
|
|
299
|
+
<Input
|
|
300
|
+
className={FIELD}
|
|
304
301
|
value={zoneText}
|
|
305
302
|
placeholder="UTC"
|
|
306
303
|
data-emvb-audience-zone=""
|
|
@@ -85,10 +85,6 @@ export function BackgroundImageControl({
|
|
|
85
85
|
}
|
|
86
86
|
}, [fetcher, setBusy]);
|
|
87
87
|
|
|
88
|
-
React.useEffect(() => {
|
|
89
|
-
if (open) void loadLibrary();
|
|
90
|
-
}, [open, loadLibrary]);
|
|
91
|
-
|
|
92
88
|
const applyUrl = (next: string) => {
|
|
93
89
|
const safe = sanitizeMediaUrl(next);
|
|
94
90
|
if (!safe || /[()\\\s"'`]/.test(safe)) {
|
|
@@ -138,7 +134,10 @@ export function BackgroundImageControl({
|
|
|
138
134
|
type="button"
|
|
139
135
|
className={BUTTON}
|
|
140
136
|
onClick={() => {
|
|
141
|
-
if (
|
|
137
|
+
if (busyRef.current) return;
|
|
138
|
+
// W-906: load in the same update that opens it, so it never paints "No images yet." first.
|
|
139
|
+
setOpen(true);
|
|
140
|
+
void loadLibrary();
|
|
142
141
|
}}
|
|
143
142
|
aria-disabled={busy}
|
|
144
143
|
ref={libraryOpenerRef}
|
|
@@ -225,7 +225,7 @@ const DEFAULT_DURATION: Record<Looping["type"], number> = { spin: 2000, pulse: 1
|
|
|
225
225
|
const looping = (a: IconAnimation | undefined): Looping | undefined =>
|
|
226
226
|
a && a.type !== "none" ? a : undefined;
|
|
227
227
|
|
|
228
|
-
/** A
|
|
228
|
+
/** A spin or pulse (Normal only) that stops after about 5 s; reduced motion sees it still. */
|
|
229
229
|
const ANIMATION_LABELS: Record<string, string> = { none: "None", spin: "Spin", pulse: "Pulse" };
|
|
230
230
|
|
|
231
231
|
/**
|
|
@@ -264,7 +264,8 @@ export function IconAnimationControl({
|
|
|
264
264
|
setType(picked);
|
|
265
265
|
if (picked === "spin" || picked === "pulse") {
|
|
266
266
|
const duration = own?.duration ?? from?.duration ?? DEFAULT_DURATION[picked];
|
|
267
|
-
|
|
267
|
+
const loop = own?.loop ?? from?.loop;
|
|
268
|
+
onChange(loop ? { type: picked, duration, loop } : { type: picked, duration });
|
|
268
269
|
} else onChange(from ? { type: "none" } : undefined);
|
|
269
270
|
}}
|
|
270
271
|
>
|
|
@@ -281,11 +282,26 @@ export function IconAnimationControl({
|
|
|
281
282
|
onCommit={(n) => onChange({ ...own, duration: n ?? DEFAULT_DURATION[own.type] })}
|
|
282
283
|
/>
|
|
283
284
|
)}
|
|
284
|
-
{own &&
|
|
285
|
+
{own && (
|
|
286
|
+
<HintedSwitch
|
|
287
|
+
label="Loop forever"
|
|
288
|
+
checked={own.loop === true}
|
|
289
|
+
onCheckedChange={(loop) => {
|
|
290
|
+
const { loop: _old, ...rest } = own;
|
|
291
|
+
onChange(loop ? { ...rest, loop: true } : rest);
|
|
292
|
+
}}
|
|
293
|
+
data={{ "data-emvb-icon-loop": "" }}
|
|
294
|
+
hint={
|
|
295
|
+
own.loop
|
|
296
|
+
? "Keeps going, for a loading spinner. Off for visitors who prefer reduced motion."
|
|
297
|
+
: "Stops on its own after about 5 seconds. Off for visitors who prefer reduced motion."
|
|
298
|
+
}
|
|
299
|
+
/>
|
|
300
|
+
)}
|
|
285
301
|
{!value && from && (
|
|
286
302
|
<p className="emvb-helper">
|
|
287
|
-
Inherited from a wider device ({ANIMATION_LABELS[from.type]}, {from.duration} ms
|
|
288
|
-
None to stop it on this one.
|
|
303
|
+
Inherited from a wider device ({ANIMATION_LABELS[from.type]}, {from.duration} ms
|
|
304
|
+
{from.loop ? ", loops forever" : ""}). Pick None to stop it on this one.
|
|
289
305
|
</p>
|
|
290
306
|
)}
|
|
291
307
|
{value?.type === "none" && from && (
|