mirror of
https://github.com/vrtmrz/obsidian-livesync.git
synced 2026-08-29 06:47:06 +00:00
Complete Commonlib rc.6 integration and setup workflows
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
<script lang="ts">
|
||||
import { translateIfAvailable as translate } from "@vrtmrz/livesync-commonlib/compat/common/i18n";
|
||||
import { translateIfAvailable as translate } from "@/common/translation";
|
||||
|
||||
type Props = {
|
||||
title: string;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script lang="ts">
|
||||
import { translateIfAvailable as translate } from "@vrtmrz/livesync-commonlib/compat/common/i18n";
|
||||
import { translateIfAvailable as translate } from "@/common/translation";
|
||||
import { fireAndForget } from "octagonal-wheels/promises";
|
||||
|
||||
type Props = {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { onMount, tick } from "svelte";
|
||||
import { translateIfAvailable as translate } from "@vrtmrz/livesync-commonlib/compat/common/i18n";
|
||||
import { translateIfAvailable as translate } from "@/common/translation";
|
||||
import { getDialogContext } from "@/modules/services/LiveSyncUI/svelteDialog";
|
||||
import { _activeDocument } from "@vrtmrz/livesync-commonlib/compat/common/coreEnvFunctions";
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script lang="ts">
|
||||
import { translateIfAvailable as translate } from "@vrtmrz/livesync-commonlib/compat/common/i18n";
|
||||
import { translateIfAvailable as translate } from "@/common/translation";
|
||||
|
||||
type Props = {
|
||||
title?: string;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script lang="ts">
|
||||
import { translateIfAvailable as translate } from "@vrtmrz/livesync-commonlib/compat/common/i18n";
|
||||
import { translateIfAvailable as translate } from "@/common/translation";
|
||||
|
||||
type Props = {
|
||||
children?: () => any;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script lang="ts">
|
||||
import { translateIfAvailable as translate } from "@vrtmrz/livesync-commonlib/compat/common/i18n";
|
||||
import { translateIfAvailable as translate } from "@/common/translation";
|
||||
|
||||
type SignalWord = "danger" | "warning" | "caution" | "notice";
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script lang="ts">
|
||||
import { translateIfAvailable as translate } from "@vrtmrz/livesync-commonlib/compat/common/i18n";
|
||||
import { translateIfAvailable as translate } from "@/common/translation";
|
||||
|
||||
type Props = {
|
||||
label: string;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { getContext } from "svelte";
|
||||
import { translateIfAvailable as translate } from "@vrtmrz/livesync-commonlib/compat/common/i18n";
|
||||
import { translateIfAvailable as translate } from "@/common/translation";
|
||||
|
||||
type Props = {
|
||||
title: string;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script lang="ts">
|
||||
import { translateIfAvailable as translate } from "@vrtmrz/livesync-commonlib/compat/common/i18n";
|
||||
import { translateIfAvailable as translate } from "@/common/translation";
|
||||
|
||||
type Props = {
|
||||
value: string;
|
||||
|
||||
@@ -1,14 +1,11 @@
|
||||
import { type App, type Plugin, Notice } from "@/deps";
|
||||
import { scheduleTask, memoIfNotExist, memoObject, retrieveMemoObject, disposeMemoObject } from "@/common/utils";
|
||||
import { EVENT_PLUGIN_UNLOADED } from "@/common/events";
|
||||
import { $msg } from "@vrtmrz/livesync-commonlib/compat/common/i18n";
|
||||
import { $msg } from "@/common/translation";
|
||||
import type { Confirm, ConfirmActionLayout } from "@vrtmrz/livesync-commonlib/compat/interfaces/Confirm";
|
||||
import { confirmAction, pickOne, promptPassword, promptText } from "@vrtmrz/obsidian-plugin-kit";
|
||||
import type { ObsidianServiceContext } from "@/modules/services/ObsidianServiceContext";
|
||||
import {
|
||||
confirmWithMessageWithWideButton,
|
||||
confirmWithMessage as confirmWithLegacyMessage,
|
||||
} from "@/modules/coreObsidian/UILib/dialogs";
|
||||
import { confirmWithMessageWithWideButton } from "@/modules/coreObsidian/UILib/dialogs";
|
||||
|
||||
export class ObsidianConfirm<T extends ObsidianServiceContext = ObsidianServiceContext> implements Confirm {
|
||||
private _context: T;
|
||||
@@ -49,6 +46,7 @@ export class ObsidianConfirm<T extends ObsidianServiceContext = ObsidianServiceC
|
||||
yes: $msg("moduleInputUIObsidian.optionYes"),
|
||||
no: $msg("moduleInputUIObsidian.optionNo"),
|
||||
},
|
||||
actionLayout: "vertical",
|
||||
defaultAction: "no",
|
||||
sourcePath: "/",
|
||||
},
|
||||
@@ -92,6 +90,7 @@ export class ObsidianConfirm<T extends ObsidianServiceContext = ObsidianServiceC
|
||||
message,
|
||||
actions: ["Yes", "No"] as const,
|
||||
labels: { Yes: yesLabel, No: noLabel },
|
||||
actionLayout: "vertical",
|
||||
defaultAction: opt.defaultOption === "Yes" ? "Yes" : "No",
|
||||
sourcePath: "/",
|
||||
},
|
||||
@@ -136,6 +135,7 @@ export class ObsidianConfirm<T extends ObsidianServiceContext = ObsidianServiceC
|
||||
title: opt.title || defaultTitle,
|
||||
message,
|
||||
actions: buttons,
|
||||
actionLayout: "vertical",
|
||||
defaultAction: opt.defaultAction,
|
||||
sourcePath: "/",
|
||||
},
|
||||
@@ -210,7 +210,7 @@ export class ObsidianConfirm<T extends ObsidianServiceContext = ObsidianServiceC
|
||||
actionLayout?: ConfirmActionLayout
|
||||
): Promise<(typeof buttons)[number] | false> {
|
||||
if (this.hasCountdown(timeout)) {
|
||||
return confirmWithLegacyMessage(this._plugin, title, contentMd, buttons, defaultAction, timeout);
|
||||
return confirmWithMessageWithWideButton(this._plugin, title, contentMd, buttons, defaultAction, timeout);
|
||||
}
|
||||
const result = await confirmAction(
|
||||
this._app,
|
||||
@@ -220,7 +220,7 @@ export class ObsidianConfirm<T extends ObsidianServiceContext = ObsidianServiceC
|
||||
actions: buttons,
|
||||
defaultAction,
|
||||
sourcePath: "/",
|
||||
...(actionLayout === undefined ? {} : { actionLayout }),
|
||||
actionLayout: actionLayout ?? "vertical",
|
||||
},
|
||||
this.dialogueLifecycle
|
||||
);
|
||||
|
||||
@@ -93,6 +93,7 @@ describe("ObsidianConfirm Fancy Kit adapter", () => {
|
||||
expect.objectContaining({
|
||||
message: "Continue?",
|
||||
actions: ["yes", "no"],
|
||||
actionLayout: "vertical",
|
||||
defaultAction: "no",
|
||||
}),
|
||||
{ signal: expect.any(AbortSignal) }
|
||||
@@ -109,15 +110,14 @@ describe("ObsidianConfirm Fancy Kit adapter", () => {
|
||||
expect(mocks.legacyAskSelectString).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("uses Kit for untimed action dialogues and retains the legacy countdown path", async () => {
|
||||
it("keeps untimed and countdown action dialogues vertically stacked", async () => {
|
||||
const { confirm, app, plugin } = createConfirm();
|
||||
mocks.confirmAction.mockResolvedValueOnce("Apply").mockResolvedValueOnce("Yes");
|
||||
mocks.legacyConfirm.mockResolvedValueOnce("Cancel");
|
||||
mocks.legacyWideConfirm.mockResolvedValueOnce("No");
|
||||
mocks.legacyWideConfirm.mockResolvedValueOnce("Cancel").mockResolvedValueOnce("No");
|
||||
|
||||
await expect(
|
||||
confirm.confirmWithMessage("Review", "**Apply?**", ["Apply", "Cancel"], "Cancel", undefined, "vertical")
|
||||
).resolves.toBe("Apply");
|
||||
await expect(confirm.confirmWithMessage("Review", "**Apply?**", ["Apply", "Cancel"], "Cancel")).resolves.toBe(
|
||||
"Apply"
|
||||
);
|
||||
await expect(confirm.askYesNoDialog("Continue?", { title: "Question", defaultOption: "Yes" })).resolves.toBe(
|
||||
"yes"
|
||||
);
|
||||
@@ -139,8 +139,29 @@ describe("ObsidianConfirm Fancy Kit adapter", () => {
|
||||
},
|
||||
{ signal: expect.any(AbortSignal) }
|
||||
);
|
||||
expect(mocks.legacyConfirm).toHaveBeenCalledWith(plugin, "Timed", "Wait", ["Apply", "Cancel"], "Cancel", 30);
|
||||
expect(mocks.legacyWideConfirm).toHaveBeenCalledWith(
|
||||
expect(mocks.confirmAction).toHaveBeenNthCalledWith(
|
||||
2,
|
||||
app,
|
||||
expect.objectContaining({
|
||||
title: "Question",
|
||||
message: "Continue?",
|
||||
actions: ["Yes", "No"],
|
||||
actionLayout: "vertical",
|
||||
defaultAction: "Yes",
|
||||
}),
|
||||
{ signal: expect.any(AbortSignal) }
|
||||
);
|
||||
expect(mocks.legacyWideConfirm).toHaveBeenNthCalledWith(
|
||||
1,
|
||||
plugin,
|
||||
"Timed",
|
||||
"Wait",
|
||||
["Apply", "Cancel"],
|
||||
"Cancel",
|
||||
30
|
||||
);
|
||||
expect(mocks.legacyWideConfirm).toHaveBeenNthCalledWith(
|
||||
2,
|
||||
plugin,
|
||||
expect.any(String),
|
||||
"Timed?",
|
||||
@@ -148,6 +169,7 @@ describe("ObsidianConfirm Fancy Kit adapter", () => {
|
||||
expect.any(String),
|
||||
10
|
||||
);
|
||||
expect(mocks.legacyConfirm).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("uses Kit for untimed multi-action selection and keeps timed wide actions on the countdown dialogue", async () => {
|
||||
@@ -176,6 +198,7 @@ describe("ObsidianConfirm Fancy Kit adapter", () => {
|
||||
title: "Next step",
|
||||
message: "Choose the next step",
|
||||
actions,
|
||||
actionLayout: "vertical",
|
||||
defaultAction: "Review later",
|
||||
sourcePath: "/",
|
||||
},
|
||||
|
||||
@@ -26,6 +26,7 @@ import { createScreenWakeLockManager } from "octagonal-wheels/browser/wakeLock";
|
||||
import { PouchDB } from "@vrtmrz/livesync-commonlib/compat/pouchdb/pouchdb-browser";
|
||||
import { OpenKeyValueDatabase } from "@/common/KeyValueDB";
|
||||
import { ObsidianNoticeGroupManager } from "./ObsidianNoticeGroups";
|
||||
import { setLang } from "@/common/translation";
|
||||
|
||||
// InjectableServiceHub
|
||||
|
||||
@@ -42,6 +43,7 @@ export class ObsidianServiceHub extends InjectableServiceHub<ObsidianServiceCont
|
||||
|
||||
const setting = new ObsidianSettingService(context, {
|
||||
APIService: API,
|
||||
onDisplayLanguageChanged: setLang,
|
||||
});
|
||||
const appLifecycle = new ObsidianAppLifecycleService(context, {
|
||||
settingService: setting,
|
||||
|
||||
Reference in New Issue
Block a user