@maily-to/core 0.0.26 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maily-to/core",
3
- "version": "0.0.26",
3
+ "version": "0.1.0",
4
4
  "description": "Powerful editor for creating beautiful, pre-designed, mobile-ready emails.",
5
5
  "private": false,
6
6
  "main": "./dist/index.js",
@@ -68,6 +68,7 @@
68
68
  "@radix-ui/react-slot": "^1.1.0",
69
69
  "@radix-ui/react-tooltip": "^1.1.3",
70
70
  "@tiptap/core": "^2.9.1",
71
+ "@tiptap/extension-code-block-lowlight": "^2.11.5",
71
72
  "@tiptap/extension-color": "^2.9.1",
72
73
  "@tiptap/extension-document": "^2.9.1",
73
74
  "@tiptap/extension-dropcursor": "^2.9.1",
@@ -89,6 +90,8 @@
89
90
  "@tiptap/suggestion": "^2.9.1",
90
91
  "clsx": "^2.1.1",
91
92
  "fast-deep-equal": "^3.1.3",
93
+ "highlight.js": "^11.11.1",
94
+ "lowlight": "^3.3.0",
92
95
  "lucide-react": "^0.453.0",
93
96
  "react-colorful": "^5.6.1",
94
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 are a way to interact with the editor using `/` followed by a command name. For example, `/heading1` will convert the current paragraph to a heading 1.
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
- // (Omitted repeated imports)
57
+ // omitting imports
54
58
  import { text, heading1 } from '@maily-to/core/blocks';
55
59
 
56
60
  <Editor
57
- blocks={[text, heading1]}
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
- > Note: The order of the blocks matters. It will be shown in the order you provide.
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
 
@@ -114,8 +191,6 @@ 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
 
117
- See the [@maily-to/render](../render) package for more information on how to render the editor content to HTML.
118
-
119
194
  ### Extensions
120
195
 
121
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.
@@ -144,7 +219,8 @@ import { MailyKit, VariableExtension, getVariableSuggestions } from '@maily-to/c
144
219
  }).configure({
145
220
  suggestions: getVariableSuggestions(
146
221
  variables,
147
- variableTriggerCharacter
222
+ variableTriggerCharacter,
223
+ variableListComponent, // optional custom component for variable list
148
224
  ),
149
225
  }),
150
226
  ]}
@@ -166,6 +242,8 @@ import { CustomExtension } from './extensions/custom-extension';
166
242
  />
167
243
  ```
168
244
 
245
+ See the [@maily-to/render](../render) package for more information on how to render the editor content to HTML.
246
+
169
247
  ## License
170
248
 
171
249
  MIT &copy; [Arik Chakma](https://twitter.com/imarikchakma)