CourseEditor.vue 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <template>
  2. <div class="editor course-editor">
  3. <course-menu :editor="editor"/>
  4. <editor-content
  5. class="editor__content"
  6. :editor="editor"
  7. />
  8. </div>
  9. </template>
  10. <script>
  11. import { Editor, EditorContent } from 'tiptap'
  12. import CourseMenu from '~/components/editor/CourseMenu'
  13. import {
  14. Bold,
  15. Italic,
  16. History,
  17. OrderedList,
  18. BulletList,
  19. ListItem,
  20. } from 'tiptap-extensions'
  21. export default {
  22. components: {
  23. EditorContent, CourseMenu
  24. },
  25. props: {
  26. initialContent: {
  27. required: true,
  28. type: String
  29. }
  30. },
  31. data() {
  32. return {
  33. editor: null
  34. }
  35. },
  36. // This is called only on client (in browser)
  37. mounted() {
  38. this.editor = new Editor({
  39. extensions: [
  40. new Bold(),
  41. new Italic(),
  42. new History(),
  43. new OrderedList(),
  44. new BulletList(),
  45. new ListItem()
  46. ],
  47. onUpdate: () => {
  48. this.emitUpdate()
  49. }
  50. })
  51. this.initialContent && this.editor.setContent(this.initialContent)
  52. },
  53. beforeDestroy() {
  54. this.editor && this.editor.destroy()
  55. },
  56. methods: {
  57. emitUpdate() {
  58. const content = this.editor.getHTML()
  59. this.$emit('editorUpdated', content)
  60. }
  61. }
  62. }
  63. </script>
  64. <style lang="scss">
  65. .course-editor {
  66. * {
  67. &:focus {
  68. outline: none;
  69. }
  70. }
  71. border: 1px solid gray;
  72. .editor__content {
  73. padding: 0 20px 20px 20px;
  74. }
  75. }
  76. </style>