@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maily-to/core",
3
- "version": "0.0.17",
3
+ "version": "0.0.19",
4
4
  "description": "Powerful editor for creating beautiful, pre-designed, mobile-ready emails.",
5
5
  "private": false,
6
6
  "main": "./dist/index.js",
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, the variables are required. You can make them optional by setting the `required` property to `false`. So it will show a placeholder if the variable is not provided.
66
-
67
- For auto-suggestions of the variables in the editor when you type `@` and pass the variables as an array of objects to the `variables` prop. The `iterable` property is used to indicate that the variable is an array of objects and can be used in `For` loop. The `keys` property is used to show the keys of the object in the auto-suggestions.
68
-
69
- ```tsx
70
- // (Omitted repeated imports)
71
- <Editor
72
- triggerSuggestionCharacter="@"
73
- variables={[
74
- {
75
- name: 'currentDate',
76
- required: false,
77
- },
78
- {
79
- name: 'notifications',
80
- iterable: true,
81
- keys: ['id', 'title'],
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