@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
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { LockKeyIcon
|
|
1
|
+
import { Empty } from "@cloudflare/kumo";
|
|
2
|
+
import { LockKeyIcon } from "@phosphor-icons/react";
|
|
3
3
|
import type * as React from "react";
|
|
4
4
|
import type { Fetcher } from "../api.ts";
|
|
5
|
+
import { ListError, LoadingStatus } from "../pages/list-kit.tsx";
|
|
5
6
|
import { canUseEmvb, useRole } from "./role.ts";
|
|
6
7
|
|
|
7
8
|
/** Renders `children` for editors and above, and a "no access" state below (D-020, D-024). */
|
|
@@ -13,14 +14,13 @@ export function RequireEditor({
|
|
|
13
14
|
children: (role: number) => React.ReactNode;
|
|
14
15
|
}) {
|
|
15
16
|
const status = useRole(fetcher);
|
|
16
|
-
if (status.state === "loading") return <
|
|
17
|
+
if (status.state === "loading") return <LoadingStatus label="Checking your access…" />;
|
|
17
18
|
if (status.state === "error") {
|
|
18
19
|
return (
|
|
19
|
-
<
|
|
20
|
-
variant="error"
|
|
21
|
-
icon={<WarningCircleIcon aria-hidden="true" />}
|
|
20
|
+
<ListError
|
|
22
21
|
title="Couldn't check your access to EmVB"
|
|
23
|
-
|
|
22
|
+
message={status.message}
|
|
23
|
+
onRetry={status.retry}
|
|
24
24
|
/>
|
|
25
25
|
);
|
|
26
26
|
}
|
package/src/admin/access/role.ts
CHANGED
|
@@ -19,12 +19,14 @@ export const canUseEmvb = (role: number) => role >= EDITOR_ROLE;
|
|
|
19
19
|
type RoleState =
|
|
20
20
|
| { state: "loading" }
|
|
21
21
|
| { state: "ready"; role: number }
|
|
22
|
-
| { state: "error"; message: string };
|
|
22
|
+
| { state: "error"; message: string; retry: () => void };
|
|
23
23
|
|
|
24
24
|
export function useRole(fetcher: Fetcher): RoleState {
|
|
25
25
|
const [status, setStatus] = React.useState<RoleState>({ state: "loading" });
|
|
26
|
+
const [attempt, setAttempt] = React.useState(0);
|
|
26
27
|
React.useEffect(() => {
|
|
27
28
|
let active = true;
|
|
29
|
+
setStatus({ state: "loading" });
|
|
28
30
|
readRole(fetcher).then(
|
|
29
31
|
(role) => active && setStatus({ state: "ready", role }),
|
|
30
32
|
(error: unknown) =>
|
|
@@ -32,11 +34,12 @@ export function useRole(fetcher: Fetcher): RoleState {
|
|
|
32
34
|
setStatus({
|
|
33
35
|
state: "error",
|
|
34
36
|
message: error instanceof Error ? error.message : String(error),
|
|
37
|
+
retry: () => setAttempt((n) => n + 1),
|
|
35
38
|
}),
|
|
36
39
|
);
|
|
37
40
|
return () => {
|
|
38
41
|
active = false;
|
|
39
42
|
};
|
|
40
|
-
}, [fetcher]);
|
|
43
|
+
}, [fetcher, attempt]);
|
|
41
44
|
return status;
|
|
42
45
|
}
|
package/src/admin/content-api.ts
CHANGED
|
@@ -88,8 +88,10 @@ export function canonicalProblem(value: string): string | null {
|
|
|
88
88
|
function seoBody(draft: PageDraft) {
|
|
89
89
|
const canonical = draft.seoCanonical;
|
|
90
90
|
return {
|
|
91
|
-
|
|
92
|
-
|
|
91
|
+
// W-663: a title or description of only spaces was saved as is, so search results and
|
|
92
|
+
// link previews showed a blank title instead of falling back to the page's own.
|
|
93
|
+
title: draft.seoTitle.trim() || null,
|
|
94
|
+
description: draft.seoDescription.trim() || null,
|
|
93
95
|
...(canonical !== undefined && !canonicalProblem(canonical)
|
|
94
96
|
? { canonical: canonical.trim() || null }
|
|
95
97
|
: {}),
|
|
@@ -111,7 +113,12 @@ export async function savePage(
|
|
|
111
113
|
{
|
|
112
114
|
method: "PUT",
|
|
113
115
|
body: {
|
|
114
|
-
data: {
|
|
116
|
+
data: {
|
|
117
|
+
title: draft.title,
|
|
118
|
+
// UX-094: a page with no layout yet leaves the field alone; the server refuses null.
|
|
119
|
+
...(draft.layout ? { layout: draft.layout } : {}),
|
|
120
|
+
canvas_mode: draft.canvasMode,
|
|
121
|
+
},
|
|
115
122
|
slug: draft.slug,
|
|
116
123
|
seo: seoBody(draft),
|
|
117
124
|
...(rev ? { _rev: rev } : {}),
|
|
@@ -18,5 +18,5 @@ export type ContentItem = {
|
|
|
18
18
|
/** The stored title, or `fallback` when it is missing or blank. */
|
|
19
19
|
export function titleOf(item: ContentItem, fallback: string): string {
|
|
20
20
|
const title = item.data?.["title"];
|
|
21
|
-
return typeof title === "string" && title ? title : fallback;
|
|
21
|
+
return typeof title === "string" && title.trim() ? title : fallback;
|
|
22
22
|
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { Button, Dialog } from "@cloudflare/kumo";
|
|
2
|
+
import { WarningCircleIcon, WarningIcon } from "@phosphor-icons/react";
|
|
3
|
+
import * as React from "react";
|
|
2
4
|
import {
|
|
3
5
|
applyA11yFix,
|
|
4
6
|
applyAllA11yFixes,
|
|
@@ -7,6 +9,7 @@ import {
|
|
|
7
9
|
type Layout,
|
|
8
10
|
} from "../../core/index.ts";
|
|
9
11
|
import { ELEMENT_NAMES } from "./element-chrome.ts";
|
|
12
|
+
import { BUTTON, SOLID_PRIMARY } from "../ui.ts";
|
|
10
13
|
|
|
11
14
|
/** Score bands for the badge colour (W-317). */
|
|
12
15
|
const scoreBand = (score: number) => (score >= 90 ? "good" : score >= 70 ? "fair" : "poor");
|
|
@@ -53,6 +56,25 @@ export function A11yDialog({
|
|
|
53
56
|
onApply: (layout: Layout, note: string) => void;
|
|
54
57
|
}) {
|
|
55
58
|
const fixable = report.issues.filter((issue) => issue.fix);
|
|
59
|
+
// W-833: a fixed issue leaves the list with its focused Fix button, so focus fell back to the
|
|
60
|
+
// dialog itself. Move it to the next fix, else Fix all, else Close.
|
|
61
|
+
const refocusAfterFix = React.useRef(false);
|
|
62
|
+
React.useEffect(() => {
|
|
63
|
+
if (!refocusAfterFix.current) return;
|
|
64
|
+
refocusAfterFix.current = false;
|
|
65
|
+
const body = document.querySelector<HTMLElement>('[data-emvb-dialog="a11y"]');
|
|
66
|
+
const active = document.activeElement;
|
|
67
|
+
if (active instanceof HTMLElement && active !== body && body?.contains(active)) return;
|
|
68
|
+
const next =
|
|
69
|
+
body?.querySelector<HTMLElement>("[data-emvb-a11y-fix]") ??
|
|
70
|
+
body?.querySelector<HTMLElement>("[data-emvb-a11y-fix-all]") ??
|
|
71
|
+
body?.querySelector<HTMLElement>("[data-emvb-a11y-close]");
|
|
72
|
+
next?.focus();
|
|
73
|
+
});
|
|
74
|
+
const apply = (next: Layout, note: string) => {
|
|
75
|
+
refocusAfterFix.current = true;
|
|
76
|
+
onApply(next, note);
|
|
77
|
+
};
|
|
56
78
|
const name = (id: string) => {
|
|
57
79
|
const node = layout ? findNode(layout, id) : undefined;
|
|
58
80
|
if (!node) return "Element";
|
|
@@ -62,63 +84,89 @@ export function A11yDialog({
|
|
|
62
84
|
return (
|
|
63
85
|
<Dialog.Root open={open} onOpenChange={onOpenChange}>
|
|
64
86
|
<Dialog size="base" className="p-6 emvb-a11y" data-emvb-a11y="">
|
|
65
|
-
<
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
<
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
87
|
+
<div className="emvb-dialog" data-emvb-dialog="a11y">
|
|
88
|
+
<Dialog.Title>
|
|
89
|
+
Accessibility · <span data-band={scoreBand(report.score)}>{report.score}</span>/100
|
|
90
|
+
</Dialog.Title>
|
|
91
|
+
{report.issues.length === 0 ? (
|
|
92
|
+
<p className="emvb-helper" data-emvb-a11y-clean="">
|
|
93
|
+
No issues found. Automated checks catch some problems, not all: try the page with a
|
|
94
|
+
keyboard and a screen reader too.
|
|
95
|
+
</p>
|
|
96
|
+
) : (
|
|
97
|
+
<ul className="emvb-a11y-issues">
|
|
98
|
+
{report.issues.map((issue) => (
|
|
99
|
+
<li key={issue.id} data-emvb-a11y-issue={issue.id} data-severity={issue.severity}>
|
|
100
|
+
{/* UX-022: severity has a shape and a name, not only the bar's colour. */}
|
|
101
|
+
{issue.severity === "error" ? (
|
|
102
|
+
<WarningCircleIcon
|
|
103
|
+
className="emvb-a11y-severity"
|
|
104
|
+
size={16}
|
|
105
|
+
role="img"
|
|
106
|
+
aria-label="Error"
|
|
107
|
+
/>
|
|
108
|
+
) : (
|
|
109
|
+
<WarningIcon
|
|
110
|
+
className="emvb-a11y-severity"
|
|
111
|
+
size={16}
|
|
112
|
+
role="img"
|
|
113
|
+
aria-label="Warning"
|
|
114
|
+
/>
|
|
115
|
+
)}
|
|
116
|
+
<span className="emvb-a11y-what">
|
|
117
|
+
<button
|
|
118
|
+
type="button"
|
|
119
|
+
className="emvb-link-button"
|
|
120
|
+
onClick={() => {
|
|
121
|
+
onSelect(issue.nodeId);
|
|
122
|
+
onOpenChange(false);
|
|
123
|
+
}}
|
|
124
|
+
>
|
|
125
|
+
{name(issue.nodeId)}
|
|
126
|
+
</button>
|
|
127
|
+
: {issue.message}
|
|
128
|
+
</span>
|
|
129
|
+
{issue.fix && layout && (
|
|
130
|
+
<Button
|
|
131
|
+
variant="secondary"
|
|
132
|
+
className={BUTTON}
|
|
133
|
+
data-emvb-a11y-fix={issue.id}
|
|
134
|
+
onClick={() =>
|
|
135
|
+
apply(applyA11yFix(layout, issue), `Fixed: ${issue.fixLabel ?? "issue"}`)
|
|
136
|
+
}
|
|
137
|
+
>
|
|
138
|
+
{issue.fixLabel ?? "Fix"}
|
|
139
|
+
</Button>
|
|
140
|
+
)}
|
|
141
|
+
</li>
|
|
142
|
+
))}
|
|
143
|
+
</ul>
|
|
120
144
|
)}
|
|
121
|
-
<
|
|
145
|
+
<div className="emvb-a11y-actions">
|
|
146
|
+
<Dialog.Close
|
|
147
|
+
render={(props) => (
|
|
148
|
+
<Button {...props} variant="secondary" className={BUTTON} data-emvb-a11y-close="">
|
|
149
|
+
Close
|
|
150
|
+
</Button>
|
|
151
|
+
)}
|
|
152
|
+
/>
|
|
153
|
+
{fixable.length > 1 && layout && (
|
|
154
|
+
<Button
|
|
155
|
+
variant="primary"
|
|
156
|
+
className={BUTTON}
|
|
157
|
+
style={SOLID_PRIMARY}
|
|
158
|
+
data-emvb-a11y-fix-all=""
|
|
159
|
+
onClick={() =>
|
|
160
|
+
apply(
|
|
161
|
+
applyAllA11yFixes(layout, fixable),
|
|
162
|
+
`Fixed ${fixable.length} accessibility issues`,
|
|
163
|
+
)
|
|
164
|
+
}
|
|
165
|
+
>
|
|
166
|
+
Fix {fixable.length} issues
|
|
167
|
+
</Button>
|
|
168
|
+
)}
|
|
169
|
+
</div>
|
|
122
170
|
</div>
|
|
123
171
|
</Dialog>
|
|
124
172
|
</Dialog.Root>
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Dialog } from "@cloudflare/kumo";
|
|
2
2
|
import * as React from "react";
|
|
3
3
|
import { filterPalette, type PaletteItem } from "./palette.ts";
|
|
4
|
+
import { isCommitEnter } from "./ime.ts";
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Ctrl/Cmd+K (W-314): one box to insert an element, jump to a layer, apply a class, or run an
|
|
@@ -17,10 +18,12 @@ export function CommandPalette({
|
|
|
17
18
|
}) {
|
|
18
19
|
const [query, setQuery] = React.useState("");
|
|
19
20
|
const [active, setActive] = React.useState(0);
|
|
20
|
-
const listRef = React.useRef<HTMLUListElement>(null);
|
|
21
21
|
// W-399: opened from a shortcut there is no trigger to return to, so focus fell to <body> on
|
|
22
22
|
// close. Remember what had focus and go back to it when nothing else took focus.
|
|
23
23
|
const wasOpen = React.useRef(false);
|
|
24
|
+
// A focus return still waiting when the palette goes away must not move focus later (W-533).
|
|
25
|
+
const settleTimer = React.useRef<number | undefined>(undefined);
|
|
26
|
+
React.useEffect(() => () => window.clearTimeout(settleTimer.current), []);
|
|
24
27
|
const returnTo = React.useRef<HTMLElement | null>(null);
|
|
25
28
|
if (open && !wasOpen.current && typeof document !== "undefined") {
|
|
26
29
|
const focused = document.activeElement;
|
|
@@ -31,6 +34,7 @@ export function CommandPalette({
|
|
|
31
34
|
const restoreFocus = (afterCommand = false) => {
|
|
32
35
|
// The dialog lets go of focus only once its close animation ends, so wait for that.
|
|
33
36
|
const started = Date.now();
|
|
37
|
+
window.clearTimeout(settleTimer.current);
|
|
34
38
|
const settle = () => {
|
|
35
39
|
const now = document.activeElement;
|
|
36
40
|
// Kumo's Dialog doesn't pass data attributes through; find the palette by its input.
|
|
@@ -38,7 +42,7 @@ export function CommandPalette({
|
|
|
38
42
|
const inPalette = now?.closest('[role="dialog"]')?.querySelector("[data-emvb-palette-input]");
|
|
39
43
|
if (now && now !== document.body && !inPalette) return;
|
|
40
44
|
if (stillOpen && Date.now() - started < 2000) {
|
|
41
|
-
setTimeout(settle, 30);
|
|
45
|
+
settleTimer.current = window.setTimeout(settle, 30);
|
|
42
46
|
return;
|
|
43
47
|
}
|
|
44
48
|
const selected = document.querySelector<HTMLElement>(
|
|
@@ -50,7 +54,7 @@ export function CommandPalette({
|
|
|
50
54
|
document.querySelector<HTMLElement>("iframe[data-emvb-canvas]");
|
|
51
55
|
target?.focus({ preventScroll: true });
|
|
52
56
|
};
|
|
53
|
-
setTimeout(settle, 30);
|
|
57
|
+
settleTimer.current = window.setTimeout(settle, 30);
|
|
54
58
|
};
|
|
55
59
|
const close = (next: boolean) => {
|
|
56
60
|
onOpenChange(next);
|
|
@@ -64,11 +68,15 @@ export function CommandPalette({
|
|
|
64
68
|
}, [open]);
|
|
65
69
|
const shown = React.useMemo(() => filterPalette(items, query), [items, query]);
|
|
66
70
|
const current = Math.min(active, Math.max(0, shown.length - 1));
|
|
67
|
-
React.
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
71
|
+
const scrollSelected = React.useCallback(
|
|
72
|
+
(list: HTMLUListElement | null) => {
|
|
73
|
+
if (!shown[current]) return;
|
|
74
|
+
list
|
|
75
|
+
?.querySelector<HTMLElement>(`[data-index="${current}"]`)
|
|
76
|
+
?.scrollIntoView?.({ block: "nearest" });
|
|
77
|
+
},
|
|
78
|
+
[current, shown],
|
|
79
|
+
);
|
|
72
80
|
const run = (item: PaletteItem | undefined) => {
|
|
73
81
|
if (!item) return;
|
|
74
82
|
onOpenChange(false);
|
|
@@ -83,7 +91,7 @@ export function CommandPalette({
|
|
|
83
91
|
event.preventDefault();
|
|
84
92
|
const step = event.key === "ArrowDown" ? 1 : -1;
|
|
85
93
|
setActive((current + step + shown.length) % Math.max(1, shown.length));
|
|
86
|
-
} else if (event
|
|
94
|
+
} else if (isCommitEnter(event)) {
|
|
87
95
|
event.preventDefault();
|
|
88
96
|
run(shown[current]);
|
|
89
97
|
} else if (event.key === "Home" && event.ctrlKey) {
|
|
@@ -94,7 +102,9 @@ export function CommandPalette({
|
|
|
94
102
|
return (
|
|
95
103
|
<Dialog.Root open={open} onOpenChange={close}>
|
|
96
104
|
<Dialog size="base" className="emvb-palette" data-emvb-palette="">
|
|
97
|
-
<Dialog.Title className="sr-only"
|
|
105
|
+
<Dialog.Title className="sr-only" data-emvb-dialog="palette">
|
|
106
|
+
Command palette
|
|
107
|
+
</Dialog.Title>
|
|
98
108
|
<input
|
|
99
109
|
className="emvb-palette-input"
|
|
100
110
|
role="combobox"
|
|
@@ -112,7 +122,12 @@ export function CommandPalette({
|
|
|
112
122
|
}}
|
|
113
123
|
onKeyDown={onKeyDown}
|
|
114
124
|
/>
|
|
115
|
-
<ul
|
|
125
|
+
<ul
|
|
126
|
+
className="emvb-palette-list"
|
|
127
|
+
id="emvb-palette-list"
|
|
128
|
+
role="listbox"
|
|
129
|
+
ref={scrollSelected}
|
|
130
|
+
>
|
|
116
131
|
{shown.length === 0 && (
|
|
117
132
|
<li className="emvb-palette-empty" role="presentation">
|
|
118
133
|
Nothing matches “{query}”.
|
|
@@ -141,8 +156,9 @@ export function CommandPalette({
|
|
|
141
156
|
>
|
|
142
157
|
<span className="emvb-palette-label">{item.label}</span>
|
|
143
158
|
<span className="emvb-palette-hint">
|
|
144
|
-
{query.trim() ? item.group :
|
|
145
|
-
{item.hint ?
|
|
159
|
+
{query.trim() ? <span className="emvb-palette-kind">{item.group}</span> : null}
|
|
160
|
+
{query.trim() && item.hint ? " " : null}
|
|
161
|
+
{item.hint ? <span className="emvb-palette-detail">{item.hint}</span> : null}
|
|
146
162
|
</span>
|
|
147
163
|
</li>
|
|
148
164
|
</React.Fragment>
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Button, createKumoToastManager, Empty } from "@cloudflare/kumo";
|
|
2
2
|
import {
|
|
3
3
|
ArrowsClockwiseIcon,
|
|
4
|
+
ArrowUUpLeftIcon,
|
|
5
|
+
ArrowUUpRightIcon,
|
|
4
6
|
ClockCounterClockwiseIcon,
|
|
5
7
|
GaugeIcon,
|
|
6
8
|
RobotIcon,
|
|
7
9
|
ShareNetworkIcon,
|
|
8
|
-
WarningCircleIcon,
|
|
9
10
|
} from "@phosphor-icons/react";
|
|
10
11
|
import * as React from "react";
|
|
11
12
|
import {
|
|
@@ -18,6 +19,7 @@ import {
|
|
|
18
19
|
type PopupDevice,
|
|
19
20
|
} from "../../core/index.ts";
|
|
20
21
|
import { PAGES_COLLECTION, THEME_PARTS_COLLECTION } from "../../constants.ts";
|
|
22
|
+
import { EditedNounContext, editedNounOf, useEditedNoun } from "./edited-noun.ts";
|
|
21
23
|
import { indexLayout } from "../../core/tree-ops.ts";
|
|
22
24
|
import type { Fetcher } from "../api.ts";
|
|
23
25
|
import { loadFormsCapability } from "../forms-api.ts";
|
|
@@ -33,6 +35,7 @@ import {
|
|
|
33
35
|
useChromeFlags,
|
|
34
36
|
} from "./editor-chrome.tsx";
|
|
35
37
|
import { EditorOverlay } from "./EditorOverlay.tsx";
|
|
38
|
+
import { EditorToasts } from "./EditorToasts.tsx";
|
|
36
39
|
import { useCanvasStyles, useEditorHost } from "./host.ts";
|
|
37
40
|
import { LiveDataProvider, siteOrigin, useLiveData } from "./live-data.tsx";
|
|
38
41
|
import { newElement } from "./dnd/new-element.ts";
|
|
@@ -50,8 +53,8 @@ import {
|
|
|
50
53
|
type LoadedDesign,
|
|
51
54
|
} from "./useEditorData.ts";
|
|
52
55
|
import { EDITOR_MIN_WIDTH_QUERY, useMediaQuery } from "./useMediaQuery.ts";
|
|
53
|
-
import {
|
|
54
|
-
import { useCollectionPreviews } from "./collection-previews.ts";
|
|
56
|
+
import { usePartTemplates } from "./section-templates.ts";
|
|
57
|
+
import { useCollectionPreviews, withPartLayouts } from "./collection-previews.ts";
|
|
55
58
|
import { useRemoteChange } from "./remote-change.ts";
|
|
56
59
|
import { A11yScoreButton } from "./A11yCopilot.tsx";
|
|
57
60
|
import { restoreOnUndo, type Deletion } from "./restore-deleted.ts";
|
|
@@ -61,6 +64,7 @@ import { useSave } from "./useSave.ts";
|
|
|
61
64
|
import { type ShortcutHandlers, useEditorShortcuts } from "./useEditorShortcuts.ts";
|
|
62
65
|
import { useNodeActions } from "./useNodeActions.ts";
|
|
63
66
|
import { type PasteRefusal, useClipboardActions } from "./useClipboardActions.ts";
|
|
67
|
+
import { ListError, LoadingStatus } from "../pages/list-kit.tsx";
|
|
64
68
|
|
|
65
69
|
/** The full-screen editor for one EmVB page or theme part (R-001, R-002, R-060). */
|
|
66
70
|
|
|
@@ -81,6 +85,24 @@ export function Editor({
|
|
|
81
85
|
}) {
|
|
82
86
|
const wideEnough = useMediaQuery(EDITOR_MIN_WIDTH_QUERY);
|
|
83
87
|
const data = useEditorData(fetcher, entryId, collection);
|
|
88
|
+
return (
|
|
89
|
+
<EditedNounContext.Provider value={editedNounOf(collection)}>
|
|
90
|
+
<EditorBody data={data} fetcher={fetcher} wideEnough={wideEnough} collection={collection} />
|
|
91
|
+
</EditedNounContext.Provider>
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function EditorBody({
|
|
96
|
+
data,
|
|
97
|
+
fetcher,
|
|
98
|
+
wideEnough,
|
|
99
|
+
collection,
|
|
100
|
+
}: {
|
|
101
|
+
data: EditorData;
|
|
102
|
+
fetcher: Fetcher;
|
|
103
|
+
wideEnough: boolean;
|
|
104
|
+
collection: string;
|
|
105
|
+
}) {
|
|
84
106
|
if (data.state === "ready") {
|
|
85
107
|
return (
|
|
86
108
|
<LiveDataProvider fetcher={fetcher}>
|
|
@@ -129,6 +151,7 @@ function EditorApp({
|
|
|
129
151
|
const saver = useSave(fetcher, state, dispatch, collection);
|
|
130
152
|
// W-466: tell the person when an agent (or anyone) changed the page while they were idle.
|
|
131
153
|
const remoteChange = useRemoteChange(fetcher, collection, entry.id, state.rev, !dirty);
|
|
154
|
+
const noun = useEditedNoun();
|
|
132
155
|
const toasts = React.useMemo(() => createKumoToastManager(), []);
|
|
133
156
|
const chrome = useChromeFlags();
|
|
134
157
|
const [device, setDevice] = React.useState<PopupDevice>("desktop");
|
|
@@ -207,11 +230,23 @@ function EditorApp({
|
|
|
207
230
|
if (chrome.leaving) exit();
|
|
208
231
|
}, [chrome.leaving, exit]);
|
|
209
232
|
|
|
210
|
-
const sectionTemplates =
|
|
233
|
+
const { sectionTemplates, loopTemplates } = usePartTemplates(state.page.layout, fetcher);
|
|
234
|
+
const partDynamic = React.useMemo(
|
|
235
|
+
() => ({ sectionTemplates, loopTemplates }),
|
|
236
|
+
[sectionTemplates, loopTemplates],
|
|
237
|
+
);
|
|
211
238
|
// W-307: bound fields show live values on the canvas (site settings, preview URL parameters).
|
|
212
239
|
const live = useLiveData();
|
|
213
240
|
// W-308: collection Loops show real entries on the canvas.
|
|
214
|
-
const
|
|
241
|
+
const previewLayout = React.useMemo(
|
|
242
|
+
() =>
|
|
243
|
+
withPartLayouts(state.page.layout, [
|
|
244
|
+
...Object.values(sectionTemplates),
|
|
245
|
+
...Object.values(loopTemplates),
|
|
246
|
+
]),
|
|
247
|
+
[state.page.layout, sectionTemplates, loopTemplates],
|
|
248
|
+
);
|
|
249
|
+
const collections = useCollectionPreviews(previewLayout, fetcher);
|
|
215
250
|
const rendered = React.useMemo(
|
|
216
251
|
() =>
|
|
217
252
|
state.page.layout
|
|
@@ -221,6 +256,7 @@ function EditorApp({
|
|
|
221
256
|
scope: state.id,
|
|
222
257
|
dynamic: {
|
|
223
258
|
...(Object.keys(sectionTemplates).length > 0 ? { sectionTemplates } : {}),
|
|
259
|
+
...(Object.keys(loopTemplates).length > 0 ? { loopTemplates } : {}),
|
|
224
260
|
site: live.site,
|
|
225
261
|
params: live.params,
|
|
226
262
|
...(siteOrigin() ? { origin: siteOrigin() } : {}),
|
|
@@ -233,6 +269,7 @@ function EditorApp({
|
|
|
233
269
|
state.page.layout,
|
|
234
270
|
state.design,
|
|
235
271
|
sectionTemplates,
|
|
272
|
+
loopTemplates,
|
|
236
273
|
device,
|
|
237
274
|
live.site,
|
|
238
275
|
live.params,
|
|
@@ -338,7 +375,7 @@ function EditorApp({
|
|
|
338
375
|
dirty={dirty && !chrome.leaving}
|
|
339
376
|
onPalette={() => chrome.open("palette")}
|
|
340
377
|
>
|
|
341
|
-
<
|
|
378
|
+
<EditorToasts toastManager={toasts}>
|
|
342
379
|
{remoteChange && (
|
|
343
380
|
<div className="emvb-remote-change" role="status" data-emvb-remote-change={remoteChange}>
|
|
344
381
|
<span className="emvb-remote-change-icon" aria-hidden="true">
|
|
@@ -351,8 +388,8 @@ function EditorApp({
|
|
|
351
388
|
<span className="emvb-remote-change-text">
|
|
352
389
|
<strong>
|
|
353
390
|
{remoteChange === "agent"
|
|
354
|
-
?
|
|
355
|
-
:
|
|
391
|
+
? `An AI agent changed this ${noun}.`
|
|
392
|
+
: `This ${noun} was changed somewhere else.`}
|
|
356
393
|
</strong>{" "}
|
|
357
394
|
<span>Reload to see the latest draft. Its changes are in the version timeline.</span>
|
|
358
395
|
</span>
|
|
@@ -379,6 +416,29 @@ function EditorApp({
|
|
|
379
416
|
onRevert={() => chrome.open("revert")}
|
|
380
417
|
tools={
|
|
381
418
|
<>
|
|
419
|
+
{/* UX-084: undo and redo were keyboard-only; toasts already say "Undo takes it back". */}
|
|
420
|
+
<Button
|
|
421
|
+
variant="ghost"
|
|
422
|
+
shape="square"
|
|
423
|
+
className="emvb-icon-btn"
|
|
424
|
+
aria-label="Undo"
|
|
425
|
+
title="Undo (Ctrl/Cmd+Z)"
|
|
426
|
+
data-emvb-undo=""
|
|
427
|
+
disabled={history.past.length === 0}
|
|
428
|
+
icon={<ArrowUUpLeftIcon aria-hidden="true" />}
|
|
429
|
+
onClick={() => dispatch({ type: "undo" })}
|
|
430
|
+
/>
|
|
431
|
+
<Button
|
|
432
|
+
variant="ghost"
|
|
433
|
+
shape="square"
|
|
434
|
+
className="emvb-icon-btn"
|
|
435
|
+
aria-label="Redo"
|
|
436
|
+
title="Redo (Ctrl/Cmd+Shift+Z)"
|
|
437
|
+
data-emvb-redo=""
|
|
438
|
+
disabled={history.future.length === 0}
|
|
439
|
+
icon={<ArrowUUpRightIcon aria-hidden="true" />}
|
|
440
|
+
onClick={() => dispatch({ type: "redo" })}
|
|
441
|
+
/>
|
|
382
442
|
<A11yScoreButton report={a11y} onOpen={() => chrome.open("a11y")} />
|
|
383
443
|
<Button
|
|
384
444
|
variant="ghost"
|
|
@@ -511,6 +571,7 @@ function EditorApp({
|
|
|
511
571
|
<SmallScreenNotice />
|
|
512
572
|
)}
|
|
513
573
|
<EditorDialogs
|
|
574
|
+
parts={partDynamic}
|
|
514
575
|
chrome={chrome}
|
|
515
576
|
fetcher={fetcher}
|
|
516
577
|
collection={collection}
|
|
@@ -533,7 +594,7 @@ function EditorApp({
|
|
|
533
594
|
playgroundUrl={host.playgroundUrl}
|
|
534
595
|
setAnnouncement={setAnnouncement}
|
|
535
596
|
/>
|
|
536
|
-
</
|
|
597
|
+
</EditorToasts>
|
|
537
598
|
</EditorOverlay>
|
|
538
599
|
);
|
|
539
600
|
}
|
|
@@ -562,15 +623,17 @@ function LoadState({ data }: { data: EditorData }) {
|
|
|
562
623
|
|
|
563
624
|
function LoadBody({ data }: { data: EditorData }) {
|
|
564
625
|
const { back } = useEditorHost();
|
|
626
|
+
const noun = useEditedNoun();
|
|
627
|
+
const Noun = noun === "page" ? "Page" : "Theme part";
|
|
565
628
|
if (data.state === "not-found" || data.state === "forbidden") {
|
|
566
629
|
return (
|
|
567
630
|
<div className="emvb-state" data-emvb-editor-state={data.state}>
|
|
568
631
|
<Empty
|
|
569
|
-
title={data.state === "not-found" ?
|
|
632
|
+
title={data.state === "not-found" ? `${Noun} not found` : `You can't open this ${noun}`}
|
|
570
633
|
description={
|
|
571
634
|
data.state === "not-found"
|
|
572
|
-
? `It may have been deleted. Choose another
|
|
573
|
-
:
|
|
635
|
+
? `It may have been deleted. Choose another ${noun} from ${back.label}.`
|
|
636
|
+
: `Your role doesn't allow editing this ${noun}.`
|
|
574
637
|
}
|
|
575
638
|
contents={
|
|
576
639
|
<Button variant="secondary" onClick={back.go}>
|
|
@@ -584,18 +647,17 @@ function LoadBody({ data }: { data: EditorData }) {
|
|
|
584
647
|
if (data.state === "error") {
|
|
585
648
|
return (
|
|
586
649
|
<div className="emvb-state" data-emvb-editor-state="error">
|
|
587
|
-
<
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
description={data.message}
|
|
650
|
+
<ListError
|
|
651
|
+
title={`Couldn't open this ${noun}`}
|
|
652
|
+
message={data.message}
|
|
653
|
+
onRetry={data.retry}
|
|
592
654
|
/>
|
|
593
655
|
</div>
|
|
594
656
|
);
|
|
595
657
|
}
|
|
596
658
|
return (
|
|
597
|
-
<div className="emvb-state">
|
|
598
|
-
<
|
|
659
|
+
<div className="emvb-state" data-emvb-editor-state="loading">
|
|
660
|
+
<LoadingStatus label={`Opening the ${noun}…`} />
|
|
599
661
|
</div>
|
|
600
662
|
);
|
|
601
663
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Toasty, type createKumoToastManager } from "@cloudflare/kumo";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
|
|
4
|
+
/** Keeps toast ownership outside the full-screen editor's stacking context. */
|
|
5
|
+
export function EditorToasts({
|
|
6
|
+
toastManager,
|
|
7
|
+
children,
|
|
8
|
+
}: {
|
|
9
|
+
toastManager: ReturnType<typeof createKumoToastManager>;
|
|
10
|
+
children: React.ReactNode;
|
|
11
|
+
}) {
|
|
12
|
+
const [container, setContainer] = React.useState<HTMLDivElement | null>(null);
|
|
13
|
+
React.useLayoutEffect(() => {
|
|
14
|
+
const element = document.createElement("div");
|
|
15
|
+
element.setAttribute("data-emvb-toasts", "");
|
|
16
|
+
document.body.append(element);
|
|
17
|
+
setContainer(element);
|
|
18
|
+
return () => element.remove();
|
|
19
|
+
}, []);
|
|
20
|
+
|
|
21
|
+
return container ? (
|
|
22
|
+
<Toasty container={container} toastManager={toastManager}>
|
|
23
|
+
{children}
|
|
24
|
+
</Toasty>
|
|
25
|
+
) : null;
|
|
26
|
+
}
|