@perkyzz/emvb 1.3.0 → 1.4.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 +2 -2
- package/package.json +2 -2
- package/src/admin/bulk-api.ts +5 -1
- package/src/admin/editor/A11yCopilot.tsx +3 -1
- package/src/admin/editor/Editor.tsx +22 -2
- package/src/admin/editor/Timeline.tsx +1 -8
- package/src/admin/editor/canvas/DeviceBar.tsx +7 -2
- package/src/admin/editor/canvas/EmptyCanvas.tsx +11 -2
- package/src/admin/editor/canvas/use-canvas-dnd.ts +1 -20
- package/src/admin/editor/canvas/vnode-react.tsx +2 -0
- package/src/admin/editor/co-design.ts +36 -1
- package/src/admin/editor/dnd/dragged-source.ts +22 -0
- package/src/admin/editor/dnd/layer-drop.ts +141 -0
- package/src/admin/editor/dnd/new-element.ts +16 -0
- package/src/admin/editor/editor-css.ts +9 -1
- package/src/admin/editor/element-chrome.ts +6 -0
- package/src/admin/editor/feature-css.ts +22 -0
- package/src/admin/editor/inert-links.ts +8 -0
- package/src/admin/editor/panels/ColorControl.tsx +2 -2
- package/src/admin/editor/panels/FontFaces.tsx +342 -0
- package/src/admin/editor/panels/LayersPanel.tsx +56 -6
- package/src/admin/editor/panels/LeftPanel.tsx +153 -29
- package/src/admin/editor/panels/SettingsPanel.tsx +1 -0
- package/src/admin/editor/panels/SiteStylesDrawer.tsx +5 -0
- package/src/admin/editor/panels/TemplatesPanel.tsx +205 -0
- package/src/admin/editor/panels/TokenScales.tsx +2 -0
- package/src/admin/editor/panels/TriggersEditor.tsx +203 -9
- package/src/admin/editor/panels/VariableSection.tsx +111 -7
- package/src/admin/editor/panels/color-space.ts +71 -6
- package/src/admin/editor/panels/settings/AudienceEditor.tsx +3 -0
- package/src/admin/editor/panels/settings/FieldControl.tsx +18 -0
- package/src/admin/editor/panels/settings/LoopItemBindControl.tsx +9 -3
- package/src/admin/editor/panels/settings/StickyControl.tsx +97 -0
- package/src/admin/editor/panels/settings/StyleRow.tsx +14 -0
- package/src/admin/editor/panels/settings/style-sections.ts +19 -2
- package/src/admin/editor/panels/url-rules.ts +43 -0
- package/src/admin/editor/panels/use-layers-drop.ts +232 -0
- package/src/admin/editor/store.ts +4 -2
- package/src/admin/editor/useExtensions.ts +3 -1
- package/src/admin/editor/useNodeActions.ts +74 -1
- package/src/admin/editor/useSave.ts +116 -85
- package/src/admin/export-api.ts +25 -2
- package/src/admin/extension-outputs.ts +179 -0
- package/src/admin/font-files-api.ts +38 -0
- package/src/admin/pages/ImportButton.tsx +15 -4
- package/src/admin/pages/ImportElementorDialog.tsx +22 -188
- package/src/admin/pages/ImportHtmlDialog.tsx +209 -0
- package/src/admin/pages/ImportImageCopies.tsx +167 -0
- package/src/admin/pages/ImportReport.tsx +63 -0
- package/src/admin/pages/NewPageDialog.tsx +54 -32
- package/src/admin/pages/PageList.tsx +9 -0
- package/src/admin/pages/ThemePartList.tsx +9 -0
- package/src/astro/EmVBPage.astro +5 -2
- package/src/astro/extension-styles.ts +35 -0
- package/src/astro/forms/EmVBFormsClient.astro +3 -0
- package/src/astro/forms/enhance.ts +107 -0
- package/src/astro/popups/runtime.ts +47 -2
- package/src/astro/render.ts +19 -4
- package/src/astro/resolve-theme.ts +11 -4
- package/src/astro/widgets/EmVBStickyRuntime.astro +9 -0
- package/src/astro/widgets/EmVBThemeRuntime.astro +9 -0
- package/src/astro/widgets/EmVBWidgetRuntimes.astro +12 -0
- package/src/astro/widgets/alerts.ts +16 -2
- package/src/astro/widgets/carousel.ts +65 -24
- package/src/astro/widgets/countdown.ts +18 -7
- package/src/astro/widgets/extension-runtimes.ts +27 -0
- package/src/astro/widgets/headline.ts +14 -5
- package/src/astro/widgets/sticky.ts +87 -0
- package/src/astro/widgets/theme.ts +52 -0
- package/src/constants.ts +1 -1
- package/src/core/a11y/audit.ts +150 -2
- package/src/core/arrange.ts +19 -1
- package/src/core/css/font-face.ts +72 -0
- package/src/core/css/generate.ts +35 -1
- package/src/core/elements/form-elements.ts +119 -9
- package/src/core/elements/icon-svg.ts +14 -0
- package/src/core/elements/index.ts +24 -4
- package/src/core/elements/input-limits.ts +44 -0
- package/src/core/elements/menu.ts +109 -47
- package/src/core/elements/site.ts +108 -0
- package/src/core/elements/widgets.ts +13 -3
- package/src/core/export/runtimes.generated.ts +7 -5
- package/src/core/export/site.ts +50 -4
- package/src/core/extensions/classes.ts +114 -0
- package/src/core/extensions/index.ts +17 -2
- package/src/core/extensions/normalize.ts +13 -0
- package/src/core/extensions/registry.ts +134 -10
- package/src/core/extensions/render-ext.ts +66 -21
- package/src/core/extensions/safe-nodes.ts +67 -11
- package/src/core/extensions/types.ts +48 -1
- package/src/core/fonts/files.ts +74 -0
- package/src/core/fonts/google.ts +112 -0
- package/src/core/fonts/test-font.ts +9 -0
- package/src/core/import/elementor/context.ts +13 -4
- package/src/core/import/elementor/index.ts +32 -21
- package/src/core/import/elementor/widgets.ts +114 -12
- package/src/core/import/html/blocks.ts +602 -0
- package/src/core/import/html/index.ts +155 -0
- package/src/core/import/html/map.ts +958 -0
- package/src/core/import/html/parse.ts +430 -0
- package/src/core/index.ts +45 -0
- package/src/core/migrate/v18.ts +3 -0
- package/src/core/public-attributes.ts +17 -0
- package/src/core/render/extras.ts +31 -7
- package/src/core/render/form.ts +103 -10
- package/src/core/render/index.ts +151 -15
- package/src/core/render/section.ts +31 -1
- package/src/core/render/spacer-basis.ts +102 -0
- package/src/core/render/theme-boot.ts +16 -0
- package/src/core/render/vnode.ts +1 -1
- package/src/core/sanitize/css.ts +68 -3
- package/src/core/sanitize/motion.ts +12 -0
- package/src/core/schema/design.ts +40 -0
- package/src/core/schema/layout.ts +114 -5
- package/src/core/schema/style.ts +28 -0
- package/src/core/templates/index.ts +218 -0
- package/src/core/templates/pages.ts +29 -0
- package/src/core/templates/sections.ts +794 -0
- package/src/core/templates/types.ts +9 -0
- package/src/core/theme/dynamic.ts +9 -6
- package/src/core/theme/popup-markup.ts +21 -2
- package/src/core/theme/popup-rules.ts +36 -0
- package/src/core/theme/triggers.ts +64 -5
- package/src/core/translatable.ts +5 -2
- package/src/extension-build.ts +331 -0
- package/src/index.ts +25 -3
- package/src/mcp/brief.ts +191 -0
- package/src/mcp/prompts.ts +33 -0
- package/src/mcp/read.ts +29 -1
- package/src/mcp/tools.ts +40 -1
- package/src/mcp/write.ts +41 -1
- package/src/server/extension-routes.ts +73 -0
- package/src/server/font-routes.ts +301 -0
- package/src/server/plugin.ts +9 -0
|
@@ -1,15 +1,23 @@
|
|
|
1
1
|
import { Tabs } from "@cloudflare/kumo";
|
|
2
2
|
import * as React from "react";
|
|
3
|
-
import type { ElementType, Layout } from "../../../core/index.ts";
|
|
3
|
+
import type { DesignSystem, ElementType, Layout } from "../../../core/index.ts";
|
|
4
4
|
import { AddPanel } from "./AddPanel.tsx";
|
|
5
|
+
import { TemplatesPanel } from "./TemplatesPanel.tsx";
|
|
5
6
|
import { LayersPanel } from "./LayersPanel.tsx";
|
|
6
7
|
import { CoDesignPanel } from "./CoDesignPanel.tsx";
|
|
7
8
|
import type { CoDesign } from "../useCoDesign.ts";
|
|
8
9
|
import { ExtensionPanels } from "../extensions/ExtensionPanels.tsx";
|
|
9
10
|
import type { ClipboardActions } from "../useClipboardActions.ts";
|
|
10
11
|
import type { SavedSectionActions } from "../useSavedSections.ts";
|
|
12
|
+
import { transferKinds } from "../dnd/drop-target.ts";
|
|
13
|
+
import { TAB_SPRING_MS } from "../dnd/layer-drop.ts";
|
|
14
|
+
import type { LayersDropCallbacks } from "./use-layers-drop.ts";
|
|
11
15
|
|
|
12
16
|
const SESSION_KEY = "emvb-left-tab";
|
|
17
|
+
const ADD_VIEW_KEY = "emvb-add-view";
|
|
18
|
+
|
|
19
|
+
const overLayersTab = (target: EventTarget | null) =>
|
|
20
|
+
target instanceof Element && target.closest('[role="tab"]')?.textContent?.trim() === "Layers";
|
|
13
21
|
|
|
14
22
|
/** Add | Layers | Agent left panel (W-018, W-930). Remembers the last tab for the session. */
|
|
15
23
|
export function LeftPanel({
|
|
@@ -18,6 +26,8 @@ export function LeftPanel({
|
|
|
18
26
|
onSelect,
|
|
19
27
|
onAdd,
|
|
20
28
|
onRecipe,
|
|
29
|
+
onTemplate,
|
|
30
|
+
design,
|
|
21
31
|
saved,
|
|
22
32
|
onDuplicate,
|
|
23
33
|
onMoveUp,
|
|
@@ -28,6 +38,8 @@ export function LeftPanel({
|
|
|
28
38
|
onSaveSection,
|
|
29
39
|
formsAvailable = true,
|
|
30
40
|
coDesign,
|
|
41
|
+
onDropNew,
|
|
42
|
+
onMoveTo,
|
|
31
43
|
}: {
|
|
32
44
|
layout: Layout | null;
|
|
33
45
|
selectedId: string | null;
|
|
@@ -35,6 +47,9 @@ export function LeftPanel({
|
|
|
35
47
|
onAdd: (type: ElementType | string) => void;
|
|
36
48
|
/** Adds a section recipe (W-320). */
|
|
37
49
|
onRecipe?: (id: string) => void;
|
|
50
|
+
/** Inserts a starter section template (W-1068); with `design`, the Add tab offers Templates. */
|
|
51
|
+
onTemplate?: (id: string) => void;
|
|
52
|
+
design?: DesignSystem;
|
|
38
53
|
/** My sections (W-876). */
|
|
39
54
|
saved?: SavedSectionActions;
|
|
40
55
|
onDuplicate: (id: string) => void;
|
|
@@ -49,7 +64,7 @@ export function LeftPanel({
|
|
|
49
64
|
formsAvailable?: boolean;
|
|
50
65
|
/** W-930: agent proposals to review; the Agent tab shows only with it. */
|
|
51
66
|
coDesign?: CoDesign;
|
|
52
|
-
}) {
|
|
67
|
+
} & LayersDropCallbacks) {
|
|
53
68
|
const [tab, setTab] = React.useState(() => {
|
|
54
69
|
try {
|
|
55
70
|
const last = sessionStorage.getItem(SESSION_KEY);
|
|
@@ -58,6 +73,27 @@ export function LeftPanel({
|
|
|
58
73
|
return "add";
|
|
59
74
|
}
|
|
60
75
|
});
|
|
76
|
+
const [addView, setAddView] = React.useState(() => {
|
|
77
|
+
try {
|
|
78
|
+
return sessionStorage.getItem(ADD_VIEW_KEY) === "templates" ? "templates" : "elements";
|
|
79
|
+
} catch {
|
|
80
|
+
return "elements";
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
const changeAddView = (value: string) => {
|
|
84
|
+
const next = value === "templates" ? "templates" : "elements";
|
|
85
|
+
setAddView(next);
|
|
86
|
+
try {
|
|
87
|
+
sessionStorage.setItem(ADD_VIEW_KEY, next);
|
|
88
|
+
} catch {
|
|
89
|
+
/* private mode */
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
const addSwitch = React.useRef<HTMLDivElement>(null);
|
|
93
|
+
React.useEffect(() => {
|
|
94
|
+
addSwitch.current?.querySelector('[role="tablist"]')?.setAttribute("aria-label", "Add");
|
|
95
|
+
});
|
|
96
|
+
const templates = onTemplate && design ? { onTemplate, design } : null;
|
|
61
97
|
const changeTab = (value: string) => {
|
|
62
98
|
setTab(value);
|
|
63
99
|
try {
|
|
@@ -66,32 +102,78 @@ export function LeftPanel({
|
|
|
66
102
|
/* private mode */
|
|
67
103
|
}
|
|
68
104
|
};
|
|
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
|
-
|
|
105
|
+
// W-1080: dragging an Add tile over the Layers tab opens Layers, so the tile can be dropped
|
|
106
|
+
// between rows. The Add panel stays mounted (hidden) until the drag ends: a removed drag
|
|
107
|
+
// source gets no dragend, which would leave the drag stash set.
|
|
108
|
+
const [dragFromAdd, setDragFromAdd] = React.useState(false);
|
|
109
|
+
const spring = React.useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
110
|
+
const stopSpring = React.useCallback(() => {
|
|
111
|
+
if (spring.current) clearTimeout(spring.current);
|
|
112
|
+
spring.current = null;
|
|
113
|
+
}, []);
|
|
114
|
+
// Entering anything but the tab (its own children count as the tab) cancels the switch.
|
|
115
|
+
// dragleave can't: it fires after the dragenter of the tab's inner label.
|
|
116
|
+
React.useEffect(() => {
|
|
117
|
+
const enter = (event: DragEvent) => {
|
|
118
|
+
if (!overLayersTab(event.target)) stopSpring();
|
|
119
|
+
};
|
|
120
|
+
document.addEventListener("dragenter", enter);
|
|
121
|
+
return () => {
|
|
122
|
+
document.removeEventListener("dragenter", enter);
|
|
123
|
+
stopSpring();
|
|
124
|
+
};
|
|
125
|
+
}, [stopSpring]);
|
|
126
|
+
React.useEffect(() => {
|
|
127
|
+
if (!dragFromAdd) return;
|
|
128
|
+
const end = () => setDragFromAdd(false);
|
|
129
|
+
window.addEventListener("dragend", end);
|
|
130
|
+
window.addEventListener("drop", end);
|
|
131
|
+
return () => {
|
|
132
|
+
window.removeEventListener("dragend", end);
|
|
133
|
+
window.removeEventListener("drop", end);
|
|
134
|
+
};
|
|
135
|
+
}, [dragFromAdd]);
|
|
136
|
+
// Playwright's and some browsers' drags send dragenter rather than a stream of dragover, so
|
|
137
|
+
// both start the switch.
|
|
138
|
+
const springOver = (event: React.DragEvent) => {
|
|
139
|
+
const kinds = transferKinds(event.dataTransfer);
|
|
140
|
+
if ((!kinds.neu && !kinds.existing) || !overLayersTab(event.target)) {
|
|
141
|
+
stopSpring();
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
if (spring.current) return;
|
|
145
|
+
spring.current = setTimeout(() => {
|
|
146
|
+
spring.current = null;
|
|
147
|
+
if (tab === "add") setDragFromAdd(true);
|
|
148
|
+
changeTab("layers");
|
|
149
|
+
}, TAB_SPRING_MS);
|
|
150
|
+
};
|
|
151
|
+
const springProps =
|
|
152
|
+
tab !== "layers" && (onDropNew || onMoveTo)
|
|
153
|
+
? { onDragEnter: springOver, onDragOver: springOver }
|
|
154
|
+
: {};
|
|
155
|
+
const showAgent = tab === "agent" && !!coDesign;
|
|
156
|
+
const showAdd = !showAgent && tab === "add";
|
|
157
|
+
const addPanel = (
|
|
158
|
+
<>
|
|
159
|
+
{templates && (
|
|
160
|
+
<div ref={addSwitch} className="emvb-add-switch" data-emvb-add-view={addView}>
|
|
161
|
+
<Tabs
|
|
162
|
+
variant="segmented"
|
|
163
|
+
size="sm"
|
|
164
|
+
className="emvb-add-switch-tabs"
|
|
165
|
+
tabs={[
|
|
166
|
+
{ value: "elements", label: "Elements" },
|
|
167
|
+
{ value: "templates", label: "Templates" },
|
|
168
|
+
]}
|
|
169
|
+
value={addView}
|
|
170
|
+
onValueChange={changeAddView}
|
|
171
|
+
/>
|
|
172
|
+
</div>
|
|
173
|
+
)}
|
|
174
|
+
{templates && addView === "templates" ? (
|
|
175
|
+
<TemplatesPanel design={templates.design} onInsert={templates.onTemplate} />
|
|
176
|
+
) : (
|
|
95
177
|
<>
|
|
96
178
|
<AddPanel
|
|
97
179
|
onAdd={onAdd}
|
|
@@ -101,7 +183,47 @@ export function LeftPanel({
|
|
|
101
183
|
/>
|
|
102
184
|
<ExtensionPanels />
|
|
103
185
|
</>
|
|
104
|
-
)
|
|
186
|
+
)}
|
|
187
|
+
</>
|
|
188
|
+
);
|
|
189
|
+
return (
|
|
190
|
+
<div className="emvb-panel-body emvb-left-panel">
|
|
191
|
+
<div className="emvb-left-tabs" data-emvb-left-tabs="" {...springProps}>
|
|
192
|
+
<Tabs
|
|
193
|
+
variant="underline"
|
|
194
|
+
className="emvb-tabs"
|
|
195
|
+
tabs={[
|
|
196
|
+
{ value: "add", label: "Add" },
|
|
197
|
+
{ value: "layers", label: "Layers" },
|
|
198
|
+
...(coDesign
|
|
199
|
+
? [
|
|
200
|
+
{
|
|
201
|
+
value: "agent",
|
|
202
|
+
label:
|
|
203
|
+
coDesign.proposals.items.length > 0
|
|
204
|
+
? `Agent (${coDesign.proposals.items.length})`
|
|
205
|
+
: "Agent",
|
|
206
|
+
},
|
|
207
|
+
]
|
|
208
|
+
: []),
|
|
209
|
+
]}
|
|
210
|
+
value={tab}
|
|
211
|
+
onValueChange={changeTab}
|
|
212
|
+
/>
|
|
213
|
+
</div>
|
|
214
|
+
{showAgent && coDesign && <CoDesignPanel co={coDesign} layout={layout} />}
|
|
215
|
+
{/* One slot for Add whether shown or held, so React keeps the dragged tile's node. */}
|
|
216
|
+
{(showAdd || dragFromAdd) && (
|
|
217
|
+
<div
|
|
218
|
+
className="emvb-add-holder"
|
|
219
|
+
data-emvb-add-held={showAdd ? undefined : ""}
|
|
220
|
+
hidden={!showAdd}
|
|
221
|
+
style={showAdd ? { display: "contents" } : undefined}
|
|
222
|
+
>
|
|
223
|
+
{addPanel}
|
|
224
|
+
</div>
|
|
225
|
+
)}
|
|
226
|
+
{!showAgent && !showAdd && (
|
|
105
227
|
<LayersPanel
|
|
106
228
|
layout={layout}
|
|
107
229
|
selectedId={selectedId}
|
|
@@ -113,6 +235,8 @@ export function LeftPanel({
|
|
|
113
235
|
clipboard={clipboard}
|
|
114
236
|
onRename={onRename}
|
|
115
237
|
onSaveSection={onSaveSection}
|
|
238
|
+
onDropNew={onDropNew}
|
|
239
|
+
onMoveTo={onMoveTo}
|
|
116
240
|
/>
|
|
117
241
|
)}
|
|
118
242
|
</div>
|
|
@@ -26,6 +26,7 @@ import {
|
|
|
26
26
|
type VariableKind,
|
|
27
27
|
} from "../../../core/index.ts";
|
|
28
28
|
import { BUTTON, SOLID_DESTRUCTIVE } from "../../ui.ts";
|
|
29
|
+
import type { Fetcher } from "../../api.ts";
|
|
29
30
|
import { ClassesSection } from "./ClassesSection.tsx";
|
|
30
31
|
import { stopEditorShortcuts } from "./settings/ClassChip.tsx";
|
|
31
32
|
import { isCancelEscape } from "../ime.ts";
|
|
@@ -51,6 +52,8 @@ type Props = {
|
|
|
51
52
|
/** W-252: called with what a delete removes, before the page loses its uses. */
|
|
52
53
|
onDeleted?: (deletion: Deletion) => void;
|
|
53
54
|
onClose: () => void;
|
|
55
|
+
/** W-1072: lets font variables upload or download their own font files. */
|
|
56
|
+
fetcher?: Fetcher;
|
|
54
57
|
};
|
|
55
58
|
|
|
56
59
|
function exportDesign(design: DesignSystem) {
|
|
@@ -77,6 +80,7 @@ export function SiteStylesDrawer({
|
|
|
77
80
|
onLayoutChange,
|
|
78
81
|
onDeleted,
|
|
79
82
|
onClose,
|
|
83
|
+
fetcher,
|
|
80
84
|
}: Props) {
|
|
81
85
|
const [tab, setTab] = React.useState<"variables" | "classes" | "defaults">("variables");
|
|
82
86
|
const [error, setError] = React.useState<string | null>(null);
|
|
@@ -299,6 +303,7 @@ export function SiteStylesDrawer({
|
|
|
299
303
|
design={design}
|
|
300
304
|
layout={layout}
|
|
301
305
|
onSave={save}
|
|
306
|
+
{...(fetcher ? { fetcher } : {})}
|
|
302
307
|
onAskDelete={(id, name) =>
|
|
303
308
|
setConfirm({ kind: "variable", variableKind: "font", id, name })
|
|
304
309
|
}
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import { Button, Input } from "@cloudflare/kumo";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import {
|
|
4
|
+
LAYOUT_SCHEMA_VERSION,
|
|
5
|
+
renderPage,
|
|
6
|
+
resolveTemplateNode,
|
|
7
|
+
SECTION_TEMPLATES,
|
|
8
|
+
type DesignSystem,
|
|
9
|
+
type Layout,
|
|
10
|
+
type SectionTemplate,
|
|
11
|
+
} from "../../../core/index.ts";
|
|
12
|
+
import { matchesSearch } from "../../search.ts";
|
|
13
|
+
import { BUTTON, FIELD } from "../../ui.ts";
|
|
14
|
+
import { NEW_ELEMENT_MIME } from "../dnd/drop-target.ts";
|
|
15
|
+
import { dragStash } from "../dnd/drag-stash.ts";
|
|
16
|
+
import { templateDragType } from "../dnd/new-element.ts";
|
|
17
|
+
import { isCancelEscape } from "../ime.ts";
|
|
18
|
+
import { inertLinks } from "../inert-links.ts";
|
|
19
|
+
|
|
20
|
+
/** The width the preview lays a section out at before scaling it down to the tile. */
|
|
21
|
+
const PREVIEW_WIDTH = 1280;
|
|
22
|
+
|
|
23
|
+
const previews = new WeakMap<DesignSystem, Map<string, string>>();
|
|
24
|
+
|
|
25
|
+
type PreviewScheme = "light" | "dark";
|
|
26
|
+
|
|
27
|
+
/** The scheme the editor canvas shows Site styles in: the admin's own system setting. */
|
|
28
|
+
const currentScheme = (): PreviewScheme =>
|
|
29
|
+
typeof matchMedia === "function" && matchMedia("(prefers-color-scheme: dark)").matches
|
|
30
|
+
? "dark"
|
|
31
|
+
: "light";
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* W-1068: a template's picture, drawn by the public renderer with the site's styles. Cached per
|
|
35
|
+
* design object, so typing in the search or reopening the panel never renders it again. The
|
|
36
|
+
* picture is pinned to one scheme (`data-emvb-theme`, as a Theme toggle pins it), with the
|
|
37
|
+
* browser's own page colours under it, so dark Site styles never land on a white page.
|
|
38
|
+
*/
|
|
39
|
+
export function templatePreviewDoc(
|
|
40
|
+
template: SectionTemplate,
|
|
41
|
+
design: DesignSystem,
|
|
42
|
+
scheme: PreviewScheme = "light",
|
|
43
|
+
): string {
|
|
44
|
+
let byKey = previews.get(design);
|
|
45
|
+
if (!byKey) {
|
|
46
|
+
byKey = new Map();
|
|
47
|
+
previews.set(design, byKey);
|
|
48
|
+
}
|
|
49
|
+
const key = `${template.id}:${scheme}`;
|
|
50
|
+
const cached = byKey.get(key);
|
|
51
|
+
if (cached) return cached;
|
|
52
|
+
const layout: Layout = {
|
|
53
|
+
schemaVersion: LAYOUT_SCHEMA_VERSION,
|
|
54
|
+
root: {
|
|
55
|
+
id: "tplview0",
|
|
56
|
+
type: "container",
|
|
57
|
+
props: {},
|
|
58
|
+
children: [resolveTemplateNode(template, design)],
|
|
59
|
+
} as Layout["root"],
|
|
60
|
+
};
|
|
61
|
+
const { html, css } = renderPage(layout, design);
|
|
62
|
+
const doc = `<!doctype html><html data-emvb-theme="${scheme}"><head><style>:root{color-scheme:${scheme}}body{margin:0;width:${PREVIEW_WIDTH}px;font-family:system-ui,sans-serif;background:Canvas;color:CanvasText}${css}</style></head><body>${inertLinks(html)}</body></html>`;
|
|
63
|
+
byKey.set(key, doc);
|
|
64
|
+
return doc;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Renders only once the tile scrolls near view, and scales the 1280 px page to the tile. */
|
|
68
|
+
function TemplatePreview({
|
|
69
|
+
template,
|
|
70
|
+
design,
|
|
71
|
+
}: {
|
|
72
|
+
template: SectionTemplate;
|
|
73
|
+
design: DesignSystem;
|
|
74
|
+
}) {
|
|
75
|
+
const ref = React.useRef<HTMLDivElement>(null);
|
|
76
|
+
const [near, setNear] = React.useState(() => typeof IntersectionObserver === "undefined");
|
|
77
|
+
const [scale, setScale] = React.useState(0.2);
|
|
78
|
+
React.useEffect(() => {
|
|
79
|
+
const box = ref.current;
|
|
80
|
+
if (!box) return;
|
|
81
|
+
const fit = () => {
|
|
82
|
+
if (box.clientWidth > 0) setScale(box.clientWidth / PREVIEW_WIDTH);
|
|
83
|
+
};
|
|
84
|
+
fit();
|
|
85
|
+
const resize = typeof ResizeObserver === "undefined" ? null : new ResizeObserver(fit);
|
|
86
|
+
resize?.observe(box);
|
|
87
|
+
const seen =
|
|
88
|
+
near || typeof IntersectionObserver === "undefined"
|
|
89
|
+
? null
|
|
90
|
+
: new IntersectionObserver(
|
|
91
|
+
(entries) => {
|
|
92
|
+
if (entries.some((entry) => entry.isIntersecting)) setNear(true);
|
|
93
|
+
},
|
|
94
|
+
{ rootMargin: "200px" },
|
|
95
|
+
);
|
|
96
|
+
seen?.observe(box);
|
|
97
|
+
return () => {
|
|
98
|
+
resize?.disconnect();
|
|
99
|
+
seen?.disconnect();
|
|
100
|
+
};
|
|
101
|
+
}, [near]);
|
|
102
|
+
return (
|
|
103
|
+
<div ref={ref} className="emvb-template-preview" aria-hidden="true">
|
|
104
|
+
{near && (
|
|
105
|
+
<iframe
|
|
106
|
+
title={`${template.name} preview`}
|
|
107
|
+
tabIndex={-1}
|
|
108
|
+
sandbox="allow-same-origin"
|
|
109
|
+
srcDoc={templatePreviewDoc(template, design, currentScheme())}
|
|
110
|
+
style={{ transform: `scale(${scale})` }}
|
|
111
|
+
/>
|
|
112
|
+
)}
|
|
113
|
+
</div>
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Starter templates in the Add panel (W-1068): ready-made sections shipped with EmVB, drawn with
|
|
119
|
+
* the site's Site styles. Click or Enter inserts one where the selection says; drag drops it.
|
|
120
|
+
*/
|
|
121
|
+
export function TemplatesPanel({
|
|
122
|
+
design,
|
|
123
|
+
onInsert,
|
|
124
|
+
defaultQuery = "",
|
|
125
|
+
}: {
|
|
126
|
+
design: DesignSystem;
|
|
127
|
+
onInsert: (id: string) => void;
|
|
128
|
+
/** Test-only initial search string. */
|
|
129
|
+
defaultQuery?: string;
|
|
130
|
+
}) {
|
|
131
|
+
const [query, setQuery] = React.useState(defaultQuery);
|
|
132
|
+
const searchRef = React.useRef<HTMLInputElement>(null);
|
|
133
|
+
const shown = SECTION_TEMPLATES.filter((template) =>
|
|
134
|
+
matchesSearch(query, template.name, template.description, "template section"),
|
|
135
|
+
);
|
|
136
|
+
return (
|
|
137
|
+
<div className="emvb-panel-body" data-emvb-panel="templates">
|
|
138
|
+
<Input
|
|
139
|
+
aria-label="Search templates"
|
|
140
|
+
type="search"
|
|
141
|
+
className={FIELD}
|
|
142
|
+
ref={searchRef}
|
|
143
|
+
value={query}
|
|
144
|
+
onChange={(event) => setQuery(event.target.value)}
|
|
145
|
+
onKeyDown={(event) => {
|
|
146
|
+
if (isCancelEscape(event) && query) {
|
|
147
|
+
event.stopPropagation();
|
|
148
|
+
setQuery("");
|
|
149
|
+
}
|
|
150
|
+
}}
|
|
151
|
+
placeholder="Search templates…"
|
|
152
|
+
/>
|
|
153
|
+
<p className="emvb-helper">
|
|
154
|
+
Ready-made sections in your Site styles. Click or drag one onto the page; for a whole page,
|
|
155
|
+
pick a page template in New page.
|
|
156
|
+
</p>
|
|
157
|
+
{shown.length === 0 ? (
|
|
158
|
+
<div className="emvb-add-nomatch" data-emvb-add-nomatch="">
|
|
159
|
+
{/* oxlint-disable-next-line jsx-a11y/prefer-tag-over-role -- a block line, as in the Add panel */}
|
|
160
|
+
<p className="emvb-helper" role="status">
|
|
161
|
+
No templates match "{query.trim()}".
|
|
162
|
+
</p>
|
|
163
|
+
<Button
|
|
164
|
+
type="button"
|
|
165
|
+
variant="secondary"
|
|
166
|
+
className={BUTTON}
|
|
167
|
+
onClick={() => {
|
|
168
|
+
setQuery("");
|
|
169
|
+
searchRef.current?.focus();
|
|
170
|
+
}}
|
|
171
|
+
>
|
|
172
|
+
Clear search
|
|
173
|
+
</Button>
|
|
174
|
+
</div>
|
|
175
|
+
) : (
|
|
176
|
+
<ul className="emvb-template-list" aria-label="Section templates">
|
|
177
|
+
{shown.map((template) => (
|
|
178
|
+
<li key={template.id} className="emvb-template-tile">
|
|
179
|
+
<TemplatePreview template={template} design={design} />
|
|
180
|
+
<button
|
|
181
|
+
type="button"
|
|
182
|
+
className="emvb-template-insert"
|
|
183
|
+
data-emvb-template={template.id}
|
|
184
|
+
aria-describedby={`emvb-template-desc-${template.id}`}
|
|
185
|
+
draggable
|
|
186
|
+
onDragStart={(event) => {
|
|
187
|
+
const type = templateDragType(template.id);
|
|
188
|
+
event.dataTransfer.setData(NEW_ELEMENT_MIME, type);
|
|
189
|
+
event.dataTransfer.effectAllowed = "copy";
|
|
190
|
+
dragStash.new(type);
|
|
191
|
+
}}
|
|
192
|
+
onClick={() => onInsert(template.id)}
|
|
193
|
+
>
|
|
194
|
+
{template.name}
|
|
195
|
+
</button>
|
|
196
|
+
<p className="emvb-template-desc" id={`emvb-template-desc-${template.id}`}>
|
|
197
|
+
{template.description}
|
|
198
|
+
</p>
|
|
199
|
+
</li>
|
|
200
|
+
))}
|
|
201
|
+
</ul>
|
|
202
|
+
)}
|
|
203
|
+
</div>
|
|
204
|
+
);
|
|
205
|
+
}
|
|
@@ -94,6 +94,7 @@ export function TokenScales({
|
|
|
94
94
|
<span className="emvb-bind-label">{kind === "type" ? "Body size" : "Base gap"} (px)</span>
|
|
95
95
|
<Input
|
|
96
96
|
className={FIELD}
|
|
97
|
+
aria-label={`${kind === "type" ? "Body size" : "Base gap"} (px)`}
|
|
97
98
|
inputMode="decimal"
|
|
98
99
|
value={base}
|
|
99
100
|
data-emvb-tokens-base=""
|
|
@@ -132,6 +133,7 @@ export function TokenScales({
|
|
|
132
133
|
<span className="emvb-bind-label">On small screens (px)</span>
|
|
133
134
|
<Input
|
|
134
135
|
className={FIELD}
|
|
136
|
+
aria-label="On small screens (px)"
|
|
135
137
|
inputMode="decimal"
|
|
136
138
|
value={minBase}
|
|
137
139
|
data-emvb-tokens-min=""
|