@daisychainapp/maily-to-core 0.0.24 → 0.1.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/dist/blocks/index.d.mts +22 -5
- package/dist/blocks/index.d.ts +22 -5
- package/dist/blocks/index.js +39 -12
- package/dist/blocks/index.js.map +1 -1
- package/dist/blocks/index.mjs +37 -11
- package/dist/blocks/index.mjs.map +1 -1
- package/dist/extensions/index.d.mts +332 -0
- package/dist/extensions/index.d.ts +332 -0
- package/dist/extensions/index.js +5119 -0
- package/dist/extensions/index.js.map +1 -0
- package/dist/extensions/index.mjs +5075 -0
- package/dist/extensions/index.mjs.map +1 -0
- package/dist/index.d.mts +24 -7
- package/dist/index.d.ts +24 -7
- package/dist/index.js +5128 -3423
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +5236 -3524
- package/dist/index.mjs.map +1 -1
- package/package.json +12 -1
- package/readme.md +135 -7
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@daisychainapp/maily-to-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Powerful editor for creating beautiful, pre-designed, mobile-ready emails.",
|
|
5
5
|
"private": false,
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -20,6 +20,11 @@
|
|
|
20
20
|
"browser": "./dist/blocks/index.mjs",
|
|
21
21
|
"import": "./dist/blocks/index.mjs",
|
|
22
22
|
"require": "./dist/blocks/index.js"
|
|
23
|
+
},
|
|
24
|
+
"./extensions": {
|
|
25
|
+
"browser": "./dist/extensions/index.mjs",
|
|
26
|
+
"import": "./dist/extensions/index.mjs",
|
|
27
|
+
"require": "./dist/extensions/index.js"
|
|
23
28
|
}
|
|
24
29
|
},
|
|
25
30
|
"typesVersions": {
|
|
@@ -29,6 +34,9 @@
|
|
|
29
34
|
],
|
|
30
35
|
"blocks": [
|
|
31
36
|
"dist/blocks/index.d.ts"
|
|
37
|
+
],
|
|
38
|
+
"extensions": [
|
|
39
|
+
"dist/extensions/index.d.ts"
|
|
32
40
|
]
|
|
33
41
|
}
|
|
34
42
|
},
|
|
@@ -60,6 +68,7 @@
|
|
|
60
68
|
"@radix-ui/react-slot": "^1.1.0",
|
|
61
69
|
"@radix-ui/react-tooltip": "^1.1.3",
|
|
62
70
|
"@tiptap/core": "^2.9.1",
|
|
71
|
+
"@tiptap/extension-code-block-lowlight": "^2.11.5",
|
|
63
72
|
"@tiptap/extension-color": "^2.9.1",
|
|
64
73
|
"@tiptap/extension-document": "^2.9.1",
|
|
65
74
|
"@tiptap/extension-dropcursor": "^2.9.1",
|
|
@@ -81,6 +90,8 @@
|
|
|
81
90
|
"@tiptap/suggestion": "^2.9.1",
|
|
82
91
|
"clsx": "^2.1.1",
|
|
83
92
|
"fast-deep-equal": "^3.1.3",
|
|
93
|
+
"highlight.js": "^11.11.1",
|
|
94
|
+
"lowlight": "^3.3.0",
|
|
84
95
|
"lucide-react": "^0.453.0",
|
|
85
96
|
"react-colorful": "^5.6.1",
|
|
86
97
|
"tailwind-merge": "^2.5.4",
|
package/readme.md
CHANGED
|
@@ -47,18 +47,95 @@ function App(props: AppProps) {
|
|
|
47
47
|
|
|
48
48
|
### Slash Commands
|
|
49
49
|
|
|
50
|
-
Slash commands
|
|
50
|
+
Slash commands let you interact with the editor by typing `/` followed by a command name. Commands are now organized into groups. Each group is an object with a `title` and a `commands` array. Every command within that array is a `BlockItem` that can either be a single command or a grouped command (with commands).
|
|
51
|
+
|
|
52
|
+
#### Basic Example
|
|
53
|
+
|
|
54
|
+
Suppose you have a couple of basic blocks, such as a text block or a heading block. You would organize them into a group like this:
|
|
51
55
|
|
|
52
56
|
```tsx
|
|
53
|
-
//
|
|
57
|
+
// omitting imports
|
|
54
58
|
import { text, heading1 } from '@maily-to/core/blocks';
|
|
55
59
|
|
|
56
60
|
<Editor
|
|
57
|
-
blocks={[
|
|
61
|
+
blocks={[
|
|
62
|
+
{
|
|
63
|
+
title: 'Basic Blocks',
|
|
64
|
+
commands: [text, heading1],
|
|
65
|
+
},
|
|
66
|
+
]}
|
|
67
|
+
/>
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
> **Note:** The order of the groups and the order of commands within each group determine how they are displayed in the editor.
|
|
71
|
+
|
|
72
|
+
#### Grouped Command Blocks with Subcommands
|
|
73
|
+
|
|
74
|
+
Sometimes, you may want a single command to open a list of commands. For this, define a command with an `id` and a `commands` array. The `id` is used for the slash command query (for example, typing `/headers.` will show its subcommands).
|
|
75
|
+
|
|
76
|
+
```tsx
|
|
77
|
+
// omitting imports
|
|
78
|
+
<Editor
|
|
79
|
+
blocks={[
|
|
80
|
+
{
|
|
81
|
+
title: 'Formatting',
|
|
82
|
+
commands: [
|
|
83
|
+
{
|
|
84
|
+
title: 'Headers',
|
|
85
|
+
// The id is used to filter commands; e.g. `/headers.` shows these subcommands.
|
|
86
|
+
id: 'headers',
|
|
87
|
+
searchTerms: ['header', 'title'],
|
|
88
|
+
commands: [
|
|
89
|
+
{
|
|
90
|
+
title: 'Heading 1',
|
|
91
|
+
searchTerms: ['h1', 'heading1'],
|
|
92
|
+
command: ({ editor, range }) => {
|
|
93
|
+
// Convert the current block to Heading 1.
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
title: 'Heading 2',
|
|
98
|
+
searchTerms: ['h2', 'heading2'],
|
|
99
|
+
command: ({ editor, range }) => {
|
|
100
|
+
// Convert the current block to Heading 2.
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
// Add more subcommands as needed.
|
|
104
|
+
],
|
|
105
|
+
},
|
|
106
|
+
],
|
|
107
|
+
},
|
|
108
|
+
]}
|
|
58
109
|
/>
|
|
59
110
|
```
|
|
60
111
|
|
|
61
|
-
|
|
112
|
+
In this setup, when the user types `/headers.`, the editor will display the available header subcommands.
|
|
113
|
+
|
|
114
|
+
> **Note:** Currently it only supports one level of depth for subcommands.
|
|
115
|
+
|
|
116
|
+
#### Custom Rendered Blocks
|
|
117
|
+
|
|
118
|
+
To render a custom block, you can pass a `render` function to the block object. The `render` function will receive the editor instance as an argument. You can return `null` if you don't want to render anything based on the editor's state.
|
|
119
|
+
|
|
120
|
+
```tsx
|
|
121
|
+
// omitting imports
|
|
122
|
+
<Editor
|
|
123
|
+
blocks={[
|
|
124
|
+
{
|
|
125
|
+
title: 'Custom Blocks',
|
|
126
|
+
commands: [
|
|
127
|
+
{
|
|
128
|
+
title: 'Custom Block',
|
|
129
|
+
searchTerms: ['custom'],
|
|
130
|
+
render: (editor) => {
|
|
131
|
+
return <div>Custom Block</div>;
|
|
132
|
+
},
|
|
133
|
+
},
|
|
134
|
+
],
|
|
135
|
+
},
|
|
136
|
+
]}
|
|
137
|
+
/>
|
|
138
|
+
```
|
|
62
139
|
|
|
63
140
|
### Variables
|
|
64
141
|
|
|
@@ -94,10 +171,10 @@ You can pass variables to the editor in two ways:
|
|
|
94
171
|
variables={({ query, from, editor }) => {
|
|
95
172
|
// magic goes here
|
|
96
173
|
// query: the text after the trigger character
|
|
97
|
-
// from: the context from where the variables are requested (
|
|
174
|
+
// from: the context from where the variables are requested (repeat, variable)
|
|
98
175
|
// editor: the editor instance
|
|
99
|
-
if (from === '
|
|
100
|
-
// return variables for the
|
|
176
|
+
if (from === 'repeat-variable') {
|
|
177
|
+
// return variables for the Repeat block `each` key
|
|
101
178
|
return [
|
|
102
179
|
{ name: 'notifications' },
|
|
103
180
|
{ name: 'comments' },
|
|
@@ -114,6 +191,57 @@ You can pass variables to the editor in two ways:
|
|
|
114
191
|
|
|
115
192
|
> Keep it in mind that if you pass an array of variable object Maily will take care of the filtering based on the query. But if you pass a function you have to take care of the filtering.
|
|
116
193
|
|
|
194
|
+
### Extensions
|
|
195
|
+
|
|
196
|
+
Extensions are a way to extend the editor's functionality. You can add custom blocks, marks, or extend the editor's functionality using extensions.
|
|
197
|
+
|
|
198
|
+
```tsx
|
|
199
|
+
// (Omitted repeated imports)
|
|
200
|
+
import { MailyKit, VariableExtension, getVariableSuggestions } from '@maily-to/core/extensions';
|
|
201
|
+
|
|
202
|
+
<Editor
|
|
203
|
+
extensions={[
|
|
204
|
+
MailyKit.configure({
|
|
205
|
+
// do disable the link card node
|
|
206
|
+
linkCard: false,
|
|
207
|
+
}),
|
|
208
|
+
// it will extend the variable extension
|
|
209
|
+
// and provide suggestions for variables
|
|
210
|
+
VariableExtension.extend({
|
|
211
|
+
addNodeView() {
|
|
212
|
+
// now you can replace the default
|
|
213
|
+
// VariableView with your custom view
|
|
214
|
+
return ReactNodeViewRenderer(VariableView, {
|
|
215
|
+
className: 'mly-relative mly-inline-block',
|
|
216
|
+
as: 'div',
|
|
217
|
+
});
|
|
218
|
+
},
|
|
219
|
+
}).configure({
|
|
220
|
+
suggestions: getVariableSuggestions(
|
|
221
|
+
variables,
|
|
222
|
+
variableTriggerCharacter,
|
|
223
|
+
variableListComponent, // optional custom component for variable list
|
|
224
|
+
),
|
|
225
|
+
}),
|
|
226
|
+
]}
|
|
227
|
+
/>
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
Or, you can add your own custom extensions, like shown below:
|
|
231
|
+
|
|
232
|
+
```tsx
|
|
233
|
+
// (Omitted repeated imports)
|
|
234
|
+
import { CustomExtension } from './extensions/custom-extension';
|
|
235
|
+
|
|
236
|
+
<Editor
|
|
237
|
+
extensions={[
|
|
238
|
+
CustomExtension.configure({
|
|
239
|
+
// your configuration
|
|
240
|
+
}),
|
|
241
|
+
]}
|
|
242
|
+
/>
|
|
243
|
+
```
|
|
244
|
+
|
|
117
245
|
See the [@maily-to/render](../render) package for more information on how to render the editor content to HTML.
|
|
118
246
|
|
|
119
247
|
## License
|