Install EmVB in a host site

EmVB is a native EmDash plugin: add the package, register it in astro.config, and add one public route. The EmDash plugin registry installs sandboxed plugins only; native plugins like EmVB are npm packages.

Project website: https://emvb.dev. Package: @perkyzz/emvb.

EmVB 1.4.2 supports EmDash 1.4.0, 1.5.0 and 1.6.0 on Node and Cloudflare. Release checks install the package on stock sites for all three versions and run the full demo browser suite on 1.4.0 and 1.6.0.

1. Install the package

From your EmDash site root:

npm i @perkyzz/emvb
# or: bun add @perkyzz/emvb

EmVB ships TypeScript source that your site’s Vite build compiles. Its peers are emdash >=1.4.0 <2, astro ^7, react and react-dom ^19, @phosphor-icons/react ^2.1.10 and the exact @cloudflare/kumo version EmDash pins: 2.6.0 (1.4), 2.15.0 (1.5) or 2.19.0 (1.6). Keep the Astro version your site came with. EmVB accepts zod 4 from 4.5.4 up so it can share EmDash’s copy.

It also installs two dependencies: zod and @perkyzz/emvb-icons, the icon sets for the editor’s Icon library (pinned to the exact version EmVB was built with). Only the editor loads the icon sets; a placed icon is saved into the page as SVG, so public pages never fetch them.

Optional (forms on EmVB pages): EmDash Forms pins EmDash’s exact Kumo version, so pick the release that matches your EmDash:

npm i @emdash-cms/[email protected]   # EmDash 1.6 (Kumo 2.19.0)
npm i @emdash-cms/[email protected]   # EmDash 1.5 (Kumo 2.15.0)
npm i @emdash-cms/[email protected]   # EmDash 1.4 (Kumo 2.6.0; 0.2.9 to 0.2.12 work)

2. Register the plugin

In astro.config.mjs (or .ts), add EmVB next to your other plugins:

import { emvb } from "@perkyzz/emvb";
import { formsPlugin } from "@emdash-cms/plugin-forms"; // optional

export default defineConfig({
  integrations: [
    emdash({
      plugins: [formsPlugin(), emvb()],
      // …adapters…
    }),
  ],
});

Your site’s styles in the editor canvas

The editor canvas is a sandboxed frame, so it doesn’t see your layout’s stylesheets or fonts. Pass them as canvasStyles and the canvas loads them before EmVB’s own CSS, so pages look in the editor as they do on your site:

emvb({
  canvasStyles: ["/styles/site.css", "https://fonts.googleapis.com/css2?family=Inter&display=swap"],
});
  • Use https: (or http:) URLs or site paths starting with /. Anything else (javascript:, data:, //host, relative paths) is ignored. At most 10.
  • EmVB’s CSS comes after them, so an element’s own styles and your Site styles still win.
  • The canvas runs no scripts, so script-loaded fonts won’t apply; use a stylesheet with @font-face or a font service’s CSS URL.
  • The demo sites load their public/site.css this way.

EmVB layouts on your own collections

canvasCollections lets entries in your own collections carry an EmVB layout, edited in place from the entry form:

emvb({ canvasCollections: ["pages"] });
  1. In the collection’s schema, add a JSON field (for example canvas) and pick the Edit with EmVB widget (emvb:canvas). Or open Host collections in the admin (administrators): it lists your collections, adds the field with Add canvas field, and shows the exact emvb({ canvasCollections: [...] }) line to paste into astro.config (EmVB can’t change that file; restart or redeploy after editing it).
  2. On the entry form, Edit with EmVB opens the full editor. Preview shows the unsaved layout in a sandboxed window (Desktop, Tablet, Mobile). Apply writes the layout back into the field; the entry’s own Save and Publish store it. While the field is empty, Convert to EmVB starts a layout from the entry’s saved rich-text body (headings, paragraphs, lists and images; other blocks are left out) without changing the body.
  3. In the public route, ask for the entry’s layout and fall back to your own template when the field is empty:
const emvb =
  (await resolveEmVBPage(Astro)) ??
  (await resolveEmVBPage(Astro, { collection: "pages", field: "canvas" }));
  • Slugs must be lowercase letters, digits and _; emvb_pages, emvb_theme_parts and anything else are ignored. At most 20.
  • Saves are checked on the server: an invalid layout is refused, and only editors and administrators can change the field (authors see a read-only summary). Since 1.1.2 this holds for every collection with an emvb:canvas field, listed or not.
  • List every collection you render with resolveEmVBPage(Astro, { collection }). Since 1.3, rendering a layout from a collection missing from canvasCollections logs one warning per collection (emvb: rendering a layout from a collection missing from emvb({ canvasCollections })) and still renders it; EmVB 2.0 will not render it.
  • An AI agent publishing such an entry follows the AI agents publish setting, like an EmVB page.
  • A hosted layout always renders in your site layout (no blank canvas mode). Preview in a field renders in the browser, so it shows dynamic data the same way the editor canvas does.
  • EmVB asks for the schema:read capability to find your emvb:canvas fields.
  • The demo sites’ pages collection has a canvas field set up this way.

Which collections Loops may list (optional)

A Loop element lists the published entries of a collection your editors pick, with fields they choose. If you keep a collection published but not meant to be listed on pages (members, internal notes), name the ones Loops may use (since 1.1.2):

emvb({ loopCollections: ["posts", "team"] });

A Loop on any other collection then renders empty. Without the option, Loops can list any collection, as before.

3. Public route

Copy the pattern from EmVB’s demos (demos/node/src/pages/[slug].astro): try resolveEmVBPage first, then fall through to the site’s own pages, and rewrite to /404 when neither matches.

---
import { getEmDashEntry, getSeoMeta, decodeSlug, getSiteSettings } from "emdash";
import { EmVBPage, resolveEmVBPage } from "@perkyzz/emvb/astro";
import { EmVBFormsRuntime } from "@perkyzz/emvb/astro/forms/client"; // only with @emdash-cms/plugin-forms
import { EmVBMenuRuntime } from "@perkyzz/emvb/astro/menu";
import { EmVBTabsRuntime } from "@perkyzz/emvb/astro/tabs";
// …site layout…

const emvb = await resolveEmVBPage(Astro);
if (!emvb && !(await getEmDashEntry("pages", decodeSlug(Astro.params.slug)))) {
  return Astro.rewrite("/404");
}
---

{emvb ? (
  <EmVBPage page={emvb}>
    {emvb.needsFormsRuntime && <EmVBFormsRuntime />}
    {emvb.needsTabsRuntime && <EmVBTabsRuntime />}
    {emvb.needsMenuRuntime && <EmVBMenuRuntime />}
  </EmVBPage>
) : (
  /* site page */
  null
)}

A fixed route has no slug parameter, so pass the page’s slug instead. To serve the EmVB page home at /, in src/pages/index.astro:

---
import { EmVBPage, resolveEmVBPage } from "@perkyzz/emvb/astro";
import { EmVBFormsRuntime } from "@perkyzz/emvb/astro/forms/client"; // only with @emdash-cms/plugin-forms
// …site layout…

const emvb = await resolveEmVBPage(Astro, { slug: "home" });
if (!emvb) return Astro.rewrite("/404");
---

<EmVBPage page={emvb}>{emvb.needsFormsRuntime && <EmVBFormsRuntime />}</EmVBPage>

Mount the tabs and menu runtimes here too, as above. Until a page with the slug home is published (step 4), / returns 404; if the site has its own home content, fall through to it instead, as the [slug] route does. The [slug] route still serves the same page at /home, so redirect that path or set the page’s canonical URL to /.

Blank-canvas EmVB pages use standalone on EmVBPage (see the demos).

@perkyzz/emvb/astro/forms does not import the forms plugin, so a site can always import it and the build still succeeds; rendering it does nothing. When @emdash-cms/plugin-forms is installed, import EmVBFormsRuntime from @perkyzz/emvb/astro/forms/client instead. That subpath calls initForms.

Public pages are script-free except for these runtimes, and each one is mounted only when the page says it needs it: needsFormsRuntime (a Form element), needsTabsRuntime (a Tabs element, @perkyzz/emvb/astro/tabs) and needsMenuRuntime (a Menu element, @perkyzz/emvb/astro/menu). Theme parts report their own flags from resolveThemeParts, with popups (@perkyzz/emvb/astro/popups) and floats (@perkyzz/emvb/astro/floats) in addition; mount those in the site layout as demos/node/src/layouts/Base.astro does. Since 1.2, widgets with an opt-in script (a dismissible Alert, a Gallery that opens pictures large, a Carousel with buttons or autoplay; since 1.3 a Counter that counts up, a live Countdown, a Map that loads on request, an Animated headline with rotating words and Share buttons with the device’s Share button; since 1.4 a Theme toggle, an element set to Hide while scrolling down, and an extension element whose extension ships its own script) list it in runtimes: EmVBPage mounts a page’s own, so a page needs no change; for theme parts, add <EmVBWidgetRuntimes names={theme.runtimes} /> from @perkyzz/emvb/astro/widgets once to the site layout, and later widgets’ scripts come through it too. 1.4 needs no other host change: a mega menu panel uses the menu runtime, an off-canvas panel the popups runtime, and custom fonts are served by EmVB’s own plugin route. A site whose Site styles have a Dark mode colour also gets a tiny inline script at the start of each EmVB page, so a visitor’s light or dark choice applies before the page is drawn; if you send a Content Security Policy, the Widgets guide has its hash. See Theme parts § Public render.

Theme parts on your site’s other routes

Headers, footers, popups, floats and the Single Post, Archive, Search Results and Error 404 templates appear only where the page calls resolveThemeParts. A display condition of Entire site means every page that does, not every URL on your site. EmVB pages do when your layout does; routes built from your site’s own templates (a starter blog’s home, /posts, category and tag pages) show none of it until their layout adds them.

To cover a route, render it with the layout that calls resolveThemeParts, as every route in the demos does through demos/node/src/layouts/Base.astro: it picks the request’s context (themeContextFrom(Astro.url, { content }) for an entry or archive, themeContextFront() for the home page, themeContextSearch and themeContext404 for those routes), puts theme.css in the head, replaces the starter header and footer with theme.header and theme.footer, uses theme.content in place of the page body when a template wins, and adds theme.popups and theme.floats before EmDashBodyEnd, with their runtimes when needsPopupsRuntime or needsFloatsRuntime is true. Put theme.header.html and theme.footer.html straight in <body>, not inside a box of your own, so a sticky header or footer part can stay on screen along the whole page. See Theme parts § Public render for every field it returns.

Tell EmVB what you know about the visitor

An element’s Visitors rules can show it only to visitors in a segment, such as members or paying customers. EmVB can’t know that on its own, so your route passes it:

---
const user = Astro.locals.user; // however your site knows who is signed in
const visitor = {
  segments: user ? ["member", ...(user.plan === "pro" ? ["pro"] : [])] : [],
};
const emvb = await resolveEmVBPage(Astro, { visitor });
const theme = await resolveThemeParts(Astro, undefined, { visitor }); // theme parts too
---
  • segments: names your editors type in Visitors → Segments (a lowercase letter or digit, then lowercase letters, digits, :, _ or -, up to 64 characters, so plan:pro works). A name that doesn’t fit is dropped. A rule matches a visitor in any of its segments.
  • country (two letters), device (mobile, tablet, desktop) and returning (true or false) replace what EmVB detects from the request, when your site knows better.
  • Pages with Visitors rules are sent with Cache-Control: private, no-store, so one visitor’s version is never cached for another.
  • Only a new or returning rule uses a cookie (emvb_seen); see Cookies and browser storage to hold it back until a visitor consents.
  • Visitors rules are presentation, not access control. A visitor controls their own cookies (A/B arm, returning visitor), and off Cloudflare and Vercel they can also send the country headers. Never hide something with a Visitors rule that a visitor mustn’t see.
  • Country detection (since 1.1.2). EmVB reads cf-ipcountry only on Cloudflare Workers and x-vercel-ip-country only on Vercel, where the edge sets them, plus Cloudflare’s request.cf. Behind your own proxy that sets one of these headers and strips the visitor’s copy, add emvb({ trustGeoHeaders: true }); false never reads them. Or pass country yourself as above.

Cookies and browser storage

EmVB stores nothing in a visitor’s browser unless a page uses a feature that needs it. Pages without these features set no cookie and stay cacheable. This is the full list:

Name Kind Set when Kept for What for
emvb_seen Cookie (first-party, HttpOnly, SameSite=Lax) The first visit to a page with a new or returning visitor Visitors rule. Country, device, segment and time rules never set it. 1 year Tells new visitors from returning ones
emvb_ab_<test> Cookie (first-party, HttpOnly, SameSite=Lax) The first visit to a page with an A/B test 30 days Keeps the visitor on the same version
emvb-theme localStorage A visitor clicks a Theme toggle Until cleared Their light or dark choice
emvb-popup-shown:<id> localStorage A popup opens by itself (not from a click) Until cleared Counts openings for Show at most
emvb-float-closed:<id> sessionStorage A visitor closes a float This visit Keeps it closed

None of them is sent to anyone else. EmDash’s own sign-in cookies, for editors, are EmDash’s.

Holding back the returning-visitor cookie (since 1.4.1). If your site asks for consent before setting non-essential cookies, set visitorCookie:

emvb({
  visitorCookie: "consent", // or "never"; the default is "always"
  visitorCookieConsent: { cookie: "cookie_consent", value: "yes" },
});
  • "always" (the default, as before 1.4.1) sets emvb_seen on a first visit to a page with a new or returning rule.
  • "consent" sets and reads it only when the request carries your consent cookie. cookie is the name of a first-party cookie your consent banner sets when the visitor accepts. value is the value (or a list of values) that means “accepted”, matched exactly. Without value, 1, true, yes, granted, accepted, allow and all count, in any case. Your banner must set this cookie where the server can see it (a normal cookie, not localStorage). If your banner stores its choice in another format, have its “accepted” callback also set a small cookie of your own, such as document.cookie = "cookie_consent=yes; path=/; max-age=31536000; samesite=lax". Without a valid visitorCookieConsent, "consent" acts as "never" and the build prints a warning.
  • "never" never sets or reads it.

When the cookie isn’t allowed, every visitor counts as new: “New visitors” rules show to everyone and “Returning visitors” rules to no one. A cookie left from before is cleared on the next page with such a rule. If your site knows who is returning (a signed-in member, say), pass returning yourself as above; that always wins. EmVB loads no consent tool and talks to none. The option covers emvb_seen only; an A/B test still keeps its 30-day cookie, so leave A/B tests off pages for visitors who haven’t consented if that cookie needs consent on your site.

Moving your site from EmDash 1.4 to 1.5

EmVB needs no change for EmDash 1.5. Upgrade EmDash the usual way (with the Cloudflare adapter, upgrade emdash and @emdash-cms/cloudflare together); on its first start EmDash 1.5 runs its own migrations, and your EmVB pages, theme parts, Site styles, uploaded icons, agent settings and requests carry over (checked on Node with SQLite and on Cloudflare with D1, bun run check:upgrade in EmVB’s repository).

4. First-run setup

  1. Start the site (bunx --bun astro dev or your host’s script).
  2. Sign in as an admin.
  3. Open Pages VisualBuilder → Set up EmVB once (creates the hidden emvb_pages collection).
  4. Create a page, publish it, open /{slug}.

5. Optional: AI agents (EmDash 1.2+)

Turn on EmDash’s MCP server with emdash({ mcp: true, … }), then open Pages VisualBuilder → AI agents to switch agents on and approve the EmVB tools on EmDash’s Plugins screen. The MCP guide covers tokens (scope mcp:tools:emvb, an editor user), the @perkyzz/emvb-mcp bridge, publishing and rate limits.

6. Package shape check

From the EmVB repo, to try an unreleased change in a host site:

bun pm pack --cwd packages/emvb
# In the host site: npm i /path/to/perkyzz-emvb-<version>.tgz, then apply steps 2–4.
bun run pack:smoke

pack:smoke checks that the packed package is @perkyzz/emvb, isn’t private, exports TypeScript source for ., ./astro, ./astro/forms, ./astro/forms/client, ./admin and ./core, ships no tests, and has no workspace: or catalog: ranges. The package also exports ./astro/popups, ./astro/floats, ./astro/tabs, ./astro/menu and ./mcp (the tool definitions the @perkyzz/emvb-mcp bridge uses).

Responsive images (optional)

EmDash 1.4 doesn’t store extra sizes for library images; it builds them at render time through Astro’s image service. EmVB can do the same for library Images on its pages. Pass Astro’s getImage and authorise your own origin so the service will resize the files:

---
import { getImage } from "astro:assets";
const emvb = await resolveEmVBPage(Astro, { getImage });
---
// astro.config.mjs
image: { remotePatterns: [{ protocol: "https", hostname: "example.com" }] },

An Image with a width and height, from the library, and without sizes of its own gets up to six srcset sizes (up to twice its width). Without getImage, or when the service leaves the URL unchanged, the plain <img> is published as before. A picked library image also takes the focal point set on it in EmDash’s media library.

Languages (optional)

EmVB follows EmDash’s translations: each language of a page is its own entry, with its own layout. With Astro’s i18n set up, resolveEmVBPage(Astro) reads the page in Astro.currentLocale (or pass locale). When that language has no translation, EmDash serves the next one in its fallback chain and the result says so in fallbackLocale, so the route can show a note and keep the page’s real language in <html lang>:

---
const emvb = await resolveEmVBPage(Astro, { getImage });
if (!emvb) return Astro.rewrite("/404");
---
<Base lang={emvb.fallbackLocale ?? emvb.locale}>
  {emvb.fallbackLocale && <p>This page isn't translated yet; here is the original.</p>}
  <EmVBPage page={emvb} />
</Base>

Keep routing: { prefixDefaultLocale: false }: prefixing the default locale breaks EmDash’s admin. The default language stays at /, others under their prefix (for example src/pages/fr/[slug].astro). Header, footer and other theme parts are shared by every language for now.

The Language switcher element links the page’s other published languages, each in its own name with hreflang, the shown one marked current; drafts are never linked. resolveEmVBPage fills it, linking the default language at /<slug> and others at /<locale>/<slug>; pass translationHref when your routes differ. For a switcher in a header or footer, pass the page’s list to the theme parts:

const theme = await resolveThemeParts(Astro, ctx, { translations: emvb?.translations });

In the editor, Page settings → Languages lists the site’s languages. Translate makes a draft in that language linked to this page, with a copy of its layout, and opens it; with Ask my agent to translate the new page ticked, it also sends your agent a request (see the AI agents guide) whose proposal you review in the new page’s Agent tab. Only words are meant to change: texts, buttons, alt text, labels and placeholders. Form field names, links and images stay.

Archive page counts (optional)

EmDash doesn’t report how many posts an archive has, so the Pagination element’s “Page N of M” shows “Page N” and its Last link is left out. To count, opt in where you resolve theme parts:

const theme = await resolveThemeParts(Astro, context, { pageCount: true });

EmVB then counts with a few one-row queries through EmDash’s public collection query (about 2·log2 of the post count, none on the last page). Pass a function instead of true to use your own count, for example an EmDash count API: pageCount: async ({ collection, where }) => n.