@kodezen/editor 1.0.0-beta.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/LICENSE +674 -0
- package/README.md +111 -0
- package/dist/index.js +140 -0
- package/package.json +35 -0
package/README.md
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
# @kodezen/editor
|
|
2
|
+
|
|
3
|
+
Embeddable drag-and-drop **block email editor**, extracted from Easy Mail Builder.
|
|
4
|
+
A drop-in replacement for a Quill/TinyMCE editor: it produces the email HTML
|
|
5
|
+
**client-side** (no DB table, CPT, REST endpoint, or the Easy Mail Builder plugin
|
|
6
|
+
required of the host) and ships **zero global CSS** (every pane is inline-styled).
|
|
7
|
+
|
|
8
|
+
## Install
|
|
9
|
+
|
|
10
|
+
Published/registry:
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm install @kodezen/editor
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Local (monorepo / sibling plugin) without publishing — point a `file:` dependency
|
|
17
|
+
at this folder:
|
|
18
|
+
|
|
19
|
+
```jsonc
|
|
20
|
+
// consumer package.json
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@kodezen/editor": "file:../easy-mail-builder/email-builder-lib"
|
|
23
|
+
}
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
The package is **pre-built** (transpiled ESM) so it works with `@wordpress/scripts`,
|
|
27
|
+
whose Babel loader skips `node_modules`.
|
|
28
|
+
|
|
29
|
+
### Peer dependencies (host-supplied)
|
|
30
|
+
|
|
31
|
+
`react`, `react-dom`, `@wordpress/i18n`. These are left external so the consumer's
|
|
32
|
+
single React instance and `wp.i18n` global are used. `@dnd-kit/*`, `react-icons`,
|
|
33
|
+
and `just-debounce-it` are bundled in. For the default media picker, the host page
|
|
34
|
+
must have run `wp_enqueue_media()`.
|
|
35
|
+
|
|
36
|
+
## Usage
|
|
37
|
+
|
|
38
|
+
```jsx
|
|
39
|
+
import { EmailEditor, renderContent, renderDocument, BLANK_TREE } from '@kodezen/editor';
|
|
40
|
+
|
|
41
|
+
const ref = useRef();
|
|
42
|
+
|
|
43
|
+
<EmailEditor
|
|
44
|
+
ref={ref}
|
|
45
|
+
initialTree={savedTree} // { version, root } — read once at mount; remount via React `key`
|
|
46
|
+
mergeTags={[{ tag: '{{first_name}}', label: 'First name' }]}
|
|
47
|
+
mediaUpload={async ({ allowedTypes }) => ({ url, id, alt })} // optional; defaults to wp.media
|
|
48
|
+
onChange={({ tree, html }) => persist(tree, html)} // debounced
|
|
49
|
+
renderMode="document" // 'document' (full email) | 'fragment' (host wraps in its own shell)
|
|
50
|
+
header // show a slim Preview bar
|
|
51
|
+
/>
|
|
52
|
+
|
|
53
|
+
// On submit, pull the latest value past the debounce:
|
|
54
|
+
const html = ref.current.getHtml();
|
|
55
|
+
const tree = ref.current.getTree();
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Exports
|
|
59
|
+
|
|
60
|
+
| Export | What |
|
|
61
|
+
| --- | --- |
|
|
62
|
+
| `EmailEditor` | The controlled editor component (forwardRef → `{ getTree, getHtml, setTree }`). Takes a `mode` prop: `"email"` (default), `"richtext"`, or `"form"`. |
|
|
63
|
+
| `RichTextEditor` | `<EmailEditor mode="richtext" />` — the plain Quill-like rich-text surface (HTML in / HTML out). |
|
|
64
|
+
| `FormEditor` | `<EmailEditor mode="form" />` — drag-and-drop form builder producing a semantic, responsive `<form>`. `onChange` emits `{ tree, html, schema }`. |
|
|
65
|
+
| `renderDocument(tree)` | Tree → full email HTML document (doctype + MSO shell). |
|
|
66
|
+
| `renderContent(tree)` | Tree → content fragment (no doctype/body) for hosts that wrap in their own email shell. |
|
|
67
|
+
| `renderFormDocument(tree)` / `renderFormContent(tree)` | Form-mode equivalents of the two above. |
|
|
68
|
+
| `extractSchema(tree)` | Form tree → JSON schema describing the fields (name, type, required, options). |
|
|
69
|
+
| `BLANK_TREE` | Starter tree used when `initialTree` is absent. |
|
|
70
|
+
| `treeFromHtml(html)` | Best-effort HTML → tree, for importing existing content into the editor. |
|
|
71
|
+
| `htmlToBlocks(html)` | Lower-level HTML → block-array conversion used by `treeFromHtml`. |
|
|
72
|
+
| `defaultMediaUpload` | The `wp.media`-backed default media handler. |
|
|
73
|
+
|
|
74
|
+
### `renderMode`
|
|
75
|
+
|
|
76
|
+
- `document` — store the full `<!doctype html>…` email (standalone sending).
|
|
77
|
+
- `fragment` — store just the content table + blocks; use when the host wraps the
|
|
78
|
+
body in its own `<html>/<body>` shell (e.g. GemCRM injects header/footer), to
|
|
79
|
+
avoid double-wrapping.
|
|
80
|
+
|
|
81
|
+
## Storage contract
|
|
82
|
+
|
|
83
|
+
The host owns persistence. `onChange` gives `{ tree, html }`:
|
|
84
|
+
|
|
85
|
+
- `html` → the field your send pipeline already uses.
|
|
86
|
+
- `tree` (JSON) → a sibling field, so the editor round-trips on reopen.
|
|
87
|
+
|
|
88
|
+
(`tree` holds HTML inside richtext attributes; if your storage sanitizes with
|
|
89
|
+
`sanitize_text_field`/kses, base64-encode it first.)
|
|
90
|
+
|
|
91
|
+
## Updating / releasing
|
|
92
|
+
|
|
93
|
+
This is built from `dev_emb/library/` in the Easy Mail Builder plugin.
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
# in easy-mail-builder/
|
|
97
|
+
npm run build:library # → email-builder-lib/dist/index.js
|
|
98
|
+
|
|
99
|
+
# bump version
|
|
100
|
+
npm version patch --prefix email-builder-lib
|
|
101
|
+
|
|
102
|
+
# publish (registry of your choice)
|
|
103
|
+
npm publish --prefix email-builder-lib # add --access public for a public scope
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
After rebuilding, `file:`-dependent consumers must re-run `npm install` (and rebuild)
|
|
107
|
+
to pick up the new `dist`.
|
|
108
|
+
|
|
109
|
+
## License
|
|
110
|
+
|
|
111
|
+
GPL-3.0-or-later. See [`LICENSE`](./LICENSE).
|