Refactor, cleanup

This commit is contained in:
Zef Hemel
2025-06-12 20:30:01 +02:00
parent b942ebabad
commit 8d3dc4cc4e
120 changed files with 1139 additions and 1101 deletions
+28 -27
View File
@@ -14,7 +14,8 @@ export class DocumentEditor {
readonly parent: HTMLElement,
readonly client: Client,
readonly saveMethod: (path: string, content: Uint8Array) => void,
) {}
) {
}
async init(extension: string) {
this.extension = extension;
@@ -62,32 +63,6 @@ export class DocumentEditor {
this.iframe.remove();
}
private async waitForSave() {
if (this.savePromise) {
try {
await Promise.race([
this.savePromise.promise,
timeout(2500),
]);
} catch {
this.savePromise.resolve();
this.savePromise = null;
console.log(
"Unable to save content of document editor in 2.5s. Aborting save",
);
}
}
}
private sendMessage(
message: { type: string; internal?: boolean; data?: any },
) {
if (!this.iframe?.contentWindow) return;
message.internal ??= false;
this.iframe.contentWindow.postMessage(message);
}
sendPublicMessage(message: { type: string; data?: any }) {
this.sendMessage(message);
}
@@ -148,6 +123,32 @@ export class DocumentEditor {
});
}
private async waitForSave() {
if (this.savePromise) {
try {
await Promise.race([
this.savePromise.promise,
timeout(2500),
]);
} catch {
this.savePromise.resolve();
this.savePromise = null;
console.log(
"Unable to save content of document editor in 2.5s. Aborting save",
);
}
}
}
private sendMessage(
message: { type: string; internal?: boolean; data?: any },
) {
if (!this.iframe?.contentWindow) return;
message.internal ??= false;
this.iframe.contentWindow.postMessage(message);
}
private async messageHandler(event: any) {
if (event.source !== this.iframe.contentWindow) return;
const response = event.data;