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 77fb641bc9ba41c1998a2c39c454a05ab39d0cb5
parent 6cefc020d168969ec1bf8beb9aa0ec27e4252bb9
Author: ebutler <e.c.butler@outlook.com>
Date:   Thu, 24 Oct 2019 08:32:32 -0400

Merge branch 'dev' of https://github.com/striven-erp/striven-editor into dev

Diffstat:
M.gitignore | 1-
A.npmignore | 3+++
Mdemo/src/App.vue | 6++++--
Mpackage-lock.json | 43+++++++++++++++++++++++++++++++------------
Mpackage.json | 4++--
Msrc/striveneditor.css | 93+++++++++++++++++++++++++++++++++++++++----------------------------------------
Msrc/striveneditor.js | 92++++++++++++++++++++++++++++++++++++-------------------------------------------
7 files changed, 128 insertions(+), 114 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -1,4 +1,3 @@ node_modules images -.gitignore dist \ No newline at end of file diff --git a/.npmignore b/.npmignore @@ -0,0 +1,2 @@ +node_modules +images +\ No newline at end of file diff --git a/demo/src/App.vue b/demo/src/App.vue @@ -3,13 +3,15 @@ id="app" style="font-family: Segoe UI; color: #2c3e50; margin-top: 20vh; display: flex; justify-content: center; align-items: center; flex-direction: column; padding: 0 1rem;" > + <striven-editor :placeholder="'Hey there'" v-model="notes" style="min-height:300px;"></striven-editor> + <div style="display: flex; padding: 1rem; width: 100%; justify-content: center;"> <!-- <div ref="editor" class="editor" style="margin-top: 20px; background-color: #fff; min-height: 300px; width: 600px;" ></div> --> - <striven-editor :placeholder="'Hey there'" v-model="notes"></striven-editor> + <br/> {{notes}} <button @click="notes = null">Clear</button> </div> @@ -31,7 +33,7 @@ export default { }, mounted() { const editorOptions = { - metaUrl: "https://mighty-anchorage-82390.herokuapp.com/meta", // metaserver.js + metaUrl: "http://localhost:4200",//"https://mighty-anchorage-82390.herokuapp.com/meta", // metaserver.js // imageUrl: "http://localhost:4200/image", // imageserver.js minimal: true, uploadOnPaste: false, diff --git a/package-lock.json b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@striven-erp/striven-editor", - "version": "2.0.2", + "version": "2.0.9", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -3018,7 +3018,8 @@ "ansi-regex": { "version": "2.1.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "aproba": { "version": "1.2.0", @@ -3039,12 +3040,14 @@ "balanced-match": { "version": "1.0.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, "dev": true, + "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -3059,17 +3062,20 @@ "code-point-at": { "version": "1.1.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "concat-map": { "version": "0.0.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "console-control-strings": { "version": "1.1.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "core-util-is": { "version": "1.0.2", @@ -3186,7 +3192,8 @@ "inherits": { "version": "2.0.3", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "ini": { "version": "1.3.5", @@ -3198,6 +3205,7 @@ "version": "1.0.0", "bundled": true, "dev": true, + "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -3212,6 +3220,7 @@ "version": "3.0.4", "bundled": true, "dev": true, + "optional": true, "requires": { "brace-expansion": "^1.1.7" } @@ -3219,12 +3228,14 @@ "minimist": { "version": "0.0.8", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "minipass": { "version": "2.3.5", "bundled": true, "dev": true, + "optional": true, "requires": { "safe-buffer": "^5.1.2", "yallist": "^3.0.0" @@ -3243,6 +3254,7 @@ "version": "0.5.1", "bundled": true, "dev": true, + "optional": true, "requires": { "minimist": "0.0.8" } @@ -3323,7 +3335,8 @@ "number-is-nan": { "version": "1.0.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "object-assign": { "version": "4.1.1", @@ -3335,6 +3348,7 @@ "version": "1.4.0", "bundled": true, "dev": true, + "optional": true, "requires": { "wrappy": "1" } @@ -3420,7 +3434,8 @@ "safe-buffer": { "version": "5.1.2", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "safer-buffer": { "version": "2.1.2", @@ -3456,6 +3471,7 @@ "version": "1.0.2", "bundled": true, "dev": true, + "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -3475,6 +3491,7 @@ "version": "3.0.1", "bundled": true, "dev": true, + "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -3518,12 +3535,14 @@ "wrappy": { "version": "1.0.2", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "yallist": { "version": "3.0.3", "bundled": true, - "dev": true + "dev": true, + "optional": true } } }, diff --git a/package.json b/package.json @@ -1,12 +1,12 @@ { "name": "@striven-erp/striven-editor", "private": false, - "version": "2.0.5", + "version": "2.0.9", "description": "The lightweight Striven WYSIWYG editor built with pure JavaScript.", "main": "./dist", "scripts": { "start": "cd demo && npm run serve", - "prepare": "npx webpack --mode=\"production\"", + "prepare": "npm run build", "build": "npx webpack --mode=\"production\"", "dev": "npx webpack -w", "meta-server": "node metaserver", diff --git a/src/striveneditor.css b/src/striveneditor.css @@ -9,8 +9,9 @@ /** Editor **/ -.Striven-Editor.editor { +.striven-editor.editor { border: 1px solid #ddd; + background-color: #fff; display: flex; position: relative; flex-direction: column; @@ -18,7 +19,7 @@ max-width: 100%; } -.Striven-Editor .body { +.striven-editor .se-body { position: relative; outline: none; padding: 10px 20px; @@ -27,11 +28,12 @@ height: auto; } -.Striven-Editor .body:empty::after { +.striven-editor .se-body:empty::after { content: attr(data-placeholder); + color:#777; } -.Striven-Editor .body .file-drop-dropzone { +.striven-editor .se-body .se-file-drop-dropzone { height: 90%; width: 95%; left: 0; @@ -46,7 +48,7 @@ align-items: center; } -.Striven-Editor .body .file-drop-dropzone p { +.striven-editor .se-body .se-file-drop-dropzone p { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; color: #777; user-select: none; @@ -56,7 +58,7 @@ /** Toolbar **/ -.Striven-Editor .toolbar { +.striven-editor .se-toolbar { display: flex; justify-content: space-between; align-items: center; @@ -64,41 +66,41 @@ position: relative } -.Striven-Editor .toolbar-options { +.striven-editor .se-toolbar-options { margin: 0 10px; } -.Striven-Editor .toolbar-option { +.striven-editor .se-toolbar-option { padding: 8px; } -.Striven-Editor .toolbar-group[data-open="true"] .toolbar-option { +.striven-editor .se-toolbar-group[data-open="true"] .se-toolbar-option { background-color: #fff; border: 2px solid #ddd; margin: 0 2px; } -.Striven-Editor .toolbar-group[data-open="true"] .toolbar-option:hover { +.striven-editor .se-toolbar-group[data-open="true"] .se-toolbar-option:hover { background-color: #ddd; } -.Striven-Editor .toolbar-option >svg { +.striven-editor .se-toolbar-option >svg { vertical-align: middle; } -.Striven-Editor .toolbar-option:hover, -.Striven-Editor .toolbar-option:focus, -.Striven-Editor .toolbar-option:active { +.striven-editor .se-toolbar-option:hover, +.striven-editor .se-toolbar-option:focus, +.striven-editor .se-toolbar-option:active { background-color: #ddd; } -.Striven-Editor .toolbar #custom-button { +.striven-editor .se-toolbar #custom-button { height: 40px; } /** File Element **/ -.Striven-Editor .file-el { +.striven-editor .se-file { width: 100%; display: flex; flex-direction: column; @@ -106,18 +108,18 @@ position: relative; } -.Striven-Editor p.file-name-el { +.striven-editor p.se-file-name { font-weight: bold; font-size: 14px; margin: 0; } -.Striven-Editor .file-size-el { +.striven-editor .se-file-size { font-size: 12px; margin: 2px 0; } -.Striven-Editor .remove-file-el { +.striven-editor .se-remove-link { margin: 0; user-select: none; color: black; @@ -127,38 +129,35 @@ cursor: pointer; background-color: #fff } +.striven-editor .se-remove-link:hover, +.striven-editor .se-remove-link:focus, +.striven-editor .se-remove-link:active +{ + color:#ddd; +} /** Meta Item **/ -.Striven-Editor .meta-item-el { +.striven-editor .se-meta-item { width: 100%; display: flex; margin: 10px; position: relative } -.Striven-Editor .meta-image-el { +.striven-editor .se-meta-image { margin-right: 10px; height: 50px; width: 75px; } -.Striven-Editor .meta-data-title-el { +.striven-editor .se-meta-data-title { font-weight: bold; margin: 0; } -.Striven-Editor .remove-meta-data-el { - user-select: none; - color: black; - position: absolute; - right: 5px; - top: -5px; - cursor: pointer; - background-color: #fff; -} - -.Striven-Editor .metadata-section, .Striven-Editor .files-section { +.striven-editor .se-metadata-section, + .striven-editor .se-files-section { display: flex; flex-wrap: wrap; z-index: 500 @@ -166,7 +165,7 @@ /** Popup Menu **/ -.Striven-Editor .popup { +.striven-editor .se-popup { display: none; position: absolute; right: 10px; @@ -177,13 +176,13 @@ z-index: 1000; } -.Striven-Editor .popup > .popup-form { +.striven-editor .se-popup > .se-popup-form { display: flex; justify-content: space-between; margin: 5px 0; } -.Striven-Editor .popup > .popup-form > .form-label { +.striven-editor .se-popup > .se-popup-form > .se-form-label { margin: 8px 10px 8px 0; font-size: 14px; width: 100%; @@ -191,18 +190,18 @@ margin-right: 10px; } -.Striven-Editor .popup > .popup-form >.form-input { +.striven-editor .se-popup > .se-popup-form >.se-form-input { outline: none; padding: 0 5px; } -.Striven-Editor .popup-button-container +.striven-editor .se-popup-button-container { float:right; } -.Striven-Editor .popup-button{ +.striven-editor .se-popup-button{ cursor: pointer; padding: 6px 12px; border: 1px solid transparent; @@ -212,25 +211,25 @@ margin:2px; } -.Striven-Editor .popup-button.button-primary{ +.striven-editor .se-popup-button.se-button-primary{ border-color: #4cae4c; background-color: #5cb85c; color: #fff; } -.Striven-Editor .popup-button.button-secondary{ +.striven-editor .se-popup-button.se-button-secondary{ border-color: #ccc; background-color: #fff; color: #333; } -.Striven-Editor .popup-button.button-primary:hover, -.Striven-Editor .popup-button.button-primary:active, -.Striven-Editor .popup-button.button-primary:focus{ +.striven-editor .se-popup-button.se-button-primary:hover, +.striven-editor .se-popup-button.se-button-primary:active, +.striven-editor .se-popup-button.se-button-primary:focus{ background-color: #4cae4c; border-color: #398439; } -.Striven-Editor .popup-button.button-secondary:hover, -.Striven-Editor .popup-button.button-secondary:active, -.Striven-Editor .popup-button.button-secondary:focus{ +.striven-editor .se-popup-button.se-button-secondary:hover, +.striven-editor .se-popup-button.se-button-secondary:active, +.striven-editor .se-popup-button.se-button-secondary:focus{ background-color: #d4d4d4; border-color: #8c8c8c; } diff --git a/src/striveneditor.js b/src/striveneditor.js @@ -121,7 +121,7 @@ export default class StrivenEditor { this.metaDataSection = this.initMetaDataSection(); this.filesSection = this.options.fileUpload && this.initFilesSection(); - this.editor.classList.add("editor", "Striven-Editor") + this.editor.classList.add("editor", "striven-editor") // Initialze with the value property in the options this.setContent(this.options.value || '') @@ -360,10 +360,10 @@ export default class StrivenEditor { this.toolbarOptionsGroup = document.createElement("div"); const groups = Object.keys(this.optionGroups); - toolbar.classList.add("toolbar"); + toolbar.classList.add("se-toolbar"); toolbar.style.minHeight = this.options.toolbarHide ? "0" : "40px"; - this.toolbarOptionsGroup.classList.add("toolbar-options"); + this.toolbarOptionsGroup.classList.add("se-toolbar-options"); this.toolbarOptionsGroup.style.display = this.options.toolbarHide ? "none" : "flex"; toolbar.onclick = () => this.body.focus(); @@ -374,7 +374,7 @@ export default class StrivenEditor { const toolbarMenu = document.createElement("div"); // const toolbarMenuIcon = document.createElement("i"); - toolbarMenu.classList.add("toolbar-menu"); + toolbarMenu.classList.add("se-toolbar-menu"); toolbarMenu.id = `menu-${group}`; // toolbarMenuIcon.classList.add(this.options.fontPack); @@ -386,7 +386,7 @@ export default class StrivenEditor { // add group to toolbarOptions const toolbarGroup = document.createElement("div"); - toolbarGroup.classList.add("toolbar-group"); + toolbarGroup.classList.add("se-toolbar-group"); toolbarGroup.id = `group-${group}`; this.options.toolbarOptions.forEach((option) => { @@ -395,7 +395,7 @@ export default class StrivenEditor { const svgData = toolbarOption[option]; const optionSpan = this.constructSVG(svgData); - optionSpan.classList.add('toolbar-option'); + optionSpan.classList.add('se-toolbar-option'); optionSpan.id = `toolbar-${option}`; toolbarGroup.appendChild(optionSpan); @@ -429,7 +429,7 @@ export default class StrivenEditor { if (customOptions.length > 0) { this.customToolbarMenu = document.createElement("div"); - this.customToolbarMenu.classList.add("toolbar-menu"); + this.customToolbarMenu.classList.add("se-toolbar-menu"); this.customToolbarMenu.id = `menu-custom`; const customSVGViewBox = "0 0 1792 1792"; @@ -440,7 +440,7 @@ export default class StrivenEditor { this.customToolbarGroup = document.createElement("div"); - this.customToolbarGroup.classList.add("toolbar-group"); + this.customToolbarGroup.classList.add("se-toolbar-group"); this.customToolbarGroup.id = "group-custom"; customOptions.forEach((customOption) => { @@ -470,8 +470,8 @@ export default class StrivenEditor { } this.toolbarOptions = toolbar.querySelectorAll("span"); - this.toolbarGroups = [...toolbar.getElementsByClassName("toolbar-group")]; - this.toolbarMenus = [...toolbar.getElementsByClassName("toolbar-menu")]; + this.toolbarGroups = [...toolbar.getElementsByClassName("se-toolbar-group")]; + this.toolbarMenus = [...toolbar.getElementsByClassName("se-toolbar-menu")]; this.customToolbarButton = toolbar.querySelector("#custom-toolbar-button"); this.toolbarMenus.push(this.customToolbarMenu); @@ -492,7 +492,7 @@ export default class StrivenEditor { initBody() { const body = document.createElement("div"); - body.classList.add("body"); + body.classList.add("se-body"); body.contentEditable = "true"; body.style.height = this.editor.style.height; body.style.minHeight = this.editor.style.minHeight; @@ -664,28 +664,26 @@ export default class StrivenEditor { const linkMenuFormInput = document.createElement("input"); linkMenu.id = "link-menu"; - linkMenu.classList.add('popup') + linkMenu.classList.add('se-popup') linkMenu.dataset.active = "false"; - linkMenuForm.classList.add('popup-form') + linkMenuForm.classList.add('se-popup-form') - linkMenuFormLabel.classList.add('form-label') + linkMenuFormLabel.classList.add('se-form-label') linkMenuFormLabel.textContent = "Web Address"; - linkMenuFormInput.classList.add('form-input') + linkMenuFormInput.classList.add('se-form-input') linkMenuFormInput.type = "text"; linkMenuFormInput.placeholder = "Insert a Link"; - linkMenuButtons.classList.add('popup-button-container'); + linkMenuButtons.classList.add('se-popup-button-container'); - linkMenuButton.classList.add('popup-button') - linkMenuButton.classList.add('button-primary') + linkMenuButton.classList.add('se-popup-button','se-button-primary'); linkMenuButton.textContent = "Insert Link"; - linkMenuCloseButton.classList.add('popup-button') - linkMenuCloseButton.classList.add('button-secondary') - linkMenuCloseButton.textContent = "Close" + linkMenuCloseButton.classList.add('se-popup-button','se-button-secondary'); + linkMenuCloseButton.textContent = "Close"; linkMenuButton.onclick = e => { const linkValue = linkMenuFormInput.value; @@ -752,26 +750,24 @@ export default class StrivenEditor { const imageMenuFormSourceInput = document.createElement("input"); imageMenu.id = "image-menu"; - imageMenu.classList.add('popup'); + imageMenu.classList.add('se-popup'); imageMenu.dataset.active = "false"; - imageMenuForm.classList.add('popup-form'); + imageMenuForm.classList.add('se-popup-form'); - imageMenuFormLabel.classList.add('form-label'); + imageMenuFormLabel.classList.add('se-form-label'); imageMenuFormLabel.textContent = "Image URL"; - imageMenuFormSourceInput.classList.add('form-input'); + imageMenuFormSourceInput.classList.add('se-form-input'); imageMenuFormSourceInput.type = "text"; imageMenuFormSourceInput.placeholder = "Insert a Link"; - imageMenuButtons.classList.add('popup-button-container'); + imageMenuButtons.classList.add('se-popup-button-container'); - imageMenuButton.classList.add('popup-button'); - imageMenuButton.classList.add('button-primary'); + imageMenuButton.classList.add('se-popup-button','se-button-primary'); imageMenuButton.textContent = "Insert Image"; - imageMenuCloseButton.classList.add('popup-button'); - imageMenuCloseButton.classList.add('button-secondary'); + imageMenuCloseButton.classList.add('se-popup-button','se-button-secondary'); imageMenuCloseButton.textContent = "Close"; imageMenuForm.appendChild(imageMenuFormLabel); @@ -837,14 +833,14 @@ export default class StrivenEditor { initMetaDataSection() { const metaDataSection = document.createElement("div"); - metaDataSection.classList.add("metadata-section"); + metaDataSection.classList.add("se-metadata-section"); return metaDataSection; } initFilesSection() { const filesSection = document.createElement("div"); - filesSection.classList.add("files-section"); + filesSection.classList.add("se-files-section"); window.addEventListener("dragover", function (e) { e = e || event; @@ -857,11 +853,11 @@ export default class StrivenEditor { }, false); this.body.ondragenter = e => { - if (!this.body.querySelector('.file-drop-dropzone')) { + if (!this.body.querySelector('.se-file-drop-dropzone')) { const dropzone = document.createElement("div"); const dropzoneTextEl = document.createElement("p"); - dropzone.classList.add('file-drop-dropzone'); + dropzone.classList.add('se-file-drop-dropzone'); dropzone.contentEditable = "false"; dropzoneTextEl.textContent = 'Drop files to upload'; @@ -874,12 +870,12 @@ export default class StrivenEditor { } this.body.ondragleave = e => { - const dropzone = this.body.querySelector('.file-drop-dropzone'); + const dropzone = this.body.querySelector('.se-file-drop-dropzone'); (dropzone && dropzone.dataset.enabled === "true") && dropzone.remove(); } this.body.ondrop = e => { - const dropzone = this.body.querySelector('.file-drop-dropzone'); + const dropzone = this.body.querySelector('.se-file-drop-dropzone'); dropzone && dropzone.remove(); e.preventDefault(); @@ -903,16 +899,15 @@ export default class StrivenEditor { fileSizeEl.textContent = size; removeFileEl.textContent = "X"; - fileEl.classList.add('file-el') + fileEl.classList.add('se-file') fileEl.dataset.fileindex = (this.files.length - 1); - fileNameEl.classList.add('file-name-el') + fileNameEl.classList.add('se-file-name') - fileSizeEl.classList.add('file-size-el') + fileSizeEl.classList.add('se-file-size') - removeFileEl.classList.add('remove-file-el') - removeFileEl.onmouseenter = () => removeFileEl.style.color = "#ddd"; - removeFileEl.onmouseleave = () => removeFileEl.style.color = "black"; + removeFileEl.classList.add('se-remove-link') + removeFileEl.onclick = e => { this.files.splice(e.target.parentElement.dataset.fileindex, 1); @@ -943,18 +938,16 @@ export default class StrivenEditor { metaLinkEl.target = "blank"; - metaItemEl.classList.add("meta-item-el") + metaItemEl.classList.add("se-meta-item"); - metaImageEl.classList.add("meta-image-el") + metaImageEl.classList.add("se-meta-image"); - metaDataTitleEl.classList.add("meta-data-title-el") + metaDataTitleEl.classList.add("se-meta-data-title"); metaDataDescriptionEl.style.margin = "0"; - removeMetaDataEl.classList.add("remove-meta-data-el") - removeMetaDataEl.onmouseenter = () => removeMetaDataEl.style.color = "#ddd"; - removeMetaDataEl.onmouseleave = () => removeMetaDataEl.style.color = "black"; - + removeMetaDataEl.classList.add("se-remove-link"); + removeMetaDataEl.onclick = e => e.target.parentElement.remove(); metaLinkEl.appendChild(metaImageEl); @@ -1232,7 +1225,6 @@ export default class StrivenEditor { setContent(html) { this.clearContent(); this.body.innerHTML = html; - this.body.blur(); } clearContent() {