tess_edit 0.6.2 → 0.6.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4606ec9405953c28850c78e56ba84dbd98746d3b5304908915cb122130b0ad54
4
- data.tar.gz: 6b97b338496fa61698751df3f4fadb6307e583a1ada2be8ccd9e903fad99f17b
3
+ metadata.gz: c3d67adc7a3fb980851a6f7d15dbfb6c0be257627d7da6e376ef1eb026168923
4
+ data.tar.gz: 48b26477825363cf6522ba0ebc03aa7ec8f33358416353df412bf763e584afcd
5
5
  SHA512:
6
- metadata.gz: 6cf843dc450464c7273b05f24f38f9299a91525785a1dea7291ae1aa3d00228f4bddf8559c0721ad1516146c79006fb1b4a69c691ff7682e3ab633e78441937c
7
- data.tar.gz: faf9a015532294fa7d5dbf2cfcead3085a7e93acf634d37c7ee5adbc063e6628b08ce7785d364688f2ba74e4064b190fa71b0c22aed80f257a396e94dd19a3eb
6
+ metadata.gz: 27e7d60dbbfeef61adc64aebb42848c7d3ec43122f0c075a3bfd409c7d37c84a7bbd6482df95d3c0124b81fcbef21a1f0868291d3be7ff50f3913c7ea81cc001
7
+ data.tar.gz: 869f784a685769ffa46bf7ccaccb7ed8f58ad21c0815550e0ee85a6d68b397af05c7b45e61768f221d1fe18ca3609edacddf3b76a0890e9dc7e654c239972986
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.
@@ -367,6 +367,7 @@ export default class extends Controller {
367
367
  document.removeEventListener("mousedown", this.outsideClick)
368
368
  document.removeEventListener("keydown", this.menuKeydown, true)
369
369
  window.removeEventListener("resize", this.closeMenuOnResize)
370
+ window.removeEventListener("blur", this.endPanReady)
370
371
  this.root?.remove()
371
372
  delete this.element.tessEdit
372
373
  }
@@ -480,7 +481,7 @@ export default class extends Controller {
480
481
 
481
482
  this.root = h(
482
483
  "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) },
484
+ { 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
485
  this.topBar,
485
486
  this.body
486
487
  )
@@ -510,6 +511,8 @@ export default class extends Controller {
510
511
  }
511
512
  }
512
513
  this.closeMenuOnResize = () => this.closeMenu()
514
+ this.endPanReady = () => this.canvas.pan.setReady(false)
515
+ window.addEventListener("blur", this.endPanReady)
513
516
  document.addEventListener("mousedown", this.outsideClick)
514
517
  document.addEventListener("keydown", this.menuKeydown, true)
515
518
  window.addEventListener("resize", this.closeMenuOnResize)
@@ -1407,6 +1410,10 @@ export default class extends Controller {
1407
1410
 
1408
1411
  // --- keyboard -----------------------------------------------------------------
1409
1412
 
1413
+ onKeyup(event) {
1414
+ if (event.code === "Space") this.canvas.pan.setReady(false)
1415
+ }
1416
+
1410
1417
  onKeydown(event) {
1411
1418
  const target = event.target
1412
1419
  const typing = target.closest?.("input, textarea, select, [contenteditable='true']")
@@ -1438,6 +1445,12 @@ export default class extends Controller {
1438
1445
  return
1439
1446
  }
1440
1447
  if (typing) return
1448
+ // Space held: the canvas is dragged around (Pan, ui/canvas.js)
1449
+ if (event.code === "Space" && !mod && !event.altKey) {
1450
+ event.preventDefault()
1451
+ this.canvas.pan.setReady(true)
1452
+ return
1453
+ }
1441
1454
  if (event.shiftKey && !mod && !event.altKey && event.code === "Digit1") {
1442
1455
  event.preventDefault()
1443
1456
  this.zoomToFit()
@@ -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
+ }
@@ -1,3 +1,3 @@
1
1
  module TessEdit
2
- VERSION = "0.6.2"
2
+ VERSION = "0.6.3"
3
3
  end
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.2
4
+ version: 0.6.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom de Grunt