sazmail-react 0.1.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 +21 -0
- package/README.md +95 -0
- package/dist/MailBuilder.d.ts +30 -0
- package/dist/index.cjs.js +296 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.es.js +674 -0
- package/package.json +46 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025-PRESENT Mazlum Ozdogan <https://github.com/mergehez>
|
|
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/README.md
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# Sazmail
|
|
2
|
+
|
|
3
|
+
This is a React component that lets you use the [Sazmail](https://github.com/mergehez/sazmail) right inside your React applications.
|
|
4
|
+
|
|
5
|
+
It's pretty straightforward to set up and use. The only dependencies are `react` and `react-dom`.
|
|
6
|
+
|
|
7
|
+
If you're working with Vue, there's a version for that too: [Sazmail](https://github.com/mergehez/sazmail)
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
bun install sazmail-react
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install sazmail-react
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Basic Usage
|
|
20
|
+
|
|
21
|
+
```tsx
|
|
22
|
+
import React, {useState, useCallback} from 'react';
|
|
23
|
+
import MailBuilder from 'sazmail-react';
|
|
24
|
+
// import type {MailBuilderDocument} from 'sazmail-react' // if you need the type for the document
|
|
25
|
+
|
|
26
|
+
const App: React.FC = () => {
|
|
27
|
+
const [doc, setDoc] = useState('{}');
|
|
28
|
+
const [html, setHtml] = useState<string | undefined>(undefined);
|
|
29
|
+
|
|
30
|
+
return (
|
|
31
|
+
<div style = {{width: '100vw', height:'100vh'}}>
|
|
32
|
+
<MailBuilder
|
|
33
|
+
id = "mb-de"
|
|
34
|
+
json = {doc}
|
|
35
|
+
html = {html}
|
|
36
|
+
onUpdateJson = {setDoc}
|
|
37
|
+
onUpdateHtml = {setHtml}
|
|
38
|
+
style = {{width: '100%', height: '100%'}}
|
|
39
|
+
/>
|
|
40
|
+
< /div>
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
export default App;
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
> Make sure the container for <MailBuilder /> has a defined height, as the builder will try to fill it.
|
|
47
|
+
|
|
48
|
+
## Properties
|
|
49
|
+
|
|
50
|
+
> `TJson`: `string` or `MailBuilderDocument`
|
|
51
|
+
|
|
52
|
+
| Prop | Type | Description |
|
|
53
|
+
|--------------|----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|
54
|
+
| id | string | An optional unique ID for the builder instance. Useful if you have multiple builders on a page. |
|
|
55
|
+
| json | TJson or undefined | The core data for the email template. You can pass a JSON string or a JavaScript object directly. Use with `v-model:json`. An empty object or `'{}'` starts a new template. |
|
|
56
|
+
| html | string or undefined | Holds the generated HTML of the email template. Use with `v-model:html`. |
|
|
57
|
+
| onUpdateJson | (nv: TJson) => void | Callback function that gets called whenever the JSON data changes. Use this to update your state or perform other actions when the JSON is modified. |
|
|
58
|
+
| onUpdateHtml | (nv: string) => void | Callback function that gets called whenever the HTML output changes. Use this to update your state or perform other actions when the HTML is modified. |
|
|
59
|
+
|
|
60
|
+
### MailBuilderDocument
|
|
61
|
+
|
|
62
|
+
The `json` prop (whether as an object or a string) should conform to this structure:
|
|
63
|
+
|
|
64
|
+
```typescript
|
|
65
|
+
type BlockId = string;
|
|
66
|
+
export type MailBuilderDocument = {
|
|
67
|
+
version: string;
|
|
68
|
+
structure: Record<BlockId, {
|
|
69
|
+
customName?: string;
|
|
70
|
+
blockId: BlockId;
|
|
71
|
+
parentId: BlockId;
|
|
72
|
+
type: string;
|
|
73
|
+
condition?: string; // A liquid.js expression for conditional rendering
|
|
74
|
+
childrenIds?: BlockId[];
|
|
75
|
+
}>;
|
|
76
|
+
data: Record<BlockId, Record<string, any>>;
|
|
77
|
+
testJson?: Record<string, any>; // Sample data for template rendering/testing
|
|
78
|
+
};
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
> Providing an empty object `{}` or an empty JSON string `'{}'` will initialize a new, blank template.
|
|
82
|
+
|
|
83
|
+
## A Little More Detail
|
|
84
|
+
|
|
85
|
+
This component is essentially a bridge to the main [Sazmail](https://github.com/mergehez/sazmail). The builder itself is a self-contained HTML file. `sazmail-react` takes that file, puts it into an iframe, and then uses postMessage and React's state/prop system to pass data back and forth. This way, you get the full builder experience without a complicated setup.
|
|
86
|
+
|
|
87
|
+
## License
|
|
88
|
+
|
|
89
|
+
This project is shared under the MIT License. You can find the details in the [LICENSE](LICENSE) file.
|
|
90
|
+
|
|
91
|
+
Feel free to use it in both personal and commercial projects.
|
|
92
|
+
|
|
93
|
+
## Contributing
|
|
94
|
+
|
|
95
|
+
Got ideas or improvements? Contributions are definitely welcome! Please read the [CONTRIBUTING.md](CONTRIBUTING.md) file for details on how to contribute.
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
export type MailBuilderDocument = {
|
|
3
|
+
version: string;
|
|
4
|
+
structure: Record<string, {
|
|
5
|
+
customName?: string;
|
|
6
|
+
blockId: string;
|
|
7
|
+
parentId: string;
|
|
8
|
+
type: string;
|
|
9
|
+
condition?: string;
|
|
10
|
+
}>;
|
|
11
|
+
data: Record<string, Record<string, any>>;
|
|
12
|
+
testJson?: Record<string, any>;
|
|
13
|
+
};
|
|
14
|
+
export interface MailBuilderRef {
|
|
15
|
+
requestDataFromBuilder: () => void;
|
|
16
|
+
}
|
|
17
|
+
export interface MailBuilderProps<TJson extends string | MailBuilderDocument> {
|
|
18
|
+
id?: string;
|
|
19
|
+
json: TJson | undefined;
|
|
20
|
+
html?: string | undefined;
|
|
21
|
+
displayMode?: 'preview' | 'edit';
|
|
22
|
+
autoSave?: boolean;
|
|
23
|
+
onUpdateJson: (json: TJson) => void;
|
|
24
|
+
onUpdateHtml: (html: string | undefined) => void;
|
|
25
|
+
style?: React.CSSProperties;
|
|
26
|
+
}
|
|
27
|
+
declare const MailBuilder: <TJson extends string | MailBuilderDocument>(props: MailBuilderProps<TJson> & {
|
|
28
|
+
ref?: React.Ref<MailBuilderRef>;
|
|
29
|
+
}) => React.ReactElement;
|
|
30
|
+
export default MailBuilder;
|