@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
|
@@ -230,7 +230,7 @@ export const loop: ElementDefinition<LoopNode> = {
|
|
|
230
230
|
label: "Image field",
|
|
231
231
|
optional: true,
|
|
232
232
|
message:
|
|
233
|
-
"The field Post image shows, such as photo. Leave it empty for the featured image.",
|
|
233
|
+
"The field Post image shows, such as photo. Leave it empty for the featured image, or else the collection's first image field.",
|
|
234
234
|
},
|
|
235
235
|
{
|
|
236
236
|
key: "excerptField",
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { ELEMENTS } from "./index.ts";
|
|
2
|
+
|
|
3
|
+
/** Words that keep their capitals in running text (acronyms, brands), as element names do. */
|
|
4
|
+
const KEEP = /^([A-Z0-9]{2,}s?|YouTube|Vimeo|Lottie|Markdown|Google|OpenStreetMap)$/;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* W-1091 (#39): plurals English can't guess from the name. Names already plural ("Tabs",
|
|
8
|
+
* "Social icons") are one element each, so several of them are sets.
|
|
9
|
+
*/
|
|
10
|
+
const PLURALS: Record<string, string> = {
|
|
11
|
+
"call to action": "calls to action",
|
|
12
|
+
"table of contents": "tables of contents",
|
|
13
|
+
tabs: "tab sets",
|
|
14
|
+
hotspots: "hotspot images",
|
|
15
|
+
"social icons": "social icon sets",
|
|
16
|
+
"share buttons": "share button sets",
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/** "icon-box" → "icon box": the element's name in running text, or its type when it has none. */
|
|
20
|
+
export function elementNoun(type: string): string {
|
|
21
|
+
const name = (ELEMENTS as Record<string, { descriptor: { name: string } } | undefined>)[type]
|
|
22
|
+
?.descriptor.name;
|
|
23
|
+
const words = (name ?? type.replaceAll(/[-_]+/g, " ")).trim().split(/\s+/);
|
|
24
|
+
return words.map((word) => (KEEP.test(word) ? word : word.toLowerCase())).join(" ");
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** English plural of the last word: box → boxes, gallery → galleries, SVG → SVGs. */
|
|
28
|
+
function pluralWord(word: string): string {
|
|
29
|
+
if (/^[A-Z0-9]{2,}$/.test(word)) return `${word}s`;
|
|
30
|
+
if (/(?:s|x|z|ch|sh)$/i.test(word)) return `${word}es`;
|
|
31
|
+
if (/[^aeiou]y$/i.test(word)) return `${word.slice(0, -1)}ies`;
|
|
32
|
+
return `${word}s`;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** "icon boxes": several of an element type, by its name. */
|
|
36
|
+
export function elementPlural(type: string): string {
|
|
37
|
+
const noun = elementNoun(type);
|
|
38
|
+
const irregular = PLURALS[noun];
|
|
39
|
+
if (irregular) return irregular;
|
|
40
|
+
const words = noun.split(" ");
|
|
41
|
+
const last = words.pop() ?? noun;
|
|
42
|
+
return [...words, pluralWord(last)].join(" ");
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** "icon box" for one, "12 icon boxes" for more. */
|
|
46
|
+
export function elementCount(type: string, n: number): string {
|
|
47
|
+
return n === 1 ? elementNoun(type) : `${n} ${elementPlural(type)}`;
|
|
48
|
+
}
|
package/src/core/export/site.ts
CHANGED
|
@@ -54,6 +54,9 @@ export type ExportPageInput = {
|
|
|
54
54
|
/** W-977: an entry of one of your collections: its public path and collection. */
|
|
55
55
|
path?: string;
|
|
56
56
|
collection?: string;
|
|
57
|
+
/** W-1091: the page's language and its translation group (EmDash i18n), when the site has them. */
|
|
58
|
+
locale?: string;
|
|
59
|
+
translationGroup?: string;
|
|
57
60
|
};
|
|
58
61
|
|
|
59
62
|
/** A published theme part as the content API returns it (`data` fields). */
|
|
@@ -30,6 +30,7 @@ export {
|
|
|
30
30
|
EXTENSION_PLACEHOLDER_CSS,
|
|
31
31
|
extensionPlaceholderLabel,
|
|
32
32
|
extensionPlaceholderVNode,
|
|
33
|
+
isExtensionPlaceholder,
|
|
33
34
|
} from "./placeholder.ts";
|
|
34
35
|
export { normalizeExtension } from "./normalize.ts";
|
|
35
36
|
export {
|
|
@@ -48,6 +49,7 @@ export {
|
|
|
48
49
|
export { safeExtensionOutput, extensionClassesOf, withExtensionClasses } from "./safe-nodes.ts";
|
|
49
50
|
export {
|
|
50
51
|
syncSourceValues,
|
|
52
|
+
resolveExtensionSource,
|
|
51
53
|
renderExtensionNode,
|
|
52
54
|
extensionOutputKey,
|
|
53
55
|
liveExtensionOutput,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Placeholder for a missing, throwing or illegal extension element (W-927, D-066).
|
|
3
|
-
*
|
|
4
|
-
* never breaks siblings.
|
|
3
|
+
* Shown in the editor and in admin previews; visitors get nothing in its place (W-1088, #37).
|
|
4
|
+
* Never runs extension code; never breaks siblings.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import type { VNode } from "../render/vnode.ts";
|
|
@@ -35,6 +35,11 @@ export function extensionPlaceholderVNode(
|
|
|
35
35
|
};
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
+
/** W-1088: true for the node `extensionPlaceholderVNode` builds. */
|
|
39
|
+
export function isExtensionPlaceholder(node: VNode): boolean {
|
|
40
|
+
return node.tag === "div" && node.attrs?.["class"] === "emvb-ext-missing";
|
|
41
|
+
}
|
|
42
|
+
|
|
38
43
|
/** Minimal CSS so the placeholder is readable without any extension stylesheet. */
|
|
39
44
|
export const EXTENSION_PLACEHOLDER_CSS =
|
|
40
45
|
".emvb-ext-missing{margin:0;padding:12px 16px;border:1px dashed currentColor;opacity:0.7;font:inherit}" +
|
|
@@ -11,6 +11,7 @@ import { safeExtensionOutput } from "./safe-nodes.ts";
|
|
|
11
11
|
import { extensionPlaceholderVNode } from "./placeholder.ts";
|
|
12
12
|
import type { ExtensionRenderContext } from "./types.ts";
|
|
13
13
|
import { parseExtensionType } from "./namespace.ts";
|
|
14
|
+
import { cleanBoundText } from "../data/bindings.ts";
|
|
14
15
|
|
|
15
16
|
export type ExtensionRenderMode = "public" | "editor";
|
|
16
17
|
|
|
@@ -18,23 +19,24 @@ function isThenable(value: unknown): value is Promise<unknown> {
|
|
|
18
19
|
return !!value && typeof (value as { then?: unknown }).then === "function";
|
|
19
20
|
}
|
|
20
21
|
|
|
21
|
-
|
|
22
|
+
/** Longest source value kept, in UTF-16 code units. */
|
|
23
|
+
const MAX_SOURCE_VALUE = 2000;
|
|
24
|
+
/** Values kept per source. */
|
|
25
|
+
const MAX_SOURCE_FIELDS = 32;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* A source's result with bad keys and non-string values dropped, and each value cleaned like a
|
|
29
|
+
* bound value (control characters and bidi overrides removed, length capped; W-1088).
|
|
30
|
+
*/
|
|
31
|
+
function cleanSourceRecord(raw: unknown): Record<string, string> {
|
|
22
32
|
const out: Record<string, string> = {};
|
|
33
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) return out;
|
|
23
34
|
let n = 0;
|
|
24
|
-
for (const [key, value] of Object.entries(raw)) {
|
|
25
|
-
if (n >=
|
|
26
|
-
if (
|
|
35
|
+
for (const [key, value] of Object.entries(raw as Record<string, unknown>)) {
|
|
36
|
+
if (n >= MAX_SOURCE_FIELDS) break;
|
|
37
|
+
if (!/^[a-zA-Z][a-zA-Z0-9_.-]{0,63}$/.test(key)) continue;
|
|
27
38
|
if (typeof value !== "string") continue;
|
|
28
|
-
|
|
29
|
-
for (const char of value) {
|
|
30
|
-
const code = char.codePointAt(0) ?? 0;
|
|
31
|
-
if (code === 9) cleaned += " ";
|
|
32
|
-
else if (code === 10 || (code >= 32 && code !== 127 && !(code >= 0x80 && code <= 0x9f))) {
|
|
33
|
-
cleaned += char;
|
|
34
|
-
}
|
|
35
|
-
if (cleaned.length >= 2000) break;
|
|
36
|
-
}
|
|
37
|
-
out[key] = cleaned.trim();
|
|
39
|
+
out[key] = cleanBoundText(value, MAX_SOURCE_VALUE);
|
|
38
40
|
n += 1;
|
|
39
41
|
}
|
|
40
42
|
return out;
|
|
@@ -52,7 +54,7 @@ export function syncSourceValues(pkg: string): Record<string, Record<string, str
|
|
|
52
54
|
try {
|
|
53
55
|
const result = source.resolve();
|
|
54
56
|
if (result && typeof result === "object" && !Array.isArray(result) && !isThenable(result)) {
|
|
55
|
-
out[source.name] = cleanSourceRecord(result
|
|
57
|
+
out[source.name] = cleanSourceRecord(result);
|
|
56
58
|
} else {
|
|
57
59
|
out[source.name] = {};
|
|
58
60
|
}
|
|
@@ -63,6 +65,38 @@ export function syncSourceValues(pkg: string): Record<string, Record<string, str
|
|
|
63
65
|
return out;
|
|
64
66
|
}
|
|
65
67
|
|
|
68
|
+
/** How long the editor waits for one source (W-1088). */
|
|
69
|
+
const SOURCE_TIMEOUT_MS = 5000;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* W-1088 (#36): one source's values for the editor's extension panels, awaited (a source may be
|
|
73
|
+
* async), cleaned like bound values. Undefined when the extension or source isn't live here, the
|
|
74
|
+
* resolver throws, or it takes longer than `timeoutMs`.
|
|
75
|
+
*/
|
|
76
|
+
export async function resolveExtensionSource(
|
|
77
|
+
pkg: string,
|
|
78
|
+
name: string,
|
|
79
|
+
timeoutMs = SOURCE_TIMEOUT_MS,
|
|
80
|
+
): Promise<Record<string, string> | undefined> {
|
|
81
|
+
const source = liveExtension(pkg)?.sources?.find((s) => s.name === name);
|
|
82
|
+
if (!source) return undefined;
|
|
83
|
+
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
84
|
+
try {
|
|
85
|
+
const result = await Promise.race([
|
|
86
|
+
Promise.resolve().then(() => source.resolve()),
|
|
87
|
+
new Promise<undefined>((resolve) => {
|
|
88
|
+
timer = setTimeout(() => resolve(undefined), timeoutMs);
|
|
89
|
+
}),
|
|
90
|
+
]);
|
|
91
|
+
if (!result || typeof result !== "object" || Array.isArray(result)) return undefined;
|
|
92
|
+
return cleanSourceRecord(result);
|
|
93
|
+
} catch {
|
|
94
|
+
return undefined;
|
|
95
|
+
} finally {
|
|
96
|
+
if (timer) clearTimeout(timer);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
66
100
|
export type VisitChildren = (nodes: LayoutNode[]) => VNode[];
|
|
67
101
|
|
|
68
102
|
const propsOf = (node: { props?: unknown }): Record<string, unknown> =>
|
|
@@ -63,6 +63,33 @@ export type ImportOptions = {
|
|
|
63
63
|
};
|
|
64
64
|
|
|
65
65
|
/** W-1026: one link of a site menu, with the links under it. */
|
|
66
|
+
/**
|
|
67
|
+
* W-1091 (#27): an Elementor Pro form as the forms plugin would hold it, so the import can say
|
|
68
|
+
* what needs connecting and (when asked) create it: its fields in order, by page when it has
|
|
69
|
+
* steps, with their Elementor types, and its messages. `nodeId` is the EmVB Form it became.
|
|
70
|
+
*/
|
|
71
|
+
export type ImportedFormField = {
|
|
72
|
+
name: string;
|
|
73
|
+
label: string;
|
|
74
|
+
/** A forms-plugin field type: text, email, tel, url, number, date, textarea, select, radio, checkbox. */
|
|
75
|
+
type: string;
|
|
76
|
+
required: boolean;
|
|
77
|
+
placeholder?: string;
|
|
78
|
+
options?: { label: string; value: string }[];
|
|
79
|
+
min?: number;
|
|
80
|
+
max?: number;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
export type ImportedForm = {
|
|
84
|
+
nodeId: string;
|
|
85
|
+
name: string;
|
|
86
|
+
pages: { title?: string; fields: ImportedFormField[] }[];
|
|
87
|
+
submitLabel: string;
|
|
88
|
+
successMessage?: string;
|
|
89
|
+
nextLabel?: string;
|
|
90
|
+
prevLabel?: string;
|
|
91
|
+
};
|
|
92
|
+
|
|
66
93
|
export type MenuLink = {
|
|
67
94
|
text: string;
|
|
68
95
|
href?: string;
|
|
@@ -112,6 +139,8 @@ export class ImportContext {
|
|
|
112
139
|
readonly menuOf: ImportOptions["menu"];
|
|
113
140
|
/** W-1026: the menu names the export's Nav Menus point at, so the dialog can fetch them. */
|
|
114
141
|
readonly menus = new Set<string>();
|
|
142
|
+
/** W-1091 (#27): the Elementor forms imported, to connect or create in the forms plugin. */
|
|
143
|
+
readonly forms: ImportedForm[] = [];
|
|
115
144
|
/** W-958: Elementor class id → its EmVB class, or undefined when it can't be one. */
|
|
116
145
|
readonly imported = new Map<string, ImportedClass | undefined>();
|
|
117
146
|
readonly useClasses: boolean;
|
|
@@ -13,7 +13,13 @@ import { atomicElement } from "./atomic.ts";
|
|
|
13
13
|
import { readSnapshots } from "./snapshots.ts";
|
|
14
14
|
import { customCss, wordRules } from "./css.ts";
|
|
15
15
|
import { type CounterItem, counterItems, counterOf } from "./counter-steps.ts";
|
|
16
|
-
import {
|
|
16
|
+
import {
|
|
17
|
+
ImportContext,
|
|
18
|
+
type ImportedForm,
|
|
19
|
+
type ImportNote,
|
|
20
|
+
type ImportOptions,
|
|
21
|
+
type StyleClass,
|
|
22
|
+
} from "./context.ts";
|
|
17
23
|
import {
|
|
18
24
|
boxReader,
|
|
19
25
|
deviceStyles,
|
|
@@ -39,7 +45,7 @@ import {
|
|
|
39
45
|
WIDGETS,
|
|
40
46
|
} from "./widgets.ts";
|
|
41
47
|
|
|
42
|
-
export type { ImportNote, ImportOptions } from "./context.ts";
|
|
48
|
+
export type { ImportedForm, ImportedFormField, ImportNote, ImportOptions } from "./context.ts";
|
|
43
49
|
|
|
44
50
|
/** Pasted or uploaded JSON larger than this is refused before parsing. */
|
|
45
51
|
export const MAX_IMPORT_CHARS = 8 * 1024 * 1024;
|
|
@@ -73,6 +79,11 @@ export type ElementorImport =
|
|
|
73
79
|
menus: string[];
|
|
74
80
|
/** W-958: images on the old site the page uses (`media` gives their library copies). */
|
|
75
81
|
images: string[];
|
|
82
|
+
/**
|
|
83
|
+
* W-1091 (#27): the Elementor forms the page has, each an EmVB Form (`nodeId`) that needs
|
|
84
|
+
* connecting to a forms-plugin form: their fields, types and messages, to list or create.
|
|
85
|
+
*/
|
|
86
|
+
forms: ImportedForm[];
|
|
76
87
|
/** W-958: with `classes`, the EmVB classes the page's elements point at, to add to the site. */
|
|
77
88
|
classes: StyleClass[];
|
|
78
89
|
}
|
|
@@ -927,12 +938,22 @@ export function importElementor(input: unknown, options: ImportOptions = {}): El
|
|
|
927
938
|
pageLinks: [...ctx.pageLinks].toSorted((a, b) => a - b),
|
|
928
939
|
menus: [...ctx.menus].toSorted(),
|
|
929
940
|
images: [...ctx.images],
|
|
941
|
+
forms: ctx.forms.filter((f) => hasNode(checked.layout.root, f.nodeId)),
|
|
930
942
|
classes: usedClasses(checked.layout, ctx).map((cls) =>
|
|
931
943
|
options.media ? (pointAtCopies(structuredClone(cls), ctx) as StyleClass) : cls,
|
|
932
944
|
),
|
|
933
945
|
};
|
|
934
946
|
}
|
|
935
947
|
|
|
948
|
+
/** Whether the layout still holds the node (pruning may have dropped it). */
|
|
949
|
+
function hasNode(tree: { id: string; children?: unknown }, id: string): boolean {
|
|
950
|
+
if (tree.id === id) return true;
|
|
951
|
+
return (
|
|
952
|
+
Array.isArray(tree.children) &&
|
|
953
|
+
tree.children.some((child) => hasNode(child as { id: string; children?: unknown }, id))
|
|
954
|
+
);
|
|
955
|
+
}
|
|
956
|
+
|
|
936
957
|
/**
|
|
937
958
|
* The imported tree as a layout EmVB accepts: whatever validation or the nesting rules refuse is
|
|
938
959
|
* pruned (and noted) until it passes. Shared with the HTML import (W-1074).
|
|
@@ -8,7 +8,13 @@ import { MAX_TABS, MAX_TEXT_LENGTH } from "../../limits.ts";
|
|
|
8
8
|
import { FIELD_NAME_PATTERN, ICON_SVG_MAX, MAX_INPUT_NUMBER } from "../../schema/layout.ts";
|
|
9
9
|
import { sanitizeHref } from "../../sanitize/href.ts";
|
|
10
10
|
import { sanitizeMediaUrl } from "../../sanitize/media-url.ts";
|
|
11
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
type ImportContext,
|
|
13
|
+
type ImportedForm,
|
|
14
|
+
type ImportedFormField,
|
|
15
|
+
type MenuLink,
|
|
16
|
+
svgFileId,
|
|
17
|
+
} from "./context.ts";
|
|
12
18
|
import {
|
|
13
19
|
type Block,
|
|
14
20
|
cleanText,
|
|
@@ -1526,13 +1532,82 @@ function typedField(type: string, raw: Settings): Record<string, unknown> {
|
|
|
1526
1532
|
|
|
1527
1533
|
const MAX_FORM_STEPS = 20;
|
|
1528
1534
|
|
|
1535
|
+
/** W-1091 (#27): the forms plugin's field type for an Elementor field type. */
|
|
1536
|
+
const PLUGIN_FIELD_TYPES: Record<string, string> = {
|
|
1537
|
+
text: "text",
|
|
1538
|
+
email: "email",
|
|
1539
|
+
url: "url",
|
|
1540
|
+
tel: "tel",
|
|
1541
|
+
number: "number",
|
|
1542
|
+
date: "date",
|
|
1543
|
+
time: "text",
|
|
1544
|
+
password: "text",
|
|
1545
|
+
textarea: "textarea",
|
|
1546
|
+
select: "select",
|
|
1547
|
+
radio: "radio",
|
|
1548
|
+
checkbox: "checkbox",
|
|
1549
|
+
acceptance: "checkbox",
|
|
1550
|
+
};
|
|
1551
|
+
|
|
1552
|
+
/**
|
|
1553
|
+
* W-1091 (#27): a field name the forms plugin accepts (a letter, then letters, digits, `_`, `-`):
|
|
1554
|
+
* Elementor's own id when it has one, cleaned up, else the label's words, else the field type.
|
|
1555
|
+
* Each name is used once per form; a repeat gets `_2`, `_3`.
|
|
1556
|
+
*/
|
|
1557
|
+
function formFieldName(
|
|
1558
|
+
candidates: readonly { text: string | undefined; lower?: boolean }[],
|
|
1559
|
+
taken: ReadonlySet<string>,
|
|
1560
|
+
fallback: string,
|
|
1561
|
+
): string {
|
|
1562
|
+
let base = "";
|
|
1563
|
+
for (const { text, lower } of candidates) {
|
|
1564
|
+
const clean = (text ?? "")
|
|
1565
|
+
.normalize("NFKD")
|
|
1566
|
+
.replaceAll(/[\u0300-\u036f]/g, "")
|
|
1567
|
+
.trim()
|
|
1568
|
+
.replaceAll(/[^a-zA-Z0-9_-]+/g, "_")
|
|
1569
|
+
.replace(/^[^a-zA-Z]+/, "")
|
|
1570
|
+
.replace(/[_-]+$/, "")
|
|
1571
|
+
.slice(0, 72);
|
|
1572
|
+
if (clean && FIELD_NAME_PATTERN.test(clean)) {
|
|
1573
|
+
base = lower ? clean.toLowerCase() : clean;
|
|
1574
|
+
break;
|
|
1575
|
+
}
|
|
1576
|
+
}
|
|
1577
|
+
base ||= fallback;
|
|
1578
|
+
let name = base;
|
|
1579
|
+
for (let n = 2; taken.has(name); n++) name = `${base}_${n}`;
|
|
1580
|
+
return name;
|
|
1581
|
+
}
|
|
1582
|
+
|
|
1583
|
+
/** W-1091 (#27): Elementor's `field_options` lines ("Label" or "Label|value") as options. */
|
|
1584
|
+
function formOptions(value: unknown): { label: string; value: string }[] {
|
|
1585
|
+
const options: { label: string; value: string }[] = [];
|
|
1586
|
+
const seen = new Set<string>();
|
|
1587
|
+
for (const line of (str(value) ?? "").split(/\r?\n/).slice(0, 100)) {
|
|
1588
|
+
const [rawLabel = "", rawValue] = line.split("|");
|
|
1589
|
+
const label = plain(rawLabel).text.trim().slice(0, 200);
|
|
1590
|
+
const option = (rawValue === undefined ? label : plain(rawValue).text.trim()).slice(0, 200);
|
|
1591
|
+
if (!label || !option || seen.has(option)) continue;
|
|
1592
|
+
seen.add(option);
|
|
1593
|
+
options.push({ label, value: option });
|
|
1594
|
+
}
|
|
1595
|
+
return options;
|
|
1596
|
+
}
|
|
1597
|
+
|
|
1598
|
+
const isOn = (value: unknown) => value === true || value === "true" || value === "yes";
|
|
1599
|
+
|
|
1529
1600
|
const form: Widget = (s, ctx, el) => {
|
|
1530
1601
|
const fields = Array.isArray(s["form_fields"]) ? s["form_fields"].slice(0, 100) : [];
|
|
1531
1602
|
const loose: N[] = [];
|
|
1532
1603
|
const steps: { title: string; children: N[] }[] = [];
|
|
1604
|
+
// W-1091 (#27): the same fields as the forms plugin holds them, page by page.
|
|
1605
|
+
const loosePlan: ImportedFormField[] = [];
|
|
1606
|
+
const stepPlans: ImportedFormField[][] = [];
|
|
1533
1607
|
const names = new Set<string>();
|
|
1534
1608
|
let nextLabel = "";
|
|
1535
1609
|
let prevLabel = "";
|
|
1610
|
+
let checkboxLists = 0;
|
|
1536
1611
|
fields.forEach((raw, i) => {
|
|
1537
1612
|
if (!isRecord(raw)) return;
|
|
1538
1613
|
const type = str(raw["field_type"]) ?? "text";
|
|
@@ -1540,6 +1615,7 @@ const form: Widget = (s, ctx, el) => {
|
|
|
1540
1615
|
if (type === "step") {
|
|
1541
1616
|
if (steps.length >= MAX_FORM_STEPS) return;
|
|
1542
1617
|
steps.push({ title: plain(raw["field_label"]).text.slice(0, 200), children: [] });
|
|
1618
|
+
stepPlans.push([]);
|
|
1543
1619
|
nextLabel ||= plain(raw["next_button"]).text.slice(0, 80);
|
|
1544
1620
|
prevLabel ||= plain(raw["previous_button"]).text.slice(0, 80);
|
|
1545
1621
|
return;
|
|
@@ -1549,13 +1625,16 @@ const form: Widget = (s, ctx, el) => {
|
|
|
1549
1625
|
ctx.note("skipped", el, `Form field type "${type}" was left out.`);
|
|
1550
1626
|
return;
|
|
1551
1627
|
}
|
|
1552
|
-
let name = str(raw["custom_id"]) ?? "";
|
|
1553
|
-
if (!FIELD_NAME_PATTERN.test(name) || name.length > 80 || names.has(name))
|
|
1554
|
-
name = `field_${i + 1}`;
|
|
1555
|
-
names.add(name);
|
|
1556
1628
|
const label =
|
|
1557
1629
|
plain(raw["field_label"]).text.slice(0, 200) ||
|
|
1558
1630
|
(type === "acceptance" ? plain(raw["acceptance_text"]).text.slice(0, 200) : "");
|
|
1631
|
+
// W-1091 (#27): Elementor's field id (cleaned), else the label, so `name` and `email` stay.
|
|
1632
|
+
const name = formFieldName(
|
|
1633
|
+
[{ text: str(raw["custom_id"]) }, { text: label, lower: true }, { text: type }],
|
|
1634
|
+
names,
|
|
1635
|
+
`field_${i + 1}`,
|
|
1636
|
+
);
|
|
1637
|
+
names.add(name);
|
|
1559
1638
|
const placeholder = plain(raw["placeholder"]).text.slice(0, 200);
|
|
1560
1639
|
const field = node(ctx, nodeType, {
|
|
1561
1640
|
field: name,
|
|
@@ -1563,12 +1642,34 @@ const form: Widget = (s, ctx, el) => {
|
|
|
1563
1642
|
...(placeholder && nodeType !== "checkbox" ? { placeholder } : {}),
|
|
1564
1643
|
...typedField(type, raw),
|
|
1565
1644
|
});
|
|
1645
|
+
const options =
|
|
1646
|
+
nodeType === "select" || nodeType === "radio" ? formOptions(raw["field_options"]) : [];
|
|
1647
|
+
if (type === "checkbox" && formOptions(raw["field_options"]).length > 1) checkboxLists += 1;
|
|
1648
|
+
const typed = typedField(type, raw) as { min?: number; max?: number };
|
|
1649
|
+
const planned: ImportedFormField = {
|
|
1650
|
+
name,
|
|
1651
|
+
label: label || name,
|
|
1652
|
+
type: PLUGIN_FIELD_TYPES[type] ?? "text",
|
|
1653
|
+
required: isOn(raw["required"]) || type === "acceptance",
|
|
1654
|
+
...(placeholder && nodeType !== "checkbox" ? { placeholder } : {}),
|
|
1655
|
+
...(options.length > 0 ? { options } : {}),
|
|
1656
|
+
...(typed.min !== undefined ? { min: typed.min } : {}),
|
|
1657
|
+
...(typed.max !== undefined ? { max: typed.max } : {}),
|
|
1658
|
+
};
|
|
1566
1659
|
const step = steps[steps.length - 1];
|
|
1567
|
-
if (step)
|
|
1568
|
-
|
|
1660
|
+
if (step) {
|
|
1661
|
+
step.children.push(field);
|
|
1662
|
+
stepPlans[stepPlans.length - 1]?.push(planned);
|
|
1663
|
+
} else {
|
|
1664
|
+
loose.push(field);
|
|
1665
|
+
loosePlan.push(planned);
|
|
1666
|
+
}
|
|
1569
1667
|
});
|
|
1570
1668
|
// Fields before the first Step field are a step of their own, as Elementor shows them.
|
|
1571
|
-
if (steps.length > 0 && loose.length > 0)
|
|
1669
|
+
if (steps.length > 0 && loose.length > 0) {
|
|
1670
|
+
steps.unshift({ title: "", children: loose.splice(0) });
|
|
1671
|
+
stepPlans.unshift(loosePlan.splice(0));
|
|
1672
|
+
}
|
|
1572
1673
|
const children: N[] = [
|
|
1573
1674
|
...loose,
|
|
1574
1675
|
...steps.map((step) =>
|
|
@@ -1580,8 +1681,11 @@ const form: Widget = (s, ctx, el) => {
|
|
|
1580
1681
|
ctx.note(
|
|
1581
1682
|
"approximated",
|
|
1582
1683
|
el,
|
|
1583
|
-
"
|
|
1684
|
+
"Each form needs connecting to an EmDash form before it shows on your site; the import can create it in EmDash Forms. Email actions weren't imported.",
|
|
1584
1685
|
);
|
|
1686
|
+
if (checkboxLists > 0) {
|
|
1687
|
+
ctx.note("approximated", el, "A checkbox list became one checkbox; its options weren't kept.");
|
|
1688
|
+
}
|
|
1585
1689
|
if (steps.length > 0) {
|
|
1586
1690
|
ctx.note(
|
|
1587
1691
|
"approximated",
|
|
@@ -1593,14 +1697,30 @@ const form: Widget = (s, ctx, el) => {
|
|
|
1593
1697
|
...(steps.length > 0 && nextLabel ? { nextLabel } : {}),
|
|
1594
1698
|
...(steps.length > 0 && prevLabel ? { prevLabel } : {}),
|
|
1595
1699
|
};
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1700
|
+
const built = node(
|
|
1701
|
+
ctx,
|
|
1702
|
+
"form",
|
|
1703
|
+
{ formId: "", ...labels },
|
|
1704
|
+
{ style: { gap: { value: 10, unit: "px" } }, children },
|
|
1705
|
+
);
|
|
1706
|
+
const successMessage = plain(s["success_message"]).text.trim().slice(0, 500);
|
|
1707
|
+
const plan: ImportedForm = {
|
|
1708
|
+
nodeId: built.id,
|
|
1709
|
+
name: plain(s["form_name"]).text.trim().slice(0, 200) || "Imported form",
|
|
1710
|
+
pages:
|
|
1711
|
+
steps.length > 0
|
|
1712
|
+
? steps.map((step, i) =>
|
|
1713
|
+
step.title
|
|
1714
|
+
? { title: step.title, fields: stepPlans[i] ?? [] }
|
|
1715
|
+
: { fields: stepPlans[i] ?? [] },
|
|
1716
|
+
)
|
|
1717
|
+
: [{ fields: loosePlan }],
|
|
1718
|
+
submitLabel: label,
|
|
1719
|
+
...(successMessage ? { successMessage } : {}),
|
|
1720
|
+
...labels,
|
|
1721
|
+
};
|
|
1722
|
+
if (ctx.forms.length < 50) ctx.forms.push(plan);
|
|
1723
|
+
return [built];
|
|
1604
1724
|
};
|
|
1605
1725
|
|
|
1606
1726
|
/** W-1026: a site menu's links as Menu items (three levels, as the Menu shows). */
|
package/src/core/index.ts
CHANGED
|
@@ -478,6 +478,13 @@ export {
|
|
|
478
478
|
type ArchivePagination,
|
|
479
479
|
type PaginationItem,
|
|
480
480
|
} from "./theme/pagination.ts";
|
|
481
|
+
export {
|
|
482
|
+
DEFAULT_IMAGE_FIELD,
|
|
483
|
+
automaticImageField,
|
|
484
|
+
entryImageValue,
|
|
485
|
+
imageFieldsOf,
|
|
486
|
+
mediaUrlOf,
|
|
487
|
+
} from "./theme/media-value.ts";
|
|
481
488
|
|
|
482
489
|
export { layoutHasMenuDropdown, layoutHasTabs } from "./tabs/presence.ts";
|
|
483
490
|
export {
|
|
@@ -628,6 +635,8 @@ export {
|
|
|
628
635
|
export { portableTextToLayout } from "./portable-text.ts";
|
|
629
636
|
export {
|
|
630
637
|
type ElementorImport,
|
|
638
|
+
type ImportedForm,
|
|
639
|
+
type ImportedFormField,
|
|
631
640
|
type ImportNote,
|
|
632
641
|
type ImportOptions,
|
|
633
642
|
importElementor,
|
package/src/core/render/index.ts
CHANGED
|
@@ -69,6 +69,7 @@ import {
|
|
|
69
69
|
extensionStylesheets,
|
|
70
70
|
isExtensionType,
|
|
71
71
|
renderExtensionNode,
|
|
72
|
+
isExtensionPlaceholder,
|
|
72
73
|
EXTENSION_PLACEHOLDER_CSS,
|
|
73
74
|
type ExtensionOutputs,
|
|
74
75
|
} from "../extensions/index.ts";
|
|
@@ -351,6 +352,12 @@ export function renderPage(
|
|
|
351
352
|
* `extensions`.
|
|
352
353
|
*/
|
|
353
354
|
separateExtensionCss?: boolean;
|
|
355
|
+
/**
|
|
356
|
+
* W-1088 (#37): public renders show the placeholder for an extension element that can't
|
|
357
|
+
* render (missing, throwing or illegal output). For the admin's previews of the public page;
|
|
358
|
+
* visitors get nothing in its place. The editor always shows it.
|
|
359
|
+
*/
|
|
360
|
+
extensionPlaceholders?: boolean;
|
|
354
361
|
} = {},
|
|
355
362
|
): RenderResult {
|
|
356
363
|
const mode = opts.mode ?? "public";
|
|
@@ -737,8 +744,7 @@ export function renderPage(
|
|
|
737
744
|
if (!Object.hasOwn(ELEMENTS, type)) {
|
|
738
745
|
// W-927: extension elements render via the Extensions API, or a placeholder when missing.
|
|
739
746
|
if (isExtensionType(type)) {
|
|
740
|
-
|
|
741
|
-
return renderExtensionNode(
|
|
747
|
+
const ext = renderExtensionNode(
|
|
742
748
|
node,
|
|
743
749
|
mode === "editor" ? "editor" : "public",
|
|
744
750
|
(nodes) =>
|
|
@@ -748,6 +754,13 @@ export function renderPage(
|
|
|
748
754
|
opts.extensionOutputs,
|
|
749
755
|
(pkg) => extensionsUsed.add(pkg),
|
|
750
756
|
);
|
|
757
|
+
// W-1088 (#37): visitors get nothing for an extension element that can't render; the
|
|
758
|
+
// stored element is kept and renders again once its extension is back.
|
|
759
|
+
if (mode === "public" && !opts.extensionPlaceholders && isExtensionPlaceholder(ext)) {
|
|
760
|
+
return undefined;
|
|
761
|
+
}
|
|
762
|
+
usedTypes.add("ext");
|
|
763
|
+
return ext;
|
|
751
764
|
}
|
|
752
765
|
warnings.push({ nodeId, code: "unknown-type", detail: type });
|
|
753
766
|
if (mode === "public") return undefined;
|
|
@@ -711,7 +711,10 @@ export const LoopNode = parentNode(
|
|
|
711
711
|
.max(200)
|
|
712
712
|
.regex(LOOP_PERMALINK, "A site path with {slug} or {id}, such as /team/{slug}")
|
|
713
713
|
.optional(),
|
|
714
|
-
/**
|
|
714
|
+
/**
|
|
715
|
+
* The entry field holding the image Post Image shows (W-330). Unset = featured_image, else the
|
|
716
|
+
* entry's first image field (W-1090).
|
|
717
|
+
*/
|
|
715
718
|
imageField: z.string().regex(FIELD_SLUG, FIELD_SLUG_HINT).optional(),
|
|
716
719
|
/** The entry field Post Excerpt shows (W-330). Unset = excerpt. */
|
|
717
720
|
excerptField: z.string().regex(FIELD_SLUG, FIELD_SLUG_HINT).optional(),
|