tess_edit 0.6.1 → 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 +4 -4
- data/README.md +6 -4
- data/app/javascript/tess_edit/controllers/editor_controller.js +367 -69
- data/app/javascript/tess_edit/ui/canvas.js +143 -3
- data/app/javascript/tess_edit/ui/icons.js +1 -0
- data/app/javascript/tess_edit/ui/text_editing.js +3 -3
- data/config/locales/en.yml +8 -0
- data/config/locales/nl.yml +8 -0
- data/lib/tess_edit/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c3d67adc7a3fb980851a6f7d15dbfb6c0be257627d7da6e376ef1eb026168923
|
|
4
|
+
data.tar.gz: 48b26477825363cf6522ba0ebc03aa7ec8f33358416353df412bf763e584afcd
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 27e7d60dbbfeef61adc64aebb42848c7d3ec43122f0c075a3bfd409c7d37c84a7bbd6482df95d3c0124b81fcbef21a1f0868291d3be7ff50f3913c7ea81cc001
|
|
7
|
+
data.tar.gz: 869f784a685769ffa46bf7ccaccb7ed8f58ad21c0815550e0ee85a6d68b397af05c7b45e61768f221d1fe18ca3609edacddf3b76a0890e9dc7e654c239972986
|
data/README.md
CHANGED
|
@@ -31,7 +31,9 @@ Liquid is completed as you type, in text and in settings:
|
|
|
31
31
|
- 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.
|
|
32
32
|
- Undo/redo, duplicate, delete, keyboard shortcuts (⌘Z, ⇧⌘Z, ⌘D, Delete, Enter to edit text, Tab to the next table cell, Esc).
|
|
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
|
-
- Panels on both sides, or combined as tabs in one sidebar on the left or right to give the canvas more room.
|
|
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
|
+
- 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.
|
|
35
37
|
- Dark mode that follows the host app's.
|
|
36
38
|
- Code dialog to view, copy or download the JSON and the kit's outputs, and to load JSON.
|
|
37
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.
|
|
@@ -102,7 +104,7 @@ Give the controller an element with a height, the kit it makes and, optionally,
|
|
|
102
104
|
|
|
103
105
|
The editor loads the document from the `jsonInput` (or from `data-tess-edit-document-value`). With neither, it starts with the kit's sample, if it has one; set `data-tess-edit-sample-value="false"` to start with an empty document.
|
|
104
106
|
|
|
105
|
-
`data-tess-edit-panels-value` sets the default panel layout: `split` (Blocks and Layers on the left, Inspect on the right, the default), `left` or `right` (Blocks, Layers and Inspect as tabs in one sidebar on that side). People can switch with the buttons in the top bar;
|
|
107
|
+
`data-tess-edit-panels-value` sets the default panel layout: `split` (Blocks and Layers on the left, Inspect on the right, the default), `left` or `right` (Blocks, Layers and Inspect as tabs in one sidebar on that side). People can switch with the buttons in the top bar, or drag a tab (Blocks, Layers, Inspect, a kit's own panel) to the other pane, or to a side without one to make a pane there; where each tab is is remembered in the browser, per kit. When the editor is narrower than 1000px, it puts all panels on the left so the canvas keeps its room, and goes back to the chosen layout when it is wide enough again.
|
|
106
108
|
|
|
107
109
|
The editor has a border with rounded corners. A page that frames it itself, such as a card it fills, turns it off with `data-tess-edit-frame-value="false"`.
|
|
108
110
|
|
|
@@ -458,7 +460,7 @@ TessEdit's own blocks are part of no kit until a kit takes them in: `extendBlock
|
|
|
458
460
|
|
|
459
461
|
The demo's Note kit (`test/dummy/app/javascript/kits/note.js`) is a small kit of a host app's own. [Nuntius](https://github.com/entdec/nuntius)' email kit (`app/javascript/nuntius/email`) is a complete one: it takes in TessEdit's blocks with their MJML, adds the email's own (Email, Wrapper, Hero, Social, Navbar), orders the Blocks panel's tiles with `palette`, loads documents from before its root's rename with `aliases`, and has its MJML compiled to HTML on the server (see [Compiling](#compiling)).
|
|
460
462
|
|
|
461
|
-
A kit can bring panels of its own, each a tab after
|
|
463
|
+
A kit can bring panels of its own, each a tab after Inspect, which can be dragged to either pane like the others, such as a test run of what is being designed:
|
|
462
464
|
|
|
463
465
|
```js
|
|
464
466
|
registerKit({
|
|
@@ -468,7 +470,7 @@ registerKit({
|
|
|
468
470
|
})
|
|
469
471
|
```
|
|
470
472
|
|
|
471
|
-
`render` fills the panel's element once, when the editor is built; `editor` is the editor, with its `doc`, `select(id)`, `renderCanvas()` and its `element`, which sends `tess-edit:change`. The canvas is drawn again when the open panel changes, so it can show what the panel is about; a panel that changes what it shows calls `editor.renderCanvas()`. The demo's Note kit has an Outline panel.
|
|
473
|
+
`render` fills the panel's element once, when the editor is built; `editor` is the editor, with its `doc`, `select(id)`, `renderCanvas()` and its `element`, which sends `tess-edit:change`. The canvas is drawn again when the open panel changes, so it can show what the panel is about; a panel that changes what it shows calls `editor.renderCanvas()`. A panel dragged to the other pane moves its element, so Stimulus controllers in it disconnect and connect again: the same controller, so state kept in `initialize` survives it. The demo's Note kit has an Outline panel.
|
|
472
474
|
|
|
473
475
|
Loading a document into the editor of another kit fails with a message saying which editor it is for.
|
|
474
476
|
|
|
@@ -87,6 +87,13 @@ const TOOL = "w-8 h-8 flex items-center justify-center rounded-md text-gray-600
|
|
|
87
87
|
const TAB = "shrink-0 whitespace-nowrap px-3 h-12 text-[13px] font-medium border-b-2 -mb-px"
|
|
88
88
|
const PANELS = ["left", "split", "right"]
|
|
89
89
|
const PANELS_KEY = "tess_edit:panels"
|
|
90
|
+
// Where each tab is, per kit (its own panels are tabs too)
|
|
91
|
+
const TABS_KEY = "tess_edit:tabs"
|
|
92
|
+
const SIDES = ["left", "right"]
|
|
93
|
+
// The canvas's zoom: the steps the buttons and keys go through, and its range
|
|
94
|
+
const ZOOMS = [0.25, 0.33, 0.5, 0.67, 0.75, 0.9, 1, 1.1, 1.25, 1.5, 1.75, 2]
|
|
95
|
+
const MIN_ZOOM = ZOOMS[0]
|
|
96
|
+
const MAX_ZOOM = ZOOMS[ZOOMS.length - 1]
|
|
90
97
|
const TRANSLATION_LOCALE_KEY = "tess_edit:translation_locale"
|
|
91
98
|
// Two sidebars (256px + 320px) leave too little canvas below this editor width.
|
|
92
99
|
const NARROW_WIDTH = 1000
|
|
@@ -100,6 +107,13 @@ function placed(node, at) {
|
|
|
100
107
|
return node
|
|
101
108
|
}
|
|
102
109
|
|
|
110
|
+
// Puts the children in an element unless they're there already: moving them
|
|
111
|
+
// would reconnect the controllers in them
|
|
112
|
+
function setChildren(element, children) {
|
|
113
|
+
const current = [...element.children]
|
|
114
|
+
if (current.length !== children.length || children.some((child, index) => current[index] !== child)) element.replaceChildren(...children)
|
|
115
|
+
}
|
|
116
|
+
|
|
103
117
|
export default class extends Controller {
|
|
104
118
|
static values = { kit: String, document: String, sample: { type: Boolean, default: true }, frame: { type: Boolean, default: true }, panels: { type: String, default: "split" }, compileUrl: { type: String, default: COMPILE_URL }, mediaUrl: String, variablesUrl: String, filtersUrl: String, tagsUrl: String, translationsUrl: String, values: String, lock: String, blocks: String, options: String }
|
|
105
119
|
static targets = ["jsonInput", "slot", "translations"]
|
|
@@ -126,8 +140,9 @@ export default class extends Controller {
|
|
|
126
140
|
this.drag = null
|
|
127
141
|
this.mode = "edit"
|
|
128
142
|
this.device = this.kit.devices?.[0]?.key || null
|
|
129
|
-
|
|
130
|
-
this.
|
|
143
|
+
// The tab open in each pane, by the side it shows on ("sheet" on a compact editor)
|
|
144
|
+
this.openTabs = {}
|
|
145
|
+
this.zoom = 1
|
|
131
146
|
this.narrow = false
|
|
132
147
|
this.compact = false
|
|
133
148
|
this.sheetOpen = false
|
|
@@ -352,6 +367,7 @@ export default class extends Controller {
|
|
|
352
367
|
document.removeEventListener("mousedown", this.outsideClick)
|
|
353
368
|
document.removeEventListener("keydown", this.menuKeydown, true)
|
|
354
369
|
window.removeEventListener("resize", this.closeMenuOnResize)
|
|
370
|
+
window.removeEventListener("blur", this.endPanReady)
|
|
355
371
|
this.root?.remove()
|
|
356
372
|
delete this.element.tessEdit
|
|
357
373
|
}
|
|
@@ -437,27 +453,40 @@ export default class extends Controller {
|
|
|
437
453
|
build() {
|
|
438
454
|
this.blocksElement = h("div", { class: "flex-1 overflow-y-auto pb-4" })
|
|
439
455
|
this.treeElement = h("div", { class: "flex-1 overflow-y-auto" })
|
|
440
|
-
|
|
441
|
-
// The kit's own panels (registerKit's panels), a tab each after Layers
|
|
456
|
+
// The kit's own panels (registerKit's panels), a tab each after Inspect
|
|
442
457
|
this.kitPanels = (this.hasBlocks ? this.kit.panels || [] : []).map((panel) => ({ ...panel, element: h("div", { class: "hidden flex-1 overflow-y-auto min-h-0", dataset: { tessEditPanel: panel.key } }) }))
|
|
443
458
|
this.inspectorElement = h("div", { class: "flex flex-1 flex-col min-h-0", dataset: { tessEditPanel: "inspect" } })
|
|
444
|
-
|
|
459
|
+
// Each tab is a panel, in the pane on either side of the canvas it was put in
|
|
460
|
+
this.tabs = this.hasBlocks
|
|
461
|
+
? [
|
|
462
|
+
{ key: "blocks", label: "Blocks", element: this.blocksElement },
|
|
463
|
+
{ key: "layers", label: "Layers", element: this.treeElement },
|
|
464
|
+
{ key: "inspect", label: "Inspect", element: this.inspectorElement },
|
|
465
|
+
...this.kitPanels.map((panel) => ({ key: panel.key, label: panel.label, element: panel.element }))
|
|
466
|
+
]
|
|
467
|
+
: []
|
|
468
|
+
this.arrangement = this.storedArrangement() || this.preset([this.storedPanels(), this.panelsValue].find((value) => PANELS.includes(value)) || "split")
|
|
469
|
+
this.panes = Object.fromEntries(SIDES.map((side) => [side, { side, element: h("aside", { dataset: { tessEditPane: side } }), strip: this.tabStrip(side) }]))
|
|
445
470
|
this.inspectPanel = h("aside")
|
|
446
471
|
this.sheetClose = h("button", { type: "button", title: t("Hide panels"), class: `${TOOL} ml-auto self-center`, html: icon("close"), onclick: () => this.setSheetOpen(false) })
|
|
447
472
|
this.textToolbar = h("div", { class: "hidden absolute left-1/2 top-3 z-20 -translate-x-1/2 flex items-center gap-0.5 rounded-lg border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800 px-1.5 py-1 shadow-md" })
|
|
448
|
-
|
|
449
|
-
|
|
473
|
+
// Zoomed by scaling the iframe (applyZoom): what's in it lays out as in a
|
|
474
|
+
// browser zoomed as much
|
|
475
|
+
this.frame = h("iframe", { class: "block h-full w-full border-0 bg-white origin-top-left", title: t("%{name} canvas", { name: t(this.kit.name) }) })
|
|
476
|
+
this.frameWrap = h("div", { class: "relative h-full mx-auto overflow-hidden transition-[width] duration-200" }, this.frame)
|
|
477
|
+
// Where a tab dragged off its pane makes a pane of its own on a side that has none
|
|
478
|
+
this.dropZones = Object.fromEntries(SIDES.map((side) => [side, this.dropZone(side)]))
|
|
450
479
|
this.topBar = h("div", { class: "flex items-center gap-1 h-12 px-3 border-b border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800 shrink-0" })
|
|
451
480
|
this.body = h("div", { class: "flex flex-1 min-h-0" })
|
|
452
481
|
|
|
453
482
|
this.root = h(
|
|
454
483
|
"div",
|
|
455
|
-
{ 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) },
|
|
456
485
|
this.topBar,
|
|
457
486
|
this.body
|
|
458
487
|
)
|
|
459
488
|
this.errorBar = h("div", { class: "hidden absolute inset-x-3 bottom-3 z-20 rounded-md border border-red-200 dark:border-red-800 bg-red-50 dark:bg-red-900/40 px-3 py-2 text-xs text-red-700 dark:text-red-300 shadow-sm", role: "alert" })
|
|
460
|
-
this.main = h("main", { class: "relative flex-1 min-w-0 min-h-0 bg-gray-100 dark:bg-gray-900", ondragover: (event) => this.drag && event.preventDefault() }, this.textToolbar, this.frameWrap, this.errorBar)
|
|
489
|
+
this.main = h("main", { class: "relative flex-1 min-w-0 min-h-0 bg-gray-100 dark:bg-gray-900", ondragover: (event) => this.drag && event.preventDefault() }, this.textToolbar, this.frameWrap, this.errorBar, this.dropZones.left, this.dropZones.right)
|
|
461
490
|
this.arrangePanels()
|
|
462
491
|
this.element.append(this.root)
|
|
463
492
|
|
|
@@ -482,14 +511,17 @@ export default class extends Controller {
|
|
|
482
511
|
}
|
|
483
512
|
}
|
|
484
513
|
this.closeMenuOnResize = () => this.closeMenu()
|
|
514
|
+
this.endPanReady = () => this.canvas.pan.setReady(false)
|
|
515
|
+
window.addEventListener("blur", this.endPanReady)
|
|
485
516
|
document.addEventListener("mousedown", this.outsideClick)
|
|
486
517
|
document.addEventListener("keydown", this.menuKeydown, true)
|
|
487
518
|
window.addEventListener("resize", this.closeMenuOnResize)
|
|
488
519
|
}
|
|
489
520
|
|
|
490
|
-
//
|
|
491
|
-
// one
|
|
492
|
-
//
|
|
521
|
+
// The panes either side of the canvas, each with the tabs put in it (see
|
|
522
|
+
// moveTab); one without tabs isn't shown. Narrow, the panes are one on the
|
|
523
|
+
// left (or the right, when that's the only one); compact, they're one sheet
|
|
524
|
+
// below the canvas, while it is open.
|
|
493
525
|
arrangePanels() {
|
|
494
526
|
const panelClass = (border, width) => `${width} shrink-0 flex flex-col ${border} border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800 min-h-0`
|
|
495
527
|
const sheetClass = `${panelClass("border-t", "h-1/2")}${this.sheetOpen ? "" : " hidden"}`
|
|
@@ -500,29 +532,176 @@ export default class extends Controller {
|
|
|
500
532
|
if (!this.hasBlocks) {
|
|
501
533
|
this.inspectPanel.className = this.compact ? sheetClass : panelClass("border-l", "w-80")
|
|
502
534
|
const children = this.compact ? [this.sheetHeader(t("Inspect")), this.inspectorElement] : [this.inspectorElement]
|
|
503
|
-
|
|
504
|
-
if (current.length !== children.length || children.some((child, index) => current[index] !== child)) this.inspectPanel.replaceChildren(...children)
|
|
535
|
+
setChildren(this.inspectPanel, children)
|
|
505
536
|
if (this.main.nextSibling !== this.inspectPanel) this.main.after(this.inspectPanel)
|
|
506
537
|
return
|
|
507
538
|
}
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
this.
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
this.
|
|
523
|
-
|
|
524
|
-
|
|
539
|
+
const shown = this.shownPanes
|
|
540
|
+
const both = shown.length === 2
|
|
541
|
+
for (const side of SIDES) {
|
|
542
|
+
const pane = this.panes[side]
|
|
543
|
+
const showing = shown.find((each) => each.element === pane.element)
|
|
544
|
+
if (!showing) {
|
|
545
|
+
pane.element.remove()
|
|
546
|
+
continue
|
|
547
|
+
}
|
|
548
|
+
const width = !both ? "w-80" : showing.keys.includes("inspect") ? "w-80" : "w-64"
|
|
549
|
+
pane.element.className = showing.side === "sheet" ? sheetClass : panelClass(side === "left" ? "border-r" : "border-l", width)
|
|
550
|
+
setChildren(pane.element, [pane.strip, ...showing.keys.map((key) => this.tab(key).element)])
|
|
551
|
+
if (side === "left" && showing.side !== "sheet") {
|
|
552
|
+
if (this.main.previousSibling !== pane.element) this.main.before(pane.element)
|
|
553
|
+
} else if (this.main.nextSibling !== pane.element) this.main.after(pane.element)
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
// The panes shown, by the side they show on, with their tabs in order
|
|
558
|
+
get shownPanes() {
|
|
559
|
+
const { left, right } = this.arrangement
|
|
560
|
+
if (this.compact) return [{ side: "sheet", element: this.panes.left.element, strip: this.panes.left.strip, keys: [...left, ...right] }]
|
|
561
|
+
if (this.narrow && left.length && right.length) return [{ side: "left", element: this.panes.left.element, strip: this.panes.left.strip, keys: [...left, ...right] }]
|
|
562
|
+
return SIDES.filter((side) => this.arrangement[side].length).map((side) => ({ ...this.panes[side], keys: this.arrangement[side] }))
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
tab(key) {
|
|
566
|
+
return this.tabs.find((tab) => tab.key === key)
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
// The tabs in the panes a preset puts them in: all on one side, or split
|
|
570
|
+
// with Inspect on the right
|
|
571
|
+
preset(panels) {
|
|
572
|
+
const keys = this.tabs.map((tab) => tab.key)
|
|
573
|
+
if (panels === "left") return { left: keys, right: [] }
|
|
574
|
+
if (panels === "right") return { left: [], right: keys }
|
|
575
|
+
return { left: keys.filter((key) => key !== "inspect"), right: keys.filter((key) => key === "inspect") }
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
// Where the tabs were put last, with tabs it doesn't know of yet (a kit's
|
|
579
|
+
// new panel) where the split preset puts them
|
|
580
|
+
storedArrangement() {
|
|
581
|
+
if (!this.hasBlocks) return null
|
|
582
|
+
let stored
|
|
583
|
+
try {
|
|
584
|
+
stored = JSON.parse(this.stored(`${TABS_KEY}:${this.kit.key}`) || "null")
|
|
585
|
+
} catch {
|
|
586
|
+
return null
|
|
587
|
+
}
|
|
588
|
+
if (!stored || !SIDES.every((side) => Array.isArray(stored[side]))) return null
|
|
589
|
+
const keys = this.tabs.map((tab) => tab.key)
|
|
590
|
+
const arrangement = Object.fromEntries(SIDES.map((side) => [side, [...new Set(stored[side])].filter((key) => keys.includes(key))]))
|
|
591
|
+
arrangement.right = arrangement.right.filter((key) => !arrangement.left.includes(key))
|
|
592
|
+
const split = this.preset("split")
|
|
593
|
+
for (const key of keys) {
|
|
594
|
+
if (arrangement.left.includes(key) || arrangement.right.includes(key)) continue
|
|
595
|
+
arrangement[split.left.includes(key) ? "left" : "right"].push(key)
|
|
525
596
|
}
|
|
597
|
+
return arrangement
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
// The preset the arrangement is: a side with no tabs, or split
|
|
601
|
+
get panels() {
|
|
602
|
+
if (!this.arrangement.right.length) return "left"
|
|
603
|
+
if (!this.arrangement.left.length) return "right"
|
|
604
|
+
return "split"
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
// A pane's tabs, which a tab can be dragged to from the other pane, and
|
|
608
|
+
// within to put it elsewhere in the row
|
|
609
|
+
tabStrip(side) {
|
|
610
|
+
const strip = h("div", { role: "tablist", class: "flex border-b border-gray-200 dark:border-gray-700 px-2 shrink-0 overflow-x-auto" })
|
|
611
|
+
strip.addEventListener("dragover", (event) => {
|
|
612
|
+
if (!this.tabDrag) return
|
|
613
|
+
event.preventDefault()
|
|
614
|
+
event.dataTransfer.dropEffect = "move"
|
|
615
|
+
this.showTabDrop(strip, this.tabDropIndex(strip, event.clientX))
|
|
616
|
+
})
|
|
617
|
+
strip.addEventListener("dragleave", (event) => !strip.contains(event.relatedTarget) && this.showTabDrop(null))
|
|
618
|
+
strip.addEventListener("drop", (event) => {
|
|
619
|
+
if (!this.tabDrag) return
|
|
620
|
+
event.preventDefault()
|
|
621
|
+
this.moveTab(this.tabDrag, this.paneSide(strip), this.tabDropIndex(strip, event.clientX))
|
|
622
|
+
})
|
|
623
|
+
return strip
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
// The side of the pane a strip is in (the left pane is also the combined one)
|
|
627
|
+
paneSide(strip) {
|
|
628
|
+
return SIDES.find((side) => this.panes[side].strip === strip)
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
// Where in a strip's row of tabs a tab let go at x goes
|
|
632
|
+
tabDropIndex(strip, x) {
|
|
633
|
+
const buttons = [...strip.querySelectorAll("[data-tess-edit-tab]")].filter((button) => button.dataset.tessEditTab !== this.tabDrag)
|
|
634
|
+
const index = buttons.findIndex((button) => {
|
|
635
|
+
const rect = button.getBoundingClientRect()
|
|
636
|
+
return x < rect.left + rect.width / 2
|
|
637
|
+
})
|
|
638
|
+
return index === -1 ? buttons.length : index
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
showTabDrop(strip, index) {
|
|
642
|
+
this.tabIndicator ||= h("span", { class: "pointer-events-none self-stretch my-2 w-0.5 shrink-0 rounded bg-blue-600 dark:bg-blue-400" })
|
|
643
|
+
if (!strip) return this.tabIndicator.remove()
|
|
644
|
+
const buttons = [...strip.querySelectorAll("[data-tess-edit-tab]")].filter((button) => button.dataset.tessEditTab !== this.tabDrag)
|
|
645
|
+
if (buttons[index]) buttons[index].before(this.tabIndicator)
|
|
646
|
+
else if (buttons.length) buttons.at(-1).after(this.tabIndicator)
|
|
647
|
+
else strip.append(this.tabIndicator)
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
// A side without a pane, while a tab is dragged: let go there, it's that
|
|
651
|
+
// side's pane
|
|
652
|
+
dropZone(side) {
|
|
653
|
+
const zone = h("div", { class: `hidden absolute inset-y-3 ${side === "left" ? "left-3" : "right-3"} z-30 w-28 flex items-center justify-center rounded-lg border-2 border-dashed border-blue-400 bg-blue-50/90 dark:bg-blue-950/80 p-2 text-center text-xs font-medium text-blue-700 dark:text-blue-300`, dataset: { tessEditDropZone: side } }, t(side === "left" ? "Put it in a panel on the left" : "Put it in a panel on the right"))
|
|
654
|
+
zone.addEventListener("dragover", (event) => {
|
|
655
|
+
if (!this.tabDrag) return
|
|
656
|
+
event.preventDefault()
|
|
657
|
+
event.dataTransfer.dropEffect = "move"
|
|
658
|
+
zone.classList.add("bg-blue-100")
|
|
659
|
+
})
|
|
660
|
+
zone.addEventListener("dragleave", () => zone.classList.remove("bg-blue-100"))
|
|
661
|
+
zone.addEventListener("drop", (event) => {
|
|
662
|
+
if (!this.tabDrag) return
|
|
663
|
+
event.preventDefault()
|
|
664
|
+
this.moveTab(this.tabDrag, side, 0)
|
|
665
|
+
})
|
|
666
|
+
return zone
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
startTabDrag(event, key) {
|
|
670
|
+
this.tabDrag = key
|
|
671
|
+
event.dataTransfer.effectAllowed = "move"
|
|
672
|
+
event.dataTransfer.setData("text/plain", key)
|
|
673
|
+
// A side with no pane takes one; not while the panes are combined
|
|
674
|
+
for (const side of SIDES) this.dropZones[side].classList.toggle("hidden", !!this.arrangement[side].length)
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
endTabDrag() {
|
|
678
|
+
this.tabDrag = null
|
|
679
|
+
this.showTabDrop(null)
|
|
680
|
+
for (const zone of Object.values(this.dropZones)) {
|
|
681
|
+
zone.classList.add("hidden")
|
|
682
|
+
zone.classList.remove("bg-blue-100")
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
// Puts a tab in a pane, at a place in its row, open there; remembered for
|
|
687
|
+
// the kit. The pane it left opens its first tab, or goes when it has none.
|
|
688
|
+
moveTab(key, side, index) {
|
|
689
|
+
const panel = this.panel
|
|
690
|
+
const arrangement = Object.fromEntries(SIDES.map((each) => [each, this.arrangement[each].filter((other) => other !== key)]))
|
|
691
|
+
arrangement[side].splice(Math.min(index, arrangement[side].length), 0, key)
|
|
692
|
+
this.endTabDrag()
|
|
693
|
+
this.setArrangement(arrangement)
|
|
694
|
+
this.openTabs[side] = key
|
|
695
|
+
this.renderLeftTabs()
|
|
696
|
+
if (panel !== this.panel) this.renderCanvas()
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
setArrangement(arrangement) {
|
|
700
|
+
this.arrangement = arrangement
|
|
701
|
+
try {
|
|
702
|
+
localStorage.setItem(`${TABS_KEY}:${this.kit.key}`, JSON.stringify(arrangement))
|
|
703
|
+
} catch {}
|
|
704
|
+
this.applyPanels()
|
|
526
705
|
}
|
|
527
706
|
|
|
528
707
|
// The sheet's title bar for a kit without blocks, which has no tabs
|
|
@@ -536,25 +715,25 @@ export default class extends Controller {
|
|
|
536
715
|
setSheetOpen(open) {
|
|
537
716
|
if (!this.compact || open === this.sheetOpen) return
|
|
538
717
|
this.sheetOpen = open
|
|
539
|
-
;(this.hasBlocks ? this.
|
|
718
|
+
;(this.hasBlocks ? this.panes.left.element : this.inspectPanel).classList.toggle("hidden", !open)
|
|
540
719
|
this.renderTopBar()
|
|
541
720
|
this.canvas.refresh()
|
|
542
721
|
}
|
|
543
722
|
|
|
723
|
+
// Puts the tabs as a preset does: all on the left or the right, or split
|
|
544
724
|
setPanels(panels) {
|
|
545
725
|
if (!PANELS.includes(panels)) return
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
} catch {}
|
|
550
|
-
this.applyPanels()
|
|
726
|
+
const panel = this.panel
|
|
727
|
+
this.setArrangement(this.preset(panels))
|
|
728
|
+
if (panel !== this.panel) this.renderCanvas()
|
|
551
729
|
}
|
|
552
730
|
|
|
553
731
|
applyPanels() {
|
|
554
|
-
|
|
732
|
+
const panel = this.panel
|
|
555
733
|
this.arrangePanels()
|
|
556
734
|
this.renderTopBar()
|
|
557
735
|
this.renderLeftTabs()
|
|
736
|
+
if (this.canvas && panel !== this.panel) this.renderCanvas()
|
|
558
737
|
}
|
|
559
738
|
|
|
560
739
|
// Combines the panels while the editor is narrower than NARROW_WIDTH, and
|
|
@@ -569,17 +748,18 @@ export default class extends Controller {
|
|
|
569
748
|
if (compact !== this.compact) this.sheetOpen = false
|
|
570
749
|
this.compact = compact
|
|
571
750
|
this.applyPanels()
|
|
572
|
-
this.
|
|
751
|
+
this.applyZoom()
|
|
573
752
|
})
|
|
574
753
|
this.resizeObserver.observe(this.root)
|
|
575
754
|
}
|
|
576
755
|
|
|
577
|
-
// The layout in use:
|
|
578
|
-
//
|
|
756
|
+
// The layout in use: a pane on each side ("split"), one on the left or the
|
|
757
|
+
// right, or the sheet; a kit without blocks has Inspect on the right
|
|
579
758
|
get layout() {
|
|
580
759
|
if (!this.hasBlocks) return "split"
|
|
581
760
|
if (this.compact) return "sheet"
|
|
582
|
-
|
|
761
|
+
const shown = this.shownPanes
|
|
762
|
+
return shown.length === 2 ? "split" : shown[0]?.side || "left"
|
|
583
763
|
}
|
|
584
764
|
|
|
585
765
|
get hasBlocks() {
|
|
@@ -598,10 +778,6 @@ export default class extends Controller {
|
|
|
598
778
|
}
|
|
599
779
|
}
|
|
600
780
|
|
|
601
|
-
get combined() {
|
|
602
|
-
return this.layout !== "split"
|
|
603
|
-
}
|
|
604
|
-
|
|
605
781
|
renderAll() {
|
|
606
782
|
this.liquidChecker?.schedule()
|
|
607
783
|
this.renderTopBar()
|
|
@@ -636,12 +812,13 @@ export default class extends Controller {
|
|
|
636
812
|
this.compact ? null : h("span", { class: "font-semibold text-gray-900 dark:text-gray-100 mr-3" }, t(this.kit.name)),
|
|
637
813
|
toggle(this.mode, [["edit", "edit", t("Edit")], ["preview", "eye", this.kit.previewTitle ? t(this.kit.previewTitle) : t("Preview")]], (mode) => this.setMode(mode)),
|
|
638
814
|
this.kit.devices?.length ? toggle(this.device, this.kit.devices.map((device) => [device.key, device.icon, t(device.title)]), (device) => this.setDevice(device)) : null,
|
|
815
|
+
this.zoomControls(),
|
|
639
816
|
this.translations.enabled ? this.translationLocaleMenu() : null,
|
|
640
817
|
h("div", { class: "flex-1" }),
|
|
641
818
|
// A compact editor shows its panels or not; one without blocks has none to arrange
|
|
642
819
|
this.compact && h("button", { type: "button", title: t(this.sheetOpen ? "Hide panels" : "Show panels"), "aria-pressed": String(this.sheetOpen), class: `${TOOL} ${this.sheetOpen ? "bg-gray-100 dark:bg-gray-700" : ""}`, html: icon("panels-bottom"), onclick: () => this.setSheetOpen(!this.sheetOpen) }),
|
|
643
820
|
this.hasBlocks && !this.compact && toggle(
|
|
644
|
-
this.layout,
|
|
821
|
+
this.narrow ? this.layout : this.panels,
|
|
645
822
|
[
|
|
646
823
|
["left", "panels-left", t("All panels on the left")],
|
|
647
824
|
["split", "panels-split", t(this.narrow ? "Too narrow to split the panels" : "Blocks on the left, Inspect on the right"), this.narrow],
|
|
@@ -681,34 +858,136 @@ export default class extends Controller {
|
|
|
681
858
|
)
|
|
682
859
|
}
|
|
683
860
|
|
|
861
|
+
// Each pane's tabs, and its open one shown. A tab is dragged to the other
|
|
862
|
+
// pane, or to a side without one, while the panes are side by side.
|
|
684
863
|
renderLeftTabs() {
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
864
|
+
if (!this.hasBlocks) return
|
|
865
|
+
const movable = !this.compact && !(this.narrow && this.arrangement.left.length && this.arrangement.right.length)
|
|
866
|
+
for (const pane of this.shownPanes) {
|
|
867
|
+
const open = this.openTab(pane)
|
|
868
|
+
const tabs = pane.keys.map((key) =>
|
|
869
|
+
h(
|
|
870
|
+
"button",
|
|
871
|
+
{
|
|
872
|
+
type: "button",
|
|
873
|
+
role: "tab",
|
|
874
|
+
"aria-selected": String(open === key),
|
|
875
|
+
draggable: movable ? "true" : null,
|
|
876
|
+
title: movable ? t("Drag to move it to another panel") : null,
|
|
877
|
+
dataset: { tessEditTab: key },
|
|
878
|
+
class: `${TAB} ${open === key ? "border-blue-600 dark:border-blue-400 text-blue-700 dark:text-blue-300" : "border-transparent text-gray-500 dark:text-gray-400 hover:text-gray-800 dark:hover:text-gray-200"}`,
|
|
879
|
+
onclick: () => this.setLeftTab(key),
|
|
880
|
+
ondragstart: (event) => this.startTabDrag(event, key),
|
|
881
|
+
ondragend: () => this.endTabDrag()
|
|
882
|
+
},
|
|
883
|
+
t(this.tab(key).label)
|
|
884
|
+
)
|
|
885
|
+
)
|
|
886
|
+
if (this.compact) tabs.push(this.sheetClose)
|
|
887
|
+
pane.strip.replaceChildren(...tabs)
|
|
888
|
+
for (const key of pane.keys) this.tab(key).element.classList.toggle("hidden", key !== open)
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
|
|
892
|
+
// The tab open in a pane: the one opened there last, else its first
|
|
893
|
+
openTab(pane) {
|
|
894
|
+
const open = this.openTabs[pane.side]
|
|
895
|
+
if (pane.keys.includes(open)) return open
|
|
896
|
+
if (pane.side !== "left" && pane.keys.includes(this.openTabs.left)) return this.openTabs.left
|
|
897
|
+
return pane.keys[0]
|
|
898
|
+
}
|
|
899
|
+
|
|
900
|
+
// Whether a tab is showing in its pane
|
|
901
|
+
isOpen(key) {
|
|
902
|
+
return this.shownPanes.some((pane) => this.openTab(pane) === key)
|
|
697
903
|
}
|
|
698
904
|
|
|
699
905
|
// The kit's panel that is open, if one is
|
|
700
906
|
get panel() {
|
|
701
|
-
|
|
907
|
+
if (!this.kitPanels.length) return null
|
|
908
|
+
return this.kitPanels.find((panel) => this.isOpen(panel.key))?.key || null
|
|
702
909
|
}
|
|
703
910
|
|
|
704
|
-
|
|
911
|
+
// Opens a tab in the pane it is in
|
|
912
|
+
setLeftTab(key) {
|
|
913
|
+
const pane = this.shownPanes.find((each) => each.keys.includes(key))
|
|
914
|
+
if (!pane) return
|
|
705
915
|
const panel = this.panel
|
|
706
|
-
this.
|
|
916
|
+
this.openTabs[pane.side] = key
|
|
707
917
|
this.renderLeftTabs()
|
|
708
918
|
// The canvas is told which of the kit's panels is open, so it draws again when that changes
|
|
709
919
|
if (panel !== this.panel) this.renderCanvas()
|
|
710
920
|
}
|
|
711
921
|
|
|
922
|
+
// --- zoom -------------------------------------------------------------------------
|
|
923
|
+
|
|
924
|
+
// Out, the zoom (which fits the canvas, or back to 100%), and in
|
|
925
|
+
zoomControls() {
|
|
926
|
+
const percent = `${Math.round(this.zoom * 100)}%`
|
|
927
|
+
return h(
|
|
928
|
+
"div",
|
|
929
|
+
{ class: "ml-1 flex items-center rounded-lg bg-gray-100 dark:bg-gray-900 p-0.5" },
|
|
930
|
+
h("button", { type: "button", title: t("Zoom out (⌘−)"), class: "w-7 h-7 flex items-center justify-center rounded-md text-gray-500 dark:text-gray-400 hover:text-gray-800 dark:hover:text-gray-200 disabled:opacity-40", disabled: this.zoom <= MIN_ZOOM, html: icon("minus"), onclick: () => this.zoomBy(-1) }),
|
|
931
|
+
h("button", { type: "button", title: t(this.zoom === 1 ? "Fit the canvas (⇧1)" : "Back to 100% (⌘0)"), "aria-label": t("Zoom"), dataset: { tessEditZoom: "" }, class: "h-7 min-w-12 px-1 rounded-md text-xs tabular-nums text-gray-600 dark:text-gray-300 hover:text-gray-900 dark:hover:text-gray-100", onclick: () => (this.zoom === 1 ? this.zoomToFit() : this.setZoom(1)) }, percent),
|
|
932
|
+
h("button", { type: "button", title: t("Zoom in (⌘+)"), class: "w-7 h-7 flex items-center justify-center rounded-md text-gray-500 dark:text-gray-400 hover:text-gray-800 dark:hover:text-gray-200 disabled:opacity-40", disabled: this.zoom >= MAX_ZOOM, html: icon("plus"), onclick: () => this.zoomBy(1) })
|
|
933
|
+
)
|
|
934
|
+
}
|
|
935
|
+
|
|
936
|
+
// To the next step in or out
|
|
937
|
+
zoomBy(direction) {
|
|
938
|
+
const next = direction > 0 ? ZOOMS.find((zoom) => zoom > this.zoom + 0.001) : [...ZOOMS].reverse().find((zoom) => zoom < this.zoom - 0.001)
|
|
939
|
+
this.setZoom(next ?? this.zoom)
|
|
940
|
+
}
|
|
941
|
+
|
|
942
|
+
// Zooms the canvas, keeping the point `at` (in the canvas's viewport) where
|
|
943
|
+
// it is; without it, the top left of what shows
|
|
944
|
+
setZoom(zoom, { at = null } = {}) {
|
|
945
|
+
zoom = Math.round(Math.min(MAX_ZOOM, Math.max(MIN_ZOOM, zoom)) * 100) / 100
|
|
946
|
+
if (zoom === this.zoom) return
|
|
947
|
+
const win = this.frame.contentWindow
|
|
948
|
+
const before = this.zoom
|
|
949
|
+
const point = at || { x: 0, y: 0 }
|
|
950
|
+
const scroll = win ? { x: win.scrollX + point.x, y: win.scrollY + point.y } : null
|
|
951
|
+
this.zoom = zoom
|
|
952
|
+
this.applyZoom()
|
|
953
|
+
if (scroll) win.scrollTo(scroll.x - (point.x * before) / zoom, scroll.y - (point.y * before) / zoom)
|
|
954
|
+
this.renderTopBar()
|
|
955
|
+
}
|
|
956
|
+
|
|
957
|
+
// The whole canvas in view, at most at 100%
|
|
958
|
+
zoomToFit() {
|
|
959
|
+
const doc = this.frame.contentDocument
|
|
960
|
+
if (!doc?.body) return
|
|
961
|
+
const range = doc.createRange()
|
|
962
|
+
range.selectNodeContents(doc.body)
|
|
963
|
+
const content = range.getBoundingClientRect()
|
|
964
|
+
const win = this.frame.contentWindow
|
|
965
|
+
const width = Math.max(content.width, 1) + 32
|
|
966
|
+
const height = Math.max(content.bottom + win.scrollY, 1) + 16
|
|
967
|
+
const box = this.frameWrap.parentElement.getBoundingClientRect()
|
|
968
|
+
const device = this.deviceWidth
|
|
969
|
+
const fit = Math.min(1, (device || box.width) / width, box.height / height)
|
|
970
|
+
this.setZoom(Math.floor(fit * 20) / 20)
|
|
971
|
+
win.scrollTo(0, 0)
|
|
972
|
+
}
|
|
973
|
+
|
|
974
|
+
// The iframe at the size that, scaled, fills its place: what's in it lays
|
|
975
|
+
// out in a viewport as much larger (or smaller) as it is zoomed out (or in)
|
|
976
|
+
applyZoom() {
|
|
977
|
+
const zoom = this.zoom
|
|
978
|
+
const scaled = zoom !== 1
|
|
979
|
+
Object.assign(this.frame.style, { width: scaled ? `${100 / zoom}%` : "", height: scaled ? `${100 / zoom}%` : "", transform: scaled ? `scale(${zoom})` : "" })
|
|
980
|
+
const width = this.deviceWidth
|
|
981
|
+
this.frameWrap.style.width = width ? `${width * zoom}px` : ""
|
|
982
|
+
this.canvas?.refresh()
|
|
983
|
+
}
|
|
984
|
+
|
|
985
|
+
// The device's width in pixels, when it has one (mobile, 375px)
|
|
986
|
+
get deviceWidth() {
|
|
987
|
+
const width = this.kit.devices?.find((option) => option.key === this.device)?.width
|
|
988
|
+
return width ? parseFloat(width) : null
|
|
989
|
+
}
|
|
990
|
+
|
|
712
991
|
setMode(mode) {
|
|
713
992
|
this.stopEditing()
|
|
714
993
|
this.mode = mode
|
|
@@ -720,8 +999,8 @@ export default class extends Controller {
|
|
|
720
999
|
this.device = device
|
|
721
1000
|
// A device without a width (desktop) fills the canvas area; one with a
|
|
722
1001
|
// width (mobile, 375px) shows a full-height frame in the middle of it.
|
|
723
|
-
const width = this.
|
|
724
|
-
this.
|
|
1002
|
+
const width = this.deviceWidth
|
|
1003
|
+
this.applyZoom()
|
|
725
1004
|
this.frameWrap.classList.toggle("shadow-sm", !!width)
|
|
726
1005
|
this.main.classList.toggle("px-4", !!width)
|
|
727
1006
|
this.renderTopBar()
|
|
@@ -819,10 +1098,10 @@ export default class extends Controller {
|
|
|
819
1098
|
|
|
820
1099
|
// --- selection and editing ---------------------------------------------------
|
|
821
1100
|
|
|
822
|
-
// `reveal` (a click on the canvas)
|
|
823
|
-
//
|
|
1101
|
+
// `reveal` (a click on the canvas) opens the Inspect tab in its pane, and
|
|
1102
|
+
// the sheet on a compact editor.
|
|
824
1103
|
select(id, { reveal = false } = {}) {
|
|
825
|
-
if (reveal && this.
|
|
1104
|
+
if (reveal && this.hasBlocks && !this.isOpen("inspect")) this.setLeftTab("inspect")
|
|
826
1105
|
if (reveal) this.setSheetOpen(true)
|
|
827
1106
|
if (this.editingId && this.editingId !== id) this.stopEditing()
|
|
828
1107
|
if (!find(this.doc, id)) id = this.doc.id
|
|
@@ -977,7 +1256,7 @@ export default class extends Controller {
|
|
|
977
1256
|
const node = createFromPalette(key)
|
|
978
1257
|
this.commit((doc) => insert(doc, parentId, index, node))
|
|
979
1258
|
this.select(node.id)
|
|
980
|
-
this.
|
|
1259
|
+
this.isOpen("layers") && this.tree.render()
|
|
981
1260
|
}
|
|
982
1261
|
|
|
983
1262
|
// Clicking a tile: add inside the selection when it fits, otherwise after the
|
|
@@ -1131,6 +1410,10 @@ export default class extends Controller {
|
|
|
1131
1410
|
|
|
1132
1411
|
// --- keyboard -----------------------------------------------------------------
|
|
1133
1412
|
|
|
1413
|
+
onKeyup(event) {
|
|
1414
|
+
if (event.code === "Space") this.canvas.pan.setReady(false)
|
|
1415
|
+
}
|
|
1416
|
+
|
|
1134
1417
|
onKeydown(event) {
|
|
1135
1418
|
const target = event.target
|
|
1136
1419
|
const typing = target.closest?.("input, textarea, select, [contenteditable='true']")
|
|
@@ -1155,8 +1438,23 @@ export default class extends Controller {
|
|
|
1155
1438
|
}
|
|
1156
1439
|
return
|
|
1157
1440
|
}
|
|
1441
|
+
// Zoom, also while typing in a field: ⌘+ and ⌘− in steps, ⌘0 back to 100%
|
|
1442
|
+
if (mod && !event.altKey && ["=", "+", "-", "0"].includes(event.key)) {
|
|
1443
|
+
event.preventDefault()
|
|
1444
|
+
event.key === "0" ? this.setZoom(1) : this.zoomBy(event.key === "-" ? -1 : 1)
|
|
1445
|
+
return
|
|
1446
|
+
}
|
|
1158
1447
|
if (typing) return
|
|
1159
|
-
|
|
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
|
+
}
|
|
1454
|
+
if (event.shiftKey && !mod && !event.altKey && event.code === "Digit1") {
|
|
1455
|
+
event.preventDefault()
|
|
1456
|
+
this.zoomToFit()
|
|
1457
|
+
} else if (mod && event.key.toLowerCase() === "z") {
|
|
1160
1458
|
event.preventDefault()
|
|
1161
1459
|
event.shiftKey ? this.redo() : this.undo()
|
|
1162
1460
|
} else if (mod && event.key.toLowerCase() === "y") {
|
|
@@ -59,9 +59,22 @@ 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
|
|
|
67
|
+
// A rect in an iframe's viewport in the page's, the iframe maybe scaled
|
|
68
|
+
export function frameToPage(frame, rect) {
|
|
69
|
+
const box = frame?.getBoundingClientRect() || { left: 0, top: 0, width: 1 }
|
|
70
|
+
const scale = frame?.offsetWidth ? box.width / frame.offsetWidth : 1
|
|
71
|
+
const left = box.left + rect.left * scale
|
|
72
|
+
const top = box.top + rect.top * scale
|
|
73
|
+
const width = (rect.right - rect.left) * scale
|
|
74
|
+
const height = (rect.bottom - rect.top) * scale
|
|
75
|
+
return { left, top, right: left + width, bottom: top + height, width, height }
|
|
76
|
+
}
|
|
77
|
+
|
|
65
78
|
// A file dragged in from outside the browser (block drags set editor.drag)
|
|
66
79
|
function isFileDrag(event, editor) {
|
|
67
80
|
return !editor.drag && Array.from(event.dataTransfer?.types || []).includes("Files")
|
|
@@ -78,6 +91,7 @@ export class Canvas {
|
|
|
78
91
|
this.hoverId = null
|
|
79
92
|
this.mode = "edit"
|
|
80
93
|
this.free = new FreeLayout(this)
|
|
94
|
+
this.pan = new Pan(this)
|
|
81
95
|
}
|
|
82
96
|
|
|
83
97
|
get doc() {
|
|
@@ -107,6 +121,15 @@ export class Canvas {
|
|
|
107
121
|
// overlay's coordinates are the document's
|
|
108
122
|
doc.documentElement.append(this.overlay)
|
|
109
123
|
this.win.scrollTo(0, scrollY)
|
|
124
|
+
// ⌘ or Ctrl and the wheel, or a pinch on a trackpad, zooms where the pointer is
|
|
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()
|
|
110
133
|
if (mode === "edit") {
|
|
111
134
|
this.listen()
|
|
112
135
|
this.annotate()
|
|
@@ -496,14 +519,21 @@ export class Canvas {
|
|
|
496
519
|
this.refresh()
|
|
497
520
|
}
|
|
498
521
|
|
|
499
|
-
// Converts a rect in iframe viewport coordinates to the parent page's
|
|
522
|
+
// Converts a rect in iframe viewport coordinates to the parent page's
|
|
523
|
+
// viewport, the iframe scaled as the canvas is zoomed
|
|
500
524
|
toParentRect(rect) {
|
|
501
|
-
|
|
502
|
-
return { left: rect.left + frame.left, top: rect.top + frame.top, right: rect.right + frame.left, bottom: rect.bottom + frame.top, width: rect.width, height: rect.height }
|
|
525
|
+
return frameToPage(this.frame, rect)
|
|
503
526
|
}
|
|
504
527
|
|
|
505
528
|
// --- events ---------------------------------------------------------------
|
|
506
529
|
|
|
530
|
+
onWheel(event) {
|
|
531
|
+
if (!event.ctrlKey && !event.metaKey) return
|
|
532
|
+
event.preventDefault()
|
|
533
|
+
const delta = event.deltaMode === 1 ? event.deltaY * 16 : event.deltaY
|
|
534
|
+
this.editor.setZoom(this.editor.zoom * Math.exp(-delta / 200), { at: { x: event.clientX, y: event.clientY } })
|
|
535
|
+
}
|
|
536
|
+
|
|
507
537
|
onMove(event) {
|
|
508
538
|
if (this.editor.drag || this.free.dragging || this.resizing) return
|
|
509
539
|
const hit = this.hit(event.target)
|
|
@@ -520,6 +550,7 @@ export class Canvas {
|
|
|
520
550
|
if (event.target.closest?.("#tess-overlay")) return
|
|
521
551
|
event.preventDefault()
|
|
522
552
|
if (this.resized) return
|
|
553
|
+
if (this.pan.swallowClick()) return
|
|
523
554
|
if (this.openLink(event)) return
|
|
524
555
|
if (this.free.swallowClick()) return
|
|
525
556
|
const hit = this.hit(event.target)
|
|
@@ -734,3 +765,112 @@ export function showText(element, value) {
|
|
|
734
765
|
})
|
|
735
766
|
)
|
|
736
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
|
+
}
|
|
@@ -30,6 +30,7 @@ const paths = {
|
|
|
30
30
|
"panels-right": '<rect x="3" y="4" width="18" height="16" rx="2"/><path d="M14 4v16"/><path d="M16.5 8h2M16.5 11h2" opacity=".6"/>',
|
|
31
31
|
lock: '<rect x="5" y="11" width="14" height="10" rx="2"/><path d="M8 11V7a4 4 0 0 1 8 0v4"/>',
|
|
32
32
|
plus: '<path d="M12 5v14M5 12h14"/>',
|
|
33
|
+
minus: '<path d="M5 12h14"/>',
|
|
33
34
|
trash: '<path d="M4 7h16M10 11v6M14 11v6M6 7l1 13h10l1-13M9 7V4h6v3"/>',
|
|
34
35
|
copy: '<rect x="8" y="8" width="12" height="12" rx="2"/><path d="M16 8V6a2 2 0 0 0-2-2H6a2 2 0 0 0-2 2v8a2 2 0 0 0 2 2h2"/>',
|
|
35
36
|
move: '<path d="M12 3v18M3 12h18M9 6l3-3 3 3M9 18l3 3 3-3M6 9l-3 3 3 3M18 9l3 3-3 3"/>',
|
|
@@ -16,7 +16,7 @@ import { Color, Decoration, DecorationSet, Editor, Extension, Plugin, PluginKey,
|
|
|
16
16
|
import { t } from "tess_edit/core/i18n"
|
|
17
17
|
import { missingArguments, translationCalls } from "tess_edit/core/translations"
|
|
18
18
|
import { valueCalls } from "tess_edit/core/values"
|
|
19
|
-
import { showText } from "tess_edit/ui/canvas"
|
|
19
|
+
import { frameToPage, showText } from "tess_edit/ui/canvas"
|
|
20
20
|
import { askText } from "tess_edit/ui/dialog"
|
|
21
21
|
import { h } from "tess_edit/ui/dom"
|
|
22
22
|
import { icon } from "tess_edit/ui/icons"
|
|
@@ -291,8 +291,8 @@ function tiptapAdapter(editor, scope) {
|
|
|
291
291
|
// The caret's place in the iframe, in the page's viewport
|
|
292
292
|
rect() {
|
|
293
293
|
const caret = editor.view.coordsAtPos(editor.state.selection.from)
|
|
294
|
-
const frame = editor.view.dom.ownerDocument.defaultView.frameElement
|
|
295
|
-
return
|
|
294
|
+
const frame = editor.view.dom.ownerDocument.defaultView.frameElement
|
|
295
|
+
return frame ? frameToPage(frame, caret) : caret
|
|
296
296
|
}
|
|
297
297
|
}
|
|
298
298
|
}
|
data/config/locales/en.yml
CHANGED
|
@@ -44,6 +44,7 @@ en:
|
|
|
44
44
|
at_least: "At least"
|
|
45
45
|
at_most: "At most"
|
|
46
46
|
auto: "Auto"
|
|
47
|
+
back_to_100_0: "Back to 100% (⌘0)"
|
|
47
48
|
background: "Background"
|
|
48
49
|
background_image: "Background image"
|
|
49
50
|
between_rows: "Between rows"
|
|
@@ -96,6 +97,7 @@ en:
|
|
|
96
97
|
drag_blocks_onto_the_canvas_or_into_the_layers_tree_liquid_b: "Drag blocks onto the canvas or into the Layers tree. Liquid blocks wrap other blocks in {% for %} or {% if %}."
|
|
97
98
|
drag_onto_the_canvas_or_click_to_add: "Drag onto the canvas, or click to add"
|
|
98
99
|
drag_to_move: "Drag to move"
|
|
100
|
+
drag_to_move_it_to_another_panel: "Drag to move it to another panel"
|
|
99
101
|
drag_to_resize: "Drag to resize"
|
|
100
102
|
drag_to_set_the_column_s_width: "Drag to set the column's width"
|
|
101
103
|
drop_a_cell_here: "Drop a cell here"
|
|
@@ -116,6 +118,7 @@ en:
|
|
|
116
118
|
every_other_row: "Every other row"
|
|
117
119
|
expand: "Expand"
|
|
118
120
|
find_in_source: "Find in %{source}"
|
|
121
|
+
fit_the_canvas_1: "Fit the canvas (⇧1)"
|
|
119
122
|
font_family: "Font family"
|
|
120
123
|
font_size: "Font size"
|
|
121
124
|
font_weight: "Font weight"
|
|
@@ -207,6 +210,8 @@ en:
|
|
|
207
210
|
paragraph_style: "Paragraph style"
|
|
208
211
|
part_of_the_layout: "Part of the layout"
|
|
209
212
|
preview: "Preview"
|
|
213
|
+
put_it_in_a_panel_on_the_left: "Put it in a panel on the left"
|
|
214
|
+
put_it_in_a_panel_on_the_right: "Put it in a panel on the right"
|
|
210
215
|
radius: "Radius"
|
|
211
216
|
redo_z: "Redo (⇧⌘Z)"
|
|
212
217
|
remove: "Remove"
|
|
@@ -282,3 +287,6 @@ en:
|
|
|
282
287
|
whether_it_s_the_last: "Whether it's the last"
|
|
283
288
|
width: "Width"
|
|
284
289
|
without: "{% %{tag} %} without {% %{block} %}"
|
|
290
|
+
zoom: "Zoom"
|
|
291
|
+
zoom_in: "Zoom in (⌘+)"
|
|
292
|
+
zoom_out: "Zoom out (⌘−)"
|
data/config/locales/nl.yml
CHANGED
|
@@ -44,6 +44,7 @@ nl:
|
|
|
44
44
|
at_least: "Minstens"
|
|
45
45
|
at_most: "Hoogstens"
|
|
46
46
|
auto: "Automatisch"
|
|
47
|
+
back_to_100_0: "Terug naar 100% (⌘0)"
|
|
47
48
|
background: "Achtergrond"
|
|
48
49
|
background_image: "Achtergrondafbeelding"
|
|
49
50
|
between_rows: "Tussen rijen"
|
|
@@ -96,6 +97,7 @@ nl:
|
|
|
96
97
|
drag_blocks_onto_the_canvas_or_into_the_layers_tree_liquid_b: "Sleep blokken naar het canvas of in de boom bij Lagen. Liquid-blokken zetten andere blokken in {% for %} of {% if %}."
|
|
97
98
|
drag_onto_the_canvas_or_click_to_add: "Sleep naar het canvas, of klik om toe te voegen"
|
|
98
99
|
drag_to_move: "Sleep om te verplaatsen"
|
|
100
|
+
drag_to_move_it_to_another_panel: "Sleep om het naar een ander paneel te verplaatsen"
|
|
99
101
|
drag_to_resize: "Sleep om het formaat te wijzigen"
|
|
100
102
|
drag_to_set_the_column_s_width: "Sleep om de kolombreedte in te stellen"
|
|
101
103
|
drop_a_cell_here: "Zet hier een cel neer"
|
|
@@ -116,6 +118,7 @@ nl:
|
|
|
116
118
|
every_other_row: "Om de andere rij"
|
|
117
119
|
expand: "Vergroten"
|
|
118
120
|
find_in_source: "Zoeken in %{source}"
|
|
121
|
+
fit_the_canvas_1: "Canvas passend maken (⇧1)"
|
|
119
122
|
font_family: "Lettertype"
|
|
120
123
|
font_size: "Lettergrootte"
|
|
121
124
|
font_weight: "Letterdikte"
|
|
@@ -207,6 +210,8 @@ nl:
|
|
|
207
210
|
paragraph_style: "Alineastijl"
|
|
208
211
|
part_of_the_layout: "Onderdeel van de layout"
|
|
209
212
|
preview: "Voorbeeld"
|
|
213
|
+
put_it_in_a_panel_on_the_left: "Zet het in een paneel links"
|
|
214
|
+
put_it_in_a_panel_on_the_right: "Zet het in een paneel rechts"
|
|
210
215
|
radius: "Afronding"
|
|
211
216
|
redo_z: "Opnieuw (⇧⌘Z)"
|
|
212
217
|
remove: "Verwijderen"
|
|
@@ -282,3 +287,6 @@ nl:
|
|
|
282
287
|
whether_it_s_the_last: "Of het de laatste is"
|
|
283
288
|
width: "Breedte"
|
|
284
289
|
without: "{% %{tag} %} zonder {% %{block} %}"
|
|
290
|
+
zoom: "Zoom"
|
|
291
|
+
zoom_in: "Inzoomen (⌘+)"
|
|
292
|
+
zoom_out: "Uitzoomen (⌘−)"
|
data/lib/tess_edit/version.rb
CHANGED