🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

@tauri-apps/plugin-dialog

Package Overview
Dependencies
Maintainers
5
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tauri-apps/plugin-dialog - npm Package Compare versions

Comparing version
2.3.3
to
2.4.0
+26
-2
dist-js/index.cjs

@@ -9,2 +9,25 @@ 'use strict';

/**
* Internal function to convert the buttons to the Rust type.
*/
function buttonsToRust(buttons) {
if (buttons === undefined) {
return undefined;
}
if (typeof buttons === 'string') {
return buttons;
}
else if ('ok' in buttons && 'cancel' in buttons) {
return { OkCancelCustom: [buttons.ok, buttons.cancel] };
}
else if ('yes' in buttons && 'no' in buttons && 'cancel' in buttons) {
return {
YesNoCancelCustom: [buttons.yes, buttons.no, buttons.cancel]
};
}
else if ('ok' in buttons) {
return { OkCustom: buttons.ok };
}
return undefined;
}
/**
* Open a file/directory selection dialog.

@@ -116,7 +139,8 @@ *

const opts = typeof options === 'string' ? { title: options } : options;
await core.invoke('plugin:dialog|message', {
return core.invoke('plugin:dialog|message', {
message: message.toString(),
title: opts?.title?.toString(),
kind: opts?.kind,
okButtonLabel: opts?.okLabel?.toString()
okButtonLabel: opts?.okLabel?.toString(),
buttons: buttonsToRust(opts?.buttons)
});

@@ -123,0 +147,0 @@ }

@@ -72,2 +72,57 @@ /**

/**
* Default buttons for a message dialog.
*
* @since 2.4.0
*/
export type MessageDialogDefaultButtons = 'Ok' | 'OkCancel' | 'YesNo' | 'YesNoCancel';
/** All possible button keys. */
type ButtonKey = 'ok' | 'cancel' | 'yes' | 'no';
/** Ban everything except a set of keys. */
type BanExcept<Allowed extends ButtonKey> = Partial<Record<Exclude<ButtonKey, Allowed>, never>>;
/**
* The Yes, No and Cancel buttons of a message dialog.
*
* @since 2.4.0
*/
export type MessageDialogButtonsYesNoCancel = {
/** The Yes button. */
yes: string;
/** The No button. */
no: string;
/** The Cancel button. */
cancel: string;
} & BanExcept<'yes' | 'no' | 'cancel'>;
/**
* The Ok and Cancel buttons of a message dialog.
*
* @since 2.4.0
*/
export type MessageDialogButtonsOkCancel = {
/** The Ok button. */
ok: string;
/** The Cancel button. */
cancel: string;
} & BanExcept<'ok' | 'cancel'>;
/**
* The Ok button of a message dialog.
*
* @since 2.4.0
*/
export type MessageDialogButtonsOk = {
/** The Ok button. */
ok: string;
} & BanExcept<'ok'>;
/**
* Custom buttons for a message dialog.
*
* @since 2.4.0
*/
export type MessageDialogCustomButtons = MessageDialogButtonsYesNoCancel | MessageDialogButtonsOkCancel | MessageDialogButtonsOk;
/**
* The buttons of a message dialog.
*
* @since 2.4.0
*/
export type MessageDialogButtons = MessageDialogDefaultButtons | MessageDialogCustomButtons;
/**
* @since 2.0.0

@@ -80,4 +135,31 @@ */

kind?: 'info' | 'warning' | 'error';
/** The label of the confirm button. */
/**
* The label of the Ok button.
*
* @deprecated Use {@linkcode MessageDialogOptions.buttons} instead.
*/
okLabel?: string;
/**
* The buttons of the dialog.
*
* @example
*
* ```ts
* // Use system default buttons texts
* await message('Hello World!', { buttons: 'Ok' })
* await message('Hello World!', { buttons: 'OkCancel' })
*
* // Or with custom button texts
* await message('Hello World!', { buttons: { ok: 'Yes!' } })
* await message('Take on the task?', {
* buttons: { ok: 'Accept', cancel: 'Cancel' }
* })
* await message('Show the file content?', {
* buttons: { yes: 'Show content', no: 'Show in folder', cancel: 'Cancel' }
* })
* ```
*
* @since 2.4.0
*/
buttons?: MessageDialogButtons;
}

@@ -174,2 +256,11 @@ interface ConfirmDialogOptions {

/**
* The result of a message dialog.
*
* The result is a string if the dialog has custom buttons,
* otherwise it is one of the default buttons.
*
* @since 2.4.0
*/
export type MessageDialogResult = 'Yes' | 'No' | 'Ok' | 'Cancel' | (string & {});
/**
* Shows a message dialog with an `Ok` button.

@@ -191,3 +282,3 @@ * @example

*/
declare function message(message: string, options?: string | MessageDialogOptions): Promise<void>;
declare function message(message: string, options?: string | MessageDialogOptions): Promise<MessageDialogResult>;
/**

@@ -194,0 +285,0 @@ * Shows a question dialog with `Yes` and `No` buttons.

@@ -7,2 +7,25 @@ import { invoke } from '@tauri-apps/api/core';

/**
* Internal function to convert the buttons to the Rust type.
*/
function buttonsToRust(buttons) {
if (buttons === undefined) {
return undefined;
}
if (typeof buttons === 'string') {
return buttons;
}
else if ('ok' in buttons && 'cancel' in buttons) {
return { OkCancelCustom: [buttons.ok, buttons.cancel] };
}
else if ('yes' in buttons && 'no' in buttons && 'cancel' in buttons) {
return {
YesNoCancelCustom: [buttons.yes, buttons.no, buttons.cancel]
};
}
else if ('ok' in buttons) {
return { OkCustom: buttons.ok };
}
return undefined;
}
/**
* Open a file/directory selection dialog.

@@ -114,7 +137,8 @@ *

const opts = typeof options === 'string' ? { title: options } : options;
await invoke('plugin:dialog|message', {
return invoke('plugin:dialog|message', {
message: message.toString(),
title: opts?.title?.toString(),
kind: opts?.kind,
okButtonLabel: opts?.okLabel?.toString()
okButtonLabel: opts?.okLabel?.toString(),
buttons: buttonsToRust(opts?.buttons)
});

@@ -121,0 +145,0 @@ }

+1
-1
{
"name": "@tauri-apps/plugin-dialog",
"version": "2.3.3",
"version": "2.4.0",
"license": "MIT OR Apache-2.0",

@@ -5,0 +5,0 @@ "authors": [