@perkyzz/emvb 0.5.0 → 0.6.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/editor/Editor.tsx +6 -0
- package/src/admin/editor/collection-previews.ts +6 -1
- package/src/admin/editor/editor-chrome.tsx +49 -0
- package/src/admin/editor/editor-commands.ts +13 -0
- package/src/admin/editor/editor-css.ts +3 -0
- package/src/admin/editor/panels/ColorControl.tsx +5 -4
- package/src/admin/editor/panels/LayersPanel.tsx +13 -3
- package/src/admin/editor/panels/VariableSection.tsx +5 -3
- package/src/admin/editor/panels/settings/FieldControl.tsx +18 -7
- package/src/admin/editor/panels/settings/MediaPicker.tsx +154 -4
- package/src/admin/editor/panels/settings/RequiredFieldsNotice.tsx +76 -0
- package/src/admin/editor/panels/variable-values.ts +14 -0
- package/src/admin/editor/store.ts +7 -3
- 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 +394 -0
- package/src/admin/image-editor/ExportDialog.tsx +354 -0
- package/src/admin/image-editor/ImageEditButton.tsx +83 -0
- package/src/admin/image-editor/ImageEditorDialog.tsx +786 -0
- package/src/admin/image-editor/MetadataPanel.tsx +183 -0
- package/src/admin/image-editor/announce.tsx +65 -0
- package/src/admin/image-editor/crop-geometry.ts +161 -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 +398 -0
- package/src/admin/image-editor/load.ts +109 -0
- package/src/admin/image-editor/panels.tsx +287 -0
- package/src/admin/image-editor/parts.tsx +565 -0
- package/src/admin/image-editor/save.ts +125 -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 +113 -3
- package/src/admin/ui.ts +5 -0
- package/src/astro/EmVBPage.astro +11 -2
- package/src/astro/render.ts +3 -0
- package/src/astro/resolve-theme.ts +15 -4
- package/src/astro/visitor.ts +4 -3
- package/src/constants.ts +1 -1
- package/src/core/arrange.ts +2 -0
- package/src/core/data/bindings.ts +12 -6
- package/src/core/design/classes.ts +5 -3
- package/src/core/design/diff.ts +3 -1
- package/src/core/design/merge.ts +3 -1
- package/src/core/design/transfer.ts +13 -2
- package/src/core/design/variables.ts +2 -1
- package/src/core/elements/dynamic-elements.ts +9 -1
- package/src/core/elements/form-elements.ts +16 -17
- package/src/core/elements/plain-text.ts +2 -2
- package/src/core/forms/binding.ts +148 -1
- package/src/core/history/diff.ts +32 -4
- package/src/core/image-edit/schema.ts +145 -0
- package/src/core/image-edit/summary.ts +58 -0
- package/src/core/index.ts +14 -0
- package/src/core/limits.ts +10 -0
- package/src/core/migrate/index.ts +3 -1
- package/src/core/perf/meter.ts +9 -1
- package/src/core/render/dynamic-post.ts +2 -1
- package/src/core/render/form.ts +24 -6
- package/src/core/render/index.ts +26 -5
- package/src/core/schema/layout.ts +11 -1
- package/src/core/share/link.ts +5 -2
- package/src/core/stable-json.ts +15 -0
- package/src/core/theme/dynamic.ts +21 -18
- package/src/core/theme/pagination.ts +30 -3
- package/src/core/theme/popup-rules.ts +10 -5
- package/src/mcp/ports.ts +8 -1
- package/src/mcp/read.ts +68 -1
- package/src/mcp/tools.ts +1 -1
- package/src/mcp/write.ts +100 -18
- package/src/server/agent-settings.ts +28 -3
- package/src/server/icon-routes.ts +8 -5
- package/src/server/mcp-routes.ts +68 -10
|
@@ -1,14 +1,29 @@
|
|
|
1
|
-
import { Button, Input } from "@cloudflare/kumo";
|
|
1
|
+
import { Badge, Button, DropdownMenu, Input } from "@cloudflare/kumo";
|
|
2
|
+
import { DotsThreeIcon, MagicWandIcon } 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";
|
|
13
28
|
|
|
14
29
|
const propsOf = (node: LayoutNode): Record<string, unknown> =>
|
|
@@ -23,13 +38,20 @@ type Props = {
|
|
|
23
38
|
onChange: (node: LayoutNode) => void;
|
|
24
39
|
/** Field label; Page settings uses "Social image" (W-287). */
|
|
25
40
|
label?: string;
|
|
41
|
+
/** Offer "Edit image" (Image elements only, W-482). */
|
|
42
|
+
editable?: boolean;
|
|
26
43
|
};
|
|
27
44
|
|
|
28
45
|
/**
|
|
29
46
|
* Image source control (W-024 / R-007): pick from EmDash media library, upload a file,
|
|
30
47
|
* or paste a URL. Upload uses the same POST /_emdash/api/media path on both demos.
|
|
31
48
|
*/
|
|
32
|
-
|
|
49
|
+
|
|
50
|
+
/** W-492: Reset to original when the original was deleted from the library. */
|
|
51
|
+
const ORIGINAL_DELETED =
|
|
52
|
+
"The original picture was deleted from the media library, so this image can't be reset. It keeps the edited copy.";
|
|
53
|
+
|
|
54
|
+
export function MediaPicker({ node, fetcher, onChange, label = "Image", editable = false }: Props) {
|
|
33
55
|
const props = propsOf(node);
|
|
34
56
|
const src = typeof props.src === "string" ? props.src : "";
|
|
35
57
|
const [open, setOpen] = React.useState(false);
|
|
@@ -38,6 +60,9 @@ export function MediaPicker({ node, fetcher, onChange, label = "Image" }: Props)
|
|
|
38
60
|
const [error, setError] = React.useState<string | null>(null);
|
|
39
61
|
const [urlDraft, setUrlDraft] = React.useState(src);
|
|
40
62
|
const fileRef = React.useRef<HTMLInputElement>(null);
|
|
63
|
+
// W-486: a library picture opened from its card's Edit… (null when the editor is closed).
|
|
64
|
+
const [editing, setEditing] = React.useState<MediaLibraryItem | null>(null);
|
|
65
|
+
const [editorOpen, setEditorOpen] = React.useState(false);
|
|
41
66
|
|
|
42
67
|
React.useEffect(() => {
|
|
43
68
|
setUrlDraft(src);
|
|
@@ -60,6 +85,58 @@ export function MediaPicker({ node, fetcher, onChange, label = "Image" }: Props)
|
|
|
60
85
|
if (open) void loadLibrary();
|
|
61
86
|
}, [open, loadLibrary]);
|
|
62
87
|
|
|
88
|
+
const edit = ImageEdit.safeParse(props.edit);
|
|
89
|
+
/** W-487: say why a picture can't be edited instead of offering a button that fails. */
|
|
90
|
+
const editCheck = src ? editableSource(props, window.location.origin) : null;
|
|
91
|
+
const editSummary = edit.success ? summarizeImageEdit(edit.data.recipe, 12) || "Edited" : null;
|
|
92
|
+
|
|
93
|
+
/** W-485: upload the edited copy as a new item; the original stays in the library. */
|
|
94
|
+
const saveCopy = async (file: File, copy: { width: number; height: number; edit: unknown }) => {
|
|
95
|
+
onChange(withProps(node, await saveEditedCopy(fetcher, props, file, copy)));
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
/** The props the element would have with this library picture (stable while editing). */
|
|
99
|
+
const editingProps = React.useMemo(
|
|
100
|
+
() => (editing ? propsFromMedia(props, editing) : null),
|
|
101
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps -- only a new card opens a new edit.
|
|
102
|
+
[editing],
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
/** W-486: Edit… saves a copy of the card's picture and selects it for this element. */
|
|
106
|
+
const saveLibraryCopy = async (
|
|
107
|
+
file: File,
|
|
108
|
+
copy: { width: number; height: number; edit: unknown },
|
|
109
|
+
) => {
|
|
110
|
+
if (!editingProps) return;
|
|
111
|
+
onChange(withProps(node, await saveEditedCopy(fetcher, editingProps, file, copy)));
|
|
112
|
+
setOpen(false);
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
/** W-485: back to the untouched original; the edited copy is not deleted. */
|
|
116
|
+
const resetToOriginal = async () => {
|
|
117
|
+
if (!edit.success) return;
|
|
118
|
+
setBusy(true);
|
|
119
|
+
setError(null);
|
|
120
|
+
try {
|
|
121
|
+
const id = edit.data.originalMediaId;
|
|
122
|
+
// W-492: a failed lookup is an error, not "no original"; a deleted original can't be reset
|
|
123
|
+
// to (its recorded URL is gone too), so the element keeps the edited copy.
|
|
124
|
+
const original = id ? await getMedia(fetcher, id) : null;
|
|
125
|
+
if (id && !original) {
|
|
126
|
+
setError(ORIGINAL_DELETED);
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
const next = propsFromOriginal(props, original);
|
|
130
|
+
if (next) onChange(withProps(node, next));
|
|
131
|
+
} catch (caught) {
|
|
132
|
+
setError(
|
|
133
|
+
`Couldn't reach the media library to find the original.${caught instanceof Error && caught.message ? ` ${caught.message}` : ""}`,
|
|
134
|
+
);
|
|
135
|
+
} finally {
|
|
136
|
+
setBusy(false);
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
|
|
63
140
|
const applyItem = (item: MediaLibraryItem) => {
|
|
64
141
|
onChange(withProps(node, propsFromMedia(propsOf(node), item)));
|
|
65
142
|
setOpen(false);
|
|
@@ -114,6 +191,14 @@ export function MediaPicker({ node, fetcher, onChange, label = "Image" }: Props)
|
|
|
114
191
|
<div className="emvb-media-preview">
|
|
115
192
|
<img src={src} alt="" className="emvb-media-thumb" />
|
|
116
193
|
<span className="emvb-helper emvb-mono">{src}</span>
|
|
194
|
+
{editSummary ? (
|
|
195
|
+
<span className="emvb-media-edited" data-emvb-image-edited="">
|
|
196
|
+
<Badge variant="neutral">Edited</Badge>
|
|
197
|
+
<span className="emvb-helper" data-emvb-image-edit-summary="">
|
|
198
|
+
{editSummary}
|
|
199
|
+
</span>
|
|
200
|
+
</span>
|
|
201
|
+
) : null}
|
|
117
202
|
</div>
|
|
118
203
|
) : (
|
|
119
204
|
<p className="emvb-helper">No image selected yet.</p>
|
|
@@ -138,6 +223,21 @@ export function MediaPicker({ node, fetcher, onChange, label = "Image" }: Props)
|
|
|
138
223
|
>
|
|
139
224
|
Upload
|
|
140
225
|
</Button>
|
|
226
|
+
{editable && src && editCheck?.ok ? (
|
|
227
|
+
<ImageEditButton imageProps={props} onSave={saveCopy} />
|
|
228
|
+
) : null}
|
|
229
|
+
{editable && edit.success ? (
|
|
230
|
+
<Button
|
|
231
|
+
type="button"
|
|
232
|
+
className={BUTTON}
|
|
233
|
+
variant="ghost"
|
|
234
|
+
onClick={() => void resetToOriginal()}
|
|
235
|
+
disabled={busy}
|
|
236
|
+
data-emvb-image-reset-original=""
|
|
237
|
+
>
|
|
238
|
+
Reset to original
|
|
239
|
+
</Button>
|
|
240
|
+
) : null}
|
|
141
241
|
<input
|
|
142
242
|
ref={fileRef}
|
|
143
243
|
type="file"
|
|
@@ -147,6 +247,11 @@ export function MediaPicker({ node, fetcher, onChange, label = "Image" }: Props)
|
|
|
147
247
|
onChange={(event) => void onUpload(event.target.files?.[0])}
|
|
148
248
|
/>
|
|
149
249
|
</div>
|
|
250
|
+
{editable && src && editCheck && !editCheck.ok ? (
|
|
251
|
+
<p className="emvb-helper" data-emvb-image-cant-edit={editCheck.reason}>
|
|
252
|
+
{editCheck.message}
|
|
253
|
+
</p>
|
|
254
|
+
) : null}
|
|
150
255
|
<Input
|
|
151
256
|
label="Or paste a URL"
|
|
152
257
|
className={FIELD}
|
|
@@ -183,7 +288,7 @@ export function MediaPicker({ node, fetcher, onChange, label = "Image" }: Props)
|
|
|
183
288
|
)}
|
|
184
289
|
<ul className="emvb-media-grid">
|
|
185
290
|
{items.map((item) => (
|
|
186
|
-
<li key={item.id}>
|
|
291
|
+
<li key={item.id} className="emvb-media-cell">
|
|
187
292
|
<button
|
|
188
293
|
type="button"
|
|
189
294
|
className="emvb-media-card"
|
|
@@ -193,11 +298,50 @@ export function MediaPicker({ node, fetcher, onChange, label = "Image" }: Props)
|
|
|
193
298
|
<img src={item.url} alt={item.alt ?? item.filename} />
|
|
194
299
|
<span>{item.filename}</span>
|
|
195
300
|
</button>
|
|
301
|
+
{editable && canEdit(item) ? (
|
|
302
|
+
<DropdownMenu onOpenChange={(next) => next && prefetchImageEditor()}>
|
|
303
|
+
<DropdownMenu.Trigger
|
|
304
|
+
render={
|
|
305
|
+
<Button
|
|
306
|
+
type="button"
|
|
307
|
+
variant="secondary"
|
|
308
|
+
size="sm"
|
|
309
|
+
shape="square"
|
|
310
|
+
className="emvb-media-card-menu"
|
|
311
|
+
aria-label={`More for ${item.alt || item.filename}`}
|
|
312
|
+
icon={<DotsThreeIcon aria-hidden="true" weight="bold" />}
|
|
313
|
+
data-emvb-media-menu={item.id}
|
|
314
|
+
/>
|
|
315
|
+
}
|
|
316
|
+
/>
|
|
317
|
+
<DropdownMenu.Content align="end">
|
|
318
|
+
<DropdownMenu.Item
|
|
319
|
+
icon={MagicWandIcon}
|
|
320
|
+
onClick={() => {
|
|
321
|
+
setEditing(item);
|
|
322
|
+
setEditorOpen(true);
|
|
323
|
+
}}
|
|
324
|
+
data-emvb-media-edit={item.id}
|
|
325
|
+
>
|
|
326
|
+
Edit…
|
|
327
|
+
</DropdownMenu.Item>
|
|
328
|
+
</DropdownMenu.Content>
|
|
329
|
+
</DropdownMenu>
|
|
330
|
+
) : null}
|
|
196
331
|
</li>
|
|
197
332
|
))}
|
|
198
333
|
</ul>
|
|
199
334
|
</div>
|
|
200
335
|
)}
|
|
336
|
+
{editingProps ? (
|
|
337
|
+
<ImageEditorLauncher
|
|
338
|
+
open={editorOpen}
|
|
339
|
+
onOpenChange={setEditorOpen}
|
|
340
|
+
imageProps={editingProps}
|
|
341
|
+
onSave={saveLibraryCopy}
|
|
342
|
+
onClosed={() => setEditing(null)}
|
|
343
|
+
/>
|
|
344
|
+
) : null}
|
|
201
345
|
</div>
|
|
202
346
|
);
|
|
203
347
|
}
|
|
@@ -217,3 +361,9 @@ function readImageSize(file: File): Promise<{ width: number; height: number }> {
|
|
|
217
361
|
img.src = url;
|
|
218
362
|
});
|
|
219
363
|
}
|
|
364
|
+
|
|
365
|
+
/** Library pictures the editor can open: same-site JPEG, PNG, WebP or AVIF (not SVG or GIF). */
|
|
366
|
+
function canEdit(item: MediaLibraryItem): boolean {
|
|
367
|
+
if (/svg|gif/i.test(item.mimeType)) return false;
|
|
368
|
+
return editableSource({ src: item.url }, window.location.origin).ok;
|
|
369
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { Banner } from "@cloudflare/kumo";
|
|
2
|
+
import { WarningIcon } from "@phosphor-icons/react";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import type { Fetcher } from "../../../api.ts";
|
|
5
|
+
import { loadFormFields, type DefinitionField } from "../../../forms-api.ts";
|
|
6
|
+
import {
|
|
7
|
+
requiredFieldIssues,
|
|
8
|
+
requiredFieldIssueText,
|
|
9
|
+
type LayoutNode,
|
|
10
|
+
type RequiredFieldIssue,
|
|
11
|
+
} from "../../../../core/index.ts";
|
|
12
|
+
|
|
13
|
+
/** The panel's short line for one issue; the full sentence is its tooltip and the MCP text. */
|
|
14
|
+
function shortReason(issue: RequiredFieldIssue): string {
|
|
15
|
+
if (issue.kind === "missing") return `has no field on this form (${issue.field}).`;
|
|
16
|
+
if (issue.kind === "hidden") {
|
|
17
|
+
return issue.devices.length === 3
|
|
18
|
+
? "is hidden on every device."
|
|
19
|
+
: `is hidden on ${issue.devices.join(" and ")}.`;
|
|
20
|
+
}
|
|
21
|
+
return `is shown only to some visitors: ${issue.who}.`;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* W-511: on a Form, the required fields visitors can't fill: missing from the form, or hidden on
|
|
26
|
+
* a device. Either way the form can't be sent there, and the visitor sees no reason why.
|
|
27
|
+
*/
|
|
28
|
+
export function RequiredFieldsNotice({ node, fetcher }: { node: LayoutNode; fetcher: Fetcher }) {
|
|
29
|
+
const formId = String((node.props as { formId?: unknown }).formId ?? "").trim();
|
|
30
|
+
const [fields, setFields] = React.useState<DefinitionField[] | null>(null);
|
|
31
|
+
React.useEffect(() => {
|
|
32
|
+
let cancelled = false;
|
|
33
|
+
setFields(null);
|
|
34
|
+
if (!formId) return undefined;
|
|
35
|
+
void loadFormFields(fetcher, formId).then((next) => {
|
|
36
|
+
if (!cancelled) setFields(next);
|
|
37
|
+
});
|
|
38
|
+
return () => {
|
|
39
|
+
cancelled = true;
|
|
40
|
+
};
|
|
41
|
+
}, [fetcher, formId]);
|
|
42
|
+
const issues = fields ? requiredFieldIssues(node, fields) : [];
|
|
43
|
+
if (issues.length === 0) return null;
|
|
44
|
+
const title =
|
|
45
|
+
issues.length === 1
|
|
46
|
+
? "A required field can't be filled in"
|
|
47
|
+
: `${issues.length} required fields can't be filled in`;
|
|
48
|
+
return (
|
|
49
|
+
<div className="emvb-required-notice" data-emvb-required-fields="">
|
|
50
|
+
<Banner
|
|
51
|
+
variant="alert"
|
|
52
|
+
icon={<WarningIcon aria-hidden="true" />}
|
|
53
|
+
title={title}
|
|
54
|
+
description={
|
|
55
|
+
<>
|
|
56
|
+
<ul className="emvb-required-notice__list">
|
|
57
|
+
{issues.map((issue) => (
|
|
58
|
+
<li
|
|
59
|
+
key={`${issue.kind}:${issue.field}`}
|
|
60
|
+
data-emvb-required-issue={issue.kind}
|
|
61
|
+
title={requiredFieldIssueText(issue)}
|
|
62
|
+
>
|
|
63
|
+
<strong>{issue.label}</strong> {shortReason(issue)}
|
|
64
|
+
</li>
|
|
65
|
+
))}
|
|
66
|
+
</ul>
|
|
67
|
+
<span className="emvb-required-notice__hint">
|
|
68
|
+
Visitors who can't fill a required field can't send the form. Show the field to
|
|
69
|
+
everyone, or make it optional in Forms.
|
|
70
|
+
</span>
|
|
71
|
+
</>
|
|
72
|
+
}
|
|
73
|
+
/>
|
|
74
|
+
</div>
|
|
75
|
+
);
|
|
76
|
+
}
|
|
@@ -73,3 +73,17 @@ export function pickerHex(hex: string): string {
|
|
|
73
73
|
}
|
|
74
74
|
return "#000000";
|
|
75
75
|
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* The picker's 6-digit colour with the alpha `previous` had: `<input type="color">` has no alpha,
|
|
79
|
+
* so picking a colour made a see-through one solid (W-526).
|
|
80
|
+
*/
|
|
81
|
+
export function withPreviousAlpha(picked: string, previous: string): string {
|
|
82
|
+
const p = previous.trim().toLowerCase();
|
|
83
|
+
const alpha = /^#[0-9a-f]{8}$/.test(p)
|
|
84
|
+
? p.slice(7)
|
|
85
|
+
: /^#[0-9a-f]{4}$/.test(p)
|
|
86
|
+
? (p[4] ?? "") + (p[4] ?? "")
|
|
87
|
+
: "";
|
|
88
|
+
return alpha && alpha !== "ff" && /^#[0-9a-f]{6}$/i.test(picked) ? picked + alpha : picked;
|
|
89
|
+
}
|
|
@@ -87,8 +87,12 @@ const withLayout = (
|
|
|
87
87
|
): EditorState => ({ ...edited(state, { ...state.page, layout }), selectedId, lastDeleted });
|
|
88
88
|
|
|
89
89
|
/** Applies an arrange result; a refused one leaves the state unchanged. */
|
|
90
|
-
const arranged = (state: EditorState, result: Arranged): EditorState =>
|
|
91
|
-
|
|
90
|
+
const arranged = (state: EditorState, result: Arranged): EditorState => {
|
|
91
|
+
if (!result.ok) return state;
|
|
92
|
+
// W-521: an unchanged layout (a drop on its own spot) only selects: no undo step, not unsaved.
|
|
93
|
+
if (result.layout === state.page.layout) return { ...state, selectedId: result.selected };
|
|
94
|
+
return withLayout(state, result.layout, result.selected);
|
|
95
|
+
};
|
|
92
96
|
|
|
93
97
|
/** Page edits kept for undo. Save, publish and design stay on the live state (D-035, proposed). */
|
|
94
98
|
const PAGE_HISTORY_LIMIT = 100;
|
|
@@ -209,7 +213,7 @@ export function editorReducer(state: EditorState, action: EditorAction): EditorS
|
|
|
209
213
|
if (!state.page.layout) return state;
|
|
210
214
|
return arranged(state, moveNode(state.page.layout, action.id, action.parentId, action.index));
|
|
211
215
|
case "apply-arranged":
|
|
212
|
-
return
|
|
216
|
+
return arranged(state, { ok: true, layout: action.layout, selected: action.selected });
|
|
213
217
|
case "saved":
|
|
214
218
|
// A saved draft on a published entry is not live until Publish (W-190).
|
|
215
219
|
return {
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The blur tool's sharp spot on the image (W-484): drag it, or focus it and use the arrow keys.
|
|
3
|
+
*
|
|
4
|
+
* Follows photocn's `blur-center-overlay.tsx` (https://github.com/rbbydotdev/photocn,
|
|
5
|
+
* apps/www/src/registry/image-editor), MIT License, Copyright (c) 2026 rbbydotdev. The keyboard
|
|
6
|
+
* control is EmVB's.
|
|
7
|
+
*/
|
|
8
|
+
import * as React from "react";
|
|
9
|
+
|
|
10
|
+
type Center = { centerX: number; centerY: number };
|
|
11
|
+
const clamp01 = (v: number) => Math.min(1, Math.max(0, v));
|
|
12
|
+
const pct = (v: number) => Math.round(v * 100);
|
|
13
|
+
|
|
14
|
+
export function BlurFocus({
|
|
15
|
+
centerX,
|
|
16
|
+
centerY,
|
|
17
|
+
disabled = false,
|
|
18
|
+
onChange,
|
|
19
|
+
onCommit,
|
|
20
|
+
}: Center & {
|
|
21
|
+
disabled?: boolean;
|
|
22
|
+
onChange: (next: Center) => void;
|
|
23
|
+
onCommit: (next: Center) => void;
|
|
24
|
+
}) {
|
|
25
|
+
const ref = React.useRef<HTMLDivElement | null>(null);
|
|
26
|
+
const [dragging, setDragging] = React.useState(false);
|
|
27
|
+
const at = (event: { clientX: number; clientY: number }): Center | null => {
|
|
28
|
+
const rect = ref.current?.getBoundingClientRect();
|
|
29
|
+
if (!rect || rect.width <= 0 || rect.height <= 0) return null;
|
|
30
|
+
return {
|
|
31
|
+
centerX: clamp01((event.clientX - rect.left) / rect.width),
|
|
32
|
+
centerY: clamp01((event.clientY - rect.top) / rect.height),
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
const end = (event: React.PointerEvent<HTMLDivElement>) => {
|
|
36
|
+
if (!dragging) return;
|
|
37
|
+
if (event.currentTarget.hasPointerCapture?.(event.pointerId)) {
|
|
38
|
+
event.currentTarget.releasePointerCapture(event.pointerId);
|
|
39
|
+
}
|
|
40
|
+
setDragging(false);
|
|
41
|
+
onCommit(at(event) ?? { centerX, centerY });
|
|
42
|
+
};
|
|
43
|
+
return (
|
|
44
|
+
<div
|
|
45
|
+
ref={ref}
|
|
46
|
+
className="emvb-ie-blur-focus"
|
|
47
|
+
data-disabled={disabled || undefined}
|
|
48
|
+
data-emvb-image-blur-area=""
|
|
49
|
+
onPointerDown={(event) => {
|
|
50
|
+
if (disabled || (event.pointerType === "mouse" && event.button !== 0)) return;
|
|
51
|
+
const pos = at(event);
|
|
52
|
+
if (!pos) return;
|
|
53
|
+
// Dragging the spot must not flash the original (the stage's press-and-hold compare).
|
|
54
|
+
event.stopPropagation();
|
|
55
|
+
event.currentTarget.setPointerCapture?.(event.pointerId);
|
|
56
|
+
setDragging(true);
|
|
57
|
+
onChange(pos);
|
|
58
|
+
}}
|
|
59
|
+
onPointerMove={(event) => {
|
|
60
|
+
if (disabled || !dragging) return;
|
|
61
|
+
const pos = at(event);
|
|
62
|
+
if (pos) onChange(pos);
|
|
63
|
+
}}
|
|
64
|
+
onPointerUp={end}
|
|
65
|
+
onPointerCancel={end}
|
|
66
|
+
>
|
|
67
|
+
<div
|
|
68
|
+
className="emvb-ie-blur-handle"
|
|
69
|
+
data-dragging={dragging || undefined}
|
|
70
|
+
data-emvb-image-blur-focus=""
|
|
71
|
+
role="slider"
|
|
72
|
+
tabIndex={disabled ? -1 : 0}
|
|
73
|
+
aria-label="Sharp spot (blur center)"
|
|
74
|
+
aria-valuemin={0}
|
|
75
|
+
aria-valuemax={100}
|
|
76
|
+
aria-valuenow={pct(centerX)}
|
|
77
|
+
aria-valuetext={`${pct(centerX)}% across, ${pct(centerY)}% down`}
|
|
78
|
+
aria-disabled={disabled || undefined}
|
|
79
|
+
style={{ left: `${centerX * 100}%`, top: `${centerY * 100}%` }}
|
|
80
|
+
onPointerDown={(event) => event.currentTarget.focus({ preventScroll: true })}
|
|
81
|
+
onKeyDown={(event) => {
|
|
82
|
+
if (disabled) return;
|
|
83
|
+
const step = event.shiftKey ? 0.1 : 0.01;
|
|
84
|
+
const moves: Record<string, [number, number]> = {
|
|
85
|
+
ArrowLeft: [-step, 0],
|
|
86
|
+
ArrowRight: [step, 0],
|
|
87
|
+
ArrowUp: [0, -step],
|
|
88
|
+
ArrowDown: [0, step],
|
|
89
|
+
};
|
|
90
|
+
const move = moves[event.key];
|
|
91
|
+
if (event.key === "Home") {
|
|
92
|
+
event.preventDefault();
|
|
93
|
+
onCommit({ centerX: 0.5, centerY: 0.5 });
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
if (!move) return;
|
|
97
|
+
event.preventDefault();
|
|
98
|
+
event.stopPropagation();
|
|
99
|
+
onChange({
|
|
100
|
+
centerX: Number(clamp01(centerX + move[0]).toFixed(2)),
|
|
101
|
+
centerY: Number(clamp01(centerY + move[1]).toFixed(2)),
|
|
102
|
+
});
|
|
103
|
+
}}
|
|
104
|
+
onKeyUp={(event) => {
|
|
105
|
+
if (event.key.startsWith("Arrow")) onCommit({ centerX, centerY });
|
|
106
|
+
}}
|
|
107
|
+
>
|
|
108
|
+
<span aria-hidden="true" />
|
|
109
|
+
</div>
|
|
110
|
+
</div>
|
|
111
|
+
);
|
|
112
|
+
}
|