tess_edit 0.6.0 → 0.6.2
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 +15 -2
- data/app/javascript/tess_edit/controllers/editor_controller.js +366 -68
- data/app/javascript/tess_edit/core/registry.js +12 -2
- data/app/javascript/tess_edit/ui/canvas.js +23 -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: 4606ec9405953c28850c78e56ba84dbd98746d3b5304908915cb122130b0ad54
|
|
4
|
+
data.tar.gz: 6b97b338496fa61698751df3f4fadb6307e583a1ada2be8ccd9e903fad99f17b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6cf843dc450464c7273b05f24f38f9299a91525785a1dea7291ae1aa3d00228f4bddf8559c0721ad1516146c79006fb1b4a69c691ff7682e3ab633e78441937c
|
|
7
|
+
data.tar.gz: faf9a015532294fa7d5dbf2cfcead3085a7e93acf634d37c7ee5adbc063e6628b08ce7785d364688f2ba74e4064b190fa71b0c22aed80f257a396e94dd19a3eb
|
data/README.md
CHANGED
|
@@ -31,7 +31,8 @@ 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.
|
|
35
36
|
- Dark mode that follows the host app's.
|
|
36
37
|
- Code dialog to view, copy or download the JSON and the kit's outputs, and to load JSON.
|
|
37
38
|
- 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 +103,7 @@ Give the controller an element with a height, the kit it makes and, optionally,
|
|
|
102
103
|
|
|
103
104
|
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
105
|
|
|
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;
|
|
106
|
+
`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
107
|
|
|
107
108
|
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
109
|
|
|
@@ -458,6 +459,18 @@ TessEdit's own blocks are part of no kit until a kit takes them in: `extendBlock
|
|
|
458
459
|
|
|
459
460
|
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
461
|
|
|
462
|
+
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:
|
|
463
|
+
|
|
464
|
+
```js
|
|
465
|
+
registerKit({
|
|
466
|
+
…,
|
|
467
|
+
panels: [{ key: "test", label: "Test", render: (element, editor) => { /* fill element, once */ } }],
|
|
468
|
+
canvas: async (doc, { editor, panel }) => … // panel: the key of the kit's panel that is open, or null
|
|
469
|
+
})
|
|
470
|
+
```
|
|
471
|
+
|
|
472
|
+
`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.
|
|
473
|
+
|
|
461
474
|
Loading a document into the editor of another kit fails with a message saying which editor it is for.
|
|
462
475
|
|
|
463
476
|
A kit can leave out `blocks`: with `blocks: false` it is its root alone, such as a text message with its fields in Inspect, and the editor has no Blocks and Layers panels. Its `canvas` and `outputs` hooks get the editor's `options` and `element` too, for a canvas that previews from your app (`/?kit=memo` in the demo), where a link with `data-tess-open` opens in a new tab instead of selecting; the canvas renders again when `data-tess-edit-variables-url-value` changes. A field's `hint` can be a function of its value, `` hint: (value, node) => `${value.length} / 160` ``, kept up to date as it's typed. Code fields color `html`, `xml`, `css` and `yaml`.
|
|
@@ -84,9 +84,16 @@ import { debounce, h } from "tess_edit/ui/dom"
|
|
|
84
84
|
import { icon } from "tess_edit/ui/icons"
|
|
85
85
|
|
|
86
86
|
const TOOL = "w-8 h-8 flex items-center justify-center rounded-md text-gray-600 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-700 hover:text-gray-900 dark:hover:text-gray-100 disabled:opacity-30 disabled:hover:bg-transparent"
|
|
87
|
-
const TAB = "px-3 h-12 text-[13px] font-medium border-b-2 -mb-px"
|
|
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
|
|
@@ -437,14 +452,29 @@ export default class extends Controller {
|
|
|
437
452
|
build() {
|
|
438
453
|
this.blocksElement = h("div", { class: "flex-1 overflow-y-auto pb-4" })
|
|
439
454
|
this.treeElement = h("div", { class: "flex-1 overflow-y-auto" })
|
|
440
|
-
|
|
455
|
+
// The kit's own panels (registerKit's panels), a tab each after Inspect
|
|
456
|
+
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 } }) }))
|
|
441
457
|
this.inspectorElement = h("div", { class: "flex flex-1 flex-col min-h-0", dataset: { tessEditPanel: "inspect" } })
|
|
442
|
-
|
|
458
|
+
// Each tab is a panel, in the pane on either side of the canvas it was put in
|
|
459
|
+
this.tabs = this.hasBlocks
|
|
460
|
+
? [
|
|
461
|
+
{ key: "blocks", label: "Blocks", element: this.blocksElement },
|
|
462
|
+
{ key: "layers", label: "Layers", element: this.treeElement },
|
|
463
|
+
{ key: "inspect", label: "Inspect", element: this.inspectorElement },
|
|
464
|
+
...this.kitPanels.map((panel) => ({ key: panel.key, label: panel.label, element: panel.element }))
|
|
465
|
+
]
|
|
466
|
+
: []
|
|
467
|
+
this.arrangement = this.storedArrangement() || this.preset([this.storedPanels(), this.panelsValue].find((value) => PANELS.includes(value)) || "split")
|
|
468
|
+
this.panes = Object.fromEntries(SIDES.map((side) => [side, { side, element: h("aside", { dataset: { tessEditPane: side } }), strip: this.tabStrip(side) }]))
|
|
443
469
|
this.inspectPanel = h("aside")
|
|
444
470
|
this.sheetClose = h("button", { type: "button", title: t("Hide panels"), class: `${TOOL} ml-auto self-center`, html: icon("close"), onclick: () => this.setSheetOpen(false) })
|
|
445
471
|
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" })
|
|
446
|
-
|
|
447
|
-
|
|
472
|
+
// Zoomed by scaling the iframe (applyZoom): what's in it lays out as in a
|
|
473
|
+
// browser zoomed as much
|
|
474
|
+
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) }) })
|
|
475
|
+
this.frameWrap = h("div", { class: "relative h-full mx-auto overflow-hidden transition-[width] duration-200" }, this.frame)
|
|
476
|
+
// Where a tab dragged off its pane makes a pane of its own on a side that has none
|
|
477
|
+
this.dropZones = Object.fromEntries(SIDES.map((side) => [side, this.dropZone(side)]))
|
|
448
478
|
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" })
|
|
449
479
|
this.body = h("div", { class: "flex flex-1 min-h-0" })
|
|
450
480
|
|
|
@@ -455,7 +485,7 @@ export default class extends Controller {
|
|
|
455
485
|
this.body
|
|
456
486
|
)
|
|
457
487
|
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" })
|
|
458
|
-
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)
|
|
488
|
+
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)
|
|
459
489
|
this.arrangePanels()
|
|
460
490
|
this.element.append(this.root)
|
|
461
491
|
|
|
@@ -464,6 +494,7 @@ export default class extends Controller {
|
|
|
464
494
|
this.inspector = new Inspector(this, this.inspectorElement)
|
|
465
495
|
this.textEditing = new TextEditing(this.textToolbar, { menu: this.variableMenu, editor: this })
|
|
466
496
|
renderBlocksPanel(this, this.blocksElement)
|
|
497
|
+
for (const panel of this.kitPanels) panel.render?.(panel.element, this)
|
|
467
498
|
this.observeWidth()
|
|
468
499
|
|
|
469
500
|
// The insert menu closes on a mousedown outside it (here or in the canvas,
|
|
@@ -484,9 +515,10 @@ export default class extends Controller {
|
|
|
484
515
|
window.addEventListener("resize", this.closeMenuOnResize)
|
|
485
516
|
}
|
|
486
517
|
|
|
487
|
-
//
|
|
488
|
-
// one
|
|
489
|
-
//
|
|
518
|
+
// The panes either side of the canvas, each with the tabs put in it (see
|
|
519
|
+
// moveTab); one without tabs isn't shown. Narrow, the panes are one on the
|
|
520
|
+
// left (or the right, when that's the only one); compact, they're one sheet
|
|
521
|
+
// below the canvas, while it is open.
|
|
490
522
|
arrangePanels() {
|
|
491
523
|
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`
|
|
492
524
|
const sheetClass = `${panelClass("border-t", "h-1/2")}${this.sheetOpen ? "" : " hidden"}`
|
|
@@ -497,31 +529,178 @@ export default class extends Controller {
|
|
|
497
529
|
if (!this.hasBlocks) {
|
|
498
530
|
this.inspectPanel.className = this.compact ? sheetClass : panelClass("border-l", "w-80")
|
|
499
531
|
const children = this.compact ? [this.sheetHeader(t("Inspect")), this.inspectorElement] : [this.inspectorElement]
|
|
500
|
-
|
|
501
|
-
if (current.length !== children.length || children.some((child, index) => current[index] !== child)) this.inspectPanel.replaceChildren(...children)
|
|
532
|
+
setChildren(this.inspectPanel, children)
|
|
502
533
|
if (this.main.nextSibling !== this.inspectPanel) this.main.after(this.inspectPanel)
|
|
503
534
|
return
|
|
504
535
|
}
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
this.
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
this.
|
|
520
|
-
|
|
521
|
-
|
|
536
|
+
const shown = this.shownPanes
|
|
537
|
+
const both = shown.length === 2
|
|
538
|
+
for (const side of SIDES) {
|
|
539
|
+
const pane = this.panes[side]
|
|
540
|
+
const showing = shown.find((each) => each.element === pane.element)
|
|
541
|
+
if (!showing) {
|
|
542
|
+
pane.element.remove()
|
|
543
|
+
continue
|
|
544
|
+
}
|
|
545
|
+
const width = !both ? "w-80" : showing.keys.includes("inspect") ? "w-80" : "w-64"
|
|
546
|
+
pane.element.className = showing.side === "sheet" ? sheetClass : panelClass(side === "left" ? "border-r" : "border-l", width)
|
|
547
|
+
setChildren(pane.element, [pane.strip, ...showing.keys.map((key) => this.tab(key).element)])
|
|
548
|
+
if (side === "left" && showing.side !== "sheet") {
|
|
549
|
+
if (this.main.previousSibling !== pane.element) this.main.before(pane.element)
|
|
550
|
+
} else if (this.main.nextSibling !== pane.element) this.main.after(pane.element)
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
// The panes shown, by the side they show on, with their tabs in order
|
|
555
|
+
get shownPanes() {
|
|
556
|
+
const { left, right } = this.arrangement
|
|
557
|
+
if (this.compact) return [{ side: "sheet", element: this.panes.left.element, strip: this.panes.left.strip, keys: [...left, ...right] }]
|
|
558
|
+
if (this.narrow && left.length && right.length) return [{ side: "left", element: this.panes.left.element, strip: this.panes.left.strip, keys: [...left, ...right] }]
|
|
559
|
+
return SIDES.filter((side) => this.arrangement[side].length).map((side) => ({ ...this.panes[side], keys: this.arrangement[side] }))
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
tab(key) {
|
|
563
|
+
return this.tabs.find((tab) => tab.key === key)
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
// The tabs in the panes a preset puts them in: all on one side, or split
|
|
567
|
+
// with Inspect on the right
|
|
568
|
+
preset(panels) {
|
|
569
|
+
const keys = this.tabs.map((tab) => tab.key)
|
|
570
|
+
if (panels === "left") return { left: keys, right: [] }
|
|
571
|
+
if (panels === "right") return { left: [], right: keys }
|
|
572
|
+
return { left: keys.filter((key) => key !== "inspect"), right: keys.filter((key) => key === "inspect") }
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
// Where the tabs were put last, with tabs it doesn't know of yet (a kit's
|
|
576
|
+
// new panel) where the split preset puts them
|
|
577
|
+
storedArrangement() {
|
|
578
|
+
if (!this.hasBlocks) return null
|
|
579
|
+
let stored
|
|
580
|
+
try {
|
|
581
|
+
stored = JSON.parse(this.stored(`${TABS_KEY}:${this.kit.key}`) || "null")
|
|
582
|
+
} catch {
|
|
583
|
+
return null
|
|
584
|
+
}
|
|
585
|
+
if (!stored || !SIDES.every((side) => Array.isArray(stored[side]))) return null
|
|
586
|
+
const keys = this.tabs.map((tab) => tab.key)
|
|
587
|
+
const arrangement = Object.fromEntries(SIDES.map((side) => [side, [...new Set(stored[side])].filter((key) => keys.includes(key))]))
|
|
588
|
+
arrangement.right = arrangement.right.filter((key) => !arrangement.left.includes(key))
|
|
589
|
+
const split = this.preset("split")
|
|
590
|
+
for (const key of keys) {
|
|
591
|
+
if (arrangement.left.includes(key) || arrangement.right.includes(key)) continue
|
|
592
|
+
arrangement[split.left.includes(key) ? "left" : "right"].push(key)
|
|
593
|
+
}
|
|
594
|
+
return arrangement
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
// The preset the arrangement is: a side with no tabs, or split
|
|
598
|
+
get panels() {
|
|
599
|
+
if (!this.arrangement.right.length) return "left"
|
|
600
|
+
if (!this.arrangement.left.length) return "right"
|
|
601
|
+
return "split"
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
// A pane's tabs, which a tab can be dragged to from the other pane, and
|
|
605
|
+
// within to put it elsewhere in the row
|
|
606
|
+
tabStrip(side) {
|
|
607
|
+
const strip = h("div", { role: "tablist", class: "flex border-b border-gray-200 dark:border-gray-700 px-2 shrink-0 overflow-x-auto" })
|
|
608
|
+
strip.addEventListener("dragover", (event) => {
|
|
609
|
+
if (!this.tabDrag) return
|
|
610
|
+
event.preventDefault()
|
|
611
|
+
event.dataTransfer.dropEffect = "move"
|
|
612
|
+
this.showTabDrop(strip, this.tabDropIndex(strip, event.clientX))
|
|
613
|
+
})
|
|
614
|
+
strip.addEventListener("dragleave", (event) => !strip.contains(event.relatedTarget) && this.showTabDrop(null))
|
|
615
|
+
strip.addEventListener("drop", (event) => {
|
|
616
|
+
if (!this.tabDrag) return
|
|
617
|
+
event.preventDefault()
|
|
618
|
+
this.moveTab(this.tabDrag, this.paneSide(strip), this.tabDropIndex(strip, event.clientX))
|
|
619
|
+
})
|
|
620
|
+
return strip
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
// The side of the pane a strip is in (the left pane is also the combined one)
|
|
624
|
+
paneSide(strip) {
|
|
625
|
+
return SIDES.find((side) => this.panes[side].strip === strip)
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
// Where in a strip's row of tabs a tab let go at x goes
|
|
629
|
+
tabDropIndex(strip, x) {
|
|
630
|
+
const buttons = [...strip.querySelectorAll("[data-tess-edit-tab]")].filter((button) => button.dataset.tessEditTab !== this.tabDrag)
|
|
631
|
+
const index = buttons.findIndex((button) => {
|
|
632
|
+
const rect = button.getBoundingClientRect()
|
|
633
|
+
return x < rect.left + rect.width / 2
|
|
634
|
+
})
|
|
635
|
+
return index === -1 ? buttons.length : index
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
showTabDrop(strip, index) {
|
|
639
|
+
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" })
|
|
640
|
+
if (!strip) return this.tabIndicator.remove()
|
|
641
|
+
const buttons = [...strip.querySelectorAll("[data-tess-edit-tab]")].filter((button) => button.dataset.tessEditTab !== this.tabDrag)
|
|
642
|
+
if (buttons[index]) buttons[index].before(this.tabIndicator)
|
|
643
|
+
else if (buttons.length) buttons.at(-1).after(this.tabIndicator)
|
|
644
|
+
else strip.append(this.tabIndicator)
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
// A side without a pane, while a tab is dragged: let go there, it's that
|
|
648
|
+
// side's pane
|
|
649
|
+
dropZone(side) {
|
|
650
|
+
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"))
|
|
651
|
+
zone.addEventListener("dragover", (event) => {
|
|
652
|
+
if (!this.tabDrag) return
|
|
653
|
+
event.preventDefault()
|
|
654
|
+
event.dataTransfer.dropEffect = "move"
|
|
655
|
+
zone.classList.add("bg-blue-100")
|
|
656
|
+
})
|
|
657
|
+
zone.addEventListener("dragleave", () => zone.classList.remove("bg-blue-100"))
|
|
658
|
+
zone.addEventListener("drop", (event) => {
|
|
659
|
+
if (!this.tabDrag) return
|
|
660
|
+
event.preventDefault()
|
|
661
|
+
this.moveTab(this.tabDrag, side, 0)
|
|
662
|
+
})
|
|
663
|
+
return zone
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
startTabDrag(event, key) {
|
|
667
|
+
this.tabDrag = key
|
|
668
|
+
event.dataTransfer.effectAllowed = "move"
|
|
669
|
+
event.dataTransfer.setData("text/plain", key)
|
|
670
|
+
// A side with no pane takes one; not while the panes are combined
|
|
671
|
+
for (const side of SIDES) this.dropZones[side].classList.toggle("hidden", !!this.arrangement[side].length)
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
endTabDrag() {
|
|
675
|
+
this.tabDrag = null
|
|
676
|
+
this.showTabDrop(null)
|
|
677
|
+
for (const zone of Object.values(this.dropZones)) {
|
|
678
|
+
zone.classList.add("hidden")
|
|
679
|
+
zone.classList.remove("bg-blue-100")
|
|
522
680
|
}
|
|
523
681
|
}
|
|
524
682
|
|
|
683
|
+
// Puts a tab in a pane, at a place in its row, open there; remembered for
|
|
684
|
+
// the kit. The pane it left opens its first tab, or goes when it has none.
|
|
685
|
+
moveTab(key, side, index) {
|
|
686
|
+
const panel = this.panel
|
|
687
|
+
const arrangement = Object.fromEntries(SIDES.map((each) => [each, this.arrangement[each].filter((other) => other !== key)]))
|
|
688
|
+
arrangement[side].splice(Math.min(index, arrangement[side].length), 0, key)
|
|
689
|
+
this.endTabDrag()
|
|
690
|
+
this.setArrangement(arrangement)
|
|
691
|
+
this.openTabs[side] = key
|
|
692
|
+
this.renderLeftTabs()
|
|
693
|
+
if (panel !== this.panel) this.renderCanvas()
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
setArrangement(arrangement) {
|
|
697
|
+
this.arrangement = arrangement
|
|
698
|
+
try {
|
|
699
|
+
localStorage.setItem(`${TABS_KEY}:${this.kit.key}`, JSON.stringify(arrangement))
|
|
700
|
+
} catch {}
|
|
701
|
+
this.applyPanels()
|
|
702
|
+
}
|
|
703
|
+
|
|
525
704
|
// The sheet's title bar for a kit without blocks, which has no tabs
|
|
526
705
|
sheetHeader(title) {
|
|
527
706
|
this.sheetTitle ||= h("div", { class: "flex items-center h-12 px-3 border-b border-gray-200 dark:border-gray-700 shrink-0 text-[13px] font-medium" })
|
|
@@ -533,25 +712,25 @@ export default class extends Controller {
|
|
|
533
712
|
setSheetOpen(open) {
|
|
534
713
|
if (!this.compact || open === this.sheetOpen) return
|
|
535
714
|
this.sheetOpen = open
|
|
536
|
-
;(this.hasBlocks ? this.
|
|
715
|
+
;(this.hasBlocks ? this.panes.left.element : this.inspectPanel).classList.toggle("hidden", !open)
|
|
537
716
|
this.renderTopBar()
|
|
538
717
|
this.canvas.refresh()
|
|
539
718
|
}
|
|
540
719
|
|
|
720
|
+
// Puts the tabs as a preset does: all on the left or the right, or split
|
|
541
721
|
setPanels(panels) {
|
|
542
722
|
if (!PANELS.includes(panels)) return
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
} catch {}
|
|
547
|
-
this.applyPanels()
|
|
723
|
+
const panel = this.panel
|
|
724
|
+
this.setArrangement(this.preset(panels))
|
|
725
|
+
if (panel !== this.panel) this.renderCanvas()
|
|
548
726
|
}
|
|
549
727
|
|
|
550
728
|
applyPanels() {
|
|
551
|
-
|
|
729
|
+
const panel = this.panel
|
|
552
730
|
this.arrangePanels()
|
|
553
731
|
this.renderTopBar()
|
|
554
732
|
this.renderLeftTabs()
|
|
733
|
+
if (this.canvas && panel !== this.panel) this.renderCanvas()
|
|
555
734
|
}
|
|
556
735
|
|
|
557
736
|
// Combines the panels while the editor is narrower than NARROW_WIDTH, and
|
|
@@ -566,17 +745,18 @@ export default class extends Controller {
|
|
|
566
745
|
if (compact !== this.compact) this.sheetOpen = false
|
|
567
746
|
this.compact = compact
|
|
568
747
|
this.applyPanels()
|
|
569
|
-
this.
|
|
748
|
+
this.applyZoom()
|
|
570
749
|
})
|
|
571
750
|
this.resizeObserver.observe(this.root)
|
|
572
751
|
}
|
|
573
752
|
|
|
574
|
-
// The layout in use:
|
|
575
|
-
//
|
|
753
|
+
// The layout in use: a pane on each side ("split"), one on the left or the
|
|
754
|
+
// right, or the sheet; a kit without blocks has Inspect on the right
|
|
576
755
|
get layout() {
|
|
577
756
|
if (!this.hasBlocks) return "split"
|
|
578
757
|
if (this.compact) return "sheet"
|
|
579
|
-
|
|
758
|
+
const shown = this.shownPanes
|
|
759
|
+
return shown.length === 2 ? "split" : shown[0]?.side || "left"
|
|
580
760
|
}
|
|
581
761
|
|
|
582
762
|
get hasBlocks() {
|
|
@@ -595,10 +775,6 @@ export default class extends Controller {
|
|
|
595
775
|
}
|
|
596
776
|
}
|
|
597
777
|
|
|
598
|
-
get combined() {
|
|
599
|
-
return this.layout !== "split"
|
|
600
|
-
}
|
|
601
|
-
|
|
602
778
|
renderAll() {
|
|
603
779
|
this.liquidChecker?.schedule()
|
|
604
780
|
this.renderTopBar()
|
|
@@ -633,12 +809,13 @@ export default class extends Controller {
|
|
|
633
809
|
this.compact ? null : h("span", { class: "font-semibold text-gray-900 dark:text-gray-100 mr-3" }, t(this.kit.name)),
|
|
634
810
|
toggle(this.mode, [["edit", "edit", t("Edit")], ["preview", "eye", this.kit.previewTitle ? t(this.kit.previewTitle) : t("Preview")]], (mode) => this.setMode(mode)),
|
|
635
811
|
this.kit.devices?.length ? toggle(this.device, this.kit.devices.map((device) => [device.key, device.icon, t(device.title)]), (device) => this.setDevice(device)) : null,
|
|
812
|
+
this.zoomControls(),
|
|
636
813
|
this.translations.enabled ? this.translationLocaleMenu() : null,
|
|
637
814
|
h("div", { class: "flex-1" }),
|
|
638
815
|
// A compact editor shows its panels or not; one without blocks has none to arrange
|
|
639
816
|
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) }),
|
|
640
817
|
this.hasBlocks && !this.compact && toggle(
|
|
641
|
-
this.layout,
|
|
818
|
+
this.narrow ? this.layout : this.panels,
|
|
642
819
|
[
|
|
643
820
|
["left", "panels-left", t("All panels on the left")],
|
|
644
821
|
["split", "panels-split", t(this.narrow ? "Too narrow to split the panels" : "Blocks on the left, Inspect on the right"), this.narrow],
|
|
@@ -678,22 +855,134 @@ export default class extends Controller {
|
|
|
678
855
|
)
|
|
679
856
|
}
|
|
680
857
|
|
|
858
|
+
// Each pane's tabs, and its open one shown. A tab is dragged to the other
|
|
859
|
+
// pane, or to a side without one, while the panes are side by side.
|
|
681
860
|
renderLeftTabs() {
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
861
|
+
if (!this.hasBlocks) return
|
|
862
|
+
const movable = !this.compact && !(this.narrow && this.arrangement.left.length && this.arrangement.right.length)
|
|
863
|
+
for (const pane of this.shownPanes) {
|
|
864
|
+
const open = this.openTab(pane)
|
|
865
|
+
const tabs = pane.keys.map((key) =>
|
|
866
|
+
h(
|
|
867
|
+
"button",
|
|
868
|
+
{
|
|
869
|
+
type: "button",
|
|
870
|
+
role: "tab",
|
|
871
|
+
"aria-selected": String(open === key),
|
|
872
|
+
draggable: movable ? "true" : null,
|
|
873
|
+
title: movable ? t("Drag to move it to another panel") : null,
|
|
874
|
+
dataset: { tessEditTab: key },
|
|
875
|
+
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"}`,
|
|
876
|
+
onclick: () => this.setLeftTab(key),
|
|
877
|
+
ondragstart: (event) => this.startTabDrag(event, key),
|
|
878
|
+
ondragend: () => this.endTabDrag()
|
|
879
|
+
},
|
|
880
|
+
t(this.tab(key).label)
|
|
881
|
+
)
|
|
882
|
+
)
|
|
883
|
+
if (this.compact) tabs.push(this.sheetClose)
|
|
884
|
+
pane.strip.replaceChildren(...tabs)
|
|
885
|
+
for (const key of pane.keys) this.tab(key).element.classList.toggle("hidden", key !== open)
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
|
|
889
|
+
// The tab open in a pane: the one opened there last, else its first
|
|
890
|
+
openTab(pane) {
|
|
891
|
+
const open = this.openTabs[pane.side]
|
|
892
|
+
if (pane.keys.includes(open)) return open
|
|
893
|
+
if (pane.side !== "left" && pane.keys.includes(this.openTabs.left)) return this.openTabs.left
|
|
894
|
+
return pane.keys[0]
|
|
895
|
+
}
|
|
896
|
+
|
|
897
|
+
// Whether a tab is showing in its pane
|
|
898
|
+
isOpen(key) {
|
|
899
|
+
return this.shownPanes.some((pane) => this.openTab(pane) === key)
|
|
900
|
+
}
|
|
901
|
+
|
|
902
|
+
// The kit's panel that is open, if one is
|
|
903
|
+
get panel() {
|
|
904
|
+
if (!this.kitPanels.length) return null
|
|
905
|
+
return this.kitPanels.find((panel) => this.isOpen(panel.key))?.key || null
|
|
906
|
+
}
|
|
907
|
+
|
|
908
|
+
// Opens a tab in the pane it is in
|
|
909
|
+
setLeftTab(key) {
|
|
910
|
+
const pane = this.shownPanes.find((each) => each.keys.includes(key))
|
|
911
|
+
if (!pane) return
|
|
912
|
+
const panel = this.panel
|
|
913
|
+
this.openTabs[pane.side] = key
|
|
696
914
|
this.renderLeftTabs()
|
|
915
|
+
// The canvas is told which of the kit's panels is open, so it draws again when that changes
|
|
916
|
+
if (panel !== this.panel) this.renderCanvas()
|
|
917
|
+
}
|
|
918
|
+
|
|
919
|
+
// --- zoom -------------------------------------------------------------------------
|
|
920
|
+
|
|
921
|
+
// Out, the zoom (which fits the canvas, or back to 100%), and in
|
|
922
|
+
zoomControls() {
|
|
923
|
+
const percent = `${Math.round(this.zoom * 100)}%`
|
|
924
|
+
return h(
|
|
925
|
+
"div",
|
|
926
|
+
{ class: "ml-1 flex items-center rounded-lg bg-gray-100 dark:bg-gray-900 p-0.5" },
|
|
927
|
+
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) }),
|
|
928
|
+
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),
|
|
929
|
+
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) })
|
|
930
|
+
)
|
|
931
|
+
}
|
|
932
|
+
|
|
933
|
+
// To the next step in or out
|
|
934
|
+
zoomBy(direction) {
|
|
935
|
+
const next = direction > 0 ? ZOOMS.find((zoom) => zoom > this.zoom + 0.001) : [...ZOOMS].reverse().find((zoom) => zoom < this.zoom - 0.001)
|
|
936
|
+
this.setZoom(next ?? this.zoom)
|
|
937
|
+
}
|
|
938
|
+
|
|
939
|
+
// Zooms the canvas, keeping the point `at` (in the canvas's viewport) where
|
|
940
|
+
// it is; without it, the top left of what shows
|
|
941
|
+
setZoom(zoom, { at = null } = {}) {
|
|
942
|
+
zoom = Math.round(Math.min(MAX_ZOOM, Math.max(MIN_ZOOM, zoom)) * 100) / 100
|
|
943
|
+
if (zoom === this.zoom) return
|
|
944
|
+
const win = this.frame.contentWindow
|
|
945
|
+
const before = this.zoom
|
|
946
|
+
const point = at || { x: 0, y: 0 }
|
|
947
|
+
const scroll = win ? { x: win.scrollX + point.x, y: win.scrollY + point.y } : null
|
|
948
|
+
this.zoom = zoom
|
|
949
|
+
this.applyZoom()
|
|
950
|
+
if (scroll) win.scrollTo(scroll.x - (point.x * before) / zoom, scroll.y - (point.y * before) / zoom)
|
|
951
|
+
this.renderTopBar()
|
|
952
|
+
}
|
|
953
|
+
|
|
954
|
+
// The whole canvas in view, at most at 100%
|
|
955
|
+
zoomToFit() {
|
|
956
|
+
const doc = this.frame.contentDocument
|
|
957
|
+
if (!doc?.body) return
|
|
958
|
+
const range = doc.createRange()
|
|
959
|
+
range.selectNodeContents(doc.body)
|
|
960
|
+
const content = range.getBoundingClientRect()
|
|
961
|
+
const win = this.frame.contentWindow
|
|
962
|
+
const width = Math.max(content.width, 1) + 32
|
|
963
|
+
const height = Math.max(content.bottom + win.scrollY, 1) + 16
|
|
964
|
+
const box = this.frameWrap.parentElement.getBoundingClientRect()
|
|
965
|
+
const device = this.deviceWidth
|
|
966
|
+
const fit = Math.min(1, (device || box.width) / width, box.height / height)
|
|
967
|
+
this.setZoom(Math.floor(fit * 20) / 20)
|
|
968
|
+
win.scrollTo(0, 0)
|
|
969
|
+
}
|
|
970
|
+
|
|
971
|
+
// The iframe at the size that, scaled, fills its place: what's in it lays
|
|
972
|
+
// out in a viewport as much larger (or smaller) as it is zoomed out (or in)
|
|
973
|
+
applyZoom() {
|
|
974
|
+
const zoom = this.zoom
|
|
975
|
+
const scaled = zoom !== 1
|
|
976
|
+
Object.assign(this.frame.style, { width: scaled ? `${100 / zoom}%` : "", height: scaled ? `${100 / zoom}%` : "", transform: scaled ? `scale(${zoom})` : "" })
|
|
977
|
+
const width = this.deviceWidth
|
|
978
|
+
this.frameWrap.style.width = width ? `${width * zoom}px` : ""
|
|
979
|
+
this.canvas?.refresh()
|
|
980
|
+
}
|
|
981
|
+
|
|
982
|
+
// The device's width in pixels, when it has one (mobile, 375px)
|
|
983
|
+
get deviceWidth() {
|
|
984
|
+
const width = this.kit.devices?.find((option) => option.key === this.device)?.width
|
|
985
|
+
return width ? parseFloat(width) : null
|
|
697
986
|
}
|
|
698
987
|
|
|
699
988
|
setMode(mode) {
|
|
@@ -707,8 +996,8 @@ export default class extends Controller {
|
|
|
707
996
|
this.device = device
|
|
708
997
|
// A device without a width (desktop) fills the canvas area; one with a
|
|
709
998
|
// width (mobile, 375px) shows a full-height frame in the middle of it.
|
|
710
|
-
const width = this.
|
|
711
|
-
this.
|
|
999
|
+
const width = this.deviceWidth
|
|
1000
|
+
this.applyZoom()
|
|
712
1001
|
this.frameWrap.classList.toggle("shadow-sm", !!width)
|
|
713
1002
|
this.main.classList.toggle("px-4", !!width)
|
|
714
1003
|
this.renderTopBar()
|
|
@@ -729,7 +1018,7 @@ export default class extends Controller {
|
|
|
729
1018
|
|
|
730
1019
|
async renderCanvas() {
|
|
731
1020
|
if (this.editingId) return
|
|
732
|
-
const result = await this.run("canvas", (options) => this.kit.canvas(this.doc, { ...options, editor: this.mode === "edit" }))
|
|
1021
|
+
const result = await this.run("canvas", (options) => this.kit.canvas(this.doc, { ...options, editor: this.mode === "edit", panel: this.panel }))
|
|
733
1022
|
if (!result || this.editingId) return
|
|
734
1023
|
// A canvas the host renders can give the values it has
|
|
735
1024
|
if (result.values) this.values.set(result.values)
|
|
@@ -806,10 +1095,10 @@ export default class extends Controller {
|
|
|
806
1095
|
|
|
807
1096
|
// --- selection and editing ---------------------------------------------------
|
|
808
1097
|
|
|
809
|
-
// `reveal` (a click on the canvas)
|
|
810
|
-
//
|
|
1098
|
+
// `reveal` (a click on the canvas) opens the Inspect tab in its pane, and
|
|
1099
|
+
// the sheet on a compact editor.
|
|
811
1100
|
select(id, { reveal = false } = {}) {
|
|
812
|
-
if (reveal && this.
|
|
1101
|
+
if (reveal && this.hasBlocks && !this.isOpen("inspect")) this.setLeftTab("inspect")
|
|
813
1102
|
if (reveal) this.setSheetOpen(true)
|
|
814
1103
|
if (this.editingId && this.editingId !== id) this.stopEditing()
|
|
815
1104
|
if (!find(this.doc, id)) id = this.doc.id
|
|
@@ -964,7 +1253,7 @@ export default class extends Controller {
|
|
|
964
1253
|
const node = createFromPalette(key)
|
|
965
1254
|
this.commit((doc) => insert(doc, parentId, index, node))
|
|
966
1255
|
this.select(node.id)
|
|
967
|
-
this.
|
|
1256
|
+
this.isOpen("layers") && this.tree.render()
|
|
968
1257
|
}
|
|
969
1258
|
|
|
970
1259
|
// Clicking a tile: add inside the selection when it fits, otherwise after the
|
|
@@ -1142,8 +1431,17 @@ export default class extends Controller {
|
|
|
1142
1431
|
}
|
|
1143
1432
|
return
|
|
1144
1433
|
}
|
|
1434
|
+
// Zoom, also while typing in a field: ⌘+ and ⌘− in steps, ⌘0 back to 100%
|
|
1435
|
+
if (mod && !event.altKey && ["=", "+", "-", "0"].includes(event.key)) {
|
|
1436
|
+
event.preventDefault()
|
|
1437
|
+
event.key === "0" ? this.setZoom(1) : this.zoomBy(event.key === "-" ? -1 : 1)
|
|
1438
|
+
return
|
|
1439
|
+
}
|
|
1145
1440
|
if (typing) return
|
|
1146
|
-
if (mod && event.
|
|
1441
|
+
if (event.shiftKey && !mod && !event.altKey && event.code === "Digit1") {
|
|
1442
|
+
event.preventDefault()
|
|
1443
|
+
this.zoomToFit()
|
|
1444
|
+
} else if (mod && event.key.toLowerCase() === "z") {
|
|
1147
1445
|
event.preventDefault()
|
|
1148
1446
|
event.shiftKey ? this.redo() : this.undo()
|
|
1149
1447
|
} else if (mod && event.key.toLowerCase() === "y") {
|
|
@@ -60,12 +60,13 @@
|
|
|
60
60
|
// starter: () => doc, // optional: the sample document
|
|
61
61
|
// devices: [{ key, icon, title, width }], // optional: canvas widths in the top bar
|
|
62
62
|
// previewTitle: "…", // the Preview button's title
|
|
63
|
-
// canvas: async (doc, { editor, compileUrl, signal, options, element }) => ({ html, errors }),
|
|
63
|
+
// canvas: async (doc, { editor, compileUrl, signal, options, element, panel }) => ({ html, errors }),
|
|
64
64
|
// // the canvas's HTML, with the tess-<id> and tessph-<id>
|
|
65
65
|
// // classes when editor is true; null when aborted.
|
|
66
66
|
// // options are the editor's (data-tess-edit-options-value),
|
|
67
67
|
// // element its element, for a kit that reads its page;
|
|
68
68
|
// // a link with data-tess-open opens in a new tab
|
|
69
|
+
// // panel is the key of the kit's panel that is open, or null
|
|
69
70
|
// outputs: async (doc, { compileUrl, signal, options, element }) => ({ outputs: { html: "…" }, errors }),
|
|
70
71
|
// // what the editor stores besides the JSON (the inputs,
|
|
71
72
|
// // the change event and the Code dialog); null when aborted
|
|
@@ -73,6 +74,15 @@
|
|
|
73
74
|
// // by key; tiles it leaves out follow in registration order
|
|
74
75
|
// blocks: false, // optional: a kit of its root alone, such as a text
|
|
75
76
|
// // message, has no Blocks and Layers panels
|
|
77
|
+
// panels: [{ key: "test", label: "Test", render: (element, editor) => {} }],
|
|
78
|
+
// // optional: panels of the kit's own, a tab each after
|
|
79
|
+
// // Layers (and Inspect, when it is a tab). render fills its
|
|
80
|
+
// // element once, when the editor is built; editor is the
|
|
81
|
+
// // editor (its doc, select, renderCanvas, and its element,
|
|
82
|
+
// // which sends tess-edit:change). The canvas is told which
|
|
83
|
+
// // one is open (panel) and drawn again when that changes;
|
|
84
|
+
// // a panel that changes what it shows calls
|
|
85
|
+
// // editor.renderCanvas(). label is translated (t)
|
|
76
86
|
// notes: { html: "…" }, // optional: what each output is, in the Code dialog
|
|
77
87
|
// errors: "The note could not be rendered" // shown before the reasons
|
|
78
88
|
// })
|
|
@@ -104,7 +114,7 @@ export function registerKit(kit) {
|
|
|
104
114
|
if (!key || !name) throw new Error("A kit needs a key and a name")
|
|
105
115
|
if (!root) throw new Error(`Kit ${key} needs a root block type`)
|
|
106
116
|
if (typeof canvas !== "function" || typeof outputs !== "function") throw new Error(`Kit ${key} needs canvas(doc, options) and outputs(doc, options)`)
|
|
107
|
-
kitList.set(key, { devices: null, notes: {}, errors: KIT_ERRORS, aliases: [], ...kit })
|
|
117
|
+
kitList.set(key, { devices: null, notes: {}, errors: KIT_ERRORS, aliases: [], panels: [], ...kit })
|
|
108
118
|
return kitList.get(key)
|
|
109
119
|
}
|
|
110
120
|
|
|
@@ -62,6 +62,17 @@ a{cursor:default}
|
|
|
62
62
|
.tess-liquid-error{text-decoration:underline wavy rgba(220,38,38,.9);text-decoration-skip-ink:none;text-underline-offset:3px}
|
|
63
63
|
`
|
|
64
64
|
|
|
65
|
+
// A rect in an iframe's viewport in the page's, the iframe maybe scaled
|
|
66
|
+
export function frameToPage(frame, rect) {
|
|
67
|
+
const box = frame?.getBoundingClientRect() || { left: 0, top: 0, width: 1 }
|
|
68
|
+
const scale = frame?.offsetWidth ? box.width / frame.offsetWidth : 1
|
|
69
|
+
const left = box.left + rect.left * scale
|
|
70
|
+
const top = box.top + rect.top * scale
|
|
71
|
+
const width = (rect.right - rect.left) * scale
|
|
72
|
+
const height = (rect.bottom - rect.top) * scale
|
|
73
|
+
return { left, top, right: left + width, bottom: top + height, width, height }
|
|
74
|
+
}
|
|
75
|
+
|
|
65
76
|
// A file dragged in from outside the browser (block drags set editor.drag)
|
|
66
77
|
function isFileDrag(event, editor) {
|
|
67
78
|
return !editor.drag && Array.from(event.dataTransfer?.types || []).includes("Files")
|
|
@@ -107,6 +118,8 @@ export class Canvas {
|
|
|
107
118
|
// overlay's coordinates are the document's
|
|
108
119
|
doc.documentElement.append(this.overlay)
|
|
109
120
|
this.win.scrollTo(0, scrollY)
|
|
121
|
+
// ⌘ or Ctrl and the wheel, or a pinch on a trackpad, zooms where the pointer is
|
|
122
|
+
doc.addEventListener("wheel", (event) => this.onWheel(event), { passive: false })
|
|
110
123
|
if (mode === "edit") {
|
|
111
124
|
this.listen()
|
|
112
125
|
this.annotate()
|
|
@@ -496,14 +509,21 @@ export class Canvas {
|
|
|
496
509
|
this.refresh()
|
|
497
510
|
}
|
|
498
511
|
|
|
499
|
-
// Converts a rect in iframe viewport coordinates to the parent page's
|
|
512
|
+
// Converts a rect in iframe viewport coordinates to the parent page's
|
|
513
|
+
// viewport, the iframe scaled as the canvas is zoomed
|
|
500
514
|
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 }
|
|
515
|
+
return frameToPage(this.frame, rect)
|
|
503
516
|
}
|
|
504
517
|
|
|
505
518
|
// --- events ---------------------------------------------------------------
|
|
506
519
|
|
|
520
|
+
onWheel(event) {
|
|
521
|
+
if (!event.ctrlKey && !event.metaKey) return
|
|
522
|
+
event.preventDefault()
|
|
523
|
+
const delta = event.deltaMode === 1 ? event.deltaY * 16 : event.deltaY
|
|
524
|
+
this.editor.setZoom(this.editor.zoom * Math.exp(-delta / 200), { at: { x: event.clientX, y: event.clientY } })
|
|
525
|
+
}
|
|
526
|
+
|
|
507
527
|
onMove(event) {
|
|
508
528
|
if (this.editor.drag || this.free.dragging || this.resizing) return
|
|
509
529
|
const hit = this.hit(event.target)
|
|
@@ -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