@destyler/file-upload 0.0.7-beta.1

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.
@@ -0,0 +1,240 @@
1
+ import * as _zag_js_anatomy from '@zag-js/anatomy';
2
+ import { RequiredBy, PropTypes, LocaleProperties, CommonProperties, NormalizeProps } from '@zag-js/types';
3
+ import * as _zag_js_core from '@zag-js/core';
4
+ import { Machine, StateMachine } from '@zag-js/core';
5
+ import { FileError, FileMimeType } from '@zag-js/file-utils';
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">;
9
+
10
+ interface FileRejection {
11
+ file: File;
12
+ errors: FileError[];
13
+ }
14
+ interface FileChangeDetails {
15
+ acceptedFiles: File[];
16
+ rejectedFiles: FileRejection[];
17
+ }
18
+ interface FileValidateDetails {
19
+ acceptedFiles: File[];
20
+ rejectedFiles: FileRejection[];
21
+ }
22
+ interface FileAcceptDetails {
23
+ files: File[];
24
+ }
25
+ interface FileRejectDetails {
26
+ files: FileRejection[];
27
+ }
28
+
29
+ type ElementIds = Partial<{
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
+ }>;
40
+ interface IntlTranslations {
41
+ dropzone?: string | undefined;
42
+ itemPreview?: (file: File) => string;
43
+ deleteFile?: (file: File) => string;
44
+ }
45
+ interface PublicContext extends LocaleProperties, CommonProperties {
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
+ }
126
+ interface PrivateContext {
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
+ }
138
+ type ComputedContext = Readonly<{
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
+ }>;
150
+ type UserDefinedContext = RequiredBy<PublicContext, 'id'>;
151
+ interface MachineContext extends PublicContext, PrivateContext, ComputedContext {
152
+ }
153
+ interface MachineState {
154
+ value: 'idle' | 'focused' | 'open' | 'dragging';
155
+ }
156
+ type State = StateMachine.State<MachineContext, MachineState>;
157
+ type Send = StateMachine.Send<StateMachine.AnyEventObject>;
158
+ type Service = Machine<MachineContext, MachineState, StateMachine.AnyEventObject>;
159
+ interface ItemProps {
160
+ file: File;
161
+ }
162
+ interface ItemPreviewImageProps extends ItemProps {
163
+ url: string;
164
+ }
165
+ interface MachineApi<T extends PropTypes> {
166
+ /**
167
+ * Whether the user is dragging something over the root element
168
+ */
169
+ dragging: boolean;
170
+ /**
171
+ * Whether the user is focused on the dropzone element
172
+ */
173
+ focused: boolean;
174
+ /**
175
+ * Function to open the file dialog
176
+ */
177
+ openFilePicker: () => void;
178
+ /**
179
+ * Function to delete the file from the list
180
+ */
181
+ deleteFile: (file: File) => void;
182
+ /**
183
+ * The accepted files that have been dropped or selected
184
+ */
185
+ acceptedFiles: File[];
186
+ /**
187
+ * The files that have been rejected
188
+ */
189
+ rejectedFiles: FileRejection[];
190
+ /**
191
+ * Function to set the value
192
+ */
193
+ setFiles: (files: File[]) => void;
194
+ /**
195
+ * Function to clear the value
196
+ */
197
+ clearFiles: () => void;
198
+ /**
199
+ * Function to clear the rejected files
200
+ */
201
+ clearRejectedFiles: () => void;
202
+ /**
203
+ * Function to format the file size (e.g. 1.2MB)
204
+ */
205
+ getFileSize: (file: File) => string;
206
+ /**
207
+ * Function to get the preview url of a file.
208
+ * Returns a function to revoke the url.
209
+ */
210
+ createFileUrl: (file: File, cb: (url: string) => void) => VoidFunction;
211
+ /**
212
+ * Function to set the clipboard files.
213
+ * Returns `true` if the clipboard data contains files, `false` otherwise.
214
+ */
215
+ setClipboardFiles: (dt: DataTransfer | null) => boolean;
216
+ getLabelProps: () => T['label'];
217
+ getRootProps: () => T['element'];
218
+ getDropzoneProps: () => T['element'];
219
+ getTriggerProps: () => T['button'];
220
+ getHiddenInputProps: () => T['input'];
221
+ getItemGroupProps: () => T['element'];
222
+ getItemProps: (props: ItemProps) => T['element'];
223
+ getItemNameProps: (props: ItemProps) => T['element'];
224
+ getItemPreviewProps: (props: ItemProps) => T['element'];
225
+ getItemPreviewImageProps: (props: ItemPreviewImageProps) => T['img'];
226
+ getItemSizeTextProps: (props: ItemProps) => T['element'];
227
+ getItemDeleteTriggerProps: (props: ItemProps) => T['button'];
228
+ getClearTriggerProps: () => T['button'];
229
+ }
230
+
231
+ declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): MachineApi<T>;
232
+
233
+ declare function machine(userContext: UserDefinedContext): _zag_js_core.Machine<MachineContext, MachineState, _zag_js_core.StateMachine.AnyEventObject>;
234
+
235
+ declare const props: ("name" | "ids" | "translations" | "accept" | "disabled" | "required" | "allowDrop" | "maxFileSize" | "minFileSize" | "maxFiles" | "preventDocumentDrop" | "validate" | "onFileChange" | "onFileAccept" | "onFileReject" | "capture" | "directory" | "invalid" | "id" | "locale" | "dir" | "getRootNode")[];
236
+ 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" | "id" | "locale" | "dir" | "getRootNode">];
237
+ declare const itemProps: "file"[];
238
+ 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 };