@emabuild/react 0.7.0 → 0.7.2
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 +21 -0
- package/dist/EmabuildEditor.d.ts +7 -26
- package/dist/EmabuildEditor.js +26 -37
- package/package.json +13 -7
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Fabio Varrenti
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/EmabuildEditor.d.ts
CHANGED
|
@@ -19,9 +19,13 @@
|
|
|
19
19
|
*/
|
|
20
20
|
import { type CSSProperties, type ReactNode } from 'react';
|
|
21
21
|
import '@emabuild/core';
|
|
22
|
-
import type
|
|
23
|
-
import type { EmailDesign, MailEditorConfig, ExportOptions, ExportResult, PlainTextResult, DesignOperation, OperationResult,
|
|
24
|
-
|
|
22
|
+
import { type FrameworkEventName, type FrameworkEventPayloads, type MailEditorElement } from '@emabuild/core';
|
|
23
|
+
import type { EmailDesign, MailEditorConfig, ExportOptions, ExportResult, PlainTextResult, DesignOperation, OperationResult, AIRunResult, AIContext, AIAction, EmailHtmlReport, ImportHtmlOptions, ImportHtmlResult } from '@emabuild/types';
|
|
24
|
+
/** `onReady`, `onDesignLoaded`, … — one optional callback per re-emitted editor event */
|
|
25
|
+
export type EmabuildEditorEventProps = {
|
|
26
|
+
[K in FrameworkEventName as `on${Capitalize<K>}`]?: (payload: FrameworkEventPayloads[K]) => void;
|
|
27
|
+
};
|
|
28
|
+
export interface EmabuildEditorProps extends EmabuildEditorEventProps {
|
|
25
29
|
/** Editor options — re-applied whenever the object identity changes (memoize it) */
|
|
26
30
|
options?: MailEditorConfig;
|
|
27
31
|
/** URL of a JSON config file, deep-merged under `options` */
|
|
@@ -36,29 +40,6 @@ export interface EmabuildEditorProps {
|
|
|
36
40
|
* `panel-bottom`, `canvas-bottom`) or an extra tab (`tab-<name>`, label in `data-tab-label`).
|
|
37
41
|
*/
|
|
38
42
|
children?: ReactNode;
|
|
39
|
-
onReady?: () => void;
|
|
40
|
-
onDesignLoaded?: (detail: {
|
|
41
|
-
design: EmailDesign;
|
|
42
|
-
}) => void;
|
|
43
|
-
onDesignUpdated?: (detail: DesignUpdatedEvent) => void;
|
|
44
|
-
onSelectionChanged?: (selection: EditorSelection | null) => void;
|
|
45
|
-
onBlockSaved?: (block: SavedBlock) => void;
|
|
46
|
-
onBlockRemoved?: (blockId: string) => void;
|
|
47
|
-
onAiStart?: (detail: unknown) => void;
|
|
48
|
-
onAiEvent?: (event: AIStreamEvent) => void;
|
|
49
|
-
onAiDone?: (result: AIRunResult) => void;
|
|
50
|
-
onAiError?: (result: AIRunResult) => void;
|
|
51
|
-
onAiUsage?: (usage: AIUsage) => void;
|
|
52
|
-
onConfigLoaded?: (detail: {
|
|
53
|
-
config: MailEditorConfig;
|
|
54
|
-
issues: Array<{
|
|
55
|
-
path: string;
|
|
56
|
-
message: string;
|
|
57
|
-
}>;
|
|
58
|
-
}) => void;
|
|
59
|
-
onConfigError?: (detail: {
|
|
60
|
-
error: string;
|
|
61
|
-
}) => void;
|
|
62
43
|
}
|
|
63
44
|
export interface EmabuildEditorHandle {
|
|
64
45
|
/** The underlying element (full API) */
|
package/dist/EmabuildEditor.js
CHANGED
|
@@ -20,22 +20,9 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
20
20
|
*/
|
|
21
21
|
import { forwardRef, useEffect, useImperativeHandle, useRef } from 'react';
|
|
22
22
|
import '@emabuild/core';
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
['design:loaded', 'onDesignLoaded', (d) => d],
|
|
27
|
-
['design:updated', 'onDesignUpdated', (d) => d],
|
|
28
|
-
['selection:changed', 'onSelectionChanged', (d) => d?.selection ?? null],
|
|
29
|
-
['block:saved', 'onBlockSaved', (d) => d?.block],
|
|
30
|
-
['block:removed', 'onBlockRemoved', (d) => d?.blockId],
|
|
31
|
-
['ai:start', 'onAiStart', (d) => d],
|
|
32
|
-
['ai:event', 'onAiEvent', (d) => d],
|
|
33
|
-
['ai:done', 'onAiDone', (d) => d],
|
|
34
|
-
['ai:error', 'onAiError', (d) => d],
|
|
35
|
-
['ai:usage', 'onAiUsage', (d) => d],
|
|
36
|
-
['config:loaded', 'onConfigLoaded', (d) => d],
|
|
37
|
-
['config:error', 'onConfigError', (d) => d],
|
|
38
|
-
];
|
|
23
|
+
import { connectFrameworkEvents } from '@emabuild/core';
|
|
24
|
+
/** Prop name of the callback for an event, e.g. `designLoaded` → `onDesignLoaded` */
|
|
25
|
+
const callbackProp = (name) => `on${name.charAt(0).toUpperCase()}${name.slice(1)}`;
|
|
39
26
|
export const EmabuildEditor = forwardRef(function EmabuildEditor(props, ref) {
|
|
40
27
|
const elRef = useRef(null);
|
|
41
28
|
const propsRef = useRef(props);
|
|
@@ -46,20 +33,15 @@ export const EmabuildEditor = forwardRef(function EmabuildEditor(props, ref) {
|
|
|
46
33
|
const el = elRef.current;
|
|
47
34
|
if (!el)
|
|
48
35
|
return;
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
cb?.(unwrap(e.detail));
|
|
58
|
-
};
|
|
59
|
-
el.addEventListener(name, fn);
|
|
60
|
-
return [name, fn];
|
|
36
|
+
return connectFrameworkEvents(el, (name, payload) => {
|
|
37
|
+
if (name === 'ready') {
|
|
38
|
+
ready.current = true;
|
|
39
|
+
if (propsRef.current.design)
|
|
40
|
+
el.loadDesign(propsRef.current.design);
|
|
41
|
+
}
|
|
42
|
+
// `name` and `payload` correlate, but TS cannot follow that through the prop lookup
|
|
43
|
+
propsRef.current[callbackProp(name)]?.(payload);
|
|
61
44
|
});
|
|
62
|
-
return () => handlers.forEach(([name, fn]) => el.removeEventListener(name, fn));
|
|
63
45
|
}, []);
|
|
64
46
|
// Options are a property, not an attribute
|
|
65
47
|
useEffect(() => {
|
|
@@ -74,18 +56,25 @@ export const EmabuildEditor = forwardRef(function EmabuildEditor(props, ref) {
|
|
|
74
56
|
if (ready.current && props.design)
|
|
75
57
|
elRef.current?.loadDesign(props.design);
|
|
76
58
|
}, [props.design]);
|
|
59
|
+
/** The mounted element; handle methods that need it throw a clear error before mount */
|
|
60
|
+
const editor = () => {
|
|
61
|
+
const el = elRef.current;
|
|
62
|
+
if (!el)
|
|
63
|
+
throw new Error('EmabuildEditor is not mounted');
|
|
64
|
+
return el;
|
|
65
|
+
};
|
|
77
66
|
useImperativeHandle(ref, () => ({
|
|
78
67
|
get editor() { return elRef.current; },
|
|
79
|
-
exportHtml: (o) =>
|
|
80
|
-
exportPlainText: (o) =>
|
|
68
|
+
exportHtml: (o) => editor().exportHtmlAsync(o),
|
|
69
|
+
exportPlainText: (o) => editor().exportPlainText(o),
|
|
81
70
|
getDesign: () => elRef.current?.getDesign(),
|
|
82
71
|
loadDesign: (d) => elRef.current?.loadDesign(d),
|
|
83
|
-
applyOperations: (ops, options) =>
|
|
84
|
-
reveal: (id) =>
|
|
85
|
-
runAI: (input) =>
|
|
86
|
-
checkHtml: (html, options) =>
|
|
87
|
-
importHtml: (html, options) =>
|
|
88
|
-
showPreview: (device) =>
|
|
72
|
+
applyOperations: (ops, options) => editor().applyOperations(ops, options),
|
|
73
|
+
reveal: (id) => editor().reveal(id),
|
|
74
|
+
runAI: (input) => editor().runAI(input),
|
|
75
|
+
checkHtml: (html, options) => editor().checkHtml(html, options),
|
|
76
|
+
importHtml: (html, options) => editor().importHtml(html, options),
|
|
77
|
+
showPreview: (device) => editor().showPreview(device),
|
|
89
78
|
undo: () => elRef.current?.undo(),
|
|
90
79
|
redo: () => elRef.current?.redo(),
|
|
91
80
|
}), []);
|
package/package.json
CHANGED
|
@@ -1,22 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@emabuild/react",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.2",
|
|
4
4
|
"description": "React wrapper component for the @emabuild/core email editor",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
7
|
-
"README.md"
|
|
7
|
+
"README.md",
|
|
8
|
+
"LICENSE"
|
|
8
9
|
],
|
|
9
10
|
"peerDependencies": {
|
|
10
11
|
"react": ">=17",
|
|
11
|
-
"@emabuild/
|
|
12
|
-
"@emabuild/
|
|
12
|
+
"@emabuild/types": "^0.8.1",
|
|
13
|
+
"@emabuild/core": "^0.9.0"
|
|
13
14
|
},
|
|
14
15
|
"devDependencies": {
|
|
15
|
-
"react": "^18.3.1",
|
|
16
16
|
"@types/react": "^18.3.12",
|
|
17
|
+
"react": "^18.3.1",
|
|
17
18
|
"typescript": "^5.7.0",
|
|
18
|
-
"@emabuild/core": "0.
|
|
19
|
-
"@emabuild/types": "0.
|
|
19
|
+
"@emabuild/core": "0.9.0",
|
|
20
|
+
"@emabuild/types": "0.8.1"
|
|
20
21
|
},
|
|
21
22
|
"license": "MIT",
|
|
22
23
|
"type": "module",
|
|
@@ -32,6 +33,11 @@
|
|
|
32
33
|
"publishConfig": {
|
|
33
34
|
"access": "public"
|
|
34
35
|
},
|
|
36
|
+
"repository": {
|
|
37
|
+
"type": "git",
|
|
38
|
+
"url": "git+https://github.com/Fabiovarrenti/emabuild.git",
|
|
39
|
+
"directory": "wrappers/react"
|
|
40
|
+
},
|
|
35
41
|
"scripts": {
|
|
36
42
|
"build": "tsc -p tsconfig.build.json",
|
|
37
43
|
"typecheck": "tsc --noEmit -p ."
|