@perkyzz/emvb 0.8.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/package.json +4 -4
- package/src/admin/agents-api.ts +45 -0
- package/src/admin/editor/A11yCopilot.tsx +1 -1
- package/src/admin/editor/Editor.tsx +325 -239
- package/src/admin/editor/FieldPreview.tsx +164 -0
- package/src/admin/editor/Timeline.tsx +2 -1
- package/src/admin/editor/TopBar.tsx +36 -3
- package/src/admin/editor/canvas/CanvasFrame.tsx +2 -2
- package/src/admin/editor/canvas/DeviceBar.tsx +17 -9
- package/src/admin/editor/canvas/canvas-scale.ts +2 -2
- package/src/admin/editor/canvas/use-canvas-session.ts +2 -2
- package/src/admin/editor/co-design.ts +190 -0
- package/src/admin/editor/dnd/new-element.ts +26 -4
- package/src/admin/editor/editor-chrome.tsx +3 -3
- package/src/admin/editor/editor-commands.ts +8 -3
- package/src/admin/editor/editor-css.ts +3 -0
- package/src/admin/editor/element-chrome.ts +3 -1
- package/src/admin/editor/extension-manifests.ts +20 -0
- package/src/admin/editor/extensions/ExtensionPanels.tsx +26 -0
- package/src/admin/editor/extensions-context.tsx +27 -0
- package/src/admin/editor/feature-css.ts +17 -0
- package/src/admin/editor/host.ts +6 -0
- package/src/admin/editor/palette-items.ts +2 -2
- package/src/admin/editor/panels/AddPanel.tsx +31 -1
- package/src/admin/editor/panels/AgentRequestBox.tsx +116 -0
- package/src/admin/editor/panels/ClassesSection.tsx +9 -6
- package/src/admin/editor/panels/CoDesignPanel.tsx +170 -0
- package/src/admin/editor/panels/ColorControl.tsx +2 -2
- package/src/admin/editor/panels/ElementPanel.tsx +53 -15
- package/src/admin/editor/panels/LanguagesSection.tsx +152 -0
- package/src/admin/editor/panels/LayersPanel.tsx +10 -6
- package/src/admin/editor/panels/LeftPanel.tsx +33 -5
- package/src/admin/editor/panels/PageSettings.tsx +4 -0
- package/src/admin/editor/panels/SettingsPanel.tsx +21 -2
- package/src/admin/editor/panels/SiteStylesDrawer.tsx +7 -7
- package/src/admin/editor/panels/settings/BackgroundControls.tsx +76 -20
- package/src/admin/editor/panels/settings/BackgroundFill.tsx +8 -6
- package/src/admin/editor/panels/settings/BoxControl.tsx +5 -5
- package/src/admin/editor/panels/settings/EffectsControls.tsx +104 -9
- package/src/admin/editor/panels/settings/FieldControl.tsx +9 -3
- package/src/admin/editor/panels/settings/IconControls.tsx +14 -11
- package/src/admin/editor/panels/settings/LengthRow.tsx +27 -16
- package/src/admin/editor/panels/settings/LoopControl.tsx +269 -0
- package/src/admin/editor/panels/settings/LoopItemBindControl.tsx +1 -1
- package/src/admin/editor/panels/settings/MediaPicker.tsx +5 -5
- package/src/admin/editor/panels/settings/MotionControl.tsx +12 -11
- package/src/admin/editor/panels/settings/QueryStyleRows.tsx +7 -4
- package/src/admin/editor/panels/settings/StyleRow.tsx +113 -13
- package/src/admin/editor/panels/settings/TextMarksControl.tsx +247 -0
- package/src/admin/editor/panels/settings/VariableBinding.tsx +2 -2
- package/src/admin/editor/panels/settings/background-mode.ts +14 -11
- package/src/admin/editor/panels/settings/box-link-name.ts +1 -1
- package/src/admin/editor/panels/settings/box-sides.ts +22 -14
- package/src/admin/editor/panels/settings/heading-warning.ts +5 -1
- package/src/admin/editor/panels/settings/length-units.ts +55 -2
- package/src/admin/editor/panels/settings/query-style.ts +3 -3
- package/src/admin/editor/panels/settings/style-sections.ts +51 -10
- package/src/admin/editor/panels/style-target.ts +9 -7
- package/src/admin/editor/presence.ts +60 -0
- package/src/admin/editor/store.ts +6 -2
- package/src/admin/editor/useCoDesign.ts +177 -0
- package/src/admin/editor/useEditorCommands.ts +4 -4
- package/src/admin/editor/useExtensions.ts +45 -0
- package/src/admin/editor/useNodeActions.ts +15 -6
- package/src/admin/editor/useProposals.ts +81 -0
- package/src/admin/index.tsx +5 -1
- package/src/admin/languages-api.ts +61 -0
- package/src/admin/media-api.ts +27 -0
- package/src/admin/pages/AgentSetup.tsx +148 -0
- package/src/admin/pages/AgentsPage.tsx +11 -28
- package/src/admin/pages/CollectionsPage.tsx +215 -0
- package/src/admin/pages/CreateDialog.tsx +15 -0
- package/src/admin/pages/ImportButton.tsx +18 -0
- package/src/admin/pages/ImportElementorDialog.tsx +669 -0
- package/src/admin/pages/ImportPageLinks.tsx +86 -0
- package/src/admin/pages/PageList.tsx +15 -1
- package/src/admin/pages/ThemePartList.tsx +15 -1
- package/src/admin/pages/section-head.tsx +27 -0
- package/src/admin/proposals-api.ts +91 -0
- package/src/admin/setup/host-collections.ts +100 -0
- package/src/admin/ui.ts +39 -2
- package/src/admin/widgets/CanvasField.tsx +202 -0
- package/src/admin/widgets/convert-body.ts +54 -0
- package/src/admin/widgets/field-fetcher.ts +79 -0
- package/src/astro/content-port.ts +14 -1
- package/src/astro/index.ts +2 -0
- package/src/astro/page-count.ts +77 -0
- package/src/astro/resolve-theme.ts +58 -3
- package/src/astro/resolve.ts +128 -5
- package/src/astro/responsive-images.ts +99 -0
- package/src/constants.ts +1 -1
- package/src/core/a11y/audit.ts +44 -14
- package/src/core/arrange.ts +5 -1
- package/src/core/bounded-array.ts +31 -0
- package/src/core/canvas-collections.ts +20 -0
- package/src/core/clipboard.ts +9 -0
- package/src/core/contract.ts +285 -0
- package/src/core/css/generate.ts +89 -20
- package/src/core/css/trace.ts +18 -9
- package/src/core/css-keywords.ts +51 -1
- package/src/core/design/cascade.ts +12 -9
- package/src/core/design/classes.ts +4 -5
- package/src/core/design/devices.ts +13 -13
- package/src/core/design/states.ts +5 -3
- package/src/core/design/transfer.ts +5 -0
- package/src/core/design/variables.ts +17 -4
- package/src/core/elements/dynamic-elements.ts +19 -4
- package/src/core/elements/index.ts +73 -9
- package/src/core/extensions/define.ts +13 -0
- package/src/core/extensions/index.ts +41 -0
- package/src/core/extensions/namespace.ts +82 -0
- package/src/core/extensions/normalize.ts +141 -0
- package/src/core/extensions/placeholder.ts +41 -0
- package/src/core/extensions/registry.ts +94 -0
- package/src/core/extensions/render-ext.ts +118 -0
- package/src/core/extensions/safe-nodes.ts +93 -0
- package/src/core/extensions/schema.ts +112 -0
- package/src/core/extensions/types.ts +159 -0
- package/src/core/forms/binding.ts +1 -1
- package/src/core/history/diff.ts +1 -1
- package/src/core/import/elementor/atomic.ts +1595 -0
- package/src/core/import/elementor/classes.ts +127 -0
- package/src/core/import/elementor/context.ts +429 -0
- package/src/core/import/elementor/counter-steps.ts +72 -0
- package/src/core/import/elementor/css.ts +445 -0
- package/src/core/import/elementor/html.ts +500 -0
- package/src/core/import/elementor/index.ts +949 -0
- package/src/core/import/elementor/inline-marks.ts +81 -0
- package/src/core/import/elementor/snapshots.ts +48 -0
- package/src/core/import/elementor/style.ts +409 -0
- package/src/core/import/elementor/values.ts +241 -0
- package/src/core/import/elementor/widgets.ts +1897 -0
- package/src/core/index.ts +84 -0
- package/src/core/json-schema.ts +107 -0
- package/src/core/limits.ts +19 -0
- package/src/core/migrate/index.ts +6 -1
- package/src/core/migrate/v18.ts +222 -0
- package/src/core/perf/meter.ts +5 -5
- package/src/core/portable-text.ts +127 -0
- package/src/core/proposals-safety.ts +102 -0
- package/src/core/proposals.ts +357 -0
- package/src/core/recipes/index.ts +2 -2
- package/src/core/render/extras.ts +3 -3
- package/src/core/render/index.ts +140 -20
- package/src/core/render/loop.ts +1 -1
- package/src/core/render/pagination.ts +20 -1
- package/src/core/render/section.ts +4 -4
- package/src/core/render/vnode.ts +1 -1
- package/src/core/sanitize/css.ts +125 -10
- package/src/core/sanitize/motion.ts +116 -0
- package/src/core/saved-sections.ts +6 -0
- package/src/core/schema/descriptors.ts +3 -1
- package/src/core/schema/design.ts +2 -1
- package/src/core/schema/layout.ts +87 -14
- package/src/core/schema/style.ts +251 -114
- package/src/core/text-marks.ts +227 -0
- package/src/core/theme/dynamic.ts +9 -4
- package/src/core/theme/float.ts +1 -0
- package/src/core/theme/pagination.ts +9 -0
- package/src/core/theme/popup-rules.ts +17 -1
- package/src/core/translatable.ts +34 -0
- package/src/core/validate.ts +13 -1
- package/src/index.ts +35 -1
- package/src/mcp/errors.ts +3 -1
- package/src/mcp/ports.ts +67 -0
- package/src/mcp/prompts.ts +1 -11
- package/src/mcp/proposals.ts +281 -0
- package/src/mcp/read.ts +10 -9
- package/src/mcp/tools.ts +71 -3
- package/src/mcp/write.ts +66 -11
- package/src/server/agent-settings.ts +21 -2
- package/src/server/hooks.ts +81 -0
- package/src/server/mcp-routes.ts +15 -0
- package/src/server/plugin.ts +53 -5
- package/src/server/presence.ts +78 -0
- package/src/server/proposals.ts +261 -0
- package/src/server/requests.ts +196 -0
- package/src/server/tools-served.ts +45 -0
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { Button, Dialog, Tabs } from "@cloudflare/kumo";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { DEVICE_PREVIEW_PX, POPUP_DEVICES, type PopupDevice } from "../../core/index.ts";
|
|
4
|
+
import { escapeAttr } from "../../core/sanitize/escape.ts";
|
|
5
|
+
import { BUTTON, UI_CSS } from "../ui.ts";
|
|
6
|
+
|
|
7
|
+
const DEVICE_NAMES: Record<PopupDevice, string> = {
|
|
8
|
+
desktop: "Desktop",
|
|
9
|
+
tablet: "Tablet",
|
|
10
|
+
mobile: "Mobile",
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* W-911: the page as the public renderer writes it, for a sandboxed `srcdoc` frame. The CSS is
|
|
15
|
+
* generated, but a `</style` in it would end the element early, so `<` is CSS-escaped.
|
|
16
|
+
*/
|
|
17
|
+
export function previewDocument({
|
|
18
|
+
html,
|
|
19
|
+
css,
|
|
20
|
+
canvasStyles,
|
|
21
|
+
origin,
|
|
22
|
+
dir,
|
|
23
|
+
inlined = {},
|
|
24
|
+
}: {
|
|
25
|
+
html: string;
|
|
26
|
+
css: string;
|
|
27
|
+
canvasStyles: readonly string[];
|
|
28
|
+
origin: string;
|
|
29
|
+
dir?: "ltr" | "rtl";
|
|
30
|
+
/** W-920: stylesheet text by href, read by the editor; a sandboxed frame can't load them. */
|
|
31
|
+
inlined?: Readonly<Record<string, string>>;
|
|
32
|
+
}): string {
|
|
33
|
+
const links = canvasStyles
|
|
34
|
+
.map((href) =>
|
|
35
|
+
inlined[href] === undefined
|
|
36
|
+
? `<link rel="stylesheet" href="${escapeAttr(href)}">`
|
|
37
|
+
: `<style>${cssText(inlined[href])}</style>`,
|
|
38
|
+
)
|
|
39
|
+
.join("");
|
|
40
|
+
return [
|
|
41
|
+
`<!doctype html><html${dir ? ` dir="${dir}"` : ""}><head><meta charset="utf-8">`,
|
|
42
|
+
`<base href="${escapeAttr(origin)}/">`,
|
|
43
|
+
`<style>html,body{margin:0}</style>`,
|
|
44
|
+
links,
|
|
45
|
+
`<style>${cssText(css)}</style></head><body>${html}</body></html>`,
|
|
46
|
+
].join("");
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** `<` is CSS-escaped so a `</style` in the text can't end the element early. */
|
|
50
|
+
const cssText = (text: string) => text.replace(/</g, "\\3c ");
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* W-920: the frame is fully sandboxed (no origin), so dev servers and strict hosts refuse its
|
|
54
|
+
* stylesheet requests and the preview fell back to the browser's default type. Same-origin
|
|
55
|
+
* site stylesheets are read here and inlined; others keep their <link>.
|
|
56
|
+
*/
|
|
57
|
+
export function useInlinedStyles(
|
|
58
|
+
hrefs: readonly string[],
|
|
59
|
+
load: (href: string) => Promise<string | null> = loadStyleText,
|
|
60
|
+
): Readonly<Record<string, string>> {
|
|
61
|
+
const [texts, setTexts] = React.useState<Record<string, string>>({});
|
|
62
|
+
const key = hrefs.join("\n");
|
|
63
|
+
React.useEffect(() => {
|
|
64
|
+
let live = true;
|
|
65
|
+
void Promise.all(hrefs.map(async (href) => [href, await load(href)] as const)).then((pairs) => {
|
|
66
|
+
if (!live) return;
|
|
67
|
+
const next: Record<string, string> = {};
|
|
68
|
+
for (const [href, text] of pairs) if (text !== null) next[href] = text;
|
|
69
|
+
setTexts(next);
|
|
70
|
+
});
|
|
71
|
+
return () => {
|
|
72
|
+
live = false;
|
|
73
|
+
};
|
|
74
|
+
// oxlint-disable-next-line react-hooks/exhaustive-deps -- keyed on the list's contents.
|
|
75
|
+
}, [key, load]);
|
|
76
|
+
return texts;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
async function loadStyleText(href: string): Promise<string | null> {
|
|
80
|
+
try {
|
|
81
|
+
const url = new URL(href, window.location.href);
|
|
82
|
+
if (url.origin !== window.location.origin) return null;
|
|
83
|
+
const response = await fetch(url, { credentials: "same-origin" });
|
|
84
|
+
if (!response.ok) return null;
|
|
85
|
+
return await response.text();
|
|
86
|
+
} catch {
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** W-911: field mode has no saved draft to preview, so the unsaved layout is shown here. */
|
|
92
|
+
export function FieldPreview({
|
|
93
|
+
open,
|
|
94
|
+
onOpenChange,
|
|
95
|
+
device: initialDevice,
|
|
96
|
+
render,
|
|
97
|
+
}: {
|
|
98
|
+
open: boolean;
|
|
99
|
+
onOpenChange: (open: boolean) => void;
|
|
100
|
+
device: PopupDevice;
|
|
101
|
+
/** Renders the current layout for a device as a full HTML document. */
|
|
102
|
+
render: (device: PopupDevice) => string | null;
|
|
103
|
+
}) {
|
|
104
|
+
const [device, setDevice] = React.useState<PopupDevice>(initialDevice);
|
|
105
|
+
React.useEffect(() => {
|
|
106
|
+
if (open) setDevice(initialDevice);
|
|
107
|
+
}, [open, initialDevice]);
|
|
108
|
+
const doc = open ? render(device) : null;
|
|
109
|
+
return (
|
|
110
|
+
<Dialog.Root open={open} onOpenChange={onOpenChange}>
|
|
111
|
+
<Dialog size="xl" className="emvb-field-preview p-4">
|
|
112
|
+
<style>{UI_CSS}</style>
|
|
113
|
+
<style>{PREVIEW_CSS}</style>
|
|
114
|
+
<div data-emvb-dialog="field-preview" className="emvb-dialog">
|
|
115
|
+
<div className="emvb-field-preview-head">
|
|
116
|
+
<div>
|
|
117
|
+
<Dialog.Title>Preview</Dialog.Title>
|
|
118
|
+
<Dialog.Description>
|
|
119
|
+
Your unsaved changes, as the site will show them. Apply, then save the entry, to
|
|
120
|
+
keep them.
|
|
121
|
+
</Dialog.Description>
|
|
122
|
+
</div>
|
|
123
|
+
<Tabs
|
|
124
|
+
variant="segmented"
|
|
125
|
+
size="sm"
|
|
126
|
+
className="emvb-device-tabs"
|
|
127
|
+
tabs={POPUP_DEVICES.map((item) => ({ value: item, label: DEVICE_NAMES[item] }))}
|
|
128
|
+
value={device}
|
|
129
|
+
onValueChange={(next) => {
|
|
130
|
+
if ((POPUP_DEVICES as readonly string[]).includes(next))
|
|
131
|
+
setDevice(next as PopupDevice);
|
|
132
|
+
}}
|
|
133
|
+
/>
|
|
134
|
+
<Button variant="secondary" className={BUTTON} onClick={() => onOpenChange(false)}>
|
|
135
|
+
Back to editing
|
|
136
|
+
</Button>
|
|
137
|
+
</div>
|
|
138
|
+
<div className="emvb-field-preview-stage">
|
|
139
|
+
{doc === null ? (
|
|
140
|
+
<p className="emvb-helper">There is nothing to preview yet.</p>
|
|
141
|
+
) : (
|
|
142
|
+
<iframe
|
|
143
|
+
title={`Preview (${DEVICE_NAMES[device]})`}
|
|
144
|
+
data-emvb-field-preview={device}
|
|
145
|
+
// No scripts and no same-origin access: the layout is untrusted (D-011).
|
|
146
|
+
sandbox=""
|
|
147
|
+
srcDoc={doc}
|
|
148
|
+
style={{ width: DEVICE_PREVIEW_PX[device] }}
|
|
149
|
+
/>
|
|
150
|
+
)}
|
|
151
|
+
</div>
|
|
152
|
+
</div>
|
|
153
|
+
</Dialog>
|
|
154
|
+
</Dialog.Root>
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const PREVIEW_CSS = `
|
|
159
|
+
.emvb-field-preview { width: min(1360px, 96vw); max-width: 96vw; }
|
|
160
|
+
.emvb-field-preview-head { display: flex; align-items: center; gap: 16px; justify-content: space-between; flex-wrap: wrap; }
|
|
161
|
+
.emvb-field-preview-head > div:first-child { flex: 1 1 280px; min-width: 0; }
|
|
162
|
+
.emvb-field-preview-stage { display: flex; overflow: auto; height: 72vh; margin-top: 12px; padding: 16px; box-sizing: border-box; border: 1px solid var(--color-kumo-line); border-radius: 8px; background: var(--color-kumo-recessed); }
|
|
163
|
+
.emvb-field-preview-stage iframe { flex: none; margin: 0 auto; max-width: none; height: 100%; border: 0; border-radius: 6px; background: #fff; box-shadow: 0 0 0 1px var(--color-kumo-line), 0 8px 24px rgb(0 0 0 / 0.18); }
|
|
164
|
+
`;
|
|
@@ -375,7 +375,8 @@ export function TimelineDialog({
|
|
|
375
375
|
title={v.agent.summary}
|
|
376
376
|
>
|
|
377
377
|
<RobotIcon aria-hidden="true" size={12} />
|
|
378
|
-
|
|
378
|
+
{/* W-930: a person's save of changes accepted from a proposal. */}
|
|
379
|
+
{v.agent.tool === "accept_proposal" ? "Via agent" : "Agent"}
|
|
379
380
|
</span>
|
|
380
381
|
)}
|
|
381
382
|
</button>
|
|
@@ -3,11 +3,14 @@ import * as React from "react";
|
|
|
3
3
|
import {
|
|
4
4
|
ArrowSquareOutIcon,
|
|
5
5
|
CaretDownIcon,
|
|
6
|
+
CheckIcon,
|
|
7
|
+
EyeIcon,
|
|
6
8
|
DesktopIcon,
|
|
7
9
|
DeviceMobileIcon,
|
|
8
10
|
DeviceTabletIcon,
|
|
9
11
|
FloppyDiskIcon,
|
|
10
12
|
KeyboardIcon,
|
|
13
|
+
LaptopIcon,
|
|
11
14
|
PaintBrushIcon,
|
|
12
15
|
SignOutIcon,
|
|
13
16
|
UploadSimpleIcon,
|
|
@@ -16,12 +19,13 @@ import {
|
|
|
16
19
|
import { BUTTON, SOLID_PRIMARY } from "../ui.ts";
|
|
17
20
|
import { statusLabel } from "../entry-status.ts";
|
|
18
21
|
import type { SaveStatus } from "./useSave.ts";
|
|
19
|
-
import type {
|
|
22
|
+
import type { Device } from "../../core/index.ts";
|
|
20
23
|
import { useMediaQuery } from "./useMediaQuery.ts";
|
|
21
24
|
|
|
22
25
|
/** Preview sizes (W-158): the canvas device widths, in a window of that size. */
|
|
23
26
|
const PREVIEW_SIZES = [
|
|
24
27
|
{ device: "desktop", label: "Desktop", icon: DesktopIcon },
|
|
28
|
+
{ device: "laptop", label: "Laptop (1200 px)", icon: LaptopIcon },
|
|
25
29
|
{ device: "tablet", label: "Tablet (768 px)", icon: DeviceTabletIcon },
|
|
26
30
|
{ device: "mobile", label: "Mobile (390 px)", icon: DeviceMobileIcon },
|
|
27
31
|
] as const;
|
|
@@ -79,6 +83,7 @@ export function TopBar({
|
|
|
79
83
|
canRevert = false,
|
|
80
84
|
onRevert,
|
|
81
85
|
tools,
|
|
86
|
+
onApply,
|
|
82
87
|
}: {
|
|
83
88
|
page: TopBarPage | null;
|
|
84
89
|
dirty: boolean;
|
|
@@ -88,7 +93,7 @@ export function TopBar({
|
|
|
88
93
|
onShortcuts: () => void;
|
|
89
94
|
onSiteStyles?: () => void;
|
|
90
95
|
/** Opens the preview; with no device, at the device shown on the canvas (W-158). */
|
|
91
|
-
onPreview: (device?:
|
|
96
|
+
onPreview: (device?: Device) => void;
|
|
92
97
|
onSave: () => void;
|
|
93
98
|
onPublish: () => void;
|
|
94
99
|
/** Site styles have unpublished changes (W-153): the Publish button carries a dot. */
|
|
@@ -99,6 +104,8 @@ export function TopBar({
|
|
|
99
104
|
onRevert?: () => void;
|
|
100
105
|
/** Extra tools beside Site styles: the page weight and accessibility meters, … (W-310). */
|
|
101
106
|
tools?: React.ReactNode;
|
|
107
|
+
/** Field mode (W-900): one Apply button replaces Preview, Revert, Save draft and Publish. */
|
|
108
|
+
onApply?: () => void;
|
|
102
109
|
}) {
|
|
103
110
|
const reducedMotion = useMediaQuery("(prefers-reduced-motion: reduce)");
|
|
104
111
|
// W-769: a disabled button drops focus to the page body, so the button that was focused when
|
|
@@ -186,7 +193,33 @@ export function TopBar({
|
|
|
186
193
|
)}
|
|
187
194
|
{page && tools}
|
|
188
195
|
</div>
|
|
189
|
-
{page && (
|
|
196
|
+
{page && onApply && (
|
|
197
|
+
// W-911: field mode previews in place; there is no saved draft for a new tab.
|
|
198
|
+
<Button
|
|
199
|
+
variant="secondary"
|
|
200
|
+
className={`${BUTTON} emvb-field-preview-button`}
|
|
201
|
+
icon={<EyeIcon aria-hidden="true" />}
|
|
202
|
+
onClick={() => onPreview()}
|
|
203
|
+
>
|
|
204
|
+
Preview
|
|
205
|
+
</Button>
|
|
206
|
+
)}
|
|
207
|
+
{page && onApply && (
|
|
208
|
+
<Button
|
|
209
|
+
variant="primary"
|
|
210
|
+
className={`${BUTTON} emvb-apply-button`}
|
|
211
|
+
style={SOLID_PRIMARY}
|
|
212
|
+
icon={<CheckIcon size={14} aria-hidden="true" />}
|
|
213
|
+
aria-disabled={busy !== null}
|
|
214
|
+
onClick={() => {
|
|
215
|
+
if (busy !== null) return;
|
|
216
|
+
onApply();
|
|
217
|
+
}}
|
|
218
|
+
>
|
|
219
|
+
Apply
|
|
220
|
+
</Button>
|
|
221
|
+
)}
|
|
222
|
+
{page && !onApply && (
|
|
190
223
|
<div
|
|
191
224
|
className="emvb-topbar-actions"
|
|
192
225
|
style={{
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createPortal } from "react-dom";
|
|
2
|
-
import { isMultilineText, type Layout, type
|
|
2
|
+
import { isMultilineText, type Layout, type Device, type VNode } from "../../../core/index.ts";
|
|
3
3
|
import type { PasteRefusal } from "../useClipboardActions.ts";
|
|
4
4
|
import { CanvasTextEdit } from "./CanvasTextEdit.tsx";
|
|
5
5
|
import { useFrameFocusRing } from "./frame-focus-ring.ts";
|
|
@@ -112,7 +112,7 @@ export function CanvasFrame({
|
|
|
112
112
|
/** The style state chosen in the Style tab, shown on the selected element (W-089). */
|
|
113
113
|
statePreview?: StatePreview | null;
|
|
114
114
|
/** The previewed device (W-096): its page width, scaled to the stage (W-158, D-046). */
|
|
115
|
-
device?:
|
|
115
|
+
device?: Device;
|
|
116
116
|
/** Fit to the stage or show at 100% (W-158). */
|
|
117
117
|
zoom?: CanvasZoom;
|
|
118
118
|
/** Told the on-screen scale whenever it changes, for the zoom readout (W-158). */
|
|
@@ -1,22 +1,30 @@
|
|
|
1
1
|
import { Button, Tabs } from "@cloudflare/kumo";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
DesktopIcon,
|
|
4
|
+
DeviceMobileIcon,
|
|
5
|
+
DeviceTabletIcon,
|
|
6
|
+
type Icon,
|
|
7
|
+
LaptopIcon,
|
|
8
|
+
} from "@phosphor-icons/react";
|
|
3
9
|
import * as React from "react";
|
|
4
|
-
import {
|
|
10
|
+
import { DEVICES, type Device } from "../../../core/index.ts";
|
|
5
11
|
|
|
6
|
-
const LABELS: Record<
|
|
12
|
+
const LABELS: Record<Device, string> = {
|
|
7
13
|
desktop: "Desktop",
|
|
14
|
+
laptop: "Laptop",
|
|
8
15
|
tablet: "Tablet",
|
|
9
16
|
mobile: "Mobile",
|
|
10
17
|
};
|
|
11
18
|
|
|
12
|
-
const ICONS: Record<
|
|
19
|
+
const ICONS: Record<Device, Icon> = {
|
|
13
20
|
desktop: DesktopIcon,
|
|
21
|
+
laptop: LaptopIcon,
|
|
14
22
|
tablet: DeviceTabletIcon,
|
|
15
23
|
mobile: DeviceMobileIcon,
|
|
16
24
|
};
|
|
17
25
|
|
|
18
26
|
/** The device's icon (decorative) and its name, which stays the tab's accessible name (W-127). */
|
|
19
|
-
function DeviceLabel({ device }: { device:
|
|
27
|
+
function DeviceLabel({ device }: { device: Device }) {
|
|
20
28
|
const DeviceIcon = ICONS[device];
|
|
21
29
|
return (
|
|
22
30
|
<span className="emvb-device-label">
|
|
@@ -38,13 +46,13 @@ export function DeviceBar({
|
|
|
38
46
|
scale = 1,
|
|
39
47
|
onZoom,
|
|
40
48
|
}: {
|
|
41
|
-
device:
|
|
49
|
+
device: Device;
|
|
42
50
|
/** Whether the selected element is hidden on `device`. */
|
|
43
51
|
hidden: boolean;
|
|
44
52
|
canHide: boolean;
|
|
45
53
|
/** From the hide-on-device command, so the checkbox wording has one source. */
|
|
46
54
|
hideLabel: string;
|
|
47
|
-
onDevice: (device:
|
|
55
|
+
onDevice: (device: Device) => void;
|
|
48
56
|
onToggleHidden: () => void;
|
|
49
57
|
/** Fit or 100% (W-158), with the current on-screen scale for the readout. */
|
|
50
58
|
zoom?: "fit" | "actual";
|
|
@@ -62,13 +70,13 @@ export function DeviceBar({
|
|
|
62
70
|
variant="segmented"
|
|
63
71
|
size="sm"
|
|
64
72
|
className="emvb-device-tabs"
|
|
65
|
-
tabs={
|
|
73
|
+
tabs={DEVICES.map((item) => ({
|
|
66
74
|
value: item,
|
|
67
75
|
label: <DeviceLabel device={item} />,
|
|
68
76
|
}))}
|
|
69
77
|
value={device}
|
|
70
78
|
onValueChange={(next) => {
|
|
71
|
-
if ((
|
|
79
|
+
if ((DEVICES as readonly string[]).includes(next)) onDevice(next as Device);
|
|
72
80
|
}}
|
|
73
81
|
/>
|
|
74
82
|
</div>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DEVICE_PREVIEW_PX, type
|
|
1
|
+
import { DEVICE_PREVIEW_PX, type Device } from "../../../core/index.ts";
|
|
2
2
|
|
|
3
3
|
/** Fit scales the canvas down to the stage; Actual shows it at 100% and scrolls (W-158). */
|
|
4
4
|
export type CanvasZoom = "fit" | "actual";
|
|
@@ -9,7 +9,7 @@ export type CanvasZoom = "fit" | "actual";
|
|
|
9
9
|
* the stage width, never up; Actual keeps 100% and the stage scrolls sideways.
|
|
10
10
|
*/
|
|
11
11
|
export function canvasScale(
|
|
12
|
-
device:
|
|
12
|
+
device: Device,
|
|
13
13
|
stageWidth: number,
|
|
14
14
|
zoom: CanvasZoom,
|
|
15
15
|
): { width: number; scale: number } {
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
isPlainTextNode,
|
|
5
5
|
plainTextOf,
|
|
6
6
|
type Layout,
|
|
7
|
-
type
|
|
7
|
+
type Device,
|
|
8
8
|
type VNode,
|
|
9
9
|
} from "../../../core/index.ts";
|
|
10
10
|
import type { PasteRefusal, ClipboardActions } from "../useClipboardActions.ts";
|
|
@@ -65,7 +65,7 @@ export function useCanvasSession({
|
|
|
65
65
|
layout: Layout | null;
|
|
66
66
|
selection: CanvasSelection;
|
|
67
67
|
statePreview: StatePreview | null;
|
|
68
|
-
device:
|
|
68
|
+
device: Device;
|
|
69
69
|
zoom: CanvasZoom;
|
|
70
70
|
onScale?: (scale: number) => void;
|
|
71
71
|
refusal: PasteRefusal | null;
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import { applyProposal, type Proposal, type ProposalRefusal } from "../../core/proposals.ts";
|
|
2
|
+
import type { DesignSystem } from "../../core/schema/design.ts";
|
|
3
|
+
import type { Layout, LayoutNode } from "../../core/schema/layout.ts";
|
|
4
|
+
import { findNode, forEachNode } from "../../core/tree-ops.ts";
|
|
5
|
+
import { ELEMENT_NAMES } from "./element-chrome.ts";
|
|
6
|
+
import { adminExtensionInstalled } from "./extension-manifests.ts";
|
|
7
|
+
|
|
8
|
+
const OPTIONS = { extensionInstalled: adminExtensionInstalled };
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* W-930 co-design review, as pure functions over the editor's own state. Accepting runs the same
|
|
12
|
+
* `applyProposal` the server checked with, on the page as it is in the editor now (unsaved edits
|
|
13
|
+
* included), so nothing an agent sent reaches the page without passing every save-time check.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
export type Op = Proposal["ops"][number];
|
|
17
|
+
export type OpGroup = "added" | "changed" | "moved" | "removed" | "styles";
|
|
18
|
+
export const GROUP_LABELS: Record<OpGroup, string> = {
|
|
19
|
+
added: "Added",
|
|
20
|
+
changed: "Changed",
|
|
21
|
+
moved: "Moved",
|
|
22
|
+
removed: "Removed",
|
|
23
|
+
styles: "Site styles",
|
|
24
|
+
};
|
|
25
|
+
export const GROUP_ORDER: readonly OpGroup[] = ["added", "changed", "moved", "removed", "styles"];
|
|
26
|
+
|
|
27
|
+
/** What the editor knows about its page and styles, as a proposal base. */
|
|
28
|
+
export type EditorBase = {
|
|
29
|
+
rev: string | null;
|
|
30
|
+
layout: Layout | null;
|
|
31
|
+
design: DesignSystem;
|
|
32
|
+
/** The style draft's revision, or the published one when there is no draft (as the server). */
|
|
33
|
+
designRevision: string | null;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export const groupOf = (op: Op): OpGroup =>
|
|
37
|
+
op.kind === "insert"
|
|
38
|
+
? "added"
|
|
39
|
+
: op.kind === "update"
|
|
40
|
+
? "changed"
|
|
41
|
+
: op.kind === "move"
|
|
42
|
+
? "moved"
|
|
43
|
+
: op.kind === "delete"
|
|
44
|
+
? "removed"
|
|
45
|
+
: "styles";
|
|
46
|
+
|
|
47
|
+
const nameOf = (node: { type?: unknown } | undefined | null): string =>
|
|
48
|
+
(typeof node?.type === "string" && ELEMENT_NAMES[node.type]) ||
|
|
49
|
+
(typeof node?.type === "string" ? node.type : "Element");
|
|
50
|
+
|
|
51
|
+
const textOf = (node: unknown): string | undefined => {
|
|
52
|
+
const props = (node as { props?: Record<string, unknown> } | null)?.props;
|
|
53
|
+
const text = props?.["text"] ?? props?.["label"];
|
|
54
|
+
if (typeof text !== "string" || !text.trim()) return undefined;
|
|
55
|
+
// W-933: direction overrides and other invisible controls could make a change read as another.
|
|
56
|
+
const plain = text.replace(BIDI_AND_CONTROLS, "").trim().replace(/\s+/g, " ");
|
|
57
|
+
return plain.length > 48 ? `${plain.slice(0, 47)}…` : plain;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
/** C0 controls (not tab or newline), zero-width and bidi formatting characters. */
|
|
61
|
+
const BIDI_AND_CONTROLS =
|
|
62
|
+
// oxlint-disable-next-line no-control-regex
|
|
63
|
+
/[\u0000-\u0008\u000B-\u001F\u007F\u200B-\u200F\u202A-\u202E\u2060-\u2069\uFEFF]/g;
|
|
64
|
+
|
|
65
|
+
const quoted = (text: string | undefined) => (text ? ` “${text}”` : "");
|
|
66
|
+
|
|
67
|
+
/** One line a person can read: what the change does, to which element. Agent text is quoted. */
|
|
68
|
+
export function describeOp(op: Op, layout: Layout | null): string {
|
|
69
|
+
const target = (id: string) => (layout ? findNode(layout, id) : null);
|
|
70
|
+
switch (op.kind) {
|
|
71
|
+
case "insert": {
|
|
72
|
+
const parent = target(op.parentId);
|
|
73
|
+
return `Add ${nameOf(op.node)}${quoted(textOf(op.node))} to ${nameOf(parent)}`;
|
|
74
|
+
}
|
|
75
|
+
case "update": {
|
|
76
|
+
const node = target(op.id);
|
|
77
|
+
const fields = Object.keys(op.set).join(", ");
|
|
78
|
+
const text = textOf({ props: op.set["props"] });
|
|
79
|
+
return text
|
|
80
|
+
? `Change ${nameOf(node)} text to${quoted(text)}`
|
|
81
|
+
: `Change ${nameOf(node)}${quoted(textOf(node))}: ${fields}`;
|
|
82
|
+
}
|
|
83
|
+
case "move": {
|
|
84
|
+
const node = target(op.id);
|
|
85
|
+
return `Move ${nameOf(node)}${quoted(textOf(node))} into ${nameOf(target(op.parentId))}`;
|
|
86
|
+
}
|
|
87
|
+
case "delete": {
|
|
88
|
+
const node = target(op.id);
|
|
89
|
+
return `Remove ${nameOf(node)}${quoted(textOf(node))}`;
|
|
90
|
+
}
|
|
91
|
+
case "class":
|
|
92
|
+
return op.value === null
|
|
93
|
+
? `Remove class ${op.id}`
|
|
94
|
+
: `Set class “${String(op.value["name"] ?? op.id)}”`;
|
|
95
|
+
case "variable":
|
|
96
|
+
return op.value === null
|
|
97
|
+
? `Remove ${op.group} variable ${op.id}`
|
|
98
|
+
: `Set ${op.group} variable “${String(op.value["name"] ?? op.id)}”`;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const baseOf = (editor: EditorBase) => ({
|
|
103
|
+
revision: editor.rev ?? "",
|
|
104
|
+
layout: editor.layout,
|
|
105
|
+
design: editor.design,
|
|
106
|
+
designRevision: editor.designRevision,
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* The page and styles with the selected changes applied, or why they can't be. Never mutates the
|
|
111
|
+
* editor's state; the caller dispatches the result as one undoable edit.
|
|
112
|
+
*/
|
|
113
|
+
export function acceptOps(
|
|
114
|
+
editor: EditorBase,
|
|
115
|
+
proposal: Proposal,
|
|
116
|
+
selected: readonly number[],
|
|
117
|
+
): { ok: true; layout: Layout; design: DesignSystem; designChanged: boolean } | ProposalRefusal {
|
|
118
|
+
const applied = applyProposal(
|
|
119
|
+
baseOf(editor),
|
|
120
|
+
proposal,
|
|
121
|
+
[...selected].toSorted((a, b) => a - b),
|
|
122
|
+
OPTIONS,
|
|
123
|
+
);
|
|
124
|
+
if (!applied.ok) return applied;
|
|
125
|
+
const designChanged = selected.some((i) => groupOf(proposal.ops[i] as Op) === "styles");
|
|
126
|
+
return { ...applied, designChanged };
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export type Ghost = {
|
|
130
|
+
layout: Layout;
|
|
131
|
+
added: Set<string>;
|
|
132
|
+
changed: Set<string>;
|
|
133
|
+
removed: Set<string>;
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
const idsOf = (layout: Layout): Set<string> => {
|
|
137
|
+
const ids = new Set<string>();
|
|
138
|
+
forEachNode(layout.root as LayoutNode, (node) => ids.add(node.id));
|
|
139
|
+
return ids;
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* W-930 ghost preview of pending changes: the layout with every pending insert, update and move
|
|
144
|
+
* applied, and removals kept in place so they can be shown struck through. A new layout object;
|
|
145
|
+
* the editor's own layout is never touched. Null when the pending changes don't apply.
|
|
146
|
+
*/
|
|
147
|
+
export function ghostOf(
|
|
148
|
+
editor: EditorBase,
|
|
149
|
+
proposal: Proposal,
|
|
150
|
+
pending: readonly number[],
|
|
151
|
+
): Ghost | null {
|
|
152
|
+
if (!editor.layout) return null;
|
|
153
|
+
const shown = pending.filter((i) => {
|
|
154
|
+
const op = proposal.ops[i];
|
|
155
|
+
return op && op.kind !== "delete" && groupOf(op) !== "styles";
|
|
156
|
+
});
|
|
157
|
+
const before = idsOf(editor.layout);
|
|
158
|
+
const applied =
|
|
159
|
+
shown.length === 0
|
|
160
|
+
? { ok: true as const, layout: structuredClone(editor.layout) }
|
|
161
|
+
: applyProposal(baseOf(editor), proposal, shown, OPTIONS);
|
|
162
|
+
if (!applied.ok) return null;
|
|
163
|
+
const added = new Set([...idsOf(applied.layout)].filter((id) => !before.has(id)));
|
|
164
|
+
const changed = new Set<string>();
|
|
165
|
+
const removed = new Set<string>();
|
|
166
|
+
for (const i of pending) {
|
|
167
|
+
const op = proposal.ops[i];
|
|
168
|
+
if (op?.kind === "update" || op?.kind === "move") changed.add(op.id);
|
|
169
|
+
if (op?.kind === "delete") removed.add(op.id);
|
|
170
|
+
}
|
|
171
|
+
return { layout: applied.layout, added, changed, removed };
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/** Canvas CSS that marks the ghost: added = blue outline, changed = dashed, removed = struck. */
|
|
175
|
+
const ghostSelector = (ids: Set<string>) =>
|
|
176
|
+
[...ids].map((id) => `[data-emvb-id="${id.replace(/[^A-Za-z0-9_-]/g, "")}"]`).join(",");
|
|
177
|
+
|
|
178
|
+
export function ghostCss(ghost: Ghost): string {
|
|
179
|
+
const sel = ghostSelector;
|
|
180
|
+
const rules: string[] = [];
|
|
181
|
+
if (ghost.added.size)
|
|
182
|
+
rules.push(`${sel(ghost.added)}{outline:2px solid #2563eb;outline-offset:2px}`);
|
|
183
|
+
if (ghost.changed.size)
|
|
184
|
+
rules.push(`${sel(ghost.changed)}{outline:2px dashed #2563eb;outline-offset:2px}`);
|
|
185
|
+
if (ghost.removed.size)
|
|
186
|
+
rules.push(
|
|
187
|
+
`${sel(ghost.removed)}{outline:2px dashed #dc2626;outline-offset:2px;opacity:.5;text-decoration:line-through}`,
|
|
188
|
+
);
|
|
189
|
+
return rules.join("\n");
|
|
190
|
+
}
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
2
|
defaultElement,
|
|
3
3
|
ELEMENTS,
|
|
4
|
+
isExtensionType,
|
|
4
5
|
newNodeId,
|
|
5
6
|
type ElementType,
|
|
6
7
|
type Layout,
|
|
7
8
|
type LayoutNode,
|
|
8
9
|
} from "../../../core/index.ts";
|
|
10
|
+
import type { ThemePartType } from "../../../core/theme/part-types.ts";
|
|
11
|
+
import { isSharedPart } from "../panels/settings/heading-warning.ts";
|
|
9
12
|
|
|
10
13
|
const hasH1 = (node: LayoutNode): boolean =>
|
|
11
14
|
((node.type === "heading" || node.type === "post-title") &&
|
|
@@ -14,10 +17,17 @@ const hasH1 = (node: LayoutNode): boolean =>
|
|
|
14
17
|
|
|
15
18
|
/**
|
|
16
19
|
* A new Heading is the page's H1 when the page has none yet, otherwise the default H2 (W-147).
|
|
17
|
-
* Other nodes, and headings whose level was already chosen, are returned as they are.
|
|
20
|
+
* Other nodes, and headings whose level was already chosen, are returned as they are. In a
|
|
21
|
+
* header, footer, popup, float, synced section or loop item it stays H2: that part lands on pages
|
|
22
|
+
* that have their own H1 (W-946).
|
|
18
23
|
*/
|
|
19
|
-
export function withPageHeadingLevel(
|
|
20
|
-
|
|
24
|
+
export function withPageHeadingLevel(
|
|
25
|
+
node: LayoutNode,
|
|
26
|
+
layout: Layout,
|
|
27
|
+
partType?: ThemePartType,
|
|
28
|
+
): LayoutNode {
|
|
29
|
+
if (node.type !== "heading" || node.props.level !== 2) return node;
|
|
30
|
+
if (isSharedPart(partType) || hasH1(layout.root)) return node;
|
|
21
31
|
return { ...node, props: { ...node.props, level: 1 } };
|
|
22
32
|
}
|
|
23
33
|
|
|
@@ -55,7 +65,19 @@ export function newTabPanel(n: number, random?: () => number): LayoutNode {
|
|
|
55
65
|
* Default node for a new element from the Add panel. Only new inserts get starter children;
|
|
56
66
|
* saved Accordions and Tabs with no items keep working as they are (W-130).
|
|
57
67
|
*/
|
|
58
|
-
export function newElement(
|
|
68
|
+
export function newElement(
|
|
69
|
+
type: string,
|
|
70
|
+
random?: () => number,
|
|
71
|
+
extensionDefaults?: Record<string, unknown>,
|
|
72
|
+
): LayoutNode | null {
|
|
73
|
+
// W-927: extension elements are stored as UnknownNodes with namespaced types.
|
|
74
|
+
if (isExtensionType(type)) {
|
|
75
|
+
return {
|
|
76
|
+
id: newNodeId(random),
|
|
77
|
+
type,
|
|
78
|
+
props: extensionDefaults ? { ...extensionDefaults } : {},
|
|
79
|
+
};
|
|
80
|
+
}
|
|
59
81
|
if (!(type in ELEMENTS)) return null;
|
|
60
82
|
if (type === "tabs") {
|
|
61
83
|
const tabs = defaultElement("tabs", newNodeId(random));
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
type A11yReport,
|
|
9
9
|
type ElementType,
|
|
10
10
|
type LayoutNode,
|
|
11
|
-
type
|
|
11
|
+
type Device,
|
|
12
12
|
type ThemeDynamicData,
|
|
13
13
|
} from "../../core/index.ts";
|
|
14
14
|
import type { Fetcher } from "../api.ts";
|
|
@@ -167,7 +167,7 @@ async function revertToPublished({
|
|
|
167
167
|
/** Hide or show the selected element on the current device (W-096). */
|
|
168
168
|
export function hideSelectedOnDevice(
|
|
169
169
|
state: EditorState,
|
|
170
|
-
device:
|
|
170
|
+
device: Device,
|
|
171
171
|
dispatch: React.Dispatch<EditorAction>,
|
|
172
172
|
): void {
|
|
173
173
|
const id = state.selectedId;
|
|
@@ -225,7 +225,7 @@ export function EditorDialogs({
|
|
|
225
225
|
selectedNode: LayoutNode | null;
|
|
226
226
|
formsAvailable: boolean;
|
|
227
227
|
paletteActions: readonly EditorCommand[];
|
|
228
|
-
addFromPanel: (type: ElementType) => void;
|
|
228
|
+
addFromPanel: (type: ElementType | string) => void;
|
|
229
229
|
addRecipe: (id: string) => void;
|
|
230
230
|
deleteAsk: { id: string; label: string; count: number } | null;
|
|
231
231
|
setDeleteAsk: (ask: { id: string; label: string; count: number } | null) => void;
|