tess_edit 0.5.17 → 0.6.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.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +91 -68
  3. data/app/controllers/tess_edit/compilations_controller.rb +6 -3
  4. data/app/javascript/tess_edit/blocks/assign.js +2 -5
  5. data/app/javascript/tess_edit/blocks/builtin.js +6 -9
  6. data/app/javascript/tess_edit/blocks/button.js +1 -4
  7. data/app/javascript/tess_edit/blocks/column.js +1 -4
  8. data/app/javascript/tess_edit/blocks/condition.js +2 -5
  9. data/app/javascript/tess_edit/blocks/content.js +4 -11
  10. data/app/javascript/tess_edit/blocks/divider.js +1 -4
  11. data/app/javascript/tess_edit/blocks/image.js +1 -4
  12. data/app/javascript/tess_edit/blocks/loop.js +2 -5
  13. data/app/javascript/tess_edit/blocks/raw.js +1 -10
  14. data/app/javascript/tess_edit/blocks/section.js +1 -5
  15. data/app/javascript/tess_edit/blocks/spacer.js +1 -4
  16. data/app/javascript/tess_edit/blocks/table.js +8 -15
  17. data/app/javascript/tess_edit/blocks/text.js +1 -4
  18. data/app/javascript/tess_edit/controllers/editor_controller.js +32 -20
  19. data/app/javascript/tess_edit/core/document.js +8 -8
  20. data/app/javascript/tess_edit/core/media.js +1 -1
  21. data/app/javascript/tess_edit/core/registry.js +29 -25
  22. data/app/javascript/tess_edit/export/compile.js +15 -6
  23. data/app/javascript/tess_edit/export/richtext.js +1 -1
  24. data/app/javascript/tess_edit/export/table.js +9 -7
  25. data/app/javascript/tess_edit/index.js +2 -3
  26. data/app/javascript/tess_edit/ui/canvas.js +19 -7
  27. data/config/locales/en.yml +1 -39
  28. data/config/locales/nl.yml +1 -39
  29. data/lib/tess_edit/content.rb +5 -4
  30. data/lib/tess_edit/version.rb +1 -1
  31. data/lib/tess_edit.rb +34 -8
  32. metadata +1 -24
  33. data/app/javascript/tess_edit/blocks/email.js +0 -83
  34. data/app/javascript/tess_edit/blocks/hero.js +0 -60
  35. data/app/javascript/tess_edit/blocks/navbar.js +0 -49
  36. data/app/javascript/tess_edit/blocks/social.js +0 -39
  37. data/app/javascript/tess_edit/blocks/wrapper.js +0 -24
  38. data/app/javascript/tess_edit/core/starter.js +0 -89
  39. data/app/javascript/tess_edit/export/mjml.js +0 -117
  40. data/app/javascript/tess_edit/kits/builtin.js +0 -5
  41. data/app/javascript/tess_edit/kits/email.js +0 -28
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 81bf024320e1b26b908b234509c20f2d3d0b28486246f677f697a73c004ec464
4
- data.tar.gz: 6fee53efa892077a3ab1e55111de4d67a827f52091cff03e3c052bae15fc108f
3
+ metadata.gz: 231a7807dcac953bd03cc48a948bd2a54a1b5fca397a9057547d86b9a58bda9d
4
+ data.tar.gz: 7467d62b9ad10074f8c16a0afac68463aa73c9425f1526d1d1a65879a6093d6d
5
5
  SHA512:
6
- metadata.gz: ba363c92cb29469719787c21fe62d2d4d2d0fa0c53d9d9764eee878e546ba5e675c9434335f45fb4a1bfb2c5f84de258e7946276743b893a8ceb93d2e8c7e312
7
- data.tar.gz: 9fa13068fed9c8fe57d31f0abe2834a0f0aa981b5f1cf1600fc700e6c6af2217e7e812105ca7784fcbba74d653b1e8abdd40177de83f007764c99137a023672d
6
+ metadata.gz: 68726bbf5c383bb7d909a11bfb7ce3fa393b79e6bd5f2fd46360b066019fa563cf4faa5f55ec5096785b8a63c6a69844d887c9b92b2f0721e3f62a777faec9c9
7
+ data.tar.gz: 3dedf85db330315841b657f2a9852ce3affe413470d7784282e18c346f344aa773a8a3e693cf4f80c172ffdf7341d4b8edda1b0a5808924dd1f2242991592643
data/README.md CHANGED
@@ -1,33 +1,41 @@
1
1
  # TessEdit
2
2
 
3
- TessEdit is a drag-and-drop email editor for Rails, written in plain JavaScript with Stimulus. You build an email from blocks; the editor stores the design as JSON and exports [MJML](https://mjml.io) and responsive HTML. Blocks can hold [Liquid](https://shopify.github.io/liquid/), which survives into the HTML so it can be rendered at send time.
3
+ TessEdit is a drag-and-drop (WYSIWYG) editor for Rails, written in plain JavaScript with Stimulus. You build a document from blocks on a canvas that shows it as it will look; the editor stores it as JSON and turns it into whatever the document is for.
4
4
 
5
- What it makes is a kit: the email is built in, and your app can add its own, such as the demo's Note, with blocks of its own and TessEdit's (see [Kits](#kits)).
5
+ What kind of document that is depends on the kit. A kit is a root block, the blocks that can go in it, and how the canvas shows it and the editor outputs it. TessEdit has none of its own: your app (or a gem) registers them, such as an email, a note, a form, a contract or a text message. A kit has blocks of its own and brings in TessEdit's (Section, Column, Text, Image, Button, Table, Loop, Condition and the rest) with how they render in it. Blocks, kits, Inspect fields, field types, palette sources and server-side compilers are all registered the same way, so everything the editor offers can be extended or replaced (see [Kits](#kits) and [Blocks and custom blocks](#blocks-and-custom-blocks)).
6
6
 
7
- The interface follows familiar layout: blocks and a layers tree on the left, the email in the middle, and Inspect, with the selected block's settings, on the right.
7
+ Blocks can hold [Liquid](https://shopify.github.io/liquid/), which survives into the output so it can be rendered later, such as when an email is sent. The editor completes your app's variables, filters and tags as you type, and says what's wrong with the Liquid.
8
8
 
9
- ![TessEdit interface](docs/overview.png)
9
+ The interface follows a familiar layout: blocks and a layers tree on the left, the document in the middle, and Inspect, with the selected block's settings, on the right. An email, made with [Nuntius](https://github.com/entdec/nuntius)' email kit, which exports [MJML](https://mjml.io) and responsive HTML:
10
+
11
+ ![TessEdit editing an email](docs/overview.png)
12
+
13
+ And a note, the demo app's kit, with a Card block of its own and TessEdit's Text, Divider and Loop:
14
+
15
+ ![TessEdit editing a note](docs/note.png)
16
+
17
+ Liquid is completed as you type, in text and in settings:
10
18
 
11
- It completes Liquid tags and variables as you type, making it easier to work with dynamic content.
12
19
  ![Liquid completion](docs/liquid.png)
13
20
 
14
21
  ## Features
15
22
 
16
- - Blocks: Section (1-4 columns), Column, Wrapper, Hero, Text, Heading, Image, Button, Divider, Spacer, Social, Navbar and raw HTML.
17
- - Liquid blocks: **Loop** (`{% for line in order.lines %}`) and **Condition** (`{% if order.total > 100 %}`) wrap other blocks.
23
+ - Blocks: Section (1-4 columns), Column, Text, Heading, Image, Button, Divider, Spacer and raw HTML, for a kit to take in, besides its own.
24
+ - Liquid blocks: **Loop** (`{% for line in order.lines %}`) and **Condition** (`{% if order.total > 100 %}`) wrap other blocks, and **Assign** sets a variable.
18
25
  - **Tables**: Table, Row and Cell blocks, a cell holding any blocks, with Loops and Conditions (and Assigns) between the rows. On the canvas a cell's menu adds and deletes rows and columns and puts its row in a Loop or Condition, a column's border is dragged to set its width, Tab goes from cell to cell (adding a row after the last), and a bracket by a Loop's or Condition's rows shows what they are.
19
- - Drag from the Blocks panel onto the canvas or into the Layers tree; move blocks on the canvas (drag handle) or in the tree; plus buttons and empty-column placeholders open an "Add block" menu.
26
+ - Drag from the Blocks panel onto the canvas or into the Layers tree; move blocks on the canvas (drag handle) or in the tree; plus buttons and empty-container placeholders open an "Add block" menu.
20
27
  - Rich text editing on the canvas with [Tiptap](https://tiptap.dev): bold, italic, underline, strikethrough, colour, links (Liquid allowed in the URL), alignment, lists and headings. A block can have several texts edited on the canvas, rich or a plain line, such as a question's label and its description.
21
28
  - Your app's Liquid variables suggested while typing `{{`, in text and in settings, and browsable from `{ }` buttons, including those of the Loop blocks around a block and the Assigns before it; after a `|` your app's filters, with a where's property and the values it can have, after `==` the values of what's compared, after `{%` the tags, a block with its end tag, and in conditions the operators; and what's wrong with it, underlined.
22
29
  - Your app's translations for Liquid's `t` filter (`{{ '.greeting' | t }}`) shown as their text in a language of your choice, with every language's text, missing ones marked, editable when pointed at, and selected text made translatable.
23
30
  - Your app's values for the Liquid in a document (`{{ customer.first_name }}` as "Ada"), shown in its place until the caret goes into it.
24
31
  - Clicking a tile in the Blocks panel adds the block in or after the selection, or else at the end of the last block it fits in.
25
32
  - Undo/redo, duplicate, delete, keyboard shortcuts (⌘Z, ⇧⌘Z, ⌘D, Delete, Enter to edit text, Tab to the next table cell, Esc).
26
- - Desktop and mobile preview, and a preview of the HTML as sent.
33
+ - A preview of the output, and the canvas at the widths a kit gives, such as an email's desktop and mobile.
27
34
  - Panels on both sides, or combined as tabs in one sidebar on the left or right to give the canvas more room.
28
35
  - Dark mode that follows the host app's.
29
- - Code dialog to view, copy or download the JSON, MJML and HTML, and to load JSON.
30
- - Kits: other kinds of documents, registered by your app, with its own blocks and output and TessEdit's blocks brought in.
36
+ - Code dialog to view, copy or download the JSON and the kit's outputs, and to load JSON.
37
+ - Kits: any kind of document, registered by your app or a gem, with its own blocks and output and TessEdit's blocks brought in.
38
+ - Compilers: a kit whose output is made on the server, such as an email's MJML compiled to HTML, compiles through the engine's endpoint with a compiler your app registers.
31
39
  - Layouts: a Content block marks where the documents using a layout put their own blocks, and a lock keeps the rest of the layout as it is.
32
40
  - Palette sources: tiles from your app in the Blocks panel, such as saved snippets, inserted as a copy that remembers where it came from.
33
41
 
@@ -37,23 +45,26 @@ It completes Liquid tags and variables as you type, making it easier to work wit
37
45
  gem "tess_edit", github: "tdegrunt/tess_edit"
38
46
  ```
39
47
 
40
- The engine adds its pins to your import map. Mount it for the compile endpoint (see [Compiling](#compiling)):
48
+ The engine adds its pins to your import map. For a kit that compiles on the server, mount it for the compile endpoint (see [Compiling](#compiling)):
41
49
 
42
50
  ```ruby
43
51
  # config/routes.rb
44
52
  mount TessEdit::Engine => "/tess_edit"
45
53
  ```
46
54
 
47
- Register the controller with your Stimulus application:
55
+ Register the controller with your Stimulus application, after the kits your editors make (see [Kits](#kits)):
48
56
 
49
57
  ```js
50
58
  // app/javascript/application.js
51
59
  import { application } from "controllers/application"
52
60
  import { registerTessEdit } from "tess_edit"
61
+ import "kits/note"
53
62
 
54
63
  registerTessEdit(application)
55
64
  ```
56
65
 
66
+ A gem can bring kits too: [Nuntius](https://github.com/entdec/nuntius) has an email kit, with MJML, for its templates and campaigns.
67
+
57
68
  ### Tailwind CSS 4 required
58
69
 
59
70
  The editor builds its interface with Tailwind classes, so it needs Tailwind CSS 4 through [`tailwindcss-rails`](https://github.com/rails/tailwindcss-rails) 4.3 or later. Tailwind 3 is not supported.
@@ -74,27 +85,28 @@ Import the editor's styles after Tailwind itself:
74
85
 
75
86
  ### Dark mode
76
87
 
77
- The editor's panels, menus and dialogs have `dark:` variants, so they follow your app's dark mode: by default the OS setting (`prefers-color-scheme`), or whatever your app makes `dark:` mean with `@custom-variant dark`, such as a `.dark` class on `<html>`. The email on the canvas keeps its own colours, as it is sent.
88
+ The editor's panels, menus and dialogs have `dark:` variants, so they follow your app's dark mode: by default the OS setting (`prefers-color-scheme`), or whatever your app makes `dark:` mean with `@custom-variant dark`, such as a `.dark` class on `<html>`. The document on the canvas keeps its own colours, as the kit renders it.
78
89
 
79
90
  ## Usage
80
91
 
81
- Give the controller an element with a height and, optionally, hidden inputs to keep up to date:
92
+ Give the controller an element with a height, the kit it makes and, optionally, hidden inputs to keep up to date:
82
93
 
83
94
  ```erb
84
- <div data-controller="tess-edit" style="height: 80vh">
95
+ <div data-controller="tess-edit" data-tess-edit-kit-value="note" style="height: 80vh">
85
96
  <%= form.hidden_field :json, data: { tess_edit_target: "jsonInput" } %>
86
- <%= form.hidden_field :mjml, data: { tess_edit_target: "mjmlInput" } %>
87
97
  <%= form.hidden_field :html, data: { tess_edit_target: "htmlInput" } %>
88
98
  </div>
89
99
  ```
90
100
 
91
- The editor loads the document from the `jsonInput` (or from `data-tess-edit-document-value`). With neither, it starts with a sample email; set `data-tess-edit-sample-value="false"` to start with an empty email.
101
+ `data-tess-edit-kit-value` names a kit your app registered (see [Kits](#kits)); with only one registered, it can be left out. There is an input for the JSON and one for each of the kit's outputs, named after it: an email's `mjml` goes in an `mjmlInput`.
102
+
103
+ The editor loads the document from the `jsonInput` (or from `data-tess-edit-document-value`). With neither, it starts with the kit's sample, if it has one; set `data-tess-edit-sample-value="false"` to start with an empty document.
92
104
 
93
105
  `data-tess-edit-panels-value` sets the default panel layout: `split` (Blocks and Layers on the left, Inspect on the right, the default), `left` or `right` (Blocks, Layers and Inspect as tabs in one sidebar on that side). People can switch with the buttons in the top bar; their choice is remembered in the browser. When the editor is narrower than 1000px, it puts all panels on the left so the canvas keeps its room, and goes back to the chosen layout when it is wide enough again.
94
106
 
95
107
  The editor has a border with rounded corners. A page that frames it itself, such as a card it fills, turns it off with `data-tess-edit-frame-value="false"`.
96
108
 
97
- Every change updates the inputs and dispatches `tess-edit:change` with `{ json, mjml, html, errors, document }` in `event.detail`. When the MJML can't be compiled, `html` is empty and `errors` says why; the editor shows the reason under the canvas. The controller instance is available as `element.tessEdit`, with `getDocument()`, `setDocument(json)` and `export()`.
109
+ Every change updates the inputs and dispatches `tess-edit:change` with `{ json, …the kit's outputs, errors, document }` in `event.detail`, e.g. `{ json, html, errors, document }`. When an output can't be made, such as MJML that can't be compiled, `errors` says why; the editor shows the reason under the canvas. The controller instance is available as `element.tessEdit`, with `getDocument()`, `setDocument(json)` and `export()`.
98
110
 
99
111
  ### The editor's language
100
112
 
@@ -129,48 +141,61 @@ A text your JavaScript makes itself, such as a block's `label(node)`, uses `t` f
129
141
  | Field | Contents |
130
142
  |---|---|
131
143
  | `json` | The block tree. The source of truth; load it back into the editor. |
132
- | `mjml` | MJML generated from the JSON. Loops and conditions are `<mj-raw>{% ... %}</mj-raw>`. |
133
- | `html` | The MJML compiled to HTML on the server, with Liquid left in place. |
144
+ | the kit's outputs | What the kit makes of it, such as `html`, or an email's `mjml` and `html`, with Liquid left in place. |
134
145
 
135
- Render the HTML with Liquid when sending. A host app can also store only the JSON or MJML and compile on its own with `TessEdit.compile(mjml)`.
146
+ Render the Liquid when the document is used, such as when an email is sent. A host app can also store only the JSON and make the output itself, with the same code as the kit.
136
147
 
137
148
  The fields are written a moment after each change. A form submitted before that, such as a Save clicked right after typing, waits for them and then goes on, also with Turbo.
138
149
 
139
150
  ### Compiling
140
151
 
141
- The editor turns the JSON into MJML in the browser and has the server compile the MJML to HTML, with [MRML](https://github.com/jdrouet/mrml) (the `mrml` gem, precompiled, no Node or Rust needed). The canvas, the preview and the `html` input all come from the same compiler the host app uses when it sends:
152
+ A kit whose output the browser can't make itself, such as an email's MJML that becomes HTML, has it compiled on the server, by a compiler your app (or the gem with the kit) registers by name:
142
153
 
143
154
  ```ruby
144
- result = TessEdit.compile(mjml)
145
- result.html # nil when the MJML can't be parsed
155
+ # config/initializers/tess_edit.rb
156
+ TessEdit.register_compiler(:mjml) { |mjml| MRML::Template.new(mjml).to_html }
157
+ ```
158
+
159
+ The block takes the source and returns the HTML, or a `TessEdit::Result` with the reasons it couldn't; an error it raises is one of those reasons too. Your app compiles with it as the editor does, so the canvas shows what it sends:
160
+
161
+ ```ruby
162
+ result = TessEdit.compile(:mjml, mjml)
163
+ result.html # nil when it couldn't be compiled
146
164
  result.errors # [] or the reasons
147
165
  ```
148
166
 
149
- The editor posts to `/tess_edit/compile`, debounced, with the page's CSRF token (`csrf_meta_tags`). Mounted elsewhere, give the editor the path with `data-tess-edit-compile-url-value`. The endpoint's controller inherits from `ActionController::Base`; make it inherit from one of your controllers so it sits behind the same sign-in and authorization:
167
+ The kit compiles with `compile` from `tess_edit`, which posts to the engine's endpoint, `/tess_edit/compile`, with `{ compiler, source }` and the page's CSRF token (`csrf_meta_tags`):
168
+
169
+ ```js
170
+ import { compile } from "tess_edit"
171
+
172
+ canvas: (doc, { editor, compileUrl, signal }) => compile(toMjml(doc, { editor }), { compiler: "mjml", url: compileUrl, signal })
173
+ ```
174
+
175
+ Mounted elsewhere, give the editor the path with `data-tess-edit-compile-url-value`; a kit gets it as `compileUrl`. The endpoint's controller inherits from `ActionController::Base`; make it inherit from one of your controllers so it sits behind the same sign-in and authorization:
150
176
 
151
177
  ```ruby
152
178
  # config/initializers/tess_edit.rb
153
179
  TessEdit.parent_controller = "Admin::BaseController"
154
- ``` Liquid inside HTML attributes, such as a button link of `{{ order.url }}`, has its double quotes changed to single quotes, which Liquid treats the same.
180
+ ```
181
+
182
+ Line endings are LF by the time a compiler gets the source, also when a browser submitted it with CRLF.
155
183
 
156
184
  ### The document format
157
185
 
158
186
  ```json
159
187
  {
160
- "version": 1, "id": "b1x2y3z", "type": "email",
161
- "attributes": { "width": "600px", "background-color": "#f3f4f6" },
162
- "data": { "subject": "...", "preheader": "...", "fontFamily": "..." },
188
+ "version": 1, "id": "b1x2y3z", "type": "note",
189
+ "attributes": {},
190
+ "data": { "title": "Weekly review", "color": "#fef9c3" },
163
191
  "children": [
164
- { "id": "...", "type": "section", "attributes": { "padding": "20px 0px" }, "data": {}, "children": [
165
- { "id": "...", "type": "column", "attributes": {}, "data": {}, "children": [
166
- { "id": "...", "type": "text", "attributes": { "align": "center" }, "data": { "content": { "type": "doc", "content": [] } }, "children": [] }
167
- ] }
168
- ] }
192
+ { "id": "...", "type": "text", "attributes": { "align": "center" }, "data": { "content": { "type": "doc", "content": [] } }, "children": [] },
193
+ { "id": "...", "type": "loop", "attributes": {}, "data": { "variable": "item", "collection": "actions" }, "children": [] }
169
194
  ]
170
195
  }
171
196
  ```
172
197
 
173
- The top node is the `email` block, which renders the `<mjml>` document with the subject, preview text and theme. Documents from before its renames, with `"type": "page"` or `"type": "root"`, still load. `attributes` map onto MJML attributes; `data` holds everything else. Text content is Tiptap (ProseMirror) JSON, so other renderers, such as a kit's own, can walk it.
198
+ The top node is the kit's root block, here a note's, which renders the whole document. `attributes` hold a block's styling, named after CSS properties and MJML's attributes, which each kit maps onto its own output; `data` holds everything else. Text content is Tiptap (ProseMirror) JSON, which a kit renders with `richTextToHtml` or walks itself.
174
199
 
175
200
  ### Locking a layout
176
201
 
@@ -178,14 +203,14 @@ To let people fill in one part of a design that is otherwise fixed, such as a te
178
203
 
179
204
  ```erb
180
205
  <div data-controller="tess-edit"
181
- data-tess-edit-lock-value='<%= {except: ["content"], fields: ["data.subject", "data.preheader"]}.to_json %>'>
206
+ data-tess-edit-lock-value='<%= {except: ["content"], fields: ["data.title"]}.to_json %>'>
182
207
  ```
183
208
 
184
209
  Only what is inside blocks of the types in `except` can change: those blocks take new blocks, and everything in them can be edited, moved, duplicated and deleted. The blocks themselves stay where they are. Of the root, only the listed `fields` can change. Everything else still shows on the canvas and can be selected, with its settings disabled in Inspect and a lock in Layers. A tile clicked while a locked block is selected goes at the end of the first block it is allowed in, and the Code dialog shows the JSON without loading it. The editor still stores the whole document; taking the open part out of it is up to the host app. The `except` type is usually `content`, the Content block (see Layouts).
185
210
 
186
211
  ### Layouts
187
212
 
188
- The Content block (in the Layout category of the Blocks panel) marks where the documents using a layout put their own blocks; a layout has one. What a layout has inside it is example content to design the layout with. Outside the editor its contents are between two comments, in `<mj-raw>` tags in MJML:
213
+ The Content block (in the Layout category of the Blocks panel) marks where the documents using a layout put their own blocks; a layout has one. What a layout has inside it is example content to design the layout with. Outside the editor its contents are between two comments, which its kit renders, in a tag of their own if the output needs one (an email's are in `<mj-raw>` tags):
189
214
 
190
215
  ```html
191
216
  <!-- tess-edit:content --> … <!-- /tess-edit:content -->
@@ -226,7 +251,7 @@ An item's `type` says where the tile can go; a container with `accepts: "inherit
226
251
 
227
252
  ### Images
228
253
 
229
- By default images are URLs. To let people choose from your app's images and upload new ones, give the editor an endpoint with `data-tess-edit-media-url-value`. Every image then has a source, Uploaded (a dropdown of your images with an Upload button) or Web (a URL): the Image block's image and the background images of heroes, sections and wrappers. New Image blocks start as Uploaded. An image file dragged from the desktop onto the canvas is uploaded and put in the nearest block with an image, an Image block or else the background of the hero, section or wrapper it's dropped on, and shows straight away while it uploads.
254
+ By default images are URLs. To let people choose from your app's images and upload new ones, give the editor an endpoint with `data-tess-edit-media-url-value`. Every image then has a source, Uploaded (a dropdown of your images with an Upload button) or Web (a URL): the Image block's image, the background image of sections, and a kit's own image fields, such as an email's heroes and wrappers. New Image blocks start as Uploaded. An image file dragged from the desktop onto the canvas is uploaded and put in the nearest block with an image, an Image block or else the background of the block it's dropped on, and shows straight away while it uploads.
230
255
 
231
256
  The endpoint answers two requests, both as JSON:
232
257
 
@@ -320,7 +345,7 @@ A kit whose canvas your app renders can give them with the canvas, `{ html, erro
320
345
 
321
346
  ### Blocks and custom blocks
322
347
 
323
- Every block is a plugin: one module in `app/javascript/tess_edit/blocks/` with its defaults, its Inspect fields, its Blocks panel tiles and a `render.mjml` hook. The built-in blocks are registered the same way a host app registers its own, so register yours before the editor connects:
348
+ Every block is a plugin: one module with its defaults, its Inspect fields, its Blocks panel tiles and a render hook for each kit it is part of. TessEdit's own blocks, in `app/javascript/tess_edit/blocks/`, are registered the same way a host app registers its own (but are part of no kit until a kit takes them in, see [Kits](#kits)), so register yours before the editor connects:
324
349
 
325
350
  ```js
326
351
  import { application } from "controllers/application"
@@ -333,20 +358,21 @@ registerBlock({
333
358
  name: "Product",
334
359
  icon: "image", // a built-in icon name, or SVG markup (24×24 viewBox)
335
360
  category: "shop", // gives it one tile; use `palette: [...]` for more, or none
336
- roles: ["content"], // goes where content goes: columns, heroes, Liquid blocks in them
361
+ kits: ["note"], // the kits it is part of
362
+ roles: ["content"], // goes where content goes: columns, Liquid blocks, the note itself
337
363
  defaults: () => ({ attributes: { padding: "10px 25px" }, data: { sku: "" } }),
338
364
  fields: [{ title: "Product", fields: [{ key: "data.sku", label: "SKU", type: "text" }, fields.padding] }],
339
365
  label: (node) => `Product · ${node.data.sku}`,
340
- render: {
341
- mjml: (node, { element, escapeText }) =>
342
- element("mj-text", node, `{{ products['${escapeText(node.data.sku)}'].title }}`)
366
+ render: { // one for each of its kits, named after the kit
367
+ note: (node, { classes, escapeText }) =>
368
+ `<p${classes(node)}>{{ products['${escapeText(node.data.sku)}'].title }}</p>`
343
369
  }
344
370
  })
345
371
 
346
372
  registerTessEdit(application)
347
373
  ```
348
374
 
349
- Roles say where a block may go: `body` (in the email or a wrapper, like sections and heroes), `wrapper`, `column` (in a section) and `content` (in a column or hero). A container lists the roles it takes in `accepts`; Loop and Condition use `"inherit"`. The full definition, and the helpers a render hook gets (`element`, `container`, `children`, `liquid`, `attrs`, `richText`, ...), are described at the top of `core/registry.js` and `export/mjml.js`. Blocks render only through their `render` hooks: `mjml` for emails, and a hook of its own for each kit. Stored documents don't change; a document with a block type that isn't registered fails `normalize`.
375
+ Roles say where a block may go: `body` (in the kit's root, like sections), `column` (in a section), `content` (in a column, or in a kit's own containers), and `row` and `cell` in tables. A container lists the roles it takes in `accepts`; Loop and Condition use `"inherit"`. A kit adds roles of its own, such as an email's `wrapper`. The full definition is described at the top of `core/registry.js`. Blocks render only through their `render` hooks, one for each kit, with the helpers the kit's renderer gives them (the Note kit's `classes`, `children`, `richText`, …). Stored documents don't change; a document with a block type that isn't registered fails `normalize`.
350
376
 
351
377
  `extendBlock(type, { fields })` adds fields to a block that is registered: a group with the title of one of its groups adds to that one, any other goes last, or before the group its `before` names.
352
378
 
@@ -378,8 +404,8 @@ A `slot` field shows an element of your page in Inspect, for settings that aren'
378
404
  ```
379
405
 
380
406
  ```js
381
- extendBlock("email", {
382
- fields: [{ title: "When", before: "Message", fields: [{
407
+ extendBlock("note", {
408
+ fields: [{ title: "When", before: "Note", fields: [{
383
409
  key: "trigger", label: "Trigger", type: "slot", slot: "trigger",
384
410
  summary: (element) => element.querySelector("select").selectedOptions[0]?.text, // shown while collapsed
385
411
  open: (element) => Boolean(element.querySelector("[role=alert]")) // open at first, e.g. with errors
@@ -411,14 +437,14 @@ A select field's `options` can be a function of the editor, `options: (editor) =
411
437
 
412
438
  ## Kits
413
439
 
414
- What the editor makes is a kit: a root block, the blocks that name the kit in their `kits`, and what the canvas shows and the editor outputs. The email is the built-in kit and its reference. Your app registers its own with `registerKit` before its root block, and picks it with `data-tess-edit-kit-value`:
440
+ What the editor makes is a kit: a root block, the blocks that name the kit in their `kits`, and what the canvas shows and the editor outputs. TessEdit has no kit of its own. Your app registers one with `registerKit` before its root block, and picks it with `data-tess-edit-kit-value`:
415
441
 
416
442
  ```js
417
443
  import { createDocument, extendBlock, registerBlock, registerKit } from "tess_edit"
418
444
 
419
445
  registerKit({
420
446
  key: "note", name: "Note", root: "note",
421
- starter: () => createDocument("note"),
447
+ starter: () => createDocument("note"), // optional: the sample
422
448
  canvas: async (doc, { editor }) => ({ html: toNoteHtml(doc, { editor }), errors: [] }), // with tess-<id> classes in the editor
423
449
  outputs: async (doc) => ({ outputs: { html: toNoteHtml(doc) }, errors: [] }) // into the htmlInput
424
450
  })
@@ -428,48 +454,46 @@ registerBlock({ type: "note", name: "Note", kits: ["note"], accepts: ["body", "c
428
454
  extendBlock("text", { kits: ["note"], render: { note: (node, ctx) => … } })
429
455
  ```
430
456
 
431
- A block is part of the email kit unless it says otherwise. `extendBlock` adds kits, render hooks and field groups to a block that is registered, also when another gem replaced it, so the kit can use TessEdit's Text, Image, Section, Loop, Condition, Content and others. The kit renders its documents itself, through its blocks' hooks; the canvas needs every block's element to have the class `tess-<id>`, and an empty container a placeholder with `tessph-<id>`. `core/registry.js` describes the definition. `kits/email.js` is the reference, and the demo's Note kit (`test/dummy/app/javascript/kits/note.js`) a small one of a host app's own.
457
+ TessEdit's own blocks are part of no kit until a kit takes them in: `extendBlock` adds kits, render hooks and field groups to a block that is registered, also when another gem replaced it, so the kit can use TessEdit's Section, Column, Text, Image, Button, Table, Loop, Condition, Content and others. A block of your own names its kits. The kit renders its documents itself, through its blocks' hooks; the canvas needs every block's element to have the class `tess-<id>`, and an empty container a placeholder with `tessph-<id>`. `export/table.js` has a table's HTML, `export/richtext.js` rich text's, for a kit to use. `core/registry.js` describes the definition.
432
458
 
433
- Loading a document into the editor of another kit fails with a message saying which editor it is for.
459
+ The demo's Note kit (`test/dummy/app/javascript/kits/note.js`) is a small kit of a host app's own. [Nuntius](https://github.com/entdec/nuntius)' email kit (`app/javascript/nuntius/email`) is a complete one: it takes in TessEdit's blocks with their MJML, adds the email's own (Email, Wrapper, Hero, Social, Navbar), orders the Blocks panel's tiles with `palette`, loads documents from before its root's rename with `aliases`, and has its MJML compiled to HTML on the server (see [Compiling](#compiling)).
434
460
 
461
+ Loading a document into the editor of another kit fails with a message saying which editor it is for.
435
462
 
436
463
  A kit can leave out `blocks`: with `blocks: false` it is its root alone, such as a text message with its fields in Inspect, and the editor has no Blocks and Layers panels. Its `canvas` and `outputs` hooks get the editor's `options` and `element` too, for a canvas that previews from your app (`/?kit=memo` in the demo), where a link with `data-tess-open` opens in a new tab instead of selecting; the canvas renders again when `data-tess-edit-variables-url-value` changes. A field's `hint` can be a function of its value, `` hint: (value, node) => `${value.length} / 160` ``, kept up to date as it's typed. Code fields color `html`, `xml`, `css` and `yaml`.
464
+
437
465
  ## Development
438
466
 
439
- The dummy app in `test/dummy` serves a demo page:
467
+ The dummy app in `test/dummy` serves a demo page, a note: the demo's own kit (`app/javascript/kits/note.js`), which takes in all of TessEdit's blocks and is what the tests edit.
440
468
 
441
469
  ```bash
442
470
  cd test/dummy && bin/dev
443
471
  ```
444
472
 
445
- `/?lock=1` opens a locked layout (`test/dummy/config/demo_layout.json`) with only its Content block, subject and preview text open.
473
+ `/?kit=memo` writes a memo instead, a kit without blocks (`app/javascript/kits/memo.js`).
474
+
475
+ `/?lock=1` opens a locked layout (`test/dummy/config/demo_layout.json`) with only its Content block and title open.
446
476
 
447
477
  `/?media=1` gives the editor the demo's image endpoint (`MediaController`), so images can be chosen from a list, uploaded, or dragged onto the canvas from the desktop; uploads go to `test/dummy/tmp/media`. Without it, images are URLs only.
448
478
 
449
479
  `/?variables=1` gives the editor the demo's variables (`VariablesController`), an order's, to try the suggestions.
450
480
 
451
- `/?kit=note` designs a note: the demo's own kit (`app/javascript/kits/note.js`).
452
-
453
481
  `/?snippets=1` adds the demo's snippets source (`app/javascript/snippets.js`, `SnippetsController`): a greeting and a footer section.
454
482
 
483
+ `/?slots=1` puts the page's own sender fields in the note's Inspect (`app/javascript/slots.js`).
484
+
455
485
  `/?blocks=text,image` only offers those blocks.
456
486
 
457
- `/?values=1` gives it values for the sample's customer and order. `/?translations=1` gives the editor the demo's translations (`TranslationsController`, in memory, in English, Dutch and German). The options combine, e.g. `/?lock=1&media=1&variables=1&translations=1`.
487
+ `/?values=1` gives it values for the sample's customer and order. `/?translations=1` gives the editor the demo's translations (`TranslationsController`, in memory, in English, Dutch and German). `/?locale=nl` shows the editor in Dutch. The options combine, e.g. `/?lock=1&media=1&variables=1&translations=1`.
458
488
 
459
489
  Tests:
460
490
 
461
491
  ```bash
462
- npm test # JavaScript: document model, kits, export and MJML snapshots (Node 22+)
463
- bin/rails test # Rails: engine, compile endpoint, MRML and Liquid rendering of the snapshots
492
+ npm test # JavaScript: document model, registry, kits, tables, Liquid (Node 22+)
493
+ bin/rails test # Rails: engine, compilers and the compile endpoint, layouts' content
464
494
  bin/rails test:system # The editor in Chrome, through Selenium
465
495
  ```
466
496
 
467
- `npm test` compares the MJML of every email block, and of the sample email, with the files in `test/javascript/snapshots`. The Rails tests compile those files with MRML and render the sample with Liquid. After an intended change in output, regenerate them and review the diff:
468
-
469
- ```bash
470
- UPDATE_SNAPSHOTS=1 npm test
471
- ```
472
-
473
497
  System tests use a local headless Chrome. With `SELENIUM_URL` set, such as `http://selenium:4444/` in a devcontainer, they use that Selenium server instead and serve the app on this machine's address (or `CAPYBARA_APP_HOST`). `HEADLESS=0` shows the browser.
474
498
 
475
499
  Tiptap is vendored as a single ES module bundle in `vendor/javascript/tess_edit`. To update it:
@@ -482,13 +506,12 @@ cd script/vendor && npm install && node build.mjs
482
506
 
483
507
  Ideas for later, not planned yet:
484
508
 
485
- - **Importing MJML.** Turn an existing MJML template into a TessEdit document, so designs made elsewhere can be edited here. Parts without a matching block could become HTML blocks.
486
- - **Images whose address is Liquid.** An image with a `src` like `{{ product.image_url }}` shows as a broken image on the canvas. It should show a placeholder there instead, and in Inspect say that the address is filled in when the email is sent.
509
+ - **Images whose address is Liquid.** An image with a `src` like `{{ product.image_url }}` shows as a broken image on the canvas. It should show a placeholder there instead, and in Inspect say that the address is filled in when the Liquid is rendered.
487
510
  - **A translation block.** Text that differs per language in one design, e.g. a block with a version of its text per locale, so a host app doesn't need a design per language. (Translations through the `t` filter are there, see Translations.)
488
511
  - **Translating with a service.** Fill in a key's missing languages with DeepL or an LLM, from the translations popover.
489
- - **Text extensions from the host app.** Tiptap (the vendored bundle exports `Node`, `Mark` and `Extension`) can be extended, but the editor's extensions, the email HTML of rich text (`export/richtext.js`) and the text toolbar are fixed. A call like `registerTextExtension({ extension, toHtml(node, children), button })` would add all three, as `registerBlock` does for blocks. A Liquid variable shown as a chip (`{{ customer.first_name }}`) would be a first example; a translation could be one too. The bundle exports ProseMirror's `Plugin`, `PluginKey`, `Decoration` and `DecorationSet` (used for translations); node views would need more.
512
+ - **Text extensions from the host app.** Tiptap (the vendored bundle exports `Node`, `Mark` and `Extension`) can be extended, but the editor's extensions, the HTML of rich text (`export/richtext.js`) and the text toolbar are fixed. A call like `registerTextExtension({ extension, toHtml(node, children), button })` would add all three, as `registerBlock` does for blocks. A Liquid variable shown as a chip (`{{ customer.first_name }}`) would be a first example; a translation could be one too. The bundle exports ProseMirror's `Plugin`, `PluginKey`, `Decoration` and `DecorationSet` (used for translations); node views would need more.
490
513
  - **Dropping an image file where there's no image.** A file dropped on an empty spot in the canvas could add a new Image block there with the upload, instead of being refused.
491
514
 
492
515
  ## License
493
516
 
494
- MIT. The vendored Tiptap is MIT licensed too; MRML, through the `mrml` gem, is MIT licensed.
517
+ MIT. The vendored Tiptap is MIT licensed too.
@@ -1,9 +1,12 @@
1
1
  module TessEdit
2
- # POST /tess_edit/compile with { mjml: "..." }: the HTML the editor shows on
3
- # its canvas and stores in its html input.
2
+ # POST /tess_edit/compile with { compiler: "mjml", source: "..." }: the HTML a kit
3
+ # shows on its canvas and stores in its html input, made by a compiler the
4
+ # host registered (TessEdit.register_compiler).
4
5
  class CompilationsController < ApplicationController
5
6
  def create
6
- result = TessEdit.compile(params.require(:mjml))
7
+ return render(json: {html: nil, errors: ["No compiler #{params[:compiler]}"]}, status: :not_found) unless TessEdit.compiler?(params[:compiler])
8
+
9
+ result = TessEdit.compile(params[:compiler], params.require(:source))
7
10
  render json: {html: result.html, errors: result.errors}, status: result.errors.empty? ? :ok : :unprocessable_content
8
11
  end
9
12
  end
@@ -7,7 +7,7 @@
7
7
  // It shows nothing; in the editor, Layers shows it. In a table it goes
8
8
  // between rows.
9
9
 
10
- const assignTag = (node) => `{% assign ${node.data.variable || "value"} = ${node.data.expression || "nil"} %}`
10
+ export const assignTag = (node) => `{% assign ${node.data.variable || "value"} = ${node.data.expression || "nil"} %}`
11
11
 
12
12
  export default {
13
13
  type: "assign",
@@ -26,8 +26,5 @@ export default {
26
26
  }
27
27
  ],
28
28
  hint: "Sets a Liquid variable for the blocks after it: {% assign variable = value %}.",
29
- label: (node) => `${node.data.variable || "…"} = ${node.data.expression || "…"}`,
30
- render: {
31
- mjml: (node, { editor }) => (editor ? "" : `<mj-raw>${assignTag(node)}</mj-raw>`)
32
- }
29
+ label: (node) => `${node.data.variable || "…"} = ${node.data.expression || "…"}`
33
30
  }
@@ -1,19 +1,16 @@
1
- // The built-in blocks, registered by core/registry.js in this order. The
2
- // order is also the order of tiles in the Blocks panel.
1
+ // TessEdit's own blocks, registered by core/registry.js in this order, the
2
+ // order of their tiles in the Blocks panel unless a kit orders them. They are
3
+ // part of no kit: a kit takes them in with extendBlock, with how they render
4
+ // in it (see core/registry.js).
3
5
 
4
- import email from "tess_edit/blocks/email"
5
- import content from "tess_edit/blocks/content"
6
- import wrapper from "tess_edit/blocks/wrapper"
7
6
  import section from "tess_edit/blocks/section"
8
7
  import column from "tess_edit/blocks/column"
9
- import hero from "tess_edit/blocks/hero"
8
+ import content from "tess_edit/blocks/content"
10
9
  import text from "tess_edit/blocks/text"
11
10
  import image from "tess_edit/blocks/image"
12
11
  import button from "tess_edit/blocks/button"
13
12
  import divider from "tess_edit/blocks/divider"
14
13
  import spacer from "tess_edit/blocks/spacer"
15
- import social from "tess_edit/blocks/social"
16
- import navbar from "tess_edit/blocks/navbar"
17
14
  import raw from "tess_edit/blocks/raw"
18
15
  import loop from "tess_edit/blocks/loop"
19
16
  import condition from "tess_edit/blocks/condition"
@@ -26,4 +23,4 @@ export const builtinCategories = [
26
23
  { key: "liquid", label: "Liquid", order: 30 }
27
24
  ]
28
25
 
29
- export const builtinBlocks = [email, section, column, wrapper, hero, content, text, image, button, divider, spacer, social, navbar, raw, loop, condition, assign, table, tableRow, tableCell]
26
+ export const builtinBlocks = [section, column, content, text, image, button, divider, spacer, raw, loop, condition, assign, table, tableRow, tableCell]
@@ -28,8 +28,5 @@ export default {
28
28
  typography(),
29
29
  border
30
30
  ],
31
- label: (node) => `${t("Button")} · ${node.data.content || ""}`,
32
- render: {
33
- mjml: (node, { element, escapeText }) => element("mj-button", node, escapeText(node.data.content))
34
- }
31
+ label: (node) => `${t("Button")} · ${node.data.content || ""}`
35
32
  }
@@ -19,8 +19,5 @@ export default {
19
19
  ]
20
20
  },
21
21
  border
22
- ],
23
- render: {
24
- mjml: (node, { container }) => container("mj-column", node)
25
- }
22
+ ]
26
23
  }
@@ -1,4 +1,4 @@
1
- const ifTag = (node) => `{% if ${node.data.expression || "true"} %}`
1
+ export const ifTag = (node) => `{% if ${node.data.expression || "true"} %}`
2
2
 
3
3
  export default {
4
4
  type: "condition",
@@ -11,8 +11,5 @@ export default {
11
11
  defaults: () => ({ data: { expression: "customer.vip" } }),
12
12
  fields: [{ title: "Condition", fields: [{ key: "data.expression", label: "Show when", type: "text", liquid: "condition", hint: "A Liquid condition, e.g. order.total > 100." }] }],
13
13
  hint: "Shows its blocks only when the condition is true: {% if expression %}.",
14
- label: (node) => `If ${node.data.expression || "…"}`,
15
- render: {
16
- mjml: (node, { liquid }) => liquid(node, ifTag(node), "{% endif %}")
17
- }
14
+ label: (node) => `If ${node.data.expression || "…"}`
18
15
  }
@@ -8,14 +8,13 @@
8
8
  //
9
9
  // <!-- tess-edit:content --> … <!-- /tess-edit:content -->
10
10
  //
11
- // In MJML the comments are in <mj-raw> tags, which MJML keeps. A kit that
12
- // uses it renders the same comments (see extendBlock in core/registry.js).
11
+ // A kit that uses it renders these comments around its children, in a tag
12
+ // of its own if it needs one, such as an email's <mj-raw> (see extendBlock in
13
+ // core/registry.js).
13
14
 
14
15
  export const CONTENT_START = "<!-- tess-edit:content -->"
15
16
  export const CONTENT_END = "<!-- /tess-edit:content -->"
16
17
 
17
- const mjRaw = (comment) => `<mj-raw>${comment}</mj-raw>`
18
-
19
18
  export default {
20
19
  type: "content",
21
20
  name: "Content",
@@ -26,11 +25,5 @@ export default {
26
25
  // parent takes, so it works at the top level and inside a column.
27
26
  roles: ["body", "content"],
28
27
  accepts: "inherit",
29
- hint: "The content of the documents using this layout goes here. What you put inside is example content for designing the layout.",
30
- render: {
31
- mjml(node, { editor, children }) {
32
- const inner = children(node)
33
- return editor ? inner.join("\n") : [mjRaw(CONTENT_START), ...inner, mjRaw(CONTENT_END)].join("\n")
34
- }
35
- }
28
+ hint: "The content of the documents using this layout goes here. What you put inside is example content for designing the layout."
36
29
  }
@@ -19,8 +19,5 @@ export default {
19
19
  padding
20
20
  ]
21
21
  }
22
- ],
23
- render: {
24
- mjml: (node, { element }) => element("mj-divider", node)
25
- }
22
+ ]
26
23
  }
@@ -24,8 +24,5 @@ export default {
24
24
  ]
25
25
  },
26
26
  { title: "Border", collapsed: true, fields: [{ key: "attributes.border", label: "Border", type: "text" }, { key: "attributes.border-radius", label: "Radius", type: "size" }, { key: "attributes.container-background-color", label: "Background", type: "color" }] }
27
- ],
28
- render: {
29
- mjml: (node, { element }) => element("mj-image", node)
30
- }
27
+ ]
31
28
  }
@@ -1,4 +1,4 @@
1
- const forTag = (node) => `{% for ${node.data.variable || "item"} in ${node.data.collection || "items"} %}`
1
+ export const forTag = (node) => `{% for ${node.data.variable || "item"} in ${node.data.collection || "items"} %}`
2
2
 
3
3
  export default {
4
4
  type: "loop",
@@ -19,8 +19,5 @@ export default {
19
19
  }
20
20
  ],
21
21
  hint: "Repeats its blocks for each item: {% for variable in collection %}.",
22
- label: (node) => `For ${node.data.variable || "item"} in ${node.data.collection || "…"}`,
23
- render: {
24
- mjml: (node, { liquid }) => liquid(node, forTag(node), "{% endfor %}")
25
- }
22
+ label: (node) => `For ${node.data.variable || "item"} in ${node.data.collection || "…"}`
26
23
  }
@@ -5,14 +5,5 @@ export default {
5
5
  category: "content",
6
6
  roles: ["body", "content"],
7
7
  defaults: () => ({ data: { html: '<p style="margin:0;padding:10px 25px;">Custom HTML</p>' } }),
8
- fields: [{ title: "HTML", fields: [{ key: "data.html", label: "HTML", type: "code", liquid: true, hint: "Copied into the email as-is. Liquid works here too." }] }],
9
- render: {
10
- mjml(node, { editor, context }) {
11
- const html = node.data.html || ""
12
- if (!editor) return `<mj-raw>${html}</mj-raw>`
13
- // mj-raw output cannot carry a class, so the canvas shows it inside a text block.
14
- const text = `<mj-text css-class="tess-${node.id}" padding="0px">${html}</mj-text>`
15
- return context === "column" ? text : `<mj-section padding="0px"><mj-column>${text}</mj-column></mj-section>`
16
- }
17
- }
8
+ fields: [{ title: "HTML", fields: [{ key: "data.html", label: "HTML", type: "code", liquid: true, hint: "Copied into the document as it is. Liquid works here too." }] }]
18
9
  }