tess_edit 0.5.9 → 0.5.10
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/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/core/registry.js +15 -8
- data/app/javascript/tess_edit/core/table.js +228 -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 +39 -4
- 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 +37 -0
- data/config/locales/nl.yml +37 -0
- data/lib/tess_edit/version.rb +1 -1
- metadata +5 -1
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
// A table (blocks/table.js) as HTML, for a kit whose tables are HTML: the
|
|
2
|
+
// email's mj-table, which MJML copies as it is, so a cell's blocks are HTML
|
|
3
|
+
// too, not MJML. Its styles are inline, as mail clients need: borders,
|
|
4
|
+
// padding and heading rows on each cell.
|
|
5
|
+
//
|
|
6
|
+
// tableHtml(node, { editor, richText, escapeText, escapeAttribute })
|
|
7
|
+
// // → "<colgroup>…</colgroup><thead>…</thead><tbody>…</tbody>"
|
|
8
|
+
//
|
|
9
|
+
// A cell's blocks are rendered here (cellBlock): Text, Image, Button,
|
|
10
|
+
// Divider, Spacer, Loop, Condition, Assign and tables; others show nothing.
|
|
11
|
+
// With editor, every element has its tess-<id> class, an empty container a
|
|
12
|
+
// placeholder that fits there, and Liquid tags are left out, so a Loop's
|
|
13
|
+
// rows show once.
|
|
14
|
+
|
|
15
|
+
import { t } from "tess_edit/core/i18n"
|
|
16
|
+
import { span } from "tess_edit/core/table"
|
|
17
|
+
|
|
18
|
+
const ROW = "table_row"
|
|
19
|
+
const PLACEHOLDER = "padding:12px;text-align:center;color:#94a3b8;font-size:13px;font-family:system-ui,sans-serif"
|
|
20
|
+
|
|
21
|
+
function style(declarations) {
|
|
22
|
+
const css = Object.entries(declarations)
|
|
23
|
+
.filter(([, value]) => value !== undefined && value !== null && value !== "")
|
|
24
|
+
.map(([name, value]) => `${name}:${value}`)
|
|
25
|
+
.join(";")
|
|
26
|
+
return css ? ` style="${css.replace(/"/g, """)}"` : ""
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const classes = (node, ctx) => (ctx.editor ? ` class="tess-${node.id}"` : "")
|
|
30
|
+
|
|
31
|
+
// The table's rows, also in its Loops and Conditions, for the column count
|
|
32
|
+
function rowsOf(node) {
|
|
33
|
+
return (node.children || []).flatMap((child) => (child.type === ROW ? [child] : ["table", "table_cell"].includes(child.type) ? [] : rowsOf(child)))
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function columnsOf(table) {
|
|
37
|
+
const list = Array.isArray(table.data?.columns) ? table.data.columns : []
|
|
38
|
+
const widest = Math.max(0, ...rowsOf(table).map((row) => (row.children || []).reduce((sum, cell) => sum + span(cell), 0)))
|
|
39
|
+
return Array.from({ length: Math.max(list.length, widest) }, (_, i) => list[i] || {})
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function tableHtml(table, ctx) {
|
|
43
|
+
const d = table.data || {}
|
|
44
|
+
const columns = columnsOf(table)
|
|
45
|
+
const line = `${d.borderWidth || "1px"} solid ${d.borderColor || "#d1d5db"}`
|
|
46
|
+
const look = {
|
|
47
|
+
// Around every cell, or only under each row
|
|
48
|
+
border: d.borders === "rows" ? { "border-bottom": line } : { border: line },
|
|
49
|
+
lineAbove: (width) => (d.borders === "rows" ? { "border-top": `${width} solid ${d.borderColor || "#d1d5db"}` } : { "border-top-width": width }),
|
|
50
|
+
padding: d.cellPadding || "6px 8px",
|
|
51
|
+
heading: { "background-color": d.headingBackground, color: d.headingColor, "font-weight": d.headingWeight || "bold" },
|
|
52
|
+
stripe: d.stripe,
|
|
53
|
+
columns
|
|
54
|
+
}
|
|
55
|
+
const kids = table.children || []
|
|
56
|
+
const heading = []
|
|
57
|
+
for (const kid of kids) {
|
|
58
|
+
if (kid.type !== ROW || !kid.data?.heading) break
|
|
59
|
+
heading.push(kid)
|
|
60
|
+
}
|
|
61
|
+
const state = { body: 0 }
|
|
62
|
+
const head = heading.map((row) => rowHtml(row, ctx, look, null))
|
|
63
|
+
let body = kids.slice(heading.length).map((kid) => between(kid, ctx, look, state))
|
|
64
|
+
if (!kids.length && ctx.editor) body = [placeholderRow(table, columns.length)]
|
|
65
|
+
const widths = columns.some((column) => column.width) ? `<colgroup>${columns.map((column) => `<col${style({ width: column.width })}>`).join("")}</colgroup>` : ""
|
|
66
|
+
return [widths, head.length ? `<thead>${head.join("")}</thead>` : "", `<tbody>${body.join("\n")}</tbody>`].join("")
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function placeholderRow(node, count) {
|
|
70
|
+
return `<tr><td class="tessph-${node.id}" colspan="${Math.max(count, 1)}" style="${PLACEHOLDER}">${t("Drop a row here")}</td></tr>`
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// What is between a table's rows: a Row, or a Loop, Condition or Assign
|
|
74
|
+
function between(node, ctx, look, state) {
|
|
75
|
+
if (node.type === ROW) return rowHtml(node, ctx, look, state)
|
|
76
|
+
const inner = () => {
|
|
77
|
+
if (!(node.children || []).length && ctx.editor) return [placeholderRow(node, look.columns.length)]
|
|
78
|
+
return node.children.map((child) => between(child, ctx, look, state))
|
|
79
|
+
}
|
|
80
|
+
const [open, close] = liquidTags(node)
|
|
81
|
+
if (open === null) return ""
|
|
82
|
+
if (ctx.editor) return node.type === "assign" ? "" : inner().join("\n")
|
|
83
|
+
return node.type === "assign" ? open : [open, ...inner(), close].join("\n")
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function liquidTags(node) {
|
|
87
|
+
const d = node.data || {}
|
|
88
|
+
if (node.type === "loop") return [`{% for ${d.variable || "item"} in ${d.collection || "items"} %}`, "{% endfor %}"]
|
|
89
|
+
if (node.type === "condition") return [`{% if ${d.expression || "true"} %}`, "{% endif %}"]
|
|
90
|
+
if (node.type === "assign") return [`{% assign ${d.variable || "value"} = ${d.expression || "nil"} %}`, ""]
|
|
91
|
+
return [null, null]
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function rowHtml(row, ctx, look, state) {
|
|
95
|
+
const heading = !!row.data?.heading
|
|
96
|
+
// Stripes on every other body row; a Loop's row counts once, as it can't
|
|
97
|
+
// know how many it will be
|
|
98
|
+
const striped = state && !heading && look.stripe && state.body++ % 2 === 1
|
|
99
|
+
let start = 0
|
|
100
|
+
const cells = (row.children || []).map((cell) => {
|
|
101
|
+
const column = look.columns[start] || {}
|
|
102
|
+
start += span(cell)
|
|
103
|
+
return cellHtml(cell, ctx, look, { row, column, heading, striped })
|
|
104
|
+
})
|
|
105
|
+
if (!cells.length && ctx.editor) cells.push(`<td class="tessph-${row.id}" style="${PLACEHOLDER}">${t("Drop a cell here")}</td>`)
|
|
106
|
+
return `<tr${classes(row, ctx)}>${cells.join("")}</tr>`
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function cellHtml(cell, ctx, look, { row, column, heading, striped }) {
|
|
110
|
+
const a = cell.attributes || {}
|
|
111
|
+
const tag = heading ? "th" : "td"
|
|
112
|
+
const declarations = {
|
|
113
|
+
...look.border,
|
|
114
|
+
...(row.data?.lineAbove ? look.lineAbove(row.data.lineAbove) : {}),
|
|
115
|
+
padding: a.padding || look.padding,
|
|
116
|
+
"text-align": a["text-align"] || column.align || "left",
|
|
117
|
+
"vertical-align": a["vertical-align"] || "top",
|
|
118
|
+
...(heading ? look.heading : {}),
|
|
119
|
+
"background-color": a["background-color"] || row.attributes?.["background-color"] || (heading ? look.heading["background-color"] : striped ? look.stripe : undefined),
|
|
120
|
+
color: a.color || (heading ? look.heading.color : undefined)
|
|
121
|
+
}
|
|
122
|
+
const colspan = span(cell) > 1 ? ` colspan="${span(cell)}"` : ""
|
|
123
|
+
const kids = cell.children || []
|
|
124
|
+
const inner = !kids.length && ctx.editor ? `<div class="tessph-${cell.id}" style="${PLACEHOLDER}">${t("Drop content here")}</div>` : kids.map((child) => cellBlock(child, ctx)).join("")
|
|
125
|
+
return `<${tag}${classes(cell, ctx)}${colspan}${style(declarations)}>${inner}</${tag}>`
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// A block in a cell, as HTML
|
|
129
|
+
export function cellBlock(node, ctx) {
|
|
130
|
+
const a = node.attributes || {}
|
|
131
|
+
const d = node.data || {}
|
|
132
|
+
const children = () => {
|
|
133
|
+
if (!(node.children || []).length && ctx.editor) return `<div class="tessph-${node.id}" style="${PLACEHOLDER}">${t("Drop content here")}</div>`
|
|
134
|
+
return node.children.map((child) => cellBlock(child, ctx)).join("")
|
|
135
|
+
}
|
|
136
|
+
switch (node.type) {
|
|
137
|
+
case "text":
|
|
138
|
+
return `<div${classes(node, ctx)}${style({ padding: a.padding, "text-align": a.align, color: a.color, "font-family": a["font-family"], "font-size": a["font-size"], "font-weight": a["font-weight"], "line-height": a["line-height"], "background-color": a["container-background-color"] })}>${ctx.richText(d.content)}</div>`
|
|
139
|
+
case "image": {
|
|
140
|
+
const image = `<img src="${ctx.escapeAttribute(a.src || "")}" alt="${ctx.escapeAttribute(a.alt || "")}"${style({ display: "block", width: a.width, "max-width": "100%", height: "auto", border: "0" })}>`
|
|
141
|
+
const linked = a.href ? `<a href="${ctx.escapeAttribute(a.href)}">${image}</a>` : image
|
|
142
|
+
return `<div${classes(node, ctx)}${style({ padding: a.padding, "text-align": a.align })}>${linked}</div>`
|
|
143
|
+
}
|
|
144
|
+
case "button":
|
|
145
|
+
return `<div${classes(node, ctx)}${style({ padding: a.padding, "text-align": a.align })}><a href="${ctx.escapeAttribute(a.href || "#")}"${style({ display: "inline-block", "background-color": a["background-color"] || "#414141", color: a.color || "#ffffff", padding: a["inner-padding"] || "10px 25px", "border-radius": a["border-radius"] || "3px", "font-size": a["font-size"], "font-weight": a["font-weight"], "text-decoration": "none" })}>${ctx.escapeText(d.content || "")}</a></div>`
|
|
146
|
+
case "divider":
|
|
147
|
+
return `<div${classes(node, ctx)}${style({ padding: a.padding })}><div${style({ "border-top": `${a["border-width"] || "1px"} ${a["border-style"] || "solid"} ${a["border-color"] || "#000000"}` })}></div></div>`
|
|
148
|
+
case "spacer":
|
|
149
|
+
return `<div${classes(node, ctx)}${style({ height: a.height || "20px" })}></div>`
|
|
150
|
+
case "table":
|
|
151
|
+
return `<div${classes(node, ctx)}${style({ padding: a.padding })}><table${style({ width: a.width || "100%", "border-collapse": "collapse" })}>${tableHtml(node, ctx)}</table></div>`
|
|
152
|
+
case "loop":
|
|
153
|
+
case "condition":
|
|
154
|
+
case "assign": {
|
|
155
|
+
const [open, close] = liquidTags(node)
|
|
156
|
+
if (node.type === "assign") return ctx.editor ? "" : open
|
|
157
|
+
return ctx.editor ? children() : `${open}${children()}${close}`
|
|
158
|
+
}
|
|
159
|
+
default:
|
|
160
|
+
return ""
|
|
161
|
+
}
|
|
162
|
+
}
|
|
@@ -16,6 +16,7 @@ export { registerBlock, registerCategory, registerFieldType, registerKit, regist
|
|
|
16
16
|
export * as fields from "tess_edit/blocks/fields"
|
|
17
17
|
export { imageField } from "tess_edit/core/media"
|
|
18
18
|
export { starterDocument } from "tess_edit/core/starter"
|
|
19
|
+
export { cellOf, tableOf } from "tess_edit/core/table"
|
|
19
20
|
|
|
20
21
|
export function registerTessEdit(application, identifier = "tess-edit") {
|
|
21
22
|
application.register(identifier, EditorController)
|
|
@@ -51,6 +51,7 @@ a{cursor:default}
|
|
|
51
51
|
.tess-v-filled,.tess-v-raw{border-radius:3px;background:rgba(5,150,105,.08);box-shadow:inset 0 -1px 0 rgba(5,150,105,.55)}
|
|
52
52
|
.ProseMirror .tess-v-filled{cursor:text}
|
|
53
53
|
.tess-v-hidden{display:none}
|
|
54
|
+
.tess-v-empty{border-radius:3px;background:rgba(220,38,38,.08);box-shadow:inset 0 -1px 0 rgba(220,38,38,.65)}
|
|
54
55
|
`
|
|
55
56
|
|
|
56
57
|
// A file dragged in from outside the browser (block drags set editor.drag)
|
|
@@ -187,9 +188,11 @@ export class Canvas {
|
|
|
187
188
|
if (!values || !this.doc?.body) return
|
|
188
189
|
for (const span of this.doc.querySelectorAll(".tess-v[data-tess-call]")) {
|
|
189
190
|
const value = values.value(span.dataset.tessExpression)
|
|
191
|
+
const empty = value === null && values.empty(span.dataset.tessExpression)
|
|
190
192
|
span.textContent = value ?? span.dataset.tessCall
|
|
191
|
-
span.title = value === null ? "" : span.dataset.tessCall
|
|
193
|
+
span.title = empty ? t("Empty for now: fill it in where it comes from") : value === null ? "" : span.dataset.tessCall
|
|
192
194
|
span.classList.toggle("tess-v-filled", value !== null)
|
|
195
|
+
span.classList.toggle("tess-v-empty", empty)
|
|
193
196
|
}
|
|
194
197
|
this.refresh()
|
|
195
198
|
}
|
|
@@ -228,8 +231,33 @@ export class Canvas {
|
|
|
228
231
|
return null
|
|
229
232
|
}
|
|
230
233
|
|
|
234
|
+
// A block's element. A Loop's blocks can show once per item, as a Table's
|
|
235
|
+
// rows do with a record's values (a host's canvas), each copy with the
|
|
236
|
+
// block's class: the copy clicked last is the one meant, and so are the
|
|
237
|
+
// blocks in it and around it, until another is clicked. The copy is kept
|
|
238
|
+
// by its place among them, as the canvas is written again.
|
|
231
239
|
elementOf(id) {
|
|
232
|
-
|
|
240
|
+
const anchor = this.anchorElement()
|
|
241
|
+
const near = anchor && (anchor.closest(`.tess-${id}`) || anchor.querySelector(`.tess-${id}, .tessph-${id}`))
|
|
242
|
+
return near || this.doc?.querySelector(`.tess-${id}`) || this.doc?.querySelector(`.tessph-${id}`)
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// Remembers the copy of a block that was clicked
|
|
246
|
+
anchorAt(hit) {
|
|
247
|
+
if (!hit || hit.placeholder) return
|
|
248
|
+
const copies = [...this.doc.querySelectorAll(`.tess-${hit.id}`)]
|
|
249
|
+
this.anchor = copies.length > 1 ? { id: hit.id, index: Math.max(0, copies.indexOf(hit.element)) } : null
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
anchorElement() {
|
|
253
|
+
if (!this.anchor || !this.doc) return null
|
|
254
|
+
return this.doc.querySelectorAll(`.tess-${this.anchor.id}`)[this.anchor.index] || null
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// The rectangle of the copy of a block an element is in, else its first
|
|
258
|
+
hoverRect(id) {
|
|
259
|
+
const element = this.hoverElement?.isConnected && this.hoverElement.closest(`.tess-${id}`)
|
|
260
|
+
return element ? element.getBoundingClientRect() : this.rectOf(id)
|
|
233
261
|
}
|
|
234
262
|
|
|
235
263
|
// The rectangle of a block in viewport coordinates of the iframe. Blocks
|
|
@@ -256,7 +284,7 @@ export class Canvas {
|
|
|
256
284
|
// Where an inline part is edited: the element its render marks with
|
|
257
285
|
// data-tess-edit-field, or for the richText shorthand the block's own
|
|
258
286
|
textContainer(id, key) {
|
|
259
|
-
const cell = this.
|
|
287
|
+
const cell = this.elementOf(id)
|
|
260
288
|
const part = this.partElement(cell, key)
|
|
261
289
|
if (part) return part
|
|
262
290
|
if (key !== getBlock(find(this.editor.doc, id)?.node.type)?.richText) return null
|
|
@@ -297,7 +325,7 @@ export class Canvas {
|
|
|
297
325
|
|
|
298
326
|
if (this.hoverId && this.hoverId !== selectedId) {
|
|
299
327
|
const hit = find(this.editor.doc, this.hoverId)
|
|
300
|
-
const rect = hit && this.
|
|
328
|
+
const rect = hit && this.hoverRect(this.hoverId)
|
|
301
329
|
if (rect && hit.node !== this.editor.doc) {
|
|
302
330
|
const box = this.box(rect, "tess-hover")
|
|
303
331
|
box.append(Object.assign(this.doc.createElement("div"), { className: "tess-label", textContent: getBlock(hit.node.type)?.name || hit.node.type }))
|
|
@@ -379,6 +407,11 @@ export class Canvas {
|
|
|
379
407
|
onMove(event) {
|
|
380
408
|
if (this.editor.drag || this.free.dragging) return
|
|
381
409
|
const hit = this.hit(event.target)
|
|
410
|
+
const element = hit && !hit.placeholder ? hit.element : null
|
|
411
|
+
if (element !== this.hoverElement) {
|
|
412
|
+
this.hoverElement = element
|
|
413
|
+
this.hoverId = null
|
|
414
|
+
}
|
|
382
415
|
this.setHover(hit && !hit.placeholder ? hit.id : null)
|
|
383
416
|
}
|
|
384
417
|
|
|
@@ -389,6 +422,7 @@ export class Canvas {
|
|
|
389
422
|
if (this.openLink(event)) return
|
|
390
423
|
if (this.free.swallowClick()) return
|
|
391
424
|
const hit = this.hit(event.target)
|
|
425
|
+
this.anchorAt(hit)
|
|
392
426
|
if (hit?.placeholder) {
|
|
393
427
|
const rect = this.toParentRect(hit.element.getBoundingClientRect())
|
|
394
428
|
this.editor.select(hit.id)
|
|
@@ -414,6 +448,7 @@ export class Canvas {
|
|
|
414
448
|
|
|
415
449
|
onDoubleClick(event) {
|
|
416
450
|
const hit = this.hit(event.target)
|
|
451
|
+
this.anchorAt(hit)
|
|
417
452
|
const part = hit && !hit.placeholder && this.partAt(event.target, hit.id)
|
|
418
453
|
if (part) this.editor.startEditing(hit.id, part)
|
|
419
454
|
}
|
|
@@ -17,10 +17,11 @@
|
|
|
17
17
|
import { t } from "tess_edit/core/i18n"
|
|
18
18
|
import { imageSource } from "tess_edit/core/media"
|
|
19
19
|
import { fieldType, getBlock, label } from "tess_edit/core/registry"
|
|
20
|
-
import { fontOptions } from "tess_edit/blocks/fields"
|
|
20
|
+
import { ALIGN, fontOptions } from "tess_edit/blocks/fields"
|
|
21
21
|
import { find, getValue } from "tess_edit/core/document"
|
|
22
22
|
import { translationCalls } from "tess_edit/core/translations"
|
|
23
23
|
import { loopScope } from "tess_edit/core/variables"
|
|
24
|
+
import { CELL, ROW, TABLE, addColumn, addRow, cellOf, columnCount, deleteColumn, deleteRow, position, rows, setColumn } from "tess_edit/core/table"
|
|
24
25
|
import { codeInput } from "tess_edit/ui/code_input"
|
|
25
26
|
import { FontPicker } from "tess_edit/ui/font_picker"
|
|
26
27
|
import { freeze, h, place } from "tess_edit/ui/dom"
|
|
@@ -105,6 +106,9 @@ export class Inspector {
|
|
|
105
106
|
|
|
106
107
|
// A group shows when one of its fields applies (see shows below)
|
|
107
108
|
const groups = (definition.fields || []).filter((group) => group.fields.some((field) => this.shows(node, field))).map((group) => this.group(node, group))
|
|
109
|
+
// A block in a table's cell, such as its Text, has the cell's table first
|
|
110
|
+
const cell = ![CELL, ROW, TABLE].includes(node.type) && cellOf(doc, node.id)
|
|
111
|
+
if (cell) groups.unshift(this.groupElement("table_cell:Table", { title: "Table" }, this.openGroups.get("table_cell:Table") ?? true, h("div", { class: "px-4 pb-4 space-y-3" }, this.table(cell))))
|
|
108
112
|
const locked = this.editor.lock && node.id !== doc.id && !this.editor.isFree(node.id)
|
|
109
113
|
? h("p", { class: "mx-4 mt-3 flex items-center gap-2 rounded-md bg-amber-50 dark:bg-amber-900/30 px-3 py-2 text-xs text-amber-800 dark:text-amber-200" }, h("span", { html: icon("lock", "w-3.5 h-3.5") }), t("Part of the layout"))
|
|
110
114
|
: null
|
|
@@ -283,6 +287,9 @@ export class Inspector {
|
|
|
283
287
|
case "list":
|
|
284
288
|
return this.list(node, field, Array.isArray(value) ? value : [], set)
|
|
285
289
|
|
|
290
|
+
case "table":
|
|
291
|
+
return this.table(node)
|
|
292
|
+
|
|
286
293
|
case "image":
|
|
287
294
|
return this.image(node, field, value, set)
|
|
288
295
|
|
|
@@ -534,6 +541,62 @@ export class Inspector {
|
|
|
534
541
|
return h("span", { class: "grid grid-cols-4 gap-1" }, inputs)
|
|
535
542
|
}
|
|
536
543
|
|
|
544
|
+
// A Cell's table (a Row's, through its first cell): the cell's column's
|
|
545
|
+
// width and alignment, and adding and deleting rows and columns
|
|
546
|
+
// (core/table.js), each one undo step, selecting the cell it gives
|
|
547
|
+
table(node) {
|
|
548
|
+
const cellId = node.type === CELL ? node.id : node.children?.find((child) => child.type === CELL)?.id
|
|
549
|
+
const at = cellId && position(this.editor.doc, cellId)
|
|
550
|
+
if (!at) return h("p", { class: "text-xs text-gray-500 dark:text-gray-400" }, t("Not in a table"))
|
|
551
|
+
|
|
552
|
+
const change = (mutate) => {
|
|
553
|
+
let next = null
|
|
554
|
+
this.editor.commit((doc) => (next = mutate(doc, cellId)))
|
|
555
|
+
if (next) this.editor.select(next.id)
|
|
556
|
+
}
|
|
557
|
+
const button = (label, mutate, disabled = false) =>
|
|
558
|
+
h("button", { type: "button", class: "flex-1 rounded-md border border-gray-300 dark:border-gray-600 px-2 py-1 text-xs text-gray-700 dark:text-gray-300 hover:bg-gray-50 dark:hover:bg-gray-700 disabled:opacity-40", disabled, onclick: () => change(mutate) }, t(label))
|
|
559
|
+
const line = (title, ...buttons) => h("div", { class: "space-y-1" }, h("span", { class: "block text-xs font-medium text-gray-700 dark:text-gray-300" }, t(title)), h("div", { class: "flex gap-1" }, ...buttons))
|
|
560
|
+
const rowCount = rows(at.table).length
|
|
561
|
+
const parts = [
|
|
562
|
+
line("Row", button("Add above", (doc, id) => addRow(doc, id, "above")), button("Add below", (doc, id) => addRow(doc, id, "below")), button("Delete", deleteRow, rowCount < 2))
|
|
563
|
+
]
|
|
564
|
+
if (node.type === CELL) {
|
|
565
|
+
const column = at.table.data?.columns?.[at.column] || {}
|
|
566
|
+
const setting = (key, value) => this.editor.commit((doc) => setColumn(doc, cellId, key, value), { coalesce: `${at.table.id}:column:${at.column}:${key}`, skipInspector: key === "width" })
|
|
567
|
+
parts.push(
|
|
568
|
+
line("Column", button("Add left", (doc, id) => addColumn(doc, id, "left")), button("Add right", (doc, id) => addColumn(doc, id, "right")), button("Delete", deleteColumn, columnCount(at.table) < 2)),
|
|
569
|
+
h(
|
|
570
|
+
"label",
|
|
571
|
+
{ class: "block" },
|
|
572
|
+
h("span", { class: "mb-1 block text-xs font-medium text-gray-700 dark:text-gray-300" }, t("Column width")),
|
|
573
|
+
h("input", { type: "text", class: INPUT, value: column.width || "", placeholder: t("Auto"), oninput: (event) => setting("width", event.target.value) })
|
|
574
|
+
),
|
|
575
|
+
h(
|
|
576
|
+
"div",
|
|
577
|
+
{ class: "block" },
|
|
578
|
+
h("span", { class: "mb-1 block text-xs font-medium text-gray-700 dark:text-gray-300" }, t("Column align")),
|
|
579
|
+
h(
|
|
580
|
+
"div",
|
|
581
|
+
{ class: "flex rounded-md border border-gray-300 dark:border-gray-600 overflow-hidden" },
|
|
582
|
+
ALIGN.map((option) =>
|
|
583
|
+
h(
|
|
584
|
+
"button",
|
|
585
|
+
{
|
|
586
|
+
type: "button",
|
|
587
|
+
class: `flex-1 px-2 py-1 text-xs border-l first:border-l-0 border-gray-300 dark:border-gray-600 ${column.align === option.value ? "bg-blue-600 text-white" : "bg-white dark:bg-gray-700 text-gray-700 dark:text-gray-300 hover:bg-gray-50 dark:hover:bg-gray-600"}`,
|
|
588
|
+
onclick: () => setting("align", column.align === option.value ? "" : option.value)
|
|
589
|
+
},
|
|
590
|
+
t(option.label)
|
|
591
|
+
)
|
|
592
|
+
)
|
|
593
|
+
)
|
|
594
|
+
)
|
|
595
|
+
)
|
|
596
|
+
}
|
|
597
|
+
return h("div", { class: "space-y-3" }, ...parts)
|
|
598
|
+
}
|
|
599
|
+
|
|
537
600
|
list(node, field, items, set) {
|
|
538
601
|
const update = (next) => {
|
|
539
602
|
set(next, { coalesce: false })
|
|
@@ -364,9 +364,11 @@ function valueDecorations(state, editing) {
|
|
|
364
364
|
const text = node.textBetween(0, node.content.size, undefined, "\ufffc")
|
|
365
365
|
for (const call of valueCalls(text)) {
|
|
366
366
|
const value = values.value(call.expression)
|
|
367
|
-
if (value === null) continue
|
|
368
367
|
const start = pos + 1 + call.start
|
|
369
368
|
const end = pos + 1 + call.end
|
|
369
|
+
// Empty for now: its Liquid, in red
|
|
370
|
+
if (value === null && values.empty(call.expression)) decorations.push(Decoration.inline(start, end, { class: "tess-v-empty" }))
|
|
371
|
+
if (value === null) continue
|
|
370
372
|
if (from < end && to > start) {
|
|
371
373
|
decorations.push(Decoration.inline(start, end, { class: "tess-v-raw" }))
|
|
372
374
|
} else {
|
data/config/locales/en.yml
CHANGED
|
@@ -4,41 +4,56 @@
|
|
|
4
4
|
en:
|
|
5
5
|
tess_edit:
|
|
6
6
|
editor:
|
|
7
|
+
0_for_no_borders: "0 for no borders."
|
|
7
8
|
1_column: "1 column"
|
|
8
9
|
2_columns: "2 columns"
|
|
9
10
|
3_columns: "3 columns"
|
|
10
11
|
4_columns: "4 columns"
|
|
12
|
+
a_background_for_every_other_row_from_the_second: "A background for every other row, from the second."
|
|
13
|
+
a_heavier_line_above_the_row_e_g_3pt_above_a_total: "A heavier line above the row, e.g. 3pt above a total."
|
|
11
14
|
a_key_is_made_of_letters_digits_and_separated_by_dots_e_g_or: "A key is made of letters, digits, _ and -, separated by dots, e.g. .order.thanks"
|
|
12
15
|
a_key_starting_with_a_dot_belongs_to_this_template: "A key starting with a dot belongs to this template."
|
|
13
16
|
a_liquid_condition_e_g_order_total_100: "A Liquid condition, e.g. order.total > 100."
|
|
17
|
+
a_liquid_expression_with_filters_e_g_order_lines_where_kind: "A Liquid expression, with filters, e.g. order.lines | where: \"kind\", \"product\"."
|
|
14
18
|
action_failed_status: "%{action} failed (%{status})"
|
|
15
19
|
add: "Add"
|
|
16
20
|
add_a_block_below: "Add a block below"
|
|
17
21
|
add_a_block_inside: "Add a block inside"
|
|
22
|
+
add_above: "Add above"
|
|
23
|
+
add_below: "Add below"
|
|
18
24
|
add_block: "Add block"
|
|
25
|
+
add_left: "Add left"
|
|
19
26
|
add_link: "Add link"
|
|
27
|
+
add_right: "Add right"
|
|
20
28
|
added_to_the_email_s_style_block: "Added to the email's <style> block."
|
|
21
29
|
align: "Align"
|
|
22
30
|
align_center: "Align center"
|
|
23
31
|
align_left: "Align left"
|
|
24
32
|
align_right: "Align right"
|
|
33
|
+
all: "All"
|
|
25
34
|
all_panels_on_the_left: "All panels on the left"
|
|
26
35
|
all_panels_on_the_right: "All panels on the right"
|
|
27
36
|
alt_text: "Alt text"
|
|
37
|
+
assign: "Assign"
|
|
28
38
|
auto: "Auto"
|
|
29
39
|
background: "Background"
|
|
30
40
|
background_image: "Background image"
|
|
31
41
|
below_this_width_columns_stack: "Below this width columns stack."
|
|
42
|
+
between_rows: "Between rows"
|
|
32
43
|
blocks: "Blocks"
|
|
33
44
|
blocks_on_the_left_inspect_on_the_right: "Blocks on the left, Inspect on the right"
|
|
34
45
|
bold_b: "Bold (⌘B)"
|
|
35
46
|
border: "Border"
|
|
47
|
+
border_color: "Border color"
|
|
48
|
+
border_width: "Border width"
|
|
36
49
|
bottom: "Bottom"
|
|
37
50
|
breakpoint: "Breakpoint"
|
|
38
51
|
bulleted_list: "Bulleted list"
|
|
39
52
|
button: "Button"
|
|
40
53
|
button_color: "Button color"
|
|
41
54
|
cancel: "Cancel"
|
|
55
|
+
cell: "Cell"
|
|
56
|
+
cell_padding: "Cell padding"
|
|
42
57
|
center: "Center"
|
|
43
58
|
center_center: "center center"
|
|
44
59
|
choose_an_image: "Choose an image"
|
|
@@ -49,7 +64,9 @@ en:
|
|
|
49
64
|
collection: "Collection"
|
|
50
65
|
color: "Color"
|
|
51
66
|
column: "Column"
|
|
67
|
+
column_align: "Column align"
|
|
52
68
|
column_order: "Column order"
|
|
69
|
+
column_width: "Column width"
|
|
53
70
|
condition: "Condition"
|
|
54
71
|
content: "Content"
|
|
55
72
|
copied: "Copied."
|
|
@@ -70,7 +87,9 @@ en:
|
|
|
70
87
|
drag_onto_the_canvas_or_click_to_add: "Drag onto the canvas, or click to add"
|
|
71
88
|
drag_to_move: "Drag to move"
|
|
72
89
|
drag_to_resize: "Drag to resize"
|
|
90
|
+
drop_a_cell_here: "Drop a cell here"
|
|
73
91
|
drop_a_column_here: "Drop a column here"
|
|
92
|
+
drop_a_row_here: "Drop a row here"
|
|
74
93
|
drop_a_section_here: "Drop a section here"
|
|
75
94
|
drop_content_here: "Drop content here"
|
|
76
95
|
duplicate: "Duplicate"
|
|
@@ -82,6 +101,8 @@ en:
|
|
|
82
101
|
editing_text_key_to_finish: "Editing text · %{key} to finish"
|
|
83
102
|
email: "Email"
|
|
84
103
|
empty: "(empty)"
|
|
104
|
+
empty_for_now_fill_it_in_where_it_comes_from: "Empty for now: fill it in where it comes from"
|
|
105
|
+
every_other_row: "Every other row"
|
|
85
106
|
expand: "Expand"
|
|
86
107
|
find_in_source: "Find in %{source}"
|
|
87
108
|
fixed_height: "Fixed height"
|
|
@@ -95,10 +116,13 @@ en:
|
|
|
95
116
|
hamburger_on_mobile: "Hamburger on mobile"
|
|
96
117
|
heading: "Heading"
|
|
97
118
|
heading_level: "Heading %{level}"
|
|
119
|
+
heading_row: "Heading row"
|
|
120
|
+
heading_rows: "Heading rows"
|
|
98
121
|
height: "Height"
|
|
99
122
|
hero: "Hero"
|
|
100
123
|
hide_panels: "Hide panels"
|
|
101
124
|
horizontal: "Horizontal"
|
|
125
|
+
how_many_columns_the_cell_takes_merging_it_with_the_cells_to: "How many columns the cell takes, merging it with the cells to its right."
|
|
102
126
|
html: "HTML"
|
|
103
127
|
icon_padding: "Icon padding"
|
|
104
128
|
icon_size: "Icon size"
|
|
@@ -106,10 +130,12 @@ en:
|
|
|
106
130
|
image_height: "Image height"
|
|
107
131
|
image_width: "Image width"
|
|
108
132
|
in_px_or_e_g_50: "In px or %, e.g. 50%."
|
|
133
|
+
in_the_heading_rows_style_heading_rows_at_the_top_repeat_on: "In the heading rows' style. Heading rows at the top repeat on every page."
|
|
109
134
|
inherit: "Inherit"
|
|
110
135
|
inner_padding: "Inner padding"
|
|
111
136
|
insert_a_variable: "Insert a variable"
|
|
112
137
|
inspect: "Inspect"
|
|
138
|
+
instead_of_the_table_s_cell_padding: "Instead of the table's cell padding."
|
|
113
139
|
italic_i: "Italic (⌘I)"
|
|
114
140
|
key: "Key"
|
|
115
141
|
key_already_says_current_in_locale: "%{key} already says “%{current}” in %{locale}."
|
|
@@ -121,7 +147,10 @@ en:
|
|
|
121
147
|
left: "Left"
|
|
122
148
|
left_to_right: "Left to right"
|
|
123
149
|
letter_spacing: "Letter spacing"
|
|
150
|
+
line_above: "Line above"
|
|
124
151
|
line_height: "Line height"
|
|
152
|
+
lines: "Lines"
|
|
153
|
+
lines_around_every_cell_or_only_under_each_row: "Lines around every cell, or only under each row."
|
|
125
154
|
link: "Link"
|
|
126
155
|
links: "Links"
|
|
127
156
|
liquid: "Liquid"
|
|
@@ -157,6 +186,7 @@ en:
|
|
|
157
186
|
no_images_yet: "No images yet"
|
|
158
187
|
no_languages_yet: "No languages yet"
|
|
159
188
|
no_variables_here: "No variables here"
|
|
189
|
+
not_in_a_table: "Not in a table"
|
|
160
190
|
nothing_matches: "Nothing matches."
|
|
161
191
|
numbered_list: "Numbered list"
|
|
162
192
|
off_word: "Off"
|
|
@@ -180,6 +210,8 @@ en:
|
|
|
180
210
|
replace: "Replace"
|
|
181
211
|
right: "Right"
|
|
182
212
|
right_to_left: "Right to left"
|
|
213
|
+
row: "Row"
|
|
214
|
+
rows_of_cells_select_a_cell_to_add_rows_and_columns_put_rows: "Rows of cells. Select a cell to add rows and columns. Put rows in a Loop to repeat them for each item."
|
|
183
215
|
same_tab: "Same tab"
|
|
184
216
|
save: "Save"
|
|
185
217
|
saving_the_translation_failed_status: "Saving the translation failed (%{status})"
|
|
@@ -187,6 +219,7 @@ en:
|
|
|
187
219
|
section: "Section"
|
|
188
220
|
select_parent: "Select parent"
|
|
189
221
|
select_the_text_to_translate_first: "Select the text to translate first."
|
|
222
|
+
sets_a_liquid_variable_for_the_blocks_after_it_assign_variab: "Sets a Liquid variable for the blocks after it: {% assign variable = value %}."
|
|
190
223
|
show_panels: "Show panels"
|
|
191
224
|
show_translations_in: "Show translations in"
|
|
192
225
|
show_when: "Show when"
|
|
@@ -195,9 +228,11 @@ en:
|
|
|
195
228
|
social: "Social"
|
|
196
229
|
solid: "Solid"
|
|
197
230
|
spacer: "Spacer"
|
|
231
|
+
spans_columns: "Spans columns"
|
|
198
232
|
strikethrough: "Strikethrough"
|
|
199
233
|
style: "Style"
|
|
200
234
|
subject: "Subject"
|
|
235
|
+
table: "Table"
|
|
201
236
|
text: "Text"
|
|
202
237
|
text_color: "Text color"
|
|
203
238
|
the_content_of_the_documents_using_this_layout_goes_here_wha: "The content of the documents using this layout goes here. What you put inside is example content for designing the layout."
|
|
@@ -206,6 +241,7 @@ en:
|
|
|
206
241
|
the_email_could_not_be_compiled: "The email could not be compiled"
|
|
207
242
|
the_name_could_not_be_rendered: "The %{name} could not be rendered"
|
|
208
243
|
the_name_each_item_gets_e_g_line: "The name each item gets, e.g. line."
|
|
244
|
+
the_name_the_blocks_after_it_use_e_g_lines: "The name the blocks after it use, e.g. lines."
|
|
209
245
|
the_upload: "The upload"
|
|
210
246
|
theme: "Theme"
|
|
211
247
|
there_are_no_languages_to_translate_into_yet: "There are no languages to translate into yet."
|
|
@@ -224,6 +260,7 @@ en:
|
|
|
224
260
|
uploaded: "Uploaded"
|
|
225
261
|
uploading: "Uploading…"
|
|
226
262
|
url: "URL"
|
|
263
|
+
value: "Value"
|
|
227
264
|
variable: "Variable"
|
|
228
265
|
variables: "Variables"
|
|
229
266
|
vertical: "Vertical"
|