tess_edit 0.5.18 → 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.
- checksums.yaml +4 -4
- data/README.md +91 -68
- data/app/controllers/tess_edit/compilations_controller.rb +6 -3
- data/app/javascript/tess_edit/blocks/assign.js +2 -5
- data/app/javascript/tess_edit/blocks/builtin.js +6 -9
- data/app/javascript/tess_edit/blocks/button.js +1 -4
- data/app/javascript/tess_edit/blocks/column.js +1 -4
- data/app/javascript/tess_edit/blocks/condition.js +2 -5
- data/app/javascript/tess_edit/blocks/content.js +4 -11
- data/app/javascript/tess_edit/blocks/divider.js +1 -4
- data/app/javascript/tess_edit/blocks/image.js +1 -4
- data/app/javascript/tess_edit/blocks/loop.js +2 -5
- data/app/javascript/tess_edit/blocks/raw.js +1 -10
- data/app/javascript/tess_edit/blocks/section.js +1 -5
- data/app/javascript/tess_edit/blocks/spacer.js +1 -4
- data/app/javascript/tess_edit/blocks/table.js +8 -15
- data/app/javascript/tess_edit/blocks/text.js +1 -4
- data/app/javascript/tess_edit/controllers/editor_controller.js +32 -20
- data/app/javascript/tess_edit/core/document.js +8 -8
- data/app/javascript/tess_edit/core/media.js +1 -1
- data/app/javascript/tess_edit/core/registry.js +29 -25
- data/app/javascript/tess_edit/export/compile.js +15 -6
- data/app/javascript/tess_edit/export/richtext.js +1 -1
- data/app/javascript/tess_edit/export/table.js +9 -7
- data/app/javascript/tess_edit/index.js +2 -3
- data/app/javascript/tess_edit/ui/canvas.js +5 -5
- data/config/locales/en.yml +1 -39
- data/config/locales/nl.yml +1 -39
- data/lib/tess_edit/content.rb +5 -4
- data/lib/tess_edit/version.rb +1 -1
- data/lib/tess_edit.rb +34 -8
- metadata +1 -24
- data/app/javascript/tess_edit/blocks/email.js +0 -83
- data/app/javascript/tess_edit/blocks/hero.js +0 -60
- data/app/javascript/tess_edit/blocks/navbar.js +0 -49
- data/app/javascript/tess_edit/blocks/social.js +0 -39
- data/app/javascript/tess_edit/blocks/wrapper.js +0 -24
- data/app/javascript/tess_edit/core/starter.js +0 -89
- data/app/javascript/tess_edit/export/mjml.js +0 -117
- data/app/javascript/tess_edit/kits/builtin.js +0 -5
- data/app/javascript/tess_edit/kits/email.js +0 -28
|
@@ -27,7 +27,6 @@ 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: "", visible: (node, editor) => editor?.kit?.key === "email" },
|
|
31
30
|
{ key: "attributes.direction", label: "Column order", type: "segmented", options: [{ value: "ltr", label: "Left to right" }, { value: "rtl", label: "Right to left" }] },
|
|
32
31
|
{ key: "attributes.text-align", label: "Align", type: "segmented", options: ALIGN },
|
|
33
32
|
padding
|
|
@@ -35,8 +34,5 @@ export default {
|
|
|
35
34
|
},
|
|
36
35
|
border
|
|
37
36
|
],
|
|
38
|
-
palette: layouts.map(([key, label, icon, widths]) => ({ key, label, icon, category: "layout", create: ({ createNode }) => section(createNode, widths) }))
|
|
39
|
-
render: {
|
|
40
|
-
mjml: (node, { container }) => container("mj-section", node)
|
|
41
|
-
}
|
|
37
|
+
palette: layouts.map(([key, label, icon, widths]) => ({ key, label, icon, category: "layout", create: ({ createNode }) => section(createNode, widths) }))
|
|
42
38
|
}
|
|
@@ -5,8 +5,5 @@ export default {
|
|
|
5
5
|
category: "content",
|
|
6
6
|
roles: ["content"],
|
|
7
7
|
defaults: () => ({ attributes: { height: "24px" } }),
|
|
8
|
-
fields: [{ title: "Spacer", fields: [{ key: "attributes.height", label: "Height", type: "size" }, { key: "attributes.container-background-color", label: "Background", type: "color" }] }]
|
|
9
|
-
render: {
|
|
10
|
-
mjml: (node, { element }) => element("mj-spacer", node)
|
|
11
|
-
}
|
|
8
|
+
fields: [{ title: "Spacer", fields: [{ key: "attributes.height", label: "Height", type: "size" }, { key: "attributes.container-background-color", label: "Background", type: "color" }] }]
|
|
12
9
|
}
|
|
@@ -7,14 +7,14 @@
|
|
|
7
7
|
// selected cell, whose Table group also adds and deletes rows and columns
|
|
8
8
|
// (core/table.js, the "table" field in ui/inspector.js).
|
|
9
9
|
//
|
|
10
|
-
//
|
|
11
|
-
//
|
|
12
|
-
//
|
|
10
|
+
// A kit takes them in with extendBlock and its own render hooks. The table's
|
|
11
|
+
// HTML, with its rows and cells, is export/table.js's tableHtml, which an
|
|
12
|
+
// email's mj-table and a note's <table> both use; a row and a cell render
|
|
13
|
+
// nothing of their own there.
|
|
13
14
|
|
|
14
15
|
import { ALIGN, VERTICAL_ALIGN, background, padding } from "tess_edit/blocks/fields"
|
|
15
16
|
import { plainText } from "tess_edit/blocks/text"
|
|
16
17
|
import { newTable } from "tess_edit/core/table"
|
|
17
|
-
import { tableHtml } from "tess_edit/export/table"
|
|
18
18
|
|
|
19
19
|
const tableActions = { key: "data", label: "", type: "table" }
|
|
20
20
|
|
|
@@ -23,7 +23,7 @@ export const table = {
|
|
|
23
23
|
name: "Table",
|
|
24
24
|
icon: '<rect x="3" y="5" width="18" height="14" rx="1"/><path d="M3 10h18M3 15h18M9 10v9M15 10v9"/>',
|
|
25
25
|
category: "layout",
|
|
26
|
-
// Content, as Text is
|
|
26
|
+
// Content, as Text is
|
|
27
27
|
roles: ["content"],
|
|
28
28
|
accepts: ["row"],
|
|
29
29
|
defaults: () => ({ attributes: { padding: "10px 25px" }, data: { columns: [], borderColor: "#d1d5db", borderWidth: "1px", cellPadding: "6px 8px", headingBackground: "#f3f4f6" } }),
|
|
@@ -50,10 +50,7 @@ export const table = {
|
|
|
50
50
|
]
|
|
51
51
|
}
|
|
52
52
|
],
|
|
53
|
-
hint: "Rows of cells. Select a cell to add rows and columns. Put rows in a Loop to repeat them for each item."
|
|
54
|
-
render: {
|
|
55
|
-
mjml: (node, ctx) => ctx.element("mj-table", node, tableHtml(node, ctx))
|
|
56
|
-
}
|
|
53
|
+
hint: "Rows of cells. Select a cell to add rows and columns. Put rows in a Loop to repeat them for each item."
|
|
57
54
|
}
|
|
58
55
|
|
|
59
56
|
export const tableRow = {
|
|
@@ -76,9 +73,7 @@ export const tableRow = {
|
|
|
76
73
|
]
|
|
77
74
|
}
|
|
78
75
|
],
|
|
79
|
-
label: (node) => (node.data.heading ? "Heading row" : "Row")
|
|
80
|
-
// In its table's (export/table.js)
|
|
81
|
-
render: { mjml: () => "" }
|
|
76
|
+
label: (node) => (node.data.heading ? "Heading row" : "Row")
|
|
82
77
|
}
|
|
83
78
|
|
|
84
79
|
export const tableCell = {
|
|
@@ -106,7 +101,5 @@ export const tableCell = {
|
|
|
106
101
|
label(node) {
|
|
107
102
|
const text = (node.children || []).map((child) => plainText(child.data?.content)).join(" ").trim()
|
|
108
103
|
return text ? `Cell · ${text.slice(0, 32)}` : "Cell"
|
|
109
|
-
}
|
|
110
|
-
// In its table's (export/table.js)
|
|
111
|
-
render: { mjml: () => "" }
|
|
104
|
+
}
|
|
112
105
|
}
|
|
@@ -34,8 +34,5 @@ export default {
|
|
|
34
34
|
category: "content",
|
|
35
35
|
create: ({ createNode }) => createNode("text", { attributes: { "font-size": "24px", "font-weight": "700", "line-height": "1.3" }, data: { content: doc("Heading") } })
|
|
36
36
|
}
|
|
37
|
-
]
|
|
38
|
-
render: {
|
|
39
|
-
mjml: (node, { element, richText }) => element("mj-text", node, richText(node.data.content))
|
|
40
|
-
}
|
|
37
|
+
]
|
|
41
38
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// <div data-controller="tess-edit"> … </div>
|
|
2
2
|
//
|
|
3
3
|
// Values:
|
|
4
|
-
// kit what the editor makes:
|
|
5
|
-
//
|
|
4
|
+
// kit what the editor makes: the key of a kit the host registered
|
|
5
|
+
// (see core/registry.js); may be left out when there is one
|
|
6
6
|
// document JSON of the document to load (falls back to the json input, then a sample)
|
|
7
7
|
// sample load the sample document when there is nothing else (default true)
|
|
8
8
|
// frame a border with rounded corners around the editor (default true); a
|
|
@@ -15,8 +15,9 @@
|
|
|
15
15
|
// below the canvas, shown and hidden from the top bar and opened
|
|
16
16
|
// by a tap on a block. A kit without blocks (blocks: false) has
|
|
17
17
|
// Inspect on the right only, or in the sheet.
|
|
18
|
-
// compileUrl the
|
|
19
|
-
// /tess_edit/compile, the engine mounted at
|
|
18
|
+
// compileUrl the engine's compile endpoint, for a kit that compiles on the
|
|
19
|
+
// server (default /tess_edit/compile, the engine mounted at
|
|
20
|
+
// /tess_edit, see export/compile.js)
|
|
20
21
|
// mediaUrl the host's images, chosen and uploaded in Image blocks (see
|
|
21
22
|
// core/media.js); without it images only have a URL
|
|
22
23
|
// variablesUrl the variables a template can use, suggested while typing {{
|
|
@@ -44,23 +45,24 @@
|
|
|
44
45
|
// editor.options, e.g. the choices of a select field
|
|
45
46
|
// (options: (editor) => editor.options.parties)
|
|
46
47
|
// Targets (all optional, usually hidden inputs in a form):
|
|
47
|
-
// jsonInput,
|
|
48
|
-
// the kit's outputs
|
|
48
|
+
// jsonInput, htmlInput, … kept up to date with every change: the JSON and
|
|
49
|
+
// the kit's outputs, an <output>Input target for each
|
|
50
|
+
// (e.g. mjmlInput for an email's mjml)
|
|
49
51
|
// slot an element of the host's, named by data-tess-edit-slot,
|
|
50
52
|
// that a "slot" field shows in Inspect (see ui/inspector.js)
|
|
51
53
|
// translations a <script type="application/json"> with the editor's words
|
|
52
54
|
// in the page's language (see core/i18n.js)
|
|
53
55
|
// Events:
|
|
54
|
-
// tess-edit:change detail: { json, ...the kit's outputs, errors, document }
|
|
55
|
-
//
|
|
56
|
-
//
|
|
56
|
+
// tess-edit:change detail: { json, ...the kit's outputs, errors, document },
|
|
57
|
+
// e.g. { json, html, errors, document }, with errors saying
|
|
58
|
+
// why an output could not be made
|
|
57
59
|
|
|
58
60
|
import { Controller } from "@hotwired/stimulus"
|
|
59
61
|
import { accepted, ancestors, createDocument, createFromPalette, duplicate, find, findType, getValue, insert, itemType, misfit, move, normalize, remove, setValue, walk } from "tess_edit/core/document"
|
|
60
62
|
import { History } from "tess_edit/core/history"
|
|
61
63
|
import { setTranslations, t } from "tess_edit/core/i18n"
|
|
62
64
|
import { canEditField, canFill, isFree, parseLock } from "tess_edit/core/lock"
|
|
63
|
-
import {
|
|
65
|
+
import { getBlock, getKit, kits, inlinePart, inlineParts, paletteItems, paletteSources } from "tess_edit/core/registry"
|
|
64
66
|
import { COMPILE_URL } from "tess_edit/export/compile"
|
|
65
67
|
import { IMAGE_FIELD, fetchMedia, uploadMedia } from "tess_edit/core/media"
|
|
66
68
|
import { Translations, keysIn, suggestKey, toTranslation, translationTag } from "tess_edit/core/translations"
|
|
@@ -99,15 +101,17 @@ function placed(node, at) {
|
|
|
99
101
|
}
|
|
100
102
|
|
|
101
103
|
export default class extends Controller {
|
|
102
|
-
static values = { kit:
|
|
103
|
-
static targets = ["jsonInput", "
|
|
104
|
+
static values = { kit: String, document: String, sample: { type: Boolean, default: true }, frame: { type: Boolean, default: true }, panels: { type: String, default: "split" }, compileUrl: { type: String, default: COMPILE_URL }, mediaUrl: String, variablesUrl: String, filtersUrl: String, tagsUrl: String, translationsUrl: String, values: String, lock: String, blocks: String, options: String }
|
|
105
|
+
static targets = ["jsonInput", "slot", "translations"]
|
|
104
106
|
|
|
105
107
|
connect() {
|
|
106
108
|
if (this.hasTranslationsTarget) setTranslations(this.parseJson(this.translationsTarget.textContent, "translations"))
|
|
107
|
-
|
|
109
|
+
// Without a kit, the one the host registered
|
|
110
|
+
this.kit = this.kitValue ? getKit(this.kitValue) : kits().length === 1 ? kits()[0] : null
|
|
108
111
|
if (!this.kit) {
|
|
109
|
-
|
|
110
|
-
this.
|
|
112
|
+
const problem = this.kitValue ? `there is no kit ${this.kitValue}` : kits().length ? "say which kit with data-tess-edit-kit-value" : "no kit is registered"
|
|
113
|
+
this.element.textContent = `TessEdit: ${problem} (see registerKit)`
|
|
114
|
+
throw new Error(`TessEdit: ${problem}`)
|
|
111
115
|
}
|
|
112
116
|
this.lock = parseLock(this.lockValue)
|
|
113
117
|
this.allowedTypes = this.parseJson(this.blocksValue, "blocks")
|
|
@@ -361,7 +365,7 @@ export default class extends Controller {
|
|
|
361
365
|
console.error("TessEdit: could not load the document", error)
|
|
362
366
|
}
|
|
363
367
|
}
|
|
364
|
-
return this.sampleValue ? this.kit.starter() : createDocument(this.kit.key)
|
|
368
|
+
return this.sampleValue && this.kit.starter ? this.kit.starter() : createDocument(this.kit.key)
|
|
365
369
|
}
|
|
366
370
|
|
|
367
371
|
// --- public API -------------------------------------------------------------
|
|
@@ -383,7 +387,7 @@ export default class extends Controller {
|
|
|
383
387
|
this.renderAll()
|
|
384
388
|
}
|
|
385
389
|
|
|
386
|
-
// The JSON and the kit's outputs, e.g. { json,
|
|
390
|
+
// The JSON and the kit's outputs, e.g. { json, html, errors }
|
|
387
391
|
async export() {
|
|
388
392
|
const { outputs, errors } = await this.kit.outputs(this.doc, { compileUrl: this.compileUrlValue })
|
|
389
393
|
return { json: JSON.stringify(this.doc), ...outputs, errors }
|
|
@@ -713,8 +717,8 @@ export default class extends Controller {
|
|
|
713
717
|
|
|
714
718
|
// --- rendering --------------------------------------------------------------
|
|
715
719
|
|
|
716
|
-
// Runs one of the kit's renderings, which may go to the server (
|
|
717
|
-
//
|
|
720
|
+
// Runs one of the kit's renderings, which may go to the server (a kit that
|
|
721
|
+
// compiles there). A newer run on the same channel aborts the older one, which
|
|
718
722
|
// then resolves to null.
|
|
719
723
|
async run(channel, render) {
|
|
720
724
|
this.requests[channel]?.abort()
|
|
@@ -759,6 +763,13 @@ export default class extends Controller {
|
|
|
759
763
|
}))
|
|
760
764
|
}
|
|
761
765
|
|
|
766
|
+
// The input of an output (jsonInput, htmlInput, …): a target named after
|
|
767
|
+
// it, which isn't declared, as a kit has outputs of its own
|
|
768
|
+
outputInput(name) {
|
|
769
|
+
const target = `${name}Input`
|
|
770
|
+
return [...this.element.querySelectorAll(`[data-${this.identifier}-target]`)].find((element) => element.getAttribute(`data-${this.identifier}-target`).split(/\s+/).includes(target))
|
|
771
|
+
}
|
|
772
|
+
|
|
762
773
|
writeOutputs() {
|
|
763
774
|
const writing = (this.writing = this.write().finally(() => {
|
|
764
775
|
if (this.writing === writing) this.writing = null
|
|
@@ -773,7 +784,8 @@ export default class extends Controller {
|
|
|
773
784
|
if (!result) return
|
|
774
785
|
const outputs = { json, ...result.outputs }
|
|
775
786
|
for (const [name, value] of Object.entries(outputs)) {
|
|
776
|
-
|
|
787
|
+
const input = this.outputInput(name)
|
|
788
|
+
if (input) input.value = value
|
|
777
789
|
}
|
|
778
790
|
this.dispatch("change", { detail: { ...outputs, errors: result.errors, document: this.doc } })
|
|
779
791
|
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
// The document is a plain JSON tree:
|
|
2
2
|
// { id, type, attributes: {}, data: {}, children: [] }
|
|
3
|
-
// `attributes` hold a block's styling, named after
|
|
4
|
-
//
|
|
3
|
+
// `attributes` hold a block's styling, named after CSS properties and
|
|
4
|
+
// MJML's attributes (each kit maps them onto its own output), `data` holds everything else
|
|
5
5
|
// (rich text, Liquid expressions, link lists). A block copied from elsewhere,
|
|
6
6
|
// such as a host's reusable content, may also have `origin`: the id of the
|
|
7
7
|
// block it is a copy of (see renumber). All functions here are pure apart
|
|
8
8
|
// from the mutating helpers, which change the tree they are given in place.
|
|
9
9
|
|
|
10
|
-
import {
|
|
10
|
+
import { getBlock, getKit, kitOf, paletteItem, typesForRoles } from "tess_edit/core/registry"
|
|
11
11
|
|
|
12
12
|
export const VERSION = 1
|
|
13
13
|
|
|
@@ -33,8 +33,8 @@ export function createNode(type, overrides = {}) {
|
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
// An empty document of a kit (see core/registry.js)
|
|
37
|
-
export function createDocument(kit
|
|
36
|
+
// An empty document of a kit (see core/registry.js)
|
|
37
|
+
export function createDocument(kit) {
|
|
38
38
|
const definition = getKit(kit)
|
|
39
39
|
if (!definition) throw new Error(`Unknown kit: ${kit}`)
|
|
40
40
|
return { version: VERSION, ...createNode(definition.root) }
|
|
@@ -178,7 +178,7 @@ export function duplicate(doc, id) {
|
|
|
178
178
|
// Sets a value on a node. `key` is "attributes.padding" or "data.subject",
|
|
179
179
|
// or deeper into a list, "data.options.0.label" (an inline part of each item,
|
|
180
180
|
// see `inline` in core/registry.js).
|
|
181
|
-
// An empty string removes an attribute, so
|
|
181
|
+
// An empty string removes an attribute, so the kit's output falls back to its default.
|
|
182
182
|
export function setValue(doc, id, key, value) {
|
|
183
183
|
const hit = find(doc, id)
|
|
184
184
|
if (!hit) return
|
|
@@ -203,10 +203,10 @@ export function getValue(node, key) {
|
|
|
203
203
|
// `kit`, the document has to be one of that kit's.
|
|
204
204
|
export function normalize(input, { kit } = {}) {
|
|
205
205
|
const doc = typeof input === "string" ? JSON.parse(input) : clone(input)
|
|
206
|
-
// The email's root block was called "page", then "root"; such documents still load.
|
|
207
|
-
if (doc?.type === "page" || doc?.type === "root") doc.type = "email"
|
|
208
206
|
const own = kitOf(doc)
|
|
209
207
|
if (!own) throw new Error("Not a TessEdit document: the top node must be a root block")
|
|
208
|
+
// A root type the kit had before (its aliases) loads as its root
|
|
209
|
+
doc.type = own.root
|
|
210
210
|
if (kit && own.key !== kit) throw new Error(`This is a document for the ${own.name} editor, not the ${getKit(kit)?.name || kit} one`)
|
|
211
211
|
walk(doc, (node) => {
|
|
212
212
|
if (!getBlock(node.type)) throw new Error(`Unknown block type: ${node.type}`)
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// GET → { images: [{ id, url, name }] }
|
|
4
4
|
// POST multipart/form-data, "file" → { id, url, name }, or { errors: [...] }
|
|
5
5
|
//
|
|
6
|
-
// `id` is the host's own reference to the image, `url` is where the
|
|
6
|
+
// `id` is the host's own reference to the image, `url` is where the document
|
|
7
7
|
// loads it from. An image field (type "image") stores both: the URL in its
|
|
8
8
|
// key, the id and where the image comes from in its `image` and `source` keys.
|
|
9
9
|
|
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
// // editor, so the rest of the block stays as it is. A plain part
|
|
24
24
|
// // is one line of text, a string; the others are Tiptap JSON
|
|
25
25
|
// palette: [{ key, label, icon, category, create: ({ createNode }) => node }], // optional
|
|
26
|
-
// kits: ["
|
|
27
|
-
// //
|
|
26
|
+
// kits: ["note"], // the kits it is part of, default none: a kit takes it
|
|
27
|
+
// // in with extendBlock, and its render hook
|
|
28
28
|
// unique: true, // optional: at most one per document, like Content
|
|
29
29
|
// layout: "free", // optional, on a container: its children are placed by
|
|
30
30
|
// // data.x and data.y, dragged on the canvas (ui/free_layout.js)
|
|
@@ -33,13 +33,14 @@
|
|
|
33
33
|
// resizeChildren: { width: "data.width" },
|
|
34
34
|
// // optional, on a free container: the same for all of its children,
|
|
35
35
|
// // or a function of the child; unit: "mm" keeps sizes as "52mm"
|
|
36
|
-
// render: {
|
|
37
|
-
// //
|
|
36
|
+
// render: { note: (node, ctx) => "<div …>" } // one per kit it is part of, named after
|
|
37
|
+
// // the kit's key (or what its kit's renderer calls)
|
|
38
38
|
// })
|
|
39
39
|
//
|
|
40
|
-
// Roles: "body" (inside
|
|
41
|
-
// "column" (inside a section), "content" (inside a column or
|
|
42
|
-
//
|
|
40
|
+
// Roles: "body" (inside a kit's root, or an email's wrapper: sections),
|
|
41
|
+
// "column" (inside a section), "content" (inside a column, or wherever a
|
|
42
|
+
// kit's own containers take it), and "row" (inside a table) and "cell"
|
|
43
|
+
// (inside a row), see blocks/table.js. A
|
|
43
44
|
// container accepts the roles in its `accepts`; Loop and Condition use
|
|
44
45
|
// "inherit" and accept what their nearest other container accepts.
|
|
45
46
|
//
|
|
@@ -54,7 +55,9 @@
|
|
|
54
55
|
// key: "note", // data-tess-edit-kit-value; blocks name it in `kits`
|
|
55
56
|
// name: "Note", // shown in the top bar
|
|
56
57
|
// root: "note", // the type of its root block, unique to the kit
|
|
57
|
-
//
|
|
58
|
+
// aliases: ["page"], // optional: root types its documents had before,
|
|
59
|
+
// // loaded as the kit's root
|
|
60
|
+
// starter: () => doc, // optional: the sample document
|
|
58
61
|
// devices: [{ key, icon, title, width }], // optional: canvas widths in the top bar
|
|
59
62
|
// previewTitle: "…", // the Preview button's title
|
|
60
63
|
// canvas: async (doc, { editor, compileUrl, signal, options, element }) => ({ html, errors }),
|
|
@@ -66,15 +69,17 @@
|
|
|
66
69
|
// outputs: async (doc, { compileUrl, signal, options, element }) => ({ outputs: { html: "…" }, errors }),
|
|
67
70
|
// // what the editor stores besides the JSON (the inputs,
|
|
68
71
|
// // the change event and the Code dialog); null when aborted
|
|
72
|
+
// palette: ["text", "heading"], // optional: the order of the Blocks panel's tiles,
|
|
73
|
+
// // by key; tiles it leaves out follow in registration order
|
|
69
74
|
// blocks: false, // optional: a kit of its root alone, such as a text
|
|
70
75
|
// // message, has no Blocks and Layers panels
|
|
71
76
|
// notes: { html: "…" }, // optional: what each output is, in the Code dialog
|
|
72
|
-
// errors: "The
|
|
77
|
+
// errors: "The note could not be rendered" // shown before the reasons
|
|
73
78
|
// })
|
|
74
79
|
//
|
|
75
|
-
//
|
|
76
|
-
//
|
|
77
|
-
//
|
|
80
|
+
// TessEdit has no kit of its own: a host (or a gem, such as Nuntius with its
|
|
81
|
+
// email) registers one with its root block and blocks, and brings TessEdit's
|
|
82
|
+
// blocks into it with extendBlock:
|
|
78
83
|
//
|
|
79
84
|
// extendBlock("text", { kits: ["note"], render: { note: (node, ctx) => "<div>…</div>" } })
|
|
80
85
|
//
|
|
@@ -84,7 +89,6 @@
|
|
|
84
89
|
|
|
85
90
|
import { builtinBlocks, builtinCategories } from "tess_edit/blocks/builtin"
|
|
86
91
|
import { t } from "tess_edit/core/i18n"
|
|
87
|
-
import { builtinKits } from "tess_edit/kits/builtin"
|
|
88
92
|
|
|
89
93
|
const definitions = new Map()
|
|
90
94
|
const categoryList = new Map()
|
|
@@ -92,8 +96,6 @@ const kitList = new Map()
|
|
|
92
96
|
const sourceList = new Map()
|
|
93
97
|
const fieldTypeList = new Map()
|
|
94
98
|
|
|
95
|
-
export const DEFAULT_KIT = "email"
|
|
96
|
-
|
|
97
99
|
// What the editor says when a kit's canvas can't be rendered, unless the kit says it itself (errors)
|
|
98
100
|
export const KIT_ERRORS = "The %{name} could not be rendered"
|
|
99
101
|
|
|
@@ -102,11 +104,11 @@ export function registerKit(kit) {
|
|
|
102
104
|
if (!key || !name) throw new Error("A kit needs a key and a name")
|
|
103
105
|
if (!root) throw new Error(`Kit ${key} needs a root block type`)
|
|
104
106
|
if (typeof canvas !== "function" || typeof outputs !== "function") throw new Error(`Kit ${key} needs canvas(doc, options) and outputs(doc, options)`)
|
|
105
|
-
kitList.set(key, { devices: null, notes: {}, errors: KIT_ERRORS, ...kit })
|
|
107
|
+
kitList.set(key, { devices: null, notes: {}, errors: KIT_ERRORS, aliases: [], ...kit })
|
|
106
108
|
return kitList.get(key)
|
|
107
109
|
}
|
|
108
110
|
|
|
109
|
-
export function getKit(key
|
|
111
|
+
export function getKit(key) {
|
|
110
112
|
return kitList.get(key)
|
|
111
113
|
}
|
|
112
114
|
|
|
@@ -116,7 +118,7 @@ export function kits() {
|
|
|
116
118
|
|
|
117
119
|
// The kit a document belongs to, from its root block
|
|
118
120
|
export function kitOf(doc) {
|
|
119
|
-
return kits().find((kit) => kit.root === doc?.type)
|
|
121
|
+
return kits().find((kit) => kit.root === doc?.type || kit.aliases.includes(doc?.type))
|
|
120
122
|
}
|
|
121
123
|
|
|
122
124
|
function inKit(definition, kit) {
|
|
@@ -161,8 +163,8 @@ export function registerBlock(definition) {
|
|
|
161
163
|
if (!name) throw new Error(`Block ${type} needs a name`)
|
|
162
164
|
// A block of no kit yet (kits: []), such as a Table, gets its render hook
|
|
163
165
|
// from the kit that takes it in (extendBlock)
|
|
164
|
-
const ownKits = definition.kits ?? [
|
|
165
|
-
if (ownKits.length && !Object.values(render || {}).some((hook) => typeof hook === "function")) throw new Error(`Block ${type} needs render
|
|
166
|
+
const ownKits = definition.kits ?? []
|
|
167
|
+
if (ownKits.length && !Object.values(render || {}).some((hook) => typeof hook === "function")) throw new Error(`Block ${type} needs a render hook for its kits, e.g. render.${ownKits[0]}(node, ctx)`)
|
|
166
168
|
if (!kits().some((kit) => kit.root === type) && !(definition.roles || []).length) throw new Error(`Block ${type} needs roles, e.g. ["content"]`)
|
|
167
169
|
|
|
168
170
|
const palette = (definition.palette ?? (definition.category ? [{ key: type, label: name, icon: definition.icon, category: definition.category }] : [])).map((item) => ({
|
|
@@ -174,7 +176,7 @@ export function registerBlock(definition) {
|
|
|
174
176
|
}))
|
|
175
177
|
const inline = definition.inline ?? (definition.richText ? [{ key: definition.richText }] : [])
|
|
176
178
|
if (inline.some((part) => !part?.key)) throw new Error(`Block ${type} needs a key for each inline part`)
|
|
177
|
-
definitions.set(type, { roles: [], kits: [
|
|
179
|
+
definitions.set(type, { roles: [], kits: [], render: {}, ...definition, palette, inline })
|
|
178
180
|
return definitions.get(type)
|
|
179
181
|
}
|
|
180
182
|
|
|
@@ -267,10 +269,13 @@ export function categories() {
|
|
|
267
269
|
return [...categoryList.values()].sort((a, b) => a.order - b.order)
|
|
268
270
|
}
|
|
269
271
|
|
|
270
|
-
// Tiles for the Blocks panel,
|
|
271
|
-
//
|
|
272
|
+
// Tiles for the Blocks panel, of a kit's blocks when one is given: in the
|
|
273
|
+
// order of the kit's `palette`, the others after them in registration order.
|
|
272
274
|
export function paletteItems(kit) {
|
|
273
|
-
|
|
275
|
+
const items = [...definitions.values()].filter((definition) => inKit(definition, kit)).flatMap((definition) => definition.palette)
|
|
276
|
+
const order = kitList.get(kit)?.palette || []
|
|
277
|
+
const rank = (item) => (order.includes(item.key) ? order.indexOf(item.key) : order.length)
|
|
278
|
+
return items.map((item, index) => ({ item, index })).sort((a, b) => rank(a.item) - rank(b.item) || a.index - b.index).map(({ item }) => item)
|
|
274
279
|
}
|
|
275
280
|
|
|
276
281
|
export function paletteItem(key) {
|
|
@@ -282,6 +287,5 @@ export function label(node) {
|
|
|
282
287
|
return definition?.label?.(node) || t(definition?.name) || node.type
|
|
283
288
|
}
|
|
284
289
|
|
|
285
|
-
builtinKits.forEach(registerKit)
|
|
286
290
|
builtinCategories.forEach(registerCategory)
|
|
287
291
|
builtinBlocks.forEach(registerBlock)
|
|
@@ -1,20 +1,29 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
3
|
-
//
|
|
1
|
+
// Compiling on the server, for a kit whose output the browser can't make
|
|
2
|
+
// itself, such as an email's MJML that becomes HTML. The host (or a gem)
|
|
3
|
+
// registers a compiler by name in Ruby (TessEdit.register_compiler), and the
|
|
4
|
+
// kit posts its source to the engine's compile endpoint, POST /tess_edit/compile
|
|
5
|
+
// with { compiler, source }:
|
|
4
6
|
//
|
|
5
|
-
//
|
|
7
|
+
// compile(mjml, { compiler: "mjml", url: compileUrl, signal })
|
|
8
|
+
//
|
|
9
|
+
// so the canvas shows the same HTML the host makes when it sends or saves.
|
|
10
|
+
//
|
|
11
|
+
// Resolves to { html, errors }: html is null when the source could not be
|
|
6
12
|
// compiled or the request failed, with the reasons in errors. Resolves to null
|
|
7
13
|
// when the request was aborted through options.signal.
|
|
8
14
|
|
|
15
|
+
// The engine mounted at /tess_edit; the editor's compileUrl value says
|
|
16
|
+
// otherwise, and a kit gets it as compileUrl
|
|
9
17
|
export const COMPILE_URL = "/tess_edit/compile"
|
|
10
18
|
|
|
11
|
-
export async function compile(
|
|
19
|
+
export async function compile(source, { compiler, url = COMPILE_URL, signal } = {}) {
|
|
20
|
+
if (!compiler) throw new Error("compile needs the name of a compiler")
|
|
12
21
|
const token = document.querySelector("meta[name='csrf-token']")?.content
|
|
13
22
|
try {
|
|
14
23
|
const response = await fetch(url, {
|
|
15
24
|
method: "POST",
|
|
16
25
|
headers: { "Content-Type": "application/json", Accept: "application/json", ...(token ? { "X-CSRF-Token": token } : {}) },
|
|
17
|
-
body: JSON.stringify({
|
|
26
|
+
body: JSON.stringify({ compiler, source }),
|
|
18
27
|
credentials: "same-origin",
|
|
19
28
|
signal
|
|
20
29
|
})
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Turns Tiptap/ProseMirror JSON into
|
|
1
|
+
// Turns Tiptap/ProseMirror JSON into HTML with inline styles, as emails need. Liquid ({{ … }} and
|
|
2
2
|
// {% … %}) is copied verbatim so quotes and comparison operators keep working.
|
|
3
3
|
|
|
4
4
|
const LIQUID = /(\{\{[\s\S]*?\}\}|\{%[\s\S]*?%\})/g
|
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
// A table (blocks/table.js) as HTML, for a kit whose tables are HTML
|
|
2
|
-
// email's mj-table, which MJML copies as it is, so a cell's blocks are
|
|
3
|
-
// too
|
|
4
|
-
//
|
|
1
|
+
// A table (blocks/table.js) as HTML, for a kit whose tables are HTML, such
|
|
2
|
+
// as an email's mj-table, which MJML copies as it is, so a cell's blocks are
|
|
3
|
+
// HTML too. Its styles are inline, as mail clients need: borders, padding
|
|
4
|
+
// and heading rows on each cell.
|
|
5
5
|
//
|
|
6
|
-
// tableHtml(node, { editor, richText, escapeText, escapeAttribute })
|
|
6
|
+
// tableHtml(node, { editor, richText, escapeText, escapeAttribute, cellBlock })
|
|
7
7
|
// // → "<colgroup>…</colgroup><thead>…</thead><tbody>…</tbody>"
|
|
8
8
|
//
|
|
9
9
|
// A cell's blocks are rendered here (cellBlock): Text, Image, Button,
|
|
10
|
-
// Divider, Spacer, Loop, Condition, Assign and tables
|
|
10
|
+
// Divider, Spacer, Loop, Condition, Assign and tables. The kit's own blocks
|
|
11
|
+
// go through its cellBlock(node, ctx), if it gives one; without it they show
|
|
12
|
+
// nothing.
|
|
11
13
|
// With editor, every element has its tess-<id> class, an empty container a
|
|
12
14
|
// placeholder that fits there, and Liquid tags are left out, so a Loop's
|
|
13
15
|
// rows show once.
|
|
@@ -157,6 +159,6 @@ export function cellBlock(node, ctx) {
|
|
|
157
159
|
return ctx.editor ? children() : `${open}${children()}${close}`
|
|
158
160
|
}
|
|
159
161
|
default:
|
|
160
|
-
return ""
|
|
162
|
+
return ctx.cellBlock?.(node, { ...ctx, style, classes: (block) => classes(block, ctx) }) || ""
|
|
161
163
|
}
|
|
162
164
|
}
|
|
@@ -7,15 +7,14 @@
|
|
|
7
7
|
import EditorController from "tess_edit/controllers/editor_controller"
|
|
8
8
|
|
|
9
9
|
export { EditorController }
|
|
10
|
-
export {
|
|
11
|
-
export { compile } from "tess_edit/export/compile"
|
|
10
|
+
export { COMPILE_URL, compile } from "tess_edit/export/compile"
|
|
12
11
|
export { escapeAttribute, escapeText, richTextToHtml } from "tess_edit/export/richtext"
|
|
12
|
+
export { tableHtml } from "tess_edit/export/table"
|
|
13
13
|
export { contentNode, createDocument, createNode, findType, normalize, renumber, withContent } from "tess_edit/core/document"
|
|
14
14
|
export { CONTENT_END, CONTENT_START } from "tess_edit/blocks/content"
|
|
15
15
|
export { registerBlock, registerCategory, registerFieldType, registerKit, registerPaletteSource, extendBlock, getBlock, getKit, kitOf, kits, blockTypes, paletteItems, paletteSources } from "tess_edit/core/registry"
|
|
16
16
|
export * as fields from "tess_edit/blocks/fields"
|
|
17
17
|
export { imageField } from "tess_edit/core/media"
|
|
18
|
-
export { starterDocument } from "tess_edit/core/starter"
|
|
19
18
|
export { cellOf, tableOf } from "tess_edit/core/table"
|
|
20
19
|
|
|
21
20
|
export function registerTessEdit(application, identifier = "tess-edit") {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
// The editing canvas: an iframe showing the
|
|
1
|
+
// The editing canvas: an iframe showing the kit's canvas HTML, with an overlay for
|
|
2
2
|
// hover and selection outlines, block tools, plus buttons and drop indicators.
|
|
3
3
|
// Elements are mapped back to blocks through the "tess-<id>" classes that the
|
|
4
|
-
//
|
|
4
|
+
// kit puts on every block's element in the editor. With the host's translations, t
|
|
5
5
|
// filters show their text in the editor's language, and with its values
|
|
6
6
|
// other Liquid output shows its value (see annotate).
|
|
7
7
|
|
|
@@ -148,7 +148,7 @@ export class Canvas {
|
|
|
148
148
|
|
|
149
149
|
// --- translations and values -----------------------------------------------
|
|
150
150
|
|
|
151
|
-
// Wraps every t filter in the
|
|
151
|
+
// Wraps every t filter in the canvas's text in a span that shows its text
|
|
152
152
|
// (showTranslations), and with the host's values every other output tag in
|
|
153
153
|
// one that shows its value (showValues), keeping the Liquid for when there's
|
|
154
154
|
// none. Again when the values change: what's wrapped stays as it is.
|
|
@@ -580,8 +580,8 @@ export class Canvas {
|
|
|
580
580
|
}
|
|
581
581
|
|
|
582
582
|
// An image file dragged from the desktop onto a block with an image field
|
|
583
|
-
// uploads it there: an Image block's image, or the background of the
|
|
584
|
-
// section or
|
|
583
|
+
// uploads it there: an Image block's image, or the background of the
|
|
584
|
+
// section (or other block with an image field) the pointer is in. Elsewhere the drop is refused, so
|
|
585
585
|
// the browser doesn't open the file.
|
|
586
586
|
onFileDragOver(event) {
|
|
587
587
|
event.preventDefault()
|