Quellcode durchsuchen

Fix TinyMCE Enter key bug (text disappearing) and merge v1.4.0 → v1.5.3

Corentin NELHOMME vor 1 Jahr
Ursprung
Commit
2e6341cb49
1 geänderte Dateien mit 43 neuen und 12 gelöschten Zeilen
  1. 43 12
      index.js

+ 43 - 12
index.js

@@ -10,11 +10,13 @@
  * - 2025/05/31 - V1.3.0 - E.Podvin - add redirections to dashboard and help pages
  * - 2025/05/31 - V1.3.0 - E.Podvin - add redirections to dashboard and help pages
  * - 2025/06/02 - V1.3.1 - E.Podvin - call newsiteeditor/image POST
  * - 2025/06/02 - V1.3.1 - E.Podvin - call newsiteeditor/image POST
  * - 2025/06/02 - V1.3.2 - E.Podvin - fix toggle on hover when we leave nse
  * - 2025/06/02 - V1.3.2 - E.Podvin - fix toggle on hover when we leave nse
- * - 2025/06/03 - V1.4.0 - C.NELHOMME - Added videoEditor, posterEditor, refactor upload function, implements Kserver
- * - 2025/06/04 - V1.4.1 - C.NELHOMME - Refactor fntManager using Modal class, add some commentary, renaming fntManager to newDeleteManager, renaming variable startingWith RG_ to normal variable
+ * - 2025/06/03 - V1.4.0 - E.Podvin - can process image element that are not embeded in img but in a background for example
+ * - 2025/06/03 - V1.4.1 - C.NELHOMME - Added videoEditor, posterEditor, refactor upload function, implements Kserver
+ * - 2025/06/04 - V1.4.2 - C.NELHOMME - Refactor fntManager using Modal class, add some commentary, renaming fntManager to newDeleteManager, renaming variable startingWith RG_ to normal variable
  * - 2025/06/04 - V1.5.0 - C.NELHOMME - Implement SmartButton and abstract class BaseHoverManager and Refactor newDeleteManager and newTranslateManager and moving her into NewSiteEditor function()
  * - 2025/06/04 - V1.5.0 - C.NELHOMME - Implement SmartButton and abstract class BaseHoverManager and Refactor newDeleteManager and newTranslateManager and moving her into NewSiteEditor function()
  * - 2025/06/11 - V1.5.1 - C.NELHOMME - Implement setCreateError to show error in modal, added page smartButton for selecting id of the currznt page 
  * - 2025/06/11 - V1.5.1 - C.NELHOMME - Implement setCreateError to show error in modal, added page smartButton for selecting id of the currznt page 
  * - 2025/06/12 - V.1.5.2 - C.NELHOMME (Stable test with Hugo) - Fix multiple request to mistral now one by one, when translate/delete is open all the tinymce is now closed, remove poster from video
  * - 2025/06/12 - V.1.5.2 - C.NELHOMME (Stable test with Hugo) - Fix multiple request to mistral now one by one, when translate/delete is open all the tinymce is now closed, remove poster from video
+ * - 2025/06/13 - V.1.5.3 - C.NELHOMME & E.Podvin - Fix TinyMCE Enter key bug (text disappearing) and merge v1.4.0 → v1.5.3
  * @copyright Intersel 2022-2025
  * @copyright Intersel 2022-2025
  *
  *
  *
  *
@@ -69,6 +71,11 @@ class Modal {
         this.isOpen = true;
         this.isOpen = true;
     }
     }
 
 
+    /**
+     * Set text error in your modal
+     * @param {String} text - The text error you want to show 
+     * @returns {Void}
+     */
     setError(text) {
     setError(text) {
         const nseHeader = this.modal.querySelector('.nseHeader');
         const nseHeader = this.modal.querySelector('.nseHeader');
         const nseError = nseHeader?.querySelector('.alert');
         const nseError = nseHeader?.querySelector('.alert');
@@ -98,6 +105,9 @@ class Modal {
         return this.isOpen;
         return this.isOpen;
     }
     }
 
 
+    /**
+     * @returns {HTMLElement} - Get the the html element modal
+     */
     getModal() {
     getModal() {
         return this.modal;
         return this.modal;
     }
     }
@@ -134,6 +144,11 @@ class SmartButton {
         this.isVisible = false;
         this.isVisible = false;
     }
     }
 
 
+    /**
+     * Move the smartButton to the target position
+     * @param {number} x - X Position
+     * @param {number} y - Y position
+     */
     moveTo(x, y) {
     moveTo(x, y) {
         Object.assign(this.button.style, {
         Object.assign(this.button.style, {
             left: `${x}px`,
             left: `${x}px`,
@@ -203,7 +218,7 @@ var NEWSITEEDITOR = (function () {
         if (editModeOn &&
         if (editModeOn &&
             (
             (
                 who.innerText.trim() === "" ||
                 who.innerText.trim() === "" ||
-                who.innerHTML.includes('<br data-mce-bogus="1">')
+                (who.innerHTML.includes('<br data-mce-bogus="1">') && who.textContent === "")
             )
             )
         )
         )
 		{
 		{
@@ -1240,19 +1255,32 @@ var NEWSITEEDITOR = (function () {
         if (el.naturalHeight === 0) {
         if (el.naturalHeight === 0) {
             current.aspectRatio = 1;
             current.aspectRatio = 1;
         } else {
         } else {
-            current.aspectRatio = el.naturalWidth / el.naturalHeight;
-        }
+			if (el.naturalWidth)
+			{
+				current.aspectRatio = el.naturalWidth / el.naturalHeight;
+			}
+			else
+			{
+				const rect = el.getBoundingClientRect();
+				current.aspectRatio = rect.height && (rect.width / rect.height);
+			}
+		}
 
 
         current.element = el;
         current.element = el;
         current.lang = el.getAttribute("data-lang");
         current.lang = el.getAttribute("data-lang");
         current.dataRessourceId = el.getAttribute("data-resource-id");
         current.dataRessourceId = el.getAttribute("data-resource-id");
         current.customFields = {
         current.customFields = {
             src: el.getAttribute("data-img-src"),
             src: el.getAttribute("data-img-src"),
+            tv: el.getAttribute("data-tv"),
             alt: el.getAttribute("data-alt"),
             alt: el.getAttribute("data-alt"),
         };
         };
         uppyReset(imageUppy);
         uppyReset(imageUppy);
 
 
-        const blob = await fetch(el.src).then((res) => res.blob());
+		if (!el.src) el.src = current.customFields.src;
+		let blob = '';
+		if (el.src)
+			blob = await fetch(el.src).then((res) => res.blob());
+
         const ts = new Date().toISOString().replace(/[-:.]/g, "").replace("Z", "");
         const ts = new Date().toISOString().replace(/[-:.]/g, "").replace("Z", "");
 
 
         imageUppy.addFile({
         imageUppy.addFile({
@@ -1298,7 +1326,6 @@ var NEWSITEEDITOR = (function () {
                 restrictions: {
                 restrictions: {
                     maxNumberOfFiles: 1,
                     maxNumberOfFiles: 1,
                     allowedFileTypes: acceptedImageTypes,
                     allowedFileTypes: acceptedImageTypes,
-                    autoProceed: true,
                 },
                 },
             });
             });
 
 
@@ -1314,7 +1341,6 @@ var NEWSITEEDITOR = (function () {
                 target: Dashboard,
                 target: Dashboard,
                 cropperOptions: {
                 cropperOptions: {
                     viewMode: 1,
                     viewMode: 1,
-                    autoCropArea: 0.8,
                 },
                 },
                 actions: {
                 actions: {
                     revert: false,
                     revert: false,
@@ -1423,6 +1449,9 @@ var NEWSITEEDITOR = (function () {
                     const [file] = imageUppy.getFiles();
                     const [file] = imageUppy.getFiles();
                     const params = new URLSearchParams();
                     const params = new URLSearchParams();
 
 
+                    console.log(file)
+
+
                     params.append("urlvalue", current.dataRessourceId);
                     params.append("urlvalue", current.dataRessourceId);
                     params.append("alt", document.getElementById("altText").value);
                     params.append("alt", document.getElementById("altText").value);
 
 
@@ -1433,6 +1462,10 @@ var NEWSITEEDITOR = (function () {
                         params.append("srcField", current.customFields.src);
                         params.append("srcField", current.customFields.src);
                     }
                     }
 
 
+                    if (current.customFields?.tv) {
+						params.append("tvField", current.customFields.tv);
+					}
+
                     if (file && !file.meta.fromServer) {
                     if (file && !file.meta.fromServer) {
                         try {
                         try {
                             document.getElementById("saveImage").innerText =
                             document.getElementById("saveImage").innerText =
@@ -1453,7 +1486,7 @@ var NEWSITEEDITOR = (function () {
                         }
                         }
                     }
                     }
 
 
-                    if (file && file.meta.updateImage && file.meta.dir) {
+                    if (file && file.meta.updateImage && file.meta.dir && file.meta.fromServer) {
                         params.append("imageSrc", file.meta.dir + "/" + file.name);
                         params.append("imageSrc", file.meta.dir + "/" + file.name);
                     }
                     }
 
 
@@ -1581,7 +1614,6 @@ var NEWSITEEDITOR = (function () {
                 cropper = new Cropper(cropperImage, {
                 cropper = new Cropper(cropperImage, {
                     viewMode: 1,
                     viewMode: 1,
                     aspectRatio: current.aspectRatio,
                     aspectRatio: current.aspectRatio,
-                    autoCropArea: 0.8,
                 });
                 });
             };
             };
             reader.readAsDataURL(file.data);
             reader.readAsDataURL(file.data);
@@ -1923,7 +1955,6 @@ var NEWSITEEDITOR = (function () {
                 if (file.meta.fromServer) {
                 if (file.meta.fromServer) {
                     return;
                     return;
                 }
                 }
-
                 uppy.getPlugin("Dashboard").openFileEditor(file);
                 uppy.getPlugin("Dashboard").openFileEditor(file);
                 return false;
                 return false;
             });
             });
@@ -2351,4 +2382,4 @@ var NEWSITEEDITOR = (function () {
     // API.get_array = get_array;
     // API.get_array = get_array;
 
 
     return API;
     return API;
-})();
+})();