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 9883817aa2ec00af19334a5e5cbd0abe365e5fde
parent 4e3f159a8fc06cdcf49cb5cbeda2162d5d2bda8c
Author: Henry Unite <unitehenry@gmail.com>
Date:   Wed, 23 Sep 2020 17:56:58 -0400

Merge branch 'dev'

Diffstat:
Mpackage.json | 2+-
Msrc/striveneditor.js | 68++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------
2 files changed, 63 insertions(+), 7 deletions(-)

diff --git a/package.json b/package.json @@ -1,7 +1,7 @@ { "name": "@striven-erp/striven-editor", "private": false, - "version": "3.7.8", + "version": "3.8.0", "description": "The editor used for the Striven ERP system.", "main": "./dist", "scripts": { diff --git a/src/striveneditor.js b/src/striveneditor.js @@ -1117,16 +1117,30 @@ export default class StrivenEditor { addEventListener('keyup', (e) => { const tab = (e.key === 'Tab' || e.keyCode === 9); + + if(tab && document.activeElement === se.body) { + if(se.body.textContent.trim() === '') { + const r = se.getRange(); - if(tab && document.activeElement === 9) { - const r = se.getRange(); + if(r) { + const selNode = document.createElement('span'); + selNode.innerHTML = '&nbsp;'; + se.body.append(selNode); - if(r) { - r.selectNodeContents(se.body); - r.collapse(); + r.selectNode(selNode); + r.collapse(); + } + + } else { + const r = se.getRange(); + + if(r) { + r.selectNodeContents(se.body); + r.collapse(); + } } } - }) + }); const bodyFocus = body.onfocus; body.onfocus = e => { @@ -1191,6 +1205,10 @@ export default class StrivenEditor { body.onblur = e => { se.editor.classList.remove('se-focus'); + if(se.body.textContent.trim() === '') { + se.clearContent(); + } + window.removeEventListener('mouseup', execRange); se.scrollPosition = { @@ -2888,6 +2906,24 @@ export default class StrivenEditor { executeCommand(command, input) { const se = this; + function textDecorationInsert(el) { + const r = se.getRange(); + + if(r) { + const b = document.createElement(el); + const selNode = document.createElement('span'); + selNode.innerHTML = '&nbsp;'; + + b.append(selNode); + + const fc = se.body.firstChild + fc ? fc.append(b) : se.body.append(b); + + r.selectNode(selNode); + r.collapse(); + } + } + switch (command) { case 'html': const saveoption = document.createElement('div'); @@ -3142,6 +3178,26 @@ export default class StrivenEditor { setTimeout(() => se.tableMenu.querySelector('input').focus(), 100); } break; + case 'bold': + if(se.body.textContent === '') { + textDecorationInsert('b'); + break; + } + case 'italic': + if(se.body.textContent === '') { + textDecorationInsert('i'); + break; + } + case 'underline': + if(se.body.textContent === '') { + textDecorationInsert('u'); + break; + } + case 'strikethrough': + if(se.body.textContent === '') { + textDecorationInsert('strike'); + break; + } default: if (se.browser.isFirefox() || se.browser.isEdge()) { input