Sha256: a53cab4c9a47a155cda10bba6ee81d8e1c0477ba64384d95da7d93d7ed401522

Contents?: true

Size: 1.45 KB

Versions: 84

Compression:

Stored size: 1.45 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-h-28 ariadne-max-h-48 ariadne-p-2 ariadne-rounded-lg ariadne-overflow-y-auto focus:ariadne-outline-none'
          }
        },
        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

84 entries across 84 versions & 1 rubygems

Version Path
ariadne_view_components-0.0.34 app/components/ariadne/rich_text_area_component/rich-text-area-component.ts
ariadne_view_components-0.0.34-x86_64-linux app/components/ariadne/rich_text_area_component/rich-text-area-component.ts
ariadne_view_components-0.0.34-x86_64-darwin app/components/ariadne/rich_text_area_component/rich-text-area-component.ts
ariadne_view_components-0.0.34-x64-mingw32 app/components/ariadne/rich_text_area_component/rich-text-area-component.ts
ariadne_view_components-0.0.34-x64-mingw-ucrt app/components/ariadne/rich_text_area_component/rich-text-area-component.ts
ariadne_view_components-0.0.34-arm64-darwin app/components/ariadne/rich_text_area_component/rich-text-area-component.ts
ariadne_view_components-0.0.34-aarch64-linux app/components/ariadne/rich_text_area_component/rich-text-area-component.ts
ariadne_view_components-0.0.33 app/components/ariadne/rich_text_area_component/rich-text-area-component.ts
ariadne_view_components-0.0.33-x86_64-linux app/components/ariadne/rich_text_area_component/rich-text-area-component.ts
ariadne_view_components-0.0.33-x86_64-darwin app/components/ariadne/rich_text_area_component/rich-text-area-component.ts
ariadne_view_components-0.0.33-x64-mingw32 app/components/ariadne/rich_text_area_component/rich-text-area-component.ts
ariadne_view_components-0.0.33-x64-mingw-ucrt app/components/ariadne/rich_text_area_component/rich-text-area-component.ts
ariadne_view_components-0.0.33-arm64-darwin app/components/ariadne/rich_text_area_component/rich-text-area-component.ts
ariadne_view_components-0.0.33-aarch64-linux app/components/ariadne/rich_text_area_component/rich-text-area-component.ts
ariadne_view_components-0.0.32 app/components/ariadne/rich_text_area_component/rich-text-area-component.ts
ariadne_view_components-0.0.32-x86_64-linux app/components/ariadne/rich_text_area_component/rich-text-area-component.ts
ariadne_view_components-0.0.32-x86_64-darwin app/components/ariadne/rich_text_area_component/rich-text-area-component.ts
ariadne_view_components-0.0.32-x64-mingw32 app/components/ariadne/rich_text_area_component/rich-text-area-component.ts
ariadne_view_components-0.0.32-x64-mingw-ucrt app/components/ariadne/rich_text_area_component/rich-text-area-component.ts
ariadne_view_components-0.0.32-arm64-darwin app/components/ariadne/rich_text_area_component/rich-text-area-component.ts