import { escapeHTML } from "../../StringUtil";
import { dispatchToCkeditor, listenToCkeditor } from "./Event";
-export type Payload = {
+export type AutosavePayload = {
html: string;
timestamp: number;
};
return;
}
- const payload: Payload = {
+ const payload: AutosavePayload = {
html,
timestamp: Date.now(),
};
}
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));
return;
}
- let payload: Payload | undefined = undefined;
+ let payload: AutosavePayload | undefined = undefined;
try {
payload = JSON.parse(value);
} catch {
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",
SubmitOnEnter = "ckeditor5:submit-on-enter",
UploadAttachment = "ckeditor5:upload-attachment",
UploadMedia = "ckeditor5:upload-media",
- Autosave = "ckeditor5:autosave",
}
type BbcodeEventPayload = {
bbcode: string;
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,
}),
);
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);
});