@perkyzz/emvb 0.5.0 → 0.7.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 -0
- package/THIRD_PARTY_NOTICES.md +23 -1
- package/licenses/exif-js.LICENSE +21 -0
- package/licenses/fflate.LICENSE +21 -0
- package/licenses/glfx.js.LICENSE +19 -0
- package/licenses/mini-photo-editor.LICENSE +21 -0
- package/licenses/photocn.LICENSE +21 -0
- package/package.json +2 -1
- package/src/admin/access/RequireEditor.tsx +7 -7
- package/src/admin/access/role.ts +5 -2
- package/src/admin/content-api.ts +10 -3
- package/src/admin/content-item.ts +1 -1
- package/src/admin/editor/A11yCopilot.tsx +104 -56
- package/src/admin/editor/CommandPalette.tsx +29 -13
- package/src/admin/editor/Editor.tsx +88 -20
- package/src/admin/editor/EditorToasts.tsx +26 -0
- package/src/admin/editor/PerfMeter.tsx +97 -72
- package/src/admin/editor/ShareLink.tsx +107 -72
- package/src/admin/editor/ShortcutsDialog.tsx +27 -16
- package/src/admin/editor/Timeline.tsx +255 -160
- package/src/admin/editor/TopBar.tsx +71 -14
- package/src/admin/editor/canvas/CanvasFrame.tsx +10 -1
- package/src/admin/editor/canvas/CanvasTextEdit.tsx +8 -2
- package/src/admin/editor/canvas/drop-line.ts +11 -3
- package/src/admin/editor/canvas/frame-focus-ring.ts +37 -0
- package/src/admin/editor/canvas/use-canvas-dnd.ts +32 -3
- package/src/admin/editor/canvas/vnode-react.tsx +7 -0
- package/src/admin/editor/collection-previews.ts +16 -1
- package/src/admin/editor/dialogs.tsx +38 -14
- package/src/admin/editor/dnd/drop-target.ts +26 -1
- package/src/admin/editor/edited-noun.ts +15 -0
- package/src/admin/editor/editor-chrome.tsx +108 -7
- package/src/admin/editor/editor-commands.ts +15 -1
- package/src/admin/editor/editor-css.ts +75 -22
- package/src/admin/editor/element-chrome.ts +21 -11
- package/src/admin/editor/feature-css.ts +45 -13
- package/src/admin/editor/icons/IconLibraryDialog.tsx +52 -11
- package/src/admin/editor/icons/library.ts +1 -1
- package/src/admin/editor/icons/use-icon-library.ts +5 -2
- package/src/admin/editor/ime.ts +29 -0
- package/src/admin/editor/palette-items.ts +10 -3
- package/src/admin/editor/panels/AddPanel.tsx +35 -10
- package/src/admin/editor/panels/ClassesSection.tsx +18 -7
- package/src/admin/editor/panels/ColorControl.tsx +135 -27
- package/src/admin/editor/panels/ConditionsEditor.tsx +52 -26
- package/src/admin/editor/panels/ElementPanel.tsx +134 -24
- package/src/admin/editor/panels/LayersPanel.tsx +68 -22
- package/src/admin/editor/panels/PageSettings.tsx +66 -35
- package/src/admin/editor/panels/SiteStylesDrawer.tsx +170 -32
- package/src/admin/editor/panels/TokenScales.tsx +76 -36
- package/src/admin/editor/panels/TriggerSettings.tsx +50 -12
- package/src/admin/editor/panels/TriggersEditor.tsx +2 -1
- package/src/admin/editor/panels/VariableSection.tsx +53 -21
- package/src/admin/editor/panels/color-space.ts +9 -3
- package/src/admin/editor/panels/settings/AdvancedFields.tsx +12 -2
- package/src/admin/editor/panels/settings/AudienceEditor.tsx +51 -35
- package/src/admin/editor/panels/settings/BackgroundControls.tsx +55 -11
- package/src/admin/editor/panels/settings/BackgroundFill.tsx +3 -2
- package/src/admin/editor/panels/settings/BindingsEditor.tsx +15 -18
- package/src/admin/editor/panels/settings/BoxControl.tsx +2 -1
- package/src/admin/editor/panels/settings/ClassChip.tsx +21 -9
- package/src/admin/editor/panels/settings/ClassChipInput.tsx +24 -16
- package/src/admin/editor/panels/settings/DraftTextField.tsx +41 -3
- package/src/admin/editor/panels/settings/EffectsControls.tsx +38 -14
- package/src/admin/editor/panels/settings/FieldBindControl.tsx +46 -28
- package/src/admin/editor/panels/settings/FieldControl.tsx +38 -15
- package/src/admin/editor/panels/settings/FormBindControl.tsx +2 -2
- package/src/admin/editor/panels/settings/HintedSwitch.tsx +33 -0
- package/src/admin/editor/panels/settings/IconControls.tsx +12 -8
- package/src/admin/editor/panels/settings/IconPicker.tsx +2 -0
- package/src/admin/editor/panels/settings/ImageSourcesField.tsx +3 -1
- package/src/admin/editor/panels/settings/ItemList.tsx +15 -2
- package/src/admin/editor/panels/settings/LengthRow.tsx +8 -6
- package/src/admin/editor/panels/settings/MediaPicker.tsx +274 -20
- package/src/admin/editor/panels/settings/MotionControl.tsx +28 -15
- package/src/admin/editor/panels/settings/NumberRow.tsx +9 -3
- package/src/admin/editor/panels/settings/PanelSelect.tsx +50 -0
- package/src/admin/editor/panels/settings/QueryStyleRows.tsx +25 -18
- package/src/admin/editor/panels/settings/RequiredFieldsNotice.tsx +141 -0
- package/src/admin/editor/panels/settings/StyleRow.tsx +10 -3
- package/src/admin/editor/panels/settings/StyleSources.tsx +4 -1
- package/src/admin/editor/panels/settings/VariantEditor.tsx +10 -1
- package/src/admin/editor/panels/settings/box-link-name.ts +6 -2
- package/src/admin/editor/panels/settings/class-suggest.ts +7 -7
- package/src/admin/editor/panels/settings/query-style.ts +38 -9
- package/src/admin/editor/panels/settings/svg-images.ts +13 -0
- package/src/admin/editor/panels/site-list.tsx +20 -6
- package/src/admin/editor/panels/variable-values.ts +25 -4
- package/src/admin/editor/restore-deleted.ts +21 -2
- package/src/admin/editor/section-templates.ts +81 -12
- package/src/admin/editor/shortcuts.ts +17 -2
- package/src/admin/editor/store.ts +14 -3
- package/src/admin/editor/useEditorCommands.ts +61 -15
- package/src/admin/editor/useEditorData.ts +4 -2
- package/src/admin/editor/useEditorShortcuts.ts +17 -7
- package/src/admin/editor/useNodeActions.ts +61 -6
- package/src/admin/editor/useSave.ts +22 -7
- package/src/admin/forms-api.ts +2 -0
- package/src/admin/image-editor/BlurFocus.tsx +112 -0
- package/src/admin/image-editor/Canvas.tsx +261 -0
- package/src/admin/image-editor/CropOverlay.tsx +390 -0
- package/src/admin/image-editor/CurvesPanel.tsx +395 -0
- package/src/admin/image-editor/ExportDialog.tsx +384 -0
- package/src/admin/image-editor/ImageEditButton.tsx +83 -0
- package/src/admin/image-editor/ImageEditorDialog.tsx +828 -0
- package/src/admin/image-editor/MetadataPanel.tsx +194 -0
- package/src/admin/image-editor/announce.tsx +65 -0
- package/src/admin/image-editor/crop-geometry.ts +162 -0
- package/src/admin/image-editor/curve-math.ts +177 -0
- package/src/admin/image-editor/data-url-fetch.ts +59 -0
- package/src/admin/image-editor/engine.ts +55 -0
- package/src/admin/image-editor/exif.ts +82 -0
- package/src/admin/image-editor/flatten.ts +54 -0
- package/src/admin/image-editor/gpu-fit.ts +81 -0
- package/src/admin/image-editor/image-editor-css.ts +400 -0
- package/src/admin/image-editor/load.ts +116 -0
- package/src/admin/image-editor/panels.tsx +287 -0
- package/src/admin/image-editor/parts.tsx +614 -0
- package/src/admin/image-editor/save.ts +141 -0
- package/src/admin/image-editor/tone-panels.tsx +338 -0
- package/src/admin/image-editor/tools.ts +59 -0
- package/src/admin/image-editor/worker.ts +111 -0
- package/src/admin/media-api.ts +114 -3
- package/src/admin/pages/AgentsPage.tsx +138 -27
- package/src/admin/pages/CreateDialog.tsx +97 -30
- package/src/admin/pages/NewPageDialog.tsx +21 -3
- package/src/admin/pages/NewThemePartDialog.tsx +11 -3
- package/src/admin/pages/PageList.tsx +14 -6
- package/src/admin/pages/SetupShell.tsx +28 -12
- package/src/admin/pages/ThemePartList.tsx +27 -7
- package/src/admin/pages/list-kit.tsx +106 -24
- package/src/admin/search.ts +15 -0
- package/src/admin/setup/useSetupStatus.ts +1 -1
- package/src/admin/theme-api.ts +13 -3
- package/src/admin/ui.ts +78 -22
- package/src/astro/EmVBPage.astro +11 -2
- package/src/astro/floats/runtime.ts +21 -0
- package/src/astro/menu/runtime.ts +34 -1
- package/src/astro/popups/runtime.ts +33 -3
- package/src/astro/render.ts +6 -0
- package/src/astro/resolve-theme.ts +67 -14
- package/src/astro/resolve.ts +9 -1
- package/src/astro/tabs/runtime.ts +12 -0
- package/src/astro/theme-posts.ts +2 -2
- package/src/astro/visitor.ts +6 -3
- package/src/constants.ts +1 -1
- package/src/core/a11y/audit.ts +171 -24
- package/src/core/arrange.ts +29 -6
- package/src/core/audience/rules.ts +5 -1
- package/src/core/audience/variants.ts +29 -3
- package/src/core/clipboard.ts +7 -0
- package/src/core/css/generate.ts +31 -6
- package/src/core/data/bindings.ts +19 -6
- package/src/core/design/classes.ts +20 -9
- package/src/core/design/diff.ts +9 -1
- package/src/core/design/merge.ts +93 -3
- package/src/core/design/tokens.ts +16 -2
- package/src/core/design/transfer.ts +46 -8
- package/src/core/design/variables.ts +32 -10
- package/src/core/elements/dynamic-elements.ts +53 -6
- package/src/core/elements/form-elements.ts +68 -30
- package/src/core/elements/index.ts +83 -38
- package/src/core/elements/menu.ts +37 -19
- package/src/core/elements/plain-text.ts +2 -2
- package/src/core/elements/select-prompt.ts +3 -0
- package/src/core/elements/svg-ids.ts +39 -0
- package/src/core/forms/binding.ts +190 -2
- package/src/core/forms/definition.ts +72 -0
- package/src/core/history/diff.ts +49 -4
- package/src/core/icons/catalog.ts +3 -2
- package/src/core/image-edit/schema.ts +155 -0
- package/src/core/image-edit/summary.ts +61 -0
- package/src/core/index.ts +29 -1
- package/src/core/limits.ts +21 -0
- package/src/core/migrate/index.ts +3 -1
- package/src/core/perf/meter.ts +51 -8
- package/src/core/recipes/index.ts +5 -4
- package/src/core/render/context.ts +8 -0
- package/src/core/render/dynamic-post.ts +71 -13
- package/src/core/render/extras.ts +77 -4
- package/src/core/render/form.ts +164 -12
- package/src/core/render/index.ts +179 -22
- package/src/core/render/loop.ts +43 -7
- package/src/core/render/pagination.ts +18 -4
- package/src/core/render/section.ts +27 -0
- package/src/core/render/tabs.ts +12 -3
- package/src/core/render/vnode.ts +1 -1
- package/src/core/sanitize/css.ts +15 -2
- package/src/core/sanitize/embed-url.ts +42 -5
- package/src/core/sanitize/url.ts +2 -1
- package/src/core/schema/layout.ts +26 -7
- package/src/core/share/link.ts +5 -2
- package/src/core/stable-json.ts +15 -0
- package/src/core/stats.ts +2 -1
- package/src/core/theme/conditions.ts +3 -1
- package/src/core/theme/dynamic.ts +57 -23
- package/src/core/theme/float.ts +9 -2
- package/src/core/theme/pagination.ts +57 -10
- package/src/core/theme/popup-markup.ts +23 -5
- package/src/core/theme/popup-rules.ts +11 -5
- package/src/core/theme/triggers.ts +3 -2
- package/src/core/tree-ops.ts +27 -0
- package/src/mcp/ports.ts +8 -1
- package/src/mcp/rate-limit.ts +2 -1
- package/src/mcp/read.ts +82 -3
- package/src/mcp/refs.ts +18 -0
- package/src/mcp/tools.ts +1 -1
- package/src/mcp/write.ts +271 -25
- package/src/server/agent-settings.ts +29 -4
- package/src/server/hooks.ts +5 -3
- package/src/server/icon-routes.ts +33 -9
- package/src/server/mcp-routes.ts +74 -11
|
@@ -1,15 +1,31 @@
|
|
|
1
|
-
import { Button, Input } from "@cloudflare/kumo";
|
|
1
|
+
import { Badge, Banner, Button, DropdownMenu, Input } from "@cloudflare/kumo";
|
|
2
|
+
import { DotsThreeIcon, MagicWandIcon, WarningCircleIcon } from "@phosphor-icons/react";
|
|
2
3
|
import * as React from "react";
|
|
3
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
ImageEdit,
|
|
6
|
+
sanitizeMediaUrl,
|
|
7
|
+
summarizeImageEdit,
|
|
8
|
+
type LayoutNode,
|
|
9
|
+
} from "../../../../core/index.ts";
|
|
4
10
|
import type { Fetcher } from "../../../api.ts";
|
|
5
11
|
import {
|
|
12
|
+
getMedia,
|
|
6
13
|
listImages,
|
|
7
14
|
propsFromMedia,
|
|
15
|
+
propsFromOriginal,
|
|
16
|
+
saveEditedCopy,
|
|
8
17
|
propsFromUrl,
|
|
9
18
|
uploadImage,
|
|
10
19
|
type MediaLibraryItem,
|
|
11
20
|
} from "../../../media-api.ts";
|
|
21
|
+
import {
|
|
22
|
+
ImageEditButton,
|
|
23
|
+
ImageEditorLauncher,
|
|
24
|
+
prefetchImageEditor,
|
|
25
|
+
} from "../../../image-editor/ImageEditButton.tsx";
|
|
26
|
+
import { editableSource } from "../../../image-editor/load.ts";
|
|
12
27
|
import { BUTTON, FIELD } from "../../../ui.ts";
|
|
28
|
+
import { isCommitEnter } from "../../ime.ts";
|
|
13
29
|
|
|
14
30
|
const propsOf = (node: LayoutNode): Record<string, unknown> =>
|
|
15
31
|
node.props as Record<string, unknown>;
|
|
@@ -23,21 +39,50 @@ type Props = {
|
|
|
23
39
|
onChange: (node: LayoutNode) => void;
|
|
24
40
|
/** Field label; Page settings uses "Social image" (W-287). */
|
|
25
41
|
label?: string;
|
|
42
|
+
/** Offer "Edit image" (Image elements only, W-482). */
|
|
43
|
+
editable?: boolean;
|
|
26
44
|
};
|
|
27
45
|
|
|
28
46
|
/**
|
|
29
47
|
* Image source control (W-024 / R-007): pick from EmDash media library, upload a file,
|
|
30
48
|
* or paste a URL. Upload uses the same POST /_emdash/api/media path on both demos.
|
|
31
49
|
*/
|
|
32
|
-
|
|
50
|
+
|
|
51
|
+
/** W-492: Reset to original when the original was deleted from the library. */
|
|
52
|
+
const ORIGINAL_DELETED =
|
|
53
|
+
"The original picture was deleted from the media library, so this image can't be reset. It keeps the edited copy.";
|
|
54
|
+
|
|
55
|
+
export function MediaPicker({ node, fetcher, onChange, label = "Image", editable = false }: Props) {
|
|
33
56
|
const props = propsOf(node);
|
|
34
57
|
const src = typeof props.src === "string" ? props.src : "";
|
|
35
58
|
const [open, setOpen] = React.useState(false);
|
|
36
59
|
const [items, setItems] = React.useState<MediaLibraryItem[]>([]);
|
|
37
|
-
const [
|
|
60
|
+
const [libraryError, setLibraryError] = React.useState<string | null>(null);
|
|
61
|
+
const [busy, setBusyState] = React.useState(false);
|
|
62
|
+
// W-819: the source buttons stay focusable while busy (aria-disabled, presses ignored), so
|
|
63
|
+
// keyboard focus no longer drops to the page body during an upload; the ref answers at once.
|
|
64
|
+
const busyRef = React.useRef(false);
|
|
65
|
+
const setBusy = React.useCallback((next: boolean) => {
|
|
66
|
+
busyRef.current = next;
|
|
67
|
+
setBusyState(next);
|
|
68
|
+
}, []);
|
|
38
69
|
const [error, setError] = React.useState<string | null>(null);
|
|
39
70
|
const [urlDraft, setUrlDraft] = React.useState(src);
|
|
40
71
|
const fileRef = React.useRef<HTMLInputElement>(null);
|
|
72
|
+
const libraryCloseRef = React.useRef<HTMLButtonElement>(null);
|
|
73
|
+
const libraryOpenerRef = React.useRef<HTMLButtonElement>(null);
|
|
74
|
+
const urlInputRef = React.useRef<HTMLInputElement>(null);
|
|
75
|
+
// W-486: a library picture opened from its card's Edit… (null when the editor is closed).
|
|
76
|
+
const [editing, setEditing] = React.useState<MediaLibraryItem | null>(null);
|
|
77
|
+
const [editorOpen, setEditorOpen] = React.useState(false);
|
|
78
|
+
const currentNode = React.useRef<LayoutNode | null>(node);
|
|
79
|
+
|
|
80
|
+
React.useEffect(() => {
|
|
81
|
+
currentNode.current = node;
|
|
82
|
+
return () => {
|
|
83
|
+
currentNode.current = null;
|
|
84
|
+
};
|
|
85
|
+
}, [node]);
|
|
41
86
|
|
|
42
87
|
React.useEffect(() => {
|
|
43
88
|
setUrlDraft(src);
|
|
@@ -45,25 +90,103 @@ export function MediaPicker({ node, fetcher, onChange, label = "Image" }: Props)
|
|
|
45
90
|
|
|
46
91
|
const loadLibrary = React.useCallback(async () => {
|
|
47
92
|
setBusy(true);
|
|
48
|
-
|
|
93
|
+
setLibraryError(null);
|
|
49
94
|
try {
|
|
50
95
|
setItems(await listImages(fetcher, { limit: 40 }));
|
|
51
96
|
} catch (caught) {
|
|
52
|
-
|
|
97
|
+
setLibraryError(
|
|
98
|
+
caught instanceof Error ? caught.message : "Couldn't load the media library.",
|
|
99
|
+
);
|
|
53
100
|
setItems([]);
|
|
54
101
|
} finally {
|
|
55
102
|
setBusy(false);
|
|
56
103
|
}
|
|
57
|
-
}, [fetcher]);
|
|
104
|
+
}, [fetcher, setBusy]);
|
|
58
105
|
|
|
59
106
|
React.useEffect(() => {
|
|
60
107
|
if (open) void loadLibrary();
|
|
61
108
|
}, [open, loadLibrary]);
|
|
62
109
|
|
|
63
|
-
|
|
64
|
-
|
|
110
|
+
/** Focus Choose from library, or the URL field while the picker is busy (W-741). */
|
|
111
|
+
const focusOpener = () => {
|
|
112
|
+
const opener = libraryOpenerRef.current;
|
|
113
|
+
const target = busyRef.current ? urlInputRef.current : opener;
|
|
114
|
+
target?.focus();
|
|
115
|
+
};
|
|
116
|
+
const closeLibrary = () => {
|
|
117
|
+
setOpen(false);
|
|
118
|
+
focusOpener();
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
const libraryRef = React.useRef<HTMLDivElement>(null);
|
|
122
|
+
|
|
123
|
+
const edit = ImageEdit.safeParse(props.edit);
|
|
124
|
+
/** W-487: say why a picture can't be edited instead of offering a button that fails. */
|
|
125
|
+
const editCheck = src ? editableSource(props, window.location.origin) : null;
|
|
126
|
+
const editSummary = edit.success ? summarizeImageEdit(edit.data.recipe, 12) || "Edited" : null;
|
|
127
|
+
|
|
128
|
+
/** W-485: upload the edited copy as a new item; the original stays in the library. */
|
|
129
|
+
const saveCopy = async (file: File, copy: { width: number; height: number; edit: unknown }) => {
|
|
130
|
+
onChange(withProps(node, await saveEditedCopy(fetcher, props, file, copy)));
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
/** The props the element would have with this library picture (stable while editing). */
|
|
134
|
+
const editingProps = React.useMemo(
|
|
135
|
+
() => (editing ? propsFromMedia(props, editing) : null),
|
|
136
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps -- only a new card opens a new edit.
|
|
137
|
+
[editing],
|
|
138
|
+
);
|
|
139
|
+
|
|
140
|
+
/** W-486: Edit… saves a copy of the card's picture and selects it for this element. */
|
|
141
|
+
const saveLibraryCopy = async (
|
|
142
|
+
file: File,
|
|
143
|
+
copy: { width: number; height: number; edit: unknown },
|
|
144
|
+
) => {
|
|
145
|
+
if (!editingProps) return;
|
|
146
|
+
onChange(withProps(node, await saveEditedCopy(fetcher, editingProps, file, copy)));
|
|
147
|
+
setOpen(false);
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
const imageTarget = () => {
|
|
151
|
+
const current = currentNode.current;
|
|
152
|
+
if (!current || current.id !== node.id) return null;
|
|
153
|
+
const latestProps = propsOf(current);
|
|
154
|
+
return latestProps.src === props.src && latestProps.edit === props.edit ? current : null;
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
/** W-485: back to the untouched original; the edited copy is not deleted. */
|
|
158
|
+
const resetToOriginal = async () => {
|
|
159
|
+
if (!edit.success) return;
|
|
160
|
+
setBusy(true);
|
|
161
|
+
setError(null);
|
|
162
|
+
try {
|
|
163
|
+
const id = edit.data.originalMediaId;
|
|
164
|
+
// W-492: a failed lookup is an error, not "no original"; a deleted original can't be reset
|
|
165
|
+
// to (its recorded URL is gone too), so the element keeps the edited copy.
|
|
166
|
+
const original = id ? await getMedia(fetcher, id) : null;
|
|
167
|
+
const target = imageTarget();
|
|
168
|
+
if (!target) return;
|
|
169
|
+
if (id && !original) {
|
|
170
|
+
setError(ORIGINAL_DELETED);
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
const next = propsFromOriginal(propsOf(target), original);
|
|
174
|
+
if (next) onChange(withProps(target, next));
|
|
175
|
+
} catch (caught) {
|
|
176
|
+
if (!imageTarget()) return;
|
|
177
|
+
setError(
|
|
178
|
+
`Couldn't reach the media library to find the original.${caught instanceof Error && caught.message ? ` ${caught.message}` : ""}`,
|
|
179
|
+
);
|
|
180
|
+
} finally {
|
|
181
|
+
setBusy(false);
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
const applyItem = (item: MediaLibraryItem, target: LayoutNode = node) => {
|
|
186
|
+
onChange(withProps(target, propsFromMedia(propsOf(target), item)));
|
|
65
187
|
setOpen(false);
|
|
66
188
|
setError(null);
|
|
189
|
+
focusOpener();
|
|
67
190
|
};
|
|
68
191
|
|
|
69
192
|
const onUpload = async (file: File | undefined) => {
|
|
@@ -75,8 +198,10 @@ export function MediaPicker({ node, fetcher, onChange, label = "Image" }: Props)
|
|
|
75
198
|
() => ({}) as { width?: number; height?: number },
|
|
76
199
|
);
|
|
77
200
|
const item = await uploadImage(fetcher, file, dims);
|
|
78
|
-
|
|
201
|
+
const target = imageTarget();
|
|
202
|
+
if (target) applyItem(item, target);
|
|
79
203
|
} catch (caught) {
|
|
204
|
+
if (!imageTarget()) return;
|
|
80
205
|
setError(caught instanceof Error ? caught.message : "Upload failed.");
|
|
81
206
|
} finally {
|
|
82
207
|
setBusy(false);
|
|
@@ -114,6 +239,14 @@ export function MediaPicker({ node, fetcher, onChange, label = "Image" }: Props)
|
|
|
114
239
|
<div className="emvb-media-preview">
|
|
115
240
|
<img src={src} alt="" className="emvb-media-thumb" />
|
|
116
241
|
<span className="emvb-helper emvb-mono">{src}</span>
|
|
242
|
+
{editSummary ? (
|
|
243
|
+
<span className="emvb-media-edited" data-emvb-image-edited="">
|
|
244
|
+
<Badge variant="neutral">Edited</Badge>
|
|
245
|
+
<span className="emvb-helper" data-emvb-image-edit-summary="">
|
|
246
|
+
{editSummary}
|
|
247
|
+
</span>
|
|
248
|
+
</span>
|
|
249
|
+
) : null}
|
|
117
250
|
</div>
|
|
118
251
|
) : (
|
|
119
252
|
<p className="emvb-helper">No image selected yet.</p>
|
|
@@ -122,8 +255,11 @@ export function MediaPicker({ node, fetcher, onChange, label = "Image" }: Props)
|
|
|
122
255
|
<Button
|
|
123
256
|
type="button"
|
|
124
257
|
className={BUTTON}
|
|
125
|
-
onClick={() =>
|
|
126
|
-
|
|
258
|
+
onClick={() => {
|
|
259
|
+
if (!busyRef.current) setOpen(true);
|
|
260
|
+
}}
|
|
261
|
+
aria-disabled={busy}
|
|
262
|
+
ref={libraryOpenerRef}
|
|
127
263
|
data-emvb-media-library=""
|
|
128
264
|
>
|
|
129
265
|
Choose from library
|
|
@@ -132,22 +268,50 @@ export function MediaPicker({ node, fetcher, onChange, label = "Image" }: Props)
|
|
|
132
268
|
type="button"
|
|
133
269
|
className={BUTTON}
|
|
134
270
|
variant="secondary"
|
|
135
|
-
onClick={() =>
|
|
136
|
-
|
|
271
|
+
onClick={() => {
|
|
272
|
+
if (!busyRef.current) fileRef.current?.click();
|
|
273
|
+
}}
|
|
274
|
+
aria-disabled={busy}
|
|
137
275
|
data-emvb-media-upload-btn=""
|
|
138
276
|
>
|
|
139
277
|
Upload
|
|
140
278
|
</Button>
|
|
279
|
+
{editable && src && editCheck?.ok ? (
|
|
280
|
+
<ImageEditButton imageProps={props} onSave={saveCopy} />
|
|
281
|
+
) : null}
|
|
282
|
+
{editable && edit.success ? (
|
|
283
|
+
<Button
|
|
284
|
+
type="button"
|
|
285
|
+
className={BUTTON}
|
|
286
|
+
variant="ghost"
|
|
287
|
+
onClick={() => {
|
|
288
|
+
if (!busyRef.current) void resetToOriginal();
|
|
289
|
+
}}
|
|
290
|
+
aria-disabled={busy}
|
|
291
|
+
data-emvb-image-reset-original=""
|
|
292
|
+
>
|
|
293
|
+
Reset to original
|
|
294
|
+
</Button>
|
|
295
|
+
) : null}
|
|
141
296
|
<input
|
|
142
297
|
ref={fileRef}
|
|
143
298
|
type="file"
|
|
144
299
|
accept="image/png,image/jpeg,image/gif,image/webp,image/avif"
|
|
145
300
|
className="emvb-sr-only"
|
|
301
|
+
// UX-050: the Upload button is the control; this input only opens the file dialog.
|
|
302
|
+
tabIndex={-1}
|
|
303
|
+
aria-hidden="true"
|
|
146
304
|
data-emvb-media-upload=""
|
|
147
305
|
onChange={(event) => void onUpload(event.target.files?.[0])}
|
|
148
306
|
/>
|
|
149
307
|
</div>
|
|
308
|
+
{editable && src && editCheck && !editCheck.ok ? (
|
|
309
|
+
<p className="emvb-helper" data-emvb-image-cant-edit={editCheck.reason}>
|
|
310
|
+
{editCheck.message}
|
|
311
|
+
</p>
|
|
312
|
+
) : null}
|
|
150
313
|
<Input
|
|
314
|
+
ref={urlInputRef}
|
|
151
315
|
label="Or paste a URL"
|
|
152
316
|
className={FIELD}
|
|
153
317
|
value={urlDraft}
|
|
@@ -156,15 +320,24 @@ export function MediaPicker({ node, fetcher, onChange, label = "Image" }: Props)
|
|
|
156
320
|
onChange={(event) => setUrlDraft(event.target.value)}
|
|
157
321
|
onBlur={() => commitUrl(false)}
|
|
158
322
|
onKeyDown={(event) => {
|
|
159
|
-
if (event
|
|
323
|
+
if (isCommitEnter(event)) commitUrl(true);
|
|
160
324
|
}}
|
|
161
325
|
/>
|
|
162
326
|
{open && (
|
|
163
327
|
<div
|
|
164
328
|
className="emvb-media-dialog"
|
|
329
|
+
ref={libraryRef}
|
|
165
330
|
role="dialog"
|
|
166
331
|
aria-label="Media library"
|
|
167
332
|
data-emvb-media-dialog=""
|
|
333
|
+
onKeyDown={(event) => {
|
|
334
|
+
// W-817: Escape left the library open; it closes it like Close does. The editor's
|
|
335
|
+
// own Escape (deselect) must not also run.
|
|
336
|
+
if (event.key !== "Escape" || event.defaultPrevented) return;
|
|
337
|
+
event.preventDefault();
|
|
338
|
+
event.stopPropagation();
|
|
339
|
+
closeLibrary();
|
|
340
|
+
}}
|
|
168
341
|
>
|
|
169
342
|
<div className="emvb-media-dialog-head">
|
|
170
343
|
<h3 className="emvb-panel-title">Media library</h3>
|
|
@@ -172,32 +345,107 @@ export function MediaPicker({ node, fetcher, onChange, label = "Image" }: Props)
|
|
|
172
345
|
type="button"
|
|
173
346
|
className={BUTTON}
|
|
174
347
|
variant="secondary"
|
|
175
|
-
|
|
348
|
+
ref={libraryCloseRef}
|
|
349
|
+
autoFocus
|
|
350
|
+
onClick={closeLibrary}
|
|
176
351
|
>
|
|
177
352
|
Close
|
|
178
353
|
</Button>
|
|
179
354
|
</div>
|
|
180
|
-
{busy &&
|
|
181
|
-
|
|
355
|
+
{busy && (
|
|
356
|
+
<p className="emvb-helper" role="status">
|
|
357
|
+
Loading…
|
|
358
|
+
</p>
|
|
359
|
+
)}
|
|
360
|
+
{!busy && libraryError && (
|
|
361
|
+
<Banner
|
|
362
|
+
role="alert"
|
|
363
|
+
variant="error"
|
|
364
|
+
icon={<WarningCircleIcon aria-hidden="true" />}
|
|
365
|
+
title="Couldn't load the media library"
|
|
366
|
+
description={libraryError}
|
|
367
|
+
action={
|
|
368
|
+
<Button
|
|
369
|
+
type="button"
|
|
370
|
+
variant="secondary"
|
|
371
|
+
className={BUTTON}
|
|
372
|
+
onClick={() => {
|
|
373
|
+
libraryCloseRef.current?.focus();
|
|
374
|
+
void loadLibrary();
|
|
375
|
+
}}
|
|
376
|
+
>
|
|
377
|
+
Retry
|
|
378
|
+
</Button>
|
|
379
|
+
}
|
|
380
|
+
/>
|
|
381
|
+
)}
|
|
382
|
+
{!busy && !libraryError && items.length === 0 && (
|
|
182
383
|
<p className="emvb-helper">No images yet. Upload one to get started.</p>
|
|
183
384
|
)}
|
|
184
385
|
<ul className="emvb-media-grid">
|
|
185
386
|
{items.map((item) => (
|
|
186
|
-
<li key={item.id}>
|
|
387
|
+
<li key={item.id} className="emvb-media-cell">
|
|
187
388
|
<button
|
|
188
389
|
type="button"
|
|
189
390
|
className="emvb-media-card"
|
|
190
391
|
data-emvb-media-id={item.id}
|
|
191
392
|
onClick={() => applyItem(item)}
|
|
192
393
|
>
|
|
193
|
-
|
|
394
|
+
{/* W-762: the file name is already the label, so no alt repeats it. */}
|
|
395
|
+
<img
|
|
396
|
+
src={item.url}
|
|
397
|
+
alt={item.alt && item.alt !== item.filename ? item.alt : ""}
|
|
398
|
+
/>
|
|
194
399
|
<span>{item.filename}</span>
|
|
195
400
|
</button>
|
|
401
|
+
{editable && canEdit(item) ? (
|
|
402
|
+
<DropdownMenu onOpenChange={(next) => next && prefetchImageEditor()}>
|
|
403
|
+
<DropdownMenu.Trigger
|
|
404
|
+
render={
|
|
405
|
+
<Button
|
|
406
|
+
type="button"
|
|
407
|
+
variant="secondary"
|
|
408
|
+
size="sm"
|
|
409
|
+
shape="square"
|
|
410
|
+
className="emvb-media-card-menu"
|
|
411
|
+
aria-label={`More for ${item.alt || item.filename}`}
|
|
412
|
+
icon={<DotsThreeIcon aria-hidden="true" weight="bold" />}
|
|
413
|
+
data-emvb-media-menu={item.id}
|
|
414
|
+
/>
|
|
415
|
+
}
|
|
416
|
+
/>
|
|
417
|
+
<DropdownMenu.Content align="end">
|
|
418
|
+
<DropdownMenu.Item
|
|
419
|
+
icon={MagicWandIcon}
|
|
420
|
+
onClick={() => {
|
|
421
|
+
setEditing(item);
|
|
422
|
+
setEditorOpen(true);
|
|
423
|
+
}}
|
|
424
|
+
data-emvb-media-edit={item.id}
|
|
425
|
+
>
|
|
426
|
+
Edit…
|
|
427
|
+
</DropdownMenu.Item>
|
|
428
|
+
</DropdownMenu.Content>
|
|
429
|
+
</DropdownMenu>
|
|
430
|
+
) : null}
|
|
196
431
|
</li>
|
|
197
432
|
))}
|
|
198
433
|
</ul>
|
|
199
434
|
</div>
|
|
200
435
|
)}
|
|
436
|
+
{editingProps ? (
|
|
437
|
+
<ImageEditorLauncher
|
|
438
|
+
open={editorOpen}
|
|
439
|
+
onOpenChange={setEditorOpen}
|
|
440
|
+
imageProps={editingProps}
|
|
441
|
+
onSave={saveLibraryCopy}
|
|
442
|
+
onClosed={() => {
|
|
443
|
+
setEditing(null);
|
|
444
|
+
// W-745: a saved copy closes the library, so the card menu that opened the editor is gone.
|
|
445
|
+
if (!libraryRef.current) focusOpener();
|
|
446
|
+
}}
|
|
447
|
+
/>
|
|
448
|
+
) : null}
|
|
201
449
|
</div>
|
|
202
450
|
);
|
|
203
451
|
}
|
|
@@ -217,3 +465,9 @@ function readImageSize(file: File): Promise<{ width: number; height: number }> {
|
|
|
217
465
|
img.src = url;
|
|
218
466
|
});
|
|
219
467
|
}
|
|
468
|
+
|
|
469
|
+
/** Library pictures the editor can open: same-site JPEG, PNG, WebP or AVIF (not SVG or GIF). */
|
|
470
|
+
function canEdit(item: MediaLibraryItem): boolean {
|
|
471
|
+
if (/svg|gif/i.test(item.mimeType)) return false;
|
|
472
|
+
return editableSource({ src: item.url }, window.location.origin).ok;
|
|
473
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Button } from "@cloudflare/kumo";
|
|
1
|
+
import { Button, DropdownMenu } from "@cloudflare/kumo";
|
|
2
2
|
import { PlusIcon, XIcon } from "@phosphor-icons/react";
|
|
3
3
|
import type * as React from "react";
|
|
4
4
|
import {
|
|
@@ -200,19 +200,32 @@ export function MotionControl({
|
|
|
200
200
|
</div>
|
|
201
201
|
))}
|
|
202
202
|
{unused.length > 0 && (
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
203
|
+
// UX-078: adding is an action, so it is a button with a menu, not a select.
|
|
204
|
+
<DropdownMenu>
|
|
205
|
+
<DropdownMenu.Trigger>
|
|
206
|
+
<Button
|
|
207
|
+
type="button"
|
|
208
|
+
variant="secondary"
|
|
209
|
+
className={`${BUTTON} emvb-add-effect`}
|
|
210
|
+
icon={<PlusIcon aria-hidden="true" />}
|
|
211
|
+
>
|
|
212
|
+
Add effect
|
|
213
|
+
</Button>
|
|
214
|
+
</DropdownMenu.Trigger>
|
|
215
|
+
<DropdownMenu.Content data-emvb-add-effect="">
|
|
216
|
+
{unused.map((type) => (
|
|
217
|
+
<DropdownMenu.Item
|
|
218
|
+
key={type}
|
|
219
|
+
onClick={() => {
|
|
220
|
+
const n = EFFECT_LABELS[type].neutral;
|
|
221
|
+
setEffects([...playing.effects, { type, from: n, to: n }]);
|
|
222
|
+
}}
|
|
223
|
+
>
|
|
224
|
+
{EFFECT_LABELS[type].label}
|
|
225
|
+
</DropdownMenu.Item>
|
|
226
|
+
))}
|
|
227
|
+
</DropdownMenu.Content>
|
|
228
|
+
</DropdownMenu>
|
|
216
229
|
)}
|
|
217
230
|
<p className="emvb-helper">
|
|
218
231
|
Plays as visitors scroll, in browsers that support scroll-driven animations. Visitors
|
|
@@ -242,7 +255,7 @@ export function MotionControl({
|
|
|
242
255
|
className={BUTTON}
|
|
243
256
|
onClick={() => onChange({ type: "none" })}
|
|
244
257
|
>
|
|
245
|
-
Turn off
|
|
258
|
+
Turn off scroll motion
|
|
246
259
|
</Button>
|
|
247
260
|
)}
|
|
248
261
|
</div>
|
|
@@ -2,6 +2,7 @@ import { Button, Input } from "@cloudflare/kumo";
|
|
|
2
2
|
import { ArrowCounterClockwiseIcon } from "@phosphor-icons/react";
|
|
3
3
|
import * as React from "react";
|
|
4
4
|
import { BUTTON, FIELD } from "../../../ui.ts";
|
|
5
|
+
import { isCommitEnter } from "../../ime.ts";
|
|
5
6
|
|
|
6
7
|
/** Range and scale of a plain number field; `scale` converts stored to shown (opacity 0–1 → %). */
|
|
7
8
|
export type NumberSpec = {
|
|
@@ -57,10 +58,15 @@ export function NumberField({
|
|
|
57
58
|
}) {
|
|
58
59
|
const [draft, setDraft] = React.useState(shown(value, spec));
|
|
59
60
|
const [error, setError] = React.useState<string | null>(null);
|
|
61
|
+
// W-604: keyed on the spec's contents, not its identity; callers that build a spec per render
|
|
62
|
+
// (Transition's Delay, Motion's fields) reset the draft whenever the panel re-rendered.
|
|
63
|
+
const specKey = JSON.stringify(spec);
|
|
64
|
+
const specRef = React.useRef(spec);
|
|
65
|
+
specRef.current = spec;
|
|
60
66
|
React.useEffect(() => {
|
|
61
|
-
setDraft(shown(value,
|
|
67
|
+
setDraft(shown(value, specRef.current));
|
|
62
68
|
setError(null);
|
|
63
|
-
}, [value,
|
|
69
|
+
}, [value, specKey]);
|
|
64
70
|
|
|
65
71
|
const commit = () => {
|
|
66
72
|
const parsed = parseNumberDraft(draft, label, spec);
|
|
@@ -85,7 +91,7 @@ export function NumberField({
|
|
|
85
91
|
onChange={(event) => setDraft(event.target.value)}
|
|
86
92
|
onBlur={commit}
|
|
87
93
|
onKeyDown={(event) => {
|
|
88
|
-
if (event
|
|
94
|
+
if (isCommitEnter(event)) commit();
|
|
89
95
|
}}
|
|
90
96
|
/>
|
|
91
97
|
);
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Select } from "@cloudflare/kumo";
|
|
2
|
+
import { FIELD } from "../../../ui.ts";
|
|
3
|
+
|
|
4
|
+
type PanelOption = { value: string; label: string };
|
|
5
|
+
|
|
6
|
+
type Props = {
|
|
7
|
+
value: string;
|
|
8
|
+
options: readonly PanelOption[];
|
|
9
|
+
onChange: (value: string) => void;
|
|
10
|
+
/** Names the trigger when the row has no visible label of its own. */
|
|
11
|
+
label?: string;
|
|
12
|
+
/** The id of the row's visible label. */
|
|
13
|
+
labelledBy?: string;
|
|
14
|
+
className?: string;
|
|
15
|
+
/** Data attributes for the wrapper, which also carries the current value as `data-value`. */
|
|
16
|
+
data?: Record<`data-${string}`, string>;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/** A 28 px Kumo Select for panel rows that used a native select (UX-005). */
|
|
20
|
+
export function PanelSelect({
|
|
21
|
+
value,
|
|
22
|
+
options,
|
|
23
|
+
onChange,
|
|
24
|
+
label,
|
|
25
|
+
labelledBy,
|
|
26
|
+
className,
|
|
27
|
+
data,
|
|
28
|
+
}: Props) {
|
|
29
|
+
return (
|
|
30
|
+
<span
|
|
31
|
+
className={className ? `emvb-panel-select ${className}` : "emvb-panel-select"}
|
|
32
|
+
data-value={value}
|
|
33
|
+
{...data}
|
|
34
|
+
>
|
|
35
|
+
<Select
|
|
36
|
+
className={FIELD}
|
|
37
|
+
value={value}
|
|
38
|
+
{...(labelledBy ? { "aria-labelledby": labelledBy } : { "aria-label": label })}
|
|
39
|
+
onValueChange={(next) => onChange(String(next))}
|
|
40
|
+
renderValue={(v: unknown) => options.find((o) => o.value === String(v))?.label ?? String(v)}
|
|
41
|
+
>
|
|
42
|
+
{options.map((option) => (
|
|
43
|
+
<Select.Option key={option.value} value={option.value}>
|
|
44
|
+
<span data-emvb-option={option.value}>{option.label}</span>
|
|
45
|
+
</Select.Option>
|
|
46
|
+
))}
|
|
47
|
+
</Select>
|
|
48
|
+
</span>
|
|
49
|
+
);
|
|
50
|
+
}
|
|
@@ -3,6 +3,11 @@ import type { LayoutNode } from "../../../../core/index.ts";
|
|
|
3
3
|
import { FIELD } from "../../../ui.ts";
|
|
4
4
|
import { savableNode } from "./DraftTextField.tsx";
|
|
5
5
|
import { formatStyleValue, parseStyleValue, QUERY_STYLE_KEYS } from "./query-style.ts";
|
|
6
|
+
import { isCommitEnter } from "../../ime.ts";
|
|
7
|
+
import { PanelSelect } from "./PanelSelect.tsx";
|
|
8
|
+
import { STYLE_LABELS } from "./style-sections.ts";
|
|
9
|
+
|
|
10
|
+
const CHOOSE = "choose";
|
|
6
11
|
|
|
7
12
|
type QueryStyle = NonNullable<LayoutNode["query"]>["style"];
|
|
8
13
|
|
|
@@ -15,6 +20,9 @@ function withQueryStyle(node: LayoutNode, style: Record<string, unknown>): Layou
|
|
|
15
20
|
}
|
|
16
21
|
|
|
17
22
|
/** One stored property: its value commits on blur or Enter; Remove deletes it. */
|
|
23
|
+
const styleName = (key: string): string =>
|
|
24
|
+
(STYLE_LABELS as Record<string, string | undefined>)[key] ?? key;
|
|
25
|
+
|
|
18
26
|
function QueryStyleRow({
|
|
19
27
|
node,
|
|
20
28
|
styleKey,
|
|
@@ -54,7 +62,7 @@ function QueryStyleRow({
|
|
|
54
62
|
return (
|
|
55
63
|
<div className="emvb-query-row" data-emvb-query-key={styleKey}>
|
|
56
64
|
<label className="emvb-field-label" htmlFor={id}>
|
|
57
|
-
{styleKey}
|
|
65
|
+
{styleName(styleKey)}
|
|
58
66
|
</label>
|
|
59
67
|
<input
|
|
60
68
|
id={id}
|
|
@@ -65,7 +73,7 @@ function QueryStyleRow({
|
|
|
65
73
|
onChange={(event) => setDraft(event.target.value)}
|
|
66
74
|
onBlur={commit}
|
|
67
75
|
onKeyDown={(event) => {
|
|
68
|
-
if (event
|
|
76
|
+
if (isCommitEnter(event)) commit();
|
|
69
77
|
}}
|
|
70
78
|
/>
|
|
71
79
|
<button
|
|
@@ -133,22 +141,21 @@ export function QueryStyleRows({
|
|
|
133
141
|
<QueryStyleRow key={key} node={node} styleKey={key} onChange={onChange} />
|
|
134
142
|
))}
|
|
135
143
|
<div className="emvb-query-add" data-emvb-query-add="">
|
|
136
|
-
<
|
|
144
|
+
<span className="emvb-field-label" id={`${keyId}-label`}>
|
|
137
145
|
Property
|
|
138
|
-
</
|
|
139
|
-
<
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
</select>
|
|
146
|
+
</span>
|
|
147
|
+
<PanelSelect
|
|
148
|
+
labelledBy={`${keyId}-label`}
|
|
149
|
+
value={newKey || CHOOSE}
|
|
150
|
+
options={[
|
|
151
|
+
{ value: CHOOSE, label: "Choose…" },
|
|
152
|
+
// UX-079: the Style tab's names ("Padding top"), not the raw keys.
|
|
153
|
+
...free
|
|
154
|
+
.map((key) => ({ value: key, label: styleName(key) }))
|
|
155
|
+
.toSorted((a, b) => a.label.localeCompare(b.label)),
|
|
156
|
+
]}
|
|
157
|
+
onChange={(value) => setNewKey(value === CHOOSE ? "" : value)}
|
|
158
|
+
/>
|
|
152
159
|
<label className="emvb-field-label" htmlFor={valueId}>
|
|
153
160
|
Value
|
|
154
161
|
</label>
|
|
@@ -161,7 +168,7 @@ export function QueryStyleRows({
|
|
|
161
168
|
aria-describedby={error ? `${valueId}-error` : undefined}
|
|
162
169
|
onChange={(event) => setNewValue(event.target.value)}
|
|
163
170
|
onKeyDown={(event) => {
|
|
164
|
-
if (event
|
|
171
|
+
if (isCommitEnter(event)) add();
|
|
165
172
|
}}
|
|
166
173
|
/>
|
|
167
174
|
<button type="button" className="emvb-link-button" onClick={add}>
|