@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,20 +1,23 @@
|
|
|
1
|
-
import { Button, DropdownMenu } from "@cloudflare/kumo";
|
|
2
|
-
import
|
|
1
|
+
import { Button, DropdownMenu, Loader } from "@cloudflare/kumo";
|
|
2
|
+
import * as React from "react";
|
|
3
3
|
import {
|
|
4
4
|
ArrowSquareOutIcon,
|
|
5
5
|
CaretDownIcon,
|
|
6
6
|
DesktopIcon,
|
|
7
7
|
DeviceMobileIcon,
|
|
8
8
|
DeviceTabletIcon,
|
|
9
|
+
FloppyDiskIcon,
|
|
9
10
|
KeyboardIcon,
|
|
10
11
|
PaintBrushIcon,
|
|
11
12
|
SignOutIcon,
|
|
13
|
+
UploadSimpleIcon,
|
|
12
14
|
WarningCircleIcon,
|
|
13
15
|
} from "@phosphor-icons/react";
|
|
14
16
|
import { BUTTON, SOLID_PRIMARY } from "../ui.ts";
|
|
15
17
|
import { statusLabel } from "../entry-status.ts";
|
|
16
18
|
import type { SaveStatus } from "./useSave.ts";
|
|
17
19
|
import type { PopupDevice } from "../../core/index.ts";
|
|
20
|
+
import { useMediaQuery } from "./useMediaQuery.ts";
|
|
18
21
|
|
|
19
22
|
/** Preview sizes (W-158): the canvas device widths, in a window of that size. */
|
|
20
23
|
const PREVIEW_SIZES = [
|
|
@@ -28,14 +31,17 @@ export type TopBarPage = { title: string; status: string };
|
|
|
28
31
|
function SaveStatusText({
|
|
29
32
|
status,
|
|
30
33
|
dirty,
|
|
34
|
+
busy,
|
|
31
35
|
onRetry,
|
|
32
36
|
}: {
|
|
33
37
|
status: SaveStatus;
|
|
34
38
|
dirty: boolean;
|
|
39
|
+
busy: "save" | "publish" | null;
|
|
35
40
|
onRetry: () => void;
|
|
36
41
|
}) {
|
|
37
42
|
let content: React.ReactNode = null;
|
|
38
|
-
if (
|
|
43
|
+
if (busy === "publish") content = "Publishing…";
|
|
44
|
+
else if (busy === "save" || status.kind === "saving") content = "Saving…";
|
|
39
45
|
else if (status.kind === "error") {
|
|
40
46
|
content = (
|
|
41
47
|
<>
|
|
@@ -94,6 +100,21 @@ export function TopBar({
|
|
|
94
100
|
/** Extra tools beside Site styles: the page weight and accessibility meters, … (W-310). */
|
|
95
101
|
tools?: React.ReactNode;
|
|
96
102
|
}) {
|
|
103
|
+
const reducedMotion = useMediaQuery("(prefers-reduced-motion: reduce)");
|
|
104
|
+
// W-769: a disabled button drops focus to the page body, so the button that was focused when
|
|
105
|
+
// the work began gets it back once it is done. W-816: Save draft and Publish no longer disable
|
|
106
|
+
// while busy (aria-disabled, repeat presses ignored), so focus stays on them throughout.
|
|
107
|
+
const refocus = React.useRef<HTMLElement | null>(null);
|
|
108
|
+
const remember = (event: React.MouseEvent<HTMLElement>) => {
|
|
109
|
+
refocus.current = document.activeElement === event.currentTarget ? event.currentTarget : null;
|
|
110
|
+
};
|
|
111
|
+
React.useEffect(() => {
|
|
112
|
+
const button = refocus.current;
|
|
113
|
+
if (busy !== null || !button) return;
|
|
114
|
+
refocus.current = null;
|
|
115
|
+
const active = document.activeElement;
|
|
116
|
+
if (button.isConnected && (!active || active === document.body)) button.focus();
|
|
117
|
+
}, [busy]);
|
|
97
118
|
return (
|
|
98
119
|
<header className="emvb-topbar">
|
|
99
120
|
<div className="emvb-topbar-start">
|
|
@@ -107,7 +128,10 @@ export function TopBar({
|
|
|
107
128
|
</Button>
|
|
108
129
|
{page && (
|
|
109
130
|
<>
|
|
110
|
-
|
|
131
|
+
{/* UX-031: a long title ellipsizes; the tooltip keeps the whole name (DESIGN.md). */}
|
|
132
|
+
<span className="emvb-topbar-title" title={page.title ? page.title : "Untitled page"}>
|
|
133
|
+
{page.title || "Untitled page"}
|
|
134
|
+
</span>
|
|
111
135
|
<span className="emvb-status" data-status={page.status}>
|
|
112
136
|
<span className="emvb-status-dot" aria-hidden="true" />
|
|
113
137
|
{statusLabel(page.status)}
|
|
@@ -115,7 +139,11 @@ export function TopBar({
|
|
|
115
139
|
</>
|
|
116
140
|
)}
|
|
117
141
|
</div>
|
|
118
|
-
{page ?
|
|
142
|
+
{page ? (
|
|
143
|
+
<SaveStatusText status={status} dirty={dirty} busy={busy} onRetry={onSave} />
|
|
144
|
+
) : (
|
|
145
|
+
<div />
|
|
146
|
+
)}
|
|
119
147
|
<div
|
|
120
148
|
className="emvb-topbar-end"
|
|
121
149
|
style={{
|
|
@@ -177,6 +205,8 @@ export function TopBar({
|
|
|
177
205
|
onClick={() => onPreview()}
|
|
178
206
|
>
|
|
179
207
|
Preview
|
|
208
|
+
{/* UX-082: the icon shows a new tab opens; screen readers hear it. */}
|
|
209
|
+
<span className="emvb-sr-only"> (opens in a new tab)</span>
|
|
180
210
|
</Button>
|
|
181
211
|
<DropdownMenu>
|
|
182
212
|
<DropdownMenu.Trigger>
|
|
@@ -202,10 +232,16 @@ export function TopBar({
|
|
|
202
232
|
<Button
|
|
203
233
|
variant="ghost"
|
|
204
234
|
className={`${BUTTON} emvb-revert-button`}
|
|
205
|
-
|
|
235
|
+
// W-828: a save or publish no longer disables Revert (focus fell to the page
|
|
236
|
+
// body on Ctrl+S); it stays focusable and ignores presses while busy.
|
|
237
|
+
disabled={!canRevert}
|
|
238
|
+
aria-disabled={busy !== null}
|
|
206
239
|
title={canRevert ? "Revert to published" : "No changes since the last publish"}
|
|
207
240
|
aria-label="Revert to published"
|
|
208
|
-
onClick={
|
|
241
|
+
onClick={() => {
|
|
242
|
+
if (busy !== null) return;
|
|
243
|
+
onRevert();
|
|
244
|
+
}}
|
|
209
245
|
>
|
|
210
246
|
Revert
|
|
211
247
|
</Button>
|
|
@@ -213,10 +249,21 @@ export function TopBar({
|
|
|
213
249
|
<Button
|
|
214
250
|
variant="secondary"
|
|
215
251
|
className={`${BUTTON} emvb-save-button`}
|
|
216
|
-
|
|
217
|
-
|
|
252
|
+
icon={
|
|
253
|
+
busy === "save" && !reducedMotion ? (
|
|
254
|
+
<Loader size={14} />
|
|
255
|
+
) : (
|
|
256
|
+
<FloppyDiskIcon size={14} aria-hidden="true" />
|
|
257
|
+
)
|
|
258
|
+
}
|
|
259
|
+
aria-disabled={busy !== null}
|
|
260
|
+
aria-busy={busy === "save"}
|
|
218
261
|
aria-label={dirty ? "Save draft (unsaved changes)" : "Save draft"}
|
|
219
|
-
onClick={
|
|
262
|
+
onClick={(event) => {
|
|
263
|
+
if (busy !== null) return;
|
|
264
|
+
remember(event);
|
|
265
|
+
onSave();
|
|
266
|
+
}}
|
|
220
267
|
>
|
|
221
268
|
Save draft
|
|
222
269
|
{dirty && <span className="emvb-unsaved-dot" aria-hidden="true" />}
|
|
@@ -225,8 +272,15 @@ export function TopBar({
|
|
|
225
272
|
variant="primary"
|
|
226
273
|
className={`${BUTTON} emvb-publish-button`}
|
|
227
274
|
style={SOLID_PRIMARY}
|
|
228
|
-
|
|
229
|
-
|
|
275
|
+
icon={
|
|
276
|
+
busy === "publish" && !reducedMotion ? (
|
|
277
|
+
<Loader size={14} />
|
|
278
|
+
) : (
|
|
279
|
+
<UploadSimpleIcon size={14} aria-hidden="true" />
|
|
280
|
+
)
|
|
281
|
+
}
|
|
282
|
+
aria-disabled={busy !== null}
|
|
283
|
+
aria-busy={busy === "publish"}
|
|
230
284
|
aria-label={stylesUnpublished ? "Publish (site styles unpublished)" : undefined}
|
|
231
285
|
title={
|
|
232
286
|
stylesUnpublished
|
|
@@ -234,10 +288,13 @@ export function TopBar({
|
|
|
234
288
|
: undefined
|
|
235
289
|
}
|
|
236
290
|
data-emvb-styles-pending={stylesUnpublished ? "true" : undefined}
|
|
237
|
-
onClick={
|
|
291
|
+
onClick={(event) => {
|
|
292
|
+
if (busy !== null) return;
|
|
293
|
+
remember(event);
|
|
294
|
+
onPublish();
|
|
295
|
+
}}
|
|
238
296
|
>
|
|
239
297
|
Publish
|
|
240
|
-
{stylesUnpublished && <span className="emvb-styles-dot" aria-hidden="true" />}
|
|
241
298
|
</Button>
|
|
242
299
|
</div>
|
|
243
300
|
)}
|
|
@@ -2,6 +2,7 @@ import { createPortal } from "react-dom";
|
|
|
2
2
|
import { isMultilineText, type Layout, type PopupDevice, type VNode } from "../../../core/index.ts";
|
|
3
3
|
import type { PasteRefusal } from "../useClipboardActions.ts";
|
|
4
4
|
import { CanvasTextEdit } from "./CanvasTextEdit.tsx";
|
|
5
|
+
import { useFrameFocusRing } from "./frame-focus-ring.ts";
|
|
5
6
|
import { type CanvasZoom } from "./canvas-scale.ts";
|
|
6
7
|
import { SelectionOverlay, type Box, type InvalidDrop } from "./SelectionOverlay.tsx";
|
|
7
8
|
import type { StatePreview } from "./state-preview.ts";
|
|
@@ -38,6 +39,9 @@ const EDITOR_CANVAS_CSS =
|
|
|
38
39
|
`:where(${DROP_BOXES}){min-height:48px}` +
|
|
39
40
|
`:is(${DROP_BOXES}){outline:1px dashed #94a3b8;outline-offset:-1px;display:flex;align-items:center;justify-content:center}` +
|
|
40
41
|
`:is(${DROP_BOXES})::after{content:"Drop elements here";${HINT}}` +
|
|
42
|
+
// UX-019: an empty page fills the canvas, so the whole stage takes a drop and says how to start.
|
|
43
|
+
":where(.emvb-root:empty){min-height:100vh}" +
|
|
44
|
+
'.emvb-root:empty::after{content:"Drag an element here from Add to start building";font-size:18px}' +
|
|
41
45
|
`:where(${DROP_BODIES}){min-height:48px}` +
|
|
42
46
|
`:is(${DROP_BODIES}){outline:1px dashed #94a3b8;outline-offset:-1px}` +
|
|
43
47
|
`:is(${DROP_BODIES})::after{content:"Drop elements here";display:block;line-height:48px;text-align:center;${HINT}}` +
|
|
@@ -131,6 +135,7 @@ export function CanvasFrame({
|
|
|
131
135
|
onScale,
|
|
132
136
|
refusal,
|
|
133
137
|
});
|
|
138
|
+
const focusRing = useFrameFocusRing();
|
|
134
139
|
const { dropLine, dropTarget, invalid } = useCanvasDnD({
|
|
135
140
|
doc: session.doc,
|
|
136
141
|
frame: session.frame,
|
|
@@ -185,7 +190,11 @@ export function CanvasFrame({
|
|
|
185
190
|
data-emvb-canvas=""
|
|
186
191
|
srcDoc={SRCDOC}
|
|
187
192
|
sandbox="allow-same-origin"
|
|
188
|
-
|
|
193
|
+
data-emvb-canvas-focus={focusRing.ring ? "keyboard" : undefined}
|
|
194
|
+
onLoad={(event) => {
|
|
195
|
+
focusRing.watch(event);
|
|
196
|
+
onLoad();
|
|
197
|
+
}}
|
|
189
198
|
/>
|
|
190
199
|
{editingId && editingText !== null && editingBox && editingEl?.nodeType === 1 && (
|
|
191
200
|
<CanvasTextEdit
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import { commitPlainText } from "../../../core/index.ts";
|
|
3
3
|
import type { Box } from "./SelectionOverlay.tsx";
|
|
4
|
+
import { isCancelEscape, isCommitEnter } from "../ime.ts";
|
|
4
5
|
|
|
5
6
|
/** Edits one element's plain text over its canvas box (W-097). The iframe stays script-free. */
|
|
6
7
|
export function CanvasTextEdit({
|
|
@@ -30,6 +31,11 @@ export function CanvasTextEdit({
|
|
|
30
31
|
letterSpacing: computed?.letterSpacing,
|
|
31
32
|
lineHeight: computed?.lineHeight,
|
|
32
33
|
padding: computed?.padding,
|
|
34
|
+
// W-560: an RTL heading edited left to right jumped to the other side and reordered mixed
|
|
35
|
+
// text; an uppercase one showed its lower-case letters.
|
|
36
|
+
direction: computed?.direction as React.CSSProperties["direction"],
|
|
37
|
+
textTransform: computed?.textTransform as React.CSSProperties["textTransform"],
|
|
38
|
+
wordSpacing: computed?.wordSpacing,
|
|
33
39
|
};
|
|
34
40
|
}, [element]);
|
|
35
41
|
const ref = React.useRef<HTMLTextAreaElement>(null);
|
|
@@ -74,10 +80,10 @@ export function CanvasTextEdit({
|
|
|
74
80
|
onBlur={() => finish(commitPlainText(draft, multiline))}
|
|
75
81
|
onKeyDown={(event) => {
|
|
76
82
|
event.stopPropagation();
|
|
77
|
-
if (event
|
|
83
|
+
if (isCancelEscape(event)) {
|
|
78
84
|
event.preventDefault();
|
|
79
85
|
finish(null);
|
|
80
|
-
} else if (event
|
|
86
|
+
} else if (isCommitEnter(event) && !multiline) {
|
|
81
87
|
event.preventDefault();
|
|
82
88
|
finish(commitPlainText(draft, false));
|
|
83
89
|
}
|
|
@@ -9,15 +9,23 @@ export function dropLineBox(
|
|
|
9
9
|
index: number,
|
|
10
10
|
): Box {
|
|
11
11
|
const row = direction.startsWith("row");
|
|
12
|
+
// W-559: in a reversed flow (row-reverse, or a row in RTL) the first child is at the far end.
|
|
13
|
+
const reverse = direction.endsWith("reverse");
|
|
12
14
|
const [start, size] = row ? (["left", "width"] as const) : (["top", "height"] as const);
|
|
15
|
+
const end = (rect: Rect) => rect[start] + rect[size];
|
|
13
16
|
const first = children[0];
|
|
14
17
|
const last = children.at(-1);
|
|
15
18
|
const before = index > 0 ? children[index - 1] : undefined;
|
|
16
19
|
const after = index < children.length ? children[index] : undefined;
|
|
17
20
|
let at = container[start];
|
|
18
|
-
if (first && index <= 0) at = first[start];
|
|
19
|
-
else if (last && index >= children.length) at = last[start]
|
|
20
|
-
else if (before && after)
|
|
21
|
+
if (first && index <= 0) at = reverse ? end(first) : first[start];
|
|
22
|
+
else if (last && index >= children.length) at = reverse ? last[start] : end(last);
|
|
23
|
+
else if (before && after) {
|
|
24
|
+
at =
|
|
25
|
+
before[start] <= after[start]
|
|
26
|
+
? (end(before) + after[start]) / 2
|
|
27
|
+
: (end(after) + before[start]) / 2;
|
|
28
|
+
}
|
|
21
29
|
return row
|
|
22
30
|
? { top: container.top, left: at - 1, width: 2, height: container.height }
|
|
23
31
|
: { top: at - 1, left: container.left, width: container.width, height: 2 };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { useRef, useState, type SyntheticEvent } from "react";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* W-809: the canvas iframe is a Tab stop (its document takes the canvas shortcuts), but a focused
|
|
5
|
+
* iframe matches neither :focus nor :focus-visible in Chrome, so CSS alone never drew a ring
|
|
6
|
+
* (WCAG 2.4.7), and the iframe element gets no focus event either. The frame's own window
|
|
7
|
+
* reports its focus here instead. A pointer press inside the page marks
|
|
8
|
+
* the focus as a click, which gets no ring, as :focus-visible would decide.
|
|
9
|
+
*/
|
|
10
|
+
export function useFrameFocusRing() {
|
|
11
|
+
const [ring, setRing] = useState(false);
|
|
12
|
+
const pointer = useRef(false);
|
|
13
|
+
const onPointer = () => {
|
|
14
|
+
pointer.current = true;
|
|
15
|
+
setRing(false);
|
|
16
|
+
};
|
|
17
|
+
const onFocus = () => {
|
|
18
|
+
setRing(!pointer.current);
|
|
19
|
+
pointer.current = false;
|
|
20
|
+
};
|
|
21
|
+
const onBlur = () => {
|
|
22
|
+
pointer.current = false;
|
|
23
|
+
setRing(false);
|
|
24
|
+
};
|
|
25
|
+
return {
|
|
26
|
+
ring,
|
|
27
|
+
/** Call on the frame's load: listens to its window's focus and to presses in its page. */
|
|
28
|
+
watch: (event: SyntheticEvent<HTMLIFrameElement>) => {
|
|
29
|
+
const win = event.currentTarget.contentWindow;
|
|
30
|
+
const doc = event.currentTarget.contentDocument;
|
|
31
|
+
win?.addEventListener("focus", onFocus);
|
|
32
|
+
win?.addEventListener("blur", onBlur);
|
|
33
|
+
doc?.addEventListener("pointerdown", onPointer, true);
|
|
34
|
+
doc?.addEventListener("mousedown", onPointer, true);
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
}
|
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
canDrop,
|
|
4
4
|
findNode,
|
|
5
5
|
isParentNode,
|
|
6
|
+
parentOf,
|
|
6
7
|
REASONS,
|
|
7
8
|
type DragSource,
|
|
8
9
|
type Layout,
|
|
@@ -13,9 +14,11 @@ import {
|
|
|
13
14
|
dropIndex,
|
|
14
15
|
edgeDrop,
|
|
15
16
|
EXISTING_ELEMENT_MIME,
|
|
17
|
+
flowDirection,
|
|
16
18
|
idAt,
|
|
17
19
|
NEW_ELEMENT_MIME,
|
|
18
20
|
transferKinds,
|
|
21
|
+
type Direction,
|
|
19
22
|
type Rect,
|
|
20
23
|
} from "../dnd/drop-target.ts";
|
|
21
24
|
import { dragStash } from "../dnd/drag-stash.ts";
|
|
@@ -25,11 +28,30 @@ import { dropLineBox } from "./drop-line.ts";
|
|
|
25
28
|
import type { Box, DropTarget, InvalidDrop } from "./SelectionOverlay.tsx";
|
|
26
29
|
import { boxOf, type CanvasSelection } from "./use-canvas-session.ts";
|
|
27
30
|
|
|
28
|
-
const
|
|
31
|
+
const ownDirection = (node: LayoutNode) =>
|
|
29
32
|
(isParentNode(node) ? node.style?.flexDirection : undefined) ?? "column";
|
|
30
33
|
|
|
31
34
|
const childrenOf = (node: LayoutNode): LayoutNode[] => (isParentNode(node) ? node.children : []);
|
|
32
35
|
|
|
36
|
+
/**
|
|
37
|
+
* W-559: the direction the canvas shows for `node`'s children, read from the element that
|
|
38
|
+
* actually lays them out (a Section's inner box, a Menu's list), so classes, tablet and mobile
|
|
39
|
+
* styles, grids and RTL count. Its own style when nothing is rendered.
|
|
40
|
+
*/
|
|
41
|
+
const directionOf = (doc: Document, node: LayoutNode): Direction => {
|
|
42
|
+
const find = (id: string) => doc.querySelector(`[data-emvb-id="${CSS.escape(id)}"]`);
|
|
43
|
+
const first = childrenOf(node)[0];
|
|
44
|
+
const box = (first && find(first.id)?.parentElement) || find(node.id);
|
|
45
|
+
const view = doc.defaultView;
|
|
46
|
+
return box && view ? flowDirection(view.getComputedStyle(box)) : ownDirection(node);
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const parentShown = (doc: Document, layout: Layout, id: string): Direction | undefined => {
|
|
50
|
+
const parentId = parentOf(layout, id);
|
|
51
|
+
const parent = parentId ? findNode(layout, parentId) : undefined;
|
|
52
|
+
return parent ? directionOf(doc, parent) : undefined;
|
|
53
|
+
};
|
|
54
|
+
|
|
33
55
|
/** Refusals that end the walk to an accepting ancestor, so the user sees why (W-128). */
|
|
34
56
|
const STOPS = new Set<string>([REASONS.intoItself, REASONS.tooDeep, REASONS.tooMany]);
|
|
35
57
|
|
|
@@ -118,10 +140,17 @@ export function useCanvasDnD({
|
|
|
118
140
|
const hoveredBox = rectOf(currentDoc, hovered.id);
|
|
119
141
|
const edge =
|
|
120
142
|
hoveredBox && hovered.id !== current.root.id
|
|
121
|
-
? edgeDrop(
|
|
143
|
+
? edgeDrop(
|
|
144
|
+
current,
|
|
145
|
+
hovered,
|
|
146
|
+
hoveredBox,
|
|
147
|
+
point,
|
|
148
|
+
(parent) => verdict(parent).ok,
|
|
149
|
+
parentShown(currentDoc, current, hovered.id),
|
|
150
|
+
)
|
|
122
151
|
: null;
|
|
123
152
|
const container = (edge && findNode(current, edge.parentId)) || hovered;
|
|
124
|
-
const direction = directionOf(container);
|
|
153
|
+
const direction = directionOf(currentDoc, container);
|
|
125
154
|
const kids = childrenOf(container);
|
|
126
155
|
const rects = kids.map((child) => {
|
|
127
156
|
const rect = rectOf(currentDoc, child.id);
|
|
@@ -13,6 +13,13 @@ const REACT_ATTR: Record<string, string> = {
|
|
|
13
13
|
minlength: "minLength",
|
|
14
14
|
maxlength: "maxLength",
|
|
15
15
|
novalidate: "noValidate",
|
|
16
|
+
// W-804: React warned "Invalid DOM property" for these and the canvas logged an error per image
|
|
17
|
+
// or background video (a priority image's fetchpriority, srcset, a post date's datetime).
|
|
18
|
+
fetchpriority: "fetchPriority",
|
|
19
|
+
srcset: "srcSet",
|
|
20
|
+
playsinline: "playsInline",
|
|
21
|
+
autoplay: "autoPlay",
|
|
22
|
+
datetime: "dateTime",
|
|
16
23
|
// The canvas never updates a radio from props, so a tab chosen there stays chosen (QA-5).
|
|
17
24
|
checked: "defaultChecked",
|
|
18
25
|
};
|
|
@@ -70,6 +70,16 @@ const ORDER: Record<string, string> = {
|
|
|
70
70
|
title: "orderBy=title&order=asc",
|
|
71
71
|
};
|
|
72
72
|
|
|
73
|
+
/**
|
|
74
|
+
* W-667: the page plus the synced sections and Loop Item parts it shows, so a collection Loop
|
|
75
|
+
* inside one of those gets real entries on the canvas like it does on the published page.
|
|
76
|
+
*/
|
|
77
|
+
export function withPartLayouts(layout: Layout | null, parts: readonly Layout[]): Layout | null {
|
|
78
|
+
if (!layout || parts.length === 0) return layout;
|
|
79
|
+
const children = [...layout.root.children, ...parts.flatMap((part) => part.root.children)];
|
|
80
|
+
return { ...layout, root: { ...layout.root, children } };
|
|
81
|
+
}
|
|
82
|
+
|
|
73
83
|
/**
|
|
74
84
|
* Real entries for collection Loops on the canvas (W-308), read through the content API. A
|
|
75
85
|
* collection the role can't read, or that doesn't exist, keeps the sample entries.
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { Button, Dialog } from "@cloudflare/kumo";
|
|
1
|
+
import { Button, Dialog, Loader } from "@cloudflare/kumo";
|
|
2
|
+
import { useMediaQuery } from "./useMediaQuery.ts";
|
|
3
|
+
import { useEditedNoun } from "./edited-noun.ts";
|
|
2
4
|
import { BUTTON, SOLID_DESTRUCTIVE, SOLID_PRIMARY, UI_CSS } from "../ui.ts";
|
|
3
5
|
|
|
4
6
|
type OpenProps = { open: boolean; onOpenChange: (open: boolean) => void };
|
|
@@ -10,14 +12,15 @@ export function ConflictDialog({
|
|
|
10
12
|
onReload,
|
|
11
13
|
onOverwrite,
|
|
12
14
|
}: OpenProps & { onReload: () => void; onOverwrite: () => void }) {
|
|
15
|
+
const noun = useEditedNoun();
|
|
13
16
|
return (
|
|
14
17
|
<Dialog.Root open={open} onOpenChange={onOpenChange}>
|
|
15
18
|
<Dialog size="base" className="p-6">
|
|
16
19
|
<style>{UI_CSS}</style>
|
|
17
20
|
<div data-emvb-dialog="conflict" className="emvb-dialog">
|
|
18
|
-
<Dialog.Title>This
|
|
21
|
+
<Dialog.Title>This {noun} was changed somewhere else</Dialog.Title>
|
|
19
22
|
<Dialog.Description>
|
|
20
|
-
Someone saved this
|
|
23
|
+
Someone saved this {noun} after you opened it. Reload to get their version and lose your
|
|
21
24
|
unsaved changes, or overwrite their version with yours.
|
|
22
25
|
</Dialog.Description>
|
|
23
26
|
<div className="emvb-dialog-actions">
|
|
@@ -30,7 +33,7 @@ export function ConflictDialog({
|
|
|
30
33
|
style={SOLID_DESTRUCTIVE}
|
|
31
34
|
onClick={onOverwrite}
|
|
32
35
|
>
|
|
33
|
-
Overwrite
|
|
36
|
+
Overwrite their version
|
|
34
37
|
</Button>
|
|
35
38
|
</div>
|
|
36
39
|
</div>
|
|
@@ -69,7 +72,7 @@ export function RevertDialog({
|
|
|
69
72
|
style={SOLID_DESTRUCTIVE}
|
|
70
73
|
onClick={onRevert}
|
|
71
74
|
>
|
|
72
|
-
Revert
|
|
75
|
+
Revert to published
|
|
73
76
|
</Button>
|
|
74
77
|
</div>
|
|
75
78
|
</div>
|
|
@@ -84,18 +87,35 @@ export function LeaveDialog({
|
|
|
84
87
|
onOpenChange,
|
|
85
88
|
onDiscard,
|
|
86
89
|
onSaveAndLeave,
|
|
87
|
-
|
|
90
|
+
saving = false,
|
|
91
|
+
}: OpenProps & {
|
|
92
|
+
onDiscard: () => void;
|
|
93
|
+
onSaveAndLeave: () => void;
|
|
94
|
+
/** W-834: Save and leave is saving; the dialog shows it and ignores presses and closing. */
|
|
95
|
+
saving?: boolean;
|
|
96
|
+
}) {
|
|
97
|
+
const noun = useEditedNoun();
|
|
98
|
+
const reducedMotion = useMediaQuery("(prefers-reduced-motion: reduce)");
|
|
99
|
+
const unlessSaving = (run: () => void) => () => {
|
|
100
|
+
if (!saving) run();
|
|
101
|
+
};
|
|
88
102
|
return (
|
|
89
|
-
<Dialog.Root
|
|
103
|
+
<Dialog.Root
|
|
104
|
+
open={open}
|
|
105
|
+
onOpenChange={(next) => {
|
|
106
|
+
if (!next && saving) return;
|
|
107
|
+
onOpenChange(next);
|
|
108
|
+
}}
|
|
109
|
+
>
|
|
90
110
|
<Dialog size="base" className="p-6">
|
|
91
111
|
<style>{UI_CSS}</style>
|
|
92
112
|
<div data-emvb-dialog="leave" className="emvb-dialog">
|
|
93
113
|
<Dialog.Title>Leave without saving?</Dialog.Title>
|
|
94
|
-
<Dialog.Description>You have unsaved changes on this
|
|
114
|
+
<Dialog.Description>You have unsaved changes on this {noun}.</Dialog.Description>
|
|
95
115
|
<div className="emvb-dialog-actions">
|
|
96
116
|
<Dialog.Close
|
|
97
117
|
render={(props) => (
|
|
98
|
-
<Button {...props} variant="secondary" className={BUTTON}>
|
|
118
|
+
<Button {...props} variant="secondary" className={BUTTON} aria-disabled={saving}>
|
|
99
119
|
Keep editing
|
|
100
120
|
</Button>
|
|
101
121
|
)}
|
|
@@ -103,7 +123,8 @@ export function LeaveDialog({
|
|
|
103
123
|
<Button
|
|
104
124
|
variant="secondary"
|
|
105
125
|
className={`${BUTTON} emvb-danger-text`}
|
|
106
|
-
|
|
126
|
+
aria-disabled={saving}
|
|
127
|
+
onClick={unlessSaving(onDiscard)}
|
|
107
128
|
>
|
|
108
129
|
Discard changes
|
|
109
130
|
</Button>
|
|
@@ -111,9 +132,12 @@ export function LeaveDialog({
|
|
|
111
132
|
variant="primary"
|
|
112
133
|
className={BUTTON}
|
|
113
134
|
style={SOLID_PRIMARY}
|
|
114
|
-
|
|
135
|
+
icon={saving && !reducedMotion ? <Loader size={14} /> : undefined}
|
|
136
|
+
aria-disabled={saving}
|
|
137
|
+
aria-busy={saving}
|
|
138
|
+
onClick={unlessSaving(onSaveAndLeave)}
|
|
115
139
|
>
|
|
116
|
-
Save and leave
|
|
140
|
+
{saving ? "Saving…" : "Save and leave"}
|
|
117
141
|
</Button>
|
|
118
142
|
</div>
|
|
119
143
|
</div>
|
|
@@ -139,7 +163,7 @@ export function DeleteSubtreeDialog({
|
|
|
139
163
|
<Dialog.Title>
|
|
140
164
|
Delete {label} and the {inside} element{inside === 1 ? "" : "s"} inside it?
|
|
141
165
|
</Dialog.Title>
|
|
142
|
-
<Dialog.Description>
|
|
166
|
+
<Dialog.Description>You can undo this with Restore right after.</Dialog.Description>
|
|
143
167
|
<div className="emvb-dialog-actions">
|
|
144
168
|
<Dialog.Close
|
|
145
169
|
render={(props) => (
|
|
@@ -154,7 +178,7 @@ export function DeleteSubtreeDialog({
|
|
|
154
178
|
style={SOLID_DESTRUCTIVE}
|
|
155
179
|
onClick={onConfirm}
|
|
156
180
|
>
|
|
157
|
-
Delete
|
|
181
|
+
Delete {count} elements
|
|
158
182
|
</Button>
|
|
159
183
|
</div>
|
|
160
184
|
</div>
|
|
@@ -58,6 +58,29 @@ function lines(rects: Rect[], row: boolean): number[][] {
|
|
|
58
58
|
return result;
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
+
/** The computed style a container's children flow by (see `flowDirection`). */
|
|
62
|
+
export type FlowStyle = { display: string; flexDirection: string; direction: string };
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* W-559: how a container's children run on the canvas, from its computed style, so classes,
|
|
66
|
+
* tablet and mobile styles and grids count, not just the element's own `flexDirection`. A row in
|
|
67
|
+
* an RTL page runs right to left, which the drop maths treats as a reversed row.
|
|
68
|
+
*/
|
|
69
|
+
export function flowDirection(style: FlowStyle): Direction {
|
|
70
|
+
const display = style.display;
|
|
71
|
+
let direction: Direction = display.includes("flex")
|
|
72
|
+
? ((["row", "row-reverse", "column", "column-reverse"] as const).find(
|
|
73
|
+
(d) => d === style.flexDirection,
|
|
74
|
+
) ?? "row")
|
|
75
|
+
: display.includes("grid")
|
|
76
|
+
? "row"
|
|
77
|
+
: "column";
|
|
78
|
+
if (style.direction === "rtl" && direction.startsWith("row")) {
|
|
79
|
+
direction = direction === "row" ? "row-reverse" : "row";
|
|
80
|
+
}
|
|
81
|
+
return direction;
|
|
82
|
+
}
|
|
83
|
+
|
|
61
84
|
/**
|
|
62
85
|
* The insertion index for a pointer over a flex container, given its children's rects in document
|
|
63
86
|
* order: before the first child whose middle (along the main axis) is past the pointer.
|
|
@@ -130,11 +153,13 @@ export function edgeDrop(
|
|
|
130
153
|
rect: Rect,
|
|
131
154
|
point: Point,
|
|
132
155
|
accepts: Accepts = anyParent,
|
|
156
|
+
/** The parent's direction as shown (`flowDirection`); else its own style's. */
|
|
157
|
+
shown?: Direction,
|
|
133
158
|
): { parentId: string; index: number } | null {
|
|
134
159
|
const parentId = parentOf(layout, container.id);
|
|
135
160
|
const parent = parentId ? findNode(layout, parentId) : undefined;
|
|
136
161
|
if (!parent || !isParentNode(parent) || !accepts(parent)) return null;
|
|
137
|
-
const direction = parent.style?.flexDirection ?? "column";
|
|
162
|
+
const direction = shown ?? parent.style?.flexDirection ?? "column";
|
|
138
163
|
const row = direction.startsWith("row");
|
|
139
164
|
const span = along(rect, row);
|
|
140
165
|
const zone = Math.min(EDGE_ZONE, (span.end - span.start) / 4);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { THEME_PARTS_COLLECTION } from "../../constants.ts";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* UX-087: what the editor has open, in words. Pages and theme parts share the editor, so copy
|
|
6
|
+
* such as "unsaved changes on this page" names the right thing.
|
|
7
|
+
*/
|
|
8
|
+
export type EditedNoun = "page" | "theme part";
|
|
9
|
+
|
|
10
|
+
export const EditedNounContext = React.createContext<EditedNoun>("page");
|
|
11
|
+
|
|
12
|
+
export const editedNounOf = (collection: string): EditedNoun =>
|
|
13
|
+
collection === THEME_PARTS_COLLECTION ? "theme part" : "page";
|
|
14
|
+
|
|
15
|
+
export const useEditedNoun = (): EditedNoun => React.useContext(EditedNounContext);
|