35 lines
774 B
JavaScript
35 lines
774 B
JavaScript
import { TpRtbBaseExtension } from './tp-rtb-base-extension.js';
|
|
import Code from '@tiptap/extension-code';
|
|
|
|
class TpRtbCode extends TpRtbBaseExtension {
|
|
constructor() {
|
|
super();
|
|
this.label = 'Code';
|
|
}
|
|
|
|
getExtension() {
|
|
return Code;
|
|
}
|
|
|
|
_handleClick() {
|
|
if (this.parentEditor && this.parentEditor.editor) {
|
|
this.parentEditor.editor.chain().focus().toggleCode().run();
|
|
}
|
|
}
|
|
|
|
_setupEditorListeners() {
|
|
const { editor } = this.parentEditor;
|
|
|
|
// Update button state when selection changes
|
|
editor.on('selectionUpdate', () => {
|
|
this.active = editor.isActive('code');
|
|
});
|
|
|
|
editor.on('focus', () => {
|
|
this.active = editor.isActive('code');
|
|
});
|
|
}
|
|
}
|
|
|
|
customElements.define('tp-rtb-code', TpRtbCode);
|