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 121d5834cd2764df38f47eb5f46fbdd93a57d7f5
parent 81d220bc5297264ae3d407a42977782794bffa9d
Author: unitehenry <unitehenry@gmail.com>
Date:   Tue, 12 Nov 2019 09:31:51 -0500

attach multiple files

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

diff --git a/package.json b/package.json @@ -1,7 +1,7 @@ { "name": "@striven-erp/striven-editor", "private": false, - "version": "2.5.1", + "version": "2.5.5", "description": "The lightweight zero-dependency Striven WYSIWYG editor.", "main": "./dist", "scripts": { diff --git a/src/striveneditor.js b/src/striveneditor.js @@ -400,6 +400,7 @@ export default class StrivenEditor { }); if ( + e.clipboardData.files && e.clipboardData.files.length > 0 && e.clipboardData.files[0].type.includes("image") ) { @@ -442,6 +443,7 @@ export default class StrivenEditor { // meta extraction on paste if ( + e.clipboardData.items && e.clipboardData.items.length > 0 && e.clipboardData.items[0].type === "text/plain" ) { @@ -450,7 +452,8 @@ export default class StrivenEditor { if (this.validURL(string)) { e.preventDefault(); - if(this.browser.isEdge() || this.browser.isFirefox()) { + if (this.browser.isEdge() || this.browser.isFirefox()) { + console.log(string) document.execCommand('insertHTML', false, `<a href="${string}">${string}</a>`); } else { document.execCommand('insertHTML', true, `<a href="${string}">${string}</a>`); @@ -501,7 +504,10 @@ export default class StrivenEditor { // disables all states this.options.toolbarOptions.forEach(opt => { - if(typeof opt === 'string' && opt.includes('list')){ + if (typeof opt === 'string') { + if (document.queryCommandState('insertUnorderedList')) { return false }; + if (document.queryCommandState('insertOrderedList')) { return false }; + document.queryCommandState(opt) && this.executeCommand(opt); } }) @@ -766,9 +772,9 @@ export default class StrivenEditor { e.preventDefault(); if (e.dataTransfer.types.includes('Files')) { - const file = (e.dataTransfer.files.length && e.dataTransfer.files[0]); - - this.attachFile(file); + if(e.dataTransfer.files.length) { + [...e.dataTransfer.files].forEach(file => this.attachFile(file)); + } } } @@ -1379,7 +1385,8 @@ export default class StrivenEditor { const attachmentInput = document.createElement("input"); attachmentInput.style.display = "none"; attachmentInput.type = "file"; - attachmentInput.onchange = e => this.attachFile(attachmentInput.files[0]) + attachmentInput.multiple = true; + attachmentInput.onchange = e => [...attachmentInput.files].forEach(file => this.attachFile(file)); attachmentInput.click(); break; case "link":