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 30117fe3c4292dc87b1d07a9309b1d7dad3cbc5e
parent 5495261237001abe39b3866910d4352f79f5a24e
Author: Henry Unite <unitehenry@gmail.com>
Date:   Mon,  7 Sep 2020 15:08:39 -0400

current dev into refactor

Diffstat:
MLICENSE.txt | 5++---
Mpackage.json | 5+++--
Msrc/blowupelement.js | 41++++++++++++++++++++++-------------------
Msrc/striveneditor.css | 4++++
Msrc/striveneditor.js | 35++++++++++++++++++++++-------------
5 files changed, 53 insertions(+), 37 deletions(-)

diff --git a/LICENSE.txt b/LICENSE.txt @@ -1,7 +1,7 @@ -Copyright 2019 Striven +Copyright 2020 Striven Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -\ No newline at end of file +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/package.json b/package.json @@ -1,14 +1,15 @@ { "name": "@striven-erp/striven-editor", "private": false, - "version": "3.5.4", + "version": "3.6.1", "description": "The editor used for the Striven ERP system.", "main": "./dist", "scripts": { "start": "cd demo && npm run serve", "prepare": "npm run build", "build": "npx webpack --mode=\"production\"", - "gh-pages": "cd demo && npm run build && node gh-pages" + "gh-pages": "cd demo && npm run build && node gh-pages", + "publish": "git checkout master && git pull origin master && git merge dev && git push origin master && npm run build && npm publish --access=public && git checkout dev" }, "repository": { "type": "git", diff --git a/src/blowupelement.js b/src/blowupelement.js @@ -27,23 +27,26 @@ export default function blowUpElement(el, bg = '#fff', onExpand) { onExpand && onExpand(el); el.collapse = () => reset(); - window.addEventListener('keydown', (e) => { - if (e.key) { - switch (e.key) { - case 'Escape': - el.dataset.expanded === 'true' && reset(); - break; - default: - break; - } - } else { - switch (e.keyCode) { - case 13: - el.dataset.expanded === 'true' && reset(); - break; - default: - break; - } - } - }) + const escapeEvt = (e) => { + if (e.key) { + switch (e.key) { + case 'Escape': + el.dataset.expanded === 'true' && reset(); + break; + default: + break; + } + } else { + switch (e.keyCode) { + case 13: + el.dataset.expanded === 'true' && reset(); + break; + default: + break; + } + } + } + + window.addEventListener('keydown', escapeEvt); + el.addEventListener('keydown', escapeEvt); } diff --git a/src/striveneditor.css b/src/striveneditor.css @@ -100,6 +100,10 @@ display: none !important; } +.striven-editor .se-html .se-toolbar-menu { + display: none !important; +} + .striven-editor .se-toolbar-close { height: 0px; } diff --git a/src/striveneditor.js b/src/striveneditor.js @@ -52,6 +52,7 @@ export default class StrivenEditor { const actives = [...menus, ...inputs, se.body, se.toolbar, se.editor]; if ( + se.editor.getAttribute('data-expanded') !== 'true' && el.innerHTML != el.data_orig && !se.toolbarClick && !actives.includes(document.activeElement) && @@ -289,6 +290,8 @@ export default class StrivenEditor { } break; case 'removeFormat': + this.executeCommand('formatBlock', 'p'); + // Remove the format of content se.executeCommand(command); @@ -1204,7 +1207,7 @@ export default class StrivenEditor { const linkMenuCheck = document.createElement('input'); function resetInput() { - linkMenuFormInput.value = 'http://'; + linkMenuFormInput.value = ''; } linkMenu.id = 'link-menu'; @@ -1865,6 +1868,7 @@ export default class StrivenEditor { }; } }); + } function setResponsive() { @@ -1919,6 +1923,7 @@ export default class StrivenEditor { textDecorationMenu.style.display = 'none'; textDecorationGroup.classList.remove('se-popup'); } + } function hideOption(option) { @@ -2000,11 +2005,12 @@ export default class StrivenEditor { */ getContent() { const se = this; - const text = se.body.textContent; + const body = se.pruneScripts(se.body); + const text = body.textContent; if (text || se.body.getElementsByTagName('img').length) { const htmlView = !!se.editor.querySelector('.se-html'); - return htmlView ? text : se.body.innerHTML; + return htmlView ? text : body.innerHTML; } else { return null; } @@ -2862,23 +2868,26 @@ export default class StrivenEditor { break; case 'fullscreen': const opt = se.toolbar.querySelector('#toolbar-fullscreen'); - if (opt.getAttribute('data-fullscreen')) { - if (se.editor.collapse) { + + if(!se.editor.oncollapse) { + se.editor.oncollapse = () => { opt.innerHTML = ''; opt.append(createSVG(EXPANDICON)); + + se.overflow(); + se.editor.style.maxHeight = null; + se.body.style.height = se.editor.style.height; + opt.removeAttribute('data-fullscreen'); + }; + } - se.editor.collapse(); - } - - se.overflow(); - se.editor.style.maxHeight = null; - se.body.style.height = se.editor.style.height; - opt.removeAttribute('data-fullscreen'); + if (opt.getAttribute('data-fullscreen')) { + se.editor.collapse && se.editor.collapse(); } else { blowUpElement(se.editor, '#fff', e => { opt.innerHTML = ''; opt.append(createSVG(COLLAPSEICON)); - + se.body.style.overflow = null; se.body.style.height = null; se.editor.style.maxHeight = 'inherit';