@perkyzz/emvb 0.6.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/package.json +1 -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 +82 -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 +10 -0
- 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 +59 -7
- package/src/admin/editor/editor-commands.ts +2 -1
- package/src/admin/editor/editor-css.ts +72 -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 +130 -23
- 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 +55 -19
- 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 +48 -18
- 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 +20 -8
- 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 +127 -23
- 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 +66 -1
- 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 +11 -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 +7 -0
- 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/CurvesPanel.tsx +2 -1
- package/src/admin/image-editor/ExportDialog.tsx +48 -18
- package/src/admin/image-editor/ImageEditorDialog.tsx +49 -7
- package/src/admin/image-editor/MetadataPanel.tsx +15 -4
- package/src/admin/image-editor/crop-geometry.ts +3 -2
- package/src/admin/image-editor/image-editor-css.ts +4 -2
- package/src/admin/image-editor/load.ts +9 -2
- package/src/admin/image-editor/parts.tsx +51 -2
- package/src/admin/image-editor/save.ts +23 -7
- package/src/admin/media-api.ts +2 -1
- 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 +73 -22
- 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 +3 -0
- package/src/astro/resolve-theme.ts +53 -11
- 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 +2 -0
- package/src/constants.ts +1 -1
- package/src/core/a11y/audit.ts +171 -24
- package/src/core/arrange.ts +27 -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 +8 -1
- package/src/core/design/classes.ts +16 -7
- package/src/core/design/diff.ts +6 -0
- package/src/core/design/merge.ts +90 -2
- package/src/core/design/tokens.ts +16 -2
- package/src/core/design/transfer.ts +33 -6
- package/src/core/design/variables.ts +30 -9
- package/src/core/elements/dynamic-elements.ts +44 -5
- package/src/core/elements/form-elements.ts +55 -16
- package/src/core/elements/index.ts +83 -38
- package/src/core/elements/menu.ts +37 -19
- package/src/core/elements/select-prompt.ts +3 -0
- package/src/core/elements/svg-ids.ts +39 -0
- package/src/core/forms/binding.ts +57 -16
- package/src/core/forms/definition.ts +72 -0
- package/src/core/history/diff.ts +18 -1
- package/src/core/icons/catalog.ts +3 -2
- package/src/core/image-edit/schema.ts +11 -1
- package/src/core/image-edit/summary.ts +6 -3
- package/src/core/index.ts +15 -1
- package/src/core/limits.ts +12 -1
- package/src/core/perf/meter.ts +42 -7
- package/src/core/recipes/index.ts +5 -4
- package/src/core/render/context.ts +8 -0
- package/src/core/render/dynamic-post.ts +69 -12
- package/src/core/render/extras.ts +77 -4
- package/src/core/render/form.ts +140 -6
- package/src/core/render/index.ts +156 -20
- 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 +15 -6
- package/src/core/stats.ts +2 -1
- package/src/core/theme/conditions.ts +3 -1
- package/src/core/theme/dynamic.ts +36 -5
- package/src/core/theme/float.ts +9 -2
- package/src/core/theme/pagination.ts +31 -11
- package/src/core/theme/popup-markup.ts +23 -5
- package/src/core/theme/popup-rules.ts +1 -0
- package/src/core/theme/triggers.ts +3 -2
- package/src/core/tree-ops.ts +27 -0
- package/src/mcp/rate-limit.ts +2 -1
- package/src/mcp/read.ts +14 -2
- package/src/mcp/refs.ts +18 -0
- package/src/mcp/write.ts +174 -10
- package/src/server/agent-settings.ts +1 -1
- package/src/server/hooks.ts +5 -3
- package/src/server/icon-routes.ts +30 -9
- package/src/server/mcp-routes.ts +6 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import type { createKumoToastManager } from "@cloudflare/kumo";
|
|
3
|
+
import { ArrowSquareOutIcon } from "@phosphor-icons/react";
|
|
3
4
|
import {
|
|
4
5
|
DEVICE_PREVIEW_PX,
|
|
5
6
|
mergeDesign,
|
|
@@ -121,7 +122,14 @@ export function useEditorCommands({
|
|
|
121
122
|
]
|
|
122
123
|
: []),
|
|
123
124
|
{
|
|
124
|
-
|
|
125
|
+
// UX-082: an icon, not "↗" read aloud as an arrow; the new tab is said in words.
|
|
126
|
+
children: React.createElement(
|
|
127
|
+
React.Fragment,
|
|
128
|
+
null,
|
|
129
|
+
"View page",
|
|
130
|
+
React.createElement(ArrowSquareOutIcon, { "aria-hidden": true, size: 14 }),
|
|
131
|
+
React.createElement("span", { className: "emvb-sr-only" }, " (opens in a new tab)"),
|
|
132
|
+
),
|
|
125
133
|
variant: "secondary",
|
|
126
134
|
onClick: () => window.open(path, "_blank", "noopener"),
|
|
127
135
|
},
|
|
@@ -145,14 +153,24 @@ export function useEditorCommands({
|
|
|
145
153
|
|
|
146
154
|
// W-325: design saves run one at a time, each against the newest revision, like page saves.
|
|
147
155
|
// Two quick edits used to both send the revision the editor started with, so the second one
|
|
148
|
-
// was refused with a 409 by the first. `written` remembers the revision
|
|
149
|
-
// the store catches up (the ref updates on the next render).
|
|
156
|
+
// was refused with a 409 by the first. `written` remembers the revision the last save produced
|
|
157
|
+
// until the store catches up (the ref updates on the next render).
|
|
150
158
|
const designQueue = React.useRef<Promise<unknown>>(Promise.resolve());
|
|
151
|
-
|
|
159
|
+
// W-536: every revision this tab's run of saves went through, not just the last one. The store
|
|
160
|
+
// can render an older one of them mid-run (save 1's revision while save 2 is out), which used
|
|
161
|
+
// to send that stale revision with save 3 and get a 409.
|
|
162
|
+
const written = React.useRef<{ chain: Set<string | null>; to: string } | null>(null);
|
|
152
163
|
const baseRevision = () => {
|
|
153
164
|
const current = latest.current.designRevision;
|
|
154
165
|
const last = written.current;
|
|
155
|
-
return last && last.
|
|
166
|
+
return last && last.chain.has(current) ? last.to : current;
|
|
167
|
+
};
|
|
168
|
+
const wrote = (sent: string | null, revision: string) => {
|
|
169
|
+
const chain = written.current?.chain.has(sent) ? written.current.chain : new Set([sent]);
|
|
170
|
+
// What the store shows now is behind this save too.
|
|
171
|
+
chain.add(latest.current.designRevision);
|
|
172
|
+
chain.add(revision);
|
|
173
|
+
written.current = { chain, to: revision };
|
|
156
174
|
};
|
|
157
175
|
const queueDesign = <T>(task: () => Promise<T>): Promise<T> => {
|
|
158
176
|
const run = designQueue.current.then(task, task);
|
|
@@ -160,24 +178,48 @@ export function useEditorCommands({
|
|
|
160
178
|
return run;
|
|
161
179
|
};
|
|
162
180
|
|
|
163
|
-
|
|
181
|
+
// W-536: the newest edit, shown at once. Each edit is built from the `design` the panels render,
|
|
182
|
+
// which used to change only after the save came back, so a second quick edit to the same
|
|
183
|
+
// class (Opacity, then Add shadow) was built without the first and saved over it.
|
|
184
|
+
const shownDesign = React.useRef<DesignSystem | null>(null);
|
|
185
|
+
const changeDesign = (next: DesignSystem) => {
|
|
186
|
+
const base = latest.current.design;
|
|
187
|
+
shownDesign.current = next;
|
|
188
|
+
dispatch({ type: "preview-design", design: next });
|
|
189
|
+
return queueDesign(() => saveDesignNow(next, base));
|
|
190
|
+
};
|
|
164
191
|
|
|
165
|
-
const saveDesignNow = async (next: DesignSystem) => {
|
|
192
|
+
const saveDesignNow = async (next: DesignSystem, base: DesignSystem) => {
|
|
166
193
|
try {
|
|
167
|
-
const
|
|
168
|
-
const revision = await saveDesign(fetcher, next,
|
|
169
|
-
|
|
170
|
-
|
|
194
|
+
const sent = baseRevision();
|
|
195
|
+
const revision = await saveDesign(fetcher, next, sent);
|
|
196
|
+
wrote(sent, revision);
|
|
197
|
+
// A newer edit waiting in the queue stays on screen; its own save follows.
|
|
198
|
+
dispatch({ type: "set-design", design: shownDesign.current ?? next, revision });
|
|
199
|
+
if (shownDesign.current === next) shownDesign.current = null;
|
|
171
200
|
} catch (error) {
|
|
172
201
|
written.current = null;
|
|
202
|
+
// A newer edit already on screen was built on this one, so it stays shown (W-536).
|
|
203
|
+
const newer =
|
|
204
|
+
shownDesign.current !== null && shownDesign.current !== next ? shownDesign.current : null;
|
|
205
|
+
const settled = () => {
|
|
206
|
+
if (!newer) shownDesign.current = null;
|
|
207
|
+
};
|
|
208
|
+
// Take back an edit that didn't save, unless a newer one is already on screen.
|
|
209
|
+
const takeBack = () => {
|
|
210
|
+
if (shownDesign.current !== next) return;
|
|
211
|
+
shownDesign.current = null;
|
|
212
|
+
dispatch({ type: "preview-design", design: base });
|
|
213
|
+
};
|
|
173
214
|
if (error instanceof ApiError && error.status === 409) {
|
|
174
215
|
// W-333: replay this tab's edit onto the styles saved elsewhere when those keys
|
|
175
216
|
// were not also changed there. A real clash still loads the server copy (W-212).
|
|
176
217
|
try {
|
|
177
218
|
const fresh = await loadDesign(fetcher);
|
|
178
|
-
const merged = mergeDesign(
|
|
219
|
+
const merged = mergeDesign(base, next, fresh.design);
|
|
179
220
|
const names = merged.conflicts.map((conflict) => conflict.name).join(", ");
|
|
180
221
|
if (merged.conflicts.length > 0) {
|
|
222
|
+
shownDesign.current = null;
|
|
181
223
|
dispatch({ type: "load-design", ...fresh });
|
|
182
224
|
throw new Error(
|
|
183
225
|
`Site styles were changed in another tab or window (${names}). The latest styles are loaded now: make your change again.`,
|
|
@@ -186,12 +228,14 @@ export function useEditorCommands({
|
|
|
186
228
|
}
|
|
187
229
|
const unchanged = JSON.stringify(merged.design) === JSON.stringify(fresh.design);
|
|
188
230
|
if (unchanged) {
|
|
189
|
-
dispatch({ type: "load-design", ...fresh });
|
|
231
|
+
dispatch({ type: "load-design", ...fresh, ...(newer ? { design: newer } : {}) });
|
|
232
|
+
settled();
|
|
190
233
|
return;
|
|
191
234
|
}
|
|
192
235
|
const revision = await saveDesign(fetcher, merged.design, fresh.revision);
|
|
193
|
-
|
|
194
|
-
dispatch({ type: "set-design", design: merged.design, revision });
|
|
236
|
+
wrote(fresh.revision, revision);
|
|
237
|
+
dispatch({ type: "set-design", design: newer ?? merged.design, revision });
|
|
238
|
+
settled();
|
|
195
239
|
return;
|
|
196
240
|
} catch (retry) {
|
|
197
241
|
if (
|
|
@@ -200,12 +244,14 @@ export function useEditorCommands({
|
|
|
200
244
|
) {
|
|
201
245
|
throw retry;
|
|
202
246
|
}
|
|
247
|
+
takeBack();
|
|
203
248
|
throw new Error(
|
|
204
249
|
"Site styles were changed somewhere else. Reload the editor and try again.",
|
|
205
250
|
{ cause: retry },
|
|
206
251
|
);
|
|
207
252
|
}
|
|
208
253
|
}
|
|
254
|
+
takeBack();
|
|
209
255
|
throw new Error(
|
|
210
256
|
error instanceof ApiError
|
|
211
257
|
? `Couldn't save site styles. ${error.message}`
|
|
@@ -54,7 +54,7 @@ export type EditorData =
|
|
|
54
54
|
| { state: "loading" }
|
|
55
55
|
| { state: "ready"; entry: EditorEntry; design: LoadedDesign }
|
|
56
56
|
| { state: "not-found" | "forbidden" }
|
|
57
|
-
| { state: "error"; message: string };
|
|
57
|
+
| { state: "error"; message: string; retry: () => void };
|
|
58
58
|
|
|
59
59
|
const UNREADABLE = "This page's layout can't be read.";
|
|
60
60
|
|
|
@@ -173,6 +173,7 @@ export function useEditorData(
|
|
|
173
173
|
collection: string = PAGES_COLLECTION,
|
|
174
174
|
): EditorData {
|
|
175
175
|
const [data, setData] = React.useState<EditorData>({ state: "loading" });
|
|
176
|
+
const [attempt, setAttempt] = React.useState(0);
|
|
176
177
|
React.useEffect(() => {
|
|
177
178
|
let active = true;
|
|
178
179
|
setData({ state: "loading" });
|
|
@@ -187,6 +188,7 @@ export function useEditorData(
|
|
|
187
188
|
setData({
|
|
188
189
|
state: "error",
|
|
189
190
|
message: error instanceof Error ? error.message : String(error),
|
|
191
|
+
retry: () => setAttempt((n) => n + 1),
|
|
190
192
|
});
|
|
191
193
|
}
|
|
192
194
|
},
|
|
@@ -194,6 +196,6 @@ export function useEditorData(
|
|
|
194
196
|
return () => {
|
|
195
197
|
active = false;
|
|
196
198
|
};
|
|
197
|
-
}, [fetcher, entryId, collection]);
|
|
199
|
+
}, [fetcher, entryId, collection, attempt]);
|
|
198
200
|
return data;
|
|
199
201
|
}
|
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
} from "../../core/index.ts";
|
|
14
14
|
import { runCommand, type CommandRunners } from "./editor-commands.ts";
|
|
15
15
|
import type { EditorState, HistoryAction } from "./store.ts";
|
|
16
|
-
import { inDialog, isPaletteShortcut } from "./shortcuts.ts";
|
|
16
|
+
import { inDialog, isPaletteShortcut, shortcutKey } from "./shortcuts.ts";
|
|
17
17
|
|
|
18
18
|
const isTextField = (target: EventTarget | null) => {
|
|
19
19
|
const element = target as HTMLElement | null;
|
|
@@ -127,18 +127,29 @@ export function useEditorShortcuts({
|
|
|
127
127
|
handlers.current.palette?.();
|
|
128
128
|
return;
|
|
129
129
|
}
|
|
130
|
-
if ((event.ctrlKey || event.metaKey) && event
|
|
130
|
+
if ((event.ctrlKey || event.metaKey) && shortcutKey(event) === "s") {
|
|
131
131
|
event.preventDefault();
|
|
132
132
|
runCommand(runners(), "save", null);
|
|
133
133
|
return;
|
|
134
134
|
}
|
|
135
|
+
// W-622: holding Delete, Ctrl+D or Ctrl+V auto-repeats; each repeat acted on the next selected
|
|
136
|
+
// element, so a long press emptied whole sections. They act once per press.
|
|
137
|
+
const destructive =
|
|
138
|
+
event.key === "Delete" ||
|
|
139
|
+
event.key === "Backspace" ||
|
|
140
|
+
((event.ctrlKey || event.metaKey) && ["d", "v"].includes(shortcutKey(event)));
|
|
141
|
+
if (event.repeat && destructive) {
|
|
142
|
+
// A held Backspace in a text field still deletes text as usual.
|
|
143
|
+
if (!isTextField(event.target) && !inDialog(event.target)) event.preventDefault();
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
135
146
|
if (isTextField(event.target) || inDialog(event.target)) return;
|
|
136
|
-
if ((event.ctrlKey || event.metaKey) && !event.altKey && event
|
|
147
|
+
if ((event.ctrlKey || event.metaKey) && !event.altKey && shortcutKey(event) === "z") {
|
|
137
148
|
event.preventDefault();
|
|
138
149
|
runCommand(runners(), event.shiftKey ? "redo" : "undo", null);
|
|
139
150
|
return;
|
|
140
151
|
}
|
|
141
|
-
if ((event.ctrlKey || event.metaKey) && !event.altKey && event
|
|
152
|
+
if ((event.ctrlKey || event.metaKey) && !event.altKey && shortcutKey(event) === "y") {
|
|
142
153
|
event.preventDefault();
|
|
143
154
|
runCommand(runners(), "redo", null);
|
|
144
155
|
return;
|
|
@@ -146,13 +157,12 @@ export function useEditorShortcuts({
|
|
|
146
157
|
if (!onCanvasOrLayers(event.target)) return;
|
|
147
158
|
const layout = latest.current.page.layout;
|
|
148
159
|
const selected = latest.current.selectedId;
|
|
149
|
-
if ((event.ctrlKey || event.metaKey) && event
|
|
160
|
+
if ((event.ctrlKey || event.metaKey) && shortcutKey(event) === "d" && selected) {
|
|
150
161
|
event.preventDefault();
|
|
151
162
|
runCommand(runners(), "duplicate", selected);
|
|
152
163
|
return;
|
|
153
164
|
}
|
|
154
|
-
const clipKey =
|
|
155
|
-
(event.ctrlKey || event.metaKey) && !event.altKey ? event.key.toLowerCase() : "";
|
|
165
|
+
const clipKey = (event.ctrlKey || event.metaKey) && !event.altKey ? shortcutKey(event) : "";
|
|
156
166
|
if (clipKey === "c" && !event.shiftKey && selected && !hasTextSelection(event.target)) {
|
|
157
167
|
event.preventDefault();
|
|
158
168
|
runCommand(runners(), "copy", selected);
|
|
@@ -9,8 +9,13 @@ import {
|
|
|
9
9
|
type WrapType,
|
|
10
10
|
ELEMENT_DESCRIPTORS,
|
|
11
11
|
findNode,
|
|
12
|
+
LAYOUT_SCHEMA_VERSION,
|
|
12
13
|
moveDown,
|
|
14
|
+
moveIn,
|
|
15
|
+
moveOut,
|
|
16
|
+
newNodeId,
|
|
13
17
|
moveUp,
|
|
18
|
+
parentOf,
|
|
14
19
|
recipeNode,
|
|
15
20
|
withFreshIds,
|
|
16
21
|
subtreeSize,
|
|
@@ -24,9 +29,40 @@ import { ELEMENT_NAMES } from "./element-chrome.ts";
|
|
|
24
29
|
import type { ItemActions } from "./panels/settings/ItemList.tsx";
|
|
25
30
|
import type { EditorAction, EditorState } from "./store.ts";
|
|
26
31
|
|
|
32
|
+
const MOVES = new Set<unknown>([moveUp, moveDown, moveIn, moveOut]);
|
|
33
|
+
|
|
34
|
+
/** "Moved. Heading is 2 of 3 in Container." for the screen reader after an Alt+arrow move. */
|
|
35
|
+
function movedTo(layout: Layout, id: string): string {
|
|
36
|
+
const node = findNode(layout, id);
|
|
37
|
+
const parentId = parentOf(layout, id);
|
|
38
|
+
const parent = parentId ? findNode(layout, parentId) : undefined;
|
|
39
|
+
const siblings: LayoutNode[] =
|
|
40
|
+
parent && "children" in parent && Array.isArray(parent.children) ? parent.children : [];
|
|
41
|
+
const index = siblings.findIndex((child) => child.id === id);
|
|
42
|
+
const name = ELEMENT_NAMES[node?.type ?? "container"] ?? "Element";
|
|
43
|
+
const where = ELEMENT_NAMES[parent?.type ?? "container"] ?? "its container";
|
|
44
|
+
return `Moved. ${name} is ${index + 1} of ${siblings.length} in ${where}.`;
|
|
45
|
+
}
|
|
46
|
+
|
|
27
47
|
const RESTORE_TIMEOUT_MS = 6000;
|
|
28
48
|
const NOTICE_TIMEOUT_MS = 4000;
|
|
29
49
|
|
|
50
|
+
/**
|
|
51
|
+
* UX-070: when an action removes the focused control (a deleted row, a closing toast), move focus
|
|
52
|
+
* to the selected layer, the Layers tree, or the canvas, instead of leaving it on the page body.
|
|
53
|
+
*/
|
|
54
|
+
function keepFocusInLayers(force = false) {
|
|
55
|
+
requestAnimationFrame(() => {
|
|
56
|
+
const active = document.activeElement;
|
|
57
|
+
if (!force && active && active !== document.body && active.isConnected) return;
|
|
58
|
+
(
|
|
59
|
+
document.querySelector<HTMLElement>('.emvb-layer-select[aria-current="true"]') ??
|
|
60
|
+
document.querySelector<HTMLElement>('[data-emvb-editor] [role="tree"]') ??
|
|
61
|
+
document.querySelector<HTMLElement>("iframe[data-emvb-canvas]")
|
|
62
|
+
)?.focus({ preventScroll: true });
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
30
66
|
/** Node actions on the layout tree: delete (with restore toast), duplicate, and add from the panel. */
|
|
31
67
|
export function useNodeActions({
|
|
32
68
|
state,
|
|
@@ -52,11 +88,18 @@ export function useNodeActions({
|
|
|
52
88
|
const canMove = canDelete;
|
|
53
89
|
|
|
54
90
|
const finishDelete = (id: string) => {
|
|
91
|
+
// UX-062: the toast names what went, as the confirm button does ("Delete 3 elements").
|
|
92
|
+
const layout = latest.current.page.layout;
|
|
93
|
+
const count = layout ? subtreeSize(layout, id) : 1;
|
|
94
|
+
const name = ELEMENT_NAMES[(layout && findNode(layout, id)?.type) || "container"] ?? "Element";
|
|
95
|
+
const title = count > 1 ? `${count} elements deleted` : `${name} deleted`;
|
|
55
96
|
dispatch({ type: "delete-node", id });
|
|
97
|
+
// UX-070: the deleted row or canvas element took focus with it; keep the keyboard in Layers.
|
|
98
|
+
keepFocusInLayers();
|
|
56
99
|
setDeleteAsk(null);
|
|
57
100
|
if (lastToast.current) toasts.close(lastToast.current);
|
|
58
101
|
const toastId: string = toasts.add({
|
|
59
|
-
title
|
|
102
|
+
title,
|
|
60
103
|
timeout: RESTORE_TIMEOUT_MS,
|
|
61
104
|
actions: [
|
|
62
105
|
{
|
|
@@ -65,6 +108,8 @@ export function useNodeActions({
|
|
|
65
108
|
onClick: () => {
|
|
66
109
|
dispatch({ type: "restore" });
|
|
67
110
|
toasts.close(toastId);
|
|
111
|
+
// The toast is closing with focus in it; the restored element's row takes it.
|
|
112
|
+
keepFocusInLayers(true);
|
|
68
113
|
},
|
|
69
114
|
},
|
|
70
115
|
],
|
|
@@ -99,6 +144,8 @@ export function useNodeActions({
|
|
|
99
144
|
return;
|
|
100
145
|
}
|
|
101
146
|
dispatch({ type: "apply-arranged", layout: result.layout, selected: result.selected });
|
|
147
|
+
// W-770: a keyboard move only announced refusals; say where the element landed.
|
|
148
|
+
if (MOVES.has(run)) announce(movedTo(result.layout, id));
|
|
102
149
|
if (result.note) {
|
|
103
150
|
announce(`Duplicated. ${result.note}`);
|
|
104
151
|
if (lastToast.current) toasts.close(lastToast.current);
|
|
@@ -176,11 +223,14 @@ export function useNodeActions({
|
|
|
176
223
|
};
|
|
177
224
|
|
|
178
225
|
const addFromPanel = (type: ElementType) => {
|
|
179
|
-
const
|
|
180
|
-
if (!
|
|
181
|
-
|
|
226
|
+
const current = latest.current.page.layout;
|
|
227
|
+
if (!current && type === "container") {
|
|
228
|
+
dispatch({ type: "add-root-container" });
|
|
182
229
|
return;
|
|
183
230
|
}
|
|
231
|
+
// UX-094: an empty page (one made outside EmVB has no layout) gets its container first, so
|
|
232
|
+
// a click or palette insert lands instead of doing nothing.
|
|
233
|
+
const layout = current ?? startingLayout();
|
|
184
234
|
const node = newElement(type);
|
|
185
235
|
if (!node) return;
|
|
186
236
|
place(layout, node, ELEMENT_DESCRIPTORS.find((d) => d.type === type)?.name ?? type);
|
|
@@ -188,8 +238,7 @@ export function useNodeActions({
|
|
|
188
238
|
|
|
189
239
|
/** A section recipe built from the site's styles (W-320). */
|
|
190
240
|
const addRecipe = (id: string) => {
|
|
191
|
-
const layout = latest.current.page.layout;
|
|
192
|
-
if (!layout) return;
|
|
241
|
+
const layout = latest.current.page.layout ?? startingLayout();
|
|
193
242
|
const node = recipeNode(id, latest.current.design, layout);
|
|
194
243
|
if (!node) return;
|
|
195
244
|
place(layout, withFreshIds(layout, node), `${node.label ?? "Section"} section`, true);
|
|
@@ -210,3 +259,9 @@ export function useNodeActions({
|
|
|
210
259
|
items,
|
|
211
260
|
};
|
|
212
261
|
}
|
|
262
|
+
|
|
263
|
+
/** One empty container, the start of a page that has no layout yet (UX-094). */
|
|
264
|
+
const startingLayout = (): Layout => ({
|
|
265
|
+
schemaVersion: LAYOUT_SCHEMA_VERSION,
|
|
266
|
+
root: { id: newNodeId(), type: "container", props: {}, children: [] },
|
|
267
|
+
});
|
|
@@ -65,7 +65,12 @@ export function saveFailure(
|
|
|
65
65
|
if (error.status === 400 || error.status === 422) {
|
|
66
66
|
const path = /\broot(?:\.children\[\d+\])*/.exec(error.message)?.[0];
|
|
67
67
|
const id = path && page.layout ? nodeIdAtPath(page.layout, path) : null;
|
|
68
|
-
|
|
68
|
+
// UX-095: with no element to highlight, "fix the highlighted setting" pointed at nothing.
|
|
69
|
+
if (!id) {
|
|
70
|
+
const message = `Couldn't save. ${error.message}`;
|
|
71
|
+
return { status: { kind: "error", message, retry: false }, rejection: error.message };
|
|
72
|
+
}
|
|
73
|
+
return { status: fixAndSave, rejection: error.message, select: id };
|
|
69
74
|
}
|
|
70
75
|
return { status: { kind: "error", message: `Couldn't save. ${error.message}`, retry: false } };
|
|
71
76
|
}
|
|
@@ -189,14 +194,24 @@ export function useSave(
|
|
|
189
194
|
}, [start]);
|
|
190
195
|
|
|
191
196
|
/** Conflict → Overwrite: take the stored revision and save over it. */
|
|
197
|
+
// W-836: the overwrite counts as the save in flight, so a save asked for meanwhile (Save draft,
|
|
198
|
+
// Ctrl+S, autosave) waits for it and uses its new revision instead of the stale one, which
|
|
199
|
+
// reopened the conflict right after a successful overwrite.
|
|
192
200
|
const overwrite = React.useCallback(async () => {
|
|
193
201
|
setConflict(false);
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
202
|
+
const run: Promise<string | null> = (async () => {
|
|
203
|
+
try {
|
|
204
|
+
const stored = await loadEntry(fetcher, latest.current.id, collection);
|
|
205
|
+
return await write(stored.rev);
|
|
206
|
+
} catch {
|
|
207
|
+
setStatus({ kind: "error", message: OFFLINE, retry: true });
|
|
208
|
+
return null;
|
|
209
|
+
}
|
|
210
|
+
})().finally(() => {
|
|
211
|
+
if (inFlight.current === run) inFlight.current = null;
|
|
212
|
+
});
|
|
213
|
+
inFlight.current = run;
|
|
214
|
+
await run;
|
|
200
215
|
}, [fetcher, write, collection]);
|
|
201
216
|
|
|
202
217
|
const publish = React.useCallback(async (): Promise<boolean> => {
|
package/src/admin/forms-api.ts
CHANGED
|
@@ -66,6 +66,8 @@ export type DefinitionField = {
|
|
|
66
66
|
type: string;
|
|
67
67
|
label: string;
|
|
68
68
|
required: boolean;
|
|
69
|
+
options?: ReadonlyArray<{ label: string; value: string }>;
|
|
70
|
+
validation?: { minLength?: number; maxLength?: number; min?: number; max?: number };
|
|
69
71
|
};
|
|
70
72
|
|
|
71
73
|
export async function loadFormFields(
|
|
@@ -25,6 +25,7 @@ import {
|
|
|
25
25
|
} from "./curve-math.ts";
|
|
26
26
|
import { drawRgbHistogram, useImageEditor, type CurvePoint } from "./engine.ts";
|
|
27
27
|
import { PanelHeader, SectionTabs } from "./parts.tsx";
|
|
28
|
+
import { isCommitEnter } from "../editor/ime.ts";
|
|
28
29
|
|
|
29
30
|
const SIZE = 240;
|
|
30
31
|
const LABEL: Record<CurvesChannel, string> = { rgb: "RGB", r: "R", g: "G", b: "B" };
|
|
@@ -379,7 +380,7 @@ function LevelField({
|
|
|
379
380
|
if (draft !== null) apply(event.currentTarget.value);
|
|
380
381
|
}}
|
|
381
382
|
onKeyDown={(event) => {
|
|
382
|
-
if (event
|
|
383
|
+
if (isCommitEnter(event)) {
|
|
383
384
|
event.preventDefault();
|
|
384
385
|
apply(event.currentTarget.value);
|
|
385
386
|
} else if (event.key === "Escape") {
|
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
XIcon,
|
|
16
16
|
} from "@phosphor-icons/react";
|
|
17
17
|
import * as React from "react";
|
|
18
|
+
import { ImageEditOutput } from "../../core/index.ts";
|
|
18
19
|
import { SOLID_PRIMARY } from "../ui.ts";
|
|
19
20
|
import { withDataUrlFetch } from "./data-url-fetch.ts";
|
|
20
21
|
import { downloadBlob, flattenToJpeg, needsFlatten } from "./flatten.ts";
|
|
@@ -42,6 +43,9 @@ export type ExportSettings = {
|
|
|
42
43
|
export type ExportResult = { blob: Blob; width: number; height: number; type: string };
|
|
43
44
|
|
|
44
45
|
const MAX_PX = 16384;
|
|
46
|
+
const COPY_SIZE_BOUNDS = ImageEditOutput.shape.maxSide.unwrap();
|
|
47
|
+
const COPY_SIZE_HINT = `For Save copy, use Full size or a custom longest side between ${COPY_SIZE_BOUNDS.minValue} and ${COPY_SIZE_BOUNDS.maxValue} px.`;
|
|
48
|
+
type Pending = "download" | "save" | null;
|
|
45
49
|
|
|
46
50
|
export function ExportDialog({
|
|
47
51
|
open,
|
|
@@ -64,10 +68,14 @@ export function ExportDialog({
|
|
|
64
68
|
onSave: (result: ExportResult, settings: ExportSettings) => Promise<void>;
|
|
65
69
|
onClosed?: () => void;
|
|
66
70
|
}) {
|
|
71
|
+
const [pending, setPending] = React.useState<Pending>(null);
|
|
67
72
|
return (
|
|
68
73
|
<Dialog.Root
|
|
69
74
|
open={open}
|
|
70
|
-
onOpenChange={(next) =>
|
|
75
|
+
onOpenChange={(next) => {
|
|
76
|
+
if (!next && pending === "save") return;
|
|
77
|
+
onOpenChange(next);
|
|
78
|
+
}}
|
|
71
79
|
onOpenChangeComplete={(next) => {
|
|
72
80
|
if (!next) onClosed?.();
|
|
73
81
|
}}
|
|
@@ -80,6 +88,8 @@ export function ExportDialog({
|
|
|
80
88
|
sourceType={sourceType}
|
|
81
89
|
downloadName={downloadName}
|
|
82
90
|
onSave={onSave}
|
|
91
|
+
pending={pending}
|
|
92
|
+
onPendingChange={setPending}
|
|
83
93
|
/>
|
|
84
94
|
) : null}
|
|
85
95
|
</Dialog>
|
|
@@ -93,12 +103,16 @@ function ExportForm({
|
|
|
93
103
|
sourceType,
|
|
94
104
|
downloadName,
|
|
95
105
|
onSave,
|
|
106
|
+
pending,
|
|
107
|
+
onPendingChange,
|
|
96
108
|
}: {
|
|
97
109
|
mainThread: boolean;
|
|
98
110
|
sourceHasGps: boolean;
|
|
99
111
|
sourceType: string;
|
|
100
112
|
downloadName: string;
|
|
101
113
|
onSave: (result: ExportResult, settings: ExportSettings) => Promise<void>;
|
|
114
|
+
pending: Pending;
|
|
115
|
+
onPendingChange: (pending: Pending) => void;
|
|
102
116
|
}) {
|
|
103
117
|
const editor = useImageEditor();
|
|
104
118
|
const id = React.useId();
|
|
@@ -111,17 +125,37 @@ function ExportForm({
|
|
|
111
125
|
full ? cappedWidth(full, DEFAULT_MAX_SIDE) : null,
|
|
112
126
|
);
|
|
113
127
|
const [stripGps, setStripGps] = React.useState(true);
|
|
114
|
-
const [pending, setPending] = React.useState<"download" | "save" | null>(null);
|
|
115
128
|
const [error, setError] = React.useState<string | null>(null);
|
|
116
129
|
const [failedSave, setFailedSave] = React.useState(false);
|
|
117
130
|
const output = full ? outputSize(full, width) : null;
|
|
131
|
+
const maximum = full
|
|
132
|
+
? outputSize(
|
|
133
|
+
full,
|
|
134
|
+
Math.max(1, Math.floor((MAX_PX * full.width) / Math.max(full.width, full.height))),
|
|
135
|
+
)
|
|
136
|
+
: null;
|
|
118
137
|
const canExport = editor.isReady && !editor.disabled;
|
|
119
138
|
const lossy = selected.lossy;
|
|
120
139
|
const jpegGps = format === "jpeg" && sourceHasGps;
|
|
121
140
|
|
|
122
141
|
const run = async (kind: "download" | "save") => {
|
|
142
|
+
// W-825: Download and Save copy stay focusable while working (aria-disabled), so a press
|
|
143
|
+
// made then is ignored here instead of by a disabled button that drops focus to the body.
|
|
144
|
+
if (pending !== null) return;
|
|
123
145
|
setError(null);
|
|
124
|
-
|
|
146
|
+
const settings: ExportSettings = {
|
|
147
|
+
format,
|
|
148
|
+
...(lossy ? { quality } : {}),
|
|
149
|
+
...(width && output ? { maxSide: Math.max(output.width, output.height) } : {}),
|
|
150
|
+
// Only JPEG copies carry EXIF over; WebP and PNG never have a location.
|
|
151
|
+
stripGps: format === "jpeg" ? stripGps : true,
|
|
152
|
+
};
|
|
153
|
+
if (kind === "save" && !ImageEditOutput.shape.maxSide.safeParse(settings.maxSide).success) {
|
|
154
|
+
setError(COPY_SIZE_HINT);
|
|
155
|
+
setFailedSave(false);
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
onPendingChange(kind);
|
|
125
159
|
const options = {
|
|
126
160
|
format,
|
|
127
161
|
quality: lossy ? quality : undefined,
|
|
@@ -142,13 +176,6 @@ function ExportForm({
|
|
|
142
176
|
try {
|
|
143
177
|
const result = mainThread ? await withDataUrlFetch(exportTask) : await exportTask();
|
|
144
178
|
if (kind === "save") {
|
|
145
|
-
const settings: ExportSettings = {
|
|
146
|
-
format,
|
|
147
|
-
...(lossy ? { quality } : {}),
|
|
148
|
-
...(width && output ? { maxSide: Math.max(output.width, output.height) } : {}),
|
|
149
|
-
// Only JPEG copies carry EXIF over; WebP and PNG never have a location.
|
|
150
|
-
stripGps: format === "jpeg" ? stripGps : true,
|
|
151
|
-
};
|
|
152
179
|
await onSave(result, settings);
|
|
153
180
|
}
|
|
154
181
|
setFailedSave(false);
|
|
@@ -156,19 +183,19 @@ function ExportForm({
|
|
|
156
183
|
setError(caught instanceof Error && caught.message ? caught.message : "Export failed.");
|
|
157
184
|
if (kind === "save") setFailedSave(true);
|
|
158
185
|
} finally {
|
|
159
|
-
|
|
186
|
+
onPendingChange(null);
|
|
160
187
|
}
|
|
161
188
|
};
|
|
162
189
|
|
|
163
190
|
const setSide = (raw: string, side: "width" | "height") => {
|
|
164
|
-
if (!full) return;
|
|
191
|
+
if (!full || !maximum) return;
|
|
165
192
|
const next = Number(raw);
|
|
166
193
|
if (!(next > 0)) {
|
|
167
194
|
setWidth(null);
|
|
168
195
|
return;
|
|
169
196
|
}
|
|
170
197
|
const w = side === "width" ? Math.round(next) : Math.round((next * full.width) / full.height);
|
|
171
|
-
setWidth(Math.max(1, Math.min(
|
|
198
|
+
setWidth(Math.max(1, Math.min(maximum.width, w)));
|
|
172
199
|
};
|
|
173
200
|
|
|
174
201
|
return (
|
|
@@ -182,8 +209,9 @@ function ExportForm({
|
|
|
182
209
|
<Dialog.Description className="emvb-ie-export-desc">
|
|
183
210
|
Pick a format and size. Rendering always starts from the original.
|
|
184
211
|
</Dialog.Description>
|
|
212
|
+
{/* W-830: Close stays focusable while saving (onOpenChange already refuses to close). */}
|
|
185
213
|
<Dialog.Close
|
|
186
|
-
disabled={pending === "save"}
|
|
214
|
+
aria-disabled={pending === "save"}
|
|
187
215
|
render={(props) => (
|
|
188
216
|
<Button
|
|
189
217
|
{...props}
|
|
@@ -261,7 +289,7 @@ function ExportForm({
|
|
|
261
289
|
type="number"
|
|
262
290
|
inputMode="numeric"
|
|
263
291
|
min={1}
|
|
264
|
-
max={MAX_PX}
|
|
292
|
+
max={maximum?.width ?? MAX_PX}
|
|
265
293
|
value={output.width}
|
|
266
294
|
data-emvb-image-export-width=""
|
|
267
295
|
onChange={(event) => setSide(event.currentTarget.value, "width")}
|
|
@@ -273,7 +301,7 @@ function ExportForm({
|
|
|
273
301
|
type="number"
|
|
274
302
|
inputMode="numeric"
|
|
275
303
|
min={1}
|
|
276
|
-
max={MAX_PX}
|
|
304
|
+
max={maximum?.height ?? MAX_PX}
|
|
277
305
|
value={output.height}
|
|
278
306
|
data-emvb-image-export-height=""
|
|
279
307
|
onChange={(event) => setSide(event.currentTarget.value, "height")}
|
|
@@ -315,7 +343,8 @@ function ExportForm({
|
|
|
315
343
|
variant="outline"
|
|
316
344
|
size="sm"
|
|
317
345
|
className="emvb-ie-btn"
|
|
318
|
-
disabled={!canExport
|
|
346
|
+
disabled={!canExport}
|
|
347
|
+
aria-disabled={pending !== null}
|
|
319
348
|
icon={
|
|
320
349
|
pending === "download" ? (
|
|
321
350
|
<span className="emvb-ie-spinner emvb-ie-spinner-sm" aria-hidden="true" />
|
|
@@ -334,7 +363,8 @@ function ExportForm({
|
|
|
334
363
|
size="sm"
|
|
335
364
|
className="emvb-ie-btn"
|
|
336
365
|
style={SOLID_PRIMARY}
|
|
337
|
-
disabled={!canExport
|
|
366
|
+
disabled={!canExport}
|
|
367
|
+
aria-disabled={pending !== null}
|
|
338
368
|
aria-busy={pending === "save" || undefined}
|
|
339
369
|
icon={
|
|
340
370
|
pending === "save" ? (
|