email-builder-online 4.1.7 → 4.1.9

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 CHANGED
@@ -925,6 +925,98 @@ The document is a flat `Record<blockId, TEditorBlock>`:
925
925
  | `Spacer` | Vertical spacing |
926
926
  | `SocialMedia` | Social media icon links |
927
927
 
928
+ ## Server-side HTML Rendering (`@eb/email-builder`)
929
+
930
+ In the browser, `EmailBuilderRef.getHtml()` renders the current document to
931
+ HTML. To do the same **outside the editor** — in an MCP server, a backend job,
932
+ or any automated flow — use the **node-safe HTML renderer** shipped by the
933
+ `@eb/email-builder` package. It turns a document (JSON) into a self-contained
934
+ HTML string in a plain Node.js process, with **no browser DOM, no Zustand
935
+ store, and no editor UI**. It renders through `react-dom/server`, so React is
936
+ required (unlike `@eb/document-core/node`, which is React-free).
937
+
938
+ This is the natural companion to `@eb/document-core/node`: validate/build the
939
+ document with one, render it to HTML with the other.
940
+
941
+ ### Two entry points
942
+
943
+ | Entry | Import specifier | Contents | Deps |
944
+ |---|---|---|---|
945
+ | Default (editor/browser) | `@eb/email-builder` | `Reader`, render contexts, block primitives, `renderEmailHtml`, `cleanDocument` | React + Zod |
946
+ | **Node-safe** | `@eb/email-builder/node` | `renderEmailHtml`, `cleanDocument`, `Reader`, types — no DOM, no store | React + Zod |
947
+
948
+ > Server-side consumers (MCP, backend, CLI) must import from
949
+ > **`@eb/email-builder/node`** so they never pull in the editor app.
950
+
951
+ ### Render a document to HTML
952
+
953
+ ```ts
954
+ import { renderEmailHtml } from '@eb/email-builder/node';
955
+
956
+ const html = renderEmailHtml(documentJson, { rootBlockId: 'root' });
957
+ // → self-contained HTML string (DOCTYPE + <head> CSS + desktop body),
958
+ // ready to hand off to Nodemailer, SES, SendGrid, etc.
959
+ ```
960
+
961
+ Validate first with `@eb/document-core/node` for a safe pipeline:
962
+
963
+ ```ts
964
+ import { validateDocument } from '@eb/document-core/node';
965
+ import { renderEmailHtml } from '@eb/email-builder/node';
966
+
967
+ const result = validateDocument(jsonDocument);
968
+ if (!result.ok) throw new Error(result.issues.join('\n'));
969
+
970
+ const html = renderEmailHtml(result.data, { rootBlockId: 'root' });
971
+ ```
972
+
973
+ The export always renders the **desktop** shell; the emitted
974
+ `@media (max-width: 640px)` rules handle mobile, so clients that strip
975
+ `<style>` blocks (Outlook desktop) still render correctly.
976
+
977
+ ### Installation
978
+
979
+ **Inside this monorepo** — workspace protocol:
980
+
981
+ ```bash
982
+ pnpm add @eb/email-builder
983
+ ```
984
+
985
+ **From an external project** (e.g. the standalone MCP repo) — the package is
986
+ not published, so consume a **vendored** build. Generate it from the monorepo:
987
+
988
+ ```bash
989
+ cd packages/email-builder
990
+ pnpm vendor # bundles the node-safe renderer → vendor/email-builder + a .tgz tarball
991
+ pnpm smoke # optional: renders a sample document via the built bundle in plain Node
992
+ ```
993
+
994
+ Copy `vendor/email-builder` (or the `eb-email-builder-<version>.tgz` tarball)
995
+ into the consumer repo and reference it via `file:`. The bundle ships
996
+ ESM + CJS + `.d.ts`; the workspace `@eb/*` packages and `csso` are bundled in,
997
+ while `react`, `react-dom`, and `zod` stay external (provided by the consumer):
998
+
999
+ ```jsonc
1000
+ // consumer package.json
1001
+ {
1002
+ "dependencies": {
1003
+ "@eb/email-builder": "file:./vendor/email-builder",
1004
+ "react": "^19", // peer deps — provided by the consumer
1005
+ "react-dom": "^19",
1006
+ "zod": "^3.22.4"
1007
+ }
1008
+ }
1009
+ ```
1010
+
1011
+ ```ts
1012
+ import { renderEmailHtml } from '@eb/email-builder';
1013
+
1014
+ const html = renderEmailHtml(documentJson, { rootBlockId: 'root' });
1015
+ ```
1016
+
1017
+ > The vendored copy is a snapshot. When the renderer or blocks change in the
1018
+ > monorepo, re-run `pnpm vendor` and re-copy into the consumer repo.
1019
+
928
1020
  ## License
929
1021
 
930
1022
  Free to use. © Laravel42. All rights reserved.