tess_edit 0.5.1 → 0.5.3
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 +1 -1
- data/app/javascript/tess_edit/blocks/email.js +1 -1
- data/app/javascript/tess_edit/blocks/fields.js +25 -3
- data/app/javascript/tess_edit/blocks/navbar.js +1 -1
- data/app/javascript/tess_edit/ui/font_picker.js +141 -0
- data/app/javascript/tess_edit/ui/inspector.js +11 -0
- data/lib/tess_edit/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f82d8e8c56d5625f8f107f277eca46f3f925f1efd3a61c04869416f9cf22c1f0
|
|
4
|
+
data.tar.gz: 2ae16142383df65bc903ed777e1a8e040d9a48985ec326a7bc6d63488659da20
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 02ad9420d971ac73f9d86f594ef543f55ca3778ed31626d27b781714c9ba00886db964b6d7a98ce220dabc995cec61100ca20d0fdaa0bb9aaa327bba103deb20
|
|
7
|
+
data.tar.gz: 0c7596f3ffe417f49bee62cef20dde71c1cd9584c35df42c3dae41927442c1f209d6e3b6f4ae728b1f548b3cbff7aa46d96c043baac5f53547f470542120fc59
|
data/README.md
CHANGED
|
@@ -304,7 +304,7 @@ extendBlock("email", {
|
|
|
304
304
|
|
|
305
305
|
With a `summary` the field shows collapsed to it, with a button to edit it; without one the element always shows. Its values are your form fields, submitted with the form; without the element the field doesn't show. The element moves into Inspect once and stays there, hidden while another block is selected, so your Stimulus controllers in it keep their state. Combining or splitting the panels moves it again: its controllers reconnect then, with the values typed and chosen written into the fields' attributes first. The demo has one at `/?slots=1` (`test/dummy/app/javascript/slots.js`).
|
|
306
306
|
|
|
307
|
-
A select field's `options` can be a function of the editor, `options: (editor) => [...]`, for choices from your app. Give the editor those with `data-tess-edit-options-value` (JSON), which blocks read as `editor.options`.
|
|
307
|
+
A select field's `options` can be a function of the editor, `options: (editor) => [...]`, for choices from your app. Give the editor those with `data-tess-edit-options-value` (JSON), which blocks read as `editor.options`. Font family fields are a select of `editor.options.fonts`: CSS font families as text, `"Maytra"` or `"'EB Garamond', serif"`, or `{ value, label }`; without them, common web fonts (`fields.FONTS`). A font a design has that isn't among them stays selected. The field lists each font in itself, with a search box, so your page needs the fonts too, such as `@font-face` rules: a browser loads a font only once it's used, and the list shows fonts as they scroll into view.
|
|
308
308
|
|
|
309
309
|
## Kits
|
|
310
310
|
|
|
@@ -39,7 +39,7 @@ export default {
|
|
|
39
39
|
{
|
|
40
40
|
title: "Theme",
|
|
41
41
|
fields: [
|
|
42
|
-
{ key: "data.fontFamily", label: "Font family", type: "
|
|
42
|
+
{ key: "data.fontFamily", label: "Font family", type: "font" },
|
|
43
43
|
{ key: "data.fontSize", label: "Font size", type: "size" },
|
|
44
44
|
{ key: "data.lineHeight", label: "Line height", type: "text" },
|
|
45
45
|
{ key: "data.textColor", label: "Text color", type: "color" }
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
// Field definitions shared by the built-in blocks, and usable by custom ones.
|
|
2
2
|
// A field: { key: "attributes.padding" | "data.subject", label, type, ... }.
|
|
3
|
-
// Types: text, textarea, code, size, color, select, segmented, toggle,
|
|
4
|
-
// spacing, list and slot (an element of the host's); see ui/inspector.js. A
|
|
3
|
+
// Types: text, textarea, code, size, color, select, font, segmented, toggle,
|
|
4
|
+
// spacing, list and slot (an element of the host's); see ui/inspector.js. A
|
|
5
|
+
// font field is a select of the host's fonts, the editor's options.fonts, or
|
|
6
|
+
// FONTS without them. A select's options can be a
|
|
5
7
|
// function of the editor, options(editor), for choices the host gives. A
|
|
6
8
|
// field's hint can be a function of its value, hint(value, node), shown as
|
|
7
9
|
// it's typed (a counter).
|
|
@@ -20,6 +22,26 @@ export const VERTICAL_ALIGN = [
|
|
|
20
22
|
{ value: "bottom", label: "Bottom" }
|
|
21
23
|
]
|
|
22
24
|
|
|
25
|
+
// Fonts every browser and mail client has, with fallbacks
|
|
26
|
+
export const FONTS = [
|
|
27
|
+
{ value: "Arial, Helvetica, sans-serif", label: "Arial" },
|
|
28
|
+
{ value: "Helvetica, Arial, sans-serif", label: "Helvetica" },
|
|
29
|
+
{ value: "Verdana, Geneva, sans-serif", label: "Verdana" },
|
|
30
|
+
{ value: "Tahoma, Geneva, sans-serif", label: "Tahoma" },
|
|
31
|
+
{ value: "'Trebuchet MS', Helvetica, sans-serif", label: "Trebuchet MS" },
|
|
32
|
+
{ value: "Georgia, serif", label: "Georgia" },
|
|
33
|
+
{ value: "'Times New Roman', Times, serif", label: "Times New Roman" },
|
|
34
|
+
{ value: "'Courier New', Courier, monospace", label: "Courier New" }
|
|
35
|
+
]
|
|
36
|
+
|
|
37
|
+
// A font field's options: none (the placeholder, inherited), the host's
|
|
38
|
+
// fonts or FONTS, and a value that is neither, as it is
|
|
39
|
+
export function fontOptions(fonts, value, placeholder = "Default") {
|
|
40
|
+
const options = (fonts?.length ? fonts : FONTS).map((font) => (typeof font === "string" ? { value: font, label: font.split(",")[0].replace(/['"]/g, "").trim() } : font))
|
|
41
|
+
const other = value && !options.some((option) => option.value === value) ? [{ value, label: value }] : []
|
|
42
|
+
return [{ value: "", label: placeholder }, ...options, ...other]
|
|
43
|
+
}
|
|
44
|
+
|
|
23
45
|
export const padding = { key: "attributes.padding", label: "Padding", type: "spacing" }
|
|
24
46
|
export const align = { key: "attributes.align", label: "Align", type: "segmented", options: ALIGN }
|
|
25
47
|
export const background = { key: "attributes.background-color", label: "Background", type: "color" }
|
|
@@ -27,7 +49,7 @@ export const background = { key: "attributes.background-color", label: "Backgrou
|
|
|
27
49
|
export const typography = (extra = []) => ({
|
|
28
50
|
title: "Typography",
|
|
29
51
|
fields: [
|
|
30
|
-
{ key: "attributes.font-family", label: "Font family", type: "
|
|
52
|
+
{ key: "attributes.font-family", label: "Font family", type: "font", placeholder: "Inherit" },
|
|
31
53
|
{ key: "attributes.font-size", label: "Font size", type: "size", placeholder: "13px" },
|
|
32
54
|
{ key: "attributes.line-height", label: "Line height", type: "text", placeholder: "1" },
|
|
33
55
|
{ key: "attributes.letter-spacing", label: "Letter spacing", type: "size" },
|
|
@@ -33,7 +33,7 @@ export default {
|
|
|
33
33
|
fields: [
|
|
34
34
|
{ key: "data.color", label: "Color", type: "color" },
|
|
35
35
|
{ key: "data.fontSize", label: "Font size", type: "size" },
|
|
36
|
-
{ key: "data.fontFamily", label: "Font family", type: "
|
|
36
|
+
{ key: "data.fontFamily", label: "Font family", type: "font", placeholder: "Inherit" },
|
|
37
37
|
{ key: "data.linkPadding", label: "Padding", type: "spacing" }
|
|
38
38
|
]
|
|
39
39
|
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
// A font field's control: a button with the font in it, and a list to choose
|
|
2
|
+
// from, each font shown in itself, with a search box for long lists. A
|
|
3
|
+
// native select can't show its options in their own fonts (macOS draws it
|
|
4
|
+
// in the select's font). Fonts are shown as they scroll into view, so a long
|
|
5
|
+
// list only loads those seen; the host's page has to have the fonts (e.g. as
|
|
6
|
+
// @font-face rules, which load when used).
|
|
7
|
+
|
|
8
|
+
import { h } from "tess_edit/ui/dom"
|
|
9
|
+
|
|
10
|
+
const ITEM = "flex w-full items-center gap-2 px-2.5 py-1.5 text-left text-[15px]"
|
|
11
|
+
|
|
12
|
+
export class FontPicker {
|
|
13
|
+
// options: [{ value, label }], the first one none (the placeholder);
|
|
14
|
+
// choose(value) when one is chosen
|
|
15
|
+
constructor(editor, { options, value, input, choose }) {
|
|
16
|
+
this.editor = editor
|
|
17
|
+
this.options = options
|
|
18
|
+
this.value = value || ""
|
|
19
|
+
this.choose = choose
|
|
20
|
+
this.button = h("button", { type: "button", class: `${input} flex items-center justify-between gap-2 text-left`, "aria-haspopup": "listbox", onclick: () => (this.element ? this.close() : this.open()) })
|
|
21
|
+
this.onOutside = (event) => {
|
|
22
|
+
if (this.element && !this.element.contains(event.target) && !this.button.contains(event.target)) this.close()
|
|
23
|
+
}
|
|
24
|
+
this.label()
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// The chosen font's name, in it
|
|
28
|
+
label() {
|
|
29
|
+
const option = this.options.find((option) => option.value === this.value) || this.options[0]
|
|
30
|
+
this.button.replaceChildren(
|
|
31
|
+
h("span", { class: "min-w-0 flex-1 truncate", style: fontStyle(option.value) }, option.label),
|
|
32
|
+
h("span", { class: "shrink-0 text-gray-400 dark:text-gray-500", "aria-hidden": "true" }, "▾")
|
|
33
|
+
)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
open() {
|
|
37
|
+
this.query = ""
|
|
38
|
+
this.search = h("input", {
|
|
39
|
+
type: "search",
|
|
40
|
+
placeholder: "Search fonts",
|
|
41
|
+
class: "w-full rounded-md border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 px-2 py-1 text-[13px] text-gray-900 dark:text-gray-100 outline-none focus:border-blue-500",
|
|
42
|
+
oninput: (event) => {
|
|
43
|
+
this.query = event.target.value
|
|
44
|
+
this.index = 0
|
|
45
|
+
this.render()
|
|
46
|
+
},
|
|
47
|
+
onkeydown: (event) => this.key(event)
|
|
48
|
+
})
|
|
49
|
+
this.list = h("div", { class: "max-h-72 overflow-y-auto py-1", role: "listbox", "aria-label": "Fonts" })
|
|
50
|
+
this.element = h("div", { class: "absolute z-50 w-72 rounded-md border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800 shadow-lg" }, h("div", { class: "p-1.5 border-b border-gray-100 dark:border-gray-700" }, this.search), this.list)
|
|
51
|
+
this.editor.root.append(this.element)
|
|
52
|
+
this.observer = new IntersectionObserver((entries) => entries.forEach((entry) => entry.isIntersecting && show(entry.target)), { root: this.list })
|
|
53
|
+
document.addEventListener("mousedown", this.onOutside, true)
|
|
54
|
+
this.index = Math.max(0, this.matches().findIndex((option) => option.value === this.value))
|
|
55
|
+
this.render()
|
|
56
|
+
this.place()
|
|
57
|
+
this.search.focus()
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
matches() {
|
|
61
|
+
const query = this.query.trim().toLowerCase()
|
|
62
|
+
return query ? this.options.filter((option, i) => i > 0 && option.label.toLowerCase().includes(query)) : this.options
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
render() {
|
|
66
|
+
const matches = this.matches()
|
|
67
|
+
this.observer.disconnect()
|
|
68
|
+
const rows = matches.map((option, i) => {
|
|
69
|
+
const chosen = option.value === this.value
|
|
70
|
+
const row = h(
|
|
71
|
+
"button",
|
|
72
|
+
{
|
|
73
|
+
type: "button",
|
|
74
|
+
role: "option",
|
|
75
|
+
"aria-selected": chosen ? "true" : "false",
|
|
76
|
+
"data-font": option.value,
|
|
77
|
+
class: `${ITEM} ${i === this.index ? "bg-blue-50 dark:bg-blue-900/40 text-blue-800 dark:text-blue-200" : "text-gray-800 dark:text-gray-200 hover:bg-gray-50 dark:hover:bg-gray-700"}`,
|
|
78
|
+
onclick: () => this.pick(option)
|
|
79
|
+
},
|
|
80
|
+
h("span", { class: "w-3 shrink-0 text-[11px]" }, chosen ? "✓" : ""),
|
|
81
|
+
h("span", { class: "min-w-0 flex-1 truncate" }, option.label)
|
|
82
|
+
)
|
|
83
|
+
this.observer.observe(row)
|
|
84
|
+
return row
|
|
85
|
+
})
|
|
86
|
+
const empty = matches.length ? null : h("p", { class: "px-2.5 py-1.5 text-xs text-gray-500 dark:text-gray-400" }, "No fonts with that name")
|
|
87
|
+
this.list.replaceChildren(...rows, ...(empty ? [empty] : []))
|
|
88
|
+
rows[this.index]?.scrollIntoView({ block: "nearest" })
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
key(event) {
|
|
92
|
+
const matches = this.matches()
|
|
93
|
+
if ((event.key === "ArrowDown" || event.key === "ArrowUp") && matches.length) {
|
|
94
|
+
this.index = (this.index + (event.key === "ArrowDown" ? 1 : matches.length - 1)) % matches.length
|
|
95
|
+
this.render()
|
|
96
|
+
} else if (event.key === "Enter") {
|
|
97
|
+
if (matches[this.index]) this.pick(matches[this.index])
|
|
98
|
+
} else if (event.key === "Escape") {
|
|
99
|
+
this.close()
|
|
100
|
+
this.button.focus()
|
|
101
|
+
} else {
|
|
102
|
+
return
|
|
103
|
+
}
|
|
104
|
+
event.preventDefault()
|
|
105
|
+
event.stopPropagation()
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
pick(option) {
|
|
109
|
+
this.value = option.value
|
|
110
|
+
this.label()
|
|
111
|
+
this.close()
|
|
112
|
+
this.choose(option.value)
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Below the button, or above it when there's no room, inside the editor
|
|
116
|
+
place() {
|
|
117
|
+
const root = this.editor.root.getBoundingClientRect()
|
|
118
|
+
const rect = this.button.getBoundingClientRect()
|
|
119
|
+
const height = this.element.offsetHeight
|
|
120
|
+
const below = rect.bottom - root.top + 4
|
|
121
|
+
const top = below + height > root.height && rect.top - root.top - height - 4 > 0 ? rect.top - root.top - height - 4 : below
|
|
122
|
+
const left = Math.max(4, Math.min(rect.left - root.left, root.width - this.element.offsetWidth - 4))
|
|
123
|
+
Object.assign(this.element.style, { top: `${top}px`, left: `${left}px` })
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
close() {
|
|
127
|
+
this.observer?.disconnect()
|
|
128
|
+
this.element?.remove()
|
|
129
|
+
this.element = null
|
|
130
|
+
document.removeEventListener("mousedown", this.onOutside, true)
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// A row's font, once it shows
|
|
135
|
+
function show(row) {
|
|
136
|
+
if (row.dataset.font) row.style.fontFamily = row.dataset.font
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function fontStyle(value) {
|
|
140
|
+
return value ? `font-family: ${value}` : ""
|
|
141
|
+
}
|
|
@@ -16,10 +16,12 @@
|
|
|
16
16
|
|
|
17
17
|
import { imageSource } from "tess_edit/core/media"
|
|
18
18
|
import { getBlock, label } from "tess_edit/core/registry"
|
|
19
|
+
import { fontOptions } from "tess_edit/blocks/fields"
|
|
19
20
|
import { find, getValue } from "tess_edit/core/document"
|
|
20
21
|
import { translationCalls } from "tess_edit/core/translations"
|
|
21
22
|
import { loopScope } from "tess_edit/core/variables"
|
|
22
23
|
import { codeInput } from "tess_edit/ui/code_input"
|
|
24
|
+
import { FontPicker } from "tess_edit/ui/font_picker"
|
|
23
25
|
import { freeze, h, place } from "tess_edit/ui/dom"
|
|
24
26
|
import { icon } from "tess_edit/ui/icons"
|
|
25
27
|
import { inputAdapter, suggestIn } from "tess_edit/ui/variable_menu"
|
|
@@ -227,6 +229,9 @@ export class Inspector {
|
|
|
227
229
|
})
|
|
228
230
|
)
|
|
229
231
|
|
|
232
|
+
case "font":
|
|
233
|
+
return this.font(field, value, set)
|
|
234
|
+
|
|
230
235
|
case "segmented":
|
|
231
236
|
return h(
|
|
232
237
|
"div",
|
|
@@ -476,6 +481,12 @@ export class Inspector {
|
|
|
476
481
|
input.textarea.focus()
|
|
477
482
|
}
|
|
478
483
|
|
|
484
|
+
// The host's fonts (options.fonts) or common ones, each shown in itself (ui/font_picker.js)
|
|
485
|
+
font(field, value, set) {
|
|
486
|
+
const options = fontOptions(this.editor.options?.fonts, value, field.placeholder)
|
|
487
|
+
return new FontPicker(this.editor, { options, value, input: INPUT, choose: set }).button
|
|
488
|
+
}
|
|
489
|
+
|
|
479
490
|
color(value, set) {
|
|
480
491
|
const text = h("input", {
|
|
481
492
|
type: "text", class: `${INPUT} font-mono text-xs`, value, placeholder: "Default", oninput: (event) => {
|
data/lib/tess_edit/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: tess_edit
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.5.
|
|
4
|
+
version: 0.5.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Tom de Grunt
|
|
@@ -118,6 +118,7 @@ files:
|
|
|
118
118
|
- app/javascript/tess_edit/ui/code_input.js
|
|
119
119
|
- app/javascript/tess_edit/ui/dialog.js
|
|
120
120
|
- app/javascript/tess_edit/ui/dom.js
|
|
121
|
+
- app/javascript/tess_edit/ui/font_picker.js
|
|
121
122
|
- app/javascript/tess_edit/ui/free_layout.js
|
|
122
123
|
- app/javascript/tess_edit/ui/icons.js
|
|
123
124
|
- app/javascript/tess_edit/ui/inspector.js
|