mirror of
https://github.com/vrtmrz/obsidian-livesync.git
synced 2025-12-13 17:55:56 +00:00
### Fixed
- Resolving conflicts of JSON files (and sensibly merging them) is now working fine, again!
- And, failure logs are more informative.
- More robust to release the event listeners on unwatching the local database.
### Refactored
- JSON file conflict resolution dialogue has been rewritten into svelte v5.
- Upgrade eslint.
- Remove unnecessary pragma comments for eslint.
90 lines
2.8 KiB
TypeScript
90 lines
2.8 KiB
TypeScript
import { App, Modal } from "../../deps.ts";
|
|
import { type FilePath, type LoadedEntry } from "../../lib/src/common/types.ts";
|
|
import JsonResolvePane from "./JsonResolvePane.svelte";
|
|
import { waitForSignal } from "../../lib/src/common/utils.ts";
|
|
import { mount, unmount } from "svelte";
|
|
|
|
export class JsonResolveModal extends Modal {
|
|
// result: Array<[number, string]>;
|
|
filename: FilePath;
|
|
callback?: (keepRev?: string, mergedStr?: string) => Promise<void>;
|
|
docs: LoadedEntry[];
|
|
component?: ReturnType<typeof mount>;
|
|
nameA: string;
|
|
nameB: string;
|
|
defaultSelect: string;
|
|
keepOrder: boolean;
|
|
hideLocal: boolean;
|
|
title: string = "Conflicted Setting";
|
|
|
|
constructor(
|
|
app: App,
|
|
filename: FilePath,
|
|
docs: LoadedEntry[],
|
|
callback: (keepRev?: string, mergedStr?: string) => Promise<void>,
|
|
nameA?: string,
|
|
nameB?: string,
|
|
defaultSelect?: string,
|
|
keepOrder?: boolean,
|
|
hideLocal?: boolean,
|
|
title: string = "Conflicted Setting"
|
|
) {
|
|
super(app);
|
|
this.callback = callback;
|
|
this.filename = filename;
|
|
this.docs = docs;
|
|
this.nameA = nameA || "";
|
|
this.nameB = nameB || "";
|
|
this.keepOrder = keepOrder || false;
|
|
this.defaultSelect = defaultSelect || "";
|
|
this.title = title;
|
|
this.hideLocal = hideLocal ?? false;
|
|
void waitForSignal(`cancel-internal-conflict:${filename}`).then(() => this.close());
|
|
}
|
|
|
|
async UICallback(keepRev?: string, mergedStr?: string) {
|
|
if (this.callback) {
|
|
await this.callback(keepRev, mergedStr);
|
|
}
|
|
this.close();
|
|
this.callback = undefined;
|
|
}
|
|
|
|
onOpen() {
|
|
const { contentEl } = this;
|
|
this.titleEl.setText(this.title);
|
|
contentEl.empty();
|
|
|
|
if (this.component == undefined) {
|
|
this.component = mount(JsonResolvePane, {
|
|
target: contentEl,
|
|
props: {
|
|
docs: this.docs,
|
|
filename: this.filename,
|
|
nameA: this.nameA,
|
|
nameB: this.nameB,
|
|
defaultSelect: this.defaultSelect,
|
|
keepOrder: this.keepOrder,
|
|
hideLocal: this.hideLocal,
|
|
callback: (keepRev: string | undefined, mergedStr: string | undefined) =>
|
|
this.UICallback(keepRev, mergedStr),
|
|
},
|
|
});
|
|
}
|
|
return;
|
|
}
|
|
|
|
onClose() {
|
|
const { contentEl } = this;
|
|
contentEl.empty();
|
|
// contentEl.empty();
|
|
if (this.callback != undefined) {
|
|
void this.callback(undefined);
|
|
}
|
|
if (this.component != undefined) {
|
|
void unmount(this.component);
|
|
this.component = undefined;
|
|
}
|
|
}
|
|
}
|