striven-editor

Maintained and contributed to an open source WYSIWYG editor as an internship project that made it to production and was adopted by the company I was working at.
git clone https://unitehenry.com/git/striven-editor.git
Log | Files | Refs | README | LICENSE

commit 2fbc88125a4550e83902b997ae55e9880516a876
parent 3f80236e7b58cb6726443dcd9f01e23e613ccce8
Author: unitehenry <unitehenry@gmail.com>
Date:   Fri, 25 Oct 2019 08:40:26 -0400

toolbar template

Diffstat:
Mdemo/src/App.vue | 6+++---
Mpackage.json | 2+-
Msrc/ko-striveneditor.js | 2+-
Msrc/striveneditor.css | 4+++-
Msrc/striveneditor.js | 35++++++++++++++++++-----------------
Msrc/vue-striveneditor.vue | 4++--
6 files changed, 28 insertions(+), 25 deletions(-)

diff --git a/demo/src/App.vue b/demo/src/App.vue @@ -11,7 +11,7 @@ :placeholder="'Type something in here...'" style="min-height:300px; width: 800px;" meta-url="metaUrl" - :custom-toolbar-button="customButton" + :toolbar-template="customButton" :on-enter="submitOnEnter" ></striven-editor> <div class="custom-button" ref="customButton" @click="sendContent">Send</div> @@ -41,7 +41,7 @@ export default { }, placeholder: "Begin typing in this editor...", submitOnEnter: (e) => { - if(e.keyCode === 13 && e.ctrlKey) { + if(e.ctrlKey) { const content = this.editor.getContent(); const files = this.editor.getFiles(); @@ -67,7 +67,7 @@ export default { if (content || files.length) { console.log({ content, files }); this.editor.clearContent(); - this.editor.clearFiles(); + this.editor.clearFiles(); } this.editor.body.blur(); } diff --git a/package.json b/package.json @@ -1,7 +1,7 @@ { "name": "@striven-erp/striven-editor", "private": false, - "version": "2.1.6", + "version": "2.1.9", "description": "The lightweight Striven WYSIWYG editor built with pure JavaScript.", "main": "./dist", "scripts": { diff --git a/src/ko-striveneditor.js b/src/ko-striveneditor.js @@ -22,7 +22,7 @@ export default class KoStrivenEditor { let editor = new StrivenEditor(element, { ...options(), - customToolbarButton: (options().customToolbarButton && options().customToolbarButton()) + toolbarTemplate: (options().toolbarTemplate && options().toolbarTemplate()) }); let pauseUpdate = false; diff --git a/src/striveneditor.css b/src/striveneditor.css @@ -94,8 +94,10 @@ background-color: #ddd; } -.striven-editor .se-toolbar #custom-button { +.striven-editor .se-toolbar #toolbar-template { height: 40px; + flex-grow: 1; + justify-content: flex-end; } /** File Element **/ diff --git a/src/striveneditor.js b/src/striveneditor.js @@ -128,7 +128,7 @@ export default class StrivenEditor { // Toolbar Hide if (this.options.toolbarHide) { - this.customToolbarButton && (this.customToolbarButton.style.display = "none"); + this.toolbarTemplate && (this.toolbarTemplate.style.display = "none"); this.toolbarOptionsGroup.style.display = "none"; const bodyFocus = this.body.onfocus; @@ -151,7 +151,7 @@ export default class StrivenEditor { ) { this.toolbarSlideDown(); } - }, 500); + }, 200); }; } @@ -283,8 +283,7 @@ export default class StrivenEditor { function frame() { if (height >= 40) { - const customButton = that.toolbar.querySelector('#custom-button'); - customButton && (customButton.style.display = "flex"); + that.toolbarTemplate && (that.toolbarTemplate.style.display = "flex"); that.toolbarOptionsGroup.style.display = "flex"; clearInterval(id); } else { @@ -297,8 +296,7 @@ export default class StrivenEditor { toolbarSlideDown() { const that = this; - const customButton = this.toolbar.querySelector('#custom-button'); - customButton && (customButton.style.display = "none"); + this.toolbarTemplate && (this.toolbarTemplate.style.display = "none"); this.toolbarOptionsGroup.style.display = "none"; let height = 40; @@ -417,20 +415,22 @@ export default class StrivenEditor { toolbar.appendChild(this.toolbarOptionsGroup); - // Custom toolbar button - if(this.options.customToolbarButton) { - const customButton = document.createElement('div'); - customButton.id = 'custom-button'; - customButton.appendChild(this.options.customToolbarButton); - toolbar.appendChild(customButton); + // Custom toolbar template + if(this.options.toolbarTemplate) { + const toolbarTemplate = document.createElement('div'); + toolbarTemplate.id = 'toolbar-template'; - this.options.toolbarHide && (customButton.style.display = "none"); + toolbarTemplate.appendChild(this.options.toolbarTemplate); + toolbar.appendChild(toolbarTemplate); + + this.options.toolbarHide && (toolbarTemplate.style.display = "none"); + this.toolbarTemplate = toolbarTemplate; } this.toolbarOptions = toolbar.querySelectorAll("span"); this.toolbarGroups = [...toolbar.getElementsByClassName("se-toolbar-group")]; this.toolbarMenus = [...toolbar.getElementsByClassName("se-toolbar-menu")]; - this.customToolbarButton = toolbar.querySelector("#custom-toolbar-button"); + // this.customToolbarButton = toolbar.querySelector("#custom-toolbar-button"); this.toolbarMenus.push(this.customToolbarMenu); this.toolbarGroups.push(this.customToolbarGroup); @@ -577,7 +577,9 @@ export default class StrivenEditor { if (this.options.onEnter && e.keyCode === 13) { - if (!document.queryCommandState('insertOrderedList') && !document.queryCommandState('insertUnorderedList')) { + this.options.onEnter(e); + + // if (!document.queryCommandState('insertOrderedList') && !document.queryCommandState('insertUnorderedList')) { // const hasText = !!this.getTextContent(); // const hasImage = !!body.querySelector('img'); @@ -588,8 +590,7 @@ export default class StrivenEditor { // divBreak && divBreak.remove(); // } - this.options.onEnter(e); - } + // } } this.toolbarState(); diff --git a/src/vue-striveneditor.vue b/src/vue-striveneditor.vue @@ -22,12 +22,12 @@ export default { activeOptionColor: String, onEnter: Function, value: String, - customToolbarButton: Function + toolbarTemplate: Function }, mounted() { let vm = this; // Create new object to avoid mutating props - let config = { ...vm.$props, customToolbarButton: (vm.customToolbarButton && vm.customToolbarButton()) }; + let config = { ...vm.$props, toolbarTemplate: (vm.toolbarTemplate && vm.toolbarTemplate()) }; vm.editor = new StrivenEditor(vm.$refs.editor, config);