commit 12efdd09c786d3d81c6ad80c5e4750ba07c667b9
parent bfa01342ac0315ccecffcfa45f48b4dbdb3fd5da
Author: Eric Butler <ebutler@striven.com>
Date: Fri, 28 Feb 2025 17:34:47 -0500
fixes for image upload placeholder
Diffstat:
3 files changed, 26 insertions(+), 14 deletions(-)
diff --git a/package.json b/package.json
@@ -1,7 +1,7 @@
{
"name": "@striven-erp/striven-editor",
"private": false,
- "version": "3.19.6",
+ "version": "3.19.8",
"description": "The editor used for the Striven ERP system.",
"main": "./dist",
"scripts": {
diff --git a/src/striveneditor.css b/src/striveneditor.css
@@ -197,6 +197,16 @@
fill: #777 !important;
}
+.striven-editor .se-image-uploading {
+ width: 100%; height: 100%; background-color: #eee;display: flex; align-items: center; justify-content: center;
+}
+
+.striven-editor .se-image-uploading::after {
+ content: 'Uploading...';
+ font-size: 16px;
+ color: #777;
+}
+
/** Toolbar **/
.striven-editor .se-toolbar {
diff --git a/src/striveneditor.js b/src/striveneditor.js
@@ -2156,7 +2156,7 @@ export default class StrivenEditor {
if (selection) {
return window.getSelection().getRangeAt(0);
}
- } catch (e) { }
+ } catch (e) {}
}
/**
@@ -2653,7 +2653,7 @@ export default class StrivenEditor {
window.getSelection().removeAllRanges();
window.getSelection().addRange(se.range);
}
- } catch (e) { }
+ } catch (e) {}
}
/**
@@ -3426,8 +3426,7 @@ export default class StrivenEditor {
*/
insertImage(file) {
const se = this;
- se.body.focus();
- se.setRange();
+
return new Promise((resolveImageInsert) => {
const bodyWidth = se.body.offsetWidth;
@@ -3435,18 +3434,18 @@ export default class StrivenEditor {
se._isImageUploading = true;
// Generate a random string to use as the image name
const randomString = 'image-' + Math.random().toString(36);
+
// Insert image with a temporary src
document.execCommand(
'insertHTML',
showUI,
- `<div id="${randomString}" style="width:${se.body.width}px; height: ${se.body.height}px; background-color: #eee;display: flex; align-items: center; justify-content: center;" >
- <svg width="25%" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><title>cloud-upload-outline</title><path d="M6.5 20Q4.22 20 2.61 18.43 1 16.85 1 14.58 1 12.63 2.17 11.1 3.35 9.57 5.25 9.15 5.88 6.85 7.75 5.43 9.63 4 12 4 14.93 4 16.96 6.04 19 8.07 19 11 20.73 11.2 21.86 12.5 23 13.78 23 15.5 23 17.38 21.69 18.69 20.38 20 18.5 20H13Q12.18 20 11.59 19.41 11 18.83 11 18V12.85L9.4 14.4L8 13L12 9L16 13L14.6 14.4L13 12.85V18H18.5Q19.55 18 20.27 17.27 21 16.55 21 15.5 21 14.45 20.27 13.73 19.55 13 18.5 13H17V11Q17 8.93 15.54 7.46 14.08 6 12 6 9.93 6 8.46 7.46 7 8.93 7 11H6.5Q5.05 11 4.03 12.03 3 13.05 3 14.5 3 15.95 4.03 17 5.05 18 6.5 18H9V20M12 13Z" /></svg>
- </div>`
+ `<div id="${randomString}" class="se-image-uploading" ></div>`
);
const tempImg = document.getElementById(randomString);
+
if (!tempImg) {
- console.error("Failed to insert image into the DOM. Make sure the editor body is focused and try again.");
+ console.error('Failed to insert image into the DOM. Make sure the editor body is focused and try again.');
return;
}
@@ -3454,28 +3453,31 @@ export default class StrivenEditor {
.then((imgDataUrl) => {
getImageDimensions(imgDataUrl)
.then(({ width, height }) => {
- const { width: newWidth, height: newHeight } = computeImageDimensions(width, height, bodyWidth);
-
- // Create the image tag to insert
- const imgTag = `<img src="${imgDataUrl}" width="${newWidth}px" alt="" data-data-url="true"/>`;
+ const { width: newWidth } = computeImageDimensions(width, height, bodyWidth);
if (se.options.imageUrl) {
//upload image if imageUrl is provided
se.getImage(imgDataUrl)
.then((imageUrl) => {
// Replace the temporary image with the uploaded image
- tempImg.outerHTML = `<img id="${randomString}" src="${imageUrl}" width="${newWidth}px" alt=""/>`;
+ tempImg.outerHTML = `<img src="${imageUrl}" width="${newWidth}px" alt=""/>`;
+
se._isImageUploading = false;
+
setTimeout(function () {
se.overflow();
}, 100);
})
.catch((err) => {
+ // Create the image tag to insert
+ const imgTag = `<img src="${imgDataUrl}" width="${newWidth}px" alt="" data-data-url="true"/>`;
// Replace the temporary image with the uploaded image
tempImg.outerHTML = imgTag;
se._isImageUploading = false;
});
} else {
+ // Create the image tag to insert
+ const imgTag = `<img src="${imgDataUrl}" width="${newWidth}px" alt="" data-data-url="true"/>`;
// Replace the temporary image with the uploaded image
tempImg.outerHTML = imgTag;
se._isImageUploading = false;