tess_edit 0.2.2 → 0.4.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.
- checksums.yaml +4 -4
- data/README.md +114 -9
- data/app/javascript/tess_edit/blocks/builtin.js +3 -2
- data/app/javascript/tess_edit/blocks/button.js +3 -1
- data/app/javascript/tess_edit/blocks/column.js +3 -1
- data/app/javascript/tess_edit/blocks/condition.js +3 -1
- data/app/javascript/tess_edit/blocks/content.js +36 -0
- data/app/javascript/tess_edit/blocks/divider.js +3 -1
- data/app/javascript/tess_edit/blocks/{root.js → email.js} +3 -3
- data/app/javascript/tess_edit/blocks/fields.js +4 -2
- data/app/javascript/tess_edit/blocks/image.js +3 -1
- data/app/javascript/tess_edit/blocks/loop.js +3 -1
- data/app/javascript/tess_edit/blocks/section.js +4 -2
- data/app/javascript/tess_edit/blocks/spacer.js +3 -1
- data/app/javascript/tess_edit/blocks/text.js +3 -1
- data/app/javascript/tess_edit/controllers/editor_controller.js +267 -60
- data/app/javascript/tess_edit/core/document.js +66 -16
- data/app/javascript/tess_edit/core/registry.js +119 -11
- data/app/javascript/tess_edit/core/translations.js +229 -0
- data/app/javascript/tess_edit/index.js +4 -3
- data/app/javascript/tess_edit/kits/builtin.js +5 -0
- data/app/javascript/tess_edit/kits/email.js +28 -0
- data/app/javascript/tess_edit/ui/blocks_panel.js +54 -5
- data/app/javascript/tess_edit/ui/canvas.js +96 -12
- data/app/javascript/tess_edit/ui/dialog.js +103 -0
- data/app/javascript/tess_edit/ui/icons.js +5 -1
- data/app/javascript/tess_edit/ui/inspector.js +76 -7
- data/app/javascript/tess_edit/ui/text_editing.js +112 -11
- data/app/javascript/tess_edit/ui/translate_dialog.js +30 -0
- data/app/javascript/tess_edit/ui/translation_popover.js +165 -0
- data/app/javascript/tess_edit/ui/tree.js +2 -2
- data/app/javascript/tess_edit/ui/variable_menu.js +29 -1
- data/lib/tess_edit/content.rb +62 -0
- data/lib/tess_edit/version.rb +1 -1
- data/lib/tess_edit.rb +1 -0
- data/vendor/javascript/tess_edit/tiptap.js +13 -13
- metadata +10 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a7edf50f5750b4cfa068076d5bce42ba51c8ff068e3b272c1b882a27ca573fec
|
|
4
|
+
data.tar.gz: d521a49419a260dcf5066274511588e5f602715fa6ceaf2fb5cd1fcfb3dea983
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ad669b198bad3b4beb556629b880448d22c8cd54c5b45cbf5d0b7c34cbdb3513d9d9e7644fe6630b60bc8ffc93e8ffa3563ace8aae009c6c1dd327b2d0b706ba
|
|
7
|
+
data.tar.gz: 89feda7ff43627f7d8df5ea18d0fb2d156ac8a07f91ae9d1dd64a6d8d71f801b8ff1c179eb08369e0d6522d24a3f5b829868714bb48ae919d3ec6b1761c81242
|
data/README.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
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.
|
|
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)).
|
|
6
|
+
|
|
5
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.
|
|
6
8
|
|
|
7
9
|

|
|
@@ -16,11 +18,15 @@ It completes Liquid tags and variables as you type, making it easier to work wit
|
|
|
16
18
|
- 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.
|
|
17
19
|
- 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.
|
|
18
20
|
- 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.
|
|
21
|
+
- 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.
|
|
19
22
|
- Undo/redo, duplicate, delete, keyboard shortcuts (⌘Z, ⇧⌘Z, ⌘D, Delete, Enter to edit text, Esc).
|
|
20
23
|
- Desktop and mobile preview, and a preview of the HTML as sent.
|
|
21
24
|
- Panels on both sides, or combined as tabs in one sidebar on the left or right to give the canvas more room.
|
|
22
25
|
- Dark mode that follows the host app's.
|
|
23
26
|
- Code dialog to view, copy or download the JSON, MJML and HTML, and to load JSON.
|
|
27
|
+
- Kits: other kinds of documents, registered by your app, with its own blocks and output and TessEdit's blocks brought in.
|
|
28
|
+
- 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.
|
|
29
|
+
- Palette sources: tiles from your app in the Blocks panel, such as saved snippets, inserted as a copy that remembers where it came from.
|
|
24
30
|
|
|
25
31
|
## Installation
|
|
26
32
|
|
|
@@ -116,7 +122,7 @@ TessEdit.parent_controller = "Admin::BaseController"
|
|
|
116
122
|
|
|
117
123
|
```json
|
|
118
124
|
{
|
|
119
|
-
"version": 1, "id": "b1x2y3z", "type": "
|
|
125
|
+
"version": 1, "id": "b1x2y3z", "type": "email",
|
|
120
126
|
"attributes": { "width": "600px", "background-color": "#f3f4f6" },
|
|
121
127
|
"data": { "subject": "...", "preheader": "...", "fontFamily": "..." },
|
|
122
128
|
"children": [
|
|
@@ -129,7 +135,7 @@ TessEdit.parent_controller = "Admin::BaseController"
|
|
|
129
135
|
}
|
|
130
136
|
```
|
|
131
137
|
|
|
132
|
-
The top node is the `
|
|
138
|
+
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.
|
|
133
139
|
|
|
134
140
|
### Locking a layout
|
|
135
141
|
|
|
@@ -140,7 +146,48 @@ To let people fill in one part of a design that is otherwise fixed, such as a te
|
|
|
140
146
|
data-tess-edit-lock-value='<%= {except: ["content"], fields: ["data.subject", "data.preheader"]}.to_json %>'>
|
|
141
147
|
```
|
|
142
148
|
|
|
143
|
-
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`
|
|
149
|
+
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).
|
|
150
|
+
|
|
151
|
+
### Layouts
|
|
152
|
+
|
|
153
|
+
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:
|
|
154
|
+
|
|
155
|
+
```html
|
|
156
|
+
<!-- tess-edit:content --> … <!-- /tess-edit:content -->
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
A document using a layout stores its own blocks. `TessEdit::Content` puts them in and takes them out again, and puts a document's output into its layout's, so a document follows its layout when the layout changes:
|
|
160
|
+
|
|
161
|
+
```ruby
|
|
162
|
+
document = TessEdit::Content.document_with(layout.json, template.blocks) # for the editor, locked to the Content block
|
|
163
|
+
blocks = TessEdit::Content.nodes(JSON.parse(params[:json])) # what to store when it is saved
|
|
164
|
+
html = TessEdit::Content.merge(layout.html, TessEdit::Content.content_of(params[:html]))
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
### Palette sources
|
|
168
|
+
|
|
169
|
+
A palette source adds a section of tiles from your app to the Blocks panel, such as saved snippets. People drag a tile onto the canvas or click it, and the source creates the node that goes in:
|
|
170
|
+
|
|
171
|
+
```js
|
|
172
|
+
import { registerPaletteSource, renumber } from "tess_edit"
|
|
173
|
+
|
|
174
|
+
registerPaletteSource({
|
|
175
|
+
key: "snippets",
|
|
176
|
+
label: "Snippets",
|
|
177
|
+
// null leaves the section out, e.g. without the setting it needs
|
|
178
|
+
items: async (editor) => {
|
|
179
|
+
if (!editor.options.snippetsUrl) return null
|
|
180
|
+
const response = await fetch(editor.options.snippetsUrl)
|
|
181
|
+
return (await response.json()).snippets // [{ key, label, type, … }]
|
|
182
|
+
},
|
|
183
|
+
// The node to insert, here a copy of the snippet's block
|
|
184
|
+
create: async (item, editor) => renumber(item.block, { origin: true })
|
|
185
|
+
})
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
An item's `type` says where the tile can go; a container with `accepts: "inherit"` goes where its children go, so a snippet with sections can't go into a column, and the editor says so. `renumber(node, { origin: true })` gives every copied block an `origin`, the id of the block it is a copy of, so your app can compare the copy with what it came from, block by block. A duplicated block is new content and has no origin. `data-tess-edit-options-value` passes settings such as `snippetsUrl` to sources and blocks, as `editor.options`.
|
|
189
|
+
|
|
190
|
+
`data-tess-edit-blocks-value` limits the blocks people can add, e.g. `["text", "image"]`; blocks already in the document, and tiles from sources, aren't affected.
|
|
144
191
|
|
|
145
192
|
### Images
|
|
146
193
|
|
|
@@ -173,6 +220,30 @@ The endpoint answers `GET` with the variables at `path` (the roots without one),
|
|
|
173
220
|
|
|
174
221
|
A field of your own gets the `{ }` button with `liquid: true`, or `liquid: "expression"` (a condition) or `liquid: "collection"` (what a loop goes over) for Liquid without braces.
|
|
175
222
|
|
|
223
|
+
### Translations
|
|
224
|
+
|
|
225
|
+
To show and edit translations for Liquid's `t` filter, as [Liquidum](https://github.com/entdec/liquidum) has it (`{{ '.greeting' | t }}`, `{{ "order.shipped" | t: name: order.name }}`), give the editor an endpoint with `data-tess-edit-translations-url-value`. Then:
|
|
226
|
+
|
|
227
|
+
- The top bar has a language menu. The canvas shows each `t` filter on a quoted key as its text in that language, or the Liquid when it has none (marked red when a language is missing it). "Keys" shows the Liquid everywhere. A filter that names a locale (`t: locale: 'nl'`) shows that one.
|
|
228
|
+
- Pointing at one lists its text in every language. Each can be edited there, and the arrow opens where your app keeps it.
|
|
229
|
+
- In text being edited on the canvas a filter shows as its text until the caret goes into it; a click on it does that.
|
|
230
|
+
- The text toolbar, and settings that usually hold Liquid text, have a "Make translatable" button: it asks for a key (suggested from the text), saves the selected text (or the whole setting) as that key's text in the chosen language, and puts `{{ '<key>' | t }}` in its place. Variables in the text become placeholders, given as the filter's arguments: "Hi {{ user.first_name }}" is saved as `Hi %{first_name}`, with `{{ '<key>' | t: first_name: user.first_name }}`; Liquid tags and filters can't go into a translation. Below such a setting its filters show their text.
|
|
231
|
+
- Placeholders (`%{name}`) show apart in a text; one the filter has no argument for is marked.
|
|
232
|
+
- Typing `{{ '` suggests the keys, with their text.
|
|
233
|
+
|
|
234
|
+
The endpoint answers, as JSON:
|
|
235
|
+
|
|
236
|
+
- `GET` with the keys in the document, comma-separated in `keys`: the languages, the translations of those keys and of the keys to suggest, and the keys to suggest
|
|
237
|
+
```json
|
|
238
|
+
{"locales": ["en", "nl"],
|
|
239
|
+
"translations": {".greeting": {"en": {"value": "Hello", "source": "Account › en", "url": "/locales/1/edit"}, "nl": null}},
|
|
240
|
+
"suggestions": [".greeting"]}
|
|
241
|
+
```
|
|
242
|
+
A missing text is `null`; `source` says where a text comes from (shown when pointed at) and `url` where to edit it (both optional).
|
|
243
|
+
- `PATCH` with `{"key": "…", "locale": "nl", "value": "…"}` (JSON, with the page's CSRF token): `{"key": "…", "translation": {"en": …, "nl": …}}`, or `{"errors": ["…"]}` with an error status
|
|
244
|
+
|
|
245
|
+
Where the texts are kept, and what a key starting with a dot is relative to, is up to your app. The dummy app's `TranslationsController` keeps them in memory (`/?translations=1`).
|
|
246
|
+
|
|
176
247
|
### Blocks and custom blocks
|
|
177
248
|
|
|
178
249
|
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:
|
|
@@ -201,7 +272,32 @@ registerBlock({
|
|
|
201
272
|
registerTessEdit(application)
|
|
202
273
|
```
|
|
203
274
|
|
|
204
|
-
Roles say where a block may go: `body` (in the
|
|
275
|
+
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`.
|
|
276
|
+
|
|
277
|
+
A select field's `options` can be a function of the editor, `options: (editor) => [...]`, for choices from your app. Give the editor those with `data-tess-edit-options-value` (JSON), which blocks read as `editor.options`.
|
|
278
|
+
|
|
279
|
+
## Kits
|
|
280
|
+
|
|
281
|
+
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`:
|
|
282
|
+
|
|
283
|
+
```js
|
|
284
|
+
import { createDocument, extendBlock, registerBlock, registerKit } from "tess_edit"
|
|
285
|
+
|
|
286
|
+
registerKit({
|
|
287
|
+
key: "note", name: "Note", root: "note",
|
|
288
|
+
starter: () => createDocument("note"),
|
|
289
|
+
canvas: async (doc, { editor }) => ({ html: toNoteHtml(doc, { editor }), errors: [] }), // with tess-<id> classes in the editor
|
|
290
|
+
outputs: async (doc) => ({ outputs: { html: toNoteHtml(doc) }, errors: [] }) // into the htmlInput
|
|
291
|
+
})
|
|
292
|
+
registerBlock({ type: "note", name: "Note", kits: ["note"], accepts: ["body", "content"], render: { note: … } })
|
|
293
|
+
|
|
294
|
+
// TessEdit's own blocks, in the kit, with how they render in it
|
|
295
|
+
extendBlock("text", { kits: ["note"], render: { note: (node, ctx) => … } })
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
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.
|
|
299
|
+
|
|
300
|
+
Loading a document into the editor of another kit fails with a message saying which editor it is for.
|
|
205
301
|
|
|
206
302
|
## Development
|
|
207
303
|
|
|
@@ -215,17 +311,25 @@ cd test/dummy && bin/dev
|
|
|
215
311
|
|
|
216
312
|
`/?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.
|
|
217
313
|
|
|
218
|
-
`/?variables=1` gives the editor the demo's variables (`VariablesController`), an order's, to try the suggestions.
|
|
314
|
+
`/?variables=1` gives the editor the demo's variables (`VariablesController`), an order's, to try the suggestions.
|
|
315
|
+
|
|
316
|
+
`/?kit=note` designs a note: the demo's own kit (`app/javascript/kits/note.js`).
|
|
317
|
+
|
|
318
|
+
`/?snippets=1` adds the demo's snippets source (`app/javascript/snippets.js`, `SnippetsController`): a greeting and a footer section.
|
|
319
|
+
|
|
320
|
+
`/?blocks=text,image` only offers those blocks.
|
|
321
|
+
|
|
322
|
+
`/?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`.
|
|
219
323
|
|
|
220
324
|
Tests:
|
|
221
325
|
|
|
222
326
|
```bash
|
|
223
|
-
npm test # JavaScript: document model,
|
|
327
|
+
npm test # JavaScript: document model, kits, export and MJML snapshots (Node 22+)
|
|
224
328
|
bin/rails test # Rails: engine, compile endpoint, MRML and Liquid rendering of the snapshots
|
|
225
329
|
bin/rails test:system # The editor in Chrome, through Selenium
|
|
226
330
|
```
|
|
227
331
|
|
|
228
|
-
`npm test` compares the MJML of every 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:
|
|
332
|
+
`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:
|
|
229
333
|
|
|
230
334
|
```bash
|
|
231
335
|
UPDATE_SNAPSHOTS=1 npm test
|
|
@@ -245,8 +349,9 @@ Ideas for later, not planned yet:
|
|
|
245
349
|
|
|
246
350
|
- **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.
|
|
247
351
|
- **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.
|
|
248
|
-
- **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.
|
|
249
|
-
- **
|
|
352
|
+
- **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.)
|
|
353
|
+
- **Translating with a service.** Fill in a key's missing languages with DeepL or an LLM, from the translations popover.
|
|
354
|
+
- **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.
|
|
250
355
|
- **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.
|
|
251
356
|
|
|
252
357
|
## License
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// The built-in blocks, registered by core/registry.js in this order. The
|
|
2
2
|
// order is also the order of tiles in the Blocks panel.
|
|
3
3
|
|
|
4
|
-
import
|
|
4
|
+
import email from "tess_edit/blocks/email"
|
|
5
|
+
import content from "tess_edit/blocks/content"
|
|
5
6
|
import wrapper from "tess_edit/blocks/wrapper"
|
|
6
7
|
import section from "tess_edit/blocks/section"
|
|
7
8
|
import column from "tess_edit/blocks/column"
|
|
@@ -23,4 +24,4 @@ export const builtinCategories = [
|
|
|
23
24
|
{ key: "liquid", label: "Liquid", order: 30 }
|
|
24
25
|
]
|
|
25
26
|
|
|
26
|
-
export const builtinBlocks = [
|
|
27
|
+
export const builtinBlocks = [email, section, column, wrapper, hero, content, text, image, button, divider, spacer, social, navbar, raw, loop, condition]
|
|
@@ -28,5 +28,7 @@ export default {
|
|
|
28
28
|
border
|
|
29
29
|
],
|
|
30
30
|
label: (node) => `Button · ${node.data.content || ""}`,
|
|
31
|
-
render: {
|
|
31
|
+
render: {
|
|
32
|
+
mjml: (node, { element, escapeText }) => element("mj-button", node, escapeText(node.data.content))
|
|
33
|
+
}
|
|
32
34
|
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
const ifTag = (node) => `{% if ${node.data.expression || "true"} %}`
|
|
2
|
+
|
|
1
3
|
export default {
|
|
2
4
|
type: "condition",
|
|
3
5
|
name: "Condition",
|
|
@@ -10,6 +12,6 @@ export default {
|
|
|
10
12
|
hint: "Shows its blocks only when the condition is true: {% if expression %}.",
|
|
11
13
|
label: (node) => `If ${node.data.expression || "…"}`,
|
|
12
14
|
render: {
|
|
13
|
-
mjml: (node, { liquid }) => liquid(node,
|
|
15
|
+
mjml: (node, { liquid }) => liquid(node, ifTag(node), "{% endif %}")
|
|
14
16
|
}
|
|
15
17
|
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// Where the documents using a layout put their own blocks. What a layout has
|
|
2
|
+
// inside it is example content to design the layout with; a document using
|
|
3
|
+
// the layout replaces it with its own. A layout has one.
|
|
4
|
+
//
|
|
5
|
+
// Outside the editor its contents are marked with two comments, so the host
|
|
6
|
+
// can put a document's content into the layout's output (see
|
|
7
|
+
// TessEdit::Content):
|
|
8
|
+
//
|
|
9
|
+
// <!-- tess-edit:content --> … <!-- /tess-edit:content -->
|
|
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).
|
|
13
|
+
|
|
14
|
+
export const CONTENT_START = "<!-- tess-edit:content -->"
|
|
15
|
+
export const CONTENT_END = "<!-- /tess-edit:content -->"
|
|
16
|
+
|
|
17
|
+
const mjRaw = (comment) => `<mj-raw>${comment}</mj-raw>`
|
|
18
|
+
|
|
19
|
+
export default {
|
|
20
|
+
type: "content",
|
|
21
|
+
name: "Content",
|
|
22
|
+
icon: "content",
|
|
23
|
+
category: "layout",
|
|
24
|
+
unique: true,
|
|
25
|
+
// Like Loop and Condition it adds no HTML of its own and takes what its
|
|
26
|
+
// parent takes, so it works at the top level and inside a column.
|
|
27
|
+
roles: ["body", "content"],
|
|
28
|
+
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
|
+
}
|
|
36
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
// The root of
|
|
1
|
+
// The root of an email: renders the whole <mjml> document, with the
|
|
2
2
|
// email's subject, preview text and theme in <mj-head>.
|
|
3
3
|
|
|
4
4
|
export default {
|
|
5
|
-
type: "
|
|
6
|
-
name: "
|
|
5
|
+
type: "email",
|
|
6
|
+
name: "Email",
|
|
7
7
|
icon: "root",
|
|
8
8
|
roles: [],
|
|
9
9
|
accepts: ["body", "wrapper"],
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
// Field definitions shared by the built-in blocks, and usable by custom ones.
|
|
2
2
|
// A field: { key: "attributes.padding" | "data.subject", label, type, ... }.
|
|
3
3
|
// Types: text, textarea, code, size, color, select, segmented, toggle,
|
|
4
|
-
// spacing and list; see ui/inspector.js.
|
|
5
|
-
//
|
|
4
|
+
// spacing and list; see ui/inspector.js. A select's options can be a
|
|
5
|
+
// function of the editor, options(editor), for choices the host gives.
|
|
6
|
+
// `liquid` gives a field a button to insert the host's variables (see
|
|
7
|
+
// Inspector#variables).
|
|
6
8
|
|
|
7
9
|
export const ALIGN = [
|
|
8
10
|
{ value: "left", label: "Left" },
|
|
@@ -25,5 +25,7 @@ export default {
|
|
|
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
27
|
],
|
|
28
|
-
render: {
|
|
28
|
+
render: {
|
|
29
|
+
mjml: (node, { element }) => element("mj-image", node)
|
|
30
|
+
}
|
|
29
31
|
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
const forTag = (node) => `{% for ${node.data.variable || "item"} in ${node.data.collection || "items"} %}`
|
|
2
|
+
|
|
1
3
|
export default {
|
|
2
4
|
type: "loop",
|
|
3
5
|
name: "Loop",
|
|
@@ -18,6 +20,6 @@ export default {
|
|
|
18
20
|
hint: "Repeats its blocks for each item: {% for variable in collection %}.",
|
|
19
21
|
label: (node) => `For ${node.data.variable || "item"} in ${node.data.collection || "…"}`,
|
|
20
22
|
render: {
|
|
21
|
-
mjml: (node, { liquid }) => liquid(node,
|
|
23
|
+
mjml: (node, { liquid }) => liquid(node, forTag(node), "{% endfor %}")
|
|
22
24
|
}
|
|
23
25
|
}
|
|
@@ -27,7 +27,7 @@ export default {
|
|
|
27
27
|
fields: [
|
|
28
28
|
background,
|
|
29
29
|
imageField("attributes.background-url", "Background image", "data.background"),
|
|
30
|
-
{ key: "attributes.full-width", label: "Full width", type: "toggle", on: "full-width", off: "" },
|
|
30
|
+
{ key: "attributes.full-width", label: "Full width", type: "toggle", on: "full-width", off: "", visible: (node, editor) => editor?.kit?.key === "email" },
|
|
31
31
|
{ key: "attributes.direction", label: "Column order", type: "segmented", options: [{ value: "ltr", label: "Left to right" }, { value: "rtl", label: "Right to left" }] },
|
|
32
32
|
{ key: "attributes.text-align", label: "Align", type: "segmented", options: ALIGN },
|
|
33
33
|
padding
|
|
@@ -36,5 +36,7 @@ export default {
|
|
|
36
36
|
border
|
|
37
37
|
],
|
|
38
38
|
palette: layouts.map(([key, label, icon, widths]) => ({ key, label, icon, category: "layout", create: ({ createNode }) => section(createNode, widths) })),
|
|
39
|
-
render: {
|
|
39
|
+
render: {
|
|
40
|
+
mjml: (node, { container }) => container("mj-section", node)
|
|
41
|
+
}
|
|
40
42
|
}
|
|
@@ -6,5 +6,7 @@ export default {
|
|
|
6
6
|
roles: ["content"],
|
|
7
7
|
defaults: () => ({ attributes: { height: "24px" } }),
|
|
8
8
|
fields: [{ title: "Spacer", fields: [{ key: "attributes.height", label: "Height", type: "size" }, { key: "attributes.container-background-color", label: "Background", type: "color" }] }],
|
|
9
|
-
render: {
|
|
9
|
+
render: {
|
|
10
|
+
mjml: (node, { element }) => element("mj-spacer", node)
|
|
11
|
+
}
|
|
10
12
|
}
|
|
@@ -35,5 +35,7 @@ export default {
|
|
|
35
35
|
create: ({ createNode }) => createNode("text", { attributes: { "font-size": "24px", "font-weight": "700", "line-height": "1.3" }, data: { content: doc("Heading") } })
|
|
36
36
|
}
|
|
37
37
|
],
|
|
38
|
-
render: {
|
|
38
|
+
render: {
|
|
39
|
+
mjml: (node, { element, richText }) => element("mj-text", node, richText(node.data.content))
|
|
40
|
+
}
|
|
39
41
|
}
|