demarches-normaliennes/app/javascript/controllers/tiptap_to_template_controller.ts

21 lines
533 B
TypeScript
Raw Normal View History

2024-07-15 23:28:02 +02:00
import { Controller } from '@hotwired/stimulus';
export class TiptapToTemplateController extends Controller {
static targets = ['output', 'trigger'];
declare readonly outputTarget: HTMLElement;
declare readonly triggerTarget: HTMLButtonElement;
connect() {
this.triggerTarget.addEventListener('click', this.handleClick.bind(this));
}
handleClick() {
const template = this.element.querySelector('.tiptap.ProseMirror p');
if (template) {
this.outputTarget.innerHTML = template.innerHTML;
}
}
}