index.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. Placeholder
  30. } from 'tiptap-extensions'
  31. import Title from '~/components/editor/components/Title'
  32. import Subtitle from '~/components/editor/components/Subtitle'
  33. import Doc from '~/components/editor/components/Doc'
  34. import javascript from 'highlight.js/lib/languages/javascript'
  35. import css from 'highlight.js/lib/languages/css'
  36. export default {
  37. components: {
  38. EditorContent,
  39. BubbleMenu,
  40. BasicMenu
  41. },
  42. data(){
  43. return {
  44. editor: null
  45. }
  46. },
  47. // This is called only on client (in browser)
  48. mounted(){
  49. this.editor = new Editor({
  50. extensions: [
  51. new Doc(),
  52. new Title(),
  53. new Subtitle(),
  54. new Placeholder({
  55. showOnlyCurrent: false,
  56. emptyNodeText: node => {
  57. if (node.type.name === 'title') {
  58. return 'Inspirational Title'
  59. }
  60. if (node.type.name === 'subtitle') {
  61. return 'Some catchy subtitle'
  62. }
  63. return 'Write your story...'
  64. }
  65. }),
  66. new Heading({ levels: [1, 2, 3]}),
  67. new Bold(),
  68. new Code(),
  69. new Italic(),
  70. new Strike(),
  71. new Underline(),
  72. new History(),
  73. new Blockquote(),
  74. new HorizontalRule(),
  75. new OrderedList(),
  76. new BulletList(),
  77. new ListItem(),
  78. new CodeBlockHighlight({
  79. languages: {
  80. javascript,
  81. css,
  82. }
  83. })
  84. ]
  85. })
  86. },
  87. beforeDestroy(){
  88. // Always destroy your editor instance when it's no longer needed
  89. this.editor && this.editor.destroy()
  90. }
  91. }
  92. </script>