@perkyzz/emvb 1.1.0 → 1.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/THIRD_PARTY_NOTICES.md +3 -2
- package/package.json +11 -10
- package/src/admin/agents-api.ts +5 -1
- package/src/admin/content-api.ts +29 -0
- package/src/admin/editor/Editor.tsx +6 -1
- package/src/admin/editor/ScheduleDialog.tsx +167 -0
- package/src/admin/editor/TopBar.tsx +33 -1
- package/src/admin/editor/canvas/vnode-react.tsx +3 -0
- package/src/admin/editor/dnd/new-element.ts +106 -0
- package/src/admin/editor/editor-chrome.tsx +9 -0
- package/src/admin/editor/element-chrome.ts +50 -0
- package/src/admin/editor/panels/ElementPanel.tsx +5 -1
- package/src/admin/editor/panels/settings/DraftTextField.tsx +33 -1
- package/src/admin/editor/panels/settings/FieldBindControl.tsx +6 -1
- package/src/admin/editor/panels/settings/FieldControl.tsx +10 -1
- package/src/admin/editor/panels/settings/IconPicker.tsx +4 -1
- package/src/admin/editor/panels/settings/ItemList.tsx +69 -2
- package/src/admin/editor/panels/settings/advanced-rules.ts +3 -0
- package/src/admin/editor/store.ts +7 -1
- package/src/admin/editor/useEditorData.ts +4 -0
- package/src/admin/editor/useSave.ts +47 -3
- package/src/admin/export-api.ts +20 -3
- package/src/admin/menus-api.ts +113 -0
- package/src/admin/pages/ImportElementorDialog.tsx +25 -1
- package/src/astro/EmVBPage.astro +3 -0
- package/src/astro/render.ts +43 -18
- package/src/astro/request-data.ts +9 -0
- package/src/astro/resolve-theme.ts +77 -44
- package/src/astro/resolve.ts +9 -0
- package/src/astro/visitor.ts +23 -4
- package/src/astro/widgets/EmVBAlertsRuntime.astro +8 -0
- package/src/astro/widgets/EmVBCarouselRuntime.astro +8 -0
- package/src/astro/widgets/EmVBCountdownRuntime.astro +8 -0
- package/src/astro/widgets/EmVBCounterRuntime.astro +8 -0
- package/src/astro/widgets/EmVBHeadlineRuntime.astro +9 -0
- package/src/astro/widgets/EmVBLightboxRuntime.astro +8 -0
- package/src/astro/widgets/EmVBMapRuntime.astro +8 -0
- package/src/astro/widgets/EmVBShareRuntime.astro +9 -0
- package/src/astro/widgets/EmVBWidgetRuntimes.astro +29 -0
- package/src/astro/widgets/alerts.ts +37 -0
- package/src/astro/widgets/carousel.ts +167 -0
- package/src/astro/widgets/countdown.ts +80 -0
- package/src/astro/widgets/counter.ts +98 -0
- package/src/astro/widgets/headline.ts +90 -0
- package/src/astro/widgets/index.ts +1 -0
- package/src/astro/widgets/lightbox.ts +123 -0
- package/src/astro/widgets/map.ts +37 -0
- package/src/astro/widgets/share.ts +21 -0
- package/src/constants.ts +1 -1
- package/src/core/a11y/audit.ts +127 -5
- package/src/core/arrange.ts +109 -1
- package/src/core/bounded-array.ts +16 -13
- package/src/core/canvas-collections.ts +28 -0
- package/src/core/contract.ts +4 -1
- package/src/core/elements/counter-format.ts +15 -0
- package/src/core/elements/icon-svg.ts +135 -0
- package/src/core/elements/index.ts +63 -127
- package/src/core/elements/marketing.ts +1490 -0
- package/src/core/elements/widgets.ts +932 -0
- package/src/core/export/runtimes.generated.ts +8 -0
- package/src/core/export/site.ts +25 -3
- package/src/core/extensions/schema.ts +2 -1
- package/src/core/geo-trust.ts +18 -0
- package/src/core/icons/social.generated.ts +29 -0
- package/src/core/image-edit/schema.ts +2 -1
- package/src/core/import/elementor/context.ts +18 -0
- package/src/core/import/elementor/index.ts +50 -7
- package/src/core/import/elementor/widgets.ts +783 -385
- package/src/core/issue-cap.ts +19 -0
- package/src/core/limits.ts +12 -0
- package/src/core/loop-collections.ts +33 -0
- package/src/core/proposals.ts +8 -2
- package/src/core/render/index.ts +48 -5
- package/src/core/render/vnode.ts +44 -6
- package/src/core/sanitize/svg-upload.ts +276 -23
- package/src/core/sanitize/svg.ts +3 -3
- package/src/core/schema/descriptors.ts +4 -0
- package/src/core/schema/design.ts +6 -5
- package/src/core/schema/layout.ts +798 -15
- package/src/core/schema/style.ts +2 -1
- package/src/core/shadowing-ids.ts +41 -0
- package/src/core/theme/conditions.ts +2 -1
- package/src/core/theme/dynamic.ts +2 -0
- package/src/core/theme/parse-doc.ts +10 -5
- package/src/core/theme/triggers.ts +3 -2
- package/src/core/validate.ts +3 -2
- package/src/index.ts +23 -2
- package/src/mcp/ports.ts +18 -7
- package/src/mcp/proposals.ts +36 -11
- package/src/mcp/tools.ts +1 -1
- package/src/server/agent-settings.ts +12 -1
- package/src/server/hooks.ts +41 -6
- package/src/server/mcp-routes.ts +11 -5
- package/src/server/plugin.ts +29 -3
- package/src/server/presence.ts +5 -1
- package/src/server/proposals.ts +16 -4
- package/src/server/requests.ts +60 -11
- package/src/server/site-origin.ts +13 -0
- package/src/server/targets.ts +26 -0
|
@@ -32,7 +32,7 @@ function CommitInput({
|
|
|
32
32
|
label: string;
|
|
33
33
|
className: string;
|
|
34
34
|
description?: string;
|
|
35
|
-
inputMode?: "numeric";
|
|
35
|
+
inputMode?: "numeric" | "decimal";
|
|
36
36
|
fieldKey: string;
|
|
37
37
|
draft: string;
|
|
38
38
|
error: string | null;
|
|
@@ -174,6 +174,38 @@ export function DraftTextField({
|
|
|
174
174
|
);
|
|
175
175
|
}
|
|
176
176
|
|
|
177
|
+
if (field.kind === "decimal") {
|
|
178
|
+
// W-1023: a plain number such as 4.5; its maximum may come from another prop (Stars).
|
|
179
|
+
const min = field.min ?? 0;
|
|
180
|
+
const fromProp = field.maxProp ? props[field.maxProp] : undefined;
|
|
181
|
+
const max = typeof fromProp === "number" ? fromProp : field.max;
|
|
182
|
+
const commit = () => {
|
|
183
|
+
if (commitClearable()) return;
|
|
184
|
+
const value = fieldNumber(draft);
|
|
185
|
+
if (!Number.isFinite(value) || value < min || (max !== undefined && value > max)) {
|
|
186
|
+
setError(
|
|
187
|
+
field.message ??
|
|
188
|
+
(max === undefined ? `Enter ${min} or more.` : `Enter a number from ${min} to ${max}.`),
|
|
189
|
+
);
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
setError(null);
|
|
193
|
+
onChange(withProp(node, field.key, value));
|
|
194
|
+
};
|
|
195
|
+
return (
|
|
196
|
+
<CommitInput
|
|
197
|
+
label={field.label}
|
|
198
|
+
className={`${FIELD} emvb-mono`}
|
|
199
|
+
inputMode="decimal"
|
|
200
|
+
fieldKey={field.key}
|
|
201
|
+
draft={draft}
|
|
202
|
+
error={error}
|
|
203
|
+
setDraft={setDraft}
|
|
204
|
+
commit={commit}
|
|
205
|
+
/>
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
|
|
177
209
|
if (field.kind === "int" || field.kind === "number") {
|
|
178
210
|
const integer = field.kind === "int";
|
|
179
211
|
const unit =
|
|
@@ -120,7 +120,12 @@ export function FieldBindControl({
|
|
|
120
120
|
return field ? fieldLabel(field) : CHOOSE;
|
|
121
121
|
}}
|
|
122
122
|
>
|
|
123
|
-
{
|
|
123
|
+
{/* W-994: always listed (disabled once a field is picked). Kumo 2.15's Select maps a
|
|
124
|
+
click to an option by its index, so an option that came and went picked the wrong
|
|
125
|
+
field. */}
|
|
126
|
+
<Select.Option value={MANUAL} disabled={known}>
|
|
127
|
+
{CHOOSE}
|
|
128
|
+
</Select.Option>
|
|
124
129
|
{fields.map((field) => (
|
|
125
130
|
<Select.Option key={field.name} value={field.name}>
|
|
126
131
|
{fieldLabel(field)}
|
|
@@ -103,7 +103,15 @@ export function FieldControl({
|
|
|
103
103
|
}
|
|
104
104
|
|
|
105
105
|
if (field.kind === "icon") {
|
|
106
|
-
return
|
|
106
|
+
return (
|
|
107
|
+
<IconPicker
|
|
108
|
+
key={field.key}
|
|
109
|
+
node={node}
|
|
110
|
+
fetcher={fetcher}
|
|
111
|
+
onChange={onChange}
|
|
112
|
+
optional={field.optional === true}
|
|
113
|
+
/>
|
|
114
|
+
);
|
|
107
115
|
}
|
|
108
116
|
|
|
109
117
|
if (field.kind === "marks") {
|
|
@@ -294,6 +302,7 @@ export const IMPLEMENTED_FIELD_KINDS = [
|
|
|
294
302
|
"textarea",
|
|
295
303
|
"number",
|
|
296
304
|
"int",
|
|
305
|
+
"decimal",
|
|
297
306
|
"select",
|
|
298
307
|
"boolean",
|
|
299
308
|
"href",
|
|
@@ -87,11 +87,14 @@ export function IconPicker({
|
|
|
87
87
|
node,
|
|
88
88
|
fetcher,
|
|
89
89
|
onChange,
|
|
90
|
+
optional = node.type === "button",
|
|
90
91
|
}: {
|
|
91
92
|
node: LayoutNode;
|
|
92
93
|
/** Enables My uploads in the library (W-239). */
|
|
93
94
|
fetcher?: Fetcher;
|
|
94
95
|
onChange: (node: LayoutNode) => void;
|
|
96
|
+
/** W-1020: only an optional icon (a Button's) can be removed; an Icon box needs one. */
|
|
97
|
+
optional?: boolean;
|
|
95
98
|
}) {
|
|
96
99
|
const props = propsOf(node);
|
|
97
100
|
const current = typeof props.iconId === "string" ? props.iconId : "";
|
|
@@ -124,7 +127,7 @@ export function IconPicker({
|
|
|
124
127
|
onChange(withProps(node, patch));
|
|
125
128
|
};
|
|
126
129
|
// W-387: a Button's icon is optional, so it can be taken off again.
|
|
127
|
-
const removable =
|
|
130
|
+
const removable = optional && (current !== "" || typeof props.iconSvg === "string");
|
|
128
131
|
const remove = () => {
|
|
129
132
|
const { iconId: _id, iconSvg: _svg, ...rest } = propsOf(node);
|
|
130
133
|
onChange({ ...node, props: rest } as LayoutNode);
|
|
@@ -7,9 +7,28 @@ import {
|
|
|
7
7
|
PlusIcon,
|
|
8
8
|
TrashIcon,
|
|
9
9
|
} from "@phosphor-icons/react";
|
|
10
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
MAX_CAROUSEL_SLIDES,
|
|
12
|
+
MAX_GALLERY_IMAGES,
|
|
13
|
+
MAX_HOTSPOTS,
|
|
14
|
+
MAX_PRICE_ITEMS,
|
|
15
|
+
MAX_SHARE_LINKS,
|
|
16
|
+
MAX_SOCIAL_LINKS,
|
|
17
|
+
MAX_TABS,
|
|
18
|
+
type FieldDescriptor,
|
|
19
|
+
type LayoutNode,
|
|
20
|
+
} from "../../../../core/index.ts";
|
|
11
21
|
import { BUTTON } from "../../../ui.ts";
|
|
12
|
-
import {
|
|
22
|
+
import {
|
|
23
|
+
newAccordionItem,
|
|
24
|
+
newCarouselSlide,
|
|
25
|
+
newGalleryImage,
|
|
26
|
+
newHotspot,
|
|
27
|
+
newPriceListItem,
|
|
28
|
+
newShareLink,
|
|
29
|
+
newSocialLink,
|
|
30
|
+
newTabPanel,
|
|
31
|
+
} from "../../dnd/new-element.ts";
|
|
13
32
|
import { DraftTextField } from "./DraftTextField.tsx";
|
|
14
33
|
|
|
15
34
|
/** Layout operations the list runs through the editor, so limits, history and Restore apply. */
|
|
@@ -39,6 +58,54 @@ const KINDS: Record<string, Kind> = {
|
|
|
39
58
|
make: (n) => newTabPanel(n),
|
|
40
59
|
max: MAX_TABS,
|
|
41
60
|
},
|
|
61
|
+
// W-1024: each row edits the link's address; its network and name are in its own panel.
|
|
62
|
+
"social-icons": {
|
|
63
|
+
noun: "link",
|
|
64
|
+
field: (n) => ({ key: "href", kind: "href", label: `Link ${n} address` }),
|
|
65
|
+
make: (n) => newSocialLink(n),
|
|
66
|
+
max: MAX_SOCIAL_LINKS,
|
|
67
|
+
},
|
|
68
|
+
// W-1019: each row edits the picture's alt text; the picture itself is chosen in its panel.
|
|
69
|
+
gallery: {
|
|
70
|
+
noun: "picture",
|
|
71
|
+
field: (n) => ({ key: "alt", kind: "text", label: `Picture ${n} alt text` }),
|
|
72
|
+
make: () => newGalleryImage(),
|
|
73
|
+
max: MAX_GALLERY_IMAGES,
|
|
74
|
+
},
|
|
75
|
+
// W-1018: each row names a slide; its content is edited on the canvas.
|
|
76
|
+
carousel: {
|
|
77
|
+
noun: "slide",
|
|
78
|
+
field: (n) => ({ key: "label", kind: "text", label: `Slide ${n} name`, optional: true }),
|
|
79
|
+
make: (n) => newCarouselSlide(n),
|
|
80
|
+
max: MAX_CAROUSEL_SLIDES,
|
|
81
|
+
},
|
|
82
|
+
// W-1043: each row edits the item's title; its price and the rest are in its own panel.
|
|
83
|
+
"price-list": {
|
|
84
|
+
noun: "item",
|
|
85
|
+
field: (n) => ({ key: "title", kind: "text", label: `Item ${n} title` }),
|
|
86
|
+
make: (n) => newPriceListItem(n),
|
|
87
|
+
max: MAX_PRICE_ITEMS,
|
|
88
|
+
},
|
|
89
|
+
// W-1047: each row names its link for screen readers; Edit picks the service in its panel.
|
|
90
|
+
"share-buttons": {
|
|
91
|
+
noun: "link",
|
|
92
|
+
field: (n) => ({
|
|
93
|
+
key: "label",
|
|
94
|
+
kind: "text",
|
|
95
|
+
label: `Link ${n} name`,
|
|
96
|
+
optional: true,
|
|
97
|
+
message: "Leave it empty for Share on and the service's name.",
|
|
98
|
+
}),
|
|
99
|
+
make: (n) => newShareLink(n),
|
|
100
|
+
max: MAX_SHARE_LINKS,
|
|
101
|
+
},
|
|
102
|
+
// W-1048: each row edits the marker's title; its place and note are in its own panel.
|
|
103
|
+
hotspots: {
|
|
104
|
+
noun: "marker",
|
|
105
|
+
field: (n) => ({ key: "title", kind: "text", label: `Marker ${n} title` }),
|
|
106
|
+
make: (n) => newHotspot(n),
|
|
107
|
+
max: MAX_HOTSPOTS,
|
|
108
|
+
},
|
|
42
109
|
};
|
|
43
110
|
|
|
44
111
|
/** True for the elements whose Content tab is a list of their items (W-130). */
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isShadowingId } from "../../../../core/shadowing-ids.ts";
|
|
1
2
|
import type { Layout, LayoutNode } from "../../../../core/index.ts";
|
|
2
3
|
import { isReservedAttribute } from "../../../../core/render/extras.ts";
|
|
3
4
|
import { nodeChildren } from "../../../../core/tree-ops.ts";
|
|
@@ -29,6 +30,8 @@ export function htmlIdError(value: string, layout: Layout | null, nodeId: string
|
|
|
29
30
|
// W-418: EmVB names headings (emvb-h-…), form fields and tabs with emvb- ids; reusing one
|
|
30
31
|
// made two elements share an id, so a contents link or a label could point at the wrong one.
|
|
31
32
|
if (/^emvb-/i.test(value)) return "Ids starting with emvb- are reserved; choose another.";
|
|
33
|
+
if (isShadowingId(value))
|
|
34
|
+
return `"${value}" is the name of a browser built-in that scripts on the page use; choose another.`;
|
|
32
35
|
if (otherHtmlIds(layout, nodeId).has(value)) return "Another element already uses this CSS id.";
|
|
33
36
|
return null;
|
|
34
37
|
}
|
|
@@ -23,6 +23,8 @@ export type EditorState = {
|
|
|
23
23
|
id: string;
|
|
24
24
|
page: PageDraft;
|
|
25
25
|
status: string;
|
|
26
|
+
/** W-1027: when EmDash will publish the saved draft by itself (ISO), or null. */
|
|
27
|
+
scheduledAt?: string | null;
|
|
26
28
|
rev: string | null;
|
|
27
29
|
design: DesignSystem;
|
|
28
30
|
designRevision: string | null;
|
|
@@ -59,6 +61,7 @@ export type EditorAction =
|
|
|
59
61
|
| { type: "apply-arranged"; layout: Layout; selected: string }
|
|
60
62
|
| { type: "saved"; rev: string; version: number }
|
|
61
63
|
| { type: "published"; rev: string }
|
|
64
|
+
| { type: "scheduled"; rev: string; status: string; at: string | null }
|
|
62
65
|
| { type: "set-design"; design: DesignSystem; revision: string | null }
|
|
63
66
|
/**
|
|
64
67
|
* W-536: a site styles edit shown before its save lands, so the next edit builds on it. The
|
|
@@ -238,7 +241,10 @@ export function editorReducer(state: EditorState, action: EditorAction): EditorS
|
|
|
238
241
|
status: state.status === "published" ? "changed" : state.status,
|
|
239
242
|
};
|
|
240
243
|
case "published":
|
|
241
|
-
return { ...state, rev: action.rev, status: "published" };
|
|
244
|
+
return { ...state, rev: action.rev, status: "published", scheduledAt: null };
|
|
245
|
+
case "scheduled":
|
|
246
|
+
// W-1027: scheduling (or cancelling it) keeps the draft; EmDash publishes it at `at`.
|
|
247
|
+
return { ...state, rev: action.rev, status: action.status, scheduledAt: action.at };
|
|
242
248
|
case "preview-design":
|
|
243
249
|
return { ...state, design: action.design };
|
|
244
250
|
case "set-design":
|
|
@@ -33,6 +33,8 @@ export type EditorEntry = {
|
|
|
33
33
|
seoNoIndex?: boolean;
|
|
34
34
|
seoImage?: string;
|
|
35
35
|
status: string;
|
|
36
|
+
/** W-1027: when EmDash publishes the entry by itself (ISO), or null. */
|
|
37
|
+
scheduledAt?: string | null;
|
|
36
38
|
rev: string | null;
|
|
37
39
|
layout: Layout | null;
|
|
38
40
|
partType?: ThemePartType;
|
|
@@ -64,6 +66,7 @@ type ContentResponse = {
|
|
|
64
66
|
slug?: string | null;
|
|
65
67
|
status?: string;
|
|
66
68
|
draftRevisionId?: string | null;
|
|
69
|
+
scheduledAt?: string | null;
|
|
67
70
|
data?: Record<string, unknown>;
|
|
68
71
|
seo?: {
|
|
69
72
|
title?: string | null;
|
|
@@ -100,6 +103,7 @@ export async function loadEntry(
|
|
|
100
103
|
seoNoIndex: body?.item?.seo?.noIndex === true,
|
|
101
104
|
seoImage: text(body?.item?.seo?.image),
|
|
102
105
|
status: entryStatus(body?.item),
|
|
106
|
+
scheduledAt: body?.item?.scheduledAt ?? null,
|
|
103
107
|
rev: body?.["_rev"] ?? null,
|
|
104
108
|
layout: readLayout(data["layout"]),
|
|
105
109
|
};
|
|
@@ -2,7 +2,7 @@ import * as React from "react";
|
|
|
2
2
|
import { byteLength, MAX_LAYOUT_BYTES, nodeIdAtPath, type Layout } from "../../core/index.ts";
|
|
3
3
|
import { PAGES_COLLECTION, THEME_PARTS_COLLECTION } from "../../constants.ts";
|
|
4
4
|
import { ApiError, type Fetcher } from "../api.ts";
|
|
5
|
-
import { publishPage, savePage } from "../content-api.ts";
|
|
5
|
+
import { publishPage, savePage, scheduleEntry } from "../content-api.ts";
|
|
6
6
|
import { publishThemePart, saveThemePart } from "../theme-api.ts";
|
|
7
7
|
import type { EditorAction, EditorState } from "./store.ts";
|
|
8
8
|
import { loadEntry } from "./useEditorData.ts";
|
|
@@ -214,7 +214,8 @@ export function useSave(
|
|
|
214
214
|
await run;
|
|
215
215
|
}, [fetcher, write, collection]);
|
|
216
216
|
|
|
217
|
-
|
|
217
|
+
/** The revision to publish or schedule: after the running save, and with unsaved edits saved. */
|
|
218
|
+
const flush = React.useCallback(async (): Promise<string | null | false> => {
|
|
218
219
|
let rev: string | null = latest.current.rev;
|
|
219
220
|
const pending = queued.current ?? inFlight.current;
|
|
220
221
|
if (pending) {
|
|
@@ -227,6 +228,12 @@ export function useSave(
|
|
|
227
228
|
rev = await start(rev);
|
|
228
229
|
if (!rev) return false;
|
|
229
230
|
}
|
|
231
|
+
return rev;
|
|
232
|
+
}, [start]);
|
|
233
|
+
|
|
234
|
+
const publish = React.useCallback(async (): Promise<boolean> => {
|
|
235
|
+
const rev = await flush();
|
|
236
|
+
if (rev === false) return false;
|
|
230
237
|
try {
|
|
231
238
|
const result =
|
|
232
239
|
collection === THEME_PARTS_COLLECTION
|
|
@@ -240,12 +247,49 @@ export function useSave(
|
|
|
240
247
|
setStatus({ kind: "error", message: publishFailureMessage(error), retry: false });
|
|
241
248
|
return false;
|
|
242
249
|
}
|
|
243
|
-
}, [fetcher, dispatch,
|
|
250
|
+
}, [fetcher, dispatch, flush, collection]);
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* W-1027: has EmDash publish the saved draft at `at` (unsaved edits are saved first), or with
|
|
254
|
+
* `at` null cancels the schedule. Returns the error message, or null when it worked.
|
|
255
|
+
*/
|
|
256
|
+
const schedule = React.useCallback(
|
|
257
|
+
async (at: Date | null): Promise<string | null> => {
|
|
258
|
+
const rev = at ? await flush() : latest.current.rev;
|
|
259
|
+
if (rev === false) return "Your changes couldn't be saved, so nothing was scheduled.";
|
|
260
|
+
try {
|
|
261
|
+
const result = await scheduleEntry(
|
|
262
|
+
fetcher,
|
|
263
|
+
`/_emdash/api/content/${collection}`,
|
|
264
|
+
latest.current.id,
|
|
265
|
+
at,
|
|
266
|
+
rev,
|
|
267
|
+
);
|
|
268
|
+
dispatch({
|
|
269
|
+
type: "scheduled",
|
|
270
|
+
rev: result.rev,
|
|
271
|
+
status: result.status,
|
|
272
|
+
at: result.scheduledAt,
|
|
273
|
+
});
|
|
274
|
+
setStatus({ kind: "saved" });
|
|
275
|
+
return null;
|
|
276
|
+
} catch (error) {
|
|
277
|
+
if (error instanceof ApiError && error.status === 409) {
|
|
278
|
+
setConflict(true);
|
|
279
|
+
return "This page was changed somewhere else. Reload or overwrite it, then schedule again.";
|
|
280
|
+
}
|
|
281
|
+
if (error instanceof ApiError && error.status === 400) return error.message;
|
|
282
|
+
return publishFailureMessage(error);
|
|
283
|
+
}
|
|
284
|
+
},
|
|
285
|
+
[fetcher, dispatch, flush, collection],
|
|
286
|
+
);
|
|
244
287
|
|
|
245
288
|
return {
|
|
246
289
|
status,
|
|
247
290
|
save,
|
|
248
291
|
publish,
|
|
292
|
+
schedule,
|
|
249
293
|
overwrite,
|
|
250
294
|
conflict,
|
|
251
295
|
closeConflict: () => setConflict(false),
|
package/src/admin/export-api.ts
CHANGED
|
@@ -134,17 +134,33 @@ export async function loadExportData(
|
|
|
134
134
|
return { pages, parts, design: design.published ?? design.design };
|
|
135
135
|
}
|
|
136
136
|
|
|
137
|
-
|
|
137
|
+
const MEDIA_LIBRARY = "/_emdash/api/media/file/";
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Media this site serves itself (same origin), which the export can copy. S-06 (W-996): nothing
|
|
141
|
+
* under /_emdash/ but the media library's files, so an API answer can't end up in the zip.
|
|
142
|
+
*/
|
|
138
143
|
export function copyableMedia(urls: readonly string[], origin: string): string[] {
|
|
139
144
|
return urls.filter((url) => {
|
|
140
145
|
try {
|
|
141
|
-
|
|
146
|
+
const parsed = new URL(url, origin);
|
|
147
|
+
if (parsed.origin !== origin) return false;
|
|
148
|
+
return !parsed.pathname.startsWith("/_emdash/") || parsed.pathname.startsWith(MEDIA_LIBRARY);
|
|
142
149
|
} catch {
|
|
143
150
|
return false;
|
|
144
151
|
}
|
|
145
152
|
});
|
|
146
153
|
}
|
|
147
154
|
|
|
155
|
+
/** S-06: what a copied file may be; anything else (JSON, HTML) is left as a link. */
|
|
156
|
+
const MEDIA_TYPE = /^(?:image|video|audio|font)\/|^application\/(?:pdf|font-woff2?|x-font-woff)\b/i;
|
|
157
|
+
|
|
158
|
+
/** S-06: the media library needs the session cookie; public files are fetched without one. */
|
|
159
|
+
export const mediaRequest = (url: string, origin: string): RequestInit => ({
|
|
160
|
+
credentials: new URL(url, origin).pathname.startsWith(MEDIA_LIBRARY) ? "same-origin" : "omit",
|
|
161
|
+
redirect: "error",
|
|
162
|
+
});
|
|
163
|
+
|
|
148
164
|
/** Up to this many media files are copied, so an export can't fill the browser's memory. */
|
|
149
165
|
const MAX_COPIED_MEDIA = 500;
|
|
150
166
|
const MAX_COPIED_BYTES = 200 * 1024 * 1024;
|
|
@@ -163,6 +179,7 @@ async function fetchMedia(
|
|
|
163
179
|
// oxlint-disable-next-line no-await-in-loop -- one at a time keeps memory and load low
|
|
164
180
|
const response = await get(new URL(url, origin).href);
|
|
165
181
|
if (!response.ok) throw new Error(String(response.status));
|
|
182
|
+
if (!MEDIA_TYPE.test(response.headers.get("content-type") ?? "")) throw new Error("type");
|
|
166
183
|
// oxlint-disable-next-line no-await-in-loop -- same
|
|
167
184
|
const bytes = new Uint8Array(await response.arrayBuffer());
|
|
168
185
|
total += bytes.length;
|
|
@@ -207,7 +224,7 @@ export async function exportSite(
|
|
|
207
224
|
let copied = 0;
|
|
208
225
|
let failed = 0;
|
|
209
226
|
if (options.copyMedia) {
|
|
210
|
-
const get = options.get ?? ((url: string) => fetch(url,
|
|
227
|
+
const get = options.get ?? ((url: string) => fetch(url, mediaRequest(url, options.origin)));
|
|
211
228
|
const result = await fetchMedia(
|
|
212
229
|
copyableMedia(site.report.media, options.origin),
|
|
213
230
|
options.origin,
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* W-1026: the site's own menus (EmDash's, which its WordPress import fills) as the links an
|
|
3
|
+
* imported Elementor Nav Menu needs. Menus need `menus:read`; a link to a page or post is
|
|
4
|
+
* resolved to its address through the content API.
|
|
5
|
+
*/
|
|
6
|
+
import type { MenuLink } from "../core/import/elementor/context.ts";
|
|
7
|
+
import { requestJson, type Fetcher } from "./api.ts";
|
|
8
|
+
|
|
9
|
+
type MenuSummary = { name: string; label?: string | null };
|
|
10
|
+
type MenuItem = {
|
|
11
|
+
id: string;
|
|
12
|
+
parentId: string | null;
|
|
13
|
+
sortOrder: number;
|
|
14
|
+
type: string;
|
|
15
|
+
referenceCollection: string | null;
|
|
16
|
+
referenceId: string | null;
|
|
17
|
+
customUrl: string | null;
|
|
18
|
+
label: string;
|
|
19
|
+
target: string | null;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/** A menu name as WordPress writes its slug: lower case, words joined by hyphens. */
|
|
23
|
+
export const menuKey = (name: string) =>
|
|
24
|
+
name
|
|
25
|
+
.toLowerCase()
|
|
26
|
+
.replace(/[^a-z0-9]+/g, "-")
|
|
27
|
+
.replace(/^-+|-+$/g, "");
|
|
28
|
+
|
|
29
|
+
/** Where a menu item goes: its own address, or the page or post it points at. */
|
|
30
|
+
async function itemHref(
|
|
31
|
+
fetcher: Fetcher,
|
|
32
|
+
item: MenuItem,
|
|
33
|
+
slugs: Map<string, Promise<string | undefined>>,
|
|
34
|
+
): Promise<string | undefined> {
|
|
35
|
+
if (item.customUrl) return item.customUrl;
|
|
36
|
+
if (!item.referenceCollection || !item.referenceId) return undefined;
|
|
37
|
+
const key = `${item.referenceCollection}/${item.referenceId}`;
|
|
38
|
+
let slug = slugs.get(key);
|
|
39
|
+
if (!slug) {
|
|
40
|
+
slug = requestJson<{ item?: { slug?: string | null } }>(
|
|
41
|
+
fetcher,
|
|
42
|
+
`/_emdash/api/content/${encodeURIComponent(item.referenceCollection)}/${encodeURIComponent(item.referenceId)}`,
|
|
43
|
+
).then(
|
|
44
|
+
(data) => data.item?.slug ?? undefined,
|
|
45
|
+
() => undefined,
|
|
46
|
+
);
|
|
47
|
+
slugs.set(key, slug);
|
|
48
|
+
}
|
|
49
|
+
const found = await slug;
|
|
50
|
+
if (found === undefined) return undefined;
|
|
51
|
+
return item.referenceCollection === "pages"
|
|
52
|
+
? `/${found}`
|
|
53
|
+
: `/${item.referenceCollection}/${found}`;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** A menu's flat items as nested links, in the menu's order. */
|
|
57
|
+
async function menuLinks(fetcher: Fetcher, items: readonly MenuItem[]): Promise<MenuLink[]> {
|
|
58
|
+
const slugs = new Map<string, Promise<string | undefined>>();
|
|
59
|
+
const hrefs = new Map(
|
|
60
|
+
await Promise.all(
|
|
61
|
+
items.map(async (item) => [item.id, await itemHref(fetcher, item, slugs)] as const),
|
|
62
|
+
),
|
|
63
|
+
);
|
|
64
|
+
const under = (parent: string | null): MenuLink[] =>
|
|
65
|
+
items
|
|
66
|
+
.filter((item) => item.parentId === parent)
|
|
67
|
+
.toSorted((a, b) => a.sortOrder - b.sortOrder)
|
|
68
|
+
.map((item) => {
|
|
69
|
+
const link: { -readonly [K in keyof MenuLink]: MenuLink[K] } = { text: item.label };
|
|
70
|
+
const href = hrefs.get(item.id);
|
|
71
|
+
const children = under(item.id);
|
|
72
|
+
if (href) link.href = href;
|
|
73
|
+
if (item.target === "_blank") link.newTab = true;
|
|
74
|
+
if (children.length > 0) link.children = children;
|
|
75
|
+
return link;
|
|
76
|
+
});
|
|
77
|
+
return under(null);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* The links of each wanted menu the site has, by the wanted name. A site menu matches by its
|
|
82
|
+
* name or label written as a slug. Menus the site doesn't have (or can't be read) are left out.
|
|
83
|
+
*/
|
|
84
|
+
export async function loadSiteMenus(
|
|
85
|
+
fetcher: Fetcher,
|
|
86
|
+
wanted: readonly string[],
|
|
87
|
+
): Promise<Map<string, MenuLink[]>> {
|
|
88
|
+
const found = new Map<string, MenuLink[]>();
|
|
89
|
+
if (wanted.length === 0) return found;
|
|
90
|
+
let menus: MenuSummary[];
|
|
91
|
+
try {
|
|
92
|
+
menus = await requestJson<MenuSummary[]>(fetcher, "/_emdash/api/menus");
|
|
93
|
+
} catch {
|
|
94
|
+
return found;
|
|
95
|
+
}
|
|
96
|
+
await Promise.all(
|
|
97
|
+
wanted.map(async (name) => {
|
|
98
|
+
const key = menuKey(name);
|
|
99
|
+
const menu = menus.find((m) => menuKey(m.name) === key || menuKey(m.label ?? "") === key);
|
|
100
|
+
if (!menu) return;
|
|
101
|
+
try {
|
|
102
|
+
const full = await requestJson<{ items?: MenuItem[] }>(
|
|
103
|
+
fetcher,
|
|
104
|
+
`/_emdash/api/menus/${encodeURIComponent(menu.name)}`,
|
|
105
|
+
);
|
|
106
|
+
found.set(name, await menuLinks(fetcher, full.items ?? []));
|
|
107
|
+
} catch {
|
|
108
|
+
// Unreadable: the import leaves that Menu empty and says so.
|
|
109
|
+
}
|
|
110
|
+
}),
|
|
111
|
+
);
|
|
112
|
+
return found;
|
|
113
|
+
}
|
|
@@ -16,6 +16,8 @@ import { THEME_PARTS_COLLECTION } from "../../constants.ts";
|
|
|
16
16
|
import { ApiError, type Fetcher } from "../api.ts";
|
|
17
17
|
import { createPage, listPages, type PageSummary } from "../content-api.ts";
|
|
18
18
|
import { uploadImage } from "../media-api.ts";
|
|
19
|
+
import { loadSiteMenus } from "../menus-api.ts";
|
|
20
|
+
import type { MenuLink } from "../../core/import/elementor/context.ts";
|
|
19
21
|
import { editorUrl } from "../editor/exit.ts";
|
|
20
22
|
import { loadIconSet } from "../editor/icons/library.ts";
|
|
21
23
|
import { createThemePart } from "../theme-api.ts";
|
|
@@ -214,6 +216,9 @@ export function ImportElementorDialog({
|
|
|
214
216
|
const [imageStatus, setImageStatus] = React.useState<string>();
|
|
215
217
|
const [copying, setCopying] = React.useState(false);
|
|
216
218
|
const imageRef = React.useRef<HTMLInputElement>(null);
|
|
219
|
+
// W-1026: the site's own menus (from its WordPress import) for imported Nav Menus, by name.
|
|
220
|
+
// A menu the site doesn't have is kept as no links, so it is asked for once.
|
|
221
|
+
const [siteMenus, setSiteMenus] = React.useState<ReadonlyMap<string, MenuLink[]>>(new Map());
|
|
217
222
|
const iconsLoad = React.useRef<Promise<IconMap> | undefined>(undefined);
|
|
218
223
|
const fileRef = React.useRef<HTMLInputElement>(null);
|
|
219
224
|
const kitRef = React.useRef<HTMLInputElement>(null);
|
|
@@ -236,6 +241,7 @@ export function ImportElementorDialog({
|
|
|
236
241
|
setPageLinks(readPageLinks());
|
|
237
242
|
setCopies(new Map());
|
|
238
243
|
setImageStatus(undefined);
|
|
244
|
+
setSiteMenus(new Map());
|
|
239
245
|
}
|
|
240
246
|
}
|
|
241
247
|
|
|
@@ -260,8 +266,9 @@ export function ImportElementorDialog({
|
|
|
260
266
|
svg: (url: string) => svgs.get(url),
|
|
261
267
|
pageLink: (id: number) => pageLinks[id],
|
|
262
268
|
media: (url: string) => copies.get(url),
|
|
269
|
+
menu: (name: string) => siteMenus.get(name),
|
|
263
270
|
}),
|
|
264
|
-
[kit, defaults, useClasses, svgs, pageLinks, copies],
|
|
271
|
+
[kit, defaults, useClasses, svgs, pageLinks, copies, siteMenus],
|
|
265
272
|
);
|
|
266
273
|
const result = React.useMemo(
|
|
267
274
|
() => (json.trim() ? importElementor(json, options(icons)) : undefined),
|
|
@@ -320,6 +327,23 @@ export function ImportElementorDialog({
|
|
|
320
327
|
);
|
|
321
328
|
setCopying(false);
|
|
322
329
|
};
|
|
330
|
+
// W-1026: fetch each menu the export's Nav Menus name once; the import re-runs with them.
|
|
331
|
+
const wantedMenus = (result?.ok ? result.menus : []).filter((name) => !siteMenus.has(name));
|
|
332
|
+
const wantedKey = wantedMenus.join("\u0000");
|
|
333
|
+
React.useEffect(() => {
|
|
334
|
+
if (!wantedKey) return;
|
|
335
|
+
const names = wantedKey.split("\u0000");
|
|
336
|
+
let live = true;
|
|
337
|
+
void loadSiteMenus(fetcher, names).then((found) => {
|
|
338
|
+
if (!live) return;
|
|
339
|
+
setSiteMenus(
|
|
340
|
+
(current) => new Map([...current, ...names.map((n) => [n, found.get(n) ?? []] as const)]),
|
|
341
|
+
);
|
|
342
|
+
});
|
|
343
|
+
return () => {
|
|
344
|
+
live = false;
|
|
345
|
+
};
|
|
346
|
+
}, [wantedKey, fetcher]);
|
|
323
347
|
const needsPages = linkedPages.length > 0 && pages === undefined;
|
|
324
348
|
React.useEffect(() => {
|
|
325
349
|
if (!needsPages) return;
|
package/src/astro/EmVBPage.astro
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
import type { RenderedPage } from "./render.ts";
|
|
3
|
+
import EmVBWidgetRuntimes from "./widgets/EmVBWidgetRuntimes.astro";
|
|
3
4
|
|
|
4
5
|
/** The resolved meta of the page (EmDash's `getSeoMeta` result fits), for blank canvas mode. */
|
|
5
6
|
interface PageMeta {
|
|
@@ -59,6 +60,7 @@ const ogDescription = seo?.ogDescription ?? description;
|
|
|
59
60
|
</head>
|
|
60
61
|
<body>
|
|
61
62
|
<Fragment set:html={page.html} />
|
|
63
|
+
<EmVBWidgetRuntimes names={page.runtimes} />
|
|
62
64
|
<slot />
|
|
63
65
|
</body>
|
|
64
66
|
</html>
|
|
@@ -66,6 +68,7 @@ const ogDescription = seo?.ogDescription ?? description;
|
|
|
66
68
|
<>
|
|
67
69
|
<style is:inline set:html={page.css} />
|
|
68
70
|
<Fragment set:html={page.html} />
|
|
71
|
+
<EmVBWidgetRuntimes names={page.runtimes} />
|
|
69
72
|
<slot />
|
|
70
73
|
</>
|
|
71
74
|
)
|