From c2e08599dc57efa8b5e26690dd24d0f0f82bcf75 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Mon, 15 Jan 2024 17:54:46 +0100 Subject: [PATCH] Improve the name of the exported type --- ts/WoltLabSuite/Core/Component/Ckeditor/Autosave.ts | 8 ++++---- ts/WoltLabSuite/Core/Component/Ckeditor/Event.ts | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/ts/WoltLabSuite/Core/Component/Ckeditor/Autosave.ts b/ts/WoltLabSuite/Core/Component/Ckeditor/Autosave.ts index c0090c5c10..a68e99fc45 100644 --- a/ts/WoltLabSuite/Core/Component/Ckeditor/Autosave.ts +++ b/ts/WoltLabSuite/Core/Component/Ckeditor/Autosave.ts @@ -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 { diff --git a/ts/WoltLabSuite/Core/Component/Ckeditor/Event.ts b/ts/WoltLabSuite/Core/Component/Ckeditor/Event.ts index 49814410cb..8761e8321e 100644 --- a/ts/WoltLabSuite/Core/Component/Ckeditor/Event.ts +++ b/ts/WoltLabSuite/Core/Component/Ckeditor/Event.ts @@ -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(EventNames.DiscardRecoveredData)); } - autosave(payload: Payload): void { + autosave(payload: AutosavePayload): void { this.#element.dispatchEvent( - new CustomEvent(EventNames.Autosave, { + new CustomEvent(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) => { + autosave(callback: (payload: AutosavePayload) => void): this { + this.#element.addEventListener(EventNames.Autosave, (event: CustomEvent) => { callback(event.detail); }); -- 2.20.1