Improve the name of the exported type
authorAlexander Ebert <ebert@woltlab.com>
Mon, 15 Jan 2024 16:54:46 +0000 (17: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
ts/WoltLabSuite/Core/Component/Ckeditor/Event.ts

index c0090c5c1021b218a1be1cc8ac22ca03d2ef2bbb..a68e99fc451a2c133071674a3e48564ec725f990 100644 (file)
@@ -15,7 +15,7 @@ import { getPhrase } from "../../Language";
 import { escapeHTML } from "../../StringUtil";
 import { dispatchToCkeditor, listenToCkeditor } from "./Event";
 
-export type Payload = {
+export type AutosavePayload = {
   html: string;
   timestamp: number;
 };
@@ -78,7 +78,7 @@ function saveDraft(element: HTMLElement, identifier: string, html: string): void
     return;
   }
 
-  const payload: Payload = {
+  const payload: AutosavePayload = {
     html,
     timestamp: Date.now(),
   };
@@ -93,7 +93,7 @@ function saveDraft(element: HTMLElement, identifier: string, html: string): void
 }
 
 export function setupRestoreDraft(editor: CKEditor5.ClassicEditor.ClassicEditor, identifier: string): void {
-  let value: Payload | undefined = undefined;
+  let value: AutosavePayload | undefined = undefined;
 
   try {
     const payload = window.localStorage.getItem(getLocalStorageKey(identifier));
@@ -211,7 +211,7 @@ function removeExpiredDrafts(): void {
         return;
       }
 
-      let payload: Payload | undefined = undefined;
+      let payload: AutosavePayload | undefined = undefined;
       try {
         payload = JSON.parse(value);
       } catch {
index 49814410cbe0805568681d37a5c5170f03c0ca43..8761e8321e2cf9adaaba8b45b9ff4ad1416e7802 100644 (file)
@@ -13,10 +13,11 @@ import type { Features } from "./Configuration";
 import type { InsertAttachmentPayload, RemoveAttachmentPayload, UploadAttachmentEventPayload } from "./Attachment";
 import type { UploadMediaEventPayload } from "./Media";
 import type { InsertQuoteEventPayload } from "./Quote";
+import type { AutosavePayload } from "./Autosave";
 import type { CKEditor5 } from "@woltlab/editor";
-import { Payload } from "WoltLabSuite/Core/Component/Ckeditor/Autosave";
 
 const enum EventNames {
+  Autosave = "ckeditor5:autosave",
   Bbcode = "ckeditor5:bbcode",
   CollectMetaData = "ckeditor5:collect-meta-data",
   Destroy = "ckeditor5:destroy",
@@ -31,7 +32,6 @@ const enum EventNames {
   SubmitOnEnter = "ckeditor5:submit-on-enter",
   UploadAttachment = "ckeditor5:upload-attachment",
   UploadMedia = "ckeditor5:upload-media",
-  Autosave = "ckeditor5:autosave",
 }
 type BbcodeEventPayload = {
   bbcode: string;
@@ -81,9 +81,9 @@ class EventDispatcher {
     this.#element.dispatchEvent(new CustomEvent<void>(EventNames.DiscardRecoveredData));
   }
 
-  autosave(payload: Payload): void {
+  autosave(payload: AutosavePayload): void {
     this.#element.dispatchEvent(
-      new CustomEvent<Payload>(EventNames.Autosave, {
+      new CustomEvent<AutosavePayload>(EventNames.Autosave, {
         detail: payload,
       }),
     );
@@ -312,8 +312,8 @@ class EventListener {
     return this;
   }
 
-  autosave(callback: (payload: Payload) => void): this {
-    this.#element.addEventListener(EventNames.Autosave, (event: CustomEvent<Payload>) => {
+  autosave(callback: (payload: AutosavePayload) => void): this {
+    this.#element.addEventListener(EventNames.Autosave, (event: CustomEvent<AutosavePayload>) => {
       callback(event.detail);
     });