@perkyzz/emvb 1.3.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/README.md +2 -2
- package/package.json +2 -2
- package/src/admin/bulk-api.ts +5 -1
- package/src/admin/content-item.ts +3 -0
- package/src/admin/copy-rich-text.ts +99 -9
- package/src/admin/editor/A11yCopilot.tsx +3 -1
- package/src/admin/editor/Editor.tsx +28 -3
- package/src/admin/editor/Timeline.tsx +1 -8
- package/src/admin/editor/canvas/DeviceBar.tsx +7 -2
- package/src/admin/editor/canvas/EmptyCanvas.tsx +11 -2
- package/src/admin/editor/canvas/use-canvas-dnd.ts +1 -20
- package/src/admin/editor/canvas/vnode-react.tsx +2 -0
- package/src/admin/editor/co-design.ts +36 -1
- package/src/admin/editor/collection-previews.ts +7 -8
- package/src/admin/editor/dnd/dragged-source.ts +22 -0
- package/src/admin/editor/dnd/layer-drop.ts +141 -0
- package/src/admin/editor/dnd/new-element.ts +16 -0
- package/src/admin/editor/editor-css.ts +9 -1
- package/src/admin/editor/element-chrome.ts +6 -0
- package/src/admin/editor/extensions/ExtensionPanels.tsx +33 -1
- package/src/admin/editor/extensions-context.tsx +16 -1
- package/src/admin/editor/feature-css.ts +27 -0
- package/src/admin/editor/inert-links.ts +8 -0
- package/src/admin/editor/panels/ColorControl.tsx +2 -2
- package/src/admin/editor/panels/ConditionsEditor.tsx +18 -0
- package/src/admin/editor/panels/ElementPanel.tsx +2 -2
- package/src/admin/editor/panels/FontFaces.tsx +342 -0
- package/src/admin/editor/panels/LayersPanel.tsx +56 -6
- package/src/admin/editor/panels/LeftPanel.tsx +153 -29
- package/src/admin/editor/panels/SettingsPanel.tsx +1 -0
- package/src/admin/editor/panels/SiteStylesDrawer.tsx +5 -0
- package/src/admin/editor/panels/TemplatesPanel.tsx +205 -0
- package/src/admin/editor/panels/TokenScales.tsx +2 -0
- package/src/admin/editor/panels/TriggersEditor.tsx +203 -9
- package/src/admin/editor/panels/VariableSection.tsx +111 -7
- package/src/admin/editor/panels/color-space.ts +71 -6
- package/src/admin/editor/panels/settings/AudienceEditor.tsx +3 -0
- package/src/admin/editor/panels/settings/FieldControl.tsx +33 -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/LoopItemBindControl.tsx +9 -3
- package/src/admin/editor/panels/settings/StickyControl.tsx +97 -0
- package/src/admin/editor/panels/settings/StyleRow.tsx +14 -0
- package/src/admin/editor/panels/settings/loop-context.ts +34 -3
- package/src/admin/editor/panels/settings/style-sections.ts +19 -2
- package/src/admin/editor/panels/url-rules.ts +43 -0
- package/src/admin/editor/panels/use-layers-drop.ts +232 -0
- package/src/admin/editor/store.ts +4 -2
- package/src/admin/editor/useExtensions.ts +3 -1
- package/src/admin/editor/useNodeActions.ts +74 -1
- package/src/admin/editor/useSave.ts +116 -85
- package/src/admin/export-api.ts +27 -2
- package/src/admin/extension-outputs.ts +236 -0
- package/src/admin/font-files-api.ts +38 -0
- package/src/admin/import-forms.ts +133 -0
- package/src/admin/pages/ImportButton.tsx +15 -4
- package/src/admin/pages/ImportElementorDialog.tsx +53 -187
- package/src/admin/pages/ImportForms.tsx +71 -0
- package/src/admin/pages/ImportHtmlDialog.tsx +209 -0
- package/src/admin/pages/ImportImageCopies.tsx +167 -0
- package/src/admin/pages/ImportReport.tsx +63 -0
- package/src/admin/pages/NewPageDialog.tsx +54 -32
- package/src/admin/pages/PageList.tsx +9 -0
- package/src/admin/pages/ThemePartList.tsx +9 -0
- package/src/admin/setup/plan.ts +2 -0
- package/src/admin/ui.ts +7 -0
- package/src/admin/widgets/ConvertToRichText.tsx +3 -2
- package/src/astro/EmVBPage.astro +5 -2
- package/src/astro/extension-styles.ts +35 -0
- package/src/astro/forms/EmVBFormsClient.astro +3 -0
- package/src/astro/forms/enhance.ts +107 -0
- package/src/astro/popups/runtime.ts +47 -2
- package/src/astro/render.ts +25 -4
- package/src/astro/resolve-theme.ts +11 -4
- package/src/astro/resolve.ts +2 -0
- package/src/astro/theme-posts.ts +17 -23
- package/src/astro/visitor.ts +14 -5
- package/src/astro/widgets/EmVBStickyRuntime.astro +9 -0
- package/src/astro/widgets/EmVBThemeRuntime.astro +9 -0
- package/src/astro/widgets/EmVBWidgetRuntimes.astro +12 -0
- package/src/astro/widgets/alerts.ts +16 -2
- package/src/astro/widgets/carousel.ts +65 -24
- package/src/astro/widgets/countdown.ts +18 -7
- package/src/astro/widgets/extension-runtimes.ts +27 -0
- package/src/astro/widgets/headline.ts +14 -5
- package/src/astro/widgets/sticky.ts +87 -0
- package/src/astro/widgets/theme.ts +52 -0
- package/src/constants.ts +1 -1
- package/src/core/a11y/audit.ts +150 -2
- package/src/core/arrange.ts +19 -1
- package/src/core/css/font-face.ts +72 -0
- package/src/core/css/generate.ts +41 -2
- 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/elements/form-elements.ts +119 -9
- package/src/core/elements/icon-svg.ts +14 -0
- package/src/core/elements/index.ts +24 -4
- package/src/core/elements/input-limits.ts +44 -0
- package/src/core/elements/menu.ts +109 -47
- package/src/core/elements/site.ts +108 -0
- package/src/core/elements/widgets.ts +13 -3
- package/src/core/export/runtimes.generated.ts +7 -5
- package/src/core/export/site.ts +53 -4
- package/src/core/extensions/classes.ts +114 -0
- package/src/core/extensions/index.ts +19 -2
- package/src/core/extensions/normalize.ts +13 -0
- package/src/core/extensions/placeholder.ts +7 -2
- package/src/core/extensions/registry.ts +134 -10
- package/src/core/extensions/render-ext.ts +115 -36
- package/src/core/extensions/safe-nodes.ts +67 -11
- package/src/core/extensions/types.ts +48 -1
- package/src/core/fonts/files.ts +74 -0
- package/src/core/fonts/google.ts +112 -0
- package/src/core/fonts/test-font.ts +9 -0
- package/src/core/import/elementor/context.ts +42 -4
- package/src/core/import/elementor/index.ts +55 -23
- package/src/core/import/elementor/widgets.ts +242 -20
- package/src/core/import/html/blocks.ts +602 -0
- package/src/core/import/html/index.ts +155 -0
- package/src/core/import/html/map.ts +958 -0
- package/src/core/import/html/parse.ts +430 -0
- package/src/core/index.ts +54 -0
- package/src/core/migrate/v18.ts +3 -0
- package/src/core/public-attributes.ts +17 -0
- package/src/core/render/extras.ts +31 -7
- package/src/core/render/form.ts +103 -10
- package/src/core/render/index.ts +165 -16
- package/src/core/render/section.ts +31 -1
- package/src/core/render/spacer-basis.ts +102 -0
- package/src/core/render/theme-boot.ts +16 -0
- package/src/core/render/vnode.ts +1 -1
- package/src/core/sanitize/css.ts +68 -3
- package/src/core/sanitize/motion.ts +12 -0
- package/src/core/schema/design.ts +40 -0
- package/src/core/schema/layout.ts +118 -6
- package/src/core/schema/style.ts +28 -0
- package/src/core/templates/index.ts +218 -0
- package/src/core/templates/pages.ts +29 -0
- package/src/core/templates/sections.ts +794 -0
- package/src/core/templates/types.ts +9 -0
- package/src/core/theme/dynamic.ts +9 -6
- package/src/core/theme/media-value.ts +88 -0
- package/src/core/theme/popup-markup.ts +21 -2
- package/src/core/theme/popup-rules.ts +36 -0
- package/src/core/theme/triggers.ts +64 -5
- package/src/core/translatable.ts +5 -2
- package/src/core/visitor-cookie.ts +91 -0
- package/src/extension-build.ts +331 -0
- package/src/index.ts +53 -4
- package/src/mcp/agent-defaults.ts +40 -0
- package/src/mcp/brief.ts +191 -0
- package/src/mcp/extensions.ts +138 -0
- package/src/mcp/prompts.ts +33 -0
- package/src/mcp/read.ts +84 -20
- package/src/mcp/tools.ts +42 -3
- package/src/mcp/write.ts +124 -9
- package/src/server/extension-routes.ts +110 -0
- package/src/server/font-routes.ts +301 -0
- package/src/server/plugin.ts +15 -0
|
@@ -3,7 +3,6 @@ import { FileArrowUpIcon } from "@phosphor-icons/react";
|
|
|
3
3
|
import * as React from "react";
|
|
4
4
|
import {
|
|
5
5
|
type ElementorImport,
|
|
6
|
-
type ImportNote,
|
|
7
6
|
importElementor,
|
|
8
7
|
mergeSectionClasses,
|
|
9
8
|
remapClassIds,
|
|
@@ -15,16 +14,20 @@ import {
|
|
|
15
14
|
import { THEME_PARTS_COLLECTION } from "../../constants.ts";
|
|
16
15
|
import { ApiError, type Fetcher } from "../api.ts";
|
|
17
16
|
import { createPage, listPages, type PageSummary } from "../content-api.ts";
|
|
18
|
-
import { uploadImage } from "../media-api.ts";
|
|
19
17
|
import { loadSiteMenus } from "../menus-api.ts";
|
|
20
18
|
import type { MenuLink } from "../../core/import/elementor/context.ts";
|
|
21
19
|
import { editorUrl } from "../editor/exit.ts";
|
|
22
20
|
import { loadIconSet } from "../editor/icons/library.ts";
|
|
23
21
|
import { createThemePart } from "../theme-api.ts";
|
|
22
|
+
import { type FormsCapability, loadFormsCapability } from "../forms-api.ts";
|
|
23
|
+
import { createImportedForms, withFormIds } from "../import-forms.ts";
|
|
24
24
|
import { saveDesign } from "../design-api.ts";
|
|
25
25
|
import { loadDesign } from "../editor/useEditorData.ts";
|
|
26
26
|
import { BUTTON, FIELD } from "../ui.ts";
|
|
27
27
|
import { CreateDialog } from "./CreateDialog.tsx";
|
|
28
|
+
import { ImportForms } from "./ImportForms.tsx";
|
|
29
|
+
import { ImportReport } from "./ImportReport.tsx";
|
|
30
|
+
import { type Copy, fileNameOf, ImportImageCopies } from "./ImportImageCopies.tsx";
|
|
28
31
|
import {
|
|
29
32
|
ImportPageLinks,
|
|
30
33
|
type PageLinks,
|
|
@@ -43,61 +46,24 @@ function loadIcons(): Promise<IconMap> {
|
|
|
43
46
|
);
|
|
44
47
|
}
|
|
45
48
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
{ kind: "skipped", title: "Left out" },
|
|
49
|
-
{ kind: "approximated", title: "Changed to fit EmVB" },
|
|
50
|
-
];
|
|
51
|
-
|
|
52
|
-
/** What the import will do, before anything is created. */
|
|
53
|
-
function ImportReport({
|
|
49
|
+
/** The Elementor report: Elementor elements, and the fonts the page uses. */
|
|
50
|
+
function ElementorReport({
|
|
54
51
|
result,
|
|
55
52
|
partType,
|
|
56
53
|
}: {
|
|
57
54
|
result: ElementorImport | undefined;
|
|
58
55
|
partType?: ThemePartType;
|
|
59
56
|
}) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
{result.error}
|
|
65
|
-
</p>
|
|
66
|
-
);
|
|
67
|
-
}
|
|
57
|
+
const summary = result?.ok
|
|
58
|
+
? `Ready to import ${result.mapped} of ${result.elements} Elementor elements` +
|
|
59
|
+
(partType ? ` as a ${THEME_PART_TYPE_LABELS[partType].toLowerCase()}.` : ".")
|
|
60
|
+
: "";
|
|
68
61
|
return (
|
|
69
|
-
<
|
|
70
|
-
|
|
71
|
-
aria-label="Import report"
|
|
72
|
-
// The report can be long; it scrolls on its own and must be reachable by keyboard.
|
|
73
|
-
tabIndex={0}
|
|
74
|
-
data-emvb-import-report=""
|
|
75
|
-
>
|
|
76
|
-
<p className="emvb-import-summary" role="status">
|
|
77
|
-
{`Ready to import ${result.mapped} of ${result.elements} Elementor elements`}
|
|
78
|
-
{partType ? ` as a ${THEME_PART_TYPE_LABELS[partType].toLowerCase()}.` : "."}
|
|
79
|
-
</p>
|
|
80
|
-
{result.fonts.length > 0 && (
|
|
62
|
+
<ImportReport result={result} summary={summary}>
|
|
63
|
+
{result?.ok && result.fonts.length > 0 && (
|
|
81
64
|
<p className="emvb-helper">{`Fonts used: ${result.fonts.join(", ")}. Make sure your site loads them.`}</p>
|
|
82
65
|
)}
|
|
83
|
-
|
|
84
|
-
const notes = result.notes.filter((note) => note.kind === kind);
|
|
85
|
-
if (notes.length === 0) return null;
|
|
86
|
-
return (
|
|
87
|
-
<details key={kind} open={kind !== "approximated"} data-emvb-import-group={kind}>
|
|
88
|
-
<summary>{`${title} (${notes.length})`}</summary>
|
|
89
|
-
<ul>
|
|
90
|
-
{notes.map((note) => (
|
|
91
|
-
<li key={`${note.element}:${note.message}`}>
|
|
92
|
-
<strong>{note.element}:</strong> {note.message}
|
|
93
|
-
{note.count > 1 ? ` (${note.count}×)` : ""}
|
|
94
|
-
</li>
|
|
95
|
-
))}
|
|
96
|
-
</ul>
|
|
97
|
-
</details>
|
|
98
|
-
);
|
|
99
|
-
})}
|
|
100
|
-
</section>
|
|
66
|
+
</ImportReport>
|
|
101
67
|
);
|
|
102
68
|
}
|
|
103
69
|
|
|
@@ -106,16 +72,6 @@ const MAX_SVG_FILE = 65_536;
|
|
|
106
72
|
/** Files fetched in one go; an export with more names them in the report. */
|
|
107
73
|
const MAX_SVG_FETCHES = 100;
|
|
108
74
|
|
|
109
|
-
/** A URL's file name, decoded and lower-cased, to match a chosen file to the export's address (W-951, W-958). */
|
|
110
|
-
export function fileNameOf(url: string): string {
|
|
111
|
-
const last = url.split(/[?#]/)[0]?.split("/").pop() ?? "";
|
|
112
|
-
try {
|
|
113
|
-
return decodeURIComponent(last).toLowerCase();
|
|
114
|
-
} catch {
|
|
115
|
-
return last.toLowerCase();
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
75
|
/** Fetches an SVG file without cookies; undefined when the site refuses (CORS) or it's too big. */
|
|
120
76
|
async function fetchSvg(url: string): Promise<string | undefined> {
|
|
121
77
|
try {
|
|
@@ -132,44 +88,6 @@ async function fetchSvg(url: string): Promise<string | undefined> {
|
|
|
132
88
|
}
|
|
133
89
|
}
|
|
134
90
|
|
|
135
|
-
/** W-958: an image copied into the media library is at most this large. */
|
|
136
|
-
const MAX_IMAGE_FILE = 20 * 1024 * 1024;
|
|
137
|
-
|
|
138
|
-
/** Fetches an old-site image without cookies; undefined when refused (CORS), not an image or too big. */
|
|
139
|
-
async function fetchImage(url: string): Promise<File | undefined> {
|
|
140
|
-
try {
|
|
141
|
-
const response = await fetch(url, {
|
|
142
|
-
credentials: "omit",
|
|
143
|
-
redirect: "follow",
|
|
144
|
-
signal: AbortSignal.timeout(20_000),
|
|
145
|
-
});
|
|
146
|
-
if (!response.ok) return undefined;
|
|
147
|
-
const blob = await response.blob();
|
|
148
|
-
if (!blob.type.startsWith("image/") || blob.size > MAX_IMAGE_FILE) return undefined;
|
|
149
|
-
return new File([blob], fileNameOf(url) || "image", { type: blob.type });
|
|
150
|
-
} catch {
|
|
151
|
-
return undefined;
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
/** Runs `run` on every item, at most `limit` at a time. */
|
|
156
|
-
async function eachLimited<T>(
|
|
157
|
-
items: readonly T[],
|
|
158
|
-
limit: number,
|
|
159
|
-
run: (item: T) => Promise<void>,
|
|
160
|
-
): Promise<void> {
|
|
161
|
-
let next = 0;
|
|
162
|
-
const worker = async (): Promise<void> => {
|
|
163
|
-
const index = next++;
|
|
164
|
-
if (index >= items.length) return;
|
|
165
|
-
await run(items[index] as T);
|
|
166
|
-
return worker();
|
|
167
|
-
};
|
|
168
|
-
await Promise.all(Array.from({ length: Math.min(limit, items.length) }, worker));
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
type Copy = { url: string; id: string };
|
|
172
|
-
|
|
173
91
|
/** Reads a chosen file as text, refusing one larger than the importer reads. */
|
|
174
92
|
async function readJsonFile(file: File): Promise<string> {
|
|
175
93
|
if (file.size > MAX_IMPORT_CHARS)
|
|
@@ -213,12 +131,14 @@ export function ImportElementorDialog({
|
|
|
213
131
|
const [pages, setPages] = React.useState<PageSummary[]>();
|
|
214
132
|
// W-958: old-site images copied into the media library, by their old address.
|
|
215
133
|
const [copies, setCopies] = React.useState<ReadonlyMap<string, Copy>>(new Map());
|
|
216
|
-
|
|
217
|
-
const [
|
|
218
|
-
const imageRef = React.useRef<HTMLInputElement>(null);
|
|
134
|
+
// A new import starts the image copy row afresh (its status line and file input).
|
|
135
|
+
const [session, setSession] = React.useState(0);
|
|
219
136
|
// W-1026: the site's own menus (from its WordPress import) for imported Nav Menus, by name.
|
|
220
137
|
// A menu the site doesn't have is kept as no links, so it is asked for once.
|
|
221
138
|
const [siteMenus, setSiteMenus] = React.useState<ReadonlyMap<string, MenuLink[]>>(new Map());
|
|
139
|
+
// W-1091 (#27): imported forms can be created in EmDash Forms (off until asked).
|
|
140
|
+
const [createForms, setCreateForms] = React.useState(false);
|
|
141
|
+
const [formsCapability, setFormsCapability] = React.useState<FormsCapability>();
|
|
222
142
|
const iconsLoad = React.useRef<Promise<IconMap> | undefined>(undefined);
|
|
223
143
|
const fileRef = React.useRef<HTMLInputElement>(null);
|
|
224
144
|
const kitRef = React.useRef<HTMLInputElement>(null);
|
|
@@ -240,8 +160,9 @@ export function ImportElementorDialog({
|
|
|
240
160
|
setSvgStatus(undefined);
|
|
241
161
|
setPageLinks(readPageLinks());
|
|
242
162
|
setCopies(new Map());
|
|
243
|
-
|
|
163
|
+
setSession((n) => n + 1);
|
|
244
164
|
setSiteMenus(new Map());
|
|
165
|
+
setCreateForms(false);
|
|
245
166
|
}
|
|
246
167
|
}
|
|
247
168
|
|
|
@@ -278,55 +199,19 @@ export function ImportElementorDialog({
|
|
|
278
199
|
const missingSvgs = result?.ok ? result.svgFiles : [];
|
|
279
200
|
const linkedPages = result?.ok ? result.pageLinks : [];
|
|
280
201
|
const oldImages = result?.ok ? result.images.filter((url) => !copies.has(url)) : [];
|
|
281
|
-
|
|
282
|
-
const
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
}
|
|
289
|
-
};
|
|
290
|
-
|
|
291
|
-
const copyImages = async () => {
|
|
292
|
-
setCopying(true);
|
|
293
|
-
const done: [string, Copy][] = [];
|
|
294
|
-
const urls = [...oldImages];
|
|
295
|
-
await eachLimited(urls, 4, async (url) => {
|
|
296
|
-
const file = await fetchImage(url);
|
|
297
|
-
if (file) await upload(url, file, done);
|
|
202
|
+
const importedForms = result?.ok ? result.forms : [];
|
|
203
|
+
const hasForms = importedForms.length > 0;
|
|
204
|
+
React.useEffect(() => {
|
|
205
|
+
if (!hasForms || formsCapability) return;
|
|
206
|
+
let live = true;
|
|
207
|
+
void loadFormsCapability(fetcher).then((found) => {
|
|
208
|
+
if (live) setFormsCapability(found);
|
|
298
209
|
});
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
? `Copied ${done.length} ${done.length === 1 ? "image" : "images"} to the media library.`
|
|
304
|
-
: `Copied ${done.length} of ${urls.length}. The rest couldn't be read from your old site from here: download them from its media library and add them with Add image files.`,
|
|
305
|
-
);
|
|
306
|
-
setCopying(false);
|
|
307
|
-
};
|
|
210
|
+
return () => {
|
|
211
|
+
live = false;
|
|
212
|
+
};
|
|
213
|
+
}, [hasForms, formsCapability, fetcher]);
|
|
308
214
|
|
|
309
|
-
const addImages = async (files: readonly File[]) => {
|
|
310
|
-
setCopying(true);
|
|
311
|
-
const wanted = new Map(oldImages.map((url) => [fileNameOf(url), url]));
|
|
312
|
-
const usable = (file: File) =>
|
|
313
|
-
file.size <= MAX_IMAGE_FILE &&
|
|
314
|
-
file.type.startsWith("image/") &&
|
|
315
|
-
wanted.has(file.name.toLowerCase());
|
|
316
|
-
const unused = files.filter((file) => !usable(file)).map((file) => file.name);
|
|
317
|
-
const done: [string, Copy][] = [];
|
|
318
|
-
await eachLimited(files.filter(usable), 4, (file) =>
|
|
319
|
-
upload(wanted.get(file.name.toLowerCase()) ?? "", file, done),
|
|
320
|
-
);
|
|
321
|
-
setCopies((current) => new Map([...current, ...done]));
|
|
322
|
-
setImageStatus(
|
|
323
|
-
`Copied ${done.length} ${done.length === 1 ? "image" : "images"} to the media library.` +
|
|
324
|
-
(unused.length > 0
|
|
325
|
-
? ` Not used (not in this export, not an image, or over 20 MB): ${unused.join(", ")}.`
|
|
326
|
-
: ""),
|
|
327
|
-
);
|
|
328
|
-
setCopying(false);
|
|
329
|
-
};
|
|
330
215
|
// W-1026: fetch each menu the export's Nav Menus name once; the import re-runs with them.
|
|
331
216
|
const wantedMenus = (result?.ok ? result.menus : []).filter((name) => !siteMenus.has(name));
|
|
332
217
|
const wantedKey = wantedMenus.join("\u0000");
|
|
@@ -412,6 +297,13 @@ export function ImportElementorDialog({
|
|
|
412
297
|
}
|
|
413
298
|
writePageLinks(pageLinks);
|
|
414
299
|
let layout = imported.layout;
|
|
300
|
+
if (createForms && imported.forms.length > 0) {
|
|
301
|
+
// W-1091 (#27): each form becomes an EmDash form and the page's Form points at it.
|
|
302
|
+
const known = await loadFormsCapability(fetcher);
|
|
303
|
+
const slugs = new Set(known.status === "ready" ? known.forms.map((f) => f.slug) : []);
|
|
304
|
+
const made = await createImportedForms(fetcher, imported.forms, slugs);
|
|
305
|
+
layout = withFormIds(layout, made.ids);
|
|
306
|
+
}
|
|
415
307
|
if (imported.classes.length > 0) {
|
|
416
308
|
// W-958 (D-060): never changes a class already on the site; identical ones are reused, a
|
|
417
309
|
// different one with the same name is added as a numbered copy. Classes are saved first,
|
|
@@ -612,45 +504,13 @@ export function ImportElementorDialog({
|
|
|
612
504
|
/>
|
|
613
505
|
</div>
|
|
614
506
|
)}
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
onClick={() => void copyImages()}
|
|
623
|
-
>
|
|
624
|
-
{copying ? "Copying…" : "Copy images"}
|
|
625
|
-
</Button>
|
|
626
|
-
<Button
|
|
627
|
-
type="button"
|
|
628
|
-
variant="secondary"
|
|
629
|
-
className={BUTTON}
|
|
630
|
-
disabled={copying || oldImages.length === 0}
|
|
631
|
-
onClick={() => imageRef.current?.click()}
|
|
632
|
-
>
|
|
633
|
-
Add image files
|
|
634
|
-
</Button>
|
|
635
|
-
<span className="emvb-helper" role="status">
|
|
636
|
-
{imageStatus ??
|
|
637
|
-
`${oldImages.length} ${oldImages.length === 1 ? "image loads" : "images load"} from your old site. Copy them to your media library (copies stay there even if you don't import), or add the files.`}
|
|
638
|
-
</span>
|
|
639
|
-
<input
|
|
640
|
-
ref={imageRef}
|
|
641
|
-
type="file"
|
|
642
|
-
accept="image/*"
|
|
643
|
-
multiple
|
|
644
|
-
hidden
|
|
645
|
-
data-emvb-elementor-images=""
|
|
646
|
-
onChange={(event) => {
|
|
647
|
-
const files = [...(event.target.files ?? [])];
|
|
648
|
-
event.target.value = "";
|
|
649
|
-
if (files.length > 0) void addImages(files);
|
|
650
|
-
}}
|
|
651
|
-
/>
|
|
652
|
-
</div>
|
|
653
|
-
)}
|
|
507
|
+
<ImportImageCopies
|
|
508
|
+
key={session}
|
|
509
|
+
fetcher={fetcher}
|
|
510
|
+
images={oldImages}
|
|
511
|
+
onCopied={(done) => setCopies((current) => new Map([...current, ...done]))}
|
|
512
|
+
dataAttribute="data-emvb-elementor-images"
|
|
513
|
+
/>
|
|
654
514
|
<ImportPageLinks
|
|
655
515
|
ids={linkedPages}
|
|
656
516
|
links={pageLinks}
|
|
@@ -686,7 +546,13 @@ export function ImportElementorDialog({
|
|
|
686
546
|
))}
|
|
687
547
|
</Select>
|
|
688
548
|
)}
|
|
689
|
-
<
|
|
549
|
+
<ImportForms
|
|
550
|
+
forms={importedForms}
|
|
551
|
+
capability={formsCapability}
|
|
552
|
+
create={createForms}
|
|
553
|
+
onCreateChange={setCreateForms}
|
|
554
|
+
/>
|
|
555
|
+
<ElementorReport result={result} {...(target === "part" ? { partType } : {})} />
|
|
690
556
|
</div>
|
|
691
557
|
</CreateDialog>
|
|
692
558
|
);
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { Checkbox } from "@cloudflare/kumo";
|
|
2
|
+
import type { ImportedForm, ImportedFormField } from "../../core/index.ts";
|
|
3
|
+
import type { FormsCapability } from "../forms-api.ts";
|
|
4
|
+
|
|
5
|
+
/** How a field reads in the list: "Email (email, required)". */
|
|
6
|
+
function fieldSummary(field: ImportedFormField): string {
|
|
7
|
+
const notes = [field.type, ...(field.required ? ["required"] : [])];
|
|
8
|
+
const label = field.label === field.name ? field.name : `${field.label} [${field.name}]`;
|
|
9
|
+
return `${label} (${notes.join(", ")})`;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* W-1091 (#27): Elementor forms arrive as EmVB Forms that aren't connected to a form yet, so they
|
|
14
|
+
* show nothing on the live site. The import says so where it can't be missed, lists each form's
|
|
15
|
+
* fields (names and types) and success message, and offers to create them in EmDash Forms.
|
|
16
|
+
*/
|
|
17
|
+
export function ImportForms({
|
|
18
|
+
forms,
|
|
19
|
+
capability,
|
|
20
|
+
create,
|
|
21
|
+
onCreateChange,
|
|
22
|
+
}: {
|
|
23
|
+
forms: readonly ImportedForm[];
|
|
24
|
+
/** The forms plugin: there and listable, there for an id only, or not installed. */
|
|
25
|
+
capability: FormsCapability | undefined;
|
|
26
|
+
create: boolean;
|
|
27
|
+
onCreateChange: (create: boolean) => void;
|
|
28
|
+
}) {
|
|
29
|
+
if (forms.length === 0) return null;
|
|
30
|
+
const one = forms.length === 1;
|
|
31
|
+
return (
|
|
32
|
+
<section className="emvb-import-forms" aria-label="Forms" data-emvb-import-forms="">
|
|
33
|
+
<p className="emvb-import-summary">
|
|
34
|
+
{one
|
|
35
|
+
? "This page has a form that needs connecting to an EmDash form. Until it is, it doesn't show on your live site."
|
|
36
|
+
: `This page has ${forms.length} forms that need connecting to EmDash forms. Until they are, they don't show on your live site.`}
|
|
37
|
+
</p>
|
|
38
|
+
<ul>
|
|
39
|
+
{forms.map((form) => {
|
|
40
|
+
const fields = form.pages.flatMap((page) => page.fields);
|
|
41
|
+
return (
|
|
42
|
+
<li key={form.nodeId} data-emvb-import-form="">
|
|
43
|
+
<strong>{form.name}:</strong>{" "}
|
|
44
|
+
{fields.length > 0 ? fields.map(fieldSummary).join(", ") : "no fields"}.
|
|
45
|
+
{form.successMessage ? ` Success message: “${form.successMessage}”` : ""}
|
|
46
|
+
</li>
|
|
47
|
+
);
|
|
48
|
+
})}
|
|
49
|
+
</ul>
|
|
50
|
+
{capability?.status === "missing" ? (
|
|
51
|
+
<p className="emvb-helper">
|
|
52
|
+
Install the EmDash Forms plugin, create {one ? "the form" : "the forms"} there, then pick{" "}
|
|
53
|
+
{one ? "it" : "each"} in the Form's settings.
|
|
54
|
+
</p>
|
|
55
|
+
) : (
|
|
56
|
+
<>
|
|
57
|
+
<Checkbox
|
|
58
|
+
label="Create the forms in EmDash Forms"
|
|
59
|
+
checked={create}
|
|
60
|
+
onCheckedChange={(checked: boolean) => onCreateChange(checked)}
|
|
61
|
+
/>
|
|
62
|
+
<p className="emvb-helper">
|
|
63
|
+
{create
|
|
64
|
+
? "Each becomes an EmDash form with these fields, types and success message, connected to the page. Needs an administrator."
|
|
65
|
+
: "Or create them in Forms yourself, then pick each in the Form's settings."}
|
|
66
|
+
</p>
|
|
67
|
+
</>
|
|
68
|
+
)}
|
|
69
|
+
</section>
|
|
70
|
+
);
|
|
71
|
+
}
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import { Button, Select } from "@cloudflare/kumo";
|
|
2
|
+
import { FileArrowUpIcon } from "@phosphor-icons/react";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import {
|
|
5
|
+
importHtml,
|
|
6
|
+
MAX_HTML_IMPORT_CHARS,
|
|
7
|
+
THEME_PART_TYPE_LABELS,
|
|
8
|
+
THEME_PART_TYPES,
|
|
9
|
+
type ThemePartType,
|
|
10
|
+
} from "../../core/index.ts";
|
|
11
|
+
import { THEME_PARTS_COLLECTION } from "../../constants.ts";
|
|
12
|
+
import { ApiError, type Fetcher } from "../api.ts";
|
|
13
|
+
import { createPage } from "../content-api.ts";
|
|
14
|
+
import { editorUrl } from "../editor/exit.ts";
|
|
15
|
+
import { createThemePart } from "../theme-api.ts";
|
|
16
|
+
import { BUTTON, FIELD } from "../ui.ts";
|
|
17
|
+
import { CreateDialog } from "./CreateDialog.tsx";
|
|
18
|
+
import { type Copy, ImportImageCopies } from "./ImportImageCopies.tsx";
|
|
19
|
+
import { ImportReport } from "./ImportReport.tsx";
|
|
20
|
+
|
|
21
|
+
/** Reads a chosen file as text, refusing one larger than the importer reads. */
|
|
22
|
+
async function readHtmlFile(file: File): Promise<string> {
|
|
23
|
+
if (file.size > MAX_HTML_IMPORT_CHARS)
|
|
24
|
+
throw new Error("This file is larger than 4 MB. Import one page at a time.");
|
|
25
|
+
return file.text();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Import HTML (W-1074): paste a WordPress post's block markup (Code editor) or choose or paste
|
|
30
|
+
* any HTML page, see what will be kept, changed or left out, then create a draft page (or theme
|
|
31
|
+
* part) and open it. Nothing is fetched from an address: the person pastes or uploads it.
|
|
32
|
+
*/
|
|
33
|
+
export function ImportHtmlDialog({
|
|
34
|
+
fetcher,
|
|
35
|
+
open,
|
|
36
|
+
onOpenChange,
|
|
37
|
+
target,
|
|
38
|
+
}: {
|
|
39
|
+
fetcher: Fetcher;
|
|
40
|
+
open: boolean;
|
|
41
|
+
onOpenChange: (open: boolean) => void;
|
|
42
|
+
target: "page" | "part";
|
|
43
|
+
}) {
|
|
44
|
+
const [html, setHtml] = React.useState("");
|
|
45
|
+
const [fileName, setFileName] = React.useState<string>();
|
|
46
|
+
const [fileError, setFileError] = React.useState<string>();
|
|
47
|
+
const [partType, setPartType] = React.useState<ThemePartType>("section");
|
|
48
|
+
const [copies, setCopies] = React.useState<ReadonlyMap<string, Copy>>(new Map());
|
|
49
|
+
const [session, setSession] = React.useState(0);
|
|
50
|
+
const fileRef = React.useRef<HTMLInputElement>(null);
|
|
51
|
+
|
|
52
|
+
const [wasOpen, setWasOpen] = React.useState(open);
|
|
53
|
+
if (open !== wasOpen) {
|
|
54
|
+
setWasOpen(open);
|
|
55
|
+
if (open) {
|
|
56
|
+
setHtml("");
|
|
57
|
+
setFileName(undefined);
|
|
58
|
+
setFileError(undefined);
|
|
59
|
+
setPartType("section");
|
|
60
|
+
setCopies(new Map());
|
|
61
|
+
setSession((n) => n + 1);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const run = React.useCallback(
|
|
66
|
+
() => importHtml(html, { media: (url: string) => copies.get(url) }),
|
|
67
|
+
[html, copies],
|
|
68
|
+
);
|
|
69
|
+
const result = React.useMemo(() => (html.trim() ? run() : undefined), [html, run]);
|
|
70
|
+
const oldImages = result?.ok ? result.images.filter((url) => !copies.has(url)) : [];
|
|
71
|
+
|
|
72
|
+
const create = async (title: string, slug: string) => {
|
|
73
|
+
const imported = html.trim() ? run() : undefined;
|
|
74
|
+
if (!imported?.ok) {
|
|
75
|
+
throw new ApiError(
|
|
76
|
+
400,
|
|
77
|
+
"IMPORT_EMPTY",
|
|
78
|
+
imported ? imported.error : "Choose or paste some HTML first.",
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
if (target === "part") {
|
|
82
|
+
const id = await createThemePart(fetcher, { title, slug, partType, layout: imported.layout });
|
|
83
|
+
return editorUrl(id, THEME_PARTS_COLLECTION);
|
|
84
|
+
}
|
|
85
|
+
return editorUrl(await createPage(fetcher, { title, slug, layout: imported.layout }));
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
return (
|
|
89
|
+
<CreateDialog
|
|
90
|
+
name="import-html"
|
|
91
|
+
heading="Import from WordPress or HTML"
|
|
92
|
+
noun={target === "part" ? "theme part" : "page"}
|
|
93
|
+
emptyTitle="Enter a title."
|
|
94
|
+
slugPrefix={target === "part" ? `${partType}-` : ""}
|
|
95
|
+
slugHint={
|
|
96
|
+
target === "part"
|
|
97
|
+
? "Tells theme parts apart. Theme parts have no public address."
|
|
98
|
+
: "The page's address on your site."
|
|
99
|
+
}
|
|
100
|
+
submitLabel="Import"
|
|
101
|
+
open={open}
|
|
102
|
+
onOpenChange={onOpenChange}
|
|
103
|
+
create={create}
|
|
104
|
+
{...(result?.ok && result.title ? { suggestedTitle: result.title } : {})}
|
|
105
|
+
>
|
|
106
|
+
<div className="emvb-import-source">
|
|
107
|
+
<p className="emvb-helper">
|
|
108
|
+
From WordPress, open the post or page, switch to the Code editor (⋮ → Code editor) and
|
|
109
|
+
copy everything. Or choose an .html file, or paste any page's source. You see what
|
|
110
|
+
will be kept before anything is created.
|
|
111
|
+
</p>
|
|
112
|
+
<div className="emvb-import-row">
|
|
113
|
+
<Button
|
|
114
|
+
type="button"
|
|
115
|
+
variant="secondary"
|
|
116
|
+
className={BUTTON}
|
|
117
|
+
icon={<FileArrowUpIcon aria-hidden="true" />}
|
|
118
|
+
onClick={() => fileRef.current?.click()}
|
|
119
|
+
>
|
|
120
|
+
Choose file
|
|
121
|
+
</Button>
|
|
122
|
+
<span className="emvb-helper" data-emvb-import-file="">
|
|
123
|
+
{fileName ?? "No file chosen"}
|
|
124
|
+
</span>
|
|
125
|
+
<input
|
|
126
|
+
ref={fileRef}
|
|
127
|
+
type="file"
|
|
128
|
+
accept="text/html,.html,.htm,text/plain,.txt"
|
|
129
|
+
hidden
|
|
130
|
+
data-emvb-html-file=""
|
|
131
|
+
onChange={(event) => {
|
|
132
|
+
const file = event.target.files?.[0];
|
|
133
|
+
event.target.value = "";
|
|
134
|
+
if (!file) return;
|
|
135
|
+
setFileError(undefined);
|
|
136
|
+
readHtmlFile(file).then(
|
|
137
|
+
(text) => {
|
|
138
|
+
setFileName(file.name);
|
|
139
|
+
setHtml(text);
|
|
140
|
+
},
|
|
141
|
+
(failure: unknown) =>
|
|
142
|
+
setFileError(
|
|
143
|
+
failure instanceof Error ? failure.message : "Couldn't read that file.",
|
|
144
|
+
),
|
|
145
|
+
);
|
|
146
|
+
}}
|
|
147
|
+
/>
|
|
148
|
+
</div>
|
|
149
|
+
{fileError && (
|
|
150
|
+
<p className="emvb-inline-error" role="alert">
|
|
151
|
+
{fileError}
|
|
152
|
+
</p>
|
|
153
|
+
)}
|
|
154
|
+
<label htmlFor="emvb-import-html" className="emvb-import-label">
|
|
155
|
+
Or paste the HTML
|
|
156
|
+
</label>
|
|
157
|
+
<textarea
|
|
158
|
+
id="emvb-import-html"
|
|
159
|
+
className={`${FIELD} emvb-import-json`}
|
|
160
|
+
rows={4}
|
|
161
|
+
spellCheck={false}
|
|
162
|
+
value={html}
|
|
163
|
+
placeholder="<!-- wp:paragraph --><p>…</p><!-- /wp:paragraph -->"
|
|
164
|
+
onChange={(event) => {
|
|
165
|
+
setFileName(undefined);
|
|
166
|
+
setHtml(event.target.value);
|
|
167
|
+
}}
|
|
168
|
+
/>
|
|
169
|
+
<ImportImageCopies
|
|
170
|
+
key={session}
|
|
171
|
+
fetcher={fetcher}
|
|
172
|
+
images={oldImages}
|
|
173
|
+
onCopied={(done) => setCopies((current) => new Map([...current, ...done]))}
|
|
174
|
+
dataAttribute="data-emvb-html-images"
|
|
175
|
+
/>
|
|
176
|
+
{target === "part" && (
|
|
177
|
+
<Select
|
|
178
|
+
label="Type"
|
|
179
|
+
className={FIELD}
|
|
180
|
+
value={partType}
|
|
181
|
+
onValueChange={(value) =>
|
|
182
|
+
setPartType(THEME_PART_TYPES.find((type) => type === value) ?? "section")
|
|
183
|
+
}
|
|
184
|
+
renderValue={(value: unknown) =>
|
|
185
|
+
THEME_PART_TYPE_LABELS[value as ThemePartType] ?? String(value)
|
|
186
|
+
}
|
|
187
|
+
>
|
|
188
|
+
{THEME_PART_TYPES.map((type) => (
|
|
189
|
+
<Select.Option key={type} value={type}>
|
|
190
|
+
{THEME_PART_TYPE_LABELS[type]}
|
|
191
|
+
</Select.Option>
|
|
192
|
+
))}
|
|
193
|
+
</Select>
|
|
194
|
+
)}
|
|
195
|
+
<ImportReport
|
|
196
|
+
result={result}
|
|
197
|
+
summary={
|
|
198
|
+
result?.ok
|
|
199
|
+
? `Ready to import ${result.mapped} of ${result.elements} ${result.source === "wordpress" ? "WordPress blocks" : "HTML elements"}` +
|
|
200
|
+
(target === "part"
|
|
201
|
+
? ` as a ${THEME_PART_TYPE_LABELS[partType].toLowerCase()}.`
|
|
202
|
+
: ".")
|
|
203
|
+
: ""
|
|
204
|
+
}
|
|
205
|
+
/>
|
|
206
|
+
</div>
|
|
207
|
+
</CreateDialog>
|
|
208
|
+
);
|
|
209
|
+
}
|