@kodezen/editor 1.0.1 → 1.1.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.
Files changed (3) hide show
  1. package/README.md +95 -52
  2. package/dist/index.js +14 -9
  3. package/package.json +20 -6
package/README.md CHANGED
@@ -1,42 +1,44 @@
1
- # @kodezen/email-builder-editor
1
+ # @kodezen/editor
2
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).
3
+ Embeddable drag-and-drop **block editor**. Framework-agnostic, zero
4
+ server/CMS dependency. A drop-in replacement for a Quill/TinyMCE editor: it
5
+ produces HTML **client-side** (no DB table, backend endpoint, or any other
6
+ package required beyond React) and ships **zero global CSS** (every pane is
7
+ inline-styled).
7
8
 
8
- ## Install
9
+ One component (`EmailEditor`) covers four modes — email builder, plain
10
+ rich-text, form builder, and certificate/print layout — plus two convenience
11
+ wrappers (`RichTextEditor`, `FormEditor`) for call sites that only ever want
12
+ one mode.
9
13
 
10
- Published/registry:
14
+ ## Install
11
15
 
12
16
  ```bash
13
- npm install @kodezen/email-builder-editor
17
+ npm install @kodezen/editor
14
18
  ```
15
19
 
16
- Local (monorepo / sibling plugin) without publishing — point a `file:` dependency
17
- at this folder:
20
+ The package is **pre-built** (transpiled ESM) so it works regardless of the
21
+ consumer's bundler/transform setup.
18
22
 
19
- ```jsonc
20
- // consumer package.json
21
- "dependencies": {
22
- "@kodezen/email-builder-editor": "file:../easy-mail-builder/email-builder-lib"
23
- }
24
- ```
23
+ ### Peer dependencies (host-supplied)
25
24
 
26
- The package is **pre-built** (transpiled ESM) so it works with `@wordpress/scripts`,
27
- whose Babel loader skips `node_modules`.
25
+ `react`, `react-dom`. These are left external so the consumer's single React
26
+ instance is reused. `@dnd-kit/*`, `react-icons`, and `just-debounce-it` are
27
+ bundled in.
28
28
 
29
- ### Peer dependencies (host-supplied)
29
+ ### Media picker
30
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()`.
31
+ The default `mediaUpload` handler opens a native `<input type="file">` picker
32
+ and resolves the chosen file as a `data:` URL — it works in any browser with
33
+ no configuration, but it's a testing baseline, not a production upload
34
+ pipeline (`data:` URLs bloat stored HTML and are unreliable in several email
35
+ clients). A host with real storage (S3, its own media library, etc.) should
36
+ pass its own `mediaUpload` prop instead — see below.
35
37
 
36
38
  ## Usage
37
39
 
38
40
  ```jsx
39
- import { EmailEditor, renderContent, renderDocument, BLANK_TREE } from '@kodezen/email-builder-editor';
41
+ import { EmailEditor, renderContent, renderDocument, BLANK_TREE } from '@kodezen/editor';
40
42
 
41
43
  const ref = useRef();
42
44
 
@@ -44,7 +46,7 @@ const ref = useRef();
44
46
  ref={ref}
45
47
  initialTree={savedTree} // { version, root } — read once at mount; remount via React `key`
46
48
  mergeTags={[{ tag: '{{first_name}}', label: 'First name' }]}
47
- mediaUpload={async ({ allowedTypes }) => ({ url, id, alt })} // optional; defaults to wp.media
49
+ mediaUpload={async ({ allowedTypes }) => ({ url, id, alt })} // optional; defaults to a native file picker
48
50
  onChange={({ tree, html }) => persist(tree, html)} // debounced
49
51
  renderMode="document" // 'document' (full email) | 'fragment' (host wraps in its own shell)
50
52
  header // show a slim Preview bar
@@ -55,47 +57,88 @@ const html = ref.current.getHtml();
55
57
  const tree = ref.current.getTree();
56
58
  ```
57
59
 
60
+ ### Modes
61
+
62
+ `EmailEditor` takes a `mode` prop; `RichTextEditor` and `FormEditor` are thin
63
+ wrappers that hard-code it (`<EmailEditor mode="richtext" />` /
64
+ `<EmailEditor mode="form" />` respectively):
65
+
66
+ | `mode` | What |
67
+ | --- | --- |
68
+ | `builder` (default) | Full drag-and-drop block email builder. |
69
+ | `richtext` | A simple Quill-like rich-text field (persistent toolbar, single editable surface). Takes `value` (HTML string) instead of `initialTree`; `onChange` still fires `{ tree, html }` (`tree` is a single Custom HTML block wrapping the field's HTML). |
70
+ | `form` | Drag-and-drop form builder (semantic, responsive `<form>` output). `onChange` fires `{ tree, html, schema }`. |
71
+ | `certificate` | The block builder laid out on a fixed landscape print page with a background, for certificates/awards. |
72
+
73
+ ### Props
74
+
75
+ | Prop | Modes | What |
76
+ | --- | --- | --- |
77
+ | `mode` | all | `'builder'` (default) \| `'richtext'` \| `'form'` \| `'certificate'`. |
78
+ | `initialTree` | builder, form, certificate | `{ version, root }` — saved block tree, or omit for a blank starter. Read **once** at mount (like `defaultValue`); remount via a React `key` to load a different record. |
79
+ | `value` | richtext | HTML string — the saved content. Re-applied if it changes while the field is unfocused (async form loads). |
80
+ | `mergeTags` | all | `[{ tag: '{{first_name}}', label: 'First name' }, ...]` — host personalization tags, inserted verbatim and resolved at the host's send time. |
81
+ | `mediaUpload` | all | `({ allowedTypes }) => Promise<{ url, id, alt } | null>`. Optional; defaults to `defaultMediaUpload` (native file picker, `data:` URL). |
82
+ | `onChange` | all | Debounced. `{ tree, html }` (`form` mode also includes `schema`). |
83
+ | `header` | builder, richtext, form | `false` (default) \| `true` — shows a slim Preview bar. Always on for `certificate`. |
84
+ | `height` | all | Editor height in px. Omit to use the stylesheet defaults (640 builder/form/certificate, 320 richtext), which hosts can override by class. |
85
+ | `renderMode` | builder | `'document'` (full `<!doctype html>…` email) \| `'fragment'` (content only — host wraps its own `<html>/<body>` shell). |
86
+ | `blocks` | builder, form, certificate | Optional manifest override, replacing the mode's default block set entirely. |
87
+ | `blockPlugins` | builder, form | `[{ type, spec, render, controls, schema }, ...]` — teach the editor host-specific blocks without forking the core. `render(node, ctx, helpers)` returns an HTML string; `helpers` exposes the built-in renderers and style utilities so a plugin can delegate to them. See `dev_emb/library/blockPlugins.js`. |
88
+ | `hideBlocks` | builder, form, certificate | `string[]` of core block types to drop from the palette/quick-add. Blocks already present in a saved tree still render. |
89
+ | `templates` | builder, certificate | Array of starter templates shown in the template picker. |
90
+ | `onTemplatesClick` | builder, certificate | Callback when the host's own "browse templates" affordance is used. |
91
+ | `suffix` | all | Theming hook, e.g. `suffix="zaplane"`. Every shell chrome piece gets a stable `--{suffix}` modifier class, and hosts can override the `--emb-*` custom properties on `.emb-embed-root--{suffix}` to theme the chrome (e.g. dark mode) without `!important`. |
92
+ | `config` | all | `{ 'English string': 'Host-translated string', ... }` — plain lookup object. The package does no translation logic of its own; the host resolves everything and hands over final strings. Anything missing falls back to the English text as-is. Omit for plain English. See [i18n](#i18n). |
93
+
94
+ Ref handle (all modes): `{ getTree, getHtml, getSchema, setTree, setHtml }`.
95
+ Not every method is meaningful in every mode (e.g. `setHtml` is for
96
+ `richtext`) — calling one that doesn't apply is a no-op. Read
97
+ `getHtml()`/`getTree()` on the host's submit to capture the latest value even
98
+ if the debounce hasn't fired.
99
+
58
100
  ### Exports
59
101
 
60
102
  | Export | What |
61
103
  | --- | --- |
62
- | `EmailEditor` | The controlled editor component (forwardRef → `{ getTree, getHtml, setTree }`). |
104
+ | `EmailEditor` | The controlled editor component (forwardRef, all modes — see above). |
105
+ | `RichTextEditor` | Convenience wrapper = `<EmailEditor mode="richtext" />`. |
106
+ | `FormEditor` | Convenience wrapper = `<EmailEditor mode="form" />`. |
63
107
  | `renderDocument(tree)` | Tree → full email HTML document (doctype + MSO shell). |
64
- | `renderContent(tree)` | Tree → content fragment (no doctype/body) for hosts that wrap in their own email shell. |
65
- | `BLANK_TREE` | Starter tree used when `initialTree` is absent. |
66
- | `defaultMediaUpload` | The `wp.media`-backed default media handler. |
108
+ | `renderContent(tree)` | Tree → email content fragment (no doctype/body) for hosts that wrap in their own email shell. |
109
+ | `renderFormDocument(tree)` / `renderFormContent(tree)` | Same, for a `form`-mode tree. |
110
+ | `renderCertificateDocument(tree)` / `renderCertificateContent(tree)` | Same, for a `certificate`-mode tree. |
111
+ | `extractSchema(tree)` | Form tree → field schema (also emitted as `schema` in `form`-mode `onChange`). |
112
+ | `pageDims` | Fixed page dimensions used by the certificate layout. |
113
+ | `treeFromHtml(html)` / `htmlToBlocks(html)` | Best-effort HTML → block tree, for importing existing content. |
114
+ | `BLANK_TREE` | Starter tree used when `initialTree` is absent (`builder`/`richtext`). |
115
+ | `BLANK_CERT_TREE` | Starter tree for `certificate` mode. |
116
+ | `defaultMediaUpload` | The native file-picker default media handler (see Media picker above). |
117
+
118
+ ## i18n
119
+
120
+ Every UI string is untranslated (plain English) by default — there's no
121
+ bundled translation catalog and no runtime translate hook. To localize, pass
122
+ a plain lookup object as the `config` prop:
67
123
 
68
- ### `renderMode`
124
+ ```jsx
125
+ <EmailEditor config={{ 'Add block': 'Ajouter un bloc' }} />
126
+ ```
69
127
 
70
- - `document` — store the full `<!doctype html>…` email (standalone sending).
71
- - `fragment` — store just the content table + blocks; use when the host wraps the
72
- body in its own `<html>/<body>` shell (e.g. GemCRM injects header/footer), to
73
- avoid double-wrapping.
128
+ The package does no lookup/interpolation logic beyond `config[text] ?? text`
129
+ — the host is responsible for resolving strings up front.
74
130
 
75
131
  ## Storage contract
76
132
 
77
- The host owns persistence. `onChange` gives `{ tree, html }`:
133
+ The host owns persistence. `onChange` gives `{ tree, html }` (plus `schema`
134
+ in `form` mode):
78
135
 
79
136
  - `html` → the field your send pipeline already uses.
80
137
  - `tree` (JSON) → a sibling field, so the editor round-trips on reopen.
81
138
 
82
- (`tree` holds HTML inside richtext attributes; if your storage sanitizes with
83
- `sanitize_text_field`/kses, base64-encode it first.)
84
-
85
- ## Updating / releasing
86
-
87
- This is built from `dev_emb/library/` in the Easy Mail Builder plugin.
139
+ ## Building from source
88
140
 
89
141
  ```bash
90
- # in easy-mail-builder/
91
- npm run build:library # → email-builder-lib/dist/index.js
92
-
93
- # bump version
94
- npm version patch --prefix email-builder-lib
95
-
96
- # publish (registry of your choice)
97
- npm publish --prefix email-builder-lib # add --access public for a public scope
142
+ npm install
143
+ npm run build # → dist/index.js
98
144
  ```
99
-
100
- After rebuilding, `file:`-dependent consumers must re-run `npm install` (and rebuild)
101
- to pick up the new `dist`.