@perkyzz/emvb 1.0.0 → 1.1.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 +9 -0
- package/package.json +2 -2
- package/src/admin/bulk-api.ts +67 -0
- package/src/admin/content-api.ts +10 -6
- package/src/admin/copy-rich-text.ts +119 -0
- package/src/admin/dialog-tab-wrap.ts +78 -0
- package/src/admin/editor/A11yCopilot.tsx +2 -0
- package/src/admin/editor/Editor.tsx +18 -6
- package/src/admin/editor/Timeline.tsx +6 -2
- package/src/admin/editor/TopBar.tsx +27 -7
- package/src/admin/editor/canvas/CanvasFrame.tsx +7 -2
- package/src/admin/editor/canvas/DeviceBar.tsx +22 -9
- package/src/admin/editor/canvas/canvas-scale.ts +3 -3
- package/src/admin/editor/canvas/use-canvas-session.ts +2 -2
- package/src/admin/editor/dnd/new-element.ts +22 -0
- package/src/admin/editor/editor-chrome.tsx +7 -5
- package/src/admin/editor/editor-commands.ts +10 -4
- package/src/admin/editor/editor-css.ts +2 -1
- package/src/admin/editor/panels/ElementPanel.tsx +29 -16
- package/src/admin/editor/panels/SettingsPanel.tsx +2 -2
- package/src/admin/editor/panels/settings/EffectsControls.tsx +79 -1
- package/src/admin/editor/panels/settings/IconControls.tsx +11 -0
- package/src/admin/editor/panels/settings/LengthRow.tsx +36 -3
- package/src/admin/editor/panels/settings/LoopItemBindControl.tsx +18 -0
- package/src/admin/editor/panels/settings/StyleRow.tsx +7 -0
- package/src/admin/editor/panels/settings/length-units.ts +15 -3
- package/src/admin/editor/panels/settings/style-sections.ts +1 -0
- package/src/admin/editor/panels/style-target.ts +17 -4
- package/src/admin/editor/section-templates.ts +26 -4
- package/src/admin/editor/store.ts +8 -2
- package/src/admin/editor/useEditorCommands.ts +7 -5
- package/src/admin/editor/useNodeActions.ts +4 -2
- package/src/admin/export-api.ts +221 -0
- package/src/admin/index.tsx +6 -1
- package/src/admin/pages/ExportDialog.tsx +395 -0
- package/src/admin/pages/PageList.tsx +67 -2
- package/src/admin/pages/ThemePartList.tsx +37 -1
- package/src/admin/pages/bulk.tsx +303 -0
- package/src/admin/search.ts +20 -0
- package/src/admin/theme-api.ts +4 -0
- package/src/admin/ui.ts +11 -2
- package/src/admin/widgets/CanvasField.tsx +8 -0
- package/src/admin/widgets/ConvertToRichText.tsx +136 -0
- package/src/admin/widgets/ExportEntryHtml.tsx +92 -0
- package/src/admin/widgets/convert-body.ts +73 -2
- package/src/astro/render.ts +6 -6
- package/src/astro/resolve-theme.ts +11 -7
- package/src/astro/tabs/runtime.ts +16 -6
- package/src/constants.ts +1 -1
- package/src/core/a11y/audit.ts +2 -1
- package/src/core/contract.ts +22 -2
- package/src/core/css/generate.ts +83 -21
- package/src/core/css/scope.ts +10 -2
- package/src/core/css/trace.ts +33 -8
- package/src/core/design/classes.ts +25 -5
- package/src/core/design/devices.ts +78 -2
- package/src/core/design/variables.ts +14 -1
- package/src/core/export/runtimes.generated.ts +9 -0
- package/src/core/export/site.ts +562 -0
- package/src/core/export/zip.ts +95 -0
- package/src/core/history/diff.ts +25 -0
- package/src/core/import/elementor/atomic.ts +22 -9
- package/src/core/import/elementor/index.ts +22 -4
- package/src/core/import/elementor/style.ts +21 -1
- package/src/core/index.ts +14 -0
- package/src/core/json-schema.ts +8 -1
- package/src/core/perf/meter.ts +37 -19
- package/src/core/portable-text-export.ts +243 -0
- package/src/core/public-attributes.ts +30 -0
- package/src/core/render/index.ts +88 -9
- package/src/core/render/tabs.ts +18 -11
- package/src/core/sanitize/css.ts +26 -0
- package/src/core/schema/design.ts +2 -2
- package/src/core/schema/layout.ts +11 -3
- package/src/core/schema/style.ts +47 -0
- package/src/core/search-text.ts +70 -0
- package/src/core/theme/float.ts +1 -0
- package/src/core/theme/popup-rules.ts +16 -0
- package/src/mcp/read.ts +2 -3
- package/src/server/icon-routes.ts +52 -12
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
import { Button, Checkbox, Dialog, Loader } from "@cloudflare/kumo";
|
|
2
|
+
import {
|
|
3
|
+
ArrowCounterClockwiseIcon,
|
|
4
|
+
DownloadSimpleIcon,
|
|
5
|
+
TrashIcon,
|
|
6
|
+
UploadSimpleIcon,
|
|
7
|
+
} from "@phosphor-icons/react";
|
|
8
|
+
import * as React from "react";
|
|
9
|
+
import type { Fetcher } from "../api.ts";
|
|
10
|
+
import { publishMany, restoreMany, trashMany, type BulkResult } from "../bulk-api.ts";
|
|
11
|
+
import { DialogCloseButton } from "../editor/DialogCloseButton.tsx";
|
|
12
|
+
import { BUTTON, SOLID_DESTRUCTIVE, UI_CSS } from "../ui.ts";
|
|
13
|
+
|
|
14
|
+
const plural = (n: number, one: string, many: string) => `${n} ${n === 1 ? one : many}`;
|
|
15
|
+
|
|
16
|
+
/** W-978: which rows are ticked, kept to the rows that still exist. */
|
|
17
|
+
export function useSelection(ids: readonly string[]) {
|
|
18
|
+
const [selected, setSelected] = React.useState<ReadonlySet<string>>(new Set());
|
|
19
|
+
const key = ids.join(" ");
|
|
20
|
+
React.useEffect(() => {
|
|
21
|
+
setSelected((current) => {
|
|
22
|
+
const kept = new Set([...current].filter((id) => ids.includes(id)));
|
|
23
|
+
return kept.size === current.size ? current : kept;
|
|
24
|
+
});
|
|
25
|
+
// `key` stands for `ids`, which is a new array on every render.
|
|
26
|
+
// oxlint-disable-next-line react-hooks/exhaustive-deps
|
|
27
|
+
}, [key]);
|
|
28
|
+
const toggle = (id: string, on: boolean) =>
|
|
29
|
+
setSelected((current) => {
|
|
30
|
+
const next = new Set(current);
|
|
31
|
+
if (on) next.add(id);
|
|
32
|
+
else next.delete(id);
|
|
33
|
+
return next;
|
|
34
|
+
});
|
|
35
|
+
const setAll = (shown: readonly string[], on: boolean) =>
|
|
36
|
+
setSelected((current) => {
|
|
37
|
+
const next = new Set(current);
|
|
38
|
+
for (const id of shown)
|
|
39
|
+
if (on) next.add(id);
|
|
40
|
+
else next.delete(id);
|
|
41
|
+
return next;
|
|
42
|
+
});
|
|
43
|
+
return { selected, toggle, setAll, clear: () => setSelected(new Set()) };
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** The header cell that ticks every row shown. */
|
|
47
|
+
export function SelectAll({
|
|
48
|
+
shown,
|
|
49
|
+
selection,
|
|
50
|
+
noun,
|
|
51
|
+
}: {
|
|
52
|
+
shown: readonly string[];
|
|
53
|
+
selection: ReturnType<typeof useSelection>;
|
|
54
|
+
noun: string;
|
|
55
|
+
}) {
|
|
56
|
+
const ticked = shown.filter((id) => selection.selected.has(id)).length;
|
|
57
|
+
return (
|
|
58
|
+
<Checkbox
|
|
59
|
+
aria-label={`Select all ${noun} shown`}
|
|
60
|
+
checked={shown.length > 0 && ticked === shown.length}
|
|
61
|
+
indeterminate={ticked > 0 && ticked < shown.length}
|
|
62
|
+
onCheckedChange={(on: boolean) => selection.setAll(shown, on)}
|
|
63
|
+
data-emvb-select-all=""
|
|
64
|
+
/>
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** A row's tick box, named after the row. */
|
|
69
|
+
export function SelectRow({
|
|
70
|
+
id,
|
|
71
|
+
title,
|
|
72
|
+
selection,
|
|
73
|
+
}: {
|
|
74
|
+
id: string;
|
|
75
|
+
title: string;
|
|
76
|
+
selection: ReturnType<typeof useSelection>;
|
|
77
|
+
}) {
|
|
78
|
+
return (
|
|
79
|
+
<Checkbox
|
|
80
|
+
aria-label={`Select ${title}`}
|
|
81
|
+
checked={selection.selected.has(id)}
|
|
82
|
+
onCheckedChange={(on: boolean) => selection.toggle(id, on)}
|
|
83
|
+
data-emvb-select-row={id}
|
|
84
|
+
/>
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
type BulkState =
|
|
89
|
+
| { kind: "idle" }
|
|
90
|
+
| { kind: "busy"; what: "publish" | "delete" | "restore" }
|
|
91
|
+
| { kind: "done"; text: string; restorable?: string[]; error?: boolean };
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* W-978: Publish, Delete (to EmDash's trash, with Restore) and, on Pages, Export for the ticked
|
|
95
|
+
* rows. Each item is its own request; one that fails is named and the rest go on.
|
|
96
|
+
*/
|
|
97
|
+
export function BulkBar({
|
|
98
|
+
fetcher,
|
|
99
|
+
collection,
|
|
100
|
+
selection,
|
|
101
|
+
titles,
|
|
102
|
+
noun,
|
|
103
|
+
nouns,
|
|
104
|
+
onChanged,
|
|
105
|
+
onExport,
|
|
106
|
+
deleteNote,
|
|
107
|
+
usage,
|
|
108
|
+
}: {
|
|
109
|
+
fetcher: Fetcher;
|
|
110
|
+
collection: string;
|
|
111
|
+
selection: ReturnType<typeof useSelection>;
|
|
112
|
+
/** Titles by id, for the confirm and the result. */
|
|
113
|
+
titles: ReadonlyMap<string, string>;
|
|
114
|
+
noun: string;
|
|
115
|
+
nouns: string;
|
|
116
|
+
/** Reloads the list after a change. */
|
|
117
|
+
onChanged: () => void;
|
|
118
|
+
onExport?: (ids: string[]) => void;
|
|
119
|
+
/** What else the delete confirm should say. */
|
|
120
|
+
deleteNote?: string;
|
|
121
|
+
/** W-980: where the chosen items are still used, by id, for the delete confirm. */
|
|
122
|
+
usage?: (ids: string[]) => Promise<Map<string, string[]>>;
|
|
123
|
+
}) {
|
|
124
|
+
const [inUse, setInUse] = React.useState<Map<string, string[]> | null>(null);
|
|
125
|
+
const [state, setState] = React.useState<BulkState>({ kind: "idle" });
|
|
126
|
+
const [confirming, setConfirming] = React.useState(false);
|
|
127
|
+
const ids = [...selection.selected];
|
|
128
|
+
const busy = state.kind === "busy";
|
|
129
|
+
const failures = (result: BulkResult) =>
|
|
130
|
+
result.failed.map((f) => `${titles.get(f.id) ?? f.id} (${f.message})`).join("; ");
|
|
131
|
+
|
|
132
|
+
const run = async (what: "publish" | "delete") => {
|
|
133
|
+
setConfirming(false);
|
|
134
|
+
setState({ kind: "busy", what });
|
|
135
|
+
const result = await (what === "publish" ? publishMany : trashMany)(fetcher, collection, ids);
|
|
136
|
+
const verb = what === "publish" ? "Published" : "Moved to the trash:";
|
|
137
|
+
const parts = [
|
|
138
|
+
result.done.length > 0 ? `${verb} ${plural(result.done.length, noun, nouns)}.` : "",
|
|
139
|
+
result.failed.length > 0
|
|
140
|
+
? `Not ${what === "publish" ? "published" : "deleted"}: ${failures(result)}.`
|
|
141
|
+
: "",
|
|
142
|
+
].filter(Boolean);
|
|
143
|
+
setState({
|
|
144
|
+
kind: "done",
|
|
145
|
+
text: parts.join(" "),
|
|
146
|
+
...(what === "delete" && result.done.length > 0 ? { restorable: result.done } : {}),
|
|
147
|
+
...(result.failed.length > 0 ? { error: true } : {}),
|
|
148
|
+
});
|
|
149
|
+
selection.clear();
|
|
150
|
+
if (result.done.length > 0) onChanged();
|
|
151
|
+
};
|
|
152
|
+
const restore = async (restorable: string[]) => {
|
|
153
|
+
setState({ kind: "busy", what: "restore" });
|
|
154
|
+
const result = await restoreMany(fetcher, collection, restorable);
|
|
155
|
+
setState({
|
|
156
|
+
kind: "done",
|
|
157
|
+
text: [
|
|
158
|
+
result.done.length > 0 ? `Restored ${plural(result.done.length, noun, nouns)}.` : "",
|
|
159
|
+
result.failed.length > 0 ? `Not restored: ${failures(result)}.` : "",
|
|
160
|
+
]
|
|
161
|
+
.filter(Boolean)
|
|
162
|
+
.join(" "),
|
|
163
|
+
...(result.failed.length > 0 ? { error: true } : {}),
|
|
164
|
+
});
|
|
165
|
+
if (result.done.length > 0) onChanged();
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
if (ids.length === 0 && state.kind === "idle") return null;
|
|
169
|
+
return (
|
|
170
|
+
<div
|
|
171
|
+
className="emvb-bulk-bar"
|
|
172
|
+
role="region"
|
|
173
|
+
aria-label={`Selected ${nouns}`}
|
|
174
|
+
data-emvb-bulk-bar=""
|
|
175
|
+
>
|
|
176
|
+
{ids.length > 0 && (
|
|
177
|
+
<>
|
|
178
|
+
<span className="emvb-bulk-count" aria-live="polite">
|
|
179
|
+
{plural(ids.length, noun, nouns)} selected
|
|
180
|
+
</span>
|
|
181
|
+
<Button
|
|
182
|
+
variant="secondary"
|
|
183
|
+
className={BUTTON}
|
|
184
|
+
icon={
|
|
185
|
+
state.kind === "busy" && state.what === "publish" ? (
|
|
186
|
+
<Loader size={14} />
|
|
187
|
+
) : (
|
|
188
|
+
<UploadSimpleIcon aria-hidden="true" />
|
|
189
|
+
)
|
|
190
|
+
}
|
|
191
|
+
aria-disabled={busy}
|
|
192
|
+
onClick={() => !busy && void run("publish")}
|
|
193
|
+
data-emvb-bulk="publish"
|
|
194
|
+
>
|
|
195
|
+
Publish
|
|
196
|
+
</Button>
|
|
197
|
+
{onExport && (
|
|
198
|
+
<Button
|
|
199
|
+
variant="secondary"
|
|
200
|
+
className={BUTTON}
|
|
201
|
+
icon={<DownloadSimpleIcon aria-hidden="true" />}
|
|
202
|
+
aria-disabled={busy}
|
|
203
|
+
onClick={() => !busy && onExport(ids)}
|
|
204
|
+
data-emvb-bulk="export"
|
|
205
|
+
>
|
|
206
|
+
Export
|
|
207
|
+
</Button>
|
|
208
|
+
)}
|
|
209
|
+
<Button
|
|
210
|
+
variant="secondary"
|
|
211
|
+
className={BUTTON}
|
|
212
|
+
icon={
|
|
213
|
+
state.kind === "busy" && state.what === "delete" ? (
|
|
214
|
+
<Loader size={14} />
|
|
215
|
+
) : (
|
|
216
|
+
<TrashIcon aria-hidden="true" />
|
|
217
|
+
)
|
|
218
|
+
}
|
|
219
|
+
aria-disabled={busy}
|
|
220
|
+
onClick={() => {
|
|
221
|
+
if (busy) return;
|
|
222
|
+
setInUse(null);
|
|
223
|
+
setConfirming(true);
|
|
224
|
+
usage?.(ids).then(setInUse, () => setInUse(new Map()));
|
|
225
|
+
}}
|
|
226
|
+
data-emvb-bulk="delete"
|
|
227
|
+
>
|
|
228
|
+
Delete
|
|
229
|
+
</Button>
|
|
230
|
+
<Button variant="ghost" className={BUTTON} onClick={selection.clear} aria-disabled={busy}>
|
|
231
|
+
Clear selection
|
|
232
|
+
</Button>
|
|
233
|
+
</>
|
|
234
|
+
)}
|
|
235
|
+
{state.kind !== "idle" && (
|
|
236
|
+
<p
|
|
237
|
+
className={
|
|
238
|
+
state.kind === "done" && state.error ? "emvb-helper emvb-danger-text" : "emvb-helper"
|
|
239
|
+
}
|
|
240
|
+
role="status"
|
|
241
|
+
data-emvb-bulk-status=""
|
|
242
|
+
>
|
|
243
|
+
{state.kind === "busy"
|
|
244
|
+
? state.what === "publish"
|
|
245
|
+
? "Publishing…"
|
|
246
|
+
: state.what === "delete"
|
|
247
|
+
? "Moving to the trash…"
|
|
248
|
+
: "Restoring…"
|
|
249
|
+
: state.text}
|
|
250
|
+
{state.kind === "done" && state.restorable && (
|
|
251
|
+
<Button
|
|
252
|
+
variant="ghost"
|
|
253
|
+
className={BUTTON}
|
|
254
|
+
icon={<ArrowCounterClockwiseIcon aria-hidden="true" />}
|
|
255
|
+
onClick={() => state.restorable && void restore(state.restorable)}
|
|
256
|
+
data-emvb-bulk="restore"
|
|
257
|
+
>
|
|
258
|
+
Restore
|
|
259
|
+
</Button>
|
|
260
|
+
)}
|
|
261
|
+
</p>
|
|
262
|
+
)}
|
|
263
|
+
<Dialog.Root open={confirming} onOpenChange={setConfirming}>
|
|
264
|
+
<Dialog size="base" className="p-6">
|
|
265
|
+
<style>{UI_CSS}</style>
|
|
266
|
+
<div className="emvb-dialog" data-emvb-dialog="bulk-delete">
|
|
267
|
+
<Dialog.Title>Delete {plural(ids.length, noun, nouns)}?</Dialog.Title>
|
|
268
|
+
<Dialog.Description>
|
|
269
|
+
{ids.length <= 5
|
|
270
|
+
? `${ids.map((id) => titles.get(id) ?? id).join(", ")} ${ids.length === 1 ? "goes" : "go"} to EmDash's trash and ${ids.length === 1 ? "leaves" : "leave"} the site.`
|
|
271
|
+
: `They go to EmDash's trash and leave the site.`}{" "}
|
|
272
|
+
You can restore them right after, or later from the trash.
|
|
273
|
+
</Dialog.Description>
|
|
274
|
+
{inUse && inUse.size > 0 && (
|
|
275
|
+
<ul className="emvb-helper emvb-danger-text" data-emvb-bulk-in-use="">
|
|
276
|
+
{[...inUse].map(([id, where]) => (
|
|
277
|
+
<li key={id}>
|
|
278
|
+
{titles.get(id) ?? id} is used on {where.slice(0, 3).join(", ")}
|
|
279
|
+
{where.length > 3 ? ` and ${where.length - 3} more` : ""}; it will show nothing
|
|
280
|
+
there.
|
|
281
|
+
</li>
|
|
282
|
+
))}
|
|
283
|
+
</ul>
|
|
284
|
+
)}
|
|
285
|
+
{deleteNote && <p className="emvb-helper">{deleteNote}</p>}
|
|
286
|
+
<div className="emvb-dialog-actions">
|
|
287
|
+
<DialogCloseButton>Cancel</DialogCloseButton>
|
|
288
|
+
<Button
|
|
289
|
+
variant="destructive"
|
|
290
|
+
className={BUTTON}
|
|
291
|
+
style={SOLID_DESTRUCTIVE}
|
|
292
|
+
onClick={() => void run("delete")}
|
|
293
|
+
data-emvb-bulk-confirm=""
|
|
294
|
+
>
|
|
295
|
+
Delete {plural(ids.length, noun, nouns)}
|
|
296
|
+
</Button>
|
|
297
|
+
</div>
|
|
298
|
+
</div>
|
|
299
|
+
</Dialog>
|
|
300
|
+
</Dialog.Root>
|
|
301
|
+
</div>
|
|
302
|
+
);
|
|
303
|
+
}
|
package/src/admin/search.ts
CHANGED
|
@@ -13,3 +13,23 @@ export function matchesSearch(query: string, ...fields: string[]): boolean {
|
|
|
13
13
|
.filter(Boolean)
|
|
14
14
|
.every((word) => haystack.includes(word));
|
|
15
15
|
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* W-978: when `query` matches an item only through its content, a short piece of that content
|
|
19
|
+
* around the first word, so the list can say why the item is shown. Undefined otherwise.
|
|
20
|
+
*/
|
|
21
|
+
export function contentSnippet(
|
|
22
|
+
query: string,
|
|
23
|
+
content: string | undefined,
|
|
24
|
+
...fields: string[]
|
|
25
|
+
): string | undefined {
|
|
26
|
+
if (!content || !query.trim() || matchesSearch(query, ...fields)) return undefined;
|
|
27
|
+
const words = fold(query).split(/\s+/).filter(Boolean);
|
|
28
|
+
const folded = fold(content);
|
|
29
|
+
const at = Math.min(...words.map((w) => folded.indexOf(w)).filter((i) => i >= 0));
|
|
30
|
+
if (!Number.isFinite(at)) return undefined;
|
|
31
|
+
// Folding can change lengths (ß → ss); close enough for a preview.
|
|
32
|
+
const start = Math.max(0, at - 30);
|
|
33
|
+
const end = Math.min(content.length, at + 60);
|
|
34
|
+
return `${start > 0 ? "…" : ""}${content.slice(start, end).trim()}${end < content.length ? "…" : ""}`;
|
|
35
|
+
}
|
package/src/admin/theme-api.ts
CHANGED
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
parseThemePartType,
|
|
7
7
|
starterLayout,
|
|
8
8
|
THEME_PART_TYPE_LABELS,
|
|
9
|
+
layoutSearchText,
|
|
9
10
|
validateLayout,
|
|
10
11
|
type ConditionsDoc,
|
|
11
12
|
type FloatSettings,
|
|
@@ -28,6 +29,8 @@ export type ThemePartSummary = {
|
|
|
28
29
|
status: string;
|
|
29
30
|
updatedAt: string;
|
|
30
31
|
conditionsSummary: string;
|
|
32
|
+
/** W-978: the layout's words, for searching by content. */
|
|
33
|
+
text?: string;
|
|
31
34
|
};
|
|
32
35
|
|
|
33
36
|
export type ThemePartDraft = {
|
|
@@ -136,6 +139,7 @@ export async function listThemeParts(fetcher: Fetcher): Promise<ThemePartSummary
|
|
|
136
139
|
// UX-061: reusable parts never match a location, so say where they're used instead.
|
|
137
140
|
conditionsSummary:
|
|
138
141
|
ITEM_PART_USE_SHORT[partTypeOf(item)] ?? summarizeConditions(item.data?.["conditions"]),
|
|
142
|
+
text: layoutSearchText(item.data?.["layout"]),
|
|
139
143
|
}));
|
|
140
144
|
}
|
|
141
145
|
|
package/src/admin/ui.ts
CHANGED
|
@@ -82,6 +82,11 @@ export const UI_CSS = `
|
|
|
82
82
|
.emvb-list-loading .skeleton-line { background: var(--color-kumo-tint); }
|
|
83
83
|
.emvb-list-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
|
|
84
84
|
.emvb-list-search { max-width: 320px; margin: 12px 0; }
|
|
85
|
+
.emvb-bulk-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 0 0 12px; }
|
|
86
|
+
.emvb-bulk-count { font-weight: 600; margin-inline-end: 4px; }
|
|
87
|
+
.emvb-bulk-bar [data-emvb-bulk-status] { flex-basis: 100%; margin: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
|
|
88
|
+
.emvb-surface-card[data-emvb-list] .emvb-row-select { width: 48px; padding-inline-end: 0; }
|
|
89
|
+
.emvb-row-found { margin-top: 2px; font-size: 12px; color: var(--text-color-kumo-subtle, inherit); overflow-wrap: anywhere; }
|
|
85
90
|
.emvb-page-title { margin: 0; font-size: 24px; line-height: 1.25; font-weight: 600; color: var(--text-color-kumo-default); }
|
|
86
91
|
.emvb-row-title { color: var(--text-color-kumo-default); font-size: 14px; line-height: 20px; font-weight: 600; text-decoration: none; }
|
|
87
92
|
.emvb-row-title:hover { text-decoration: underline; text-underline-offset: 2px; }
|
|
@@ -91,8 +96,9 @@ export const UI_CSS = `
|
|
|
91
96
|
.emvb-row-title, .emvb-row-slug { overflow-wrap: anywhere; }
|
|
92
97
|
/* UX-018: on narrow admin widths the short columns keep one line and the title keeps a readable
|
|
93
98
|
width; the card scrolls sideways before anything breaks mid-word or mid-date. */
|
|
94
|
-
|
|
95
|
-
.emvb-surface-card[data-emvb-list] td:first-child {
|
|
99
|
+
/* W-978: the title column wraps and keeps a minimum width; it follows the tick-box column. */
|
|
100
|
+
.emvb-surface-card[data-emvb-list] :is(th, td):not(:first-child):not(:has(> .emvb-row-title)) { white-space: nowrap; }
|
|
101
|
+
.emvb-surface-card[data-emvb-list] td:has(> .emvb-row-title) { min-width: 180px; }
|
|
96
102
|
.emvb-tabular { font-variant-numeric: tabular-nums; color: var(--text-color-kumo-subtle); font-size: 13px; }
|
|
97
103
|
|
|
98
104
|
/* Elevated EmVB-owned card chrome (lists, empty/setup shells) — not host sidebar/header */
|
|
@@ -153,6 +159,8 @@ export const UI_CSS = `
|
|
|
153
159
|
.emvb-surface-card[data-emvb-list] tbody tr:hover { background: var(--color-kumo-tint); }
|
|
154
160
|
.emvb-surface-card[data-emvb-list] tbody tr:hover .emvb-row-title { text-decoration: underline; text-underline-offset: 2px; }
|
|
155
161
|
.emvb-surface-card[data-emvb-list] .emvb-row-title::after { content: ""; position: absolute; inset: 0; }
|
|
162
|
+
/* W-978: the row's tick box sits above the stretched title link, so it can be clicked. */
|
|
163
|
+
.emvb-surface-card[data-emvb-list] .emvb-row-select > * { position: relative; z-index: 1; }
|
|
156
164
|
.emvb-surface-card .emvb-empty-shell,
|
|
157
165
|
.emvb-empty-shell {
|
|
158
166
|
display: flex;
|
|
@@ -239,6 +247,7 @@ export const UI_CSS = `
|
|
|
239
247
|
.emvb-create-fields { display: flex; flex-direction: column; gap: 10px; min-width: 0; margin: 0; padding: 0; border: 0; }
|
|
240
248
|
.emvb-create-status { min-height: 18px; }
|
|
241
249
|
/* W-945: Import from Elementor. The JSON box keeps its rows; the report scrolls on its own. */
|
|
250
|
+
.emvb-export-fields { display: flex; flex-direction: column; gap: 12px; margin-top: 12px; }
|
|
242
251
|
.emvb-import-source { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
|
|
243
252
|
.emvb-import-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; min-width: 0; }
|
|
244
253
|
.emvb-import-label { font-size: 14px; font-weight: 500; color: var(--text-color-kumo-default); }
|
|
@@ -11,6 +11,8 @@ import { EditorHostContext, type EditorHost } from "../editor/host.ts";
|
|
|
11
11
|
import { layerPreview } from "../editor/panels/LayersPanel.tsx";
|
|
12
12
|
import { BUTTON, SOLID_PRIMARY } from "../ui.ts";
|
|
13
13
|
import { convertEntryBody, hostEntryFromLocation } from "./convert-body.ts";
|
|
14
|
+
import { ConvertToRichText } from "./ConvertToRichText.tsx";
|
|
15
|
+
import { ExportEntryHtml } from "./ExportEntryHtml.tsx";
|
|
14
16
|
import { createFieldFetcher, FIELD_ENTRY_ID, readFieldLayout } from "./field-fetcher.ts";
|
|
15
17
|
import type { FieldWidgetProps } from "./LayoutField.tsx";
|
|
16
18
|
|
|
@@ -178,6 +180,12 @@ export function CanvasField({
|
|
|
178
180
|
Convert to EmVB
|
|
179
181
|
</Button>
|
|
180
182
|
)}
|
|
183
|
+
{entry && layout && !unreadable && (layout.root.children ?? []).length > 0 && (
|
|
184
|
+
<ConvertToRichText fetcher={fetcher} entry={entry} layout={layout} />
|
|
185
|
+
)}
|
|
186
|
+
{entry && layout && !unreadable && (layout.root.children ?? []).length > 0 && (
|
|
187
|
+
<ExportEntryHtml fetcher={fetcher} entry={entry} />
|
|
188
|
+
)}
|
|
181
189
|
</div>
|
|
182
190
|
)}
|
|
183
191
|
{(convert.state === "done" || convert.state === "error") && (
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { Button, Dialog, Loader } from "@cloudflare/kumo";
|
|
2
|
+
import { TextAlignLeftIcon } from "@phosphor-icons/react";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import type { Layout } from "../../core/index.ts";
|
|
5
|
+
import type { Fetcher } from "../api.ts";
|
|
6
|
+
import { DialogCloseButton } from "../editor/DialogCloseButton.tsx";
|
|
7
|
+
import { BUTTON, SOLID_DESTRUCTIVE, UI_CSS } from "../ui.ts";
|
|
8
|
+
import { planRichText, writeRichText, type RichTextPlan } from "./convert-body.ts";
|
|
9
|
+
|
|
10
|
+
type Plan = Extract<RichTextPlan, { ok: true }>;
|
|
11
|
+
|
|
12
|
+
const plural = (n: number, one: string) => `${n} ${n === 1 ? one : `${one}s`}`;
|
|
13
|
+
|
|
14
|
+
/** "form, 2 icons", for what a conversion leaves out. */
|
|
15
|
+
export function leftOutText(skipped: Record<string, number>): string {
|
|
16
|
+
return Object.entries(skipped)
|
|
17
|
+
.map(([type, n]) => (n === 1 ? type : `${n} ${type}s`))
|
|
18
|
+
.join(", ");
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* W-963: Convert to rich text, the way out of a canvas field. The layout's words, headings, lists,
|
|
23
|
+
* links and images replace the entry's rich-text field, after a confirm that says what is kept and
|
|
24
|
+
* what is left out. The layout itself is untouched; the entry reloads so its form shows the result.
|
|
25
|
+
*/
|
|
26
|
+
export function ConvertToRichText({
|
|
27
|
+
fetcher,
|
|
28
|
+
entry,
|
|
29
|
+
layout,
|
|
30
|
+
reload = () => window.location.reload(),
|
|
31
|
+
}: {
|
|
32
|
+
fetcher: Fetcher;
|
|
33
|
+
entry: { collection: string; id: string };
|
|
34
|
+
layout: Layout;
|
|
35
|
+
reload?: () => void;
|
|
36
|
+
}) {
|
|
37
|
+
const [state, setState] = React.useState<
|
|
38
|
+
| { kind: "idle" }
|
|
39
|
+
| { kind: "planning" }
|
|
40
|
+
| { kind: "confirm" | "writing"; plan: Plan }
|
|
41
|
+
| { kind: "error"; message: string }
|
|
42
|
+
>({ kind: "idle" });
|
|
43
|
+
|
|
44
|
+
const start = async () => {
|
|
45
|
+
setState({ kind: "planning" });
|
|
46
|
+
try {
|
|
47
|
+
const plan = await planRichText(fetcher, entry, layout);
|
|
48
|
+
setState(plan.ok ? { kind: "confirm", plan } : { kind: "error", message: plan.message });
|
|
49
|
+
} catch {
|
|
50
|
+
setState({ kind: "error", message: "The entry couldn't be read. Try again." });
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
const write = async (plan: Plan) => {
|
|
54
|
+
setState({ kind: "writing", plan });
|
|
55
|
+
try {
|
|
56
|
+
await writeRichText(fetcher, entry, plan);
|
|
57
|
+
reload();
|
|
58
|
+
} catch (error) {
|
|
59
|
+
setState({
|
|
60
|
+
kind: "error",
|
|
61
|
+
message: `The ${plan.field} field wasn't changed: ${error instanceof Error ? error.message : String(error)}`,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
const plan = state.kind === "confirm" || state.kind === "writing" ? state.plan : null;
|
|
66
|
+
const writing = state.kind === "writing";
|
|
67
|
+
const leftOut = plan ? leftOutText(plan.skipped) : "";
|
|
68
|
+
|
|
69
|
+
return (
|
|
70
|
+
<>
|
|
71
|
+
<Button
|
|
72
|
+
variant="secondary"
|
|
73
|
+
className={BUTTON}
|
|
74
|
+
icon={
|
|
75
|
+
state.kind === "planning" ? (
|
|
76
|
+
<Loader size={14} />
|
|
77
|
+
) : (
|
|
78
|
+
<TextAlignLeftIcon aria-hidden="true" />
|
|
79
|
+
)
|
|
80
|
+
}
|
|
81
|
+
disabled={state.kind === "planning"}
|
|
82
|
+
onClick={() => void start()}
|
|
83
|
+
data-emvb-convert-rich-text=""
|
|
84
|
+
>
|
|
85
|
+
Convert to rich text
|
|
86
|
+
</Button>
|
|
87
|
+
{state.kind === "error" && (
|
|
88
|
+
<p className="emvb-canvas-convert-note" role="alert" data-emvb-convert="error">
|
|
89
|
+
{state.message}
|
|
90
|
+
</p>
|
|
91
|
+
)}
|
|
92
|
+
<Dialog.Root
|
|
93
|
+
open={plan !== null}
|
|
94
|
+
onOpenChange={(open) => {
|
|
95
|
+
if (!open && !writing) setState({ kind: "idle" });
|
|
96
|
+
}}
|
|
97
|
+
>
|
|
98
|
+
<Dialog size="base" className="p-6">
|
|
99
|
+
<style>{UI_CSS}</style>
|
|
100
|
+
<div data-emvb-dialog="convert-rich-text" className="emvb-dialog">
|
|
101
|
+
<Dialog.Title>Copy this layout into {plan?.field}?</Dialog.Title>
|
|
102
|
+
<Dialog.Description>
|
|
103
|
+
{plan &&
|
|
104
|
+
`${plural(plan.body.length, "block")} of words, headings, lists, links and images go into the entry's ${plan.field} field${plan.replaces ? ", replacing what it holds now" : ""}. The design (colours, columns, spacing) doesn't come across.`}
|
|
105
|
+
</Dialog.Description>
|
|
106
|
+
{plan && leftOut && (
|
|
107
|
+
<p className="emvb-helper" data-emvb-left-out="">
|
|
108
|
+
Left out: {leftOut}.
|
|
109
|
+
</p>
|
|
110
|
+
)}
|
|
111
|
+
<p className="emvb-helper">
|
|
112
|
+
The layout stays as it is. Save your other changes to this entry first: it reloads
|
|
113
|
+
afterwards. To show the rich text on your site, clear the layout and save the entry.
|
|
114
|
+
</p>
|
|
115
|
+
<div className="emvb-dialog-actions">
|
|
116
|
+
<DialogCloseButton>Cancel</DialogCloseButton>
|
|
117
|
+
<Button
|
|
118
|
+
variant={plan?.replaces ? "destructive" : "primary"}
|
|
119
|
+
className={BUTTON}
|
|
120
|
+
{...(plan?.replaces ? { style: SOLID_DESTRUCTIVE } : {})}
|
|
121
|
+
icon={writing ? <Loader size={14} /> : undefined}
|
|
122
|
+
aria-disabled={writing}
|
|
123
|
+
aria-busy={writing}
|
|
124
|
+
onClick={() => {
|
|
125
|
+
if (plan && !writing) void write(plan);
|
|
126
|
+
}}
|
|
127
|
+
>
|
|
128
|
+
{plan?.replaces ? `Replace ${plan.field}` : `Copy into ${plan?.field ?? "field"}`}
|
|
129
|
+
</Button>
|
|
130
|
+
</div>
|
|
131
|
+
</div>
|
|
132
|
+
</Dialog>
|
|
133
|
+
</Dialog.Root>
|
|
134
|
+
</>
|
|
135
|
+
);
|
|
136
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { Button, Loader } from "@cloudflare/kumo";
|
|
2
|
+
import { DownloadSimpleIcon } from "@phosphor-icons/react";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import type { Fetcher } from "../api.ts";
|
|
5
|
+
import { canvasSources, exportSite } from "../export-api.ts";
|
|
6
|
+
import { downloadBlob } from "../image-editor/flatten.ts";
|
|
7
|
+
import { BUTTON } from "../ui.ts";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* W-977: Export HTML on an entry's Canvas card. Downloads the entry's published layout as a zip
|
|
11
|
+
* of HTML and CSS, with the header, footer, popups and floats it shows, the same as Export pages
|
|
12
|
+
* does for EmVB pages.
|
|
13
|
+
*/
|
|
14
|
+
export function ExportEntryHtml({
|
|
15
|
+
fetcher,
|
|
16
|
+
entry,
|
|
17
|
+
origin = window.location.origin,
|
|
18
|
+
}: {
|
|
19
|
+
fetcher: Fetcher;
|
|
20
|
+
entry: { collection: string; id: string };
|
|
21
|
+
origin?: string;
|
|
22
|
+
}) {
|
|
23
|
+
const [state, setState] = React.useState<
|
|
24
|
+
{ kind: "idle" } | { kind: "busy" } | { kind: "done" | "error"; message: string }
|
|
25
|
+
>({ kind: "idle" });
|
|
26
|
+
const run = async () => {
|
|
27
|
+
setState({ kind: "busy" });
|
|
28
|
+
try {
|
|
29
|
+
const source = (await canvasSources(fetcher)).find((s) => s.collection === entry.collection);
|
|
30
|
+
if (!source) {
|
|
31
|
+
setState({ kind: "error", message: "This collection has no EmVB layout field to export." });
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const date = new Date().toISOString().slice(0, 10);
|
|
35
|
+
const result = await exportSite(fetcher, {
|
|
36
|
+
source,
|
|
37
|
+
onlyPageId: entry.id,
|
|
38
|
+
copyMedia: true,
|
|
39
|
+
origin,
|
|
40
|
+
date,
|
|
41
|
+
});
|
|
42
|
+
const page = result.site.report.pages[0];
|
|
43
|
+
if (!page) {
|
|
44
|
+
setState({
|
|
45
|
+
kind: "error",
|
|
46
|
+
message:
|
|
47
|
+
"Only the published version is exported, and this entry has no published layout yet. Publish it first.",
|
|
48
|
+
});
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
downloadBlob(
|
|
52
|
+
new Blob([result.zip as Uint8Array<ArrayBuffer>], { type: "application/zip" }),
|
|
53
|
+
`emvb-export-${page.path.replace(/\/$/, "")}-${date}.zip`,
|
|
54
|
+
);
|
|
55
|
+
setState({
|
|
56
|
+
kind: "done",
|
|
57
|
+
message:
|
|
58
|
+
"Downloaded the published layout as HTML and CSS. EXPORT-REPORT.md in the zip lists what only works on the live site.",
|
|
59
|
+
});
|
|
60
|
+
} catch (error) {
|
|
61
|
+
setState({
|
|
62
|
+
kind: "error",
|
|
63
|
+
message: `The export didn't finish: ${error instanceof Error ? error.message : String(error)}. Try again.`,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
return (
|
|
68
|
+
<>
|
|
69
|
+
<Button
|
|
70
|
+
variant="secondary"
|
|
71
|
+
className={BUTTON}
|
|
72
|
+
icon={
|
|
73
|
+
state.kind === "busy" ? <Loader size={14} /> : <DownloadSimpleIcon aria-hidden="true" />
|
|
74
|
+
}
|
|
75
|
+
disabled={state.kind === "busy"}
|
|
76
|
+
onClick={() => void run()}
|
|
77
|
+
data-emvb-export-entry=""
|
|
78
|
+
>
|
|
79
|
+
Export HTML
|
|
80
|
+
</Button>
|
|
81
|
+
{(state.kind === "done" || state.kind === "error") && (
|
|
82
|
+
<p
|
|
83
|
+
className="emvb-canvas-convert-note"
|
|
84
|
+
role={state.kind === "error" ? "alert" : "status"}
|
|
85
|
+
data-emvb-export-entry-status={state.kind}
|
|
86
|
+
>
|
|
87
|
+
{state.message}
|
|
88
|
+
</p>
|
|
89
|
+
)}
|
|
90
|
+
</>
|
|
91
|
+
);
|
|
92
|
+
}
|