mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-09-22 21:30:44 +02:00
refactor(dialog)!: remove deprecated MessageDialogOptions.okLabel (#3612)
* refactor(dialog)!: remove deprecated MessageDialogOptions.okLabel
Use `buttons: { ok: 'label' }` instead. `ConfirmDialogOptions` (used by
`ask` and `confirm`) still accepts `okLabel` and `cancelLabel`.
* Apply suggestion from @amrbashir
---------
Co-authored-by: Amr Bashir <github@amrbashir.me>
This commit is contained in:
co-authored by
Amr Bashir
parent
1a43e4701d
commit
b2d7c387ef
@@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
"dialog-js": major
|
||||||
|
"dialog": major
|
||||||
|
---
|
||||||
|
|
||||||
|
**Breaking:** Removed the deprecated `okLabel` option of `MessageDialogOptions`. Use `buttons: { ok: 'label' }` instead. `ConfirmDialogOptions` (used by `ask` and `confirm`) still accepts `okLabel` and `cancelLabel`.
|
||||||
@@ -1 +1 @@
|
|||||||
if("__TAURI__"in window){var __TAURI_PLUGIN_DIALOG__=function(n){"use strict";async function e(n,e={},t){return window.__TAURI_INTERNALS__.invoke(n,e,t)}function t(n){if(void 0!==n)return"string"==typeof n?n:"ok"in n&&"cancel"in n?{OkCancelCustom:[n.ok,n.cancel]}:"yes"in n&&"no"in n&&"cancel"in n?{YesNoCancelCustom:[n.yes,n.no,n.cancel]}:"ok"in n?{OkCustom:n.ok}:void 0}async function o(n,o){return await e("plugin:dialog|message",{message:n,title:o?.title,kind:o?.kind,buttons:t(o?.buttons)})}return"function"==typeof SuppressedError&&SuppressedError,n.ask=async function(n,e){const t="string"==typeof e?{title:e}:e,i=t?.okLabel||t?.cancelLabel,a=t?.okLabel??"Yes";return await o(n,{title:t?.title,kind:t?.kind,buttons:i?{ok:a,cancel:t.cancelLabel??"No"}:"YesNo"})===a},n.confirm=async function(n,e){const t="string"==typeof e?{title:e}:e,i=t?.okLabel||t?.cancelLabel,a=t?.okLabel??"Ok";return await o(n,{title:t?.title,kind:t?.kind,buttons:i?{ok:a,cancel:t.cancelLabel??"Cancel"}:"OkCancel"})===a},n.message=async function(n,e){const t="string"==typeof e?{title:e}:e;return t&&!t.buttons&&t.okLabel&&(t.buttons={ok:t.okLabel}),o(n,t)},n.open=async function(n={}){return"object"==typeof n&&Object.freeze(n),await e("plugin:dialog|open",{options:n})},n.save=async function(n={}){return"object"==typeof n&&Object.freeze(n),await e("plugin:dialog|save",{options:n})},n}({});Object.defineProperty(window.__TAURI__,"dialog",{value:__TAURI_PLUGIN_DIALOG__})}
|
if("__TAURI__"in window){var __TAURI_PLUGIN_DIALOG__=function(n){"use strict";async function e(n,e={},t){return window.__TAURI_INTERNALS__.invoke(n,e,t)}function t(n){if(void 0!==n)return"string"==typeof n?n:"ok"in n&&"cancel"in n?{OkCancelCustom:[n.ok,n.cancel]}:"yes"in n&&"no"in n&&"cancel"in n?{YesNoCancelCustom:[n.yes,n.no,n.cancel]}:"ok"in n?{OkCustom:n.ok}:void 0}async function o(n,o){return await e("plugin:dialog|message",{message:n,title:o?.title,kind:o?.kind,buttons:t(o?.buttons)})}return"function"==typeof SuppressedError&&SuppressedError,n.ask=async function(n,e){const t="string"==typeof e?{title:e}:e,i=t?.okLabel||t?.cancelLabel,a=t?.okLabel??"Yes";return await o(n,{title:t?.title,kind:t?.kind,buttons:i?{ok:a,cancel:t.cancelLabel??"No"}:"YesNo"})===a},n.confirm=async function(n,e){const t="string"==typeof e?{title:e}:e,i=t?.okLabel||t?.cancelLabel,a=t?.okLabel??"Ok";return await o(n,{title:t?.title,kind:t?.kind,buttons:i?{ok:a,cancel:t.cancelLabel??"Cancel"}:"OkCancel"})===a},n.message=async function(n,e){return o(n,"string"==typeof e?{title:e}:e)},n.open=async function(n={}){return"object"==typeof n&&Object.freeze(n),await e("plugin:dialog|open",{options:n})},n.save=async function(n={}){return"object"==typeof n&&Object.freeze(n),await e("plugin:dialog|save",{options:n})},n}({});Object.defineProperty(window.__TAURI__,"dialog",{value:__TAURI_PLUGIN_DIALOG__})}
|
||||||
|
|||||||
@@ -228,12 +228,6 @@ interface MessageDialogOptions {
|
|||||||
title?: string
|
title?: string
|
||||||
/** The kind of the dialog. Defaults to `info`. */
|
/** The kind of the dialog. Defaults to `info`. */
|
||||||
kind?: 'info' | 'warning' | 'error'
|
kind?: 'info' | 'warning' | 'error'
|
||||||
/**
|
|
||||||
* The label of the Ok button.
|
|
||||||
*
|
|
||||||
* @deprecated Use {@linkcode MessageDialogOptions.buttons} instead.
|
|
||||||
*/
|
|
||||||
okLabel?: string
|
|
||||||
/**
|
/**
|
||||||
* The buttons of the dialog.
|
* The buttons of the dialog.
|
||||||
*
|
*
|
||||||
@@ -405,10 +399,7 @@ async function save(options: SaveDialogOptions = {}): Promise<string | null> {
|
|||||||
*/
|
*/
|
||||||
export type MessageDialogResult = 'Yes' | 'No' | 'Ok' | 'Cancel' | (string & {})
|
export type MessageDialogResult = 'Yes' | 'No' | 'Ok' | 'Cancel' | (string & {})
|
||||||
|
|
||||||
async function messageCommand(
|
async function messageCommand(message: string, options?: MessageDialogOptions) {
|
||||||
message: string,
|
|
||||||
options?: Omit<MessageDialogOptions, 'okLabel'>
|
|
||||||
) {
|
|
||||||
return await invoke<MessageDialogResult>('plugin:dialog|message', {
|
return await invoke<MessageDialogResult>('plugin:dialog|message', {
|
||||||
message,
|
message,
|
||||||
title: options?.title,
|
title: options?.title,
|
||||||
@@ -439,9 +430,6 @@ async function message(
|
|||||||
options?: string | MessageDialogOptions
|
options?: string | MessageDialogOptions
|
||||||
): Promise<MessageDialogResult> {
|
): Promise<MessageDialogResult> {
|
||||||
const opts = typeof options === 'string' ? { title: options } : options
|
const opts = typeof options === 'string' ? { title: options } : options
|
||||||
if (opts && !opts.buttons && opts.okLabel) {
|
|
||||||
opts.buttons = { ok: opts.okLabel }
|
|
||||||
}
|
|
||||||
return messageCommand(message, opts)
|
return messageCommand(message, opts)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user