(chore): Resolving circular references

This commit is contained in:
vorotamoroz
2026-06-10 11:45:41 +01:00
parent e4b36602ec
commit 27e9b68510
14 changed files with 216 additions and 301 deletions
+1 -46
View File
@@ -1,8 +1,7 @@
import { delay, fireAndForget } from "octagonal-wheels/promises";
import { delay } from "octagonal-wheels/promises";
import { __onMissingTranslation } from "@lib/common/i18n";
import { AbstractObsidianModule } from "@/modules/AbstractObsidianModule.ts";
import { LOG_LEVEL_VERBOSE } from "octagonal-wheels/common/logger";
import { eventHub } from "@/common/events";
import { enableTestFunction } from "./devUtil/testUtils.ts";
import { TestPaneView, VIEW_TYPE_TEST } from "./devUtil/TestPaneView.ts";
import { writable } from "svelte/store";
@@ -41,50 +40,6 @@ export class ModuleDev extends AbstractObsidianModule {
__onMissingTranslation((key) => {
void this.onMissingTranslation(key);
});
type STUB = {
toc: Set<string>;
stub: { [key: string]: { [key: string]: Map<string, Record<string, string>> } };
};
eventHub.onEvent("document-stub-created", (detail: STUB) => {
fireAndForget(async () => {
const stub = detail.stub;
const toc = detail.toc;
const stubDocX = Object.entries(stub)
.map(([key, value]) => {
return [
`## ${key}`,
Object.entries(value)
.map(([key2, value2]) => {
return [
`### ${key2}`,
[...value2.entries()].map(([key3, value3]) => {
// return `#### ${key3}` + "\n" + JSON.stringify(value3);
const isObsolete = value3["is_obsolete"] ? " (obsolete)" : "";
const desc = value3["desc"] ?? "";
const key = value3["key"] ? "Setting key: " + value3["key"] + "\n" : "";
return `#### ${key3}${isObsolete}\n${key}${desc}\n`;
}),
].flat();
})
.flat(),
].flat();
})
.flat();
const stubDocMD =
`
| Icon | Description |
| :---: | ----------------------------------------------------------------- |
` +
[...toc.values()].map((e) => `${e}`).join("\n") +
"\n\n" +
stubDocX.join("\n");
await this.core.storageAccess.writeHiddenFileAuto(
this.app.vault.configDir + "/ls-debug/stub-doc.md",
stubDocMD
);
});
});
enableTestFunction(this.plugin);
this.registerView(VIEW_TYPE_TEST, (leaf) => new TestPaneView(leaf, this.plugin, this));
@@ -1,7 +1,7 @@
import { TFile, Modal, App, DIFF_DELETE, DIFF_EQUAL, DIFF_INSERT, diff_match_patch } from "@/deps.ts";
import { getPathFromTFile, isValidPath } from "@/common/utils.ts";
import { decodeBinary, readString } from "@lib/string_and_binary/convert.ts";
import ObsidianLiveSyncPlugin from "@/main.ts";
import type ObsidianLiveSyncPlugin from "@/main.ts";
import type { DocumentID, FilePathWithPrefix, LoadedEntry } from "@lib/common/models/db.type";
import { LOG_LEVEL_INFO, LOG_LEVEL_NOTICE, LOG_LEVEL_VERBOSE } from "@lib/common/logger";
import { Logger } from "@lib/common/logger.ts";
@@ -1,5 +1,5 @@
<script lang="ts">
import ObsidianLiveSyncPlugin from "@/main.ts";
import type ObsidianLiveSyncPlugin from "@/main.ts";
import { onDestroy, onMount } from "svelte";
import type { AnyEntry, FilePathWithPrefix } from "@lib/common/types.ts";
import { getDocData, isAnyNote, isDocContentSame, readAsBlob } from "@lib/common/utils.ts";
@@ -10,7 +10,7 @@ import {
import { unique } from "octagonal-wheels/collection";
import type { ConfigurationItem } from "@lib/common/models/shared.definition.configNames";
import { LEVEL_ADVANCED, LEVEL_POWER_USER, statusDisplay } from "@lib/common/models/shared.definition.configNames";
import { createStub, type ObsidianLiveSyncSettingTab } from "./ObsidianLiveSyncSettingTab.ts";
import type { ObsidianLiveSyncSettingTab } from "./ObsidianLiveSyncSettingTab.ts";
import {
type AllSettingItemKey,
getConfig,
@@ -20,7 +20,7 @@ import {
type AllBooleanItemKey,
} from "./settingConstants.ts";
import { $msg } from "@lib/common/i18n.ts";
import { findAttrFromParent, wrapMemo, type AutoWireOption, type OnUpdateResult } from "./SettingPane.ts";
import { wrapMemo, type AutoWireOption, type OnUpdateResult } from "./SettingPane.ts";
export class LiveSyncSetting extends Setting {
autoWiredComponent?: TextComponent | ToggleComponent | DropdownComponent | ButtonComponent | TextAreaComponent;
@@ -42,31 +42,13 @@ export class LiveSyncSetting extends Setting {
LiveSyncSetting.env.settingComponents.push(this);
}
_createDocStub(key: string, value: string | DocumentFragment) {
DEV: {
const paneName = findAttrFromParent(this.settingEl, "data-pane");
const panelName = findAttrFromParent(this.settingEl, "data-panel");
const itemName =
typeof this.nameBuf == "string" ? this.nameBuf : (this.nameBuf.textContent?.toString() ?? "");
const strValue = typeof value == "string" ? value : (value.textContent?.toString() ?? "");
createStub(itemName, key, strValue, panelName, paneName);
}
}
override setDesc(desc: string | DocumentFragment): this {
this.descBuf = desc;
DEV: {
this._createDocStub("desc", desc);
}
super.setDesc(desc);
return this;
}
override setName(name: string | DocumentFragment): this {
this.nameBuf = name;
DEV: {
this._createDocStub("name", name);
}
super.setName(name);
return this;
}
@@ -85,11 +67,6 @@ export class LiveSyncSetting extends Setting {
if (conf.desc) {
this.setDesc(conf.desc);
}
DEV: {
this._createDocStub("key", key);
if (conf.obsolete) this._createDocStub("is_obsolete", "true");
if (conf.level) this._createDocStub("level", conf.level);
}
this.holdValue = opt?.holdValue || this.holdValue;
this.selfKey = key;
@@ -10,7 +10,7 @@ import { versionNumberString2Number } from "@lib/string_and_binary/convert.ts";
import { Logger } from "@lib/common/logger.ts";
import { checkSyncInfo } from "@lib/pouchdb/negotiation.ts";
import { testCrypt } from "octagonal-wheels/encryption/encryption";
import ObsidianLiveSyncPlugin from "@/main.ts";
import type ObsidianLiveSyncPlugin from "@/main.ts";
import { scheduleTask } from "@/common/utils.ts";
import { LiveSyncCouchDBReplicator } from "@lib/replication/couchdb/LiveSyncReplicator.ts";
import {
@@ -32,8 +32,6 @@ import { JournalSyncMinio } from "@lib/replication/journal/objectstore/JournalSy
import { paneChangeLog } from "./PaneChangeLog.ts";
import {
enableOnly,
findAttrFromParent,
getLevelStr,
setLevelClass,
setStyle,
visibleOnly,
@@ -56,27 +54,6 @@ import { panePatches } from "./PanePatches.ts";
import { paneMaintenance } from "./PaneMaintenance.ts";
import { compatGlobal } from "@lib/common/coreEnvFunctions.ts";
// For creating a document
const toc = new Set<string>();
const stubs = {} as {
[key: string]: { [key: string]: Map<string, Record<string, string>> };
};
export function createStub(name: string, key: string, value: string, panel: string, pane: string) {
DEV: {
if (!(pane in stubs)) {
stubs[pane] = {};
}
if (!(panel in stubs[pane])) {
stubs[pane][panel] = new Map<string, Record<string, string>>();
}
const old = stubs[pane][panel].get(name) ?? {};
stubs[pane][panel].set(name, { ...old, [key]: value });
scheduleTask("update-stub", 100, () => {
eventHub.emitEvent("document-stub-created", { toc: toc, stub: stubs });
});
}
}
export class ObsidianLiveSyncSettingTab extends PluginSettingTab {
plugin: ObsidianLiveSyncPlugin;
get core() {
@@ -711,7 +688,6 @@ export class ObsidianLiveSyncSettingTab extends PluginSettingTab {
visibleOnly(() => this.isNeedRebuildLocal() || this.isNeedRebuildRemote())
);
let paneNo = 0;
const addPane = (
parentEl: HTMLElement,
title: string,
@@ -721,16 +697,6 @@ export class ObsidianLiveSyncSettingTab extends PluginSettingTab {
level?: ConfigLevel
) => {
const el = this.createEl(parentEl, "div", { text: "" });
DEV: {
const mdTitle = `${paneNo++}. ${title}${getLevelStr(level ?? "")}`;
el.setAttribute("data-pane", mdTitle);
toc.add(
`| ${icon} | [${mdTitle}](#${mdTitle
.toLowerCase()
.replace(/ /g, "-")
.replace(/[^\w\s-]/g, "")}) | `
);
}
setLevelClass(el, level);
// TODO: Refactor to use Obsidian's recommended way to create heading.
// eslint-disable-next-line obsidianmd/settings-tab/no-manual-html-headings
@@ -765,7 +731,6 @@ export class ObsidianLiveSyncSettingTab extends PluginSettingTab {
// });
return p;
};
const panelNoMap = {} as { [key: string]: number };
const addPanel = (
parentEl: HTMLElement,
title: string,
@@ -774,15 +739,6 @@ export class ObsidianLiveSyncSettingTab extends PluginSettingTab {
level?: ConfigLevel
) => {
const el = this.createEl(parentEl, "div", { text: "" }, callback, func);
DEV: {
const paneNo = findAttrFromParent(parentEl, "data-pane");
if (!(paneNo in panelNoMap)) {
panelNoMap[paneNo] = 0;
}
panelNoMap[paneNo] += 1;
const panelNo = panelNoMap[paneNo];
el.setAttribute("data-panel", `${panelNo}. ${title}${getLevelStr(level ?? "")}`);
}
setLevelClass(el, level);
this.createEl(el, "h4", { text: title, cls: "sls-setting-panel-title" });
const p = Promise.resolve(el);