@perkyzz/emvb 1.1.0 → 1.2.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 +1 -0
- package/package.json +10 -9
- 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/dnd/new-element.ts +46 -0
- package/src/admin/editor/editor-chrome.tsx +9 -0
- package/src/admin/editor/element-chrome.ts +22 -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 +36 -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 +3 -0
- package/src/astro/resolve-theme.ts +77 -44
- 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/EmVBLightboxRuntime.astro +8 -0
- package/src/astro/widgets/EmVBWidgetRuntimes.astro +19 -0
- package/src/astro/widgets/alerts.ts +37 -0
- package/src/astro/widgets/carousel.ts +167 -0
- package/src/astro/widgets/index.ts +1 -0
- package/src/astro/widgets/lightbox.ts +123 -0
- package/src/constants.ts +1 -1
- package/src/core/a11y/audit.ts +101 -2
- package/src/core/arrange.ts +57 -1
- package/src/core/bounded-array.ts +16 -13
- package/src/core/contract.ts +4 -1
- package/src/core/elements/icon-svg.ts +135 -0
- package/src/core/elements/index.ts +33 -127
- package/src/core/elements/widgets.ts +907 -0
- package/src/core/export/runtimes.generated.ts +3 -0
- package/src/core/export/site.ts +20 -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 +394 -133
- package/src/core/issue-cap.ts +19 -0
- package/src/core/limits.ts +6 -0
- package/src/core/loop-collections.ts +33 -0
- package/src/core/proposals.ts +8 -2
- package/src/core/render/index.ts +27 -4
- 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 +395 -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/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 +27 -2
- 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
|
@@ -7,9 +7,22 @@ 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_SOCIAL_LINKS,
|
|
14
|
+
MAX_TABS,
|
|
15
|
+
type FieldDescriptor,
|
|
16
|
+
type LayoutNode,
|
|
17
|
+
} from "../../../../core/index.ts";
|
|
11
18
|
import { BUTTON } from "../../../ui.ts";
|
|
12
|
-
import {
|
|
19
|
+
import {
|
|
20
|
+
newAccordionItem,
|
|
21
|
+
newCarouselSlide,
|
|
22
|
+
newGalleryImage,
|
|
23
|
+
newSocialLink,
|
|
24
|
+
newTabPanel,
|
|
25
|
+
} from "../../dnd/new-element.ts";
|
|
13
26
|
import { DraftTextField } from "./DraftTextField.tsx";
|
|
14
27
|
|
|
15
28
|
/** Layout operations the list runs through the editor, so limits, history and Restore apply. */
|
|
@@ -39,6 +52,27 @@ const KINDS: Record<string, Kind> = {
|
|
|
39
52
|
make: (n) => newTabPanel(n),
|
|
40
53
|
max: MAX_TABS,
|
|
41
54
|
},
|
|
55
|
+
// W-1024: each row edits the link's address; its network and name are in its own panel.
|
|
56
|
+
"social-icons": {
|
|
57
|
+
noun: "link",
|
|
58
|
+
field: (n) => ({ key: "href", kind: "href", label: `Link ${n} address` }),
|
|
59
|
+
make: (n) => newSocialLink(n),
|
|
60
|
+
max: MAX_SOCIAL_LINKS,
|
|
61
|
+
},
|
|
62
|
+
// W-1019: each row edits the picture's alt text; the picture itself is chosen in its panel.
|
|
63
|
+
gallery: {
|
|
64
|
+
noun: "picture",
|
|
65
|
+
field: (n) => ({ key: "alt", kind: "text", label: `Picture ${n} alt text` }),
|
|
66
|
+
make: () => newGalleryImage(),
|
|
67
|
+
max: MAX_GALLERY_IMAGES,
|
|
68
|
+
},
|
|
69
|
+
// W-1018: each row names a slide; its content is edited on the canvas.
|
|
70
|
+
carousel: {
|
|
71
|
+
noun: "slide",
|
|
72
|
+
field: (n) => ({ key: "label", kind: "text", label: `Slide ${n} name`, optional: true }),
|
|
73
|
+
make: (n) => newCarouselSlide(n),
|
|
74
|
+
max: MAX_CAROUSEL_SLIDES,
|
|
75
|
+
},
|
|
42
76
|
};
|
|
43
77
|
|
|
44
78
|
/** 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
|
)
|
package/src/astro/render.ts
CHANGED
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
type Layout,
|
|
10
10
|
type ThemeDynamicData,
|
|
11
11
|
} from "../core/index.ts";
|
|
12
|
+
import type { WidgetRuntime } from "../core/elements/widgets.ts";
|
|
12
13
|
import { PLUGIN_ID } from "../constants.ts";
|
|
13
14
|
|
|
14
15
|
export type RenderedPage = {
|
|
@@ -17,6 +18,11 @@ export type RenderedPage = {
|
|
|
17
18
|
needsFormsRuntime: boolean;
|
|
18
19
|
needsTabsRuntime: boolean;
|
|
19
20
|
needsMenuRuntime: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* W-1025: the opt-in widget scripts this page needs (a dismissible Alert…). `EmVBPage` loads
|
|
23
|
+
* them itself; set only when there is one.
|
|
24
|
+
*/
|
|
25
|
+
runtimes?: WidgetRuntime[];
|
|
20
26
|
/** The site's text direction when set, for the host's `<html dir>` (W-230). */
|
|
21
27
|
dir?: "ltr" | "rtl" | "auto";
|
|
22
28
|
/** W-971: the element types whose base rules `css` holds, for `sharedPartCss`. */
|
|
@@ -77,37 +83,56 @@ export function renderStored(
|
|
|
77
83
|
/** The page's language, e.g. "fr-CA", for Post Dates (W-688). */
|
|
78
84
|
lang?: string,
|
|
79
85
|
): RenderedPage {
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
86
|
+
const empty: RenderedPage = {
|
|
87
|
+
html: "",
|
|
88
|
+
css: "",
|
|
89
|
+
needsFormsRuntime: false,
|
|
90
|
+
needsTabsRuntime: false,
|
|
91
|
+
needsMenuRuntime: false,
|
|
92
|
+
...(design.direction ? { dir: design.direction } : {}),
|
|
93
|
+
};
|
|
94
|
+
let result: ReturnType<typeof renderPage>;
|
|
95
|
+
try {
|
|
96
|
+
const { layout, problem } = inspectLayout(raw);
|
|
97
|
+
if (!layout) {
|
|
98
|
+
if (raw !== null && raw !== undefined && raw !== "") {
|
|
99
|
+
// Public renders have no plugin logger. The page id and where the layout first fails
|
|
100
|
+
// (a structural path and an issue code), never layout content or issue messages (W-182).
|
|
101
|
+
// oxlint-disable-next-line no-console
|
|
102
|
+
console.error("emvb: stored layout is unreadable", { pageId, ...problem });
|
|
103
|
+
}
|
|
104
|
+
return empty;
|
|
87
105
|
}
|
|
88
|
-
|
|
89
|
-
html: "",
|
|
90
|
-
css: "",
|
|
91
|
-
needsFormsRuntime: false,
|
|
92
|
-
needsTabsRuntime: false,
|
|
93
|
-
needsMenuRuntime: false,
|
|
94
|
-
...(design.direction ? { dir: design.direction } : {}),
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
const { html, css, needsFormsRuntime, needsTabsRuntime, needsMenuRuntime, baseTypes } =
|
|
98
|
-
renderPage(layout, design, {
|
|
106
|
+
result = renderPage(layout, design, {
|
|
99
107
|
formDefinitions,
|
|
100
108
|
dynamic,
|
|
101
109
|
scope: pageId,
|
|
102
110
|
...(partIds ? { partIds } : {}),
|
|
103
111
|
...(lang ? { lang } : {}),
|
|
104
112
|
});
|
|
113
|
+
} catch (error) {
|
|
114
|
+
// S-02: a layout that can't render leaves the page empty instead of failing the request.
|
|
115
|
+
// oxlint-disable-next-line no-console
|
|
116
|
+
console.error("emvb: stored layout failed to render", {
|
|
117
|
+
pageId,
|
|
118
|
+
error: error instanceof Error ? error.name : "unknown",
|
|
119
|
+
});
|
|
120
|
+
return empty;
|
|
121
|
+
}
|
|
122
|
+
const { html, css, needsFormsRuntime, needsTabsRuntime, needsMenuRuntime, baseTypes, runtimes } =
|
|
123
|
+
result;
|
|
124
|
+
for (const warning of result.warnings) {
|
|
125
|
+
if (warning.code !== "refused-markup") continue;
|
|
126
|
+
// oxlint-disable-next-line no-console
|
|
127
|
+
console.error("emvb: an element could not render", { pageId, nodeId: warning.nodeId });
|
|
128
|
+
}
|
|
105
129
|
return {
|
|
106
130
|
html,
|
|
107
131
|
css,
|
|
108
132
|
needsFormsRuntime,
|
|
109
133
|
needsTabsRuntime,
|
|
110
134
|
needsMenuRuntime,
|
|
135
|
+
...(runtimes.length > 0 ? { runtimes } : {}),
|
|
111
136
|
...(design.direction ? { dir: design.direction } : {}),
|
|
112
137
|
baseTypes,
|
|
113
138
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { loopCollectionAllowed } from "../core/loop-collections.ts";
|
|
1
2
|
import { emdashContent, type ContentPort } from "./content-port.ts";
|
|
2
3
|
import { siteFor } from "./render-session.ts";
|
|
3
4
|
import {
|
|
@@ -31,6 +32,8 @@ const ORDER_BY: Record<CollectionLoop["order"], Record<string, "asc" | "desc">>
|
|
|
31
32
|
|
|
32
33
|
/** Published entries for one collection Loop (W-308); a failing query lists nothing. */
|
|
33
34
|
async function loopEntries(loop: CollectionLoop, content: ContentPort): Promise<ThemePostFields[]> {
|
|
35
|
+
// S-11 (W-1000): a site that lists its Loop collections shows nothing from the others.
|
|
36
|
+
if (!loopCollectionAllowed(loop.collection)) return [];
|
|
34
37
|
try {
|
|
35
38
|
const result = await content.getCollection(loop.collection, {
|
|
36
39
|
status: "published",
|