@kontakto/email-template-editor 1.2.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 ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Waypoint (Metaccountant, Inc.)
4
+ Copyright (c) 2025 Kontakto Oy
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,169 @@
1
+ # Email Editor for React
2
+
3
+ A React-based email template editor component that allows users to create and customize email templates through a visual interface. This component can be embedded in any React application.
4
+
5
+ ## Features
6
+
7
+ - Visual email template builder
8
+ - Rich set of components (text, buttons, images, dividers, containers, columns, etc.)
9
+ - Markdown support for text editing
10
+ - Responsive email templates
11
+ - Embeddable into React applications
12
+
13
+ ## Installation
14
+
15
+ ```bash
16
+ npm install @kontakto/email-template-editor
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ ### Embedding into existing project
22
+
23
+ You can easily embed the EmailEditor into any React application:
24
+
25
+ ```jsx
26
+ import { EmailEditor } from '@kontakto/email-template-editor';
27
+
28
+ function MyApp() {
29
+ return (
30
+ <div className="my-container">
31
+ <EmailEditor
32
+ persistenceEnabled={true}
33
+ minHeight="80vh"
34
+ />
35
+ </div>
36
+ );
37
+ }
38
+ ```
39
+
40
+ #### Available Props
41
+
42
+ | Prop | Type | Default | Description |
43
+ |------|------|---------|-------------|
44
+ | `minHeight` | string | '100vh' | Sets the minimum height of the editor container |
45
+ | `persistenceEnabled` | boolean | false | When true, enables save functionality and shows save buttons. Requires callbacks for persistence operations. |
46
+ | `samplesDrawerEnabled` | boolean | true | Controls whether the templates/samples drawer is shown |
47
+ | `drawerEnterDuration` | number | 225 | Duration for drawer enter transition (ms) |
48
+ | `drawerExitDuration` | number | 225 | Duration for drawer exit transition (ms) |
49
+ | `initialTemplate` | object | - | Initial template to load when editor first mounts |
50
+ | `initialTemplateId` | string | - | ID of the initial template |
51
+ | `initialTemplateName` | string | - | Name of the initial template |
52
+ | `onSave` | function | - | Callback when template is saved: `(template) => void` |
53
+ | `onChange` | function | - | Callback when template changes: `(template) => void` |
54
+ | `loadSamples` | function | - | Loads sample templates: `() => Promise<SampleTemplate[]>` |
55
+ | `loadTemplates` | function | - | Loads user templates: `() => Promise<SampleTemplate[]>` |
56
+ | `loadTemplate` | function | - | Loads specific template: `(id) => Promise<Template>` |
57
+ | `deleteTemplate` | function | - | Deletes a template: `(id) => void` |
58
+ | `copyTemplate` | function | - | Copies a template: `(name, content) => void` |
59
+ | `saveAs` | function | - | Saves template with new name: `(name, content) => Promise<{id, name}>` |
60
+ | `theme` | object | theme.ts | Custom theme for the EmailEditor, must be a Material UI theme object |
61
+
62
+ #### Imperative API
63
+
64
+ You can access the EmailEditor's methods using a ref:
65
+
66
+ ```jsx
67
+ import { EmailEditor } from 'kontakto-email-editor';
68
+ import { useRef } from 'react';
69
+
70
+ function MyApp() {
71
+ const editorRef = useRef(null);
72
+
73
+ const handleSave = () => {
74
+ const template = editorRef.current.saveTemplate();
75
+ console.log('Saved template:', template);
76
+ };
77
+
78
+ const handleLoad = (template) => {
79
+ editorRef.current.loadTemplate(template);
80
+ };
81
+
82
+ const handleGetCurrent = () => {
83
+ const current = editorRef.current.getTemplate();
84
+ console.log('Current template:', current);
85
+ };
86
+
87
+ return (
88
+ <div>
89
+ <button onClick={handleSave}>Save</button>
90
+ <button onClick={handleGetCurrent}>Get Current</button>
91
+ <EmailEditor ref={editorRef} minHeight="600px" />
92
+ </div>
93
+ );
94
+ }
95
+ ```
96
+
97
+ ### Stand-alone version using Vite
98
+
99
+ This project includes a standalone version that can be run using Vite:
100
+
101
+ ```bash
102
+ # Install dependencies
103
+ npm install
104
+
105
+ # Run the development server
106
+ npm run dev
107
+ ```
108
+
109
+ This will start a development server with the EmailEditor running as a standalone application that uses browsers local storage to save and load templates.
110
+
111
+ ## Theming
112
+
113
+ The EmailEditor component has the CssBaseline and ThemeProvider components from Material UI applied by default. However, if you need to supply a custom theme, you can do so by passing a custom theme to the EmailEditor component. The theme should be a Material UI theme object.
114
+
115
+
116
+ ## Development
117
+
118
+ To run this locally:
119
+
120
+ 1. Clone the repository
121
+ 2. Install dependencies:
122
+ ```
123
+ npm install
124
+ ```
125
+ 3. Start the development server:
126
+ ```
127
+ npm run dev
128
+ ```
129
+ 4. Visit http://localhost:5173/ in your browser
130
+
131
+ ## Project Structure
132
+
133
+ - `src/blocks/` - Email components (text, images, buttons, etc.)
134
+ - `src/editor/` - Core editor functionality
135
+ - `src/app/` - Main application components
136
+ - `src/email-builder/` - Email template rendering
137
+ - `src/core/` - Core utilities and types
138
+
139
+ ## Technologies
140
+
141
+ - React
142
+ - TypeScript
143
+ - Material UI
144
+ - Zustand for state management
145
+ - Vite as the build tool
146
+ - Marked and Highlight.js for markdown and code highlighting
147
+
148
+ # Email-Template-Editor
149
+
150
+ Licensed under the MIT License. See `LICENSE` for details.
151
+
152
+ This project, Email-Template-Editor, is a substantial derivative work based on an original MIT-licensed project, `email-builder-js` by Waypoint (Metaccountant, Inc.). `email-builder-js` is a free and open-source block-based email template builder designed for developers to create emails with JSON or HTML output. While the original code was created by Waypoint, this project has been significantly refactored with:
153
+
154
+ 1. Restructuring of the project files and directories.
155
+ 2. Implementation of how external context is handled.
156
+ 3. Changes to the purpose of the project to be integrated and embedded into other React based projects.
157
+
158
+ ## Original Code from Waypoint (Metaccountant, Inc.)
159
+
160
+ The following parts (not limited to) of this project are derived from the original MIT-licensed project `email-builder-js` by Waypoint:
161
+
162
+ * The parsing logic is based on Waypoint's original block-based parsing approach
163
+ * The concepts for the blocks
164
+ * The concepts for the editor
165
+ * The concepts of the builder
166
+
167
+ ## Acknowledgements
168
+
169
+ This project gratefully acknowledges the original work by Waypoint (Metaccountant, Inc.) on `email-builder-js` as the foundation upon which this version was built.