You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

186 lines
4.4 KiB

5 years ago
5 years ago
  1. <template lang='pug'>
  2. .editor-ckeditor
  3. div(ref='toolbarContainer')
  4. div.contents(ref='editor')
  5. v-system-bar.editor-ckeditor-sysbar(dark, status, color='grey darken-3')
  6. .caption.editor-ckeditor-sysbar-locale {{locale.toUpperCase()}}
  7. .caption.px-3 /{{path}}
  8. template(v-if='$vuetify.breakpoint.mdAndUp')
  9. v-spacer
  10. .caption Visual Editor
  11. v-spacer
  12. .caption {{stats.characters}} Chars, {{stats.words}} Words
  13. </template>
  14. <script>
  15. import _ from 'lodash'
  16. import { get, sync } from 'vuex-pathify'
  17. import DecoupledEditor from '@requarks/ckeditor5'
  18. export default {
  19. props: {
  20. save: {
  21. type: Function,
  22. default: () => {}
  23. }
  24. },
  25. data() {
  26. return {
  27. editor: null,
  28. stats: {
  29. characters: 0,
  30. words: 0
  31. },
  32. content: ''
  33. }
  34. },
  35. computed: {
  36. isMobile() {
  37. return this.$vuetify.breakpoint.smAndDown
  38. },
  39. locale: get('page/locale'),
  40. path: get('page/path'),
  41. activeModal: sync('editor/activeModal')
  42. },
  43. methods: {
  44. },
  45. async mounted () {
  46. this.$store.set('editor/editorKey', 'ckeditor')
  47. this.editor = await DecoupledEditor.create(this.$refs.editor, {
  48. placeholder: 'Type the page content here',
  49. wordCount: {
  50. onUpdate: stats => {
  51. this.stats = {
  52. characters: stats.characters,
  53. words: stats.words
  54. }
  55. }
  56. }
  57. })
  58. this.$refs.toolbarContainer.appendChild(this.editor.ui.view.toolbar.element)
  59. if (this.mode !== 'create') {
  60. this.editor.setData(this.$store.get('editor/content'))
  61. }
  62. this.editor.model.document.on('change:data', _.debounce(evt => {
  63. this.$store.set('editor/content', this.editor.getData())
  64. }, 300))
  65. this.$root.$on('editorInsert', opts => {
  66. switch (opts.kind) {
  67. case 'IMAGE':
  68. this.editor.execute('imageInsert', {
  69. source: opts.path
  70. })
  71. break
  72. case 'BINARY':
  73. this.editor.execute('link', opts.path, {
  74. linkIsDownloadable: true
  75. })
  76. break
  77. }
  78. })
  79. },
  80. beforeDestroy () {
  81. if (this.editor) {
  82. this.editor.destroy()
  83. this.editor = null
  84. }
  85. }
  86. }
  87. </script>
  88. <style lang="scss">
  89. $editor-height: calc(100vh - 64px - 24px);
  90. $editor-height-mobile: calc(100vh - 56px - 16px);
  91. .editor-ckeditor {
  92. background-color: mc('grey', '200');
  93. flex: 1 1 50%;
  94. display: flex;
  95. flex-flow: column nowrap;
  96. height: $editor-height;
  97. max-height: $editor-height;
  98. position: relative;
  99. @at-root .theme--dark & {
  100. background-color: mc('grey', '900');
  101. }
  102. @include until($tablet) {
  103. height: $editor-height-mobile;
  104. max-height: $editor-height-mobile;
  105. }
  106. &-sysbar {
  107. padding-left: 0;
  108. &-locale {
  109. background-color: rgba(255,255,255,.25);
  110. display:inline-flex;
  111. padding: 0 12px;
  112. height: 24px;
  113. width: 63px;
  114. justify-content: center;
  115. align-items: center;
  116. }
  117. }
  118. .ck.ck-toolbar {
  119. border: none;
  120. justify-content: center;
  121. background-color: mc('grey', '300');
  122. color: #FFF;
  123. }
  124. > .ck-editor__editable {
  125. background-color: mc('grey', '100');
  126. overflow-y: auto;
  127. overflow-x: hidden;
  128. padding: 2rem;
  129. box-shadow: 0 0 5px hsla(0, 0, 0, .1);
  130. margin: 1rem auto 0;
  131. width: calc(100vw - 256px - 16vw);
  132. min-height: calc(100vh - 64px - 24px - 1rem - 40px);
  133. border-radius: 5px;
  134. @at-root .theme--dark & {
  135. background-color: #303030;
  136. color: #FFF;
  137. }
  138. @include until($widescreen) {
  139. width: calc(100vw - 2rem);
  140. margin: 1rem 1rem 0 1rem;
  141. min-height: calc(100vh - 64px - 24px - 1rem - 40px);
  142. }
  143. @include until($tablet) {
  144. width: 100%;
  145. margin: 0;
  146. min-height: calc(100vh - 56px - 24px - 76px);
  147. }
  148. &.ck.ck-editor__editable:not(.ck-editor__nested-editable).ck-focused {
  149. border-color: #FFF;
  150. box-shadow: 0 0 10px rgba(mc('blue', '700'), .25);
  151. @at-root .theme--dark & {
  152. border-color: #444;
  153. border-bottom: none;
  154. box-shadow: 0 0 10px rgba(#000, .25);
  155. }
  156. }
  157. &.ck .ck-editor__nested-editable.ck-editor__nested-editable_focused,
  158. &.ck .ck-editor__nested-editable:focus,
  159. .ck-widget.table td.ck-editor__nested-editable.ck-editor__nested-editable_focused,
  160. .ck-widget.table th.ck-editor__nested-editable.ck-editor__nested-editable_focused {
  161. background-color: mc('grey', '900');
  162. }
  163. }
  164. }
  165. </style>