Created
June 7, 2024 12:59
-
-
Save dedemenezes/5df34d9394d55e456e5c0d060e5da144 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Controller } from "@hotwired/stimulus" | |
import Trix from 'trix' | |
const { lang } = Trix.config | |
// Connects to data-controller="trix" | |
export default class extends Controller { | |
static targets = ['editor'] | |
connect() { | |
document.addEventListener('trix-before-initialize', () => { | |
this.initTrix() | |
// console.log() | |
}) | |
} | |
initTrix() { | |
// Trix.config.blockAttributes.heading1.tagName = 'h3' | |
Trix.config.toolbar.getDefaultHTML = this.getDefaultHTML.bind(this) | |
// this.addForegroundButtonConfig() | |
// this.addBackgroundButtonConfig() | |
this.addTextAlignCenterButtonConfig() | |
this.addTextAlignRightButtonConfig() | |
this.addTextAlignJustifyButtonConfig() | |
this.addTextAlignLeftButtonConfig() | |
} | |
addTextAlignCenterButtonConfig() { | |
Trix.config.blockAttributes.textAlignCenter = { | |
tagName: 'centered-div' | |
} | |
} | |
addTextAlignRightButtonConfig() { | |
Trix.config.blockAttributes.textAlignRight = { | |
tagName: 'right-div' | |
} | |
} | |
addTextAlignJustifyButtonConfig() { | |
Trix.config.blockAttributes.textAlignJustify = { | |
tagName: 'justified-div' | |
} | |
} | |
addTextAlignLeftButtonConfig() { | |
Trix.config.blockAttributes.textAlignLeft = { | |
tagName: 'left-div' | |
} | |
} | |
getDefaultHTML() { | |
// trix default HTML from: | |
// ${this.textAlignButtons} | |
// trix default HTML | |
} | |
get textAlignButtons() { | |
// return my text align HTML | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment