@destyler/file-upload 0.0.7-beta.7 → 0.1.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/dist/index.d.ts +219 -207
- package/dist/index.js +550 -0
- package/package.json +13 -17
- package/dist/index.cjs +0 -580
- package/dist/index.d.cts +0 -240
- package/dist/index.d.mts +0 -240
- package/dist/index.mjs +0 -572
package/dist/index.d.ts
CHANGED
|
@@ -1,240 +1,252 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import {
|
|
3
|
-
import * as
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
export { FileError, FileMimeType } from '@zag-js/file-utils';
|
|
7
|
-
|
|
8
|
-
declare const anatomy: _zag_js_anatomy.AnatomyInstance<"root" | "dropzone" | "item" | "itemDeleteTrigger" | "itemGroup" | "itemName" | "itemPreview" | "itemPreviewImage" | "itemSizeText" | "label" | "trigger" | "clearTrigger">;
|
|
1
|
+
import * as _destyler_anatomy0 from "@destyler/anatomy";
|
|
2
|
+
import { FileError, FileMimeType } from "@destyler/file";
|
|
3
|
+
import * as _destyler_xstate0 from "@destyler/xstate";
|
|
4
|
+
import { AnyEventObject, Machine, XSend, XState } from "@destyler/xstate";
|
|
5
|
+
import { CommonProperties, LocaleProperties, NormalizeProps, PropTypes, RequiredBy } from "@destyler/types";
|
|
9
6
|
|
|
7
|
+
//#region src/anatomy.d.ts
|
|
8
|
+
declare const anatomy: _destyler_anatomy0.AnatomyInstance<"root" | "dropzone" | "trigger" | "label" | "item" | "itemName" | "itemSizeText" | "itemPreview" | "itemDeleteTrigger" | "itemGroup" | "itemPreviewImage" | "clearTrigger">;
|
|
9
|
+
//#endregion
|
|
10
|
+
//#region src/types.d.ts
|
|
10
11
|
interface FileRejection {
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
file: File;
|
|
13
|
+
errors: FileError[];
|
|
13
14
|
}
|
|
14
15
|
interface FileChangeDetails {
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
acceptedFiles: File[];
|
|
17
|
+
rejectedFiles: FileRejection[];
|
|
17
18
|
}
|
|
18
19
|
interface FileValidateDetails {
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
acceptedFiles: File[];
|
|
21
|
+
rejectedFiles: FileRejection[];
|
|
21
22
|
}
|
|
22
23
|
interface FileAcceptDetails {
|
|
23
|
-
|
|
24
|
+
files: File[];
|
|
24
25
|
}
|
|
25
26
|
interface FileRejectDetails {
|
|
26
|
-
|
|
27
|
+
files: FileRejection[];
|
|
27
28
|
}
|
|
28
|
-
|
|
29
29
|
type ElementIds = Partial<{
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
30
|
+
root: string;
|
|
31
|
+
dropzone: string;
|
|
32
|
+
hiddenInput: string;
|
|
33
|
+
trigger: string;
|
|
34
|
+
label: string;
|
|
35
|
+
item: (id: string) => string;
|
|
36
|
+
itemName: (id: string) => string;
|
|
37
|
+
itemSizeText: (id: string) => string;
|
|
38
|
+
itemPreview: (id: string) => string;
|
|
39
39
|
}>;
|
|
40
40
|
interface IntlTranslations {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
dropzone?: string | undefined;
|
|
42
|
+
itemPreview?: (file: File) => string;
|
|
43
|
+
deleteFile?: (file: File) => string;
|
|
44
44
|
}
|
|
45
45
|
interface PublicContext extends LocaleProperties, CommonProperties {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
46
|
+
/**
|
|
47
|
+
* The name of the underlying file input
|
|
48
|
+
*/
|
|
49
|
+
name?: string | undefined;
|
|
50
|
+
/**
|
|
51
|
+
* The ids of the elements. Useful for composition.
|
|
52
|
+
*/
|
|
53
|
+
ids?: ElementIds | undefined;
|
|
54
|
+
/**
|
|
55
|
+
* The localized messages to use.
|
|
56
|
+
*/
|
|
57
|
+
translations: IntlTranslations;
|
|
58
|
+
/**
|
|
59
|
+
* The accept file types
|
|
60
|
+
*/
|
|
61
|
+
accept?: Record<string, string[]> | FileMimeType | FileMimeType[] | undefined;
|
|
62
|
+
/**
|
|
63
|
+
* Whether the file input is disabled
|
|
64
|
+
*/
|
|
65
|
+
disabled?: boolean | undefined;
|
|
66
|
+
/**
|
|
67
|
+
* Whether the file input is required
|
|
68
|
+
*/
|
|
69
|
+
required?: boolean | undefined;
|
|
70
|
+
/**
|
|
71
|
+
* Whether to allow drag and drop in the dropzone element
|
|
72
|
+
* @default true
|
|
73
|
+
*/
|
|
74
|
+
allowDrop?: boolean | undefined;
|
|
75
|
+
/**
|
|
76
|
+
* The maximum file size in bytes
|
|
77
|
+
*
|
|
78
|
+
* @default Infinity
|
|
79
|
+
*/
|
|
80
|
+
maxFileSize: number;
|
|
81
|
+
/**
|
|
82
|
+
* The minimum file size in bytes
|
|
83
|
+
*
|
|
84
|
+
* @default 0
|
|
85
|
+
*/
|
|
86
|
+
minFileSize: number;
|
|
87
|
+
/**
|
|
88
|
+
* The maximum number of files
|
|
89
|
+
* @default 1
|
|
90
|
+
*/
|
|
91
|
+
maxFiles: number;
|
|
92
|
+
/**
|
|
93
|
+
* Whether to prevent the drop event on the document
|
|
94
|
+
* @default true
|
|
95
|
+
*/
|
|
96
|
+
preventDocumentDrop?: boolean | undefined;
|
|
97
|
+
/**
|
|
98
|
+
* Function to validate a file
|
|
99
|
+
*/
|
|
100
|
+
validate?: ((file: File, details: FileValidateDetails) => FileError[] | null) | undefined;
|
|
101
|
+
/**
|
|
102
|
+
* Function called when the value changes, whether accepted or rejected
|
|
103
|
+
*/
|
|
104
|
+
onFileChange?: ((details: FileChangeDetails) => void) | undefined;
|
|
105
|
+
/**
|
|
106
|
+
* Function called when the file is accepted
|
|
107
|
+
*/
|
|
108
|
+
onFileAccept?: ((details: FileAcceptDetails) => void) | undefined;
|
|
109
|
+
/**
|
|
110
|
+
* Function called when the file is rejected
|
|
111
|
+
*/
|
|
112
|
+
onFileReject?: ((details: FileRejectDetails) => void) | undefined;
|
|
113
|
+
/**
|
|
114
|
+
* The default camera to use when capturing media
|
|
115
|
+
*/
|
|
116
|
+
capture?: 'user' | 'environment' | undefined;
|
|
117
|
+
/**
|
|
118
|
+
* Whether to accept directories, only works in webkit browsers
|
|
119
|
+
*/
|
|
120
|
+
directory?: boolean | undefined;
|
|
121
|
+
/**
|
|
122
|
+
* Whether the file input is invalid
|
|
123
|
+
*/
|
|
124
|
+
invalid?: boolean | undefined;
|
|
125
125
|
}
|
|
126
126
|
interface PrivateContext {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
127
|
+
/**
|
|
128
|
+
* @internal
|
|
129
|
+
* The rejected files
|
|
130
|
+
*/
|
|
131
|
+
rejectedFiles: FileRejection[];
|
|
132
|
+
/**
|
|
133
|
+
* @internal
|
|
134
|
+
* The current value of the file input
|
|
135
|
+
*/
|
|
136
|
+
acceptedFiles: File[];
|
|
137
137
|
}
|
|
138
138
|
type ComputedContext = Readonly<{
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
139
|
+
/**
|
|
140
|
+
* @computed
|
|
141
|
+
* The accept attribute as a string
|
|
142
|
+
*/
|
|
143
|
+
acceptAttr: string | undefined;
|
|
144
|
+
/**
|
|
145
|
+
* @computed
|
|
146
|
+
* Whether the file can select multiple files
|
|
147
|
+
*/
|
|
148
|
+
multiple: boolean;
|
|
149
149
|
}>;
|
|
150
150
|
type UserDefinedContext = RequiredBy<PublicContext, 'id'>;
|
|
151
|
-
interface MachineContext extends PublicContext, PrivateContext, ComputedContext {
|
|
152
|
-
}
|
|
151
|
+
interface MachineContext extends PublicContext, PrivateContext, ComputedContext {}
|
|
153
152
|
interface MachineState {
|
|
154
|
-
|
|
153
|
+
value: 'idle' | 'focused' | 'open' | 'dragging';
|
|
155
154
|
}
|
|
156
|
-
type State =
|
|
157
|
-
type Send =
|
|
158
|
-
type Service = Machine<MachineContext, MachineState,
|
|
155
|
+
type State = XState<MachineContext, MachineState>;
|
|
156
|
+
type Send = XSend<AnyEventObject>;
|
|
157
|
+
type Service = Machine<MachineContext, MachineState, AnyEventObject>;
|
|
159
158
|
interface ItemProps {
|
|
160
|
-
|
|
159
|
+
file: File;
|
|
161
160
|
}
|
|
162
161
|
interface ItemPreviewImageProps extends ItemProps {
|
|
163
|
-
|
|
162
|
+
url: string;
|
|
163
|
+
}
|
|
164
|
+
interface DropzoneProps {
|
|
165
|
+
/**
|
|
166
|
+
* Whether to disable the click event on the dropzone
|
|
167
|
+
*/
|
|
168
|
+
disableClick?: boolean;
|
|
164
169
|
}
|
|
165
170
|
interface MachineApi<T extends PropTypes> {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
171
|
+
/**
|
|
172
|
+
* Whether the user is dragging something over the root element
|
|
173
|
+
*/
|
|
174
|
+
dragging: boolean;
|
|
175
|
+
/**
|
|
176
|
+
* Whether the user is focused on the dropzone element
|
|
177
|
+
*/
|
|
178
|
+
focused: boolean;
|
|
179
|
+
/**
|
|
180
|
+
* Whether the file input is disabled
|
|
181
|
+
*/
|
|
182
|
+
disabled: boolean;
|
|
183
|
+
/**
|
|
184
|
+
* Function to open the file dialog
|
|
185
|
+
*/
|
|
186
|
+
openFilePicker: () => void;
|
|
187
|
+
/**
|
|
188
|
+
* Function to delete the file from the list
|
|
189
|
+
*/
|
|
190
|
+
deleteFile: (file: File) => void;
|
|
191
|
+
/**
|
|
192
|
+
* The accepted files that have been dropped or selected
|
|
193
|
+
*/
|
|
194
|
+
acceptedFiles: File[];
|
|
195
|
+
/**
|
|
196
|
+
* The files that have been rejected
|
|
197
|
+
*/
|
|
198
|
+
rejectedFiles: FileRejection[];
|
|
199
|
+
/**
|
|
200
|
+
* Function to set the value
|
|
201
|
+
*/
|
|
202
|
+
setFiles: (files: File[]) => void;
|
|
203
|
+
/**
|
|
204
|
+
* Function to clear the value
|
|
205
|
+
*/
|
|
206
|
+
clearFiles: () => void;
|
|
207
|
+
/**
|
|
208
|
+
* Function to clear the rejected files
|
|
209
|
+
*/
|
|
210
|
+
clearRejectedFiles: () => void;
|
|
211
|
+
/**
|
|
212
|
+
* Function to format the file size (e.g. 1.2MB)
|
|
213
|
+
*/
|
|
214
|
+
getFileSize: (file: File) => string;
|
|
215
|
+
/**
|
|
216
|
+
* Function to get the preview url of a file.
|
|
217
|
+
* Returns a function to revoke the url.
|
|
218
|
+
*/
|
|
219
|
+
createFileUrl: (file: File, cb: (url: string) => void) => VoidFunction;
|
|
220
|
+
/**
|
|
221
|
+
* Function to set the clipboard files.
|
|
222
|
+
* Returns `true` if the clipboard data contains files, `false` otherwise.
|
|
223
|
+
*/
|
|
224
|
+
setClipboardFiles: (dt: DataTransfer | null) => boolean;
|
|
225
|
+
getLabelProps: () => T['label'];
|
|
226
|
+
getRootProps: () => T['element'];
|
|
227
|
+
getDropzoneProps: (props?: DropzoneProps) => T['element'];
|
|
228
|
+
getTriggerProps: () => T['button'];
|
|
229
|
+
getHiddenInputProps: () => T['input'];
|
|
230
|
+
getItemGroupProps: () => T['element'];
|
|
231
|
+
getItemProps: (props: ItemProps) => T['element'];
|
|
232
|
+
getItemNameProps: (props: ItemProps) => T['element'];
|
|
233
|
+
getItemPreviewProps: (props: ItemProps) => T['element'];
|
|
234
|
+
getItemPreviewImageProps: (props: ItemPreviewImageProps) => T['img'];
|
|
235
|
+
getItemSizeTextProps: (props: ItemProps) => T['element'];
|
|
236
|
+
getItemDeleteTriggerProps: (props: ItemProps) => T['button'];
|
|
237
|
+
getClearTriggerProps: () => T['button'];
|
|
229
238
|
}
|
|
230
|
-
|
|
239
|
+
//#endregion
|
|
240
|
+
//#region src/connect.d.ts
|
|
231
241
|
declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): MachineApi<T>;
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
242
|
+
//#endregion
|
|
243
|
+
//#region src/machine.d.ts
|
|
244
|
+
declare function machine(userContext: UserDefinedContext): _destyler_xstate0.Machine<MachineContext, MachineState, _destyler_xstate0.AnyEventObject>;
|
|
245
|
+
//#endregion
|
|
246
|
+
//#region src/props.d.ts
|
|
247
|
+
declare const props: ("name" | "ids" | "translations" | "accept" | "disabled" | "required" | "allowDrop" | "maxFileSize" | "minFileSize" | "maxFiles" | "preventDocumentDrop" | "validate" | "onFileChange" | "onFileAccept" | "onFileReject" | "capture" | "directory" | "invalid" | "locale" | "dir" | "id" | "getRootNode")[];
|
|
248
|
+
declare const splitProps: <Props extends Partial<UserDefinedContext>>(props: Props) => [Partial<UserDefinedContext>, Omit<Props, "name" | "ids" | "translations" | "accept" | "disabled" | "required" | "allowDrop" | "maxFileSize" | "minFileSize" | "maxFiles" | "preventDocumentDrop" | "validate" | "onFileChange" | "onFileAccept" | "onFileReject" | "capture" | "directory" | "invalid" | "locale" | "dir" | "id" | "getRootNode">];
|
|
237
249
|
declare const itemProps: "file"[];
|
|
238
250
|
declare const splitItemProps: <Props extends ItemProps>(props: Props) => [ItemProps, Omit<Props, "file">];
|
|
239
|
-
|
|
240
|
-
export { type MachineApi as Api, type UserDefinedContext as Context, type ElementIds, type FileAcceptDetails, type FileChangeDetails, type FileRejectDetails, type FileRejection, type FileValidateDetails, type IntlTranslations, type ItemPreviewImageProps, type ItemProps, type Service, anatomy, connect, itemProps, machine, props, splitItemProps, splitProps };
|
|
251
|
+
//#endregion
|
|
252
|
+
export { type MachineApi as Api, type UserDefinedContext as Context, type ElementIds, type FileAcceptDetails, type FileChangeDetails, type FileError, type FileMimeType, type FileRejectDetails, type FileRejection, type FileValidateDetails, type IntlTranslations, type ItemPreviewImageProps, type ItemProps, type Service, anatomy, connect, itemProps, machine, props, splitItemProps, splitProps };
|