From cb388cc6249339413a77c163845ed7722697676b Mon Sep 17 00:00:00 2001 From: Cyperghost Date: Fri, 12 Jan 2024 12:54:03 +0100 Subject: [PATCH] Ckeditor5 saveDraft and deleteDraft event --- ts/WoltLabSuite/Core/Component/Ckeditor/Autosave.ts | 10 ++++++++++ .../WoltLabSuite/Core/Component/Ckeditor/Autosave.js | 10 +++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/ts/WoltLabSuite/Core/Component/Ckeditor/Autosave.ts b/ts/WoltLabSuite/Core/Component/Ckeditor/Autosave.ts index 505fcc3bf3..ef682c60dd 100644 --- a/ts/WoltLabSuite/Core/Component/Ckeditor/Autosave.ts +++ b/ts/WoltLabSuite/Core/Component/Ckeditor/Autosave.ts @@ -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); } diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Component/Ckeditor/Autosave.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Component/Ckeditor/Autosave.js index 08145bd587..571589e574 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Component/Ckeditor/Autosave.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Component/Ckeditor/Autosave.js @@ -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); -- 2.20.1