@perkyzz/emvb 0.7.0 → 0.8.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.
Files changed (71) hide show
  1. package/README.md +2 -2
  2. package/THIRD_PARTY_NOTICES.md +1 -1
  3. package/package.json +7 -7
  4. package/src/admin/editor/DialogCloseButton.tsx +16 -0
  5. package/src/admin/editor/Editor.tsx +33 -0
  6. package/src/admin/editor/PerfMeter.tsx +3 -9
  7. package/src/admin/editor/SavedSectionDialogs.tsx +169 -0
  8. package/src/admin/editor/ShareLink.tsx +2 -7
  9. package/src/admin/editor/ShortcutsDialog.tsx +19 -11
  10. package/src/admin/editor/Timeline.tsx +2 -7
  11. package/src/admin/editor/dialogs.tsx +3 -14
  12. package/src/admin/editor/editor-chrome.tsx +8 -24
  13. package/src/admin/editor/editor-commands.ts +15 -1
  14. package/src/admin/editor/editor-css.ts +3 -2
  15. package/src/admin/editor/feature-css.ts +11 -1
  16. package/src/admin/editor/focus-when-lost.ts +23 -0
  17. package/src/admin/editor/icons/IconLibraryDialog.tsx +2 -7
  18. package/src/admin/editor/palette-items.ts +17 -0
  19. package/src/admin/editor/panels/AddPanel.tsx +9 -1
  20. package/src/admin/editor/panels/LayersPanel.tsx +6 -1
  21. package/src/admin/editor/panels/LeftPanel.tsx +9 -1
  22. package/src/admin/editor/panels/SavedSectionsGroup.tsx +246 -0
  23. package/src/admin/editor/panels/SiteStylesDrawer.tsx +54 -10
  24. package/src/admin/editor/panels/TokenScales.tsx +16 -16
  25. package/src/admin/editor/panels/TriggersEditor.tsx +1 -1
  26. package/src/admin/editor/panels/color-space.ts +14 -26
  27. package/src/admin/editor/panels/settings/AudienceEditor.tsx +36 -39
  28. package/src/admin/editor/panels/settings/IconControls.tsx +21 -5
  29. package/src/admin/editor/panels/settings/LoopItemBindControl.tsx +1 -1
  30. package/src/admin/editor/shortcuts.ts +14 -0
  31. package/src/admin/editor/useSavedSections.ts +197 -0
  32. package/src/admin/image-editor/Canvas.tsx +61 -17
  33. package/src/admin/image-editor/ImageEditorDialog.tsx +130 -1
  34. package/src/admin/image-editor/image-editor-css.ts +11 -8
  35. package/src/admin/image-editor/parts.tsx +18 -17
  36. package/src/admin/image-editor/save.ts +31 -1
  37. package/src/admin/pages/ThemePartList.tsx +32 -4
  38. package/src/admin/saved-sections-api.ts +51 -0
  39. package/src/admin/theme-api.ts +3 -2
  40. package/src/admin/ui.ts +9 -0
  41. package/src/astro/popups/runtime.ts +8 -6
  42. package/src/constants.ts +1 -1
  43. package/src/core/a11y/audit.ts +32 -7
  44. package/src/core/arrange.ts +21 -6
  45. package/src/core/css/print.ts +5 -0
  46. package/src/core/design/classes.ts +23 -9
  47. package/src/core/design/devices.ts +7 -13
  48. package/src/core/design/states.ts +7 -13
  49. package/src/core/elements/dynamic-elements.ts +11 -11
  50. package/src/core/elements/index.ts +1 -1
  51. package/src/core/elements/menu.ts +3 -0
  52. package/src/core/icons/animation-runs.ts +11 -0
  53. package/src/core/index.ts +20 -0
  54. package/src/core/migrate/index.ts +3 -0
  55. package/src/core/render/loop.ts +1 -1
  56. package/src/core/sanitize/css.ts +14 -6
  57. package/src/core/saved-sections.ts +318 -0
  58. package/src/core/schema/design.ts +1 -1
  59. package/src/core/schema/layout.ts +1 -1
  60. package/src/core/schema/style.ts +4 -2
  61. package/src/core/theme/float.ts +3 -0
  62. package/src/core/theme/pagination.ts +25 -24
  63. package/src/core/theme/part-types.ts +4 -4
  64. package/src/mcp/ports.ts +22 -1
  65. package/src/mcp/read.ts +1 -1
  66. package/src/mcp/sections.ts +183 -0
  67. package/src/mcp/tools.ts +44 -0
  68. package/src/mcp/write.ts +4 -4
  69. package/src/server/mcp-routes.ts +2 -0
  70. package/src/server/plugin.ts +14 -0
  71. package/src/server/saved-sections.ts +163 -0
@@ -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
- let a = 1;
76
- const alpha = parts[3];
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
- let a = 1;
199
- const alpha = parts[3];
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
- <input
137
- className="emvb-native-input"
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
- <label key={device}>
153
- <input
154
- type="checkbox"
155
- checked={base.devices?.includes(device) ?? false}
156
- data-emvb-audience-device={device}
157
- onChange={(event) => {
158
- const now = new Set(base.devices ?? []);
159
- if (event.currentTarget.checked) now.add(device);
160
- else now.delete(device);
161
- set({ ...base, devices: AUDIENCE_DEVICES.filter((d) => now.has(d)) });
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
- <input
191
- className="emvb-native-input"
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
- <input
245
- className="emvb-native-input"
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
- <input
263
- className="emvb-native-input"
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
- <label key={day}>
284
- <input
285
- type="checkbox"
286
- checked={base.days?.includes(index) ?? false}
287
- data-emvb-audience-day={index}
288
- onChange={(event) => {
289
- const now = new Set(base.days ?? []);
290
- if (event.currentTarget.checked) now.add(index);
291
- else now.delete(index);
292
- set({ ...base, days: DAYS.map((_d, i) => i).filter((i) => now.has(i)) });
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
- <input
303
- className="emvb-native-input"
299
+ <Input
300
+ className={FIELD}
304
301
  value={zoneText}
305
302
  placeholder="UTC"
306
303
  data-emvb-audience-zone=""
@@ -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 looping spin or pulse (Normal only); visitors who prefer reduced motion see it still. */
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
- onChange({ type: picked, duration });
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 && <p className="emvb-helper">Off for visitors who prefer reduced motion.</p>}
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). Pick
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 && (
@@ -18,7 +18,7 @@ export function LoopItemBindControl({
18
18
  fetcher,
19
19
  onChange,
20
20
  partType = "loop_item",
21
- label = "Loop Item",
21
+ label = "Loop item",
22
22
  emptyLabel = "Use nested elements",
23
23
  marker = "loop-item",
24
24
  }: {
@@ -19,6 +19,20 @@ export const SHORTCUTS: readonly { action: string; keys: string }[] = [
19
19
  { action: "Save draft", keys: "Ctrl/Cmd+S" },
20
20
  ];
21
21
 
22
+ /** One alternative in a shortcut ("Ctrl/Cmd+Shift+Z"), with the separator before it. */
23
+ export type KeyCombo = { before: string; keys: string[] };
24
+
25
+ /** W-864: "Ctrl/Cmd+Z / Ctrl/Cmd+Y" as combos of single keys, for key boxes. */
26
+ export function keyCombos(keys: string): KeyCombo[] {
27
+ const parts = keys.split(/( \/ | or )/);
28
+ const combos: KeyCombo[] = [];
29
+ for (let i = 0; i < parts.length; i += 2) {
30
+ const combo = parts[i] ?? "";
31
+ combos.push({ before: i === 0 ? "" : (parts[i - 1] ?? ""), keys: combo.split(/\+(?=.)/) });
32
+ }
33
+ return combos;
34
+ }
35
+
22
36
  /**
23
37
  * W-565: the letter of a Ctrl/Cmd shortcut on any keyboard layout. A Russian, Greek, Hebrew or
24
38
  * Arabic layout reports its own letter (Ctrl+Z is "я"), so the key's position stands in when the
@@ -0,0 +1,197 @@
1
+ import * as React from "react";
2
+ import type { createKumoToastManager } from "@cloudflare/kumo";
3
+ import {
4
+ classMergeNotice,
5
+ droppedNotice,
6
+ insertSavedSection,
7
+ LAYOUT_SCHEMA_VERSION,
8
+ newNodeId,
9
+ pageSlug,
10
+ snapshotSection,
11
+ syncedPartLayout,
12
+ wrapInThemeSection,
13
+ type DesignSystem,
14
+ type Layout,
15
+ } from "../../core/index.ts";
16
+ import type { Fetcher } from "../api.ts";
17
+ import {
18
+ deleteSavedSection,
19
+ getSavedSection,
20
+ listSavedSections,
21
+ renameSavedSection,
22
+ saveSavedSection,
23
+ type SavedSectionSummary,
24
+ } from "../saved-sections-api.ts";
25
+ import { createThemePart } from "../theme-api.ts";
26
+ import type { EditorAction, EditorState } from "./store.ts";
27
+
28
+ export type SaveMode = "copy" | "synced";
29
+
30
+ /** What the Add panel, the palette and the Save as section dialog use (W-876). */
31
+ export type SavedSectionActions = {
32
+ list: SavedSectionSummary[];
33
+ /** Null until the first list arrives; a message when it couldn't be read. */
34
+ loadError: string | null;
35
+ loaded: boolean;
36
+ refresh: () => void;
37
+ /** Resolves to null when saved, or the reason it wasn't. */
38
+ save: (nodeId: string, name: string, mode: SaveMode) => Promise<string | null>;
39
+ insert: (id: string) => Promise<void>;
40
+ rename: (id: string, name: string) => Promise<string | null>;
41
+ remove: (id: string) => Promise<string | null>;
42
+ };
43
+
44
+ const NOTICE_MS = 5000;
45
+ const messageOf = (error: unknown, fallback: string) =>
46
+ error instanceof Error && error.message ? error.message : fallback;
47
+
48
+ /**
49
+ * Saved sections in the editor (W-876, D-060). Copies go to `emvb_saved_sections`; Synced makes a
50
+ * Section theme part (W-098) from the element and puts the element inside a Theme section that
51
+ * embeds it. Inserting brings the section's classes into Site styles first, never overwriting one.
52
+ */
53
+ export function useSavedSections({
54
+ fetcher,
55
+ latest,
56
+ dispatch,
57
+ changeDesign,
58
+ announce,
59
+ toasts,
60
+ }: {
61
+ fetcher: Fetcher;
62
+ latest: React.RefObject<EditorState>;
63
+ dispatch: React.Dispatch<EditorAction>;
64
+ changeDesign: (next: DesignSystem) => Promise<unknown>;
65
+ announce: (message: string) => void;
66
+ toasts: ReturnType<typeof createKumoToastManager>;
67
+ }): SavedSectionActions {
68
+ const [list, setList] = React.useState<SavedSectionSummary[]>([]);
69
+ const [loaded, setLoaded] = React.useState(false);
70
+ const [loadError, setLoadError] = React.useState<string | null>(null);
71
+ const tell = React.useCallback(
72
+ (title: string, description?: string) => {
73
+ announce(description ? `${title}. ${description}` : title);
74
+ toasts.add({ title, ...(description ? { description } : {}), timeout: NOTICE_MS });
75
+ },
76
+ [announce, toasts],
77
+ );
78
+
79
+ const refresh = React.useCallback(() => {
80
+ listSavedSections(fetcher).then(
81
+ (items) => {
82
+ setList(items);
83
+ setLoadError(null);
84
+ setLoaded(true);
85
+ },
86
+ (error: unknown) => {
87
+ setLoadError(messageOf(error, "Couldn't load My sections."));
88
+ setLoaded(true);
89
+ },
90
+ );
91
+ }, [fetcher]);
92
+ React.useEffect(refresh, [refresh]);
93
+
94
+ const saveCopy = async (layout: Layout, nodeId: string, name: string) => {
95
+ const snap = snapshotSection(
96
+ layout,
97
+ nodeId,
98
+ latest.current.design,
99
+ name,
100
+ new Date().toISOString(),
101
+ );
102
+ if (!snap.ok) return snap.reason;
103
+ await saveSavedSection(fetcher, snap.record);
104
+ refresh();
105
+ tell(`Saved "${snap.record.name}" to My sections`);
106
+ return null;
107
+ };
108
+
109
+ const saveSynced = async (layout: Layout, nodeId: string, name: string) => {
110
+ const partLayout = syncedPartLayout(layout, nodeId);
111
+ const title = name.trim();
112
+ if (!title) return "Give the section a name.";
113
+ if (!partLayout) return "Choose an element inside the page.";
114
+ // Try the wrap first: a refused one (a tab panel, a menu item) used to leave a stray part (W-880).
115
+ const fits = wrapInThemeSection(layout, nodeId, "check");
116
+ if (!fits.ok) return fits.reason;
117
+ // The slug only tells theme parts apart; a short random tail keeps two "Hero"s apart.
118
+ const slug = `${pageSlug(`section-${title}`).slice(0, 60)}-${newNodeId().slice(0, 4)}`;
119
+ const partId = await createThemePart(fetcher, {
120
+ title,
121
+ slug,
122
+ partType: "section",
123
+ layout: partLayout,
124
+ });
125
+ const now = latest.current.page.layout;
126
+ const wrapped = now ? wrapInThemeSection(now, nodeId, partId) : null;
127
+ if (!wrapped?.ok) {
128
+ return `The theme section "${title}" was made, but this element couldn't be linked to it. ${wrapped?.reason ?? ""}`.trim();
129
+ }
130
+ dispatch({ type: "apply-arranged", layout: wrapped.layout, selected: wrapped.selected });
131
+ tell(
132
+ `Made the synced section "${title}"`,
133
+ "Edit it in Theme Builder; publish it there to use it on the site.",
134
+ );
135
+ return null;
136
+ };
137
+
138
+ const save: SavedSectionActions["save"] = async (nodeId, name, mode) => {
139
+ const layout = latest.current.page.layout;
140
+ if (!layout) return "This page has no elements yet.";
141
+ try {
142
+ return await (mode === "synced" ? saveSynced : saveCopy)(layout, nodeId, name);
143
+ } catch (error) {
144
+ return messageOf(error, "Couldn't save the section.");
145
+ }
146
+ };
147
+
148
+ const insert: SavedSectionActions["insert"] = async (id) => {
149
+ try {
150
+ const section = await getSavedSection(fetcher, id);
151
+ const state = latest.current;
152
+ const layout = state.page.layout ?? {
153
+ schemaVersion: LAYOUT_SCHEMA_VERSION,
154
+ root: { id: newNodeId(), type: "container" as const, props: {}, children: [] },
155
+ };
156
+ const result = insertSavedSection(section, layout, state.design, state.selectedId);
157
+ if (!result.ok) {
158
+ tell(result.reason);
159
+ return;
160
+ }
161
+ const classes = classMergeNotice(result.merge);
162
+ // Classes first: an inserted copy never points at a class Site styles failed to save.
163
+ if (classes) await changeDesign(result.design);
164
+ dispatch({ type: "apply-arranged", layout: result.layout, selected: result.selected });
165
+ const left = droppedNotice(result.dropped);
166
+ const extra = [classes, left].filter(Boolean).join(" ");
167
+ if (extra) tell(`Inserted "${section.name}"`, extra);
168
+ else announce(`Inserted "${section.name}"`);
169
+ } catch (error) {
170
+ tell(messageOf(error, "Couldn't insert the section."));
171
+ }
172
+ };
173
+
174
+ const rename: SavedSectionActions["rename"] = async (id, name) => {
175
+ try {
176
+ const item = await renameSavedSection(fetcher, id, name);
177
+ setList((items) => items.map((entry) => (entry.id === id ? item : entry)));
178
+ announce(`Renamed to "${item.name}"`);
179
+ return null;
180
+ } catch (error) {
181
+ return messageOf(error, "Couldn't rename the section.");
182
+ }
183
+ };
184
+
185
+ const remove: SavedSectionActions["remove"] = async (id) => {
186
+ try {
187
+ await deleteSavedSection(fetcher, id);
188
+ setList((items) => items.filter((entry) => entry.id !== id));
189
+ announce("Section deleted. Pages that use a copy keep it.");
190
+ return null;
191
+ } catch (error) {
192
+ return messageOf(error, "Couldn't delete the section.");
193
+ }
194
+ };
195
+
196
+ return { list, loaded, loadError, refresh, save, insert, rename, remove };
197
+ }
@@ -7,8 +7,13 @@
7
7
  * apps/www/src/registry/image-editor), MIT License, Copyright (c) 2026 rbbydotdev. Dropping and
8
8
  * opening files are left out: the editor opens the Image element's picture.
9
9
  */
10
- import { Button } from "@cloudflare/kumo";
11
- import { CircleNotchIcon, CornersOutIcon } from "@phosphor-icons/react";
10
+ import {
11
+ CircleNotchIcon,
12
+ CornersOutIcon,
13
+ MagnifyingGlassMinusIcon,
14
+ MagnifyingGlassPlusIcon,
15
+ } from "@phosphor-icons/react";
16
+ import { IconButton } from "./parts.tsx";
12
17
  import * as React from "react";
13
18
  import { BlurFocus } from "./BlurFocus.tsx";
14
19
  import { CornerHandlesOverlay, CropFrameOverlay } from "./CropOverlay.tsx";
@@ -23,6 +28,17 @@ import { useImageEditor } from "./engine.ts";
23
28
 
24
29
  type UserView = { scale: number; x: number; y: number };
25
30
  const IDENTITY_VIEW: UserView = { scale: 1, x: 0, y: 0 };
31
+ const MAX_ZOOM = 8;
32
+ /** W-861 (IE-6): one Zoom in or Zoom out press. */
33
+ const ZOOM_STEP = 1.5;
34
+
35
+ /** Zoom by `factor` keeping the stage point (cx, cy) still; back to 1 is the plain fit. */
36
+ function zoomAt(prev: UserView, factor: number, cx: number, cy: number): UserView {
37
+ const scale = Math.min(MAX_ZOOM, Math.max(1, prev.scale * factor));
38
+ if (scale === 1) return IDENTITY_VIEW;
39
+ const f = scale / prev.scale;
40
+ return { scale, x: cx - (cx - prev.x) * f, y: cy - (cy - prev.y) * f };
41
+ }
26
42
  const SETTLE_MS = 240;
27
43
  const easeOutCubic = (t: number) => 1 - (1 - t) ** 3;
28
44
 
@@ -135,10 +151,7 @@ export function EditorCanvas({ alt, padding = 24 }: { alt: string; padding?: num
135
151
  const cy = event.clientY - rect.top;
136
152
  setUserView((prev) => {
137
153
  if (!zooming) return { ...prev, x: prev.x - event.deltaX, y: prev.y - event.deltaY };
138
- const scale = Math.min(8, Math.max(1, prev.scale * Math.exp(-event.deltaY * 0.01)));
139
- const f = scale / prev.scale;
140
- if (scale === 1) return IDENTITY_VIEW;
141
- return { scale, x: cx - (cx - prev.x) * f, y: cy - (cy - prev.y) * f };
154
+ return zoomAt(prev, Math.exp(-event.deltaY * 0.01), cx, cy);
142
155
  });
143
156
  };
144
157
  React.useEffect(() => {
@@ -242,18 +255,49 @@ export function EditorCanvas({ alt, padding = 24 }: { alt: string; padding?: num
242
255
  />
243
256
  </div>
244
257
  ) : null}
245
- {!isCropView && userView !== IDENTITY_VIEW ? (
246
- <Button
247
- aria-label="Fit to screen"
248
- className="emvb-ie-fit"
249
- shape="square"
250
- size="sm"
251
- variant="secondary"
252
- icon={<CornersOutIcon aria-hidden="true" />}
253
- onClick={() => setUserView(IDENTITY_VIEW)}
258
+ {!isCropView ? (
259
+ // W-861 (IE-6): Zoom out, Zoom in and Fit, as photocn's toolbar actions; Ctrl/⌘-scroll
260
+ // and pinch still zoom too.
261
+ <div
262
+ className="emvb-ie-zoom"
263
+ role="group"
264
+ aria-label="Zoom"
265
+ data-emvb-image-zoom={Math.round(userView.scale * 100)}
254
266
  onPointerDown={(event) => event.stopPropagation()}
255
- type="button"
256
- />
267
+ >
268
+ <IconButton
269
+ label="Zoom out"
270
+ variant="outline"
271
+ icon={<MagnifyingGlassMinusIcon aria-hidden="true" />}
272
+ disabled={editor.disabled || userView.scale <= 1}
273
+ onClick={() =>
274
+ setUserView((prev) =>
275
+ zoomAt(prev, 1 / ZOOM_STEP, (stage?.width ?? 0) / 2, (stage?.height ?? 0) / 2),
276
+ )
277
+ }
278
+ data-emvb-image-zoom-out=""
279
+ />
280
+ <IconButton
281
+ label="Zoom in"
282
+ variant="outline"
283
+ icon={<MagnifyingGlassPlusIcon aria-hidden="true" />}
284
+ disabled={editor.disabled || !editor.isReady || userView.scale >= MAX_ZOOM}
285
+ onClick={() =>
286
+ setUserView((prev) =>
287
+ zoomAt(prev, ZOOM_STEP, (stage?.width ?? 0) / 2, (stage?.height ?? 0) / 2),
288
+ )
289
+ }
290
+ data-emvb-image-zoom-in=""
291
+ />
292
+ {userView !== IDENTITY_VIEW ? (
293
+ <IconButton
294
+ label="Fit to screen"
295
+ variant="outline"
296
+ icon={<CornersOutIcon aria-hidden="true" />}
297
+ onClick={() => setUserView(IDENTITY_VIEW)}
298
+ />
299
+ ) : null}
300
+ </div>
257
301
  ) : null}
258
302
  </div>
259
303
  </div>