Unverified Commit 51c40445 authored by NGPixel's avatar NGPixel

feat: adapt remaining markdown actions to monaco

parent 9e875794
...@@ -192,14 +192,6 @@ ...@@ -192,14 +192,6 @@
@click='toggleMarkup({ start: `<kbd>`, end: `</kbd>` })' @click='toggleMarkup({ start: `<kbd>`, end: `</kbd>` })'
) )
q-tooltip(anchor='top middle' self='bottom middle') {{ t('editor.markup.keyboardKey') }} q-tooltip(anchor='top middle' self='bottom middle') {{ t('editor.markup.keyboardKey') }}
q-btn(
v-if='!state.previewShown'
icon='mdi-eye-arrow-right-outline'
padding='xs sm'
flat
@click='state.previewShown = true'
)
q-tooltip(anchor='top middle' self='bottom middle') {{ t('editor.togglePreviewPane') }}
//-------------------------------------------------------- //--------------------------------------------------------
//- MONACO EDITOR //- MONACO EDITOR
//-------------------------------------------------------- //--------------------------------------------------------
...@@ -225,7 +217,7 @@ ...@@ -225,7 +217,7 @@
@click='state.previewShown = false' @click='state.previewShown = false'
) )
q-tooltip(anchor='top middle' self='bottom middle') {{ t('editor.togglePreviewPane') }} q-tooltip(anchor='top middle' self='bottom middle') {{ t('editor.togglePreviewPane') }}
.editor-markdown-preview-content.contents(ref='editorPreviewContainer') .editor-markdown-preview-content.page-contents(ref='editorPreviewContainer')
div( div(
ref='editorPreview' ref='editorPreview'
v-html='pageStore.render' v-html='pageStore.render'
...@@ -240,7 +232,6 @@ import { get, flatten, last, times, startsWith, debounce } from 'lodash-es' ...@@ -240,7 +232,6 @@ import { get, flatten, last, times, startsWith, debounce } from 'lodash-es'
import { DateTime } from 'luxon' import { DateTime } from 'luxon'
import * as monaco from 'monaco-editor' import * as monaco from 'monaco-editor'
import { Position, Range } from 'monaco-editor' import { Position, Range } from 'monaco-editor'
import { WorkspaceEdit } from '../helpers/monacoTypes'
import { useEditorStore } from 'src/stores/editor' import { useEditorStore } from 'src/stores/editor'
import { usePageStore } from 'src/stores/page' import { usePageStore } from 'src/stores/page'
...@@ -298,9 +289,9 @@ function insertAssetClb (opts) { ...@@ -298,9 +289,9 @@ function insertAssetClb (opts) {
break break
} }
} }
insertAtCursor({ content }) insertAtCursor({ content, focus: false })
setTimeout(() => { setTimeout(() => {
cm.value.focus() editor.focus()
}, 500) }, 500)
} }
...@@ -313,15 +304,22 @@ function insertTable () { ...@@ -313,15 +304,22 @@ function insertTable () {
/** /**
* Set current line as header * Set current line as header
*/ */
function setHeaderLine (lvl) { function setHeaderLine (lvl, focus = true) {
const curLine = cm.value.doc.getCursor('head').line const curLine = editor.getPosition().lineNumber
let lineContent = cm.value.doc.getLine(curLine) let lineContent = editor.getModel().getLineContent(curLine)
const lineLength = lineContent.length const lineLength = lineContent.length
if (startsWith(lineContent, '#')) { if (startsWith(lineContent, '#')) {
lineContent = lineContent.replace(/^(#+ )/, '') lineContent = lineContent.replace(/^(#+ )/, '')
} }
lineContent = times(lvl, n => '#').join('') + ' ' + lineContent lineContent = times(lvl, n => '#').join('') + ' ' + lineContent
cm.value.doc.replaceRange(lineContent, { line: curLine, ch: 0 }, { line: curLine, ch: lineLength }) editor.executeEdits('', [{
range: new Range(curLine, 1, curLine, lineLength + 1),
text: lineContent,
forceMoveMarkers: true
}])
if (focus) {
editor.focus()
}
} }
/** /**
...@@ -341,45 +339,68 @@ function getHeaderLevel (cm) { ...@@ -341,45 +339,68 @@ function getHeaderLevel (cm) {
/** /**
* Insert content at cursor * Insert content at cursor
*/ */
function insertAtCursor ({ content }) { function insertAtCursor ({ content, focus = true }) {
const cursor = cm.value.doc.getCursor('head') const cursor = editor.getPosition()
cm.value.doc.replaceRange(content, cursor) editor.executeEdits('', [{
range: new Range(cursor.lineNumber, cursor.column, cursor.lineNumber, cursor.column),
text: content,
forceMoveMarkers: true
}])
if (focus) {
editor.focus()
}
} }
/** /**
* Insert content after current line * Insert content after current line
*/ */
function insertAfter ({ content, newLine }) { function insertAfter ({ content, newLine, focus = true }) {
const curLine = cm.value.doc.getCursor('to').line const curLine = editor.getPosition().lineNumber
const lineLength = cm.value.doc.getLine(curLine).length editor.executeEdits('', [{
cm.value.doc.replaceRange(newLine ? `\n${content}\n` : content, { line: curLine, ch: lineLength + 1 }) range: new Range(curLine + 1, 1, curLine + 1, 1),
text: newLine ? `\n${content}\n` : content,
forceMoveMarkers: true
}])
if (focus) {
editor.focus()
}
} }
/** /**
* Insert content before current line * Insert content before current line
*/ */
function insertBeforeEachLine ({ content, after }) { function insertBeforeEachLine ({ content, after, focus = true }) {
let lines = [] const edits = []
if (!cm.value.doc.somethingSelected()) { for (const selection of editor.getSelections()) {
lines.push(cm.value.doc.getCursor('head').line) const lineCount = selection.endLineNumber - selection.startLineNumber + 1
} else { const lines = times(lineCount, l => l + selection.startLineNumber)
lines = flatten(cm.value.doc.listSelections().map(sl => { for (const line of lines) {
const range = Math.abs(sl.anchor.line - sl.head.line) + 1 let lineContent = editor.getModel().getLineContent(line)
const lowestLine = (sl.anchor.line > sl.head.line) ? sl.head.line : sl.anchor.line const lineLength = lineContent.length
return times(range, l => l + lowestLine) if (startsWith(lineContent, content)) {
})) lineContent = lineContent.substring(content.length)
} }
lines.forEach(ln => { edits.push({
let lineContent = cm.value.doc.getLine(ln) range: new Range(line, 1, line, lineLength + 1),
const lineLength = lineContent.length text: `${content}${lineContent}`,
if (startsWith(lineContent, content)) { forceMoveMarkers: true
lineContent = lineContent.substring(content.length) })
} }
cm.value.doc.replaceRange(content + lineContent, { line: ln, ch: 0 }, { line: ln, ch: lineLength }) if (after) {
}) const lastLine = last(lines)
if (after) { const lineLength = editor.getModel().getLineContent(lastLine).length
const lastLine = last(lines) edits.push({
cm.value.doc.replaceRange(`\n${after}\n`, { line: lastLine, ch: cm.value.doc.getLine(lastLine).length + 1 }) range: new Range(lastLine, lineLength + 1, lastLine, lineLength + 1),
text: `\n${after}`,
forceMoveMarkers: true
})
}
}
editor.executeEdits('', edits)
if (focus) {
editor.focus()
} }
} }
...@@ -387,7 +408,7 @@ function insertBeforeEachLine ({ content, after }) { ...@@ -387,7 +408,7 @@ function insertBeforeEachLine ({ content, after }) {
* Insert an Horizontal Bar * Insert an Horizontal Bar
*/ */
function insertHorizontalBar () { function insertHorizontalBar () {
insertAfter({ content: '---', newLine: true }) insertAfter({ content: '\n---\n', newLine: true })
} }
/** /**
...@@ -442,7 +463,7 @@ onMounted(async () => { ...@@ -442,7 +463,7 @@ onMounted(async () => {
'editor.background': '#070a0d', 'editor.background': '#070a0d',
'editor.lineHighlightBackground': '#0d1117', 'editor.lineHighlightBackground': '#0d1117',
'editorLineNumber.foreground': '#546e7a', 'editorLineNumber.foreground': '#546e7a',
'editorGutter.background': '#1e232a' 'editorGutter.background': '#0d1117'
} }
}) })
...@@ -455,7 +476,13 @@ onMounted(async () => { ...@@ -455,7 +476,13 @@ onMounted(async () => {
scrollBeyondLastLine: false, scrollBeyondLastLine: false,
fontSize: 16, fontSize: 16,
formatOnType: true, formatOnType: true,
lineNumbersMinChars: 3 lineNumbersMinChars: 3,
tabSize: 2,
padding: {
top: 10,
bottom: 10
},
wordWrap: 'on'
}) })
window.edd = editor window.edd = editor
...@@ -467,7 +494,7 @@ onMounted(async () => { ...@@ -467,7 +494,7 @@ onMounted(async () => {
id: 'markdown.extension.editing.toggleBold', id: 'markdown.extension.editing.toggleBold',
keybindings: [monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyB], keybindings: [monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyB],
label: 'Toggle bold', label: 'Toggle bold',
precondition: '', precondition: 'editorHasSelection',
run (ed) { run (ed) {
toggleMarkup({ start: '**' }) toggleMarkup({ start: '**' })
} }
...@@ -479,12 +506,21 @@ onMounted(async () => { ...@@ -479,12 +506,21 @@ onMounted(async () => {
id: 'markdown.extension.editing.toggleItalic', id: 'markdown.extension.editing.toggleItalic',
keybindings: [monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyI], keybindings: [monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyI],
label: 'Toggle italic', label: 'Toggle italic',
precondition: '', precondition: 'editorHasSelection',
run (ed) { run (ed) {
toggleMarkup({ start: '*' }) toggleMarkup({ start: '*' })
} }
}) })
editor.addAction({
id: 'save',
keybindings: [monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyS],
label: 'Save',
precondition: '',
run (ed) {
}
})
editor.onDidChangeModelContent(debounce(ev => { editor.onDidChangeModelContent(debounce(ev => {
editorStore.$patch({ editorStore.$patch({
lastChangeTimestamp: DateTime.utc() lastChangeTimestamp: DateTime.utc()
...@@ -495,61 +531,10 @@ onMounted(async () => { ...@@ -495,61 +531,10 @@ onMounted(async () => {
processContent(pageStore.content) processContent(pageStore.content)
}, 500)) }, 500))
// -> Initialize CodeMirror editor.focus()
// cm.value = CodeMirror.fromTextArea(cmRef.value, {
// tabSize: 2,
// mode: 'text/markdown',
// theme: 'wikijs-dark',
// lineNumbers: true,
// lineWrapping: true,
// line: true,
// styleActiveLine: true,
// highlightSelectionMatches: {
// annotateScrollbar: true
// },
// viewportMargin: 50,
// inputStyle: 'contenteditable',
// allowDropFileTypes: ['image/jpg', 'image/png', 'image/svg', 'image/jpeg', 'image/gif'],
// // direction: siteConfig.rtl ? 'rtl' : 'ltr',
// foldGutter: true,
// gutters: ['CodeMirror-linenumbers', 'CodeMirror-foldgutter']
// })
// cm.value.setValue(pageStore.content)
// cm.value.on('change', c => {
// editorStore.$patch({
// lastChangeTimestamp: DateTime.utc()
// })
// pageStore.$patch({
// content: c.getValue()
// })
// onCmInput(pageStore.content)
// })
// cm.value.setSize(null, '100%')
// -> Set Keybindings // -> Set Keybindings
// const keyBindings = { // const keyBindings = {
// 'F11' (c) {
// c.setOption('fullScreen', !c.getOption('fullScreen'))
// },
// 'Esc' (c) {
// if (c.getOption('fullScreen')) {
// c.setOption('fullScreen', false)
// }
// },
// [`${CtrlKey}-S`] (c) {
// // save()
// return false
// },
// [`${CtrlKey}-B`] (c) {
// toggleMarkup({ start: '**' })
// return false
// },
// [`${CtrlKey}-I`] (c) {
// toggleMarkup({ start: '*' })
// return false
// },
// [`${CtrlKey}-Alt-Right`] (c) { // [`${CtrlKey}-Alt-Right`] (c) {
// let lvl = getHeaderLevel(c) // let lvl = getHeaderLevel(c)
// if (lvl >= 6) { lvl = 5 } // if (lvl >= 6) { lvl = 5 }
...@@ -563,7 +548,6 @@ onMounted(async () => { ...@@ -563,7 +548,6 @@ onMounted(async () => {
// return false // return false
// } // }
// } // }
// cm.value.setOption('extraKeys', keyBindings)
// this.cm.on('inputRead', this.autocomplete) // this.cm.on('inputRead', this.autocomplete)
// // Handle cursor movement // // Handle cursor movement
...@@ -575,13 +559,6 @@ onMounted(async () => { ...@@ -575,13 +559,6 @@ onMounted(async () => {
// // Handle special paste // // Handle special paste
// this.cm.on('paste', this.onCmPaste) // this.cm.on('paste', this.onCmPaste)
// // Render initial preview
// processContent(pageStore.content)
// nextTick(() => {
// cm.value.refresh()
// cm.value.focus()
// })
EVENT_BUS.on('insertAsset', insertAssetClb) EVENT_BUS.on('insertAsset', insertAssetClb)
// this.$root.$on('editorInsert', opts => { // this.$root.$on('editorInsert', opts => {
...@@ -619,9 +596,9 @@ onMounted(async () => { ...@@ -619,9 +596,9 @@ onMounted(async () => {
onBeforeUnmount(() => { onBeforeUnmount(() => {
EVENT_BUS.off('insertAsset', insertAssetClb) EVENT_BUS.off('insertAsset', insertAssetClb)
// if (editor.value) { if (editor) {
// editor.value.destroy() editor.dispose()
// } }
}) })
</script> </script>
...@@ -662,7 +639,7 @@ $editor-height-mobile: calc(100vh - 112px - 16px); ...@@ -662,7 +639,7 @@ $editor-height-mobile: calc(100vh - 112px - 16px);
font-weight: 500; font-weight: 500;
} }
&-preview { &-preview {
flex: 1 1 50%; flex: 0 1 50%;
position: relative; position: relative;
height: $editor-height; height: $editor-height;
overflow: hidden; overflow: hidden;
...@@ -706,7 +683,7 @@ $editor-height-mobile: calc(100vh - 112px - 16px); ...@@ -706,7 +683,7 @@ $editor-height-mobile: calc(100vh - 112px - 16px);
height: $editor-height; height: $editor-height;
overflow-y: scroll; overflow-y: scroll;
padding: 1rem; padding: 1rem;
width: calc(100% + 17px); max-width: calc(50vw - 57px);
// -ms-overflow-style: none; // -ms-overflow-style: none;
// &::-webkit-scrollbar { // &::-webkit-scrollbar {
// width: 0px; // width: 0px;
......
...@@ -106,14 +106,21 @@ ...@@ -106,14 +106,21 @@
aria-label='Print' aria-label='Print'
) )
q-tooltip Print q-tooltip Print
q-btn.q-mr-sm.acrylic-btn( template(v-if='editorStore.isActive')
v-if='editorStore.isActive' q-btn.q-mr-sm.acrylic-btn(
icon='las la-question-circle' icon='las la-question-circle'
flat flat
color='grey' color='grey'
:href='siteStore.docsBase + `/editor/${editorStore.editor}`' :href='siteStore.docsBase + `/editor/${editorStore.editor}`'
target='_blank' target='_blank'
type='a' type='a'
)
q-btn.q-mr-sm.acrylic-btn(
icon='las la-cog'
flat
color='grey'
:aria-label='t(`editor.settings`)'
@click='openEditorSettings'
) )
template(v-if='editorStore.isActive || editorStore.hasPendingChanges') template(v-if='editorStore.isActive || editorStore.hasPendingChanges')
q-btn.acrylic-btn.q-mr-sm( q-btn.acrylic-btn.q-mr-sm(
...@@ -210,6 +217,10 @@ const editUrl = computed(() => { ...@@ -210,6 +217,10 @@ const editUrl = computed(() => {
// METHODS // METHODS
function openEditorSettings () {
EVENT_BUS.emit('openEditorSettings')
}
async function discardChanges () { async function discardChanges () {
// Is it the home page in create mode? // Is it the home page in create mode?
if (editorStore.mode === 'create' && pageStore.path === '' && pageStore.locale === 'en') { if (editorStore.mode === 'create' && pageStore.path === '' && pageStore.locale === 'en') {
......
...@@ -240,11 +240,5 @@ body::-webkit-scrollbar-thumb { ...@@ -240,11 +240,5 @@ body::-webkit-scrollbar-thumb {
// ------------------------------------------------------------------ // ------------------------------------------------------------------
@import './animation.scss'; @import './animation.scss';
@import 'v-network-graph/lib/style.css'; @import 'v-network-graph/lib/style.css';
@import './page-contents.scss'; @import './page-contents.scss';
// @import '~codemirror/lib/codemirror.css';
// @import '~codemirror/theme/elegant.css';
// @import '~codemirror/theme/material-ocean.css';
.cm-s-wikijs-dark.CodeMirror {
background: $dark-6;
color: #e0e0e0;
}
.cm-s-wikijs-dark div.CodeMirror-selected {
background: $teal-8;
}
.cm-s-wikijs-dark .cm-matchhighlight {
background: $teal-8;
}
.cm-s-wikijs-dark .CodeMirror-line::selection, .cm-s-wikijs-dark .CodeMirror-line > span::selection, .cm-s-wikijs-dark .CodeMirror-line > span > span::selection {
background: $blue-8;
}
.cm-s-wikijs-dark .CodeMirror-line::-moz-selection, .cm-s-wikijs-dark .CodeMirror-line > span::-moz-selection, .cm-s-wikijs-dark .CodeMirror-line > span > span::-moz-selection {
background: $blue-8;
}
.cm-s-wikijs-dark .CodeMirror-gutters {
background: $dark-3;
border-right: 1px solid $dark-2;
}
.cm-s-wikijs-dark .CodeMirror-guttermarker {
color: #ac4142;
}
.cm-s-wikijs-dark .CodeMirror-guttermarker-subtle {
color: #505050;
}
.cm-s-wikijs-dark .CodeMirror-linenumber {
color: $blue-grey-7;
}
.cm-s-wikijs-dark .CodeMirror-cursor {
border-left: 1px solid #b0b0b0;
}
.cm-s-wikijs-dark span.cm-comment {
color: $orange-8;
}
.cm-s-wikijs-dark span.cm-atom {
color: #aa759f;
}
.cm-s-wikijs-dark span.cm-number {
color: #aa759f;
}
.cm-s-wikijs-dark span.cm-property, .cm-s-wikijs-dark span.cm-attribute {
color: #90a959;
}
.cm-s-wikijs-dark span.cm-keyword {
color: #ac4142;
}
.cm-s-wikijs-dark span.cm-string {
color: #f4bf75;
}
.cm-s-wikijs-dark span.cm-variable {
color: #90a959;
}
.cm-s-wikijs-dark span.cm-variable-2 {
color: #6a9fb5;
}
.cm-s-wikijs-dark span.cm-def {
color: #d28445;
}
.cm-s-wikijs-dark span.cm-bracket {
color: #e0e0e0;
}
.cm-s-wikijs-dark span.cm-tag {
color: #ac4142;
}
.cm-s-wikijs-dark span.cm-link {
color: #aa759f;
}
.cm-s-wikijs-dark span.cm-error {
background: #ac4142;
color: #b0b0b0;
}
.cm-s-wikijs-dark .CodeMirror-activeline-background {
background: $dark-4;
}
.cm-s-wikijs-dark .CodeMirror-matchingbracket {
text-decoration: underline;
color: white !important;
}
.cm-s-wikijs-dark .CodeMirror-foldmarker {
margin-left: 10px;
display: inline-block;
background-color: rgba($amber-8, .3);
padding: 8px 5px;
color: $amber-5;
border-radius: 5px;
text-shadow: none;
}
.cm-s-wikijs-dark .CodeMirror-buttonmarker {
display: inline-block;
background-color: rgba($blue-5, .3);
border: 1px solid $blue-8;
padding: 1px 10px;
color: $blue-2 !important;
border-radius: 5px;
margin-left: 5px;
cursor: pointer;
}
...@@ -61,10 +61,6 @@ ...@@ -61,10 +61,6 @@
} }
} }
* + h1, * + h2, * + h3 {
border-top: 1px solid #DDD;
}
h1 { h1 {
font-size: 3em; font-size: 3em;
font-weight: 500; font-weight: 500;
...@@ -396,19 +392,7 @@ ...@@ -396,19 +392,7 @@
} }
ul:not(.tabset-tabs):not(.contains-task-list) { ul:not(.tabset-tabs):not(.contains-task-list) {
list-style: none; list-style: square;
> li::before {
position: absolute;
left: -1.1rem;
content: '\25b8';
color: mc('grey', '600');
width: 1.35rem;
@at-root .is-rtl & {
right: -1.1rem;
content: '\25C3';
}
}
} }
ol, ul:not(.tabset-tabs) { ol, ul:not(.tabset-tabs) {
> li { > li {
......
...@@ -1548,6 +1548,7 @@ ...@@ -1548,6 +1548,7 @@
"editor.select.cannotChange": "This cannot be changed once the page is created.", "editor.select.cannotChange": "This cannot be changed once the page is created.",
"editor.select.customView": "or create a custom view?", "editor.select.customView": "or create a custom view?",
"editor.select.title": "Which editor do you want to use for this page?", "editor.select.title": "Which editor do you want to use for this page?",
"editor.settings": "Editor Settings",
"editor.tableEditor.title": "Table Editor", "editor.tableEditor.title": "Table Editor",
"editor.togglePreviewPane": "Toggle Preview Pane", "editor.togglePreviewPane": "Toggle Preview Pane",
"editor.toggleScrollSync": "Toggle Scroll Sync", "editor.toggleScrollSync": "Toggle Scroll Sync",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment