X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/63d62722825b9ba77f75db531363d29f9dcc6c68..refs/pull/3908/head:/resources/js/components/markdown-editor.js diff --git a/resources/js/components/markdown-editor.js b/resources/js/components/markdown-editor.js index 671aa4e65..4c3de91f6 100644 --- a/resources/js/components/markdown-editor.js +++ b/resources/js/components/markdown-editor.js @@ -14,6 +14,11 @@ export class MarkdownEditor extends Component { this.display = this.$refs.display; this.input = this.$refs.input; + this.divider = this.$refs.divider; + this.displayWrap = this.$refs.displayWrap; + + const settingContainer = this.$refs.settingContainer; + const settingInputs = settingContainer.querySelectorAll('input[type="checkbox"]'); this.editor = null; initEditor({ @@ -22,10 +27,11 @@ export class MarkdownEditor extends Component { displayEl: this.display, inputEl: this.input, drawioUrl: this.getDrawioUrl(), + settingInputs: Array.from(settingInputs), text: { serverUploadLimit: this.serverUploadLimitText, imageUploadError: this.imageUploadErrorText, - } + }, }).then(editor => { this.editor = editor; this.setupListeners(); @@ -78,6 +84,36 @@ export class MarkdownEditor extends Component { const resizeDebounced = debounce(() => this.editor.cm.refresh(), 100, false); const observer = new ResizeObserver(resizeDebounced); observer.observe(this.elem); + + this.handleDividerDrag(); + } + + handleDividerDrag() { + this.divider.addEventListener('pointerdown', event => { + const wrapRect = this.elem.getBoundingClientRect(); + const moveListener = (event) => { + const xRel = event.pageX - wrapRect.left; + const xPct = Math.min(Math.max(20, Math.floor((xRel / wrapRect.width) * 100)), 80); + this.displayWrap.style.flexBasis = `${100-xPct}%`; + this.editor.settings.set('editorWidth', xPct); + }; + const upListener = (event) => { + window.removeEventListener('pointermove', moveListener); + window.removeEventListener('pointerup', upListener); + this.display.style.pointerEvents = null; + document.body.style.userSelect = null; + this.editor.cm.refresh(); + }; + + this.display.style.pointerEvents = 'none'; + document.body.style.userSelect = 'none'; + window.addEventListener('pointermove', moveListener); + window.addEventListener('pointerup', upListener); + }); + const widthSetting = this.editor.settings.get('editorWidth'); + if (widthSetting) { + this.displayWrap.style.flexBasis = `${100-widthSetting}%`; + } } scrollToTextIfNeeded() {