@perkyzz/emvb 0.2.1 → 0.3.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/editor/A11yCopilot.tsx +126 -0
- package/src/admin/editor/CommandPalette.tsx +118 -0
- package/src/admin/editor/Editor.tsx +274 -12
- package/src/admin/editor/EditorOverlay.tsx +6 -0
- package/src/admin/editor/PerfMeter.tsx +121 -0
- package/src/admin/editor/ShareLink.tsx +164 -0
- package/src/admin/editor/Timeline.tsx +274 -0
- package/src/admin/editor/TopBar.tsx +4 -0
- package/src/admin/editor/canvas/CanvasFrame.tsx +12 -3
- package/src/admin/editor/canvas/SelectionOverlay.tsx +1 -1
- package/src/admin/editor/collection-previews.ts +91 -0
- package/src/admin/editor/editor-css.ts +5 -3
- package/src/admin/editor/feature-css.ts +105 -0
- package/src/admin/editor/host.ts +2 -0
- package/src/admin/editor/live-data.tsx +71 -0
- package/src/admin/editor/palette-items.ts +105 -0
- package/src/admin/editor/palette.ts +67 -0
- package/src/admin/editor/panels/AddPanel.tsx +47 -2
- package/src/admin/editor/panels/ClassesSection.tsx +5 -1
- package/src/admin/editor/panels/ElementPanel.tsx +34 -3
- package/src/admin/editor/panels/LayersPanel.tsx +38 -1
- package/src/admin/editor/panels/LeftPanel.tsx +4 -1
- package/src/admin/editor/panels/SettingsPanel.tsx +12 -0
- package/src/admin/editor/panels/SiteStylesDrawer.tsx +2 -0
- package/src/admin/editor/panels/TokenScales.tsx +168 -0
- package/src/admin/editor/panels/VariableSection.tsx +9 -4
- package/src/admin/editor/panels/settings/AudienceEditor.tsx +215 -0
- package/src/admin/editor/panels/settings/BindingsEditor.tsx +221 -0
- package/src/admin/editor/panels/settings/ClassChipInput.tsx +1 -1
- package/src/admin/editor/panels/settings/EffectsControls.tsx +2 -2
- package/src/admin/editor/panels/settings/MotionControl.tsx +252 -0
- package/src/admin/editor/panels/settings/StateSwitcher.tsx +1 -1
- package/src/admin/editor/panels/settings/StyleRow.tsx +12 -0
- package/src/admin/editor/panels/settings/StyleSources.tsx +94 -0
- package/src/admin/editor/panels/settings/VariableBinding.tsx +1 -1
- package/src/admin/editor/panels/settings/VariantEditor.tsx +83 -0
- package/src/admin/editor/panels/settings/length-units.ts +1 -1
- package/src/admin/editor/panels/settings/style-sections.ts +2 -1
- package/src/admin/editor/shortcuts.ts +2 -1
- package/src/admin/editor/useEditorShortcuts.ts +8 -0
- package/src/admin/editor/useNodeActions.ts +38 -15
- package/src/admin/ui.ts +4 -4
- package/src/astro/request-data.ts +97 -0
- package/src/astro/resolve-theme.ts +35 -5
- package/src/astro/resolve.ts +8 -2
- package/src/astro/theme-posts.ts +32 -0
- package/src/astro/visitor.ts +142 -0
- package/src/constants.ts +1 -1
- package/src/core/a11y/audit.ts +282 -0
- package/src/core/arrange.ts +91 -0
- package/src/core/audience/rules.ts +104 -0
- package/src/core/audience/variants.ts +51 -0
- package/src/core/css/generate.ts +20 -2
- package/src/core/css/trace.ts +169 -0
- package/src/core/data/bindings.ts +257 -0
- package/src/core/design/tokens.ts +127 -0
- package/src/core/elements/dynamic-elements.ts +87 -2
- package/src/core/elements/index.ts +2 -0
- package/src/core/history/diff.ts +152 -0
- package/src/core/index.ts +111 -0
- package/src/core/migrate/index.ts +4 -1
- package/src/core/nesting.ts +1 -0
- package/src/core/perf/meter.ts +160 -0
- package/src/core/perf/scripts.ts +58 -0
- package/src/core/recipes/index.ts +433 -0
- package/src/core/render/index.ts +51 -4
- package/src/core/render/loop.ts +54 -7
- package/src/core/render/pagination.ts +9 -1
- package/src/core/sanitize/css.ts +39 -3
- package/src/core/sanitize/motion.ts +129 -0
- package/src/core/schema/design.ts +25 -2
- package/src/core/schema/layout.ts +168 -18
- package/src/core/schema/motion.ts +14 -0
- package/src/core/schema/style.ts +48 -3
- package/src/core/share/link.ts +147 -0
- package/src/core/theme/dynamic.ts +49 -0
- package/src/core/theme/pagination.ts +56 -0
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { Button, Dialog } from "@cloudflare/kumo";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import {
|
|
4
|
+
measurePage,
|
|
5
|
+
PERF_BUDGETS,
|
|
6
|
+
SCRIPT_LABELS,
|
|
7
|
+
type DesignSystem,
|
|
8
|
+
type Layout,
|
|
9
|
+
type PerfKind,
|
|
10
|
+
} from "../../core/index.ts";
|
|
11
|
+
import { ELEMENT_NAMES } from "./panels/ElementPanel.tsx";
|
|
12
|
+
|
|
13
|
+
const KINDS: { kind: PerfKind; label: string }[] = [
|
|
14
|
+
{ kind: "html", label: "HTML" },
|
|
15
|
+
{ kind: "css", label: "CSS" },
|
|
16
|
+
{ kind: "js", label: "JavaScript" },
|
|
17
|
+
{ kind: "images", label: "Images" },
|
|
18
|
+
];
|
|
19
|
+
|
|
20
|
+
const kb = (bytes: number) => (bytes < 1000 ? `${bytes} B` : `${(bytes / 1000).toFixed(1)} KB`);
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The page's weight against its budget (W-310): one bar per kind, the scripts it loads (zero
|
|
24
|
+
* by default, W-311), warnings, and the heaviest sections, each a click away on the canvas.
|
|
25
|
+
*/
|
|
26
|
+
export function PerfMeterDialog({
|
|
27
|
+
open,
|
|
28
|
+
onOpenChange,
|
|
29
|
+
layout,
|
|
30
|
+
design,
|
|
31
|
+
onSelect,
|
|
32
|
+
}: {
|
|
33
|
+
open: boolean;
|
|
34
|
+
onOpenChange: (open: boolean) => void;
|
|
35
|
+
layout: Layout | null;
|
|
36
|
+
design: DesignSystem;
|
|
37
|
+
onSelect: (id: string) => void;
|
|
38
|
+
}) {
|
|
39
|
+
const report = React.useMemo(
|
|
40
|
+
() => (open && layout ? measurePage(layout, design) : null),
|
|
41
|
+
[open, layout, design],
|
|
42
|
+
);
|
|
43
|
+
return (
|
|
44
|
+
<Dialog.Root open={open} onOpenChange={onOpenChange}>
|
|
45
|
+
<Dialog size="base" className="p-6 emvb-perf" data-emvb-perf="">
|
|
46
|
+
<Dialog.Title>Page weight</Dialog.Title>
|
|
47
|
+
{report && (
|
|
48
|
+
<>
|
|
49
|
+
<ul className="emvb-perf-bars">
|
|
50
|
+
{KINDS.map(({ kind, label }) => {
|
|
51
|
+
const share = Math.min(1, report.bytes[kind] / PERF_BUDGETS[kind]);
|
|
52
|
+
const over = report.over.includes(kind);
|
|
53
|
+
return (
|
|
54
|
+
<li key={kind} data-emvb-perf-kind={kind} data-over={over ? "" : undefined}>
|
|
55
|
+
<span className="emvb-perf-label">{label}</span>
|
|
56
|
+
<span
|
|
57
|
+
className="emvb-perf-bar"
|
|
58
|
+
role="meter"
|
|
59
|
+
aria-label={`${label} weight`}
|
|
60
|
+
aria-valuemin={0}
|
|
61
|
+
aria-valuemax={PERF_BUDGETS[kind]}
|
|
62
|
+
aria-valuenow={Math.min(report.bytes[kind], PERF_BUDGETS[kind])}
|
|
63
|
+
aria-valuetext={`${kb(report.bytes[kind])} of ${kb(PERF_BUDGETS[kind])}`}
|
|
64
|
+
>
|
|
65
|
+
<span style={{ width: `${Math.round(share * 100)}%` }} />
|
|
66
|
+
</span>
|
|
67
|
+
<span className="emvb-perf-value">
|
|
68
|
+
{kb(report.bytes[kind])} / {kb(PERF_BUDGETS[kind])}
|
|
69
|
+
</span>
|
|
70
|
+
</li>
|
|
71
|
+
);
|
|
72
|
+
})}
|
|
73
|
+
</ul>
|
|
74
|
+
<p className="emvb-helper" data-emvb-perf-js="">
|
|
75
|
+
{report.scripts.length === 0
|
|
76
|
+
? "Zero JavaScript: this page is plain HTML and CSS."
|
|
77
|
+
: `Scripts: ${report.scripts.map((s) => SCRIPT_LABELS[s.script]).join(", ")}.`}
|
|
78
|
+
</p>
|
|
79
|
+
{report.warnings.length > 0 && (
|
|
80
|
+
<ul className="emvb-perf-warnings" data-emvb-perf-warnings="">
|
|
81
|
+
{report.warnings.map((warning) => (
|
|
82
|
+
<li key={warning}>{warning}</li>
|
|
83
|
+
))}
|
|
84
|
+
</ul>
|
|
85
|
+
)}
|
|
86
|
+
{report.sections.length > 0 && (
|
|
87
|
+
<>
|
|
88
|
+
<h3 className="emvb-perf-heading">Heaviest sections</h3>
|
|
89
|
+
<ol className="emvb-perf-sections">
|
|
90
|
+
{report.sections.slice(0, 5).map((section) => (
|
|
91
|
+
<li key={section.id}>
|
|
92
|
+
<button
|
|
93
|
+
type="button"
|
|
94
|
+
className="emvb-link-button"
|
|
95
|
+
data-emvb-perf-section={section.id}
|
|
96
|
+
onClick={() => {
|
|
97
|
+
onSelect(section.id);
|
|
98
|
+
onOpenChange(false);
|
|
99
|
+
}}
|
|
100
|
+
>
|
|
101
|
+
{section.label || ELEMENT_NAMES[section.type] || section.type}
|
|
102
|
+
</button>{" "}
|
|
103
|
+
{kb(section.bytes)}
|
|
104
|
+
{section.images > 0
|
|
105
|
+
? ` · ${section.images} image${section.images === 1 ? "" : "s"}`
|
|
106
|
+
: ""}
|
|
107
|
+
</li>
|
|
108
|
+
))}
|
|
109
|
+
</ol>
|
|
110
|
+
</>
|
|
111
|
+
)}
|
|
112
|
+
<p className="emvb-helper">
|
|
113
|
+
HTML and CSS are gzipped estimates; image sizes come from their width and height.
|
|
114
|
+
</p>
|
|
115
|
+
</>
|
|
116
|
+
)}
|
|
117
|
+
<Dialog.Close render={(props) => <Button {...props}>Close</Button>} />
|
|
118
|
+
</Dialog>
|
|
119
|
+
</Dialog.Root>
|
|
120
|
+
);
|
|
121
|
+
}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { Button, Dialog, Input, Switch } from "@cloudflare/kumo";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import {
|
|
4
|
+
encodeSharedPage,
|
|
5
|
+
LONG_LINK_CHARS,
|
|
6
|
+
shareUrl,
|
|
7
|
+
type DesignSystem,
|
|
8
|
+
type Layout,
|
|
9
|
+
type LayoutNode,
|
|
10
|
+
} from "../../core/index.ts";
|
|
11
|
+
import { BUTTON, FIELD } from "../ui.ts";
|
|
12
|
+
|
|
13
|
+
const MEDIA_KEYS = ["src", "poster", "backgroundImage", "backgroundVideo"];
|
|
14
|
+
const siteOnly = (value: unknown) =>
|
|
15
|
+
typeof value === "string" && value.trim() !== "" && !/^(https?:)?\/\//i.test(value.trim());
|
|
16
|
+
|
|
17
|
+
/** Media on the page whose address only works on this site (W-321): a path, not a full URL. */
|
|
18
|
+
export function siteOnlyMedia(layout: Layout): number {
|
|
19
|
+
let count = 0;
|
|
20
|
+
const visit = (node: LayoutNode) => {
|
|
21
|
+
const props = node.props as Record<string, unknown>;
|
|
22
|
+
const style = (node.style ?? {}) as Record<string, unknown>;
|
|
23
|
+
for (const key of MEDIA_KEYS) {
|
|
24
|
+
const raw = props[key] ?? style[key];
|
|
25
|
+
const url = typeof raw === "object" && raw !== null ? (raw as { url?: unknown }).url : raw;
|
|
26
|
+
if (siteOnly(url)) count += 1;
|
|
27
|
+
}
|
|
28
|
+
const kids = (node as { children?: LayoutNode[] }).children;
|
|
29
|
+
if (Array.isArray(kids)) for (const child of kids) visit(child);
|
|
30
|
+
};
|
|
31
|
+
visit(layout.root);
|
|
32
|
+
return count;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Shareable playground link (W-321): this page (as it is now, saved or not) and optionally the
|
|
37
|
+
* Site styles, packed into a link that opens it on emvb.dev/playground. Nothing is uploaded: the
|
|
38
|
+
* page travels in the link's `#` part, which browsers never send to a server.
|
|
39
|
+
*/
|
|
40
|
+
export function ShareLinkDialog({
|
|
41
|
+
open,
|
|
42
|
+
onOpenChange,
|
|
43
|
+
layout,
|
|
44
|
+
design,
|
|
45
|
+
title,
|
|
46
|
+
base,
|
|
47
|
+
}: {
|
|
48
|
+
open: boolean;
|
|
49
|
+
onOpenChange: (open: boolean) => void;
|
|
50
|
+
layout: Layout | null;
|
|
51
|
+
design: DesignSystem;
|
|
52
|
+
title: string;
|
|
53
|
+
/** Playground address; emvb.dev's by default. */
|
|
54
|
+
base?: string;
|
|
55
|
+
}) {
|
|
56
|
+
const [withStyles, setWithStyles] = React.useState(true);
|
|
57
|
+
const [link, setLink] = React.useState<string | null>(null);
|
|
58
|
+
const [error, setError] = React.useState<string | null>(null);
|
|
59
|
+
const [copied, setCopied] = React.useState<"yes" | "no" | null>(null);
|
|
60
|
+
|
|
61
|
+
React.useEffect(() => {
|
|
62
|
+
if (!open || !layout) return;
|
|
63
|
+
let cancelled = false;
|
|
64
|
+
setLink(null);
|
|
65
|
+
setError(null);
|
|
66
|
+
setCopied(null);
|
|
67
|
+
encodeSharedPage({ title, layout, ...(withStyles ? { design } : {}) }).then(
|
|
68
|
+
(encoded) => {
|
|
69
|
+
if (!cancelled) setLink(shareUrl(encoded, base));
|
|
70
|
+
},
|
|
71
|
+
(reason: unknown) => {
|
|
72
|
+
if (!cancelled) setError(reason instanceof Error ? reason.message : String(reason));
|
|
73
|
+
},
|
|
74
|
+
);
|
|
75
|
+
return () => {
|
|
76
|
+
cancelled = true;
|
|
77
|
+
};
|
|
78
|
+
}, [open, layout, design, title, withStyles, base]);
|
|
79
|
+
|
|
80
|
+
const copy = () => {
|
|
81
|
+
if (!link) return;
|
|
82
|
+
if (!navigator.clipboard?.writeText) {
|
|
83
|
+
setCopied("no");
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
navigator.clipboard.writeText(link).then(
|
|
87
|
+
() => setCopied("yes"),
|
|
88
|
+
() => setCopied("no"),
|
|
89
|
+
);
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const siteMedia = layout ? siteOnlyMedia(layout) : 0;
|
|
93
|
+
return (
|
|
94
|
+
<Dialog.Root open={open} onOpenChange={onOpenChange}>
|
|
95
|
+
<Dialog size="base" className="p-6 emvb-share" data-emvb-share="">
|
|
96
|
+
<Dialog.Title>Share as a playground link</Dialog.Title>
|
|
97
|
+
<Dialog.Description>
|
|
98
|
+
Anyone with the link can open a copy of this page in the EmVB playground and edit it in
|
|
99
|
+
their own browser. The page travels inside the link; nothing is uploaded.
|
|
100
|
+
</Dialog.Description>
|
|
101
|
+
<Switch
|
|
102
|
+
label="Include Site styles (colours, fonts, sizes, classes)"
|
|
103
|
+
checked={withStyles}
|
|
104
|
+
onCheckedChange={(checked) => setWithStyles(checked === true)}
|
|
105
|
+
/>
|
|
106
|
+
{error ? (
|
|
107
|
+
<p className="emvb-helper" role="alert">
|
|
108
|
+
Couldn't build the link: {error}
|
|
109
|
+
</p>
|
|
110
|
+
) : (
|
|
111
|
+
<Input
|
|
112
|
+
label="Link"
|
|
113
|
+
className={FIELD}
|
|
114
|
+
readOnly
|
|
115
|
+
value={link ?? "Building the link…"}
|
|
116
|
+
data-emvb-share-link=""
|
|
117
|
+
onFocus={(event) => event.currentTarget.select()}
|
|
118
|
+
/>
|
|
119
|
+
)}
|
|
120
|
+
{link && (
|
|
121
|
+
<p className="emvb-helper" data-emvb-share-size="">
|
|
122
|
+
{link.length.toLocaleString("en")} characters
|
|
123
|
+
{link.length > LONG_LINK_CHARS
|
|
124
|
+
? ". That's long: some chat apps cut links this size, so paste it somewhere that keeps it whole."
|
|
125
|
+
: "."}
|
|
126
|
+
</p>
|
|
127
|
+
)}
|
|
128
|
+
{siteMedia > 0 && (
|
|
129
|
+
<p className="emvb-helper" data-emvb-share-media="">
|
|
130
|
+
{siteMedia === 1 ? "1 image or video uses" : `${siteMedia} images or videos use`} an
|
|
131
|
+
address on this site only, so the playground shows {siteMedia === 1 ? "it" : "them"}{" "}
|
|
132
|
+
empty.
|
|
133
|
+
</p>
|
|
134
|
+
)}
|
|
135
|
+
<p className="emvb-helper">
|
|
136
|
+
Unsaved changes are included. Posts, forms and uploads stay on this site.
|
|
137
|
+
</p>
|
|
138
|
+
<div className="emvb-dialog-actions">
|
|
139
|
+
{copied && (
|
|
140
|
+
<span role="status" className="emvb-helper">
|
|
141
|
+
{copied === "yes" ? "Copied." : "Copy didn't work here: select the link and copy it."}
|
|
142
|
+
</span>
|
|
143
|
+
)}
|
|
144
|
+
<Dialog.Close
|
|
145
|
+
render={(props) => (
|
|
146
|
+
<Button {...props} variant="secondary" className={BUTTON}>
|
|
147
|
+
Close
|
|
148
|
+
</Button>
|
|
149
|
+
)}
|
|
150
|
+
/>
|
|
151
|
+
<Button
|
|
152
|
+
variant="primary"
|
|
153
|
+
className={BUTTON}
|
|
154
|
+
disabled={!link}
|
|
155
|
+
onClick={copy}
|
|
156
|
+
data-emvb-share-copy=""
|
|
157
|
+
>
|
|
158
|
+
Copy link
|
|
159
|
+
</Button>
|
|
160
|
+
</div>
|
|
161
|
+
</Dialog>
|
|
162
|
+
</Dialog.Root>
|
|
163
|
+
);
|
|
164
|
+
}
|
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
import { Button, Dialog } from "@cloudflare/kumo";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import {
|
|
4
|
+
changedIds,
|
|
5
|
+
diffSections,
|
|
6
|
+
renderPage,
|
|
7
|
+
restoreSection,
|
|
8
|
+
validateLayout,
|
|
9
|
+
type DesignSystem,
|
|
10
|
+
type Layout,
|
|
11
|
+
type SectionChange,
|
|
12
|
+
} from "../../core/index.ts";
|
|
13
|
+
import { ApiError, requestJson, type Fetcher } from "../api.ts";
|
|
14
|
+
import { ELEMENT_NAMES } from "./panels/ElementPanel.tsx";
|
|
15
|
+
|
|
16
|
+
type RevisionItem = {
|
|
17
|
+
id: string;
|
|
18
|
+
createdAt: string;
|
|
19
|
+
authorId?: string | null;
|
|
20
|
+
data?: Record<string, unknown>;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
type TimelineVersion = { id: string; at: string; layout: Layout | null };
|
|
24
|
+
|
|
25
|
+
/** A revision's layout, or null when it has none or it doesn't validate (W-315). */
|
|
26
|
+
export function revisionLayout(data: Record<string, unknown> | undefined): Layout | null {
|
|
27
|
+
let raw: unknown = data?.["layout"];
|
|
28
|
+
if (typeof raw === "string") {
|
|
29
|
+
try {
|
|
30
|
+
raw = JSON.parse(raw) as unknown;
|
|
31
|
+
} catch {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if (!raw || typeof raw !== "object") return null;
|
|
36
|
+
const result = validateLayout(raw);
|
|
37
|
+
return result.ok ? result.layout : null;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** A host without EmDash revisions for this collection answers 404. */
|
|
41
|
+
export const NO_REVISIONS =
|
|
42
|
+
"This site doesn't keep saved versions of this page, so there's no timeline to show.";
|
|
43
|
+
|
|
44
|
+
function useRevisions(fetcher: Fetcher, collection: string, entryId: string, open: boolean) {
|
|
45
|
+
const [state, setState] = React.useState<
|
|
46
|
+
| { kind: "loading" }
|
|
47
|
+
| { kind: "error"; message: string }
|
|
48
|
+
| { kind: "ready"; versions: TimelineVersion[] }
|
|
49
|
+
>({ kind: "loading" });
|
|
50
|
+
React.useEffect(() => {
|
|
51
|
+
if (!open) return;
|
|
52
|
+
let cancelled = false;
|
|
53
|
+
setState({ kind: "loading" });
|
|
54
|
+
requestJson<{ items?: RevisionItem[] }>(
|
|
55
|
+
fetcher,
|
|
56
|
+
`/_emdash/api/content/${encodeURIComponent(collection)}/${encodeURIComponent(entryId)}/revisions?limit=50`,
|
|
57
|
+
)
|
|
58
|
+
.then((body) => {
|
|
59
|
+
if (cancelled) return;
|
|
60
|
+
const versions = (body?.items ?? [])
|
|
61
|
+
.map((item) => ({ id: item.id, at: item.createdAt, layout: revisionLayout(item.data) }))
|
|
62
|
+
.toSorted((a, b) => (a.at < b.at ? 1 : -1));
|
|
63
|
+
setState({ kind: "ready", versions });
|
|
64
|
+
})
|
|
65
|
+
.catch((error: unknown) => {
|
|
66
|
+
if (!cancelled) {
|
|
67
|
+
setState({
|
|
68
|
+
kind: "error",
|
|
69
|
+
message:
|
|
70
|
+
error instanceof ApiError && error.status === 404
|
|
71
|
+
? NO_REVISIONS
|
|
72
|
+
: `Couldn't load versions: ${error instanceof Error ? error.message : String(error)}`,
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
return () => {
|
|
77
|
+
cancelled = true;
|
|
78
|
+
};
|
|
79
|
+
}, [fetcher, collection, entryId, open]);
|
|
80
|
+
return state;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const KIND_LABELS: Record<SectionChange["kind"], string> = {
|
|
84
|
+
added: "Added since",
|
|
85
|
+
removed: "Removed since",
|
|
86
|
+
changed: "Changed",
|
|
87
|
+
moved: "Moved",
|
|
88
|
+
same: "Unchanged",
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
const DIFF_CSS = {
|
|
92
|
+
added: "outline:3px solid #16a34a;outline-offset:-3px",
|
|
93
|
+
removed: "outline:3px solid #dc2626;outline-offset:-3px",
|
|
94
|
+
changed: "outline:3px solid #d97706;outline-offset:-3px",
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
const when = (iso: string) => {
|
|
98
|
+
const date = new Date(iso);
|
|
99
|
+
return Number.isNaN(date.getTime()) ? iso : date.toLocaleString();
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
/** A small, script-free picture of one version with its changed sections outlined (W-315). */
|
|
103
|
+
function Snapshot({
|
|
104
|
+
layout,
|
|
105
|
+
design,
|
|
106
|
+
ids,
|
|
107
|
+
title,
|
|
108
|
+
}: {
|
|
109
|
+
layout: Layout;
|
|
110
|
+
design: DesignSystem;
|
|
111
|
+
ids: Partial<Record<"added" | "removed" | "changed", string[]>>;
|
|
112
|
+
title: string;
|
|
113
|
+
}) {
|
|
114
|
+
const doc = React.useMemo(() => {
|
|
115
|
+
const { html, css } = renderPage(layout, design, { mode: "editor" });
|
|
116
|
+
const outline = (Object.entries(ids) as [keyof typeof DIFF_CSS, string[]][])
|
|
117
|
+
.flatMap(([kind, list]) => list.map((id) => `[data-emvb-id="${id}"]{${DIFF_CSS[kind]}}`))
|
|
118
|
+
.join("");
|
|
119
|
+
return `<!doctype html><html><head><style>html{zoom:.35}body{margin:0}${css}${outline}</style></head><body>${html}</body></html>`;
|
|
120
|
+
}, [layout, design, ids]);
|
|
121
|
+
return <iframe className="emvb-timeline-frame" title={title} sandbox="" srcDoc={doc} />;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Version timeline (W-315): every saved version of the page, a side-by-side picture against the
|
|
126
|
+
* current page with what changed outlined, and restore for one section or the whole version.
|
|
127
|
+
* Restoring is an ordinary edit: undo takes it back, and nothing is saved until you save.
|
|
128
|
+
*/
|
|
129
|
+
export function TimelineDialog({
|
|
130
|
+
open,
|
|
131
|
+
onOpenChange,
|
|
132
|
+
fetcher,
|
|
133
|
+
collection,
|
|
134
|
+
entryId,
|
|
135
|
+
current,
|
|
136
|
+
design,
|
|
137
|
+
onApply,
|
|
138
|
+
}: {
|
|
139
|
+
open: boolean;
|
|
140
|
+
onOpenChange: (open: boolean) => void;
|
|
141
|
+
fetcher: Fetcher;
|
|
142
|
+
collection: string;
|
|
143
|
+
entryId: string;
|
|
144
|
+
current: Layout | null;
|
|
145
|
+
design: DesignSystem;
|
|
146
|
+
onApply: (layout: Layout, note: string) => void;
|
|
147
|
+
}) {
|
|
148
|
+
const revisions = useRevisions(fetcher, collection, entryId, open);
|
|
149
|
+
const [pickedId, setPickedId] = React.useState<string | null>(null);
|
|
150
|
+
const [error, setError] = React.useState<string | null>(null);
|
|
151
|
+
const versions = revisions.kind === "ready" ? revisions.versions : [];
|
|
152
|
+
const picked = versions.find((v) => v.id === pickedId) ?? versions[0];
|
|
153
|
+
const changes = React.useMemo(
|
|
154
|
+
() => (picked?.layout && current ? diffSections(picked.layout, current) : []),
|
|
155
|
+
[picked, current],
|
|
156
|
+
);
|
|
157
|
+
const ids = React.useMemo(() => changedIds(changes), [changes]);
|
|
158
|
+
return (
|
|
159
|
+
<Dialog.Root open={open} onOpenChange={onOpenChange}>
|
|
160
|
+
<Dialog size="xl" className="p-6 emvb-timeline" data-emvb-timeline="">
|
|
161
|
+
<Dialog.Title>Version timeline</Dialog.Title>
|
|
162
|
+
{revisions.kind === "loading" && <p className="emvb-helper">Loading versions…</p>}
|
|
163
|
+
{revisions.kind === "error" && (
|
|
164
|
+
<p className="emvb-helper" role="alert">
|
|
165
|
+
{revisions.message}
|
|
166
|
+
</p>
|
|
167
|
+
)}
|
|
168
|
+
{revisions.kind === "ready" && versions.length === 0 && (
|
|
169
|
+
<p className="emvb-helper" data-emvb-timeline-empty="">
|
|
170
|
+
No saved versions yet. Each save adds one.
|
|
171
|
+
</p>
|
|
172
|
+
)}
|
|
173
|
+
{picked && current && (
|
|
174
|
+
<div className="emvb-timeline-body">
|
|
175
|
+
<ol className="emvb-timeline-list" aria-label="Saved versions">
|
|
176
|
+
{versions.map((v) => (
|
|
177
|
+
<li key={v.id}>
|
|
178
|
+
<button
|
|
179
|
+
type="button"
|
|
180
|
+
className="emvb-timeline-version"
|
|
181
|
+
aria-current={v.id === picked.id ? "true" : undefined}
|
|
182
|
+
data-emvb-version={v.id}
|
|
183
|
+
onClick={() => setPickedId(v.id)}
|
|
184
|
+
>
|
|
185
|
+
{when(v.at)}
|
|
186
|
+
{!v.layout && " (no layout)"}
|
|
187
|
+
</button>
|
|
188
|
+
</li>
|
|
189
|
+
))}
|
|
190
|
+
</ol>
|
|
191
|
+
<div className="emvb-timeline-main">
|
|
192
|
+
{picked.layout ? (
|
|
193
|
+
<>
|
|
194
|
+
<div className="emvb-timeline-frames">
|
|
195
|
+
<figure>
|
|
196
|
+
<figcaption>{when(picked.at)}</figcaption>
|
|
197
|
+
<Snapshot
|
|
198
|
+
layout={picked.layout}
|
|
199
|
+
design={design}
|
|
200
|
+
ids={{ removed: ids.removed, changed: ids.changed }}
|
|
201
|
+
title="Saved version"
|
|
202
|
+
/>
|
|
203
|
+
</figure>
|
|
204
|
+
<figure>
|
|
205
|
+
<figcaption>Now</figcaption>
|
|
206
|
+
<Snapshot
|
|
207
|
+
layout={current}
|
|
208
|
+
design={design}
|
|
209
|
+
ids={{ added: ids.added, changed: ids.changed }}
|
|
210
|
+
title="Current page"
|
|
211
|
+
/>
|
|
212
|
+
</figure>
|
|
213
|
+
</div>
|
|
214
|
+
<ul className="emvb-timeline-changes" data-emvb-timeline-changes="">
|
|
215
|
+
{changes.map((change) => (
|
|
216
|
+
<li key={`${change.kind}:${change.id}`} data-kind={change.kind}>
|
|
217
|
+
<span className="emvb-timeline-kind">{KIND_LABELS[change.kind]}</span>{" "}
|
|
218
|
+
{change.label || ELEMENT_NAMES[change.type] || change.type}
|
|
219
|
+
{change.kind === "changed" &&
|
|
220
|
+
` · ${change.edits} element${change.edits === 1 ? "" : "s"}`}
|
|
221
|
+
{(change.kind === "changed" || change.kind === "removed") && (
|
|
222
|
+
<button
|
|
223
|
+
type="button"
|
|
224
|
+
className="emvb-link-button"
|
|
225
|
+
data-emvb-restore-section={change.id}
|
|
226
|
+
onClick={() => {
|
|
227
|
+
if (!picked.layout) return;
|
|
228
|
+
const result = restoreSection(current, picked.layout, change.id);
|
|
229
|
+
if (!result.ok) {
|
|
230
|
+
setError(result.reason);
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
setError(null);
|
|
234
|
+
onApply(result.layout, "Section restored");
|
|
235
|
+
}}
|
|
236
|
+
>
|
|
237
|
+
Restore this section
|
|
238
|
+
</button>
|
|
239
|
+
)}
|
|
240
|
+
</li>
|
|
241
|
+
))}
|
|
242
|
+
</ul>
|
|
243
|
+
{error && (
|
|
244
|
+
<p className="emvb-helper" role="alert">
|
|
245
|
+
{error}
|
|
246
|
+
</p>
|
|
247
|
+
)}
|
|
248
|
+
<p className="emvb-helper">
|
|
249
|
+
Restoring changes the page here; undo takes it back, and nothing is saved until
|
|
250
|
+
you save.
|
|
251
|
+
</p>
|
|
252
|
+
<Button
|
|
253
|
+
variant="secondary"
|
|
254
|
+
data-emvb-restore-version=""
|
|
255
|
+
onClick={() => {
|
|
256
|
+
if (!picked.layout) return;
|
|
257
|
+
onApply(picked.layout, "Version restored");
|
|
258
|
+
onOpenChange(false);
|
|
259
|
+
}}
|
|
260
|
+
>
|
|
261
|
+
Restore this whole version
|
|
262
|
+
</Button>
|
|
263
|
+
</>
|
|
264
|
+
) : (
|
|
265
|
+
<p className="emvb-helper">This version has no page layout to compare.</p>
|
|
266
|
+
)}
|
|
267
|
+
</div>
|
|
268
|
+
</div>
|
|
269
|
+
)}
|
|
270
|
+
<Dialog.Close render={(props) => <Button {...props}>Close</Button>} />
|
|
271
|
+
</Dialog>
|
|
272
|
+
</Dialog.Root>
|
|
273
|
+
);
|
|
274
|
+
}
|
|
@@ -72,6 +72,7 @@ export function TopBar({
|
|
|
72
72
|
stylesUnpublished = false,
|
|
73
73
|
canRevert = false,
|
|
74
74
|
onRevert,
|
|
75
|
+
tools,
|
|
75
76
|
}: {
|
|
76
77
|
page: TopBarPage | null;
|
|
77
78
|
dirty: boolean;
|
|
@@ -90,6 +91,8 @@ export function TopBar({
|
|
|
90
91
|
canRevert?: boolean;
|
|
91
92
|
/** Shown once the entry has a published version; asks before discarding. */
|
|
92
93
|
onRevert?: () => void;
|
|
94
|
+
/** Extra tools beside Site styles: the page weight and accessibility meters, … (W-310). */
|
|
95
|
+
tools?: React.ReactNode;
|
|
93
96
|
}) {
|
|
94
97
|
return (
|
|
95
98
|
<header className="emvb-topbar">
|
|
@@ -153,6 +156,7 @@ export function TopBar({
|
|
|
153
156
|
onClick={onSiteStyles}
|
|
154
157
|
/>
|
|
155
158
|
)}
|
|
159
|
+
{page && tools}
|
|
156
160
|
</div>
|
|
157
161
|
{page && (
|
|
158
162
|
<div
|
|
@@ -44,7 +44,7 @@ const SRCDOC =
|
|
|
44
44
|
'<!doctype html><html><head><meta charset="utf-8"><style>html,body{margin:0}</style></head><body></body></html>';
|
|
45
45
|
|
|
46
46
|
/** Element types that hold other elements and show the empty drop placeholder (W-128). */
|
|
47
|
-
const DROP_BOXES = ["container", "div-block", "flexbox", "grid", "section", "form"]
|
|
47
|
+
const DROP_BOXES = ["container", "div-block", "flexbox", "grid", "section", "form", "loop-empty"]
|
|
48
48
|
.map((type) => `.emvb-${type}:empty`)
|
|
49
49
|
.join(",");
|
|
50
50
|
/**
|
|
@@ -72,7 +72,16 @@ const EDITOR_CANVAS_CSS =
|
|
|
72
72
|
`:where(${NO_ITEMS}){min-height:48px}` +
|
|
73
73
|
`:is(${NO_ITEMS}){outline:1px dashed #94a3b8;outline-offset:-1px}` +
|
|
74
74
|
`:is(${NO_ITEMS})::after{content:"No items yet: add them in this element's Content settings";display:block;line-height:48px;text-align:center;${HINT}}` +
|
|
75
|
-
".emvb-image-missing{display:inline-block;min-width:48px;min-height:48px;background:var(--color-kumo-tint, #eee)}[data-emvb-editing]{color:transparent !important}"
|
|
75
|
+
".emvb-image-missing{display:inline-block;min-width:48px;min-height:48px;background:var(--color-kumo-tint, #eee)}[data-emvb-editing]{color:transparent !important}" +
|
|
76
|
+
// W-307: a bound element shows a thin violet underline so live values read as live.
|
|
77
|
+
"[data-emvb-bound]{text-decoration-line:underline;text-decoration-style:dotted;text-decoration-color:#7c3aed;text-underline-offset:3px}" +
|
|
78
|
+
// W-312: every A/B arm shows on the canvas, outlined so it's clear visitors see only one.
|
|
79
|
+
"[data-emvb-variant]{outline:1px dashed #d97706;outline-offset:2px}" +
|
|
80
|
+
// W-313: visitor-aware elements show on the canvas, outlined in teal.
|
|
81
|
+
"[data-emvb-audience]{outline:1px dashed #0d9488;outline-offset:2px}" +
|
|
82
|
+
// W-308: the Loop's Empty state shows under its items in the editor, marked as such.
|
|
83
|
+
".emvb-loop-item~.emvb-loop-empty{outline:1px dashed #94a3b8;outline-offset:2px;position:relative}" +
|
|
84
|
+
`.emvb-loop-item~.emvb-loop-empty::before{content:"Empty state: shown when there are no entries";display:block;${HINT}}`;
|
|
76
85
|
|
|
77
86
|
/**
|
|
78
87
|
* Tablet and Mobile previews scroll without a visible scrollbar (W-140), as phones and tablets
|
|
@@ -277,7 +286,7 @@ export function CanvasFrame({
|
|
|
277
286
|
...selection,
|
|
278
287
|
onEditText: (id) => {
|
|
279
288
|
const node = layoutRef.current ? findNode(layoutRef.current, id) : undefined;
|
|
280
|
-
if (node && isPlainTextNode(node) && plainTextOf(node) !== null) {
|
|
289
|
+
if (node && isPlainTextNode(node) && plainTextOf(node) !== null && !node.bind?.["text"]) {
|
|
281
290
|
selection.onSelect(id);
|
|
282
291
|
setEditingId(id);
|
|
283
292
|
}
|
|
@@ -63,7 +63,7 @@ const place = (box: Box) => ({
|
|
|
63
63
|
height: box.height,
|
|
64
64
|
});
|
|
65
65
|
|
|
66
|
-
/** Hover and selection outlines plus the floating label. */
|
|
66
|
+
/** Hover and selection outlines plus the floating label (DESIGN.md, canvas overlay). */
|
|
67
67
|
export function SelectionOverlay({
|
|
68
68
|
hover,
|
|
69
69
|
selected,
|