@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 CHANGED
@@ -1,240 +1,252 @@
1
- import * as _zag_js_anatomy from '@zag-js/anatomy';
2
- import { LocaleProperties, CommonProperties, PropTypes, RequiredBy, NormalizeProps } from '@zag-js/types';
3
- import * as _zag_js_core from '@zag-js/core';
4
- import { StateMachine, Machine } from '@zag-js/core';
5
- import { FileMimeType, FileError } 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">;
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
- file: File;
12
- errors: FileError[];
12
+ file: File;
13
+ errors: FileError[];
13
14
  }
14
15
  interface FileChangeDetails {
15
- acceptedFiles: File[];
16
- rejectedFiles: FileRejection[];
16
+ acceptedFiles: File[];
17
+ rejectedFiles: FileRejection[];
17
18
  }
18
19
  interface FileValidateDetails {
19
- acceptedFiles: File[];
20
- rejectedFiles: FileRejection[];
20
+ acceptedFiles: File[];
21
+ rejectedFiles: FileRejection[];
21
22
  }
22
23
  interface FileAcceptDetails {
23
- files: File[];
24
+ files: File[];
24
25
  }
25
26
  interface FileRejectDetails {
26
- files: FileRejection[];
27
+ files: FileRejection[];
27
28
  }
28
-
29
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;
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
- dropzone?: string | undefined;
42
- itemPreview?: (file: File) => string;
43
- deleteFile?: (file: File) => string;
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
- * 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;
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
- * @internal
129
- * The rejected files
130
- */
131
- rejectedFiles: FileRejection[];
132
- /**
133
- * @internal
134
- * The current value of the file input
135
- */
136
- acceptedFiles: File[];
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
- * @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;
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
- value: 'idle' | 'focused' | 'open' | 'dragging';
153
+ value: 'idle' | 'focused' | 'open' | 'dragging';
155
154
  }
156
- type State = StateMachine.State<MachineContext, MachineState>;
157
- type Send = StateMachine.Send<StateMachine.AnyEventObject>;
158
- type Service = Machine<MachineContext, MachineState, StateMachine.AnyEventObject>;
155
+ type State = XState<MachineContext, MachineState>;
156
+ type Send = XSend<AnyEventObject>;
157
+ type Service = Machine<MachineContext, MachineState, AnyEventObject>;
159
158
  interface ItemProps {
160
- file: File;
159
+ file: File;
161
160
  }
162
161
  interface ItemPreviewImageProps extends ItemProps {
163
- url: string;
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
- * 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'];
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
- 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">];
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 };