tess_edit 0.6.0 → 0.6.1
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 +12 -0
- data/app/javascript/tess_edit/controllers/editor_controller.js +17 -4
- data/app/javascript/tess_edit/core/registry.js +12 -2
- 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: 8335fb097106c74abdf46d0df1489766f3868bd0bb08169b103a49b3542afd1b
|
|
4
|
+
data.tar.gz: a5aded7ba78002b81214a8f55ef4916a90c1e55a6d8a1dbe2d6747e67df96ba3
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7cb9c17a7e0e24780821b00b66ee30ee42167e9dd660e5c89fd68625c55fe6eb88307996d84f824c2851aa9603a0802a6f751ce5d39b0eb37fdc9c3321c25abc
|
|
7
|
+
data.tar.gz: 479ad383c95aff99940edc2e8fec3fa803aef1a682db1afc72ba8004b1511fd31dbbb8c7c90acfdf6d6ca376718bf0dbbf6c8c95960c2371abd046da238318fb
|
data/README.md
CHANGED
|
@@ -458,6 +458,18 @@ TessEdit's own blocks are part of no kit until a kit takes them in: `extendBlock
|
|
|
458
458
|
|
|
459
459
|
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
460
|
|
|
461
|
+
A kit can bring panels of its own, each a tab after Layers (and Inspect, when that is a tab), such as a test run of what is being designed:
|
|
462
|
+
|
|
463
|
+
```js
|
|
464
|
+
registerKit({
|
|
465
|
+
…,
|
|
466
|
+
panels: [{ key: "test", label: "Test", render: (element, editor) => { /* fill element, once */ } }],
|
|
467
|
+
canvas: async (doc, { editor, panel }) => … // panel: the key of the kit's panel that is open, or null
|
|
468
|
+
})
|
|
469
|
+
```
|
|
470
|
+
|
|
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.
|
|
472
|
+
|
|
461
473
|
Loading a document into the editor of another kit fails with a message saying which editor it is for.
|
|
462
474
|
|
|
463
475
|
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,7 +84,7 @@ 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
90
|
const TRANSLATION_LOCALE_KEY = "tess_edit:translation_locale"
|
|
@@ -437,7 +437,9 @@ export default class extends Controller {
|
|
|
437
437
|
build() {
|
|
438
438
|
this.blocksElement = h("div", { class: "flex-1 overflow-y-auto pb-4" })
|
|
439
439
|
this.treeElement = h("div", { class: "flex-1 overflow-y-auto" })
|
|
440
|
-
this.leftTabs = h("div", { class: "flex border-b border-gray-200 dark:border-gray-700 px-2 shrink-0" })
|
|
440
|
+
this.leftTabs = h("div", { class: "flex border-b border-gray-200 dark:border-gray-700 px-2 shrink-0 overflow-x-auto" })
|
|
441
|
+
// The kit's own panels (registerKit's panels), a tab each after Layers
|
|
442
|
+
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
443
|
this.inspectorElement = h("div", { class: "flex flex-1 flex-col min-h-0", dataset: { tessEditPanel: "inspect" } })
|
|
442
444
|
this.sidePanel = h("aside")
|
|
443
445
|
this.inspectPanel = h("aside")
|
|
@@ -464,6 +466,7 @@ export default class extends Controller {
|
|
|
464
466
|
this.inspector = new Inspector(this, this.inspectorElement)
|
|
465
467
|
this.textEditing = new TextEditing(this.textToolbar, { menu: this.variableMenu, editor: this })
|
|
466
468
|
renderBlocksPanel(this, this.blocksElement)
|
|
469
|
+
for (const panel of this.kitPanels) panel.render?.(panel.element, this)
|
|
467
470
|
this.observeWidth()
|
|
468
471
|
|
|
469
472
|
// The insert menu closes on a mousedown outside it (here or in the canvas,
|
|
@@ -502,7 +505,7 @@ export default class extends Controller {
|
|
|
502
505
|
if (this.main.nextSibling !== this.inspectPanel) this.main.after(this.inspectPanel)
|
|
503
506
|
return
|
|
504
507
|
}
|
|
505
|
-
this.sidePanel.replaceChildren(this.leftTabs, this.blocksElement, this.treeElement)
|
|
508
|
+
this.sidePanel.replaceChildren(this.leftTabs, this.blocksElement, this.treeElement, ...this.kitPanels.map((panel) => panel.element))
|
|
506
509
|
if (this.layout === "sheet") {
|
|
507
510
|
this.sidePanel.className = sheetClass
|
|
508
511
|
this.sidePanel.append(this.inspectorElement)
|
|
@@ -684,16 +687,26 @@ export default class extends Controller {
|
|
|
684
687
|
// replaceChildren would turn a null into the text "null", so only pass real tabs.
|
|
685
688
|
const tabs = [tab("blocks", t("Blocks")), tab("layers", t("Layers"))]
|
|
686
689
|
if (this.combined) tabs.push(tab("inspect", t("Inspect")))
|
|
690
|
+
for (const panel of this.kitPanels) tabs.push(tab(panel.key, t(panel.label)))
|
|
687
691
|
if (this.compact && this.hasBlocks) tabs.push(this.sheetClose)
|
|
688
692
|
this.leftTabs.replaceChildren(...tabs)
|
|
689
693
|
this.blocksElement.classList.toggle("hidden", this.leftTab !== "blocks")
|
|
690
694
|
this.treeElement.classList.toggle("hidden", this.leftTab !== "layers")
|
|
691
695
|
this.inspectorElement.classList.toggle("hidden", this.combined && this.leftTab !== "inspect")
|
|
696
|
+
for (const panel of this.kitPanels) panel.element.classList.toggle("hidden", this.leftTab !== panel.key)
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
// The kit's panel that is open, if one is
|
|
700
|
+
get panel() {
|
|
701
|
+
return this.kitPanels.some((panel) => panel.key === this.leftTab) ? this.leftTab : null
|
|
692
702
|
}
|
|
693
703
|
|
|
694
704
|
setLeftTab(tab) {
|
|
705
|
+
const panel = this.panel
|
|
695
706
|
this.leftTab = tab
|
|
696
707
|
this.renderLeftTabs()
|
|
708
|
+
// The canvas is told which of the kit's panels is open, so it draws again when that changes
|
|
709
|
+
if (panel !== this.panel) this.renderCanvas()
|
|
697
710
|
}
|
|
698
711
|
|
|
699
712
|
setMode(mode) {
|
|
@@ -729,7 +742,7 @@ export default class extends Controller {
|
|
|
729
742
|
|
|
730
743
|
async renderCanvas() {
|
|
731
744
|
if (this.editingId) return
|
|
732
|
-
const result = await this.run("canvas", (options) => this.kit.canvas(this.doc, { ...options, editor: this.mode === "edit" }))
|
|
745
|
+
const result = await this.run("canvas", (options) => this.kit.canvas(this.doc, { ...options, editor: this.mode === "edit", panel: this.panel }))
|
|
733
746
|
if (!result || this.editingId) return
|
|
734
747
|
// A canvas the host renders can give the values it has
|
|
735
748
|
if (result.values) this.values.set(result.values)
|
|
@@ -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
|
|
data/lib/tess_edit/version.rb
CHANGED