esender-email-editor 1.1.0 → 1.2.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/README.md +20 -45
- package/dist/index.cjs +6 -6
- package/dist/index.d.ts +50 -38
- package/dist/index.js +6 -6
- package/dist/styles.css +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -11,9 +11,11 @@ A drag-and-drop **MJML email editor** for React 18 + Ant Design 5. The editor re
|
|
|
11
11
|
The package is published on the public **npm registry**.
|
|
12
12
|
|
|
13
13
|
```bash
|
|
14
|
-
npm install esender-email-editor
|
|
14
|
+
npm install esender-email-editor --legacy-peer-deps
|
|
15
15
|
```
|
|
16
16
|
|
|
17
|
+
> `--legacy-peer-deps` is required because `react-giphy-searchbox` (a transitive runtime dependency used by the Gif block) still declares an ancient `react@16.x` peer. The runtime works fine on React 18 — only the metadata is stale.
|
|
18
|
+
|
|
17
19
|
## Peer dependencies
|
|
18
20
|
|
|
19
21
|
The package externalizes its heavy runtime deps so the host app provides them. Peer ranges are intentionally permissive — any version within the declared range works, and hosts that already satisfy a peer can skip it.
|
|
@@ -116,7 +118,6 @@ export const Composer = () => {
|
|
|
116
118
|
| Prop | Type | Required | Description |
|
|
117
119
|
|---|---|---|---|
|
|
118
120
|
| `apiKey` | `string` | yes | License key. Exchanged for a JWT on mount. |
|
|
119
|
-
| `apiConfig` | `ApiConfig` | no | Override base URL and any endpoint path. See [API configuration](#api-configuration). |
|
|
120
121
|
| `customButtons` | `ReactNode` | no | Slot rendered in the editor's top-right toolbar. |
|
|
121
122
|
| `showUndoRedo` | `boolean` | no | Show the undo/redo toolbar (default `true`). |
|
|
122
123
|
| `onLicenseError` | `(error: LicenseError) => void` | no | Fires when the license verify call fails. |
|
|
@@ -133,43 +134,14 @@ export const Composer = () => {
|
|
|
133
134
|
|---|---|---|
|
|
134
135
|
| `getJson()` | `string` | Stringified MJML JSON tree (export-ready). |
|
|
135
136
|
| `getHtml()` | `string` | Compiled email HTML via `mjml-browser`. Triggers `onHtmlExport`. |
|
|
136
|
-
| `loadJson(json, raw?)` | `void` | Load a previously saved template. `json`
|
|
137
|
-
| `
|
|
138
|
-
| `
|
|
139
|
-
|
|
140
|
-
## API configuration
|
|
141
|
-
|
|
142
|
-
The editor talks to a small set of backend endpoints. Defaults point at the hosted eSender API, but every URL is overridable via the `apiConfig` prop so consumers can self-host the backend.
|
|
143
|
-
|
|
144
|
-
```tsx
|
|
145
|
-
<Package
|
|
146
|
-
ref={ref}
|
|
147
|
-
apiKey="…"
|
|
148
|
-
apiConfig={{
|
|
149
|
-
baseUrl: 'https://api.example.com',
|
|
150
|
-
verifyUrl: '/license/verify',
|
|
151
|
-
refreshUrl: '/license/refresh',
|
|
152
|
-
saveTemplateUrl: '/templates',
|
|
153
|
-
getTemplatesUrl: '/templates/:projectId',
|
|
154
|
-
getTemplateByIdUrl: '/templates/:projectId/:templateId',
|
|
155
|
-
uploadMediaUrl: '/media',
|
|
156
|
-
}}
|
|
157
|
-
/>
|
|
158
|
-
```
|
|
137
|
+
| `loadJson(json, raw?)` | `void` | Load a previously saved template. `json` accepts either the stringified output of `getJson()` or a deserialized object. Pass `null` to clear the canvas. |
|
|
138
|
+
| `loadHtml(html)` | `void` | Load raw HTML into the editor. The HTML is wrapped in an MJML `mj-raw` block and rendered verbatim. The editor cannot break arbitrary HTML back into editable blocks — for full editability, prefer `loadJson` with a previously saved template. |
|
|
139
|
+
| `saveTemplate({ projectId, templateId? })` | `Promise<TemplateApiResponse>` | Create or update a template. Omit `templateId` to create; include it to update. POSTs to `https://esender.in/api/license/template/create`. |
|
|
140
|
+
| `loadTemplate({ projectId, templateId? })` | `Promise<TemplateApiResponse>` | GET from `https://esender.in/api/license/template/:projectId[/:templateId]` and pipe the JSON back into `loadJson(...)`. |
|
|
159
141
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
| Field | Default | Method | Purpose |
|
|
163
|
-
|---|---|---|---|
|
|
164
|
-
| `baseUrl` | `https://esender.in/api` | — | Prepended to every relative URL below. |
|
|
165
|
-
| `verifyUrl` | `/verify` | POST | Exchange `apiKey` for access + refresh tokens. |
|
|
166
|
-
| `refreshUrl` | `/refresh` | POST | Exchange a refresh token for a new access token. |
|
|
167
|
-
| `saveTemplateUrl` | `/template/create` | POST | Create (or update, if `templateId` is in the body) a template. |
|
|
168
|
-
| `getTemplatesUrl` | `/template/:projectId` | GET | Load the project's current template. |
|
|
169
|
-
| `getTemplateByIdUrl` | `/template/:projectId/:templateId` | GET | Load a specific template. |
|
|
170
|
-
| `uploadMediaUrl` | `/media/add` | POST (multipart) | Upload an image; returns a hosted URL. |
|
|
142
|
+
## Backend
|
|
171
143
|
|
|
172
|
-
|
|
144
|
+
The editor talks to the hosted eSender API at `https://esender.in/api`. Endpoints are fixed and not configurable; consumers only supply `apiKey`.
|
|
173
145
|
|
|
174
146
|
## Events
|
|
175
147
|
|
|
@@ -187,13 +159,11 @@ Callbacks are stored internally in a ref, so inline arrow functions are safe —
|
|
|
187
159
|
|
|
188
160
|
## Theme isolation
|
|
189
161
|
|
|
190
|
-
The editor
|
|
162
|
+
The editor does **not** mount its own `<ConfigProvider>` or antd `<App />`. It inherits the host application's antd theme, locale, and static-method context — nothing the editor renders will override your colors, components, or token configuration.
|
|
191
163
|
|
|
192
|
-
-
|
|
193
|
-
- Your host app's `<ConfigProvider theme={…}>` will **not** restyle the editor.
|
|
194
|
-
- Antd's `message` / `notification` / `Modal.useApp` are scoped via `<App />` inside the editor.
|
|
164
|
+
All editor-specific CSS lives under a single `.aee-root` class scope (the wrapper div around the editor), so SCSS overrides and resets cannot reach host components either.
|
|
195
165
|
|
|
196
|
-
|
|
166
|
+
If you want the editor branded purple like the default screenshots, wrap your host app in your own `<ConfigProvider theme={{ token: { colorPrimary: '#7747ff' } }}>` — the editor will inherit it.
|
|
197
167
|
|
|
198
168
|
## License handshake
|
|
199
169
|
|
|
@@ -201,9 +171,9 @@ The editor will not render until the eSender license is verified:
|
|
|
201
171
|
|
|
202
172
|
1. Host passes `apiKey` to `<Package />`.
|
|
203
173
|
2. On mount, the package checks `localStorage` for a cached access token.
|
|
204
|
-
3. If absent, it `POST`s to `
|
|
174
|
+
3. If absent, it `POST`s to `https://esender.in/api/license/verify` with `x-api-key: <apiKey>`.
|
|
205
175
|
4. On success the returned `accessToken` and `refreshToken` are stored in `localStorage` and the editor mounts.
|
|
206
|
-
5. While running, the internal axios client attaches the access token to protected calls; on `401` / `token expired` it calls `
|
|
176
|
+
5. While running, the internal axios client attaches the access token to protected calls; on `401` / `token expired` it calls `https://esender.in/api/license/refresh` once and retries. If refresh fails, tokens are cleared and the next mount re-runs verify.
|
|
207
177
|
|
|
208
178
|
No further token management is required from the host.
|
|
209
179
|
|
|
@@ -291,11 +261,16 @@ import Package, {
|
|
|
291
261
|
type RefreshTokenResponse,
|
|
292
262
|
type TemplateApiResponse,
|
|
293
263
|
type TemplateDocument,
|
|
294
|
-
type ApiConfig,
|
|
295
264
|
type EditorEventCallbacks,
|
|
296
265
|
type SaveEvent,
|
|
297
266
|
type LoadEvent,
|
|
298
267
|
type MediaUploadEvent,
|
|
268
|
+
// convenience aliases
|
|
269
|
+
type EditorInstance, // = EditorHandle
|
|
270
|
+
type TemplateData, // = TemplateDocument
|
|
271
|
+
type TemplateJson, // shape of getJson()/loadJson() payload
|
|
272
|
+
type SaveTemplatePayload, // = SaveTemplateOptions
|
|
273
|
+
type LoadTemplatePayload, // = LoadTemplateOptions
|
|
299
274
|
} from 'esender-email-editor';
|
|
300
275
|
```
|
|
301
276
|
|