diff --git a/system/typemill/author/js/vue-blox-components.js b/system/typemill/author/js/vue-blox-components.js index 830b225..88646bb 100644 --- a/system/typemill/author/js/vue-blox-components.js +++ b/system/typemill/author/js/vue-blox-components.js @@ -1,7 +1,13 @@ bloxeditor.component('title-component', { props: ['markdown', 'disabled', 'index'], template: `
- +
`, mounted: function(){ this.$refs.markdown.focus(); @@ -31,7 +37,13 @@ bloxeditor.component('markdown-component', { - + `, mounted: function(){ @@ -74,7 +86,14 @@ bloxeditor.component('headline-component', { - + `, data: function(){ return { @@ -108,7 +127,7 @@ bloxeditor.component('headline-component', { { this.$emit('saveBlockEvent'); }, - updatemarkdown: function(event) + updatemarkdown(event) { this.level = this.getHeadlineLevel(this.compmarkdown); if(this.level > 6) @@ -125,7 +144,7 @@ bloxeditor.component('headline-component', { this.$emit('updateMarkdownEvent', this.compmarkdown); }, - headlinedown: function() + headlinedown() { this.level = this.getHeadlineLevel(this.compmarkdown); if(this.level < 6) @@ -143,7 +162,7 @@ bloxeditor.component('headline-component', { this.$emit('updateMarkdownEvent', this.compmarkdown); }, - getHeadlineLevel: function(str) + getHeadlineLevel(str) { var count = 0; for(var i = 0; i < str.length; i++){ @@ -164,7 +183,14 @@ bloxeditor.component('ulist-component', { - + `, data: function(){ @@ -205,6 +231,8 @@ bloxeditor.component('ulist-component', { this.compmarkdown = md; } + this.$emit('updateMarkdownEvent', this.compmarkdown); + this.$nextTick(function () { autosize(document.querySelectorAll('textarea')); }); @@ -215,13 +243,15 @@ bloxeditor.component('ulist-component', { beforeSave() { this.$emit('saveBlockEvent'); - }, - updatemarkdown: function(event) - { - this.$emit('updateMarkdownEvent', event.target.value); }, - newLine: function(event) + updatemarkdown(value) { + this.$emit('updateMarkdownEvent', value); + }, + newLine(event) + { + this.compmarkdown = this.markdown; + let listend = '* \n'; // '1. \n'; let liststyle = '* '; // '1. '; @@ -239,6 +269,8 @@ bloxeditor.component('ulist-component', { this.compmarkdown = this.compmarkdown.substr(0, end) + liststyle + this.compmarkdown.substr(end); + this.$emit('updateMarkdownEvent', this.compmarkdown); + mdtextarea[0].focus(); if(mdtextarea[0].setSelectionRange) { @@ -261,7 +293,14 @@ bloxeditor.component('olist-component', { - + `, data: function(){ @@ -280,6 +319,8 @@ bloxeditor.component('olist-component', { this.compmarkdown = '1. '; } + this.$emit('updateMarkdownEvent', this.compmarkdown); + this.$nextTick(function () { autosize(document.querySelectorAll('textarea')); }); @@ -291,12 +332,14 @@ bloxeditor.component('olist-component', { { this.$emit('saveBlockEvent'); }, - updatemarkdown: function(event) + updatemarkdown(value) { - this.$emit('updateMarkdownEvent', event.target.value); + this.$emit('updateMarkdownEvent', value); }, - newLine: function(event) + newLine(event) { + this.compmarkdown = this.markdown; + let listend = '1. \n'; let liststyle = '1. '; @@ -314,6 +357,8 @@ bloxeditor.component('olist-component', { this.compmarkdown = this.compmarkdown.substr(0, end) + liststyle + this.compmarkdown.substr(end); + this.$emit('updateMarkdownEvent', this.compmarkdown); + mdtextarea[0].focus(); if(mdtextarea[0].setSelectionRange) { @@ -338,7 +383,13 @@ bloxeditor.component('code-component', { - + `, data: function(){ return { @@ -387,18 +438,18 @@ bloxeditor.component('code-component', { { this.$emit('saveBlockEvent'); }, - createlanguage: function() + createlanguage() { var codeblock = this.prefix + this.language + '\n' + this.codeblock + '\n' + this.prefix; this.updatemarkdown(codeblock); }, - createmarkdown: function(event) + createmarkdown(event) { this.codeblock = event.target.value; var codeblock = this.prefix + this.language + '\n' + this.codeblock + '\n' + this.prefix; this.updatemarkdown(codeblock); }, - updatemarkdown: function(codeblock) + updatemarkdown(codeblock) { this.$emit('updateMarkdownEvent', codeblock); }, @@ -413,7 +464,13 @@ bloxeditor.component('hr-component', { - + `, mounted: function(){ @@ -430,7 +487,7 @@ bloxeditor.component('hr-component', { { this.$emit('saveBlockEvent'); }, - updatemarkdown: function(event) + updatemarkdown(event) { var emptyline = /^\s*$(?:\r\n?|\n)/gm; @@ -453,7 +510,13 @@ bloxeditor.component('toc-component', { - + `, mounted: function(){ @@ -470,7 +533,7 @@ bloxeditor.component('toc-component', { { this.$emit('saveBlockEvent'); }, - updatemarkdown: function(event) + updatemarkdown(event) { var emptyline = /^\s*$(?:\r\n?|\n)/gm; @@ -485,6 +548,7 @@ bloxeditor.component('toc-component', { }, }) + bloxeditor.component('quote-component', { props: ['markdown', 'disabled', 'index'], template: `
@@ -494,61 +558,79 @@ bloxeditor.component('quote-component', {
- + `, data: function(){ return { - prefix: '> ', - quote: '' + compmarkdown: '' } }, mounted: function(){ eventBus.$on('beforeSave', this.beforeSave ); - this.$refs.markdown.focus(); + this.compmarkdown = this.markdown; - if(this.markdown) + if(this.compmarkdown == '') { - var lines = this.markdown.match(/^.*([\n\r]+|$)/gm); - for (var i = 0; i < lines.length; i++) { - lines[i] = lines[i].replace(/(^[\> ]+)/mg, ''); - } - - this.quote = lines.join(''); + this.compmarkdown = '> '; } + + this.$emit('updateMarkdownEvent', this.compmarkdown); + this.$nextTick(function () { autosize(document.querySelectorAll('textarea')); }); + + this.$refs.markdown.focus(); }, methods: { beforeSave() { this.$emit('saveBlockEvent'); }, - updatemarkdown: function(value) + updatemarkdown(value) { - this.quote = value; + this.$emit('updateMarkdownEvent', value); + }, + newLine(event) + { + this.compmarkdown = this.markdown; - let emptyline = /^\s*$(?:\r\n?|\n)/gm; + let listend = '> \n'; + let liststyle = '> '; - if(value.search(emptyline) > -1) + if(this.compmarkdown.endsWith(listend)) { - - let cleanvalue = value.trim(); - let lines = cleanvalue.match(/^.*([\n\r]|$)/gm); - let quote = this.prefix + lines.join(this.prefix); - - this.$emit('updateMarkdownEvent', quote); + this.compmarkdown = this.compmarkdown.replace(listend, ''); + this.$emit('updateMarkdownEvent', this.compmarkdown); this.$emit('saveBlockEvent'); } else { - let lines = value.match(/^.*([\n\r]|$)/gm); - let quote = this.prefix + lines.join(this.prefix); + let mdtextarea = document.getElementsByTagName('textarea'); + let start = mdtextarea[0].selectionStart; + let end = mdtextarea[0].selectionEnd; + + this.compmarkdown = this.compmarkdown.substr(0, end) + liststyle + this.compmarkdown.substr(end); - this.$emit('updateMarkdownEvent', quote); + this.$emit('updateMarkdownEvent', this.compmarkdown); + + mdtextarea[0].focus(); + if(mdtextarea[0].setSelectionRange) + { + setTimeout(function(){ + mdtextarea[0].setSelectionRange(end+3, end+3); + }, 1); + } } } } @@ -565,7 +647,13 @@ bloxeditor.component('notice-component', { - + `, data: function(){ return { @@ -602,7 +690,7 @@ bloxeditor.component('notice-component', { { this.$emit('saveBlockEvent'); }, - noticedown: function() + noticedown() { this.prefix = this.getNoticePrefix(this.markdown); @@ -620,7 +708,7 @@ bloxeditor.component('notice-component', { this.noteclass = 'note' + (this.prefix.length); this.updatemarkdown(this.notice); }, - getNoticePrefix: function(str) + getNoticePrefix(str) { var prefix = ''; if(str === undefined) @@ -634,7 +722,7 @@ bloxeditor.component('notice-component', { } return prefix; }, - updatemarkdown: function(value) + updatemarkdown(value) { this.notice = value; @@ -657,6 +745,7 @@ bloxeditor.component('table-component', { ['2', 'cell', 'cell'], ['3', 'cell', 'cell'], ], + aligns: ['0', 'left', 'left'], editable: 'editable', noteditable: 'noteditable', cellcontent: '', @@ -677,35 +766,46 @@ bloxeditor.component('table-component', { - {{value}}
+
+
:---
+
:---:
+
---:
+
{{ $filters.translate('add left column') }}
{{ $filters.translate('add right column') }}
{{ $filters.translate('delete column') }}
- {{ value }} -
{{ $filters.translate('add row above') }}
@@ -743,7 +843,29 @@ bloxeditor.component('table-component', { for(i = 0; i < length; i++) { - if(i == 1){ continue } + if(i == 1) + { + this.aligns = [0]; + var line = lines[i].trim(); + var columns = line.split("|"); + for(x = 0; x < columns.length; x++) + { + switch(columns[x].trim()) + { + case "": + break; + case ":---:": + this.aligns[x] = "center"; + break; + case "---:": + this.aligns[x] = "right"; + break; + default: + this.aligns[x] = "left"; + } + } + continue; + } var line = lines[i].trim(); var row = line.split("|").map(function(cell){ @@ -813,6 +935,11 @@ bloxeditor.component('table-component', { } this.markdowntable(); }, + aligncolumn(event, index, align) + { + this.aligns.splice(index,1,align); + this.markdowntable(); + }, addleftcolumn(event, index) { var tableLength = this.table.length; @@ -841,7 +968,21 @@ bloxeditor.component('table-component', { for(var i = 0; i < cols; i++) { if(i == 0){ continue; } - separator += '---|'; + + switch(this.aligns[i]) + { + case "left": + separator += ':---|'; + break + case "center": + separator += ':---:|'; + break + case "right": + separator += '---:|'; + break + default: + separator += '---|'; + } } for(var i = 0; i < rows; i++) @@ -1159,11 +1300,11 @@ bloxeditor.component('inline-formats', { } }, methods: { - onMousedown: function(event) { + onMousedown(event) { this.startX = event.offsetX; this.startY = event.offsetY; }, - onMouseup: function(event) { + onMouseup(event) { /* if click is on format popup */ if(this.formatBar.contains(event.target) || this.stopNext) @@ -1933,23 +2074,23 @@ bloxeditor.component('file-component', { this.createmarkdown(); this.getrestriction(file.url); }, - openmedialib: function() + openmedialib() { this.showmedialib = true; }, - isChecked: function(classname) + isChecked(classname) { if(this.fileclass == classname) { return ' checked'; } }, - updatemarkdown: function(event, url) + updatemarkdown(event, url) { this.$emit('updateMarkdownEvent', event.target.value); this.getrestriction(url); }, - createmarkdown: function() + createmarkdown() { var errors = false; @@ -1987,7 +2128,7 @@ bloxeditor.component('file-component', { this.compmarkdown = filemarkdown; } }, - getrestriction: function(url) + getrestriction(url) { var fileurl = this.fileurl; if(url) @@ -2017,7 +2158,7 @@ bloxeditor.component('file-component', { } }); }, - updaterestriction: function() + updaterestriction() { tmaxios.post('/api/v1/filerestrictions',{ 'url': data.urlinfo.route, @@ -2027,7 +2168,7 @@ bloxeditor.component('file-component', { .then(function (response) {}) .catch(function (error){ alert("reponse error")}); }, - onFileChange: function( e ) + onFileChange( e ) { if(e.target.files.length > 0) { @@ -2343,7 +2484,7 @@ bloxeditor.component('shortcode-component', { } } }, - createmarkdown: function(shortcodename,attribute = false) + createmarkdown(shortcodename,attribute = false) { var attributes = ''; if(attribute) @@ -2361,13 +2502,13 @@ bloxeditor.component('shortcode-component', { this.$emit('updateMarkdownEvent', this.compmarkdown); }, - selectsearch: function(item,attribute) + selectsearch(item,attribute) { /* check if still reactive */ this.shortcodedata[this.shortcodename][attribute].value = item; this.createmarkdown(this.shortcodename,attribute); }, - updatemarkdown: function(event) + updatemarkdown(event) { this.$emit('updateMarkdownEvent', event.target.value); }, diff --git a/system/typemill/author/js/vue-blox.js b/system/typemill/author/js/vue-blox.js index 3c4d590..7c4f1fa 100644 --- a/system/typemill/author/js/vue-blox.js +++ b/system/typemill/author/js/vue-blox.js @@ -475,6 +475,12 @@ bloxeditor.component('new-block',{ { eventBus.$emit('item', response.data.item); } + + if(self.index == 999999) + { + self.setComponentType(false, 'markdown-component'); + } + }) .catch(function (error) {