@perkyzz/emvb 1.4.0 → 1.4.2

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.
Files changed (57) hide show
  1. package/README.md +2 -2
  2. package/package.json +6 -6
  3. package/src/admin/content-item.ts +3 -0
  4. package/src/admin/copy-rich-text.ts +99 -9
  5. package/src/admin/editor/Editor.tsx +7 -2
  6. package/src/admin/editor/collection-previews.ts +7 -8
  7. package/src/admin/editor/extensions/ExtensionPanels.tsx +33 -1
  8. package/src/admin/editor/extensions-context.tsx +16 -1
  9. package/src/admin/editor/feature-css.ts +5 -0
  10. package/src/admin/editor/panels/ConditionsEditor.tsx +18 -0
  11. package/src/admin/editor/panels/ElementPanel.tsx +2 -2
  12. package/src/admin/editor/panels/settings/FieldControl.tsx +15 -0
  13. package/src/admin/editor/panels/settings/FormBindControl.tsx +27 -31
  14. package/src/admin/editor/panels/settings/ImageFieldControl.tsx +106 -0
  15. package/src/admin/editor/panels/settings/loop-context.ts +34 -3
  16. package/src/admin/export-api.ts +2 -0
  17. package/src/admin/extension-outputs.ts +57 -0
  18. package/src/admin/import-forms.ts +133 -0
  19. package/src/admin/pages/ImportElementorDialog.tsx +32 -0
  20. package/src/admin/pages/ImportForms.tsx +71 -0
  21. package/src/admin/setup/plan.ts +2 -0
  22. package/src/admin/ui.ts +7 -0
  23. package/src/admin/widgets/ConvertToRichText.tsx +3 -2
  24. package/src/astro/render.ts +11 -0
  25. package/src/astro/resolve-theme.ts +11 -15
  26. package/src/astro/resolve.ts +2 -0
  27. package/src/astro/theme-posts.ts +17 -23
  28. package/src/astro/visitor.ts +14 -5
  29. package/src/astro/widgets/sticky.ts +4 -1
  30. package/src/constants.ts +1 -1
  31. package/src/core/css/generate.ts +6 -1
  32. package/src/core/css/trace.ts +8 -0
  33. package/src/core/data/bindings.ts +7 -4
  34. package/src/core/elements/dynamic-elements.ts +1 -1
  35. package/src/core/elements/element-nouns.ts +48 -0
  36. package/src/core/export/runtimes.generated.ts +1 -1
  37. package/src/core/export/site.ts +7 -11
  38. package/src/core/extensions/index.ts +2 -0
  39. package/src/core/extensions/placeholder.ts +7 -2
  40. package/src/core/extensions/render-ext.ts +49 -15
  41. package/src/core/import/elementor/context.ts +29 -0
  42. package/src/core/import/elementor/index.ts +23 -2
  43. package/src/core/import/elementor/widgets.ts +137 -17
  44. package/src/core/index.ts +11 -0
  45. package/src/core/render/index.ts +30 -2
  46. package/src/core/schema/layout.ts +4 -1
  47. package/src/core/theme/media-value.ts +88 -0
  48. package/src/core/theme/part-wrapper.ts +100 -0
  49. package/src/core/visitor-cookie.ts +91 -0
  50. package/src/index.ts +28 -1
  51. package/src/mcp/agent-defaults.ts +40 -0
  52. package/src/mcp/extensions.ts +138 -0
  53. package/src/mcp/read.ts +55 -19
  54. package/src/mcp/tools.ts +3 -3
  55. package/src/mcp/write.ts +83 -8
  56. package/src/server/extension-routes.ts +37 -0
  57. package/src/server/plugin.ts +7 -1
@@ -2,7 +2,6 @@ import { emdashContent, type ContentPort } from "./content-port.ts";
2
2
  import { formIdsInLayouts } from "./forms-definitions.ts";
3
3
  import {
4
4
  collectLoopItemPartIds,
5
- escapeAttr,
6
5
  collectSectionPartIds,
7
6
  contentPartTypeForContext,
8
7
  defaultConditions,
@@ -20,6 +19,7 @@ import {
20
19
  validateTriggers,
21
20
  wrapFloatMarkup,
22
21
  wrapPopupMarkup,
22
+ wrapThemePart,
23
23
  type ChromeLabels,
24
24
  type FloatSettings,
25
25
  type Layout,
@@ -47,12 +47,6 @@ import { decodePathSegment, themeContextFrom } from "./theme-context.ts";
47
47
  import { entryTimestamp, themePostFromEntry } from "./theme-posts.ts";
48
48
  import { probeCounter, totalPagesFor, type PostCounter } from "./page-count.ts";
49
49
 
50
- /** The landmark element for a part's wrapper (W-216); other parts get a plain div. */
51
- const WRAPPER_TAGS: Partial<Record<string, "header" | "footer">> = {
52
- header: "header",
53
- footer: "footer",
54
- };
55
-
56
50
  export type RenderedThemePart = {
57
51
  id: string;
58
52
  title: string;
@@ -559,6 +553,8 @@ export async function resolveThemePartsWith(
559
553
  const rendered: RenderedPage[] = [];
560
554
  // W-971: each part's scoped sheet, to write the shared rules once in `css`.
561
555
  const sheets = new Map<string, { css: string; scope: string; baseTypes: readonly string[] }>();
556
+ // W-1097: sticky header and footer wrappers' rules, after the parts' own sheets.
557
+ const wrapperCss: string[] = [];
562
558
  // W-307: bound fields in a part read site settings and URL parameters too.
563
559
  // W-312/W-313: synced sections and Loop items the part uses count too.
564
560
  const boundFor = (stored: StoredPart, referenced: ThemeDynamicData | undefined) =>
@@ -608,14 +604,14 @@ export async function resolveThemePartsWith(
608
604
  // straight in <body> instead of their own <header>/<footer>).
609
605
  // W-586: a part that already has its own header or footer box keeps that one as the landmark;
610
606
  // a second wrapper around it would nest <header> in <header> (invalid, two banners).
611
- const ownLandmark = /<(?:header|footer)[\s>]/.test(page.html);
612
- const tag = (!ownLandmark && WRAPPER_TAGS[stored.partType]) || "div";
613
- const partId = escapeAttr(stored.id);
614
- const html = page.html
615
- ? `<${tag} class="emvb-theme-${stored.partType}" data-emvb-theme-part="${partId}">${page.html}</${tag}>`
616
- : "";
607
+ // W-1097: a sticky top-level box makes the wrapper sticky (`wrapper.css`, else empty).
608
+ const wrapper = wrapThemePart(stored.partType, stored.id, page.html, page.stickyFrame);
609
+ if (wrapper.css) wrapperCss.push(wrapper.css);
617
610
  // W-1086: a part's own css stays whole; the shared `css` below writes extension sheets once.
618
- return { html, css: page.css + extensionStylesheets(page.extensions ?? []) };
611
+ return {
612
+ html: wrapper.html,
613
+ css: page.css + extensionStylesheets(page.extensions ?? []) + wrapper.css,
614
+ };
619
615
  };
620
616
 
621
617
  /** Synced sections and loop items a part uses, for every part type (W-200). */
@@ -756,7 +752,7 @@ export async function resolveThemePartsWith(
756
752
  const sheet = part ? sheets.get(part.id) : undefined;
757
753
  return sheet ? [sheet] : [];
758
754
  });
759
- const cssParts = [sharedPartCss(ordered)];
755
+ const cssParts = [sharedPartCss(ordered), ...wrapperCss];
760
756
  // W-1086: each extension stylesheet once for all the parts; the page in this response skips them.
761
757
  const extensionIds = [...new Set(rendered.flatMap((page) => page.extensions ?? []))].toSorted();
762
758
  cssParts.push(extensionStylesheets(extensionIds));
@@ -202,6 +202,8 @@ export async function resolveEmVBPageWith(
202
202
  Object.keys(dynamic).length > 0 ? dynamic : undefined,
203
203
  false,
204
204
  options.lang ?? found.fallbackLocale ?? locale,
205
+ // W-1088 (#37): a draft preview (editors) keeps the missing-extension note.
206
+ Boolean(found.isPreview),
205
207
  ),
206
208
  entry,
207
209
  collection: hosted ? (options.collection as string) : PAGES_COLLECTION,
@@ -1,30 +1,23 @@
1
- import { clipText, loopPermalink, type ThemePostFields } from "../core/index.ts";
1
+ import {
2
+ clipText,
3
+ entryImageValue,
4
+ loopPermalink,
5
+ mediaUrlOf,
6
+ type ThemePostFields,
7
+ } from "../core/index.ts";
2
8
 
3
- type MediaLike = {
4
- src?: unknown;
5
- url?: unknown;
6
- previewUrl?: unknown;
7
- alt?: unknown;
8
- };
9
-
10
- /** Pull a sanitized-ready image URL + alt from an EmDash media / image field value. */
9
+ /**
10
+ * Pull a sanitized-ready image URL + alt from an EmDash media / image field value. W-1090 (#32):
11
+ * a local upload picked in EmDash's admin has no `src`, only its storage key.
12
+ */
11
13
  export function mediaFieldsFrom(value: unknown): {
12
14
  featuredImageUrl?: string;
13
15
  featuredImageAlt?: string;
14
16
  } {
15
17
  if (!value || typeof value !== "object") return {};
16
- const media = value as MediaLike;
17
- const candidates = [media.src, media.url, media.previewUrl];
18
- let featuredImageUrl: string | undefined;
19
- for (const candidate of candidates) {
20
- if (typeof candidate === "string" && candidate.trim()) {
21
- featuredImageUrl = candidate.trim();
22
- break;
23
- }
24
- }
25
- const featuredImageAlt =
26
- typeof media.alt === "string" && media.alt.trim() ? media.alt.trim() : undefined;
27
- return { featuredImageUrl, featuredImageAlt };
18
+ const alt = (value as { alt?: unknown }).alt;
19
+ const featuredImageAlt = typeof alt === "string" && alt.trim() ? alt.trim() : undefined;
20
+ return { featuredImageUrl: mediaUrlOf(value), featuredImageAlt };
28
21
  }
29
22
 
30
23
  /**
@@ -46,7 +39,7 @@ export function themePostFromEntry(
46
39
  permalinkPrefix?: string;
47
40
  /** W-330: a Loop's link pattern, e.g. `/team/{slug}`. */
48
41
  permalinkPattern?: string;
49
- /** W-330: the field with the entry's image, instead of `featured_image`. */
42
+ /** W-330: the field with the entry's image, instead of the automatic one (W-1090). */
50
43
  imageField?: string;
51
44
  /** W-330: the field with the entry's excerpt, instead of `excerpt`. */
52
45
  excerptField?: string;
@@ -67,7 +60,8 @@ export function themePostFromEntry(
67
60
  const permalink = options.permalinkPattern
68
61
  ? loopPermalink(options.permalinkPattern, { slug: slug || id, id: id || slug })
69
62
  : `${prefix.replace(/\/$/, "")}/${slug || id}`;
70
- const media = mediaFieldsFrom(data[options.imageField ?? "featured_image"]);
63
+ // W-1090 (#32): unset reads featured_image, else the entry's first image field.
64
+ const media = mediaFieldsFrom(entryImageValue(data, options.imageField));
71
65
  // W-303: EmDash's own publish date is `data.publishedAt`, a `Date`; a custom field may be text.
72
66
  const publishedAt = ["published_at", "publishedAt", "date"]
73
67
  .map((key) => entryTimestamp(data[key]))
@@ -1,4 +1,5 @@
1
1
  import { geoTrust } from "../core/geo-trust.ts";
2
+ import { visitorCookie, visitorCookieAllowed } from "../core/visitor-cookie.ts";
2
3
  import {
3
4
  AUDIENCE_SEGMENT,
4
5
  abCookieName,
@@ -190,7 +191,8 @@ export function hostVisitorFacts(host: HostVisitor | undefined): Partial<Visitor
190
191
 
191
192
  /**
192
193
  * What the server knows about this visitor, for visitor-aware elements (W-313): country from
193
- * the edge, device from the User-Agent, new or returning from a first-party cookie, and the time.
194
+ * the edge, device from the User-Agent, new or returning from a first-party cookie (when
195
+ * `emvb({ visitorCookie })` allows it, W-1092), and the time.
194
196
  * Facts the host passes (W-329) win over detected ones. Only read when the layout has a rule.
195
197
  */
196
198
  export function visitorFor(
@@ -205,13 +207,20 @@ export function visitorFor(
205
207
  if (country) visitor.country = country;
206
208
  const device = deviceFromUserAgent(headers?.get("user-agent"), headers?.get("sec-ch-ua-mobile"));
207
209
  if (device) visitor.device = device;
210
+ // W-1092 (#34): only a new/returning rule reads or sets the cookie, and only when
211
+ // `emvb({ visitorCookie })` allows it for this request. Otherwise everyone counts as new.
208
212
  if (astro.cookies && layoutUsesVisitorRule(layout)) {
209
- visitor.returning = requestCookie(astro, SEEN_COOKIE) === "1";
210
- if (!visitor.returning) {
213
+ const cookieAllowed = visitorCookieAllowed(visitorCookie(), (name) =>
214
+ requestCookie(astro, name),
215
+ );
216
+ const seen = requestCookie(astro, SEEN_COOKIE);
217
+ visitor.returning = cookieAllowed && seen === "1";
218
+ if (cookieAllowed ? !visitor.returning : seen !== undefined) {
211
219
  try {
212
- astro.cookies.set(SEEN_COOKIE, "1", {
220
+ // Without consent (or in "never" mode) a cookie left from before is cleared.
221
+ astro.cookies.set(SEEN_COOKIE, cookieAllowed ? "1" : "", {
213
222
  path: "/",
214
- maxAge: SEEN_DAYS * 86_400,
223
+ maxAge: cookieAllowed ? SEEN_DAYS * 86_400 : 0,
215
224
  sameSite: "lax",
216
225
  httpOnly: true,
217
226
  secure: astro.url.protocol === "https:",
@@ -46,8 +46,11 @@ function heldAtBottom(el: HTMLElement): boolean {
46
46
  }
47
47
 
48
48
  export function initSticky(root: ParentNode = document): void {
49
+ // W-1097: a sticky header or footer part's wrapper hides for its box; the box stays in it.
49
50
  const all = [...root.querySelectorAll<HTMLElement>("[data-emvb-sticky-hide]")].filter(
50
- (el) => el.dataset["emvbReady"] === undefined,
51
+ (el) =>
52
+ el.dataset["emvbReady"] === undefined &&
53
+ !el.parentElement?.closest("[data-emvb-sticky-hide]"),
51
54
  );
52
55
  if (all.length === 0) return;
53
56
  const reduced = globalThis.matchMedia?.("(prefers-reduced-motion: reduce)").matches === true;
package/src/constants.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export const PLUGIN_ID = "emvb";
2
- export const PLUGIN_VERSION = "1.4.0";
2
+ export const PLUGIN_VERSION = "1.4.2";
3
3
  export const PACKAGE_NAME = "@perkyzz/emvb";
4
4
  export const ADMIN_ENTRY = `${PACKAGE_NAME}/admin`;
5
5
  export const PAGES_COLLECTION = "emvb_pages";
@@ -119,7 +119,12 @@ function tagDefaultCss(
119
119
  if (!style) continue;
120
120
  // W-670: tracked like classes, so a tag default's entrance gets its keyframes and turns off
121
121
  // for reduced motion.
122
- const selector = `:where(.emvb-root) ${tag}`;
122
+ // W-1090 (#30): a Button with a URL renders as `<a>`, and the `button` default reaches it
123
+ // too, at the same tag weight and after the `a` default. Link elements are not Buttons.
124
+ const selector =
125
+ tag === "button"
126
+ ? ":where(.emvb-root) button,:where(.emvb-root) a:where(.emvb-button)"
127
+ : `:where(.emvb-root) ${tag}`;
123
128
  css += block(selector, track(selector, styleDeclarations(style).declarations));
124
129
  }
125
130
  return css;
@@ -94,6 +94,14 @@ export function styleLayers(
94
94
  style: tagStyle,
95
95
  });
96
96
  }
97
+ // W-1090 (#30): a link Button gets the `button` default too, above the `a` one.
98
+ const buttonStyle = design.defaults?.button;
99
+ if (tag === "a" && node.type === "button" && buttonStyle) {
100
+ layers.push({
101
+ source: { kind: "default", label: "Site default (BUTTON)", layer: "Desktop" },
102
+ style: buttonStyle,
103
+ });
104
+ }
97
105
  const applied = new Set(node.classes ?? []);
98
106
  const owners: Owner[] = [];
99
107
  for (const cls of design.classes ?? []) {
@@ -95,8 +95,11 @@ function postValue(post: ThemePostFields | undefined, key: string): string | und
95
95
  return scalar(fields[key]);
96
96
  }
97
97
 
98
- /** Text with control characters removed and its length capped. */
99
- function clean(value: string): string {
98
+ /**
99
+ * Text with control characters removed and its length capped. W-1088: extension source values
100
+ * are cleaned with it too, with their own (longer) cap.
101
+ */
102
+ export function cleanBoundText(value: string, max = MAX_BOUND_LENGTH): string {
100
103
  let out = "";
101
104
  for (const char of value) {
102
105
  const code = char.codePointAt(0) ?? 0;
@@ -109,7 +112,7 @@ function clean(value: string): string {
109
112
  (code >= 0x2066 && code <= 0x2069);
110
113
  const kept = code === 9 ? " " : code === 10 || (code >= 32 && !dropped) ? char : "";
111
114
  // W-502: cutting at a UTF-16 length split an emoji at the limit into a broken half.
112
- if (out.length + kept.length > MAX_BOUND_LENGTH) break;
115
+ if (out.length + kept.length > max) break;
113
116
  out += kept;
114
117
  }
115
118
  return out.trim();
@@ -126,7 +129,7 @@ export function resolveBinding(binding: Binding, data: BindingData): string | un
126
129
  data.params && Object.hasOwn(data.params, binding.key) ? data.params[binding.key] : undefined;
127
130
  }
128
131
  if (raw === undefined) return undefined;
129
- const value = clean(raw);
132
+ const value = cleanBoundText(raw);
130
133
  return value.length > 0 ? value : undefined;
131
134
  }
132
135
 
@@ -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
+ }
@@ -14,6 +14,6 @@ export const EXPORT_RUNTIMES = {
14
14
  map: "(()=>{var r=/^https:\\/\\/www\\.(?:openstreetmap\\.org\\/export\\/embed\\.html|google\\.com\\/maps)\\?/;function s(t){let o=t.dataset.src??\"\";if(!r.test(o))return;let e=t.ownerDocument.createElement(\"iframe\");e.setAttribute(\"sandbox\",\"allow-scripts allow-same-origin allow-popups allow-popups-to-escape-sandbox\"),e.src=o,e.title=t.dataset.title||\"Map\",e.height=t.dataset.height||\"360\",e.loading=\"lazy\",e.referrerPolicy=\"no-referrer-when-downgrade\",t.replaceChildren(e),e.focus()}function a(t=document){for(let o of t.querySelectorAll(\"[data-emvb-map]\")){if(o.dataset.emvbReady!==void 0)continue;let e=o.querySelector(\".emvb-map-frame\"),n=e?.querySelector(\".emvb-map-load\");if(!e||!n)continue;o.dataset.emvbReady=\"\",n.addEventListener(\"click\",()=>s(e))}}a();})();",
15
15
  headline: "(()=>{function v(e){let t;try{t=JSON.parse(e.dataset.emvbRotate??\"\")}catch{return}if(!Array.isArray(t))return;let n=t.filter((a)=>typeof a===\"string\"&&a.trim()!==\"\");if(n.length<2)return;let o=Number(e.dataset.interval),r=Number(e.dataset.turns);return{words:n,interval:Number.isFinite(o)?Math.min(10,Math.max(1.5,o)):2.5,turns:Number.isFinite(r)?Math.min(5,Math.max(1,Math.round(r))):2}}function p(e,t){let n=e.ownerDocument,o=e.closest(\"h1, h2, h3, h4, h5, h6\")??e,r=[...e.childNodes].find((s)=>s.nodeType===Node.TEXT_NODE);if(!r)return;let a=r,d=n.createElement(\"span\");d.className=\"emvb-headline-sr\",d.textContent=t.words[0]??\"\",e.before(d),e.setAttribute(\"aria-hidden\",\"true\");let i=n.createElement(\"button\");i.type=\"button\",i.className=\"emvb-headline-pause\",i.setAttribute(\"aria-pressed\",\"false\"),i.textContent=\"Pause\",o.after(i);let u=0,m=t.words.length*t.turns,h=setInterval(()=>{if(u++,a.textContent=t.words[u%t.words.length]??\"\",u<m)return;let s=n.activeElement===i,b=i.nextElementSibling;if(c(),s)l(b)},t.interval*1000);function c(){clearInterval(h),a.textContent=t.words[0]??\"\",e.removeAttribute(\"aria-hidden\"),d.remove(),i.remove()}function l(s){if(s instanceof HTMLElement&&s.matches(\"a[href], button, input, select, textarea, [tabindex]\"))s.focus();else if(o instanceof HTMLElement)o.tabIndex=-1,o.focus()}i.addEventListener(\"click\",()=>{let s=i.nextElementSibling;c(),l(s)})}function f(e=document){if(globalThis.matchMedia?.(\"(prefers-reduced-motion: reduce)\").matches===!0)return;for(let n of e.querySelectorAll(\"[data-emvb-rotate]\")){if(n.dataset.emvbReady!==void 0)continue;n.dataset.emvbReady=\"\";let o=v(n);if(o)p(n,o)}}f();})();",
16
16
  share: "(()=>{function o(a=document){let e=globalThis.navigator;if(typeof e?.share!==\"function\")return;for(let t of a.querySelectorAll(\"[data-emvb-share-list]\")){if(t.dataset.emvbReady!==void 0)continue;t.dataset.emvbReady=\"\",t.querySelector(\"[data-emvb-share]\")?.addEventListener(\"click\",()=>{let n=t.ownerDocument;e.share({title:n.title,url:n.location.href.split(\"#\")[0]}).catch(()=>{})})}}o();})();",
17
- sticky: "(()=>{function d(e,t,o){let i=e.style.translate;if(i===t)return;if(e.style.translate=t,o||typeof e.animate!==\"function\")return;e.animate([{translate:i||\"0 0\"},{translate:t||\"0 0\"}],{duration:250,easing:\"ease\"})}function s(e,t){delete e.dataset.emvbAway,d(e,\"\",t)}function u(e){return e.getPropertyValue(\"--emvb-sticky-hide\").trim()!==\"0\"}function y(e){let{top:t,height:o}=e.getBoundingClientRect();return t+o/2>globalThis.innerHeight/2}function c(e=document){let t=[...e.querySelectorAll(\"[data-emvb-sticky-hide]\")].filter((n)=>n.dataset.emvbReady===void 0);if(t.length===0)return;let o=globalThis.matchMedia?.(\"(prefers-reduced-motion: reduce)\").matches===!0;for(let n of t)n.dataset.emvbReady=\"\",n.addEventListener(\"focusin\",()=>s(n,o));let i=globalThis.scrollY,l=0,m=()=>{let n=globalThis.scrollY;if(Math.abs(n-i)<4)return;let r=n>i;i=n;for(let a of t){let f=getComputedStyle(a);if(!u(f)){if(a.dataset.emvbAway!==void 0)s(a,o)}else if(r&&n>a.offsetHeight&&!a.contains(document.activeElement)){if(a.dataset.emvbAway!==void 0)continue;a.dataset.emvbAway=\"\",d(a,y(a)?\"0 100%\":\"0 -100%\",o)}else if(!r)s(a,o)}};globalThis.addEventListener(\"scroll\",()=>{cancelAnimationFrame(l),l=requestAnimationFrame(m)},{passive:!0})}c();})();",
17
+ sticky: "(()=>{function d(e,t,i){let o=e.style.translate;if(o===t)return;if(e.style.translate=t,i||typeof e.animate!==\"function\")return;e.animate([{translate:o||\"0 0\"},{translate:t||\"0 0\"}],{duration:250,easing:\"ease\"})}function s(e,t){delete e.dataset.emvbAway,d(e,\"\",t)}function u(e){return e.getPropertyValue(\"--emvb-sticky-hide\").trim()!==\"0\"}function y(e){let{top:t,height:i}=e.getBoundingClientRect();return t+i/2>globalThis.innerHeight/2}function c(e=document){let t=[...e.querySelectorAll(\"[data-emvb-sticky-hide]\")].filter((n)=>n.dataset.emvbReady===void 0&&!n.parentElement?.closest(\"[data-emvb-sticky-hide]\"));if(t.length===0)return;let i=globalThis.matchMedia?.(\"(prefers-reduced-motion: reduce)\").matches===!0;for(let n of t)n.dataset.emvbReady=\"\",n.addEventListener(\"focusin\",()=>s(n,i));let o=globalThis.scrollY,l=0,m=()=>{let n=globalThis.scrollY;if(Math.abs(n-o)<4)return;let r=n>o;o=n;for(let a of t){let f=getComputedStyle(a);if(!u(f)){if(a.dataset.emvbAway!==void 0)s(a,i)}else if(r&&n>a.offsetHeight&&!a.contains(document.activeElement)){if(a.dataset.emvbAway!==void 0)continue;a.dataset.emvbAway=\"\",d(a,y(a)?\"0 100%\":\"0 -100%\",i)}else if(!r)s(a,i)}};globalThis.addEventListener(\"scroll\",()=>{cancelAnimationFrame(l),l=requestAnimationFrame(m)},{passive:!0})}c();})();",
18
18
  theme: "(()=>{var n=\"emvb-theme\";function s(){try{let e=localStorage.getItem(n);return e===\"light\"||e===\"dark\"?e:null}catch{return null}}var d=()=>globalThis.matchMedia?.(\"(prefers-color-scheme: dark)\").matches===!0,c=()=>{let e=document.documentElement.dataset.emvbTheme;return e===\"dark\"||e!==\"light\"&&d()};function r(){let e=String(c());for(let t of document.querySelectorAll(\"[data-emvb-theme-toggle]\"))t.setAttribute(\"aria-pressed\",e)}function m(e=document){let t=s();if(t)document.documentElement.dataset.emvbTheme=t;for(let o of e.querySelectorAll(\"[data-emvb-theme-toggle]\")){if(o.dataset.emvbReady!==void 0)continue;o.dataset.emvbReady=\"\",o.addEventListener(\"click\",()=>{let a=c()?\"light\":\"dark\";document.documentElement.dataset.emvbTheme=a;try{localStorage.setItem(n,a)}catch{}r()})}globalThis.matchMedia?.(\"(prefers-color-scheme: dark)\").addEventListener?.(\"change\",r),r()}m();})();",
19
19
  } as const;
@@ -24,6 +24,7 @@ import {
24
24
  validateTriggers,
25
25
  wrapFloatMarkup,
26
26
  wrapPopupMarkup,
27
+ wrapThemePart,
27
28
  type ConditionsDoc,
28
29
  type DesignSystem,
29
30
  type FloatSettings,
@@ -54,6 +55,9 @@ export type ExportPageInput = {
54
55
  /** W-977: an entry of one of your collections: its public path and collection. */
55
56
  path?: string;
56
57
  collection?: string;
58
+ /** W-1091: the page's language and its translation group (EmDash i18n), when the site has them. */
59
+ locale?: string;
60
+ translationGroup?: string;
57
61
  };
58
62
 
59
63
  /** A published theme part as the content API returns it (`data` fields). */
@@ -362,17 +366,9 @@ export function buildSiteExport(input: {
362
366
  ...extensionOutputs,
363
367
  });
364
368
  if (scopeOnly) return result;
365
- const ownLandmark = /<(?:header|footer)[\s>]/.test(result.html);
366
- const tag =
367
- !ownLandmark && (part.partType === "header" || part.partType === "footer")
368
- ? part.partType
369
- : "div";
370
- return {
371
- ...result,
372
- html: result.html
373
- ? `<${tag} class="emvb-theme-${part.partType}" data-emvb-theme-part="${escapeAttr(part.id)}">${result.html}</${tag}>`
374
- : "",
375
- };
369
+ // W-1097: the same wrapper as the live site, sticky when the part's top-level box is.
370
+ const wrapper = wrapThemePart(part.partType, part.id, result.html, result.stickyFrame);
371
+ return { ...result, html: wrapper.html, css: result.css + wrapper.css };
376
372
  };
377
373
 
378
374
  for (const page of input.pages) {
@@ -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
- * Visible in the editor and on the published page; never runs extension code;
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
- function cleanSourceRecord(raw: Readonly<Record<string, string>>): Record<string, string> {
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 >= 32) break;
26
- if (typeof key !== "string" || !/^[a-zA-Z][a-zA-Z0-9_.-]{0,63}$/.test(key)) continue;
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
- let cleaned = "";
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 as Readonly<Record<string, string>>);
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 { ImportContext, type ImportNote, type ImportOptions, type StyleClass } from "./context.ts";
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).