@tauri-apps/plugin-dialog 2.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.spdx +20 -0
- package/README.md +74 -0
- package/dist-js/index.d.ts +188 -0
- package/dist-js/index.min.js +175 -0
- package/dist-js/index.mjs +175 -0
- package/package.json +32 -0
package/LICENSE.spdx
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
SPDXVersion: SPDX-2.1
|
|
2
|
+
DataLicense: CC0-1.0
|
|
3
|
+
PackageName: tauri
|
|
4
|
+
DataFormat: SPDXRef-1
|
|
5
|
+
PackageSupplier: Organization: The Tauri Programme in the Commons Conservancy
|
|
6
|
+
PackageHomePage: https://tauri.app
|
|
7
|
+
PackageLicenseDeclared: Apache-2.0
|
|
8
|
+
PackageLicenseDeclared: MIT
|
|
9
|
+
PackageCopyrightText: 2019-2022, The Tauri Programme in the Commons Conservancy
|
|
10
|
+
PackageSummary: <text>Tauri is a rust project that enables developers to make secure
|
|
11
|
+
and small desktop applications using a web frontend.
|
|
12
|
+
</text>
|
|
13
|
+
PackageComment: <text>The package includes the following libraries; see
|
|
14
|
+
Relationship information.
|
|
15
|
+
</text>
|
|
16
|
+
Created: 2019-05-20T09:00:00Z
|
|
17
|
+
PackageDownloadLocation: git://github.com/tauri-apps/tauri
|
|
18
|
+
PackageDownloadLocation: git+https://github.com/tauri-apps/tauri.git
|
|
19
|
+
PackageDownloadLocation: git+ssh://github.com/tauri-apps/tauri.git
|
|
20
|
+
Creator: Person: Daniel Thompson-Yvetot
|
package/README.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Dialog
|
|
2
|
+
|
|
3
|
+
Native system dialogs for opening and saving files along with message dialogs.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
_This plugin requires a Rust version of at least **1.65**_
|
|
8
|
+
|
|
9
|
+
There are three general methods of installation that we can recommend.
|
|
10
|
+
|
|
11
|
+
1. Use crates.io and npm (easiest, and requires you to trust that our publishing pipeline worked)
|
|
12
|
+
2. Pull sources directly from Github using git tags / revision hashes (most secure)
|
|
13
|
+
3. Git submodule install this repo in your tauri project and then use file protocol to ingest the source (most secure, but inconvenient to use)
|
|
14
|
+
|
|
15
|
+
Install the Core plugin by adding the following to your `Cargo.toml` file:
|
|
16
|
+
|
|
17
|
+
`src-tauri/Cargo.toml`
|
|
18
|
+
|
|
19
|
+
```toml
|
|
20
|
+
[dependencies]
|
|
21
|
+
tauri-plugin-dialog = "2.0.0-alpha"
|
|
22
|
+
# alternatively with Git:
|
|
23
|
+
tauri-plugin-dialog = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v2" }
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
You can install the JavaScript Guest bindings using your preferred JavaScript package manager:
|
|
27
|
+
|
|
28
|
+
> Note: Since most JavaScript package managers are unable to install packages from git monorepos we provide read-only mirrors of each plugin. This makes installation option 2 more ergonomic to use.
|
|
29
|
+
|
|
30
|
+
```sh
|
|
31
|
+
pnpm add @tauri-apps/plugin-dialog
|
|
32
|
+
# or
|
|
33
|
+
npm add @tauri-apps/plugin-dialog
|
|
34
|
+
# or
|
|
35
|
+
yarn add @tauri-apps/plugin-dialog
|
|
36
|
+
|
|
37
|
+
# alternatively with Git:
|
|
38
|
+
pnpm add https://github.com/tauri-apps/tauri-plugin-dialog#v2
|
|
39
|
+
# or
|
|
40
|
+
npm add https://github.com/tauri-apps/tauri-plugin-dialog#v2
|
|
41
|
+
# or
|
|
42
|
+
yarn add https://github.com/tauri-apps/tauri-plugin-dialog#v2
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Usage
|
|
46
|
+
|
|
47
|
+
First you need to register the core plugin with Tauri:
|
|
48
|
+
|
|
49
|
+
`src-tauri/src/main.rs`
|
|
50
|
+
|
|
51
|
+
```rust
|
|
52
|
+
fn main() {
|
|
53
|
+
tauri::Builder::default()
|
|
54
|
+
.plugin(tauri_plugin_dialog::init())
|
|
55
|
+
.run(tauri::generate_context!())
|
|
56
|
+
.expect("error while running tauri application");
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Afterwards all the plugin's APIs are available through the JavaScript guest bindings:
|
|
61
|
+
|
|
62
|
+
```javascript
|
|
63
|
+
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Contributing
|
|
67
|
+
|
|
68
|
+
PRs accepted. Please make sure to read the Contributing Guide before making a pull request.
|
|
69
|
+
|
|
70
|
+
## License
|
|
71
|
+
|
|
72
|
+
Code: (c) 2015 - Present - The Tauri Programme within The Commons Conservancy.
|
|
73
|
+
|
|
74
|
+
MIT or MIT/Apache 2.0 where applicable.
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
declare global {
|
|
2
|
+
interface Window {
|
|
3
|
+
__TAURI_INVOKE__: <T>(cmd: string, args?: unknown) => Promise<T>;
|
|
4
|
+
}
|
|
5
|
+
}
|
|
6
|
+
interface FileResponse {
|
|
7
|
+
base64Data?: string;
|
|
8
|
+
duration?: number;
|
|
9
|
+
height?: number;
|
|
10
|
+
width?: number;
|
|
11
|
+
mimeType?: string;
|
|
12
|
+
modifiedAt?: number;
|
|
13
|
+
name?: string;
|
|
14
|
+
path: string;
|
|
15
|
+
size: number;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Extension filters for the file dialog.
|
|
19
|
+
*
|
|
20
|
+
* @since 2.0.0
|
|
21
|
+
*/
|
|
22
|
+
interface DialogFilter {
|
|
23
|
+
/** Filter name. */
|
|
24
|
+
name: string;
|
|
25
|
+
/**
|
|
26
|
+
* Extensions to filter, without a `.` prefix.
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* extensions: ['svg', 'png']
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
extensions: string[];
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Options for the open dialog.
|
|
36
|
+
*
|
|
37
|
+
* @since 2.0.0
|
|
38
|
+
*/
|
|
39
|
+
interface OpenDialogOptions {
|
|
40
|
+
/** The title of the dialog window. */
|
|
41
|
+
title?: string;
|
|
42
|
+
/** The filters of the dialog. */
|
|
43
|
+
filters?: DialogFilter[];
|
|
44
|
+
/** Initial directory or file path. */
|
|
45
|
+
defaultPath?: string;
|
|
46
|
+
/** Whether the dialog allows multiple selection or not. */
|
|
47
|
+
multiple?: boolean;
|
|
48
|
+
/** Whether the dialog is a directory selection or not. */
|
|
49
|
+
directory?: boolean;
|
|
50
|
+
/**
|
|
51
|
+
* If `directory` is true, indicates that it will be read recursively later.
|
|
52
|
+
* Defines whether subdirectories will be allowed on the scope or not.
|
|
53
|
+
*/
|
|
54
|
+
recursive?: boolean;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Options for the save dialog.
|
|
58
|
+
*
|
|
59
|
+
* @since 2.0.0
|
|
60
|
+
*/
|
|
61
|
+
interface SaveDialogOptions {
|
|
62
|
+
/** The title of the dialog window. */
|
|
63
|
+
title?: string;
|
|
64
|
+
/** The filters of the dialog. */
|
|
65
|
+
filters?: DialogFilter[];
|
|
66
|
+
/**
|
|
67
|
+
* Initial directory or file path.
|
|
68
|
+
* If it's a directory path, the dialog interface will change to that folder.
|
|
69
|
+
* If it's not an existing directory, the file name will be set to the dialog's file name input and the dialog will be set to the parent folder.
|
|
70
|
+
*/
|
|
71
|
+
defaultPath?: string;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* @since 2.0.0
|
|
75
|
+
*/
|
|
76
|
+
interface MessageDialogOptions {
|
|
77
|
+
/** The title of the dialog. Defaults to the app name. */
|
|
78
|
+
title?: string;
|
|
79
|
+
/** The type of the dialog. Defaults to `info`. */
|
|
80
|
+
type?: "info" | "warning" | "error";
|
|
81
|
+
/** The label of the confirm button. */
|
|
82
|
+
okLabel?: string;
|
|
83
|
+
}
|
|
84
|
+
interface ConfirmDialogOptions {
|
|
85
|
+
/** The title of the dialog. Defaults to the app name. */
|
|
86
|
+
title?: string;
|
|
87
|
+
/** The type of the dialog. Defaults to `info`. */
|
|
88
|
+
type?: "info" | "warning" | "error";
|
|
89
|
+
/** The label of the confirm button. */
|
|
90
|
+
okLabel?: string;
|
|
91
|
+
/** The label of the cancel button. */
|
|
92
|
+
cancelLabel?: string;
|
|
93
|
+
}
|
|
94
|
+
declare function open(options?: OpenDialogOptions & {
|
|
95
|
+
multiple?: false;
|
|
96
|
+
directory?: false;
|
|
97
|
+
}): Promise<null | FileResponse>;
|
|
98
|
+
declare function open(options?: OpenDialogOptions & {
|
|
99
|
+
multiple?: true;
|
|
100
|
+
directory?: false;
|
|
101
|
+
}): Promise<null | FileResponse[]>;
|
|
102
|
+
declare function open(options?: OpenDialogOptions & {
|
|
103
|
+
multiple?: false;
|
|
104
|
+
directory?: true;
|
|
105
|
+
}): Promise<null | string>;
|
|
106
|
+
declare function open(options?: OpenDialogOptions & {
|
|
107
|
+
multiple?: true;
|
|
108
|
+
directory?: true;
|
|
109
|
+
}): Promise<null | string[]>;
|
|
110
|
+
/**
|
|
111
|
+
* Open a file/directory save dialog.
|
|
112
|
+
*
|
|
113
|
+
* The selected path is added to the filesystem and asset protocol scopes.
|
|
114
|
+
* When security is more important than the easy of use of this API,
|
|
115
|
+
* prefer writing a dedicated command instead.
|
|
116
|
+
*
|
|
117
|
+
* Note that the scope change is not persisted, so the values are cleared when the application is restarted.
|
|
118
|
+
* You can save it to the filesystem using [tauri-plugin-persisted-scope](https://github.com/tauri-apps/tauri-plugin-persisted-scope).
|
|
119
|
+
* @example
|
|
120
|
+
* ```typescript
|
|
121
|
+
* import { save } from '@tauri-apps/api/dialog';
|
|
122
|
+
* const filePath = await save({
|
|
123
|
+
* filters: [{
|
|
124
|
+
* name: 'Image',
|
|
125
|
+
* extensions: ['png', 'jpeg']
|
|
126
|
+
* }]
|
|
127
|
+
* });
|
|
128
|
+
* ```
|
|
129
|
+
*
|
|
130
|
+
* @returns A promise resolving to the selected path.
|
|
131
|
+
*
|
|
132
|
+
* @since 2.0.0
|
|
133
|
+
*/
|
|
134
|
+
declare function save(options?: SaveDialogOptions): Promise<string | null>;
|
|
135
|
+
/**
|
|
136
|
+
* Shows a message dialog with an `Ok` button.
|
|
137
|
+
* @example
|
|
138
|
+
* ```typescript
|
|
139
|
+
* import { message } from '@tauri-apps/api/dialog';
|
|
140
|
+
* await message('Tauri is awesome', 'Tauri');
|
|
141
|
+
* await message('File not found', { title: 'Tauri', type: 'error' });
|
|
142
|
+
* ```
|
|
143
|
+
*
|
|
144
|
+
* @param message The message to show.
|
|
145
|
+
* @param options The dialog's options. If a string, it represents the dialog title.
|
|
146
|
+
*
|
|
147
|
+
* @returns A promise indicating the success or failure of the operation.
|
|
148
|
+
*
|
|
149
|
+
* @since 2.0.0
|
|
150
|
+
*
|
|
151
|
+
*/
|
|
152
|
+
declare function message(message: string, options?: string | MessageDialogOptions): Promise<void>;
|
|
153
|
+
/**
|
|
154
|
+
* Shows a question dialog with `Yes` and `No` buttons.
|
|
155
|
+
* @example
|
|
156
|
+
* ```typescript
|
|
157
|
+
* import { ask } from '@tauri-apps/api/dialog';
|
|
158
|
+
* const yes = await ask('Are you sure?', 'Tauri');
|
|
159
|
+
* const yes2 = await ask('This action cannot be reverted. Are you sure?', { title: 'Tauri', type: 'warning' });
|
|
160
|
+
* ```
|
|
161
|
+
*
|
|
162
|
+
* @param message The message to show.
|
|
163
|
+
* @param options The dialog's options. If a string, it represents the dialog title.
|
|
164
|
+
*
|
|
165
|
+
* @returns A promise resolving to a boolean indicating whether `Yes` was clicked or not.
|
|
166
|
+
*
|
|
167
|
+
* @since 2.0.0
|
|
168
|
+
*/
|
|
169
|
+
declare function ask(message: string, options?: string | ConfirmDialogOptions): Promise<boolean>;
|
|
170
|
+
/**
|
|
171
|
+
* Shows a question dialog with `Ok` and `Cancel` buttons.
|
|
172
|
+
* @example
|
|
173
|
+
* ```typescript
|
|
174
|
+
* import { confirm } from '@tauri-apps/api/dialog';
|
|
175
|
+
* const confirmed = await confirm('Are you sure?', 'Tauri');
|
|
176
|
+
* const confirmed2 = await confirm('This action cannot be reverted. Are you sure?', { title: 'Tauri', type: 'warning' });
|
|
177
|
+
* ```
|
|
178
|
+
*
|
|
179
|
+
* @param message The message to show.
|
|
180
|
+
* @param options The dialog's options. If a string, it represents the dialog title.
|
|
181
|
+
*
|
|
182
|
+
* @returns A promise resolving to a boolean indicating whether `Ok` was clicked or not.
|
|
183
|
+
*
|
|
184
|
+
* @since 2.0.0
|
|
185
|
+
*/
|
|
186
|
+
declare function confirm(message: string, options?: string | ConfirmDialogOptions): Promise<boolean>;
|
|
187
|
+
export type { DialogFilter, OpenDialogOptions, SaveDialogOptions, MessageDialogOptions, ConfirmDialogOptions, };
|
|
188
|
+
export { open, save, message, ask, confirm };
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
// SPDX-License-Identifier: MIT
|
|
4
|
+
/**
|
|
5
|
+
* Open a file/directory selection dialog.
|
|
6
|
+
*
|
|
7
|
+
* The selected paths are added to the filesystem and asset protocol scopes.
|
|
8
|
+
* When security is more important than the easy of use of this API,
|
|
9
|
+
* prefer writing a dedicated command instead.
|
|
10
|
+
*
|
|
11
|
+
* Note that the scope change is not persisted, so the values are cleared when the application is restarted.
|
|
12
|
+
* You can save it to the filesystem using [tauri-plugin-persisted-scope](https://github.com/tauri-apps/tauri-plugin-persisted-scope).
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* import { open } from '@tauri-apps/api/dialog';
|
|
16
|
+
* // Open a selection dialog for image files
|
|
17
|
+
* const selected = await open({
|
|
18
|
+
* multiple: true,
|
|
19
|
+
* filters: [{
|
|
20
|
+
* name: 'Image',
|
|
21
|
+
* extensions: ['png', 'jpeg']
|
|
22
|
+
* }]
|
|
23
|
+
* });
|
|
24
|
+
* if (Array.isArray(selected)) {
|
|
25
|
+
* // user selected multiple files
|
|
26
|
+
* } else if (selected === null) {
|
|
27
|
+
* // user cancelled the selection
|
|
28
|
+
* } else {
|
|
29
|
+
* // user selected a single file
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* import { open } from '@tauri-apps/api/dialog';
|
|
36
|
+
* import { appDir } from '@tauri-apps/api/path';
|
|
37
|
+
* // Open a selection dialog for directories
|
|
38
|
+
* const selected = await open({
|
|
39
|
+
* directory: true,
|
|
40
|
+
* multiple: true,
|
|
41
|
+
* defaultPath: await appDir(),
|
|
42
|
+
* });
|
|
43
|
+
* if (Array.isArray(selected)) {
|
|
44
|
+
* // user selected multiple directories
|
|
45
|
+
* } else if (selected === null) {
|
|
46
|
+
* // user cancelled the selection
|
|
47
|
+
* } else {
|
|
48
|
+
* // user selected a single directory
|
|
49
|
+
* }
|
|
50
|
+
* ```
|
|
51
|
+
*
|
|
52
|
+
* @returns A promise resolving to the selected path(s)
|
|
53
|
+
*
|
|
54
|
+
* @since 2.0.0
|
|
55
|
+
*/
|
|
56
|
+
async function open(options = {}) {
|
|
57
|
+
if (typeof options === "object") {
|
|
58
|
+
Object.freeze(options);
|
|
59
|
+
}
|
|
60
|
+
return window.__TAURI_INVOKE__("plugin:dialog|open", { options });
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Open a file/directory save dialog.
|
|
64
|
+
*
|
|
65
|
+
* The selected path is added to the filesystem and asset protocol scopes.
|
|
66
|
+
* When security is more important than the easy of use of this API,
|
|
67
|
+
* prefer writing a dedicated command instead.
|
|
68
|
+
*
|
|
69
|
+
* Note that the scope change is not persisted, so the values are cleared when the application is restarted.
|
|
70
|
+
* You can save it to the filesystem using [tauri-plugin-persisted-scope](https://github.com/tauri-apps/tauri-plugin-persisted-scope).
|
|
71
|
+
* @example
|
|
72
|
+
* ```typescript
|
|
73
|
+
* import { save } from '@tauri-apps/api/dialog';
|
|
74
|
+
* const filePath = await save({
|
|
75
|
+
* filters: [{
|
|
76
|
+
* name: 'Image',
|
|
77
|
+
* extensions: ['png', 'jpeg']
|
|
78
|
+
* }]
|
|
79
|
+
* });
|
|
80
|
+
* ```
|
|
81
|
+
*
|
|
82
|
+
* @returns A promise resolving to the selected path.
|
|
83
|
+
*
|
|
84
|
+
* @since 2.0.0
|
|
85
|
+
*/
|
|
86
|
+
async function save(options = {}) {
|
|
87
|
+
if (typeof options === "object") {
|
|
88
|
+
Object.freeze(options);
|
|
89
|
+
}
|
|
90
|
+
return window.__TAURI_INVOKE__("plugin:dialog|save", { options });
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Shows a message dialog with an `Ok` button.
|
|
94
|
+
* @example
|
|
95
|
+
* ```typescript
|
|
96
|
+
* import { message } from '@tauri-apps/api/dialog';
|
|
97
|
+
* await message('Tauri is awesome', 'Tauri');
|
|
98
|
+
* await message('File not found', { title: 'Tauri', type: 'error' });
|
|
99
|
+
* ```
|
|
100
|
+
*
|
|
101
|
+
* @param message The message to show.
|
|
102
|
+
* @param options The dialog's options. If a string, it represents the dialog title.
|
|
103
|
+
*
|
|
104
|
+
* @returns A promise indicating the success or failure of the operation.
|
|
105
|
+
*
|
|
106
|
+
* @since 2.0.0
|
|
107
|
+
*
|
|
108
|
+
*/
|
|
109
|
+
async function message(message, options) {
|
|
110
|
+
var _a, _b;
|
|
111
|
+
const opts = typeof options === "string" ? { title: options } : options;
|
|
112
|
+
return window.__TAURI_INVOKE__("plugin:dialog|message", {
|
|
113
|
+
message: message.toString(),
|
|
114
|
+
title: (_a = opts === null || opts === void 0 ? void 0 : opts.title) === null || _a === void 0 ? void 0 : _a.toString(),
|
|
115
|
+
type_: opts === null || opts === void 0 ? void 0 : opts.type,
|
|
116
|
+
okButtonLabel: (_b = opts === null || opts === void 0 ? void 0 : opts.okLabel) === null || _b === void 0 ? void 0 : _b.toString(),
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Shows a question dialog with `Yes` and `No` buttons.
|
|
121
|
+
* @example
|
|
122
|
+
* ```typescript
|
|
123
|
+
* import { ask } from '@tauri-apps/api/dialog';
|
|
124
|
+
* const yes = await ask('Are you sure?', 'Tauri');
|
|
125
|
+
* const yes2 = await ask('This action cannot be reverted. Are you sure?', { title: 'Tauri', type: 'warning' });
|
|
126
|
+
* ```
|
|
127
|
+
*
|
|
128
|
+
* @param message The message to show.
|
|
129
|
+
* @param options The dialog's options. If a string, it represents the dialog title.
|
|
130
|
+
*
|
|
131
|
+
* @returns A promise resolving to a boolean indicating whether `Yes` was clicked or not.
|
|
132
|
+
*
|
|
133
|
+
* @since 2.0.0
|
|
134
|
+
*/
|
|
135
|
+
async function ask(message, options) {
|
|
136
|
+
var _a, _b, _c, _d, _e;
|
|
137
|
+
const opts = typeof options === "string" ? { title: options } : options;
|
|
138
|
+
return window.__TAURI_INVOKE__("plugin:dialog|ask", {
|
|
139
|
+
message: message.toString(),
|
|
140
|
+
title: (_a = opts === null || opts === void 0 ? void 0 : opts.title) === null || _a === void 0 ? void 0 : _a.toString(),
|
|
141
|
+
type_: opts === null || opts === void 0 ? void 0 : opts.type,
|
|
142
|
+
okButtonLabel: (_c = (_b = opts === null || opts === void 0 ? void 0 : opts.okLabel) === null || _b === void 0 ? void 0 : _b.toString()) !== null && _c !== void 0 ? _c : "Yes",
|
|
143
|
+
cancelButtonLabel: (_e = (_d = opts === null || opts === void 0 ? void 0 : opts.cancelLabel) === null || _d === void 0 ? void 0 : _d.toString()) !== null && _e !== void 0 ? _e : "No",
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Shows a question dialog with `Ok` and `Cancel` buttons.
|
|
148
|
+
* @example
|
|
149
|
+
* ```typescript
|
|
150
|
+
* import { confirm } from '@tauri-apps/api/dialog';
|
|
151
|
+
* const confirmed = await confirm('Are you sure?', 'Tauri');
|
|
152
|
+
* const confirmed2 = await confirm('This action cannot be reverted. Are you sure?', { title: 'Tauri', type: 'warning' });
|
|
153
|
+
* ```
|
|
154
|
+
*
|
|
155
|
+
* @param message The message to show.
|
|
156
|
+
* @param options The dialog's options. If a string, it represents the dialog title.
|
|
157
|
+
*
|
|
158
|
+
* @returns A promise resolving to a boolean indicating whether `Ok` was clicked or not.
|
|
159
|
+
*
|
|
160
|
+
* @since 2.0.0
|
|
161
|
+
*/
|
|
162
|
+
async function confirm(message, options) {
|
|
163
|
+
var _a, _b, _c, _d, _e;
|
|
164
|
+
const opts = typeof options === "string" ? { title: options } : options;
|
|
165
|
+
return window.__TAURI_INVOKE__("plugin:dialog|confirm", {
|
|
166
|
+
message: message.toString(),
|
|
167
|
+
title: (_a = opts === null || opts === void 0 ? void 0 : opts.title) === null || _a === void 0 ? void 0 : _a.toString(),
|
|
168
|
+
type_: opts === null || opts === void 0 ? void 0 : opts.type,
|
|
169
|
+
okButtonLabel: (_c = (_b = opts === null || opts === void 0 ? void 0 : opts.okLabel) === null || _b === void 0 ? void 0 : _b.toString()) !== null && _c !== void 0 ? _c : "Ok",
|
|
170
|
+
cancelButtonLabel: (_e = (_d = opts === null || opts === void 0 ? void 0 : opts.cancelLabel) === null || _d === void 0 ? void 0 : _d.toString()) !== null && _e !== void 0 ? _e : "Cancel",
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export { ask, confirm, message, open, save };
|
|
175
|
+
//# sourceMappingURL=index.min.js.map
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
// SPDX-License-Identifier: MIT
|
|
4
|
+
/**
|
|
5
|
+
* Open a file/directory selection dialog.
|
|
6
|
+
*
|
|
7
|
+
* The selected paths are added to the filesystem and asset protocol scopes.
|
|
8
|
+
* When security is more important than the easy of use of this API,
|
|
9
|
+
* prefer writing a dedicated command instead.
|
|
10
|
+
*
|
|
11
|
+
* Note that the scope change is not persisted, so the values are cleared when the application is restarted.
|
|
12
|
+
* You can save it to the filesystem using [tauri-plugin-persisted-scope](https://github.com/tauri-apps/tauri-plugin-persisted-scope).
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* import { open } from '@tauri-apps/api/dialog';
|
|
16
|
+
* // Open a selection dialog for image files
|
|
17
|
+
* const selected = await open({
|
|
18
|
+
* multiple: true,
|
|
19
|
+
* filters: [{
|
|
20
|
+
* name: 'Image',
|
|
21
|
+
* extensions: ['png', 'jpeg']
|
|
22
|
+
* }]
|
|
23
|
+
* });
|
|
24
|
+
* if (Array.isArray(selected)) {
|
|
25
|
+
* // user selected multiple files
|
|
26
|
+
* } else if (selected === null) {
|
|
27
|
+
* // user cancelled the selection
|
|
28
|
+
* } else {
|
|
29
|
+
* // user selected a single file
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* import { open } from '@tauri-apps/api/dialog';
|
|
36
|
+
* import { appDir } from '@tauri-apps/api/path';
|
|
37
|
+
* // Open a selection dialog for directories
|
|
38
|
+
* const selected = await open({
|
|
39
|
+
* directory: true,
|
|
40
|
+
* multiple: true,
|
|
41
|
+
* defaultPath: await appDir(),
|
|
42
|
+
* });
|
|
43
|
+
* if (Array.isArray(selected)) {
|
|
44
|
+
* // user selected multiple directories
|
|
45
|
+
* } else if (selected === null) {
|
|
46
|
+
* // user cancelled the selection
|
|
47
|
+
* } else {
|
|
48
|
+
* // user selected a single directory
|
|
49
|
+
* }
|
|
50
|
+
* ```
|
|
51
|
+
*
|
|
52
|
+
* @returns A promise resolving to the selected path(s)
|
|
53
|
+
*
|
|
54
|
+
* @since 2.0.0
|
|
55
|
+
*/
|
|
56
|
+
async function open(options = {}) {
|
|
57
|
+
if (typeof options === "object") {
|
|
58
|
+
Object.freeze(options);
|
|
59
|
+
}
|
|
60
|
+
return window.__TAURI_INVOKE__("plugin:dialog|open", { options });
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Open a file/directory save dialog.
|
|
64
|
+
*
|
|
65
|
+
* The selected path is added to the filesystem and asset protocol scopes.
|
|
66
|
+
* When security is more important than the easy of use of this API,
|
|
67
|
+
* prefer writing a dedicated command instead.
|
|
68
|
+
*
|
|
69
|
+
* Note that the scope change is not persisted, so the values are cleared when the application is restarted.
|
|
70
|
+
* You can save it to the filesystem using [tauri-plugin-persisted-scope](https://github.com/tauri-apps/tauri-plugin-persisted-scope).
|
|
71
|
+
* @example
|
|
72
|
+
* ```typescript
|
|
73
|
+
* import { save } from '@tauri-apps/api/dialog';
|
|
74
|
+
* const filePath = await save({
|
|
75
|
+
* filters: [{
|
|
76
|
+
* name: 'Image',
|
|
77
|
+
* extensions: ['png', 'jpeg']
|
|
78
|
+
* }]
|
|
79
|
+
* });
|
|
80
|
+
* ```
|
|
81
|
+
*
|
|
82
|
+
* @returns A promise resolving to the selected path.
|
|
83
|
+
*
|
|
84
|
+
* @since 2.0.0
|
|
85
|
+
*/
|
|
86
|
+
async function save(options = {}) {
|
|
87
|
+
if (typeof options === "object") {
|
|
88
|
+
Object.freeze(options);
|
|
89
|
+
}
|
|
90
|
+
return window.__TAURI_INVOKE__("plugin:dialog|save", { options });
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Shows a message dialog with an `Ok` button.
|
|
94
|
+
* @example
|
|
95
|
+
* ```typescript
|
|
96
|
+
* import { message } from '@tauri-apps/api/dialog';
|
|
97
|
+
* await message('Tauri is awesome', 'Tauri');
|
|
98
|
+
* await message('File not found', { title: 'Tauri', type: 'error' });
|
|
99
|
+
* ```
|
|
100
|
+
*
|
|
101
|
+
* @param message The message to show.
|
|
102
|
+
* @param options The dialog's options. If a string, it represents the dialog title.
|
|
103
|
+
*
|
|
104
|
+
* @returns A promise indicating the success or failure of the operation.
|
|
105
|
+
*
|
|
106
|
+
* @since 2.0.0
|
|
107
|
+
*
|
|
108
|
+
*/
|
|
109
|
+
async function message(message, options) {
|
|
110
|
+
var _a, _b;
|
|
111
|
+
const opts = typeof options === "string" ? { title: options } : options;
|
|
112
|
+
return window.__TAURI_INVOKE__("plugin:dialog|message", {
|
|
113
|
+
message: message.toString(),
|
|
114
|
+
title: (_a = opts === null || opts === void 0 ? void 0 : opts.title) === null || _a === void 0 ? void 0 : _a.toString(),
|
|
115
|
+
type_: opts === null || opts === void 0 ? void 0 : opts.type,
|
|
116
|
+
okButtonLabel: (_b = opts === null || opts === void 0 ? void 0 : opts.okLabel) === null || _b === void 0 ? void 0 : _b.toString(),
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Shows a question dialog with `Yes` and `No` buttons.
|
|
121
|
+
* @example
|
|
122
|
+
* ```typescript
|
|
123
|
+
* import { ask } from '@tauri-apps/api/dialog';
|
|
124
|
+
* const yes = await ask('Are you sure?', 'Tauri');
|
|
125
|
+
* const yes2 = await ask('This action cannot be reverted. Are you sure?', { title: 'Tauri', type: 'warning' });
|
|
126
|
+
* ```
|
|
127
|
+
*
|
|
128
|
+
* @param message The message to show.
|
|
129
|
+
* @param options The dialog's options. If a string, it represents the dialog title.
|
|
130
|
+
*
|
|
131
|
+
* @returns A promise resolving to a boolean indicating whether `Yes` was clicked or not.
|
|
132
|
+
*
|
|
133
|
+
* @since 2.0.0
|
|
134
|
+
*/
|
|
135
|
+
async function ask(message, options) {
|
|
136
|
+
var _a, _b, _c, _d, _e;
|
|
137
|
+
const opts = typeof options === "string" ? { title: options } : options;
|
|
138
|
+
return window.__TAURI_INVOKE__("plugin:dialog|ask", {
|
|
139
|
+
message: message.toString(),
|
|
140
|
+
title: (_a = opts === null || opts === void 0 ? void 0 : opts.title) === null || _a === void 0 ? void 0 : _a.toString(),
|
|
141
|
+
type_: opts === null || opts === void 0 ? void 0 : opts.type,
|
|
142
|
+
okButtonLabel: (_c = (_b = opts === null || opts === void 0 ? void 0 : opts.okLabel) === null || _b === void 0 ? void 0 : _b.toString()) !== null && _c !== void 0 ? _c : "Yes",
|
|
143
|
+
cancelButtonLabel: (_e = (_d = opts === null || opts === void 0 ? void 0 : opts.cancelLabel) === null || _d === void 0 ? void 0 : _d.toString()) !== null && _e !== void 0 ? _e : "No",
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Shows a question dialog with `Ok` and `Cancel` buttons.
|
|
148
|
+
* @example
|
|
149
|
+
* ```typescript
|
|
150
|
+
* import { confirm } from '@tauri-apps/api/dialog';
|
|
151
|
+
* const confirmed = await confirm('Are you sure?', 'Tauri');
|
|
152
|
+
* const confirmed2 = await confirm('This action cannot be reverted. Are you sure?', { title: 'Tauri', type: 'warning' });
|
|
153
|
+
* ```
|
|
154
|
+
*
|
|
155
|
+
* @param message The message to show.
|
|
156
|
+
* @param options The dialog's options. If a string, it represents the dialog title.
|
|
157
|
+
*
|
|
158
|
+
* @returns A promise resolving to a boolean indicating whether `Ok` was clicked or not.
|
|
159
|
+
*
|
|
160
|
+
* @since 2.0.0
|
|
161
|
+
*/
|
|
162
|
+
async function confirm(message, options) {
|
|
163
|
+
var _a, _b, _c, _d, _e;
|
|
164
|
+
const opts = typeof options === "string" ? { title: options } : options;
|
|
165
|
+
return window.__TAURI_INVOKE__("plugin:dialog|confirm", {
|
|
166
|
+
message: message.toString(),
|
|
167
|
+
title: (_a = opts === null || opts === void 0 ? void 0 : opts.title) === null || _a === void 0 ? void 0 : _a.toString(),
|
|
168
|
+
type_: opts === null || opts === void 0 ? void 0 : opts.type,
|
|
169
|
+
okButtonLabel: (_c = (_b = opts === null || opts === void 0 ? void 0 : opts.okLabel) === null || _b === void 0 ? void 0 : _b.toString()) !== null && _c !== void 0 ? _c : "Ok",
|
|
170
|
+
cancelButtonLabel: (_e = (_d = opts === null || opts === void 0 ? void 0 : opts.cancelLabel) === null || _d === void 0 ? void 0 : _d.toString()) !== null && _e !== void 0 ? _e : "Cancel",
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export { ask, confirm, message, open, save };
|
|
175
|
+
//# sourceMappingURL=index.mjs.map
|
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tauri-apps/plugin-dialog",
|
|
3
|
+
"version": "2.0.0-alpha.0",
|
|
4
|
+
"license": "MIT or APACHE-2.0",
|
|
5
|
+
"authors": [
|
|
6
|
+
"Tauri Programme within The Commons Conservancy"
|
|
7
|
+
],
|
|
8
|
+
"type": "module",
|
|
9
|
+
"browser": "dist-js/index.min.js",
|
|
10
|
+
"module": "dist-js/index.mjs",
|
|
11
|
+
"types": "dist-js/index.d.ts",
|
|
12
|
+
"exports": {
|
|
13
|
+
"import": "./dist-js/index.mjs",
|
|
14
|
+
"types": "./dist-js/index.d.ts",
|
|
15
|
+
"browser": "./dist-js/index.min.js"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist-js",
|
|
19
|
+
"!dist-js/**/*.map",
|
|
20
|
+
"README.md",
|
|
21
|
+
"LICENSE"
|
|
22
|
+
],
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"tslib": "^2.4.1"
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@tauri-apps/api": "2.0.0-alpha.4"
|
|
28
|
+
},
|
|
29
|
+
"scripts": {
|
|
30
|
+
"build": "rollup -c"
|
|
31
|
+
}
|
|
32
|
+
}
|