@kodezen/editor 1.0.0-beta.0 → 1.0.0-beta.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.
Files changed (2) hide show
  1. package/README.md +50 -47
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -7,22 +7,10 @@ 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
-
12
10
  ```bash
13
11
  npm install @kodezen/editor
14
12
  ```
15
13
 
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
14
  The package is **pre-built** (transpiled ESM) so it works with `@wordpress/scripts`,
27
15
  whose Babel loader skips `node_modules`.
28
16
 
@@ -35,24 +23,57 @@ must have run `wp_enqueue_media()`.
35
23
 
36
24
  ## Usage
37
25
 
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
+
38
29
  ```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();
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
+ }
56
77
  ```
57
78
 
58
79
  ### Exports
@@ -88,24 +109,6 @@ The host owns persistence. `onChange` gives `{ tree, html }`:
88
109
  (`tree` holds HTML inside richtext attributes; if your storage sanitizes with
89
110
  `sanitize_text_field`/kses, base64-encode it first.)
90
111
 
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
112
  ## License
110
113
 
111
114
  GPL-3.0-or-later. See [`LICENSE`](./LICENSE).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kodezen/editor",
3
- "version": "1.0.0-beta.0",
3
+ "version": "1.0.0-beta.1",
4
4
  "description": "Embeddable drag-and-drop block email editor extracted from Easy Mail Builder. Drop-in replacement for a Quill/TinyMCE editor — produces email HTML client-side, no DB/CPT/REST required of the host.",
5
5
  "license": "GPL-3.0-or-later",
6
6
  "author": "Kodezen",