Ckeditor5 saveDraft and deleteDraft event
authorCyperghost <olaf_schmitz_1@t-online.de>
Fri, 12 Jan 2024 11:54:03 +0000 (12:54 +0100)
committerOlaf Braun <info@braun-development.de>
Thu, 7 Mar 2024 15:36:30 +0000 (16:36 +0100)
ts/WoltLabSuite/Core/Component/Ckeditor/Autosave.ts
wcfsetup/install/files/js/WoltLabSuite/Core/Component/Ckeditor/Autosave.js

index 505fcc3bf379aa57b6fa60342ea7c9ef71f26287..ef682c60dd5f8f639fe5e7c082f0b2eb72110134 100644 (file)
@@ -14,6 +14,7 @@ import { getStoragePrefix } from "../../Core";
 import { getPhrase } from "../../Language";
 import { escapeHTML } from "../../StringUtil";
 import { dispatchToCkeditor, listenToCkeditor } from "./Event";
+import * as EventHandler from "../../Event/Handler";
 
 type Payload = {
   html: string;
@@ -66,6 +67,10 @@ function getReturnToRestoreDialogOverlay(): HTMLElement {
 export function deleteDraft(identifier: string): void {
   try {
     window.localStorage.removeItem(getLocalStorageKey(identifier));
+
+    EventHandler.fire("com.woltlab.wcf.ckeditor5", "deleteDraft", {
+      identifier,
+    });
   } catch {
     // We cannot do anything meaningful if this fails.
   }
@@ -85,6 +90,11 @@ function saveDraft(identifier: string, html: string): void {
 
   try {
     window.localStorage.setItem(getLocalStorageKey(identifier), JSON.stringify(payload));
+
+    EventHandler.fire("com.woltlab.wcf.ckeditor5", "saveDraft", {
+      identifier,
+      payload,
+    });
   } catch (e) {
     console.warn("Unable to write to the local storage.", e);
   }
index 08145bd58783ad9f6d525389249ab1b3ad76d307..571589e57464045edc0ed3e03696be759cd4da0e 100644 (file)
@@ -8,10 +8,11 @@
  * @since 6.0
  * @woltlabExcludeBundle tiny
  */
-define(["require", "exports", "../../Core", "../../Language", "../../StringUtil", "./Event"], function (require, exports, Core_1, Language_1, StringUtil_1, Event_1) {
+define(["require", "exports", "tslib", "../../Core", "../../Language", "../../StringUtil", "./Event", "../../Event/Handler"], function (require, exports, tslib_1, Core_1, Language_1, StringUtil_1, Event_1, EventHandler) {
     "use strict";
     Object.defineProperty(exports, "__esModule", { value: true });
     exports.initializeAutosave = exports.setupRestoreDraft = exports.deleteDraft = void 0;
+    EventHandler = tslib_1.__importStar(EventHandler);
     function getLocalStorageKey(identifier) {
         return `${(0, Core_1.getStoragePrefix)()}ckeditor5-${identifier}`;
     }
@@ -51,6 +52,9 @@ define(["require", "exports", "../../Core", "../../Language", "../../StringUtil"
     function deleteDraft(identifier) {
         try {
             window.localStorage.removeItem(getLocalStorageKey(identifier));
+            EventHandler.fire("com.woltlab.wcf.ckeditor5", "deleteDraft", {
+                identifier,
+            });
         }
         catch {
             // We cannot do anything meaningful if this fails.
@@ -68,6 +72,10 @@ define(["require", "exports", "../../Core", "../../Language", "../../StringUtil"
         };
         try {
             window.localStorage.setItem(getLocalStorageKey(identifier), JSON.stringify(payload));
+            EventHandler.fire("com.woltlab.wcf.ckeditor5", "saveDraft", {
+                identifier,
+                payload,
+            });
         }
         catch (e) {
             console.warn("Unable to write to the local storage.", e);