mirror of
https://github.com/zadam/trilium.git
synced 2025-11-02 19:36:12 +01:00
chore(client/ts): port widgets/dialogs/confirm
This commit is contained in:
@@ -17,6 +17,7 @@ import { t, initLocale } from "../services/i18n.js";
|
|||||||
import NoteDetailWidget from "../widgets/note_detail.js";
|
import NoteDetailWidget from "../widgets/note_detail.js";
|
||||||
import { ResolveOptions } from "../widgets/dialogs/delete_notes.js";
|
import { ResolveOptions } from "../widgets/dialogs/delete_notes.js";
|
||||||
import { PromptDialogOptions } from "../widgets/dialogs/prompt.js";
|
import { PromptDialogOptions } from "../widgets/dialogs/prompt.js";
|
||||||
|
import { ConfirmWithMessageOptions } from "../widgets/dialogs/confirm.js";
|
||||||
|
|
||||||
interface Layout {
|
interface Layout {
|
||||||
getRootWidget: (appContext: AppContext) => RootWidget;
|
getRootWidget: (appContext: AppContext) => RootWidget;
|
||||||
@@ -34,7 +35,6 @@ export type TriggerData = {
|
|||||||
noteId?: string;
|
noteId?: string;
|
||||||
noteIds?: string[];
|
noteIds?: string[];
|
||||||
messages?: unknown[];
|
messages?: unknown[];
|
||||||
callback?: () => void;
|
|
||||||
} | {
|
} | {
|
||||||
ntxId: string;
|
ntxId: string;
|
||||||
notePath: string;
|
notePath: string;
|
||||||
@@ -50,7 +50,9 @@ export type TriggerData = {
|
|||||||
branchIdsToDelete: string[];
|
branchIdsToDelete: string[];
|
||||||
callback: (value: ResolveOptions) => void;
|
callback: (value: ResolveOptions) => void;
|
||||||
forceDeleteAllClones: boolean;
|
forceDeleteAllClones: boolean;
|
||||||
} | PromptDialogOptions; // For "showPromptDialog"
|
}
|
||||||
|
| PromptDialogOptions // For "showPromptDialog"
|
||||||
|
| ConfirmWithMessageOptions // For "showConfirmDialog"
|
||||||
|
|
||||||
class AppContext extends Component {
|
class AppContext extends Component {
|
||||||
|
|
||||||
|
|||||||
@@ -1,24 +1,26 @@
|
|||||||
import appContext from "../components/app_context.js";
|
import appContext from "../components/app_context.js";
|
||||||
|
import { ConfirmDialogOptions, ConfirmWithMessageOptions } from "../widgets/dialogs/confirm.js";
|
||||||
|
import { PromptDialogOptions } from "../widgets/dialogs/prompt.js";
|
||||||
|
|
||||||
async function info(message) {
|
async function info(message: string) {
|
||||||
return new Promise(res =>
|
return new Promise(res =>
|
||||||
appContext.triggerCommand("showInfoDialog", {message, callback: res}));
|
appContext.triggerCommand("showInfoDialog", {message, callback: res}));
|
||||||
}
|
}
|
||||||
|
|
||||||
async function confirm(message) {
|
async function confirm(message: string) {
|
||||||
return new Promise(res =>
|
return new Promise(res =>
|
||||||
appContext.triggerCommand("showConfirmDialog", {
|
appContext.triggerCommand("showConfirmDialog", <ConfirmWithMessageOptions>{
|
||||||
message,
|
message,
|
||||||
callback: x => res(x.confirmed)
|
callback: (x: false | ConfirmDialogOptions) => res(x && x.confirmed)
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
async function confirmDeleteNoteBoxWithNote(title) {
|
async function confirmDeleteNoteBoxWithNote(title: string) {
|
||||||
return new Promise(res =>
|
return new Promise(res =>
|
||||||
appContext.triggerCommand("showConfirmDeleteNoteBoxWithNoteDialog", {title, callback: res}));
|
appContext.triggerCommand("showConfirmDeleteNoteBoxWithNoteDialog", {title, callback: res}));
|
||||||
}
|
}
|
||||||
|
|
||||||
async function prompt(props) {
|
async function prompt(props: PromptDialogOptions) {
|
||||||
return new Promise(res =>
|
return new Promise(res =>
|
||||||
appContext.triggerCommand("showPromptDialog", {...props, callback: res}));
|
appContext.triggerCommand("showPromptDialog", {...props, callback: res}));
|
||||||
}
|
}
|
||||||
@@ -27,12 +27,16 @@ const TPL = `
|
|||||||
</div>
|
</div>
|
||||||
</div>`;
|
</div>`;
|
||||||
|
|
||||||
export type ConfirmDialogCallback = (val: false | {
|
type ConfirmDialogCallback = (val: false | ConfirmDialogOptions) => void;
|
||||||
|
|
||||||
|
export interface ConfirmDialogOptions {
|
||||||
confirmed: boolean;
|
confirmed: boolean;
|
||||||
isDeleteNoteChecked: boolean
|
isDeleteNoteChecked: boolean
|
||||||
}) => void;
|
}
|
||||||
|
|
||||||
interface ConfirmWithMessageOptions {
|
// For "showConfirmDialog"
|
||||||
|
|
||||||
|
export interface ConfirmWithMessageOptions {
|
||||||
message: string | HTMLElement | JQuery<HTMLElement>;
|
message: string | HTMLElement | JQuery<HTMLElement>;
|
||||||
callback: ConfirmDialogCallback;
|
callback: ConfirmDialogCallback;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user