Refactor, cleanup
This commit is contained in:
+28
-27
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user