@kontakto/email-template-editor 2.2.1 → 2.3.0
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 +28 -0
- package/dist/index.cjs +1837 -873
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +34 -6
- package/dist/index.d.ts +34 -6
- package/dist/index.js +1662 -701
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -123,6 +123,34 @@ type SavePayload = {
|
|
|
123
123
|
|
|
124
124
|
The `renderToStaticMarkup` and `renderToText` utilities are also exposed publicly for consumers that need to re-render outside the save flow (e.g. batch jobs).
|
|
125
125
|
|
|
126
|
+
#### Handlebars render pipeline
|
|
127
|
+
|
|
128
|
+
`renderToStaticMarkup(doc, { rootBlockId, variables? })` and `renderToText(doc, { rootBlockId, variables? })` both accept an optional `variables` context. When omitted (the default — including `buildSavePayload`), the output keeps raw `{{name}}` placeholders in place so the consumer's sending pipeline can evaluate them at send time with the recipient's actual data. When provided, the rendered output is compiled and evaluated as a [Handlebars](https://handlebarsjs.com/) template:
|
|
129
|
+
|
|
130
|
+
```ts
|
|
131
|
+
renderToStaticMarkup(doc, {
|
|
132
|
+
rootBlockId: 'root',
|
|
133
|
+
variables: { name: 'Alice', premium: true, amount: 19.99, next_bill: '2026-05-01' },
|
|
134
|
+
});
|
|
135
|
+
// → "<!DOCTYPE html>...Hi Alice! Premium user. Next bill: 5/1/2026, total €19.99..."
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
Built-in block helpers are whatever Handlebars ships with: `{{#if}}`, `{{#unless}}`, `{{#each}}`, `{{#with}}`, `{{else}}`. The editor registers two extra formatters on a scoped Handlebars instance:
|
|
139
|
+
|
|
140
|
+
- `{{formatDate value "date"|"time"|"datetime"|"iso"}}` — formats a Date or ISO string via the user's locale.
|
|
141
|
+
- `{{formatNumber value currency="EUR" style="currency" maximumFractionDigits=0}}` — wraps `Intl.NumberFormat`.
|
|
142
|
+
|
|
143
|
+
The scoped instance is exported as `editorHandlebars` for consumers who want to register additional helpers or partials without polluting the global `Handlebars` default instance:
|
|
144
|
+
|
|
145
|
+
```ts
|
|
146
|
+
import { editorHandlebars, evaluateHandlebars } from '@kontakto/email-template-editor';
|
|
147
|
+
|
|
148
|
+
editorHandlebars.registerHelper('upper', (s: string) => (s ?? '').toUpperCase());
|
|
149
|
+
evaluateHandlebars('Hello {{upper name}}', { name: 'world' }); // → "Hello WORLD"
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
Backwards compat: templates using only simple `{{placeholder}}` substitution render identically whether Handlebars is invoked or not, so existing consumers can opt in gradually.
|
|
153
|
+
|
|
126
154
|
#### Image upload and library (BYO backend)
|
|
127
155
|
|
|
128
156
|
The editor delegates image storage to the consumer through three optional callbacks. When omitted, the corresponding UI is hidden and URL paste remains the fallback.
|