From 0307007bb30c873609af08d75a1c6d2a02c65c75 Mon Sep 17 00:00:00 2001 From: trendschau Date: Mon, 29 Jan 2024 16:15:36 +0100 Subject: [PATCH] v2.1.2 fix behavior of open and close blocks --- system/typemill/author/js/vue-blox.js | 278 +++++++++++++------------- 1 file changed, 140 insertions(+), 138 deletions(-) diff --git a/system/typemill/author/js/vue-blox.js b/system/typemill/author/js/vue-blox.js index 7cefb3d..2bfb15e 100644 --- a/system/typemill/author/js/vue-blox.js +++ b/system/typemill/author/js/vue-blox.js @@ -96,141 +96,6 @@ const bloxeditor = Vue.createApp({ bloxeditor.component('draggable', vuedraggable); -bloxeditor.component('new-block',{ - props: ['markdown', 'index'], - template: ` -
-
- -
-
- -
- - -
-
-
- `, - data: function () { - return { - formats: bloxFormats, - componentType: false, - disabled: false, - newblockmarkdown: '', - unsafedcontent: false, - } - }, - mounted: function() - { - console.info('new-block: mounted'); - - eventBus.$on('closeComponents', this.closeComponent); - - eventBus.$on('inlineFormat', content => { - this.newblockmarkdown = content; - }); - - eventBus.$on('lockcontent', content => { - this.unsafedcontent = true; - }); - - eventBus.$on('unlockcontent', content => { - this.unsafedcontent = false; - }); - }, - methods: { - setComponentType(event, componenttype) - { - if(this.unsafedcontent) - { - eventBus.$emit('publishermessage', 'Save or cancel your changes first.'); - } - else - { -/* eventBus.$emit('closeComponents'); will also close component above, refactor logic */ - eventBus.$emit('freezeblocks'); - - this.componentType = componenttype; - } - }, - closeComponent() - { - this.componentType = false; - this.newblockmarkdown = ''; - eventBus.$emit('unlockcontent'); - eventBus.$emit('publisherclear'); - }, - updateMarkdownFunction(value) - { - eventBus.$emit('lockcontent'); - this.newblockmarkdown = value; - }, - beforeSaveNew() - { - eventBus.$emit('beforeSave'); - }, - saveNewBlock() - { - if( - this.newblockmarkdown == undefined || - this.newblockmarkdown.replace(/(\r\n|\n|\r|\s)/gm,"") == '' - ) - { - this.closeComponent(); - return; - } - - if(typeof this.$refs.activeComponent.saveBlock === "function") - { - this.$refs.activeComponent.saveBlock(this.updatedmarkdown); - return; - } - - var self = this; - - eventBus.$emit('publisherclear'); - - tmaxios.post('/api/v1/block',{ - 'url': data.urlinfo.route, - 'block_id': this.index, - 'markdown': this.newblockmarkdown.trim(), - }) - .then(function (response) - { - self.$root.$data.content = response.data.content; - self.closeComponent(); - eventBus.$emit('closeComponents'); - if(response.data.navigation) - { - eventBus.$emit('navigation', response.data.navigation); - } - if(response.data.item) - { - eventBus.$emit('item', response.data.item); - } - }) - .catch(function (error) - { - if(error.response) - { - let message = handleErrorMessage(error); - if(message) - { - eventBus.$emit('publishermessage', message); - } - } - }); - }, - } -}); - - bloxeditor.component('content-block', { props: ['element', 'index'], template: ` @@ -313,12 +178,12 @@ bloxeditor.component('content-block', { } }, closeNewBlock() - { + { eventBus.$emit('unlockcontent'); eventBus.$emit('unfreeze'); eventBus.$emit('publisherclear'); - this.newblock = false; + this.newblock = false; }, closeEditor() { @@ -487,4 +352,141 @@ bloxeditor.component('content-block', { }); }, }, -}) \ No newline at end of file +}) + +bloxeditor.component('new-block',{ + props: ['markdown', 'index'], + template: ` +
+
+ +
+
+ +
+ + +
+
+
+ `, + data: function () { + return { + formats: bloxFormats, + componentType: false, + disabled: false, + newblockmarkdown: '', + unsafedcontent: false, + } + }, + mounted: function() + { + eventBus.$on('closeComponents', this.closeComponent); + + eventBus.$on('inlineFormat', content => { + this.newblockmarkdown = content; + }); + + eventBus.$on('lockcontent', content => { + this.unsafedcontent = true; + }); + + eventBus.$on('unlockcontent', content => { + this.unsafedcontent = false; + }); + }, + methods: { + setComponentType(event, componenttype) + { + if(this.unsafedcontent) + { + eventBus.$emit('publishermessage', 'Save or cancel your changes first.'); + } + else + { + /* if it is a new block at the end of the page, close other open blocks first */ + if(this.index == 999999) + { + eventBus.$emit('closeComponents'); + } + + eventBus.$emit('freezeblocks'); + + this.componentType = componenttype; + } + }, + closeComponent() + { + this.componentType = false; + this.newblockmarkdown = ''; + eventBus.$emit('unlockcontent'); + eventBus.$emit('publisherclear'); + }, + updateMarkdownFunction(value) + { + eventBus.$emit('lockcontent'); + this.newblockmarkdown = value; + }, + beforeSaveNew() + { + eventBus.$emit('beforeSave'); + }, + saveNewBlock() + { + if( + this.newblockmarkdown == undefined || + this.newblockmarkdown.replace(/(\r\n|\n|\r|\s)/gm,"") == '' + ) + { + this.closeComponent(); + return; + } + + if(typeof this.$refs.activeComponent.saveBlock === "function") + { + this.$refs.activeComponent.saveBlock(this.updatedmarkdown); + return; + } + + var self = this; + + eventBus.$emit('publisherclear'); + + tmaxios.post('/api/v1/block',{ + 'url': data.urlinfo.route, + 'block_id': this.index, + 'markdown': this.newblockmarkdown.trim(), + }) + .then(function (response) + { + self.$root.$data.content = response.data.content; + self.closeComponent(); + eventBus.$emit('closeComponents'); + if(response.data.navigation) + { + eventBus.$emit('navigation', response.data.navigation); + } + if(response.data.item) + { + eventBus.$emit('item', response.data.item); + } + }) + .catch(function (error) + { + if(error.response) + { + let message = handleErrorMessage(error); + if(message) + { + eventBus.$emit('publishermessage', message); + } + } + }); + }, + } +});