@perkyzz/emvb 1.4.0 → 1.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/admin/content-item.ts +3 -0
- package/src/admin/copy-rich-text.ts +99 -9
- package/src/admin/editor/Editor.tsx +7 -2
- package/src/admin/editor/collection-previews.ts +7 -8
- package/src/admin/editor/extensions/ExtensionPanels.tsx +33 -1
- package/src/admin/editor/extensions-context.tsx +16 -1
- package/src/admin/editor/feature-css.ts +5 -0
- package/src/admin/editor/panels/ConditionsEditor.tsx +18 -0
- package/src/admin/editor/panels/ElementPanel.tsx +2 -2
- package/src/admin/editor/panels/settings/FieldControl.tsx +15 -0
- package/src/admin/editor/panels/settings/FormBindControl.tsx +27 -31
- package/src/admin/editor/panels/settings/ImageFieldControl.tsx +106 -0
- package/src/admin/editor/panels/settings/loop-context.ts +34 -3
- package/src/admin/export-api.ts +2 -0
- package/src/admin/extension-outputs.ts +57 -0
- package/src/admin/import-forms.ts +133 -0
- package/src/admin/pages/ImportElementorDialog.tsx +32 -0
- package/src/admin/pages/ImportForms.tsx +71 -0
- package/src/admin/setup/plan.ts +2 -0
- package/src/admin/ui.ts +7 -0
- package/src/admin/widgets/ConvertToRichText.tsx +3 -2
- package/src/astro/render.ts +6 -0
- package/src/astro/resolve.ts +2 -0
- package/src/astro/theme-posts.ts +17 -23
- package/src/astro/visitor.ts +14 -5
- package/src/constants.ts +1 -1
- package/src/core/css/generate.ts +6 -1
- package/src/core/css/trace.ts +8 -0
- package/src/core/data/bindings.ts +7 -4
- package/src/core/elements/dynamic-elements.ts +1 -1
- package/src/core/elements/element-nouns.ts +48 -0
- package/src/core/export/site.ts +3 -0
- package/src/core/extensions/index.ts +2 -0
- package/src/core/extensions/placeholder.ts +7 -2
- package/src/core/extensions/render-ext.ts +49 -15
- package/src/core/import/elementor/context.ts +29 -0
- package/src/core/import/elementor/index.ts +23 -2
- package/src/core/import/elementor/widgets.ts +137 -17
- package/src/core/index.ts +9 -0
- package/src/core/render/index.ts +15 -2
- package/src/core/schema/layout.ts +4 -1
- package/src/core/theme/media-value.ts +88 -0
- package/src/core/visitor-cookie.ts +91 -0
- package/src/index.ts +28 -1
- package/src/mcp/agent-defaults.ts +40 -0
- package/src/mcp/extensions.ts +138 -0
- package/src/mcp/read.ts +55 -19
- package/src/mcp/tools.ts +3 -3
- package/src/mcp/write.ts +83 -8
- package/src/server/extension-routes.ts +37 -0
- package/src/server/plugin.ts +7 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@perkyzz/emvb",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.1",
|
|
4
4
|
"description": "Visual page builder plugin for EmDash CMS",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"astro",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"test:astro": "bun --bun vitest run"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@perkyzz/emvb-icons": "1.4.
|
|
53
|
+
"@perkyzz/emvb-icons": "1.4.1",
|
|
54
54
|
"photocn": "0.1.2",
|
|
55
55
|
"zod": ">=4.5.4 <5"
|
|
56
56
|
},
|
|
@@ -6,6 +6,9 @@ export type ContentItem = {
|
|
|
6
6
|
draftRevisionId?: string | null;
|
|
7
7
|
updatedAt?: string;
|
|
8
8
|
data?: Record<string, unknown>;
|
|
9
|
+
/** W-1091: EmDash i18n: the entry's language, and the group its translations share. */
|
|
10
|
+
locale?: string | null;
|
|
11
|
+
translationGroup?: string | null;
|
|
9
12
|
seo?: {
|
|
10
13
|
title?: string | null;
|
|
11
14
|
description?: string | null;
|
|
@@ -4,6 +4,7 @@ import { THEME_PARTS_COLLECTION } from "../constants.ts";
|
|
|
4
4
|
import { ApiError, listAllItems, requestJson, type Fetcher } from "./api.ts";
|
|
5
5
|
import type { ContentItem } from "./content-item.ts";
|
|
6
6
|
import { loadExportData } from "./export-api.ts";
|
|
7
|
+
import { siteLocales } from "./languages-api.ts";
|
|
7
8
|
import { readCollection } from "./setup/run.ts";
|
|
8
9
|
|
|
9
10
|
export type RichTextTarget = {
|
|
@@ -13,6 +14,13 @@ export type RichTextTarget = {
|
|
|
13
14
|
field: string;
|
|
14
15
|
/** The collection has a `title` field for the page title. */
|
|
15
16
|
hasTitle: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* W-1091: false when the rich-text field is shared by every language of an entry (EmDash's
|
|
19
|
+
* per-field `translatable`); then only the default language is copied.
|
|
20
|
+
*/
|
|
21
|
+
translatable?: boolean;
|
|
22
|
+
/** W-1091: false when the title is shared by every language (a translation must not send it). */
|
|
23
|
+
titleTranslatable?: boolean;
|
|
16
24
|
};
|
|
17
25
|
|
|
18
26
|
/** Visible collections with a rich-text field: where EmVB pages can be copied as rich text. */
|
|
@@ -29,12 +37,15 @@ export async function richTextTargets(fetcher: Fetcher): Promise<RichTextTarget[
|
|
|
29
37
|
const rich = fields.filter((f) => f.type === "portableText");
|
|
30
38
|
const field = rich.find((f) => f.slug === "content") ?? rich[0];
|
|
31
39
|
if (!field) return null;
|
|
40
|
+
const title = fields.find((f) => f.slug === "title");
|
|
32
41
|
const target: RichTextTarget = {
|
|
33
42
|
slug: c.slug,
|
|
34
43
|
label: c.label?.trim() || c.slug,
|
|
35
44
|
field: field.slug,
|
|
36
|
-
hasTitle:
|
|
45
|
+
hasTitle: !!title,
|
|
37
46
|
};
|
|
47
|
+
if (field.translatable === false) target.translatable = false;
|
|
48
|
+
if (title?.translatable === false) target.titleTranslatable = false;
|
|
38
49
|
return target;
|
|
39
50
|
}),
|
|
40
51
|
);
|
|
@@ -42,25 +53,66 @@ export async function richTextTargets(fetcher: Fetcher): Promise<RichTextTarget[
|
|
|
42
53
|
}
|
|
43
54
|
|
|
44
55
|
export type CopyResult = {
|
|
45
|
-
|
|
56
|
+
/** W-1091: `locale` is set when the site has languages; the title then names it. */
|
|
57
|
+
created: { title: string; id: string; locale?: string }[];
|
|
46
58
|
failed: { title: string; message: string }[];
|
|
47
59
|
/** Elements left out across all pages, by type. */
|
|
48
60
|
skipped: Record<string, number>;
|
|
49
61
|
};
|
|
50
62
|
|
|
63
|
+
type Page = Awaited<ReturnType<typeof loadExportData>>["pages"][number];
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* W-1091 (#26): the pages in the order they are copied, grouped by translation: in each group the
|
|
67
|
+
* default language first, so the others can be created as its translations. With `onlyDefault`,
|
|
68
|
+
* the other languages are set aside (returned in `rest`).
|
|
69
|
+
*/
|
|
70
|
+
function translationOrder(
|
|
71
|
+
pages: readonly Page[],
|
|
72
|
+
defaultLocale: string,
|
|
73
|
+
onlyDefault: boolean,
|
|
74
|
+
): { copy: Page[]; rest: Page[] } {
|
|
75
|
+
const groups = new Map<string, Page[]>();
|
|
76
|
+
for (const page of pages) {
|
|
77
|
+
const group = page.translationGroup || page.id;
|
|
78
|
+
groups.set(group, [...(groups.get(group) ?? []), page]);
|
|
79
|
+
}
|
|
80
|
+
const copy: Page[] = [];
|
|
81
|
+
const rest: Page[] = [];
|
|
82
|
+
for (const [group, members] of groups) {
|
|
83
|
+
const rank = (p: Page) => (p.locale === defaultLocale ? 0 : p.id === group ? 1 : 2);
|
|
84
|
+
const ordered = members.toSorted(
|
|
85
|
+
(a, b) => rank(a) - rank(b) || (a.locale ?? "").localeCompare(b.locale ?? ""),
|
|
86
|
+
);
|
|
87
|
+
if (onlyDefault) {
|
|
88
|
+
const [first, ...others] = ordered;
|
|
89
|
+
if (first) copy.push(first);
|
|
90
|
+
rest.push(...others);
|
|
91
|
+
} else copy.push(...ordered);
|
|
92
|
+
}
|
|
93
|
+
return { copy, rest };
|
|
94
|
+
}
|
|
95
|
+
|
|
51
96
|
/**
|
|
52
97
|
* W-963: published EmVB pages (all or one) become draft entries in another collection, their
|
|
53
98
|
* words, headings, lists, links and images as rich text. EmVB pages are only read; nothing is
|
|
54
99
|
* published. A page whose entry can't be created (a slug in use) is reported and the rest go on.
|
|
100
|
+
*
|
|
101
|
+
* W-1091 (#26): on a site with languages each page keeps its own: one entry per language, in that
|
|
102
|
+
* locale, with that language's words, created as a translation of the default language's entry
|
|
103
|
+
* (slugs are unique per language in EmDash, so translations share theirs). When the target's
|
|
104
|
+
* rich-text field is shared across languages, or the site has no languages set up, only one
|
|
105
|
+
* language per page is copied and the others are reported, never written under another locale.
|
|
55
106
|
*/
|
|
56
107
|
export async function copyPagesAsRichText(
|
|
57
108
|
fetcher: Fetcher,
|
|
58
109
|
target: RichTextTarget,
|
|
59
110
|
onlyPageId?: string | readonly string[],
|
|
60
111
|
): Promise<CopyResult> {
|
|
61
|
-
const [{ pages }, partItems] = await Promise.all([
|
|
112
|
+
const [{ pages }, partItems, languages] = await Promise.all([
|
|
62
113
|
loadExportData(fetcher, onlyPageId),
|
|
63
114
|
listAllItems<ContentItem>(fetcher, `/_emdash/api/content/${THEME_PARTS_COLLECTION}`),
|
|
115
|
+
siteLocales(fetcher).catch(() => null),
|
|
64
116
|
]);
|
|
65
117
|
const sectionTemplates: Record<string, Layout> = {};
|
|
66
118
|
for (const part of partItems) {
|
|
@@ -69,7 +121,33 @@ export async function copyPagesAsRichText(
|
|
|
69
121
|
if (checked.ok) sectionTemplates[part.id] = checked.layout;
|
|
70
122
|
}
|
|
71
123
|
const result: CopyResult = { created: [], failed: [], skipped: {} };
|
|
72
|
-
|
|
124
|
+
const defaultLocale = languages?.defaultLocale ?? "en";
|
|
125
|
+
const perLanguage = !!languages && target.translatable !== false;
|
|
126
|
+
const { copy, rest } = translationOrder(pages, defaultLocale, !perLanguage);
|
|
127
|
+
// A page's title names its language when the pages have more than one.
|
|
128
|
+
const multilingual = new Set(pages.map((p) => p.locale ?? defaultLocale)).size > 1;
|
|
129
|
+
const named = (page: Page) =>
|
|
130
|
+
multilingual && page.locale ? `${page.title} (${page.locale})` : page.title;
|
|
131
|
+
for (const page of rest) {
|
|
132
|
+
result.failed.push({
|
|
133
|
+
title: named(page),
|
|
134
|
+
message: languages
|
|
135
|
+
? `${target.label} shares its ${target.field} field across languages, so only the ${defaultLocale} page was copied`
|
|
136
|
+
: "this site has no languages set up, so only one language of each page was copied",
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
// Translation group → the entry its first language became.
|
|
140
|
+
const sources = new Map<string, string>();
|
|
141
|
+
for (const page of copy) {
|
|
142
|
+
const group = page.translationGroup || page.id;
|
|
143
|
+
const locale = languages ? page.locale || defaultLocale : undefined;
|
|
144
|
+
if (locale && languages && !languages.locales.includes(locale)) {
|
|
145
|
+
result.failed.push({
|
|
146
|
+
title: named(page),
|
|
147
|
+
message: `its language (${locale}) isn't set up on this site`,
|
|
148
|
+
});
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
73
151
|
let raw = page.layout;
|
|
74
152
|
if (typeof raw === "string") {
|
|
75
153
|
try {
|
|
@@ -80,12 +158,15 @@ export async function copyPagesAsRichText(
|
|
|
80
158
|
}
|
|
81
159
|
const checked = validateLayout(raw);
|
|
82
160
|
if (!checked.ok) {
|
|
83
|
-
result.failed.push({ title: page
|
|
161
|
+
result.failed.push({ title: named(page), message: "its layout couldn't be read" });
|
|
84
162
|
continue;
|
|
85
163
|
}
|
|
86
164
|
const converted = layoutToPortableText(checked.layout, { sectionTemplates });
|
|
87
165
|
for (const [type, n] of Object.entries(converted.skipped))
|
|
88
166
|
result.skipped[type] = (result.skipped[type] ?? 0) + n;
|
|
167
|
+
const source = sources.get(group);
|
|
168
|
+
// A title shared by every language comes from the entry it translates.
|
|
169
|
+
const sendTitle = target.hasTitle && !(source && target.titleTranslatable === false);
|
|
89
170
|
try {
|
|
90
171
|
// oxlint-disable-next-line no-await-in-loop -- one entry at a time; failures are per page
|
|
91
172
|
const body = await requestJson<{ item: { id: string } }>(
|
|
@@ -95,20 +176,29 @@ export async function copyPagesAsRichText(
|
|
|
95
176
|
method: "POST",
|
|
96
177
|
body: {
|
|
97
178
|
data: {
|
|
98
|
-
...(
|
|
179
|
+
...(sendTitle ? { title: page.title } : {}),
|
|
99
180
|
[target.field]: converted.body,
|
|
100
181
|
},
|
|
101
182
|
...(page.slug ? { slug: page.slug } : {}),
|
|
183
|
+
...(locale ? { locale } : {}),
|
|
184
|
+
...(locale && source ? { translationOf: source } : {}),
|
|
102
185
|
},
|
|
103
186
|
},
|
|
104
187
|
);
|
|
105
|
-
|
|
188
|
+
if (!sources.has(group)) sources.set(group, body.item.id);
|
|
189
|
+
result.created.push({
|
|
190
|
+
title: named(page),
|
|
191
|
+
id: body.item.id,
|
|
192
|
+
...(locale ? { locale } : {}),
|
|
193
|
+
});
|
|
106
194
|
} catch (error) {
|
|
107
195
|
result.failed.push({
|
|
108
|
-
title: page
|
|
196
|
+
title: named(page),
|
|
109
197
|
message:
|
|
110
198
|
error instanceof ApiError && error.status === 409
|
|
111
|
-
?
|
|
199
|
+
? locale && multilingual
|
|
200
|
+
? `its address is already used there in ${locale}`
|
|
201
|
+
: "its address is already used there"
|
|
112
202
|
: error instanceof Error
|
|
113
203
|
? error.message
|
|
114
204
|
: String(error),
|
|
@@ -63,7 +63,7 @@ import {
|
|
|
63
63
|
import { EDITOR_MIN_WIDTH_QUERY, useMediaQuery } from "./useMediaQuery.ts";
|
|
64
64
|
import { partDraftLabel, usePartTemplates } from "./section-templates.ts";
|
|
65
65
|
import { useCollectionPreviews, withPartLayouts } from "./collection-previews.ts";
|
|
66
|
-
import { useExtensionOutputs } from "../extension-outputs.ts";
|
|
66
|
+
import { useExtensionOutputs, useExtensionSourceValues } from "../extension-outputs.ts";
|
|
67
67
|
import { useEditorPresence } from "./presence.ts";
|
|
68
68
|
import { useCoDesign } from "./useCoDesign.ts";
|
|
69
69
|
import { useRemoteChange } from "./remote-change.ts";
|
|
@@ -162,6 +162,8 @@ function EditorApp({
|
|
|
162
162
|
const host = useEditorHost();
|
|
163
163
|
const canvasStyles = useCanvasStyles(fetcher);
|
|
164
164
|
const extensionManifests = useExtensionManifests(fetcher);
|
|
165
|
+
// W-1088 (#36): the values of the sources extension panels name, listed read-only.
|
|
166
|
+
const extensionSources = useExtensionSourceValues(fetcher, extensionManifests);
|
|
165
167
|
const inlinedStyles = useInlinedStyles(canvasStyles);
|
|
166
168
|
const { exit } = host;
|
|
167
169
|
const saver = useSave(fetcher, state, dispatch, collection);
|
|
@@ -344,6 +346,9 @@ function EditorApp({
|
|
|
344
346
|
},
|
|
345
347
|
previewDevice,
|
|
346
348
|
extensionOutputs,
|
|
349
|
+
// W-1088 (#37): visitors get nothing for an extension that can't render; this preview
|
|
350
|
+
// keeps the note so the editor knows something is missing.
|
|
351
|
+
extensionPlaceholders: true,
|
|
347
352
|
});
|
|
348
353
|
return previewDocument({
|
|
349
354
|
html: result.html,
|
|
@@ -455,7 +460,7 @@ function EditorApp({
|
|
|
455
460
|
})[0];
|
|
456
461
|
|
|
457
462
|
return (
|
|
458
|
-
<ExtensionsProvider extensions={extensionManifests}>
|
|
463
|
+
<ExtensionsProvider extensions={extensionManifests} sourceValues={extensionSources}>
|
|
459
464
|
<EditorOverlay
|
|
460
465
|
label={`EmVB editor: ${state.page.title || "Untitled page"}`}
|
|
461
466
|
dirty={dirty && !chrome.leaving}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import {
|
|
3
3
|
collectCollectionLoops,
|
|
4
|
+
entryImageValue,
|
|
4
5
|
loopPermalink,
|
|
6
|
+
mediaUrlOf,
|
|
5
7
|
type CollectionLoop,
|
|
6
8
|
type Layout,
|
|
7
9
|
type ThemePostFields,
|
|
@@ -13,16 +15,13 @@ type ContentItem = { id: string; slug?: string | null; data?: Record<string, unk
|
|
|
13
15
|
const text = (value: unknown): string => (typeof value === "string" ? value : "");
|
|
14
16
|
|
|
15
17
|
/** A content API item as Loop fields; the host's mapping covers images and plain fields. */
|
|
16
|
-
function previewPost(item: ContentItem, loop: CollectionLoop): ThemePostFields {
|
|
18
|
+
export function previewPost(item: ContentItem, loop: CollectionLoop): ThemePostFields {
|
|
17
19
|
const data = item.data ?? {};
|
|
18
20
|
const slug = item.slug || text(data["slug"]);
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
: image && typeof image === "object" && "src" in image
|
|
24
|
-
? text((image as { src?: unknown }).src)
|
|
25
|
-
: "";
|
|
21
|
+
// W-1090 (#32): as published pages read it: a picked upload has no `src`, only a storage key,
|
|
22
|
+
// and unset falls back from featured_image to the entry's first image field.
|
|
23
|
+
const image = entryImageValue(data, loop.imageField);
|
|
24
|
+
const src = typeof image === "string" ? image : (mediaUrlOf(image) ?? "");
|
|
26
25
|
const fields: Record<string, string> = {};
|
|
27
26
|
for (const [key, value] of Object.entries(data).slice(0, 100)) {
|
|
28
27
|
if (typeof value === "string" && value.length <= 2000) fields[key] = value;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { ExtensionManifest } from "../../../core/index.ts";
|
|
2
|
+
import { useExtensions, useExtensionSourceValuesContext } from "../extensions-context.tsx";
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* W-927 / D-067: Kumo-slot area for declarative extension panels. EmVB renders the
|
|
5
6
|
* panel copy with existing EmVB/Kumo tokens; extensions may not inject global admin CSS.
|
|
7
|
+
* W-1088 (#36): a panel that names a source lists that source's values read-only, as plain text.
|
|
6
8
|
*/
|
|
7
9
|
export function ExtensionPanels() {
|
|
8
10
|
const extensions = useExtensions();
|
|
@@ -19,8 +21,38 @@ export function ExtensionPanels() {
|
|
|
19
21
|
From {ext.label}
|
|
20
22
|
{panel.source ? ` · source “${panel.source}”` : ""}
|
|
21
23
|
</p>
|
|
24
|
+
{panel.source ? <SourceValues ext={ext} name={panel.source} /> : null}
|
|
22
25
|
</div>
|
|
23
26
|
))}
|
|
24
27
|
</div>
|
|
25
28
|
);
|
|
26
29
|
}
|
|
30
|
+
|
|
31
|
+
/** One source's values as a read-only list of labels and values. */
|
|
32
|
+
function SourceValues({ ext, name }: { ext: ExtensionManifest; name: string }) {
|
|
33
|
+
const all = useExtensionSourceValuesContext();
|
|
34
|
+
const source = ext.sources.find((s) => s.name === name);
|
|
35
|
+
if (!source) return null;
|
|
36
|
+
const id = `ext:${ext.id}/${name}`;
|
|
37
|
+
if (!all) return <p className="emvb-helper">Loading values…</p>;
|
|
38
|
+
const values = all.get(id);
|
|
39
|
+
if (!values) {
|
|
40
|
+
return (
|
|
41
|
+
<p className="emvb-helper" data-emvb-ext-source-unavailable="">
|
|
42
|
+
This source's values couldn't be read on this server.
|
|
43
|
+
</p>
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
const entries = Object.entries(values);
|
|
47
|
+
if (entries.length === 0) return <p className="emvb-helper">This source has no values.</p>;
|
|
48
|
+
return (
|
|
49
|
+
<dl className="emvb-ext-source" data-emvb-ext-source={id} aria-label={`${source.label} values`}>
|
|
50
|
+
{entries.map(([key, value]) => (
|
|
51
|
+
<div key={key}>
|
|
52
|
+
<dt>{key}</dt>
|
|
53
|
+
<dd>{value}</dd>
|
|
54
|
+
</div>
|
|
55
|
+
))}
|
|
56
|
+
</dl>
|
|
57
|
+
);
|
|
58
|
+
}
|
|
@@ -1,17 +1,32 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import type { ExtensionManifest } from "../../core/index.ts";
|
|
3
|
+
import type { ExtensionSourceValues } from "../extension-outputs.ts";
|
|
3
4
|
import { extensionElementManifests } from "./useExtensions.ts";
|
|
4
5
|
|
|
5
6
|
const ExtensionsContext = React.createContext<readonly ExtensionManifest[]>([]);
|
|
7
|
+
/** W-1088: the values of the sources extension panels name; undefined while loading. */
|
|
8
|
+
const ExtensionSourcesContext = React.createContext<ExtensionSourceValues | undefined>(undefined);
|
|
6
9
|
|
|
7
10
|
export function ExtensionsProvider({
|
|
8
11
|
extensions,
|
|
12
|
+
sourceValues,
|
|
9
13
|
children,
|
|
10
14
|
}: {
|
|
11
15
|
extensions: readonly ExtensionManifest[];
|
|
16
|
+
sourceValues?: ExtensionSourceValues;
|
|
12
17
|
children: React.ReactNode;
|
|
13
18
|
}) {
|
|
14
|
-
return
|
|
19
|
+
return (
|
|
20
|
+
<ExtensionsContext.Provider value={extensions}>
|
|
21
|
+
<ExtensionSourcesContext.Provider value={sourceValues}>
|
|
22
|
+
{children}
|
|
23
|
+
</ExtensionSourcesContext.Provider>
|
|
24
|
+
</ExtensionsContext.Provider>
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function useExtensionSourceValuesContext(): ExtensionSourceValues | undefined {
|
|
29
|
+
return React.useContext(ExtensionSourcesContext);
|
|
15
30
|
}
|
|
16
31
|
|
|
17
32
|
export function useExtensions(): readonly ExtensionManifest[] {
|
|
@@ -26,6 +26,11 @@ export const FEATURE_CSS = `
|
|
|
26
26
|
.emvb-bind-row > .emvb-bind-label + .emvb-field:last-child { grid-column: 1 / -1; }
|
|
27
27
|
.emvb-bind-live { grid-column: 1 / -1; margin: 0; font-size: 12px; color: var(--text-color-kumo-default); overflow-wrap: anywhere; }
|
|
28
28
|
.emvb-bind-live > b { font-weight: 600; }
|
|
29
|
+
/* W-1088: an extension panel's source values, read-only. */
|
|
30
|
+
.emvb-ext-source { display: grid; grid-template-columns: minmax(0, auto) minmax(0, 1fr); gap: 2px 12px; margin: 4px 0 0; font-size: 12px; line-height: 16px; }
|
|
31
|
+
.emvb-ext-source > div { display: contents; }
|
|
32
|
+
.emvb-ext-source dt { font-weight: 600; color: var(--text-color-kumo-default); overflow-wrap: anywhere; }
|
|
33
|
+
.emvb-ext-source dd { margin: 0; color: var(--text-color-kumo-default); overflow-wrap: anywhere; white-space: pre-line; }
|
|
29
34
|
.emvb-bind-outside { grid-column: 1 / -1; display: grid; gap: 4px; }
|
|
30
35
|
.emvb-bind-outside > label { display: flex; gap: 6px; align-items: center; font-size: 12px; }
|
|
31
36
|
.emvb-bind-warning { margin: 0; padding: 6px 8px; border-radius: 6px; font-size: 12px; background: var(--color-kumo-warning-tint); color: var(--text-color-kumo-default); }
|
|
@@ -111,6 +111,10 @@ export function ruleFromOption(
|
|
|
111
111
|
};
|
|
112
112
|
}
|
|
113
113
|
|
|
114
|
+
/** W-1090 (#40): the install guide's section on theme parts for the site's own routes. */
|
|
115
|
+
const OTHER_ROUTES_DOCS =
|
|
116
|
+
"https://github.com/PerkyZZ999/EmVB/blob/main/docs/guides/install-in-a-host-site.md#theme-parts-on-your-sites-other-routes";
|
|
117
|
+
|
|
114
118
|
let ruleSeq = 0;
|
|
115
119
|
const newConditionId = () => `r-${Date.now().toString(36)}-${(++ruleSeq).toString(36)}`;
|
|
116
120
|
|
|
@@ -121,6 +125,10 @@ export function ConditionsEditor({ conditions, onChange }: Props) {
|
|
|
121
125
|
|
|
122
126
|
/** The schema allows at most 20 rules, so a 21st would make the part unsavable (W-092). */
|
|
123
127
|
const full = doc.rules.length >= MAX_CONDITION_RULES;
|
|
128
|
+
// W-1090 (#40): routes that don't call resolveThemeParts never show the part.
|
|
129
|
+
const entireSite = doc.rules.some(
|
|
130
|
+
(rule) => rule.op === "include" && rule.group === "general" && rule.name === "entire_site",
|
|
131
|
+
);
|
|
124
132
|
const fullReason = `${MAX_CONDITION_RULES} conditions is the most one part can have. Remove one to add another.`;
|
|
125
133
|
|
|
126
134
|
const add = (op: "include" | "exclude") => {
|
|
@@ -190,6 +198,16 @@ export function ConditionsEditor({ conditions, onChange }: Props) {
|
|
|
190
198
|
</li>
|
|
191
199
|
))}
|
|
192
200
|
</ul>
|
|
201
|
+
{entireSite && (
|
|
202
|
+
<p className="emvb-helper" data-emvb-entire-site-hint="">
|
|
203
|
+
Entire site means every page that renders EmVB theme parts: EmVB pages and the routes
|
|
204
|
+
whose layout adds them. A blog home or post list from your site's own templates may
|
|
205
|
+
not.{" "}
|
|
206
|
+
<a href={OTHER_ROUTES_DOCS} target="_blank" rel="noopener noreferrer">
|
|
207
|
+
Add theme parts to other routes
|
|
208
|
+
</a>
|
|
209
|
+
</p>
|
|
210
|
+
)}
|
|
193
211
|
{/* UX-051: sentence case; the plus says "add", so both fit on one row at 264 px. */}
|
|
194
212
|
<div className="emvb-condition-actions">
|
|
195
213
|
<Button
|
|
@@ -674,9 +674,9 @@ function KnownElementPanel({
|
|
|
674
674
|
{buttonUrlNote(node)}
|
|
675
675
|
</p>
|
|
676
676
|
)}
|
|
677
|
-
{loopContextNote(node, partType) && (
|
|
677
|
+
{loopContextNote(node, partType, layout) && (
|
|
678
678
|
<p className="emvb-helper" data-emvb-loop-note>
|
|
679
|
-
{loopContextNote(node, partType)}
|
|
679
|
+
{loopContextNote(node, partType, layout)}
|
|
680
680
|
</p>
|
|
681
681
|
)}
|
|
682
682
|
{imageAltNote(node) && (
|
|
@@ -10,6 +10,7 @@ import { HintedSwitch } from "./HintedSwitch.tsx";
|
|
|
10
10
|
import { RequiredFieldsNotice } from "./RequiredFieldsNotice.tsx";
|
|
11
11
|
import { LoopItemBindControl } from "./LoopItemBindControl.tsx";
|
|
12
12
|
import { IconPicker } from "./IconPicker.tsx";
|
|
13
|
+
import { ImageFieldControl } from "./ImageFieldControl.tsx";
|
|
13
14
|
import { ImageSourcesField } from "./ImageSourcesField.tsx";
|
|
14
15
|
import { MediaPicker } from "./MediaPicker.tsx";
|
|
15
16
|
import { propsOf, withProp } from "./node-props.ts";
|
|
@@ -53,6 +54,20 @@ export function FieldControl({
|
|
|
53
54
|
);
|
|
54
55
|
}
|
|
55
56
|
|
|
57
|
+
if (field.key === "imageField" && node.type === "loop" && fetcher) {
|
|
58
|
+
// W-1090 (#32): picked from the collection's image fields.
|
|
59
|
+
return (
|
|
60
|
+
<ImageFieldControl
|
|
61
|
+
key={field.key}
|
|
62
|
+
field={field}
|
|
63
|
+
node={node}
|
|
64
|
+
collection={typeof props["collection"] === "string" ? props["collection"] : undefined}
|
|
65
|
+
fetcher={fetcher}
|
|
66
|
+
onChange={onChange}
|
|
67
|
+
/>
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
|
|
56
71
|
if (field.key === "partId" && node.type === "loop" && fetcher) {
|
|
57
72
|
return (
|
|
58
73
|
<LoopItemBindControl
|
|
@@ -48,11 +48,15 @@ export function FormBindControl({
|
|
|
48
48
|
);
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
51
|
+
// W-1094: one tree for both states, so the Form id input stays the same element when the forms
|
|
52
|
+
// list arrives. Swapping trees remounted it, so a person typing there lost focus and the next
|
|
53
|
+
// Delete or Backspace reached the editor, which offered to delete the selected Form.
|
|
54
|
+
const listed = capability?.status === "ready" && capability.forms.length > 0;
|
|
55
|
+
const known = listed && capability.forms.some((form) => form.id === value);
|
|
56
|
+
const placeholder = !known && value ? "Current id (not in list)" : "Choose a form…";
|
|
57
|
+
return (
|
|
58
|
+
<div className="emvb-field-group" data-emvb-form-bind={listed ? "list" : "manual"}>
|
|
59
|
+
{listed && (
|
|
56
60
|
<Select
|
|
57
61
|
label="Form"
|
|
58
62
|
className={FIELD}
|
|
@@ -73,38 +77,30 @@ export function FormBindControl({
|
|
|
73
77
|
</Select.Option>
|
|
74
78
|
))}
|
|
75
79
|
</Select>
|
|
76
|
-
|
|
77
|
-
label="Form id"
|
|
78
|
-
className={`${FIELD} emvb-mono`}
|
|
79
|
-
value={value}
|
|
80
|
-
onChange={(event) => onChange(event.target.value.trim())}
|
|
81
|
-
/>
|
|
82
|
-
{adminLinks && (
|
|
83
|
-
<p className="emvb-helper">
|
|
84
|
-
<a href="/_emdash/admin/plugins/emdash-forms/pages">Create or edit forms</a>
|
|
85
|
-
</p>
|
|
86
|
-
)}
|
|
87
|
-
</div>
|
|
88
|
-
);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
return (
|
|
92
|
-
<div className="emvb-field-group" data-emvb-form-bind="manual">
|
|
80
|
+
)}
|
|
93
81
|
<Input
|
|
94
82
|
label="Form id"
|
|
95
83
|
className={`${FIELD} emvb-mono`}
|
|
96
84
|
value={value}
|
|
97
85
|
onChange={(event) => onChange(event.target.value.trim())}
|
|
98
86
|
/>
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
87
|
+
{listed ? (
|
|
88
|
+
adminLinks && (
|
|
89
|
+
<p className="emvb-helper">
|
|
90
|
+
<a href="/_emdash/admin/plugins/emdash-forms/pages">Create or edit forms</a>
|
|
91
|
+
</p>
|
|
92
|
+
)
|
|
93
|
+
) : (
|
|
94
|
+
<p className="emvb-helper">
|
|
95
|
+
Paste a forms-plugin form id.
|
|
96
|
+
{adminLinks && (
|
|
97
|
+
<>
|
|
98
|
+
{" "}
|
|
99
|
+
<a href="/_emdash/admin/plugins/emdash-forms/pages">Open Forms</a>
|
|
100
|
+
</>
|
|
101
|
+
)}
|
|
102
|
+
</p>
|
|
103
|
+
)}
|
|
108
104
|
</div>
|
|
109
105
|
);
|
|
110
106
|
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { Select } from "@cloudflare/kumo";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { imageFieldsOf, type FieldDescriptor, type LayoutNode } from "../../../../core/index.ts";
|
|
4
|
+
import { requestJson, type Fetcher } from "../../../api.ts";
|
|
5
|
+
import { FIELD } from "../../../ui.ts";
|
|
6
|
+
import { DraftTextField } from "./DraftTextField.tsx";
|
|
7
|
+
import { propsOf, withProp } from "./node-props.ts";
|
|
8
|
+
|
|
9
|
+
const AUTO = "__auto__";
|
|
10
|
+
const CURRENT = "__current__";
|
|
11
|
+
|
|
12
|
+
type SchemaField = { slug: string; type: string; label?: string | null };
|
|
13
|
+
|
|
14
|
+
/** The collection's image fields from EmDash's schema API; null when it can't be read. */
|
|
15
|
+
async function loadImageFields(
|
|
16
|
+
fetcher: Fetcher,
|
|
17
|
+
collection: string,
|
|
18
|
+
): Promise<{ slug: string; label: string }[] | null> {
|
|
19
|
+
try {
|
|
20
|
+
const data = await requestJson<{ item?: { fields?: SchemaField[] } }>(
|
|
21
|
+
fetcher,
|
|
22
|
+
`/_emdash/api/schema/collections/${encodeURIComponent(collection)}?includeFields=true`,
|
|
23
|
+
);
|
|
24
|
+
return imageFieldsOf(data.item?.fields ?? []);
|
|
25
|
+
} catch {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* W-1090 (#32): a collection Loop's Image field, picked from the collection's image fields.
|
|
32
|
+
* Unset is Automatic: `featured_image`, else the collection's first image field, as published
|
|
33
|
+
* pages read it. A name not in the list (typed before, or a field since removed) stays chosen.
|
|
34
|
+
* Without a collection, or when the schema can't be read, it is the plain text field.
|
|
35
|
+
*/
|
|
36
|
+
export function ImageFieldControl({
|
|
37
|
+
field,
|
|
38
|
+
node,
|
|
39
|
+
collection,
|
|
40
|
+
fetcher,
|
|
41
|
+
onChange,
|
|
42
|
+
}: {
|
|
43
|
+
field: FieldDescriptor;
|
|
44
|
+
node: LayoutNode;
|
|
45
|
+
collection: string | undefined;
|
|
46
|
+
fetcher: Fetcher;
|
|
47
|
+
onChange: (node: LayoutNode) => void;
|
|
48
|
+
}) {
|
|
49
|
+
// Keyed by collection, so a changed Collection never shows the previous one's fields.
|
|
50
|
+
const [loaded, setLoaded] = React.useState<{
|
|
51
|
+
collection: string;
|
|
52
|
+
fields: { slug: string; label: string }[] | null;
|
|
53
|
+
} | null>(null);
|
|
54
|
+
|
|
55
|
+
React.useEffect(() => {
|
|
56
|
+
if (!collection) return;
|
|
57
|
+
let cancelled = false;
|
|
58
|
+
void loadImageFields(fetcher, collection).then((next) => {
|
|
59
|
+
if (!cancelled) setLoaded({ collection, fields: next });
|
|
60
|
+
});
|
|
61
|
+
return () => {
|
|
62
|
+
cancelled = true;
|
|
63
|
+
};
|
|
64
|
+
}, [fetcher, collection]);
|
|
65
|
+
|
|
66
|
+
const fields = loaded && loaded.collection === collection ? loaded.fields : null;
|
|
67
|
+
if (!collection || !fields || fields.length === 0) {
|
|
68
|
+
return <DraftTextField field={field} node={node} onChange={onChange} />;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const raw = propsOf(node)[field.key];
|
|
72
|
+
const value = typeof raw === "string" ? raw : "";
|
|
73
|
+
const known = fields.some((f) => f.slug === value);
|
|
74
|
+
const automatic = `Automatic (${fields[0]?.label ?? ""})`;
|
|
75
|
+
const labelOf = (current: string) => {
|
|
76
|
+
if (current === AUTO) return automatic;
|
|
77
|
+
if (current === CURRENT) return `${value} (not an image field here)`;
|
|
78
|
+
return fields.find((f) => f.slug === current)?.label ?? current;
|
|
79
|
+
};
|
|
80
|
+
return (
|
|
81
|
+
<div data-emvb-field={field.key} data-emvb-image-field="list">
|
|
82
|
+
<Select
|
|
83
|
+
label={field.label}
|
|
84
|
+
className={FIELD}
|
|
85
|
+
value={value === "" ? AUTO : known ? value : CURRENT}
|
|
86
|
+
renderValue={(current: unknown) => labelOf(String(current))}
|
|
87
|
+
onValueChange={(next) => {
|
|
88
|
+
if (!next || next === CURRENT) return;
|
|
89
|
+
onChange(withProp(node, field.key, next === AUTO ? undefined : String(next)));
|
|
90
|
+
}}
|
|
91
|
+
>
|
|
92
|
+
<Select.Option value={AUTO}>{automatic}</Select.Option>
|
|
93
|
+
{!known && value ? <Select.Option value={CURRENT}>{labelOf(CURRENT)}</Select.Option> : null}
|
|
94
|
+
{fields.map((f) => (
|
|
95
|
+
<Select.Option key={f.slug} value={f.slug}>
|
|
96
|
+
{f.label}
|
|
97
|
+
</Select.Option>
|
|
98
|
+
))}
|
|
99
|
+
</Select>
|
|
100
|
+
<p className="emvb-helper">
|
|
101
|
+
The image Post image shows. Automatic uses the featured image, or else the collection's
|
|
102
|
+
first image field.
|
|
103
|
+
</p>
|
|
104
|
+
</div>
|
|
105
|
+
);
|
|
106
|
+
}
|