2018-02-11 05:20:17 +00:00
|
|
|
<template lang='pug'>
|
|
|
|
.editor-code
|
2018-02-19 07:00:55 +00:00
|
|
|
v-toolbar(color='blue', flat, dense, dark)
|
2018-02-20 05:12:50 +00:00
|
|
|
v-icon(color='blue lighten-5') edit
|
2018-02-19 07:00:55 +00:00
|
|
|
v-toolbar-title.white--text Sample Page
|
2018-02-11 05:20:17 +00:00
|
|
|
.editor-code-toolbar
|
|
|
|
.editor-code-toolbar-group
|
|
|
|
.editor-code-toolbar-item
|
|
|
|
svg.icons.is-18(role='img')
|
|
|
|
title Bold
|
|
|
|
use(xlink:href='#fa-bold')
|
|
|
|
.editor-code-toolbar-item
|
|
|
|
svg.icons.is-18(role='img')
|
|
|
|
title Italic
|
|
|
|
use(xlink:href='#fa-italic')
|
|
|
|
.editor-code-toolbar-item
|
|
|
|
svg.icons.is-18(role='img')
|
|
|
|
title Strikethrough
|
|
|
|
use(xlink:href='#fa-strikethrough')
|
|
|
|
.editor-code-toolbar-group
|
2018-02-12 03:03:51 +00:00
|
|
|
v-menu(offset-y, open-on-hover)
|
|
|
|
.editor-code-toolbar-item.is-dropdown(slot='activator')
|
|
|
|
svg.icons.is-18(role='img')
|
|
|
|
title Heading
|
|
|
|
use(xlink:href='#fa-heading')
|
|
|
|
v-list
|
2018-02-17 23:17:25 +00:00
|
|
|
v-list-tile(v-for='(n, idx) in 6', @click='', :key='idx')
|
2018-02-12 03:03:51 +00:00
|
|
|
v-list-tile-action: v-icon format_size
|
|
|
|
v-list-tile-title Heading {{n}}
|
2018-02-17 23:17:25 +00:00
|
|
|
.editor-code-toolbar-item
|
|
|
|
svg.icons.is-18(role='img')
|
|
|
|
title Blockquote
|
|
|
|
use(xlink:href='#fa-quote-left')
|
2018-02-11 05:20:17 +00:00
|
|
|
.editor-code-toolbar-group
|
|
|
|
.editor-code-toolbar-item
|
|
|
|
svg.icons.is-18(role='img')
|
|
|
|
title Unordered List
|
|
|
|
use(xlink:href='#fa-list-ul')
|
|
|
|
.editor-code-toolbar-item
|
|
|
|
svg.icons.is-18(role='img')
|
|
|
|
title Ordered List
|
|
|
|
use(xlink:href='#fa-list-ol')
|
|
|
|
.editor-code-toolbar-group
|
|
|
|
.editor-code-toolbar-item
|
|
|
|
svg.icons.is-18(role='img')
|
|
|
|
title Link
|
|
|
|
use(xlink:href='#fa-link')
|
2018-02-12 03:03:51 +00:00
|
|
|
.editor-code-toolbar-group
|
|
|
|
.editor-code-toolbar-item
|
|
|
|
svg.icons.is-18(role='img')
|
|
|
|
title Inline Code
|
|
|
|
use(xlink:href='#fa-terminal')
|
|
|
|
.editor-code-toolbar-item
|
|
|
|
svg.icons.is-18(role='img')
|
|
|
|
title Code Block
|
|
|
|
use(xlink:href='#fa-code')
|
2018-02-11 23:36:20 +00:00
|
|
|
.editor-code-toolbar-group
|
|
|
|
.editor-code-toolbar-item
|
|
|
|
svg.icons.is-18(role='img')
|
|
|
|
title Horizontal Bar
|
|
|
|
use(xlink:href='#fa-minus')
|
2018-02-11 05:20:17 +00:00
|
|
|
.editor-code-main
|
|
|
|
.editor-code-editor
|
|
|
|
.editor-code-editor-title Editor
|
2018-02-24 22:35:56 +00:00
|
|
|
codemirror(ref='cm', v-model='code', :options='cmOptions', @ready='onCmReady', @input='onCmInput')
|
2018-02-11 05:20:17 +00:00
|
|
|
.editor-code-preview
|
|
|
|
.editor-code-preview-title Preview
|
2018-02-25 01:53:32 +00:00
|
|
|
.editor-code-preview-content.markdown-content(ref='editorPreview', v-html='previewHTML')
|
2018-02-19 07:00:55 +00:00
|
|
|
v-speed-dial(v-model='fabInsertMenu', :open-on-hover='true', direction='top', transition='slide-y-reverse-transition', :fixed='true', :right='!isMobile', :left='isMobile', :bottom='true')
|
|
|
|
v-btn(color='blue', fab, dark, v-model='fabInsertMenu', slot='activator')
|
2018-02-17 23:17:25 +00:00
|
|
|
v-icon add_circle
|
|
|
|
v-icon close
|
|
|
|
v-btn(color='teal', fab, dark): v-icon image
|
|
|
|
v-btn(color='pink', fab, dark): v-icon insert_drive_file
|
|
|
|
v-btn(color='red', fab, dark): v-icon play_circle_outline
|
|
|
|
v-btn(color='purple', fab, dark): v-icon multiline_chart
|
|
|
|
v-btn(color='indigo', fab, dark): v-icon functions
|
2018-02-19 07:00:55 +00:00
|
|
|
v-speed-dial(v-model='fabMainMenu', :open-on-hover='true', :direction='saveMenuDirection', transition='slide-x-reverse-transition', :fixed='true', :right='true', :top='!isMobile', :bottom='isMobile')
|
|
|
|
v-btn(color='white', fab, light, v-model='fabMainMenu' slot='activator')
|
|
|
|
v-icon(color='blue darken-2') blur_on
|
|
|
|
v-icon(color='blue darken-2') close
|
2018-02-19 20:41:36 +00:00
|
|
|
v-btn(color='blue-grey', fab, dark, @click.native.stop='$parent.openModal(`properties`)'): v-icon sort_by_alpha
|
|
|
|
v-btn(color='green', fab, dark, @click.native.stop='$parent.save()'): v-icon save
|
2018-02-17 23:17:25 +00:00
|
|
|
v-btn(color='red', fab, dark, small): v-icon not_interested
|
2018-02-19 20:41:36 +00:00
|
|
|
v-btn(color='orange', fab, dark, small, @click.native.stop='$parent.openModal(`access`)'): v-icon vpn_lock
|
2018-02-17 23:17:25 +00:00
|
|
|
v-btn(color='indigo', fab, dark, small): v-icon restore
|
|
|
|
v-btn(color='brown', fab, dark, small): v-icon archive
|
2018-02-11 05:20:17 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2018-02-24 22:35:56 +00:00
|
|
|
import _ from 'lodash'
|
|
|
|
|
2018-02-11 05:20:17 +00:00
|
|
|
import { codemirror } from 'vue-codemirror'
|
|
|
|
import 'codemirror/lib/codemirror.css'
|
|
|
|
|
|
|
|
// Language
|
|
|
|
import 'codemirror/mode/markdown/markdown.js'
|
|
|
|
|
|
|
|
// Addons
|
|
|
|
import 'codemirror/addon/selection/active-line.js'
|
|
|
|
import 'codemirror/addon/display/fullscreen.js'
|
|
|
|
import 'codemirror/addon/display/fullscreen.css'
|
|
|
|
import 'codemirror/addon/selection/mark-selection.js'
|
|
|
|
import 'codemirror/addon/scroll/annotatescrollbar.js'
|
|
|
|
import 'codemirror/addon/search/matchesonscrollbar.js'
|
|
|
|
import 'codemirror/addon/search/searchcursor.js'
|
|
|
|
import 'codemirror/addon/search/match-highlighter.js'
|
|
|
|
|
2018-02-24 22:35:56 +00:00
|
|
|
// Markdown-it
|
|
|
|
import MarkdownIt from 'markdown-it'
|
2018-02-25 06:28:26 +00:00
|
|
|
import mdEmoji from 'markdown-it-emoji'
|
|
|
|
import mdTaskLists from 'markdown-it-task-lists'
|
2018-02-25 17:59:59 +00:00
|
|
|
import mdExpandTabs from 'markdown-it-expand-tabs'
|
|
|
|
import mdAbbr from 'markdown-it-abbr'
|
|
|
|
import mdSup from 'markdown-it-sup'
|
|
|
|
import mdSub from 'markdown-it-sub'
|
|
|
|
import mdMark from 'markdown-it-mark'
|
|
|
|
import mdImsize from 'markdown-it-imsize'
|
|
|
|
|
|
|
|
// Prism (Syntax Highlighting)
|
2018-02-25 01:53:32 +00:00
|
|
|
import Prism from '../libs/prism/prism.js'
|
2018-02-24 22:35:56 +00:00
|
|
|
|
|
|
|
const md = new MarkdownIt({
|
|
|
|
html: true,
|
|
|
|
breaks: true,
|
|
|
|
linkify: true,
|
2018-02-25 01:53:32 +00:00
|
|
|
typography: true,
|
|
|
|
highlight(str, lang) {
|
|
|
|
return `<pre class="line-numbers"><code class="language-${lang}">${str}</code></pre>`
|
|
|
|
}
|
2018-02-24 22:35:56 +00:00
|
|
|
})
|
2018-02-25 06:28:26 +00:00
|
|
|
.use(mdEmoji)
|
|
|
|
.use(mdTaskLists)
|
2018-02-25 17:59:59 +00:00
|
|
|
.use(mdExpandTabs)
|
|
|
|
.use(mdAbbr)
|
|
|
|
.use(mdSup)
|
|
|
|
.use(mdSub)
|
|
|
|
.use(mdMark)
|
|
|
|
.use(mdImsize)
|
2018-02-24 22:35:56 +00:00
|
|
|
|
2018-02-25 20:54:35 +00:00
|
|
|
// Inject line numbers for preview scroll sync
|
|
|
|
let linesMap = []
|
|
|
|
function injectLineNumbers (tokens, idx, options, env, slf) {
|
|
|
|
let line
|
|
|
|
if (tokens[idx].map && tokens[idx].level === 0) {
|
|
|
|
line = tokens[idx].map[0]
|
|
|
|
tokens[idx].attrJoin('class', 'line')
|
|
|
|
tokens[idx].attrSet('data-line', String(line))
|
|
|
|
linesMap.push(line)
|
|
|
|
}
|
|
|
|
return slf.renderToken(tokens, idx, options, env, slf)
|
|
|
|
}
|
|
|
|
md.renderer.rules.paragraph_open = injectLineNumbers
|
|
|
|
md.renderer.rules.heading_open = injectLineNumbers
|
|
|
|
|
2018-02-11 05:20:17 +00:00
|
|
|
export default {
|
|
|
|
components: {
|
2018-02-19 07:00:55 +00:00
|
|
|
codemirror
|
2018-02-11 05:20:17 +00:00
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
2018-02-19 07:00:55 +00:00
|
|
|
fabMainMenu: false,
|
|
|
|
fabInsertMenu: false,
|
2018-02-25 06:28:26 +00:00
|
|
|
code: '# Header 1\n\nSample **Text**\nhttp://wiki.js.org\n:rocket: :) :( :| :P\n\n## Header 2\nSample Text\n\n```javascript\nvar test = require("test");\n\n// some comment\nconst foo = bar(\'param\') + 1.234;\n```\n\n### Header 3\nLorem *ipsum* ~~text~~',
|
2018-02-11 05:20:17 +00:00
|
|
|
cmOptions: {
|
|
|
|
tabSize: 2,
|
|
|
|
mode: 'text/markdown',
|
2018-02-25 21:19:08 +00:00
|
|
|
theme: 'wikijs-dark',
|
2018-02-11 23:36:20 +00:00
|
|
|
lineNumbers: true,
|
2018-02-11 05:20:17 +00:00
|
|
|
lineWrapping: true,
|
|
|
|
line: true,
|
|
|
|
styleActiveLine: true,
|
|
|
|
highlightSelectionMatches: {
|
|
|
|
annotateScrollbar: true
|
|
|
|
},
|
2018-02-20 05:12:50 +00:00
|
|
|
viewportMargin: 50
|
2018-02-24 22:35:56 +00:00
|
|
|
},
|
|
|
|
previewHTML: ''
|
2018-02-11 05:20:17 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
cm() {
|
|
|
|
return this.$refs.cm.codemirror
|
2018-02-17 23:17:25 +00:00
|
|
|
},
|
|
|
|
isMobile() {
|
|
|
|
return this.$vuetify.breakpoint.smAndDown
|
|
|
|
},
|
|
|
|
saveMenuDirection() {
|
|
|
|
return this.isMobile ? 'top' : 'bottom'
|
2018-02-11 05:20:17 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
onCmReady(cm) {
|
2018-02-20 05:12:50 +00:00
|
|
|
let self = this
|
|
|
|
cm.setSize(null, 'calc(100vh - 100px)')
|
|
|
|
cm.setOption('extraKeys', {
|
|
|
|
'F11'(cm) {
|
|
|
|
cm.setOption('fullScreen', !cm.getOption('fullScreen'))
|
|
|
|
},
|
|
|
|
'Esc'(cm) {
|
|
|
|
if (cm.getOption('fullScreen')) cm.setOption('fullScreen', false)
|
|
|
|
},
|
|
|
|
'Ctrl-S'(cm) {
|
|
|
|
self.$parent.save()
|
|
|
|
}
|
|
|
|
})
|
2018-02-25 20:54:35 +00:00
|
|
|
cm.on('cursorActivity', this.scrollSync)
|
2018-02-24 22:35:56 +00:00
|
|
|
this.onCmInput(this.code)
|
|
|
|
},
|
|
|
|
onCmInput: _.debounce(function (newContent) {
|
2018-02-25 20:54:35 +00:00
|
|
|
linesMap = []
|
2018-02-24 22:35:56 +00:00
|
|
|
this.previewHTML = md.render(newContent)
|
2018-02-25 20:54:35 +00:00
|
|
|
this.$nextTick(() => {
|
2018-02-25 01:53:32 +00:00
|
|
|
Prism.highlightAllUnder(this.$refs.editorPreview)
|
2018-02-25 20:54:35 +00:00
|
|
|
this.scrollSync(this.cm)
|
2018-02-25 01:53:32 +00:00
|
|
|
})
|
2018-02-25 20:54:35 +00:00
|
|
|
}, 500),
|
|
|
|
/**
|
|
|
|
* Update scroll sync
|
|
|
|
*/
|
|
|
|
scrollSync: _.debounce(function (cm) {
|
|
|
|
if (cm.somethingSelected()) { return }
|
|
|
|
let currentLine = cm.getCursor().line
|
|
|
|
if (currentLine < 3) {
|
|
|
|
this.Velocity(this.$refs.editorPreview, 'stop', true)
|
|
|
|
this.Velocity(this.$refs.editorPreview.firstChild, 'scroll', { offset: '-50', duration: 1000, container: this.$refs.editorPreview })
|
|
|
|
} else {
|
|
|
|
let closestLine = _.findLast(linesMap, n => n <= currentLine)
|
|
|
|
let destElm = this.$refs.editorPreview.querySelector(`[data-line='${closestLine}']`)
|
|
|
|
if (destElm) {
|
|
|
|
this.Velocity(this.$refs.editorPreview, 'stop', true)
|
|
|
|
this.Velocity(destElm, 'scroll', { offset: '-100', duration: 1000, container: this.$refs.editorPreview })
|
|
|
|
}
|
|
|
|
}
|
2018-02-24 22:35:56 +00:00
|
|
|
}, 500)
|
2018-02-11 05:20:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang='scss'>
|
|
|
|
.editor-code {
|
|
|
|
&-main {
|
|
|
|
display: flex;
|
|
|
|
width: 100%;
|
|
|
|
}
|
|
|
|
|
|
|
|
&-editor {
|
2018-02-25 20:54:35 +00:00
|
|
|
background-color: darken(mc('grey', '900'), 4.5%);
|
2018-02-11 05:20:17 +00:00
|
|
|
flex: 1 1 50%;
|
|
|
|
display: block;
|
2018-02-25 20:54:35 +00:00
|
|
|
height: calc(100vh - 100px);
|
2018-02-11 05:20:17 +00:00
|
|
|
position: relative;
|
|
|
|
|
|
|
|
&-title {
|
|
|
|
background-color: mc('grey', '800');
|
|
|
|
border-bottom-left-radius: 5px;
|
|
|
|
display: inline-flex;
|
|
|
|
height: 30px;
|
|
|
|
justify-content: center;
|
|
|
|
align-items: center;
|
|
|
|
padding: 0 1rem;
|
|
|
|
color: mc('grey', '500');
|
|
|
|
position: absolute;
|
|
|
|
top: 0;
|
|
|
|
right: 0;
|
2018-02-25 20:54:35 +00:00
|
|
|
z-index: 7;
|
2018-02-11 05:20:17 +00:00
|
|
|
text-transform: uppercase;
|
|
|
|
font-size: .7rem;
|
2018-02-17 23:17:25 +00:00
|
|
|
|
|
|
|
@include until($tablet) {
|
|
|
|
display: none;
|
|
|
|
}
|
2018-02-11 05:20:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
&-preview {
|
|
|
|
flex: 1 1 50%;
|
|
|
|
background-color: mc('grey', '100');
|
|
|
|
position: relative;
|
2018-02-25 20:54:35 +00:00
|
|
|
height: calc(100vh - 100px);
|
|
|
|
overflow: hidden;
|
2018-02-11 05:20:17 +00:00
|
|
|
|
2018-02-17 23:17:25 +00:00
|
|
|
@include until($tablet) {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
|
2018-02-25 20:54:35 +00:00
|
|
|
&-content {
|
|
|
|
height: calc(100vh - 100px);
|
|
|
|
overflow-y: scroll;
|
|
|
|
padding: 30px 1rem 1rem 1rem;
|
|
|
|
width: calc(100% + 1rem + 17px)
|
|
|
|
// -ms-overflow-style: none;
|
|
|
|
|
|
|
|
// &::-webkit-scrollbar {
|
|
|
|
// width: 0px;
|
|
|
|
// background: transparent;
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
|
2018-02-11 05:20:17 +00:00
|
|
|
&-title {
|
2018-02-25 20:54:35 +00:00
|
|
|
background-color: rgba(mc('blue', '100'), .75);
|
2018-02-11 05:20:17 +00:00
|
|
|
border-bottom-right-radius: 5px;
|
|
|
|
display: inline-flex;
|
|
|
|
height: 30px;
|
|
|
|
justify-content: center;
|
|
|
|
align-items: center;
|
|
|
|
padding: 0 1rem;
|
|
|
|
color: mc('blue', '800');
|
|
|
|
position: absolute;
|
|
|
|
top: 0;
|
|
|
|
left: 0;
|
|
|
|
z-index: 2;
|
|
|
|
text-transform: uppercase;
|
|
|
|
font-size: .7rem;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
&-toolbar {
|
|
|
|
background-color: mc('blue', '700');
|
|
|
|
background-image: linear-gradient(to bottom, mc('blue', '700') 0%, mc('blue','800') 100%);
|
|
|
|
height: 50px;
|
|
|
|
color: #FFF;
|
|
|
|
display: flex;
|
|
|
|
|
2018-02-17 23:17:25 +00:00
|
|
|
@include until($tablet) {
|
|
|
|
justify-content: center;
|
|
|
|
}
|
|
|
|
|
2018-02-11 05:20:17 +00:00
|
|
|
&-group {
|
|
|
|
display: flex;
|
|
|
|
|
|
|
|
+ .editor-code-toolbar-group {
|
2018-02-19 20:41:36 +00:00
|
|
|
border-left: 1px solid rgba(mc('blue', '600'), .5);
|
2018-02-11 05:20:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
&-item {
|
|
|
|
width: 40px;
|
|
|
|
height: 50px;
|
|
|
|
display: flex;
|
|
|
|
justify-content: center;
|
|
|
|
align-items: center;
|
|
|
|
transition: all .4s ease;
|
|
|
|
cursor: pointer;
|
|
|
|
|
|
|
|
&:first-child {
|
|
|
|
padding-left: .5rem;
|
|
|
|
}
|
|
|
|
|
|
|
|
&:last-child {
|
|
|
|
padding-right: .5rem;
|
|
|
|
}
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
background-color: mc('blue', '600');
|
|
|
|
}
|
2018-02-17 23:17:25 +00:00
|
|
|
|
|
|
|
@include until($tablet) {
|
|
|
|
width: 35px;
|
|
|
|
}
|
2018-02-11 05:20:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
svg {
|
|
|
|
use {
|
|
|
|
color: #FFF;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-02-25 20:54:35 +00:00
|
|
|
|
|
|
|
// Fix FAB revealing under codemirror
|
|
|
|
.speed-dial--fixed {
|
|
|
|
z-index: 5;
|
|
|
|
}
|
2018-02-11 05:20:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
.CodeMirror {
|
|
|
|
height: auto;
|
2018-02-18 03:18:37 +00:00
|
|
|
|
|
|
|
.cm-header-1 {
|
|
|
|
font-size: 1.5rem;
|
|
|
|
}
|
|
|
|
.cm-header-2 {
|
|
|
|
font-size: 1.25rem;
|
|
|
|
}
|
|
|
|
.cm-header-3 {
|
|
|
|
font-size: 1.15rem;
|
|
|
|
}
|
|
|
|
.cm-header-4 {
|
|
|
|
font-size: 1.1rem;
|
|
|
|
}
|
|
|
|
.cm-header-5 {
|
|
|
|
font-size: 1.05rem;
|
|
|
|
}
|
|
|
|
.cm-header-6 {
|
|
|
|
font-size: 1.025rem;
|
|
|
|
}
|
2018-02-11 05:20:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
.CodeMirror-focused .cm-matchhighlight {
|
|
|
|
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAYAAABytg0kAAAAFklEQVQI12NgYGBgkKzc8x9CMDAwAAAmhwSbidEoSQAAAABJRU5ErkJggg==);
|
|
|
|
background-position: bottom;
|
|
|
|
background-repeat: repeat-x;
|
|
|
|
}
|
|
|
|
.cm-matchhighlight {
|
|
|
|
background-color: mc('grey', '800');
|
|
|
|
}
|
|
|
|
.CodeMirror-selection-highlight-scrollbar {
|
|
|
|
background-color: mc('green', '600');
|
|
|
|
}
|
|
|
|
</style>
|