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 a65ac93f9e63816433137200269b0854f3d31ee5
parent 00843ce9ce2157f193e0d93336fe4282edc7dbb1
Author: sanjogs <sanjogsharma@gmail.com>
Date:   Tue,  1 Oct 2024 15:04:26 -0400

edit image button is overlayed towards bottom left of the image #163

Diffstat:
Msrc/striveneditor.css | 991++++++++++++++++++++++++++++++++++++++++---------------------------------------
Msrc/striveneditor.js | 13+++++++++++++
2 files changed, 513 insertions(+), 491 deletions(-)

diff --git a/src/striveneditor.css b/src/striveneditor.css @@ -1,491 +1,500 @@ -/** -** - Editor -** - Toolbar -** - Image Menu -** - File element -** - Meta Item -** - Link Menu -*/ - -/** Editor **/ - -.striven-editor { - border: 1px solid #ddd; - background-color: #fff; - display: flex; - position: relative; - flex-direction: column; - font-family: 'Segoe UI', Arial; - max-width: 100%; -} - -.striven-editor .se-body { - position: relative; - outline: none; - padding: 10px 20px; - min-height: auto; - max-height: auto; - height: auto; - word-break: break-word; -} - -.striven-editor .se-body:empty::after { - content: attr(data-placeholder); - color: #777; -} - -.striven-editor .se-body table { - width: max-content; -} - -.striven-editor .se-body a { - position: relative; -} - -.striven-editor .se-body .se-link-options, -.striven-editor .se-body .se-image-options { - position: absolute; - /*left: 0;*/ - /*top: 100%;*/ - padding: 7px; - background-color: #fff; - min-width: max-content; - border: 1px solid #ddd; - box-shadow: 5px 5px 5px #ddd; - font-size: 12px; - font-style: normal; - font-weight: normal; -} - -.striven-editor .se-body .se-link-options span, -.striven-editor .se-body .se-image-options span { - cursor: pointer; - color: #428bca; - text-decoration: underline; -} - -.striven-editor .se-body .se-link-options span:first-child:after { - content: '|'; - margin: 0 5px; - color: #000; -} - -.striven-editor .se-body .se-file-drop-dropzone { - height: 90%; - width: 95%; - left: 0; - right: 0; - bottom: 0; - top: 0; - margin: auto; - position: absolute; - border: 5px dashed #ddd; - background-color: rgba(0, 0, 0, 0.025); - display: flex; - justify-content: center; - align-items: center; -} - -.striven-editor .se-body .se-file-drop-dropzone p { - font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; - color: #777; - user-select: none; - text-align: center; - font-size: 25px; -} - -/** Toolbar **/ - -.striven-editor .se-toolbar { - display: flex; - justify-content: space-between; - flex-wrap: wrap; - min-height: 40px; - transition: height 200ms; -} - -.striven-editor .se-toolbar .se-divider-section { - height: 100%; - width: 5px; - display: flex; - justify-content: center; - align-items: center; -} - -.striven-editor .se-toolbar .se-divider-section .se-divider-bar { - height: 50%; - width: 1px; - background-color: #ddd; -} - -@media (max-width: 1000px) { - .striven-editor .se-toolbar .se-divider-section { - display: none; - } -} - -.striven-editor .se-html .se-toolbar-group { - display: none !important; -} - -.striven-editor .se-html .se-toolbar-selection { - display: none !important; -} - -.striven-editor .se-html .se-divider-section { - display: none !important; -} - -.striven-editor .se-html .se-toolbar-menu { - display: none !important; -} - -.striven-editor .se-toolbar-close { - height: 0px; -} - -.striven-editor .se-toolbar.se-toolbar-top { - align-items: flex-start; -} - -.striven-editor .se-toolbar.se-toolbar-bottom { - align-items: flex-end; -} - -.striven-editor .se-toolbar-options { - display: flex; - margin-right: 10px; -} - -.striven-editor .se-toolbar-option { - border: 1px solid transparent; - display: inline-block; - padding: 4px 7px; - cursor: pointer; - user-select: none; - line-height: 2em; -} - -.striven-editor .se-toolbar-option svg { - width: 16px; - height: 14px; -} - -.striven-editor .se-toolbar-option img { - width: 16px; - height: 14px; - vertical-align: middle; -} - -.striven-editor .se-toolbar .se-arrow-span svg { - transform: translateY(2px); -} - -.striven-editor .se-toolbar.se-toolbar-bottom .se-arrow-span svg { - transform: rotate(180deg) translateY(-3px); -} - -.striven-editor .se-toolbar-option.se-toolbar-option-active { - border: 1px solid rgba(0, 0, 0, 0.25); - background-color: #d4e7fc; -} - -.striven-editor .se-toolbar-option:hover.se-toolbar-option-active { - background-color: #b6d6fa; -} - -.striven-editor .se-toolbar-group { - z-index: 500; - background-color: transparent; - display: flex; - align-items: stretch; -} - -.striven-editor .se-toolbar-group[data-open='true'] { - z-index: 1000; -} - -/* -.striven-editor .se-toolbar-group:after { - content: ''; - margin: 0 auto; - padding-bottom: 5px; - border-right: 1px solid #ddd; -} -*/ - -/* -.striven-editor .se-toolbar-group[data-open='true'] .se-toolbar-option { - background-color: #fff; - border: 1px solid #ddd; -} - -.striven-editor .se-toolbar-group[data-open='true'] .se-toolbar-option:hover { - background-color: #eee; -} -*/ - -.striven-editor .se-toolbar-option > svg { - transform: scale(1); /* chrome bug fix */ - vertical-align: middle; -} - -.striven-editor .se-toolbar-option:hover, -.striven-editor .se-toolbar-option:focus, -.striven-editor .se-toolbar-option:active { - background-color: #eee; - border-color: transparent; -} - -.striven-editor .se-toolbar #toolbar-template { - min-height: 40px; - flex-grow: 1; - justify-content: flex-end; -} - -.striven-editor .se-toolbar .se-toolbar-selection { - display: flex; - justify-content: center; - align-items: center; - background-color: transparent; - cursor: pointer; - padding: 0 5px; - transition: background-color 100ms; -} - -.striven-editor .se-toolbar .se-toolbar-selection:hover { - background-color: #eee; -} - -.striven-editor .se-toolbar .se-toolbar-selection p { - margin: 0; - background-color: transparent; -} - -/* -.striven-editor .se-toolbar .se-toolbar-selection .se-toolbar-option { - border: 1px solid #ddd; - user-select: none; - margin: 0; - padding: 5px 15px; - font-size: 14px; - text-align: center; - background-color: #eee; - transition: background-color 100ms; - cursor: pointer; -} - -.striven-editor .se-toolbar .se-toolbar-selection .se-toolbar-option:hover { - background-color: #ddd; -} -*/ - -.striven-editor .se-toolbar .se-toolbar-color { - height: 16px; - width: 16px; -} - -.striven-editor .se-toolbar .se-toolbar-colorholder { - /* padding: 4px; */ - /* border: 1px solid #ddd;*/ - /* background-color: #eee;*/ - transition: background-color 100ms; -} - -.striven-editor .se-toolbar .se-toolbar-colorholder:hover { - background-color: #ddd; -} - -.striven-editor .se-toolbar-popup-option { - padding: 10px 15px; - background-color: transparent; - transition: background-color 200ms; - font-size: 16px; - cursor: pointer; -} - -.striven-editor .se-toolbar-popup-option:hover { - background-color: #eee; -} - -/** Toolbar Menu **/ - -.striven-editor .se-toolbar-menu { - border: 1px solid transparent; - padding: 4px 7px; - cursor: pointer; - align-items: center; - user-select: none; -} - -.striven-editor .se-toolbar-menu:hover { - background-color: #eee; -} - -.striven-editor .se-toolbar-menu > svg { - transform: scale(1); /* chrome bug fix */ - vertical-align: middle; -} - -/** File Element **/ - -.striven-editor .se-file { - width: 100%; - display: flex; - flex-direction: column; - margin: 10px; - position: relative; -} - -.striven-editor p.se-file-name { - font-weight: bold; - font-size: 14px; - margin: 0; -} - -.striven-editor .se-file-size { - font-size: 12px; - margin: 2px 0; -} - -.striven-editor .se-remove-link { - margin: 0; - user-select: none; - color: black; - position: absolute; - right: 5px; - top: -5px; - 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 .se-meta-item { - width: 100%; - display: flex; - margin: 10px; - position: relative; -} - -.striven-editor .se-meta-image { - margin-right: 10px; - height: 50px; - width: 75px; -} - -.striven-editor .se-meta-data-title { - font-weight: bold; - margin: 0; -} - -.striven-editor .se-metadata-section, -.striven-editor .se-files-section { - display: flex; - flex-wrap: wrap; - z-index: 500; -} - -/** Popup Menu **/ - -.striven-editor .se-popup { - visibility: hidden; - position: absolute; - background-color: #fff; - border: 1px solid #ddd; - padding: 5px; - z-index: 1000; - opacity: 0; - transition: opacity, transform, box-shadow, 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); - box-shadow: 5px 5px 5px #ddd; - opacity: 1; -} - -.striven-editor .se-popup-header { - color: #888; - font-size: 12px; - margin: 0; - border-bottom: 1px solid #ddd; - padding-bottom: 3px; -} - -.striven-editor .se-popup > .se-popup-form { - display: flex; - justify-content: space-between; - margin: 5px 0; -} - -.striven-editor .se-popup > .se-popup-form > .se-form-label { - margin: 8px 10px 8px 0; - font-size: 12px; - text-align: right; - margin-right: 10px; -} - -.striven-editor .se-popup > .se-popup-form > .se-form-input { - outline: none; - padding: 5px; -} - -@media (min-width: 900px) { - .striven-editor .se-popup > .se-popup-form > .se-form-input { - width: 250px; - } -} - -.striven-editor .se-popup-button-container { - float: right; -} - -.striven-editor .se-popup-button { - cursor: pointer; - padding: 6px 12px; - border: 1px solid transparent; - font-size: 14px; - outline: none; - color: #333; - margin: 2px; -} - -.striven-editor .se-popup-button.se-button-primary { - border-color: #357ebd; - background-color: #428bca; - color: #fff; -} -.striven-editor .se-popup-button.se-button-secondary { - border-color: #ccc; - background-color: #fff; - color: #333; -} -.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: #285e8e; - border-color: #285e8e; -} -.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; -} +/** +** - Editor +** - Toolbar +** - Image Menu +** - File element +** - Meta Item +** - Link Menu +*/ + +/** Editor **/ + +.striven-editor { + border: 1px solid #ddd; + background-color: #fff; + display: flex; + position: relative; + flex-direction: column; + font-family: 'Segoe UI', Arial; + max-width: 100%; +} + +.striven-editor .se-body { + position: relative; + outline: none; + padding: 10px 20px; + min-height: auto; + max-height: auto; + height: auto; + word-break: break-word; +} + +.striven-editor .se-body:empty::after { + content: attr(data-placeholder); + color: #777; +} + +.striven-editor .se-body table { + width: max-content; +} + +.striven-editor .se-body a { + position: relative; +} + +.striven-editor .se-body .se-link-options, +.striven-editor .se-body .se-image-options { + position: absolute; + /*left: 0;*/ + /*top: 100%;*/ + padding: 7px; + background-color: #fff; + min-width: max-content; + border: 1px solid #ddd; + box-shadow: 5px 5px 5px #ddd; + font-size: 12px; + font-style: normal; + font-weight: normal; +} +.striven-editor .se-body .se-image-wrapper{ + position:relative; + display: inline-block; +} +.striven-editor .se-body .se-image-options { + left:0; + bottom:0px; +} + + +.striven-editor .se-body .se-link-options span, +.striven-editor .se-body .se-image-options span { + cursor: pointer; + color: #428bca; + text-decoration: underline; +} + +.striven-editor .se-body .se-link-options span:first-child:after { + content: '|'; + margin: 0 5px; + color: #000; +} + +.striven-editor .se-body .se-file-drop-dropzone { + height: 90%; + width: 95%; + left: 0; + right: 0; + bottom: 0; + top: 0; + margin: auto; + position: absolute; + border: 5px dashed #ddd; + background-color: rgba(0, 0, 0, 0.025); + display: flex; + justify-content: center; + align-items: center; +} + +.striven-editor .se-body .se-file-drop-dropzone p { + font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; + color: #777; + user-select: none; + text-align: center; + font-size: 25px; +} + +/** Toolbar **/ + +.striven-editor .se-toolbar { + display: flex; + justify-content: space-between; + flex-wrap: wrap; + min-height: 40px; + transition: height 200ms; +} + +.striven-editor .se-toolbar .se-divider-section { + height: 100%; + width: 5px; + display: flex; + justify-content: center; + align-items: center; +} + +.striven-editor .se-toolbar .se-divider-section .se-divider-bar { + height: 50%; + width: 1px; + background-color: #ddd; +} + +@media (max-width: 1000px) { + .striven-editor .se-toolbar .se-divider-section { + display: none; + } +} + +.striven-editor .se-html .se-toolbar-group { + display: none !important; +} + +.striven-editor .se-html .se-toolbar-selection { + display: none !important; +} + +.striven-editor .se-html .se-divider-section { + display: none !important; +} + +.striven-editor .se-html .se-toolbar-menu { + display: none !important; +} + +.striven-editor .se-toolbar-close { + height: 0px; +} + +.striven-editor .se-toolbar.se-toolbar-top { + align-items: flex-start; +} + +.striven-editor .se-toolbar.se-toolbar-bottom { + align-items: flex-end; +} + +.striven-editor .se-toolbar-options { + display: flex; + margin-right: 10px; +} + +.striven-editor .se-toolbar-option { + border: 1px solid transparent; + display: inline-block; + padding: 4px 7px; + cursor: pointer; + user-select: none; + line-height: 2em; +} + +.striven-editor .se-toolbar-option svg { + width: 16px; + height: 14px; +} + +.striven-editor .se-toolbar-option img { + width: 16px; + height: 14px; + vertical-align: middle; +} + +.striven-editor .se-toolbar .se-arrow-span svg { + transform: translateY(2px); +} + +.striven-editor .se-toolbar.se-toolbar-bottom .se-arrow-span svg { + transform: rotate(180deg) translateY(-3px); +} + +.striven-editor .se-toolbar-option.se-toolbar-option-active { + border: 1px solid rgba(0, 0, 0, 0.25); + background-color: #d4e7fc; +} + +.striven-editor .se-toolbar-option:hover.se-toolbar-option-active { + background-color: #b6d6fa; +} + +.striven-editor .se-toolbar-group { + z-index: 500; + background-color: transparent; + display: flex; + align-items: stretch; +} + +.striven-editor .se-toolbar-group[data-open='true'] { + z-index: 1000; +} + +/* +.striven-editor .se-toolbar-group:after { + content: ''; + margin: 0 auto; + padding-bottom: 5px; + border-right: 1px solid #ddd; +} +*/ + +/* +.striven-editor .se-toolbar-group[data-open='true'] .se-toolbar-option { + background-color: #fff; + border: 1px solid #ddd; +} + +.striven-editor .se-toolbar-group[data-open='true'] .se-toolbar-option:hover { + background-color: #eee; +} +*/ + +.striven-editor .se-toolbar-option > svg { + transform: scale(1); /* chrome bug fix */ + vertical-align: middle; +} + +.striven-editor .se-toolbar-option:hover, +.striven-editor .se-toolbar-option:focus, +.striven-editor .se-toolbar-option:active { + background-color: #eee; + border-color: transparent; +} + +.striven-editor .se-toolbar #toolbar-template { + min-height: 40px; + flex-grow: 1; + justify-content: flex-end; +} + +.striven-editor .se-toolbar .se-toolbar-selection { + display: flex; + justify-content: center; + align-items: center; + background-color: transparent; + cursor: pointer; + padding: 0 5px; + transition: background-color 100ms; +} + +.striven-editor .se-toolbar .se-toolbar-selection:hover { + background-color: #eee; +} + +.striven-editor .se-toolbar .se-toolbar-selection p { + margin: 0; + background-color: transparent; +} + +/* +.striven-editor .se-toolbar .se-toolbar-selection .se-toolbar-option { + border: 1px solid #ddd; + user-select: none; + margin: 0; + padding: 5px 15px; + font-size: 14px; + text-align: center; + background-color: #eee; + transition: background-color 100ms; + cursor: pointer; +} + +.striven-editor .se-toolbar .se-toolbar-selection .se-toolbar-option:hover { + background-color: #ddd; +} +*/ + +.striven-editor .se-toolbar .se-toolbar-color { + height: 16px; + width: 16px; +} + +.striven-editor .se-toolbar .se-toolbar-colorholder { + /* padding: 4px; */ + /* border: 1px solid #ddd;*/ + /* background-color: #eee;*/ + transition: background-color 100ms; +} + +.striven-editor .se-toolbar .se-toolbar-colorholder:hover { + background-color: #ddd; +} + +.striven-editor .se-toolbar-popup-option { + padding: 10px 15px; + background-color: transparent; + transition: background-color 200ms; + font-size: 16px; + cursor: pointer; +} + +.striven-editor .se-toolbar-popup-option:hover { + background-color: #eee; +} + +/** Toolbar Menu **/ + +.striven-editor .se-toolbar-menu { + border: 1px solid transparent; + padding: 4px 7px; + cursor: pointer; + align-items: center; + user-select: none; +} + +.striven-editor .se-toolbar-menu:hover { + background-color: #eee; +} + +.striven-editor .se-toolbar-menu > svg { + transform: scale(1); /* chrome bug fix */ + vertical-align: middle; +} + +/** File Element **/ + +.striven-editor .se-file { + width: 100%; + display: flex; + flex-direction: column; + margin: 10px; + position: relative; +} + +.striven-editor p.se-file-name { + font-weight: bold; + font-size: 14px; + margin: 0; +} + +.striven-editor .se-file-size { + font-size: 12px; + margin: 2px 0; +} + +.striven-editor .se-remove-link { + margin: 0; + user-select: none; + color: black; + position: absolute; + right: 5px; + top: -5px; + 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 .se-meta-item { + width: 100%; + display: flex; + margin: 10px; + position: relative; +} + +.striven-editor .se-meta-image { + margin-right: 10px; + height: 50px; + width: 75px; +} + +.striven-editor .se-meta-data-title { + font-weight: bold; + margin: 0; +} + +.striven-editor .se-metadata-section, +.striven-editor .se-files-section { + display: flex; + flex-wrap: wrap; + z-index: 500; +} + +/** Popup Menu **/ + +.striven-editor .se-popup { + visibility: hidden; + position: absolute; + background-color: #fff; + border: 1px solid #ddd; + padding: 5px; + z-index: 1000; + opacity: 0; + transition: opacity, transform, box-shadow, 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); + box-shadow: 5px 5px 5px #ddd; + opacity: 1; +} + +.striven-editor .se-popup-header { + color: #888; + font-size: 12px; + margin: 0; + border-bottom: 1px solid #ddd; + padding-bottom: 3px; +} + +.striven-editor .se-popup > .se-popup-form { + display: flex; + justify-content: space-between; + margin: 5px 0; +} + +.striven-editor .se-popup > .se-popup-form > .se-form-label { + margin: 8px 10px 8px 0; + font-size: 12px; + text-align: right; + margin-right: 10px; +} + +.striven-editor .se-popup > .se-popup-form > .se-form-input { + outline: none; + padding: 5px; +} + +@media (min-width: 900px) { + .striven-editor .se-popup > .se-popup-form > .se-form-input { + width: 250px; + } +} + +.striven-editor .se-popup-button-container { + float: right; +} + +.striven-editor .se-popup-button { + cursor: pointer; + padding: 6px 12px; + border: 1px solid transparent; + font-size: 14px; + outline: none; + color: #333; + margin: 2px; +} + +.striven-editor .se-popup-button.se-button-primary { + border-color: #357ebd; + background-color: #428bca; + color: #fff; +} +.striven-editor .se-popup-button.se-button-secondary { + border-color: #ccc; + background-color: #fff; + color: #333; +} +.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: #285e8e; + border-color: #285e8e; +} +.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 @@ -2521,6 +2521,11 @@ export default class StrivenEditor { const imagesToEdit = se.body.querySelectorAll('.se-image-to-edit'); for (const img of imagesToEdit) { img.classList.remove("se-image-to-edit"); + let wrapper= img.parentElement; + if(wrapper.classList.contains('se-image-wrapper')){ + wrapper.parentElement.insertBefore(img, wrapper); + wrapper.remove(); + } } } @@ -3053,6 +3058,14 @@ export default class StrivenEditor { image.onclick = e => { if (!image.nextElementSibling || image.nextElementSibling.className !== "se-image-options") { + let imageWrapper = image.parentElement + if(!imageWrapper.classList.contains('se-image-wrapper')){ + imageWrapper = document.createElement('div'); + imageWrapper.classList.add('se-image-wrapper'); + imageWrapper.setAttribute('contenteditable', false); + image.parentElement.insertBefore(imageWrapper,image); + imageWrapper.appendChild(image); + } const editImageMenu = document.createElement('span'); editImageMenu.setAttribute('class', 'se-image-options'); editImageMenu.setAttribute('contenteditable', false);