Sha256: 1ad77be292822fceb8401492702ea5f198e6e69e44f67dc6626dd504a8067261
Contents?: true
Size: 1.33 KB
Versions: 7
Compression:
Stored size: 1.33 KB
Contents
import {Controller} from '@hotwired/stimulus' import {Editor} from '@tiptap/core' import {Document} from '@tiptap/extension-document' import {Paragraph} from '@tiptap/extension-paragraph' import {Text} from '@tiptap/extension-text' import DropCursor from '@tiptap/extension-dropcursor' import GapCursor from '@tiptap/extension-gapcursor' import {History} from '@tiptap/extension-history' export default class RichTextArea extends Controller { static targets = ['editor'] declare readonly editorTargets: [HTMLDivElement] connect() { for (const editorElement of this.editorTargets) { const pmEditor = new Editor({ extensions: [DropCursor, GapCursor, History, Document, Paragraph, Text], content: '', injectCSS: false, element: editorElement, editorProps: { attributes: { class: 'ariadne-p-3' } }, parseOptions: { preserveWhitespace: true } }) const tiptapValueContainer = editorElement.previousElementSibling if (tiptapValueContainer) { const parentForm = editorElement.closest('form') parentForm?.addEventListener('submit', () => { tiptapValueContainer.setAttribute('value', pmEditor.getText() || '') pmEditor.commands.clearContent() // TODO: test this }) } } } }
Version data entries
7 entries across 7 versions & 1 rubygems