@tauri-apps/plugin-dialog 2.0.0-alpha.5 → 2.0.0-beta.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/README.md CHANGED
@@ -18,7 +18,7 @@ Install the Core plugin by adding the following to your `Cargo.toml` file:
18
18
 
19
19
  ```toml
20
20
  [dependencies]
21
- tauri-plugin-dialog = "2.0.0-alpha"
21
+ tauri-plugin-dialog = "2.0.0-beta"
22
22
  # alternatively with Git:
23
23
  tauri-plugin-dialog = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v2" }
24
24
  ```
@@ -86,22 +86,60 @@ interface ConfirmDialogOptions {
86
86
  /** The label of the cancel button. */
87
87
  cancelLabel?: string;
88
88
  }
89
- declare function open(options?: OpenDialogOptions & {
90
- multiple?: false;
91
- directory?: false;
92
- }): Promise<null | FileResponse>;
93
- declare function open(options?: OpenDialogOptions & {
94
- multiple?: true;
95
- directory?: false;
96
- }): Promise<null | FileResponse[]>;
97
- declare function open(options?: OpenDialogOptions & {
98
- multiple?: false;
99
- directory?: true;
100
- }): Promise<null | string>;
101
- declare function open(options?: OpenDialogOptions & {
102
- multiple?: true;
103
- directory?: true;
104
- }): Promise<null | string[]>;
89
+ type OpenDialogReturn<T extends OpenDialogOptions> = T["directory"] extends true ? T["multiple"] extends true ? string[] | null : string | null : T["multiple"] extends true ? FileResponse[] | null : FileResponse | null;
90
+ /**
91
+ * Open a file/directory selection dialog.
92
+ *
93
+ * The selected paths are added to the filesystem and asset protocol scopes.
94
+ * When security is more important than the easy of use of this API,
95
+ * prefer writing a dedicated command instead.
96
+ *
97
+ * Note that the scope change is not persisted, so the values are cleared when the application is restarted.
98
+ * You can save it to the filesystem using [tauri-plugin-persisted-scope](https://github.com/tauri-apps/tauri-plugin-persisted-scope).
99
+ * @example
100
+ * ```typescript
101
+ * import { open } from '@tauri-apps/plugin-dialog';
102
+ * // Open a selection dialog for image files
103
+ * const selected = await open({
104
+ * multiple: true,
105
+ * filters: [{
106
+ * name: 'Image',
107
+ * extensions: ['png', 'jpeg']
108
+ * }]
109
+ * });
110
+ * if (Array.isArray(selected)) {
111
+ * // user selected multiple files
112
+ * } else if (selected === null) {
113
+ * // user cancelled the selection
114
+ * } else {
115
+ * // user selected a single file
116
+ * }
117
+ * ```
118
+ *
119
+ * @example
120
+ * ```typescript
121
+ * import { open } from '@tauri-apps/plugin-dialog';
122
+ * import { appDir } from '@tauri-apps/api/path';
123
+ * // Open a selection dialog for directories
124
+ * const selected = await open({
125
+ * directory: true,
126
+ * multiple: true,
127
+ * defaultPath: await appDir(),
128
+ * });
129
+ * if (Array.isArray(selected)) {
130
+ * // user selected multiple directories
131
+ * } else if (selected === null) {
132
+ * // user cancelled the selection
133
+ * } else {
134
+ * // user selected a single directory
135
+ * }
136
+ * ```
137
+ *
138
+ * @returns A promise resolving to the selected path(s)
139
+ *
140
+ * @since 2.0.0
141
+ */
142
+ declare function open<T extends OpenDialogOptions>(options?: T): Promise<OpenDialogReturn<T>>;
105
143
  /**
106
144
  * Open a file/directory save dialog.
107
145
  *
@@ -179,5 +217,5 @@ declare function ask(message: string, options?: string | ConfirmDialogOptions):
179
217
  * @since 2.0.0
180
218
  */
181
219
  declare function confirm(message: string, options?: string | ConfirmDialogOptions): Promise<boolean>;
182
- export type { DialogFilter, FileResponse, OpenDialogOptions, SaveDialogOptions, MessageDialogOptions, ConfirmDialogOptions, };
220
+ export type { DialogFilter, FileResponse, OpenDialogOptions, OpenDialogReturn, SaveDialogOptions, MessageDialogOptions, ConfirmDialogOptions, };
183
221
  export { open, save, message, ask, confirm };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tauri-apps/plugin-dialog",
3
- "version": "2.0.0-alpha.5",
3
+ "version": "2.0.0-beta.0",
4
4
  "license": "MIT or APACHE-2.0",
5
5
  "authors": [
6
6
  "Tauri Programme within The Commons Conservancy"
@@ -20,7 +20,7 @@
20
20
  "LICENSE"
21
21
  ],
22
22
  "dependencies": {
23
- "@tauri-apps/api": "2.0.0-alpha.13"
23
+ "@tauri-apps/api": "2.0.0-beta.0"
24
24
  },
25
25
  "scripts": {
26
26
  "build": "rollup -c"