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 517243972108c30da9b9992367e49c67b91d10b6
parent b7c474f89cef3c1b7cea04ee08bf27f5053bbda7
Author: unitehenry <unitehenry@gmail.com>
Date:   Thu, 24 Oct 2019 11:39:54 -0400

2.0.5

Diffstat:
M.npmignore | 5+++--
Mdemo/src/App.vue | 12+++++++++---
Mpackage.json | 2+-
Msrc/ko-striveneditor.js | 2+-
Msrc/striveneditor.css | 25++++++++++++++++++++-----
Msrc/striveneditor.js | 90++++++++++++++++++++++++++++++-------------------------------------------------
6 files changed, 68 insertions(+), 68 deletions(-)

diff --git a/.npmignore b/.npmignore @@ -1,2 +1,3 @@ node_modules -images -\ No newline at end of file +images +demo +\ No newline at end of file diff --git a/demo/src/App.vue b/demo/src/App.vue @@ -5,12 +5,14 @@ > <striven-editor ref="editor" + v-model="notes" + :toolbar-hide="toolbarHide" + :toolbar-bottom="true" :placeholder="'Type something in here...'" - style="min-height:300px; width: 600px;" + style="min-height:300px; width: 800px;" meta-url="http://localhost:4200/meta" :custom-toolbar-button="customButton" ></striven-editor> - <div ref="customButton" class="custom-button" @click="sendContent">Send</div> </div> </template> @@ -40,9 +42,13 @@ export default { } this.editor.body.blur(); }, - customButton: () => this.$refs.customButton + customButton: () => this.$refs.customButton, + editor: null }; }, + mounted() { + this.editor = this.$refs.editor.editor; + }, methods: { sendContent() { const content = this.editor.getContent(); diff --git a/package.json b/package.json @@ -1,7 +1,7 @@ { "name": "@striven-erp/striven-editor", "private": false, - "version": "2.1.4", + "version": "2.1.5", "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()) + customToolbarButton: (options().customToolbarButton && options().customToolbarButton()) }); let pauseUpdate = false; diff --git a/src/striveneditor.css b/src/striveneditor.css @@ -63,7 +63,6 @@ justify-content: space-between; align-items: center; flex-wrap: wrap; - position: relative } .striven-editor .se-toolbar-options { @@ -166,14 +165,30 @@ /** Popup Menu **/ .striven-editor .se-popup { - display: none; + visibility: hidden; position: absolute; - right: 10px; - bottom: 10px; background-color: #fff; border: 2px solid #ddd; padding: 10px 20px; - z-index: 1000; + z-index: 1000; + opacity: 0; + transition: all 500ms; +} + +.striven-editor .se-popup.se-popup-top { + top: 40px; + transform: translateY(-30px); +} + +.striven-editor .se-popup.se-popup-bottom { + bottom: 40px; + transform: translateY(30px); +} + +.striven-editor .se-popup.se-popup-open { + visibility: visible; + transform: translateY(0); + opacity: 1; } .striven-editor .se-popup > .se-popup-form { diff --git a/src/striveneditor.js b/src/striveneditor.js @@ -222,7 +222,7 @@ export default class StrivenEditor { if (this.linkMenu.dataset.active === "true") { this.closeLinkMenu(); } else { - this.linkMenuSlideIn(); + this.openLinkMenu(); this.linkMenu.querySelector('input').focus(); } @@ -231,7 +231,7 @@ export default class StrivenEditor { if (this.imageMenu.dataset.active === "true") { this.closeImageMenu(); } else { - this.imageMenuSlideIn(); + this.openImageMenu(); this.range = this.getRange(); this.imageMenu.querySelector('input').focus(); @@ -264,56 +264,14 @@ export default class StrivenEditor { // Reposition Toolbar if (this.options.toolbarBottom) { - this.editor.removeChild(this.toolbar); - this.editor.append(this.toolbar); - } - } - - imageMenuSlideIn() { - const that = this; - - this.openImageMenu(); - - let opacity = 0; - let right = this.editor.offsetWidth / 4; - let id = setInterval(frame, 5); - - this.imageMenu.style.opacity = opacity; - - function frame() { - if (right <= 10) { - clearInterval(id); - that.imageMenu.style.opacity = 1; - } else { - right -= 2.5; - opacity += .01; - that.imageMenu.style.opacity = `${opacity}`; - that.imageMenu.style.right = `${right}px`; - } - } - } - - linkMenuSlideIn() { - const that = this; - - this.openLinkMenu(); + this.linkMenu.classList.remove('se-popup-top'); + this.linkMenu.classList.add('se-popup-bottom'); - let opacity = 0; - let right = this.editor.offsetWidth / 4; - let id = setInterval(frame, 5); + this.imageMenu.classList.remove('se-popup-top'); + this.imageMenu.classList.add('se-popup-bottom'); - this.linkMenu.style.opacity = opacity; - - function frame() { - if (right <= 10) { - clearInterval(id); - that.linkMenu.style.opacity = 1; - } else { - right -= 2.5; - opacity += .01; - that.linkMenu.style.opacity = `${opacity}`; - that.linkMenu.style.right = `${right}px`; - } + this.editor.removeChild(this.toolbar); + this.editor.append(this.toolbar); } } @@ -664,7 +622,7 @@ export default class StrivenEditor { const linkMenuFormInput = document.createElement("input"); linkMenu.id = "link-menu"; - linkMenu.classList.add('se-popup') + linkMenu.classList.add('se-popup', 'se-popup-top'); linkMenu.dataset.active = "false"; linkMenuForm.classList.add('se-popup-form') @@ -750,7 +708,7 @@ export default class StrivenEditor { const imageMenuFormSourceInput = document.createElement("input"); imageMenu.id = "image-menu"; - imageMenu.classList.add('se-popup'); + imageMenu.classList.add('se-popup', 'se-popup-top'); imageMenu.dataset.active = "false"; imageMenuForm.classList.add('se-popup-form'); @@ -1179,31 +1137,51 @@ export default class StrivenEditor { }, 500); } + setMenuOffset(button, menu) { + const editorRect = this.editor.getClientRects()[0]; + const buttonRect = button.getClientRects()[0]; + const buttonOffset = buttonRect.left - editorRect.left; + const menuRight = buttonOffset + menu.clientWidth; + + let offset; + if(menuRight > this.editor.clientWidth) { + offset = buttonOffset + (this.editor.clientWidth - menuRight); + } else { + offset = buttonOffset; + } + + menu.style.left = `${offset}px`; + } + openLinkMenu() { + this.setMenuOffset(this.toolbar.querySelector('#toolbar-link'), this.linkMenu); + this.linkMenu.classList.add('se-popup-open'); + //close other open popups this.closeImageMenu(); this.linkMenu.dataset.active = "true"; - this.linkMenu.style.display = "block"; this.addPopupEscapeHandler(); } openImageMenu() { + this.setMenuOffset(this.toolbar.querySelector('#toolbar-image'), this.imageMenu); + this.imageMenu.classList.add('se-popup-open'); + //close other open popups this.closeLinkMenu(); this.imageMenu.dataset.active = "true"; - this.imageMenu.style.display = "block"; this.addPopupEscapeHandler(); } closeLinkMenu() { + this.linkMenu.classList.remove('se-popup-open'); this.linkMenu.dataset.active = "false"; - this.linkMenu.style.display = "none"; this.removePopupEscapeHandler(); } closeImageMenu() { + this.imageMenu.classList.remove('se-popup-open'); this.imageMenu.dataset.active = "false"; - this.imageMenu.style.display = "none"; this.removePopupEscapeHandler(); }