@maily-to/core 0.0.17 → 0.0.19
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/index.d.mts +17 -5
- package/dist/index.d.ts +17 -5
- package/dist/index.js +1873 -1498
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1845 -1465
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/readme.md +51 -21
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -62,27 +62,57 @@ import { text, heading1 } from '@maily-to/core/blocks';
|
|
|
62
62
|
|
|
63
63
|
### Variables
|
|
64
64
|
|
|
65
|
-
By default,
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
65
|
+
By default, variables are required. You can make them optional by setting the `required` property to `false`. When a variable is optional and not provided, a placeholder will be displayed in its place.
|
|
66
|
+
|
|
67
|
+
You can pass variables to the editor in two ways:
|
|
68
|
+
|
|
69
|
+
1. As an Array of Objects:
|
|
70
|
+
|
|
71
|
+
For auto-suggestions of variables in the editor when you type `@`, pass the variables as an array of objects to the `variables` prop.
|
|
72
|
+
|
|
73
|
+
```tsx
|
|
74
|
+
// (Omitted repeated imports)
|
|
75
|
+
<Editor
|
|
76
|
+
variableTriggerCharacter="@"
|
|
77
|
+
variables={[
|
|
78
|
+
{
|
|
79
|
+
name: 'currentDate',
|
|
80
|
+
required: false,
|
|
81
|
+
},
|
|
82
|
+
]}
|
|
83
|
+
/>
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
2. As a Function:
|
|
87
|
+
|
|
88
|
+
If the variables are dynamic and need to be generated based on the editor's state or other inputs, you can provide a function to the `variables` prop.
|
|
89
|
+
|
|
90
|
+
```tsx
|
|
91
|
+
// (Omitted repeated imports)
|
|
92
|
+
<Editor
|
|
93
|
+
variableTriggerCharacter="@"
|
|
94
|
+
variables={({ query, from, editor }) => {
|
|
95
|
+
// magic goes here
|
|
96
|
+
// query: the text after the trigger character
|
|
97
|
+
// from: the context from where the variables are requested (for, variable)
|
|
98
|
+
// editor: the editor instance
|
|
99
|
+
if (from === 'for') {
|
|
100
|
+
// return variables for the For block `each` key
|
|
101
|
+
return [
|
|
102
|
+
{ name: 'notifications' },
|
|
103
|
+
{ name: 'comments' },
|
|
104
|
+
];
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return [
|
|
108
|
+
{ name: 'currentDate' },
|
|
109
|
+
{ name: 'currentTime', required: false },
|
|
110
|
+
];
|
|
111
|
+
}}
|
|
112
|
+
/>
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
> 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.
|
|
86
116
|
|
|
87
117
|
See the [@maily-to/render](../render) package for more information on how to render the editor content to HTML.
|
|
88
118
|
|