EditorView.vue 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <template>
  2. <div class="editor editor-squished">
  3. <editor-content
  4. class="editor__content"
  5. :editor="editor"
  6. />
  7. </div>
  8. </template>
  9. <script>
  10. import { Editor, EditorContent } from 'tiptap'
  11. import {
  12. Heading,
  13. Bold,
  14. Code,
  15. Italic,
  16. Strike,
  17. Underline,
  18. Blockquote,
  19. HorizontalRule,
  20. OrderedList,
  21. BulletList,
  22. ListItem,
  23. CodeBlockHighlight
  24. } from 'tiptap-extensions'
  25. import Title from '~/components/editor/components/Title'
  26. import Subtitle from '~/components/editor/components/Subtitle'
  27. import Doc from '~/components/editor/components/Doc'
  28. import javascript from 'highlight.js/lib/languages/javascript'
  29. import css from 'highlight.js/lib/languages/css'
  30. export default {
  31. components: {
  32. EditorContent
  33. },
  34. props: {
  35. initialContent: {
  36. required: true,
  37. type: String
  38. }
  39. },
  40. data() {
  41. return {
  42. editor: null
  43. }
  44. },
  45. // This is called only on client (in browser)
  46. mounted() {
  47. this.editor = new Editor({
  48. editable: false,
  49. extensions: [
  50. new Doc(),
  51. new Title(),
  52. new Subtitle(),
  53. new Heading({ levels: [1, 2, 3]}),
  54. new Bold(),
  55. new Code(),
  56. new Italic(),
  57. new Strike(),
  58. new Underline(),
  59. new Blockquote(),
  60. new HorizontalRule(),
  61. new OrderedList(),
  62. new BulletList(),
  63. new ListItem(),
  64. new CodeBlockHighlight({
  65. languages: {
  66. javascript,
  67. css,
  68. }
  69. })
  70. ]
  71. })
  72. this.initialContent && this.editor.setContent(this.initialContent)
  73. },
  74. beforeDestroy() {
  75. // Always destroy your editor instance when it's no longer needed
  76. this.editor && this.editor.destroy()
  77. }
  78. }
  79. </script>