@kontakto/email-template-editor 1.5.1 → 2.0.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/README.md CHANGED
@@ -49,14 +49,70 @@ function MyApp() {
49
49
  | `initialTemplate` | object | - | Initial template to load when editor first mounts |
50
50
  | `initialTemplateId` | string | - | ID of the initial template |
51
51
  | `initialTemplateName` | string | - | Name of the initial template |
52
- | `onSave` | function | - | Callback when template is saved: `(template) => void` |
52
+ | `onSave` | function | - | Callback when template is saved: `(payload: SavePayload) => void \| Promise<void>` (see SavePayload below) |
53
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[]>` |
54
+ | `loadSamples` | function | - | Loads sample templates: `() => Promise<TemplateListItem[]>` |
55
+ | `loadTemplates` | function | - | Loads user templates: `() => Promise<TemplateListItem[]>` |
56
56
  | `loadTemplate` | function | - | Loads specific template: `(id) => Promise<Template>` |
57
57
  | `deleteTemplate` | function | - | Deletes a template: `(id) => void` |
58
58
  | `copyTemplate` | function | - | Copies a template: `(name, content) => void` |
59
- | `saveAs` | function | - | Saves template with new name: `(name, content) => Promise<{id, name}>` |
59
+ | `renameTemplate` | function | - | Renames a template: `(id, newSlug) => void \| Promise<void>` |
60
+ | `setTemplateKind` | function | - | Promotes/demotes a row between template and sample: `(id, kind) => void \| Promise<void>`. When omitted, promote/demote menu items are hidden. |
61
+ | `saveAs` | function | - | Saves template with a new name: `(name, payload: SavePayload) => Promise<{ id, slug }>` |
62
+
63
+ `TemplateListItem` is the lean list-endpoint shape (no `editor_config`):
64
+
65
+ ```ts
66
+ type TemplateKind = 'template' | 'sample';
67
+
68
+ type TemplateListItem = {
69
+ id: string;
70
+ slug: string; // primary label
71
+ kind: TemplateKind; // 'template' (editable) or 'sample' (read-only starting point)
72
+ description?: string; // secondary line
73
+ subject?: string;
74
+ variables?: Array<{ name: string; description?: string }>;
75
+ tags?: string[];
76
+ thumbnailUrl?: string;
77
+ createdAt?: string;
78
+ updatedAt?: string;
79
+ };
80
+ ```
81
+
82
+ The drawer groups rows by `kind`, not by which callback returned them. Both `loadTemplates` and `loadSamples` should return their items with the correct `kind`; backends typically scope the two endpoints differently (per-user vs. org-wide), but the `kind` field is what determines the section a row appears in.
83
+
84
+ Samples are read-only starting points: Save on a loaded sample is disabled — the user must use Save As, which creates a fresh row with `kind='template'`.
85
+
86
+ #### Subject and variables
87
+
88
+ Email subject and template variables are stored on the `EmailLayout` block's data and round-trip with the editor configuration:
89
+
90
+ ```ts
91
+ type EmailLayoutData = {
92
+ // ...style fields
93
+ subject?: string;
94
+ variables?: Array<{ name: string; description?: string }>;
95
+ };
96
+ ```
97
+
98
+ The editor renders a subject input above the canvas (always visible, supports `{{variable}}` syntax) and a Variables tab in the right inspector panel for declaring variables. Both persist via the standard save flow — consumers who previously stored `subject` in a separate DB column can read it from the saved `editor_config` instead.
99
+
100
+ #### Save payload
101
+
102
+ `onSave` and `saveAs` receive the same `SavePayload`. The editor renders body HTML and plain text on every save so consumers don't ship the renderer themselves:
103
+
104
+ ```ts
105
+ type SavePayload = {
106
+ editorConfig: TEditorConfiguration; // source of truth
107
+ subject?: string; // from the subject input
108
+ variables?: Array<{ name: string; description?: string }>;
109
+ bodyHtml: string; // pre-rendered, ready to send
110
+ bodyText: string; // pre-rendered, ready to send
111
+ };
112
+ ```
113
+
114
+ The `renderToStaticMarkup` and `renderToText` utilities are also exposed publicly for consumers that need to re-render outside the save flow (e.g. batch jobs).
115
+
60
116
  | `theme` | object | theme.ts | Custom theme for the EmailEditor, must be a Material UI theme object |
61
117
 
62
118
  #### Imperative API