tess_edit 0.5.9 → 0.5.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +2 -1
- data/app/javascript/tess_edit/blocks/assign.js +33 -0
- data/app/javascript/tess_edit/blocks/builtin.js +3 -1
- data/app/javascript/tess_edit/blocks/condition.js +2 -1
- data/app/javascript/tess_edit/blocks/loop.js +2 -1
- data/app/javascript/tess_edit/blocks/table.js +112 -0
- data/app/javascript/tess_edit/controllers/editor_controller.js +88 -14
- data/app/javascript/tess_edit/core/registry.js +15 -8
- data/app/javascript/tess_edit/core/table.js +262 -0
- data/app/javascript/tess_edit/core/values.js +20 -5
- data/app/javascript/tess_edit/export/table.js +162 -0
- data/app/javascript/tess_edit/index.js +1 -0
- data/app/javascript/tess_edit/ui/canvas.js +130 -7
- data/app/javascript/tess_edit/ui/inspector.js +64 -1
- data/app/javascript/tess_edit/ui/text_editing.js +3 -1
- data/config/locales/en.yml +47 -0
- data/config/locales/nl.yml +47 -0
- data/lib/tess_edit/version.rb +1 -1
- metadata +5 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ca98a5df42d18e55649fb75c9e3df79e3b4625f76114f362872ed8340bfdee37
|
|
4
|
+
data.tar.gz: 25023d749d04c4ddd1e508131354632bcfa5165d9ca0a2166929a9a408ea9728
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 618cd69b5a1c90e4ca7d8d17882f8e73148eb753d2d3e6bce78e6418f3ff9ec0b4037280f1150bec51a3a16e0f174fa1133221ec06cd7603fe677e7618144baf
|
|
7
|
+
data.tar.gz: '0028d406120c409203369393781af3eef1e9863f13b46c43a36168850b9a145b11af3d1e81cb83a2462e2a0a2229d4b4c8d77773572d6c6ff9d365a8cad99e07'
|
data/README.md
CHANGED
|
@@ -15,13 +15,14 @@ It completes Liquid tags and variables as you type, making it easier to work wit
|
|
|
15
15
|
|
|
16
16
|
- Blocks: Section (1-4 columns), Column, Wrapper, Hero, Text, Heading, Image, Button, Divider, Spacer, Social, Navbar and raw HTML.
|
|
17
17
|
- Liquid blocks: **Loop** (`{% for line in order.lines %}`) and **Condition** (`{% if order.total > 100 %}`) wrap other blocks.
|
|
18
|
+
- **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.
|
|
18
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.
|
|
19
20
|
- 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.
|
|
20
21
|
- 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
22
|
- 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.
|
|
22
23
|
- 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.
|
|
23
24
|
- 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.
|
|
24
|
-
- Undo/redo, duplicate, delete, keyboard shortcuts (⌘Z, ⇧⌘Z, ⌘D, Delete, Enter to edit text, Esc).
|
|
25
|
+
- Undo/redo, duplicate, delete, keyboard shortcuts (⌘Z, ⇧⌘Z, ⌘D, Delete, Enter to edit text, Tab to the next table cell, Esc).
|
|
25
26
|
- Desktop and mobile preview, and a preview of the HTML as sent.
|
|
26
27
|
- Panels on both sides, or combined as tabs in one sidebar on the left or right to give the canvas more room.
|
|
27
28
|
- Dark mode that follows the host app's.
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// {% assign variable = expression %}: a Liquid variable for the blocks after
|
|
2
|
+
// it, such as a collection filtered before a Loop goes over it (Liquid's for
|
|
3
|
+
// and if take no filters):
|
|
4
|
+
//
|
|
5
|
+
// {% assign lines = contract.lines | where: "party", "account" %}
|
|
6
|
+
//
|
|
7
|
+
// It shows nothing; in the editor, Layers shows it. In a table it goes
|
|
8
|
+
// between rows.
|
|
9
|
+
|
|
10
|
+
const assignTag = (node) => `{% assign ${node.data.variable || "value"} = ${node.data.expression || "nil"} %}`
|
|
11
|
+
|
|
12
|
+
export default {
|
|
13
|
+
type: "assign",
|
|
14
|
+
name: "Assign",
|
|
15
|
+
icon: '<path d="M5 9h6M5 15h6"/><path d="M14 7l5 5-5 5"/>',
|
|
16
|
+
category: "liquid",
|
|
17
|
+
roles: ["body", "content", "row"],
|
|
18
|
+
defaults: () => ({ data: { variable: "items", expression: "" } }),
|
|
19
|
+
fields: [
|
|
20
|
+
{
|
|
21
|
+
title: "Assign",
|
|
22
|
+
fields: [
|
|
23
|
+
{ key: "data.variable", label: "Variable", type: "text", hint: "The name the blocks after it use, e.g. lines." },
|
|
24
|
+
{ key: "data.expression", label: "Value", type: "text", liquid: "expression", hint: "A Liquid expression, with filters, e.g. order.lines | where: \"kind\", \"product\"." }
|
|
25
|
+
]
|
|
26
|
+
}
|
|
27
|
+
],
|
|
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
|
+
}
|
|
33
|
+
}
|
|
@@ -17,6 +17,8 @@ import navbar from "tess_edit/blocks/navbar"
|
|
|
17
17
|
import raw from "tess_edit/blocks/raw"
|
|
18
18
|
import loop from "tess_edit/blocks/loop"
|
|
19
19
|
import condition from "tess_edit/blocks/condition"
|
|
20
|
+
import assign from "tess_edit/blocks/assign"
|
|
21
|
+
import { table, tableCell, tableRow } from "tess_edit/blocks/table"
|
|
20
22
|
|
|
21
23
|
export const builtinCategories = [
|
|
22
24
|
{ key: "layout", label: "Layout", order: 10 },
|
|
@@ -24,4 +26,4 @@ export const builtinCategories = [
|
|
|
24
26
|
{ key: "liquid", label: "Liquid", order: 30 }
|
|
25
27
|
]
|
|
26
28
|
|
|
27
|
-
export const builtinBlocks = [email, section, column, wrapper, hero, content, text, image, button, divider, spacer, social, navbar, raw, loop, condition]
|
|
29
|
+
export const builtinBlocks = [email, section, column, wrapper, hero, content, text, image, button, divider, spacer, social, navbar, raw, loop, condition, assign, table, tableRow, tableCell]
|
|
@@ -5,7 +5,8 @@ export default {
|
|
|
5
5
|
name: "Condition",
|
|
6
6
|
icon: "condition",
|
|
7
7
|
category: "liquid",
|
|
8
|
-
|
|
8
|
+
// "row": between a table's rows (blocks/table.js)
|
|
9
|
+
roles: ["body", "content", "row"],
|
|
9
10
|
accepts: "inherit",
|
|
10
11
|
defaults: () => ({ data: { expression: "customer.vip" } }),
|
|
11
12
|
fields: [{ title: "Condition", fields: [{ key: "data.expression", label: "Show when", type: "text", liquid: "expression", hint: "A Liquid condition, e.g. order.total > 100." }] }],
|
|
@@ -5,7 +5,8 @@ export default {
|
|
|
5
5
|
name: "Loop",
|
|
6
6
|
icon: "loop",
|
|
7
7
|
category: "liquid",
|
|
8
|
-
|
|
8
|
+
// "row": between a table's rows (blocks/table.js)
|
|
9
|
+
roles: ["body", "content", "row"],
|
|
9
10
|
accepts: "inherit",
|
|
10
11
|
defaults: () => ({ data: { variable: "item", collection: "items" } }),
|
|
11
12
|
fields: [
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
// A table: Table › Row › Cell › content, as Section › Column › content, so
|
|
2
|
+
// a cell holds any block (Text, Image, …). Rows can be in a Loop or a
|
|
3
|
+
// Condition in the table, which take rows there ("inherit"): a Loop around a
|
|
4
|
+
// Row prints it for each item, with the item's values in its cells.
|
|
5
|
+
//
|
|
6
|
+
// The table's columns are data.columns ({ width, align } each), set from a
|
|
7
|
+
// selected cell, whose Table group also adds and deletes rows and columns
|
|
8
|
+
// (core/table.js, the "table" field in ui/inspector.js).
|
|
9
|
+
//
|
|
10
|
+
// In an email the table is an mj-table, which MJML copies as it is, so its
|
|
11
|
+
// cells' blocks are HTML (export/table.js), not MJML. Another kit takes them
|
|
12
|
+
// in with extendBlock and its own render hook, as a host's PDF kit does.
|
|
13
|
+
|
|
14
|
+
import { ALIGN, VERTICAL_ALIGN, background, padding } from "tess_edit/blocks/fields"
|
|
15
|
+
import { plainText } from "tess_edit/blocks/text"
|
|
16
|
+
import { newTable } from "tess_edit/core/table"
|
|
17
|
+
import { tableHtml } from "tess_edit/export/table"
|
|
18
|
+
|
|
19
|
+
const tableActions = { key: "data", label: "", type: "table" }
|
|
20
|
+
|
|
21
|
+
export const table = {
|
|
22
|
+
type: "table",
|
|
23
|
+
name: "Table",
|
|
24
|
+
icon: '<rect x="3" y="5" width="18" height="14" rx="1"/><path d="M3 10h18M3 15h18M9 10v9M15 10v9"/>',
|
|
25
|
+
category: "layout",
|
|
26
|
+
// Content, as Text is: in an email inside a column, as an mj-table must be
|
|
27
|
+
roles: ["content"],
|
|
28
|
+
accepts: ["row"],
|
|
29
|
+
defaults: () => ({ attributes: { padding: "10px 25px" }, data: { columns: [], borderColor: "#d1d5db", borderWidth: "1px", cellPadding: "6px 8px", headingBackground: "#f3f4f6" } }),
|
|
30
|
+
palette: [{ key: "table", label: "Table", category: "layout", create: () => newTable(3, 3, { headings: ["Heading", "Heading", "Heading"] }) }],
|
|
31
|
+
fields: [
|
|
32
|
+
{
|
|
33
|
+
title: "Table",
|
|
34
|
+
fields: [
|
|
35
|
+
{ key: "attributes.width", label: "Width", type: "size", placeholder: "100%" },
|
|
36
|
+
{ key: "data.borders", label: "Lines", type: "segmented", options: [{ value: "", label: "All" }, { value: "rows", label: "Between rows" }], hint: "Lines around every cell, or only under each row." },
|
|
37
|
+
{ key: "data.borderColor", label: "Border color", type: "color" },
|
|
38
|
+
{ key: "data.borderWidth", label: "Border width", type: "size", placeholder: "1px", hint: "0 for no borders." },
|
|
39
|
+
{ key: "data.cellPadding", label: "Cell padding", type: "spacing" },
|
|
40
|
+
{ key: "data.stripe", label: "Every other row", type: "color", hint: "A background for every other row, from the second." },
|
|
41
|
+
padding
|
|
42
|
+
]
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
title: "Heading rows",
|
|
46
|
+
fields: [
|
|
47
|
+
{ key: "data.headingBackground", label: "Background", type: "color" },
|
|
48
|
+
{ key: "data.headingColor", label: "Text color", type: "color" },
|
|
49
|
+
{ key: "data.headingWeight", label: "Font weight", type: "select", options: ["", "400", "500", "600", "700"] }
|
|
50
|
+
]
|
|
51
|
+
}
|
|
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
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export const tableRow = {
|
|
60
|
+
type: "table_row",
|
|
61
|
+
name: "Row",
|
|
62
|
+
icon: '<rect x="3" y="9" width="18" height="6" rx="1"/><path d="M9 9v6M15 9v6"/>',
|
|
63
|
+
roles: ["row"],
|
|
64
|
+
accepts: ["cell"],
|
|
65
|
+
horizontal: true,
|
|
66
|
+
palette: [],
|
|
67
|
+
defaults: () => ({ attributes: {}, data: {} }),
|
|
68
|
+
fields: [
|
|
69
|
+
{ title: "Table", fields: [tableActions] },
|
|
70
|
+
{
|
|
71
|
+
title: "Row",
|
|
72
|
+
fields: [
|
|
73
|
+
{ key: "data.heading", label: "Heading row", type: "toggle", on: "heading", off: "", hint: "In the heading rows' style. Heading rows at the top repeat on every page." },
|
|
74
|
+
background,
|
|
75
|
+
{ key: "data.lineAbove", label: "Line above", type: "size", hint: "A heavier line above the row, e.g. 3pt above a total." }
|
|
76
|
+
]
|
|
77
|
+
}
|
|
78
|
+
],
|
|
79
|
+
label: (node) => (node.data.heading ? "Heading row" : "Row"),
|
|
80
|
+
// In its table's (export/table.js)
|
|
81
|
+
render: { mjml: () => "" }
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export const tableCell = {
|
|
85
|
+
type: "table_cell",
|
|
86
|
+
name: "Cell",
|
|
87
|
+
icon: '<rect x="4" y="4" width="16" height="16" rx="1"/><path d="M8 10h8M8 14h5"/>',
|
|
88
|
+
roles: ["cell"],
|
|
89
|
+
accepts: ["content"],
|
|
90
|
+
palette: [],
|
|
91
|
+
defaults: () => ({ attributes: {}, data: {} }),
|
|
92
|
+
fields: [
|
|
93
|
+
{ title: "Table", fields: [tableActions] },
|
|
94
|
+
{
|
|
95
|
+
title: "Cell",
|
|
96
|
+
fields: [
|
|
97
|
+
{ key: "attributes.text-align", label: "Align", type: "segmented", options: ALIGN },
|
|
98
|
+
{ key: "attributes.vertical-align", label: "Vertical align", type: "segmented", options: VERTICAL_ALIGN },
|
|
99
|
+
background,
|
|
100
|
+
{ key: "attributes.color", label: "Text color", type: "color" },
|
|
101
|
+
{ ...padding, hint: "Instead of the table's cell padding." },
|
|
102
|
+
{ key: "data.colspan", label: "Spans columns", type: "text", placeholder: "1", hint: "How many columns the cell takes, merging it with the cells to its right." }
|
|
103
|
+
]
|
|
104
|
+
}
|
|
105
|
+
],
|
|
106
|
+
label(node) {
|
|
107
|
+
const text = (node.children || []).map((child) => plainText(child.data?.content)).join(" ").trim()
|
|
108
|
+
return text ? `Cell · ${text.slice(0, 32)}` : "Cell"
|
|
109
|
+
},
|
|
110
|
+
// In its table's (export/table.js)
|
|
111
|
+
render: { mjml: () => "" }
|
|
112
|
+
}
|
|
@@ -62,6 +62,7 @@ import { IMAGE_FIELD, fetchMedia, uploadMedia } from "tess_edit/core/media"
|
|
|
62
62
|
import { Translations, keysIn, suggestKey, toTranslation, translationTag } from "tess_edit/core/translations"
|
|
63
63
|
import { Values } from "tess_edit/core/values"
|
|
64
64
|
import { Variables, loopScope } from "tess_edit/core/variables"
|
|
65
|
+
import { addColumn, addRow, cellOf, columnCount, deleteColumn, deleteRow, nextCell, position, rows, wrapRow } from "tess_edit/core/table"
|
|
65
66
|
import { Canvas } from "tess_edit/ui/canvas"
|
|
66
67
|
import { freeChild, number } from "tess_edit/ui/free_layout"
|
|
67
68
|
import { Tree } from "tess_edit/ui/tree"
|
|
@@ -995,9 +996,43 @@ export default class extends Controller {
|
|
|
995
996
|
}
|
|
996
997
|
|
|
997
998
|
openInsertMenu(parentId, index, rect) {
|
|
998
|
-
const
|
|
999
|
-
|
|
1000
|
-
|
|
999
|
+
const allowed = this.accepted(parentId)
|
|
1000
|
+
const items = this.paletteItems().filter((item) => allowed.includes(item.type))
|
|
1001
|
+
if (!items.length) return this.closeMenu()
|
|
1002
|
+
this.showMenu(`${parentId}:${index}`, "insert", t("Add block"), rect,
|
|
1003
|
+
items.map((item) => ({ label: t(item.label), icon: icon(item.icon), action: () => this.insertAt(item.key, parentId, index) })))
|
|
1004
|
+
}
|
|
1005
|
+
|
|
1006
|
+
// A cell's rows and columns (core/table.js), as on the Cell in Inspect, and
|
|
1007
|
+
// wrapping its row in a Loop or Condition, selected to fill in
|
|
1008
|
+
openTableMenu(cellId, rect) {
|
|
1009
|
+
const at = position(this.doc, cellId)
|
|
1010
|
+
if (!at) return
|
|
1011
|
+
const rowParent = find(this.doc, at.row.id)?.parent
|
|
1012
|
+
const change = (mutate) => () => {
|
|
1013
|
+
let next = null
|
|
1014
|
+
this.commit((doc) => (next = mutate(doc, cellId)))
|
|
1015
|
+
if (next) this.select(next.id)
|
|
1016
|
+
}
|
|
1017
|
+
const entries = [
|
|
1018
|
+
{ label: t("Add row above"), action: change((doc, id) => addRow(doc, id, "above")) },
|
|
1019
|
+
{ label: t("Add row below"), action: change((doc, id) => addRow(doc, id, "below")) },
|
|
1020
|
+
{ label: t("Add column left"), action: change((doc, id) => addColumn(doc, id, "left")) },
|
|
1021
|
+
{ label: t("Add column right"), action: change((doc, id) => addColumn(doc, id, "right")) },
|
|
1022
|
+
{ label: t("Delete row"), disabled: rows(at.table).length < 2, action: change(deleteRow) },
|
|
1023
|
+
{ label: t("Delete column"), disabled: columnCount(at.table) < 2, action: change(deleteColumn) }
|
|
1024
|
+
]
|
|
1025
|
+
for (const type of ["loop", "condition"]) {
|
|
1026
|
+
if (!rowParent || !this.allows(type) || !this.accepted(rowParent.id).includes(type)) continue
|
|
1027
|
+
entries.push({ label: t(type === "loop" ? "Repeat the row in a Loop" : "Show the row in a Condition"), icon: icon(type), separator: entries.every((entry) => !entry.separator), action: change((doc, id) => wrapRow(doc, id, type)) })
|
|
1028
|
+
}
|
|
1029
|
+
this.showMenu(`table:${cellId}`, "table", t("Rows and columns"), rect, entries)
|
|
1030
|
+
}
|
|
1031
|
+
|
|
1032
|
+
// A menu below (or above) `rect`, in the page's coordinates; a second click
|
|
1033
|
+
// on what opened it (`anchor`) closes it. Its mousedown already closed it
|
|
1034
|
+
// as an outside click, so that's checked too.
|
|
1035
|
+
showMenu(anchor, kind, title, rect, entries) {
|
|
1001
1036
|
const closed = this.menuClosed
|
|
1002
1037
|
if (this.menu?.dataset.anchor === anchor || (closed?.anchor === anchor && Date.now() - closed.at < 500)) {
|
|
1003
1038
|
this.closeMenu()
|
|
@@ -1005,29 +1040,28 @@ export default class extends Controller {
|
|
|
1005
1040
|
return
|
|
1006
1041
|
}
|
|
1007
1042
|
this.closeMenu()
|
|
1008
|
-
const allowed = this.accepted(parentId)
|
|
1009
|
-
const items = this.paletteItems().filter((item) => allowed.includes(item.type))
|
|
1010
|
-
if (!items.length) return
|
|
1011
1043
|
this.menu = h(
|
|
1012
1044
|
"div",
|
|
1013
|
-
{ class: "fixed z-50 w-56 max-h-80 overflow-y-auto rounded-lg border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800 p-1 shadow-lg", role: "menu", "data-anchor": anchor, "data-tess-edit-menu":
|
|
1014
|
-
h("div", { class: "px-2 py-1.5 text-[11px] font-semibold uppercase tracking-wide text-gray-500 dark:text-gray-400" },
|
|
1015
|
-
|
|
1045
|
+
{ class: "fixed z-50 w-56 max-h-80 overflow-y-auto rounded-lg border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800 p-1 shadow-lg", role: "menu", "data-anchor": anchor, "data-tess-edit-menu": kind },
|
|
1046
|
+
h("div", { class: "px-2 py-1.5 text-[11px] font-semibold uppercase tracking-wide text-gray-500 dark:text-gray-400" }, title),
|
|
1047
|
+
entries.flatMap((entry) => [
|
|
1048
|
+
...(entry.separator ? [h("div", { class: "my-1 border-t border-gray-200 dark:border-gray-700" })] : []),
|
|
1016
1049
|
h(
|
|
1017
1050
|
"button",
|
|
1018
1051
|
{
|
|
1019
1052
|
type: "button",
|
|
1020
1053
|
role: "menuitem",
|
|
1021
|
-
|
|
1054
|
+
disabled: !!entry.disabled,
|
|
1055
|
+
class: "flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-[13px] text-gray-700 dark:text-gray-300 hover:bg-blue-50 dark:hover:bg-blue-900/40 hover:text-blue-700 dark:hover:text-blue-300 disabled:opacity-40 disabled:pointer-events-none",
|
|
1022
1056
|
onclick: () => {
|
|
1023
1057
|
this.closeMenu()
|
|
1024
|
-
|
|
1058
|
+
entry.action()
|
|
1025
1059
|
}
|
|
1026
1060
|
},
|
|
1027
|
-
h("span", { class: "text-gray-400 dark:text-gray-500", html:
|
|
1028
|
-
|
|
1061
|
+
...(entry.icon ? [h("span", { class: "text-gray-400 dark:text-gray-500", html: entry.icon })] : []),
|
|
1062
|
+
entry.label
|
|
1029
1063
|
)
|
|
1030
|
-
)
|
|
1064
|
+
])
|
|
1031
1065
|
)
|
|
1032
1066
|
document.body.append(this.menu)
|
|
1033
1067
|
const width = 224
|
|
@@ -1062,6 +1096,13 @@ export default class extends Controller {
|
|
|
1062
1096
|
this.closeMenu()
|
|
1063
1097
|
return
|
|
1064
1098
|
}
|
|
1099
|
+
// Tab to the next cell of a table (Shift+Tab to the one before), from the
|
|
1100
|
+
// text being edited in one or the block selected in one; unless the
|
|
1101
|
+
// variable menu took it
|
|
1102
|
+
if (event.key === "Tab" && !mod && !event.altKey && !event.defaultPrevented && (this.editingId || !typing) && this.tabToCell(event.shiftKey)) {
|
|
1103
|
+
event.preventDefault()
|
|
1104
|
+
return
|
|
1105
|
+
}
|
|
1065
1106
|
if (this.editingId) {
|
|
1066
1107
|
if (event.key === "Escape") {
|
|
1067
1108
|
event.preventDefault()
|
|
@@ -1096,6 +1137,39 @@ export default class extends Controller {
|
|
|
1096
1137
|
}
|
|
1097
1138
|
}
|
|
1098
1139
|
|
|
1140
|
+
// Edits the next cell's first text, or selects the cell when it has none;
|
|
1141
|
+
// from the last cell it adds a row and goes to its first, once the canvas
|
|
1142
|
+
// has it. False when the block isn't in a table's cell, or there's no cell
|
|
1143
|
+
// before the first
|
|
1144
|
+
tabToCell(backwards) {
|
|
1145
|
+
const id = this.editingId || this.selectedId
|
|
1146
|
+
const cell = id && cellOf(this.doc, id)
|
|
1147
|
+
if (!cell) return false
|
|
1148
|
+
let next = nextCell(this.doc, cell.id, { backwards })
|
|
1149
|
+
const added = !next && !backwards
|
|
1150
|
+
if (added) {
|
|
1151
|
+
this.stopEditing()
|
|
1152
|
+
this.commit((doc) => addRow(doc, cell.id, "below") && (next = nextCell(doc, cell.id)))
|
|
1153
|
+
}
|
|
1154
|
+
if (!next) return false
|
|
1155
|
+
let text = null
|
|
1156
|
+
walk(next, (node) => {
|
|
1157
|
+
if (text) return false
|
|
1158
|
+
const part = node !== next && inlineParts(node.type)[0]
|
|
1159
|
+
if (part && this.canEditField(node.id, part.key)) text = node
|
|
1160
|
+
})
|
|
1161
|
+
if (!text) {
|
|
1162
|
+
this.select(next.id)
|
|
1163
|
+
} else if (added) {
|
|
1164
|
+
this.select(text.id)
|
|
1165
|
+
this.scheduleCanvas.cancel()
|
|
1166
|
+
this.renderCanvas().then(() => this.selectedId === text.id && this.startEditing(text.id))
|
|
1167
|
+
} else {
|
|
1168
|
+
this.startEditing(text.id)
|
|
1169
|
+
}
|
|
1170
|
+
return true
|
|
1171
|
+
}
|
|
1172
|
+
|
|
1099
1173
|
// --- code dialog ----------------------------------------------------------------
|
|
1100
1174
|
|
|
1101
1175
|
async openCodeDialog(tab = "json") {
|
|
@@ -23,7 +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: ["email"], // the kits it is part of, default ["email"]
|
|
26
|
+
// kits: ["email"], // the kits it is part of, default ["email"]; [] for none
|
|
27
|
+
// // yet: a kit takes it in with extendBlock, and its render hook
|
|
27
28
|
// unique: true, // optional: at most one per document, like Content
|
|
28
29
|
// layout: "free", // optional, on a container: its children are placed by
|
|
29
30
|
// // data.x and data.y, dragged on the canvas (ui/free_layout.js)
|
|
@@ -37,7 +38,8 @@
|
|
|
37
38
|
// })
|
|
38
39
|
//
|
|
39
40
|
// Roles: "body" (inside the page or a wrapper: sections, heroes), "wrapper",
|
|
40
|
-
// "column" (inside a section)
|
|
41
|
+
// "column" (inside a section), "content" (inside a column or hero), and
|
|
42
|
+
// "row" (inside a table) and "cell" (inside a row), see blocks/table.js. A
|
|
41
43
|
// container accepts the roles in its `accepts`; Loop and Condition use
|
|
42
44
|
// "inherit" and accept what their nearest other container accepts.
|
|
43
45
|
//
|
|
@@ -157,7 +159,10 @@ export function registerBlock(definition) {
|
|
|
157
159
|
const { type, name, render } = definition || {}
|
|
158
160
|
if (!type || typeof type !== "string") throw new Error("A block needs a type")
|
|
159
161
|
if (!name) throw new Error(`Block ${type} needs a name`)
|
|
160
|
-
|
|
162
|
+
// A block of no kit yet (kits: []), such as a Table, gets its render hook
|
|
163
|
+
// from the kit that takes it in (extendBlock)
|
|
164
|
+
const ownKits = definition.kits ?? [DEFAULT_KIT]
|
|
165
|
+
if (ownKits.length && !Object.values(render || {}).some((hook) => typeof hook === "function")) throw new Error(`Block ${type} needs render.mjml(node, ctx) or render.html(node, ctx)`)
|
|
161
166
|
if (!kits().some((kit) => kit.root === type) && !(definition.roles || []).length) throw new Error(`Block ${type} needs roles, e.g. ["content"]`)
|
|
162
167
|
|
|
163
168
|
const palette = (definition.palette ?? (definition.category ? [{ key: type, label: name, icon: definition.icon, category: definition.category }] : [])).map((item) => ({
|
|
@@ -190,7 +195,7 @@ function keyPattern(key) {
|
|
|
190
195
|
}
|
|
191
196
|
|
|
192
197
|
// The field types of ui/inspector.js
|
|
193
|
-
export const FIELD_TYPES = ["text", "textarea", "code", "size", "color", "select", "font", "segmented", "toggle", "spacing", "list", "image", "slot"]
|
|
198
|
+
export const FIELD_TYPES = ["text", "textarea", "code", "size", "color", "select", "font", "segmented", "toggle", "spacing", "list", "image", "slot", "table"]
|
|
194
199
|
|
|
195
200
|
// A field type of the host's, for what TessEdit's own can't do, such as
|
|
196
201
|
// parts that depend on each other:
|
|
@@ -215,15 +220,17 @@ export function fieldType(type) {
|
|
|
215
220
|
return fieldTypeList.get(type)
|
|
216
221
|
}
|
|
217
222
|
|
|
218
|
-
// Adds kits, render hooks and field groups to a registered block. A
|
|
219
|
-
// with the title of one it has adds its fields to that one; a new group
|
|
220
|
-
// last, or before the group its `before` names.
|
|
221
|
-
|
|
223
|
+
// Adds kits, roles, render hooks and field groups to a registered block. A
|
|
224
|
+
// group with the title of one it has adds its fields to that one; a new group
|
|
225
|
+
// goes last, or before the group its `before` names. Roles let it go where
|
|
226
|
+
// another kit's blocks take it.
|
|
227
|
+
export function extendBlock(type, { kits = [], roles = [], render = {}, fields = [] } = {}) {
|
|
222
228
|
const definition = definitions.get(type)
|
|
223
229
|
if (!definition) throw new Error(`No block ${type} to extend`)
|
|
224
230
|
definitions.set(type, {
|
|
225
231
|
...definition,
|
|
226
232
|
kits: [...new Set([...definition.kits, ...kits])],
|
|
233
|
+
roles: [...new Set([...definition.roles, ...roles])],
|
|
227
234
|
render: { ...definition.render, ...render },
|
|
228
235
|
fields: fields.reduce(addGroup, definition.fields || [])
|
|
229
236
|
})
|