@maily-to/core 2.0.0-beta.1 → 2.0.0-beta.11

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.
Files changed (49) hide show
  1. package/LICENSE +21 -0
  2. package/dist/blocks/index.cjs +8 -1
  3. package/dist/blocks/index.d.cts +1 -38
  4. package/dist/blocks/index.d.mts +14 -6
  5. package/dist/blocks/index.d.mts.map +1 -1
  6. package/dist/blocks/index.mjs +2 -2
  7. package/dist/extensions/index.cjs +266 -286
  8. package/dist/extensions/index.d.cts +1 -379
  9. package/dist/extensions/index.d.mts +127 -224
  10. package/dist/extensions/index.d.mts.map +1 -1
  11. package/dist/extensions/index.mjs +238 -271
  12. package/dist/index.cjs +8717 -11689
  13. package/dist/index.d.cts +1 -107
  14. package/dist/index.d.mts +711 -73
  15. package/dist/index.d.mts.map +1 -1
  16. package/dist/index.mjs +8397 -11474
  17. package/dist/{slash-command-BmWRVPbv.d.mts → slash-command-BrwA1bHs.d.mts} +10 -11
  18. package/dist/slash-command-BrwA1bHs.d.mts.map +1 -0
  19. package/dist/theme-D1CI7_8s.d.mts +70 -0
  20. package/dist/theme-D1CI7_8s.d.mts.map +1 -0
  21. package/dist/typography-BdOKvXfQ.mjs +911 -0
  22. package/dist/typography-D-VnwOSw.cjs +970 -0
  23. package/dist/typography-DW7VApAR.cjs +1072 -0
  24. package/dist/use-maily-editor-Atvy2kSO.cjs +3993 -0
  25. package/dist/use-maily-editor-CByaDhmT.cjs +4955 -0
  26. package/dist/use-maily-editor-idL0RNsG.mjs +4504 -0
  27. package/package.json +102 -90
  28. package/readme.md +177 -133
  29. package/src/styles/index.css +2537 -0
  30. package/dist/blocks/index.d.cts.map +0 -1
  31. package/dist/chunk-CfYAbeIz.mjs +0 -13
  32. package/dist/extensions/index.d.cts.map +0 -1
  33. package/dist/extensions/index.mjs.map +0 -1
  34. package/dist/index.css +0 -2312
  35. package/dist/index.d.cts.map +0 -1
  36. package/dist/index.mjs.map +0 -1
  37. package/dist/slash-command-BmWRVPbv.d.mts.map +0 -1
  38. package/dist/slash-command-CK0-1FwR.d.cts +0 -39
  39. package/dist/slash-command-CK0-1FwR.d.cts.map +0 -1
  40. package/dist/spacer-DBtsr3hu.cjs +0 -5768
  41. package/dist/spacer-DzZWX-wB.mjs +0 -5456
  42. package/dist/spacer-DzZWX-wB.mjs.map +0 -1
  43. package/dist/typography-CWL13acR.cjs +0 -400
  44. package/dist/typography-DhrUe809.mjs +0 -282
  45. package/dist/typography-DhrUe809.mjs.map +0 -1
  46. package/dist/variable-C9S9ZoHv.d.cts +0 -108
  47. package/dist/variable-C9S9ZoHv.d.cts.map +0 -1
  48. package/dist/variable-DVwGrg2a.d.mts +0 -108
  49. package/dist/variable-DVwGrg2a.d.mts.map +0 -1
package/readme.md CHANGED
@@ -1,8 +1,4 @@
1
- [![MAILY](../../_static/maily.jpg)](https://maily.to)
2
-
3
- <p align="center">
4
- AI-powered powerful editor for creating beautiful,<br /> pre-designed with flexibility, mobile-ready emails.
5
- </p>
1
+ [![@maily-to/core](../../_static/core.jpg)](https://maily.to)
6
2
 
7
3
  <p align="center">
8
4
  <a href="https://github.com/arikchakma/maily.to/blob/main/LICENSE">
@@ -24,14 +20,15 @@ pnpm add -D @tiptap/core
24
20
 
25
21
  ### Quick Start
26
22
 
27
- The editor uses a **compound component** pattern — compose `Editor.Root`, `Editor.Frame`, and `Editor.Content` to build your layout.
23
+ The editor uses a **compound component** pattern — compose `Editor.Root`,
24
+ `Editor.Frame`, and `Editor.Content` to build your layout.
28
25
 
29
26
  ```tsx
30
27
  import '@maily-to/core/style.css';
31
28
 
32
29
  import { useState } from 'react';
33
30
  import { Editor } from '@maily-to/core';
34
- import type { Editor as TiptapEditor, JSONContent } from '@tiptap/core';
31
+ import type { Editor as TiptapEditor } from '@tiptap/core';
35
32
 
36
33
  function App() {
37
34
  const [editor, setEditor] = useState<TiptapEditor>();
@@ -44,6 +41,8 @@ function App() {
44
41
  >
45
42
  <Editor.Frame>
46
43
  <Editor.Content />
44
+ <Editor.BubbleMenus />
45
+ <Editor.DragContextHandle />
47
46
  </Editor.Frame>
48
47
  </Editor.Root>
49
48
  );
@@ -52,39 +51,47 @@ function App() {
52
51
 
53
52
  #### Editor Components
54
53
 
55
- | Component | Description |
56
- | ------------------ | ----------------------------------------------------------------------------- |
57
- | `Editor.Root` | Top-level provider. Accepts content, extensions, theme, and editor callbacks. |
58
- | `Editor.Body` | Applies theme CSS variables and body background/padding. |
59
- | `Editor.Container` | Constrains content to the theme's max-width with padding. |
60
- | `Editor.Content` | Renders the Tiptap editor and all bubble menus. |
61
- | `Editor.Frame` | Convenience wrapper — renders `Body > Container` in one component. |
54
+ | Component | Description |
55
+ | -------------------------- | ---------------------------------------------------------------------- |
56
+ | `Editor.Root` | Top-level provider. Accepts content, extensions, and editor callbacks. |
57
+ | `Editor.Frame` | Renders the document's body and container shells. |
58
+ | `Editor.Content` | Renders the Tiptap editor. |
59
+ | `Editor.BubbleMenus` | Renders every node and text bubble menu. |
60
+ | `Editor.DragContextHandle` | Renders the drag handle and its context menu. |
62
61
 
63
- `Editor.Frame` is shorthand for nesting `Body` and `Container`. Use the individual pieces when you need more control:
62
+ `Editor.Content` renders only the editor. Compose `Editor.BubbleMenus` and
63
+ `Editor.DragContextHandle` beside it to get Maily's chrome, and leave them out
64
+ for a bare canvas.
64
65
 
65
- ```tsx
66
- <Editor.Root content={content}>
67
- <Editor.Body>
68
- <Editor.Container>
69
- <Editor.Content />
70
- </Editor.Container>
71
- </Editor.Body>
72
- </Editor.Root>
73
- ```
66
+ #### Reading the document
74
67
 
75
- #### Accessing the Editor Context
76
-
77
- Use `useEditorRootContext` to access the theme and text direction from any child component:
68
+ Pass a `ref` to `Editor.Root` to reach the editor and its content from outside.
78
69
 
79
70
  ```tsx
80
- import { useEditorRootContext } from '@maily-to/core';
71
+ import { useRef } from 'react';
72
+ import { Editor } from '@maily-to/core';
81
73
 
82
- function MyComponent() {
83
- const { textDirection, setTextDirection, theme } = useEditorRootContext();
84
- // ...
74
+ function App() {
75
+ const editorRef = useRef<Editor.Root.Handle>(null);
76
+
77
+ const save = () => {
78
+ const json = editorRef.current?.getJSON();
79
+ // ...
80
+ };
81
+
82
+ return <Editor.Root ref={editorRef}>{/* ... */}</Editor.Root>;
85
83
  }
86
84
  ```
87
85
 
86
+ `Editor.Root.Props` types the props in the same way.
87
+
88
+ | Method | Returns |
89
+ | --------------- | -------------------------------- |
90
+ | `getEditor` | The underlying Tiptap `Editor` |
91
+ | `getJSON` | The document as a `DocumentNode` |
92
+ | `getEditorHTML` | The editor's HTML |
93
+ | `getText` | The document's plain text |
94
+
88
95
  ### Toolbar
89
96
 
90
97
  A composable toolbar with pre-built action buttons:
@@ -98,6 +105,7 @@ import { Editor, Toolbar } from '@maily-to/core';
98
105
  </Toolbar.Root>
99
106
  <Editor.Frame>
100
107
  <Editor.Content />
108
+ <Editor.BubbleMenus />
101
109
  </Editor.Frame>
102
110
  </Editor.Root>;
103
111
  ```
@@ -134,18 +142,25 @@ Or pick individual buttons:
134
142
 
135
143
  ### Slash Commands
136
144
 
137
- Slash commands let you interact with the editor by typing `/` followed by a command name. Commands are organized into groups with a `title` and a `commands` array.
145
+ Slash commands let you interact with the editor by typing `/` followed by a
146
+ command name. Commands are organized into groups with a `title` and a `commands`
147
+ array.
138
148
 
139
149
  #### Basic Example
140
150
 
141
151
  ```tsx
142
- import { text, heading1 } from '@maily-to/core/blocks';
152
+ import { heading1, text } from '@maily-to/core/blocks';
143
153
  import { SlashCommandExtension } from '@maily-to/core/extensions';
144
154
 
145
155
  <Editor.Root
146
156
  extensions={[
147
157
  SlashCommandExtension.configure({
148
- commands: [text, heading1],
158
+ commands: [
159
+ {
160
+ title: 'Blocks',
161
+ commands: [text, heading1],
162
+ },
163
+ ],
149
164
  }),
150
165
  ]}
151
166
  >
@@ -153,71 +168,103 @@ import { SlashCommandExtension } from '@maily-to/core/extensions';
153
168
  </Editor.Root>;
154
169
  ```
155
170
 
171
+ `commands` takes groups, not blocks — every block belongs to a group with a
172
+ `title`. `DEFAULT_SLASH_COMMANDS` is the set the editor ships with, so extend it
173
+ rather than restate it when you only want to add one group.
174
+
156
175
  > The order of the groups and commands determines how they are displayed in the editor.
157
176
 
158
177
  #### Available Blocks
159
178
 
160
179
  Import pre-built blocks from `@maily-to/core/blocks`:
161
180
 
162
- **Typography:** `text`, `heading1`, `heading2`, `heading3`, `blockquote`, `footer`, `hardBreak`, `clearLine`
181
+ **Typography:** `text`, `heading1`, `heading2`, `heading3`, `blockquote`, `hardBreak`, `clearLine`
163
182
 
164
- **Layout:** `spacer`, `divider`, `section`, `columns`, `repeat`, `htmlCodeBlock`
183
+ **Layout:** `spacer`, `divider`, `section`, `columns`, `repeat`, `table`, `htmlCodeBlock`
165
184
 
166
185
  **Content:** `button`, `image`, `inlineImage`, `linkCard`, `bulletList`, `orderedList`
167
186
 
187
+ **Headers:** `headerLogoWithCoverImage`, `headerLogoWithTextHorizontal`, `headerLogoWithTextVertical`
188
+
189
+ **Footers:** `footer`, `footerCommunityFeedbackCta`, `footerCompanySignature`, `footerCopyrightText`
190
+
168
191
  #### Grouped Commands with Subcommands
169
192
 
170
- Define a command with an `id` and a `commands` array to create nested menus. Typing `/headers.` will show the subcommands.
193
+ An item with an `id` and a `commands` array becomes a nested menu. Typing
194
+ `/headers.` then shows its subcommands.
171
195
 
172
196
  ```tsx
197
+ import { heading1, heading2, heading3 } from '@maily-to/core/blocks';
198
+ import { SlashCommandExtension } from '@maily-to/core/extensions';
199
+
173
200
  <Editor.Root
174
- blocks={[
175
- {
176
- title: 'Formatting',
201
+ extensions={[
202
+ SlashCommandExtension.configure({
177
203
  commands: [
178
204
  {
179
- title: 'Headers',
180
- id: 'headers',
181
- searchTerms: ['header', 'title'],
205
+ title: 'Blocks',
182
206
  commands: [
183
207
  {
184
- title: 'Heading 1',
185
- searchTerms: ['h1'],
186
- command: ({ editor, range }) => {
187
- editor
188
- .chain()
189
- .deleteRange(range)
190
- .setHeading({ level: 1 })
191
- .run();
192
- },
208
+ title: 'Headers',
209
+ id: 'headers',
210
+ searchTerms: ['header', 'title'],
211
+ commands: [heading1, heading2, heading3],
193
212
  },
194
213
  ],
195
214
  },
196
215
  ],
197
- },
216
+ }),
198
217
  ]}
199
- />
218
+ >
219
+ ...
220
+ </Editor.Root>;
200
221
  ```
201
222
 
223
+ The `id` and the nesting live on the **item**, not on the group — a group only
224
+ carries a `title` and its `commands`.
225
+
202
226
  > Currently supports one level of depth for subcommands.
203
227
 
204
- #### Custom Rendered Blocks
228
+ #### Writing a Block
229
+
230
+ A block is an item with a `title`, `searchTerms`, and a `command` that runs
231
+ against the editor and the typed range.
232
+
233
+ ```tsx
234
+ {
235
+ title: 'Custom Block',
236
+ searchTerms: ['custom'],
237
+ command: ({ editor, range }) => {
238
+ editor.chain().deleteRange(range).run();
239
+ },
240
+ }
241
+ ```
242
+
243
+ #### Controlling How a Block Appears
205
244
 
206
- Pass a `render` function to return custom JSX. Return `null` to skip rendering based on editor state.
245
+ `render` decides whether an item shows and what its row looks like. Return
246
+ `null` to hide it, `true` for the default row, or JSX to replace the row.
207
247
 
208
248
  ```tsx
209
249
  {
210
250
  title: 'Custom Block',
211
251
  searchTerms: ['custom'],
252
+ command: ({ editor, range }) => {
253
+ editor.chain().deleteRange(range).run();
254
+ },
212
255
  render: (editor) => {
213
- return <div>Custom Block</div>;
256
+ return editor.isActive('section') ? null : true;
214
257
  },
215
258
  }
216
259
  ```
217
260
 
261
+ Add `preview` to show a preview beside the row, and `description` or `icon` to
262
+ fill out the default one.
263
+
218
264
  ### Variables
219
265
 
220
- Variables are dynamic placeholders (e.g. `{{name}}`) that get replaced at render time. Trigger the variable picker by typing the suggestion character (default `@`).
266
+ Variables are dynamic placeholders that get replaced at render time. Typing `{{`
267
+ opens the variable picker.
221
268
 
222
269
  #### Array of Variables
223
270
 
@@ -230,7 +277,7 @@ import { VariableExtension } from '@maily-to/core/extensions';
230
277
  variables: [
231
278
  { id: 'currentDate' },
232
279
  { id: 'currentTime', required: false },
233
- { id: 'first_name', required: false, hideDefaultValue: true },
280
+ { id: 'first_name', required: false, isDefaultEditable: false },
234
281
  ],
235
282
  }),
236
283
  ]}
@@ -239,7 +286,9 @@ import { VariableExtension } from '@maily-to/core/extensions';
239
286
  </Editor.Root>;
240
287
  ```
241
288
 
242
- When passing an array, Maily handles query filtering automatically. A dynamic entry is appended when no exact match exists, allowing users to create variables on the fly.
289
+ When passing an array, Maily handles query filtering automatically. A dynamic
290
+ entry is appended when no exact match exists, allowing users to create variables
291
+ on the fly.
243
292
 
244
293
  #### Function-based Variables
245
294
 
@@ -256,14 +305,15 @@ VariableExtension.configure({
256
305
 
257
306
  ### Extensions
258
307
 
259
- Extensions extend the editor's functionality. All Maily extensions are included by default — use the `extensions` prop to add more or override existing ones.
308
+ Extensions extend the editor's functionality. Maily's own extensions are
309
+ included by default — use the `extensions` prop to configure them, to override
310
+ one, or to add an opt-in extension.
260
311
 
261
312
  ```tsx
262
313
  import {
263
- VariableExtension,
264
314
  ImageUploadExtension,
265
- AIActions,
266
- InlineSuggestion,
315
+ LinkCardExtension,
316
+ VariableExtension,
267
317
  } from '@maily-to/core/extensions';
268
318
 
269
319
  <Editor.Root
@@ -275,12 +325,15 @@ import {
275
325
  return url;
276
326
  },
277
327
  }),
328
+ LinkCardExtension,
278
329
  ]}
279
330
  >
280
331
  ...
281
332
  </Editor.Root>
282
333
  ```
283
334
 
335
+ `LinkCardExtension` is opt-in — add it to get the link card node.
336
+
284
337
  #### Image Upload
285
338
 
286
339
  Handle file drops and pastes with the `ImageUploadExtension`:
@@ -304,100 +357,91 @@ ImageUploadExtension.configure({
304
357
 
305
358
  Supports `image/jpeg`, `image/png`, `image/gif`, `image/webp`, and `image/svg+xml`.
306
359
 
307
- #### AI Actions
360
+ #### AI Actions and Inline Suggestions
361
+
362
+ AI transformations and ghost-text autocomplete ship inside this package. The
363
+ text bubble menu renders `AIActionsDropdown` when the AI actions extension is
364
+ present. See [extension-ai-actions](../extension-ai-actions) and
365
+ [extension-inline-suggestion](../extension-inline-suggestion).
308
366
 
309
- Add AI-powered content transformations (rewriting, summarizing, expanding):
367
+ ### Theming
368
+
369
+ A document carries its own appearance. `ThemeExtension` writes a theme into the
370
+ document's `theme` attribute, and every node's `style` attribute is what the
371
+ renderer reads — so `@maily-to/render` applies no theme of its own and the email
372
+ matches the canvas.
310
373
 
311
374
  ```tsx
312
- import { AIActions } from '@maily-to/core/extensions';
313
- import type {
314
- AIActionsOptions,
315
- AIActionsTransformParams,
316
- } from '@maily-to/core/extensions';
375
+ import { BASIC_NODE_THEME } from '@maily-to/shared';
376
+ import { ThemeExtension } from '@maily-to/core/extensions';
377
+
378
+ <Editor.Root
379
+ extensions={[ThemeExtension.configure({ theme: BASIC_NODE_THEME })]}
380
+ >
381
+ ...
382
+ </Editor.Root>;
317
383
  ```
318
384
 
319
- #### Inline Suggestions
385
+ `BASIC_NODE_THEME` is a plain starter theme. Omit `ThemeExtension`
386
+ entirely for an unthemed document — the editor stays fully usable and applies no
387
+ Maily appearance.
320
388
 
321
- Add ghost-text autocomplete suggestions (like AI code completion):
389
+ A theme is a `NodeThemeOptions` map from node type to an inline style:
322
390
 
323
- ```tsx
324
- import { InlineSuggestion } from '@maily-to/core/extensions';
325
- import type { InlineSuggestionOptions } from '@maily-to/core/extensions';
391
+ ```ts
392
+ import type { NodeThemeOptions } from '@maily-to/shared';
393
+
394
+ const theme: NodeThemeOptions = {
395
+ body: { backgroundColor: '#ffffff', padding: '24px' },
396
+ container: { backgroundColor: '#f9fafb', maxWidth: '600px' },
397
+ button: { backgroundColor: '#4f46e5', color: '#ffffff' },
398
+ link: { color: '#2563eb' },
399
+ paragraph: { fontSize: '15px', lineHeight: '24px' },
400
+ };
326
401
  ```
327
402
 
328
- ### Theming
403
+ #### Editing the theme
329
404
 
330
- Customize the editor appearance through the `theme` prop on `Editor.Root`. Theme values are applied as CSS custom variables.
405
+ `ThemeSettings` gives writers a panel for the theme the document holds. Each
406
+ part edits one group of declarations.
331
407
 
332
408
  ```tsx
333
- <Editor.Root
334
- theme={{
335
- container: {
336
- backgroundColor: '#f9fafb',
337
- maxWidth: 640,
338
- borderRadius: 8,
339
- borderWidth: 1,
340
- borderColor: '#e5e7eb',
341
- paddingTop: 16,
342
- paddingRight: 16,
343
- paddingBottom: 16,
344
- paddingLeft: 16,
345
- },
346
- body: {
347
- backgroundColor: '#ffffff',
348
- paddingTop: 24,
349
- paddingRight: 24,
350
- paddingBottom: 24,
351
- paddingLeft: 24,
352
- },
353
- button: {
354
- backgroundColor: '#4f46e5',
355
- color: '#ffffff',
356
- },
357
- link: {
358
- color: '#2563eb',
359
- },
360
- font: {
361
- fontFamily: 'Inter',
362
- fallbackFontFamily: 'sans-serif',
363
- webFont: {
364
- format: 'woff2',
365
- url: 'https://cdn.usemaily.com/fonts/v0/inter.woff2',
366
- },
367
- },
368
- }}
369
- >
370
- ...
371
- </Editor.Root>
409
+ import { ThemeSettings } from '@maily-to/core';
410
+
411
+ <ThemeSettings.Root>
412
+ <ThemeSettings.Font />
413
+ <ThemeSettings.Layout />
414
+ <ThemeSettings.Button />
415
+ <ThemeSettings.Text />
416
+ </ThemeSettings.Root>;
372
417
  ```
373
418
 
419
+ The `setNodeTheme`, `updateNodeTheme`, and `updateShellTheme` commands do the
420
+ same work from your own UI.
421
+
374
422
  ## Text Direction
375
423
 
376
- The editor supports LTR and RTL text directions. Control it via props on `Editor.Root`:
424
+ The editor supports LTR and RTL text directions. Set the initial direction with
425
+ the `textDirection` prop on `Editor.Root`:
377
426
 
378
427
  ```tsx
379
- // Uncontrolled (editor manages state)
380
- <Editor.Root defaultTextDirection="ltr">
381
-
382
- // Controlled
383
- <Editor.Root
384
- textDirection={direction}
385
- onTextDirectionChange={setDirection}
386
- >
428
+ <Editor.Root textDirection="rtl">
387
429
  ```
388
430
 
389
431
  Use `Toolbar.Direction` to let users toggle direction from the toolbar.
390
432
 
391
433
  ## Entry Points
392
434
 
393
- | Import path | Contents |
394
- | --------------------------- | ----------------------------------------------------------------------------------------------------------- |
395
- | `@maily-to/core` | `Editor`, `Toolbar`, `useEditorRootContext`, `useEditorVariables`, `filterVariableSuggestions`, theme types |
396
- | `@maily-to/core/blocks` | Pre-built slash command block items and types |
397
- | `@maily-to/core/extensions` | All Tiptap extensions and their option/storage types |
398
- | `@maily-to/core/style.css` | Required CSS stylesheet |
435
+ | Import path | Contents |
436
+ | --------------------------- | -------------------------------------------------------------------------------------------- |
437
+ | `@maily-to/core` | `Editor`, `Toolbar`, `ThemeSettings`, bubble menus, headless UI primitives, hooks, and types |
438
+ | `@maily-to/core/blocks` | Pre-built slash command block items and types |
439
+ | `@maily-to/core/extensions` | All Tiptap extensions and their option/storage types |
440
+ | `@maily-to/core/style.css` | Optional stylesheet — the editor works without it and carries no Maily visual styles |
399
441
 
400
- See the [@maily-to/render](../render) package for converting editor content to HTML email templates.
442
+ See the [@maily-to/render](../render) package for converting editor content to
443
+ HTML email templates, and [@maily-to/migration](../migration) for loading v1
444
+ documents.
401
445
 
402
446
  ### Sponsors
403
447