@kodezen/editor 1.0.0-beta.1 → 1.0.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 CHANGED
@@ -1,4 +1,4 @@
1
- # @kodezen/editor
1
+ # @kodezen/email-builder-editor
2
2
 
3
3
  Embeddable drag-and-drop **block email editor**, extracted from Easy Mail Builder.
4
4
  A drop-in replacement for a Quill/TinyMCE editor: it produces the email HTML
@@ -7,8 +7,20 @@ required of the host) and ships **zero global CSS** (every pane is inline-styled
7
7
 
8
8
  ## Install
9
9
 
10
+ Published/registry:
11
+
10
12
  ```bash
11
- npm install @kodezen/editor
13
+ npm install @kodezen/email-builder-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/email-builder-editor": "file:../easy-mail-builder/email-builder-lib"
23
+ }
12
24
  ```
13
25
 
14
26
  The package is **pre-built** (transpiled ESM) so it works with `@wordpress/scripts`,
@@ -23,73 +35,34 @@ must have run `wp_enqueue_media()`.
23
35
 
24
36
  ## Usage
25
37
 
26
- A full example: an email-template editor screen that loads an existing record,
27
- lets the user edit it, and saves both `html` and `tree` on submit.
28
-
29
38
  ```jsx
30
- import { useEffect, useRef, useState } from 'react';
31
- import { EmailEditor, BLANK_TREE } from '@kodezen/editor';
32
-
33
- function EmailTemplateScreen( { templateId } ) {
34
- const ref = useRef();
35
- const [ initialTree, setInitialTree ] = useState( null );
36
- const [ saving, setSaving ] = useState( false );
37
-
38
- // Load once — initialTree is read only at mount.
39
- useEffect( () => {
40
- fetchTemplate( templateId ).then( ( record ) => {
41
- setInitialTree( record.tree ?? BLANK_TREE );
42
- } );
43
- }, [ templateId ] );
44
-
45
- const handleSave = async () => {
46
- setSaving( true );
47
- await persistTemplate( templateId, {
48
- html: ref.current.getHtml(), // pull latest value past the debounce
49
- tree: ref.current.getTree(),
50
- } );
51
- setSaving( false );
52
- };
53
-
54
- if ( ! initialTree ) {
55
- return <p>Loading…</p>;
56
- }
57
-
58
- return (
59
- <>
60
- <EmailEditor
61
- // Remount when switching records (initialTree is read once at mount).
62
- key={ templateId }
63
- ref={ ref }
64
- initialTree={ initialTree }
65
- mergeTags={ [ { tag: '{{first_name}}', label: 'First name' } ] }
66
- mediaUpload={ async ( { allowedTypes } ) => ( { url, id, alt } ) } // optional; defaults to wp.media
67
- onChange={ ( { tree, html } ) => autosave( templateId, { tree, html } ) } // debounced
68
- renderMode="document" // 'document' (full email) | 'fragment' (host wraps in its own shell)
69
- header // show a slim Preview bar
70
- />
71
- <button onClick={ handleSave } disabled={ saving }>
72
- { saving ? 'Saving…' : 'Save' }
73
- </button>
74
- </>
75
- );
76
- }
39
+ import { EmailEditor, renderContent, renderDocument, BLANK_TREE } from '@kodezen/email-builder-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();
77
56
  ```
78
57
 
79
58
  ### Exports
80
59
 
81
60
  | Export | What |
82
61
  | --- | --- |
83
- | `EmailEditor` | The controlled editor component (forwardRef → `{ getTree, getHtml, setTree }`). Takes a `mode` prop: `"email"` (default), `"richtext"`, or `"form"`. |
84
- | `RichTextEditor` | `<EmailEditor mode="richtext" />` — the plain Quill-like rich-text surface (HTML in / HTML out). |
85
- | `FormEditor` | `<EmailEditor mode="form" />` — drag-and-drop form builder producing a semantic, responsive `<form>`. `onChange` emits `{ tree, html, schema }`. |
62
+ | `EmailEditor` | The controlled editor component (forwardRef → `{ getTree, getHtml, setTree }`). |
86
63
  | `renderDocument(tree)` | Tree → full email HTML document (doctype + MSO shell). |
87
64
  | `renderContent(tree)` | Tree → content fragment (no doctype/body) for hosts that wrap in their own email shell. |
88
- | `renderFormDocument(tree)` / `renderFormContent(tree)` | Form-mode equivalents of the two above. |
89
- | `extractSchema(tree)` | Form tree → JSON schema describing the fields (name, type, required, options). |
90
65
  | `BLANK_TREE` | Starter tree used when `initialTree` is absent. |
91
- | `treeFromHtml(html)` | Best-effort HTML → tree, for importing existing content into the editor. |
92
- | `htmlToBlocks(html)` | Lower-level HTML → block-array conversion used by `treeFromHtml`. |
93
66
  | `defaultMediaUpload` | The `wp.media`-backed default media handler. |
94
67
 
95
68
  ### `renderMode`
@@ -109,6 +82,20 @@ The host owns persistence. `onChange` gives `{ tree, html }`:
109
82
  (`tree` holds HTML inside richtext attributes; if your storage sanitizes with
110
83
  `sanitize_text_field`/kses, base64-encode it first.)
111
84
 
112
- ## License
85
+ ## Updating / releasing
86
+
87
+ This is built from `dev_emb/library/` in the Easy Mail Builder plugin.
88
+
89
+ ```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
98
+ ```
113
99
 
114
- GPL-3.0-or-later. See [`LICENSE`](./LICENSE).
100
+ After rebuilding, `file:`-dependent consumers must re-run `npm install` (and rebuild)
101
+ to pick up the new `dist`.