@zayne-labs/ui-react 0.10.44 → 0.10.46
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/css/theme.css +4 -2
- package/dist/esm/{chunk-BL-4obUL.js → chunk-CpZCTQkd.js} +2 -2
- package/dist/esm/{client-gate-B3fRopBx.js → client-gate-CZczUIeY.js} +3 -3
- package/dist/esm/{client-gate-B3fRopBx.js.map → client-gate-CZczUIeY.js.map} +1 -1
- package/dist/esm/cn-Dnsqr-G7.js.map +1 -1
- package/dist/esm/common/await/index.d.ts +6 -6
- package/dist/esm/common/await/index.js +3 -3
- package/dist/esm/common/await/index.js.map +1 -1
- package/dist/esm/common/client-gate/index.d.ts +6 -6
- package/dist/esm/common/client-gate/index.js +1 -1
- package/dist/esm/common/error-boundary/index.d.ts +2 -2
- package/dist/esm/common/for/index.d.ts +4 -4
- package/dist/esm/common/presence/index.d.ts +4 -4
- package/dist/esm/common/presence/index.js +1 -1
- package/dist/esm/common/show/index.d.ts +4 -4
- package/dist/esm/common/show/index.js +1 -1
- package/dist/esm/common/slot/index.d.ts +4 -4
- package/dist/esm/common/slot/index.js +1 -1
- package/dist/esm/common/suspense-with-boundary/index.d.ts +2 -2
- package/dist/esm/common/switch/index.d.ts +4 -4
- package/dist/esm/common/switch/index.js +2 -2
- package/dist/esm/common/teleport/index.d.ts +3 -3
- package/dist/esm/common/teleport/index.js +7 -2
- package/dist/esm/common/teleport/index.js.map +1 -1
- package/dist/esm/error-boundary-TM4xzQfq.js.map +1 -1
- package/dist/esm/{index-CNsd7z3f.d.ts → index-Bw26wyvy.d.ts} +4 -4
- package/dist/esm/{index-DtTMMfkV.d.ts → index-D3QKG4Tt.d.ts} +9 -9
- package/dist/esm/{presence-Ctp-Trws.js → presence-BTPyxGeW.js} +2 -2
- package/dist/esm/presence-BTPyxGeW.js.map +1 -0
- package/dist/esm/{show-7VInUu_D.js → show-1Md5CZML.js} +3 -3
- package/dist/esm/{show-7VInUu_D.js.map → show-1Md5CZML.js.map} +1 -1
- package/dist/esm/{slot-CURylbjq.js → slot-aKEvaEWn.js} +3 -3
- package/dist/esm/slot-aKEvaEWn.js.map +1 -0
- package/dist/esm/ui/card/index.d.ts +8 -8
- package/dist/esm/ui/card/index.js +3 -3
- package/dist/esm/ui/card/index.js.map +1 -1
- package/dist/esm/ui/carousel/index.d.ts +9 -9
- package/dist/esm/ui/carousel/index.js +3 -3
- package/dist/esm/ui/carousel/index.js.map +1 -1
- package/dist/esm/ui/drag-scroll/index.d.ts +98 -11
- package/dist/esm/ui/drag-scroll/index.js +242 -71
- package/dist/esm/ui/drag-scroll/index.js.map +1 -1
- package/dist/esm/ui/drop-zone/index.d.ts +71 -72
- package/dist/esm/ui/drop-zone/index.js +23 -15
- package/dist/esm/ui/drop-zone/index.js.map +1 -1
- package/dist/esm/ui/form/index.d.ts +22 -23
- package/dist/esm/ui/form/index.js +38 -36
- package/dist/esm/ui/form/index.js.map +1 -1
- package/dist/style.css +9 -2
- package/package.json +13 -9
- package/dist/esm/presence-Ctp-Trws.js.map +0 -1
- package/dist/esm/slot-CURylbjq.js.map +0 -1
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
import { InferProps, PolymorphicPropsStrict } from "@zayne-labs/toolkit-react/utils";
|
|
2
2
|
import * as _zayne_labs_toolkit_type_helpers0 from "@zayne-labs/toolkit-type-helpers";
|
|
3
3
|
import { Awaitable, SelectorFn } from "@zayne-labs/toolkit-type-helpers";
|
|
4
|
-
import * as
|
|
4
|
+
import * as react0 from "react";
|
|
5
5
|
import "@zayne-labs/toolkit-react";
|
|
6
|
-
import * as
|
|
6
|
+
import * as react_jsx_runtime7 from "react/jsx-runtime";
|
|
7
7
|
import * as _zayne_labs_toolkit_core1 from "@zayne-labs/toolkit-core";
|
|
8
8
|
import { FileMeta, FileOrFileMeta, FileValidationErrorContextEach, FileValidationHooksAsync, FileValidationSettingsAsync } from "@zayne-labs/toolkit-core";
|
|
9
9
|
|
|
10
10
|
//#region src/components/ui/drop-zone/drop-zone-store.d.ts
|
|
11
11
|
type RequiredUseDropZoneProps = { [Key in keyof Required<UseDropZoneProps>]: UseDropZoneProps[Key] | undefined };
|
|
12
|
-
type InitStoreValues = Omit<RequiredUseDropZoneProps, "disabled" | "disableFilePickerOpenOnAreaClick" | "disableInternalStateSubscription" | "extraProps"
|
|
13
|
-
inputRef: React.RefObject<HTMLInputElement | null>;
|
|
14
|
-
};
|
|
12
|
+
type InitStoreValues = Omit<RequiredUseDropZoneProps, "disabled" | "disableFilePickerOpenOnAreaClick" | "disableInternalStateSubscription" | "extraProps">;
|
|
15
13
|
declare const createDropZoneStore: (initStoreValues: InitStoreValues) => _zayne_labs_toolkit_core1.StoreApi<DropZoneStore>;
|
|
16
14
|
//#endregion
|
|
17
15
|
//#region src/components/ui/drop-zone/utils.d.ts
|
|
@@ -31,31 +29,31 @@ type FileErrorContext = Omit<FileValidationErrorContextEach, "code"> & {
|
|
|
31
29
|
};
|
|
32
30
|
interface FileState {
|
|
33
31
|
/**
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
32
|
+
* Validation errors for the file
|
|
33
|
+
*
|
|
34
|
+
*/
|
|
37
35
|
error?: FileErrorContext;
|
|
38
36
|
/**
|
|
39
|
-
|
|
40
|
-
|
|
37
|
+
* File object or file metadata
|
|
38
|
+
*/
|
|
41
39
|
file: FileOrFileMeta;
|
|
42
40
|
/**
|
|
43
|
-
|
|
44
|
-
|
|
41
|
+
* Unique ID for the file
|
|
42
|
+
*/
|
|
45
43
|
id: string;
|
|
46
44
|
/**
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
45
|
+
* Preview URL for the file
|
|
46
|
+
* - Will be null if `disallowPreviewForNonImageFiles` is set to `true` and the file is not an image
|
|
47
|
+
* - Can also be null if `URL.createObjectURL` fails
|
|
48
|
+
*/
|
|
51
49
|
preview: string | undefined;
|
|
52
50
|
/**
|
|
53
|
-
|
|
54
|
-
|
|
51
|
+
* Progress of the file upload
|
|
52
|
+
*/
|
|
55
53
|
progress: number;
|
|
56
54
|
/**
|
|
57
|
-
|
|
58
|
-
|
|
55
|
+
* Status of the file upload
|
|
56
|
+
*/
|
|
59
57
|
status: "error" | "idle" | "success" | "uploading";
|
|
60
58
|
}
|
|
61
59
|
type FileStateOrIDProp = {
|
|
@@ -112,20 +110,20 @@ type DropZonePropGetters = { [Key in keyof PartProps as `get${Capitalize<Key>}Pr
|
|
|
112
110
|
type PartInputProps = { [Key in keyof PartProps]: PartProps[Key]["input"] };
|
|
113
111
|
type DropZoneState = {
|
|
114
112
|
/**
|
|
115
|
-
|
|
116
|
-
|
|
113
|
+
* List of validation errors
|
|
114
|
+
*/
|
|
117
115
|
errors: FileErrorContext[];
|
|
118
116
|
/**
|
|
119
|
-
|
|
120
|
-
|
|
117
|
+
* List of files with their preview URLs and unique IDs
|
|
118
|
+
*/
|
|
121
119
|
fileStateArray: FileState[];
|
|
122
120
|
/**
|
|
123
|
-
|
|
124
|
-
|
|
121
|
+
* Whether or not a file is currently being dragged over the drop zone
|
|
122
|
+
*/
|
|
125
123
|
isDraggingOver: boolean;
|
|
126
124
|
/**
|
|
127
|
-
|
|
128
|
-
|
|
125
|
+
* Whether or not any of the files are invalid
|
|
126
|
+
*/
|
|
129
127
|
isInvalid: boolean;
|
|
130
128
|
};
|
|
131
129
|
type DropZoneActions = {
|
|
@@ -146,6 +144,7 @@ type DropZoneActions = {
|
|
|
146
144
|
handlePaste: (event: React.ClipboardEvent<HTMLElement>) => Awaitable<void>;
|
|
147
145
|
openFilePicker: () => void;
|
|
148
146
|
removeFile: (ctx: FileStateOrIDProp) => void;
|
|
147
|
+
setInputRef: (element: HTMLInputElement | null) => void;
|
|
149
148
|
updateFileState: (ctx: FileStateOrIDProp & Partial<Omit<FileState, "file" | "id" | "preview">>) => void;
|
|
150
149
|
};
|
|
151
150
|
};
|
|
@@ -158,41 +157,41 @@ interface UseDropZoneResult extends Pick<Required<UseDropZoneProps>, "disabled"
|
|
|
158
157
|
}
|
|
159
158
|
interface UseDropZoneProps extends FileValidationSettingsAsync {
|
|
160
159
|
/**
|
|
161
|
-
|
|
162
|
-
|
|
160
|
+
* Whether or not the drop zone is disabled
|
|
161
|
+
*/
|
|
163
162
|
disabled?: boolean;
|
|
164
163
|
/**
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
164
|
+
* Whether clicking the drop zone area will open the default file picker or not
|
|
165
|
+
*
|
|
166
|
+
* @default false
|
|
167
|
+
*/
|
|
169
168
|
disableFilePickerOpenOnAreaClick?: boolean;
|
|
170
169
|
/**
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
170
|
+
* Whether to disable the internal state subscription such as drag over state etc for setting things like data attributes
|
|
171
|
+
* - This is useful if you want to subscribe to the state yourself
|
|
172
|
+
* @default false
|
|
173
|
+
*/
|
|
175
174
|
disableInternalStateSubscription?: boolean;
|
|
176
175
|
/**
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
176
|
+
* Whether to disallow preview generation for non-image files
|
|
177
|
+
* @default true
|
|
178
|
+
*/
|
|
180
179
|
disablePreviewGenForNonImageFiles?: boolean;
|
|
181
180
|
/**
|
|
182
|
-
|
|
183
|
-
|
|
181
|
+
* Initial files to populate the drop zone
|
|
182
|
+
*/
|
|
184
183
|
initialFiles?: FileMeta | FileMeta[] | null;
|
|
185
184
|
/**
|
|
186
|
-
|
|
187
|
-
|
|
185
|
+
* Whether to allow multiple files to be uploaded
|
|
186
|
+
*/
|
|
188
187
|
multiple?: boolean;
|
|
189
188
|
/**
|
|
190
|
-
|
|
191
|
-
|
|
189
|
+
* Callback function to be called when internal files state changes
|
|
190
|
+
*/
|
|
192
191
|
onFilesChange?: (context: Pick<DropZoneState, "fileStateArray">) => void;
|
|
193
192
|
/**
|
|
194
|
-
|
|
195
|
-
|
|
193
|
+
* Callback function to be called when new files are uploaded
|
|
194
|
+
*/
|
|
196
195
|
onUpload?: (context: Pick<DropZoneState, "fileStateArray"> & {
|
|
197
196
|
onError: (ctx: FileStateOrIDProp & {
|
|
198
197
|
error: DropZoneError;
|
|
@@ -203,19 +202,19 @@ interface UseDropZoneProps extends FileValidationSettingsAsync {
|
|
|
203
202
|
onSuccess: (ctx: FileStateOrIDProp) => void;
|
|
204
203
|
}) => Awaitable<void>;
|
|
205
204
|
/**
|
|
206
|
-
|
|
207
|
-
|
|
205
|
+
* Callback function to be called on each file validation error as they occur
|
|
206
|
+
*/
|
|
208
207
|
onValidationError?: FileValidationHooksAsync["onErrorEach"];
|
|
209
208
|
/**
|
|
210
|
-
|
|
211
|
-
|
|
209
|
+
* Callback function to be called once after all files have been successfully validated
|
|
210
|
+
*/
|
|
212
211
|
onValidationSuccess?: FileValidationHooksAsync["onSuccessBatch"];
|
|
213
212
|
/**
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
213
|
+
* Custom validation function.
|
|
214
|
+
*
|
|
215
|
+
* If the function returns false, the file will be rejected
|
|
216
|
+
*
|
|
217
|
+
*/
|
|
219
218
|
validator?: FileValidationSettingsAsync["validator"];
|
|
220
219
|
}
|
|
221
220
|
//#endregion
|
|
@@ -223,7 +222,7 @@ interface UseDropZoneProps extends FileValidationSettingsAsync {
|
|
|
223
222
|
declare const DropZoneStoreContextProvider: (props: {
|
|
224
223
|
children: React.ReactNode;
|
|
225
224
|
store: _zayne_labs_toolkit_core1.StoreApi<DropZoneStore>;
|
|
226
|
-
}) =>
|
|
225
|
+
}) => react0.FunctionComponentElement<react0.ProviderProps<_zayne_labs_toolkit_core1.StoreApi<DropZoneStore>>>, useDropZoneStoreContext: <TResult = DropZoneStore>(selector?: _zayne_labs_toolkit_type_helpers0.SelectorFn<DropZoneStore, TResult> | undefined) => TResult;
|
|
227
226
|
type FileItemContextType = {
|
|
228
227
|
fileState: FileState;
|
|
229
228
|
};
|
|
@@ -232,29 +231,29 @@ type FileItemContextType = {
|
|
|
232
231
|
type DropZoneRootProps = UseDropZoneProps & {
|
|
233
232
|
children: React.ReactNode;
|
|
234
233
|
};
|
|
235
|
-
declare function DropZoneRoot(props: DropZoneRootProps):
|
|
234
|
+
declare function DropZoneRoot(props: DropZoneRootProps): react_jsx_runtime7.JSX.Element;
|
|
236
235
|
type DropZoneContextProps<TSlice> = {
|
|
237
236
|
children: React.ReactNode | ((context: TSlice) => React.ReactNode);
|
|
238
237
|
selector?: SelectorFn<DropZoneStore, TSlice>;
|
|
239
238
|
};
|
|
240
|
-
declare function DropZoneContext<TSlice = DropZoneStore>(props: DropZoneContextProps<TSlice>):
|
|
239
|
+
declare function DropZoneContext<TSlice = DropZoneStore>(props: DropZoneContextProps<TSlice>): react0.ReactNode;
|
|
241
240
|
type DropZoneContainerProps = PartInputProps["container"] & {
|
|
242
241
|
asChild?: boolean;
|
|
243
242
|
};
|
|
244
|
-
declare function DropZoneContainer<TElement extends React.ElementType = "div">(props: PolymorphicPropsStrict<TElement, DropZoneContainerProps>):
|
|
243
|
+
declare function DropZoneContainer<TElement extends React.ElementType = "div">(props: PolymorphicPropsStrict<TElement, DropZoneContainerProps>): react_jsx_runtime7.JSX.Element;
|
|
245
244
|
type DropZoneInputProps = PartInputProps["input"] & {
|
|
246
245
|
asChild?: boolean;
|
|
247
246
|
};
|
|
248
|
-
declare function DropZoneInput(props: DropZoneInputProps):
|
|
247
|
+
declare function DropZoneInput(props: DropZoneInputProps): react_jsx_runtime7.JSX.Element;
|
|
249
248
|
type DropZoneAreaProps<TSlice> = DropZoneContextProps<TSlice> & PartInputProps["container"] & {
|
|
250
249
|
classNames?: Partial<Record<Extract<keyof PartInputProps, "container" | "input">, string>>;
|
|
251
250
|
extraProps?: Partial<Pick<PartInputProps, "container" | "input">>;
|
|
252
251
|
};
|
|
253
|
-
declare function DropZoneArea<TSlice = DropZoneStore>(props: DropZoneAreaProps<TSlice>):
|
|
252
|
+
declare function DropZoneArea<TSlice = DropZoneStore>(props: DropZoneAreaProps<TSlice>): react_jsx_runtime7.JSX.Element;
|
|
254
253
|
type DropZoneTriggerProps = PartInputProps["trigger"] & {
|
|
255
254
|
asChild?: boolean;
|
|
256
255
|
};
|
|
257
|
-
declare function DropZoneTrigger(props: DropZoneTriggerProps):
|
|
256
|
+
declare function DropZoneTrigger(props: DropZoneTriggerProps): react_jsx_runtime7.JSX.Element;
|
|
258
257
|
type ListPerItemContext = Pick<DropZoneStore, "actions"> & {
|
|
259
258
|
array: DropZoneStore["fileStateArray"];
|
|
260
259
|
fileState: DropZoneStore["fileStateArray"][number];
|
|
@@ -273,21 +272,21 @@ type DropZoneFileListProps = Omit<PartInputProps["fileList"], "children"> & {
|
|
|
273
272
|
asChild?: boolean;
|
|
274
273
|
forceMount?: boolean;
|
|
275
274
|
} & (FileListManualListVariant | FileListPerItemVariant);
|
|
276
|
-
declare function DropZoneFileList<TElement extends React.ElementType = "ul">(props: PolymorphicPropsStrict<TElement, DropZoneFileListProps>):
|
|
275
|
+
declare function DropZoneFileList<TElement extends React.ElementType = "ul">(props: PolymorphicPropsStrict<TElement, DropZoneFileListProps>): react_jsx_runtime7.JSX.Element;
|
|
277
276
|
type DropZoneFileItemProps = FileItemContextType & PartInputProps["fileItem"] & {
|
|
278
277
|
asChild?: boolean;
|
|
279
278
|
};
|
|
280
|
-
declare function DropZoneFileItem<TElement extends React.ElementType = "li">(props: PolymorphicPropsStrict<TElement, DropZoneFileItemProps>):
|
|
279
|
+
declare function DropZoneFileItem<TElement extends React.ElementType = "li">(props: PolymorphicPropsStrict<TElement, DropZoneFileItemProps>): react_jsx_runtime7.JSX.Element;
|
|
281
280
|
type DropZoneFileItemDeleteProps = PartInputProps["fileItemDelete"] & {
|
|
282
281
|
asChild?: boolean;
|
|
283
282
|
};
|
|
284
|
-
declare function DropZoneFileItemDelete(props: DropZoneFileItemDeleteProps):
|
|
283
|
+
declare function DropZoneFileItemDelete(props: DropZoneFileItemDeleteProps): react_jsx_runtime7.JSX.Element;
|
|
285
284
|
type DropZoneFileItemProgressProps = PartInputProps["fileItemProgress"] & {
|
|
286
285
|
asChild?: boolean;
|
|
287
286
|
forceMount?: boolean;
|
|
288
287
|
size?: number;
|
|
289
288
|
};
|
|
290
|
-
declare function DropZoneFileItemProgress<TElement extends React.ElementType = "span">(props: PolymorphicPropsStrict<TElement, DropZoneFileItemProgressProps>):
|
|
289
|
+
declare function DropZoneFileItemProgress<TElement extends React.ElementType = "span">(props: PolymorphicPropsStrict<TElement, DropZoneFileItemProgressProps>): react_jsx_runtime7.JSX.Element | null;
|
|
291
290
|
type RenderPreviewDetails<TElement extends React.ElementType = "svg"> = {
|
|
292
291
|
node?: React.ReactNode;
|
|
293
292
|
} & {
|
|
@@ -316,7 +315,7 @@ type DropZoneFileItemPreviewProps = Omit<PartInputProps["fileItemPreview"], "chi
|
|
|
316
315
|
}) => React.ReactNode);
|
|
317
316
|
renderPreview?: boolean | RenderPreview;
|
|
318
317
|
};
|
|
319
|
-
declare function DropZoneFileItemPreview<TElement extends React.ElementType>(props: PolymorphicPropsStrict<TElement, DropZoneFileItemPreviewProps>):
|
|
318
|
+
declare function DropZoneFileItemPreview<TElement extends React.ElementType>(props: PolymorphicPropsStrict<TElement, DropZoneFileItemPreviewProps>): react_jsx_runtime7.JSX.Element | null;
|
|
320
319
|
type DropZoneFileItemMetadataProps = Omit<PartInputProps["fileItemMetadata"], "children"> & Partial<Pick<FileItemContextType, "fileState">> & {
|
|
321
320
|
asChild?: boolean;
|
|
322
321
|
children?: React.ReactNode | ((context: Pick<FileItemContextType, "fileState">) => React.ReactNode);
|
|
@@ -326,12 +325,12 @@ type DropZoneFileItemMetadataProps = Omit<PartInputProps["fileItemMetadata"], "c
|
|
|
326
325
|
};
|
|
327
326
|
size?: "default" | "sm";
|
|
328
327
|
};
|
|
329
|
-
declare function DropZoneFileItemMetadata(props: DropZoneFileItemMetadataProps):
|
|
328
|
+
declare function DropZoneFileItemMetadata(props: DropZoneFileItemMetadataProps): react_jsx_runtime7.JSX.Element | null;
|
|
330
329
|
type DropZoneFileClearProps = PartInputProps["fileItemClear"] & {
|
|
331
330
|
asChild?: boolean;
|
|
332
331
|
forceMount?: boolean;
|
|
333
332
|
};
|
|
334
|
-
declare function DropZoneFileClear(props: DropZoneFileClearProps):
|
|
333
|
+
declare function DropZoneFileClear(props: DropZoneFileClearProps): react_jsx_runtime7.JSX.Element | null;
|
|
335
334
|
declare namespace drop_zone_parts_d_exports {
|
|
336
335
|
export { DropZoneArea as Area, DropZoneContainer as Container, DropZoneContext as Context, DropZoneFileClear as FileClear, DropZoneFileItem as FileItem, DropZoneFileItemDelete as FileItemDelete, DropZoneFileItemMetadata as FileItemMetadata, DropZoneFileItemPreview as FileItemPreview, DropZoneFileItemProgress as FileItemProgress, DropZoneFileList as FileList, DropZoneInput as Input, DropZoneRoot as Root, DropZoneTrigger as Trigger };
|
|
337
336
|
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
import { t as
|
|
4
|
-
import { n as SlotRoot } from "../../slot-
|
|
3
|
+
import { t as __exportAll } from "../../chunk-CpZCTQkd.js";
|
|
4
|
+
import { n as SlotRoot } from "../../slot-aKEvaEWn.js";
|
|
5
5
|
import { n as For } from "../../for-BeCRb3k2.js";
|
|
6
|
-
import { t as Presence } from "../../presence-
|
|
6
|
+
import { t as Presence } from "../../presence-BTPyxGeW.js";
|
|
7
7
|
import { t as cnMerge } from "../../cn-Dnsqr-G7.js";
|
|
8
8
|
import { composeRefs, composeTwoEventHandlers } from "@zayne-labs/toolkit-react/utils";
|
|
9
9
|
import { isBoolean, isFile, isFunction, isNumber, isObject, isString } from "@zayne-labs/toolkit-type-helpers";
|
|
10
10
|
import { useCallback, useMemo, useRef } from "react";
|
|
11
|
-
import { createCustomContext, useCallbackRef,
|
|
11
|
+
import { createCustomContext, useCallbackRef, useCompareSelector, useCompareValue, useConstant, useStore, useUnmountEffect } from "@zayne-labs/toolkit-react";
|
|
12
12
|
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
13
13
|
import { createFileURL, createStore, dataAttr, formatBytes, generateFileID, handleFileValidationAsync, toArray } from "@zayne-labs/toolkit-core";
|
|
14
14
|
import { createReactStoreContext } from "@zayne-labs/toolkit-react/zustand";
|
|
@@ -221,7 +221,8 @@ const getErrorContext = (error) => {
|
|
|
221
221
|
//#endregion
|
|
222
222
|
//#region src/components/ui/drop-zone/drop-zone-store.ts
|
|
223
223
|
const createDropZoneStore = (initStoreValues) => {
|
|
224
|
-
const { allowedFileTypes, disablePreviewGenForNonImageFiles, initialFiles,
|
|
224
|
+
const { allowedFileTypes, disablePreviewGenForNonImageFiles, initialFiles, maxFileCount, maxFileSize, multiple, onFilesChange, onUpload, onValidationError, onValidationSuccess, rejectDuplicateFiles, validator } = initStoreValues;
|
|
225
|
+
const inputRef = { current: null };
|
|
225
226
|
const initialFileArray = toArray(initialFiles).filter(Boolean);
|
|
226
227
|
const clearInputValue = () => {
|
|
227
228
|
if (!inputRef.current) return;
|
|
@@ -411,6 +412,9 @@ const createDropZoneStore = (initStoreValues) => {
|
|
|
411
412
|
})
|
|
412
413
|
});
|
|
413
414
|
},
|
|
415
|
+
setInputRef: (element) => {
|
|
416
|
+
inputRef.current = element;
|
|
417
|
+
},
|
|
414
418
|
updateFileState: (ctx) => {
|
|
415
419
|
const { fileStateOrID, ...updatedFileState } = ctx;
|
|
416
420
|
const { fileStateArray } = get();
|
|
@@ -447,14 +451,13 @@ const useDropZone = (props) => {
|
|
|
447
451
|
const stableOnUploadSuccess = useCallbackRef(onValidationSuccess);
|
|
448
452
|
const stableValidator = useCallbackRef(validator);
|
|
449
453
|
const constantInitialFiles = useConstant(() => initialFiles);
|
|
450
|
-
const shallowComparedMaxFileSize =
|
|
451
|
-
const shallowComparedAllowedFileTypes =
|
|
454
|
+
const shallowComparedMaxFileSize = useCompareValue(maxFileSize);
|
|
455
|
+
const shallowComparedAllowedFileTypes = useCompareValue(allowedFileTypes);
|
|
452
456
|
const storeApi = useMemo(() => {
|
|
453
457
|
return createDropZoneStore({
|
|
454
458
|
allowedFileTypes: shallowComparedAllowedFileTypes,
|
|
455
459
|
disablePreviewGenForNonImageFiles,
|
|
456
460
|
initialFiles: constantInitialFiles,
|
|
457
|
-
inputRef,
|
|
458
461
|
maxFileCount,
|
|
459
462
|
maxFileSize: shallowComparedMaxFileSize,
|
|
460
463
|
multiple,
|
|
@@ -532,6 +535,10 @@ const useDropZone = (props) => {
|
|
|
532
535
|
isInvalid,
|
|
533
536
|
disableFilePickerOpenOnAreaClick
|
|
534
537
|
]);
|
|
538
|
+
const refCallback = useCallbackRef((node) => {
|
|
539
|
+
inputRef.current = node;
|
|
540
|
+
actions.setInputRef(node);
|
|
541
|
+
});
|
|
535
542
|
const getInputProps = useCallback((innerProps) => {
|
|
536
543
|
const isDisabled = innerProps.disabled ?? disabled;
|
|
537
544
|
const onFileChange = !isDisabled ? actions.handleChange : void 0;
|
|
@@ -545,7 +552,7 @@ const useDropZone = (props) => {
|
|
|
545
552
|
disabled: isDisabled,
|
|
546
553
|
multiple: multiple ?? innerProps.multiple,
|
|
547
554
|
onChange: composeTwoEventHandlers(onFileChange, innerProps.onChange),
|
|
548
|
-
ref: composeRefs(
|
|
555
|
+
ref: composeRefs(refCallback, innerProps.ref),
|
|
549
556
|
type: "file"
|
|
550
557
|
};
|
|
551
558
|
}, [
|
|
@@ -554,7 +561,8 @@ const useDropZone = (props) => {
|
|
|
554
561
|
disableInternalStateSubscription,
|
|
555
562
|
disabled,
|
|
556
563
|
isDraggingOver,
|
|
557
|
-
multiple
|
|
564
|
+
multiple,
|
|
565
|
+
refCallback
|
|
558
566
|
]);
|
|
559
567
|
const getTriggerProps = useCallback((innerProps) => {
|
|
560
568
|
const isDisabled = innerProps.disabled ?? disabled;
|
|
@@ -656,20 +664,20 @@ const useDropZone = (props) => {
|
|
|
656
664
|
getInputProps,
|
|
657
665
|
getTriggerProps
|
|
658
666
|
]);
|
|
659
|
-
const
|
|
667
|
+
const stableUseDropZoneStore = useCallbackRef(useDropZoneStore);
|
|
660
668
|
return useMemo(() => ({
|
|
661
669
|
disabled,
|
|
662
670
|
disableInternalStateSubscription,
|
|
663
671
|
inputRef,
|
|
664
672
|
propGetters,
|
|
665
673
|
storeApi,
|
|
666
|
-
useDropZoneStore:
|
|
674
|
+
useDropZoneStore: stableUseDropZoneStore
|
|
667
675
|
}), [
|
|
668
676
|
disabled,
|
|
669
677
|
disableInternalStateSubscription,
|
|
670
678
|
propGetters,
|
|
671
679
|
storeApi,
|
|
672
|
-
|
|
680
|
+
stableUseDropZoneStore
|
|
673
681
|
]);
|
|
674
682
|
};
|
|
675
683
|
|
|
@@ -698,7 +706,7 @@ function DropZoneRoot(props) {
|
|
|
698
706
|
}
|
|
699
707
|
function DropZoneContext(props) {
|
|
700
708
|
const { children, selector } = props;
|
|
701
|
-
const dropZoneCtx = useDropZoneStoreContext(
|
|
709
|
+
const dropZoneCtx = useDropZoneStoreContext(useCompareSelector(selector));
|
|
702
710
|
return isFunction(children) ? children(dropZoneCtx) : children;
|
|
703
711
|
}
|
|
704
712
|
function DropZoneContainer(props) {
|
|
@@ -992,7 +1000,7 @@ function DropZoneFileClear(props) {
|
|
|
992
1000
|
|
|
993
1001
|
//#endregion
|
|
994
1002
|
//#region src/components/ui/drop-zone/drop-zone-parts.ts
|
|
995
|
-
var drop_zone_parts_exports = /* @__PURE__ */
|
|
1003
|
+
var drop_zone_parts_exports = /* @__PURE__ */ __exportAll({
|
|
996
1004
|
Area: () => DropZoneArea,
|
|
997
1005
|
Container: () => DropZoneContainer,
|
|
998
1006
|
Context: () => DropZoneContext,
|