tess_edit 0.6.2 → 0.6.4
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 -0
- data/app/javascript/tess_edit/controllers/editor_controller.js +31 -7
- data/app/javascript/tess_edit/core/color.js +31 -0
- data/app/javascript/tess_edit/ui/canvas.js +120 -0
- data/app/javascript/tess_edit/ui/inspector.js +54 -28
- data/config/locales/en.yml +2 -0
- data/config/locales/nl.yml +2 -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: 33f9692789fccf3b721207f4580b05f5239b28446db19337d55f9151159fbdb2
|
|
4
|
+
data.tar.gz: 0f96d538e9e5614fc185ea2fa7c43e046f412ce5b152e3559dad289e3a6047c6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 14b571ccf3f5aa9bba36439c852c2a13ae14ef2243d3db11333c9c5e262fd06c33d0522d0b116daf4f8f76db3b715e109d4df773faa50f04668cc0580788b255
|
|
7
|
+
data.tar.gz: f6c17136fff60e6ff8474589d7cf5aaa555896302b5d1a6083005149087c2dc1eaf41009b3fa35ab8158c0d9bb7b1e298d429ee9ba947a02cdf42fe7ece083f4
|
data/README.md
CHANGED
|
@@ -33,6 +33,7 @@ Liquid is completed as you type, in text and in settings:
|
|
|
33
33
|
- A preview of the output, and the canvas at the widths a kit gives, such as an email's desktop and mobile.
|
|
34
34
|
- Panels on both sides, or combined as tabs in one sidebar on the left or right to give the canvas more room; each tab can be dragged to the other side.
|
|
35
35
|
- Zoom on the canvas: buttons, ⌘+ / ⌘− / ⌘0, ⇧1 to fit, and pinch or ⌘ and the wheel.
|
|
36
|
+
- Panning the canvas: drag its background, or anywhere with Space held or the middle button.
|
|
36
37
|
- Dark mode that follows the host app's.
|
|
37
38
|
- Code dialog to view, copy or download the JSON and the kit's outputs, and to load JSON.
|
|
38
39
|
- Kits: any kind of document, registered by your app or a gem, with its own blocks and output and TessEdit's blocks brought in.
|
|
@@ -326,6 +326,15 @@ export default class extends Controller {
|
|
|
326
326
|
})
|
|
327
327
|
}
|
|
328
328
|
|
|
329
|
+
// Takes the image out of a block's image field, as one undo step
|
|
330
|
+
clearImage(id, field = IMAGE_FIELD) {
|
|
331
|
+
if (!this.canEditField(id, field.key)) return
|
|
332
|
+
this.commit((doc) => {
|
|
333
|
+
setValue(doc, id, field.image, "")
|
|
334
|
+
setValue(doc, id, field.key, "")
|
|
335
|
+
})
|
|
336
|
+
}
|
|
337
|
+
|
|
329
338
|
// An image file dropped on a block: shown at once, then uploaded
|
|
330
339
|
async dropImage(id, file, field = IMAGE_FIELD) {
|
|
331
340
|
this.select(id)
|
|
@@ -367,6 +376,7 @@ export default class extends Controller {
|
|
|
367
376
|
document.removeEventListener("mousedown", this.outsideClick)
|
|
368
377
|
document.removeEventListener("keydown", this.menuKeydown, true)
|
|
369
378
|
window.removeEventListener("resize", this.closeMenuOnResize)
|
|
379
|
+
window.removeEventListener("blur", this.endPanReady)
|
|
370
380
|
this.root?.remove()
|
|
371
381
|
delete this.element.tessEdit
|
|
372
382
|
}
|
|
@@ -480,7 +490,7 @@ export default class extends Controller {
|
|
|
480
490
|
|
|
481
491
|
this.root = h(
|
|
482
492
|
"div",
|
|
483
|
-
{ class: `tess-edit relative flex flex-col h-full min-h-[560px] overflow-hidden ${this.frameValue ? "rounded-lg border border-gray-200 dark:border-gray-700 " : ""}bg-gray-50 dark:bg-gray-900 text-sm text-gray-800 dark:text-gray-200 antialiased dark:[color-scheme:dark]`, tabindex: "-1", onkeydown: (event) => this.onKeydown(event) },
|
|
493
|
+
{ class: `tess-edit relative flex flex-col h-full min-h-[560px] overflow-hidden ${this.frameValue ? "rounded-lg border border-gray-200 dark:border-gray-700 " : ""}bg-gray-50 dark:bg-gray-900 text-sm text-gray-800 dark:text-gray-200 antialiased dark:[color-scheme:dark]`, tabindex: "-1", onkeydown: (event) => this.onKeydown(event), onkeyup: (event) => this.onKeyup(event) },
|
|
484
494
|
this.topBar,
|
|
485
495
|
this.body
|
|
486
496
|
)
|
|
@@ -510,6 +520,8 @@ export default class extends Controller {
|
|
|
510
520
|
}
|
|
511
521
|
}
|
|
512
522
|
this.closeMenuOnResize = () => this.closeMenu()
|
|
523
|
+
this.endPanReady = () => this.canvas.pan.setReady(false)
|
|
524
|
+
window.addEventListener("blur", this.endPanReady)
|
|
513
525
|
document.addEventListener("mousedown", this.outsideClick)
|
|
514
526
|
document.addEventListener("keydown", this.menuKeydown, true)
|
|
515
527
|
window.addEventListener("resize", this.closeMenuOnResize)
|
|
@@ -1407,9 +1419,16 @@ export default class extends Controller {
|
|
|
1407
1419
|
|
|
1408
1420
|
// --- keyboard -----------------------------------------------------------------
|
|
1409
1421
|
|
|
1422
|
+
onKeyup(event) {
|
|
1423
|
+
if (event.code === "Space") this.canvas.pan.setReady(false)
|
|
1424
|
+
}
|
|
1425
|
+
|
|
1410
1426
|
onKeydown(event) {
|
|
1411
1427
|
const target = event.target
|
|
1412
1428
|
const typing = target.closest?.("input, textarea, select, [contenteditable='true']")
|
|
1429
|
+
// A text field undoes its own typing; a select, a checkbox or a button has
|
|
1430
|
+
// no undo of its own, so ⌘Z there is the editor's
|
|
1431
|
+
const ownUndo = target.closest?.("textarea, [contenteditable='true'], input:not([type=checkbox], [type=radio], [type=file], [type=button], [type=submit], [type=range], [type=color])")
|
|
1413
1432
|
const mod = event.metaKey || event.ctrlKey
|
|
1414
1433
|
|
|
1415
1434
|
if (this.menu && event.key === "Escape") {
|
|
@@ -1437,16 +1456,21 @@ export default class extends Controller {
|
|
|
1437
1456
|
event.key === "0" ? this.setZoom(1) : this.zoomBy(event.key === "-" ? -1 : 1)
|
|
1438
1457
|
return
|
|
1439
1458
|
}
|
|
1459
|
+
if (mod && !event.altKey && !ownUndo && ["z", "y"].includes(event.key.toLowerCase())) {
|
|
1460
|
+
event.preventDefault()
|
|
1461
|
+
event.shiftKey || event.key.toLowerCase() === "y" ? this.redo() : this.undo()
|
|
1462
|
+
return
|
|
1463
|
+
}
|
|
1440
1464
|
if (typing) return
|
|
1465
|
+
// Space held: the canvas is dragged around (Pan, ui/canvas.js)
|
|
1466
|
+
if (event.code === "Space" && !mod && !event.altKey) {
|
|
1467
|
+
event.preventDefault()
|
|
1468
|
+
this.canvas.pan.setReady(true)
|
|
1469
|
+
return
|
|
1470
|
+
}
|
|
1441
1471
|
if (event.shiftKey && !mod && !event.altKey && event.code === "Digit1") {
|
|
1442
1472
|
event.preventDefault()
|
|
1443
1473
|
this.zoomToFit()
|
|
1444
|
-
} else if (mod && event.key.toLowerCase() === "z") {
|
|
1445
|
-
event.preventDefault()
|
|
1446
|
-
event.shiftKey ? this.redo() : this.undo()
|
|
1447
|
-
} else if (mod && event.key.toLowerCase() === "y") {
|
|
1448
|
-
event.preventDefault()
|
|
1449
|
-
this.redo()
|
|
1450
1474
|
} else if (mod && event.key.toLowerCase() === "d") {
|
|
1451
1475
|
event.preventDefault()
|
|
1452
1476
|
if (this.selectedId !== this.doc.id) this.duplicate(this.selectedId)
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// A color field's value as a color and its opacity, for its swatch and its
|
|
2
|
+
// Opacity slider: #rgb, #rrggbb, #rrggbbaa, rgb(), rgba() and transparent.
|
|
3
|
+
// Anything else (a color's name, Liquid) isn't read: null.
|
|
4
|
+
export function parseColor(value) {
|
|
5
|
+
const text = String(value ?? "").trim().toLowerCase()
|
|
6
|
+
if (text === "transparent") return { hex: "#ffffff", alpha: 0 }
|
|
7
|
+
|
|
8
|
+
let match = text.match(/^#([0-9a-f]{3})$/)
|
|
9
|
+
if (match) return { hex: `#${[...match[1]].map((digit) => digit + digit).join("")}`, alpha: 1 }
|
|
10
|
+
|
|
11
|
+
match = text.match(/^#([0-9a-f]{6})([0-9a-f]{2})?$/)
|
|
12
|
+
if (match) return { hex: `#${match[1]}`, alpha: match[2] ? round(parseInt(match[2], 16) / 255) : 1 }
|
|
13
|
+
|
|
14
|
+
match = text.match(/^rgba?\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*(?:,\s*([\d.]+)(%?)\s*)?\)$/)
|
|
15
|
+
if (!match) return null
|
|
16
|
+
const channels = match.slice(1, 4).map(Number)
|
|
17
|
+
const alpha = match[4] === undefined ? 1 : Number(match[4]) / (match[5] ? 100 : 1)
|
|
18
|
+
if (channels.some((channel) => channel > 255) || !(alpha >= 0 && alpha <= 1)) return null
|
|
19
|
+
return { hex: `#${channels.map((channel) => channel.toString(16).padStart(2, "0")).join("")}`, alpha: round(alpha) }
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Its hex when it's opaque, else rgba(), which email clients take best
|
|
23
|
+
export function formatColor(hex, alpha) {
|
|
24
|
+
if (alpha >= 1) return hex
|
|
25
|
+
const [red, green, blue] = [1, 3, 5].map((index) => parseInt(hex.slice(index, index + 2), 16))
|
|
26
|
+
return `rgba(${red}, ${green}, ${blue}, ${round(alpha)})`
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function round(alpha) {
|
|
30
|
+
return Math.round(alpha * 100) / 100
|
|
31
|
+
}
|
|
@@ -59,6 +59,8 @@ a{cursor:default}
|
|
|
59
59
|
.ProseMirror .tess-v-filled{cursor:text}
|
|
60
60
|
.tess-v-hidden{display:none}
|
|
61
61
|
.tess-v-empty{border-radius:3px;background:rgba(220,38,38,.08);box-shadow:inset 0 -1px 0 rgba(220,38,38,.65)}
|
|
62
|
+
html.tess-pan-ready,html.tess-pan-ready *{cursor:grab!important}
|
|
63
|
+
html.tess-panning,html.tess-panning *{cursor:grabbing!important;user-select:none!important}
|
|
62
64
|
.tess-liquid-error{text-decoration:underline wavy rgba(220,38,38,.9);text-decoration-skip-ink:none;text-underline-offset:3px}
|
|
63
65
|
`
|
|
64
66
|
|
|
@@ -89,6 +91,7 @@ export class Canvas {
|
|
|
89
91
|
this.hoverId = null
|
|
90
92
|
this.mode = "edit"
|
|
91
93
|
this.free = new FreeLayout(this)
|
|
94
|
+
this.pan = new Pan(this)
|
|
92
95
|
}
|
|
93
96
|
|
|
94
97
|
get doc() {
|
|
@@ -120,6 +123,13 @@ export class Canvas {
|
|
|
120
123
|
this.win.scrollTo(0, scrollY)
|
|
121
124
|
// ⌘ or Ctrl and the wheel, or a pinch on a trackpad, zooms where the pointer is
|
|
122
125
|
doc.addEventListener("wheel", (event) => this.onWheel(event), { passive: false })
|
|
126
|
+
// Space held or the middle button drags the canvas around; in the editor,
|
|
127
|
+
// so does a drag from its background (see Pan)
|
|
128
|
+
doc.addEventListener("pointerdown", (event) => this.pan.onPointerDown(event), true)
|
|
129
|
+
// Not the browser's own scrolling with the middle button
|
|
130
|
+
doc.addEventListener("mousedown", (event) => event.button === 1 && event.preventDefault(), true)
|
|
131
|
+
doc.addEventListener("keyup", (event) => this.editor.onKeyup(event))
|
|
132
|
+
this.pan.showReady()
|
|
123
133
|
if (mode === "edit") {
|
|
124
134
|
this.listen()
|
|
125
135
|
this.annotate()
|
|
@@ -540,6 +550,7 @@ export class Canvas {
|
|
|
540
550
|
if (event.target.closest?.("#tess-overlay")) return
|
|
541
551
|
event.preventDefault()
|
|
542
552
|
if (this.resized) return
|
|
553
|
+
if (this.pan.swallowClick()) return
|
|
543
554
|
if (this.openLink(event)) return
|
|
544
555
|
if (this.free.swallowClick()) return
|
|
545
556
|
const hit = this.hit(event.target)
|
|
@@ -754,3 +765,112 @@ export function showText(element, value) {
|
|
|
754
765
|
})
|
|
755
766
|
)
|
|
756
767
|
}
|
|
768
|
+
|
|
769
|
+
// Moving the canvas around by dragging it, as its scroll position: with
|
|
770
|
+
// Space held or the middle button anywhere, or, in the editor, from its
|
|
771
|
+
// background (no block but the root under the pointer) once it has moved a
|
|
772
|
+
// little, so a click there still selects the root. The pointer is the
|
|
773
|
+
// iframe's, so the content follows it whatever the zoom.
|
|
774
|
+
const PAN_THRESHOLD = 4
|
|
775
|
+
|
|
776
|
+
export class Pan {
|
|
777
|
+
constructor(canvas) {
|
|
778
|
+
this.canvas = canvas
|
|
779
|
+
this.ready = false
|
|
780
|
+
this.gesture = null
|
|
781
|
+
this.panned = false
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
get editor() {
|
|
785
|
+
return this.canvas.editor
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
// Space held: the canvas shows it can be dragged
|
|
789
|
+
setReady(ready) {
|
|
790
|
+
if (ready === this.ready) return
|
|
791
|
+
this.ready = ready
|
|
792
|
+
this.showReady()
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
showReady() {
|
|
796
|
+
this.canvas.doc?.documentElement?.classList.toggle("tess-pan-ready", this.ready && !this.gesture)
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
onPointerDown(event) {
|
|
800
|
+
const canvas = this.canvas
|
|
801
|
+
if (this.gesture || this.editor.editingId || canvas.free.dragging) return
|
|
802
|
+
const background = event.button === 0 && canvas.mode === "edit" && !event.target.closest?.("#tess-overlay") && this.isBackground(event.target)
|
|
803
|
+
const now = event.button === 1 || (event.button === 0 && this.ready)
|
|
804
|
+
if (!now && !background) return
|
|
805
|
+
if (now) {
|
|
806
|
+
event.preventDefault()
|
|
807
|
+
event.stopPropagation()
|
|
808
|
+
}
|
|
809
|
+
const win = canvas.win
|
|
810
|
+
this.gesture = { x: event.clientX, y: event.clientY, scrollX: win.scrollX, scrollY: win.scrollY, active: now, pointerId: event.pointerId, target: event.target }
|
|
811
|
+
if (now) this.activate()
|
|
812
|
+
const doc = canvas.doc
|
|
813
|
+
this.onMove = (moveEvent) => this.move(moveEvent)
|
|
814
|
+
this.onUp = (upEvent) => this.end(upEvent)
|
|
815
|
+
doc.addEventListener("pointermove", this.onMove)
|
|
816
|
+
doc.addEventListener("pointerup", this.onUp)
|
|
817
|
+
doc.addEventListener("pointercancel", this.onUp)
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
// Nothing but the root under the pointer: what a kit draws around its blocks
|
|
821
|
+
isBackground(target) {
|
|
822
|
+
const hit = this.canvas.hit(target)
|
|
823
|
+
if (hit?.placeholder) return false
|
|
824
|
+
if (hit && hit.id !== this.editor.doc.id) return false
|
|
825
|
+
// Not a field or link of the kit's own
|
|
826
|
+
return !target.closest?.("a, button, input, select, textarea, [contenteditable='true'], .ProseMirror")
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
activate() {
|
|
830
|
+
const gesture = this.gesture
|
|
831
|
+
gesture.active = true
|
|
832
|
+
try {
|
|
833
|
+
gesture.target.setPointerCapture?.(gesture.pointerId)
|
|
834
|
+
} catch {}
|
|
835
|
+
const root = this.canvas.doc.documentElement
|
|
836
|
+
root.classList.add("tess-panning")
|
|
837
|
+
root.classList.remove("tess-pan-ready")
|
|
838
|
+
this.editor.closeMenu()
|
|
839
|
+
this.canvas.setHover(null)
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
move(event) {
|
|
843
|
+
const gesture = this.gesture
|
|
844
|
+
if (!gesture || event.pointerId !== gesture.pointerId) return
|
|
845
|
+
const dx = event.clientX - gesture.x
|
|
846
|
+
const dy = event.clientY - gesture.y
|
|
847
|
+
if (!gesture.active) {
|
|
848
|
+
if (Math.hypot(dx, dy) < PAN_THRESHOLD) return
|
|
849
|
+
this.activate()
|
|
850
|
+
}
|
|
851
|
+
event.preventDefault()
|
|
852
|
+
// The pointer's place in the viewport, which scrolling doesn't change
|
|
853
|
+
this.canvas.win.scrollTo(gesture.scrollX - dx, gesture.scrollY - dy)
|
|
854
|
+
}
|
|
855
|
+
|
|
856
|
+
end(event) {
|
|
857
|
+
const gesture = this.gesture
|
|
858
|
+
if (!gesture || (event && event.pointerId !== gesture.pointerId)) return
|
|
859
|
+
const doc = this.canvas.doc
|
|
860
|
+
doc.removeEventListener("pointermove", this.onMove)
|
|
861
|
+
doc.removeEventListener("pointerup", this.onUp)
|
|
862
|
+
doc.removeEventListener("pointercancel", this.onUp)
|
|
863
|
+
doc.documentElement.classList.remove("tess-panning")
|
|
864
|
+
this.gesture = null
|
|
865
|
+
// The click that ends a pan doesn't select
|
|
866
|
+
if (gesture.active) {
|
|
867
|
+
this.panned = true
|
|
868
|
+
setTimeout(() => (this.panned = false))
|
|
869
|
+
}
|
|
870
|
+
this.showReady()
|
|
871
|
+
}
|
|
872
|
+
|
|
873
|
+
swallowClick() {
|
|
874
|
+
return this.panned
|
|
875
|
+
}
|
|
876
|
+
}
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
// host's Stimulus controllers in it keep their state: it and its group stay
|
|
15
15
|
// in Inspect, hidden while another block is selected (see place in ui/dom.js).
|
|
16
16
|
|
|
17
|
+
import { formatColor, parseColor } from "tess_edit/core/color"
|
|
17
18
|
import { t } from "tess_edit/core/i18n"
|
|
18
19
|
import { imageSource } from "tess_edit/core/media"
|
|
19
20
|
import { fieldType, getBlock, label } from "tess_edit/core/registry"
|
|
@@ -78,6 +79,9 @@ export class Inspector {
|
|
|
78
79
|
}
|
|
79
80
|
|
|
80
81
|
render() {
|
|
82
|
+
// A control that's drawn again loses focus: the editor keeps it, so its
|
|
83
|
+
// keys (⌘Z) still work
|
|
84
|
+
const focused = this.element?.contains(document.activeElement)
|
|
81
85
|
const { doc, selectedId } = this.editor
|
|
82
86
|
const hit = find(doc, selectedId) || { node: doc }
|
|
83
87
|
const node = hit.node
|
|
@@ -119,6 +123,7 @@ export class Inspector {
|
|
|
119
123
|
|
|
120
124
|
place(this.body, [locked, hint, ...groups].filter(Boolean), new Set([...this.keptGroups.values()].map((kept) => kept.details)))
|
|
121
125
|
this.showLiquidProblems()
|
|
126
|
+
if (focused && !this.element.contains(document.activeElement)) this.editor.root?.focus({ preventScroll: true })
|
|
122
127
|
}
|
|
123
128
|
|
|
124
129
|
// Under a field with Liquid, what's wrong with it (core/liquid_check.js),
|
|
@@ -187,9 +192,11 @@ export class Inspector {
|
|
|
187
192
|
const set = (next, options = {}) => this.editor.setValue(node.id, field.key, next, options)
|
|
188
193
|
// A fieldset disables every input and button of a locked field at once.
|
|
189
194
|
const editable = this.editor.canEditField(node.id, field.key)
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
195
|
+
// A toggle is its checkbox next to its label, which clicks it: checked is on
|
|
196
|
+
const own = field.type === "toggle"
|
|
197
|
+
? h("label", { class: "flex cursor-pointer items-center gap-2 text-xs font-medium text-gray-700 dark:text-gray-300" }, this.control(node, field, value, set), h("span", {}, t(field.label)))
|
|
198
|
+
: this.control(node, field, value, set)
|
|
199
|
+
const control = editable ? own : h("fieldset", { disabled: true, class: "opacity-60" }, own)
|
|
193
200
|
const expand = field.type === "code" && editable
|
|
194
201
|
? h("button", { type: "button", title: t("Edit %{label} in a larger window", { label: t(field.label) }), class: "rounded px-1 text-[11px] font-medium text-blue-600 dark:text-blue-400 hover:bg-blue-50 dark:hover:bg-blue-900/40", onclick: () => this.expand(node, field) }, t("Expand"))
|
|
195
202
|
: null
|
|
@@ -216,7 +223,7 @@ export class Inspector {
|
|
|
216
223
|
return h(
|
|
217
224
|
"div",
|
|
218
225
|
{ class: "relative block", oninput: typeof field.hint === "function" ? showHint : null },
|
|
219
|
-
h("span", { class: "mb-1 block text-xs font-medium text-gray-700 dark:text-gray-300" }, t(field.label)),
|
|
226
|
+
field.type === "toggle" ? null : h("span", { class: "mb-1 block text-xs font-medium text-gray-700 dark:text-gray-300" }, t(field.label)),
|
|
220
227
|
tools,
|
|
221
228
|
control,
|
|
222
229
|
input ? this.translationHint(input) : null,
|
|
@@ -291,23 +298,14 @@ export class Inspector {
|
|
|
291
298
|
)
|
|
292
299
|
)
|
|
293
300
|
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
return h(
|
|
297
|
-
"
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
checked: value === field.on,
|
|
303
|
-
onchange: (event) => {
|
|
304
|
-
set(event.target.checked ? field.on : field.off)
|
|
305
|
-
state.textContent = t(event.target.checked ? "On" : "Off")
|
|
306
|
-
}
|
|
307
|
-
}),
|
|
308
|
-
state
|
|
309
|
-
)
|
|
310
|
-
}
|
|
301
|
+
// Only its checkbox: field() puts it next to its label
|
|
302
|
+
case "toggle":
|
|
303
|
+
return h("input", {
|
|
304
|
+
type: "checkbox",
|
|
305
|
+
class: "h-4 w-4 shrink-0 rounded border-gray-300 dark:border-gray-600 dark:bg-gray-700 text-blue-600 dark:text-blue-400",
|
|
306
|
+
checked: value === field.on,
|
|
307
|
+
onchange: (event) => set(event.target.checked ? field.on : field.off)
|
|
308
|
+
})
|
|
311
309
|
|
|
312
310
|
case "spacing":
|
|
313
311
|
return this.spacing(value, set)
|
|
@@ -461,12 +459,13 @@ export class Inspector {
|
|
|
461
459
|
"select",
|
|
462
460
|
{
|
|
463
461
|
class: `${INPUT} min-w-0 flex-1 pr-7`,
|
|
462
|
+
// The empty choice takes the image out
|
|
464
463
|
onchange: (event) => {
|
|
465
464
|
const image = images.find((option) => option.id === event.target.value)
|
|
466
|
-
|
|
465
|
+
image ? this.editor.chooseImage(node.id, image, field) : this.editor.clearImage(node.id, field)
|
|
467
466
|
}
|
|
468
467
|
},
|
|
469
|
-
h("option", { value: "" }, t(images.length ? "Choose an image" : "No images yet")),
|
|
468
|
+
h("option", { value: "" }, t(value ? "No image" : images.length ? "Choose an image" : "No images yet")),
|
|
470
469
|
images.map((image) => h("option", { value: image.id, selected: image.id === value }, image.name))
|
|
471
470
|
)
|
|
472
471
|
return h(
|
|
@@ -528,23 +527,50 @@ export class Inspector {
|
|
|
528
527
|
return new FontPicker(this.editor, { options, value, input: INPUT, choose: set }).button
|
|
529
528
|
}
|
|
530
529
|
|
|
530
|
+
// A color: its swatch, its value as text (any CSS color, or Liquid), and
|
|
531
|
+
// its opacity, 0% transparent (core/color.js). A value the slider can't
|
|
532
|
+
// read, such as a color's name or Liquid, leaves it off.
|
|
531
533
|
color(value, set) {
|
|
534
|
+
let color = parseColor(value)
|
|
535
|
+
const change = (next) => {
|
|
536
|
+
text.value = next
|
|
537
|
+
set(next)
|
|
538
|
+
show()
|
|
539
|
+
}
|
|
532
540
|
const text = h("input", {
|
|
533
541
|
type: "text", class: `${INPUT} font-mono text-xs`, value, placeholder: t("Default"), oninput: (event) => {
|
|
534
542
|
set(event.target.value)
|
|
535
|
-
|
|
543
|
+
color = parseColor(event.target.value)
|
|
544
|
+
if (color) swatch.value = color.hex
|
|
545
|
+
show(event.target.value)
|
|
536
546
|
}
|
|
537
547
|
})
|
|
538
548
|
const swatch = h("input", {
|
|
539
549
|
type: "color",
|
|
540
550
|
class: "h-7 w-8 shrink-0 cursor-pointer rounded border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 p-0.5",
|
|
541
|
-
value:
|
|
551
|
+
value: color?.hex || "#ffffff",
|
|
542
552
|
oninput: (event) => {
|
|
543
|
-
|
|
544
|
-
|
|
553
|
+
color = { hex: event.target.value, alpha: color?.alpha ?? 1 }
|
|
554
|
+
change(formatColor(color.hex, color.alpha))
|
|
555
|
+
}
|
|
556
|
+
})
|
|
557
|
+
const percent = h("span", { class: "w-9 shrink-0 text-right text-[11px] tabular-nums text-gray-500 dark:text-gray-400" })
|
|
558
|
+
const opacity = h("input", {
|
|
559
|
+
type: "range", min: "0", max: "100", step: "1",
|
|
560
|
+
class: "h-1.5 min-w-0 flex-1 cursor-pointer accent-blue-600 disabled:cursor-default disabled:opacity-40",
|
|
561
|
+
title: t("Opacity"), "aria-label": t("Opacity"),
|
|
562
|
+
oninput: (event) => {
|
|
563
|
+
color = { hex: color?.hex || swatch.value, alpha: Number(event.target.value) / 100 }
|
|
564
|
+
change(formatColor(color.hex, color.alpha))
|
|
545
565
|
}
|
|
546
566
|
})
|
|
547
|
-
|
|
567
|
+
const show = (current = text.value) => {
|
|
568
|
+
opacity.disabled = !color && current.trim() !== ""
|
|
569
|
+
opacity.value = String(Math.round((color?.alpha ?? 1) * 100))
|
|
570
|
+
percent.textContent = `${opacity.value}%`
|
|
571
|
+
}
|
|
572
|
+
show(value || "")
|
|
573
|
+
return h("span", { class: "block space-y-1.5" }, h("span", { class: "flex items-center gap-1.5" }, swatch, text), h("span", { class: "flex items-center gap-2", title: t("Opacity") }, opacity, percent))
|
|
548
574
|
}
|
|
549
575
|
|
|
550
576
|
spacing(value, set) {
|
data/config/locales/en.yml
CHANGED
|
@@ -191,6 +191,7 @@ en:
|
|
|
191
191
|
new_tab: "New tab"
|
|
192
192
|
no_argument_for_names_in_the_t_filter: "No argument for %{names} in the t filter"
|
|
193
193
|
no_fonts_with_that_name: "No fonts with that name"
|
|
194
|
+
no_image: "No image"
|
|
194
195
|
no_images_yet: "No images yet"
|
|
195
196
|
no_languages_yet: "No languages yet"
|
|
196
197
|
no_variables_here: "No variables here"
|
|
@@ -199,6 +200,7 @@ en:
|
|
|
199
200
|
numbered_list: "Numbered list"
|
|
200
201
|
off_word: "Off"
|
|
201
202
|
on_word: "On"
|
|
203
|
+
opacity: "Opacity"
|
|
202
204
|
open_in: "Open in"
|
|
203
205
|
open_source: "Open %{source}"
|
|
204
206
|
open_where_it_s_kept: "Open where it's kept"
|
data/config/locales/nl.yml
CHANGED
|
@@ -191,6 +191,7 @@ nl:
|
|
|
191
191
|
new_tab: "Nieuw tabblad"
|
|
192
192
|
no_argument_for_names_in_the_t_filter: "Geen argument voor %{names} in het t-filter"
|
|
193
193
|
no_fonts_with_that_name: "Geen lettertypen met die naam"
|
|
194
|
+
no_image: "Geen afbeelding"
|
|
194
195
|
no_images_yet: "Nog geen afbeeldingen"
|
|
195
196
|
no_languages_yet: "Nog geen talen"
|
|
196
197
|
no_variables_here: "Hier zijn geen variabelen"
|
|
@@ -199,6 +200,7 @@ nl:
|
|
|
199
200
|
numbered_list: "Genummerde lijst"
|
|
200
201
|
off_word: "Uit"
|
|
201
202
|
on_word: "Aan"
|
|
203
|
+
opacity: "Dekking"
|
|
202
204
|
open_in: "Openen in"
|
|
203
205
|
open_source: "%{source} openen"
|
|
204
206
|
open_where_it_s_kept: "Openen waar het staat"
|
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.6.
|
|
4
|
+
version: 0.6.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Tom de Grunt
|
|
@@ -83,6 +83,7 @@ files:
|
|
|
83
83
|
- app/javascript/tess_edit/blocks/table.js
|
|
84
84
|
- app/javascript/tess_edit/blocks/text.js
|
|
85
85
|
- app/javascript/tess_edit/controllers/editor_controller.js
|
|
86
|
+
- app/javascript/tess_edit/core/color.js
|
|
86
87
|
- app/javascript/tess_edit/core/document.js
|
|
87
88
|
- app/javascript/tess_edit/core/history.js
|
|
88
89
|
- app/javascript/tess_edit/core/i18n.js
|