index.vue 1.5 KB

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