@zayne-labs/ui-react 0.8.4 → 0.8.6

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.
@@ -1,6 +1,6 @@
1
1
  import * as react from 'react';
2
2
  import { DiscriminatedRenderProps, InferProps, GetSlotComponentProps } from '@zayne-labs/toolkit-react/utils';
3
- import { FileValidationErrorContext, FileMeta, FileValidationOptions } from '@zayne-labs/toolkit-core';
3
+ import { FileMeta, FileValidationErrorContext, FileValidationOptions } from '@zayne-labs/toolkit-core';
4
4
  import { Prettify } from '@zayne-labs/toolkit-type-helpers';
5
5
 
6
6
  type RootProps = InferProps<HTMLElement> & {
@@ -11,35 +11,59 @@ type RootProps = InferProps<HTMLElement> & {
11
11
  };
12
12
  type InputProps = InferProps<"input">;
13
13
  type FileWithPreview = {
14
+ /**
15
+ * File object or file metadata
16
+ */
14
17
  file: File | FileMeta;
18
+ /**
19
+ * Unique ID for the file
20
+ */
15
21
  id: string;
16
- preview?: string;
22
+ /**
23
+ * Preview URL for the file
24
+ * - Will be undefined if `disallowPreviewForNonImageFiles` is set to `true` and the file is not an image
25
+ * - Can also be undefined if `URL.createObjectURL` fails
26
+ */
27
+ preview: string | undefined;
17
28
  };
18
- type FileUploadState = {
29
+ type DropZoneState = {
30
+ /**
31
+ * List of validation errors
32
+ */
19
33
  errors: FileValidationErrorContext[];
34
+ /**
35
+ * List of files with their preview URLs and unique IDs
36
+ */
20
37
  filesWithPreview: FileWithPreview[];
38
+ /**
39
+ * Whether or not a file is currently being dragged over the drop zone
40
+ */
21
41
  isDragging: boolean;
22
42
  };
23
43
  type ChangeOrDragEvent = React.ChangeEvent<HTMLInputElement> | React.DragEvent<HTMLElement>;
24
- type UseDropZoneResult = {
44
+ type DropZoneActions = {
25
45
  addFiles: (fileList: File[] | FileList | null, event?: ChangeOrDragEvent) => void;
26
46
  clearErrors: () => void;
27
47
  clearFiles: () => void;
28
- dropZoneState: FileUploadState;
29
- getInputProps: (inputProps?: InputProps) => InputProps;
30
- getResolvedChildren: () => React.ReactNode;
31
- getRootProps: (rootProps?: RootProps) => RootProps;
32
48
  handleDragEnter: (event: React.DragEvent<HTMLElement>) => void;
33
49
  handleDragLeave: (event: React.DragEvent<HTMLElement>) => void;
34
50
  handleDragOver: (event: React.DragEvent<HTMLElement>) => void;
35
- handleFileUpload: (event: React.ChangeEvent<HTMLInputElement> | React.DragEvent<HTMLElement>) => void;
36
- inputRef: React.RefObject<HTMLInputElement | null>;
51
+ handleFileUpload: (event: ChangeOrDragEvent) => void;
37
52
  openFilePicker: () => void;
38
- removeFile: (id: string) => void;
53
+ removeFile: (fileToRemoveOrId: string | FileWithPreview) => void;
54
+ };
55
+ type RenderProps = {
56
+ dropZoneActions: DropZoneActions;
57
+ dropZoneState: DropZoneState;
58
+ getInputProps: (inputProps?: InputProps) => InputProps;
59
+ getRootProps: (rootProps?: RootProps) => RootProps;
60
+ inputRef: React.RefObject<HTMLInputElement | null>;
61
+ };
62
+ type DropZoneResult = RenderProps & {
63
+ getResolvedChildren: () => React.ReactNode;
39
64
  };
40
- type RenderProps = Omit<UseDropZoneResult, "getResolvedChildren">;
41
65
  type DropZoneRenderProps = DiscriminatedRenderProps<React.ReactNode | ((props: RenderProps) => React.ReactNode)>;
42
- type UseDropZoneProps = DropZoneRenderProps & {
66
+ type DropZoneProps = DropZoneRenderProps & {
43
67
  /**
44
68
  * Allowed file types to be uploaded.
45
69
  */
@@ -55,6 +79,11 @@ type UseDropZoneProps = DropZoneRenderProps & {
55
79
  * @default true
56
80
  */
57
81
  disallowDuplicates?: boolean;
82
+ /**
83
+ * Whether to disallow preview for non-image files
84
+ * @default true
85
+ */
86
+ disallowPreviewForNonImageFiles?: boolean;
58
87
  /**
59
88
  * Extra props to pass to the input element
60
89
  */
@@ -109,15 +138,15 @@ type UseDropZoneProps = DropZoneRenderProps & {
109
138
  */
110
139
  validator?: FileValidationOptions["validator"];
111
140
  };
112
- declare const useDropZone: (props?: UseDropZoneProps) => UseDropZoneResult;
141
+ declare const useDropZone: (props?: DropZoneProps) => DropZoneResult;
113
142
 
114
- type DropZoneProps = UseDropZoneProps & {
143
+ type DropZoneWrapperProps = DropZoneProps & {
115
144
  /**
116
145
  * Controls whether to include internal elements (root and input) or not.
117
146
  */
118
147
  withInternalElements?: boolean;
119
148
  };
120
- declare function DropZoneRoot(props: DropZoneProps): react.JSX.Element;
149
+ declare function DropZoneRoot(props: DropZoneWrapperProps): react.JSX.Element;
121
150
  declare const DropZoneImagePreview: {
122
151
  (props: Pick<GetSlotComponentProps<string, react.ReactNode>, "children"> & Record<string, unknown>): react.ReactNode;
123
152
  readonly slotName?: "preview" | undefined;
@@ -128,4 +157,4 @@ declare namespace dropZoneParts {
128
157
  export { DropZoneImagePreview as ImagePreview, DropZoneRoot as Root };
129
158
  }
130
159
 
131
- export { dropZoneParts as DropZone, DropZoneImagePreview, DropZoneRoot, type FileUploadState, type FileWithPreview, type InputProps, type RootProps, type UseDropZoneProps, useDropZone };
160
+ export { dropZoneParts as DropZone, type DropZoneActions, DropZoneImagePreview, type DropZoneProps, type DropZoneResult, DropZoneRoot, type DropZoneState, type FileWithPreview, type InputProps, type RenderProps, type RootProps, useDropZone };
@@ -4,7 +4,7 @@ import { __export } from '../../chunk-PZ5AY32C.js';
4
4
  import * as React from 'react';
5
5
  import { isValidElement, Fragment, useRef, useState, useCallback } from 'react';
6
6
  import { withSlotNameAndSymbol, getSlotMap, mergeTwoProps, composeRefs } from '@zayne-labs/toolkit-react/utils';
7
- import { isArray, isFile, isFunction } from '@zayne-labs/toolkit-type-helpers';
7
+ import { isArray, isString, isFile, isFunction } from '@zayne-labs/toolkit-type-helpers';
8
8
  import { toArray, handleFileValidation, createImagePreview } from '@zayne-labs/toolkit-core';
9
9
  import { useCallbackRef } from '@zayne-labs/toolkit-react';
10
10
 
@@ -14,11 +14,15 @@ var generateUniqueId = (file) => {
14
14
  }
15
15
  return `${file.name}-(${Math.round(performance.now())})-${crypto.randomUUID().slice(0, 8)}`;
16
16
  };
17
- var clearObjectURL = (fileObject) => {
18
- const shouldClearObjectURL = isFile(fileObject?.file) && fileObject.file.type.startsWith("image/");
19
- if (fileObject?.preview && shouldClearObjectURL) {
20
- URL.revokeObjectURL(fileObject.preview);
21
- }
17
+ var createObjectURL = (file, disallowPreviewForNonImageFiles) => {
18
+ if (disallowPreviewForNonImageFiles && !file.type.startsWith("image/")) return;
19
+ return createImagePreview(file);
20
+ };
21
+ var clearObjectURL = (fileWithPreview, disallowPreviewForNonImageFiles) => {
22
+ if (!isFile(fileWithPreview?.file)) return;
23
+ if (disallowPreviewForNonImageFiles && !fileWithPreview.file.type.startsWith("image/")) return;
24
+ if (!fileWithPreview.preview) return;
25
+ URL.revokeObjectURL(fileWithPreview.preview);
22
26
  };
23
27
 
24
28
  // src/components/ui/drop-zone/use-drop-zone.ts
@@ -28,6 +32,7 @@ var useDropZone = (props) => {
28
32
  children,
29
33
  classNames,
30
34
  disallowDuplicates = true,
35
+ disallowPreviewForNonImageFiles = true,
31
36
  extraInputProps,
32
37
  extraRootProps,
33
38
  initialFiles,
@@ -81,7 +86,7 @@ var useDropZone = (props) => {
81
86
  const filesWithPreview = validFiles.map((file) => ({
82
87
  file,
83
88
  id: generateUniqueId(file),
84
- preview: createImagePreview({ file })
89
+ preview: createObjectURL(file, disallowPreviewForNonImageFiles)
85
90
  }));
86
91
  if (event) {
87
92
  onUpload?.({ event, filesWithPreview });
@@ -97,7 +102,9 @@ var useDropZone = (props) => {
97
102
  inputRef.current && (inputRef.current.value = "");
98
103
  });
99
104
  const clearFiles = useCallbackRef(() => {
100
- dropZoneState.filesWithPreview.forEach((fileObject) => clearObjectURL(fileObject));
105
+ dropZoneState.filesWithPreview.forEach(
106
+ (fileWithPreview) => clearObjectURL(fileWithPreview, disallowPreviewForNonImageFiles)
107
+ );
101
108
  const newFileUploadState = {
102
109
  ...dropZoneState,
103
110
  errors: [],
@@ -107,10 +114,13 @@ var useDropZone = (props) => {
107
114
  setDropZoneState(newFileUploadState);
108
115
  inputRef.current && (inputRef.current.value = "");
109
116
  });
110
- const removeFile = useCallbackRef((id) => {
111
- const fileToRemove = dropZoneState.filesWithPreview.find((fileObject) => fileObject.id === id);
112
- clearObjectURL(fileToRemove);
113
- const newFilesWithPreview = dropZoneState.filesWithPreview.filter((file) => file.id !== id);
117
+ const removeFile = useCallbackRef((fileToRemoveOrId) => {
118
+ const actualFileToRemove = isString(fileToRemoveOrId) ? dropZoneState.filesWithPreview.find((file) => file.id === fileToRemoveOrId) : fileToRemoveOrId;
119
+ if (!actualFileToRemove) return;
120
+ clearObjectURL(actualFileToRemove, disallowPreviewForNonImageFiles);
121
+ const newFilesWithPreview = dropZoneState.filesWithPreview.filter(
122
+ (file) => file.id !== actualFileToRemove.id
123
+ );
114
124
  onFilesChange?.({ filesWithPreview: newFilesWithPreview });
115
125
  setDropZoneState({
116
126
  ...dropZoneState,
@@ -226,19 +236,21 @@ var useDropZone = (props) => {
226
236
  ]
227
237
  );
228
238
  const renderProps = {
229
- addFiles,
230
- clearErrors,
231
- clearFiles,
239
+ dropZoneActions: {
240
+ addFiles,
241
+ clearErrors,
242
+ clearFiles,
243
+ handleDragEnter,
244
+ handleDragLeave,
245
+ handleDragOver,
246
+ handleFileUpload,
247
+ openFilePicker,
248
+ removeFile
249
+ },
232
250
  dropZoneState,
233
251
  getInputProps,
234
252
  getRootProps,
235
- handleDragEnter,
236
- handleDragLeave,
237
- handleDragOver,
238
- handleFileUpload,
239
- inputRef,
240
- openFilePicker,
241
- removeFile
253
+ inputRef
242
254
  };
243
255
  const selectedChildren = children ?? render;
244
256
  const getResolvedChildren = () => {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/components/ui/drop-zone/utils.ts","../../../../src/components/ui/drop-zone/use-drop-zone.ts","../../../../src/components/ui/drop-zone/drop-zone.tsx","../../../../src/components/ui/drop-zone/drop-zone-parts.ts"],"names":["ReactFragment"],"mappings":";;;;;;;;;;AAIO,IAAM,gBAAA,GAAmB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jD,EAAM,MAAA,yBAAA,GACL,QAAQ,gBAAgB,CAAA,IACpB,eAAe,gBAAgB,CAAA,IAAK,iBAAiB,IAAS,KAAAA,QAAA;AAEnE,EAAM,MAAA,KAAA,GAAQ,WAA+B,gBAAkB,EAAA;AAAA,IAC9D,WAAW,oBAAwB,IAAA;AAAA,GACnC,CAAA;AAED,EAAA,uBAEE,KAAA,CAAA,aAAA,CAAA,KAAA,CAAA,QAAA,EAAA,IAAA,kBAAA,KAAA,CAAA,aAAA,CAAC,aAAe,EAAA,EAAA,GAAG,sCACjB,KAAA,CAAA,aAAA,CAAA,cAAA,EAAA,EAAgB,GAAG,mBAAA,EAAqB,CAExC,EAAA,KAAA,CAAM,OACR,CAAA,EAEC,MAAM,OACR,CAAA;AAEF;AAIa,IAAA,oBAAA,GAAuB,sBAA0C,SAAS;;;AC3DvF,IAAA,uBAAA,GAAA;AAAA,QAAA,CAAA,uBAAA,EAAA;AAAA,EAAA,YAAA,EAAA,MAAA,oBAAA;AAAA,EAAA,IAAA,EAAA,MAAA;AAAA,CAAA,CAAA","file":"index.js","sourcesContent":["import type { FileMeta } from \"@zayne-labs/toolkit-core\";\nimport { isFile } from \"@zayne-labs/toolkit-type-helpers\";\nimport type { FileWithPreview } from \"./use-drop-zone\";\n\nexport const generateUniqueId = (file: File | FileMeta): string => {\n\tif (!isFile(file)) {\n\t\treturn file.id;\n\t}\n\n\treturn `${file.name}-(${Math.round(performance.now())})-${crypto.randomUUID().slice(0, 8)}`;\n};\n\nexport const clearObjectURL = (fileObject: FileWithPreview | undefined) => {\n\tconst shouldClearObjectURL = isFile(fileObject?.file) && fileObject.file.type.startsWith(\"image/\");\n\n\tif (fileObject?.preview && shouldClearObjectURL) {\n\t\tURL.revokeObjectURL(fileObject.preview);\n\t}\n};\n","import { cnMerge } from \"@/lib/utils/cn\";\nimport { dataAttr } from \"@/lib/utils/common\";\nimport { toArray } from \"@zayne-labs/toolkit-core\";\nimport {\n\ttype FileMeta,\n\ttype FileValidationErrorContext,\n\ttype FileValidationOptions,\n\tcreateImagePreview,\n\thandleFileValidation,\n} from \"@zayne-labs/toolkit-core\";\nimport { useCallbackRef } from \"@zayne-labs/toolkit-react\";\nimport {\n\ttype DiscriminatedRenderProps,\n\ttype InferProps,\n\tcomposeRefs,\n\tmergeTwoProps,\n} from \"@zayne-labs/toolkit-react/utils\";\nimport { type Prettify, isFunction } from \"@zayne-labs/toolkit-type-helpers\";\nimport { useCallback, useRef, useState } from \"react\";\nimport { clearObjectURL, generateUniqueId } from \"./utils\";\n\nexport type RootProps = InferProps<HTMLElement> & {\n\tclassNames?: {\n\t\tbase?: string;\n\t\tisDragging?: string;\n\t};\n};\n\nexport type InputProps = InferProps<\"input\">;\n\nexport type FileWithPreview = {\n\tfile: File | FileMeta;\n\tid: string;\n\tpreview?: string;\n};\n\nexport type FileUploadState = {\n\terrors: FileValidationErrorContext[];\n\tfilesWithPreview: FileWithPreview[];\n\tisDragging: boolean;\n};\n\ntype ChangeOrDragEvent = React.ChangeEvent<HTMLInputElement> | React.DragEvent<HTMLElement>;\n\ntype UseDropZoneResult = {\n\taddFiles: (fileList: File[] | FileList | null, event?: ChangeOrDragEvent) => void;\n\tclearErrors: () => void;\n\tclearFiles: () => void;\n\tdropZoneState: FileUploadState;\n\tgetInputProps: (inputProps?: InputProps) => InputProps;\n\tgetResolvedChildren: () => React.ReactNode;\n\tgetRootProps: (rootProps?: RootProps) => RootProps;\n\thandleDragEnter: (event: React.DragEvent<HTMLElement>) => void;\n\thandleDragLeave: (event: React.DragEvent<HTMLElement>) => void;\n\thandleDragOver: (event: React.DragEvent<HTMLElement>) => void;\n\thandleFileUpload: (event: React.ChangeEvent<HTMLInputElement> | React.DragEvent<HTMLElement>) => void;\n\tinputRef: React.RefObject<HTMLInputElement | null>;\n\topenFilePicker: () => void;\n\tremoveFile: (id: string) => void;\n};\n\ntype RenderProps = Omit<UseDropZoneResult, \"getResolvedChildren\">;\n\ntype DropZoneRenderProps = DiscriminatedRenderProps<\n\tReact.ReactNode | ((props: RenderProps) => React.ReactNode)\n>;\n\nexport type UseDropZoneProps = DropZoneRenderProps & {\n\t/**\n\t * Allowed file types to be uploaded.\n\t */\n\tallowedFileTypes?: string[];\n\n\t/**\n\t * CSS classes to apply to the various parts of the drop zone\n\t */\n\tclassNames?: Prettify<RootProps[\"classNames\"] & { input?: string }>;\n\n\t/**\n\t * Whether to disallow duplicate files\n\t * @default true\n\t */\n\tdisallowDuplicates?: boolean;\n\n\t/**\n\t * Extra props to pass to the input element\n\t */\n\textraInputProps?: InputProps;\n\n\t/**\n\t * Extra props to pass to the root element\n\t */\n\textraRootProps?: RootProps;\n\n\t/**\n\t * Initial files to populate the drop zone\n\t */\n\tinitialFiles?: FileMeta | FileMeta[] | null;\n\n\t/**\n\t * Maximum number of files that can be uploaded.\n\t */\n\tmaxFileCount?: number;\n\n\t/**\n\t * Maximum file size in MB\n\t */\n\tmaxFileSize?: number;\n\n\t/**\n\t * Whether to allow multiple files to be uploaded\n\t */\n\tmultiple?: boolean;\n\n\t/**\n\t * Callback function to be called when internal files state changes\n\t */\n\tonFilesChange?: (context: { filesWithPreview: FileWithPreview[] }) => void;\n\n\t/**\n\t * Callback function to be called when new files are uploaded\n\t */\n\tonUpload?: (context: { event: ChangeOrDragEvent; filesWithPreview: FileWithPreview[] }) => void;\n\n\t/**\n\t * Callback function to be called on each file upload as they occur\n\t */\n\tonUploadError?: FileValidationOptions[\"onError\"];\n\n\t/**\n\t * Callback function to be called once after all file upload errors have occurred\n\t */\n\tonUploadErrors?: FileValidationOptions[\"onErrors\"];\n\n\t/**\n\t * Callback function to be called on file upload success\n\t */\n\tonUploadSuccess?: FileValidationOptions[\"onSuccess\"];\n\n\t/**\n\t * Custom validator function to handle file validation\n\t */\n\tvalidator?: FileValidationOptions[\"validator\"];\n};\n\nexport const useDropZone = (props?: UseDropZoneProps): UseDropZoneResult => {\n\tconst {\n\t\tallowedFileTypes,\n\t\tchildren,\n\t\tclassNames,\n\t\tdisallowDuplicates = true,\n\t\textraInputProps,\n\t\textraRootProps,\n\t\tinitialFiles,\n\t\tmaxFileCount,\n\t\tmaxFileSize,\n\t\tmultiple,\n\t\tonFilesChange,\n\t\tonUpload,\n\t\tonUploadError,\n\t\tonUploadErrors,\n\t\tonUploadSuccess,\n\t\trender,\n\t\tvalidator,\n\t} = props ?? {};\n\n\tconst inputRef = useRef<HTMLInputElement>(null);\n\n\tconst initialFileArray = toArray(initialFiles).filter(Boolean);\n\n\tconst [dropZoneState, setDropZoneState] = useState<FileUploadState>({\n\t\terrors: [],\n\t\tfilesWithPreview: initialFileArray.map((fileMeta) => ({\n\t\t\tfile: fileMeta,\n\t\t\tid: fileMeta.id,\n\t\t\tpreview: fileMeta.url,\n\t\t})),\n\t\tisDragging: false,\n\t});\n\n\tconst toggleIsDragging = (value: boolean) => {\n\t\tsetDropZoneState((prevState) => ({ ...prevState, isDragging: value }));\n\t};\n\n\tconst addFiles: UseDropZoneResult[\"addFiles\"] = useCallbackRef((fileList, event) => {\n\t\tif (!fileList || fileList.length === 0) {\n\t\t\tconsole.warn(\"No file selected!\");\n\t\t\treturn;\n\t\t}\n\n\t\t// Clear existing errors when new files are uploaded\n\t\tclearErrors();\n\n\t\t// In single file mode, clear existing files first\n\t\tif (!multiple) {\n\t\t\tclearFiles();\n\t\t}\n\n\t\tconst { errors, validFiles } = handleFileValidation({\n\t\t\texistingFiles: dropZoneState.filesWithPreview.map((fileWithPreview) => fileWithPreview.file),\n\t\t\tnewFiles: fileList,\n\t\t\tonError: onUploadError,\n\t\t\tonErrors: onUploadErrors,\n\t\t\tonSuccess: onUploadSuccess,\n\t\t\tvalidationSettings: { allowedFileTypes, disallowDuplicates, maxFileCount, maxFileSize },\n\t\t\tvalidator,\n\t\t});\n\n\t\tif (validFiles.length === 0) {\n\t\t\tsetDropZoneState((prevState) => ({ ...prevState, errors }));\n\t\t\treturn;\n\t\t}\n\n\t\tconst filesWithPreview: FileWithPreview[] = validFiles.map((file) => ({\n\t\t\tfile,\n\t\t\tid: generateUniqueId(file),\n\t\t\tpreview: createImagePreview({ file }),\n\t\t}));\n\n\t\t// == Only call onUpload callback if event is provided, which indicates that new files were uploaded from an event handler\n\n\t\tif (event) {\n\t\t\tonUpload?.({ event, filesWithPreview });\n\t\t}\n\n\t\tconst newFileUploadState = {\n\t\t\t...dropZoneState,\n\t\t\terrors,\n\t\t\t...(event?.type === \"drop\" && { isDragging: false }),\n\t\t\tfilesWithPreview: multiple\n\t\t\t\t? [...dropZoneState.filesWithPreview, ...filesWithPreview]\n\t\t\t\t: filesWithPreview,\n\t\t} satisfies FileUploadState;\n\n\t\tonFilesChange?.({ filesWithPreview: newFileUploadState.filesWithPreview });\n\n\t\tsetDropZoneState(newFileUploadState);\n\n\t\t// == Reset input value after adding files\n\t\tinputRef.current && (inputRef.current.value = \"\");\n\t});\n\n\tconst clearFiles: UseDropZoneResult[\"clearFiles\"] = useCallbackRef(() => {\n\t\t// == Clean up object URLs if any\n\t\tdropZoneState.filesWithPreview.forEach((fileObject) => clearObjectURL(fileObject));\n\n\t\tconst newFileUploadState = {\n\t\t\t...dropZoneState,\n\t\t\terrors: [],\n\t\t\tfilesWithPreview: [],\n\t\t} satisfies FileUploadState;\n\n\t\tonFilesChange?.({ filesWithPreview: newFileUploadState.filesWithPreview });\n\n\t\tsetDropZoneState(newFileUploadState);\n\n\t\t// == Reset input value after clearing files\n\t\tinputRef.current && (inputRef.current.value = \"\");\n\t});\n\n\tconst removeFile: UseDropZoneResult[\"removeFile\"] = useCallbackRef((id) => {\n\t\tconst fileToRemove = dropZoneState.filesWithPreview.find((fileObject) => fileObject.id === id);\n\n\t\tclearObjectURL(fileToRemove);\n\n\t\tconst newFilesWithPreview = dropZoneState.filesWithPreview.filter((file) => file.id !== id);\n\n\t\tonFilesChange?.({ filesWithPreview: newFilesWithPreview });\n\n\t\tsetDropZoneState({\n\t\t\t...dropZoneState,\n\t\t\terrors: [],\n\t\t\tfilesWithPreview: newFilesWithPreview,\n\t\t});\n\t});\n\n\tconst clearErrors: UseDropZoneResult[\"clearErrors\"] = useCallbackRef(() => {\n\t\tsetDropZoneState((prevState) => ({ ...prevState, errors: [] }));\n\t});\n\n\tconst handleFileUpload: UseDropZoneResult[\"handleFileUpload\"] = useCallbackRef((event) => {\n\t\tif (event.defaultPrevented) return;\n\n\t\tif (inputRef.current?.disabled) return;\n\n\t\tif (event.type === \"drop\") {\n\t\t\tevent.preventDefault();\n\t\t\tevent.stopPropagation();\n\t\t}\n\n\t\tconst fileList =\n\t\t\tevent.type === \"drop\"\n\t\t\t\t? (event as React.DragEvent).dataTransfer.files\n\t\t\t\t: (event as React.ChangeEvent<HTMLInputElement>).target.files;\n\n\t\t// == In single file mode, only use the first file\n\t\tif (!multiple) {\n\t\t\tconst firstFile = fileList?.[0];\n\n\t\t\tfirstFile && addFiles([firstFile], event);\n\n\t\t\treturn;\n\t\t}\n\n\t\taddFiles(fileList, event);\n\t});\n\n\tconst handleDragEnter: UseDropZoneResult[\"handleDragEnter\"] = useCallbackRef((event) => {\n\t\tevent.preventDefault();\n\t\tevent.stopPropagation();\n\t\ttoggleIsDragging(true);\n\t});\n\n\tconst handleDragOver: UseDropZoneResult[\"handleDragOver\"] = useCallbackRef((event) => {\n\t\tevent.preventDefault();\n\t\tevent.stopPropagation();\n\t\ttoggleIsDragging(true);\n\t});\n\n\tconst handleDragLeave: UseDropZoneResult[\"handleDragLeave\"] = useCallbackRef((event) => {\n\t\tevent.preventDefault();\n\t\tevent.stopPropagation();\n\t\ttoggleIsDragging(false);\n\t});\n\n\tconst openFilePicker: UseDropZoneResult[\"openFilePicker\"] = useCallbackRef(() => {\n\t\tinputRef.current?.click();\n\t});\n\n\tconst getRootProps: UseDropZoneResult[\"getRootProps\"] = useCallback(\n\t\t(rootProps) => {\n\t\t\tconst mergedRootProps = mergeTwoProps(extraRootProps, rootProps);\n\n\t\t\treturn {\n\t\t\t\t...mergedRootProps,\n\t\t\t\tclassName: cnMerge(\n\t\t\t\t\t\"relative isolate flex flex-col\",\n\t\t\t\t\tmergedRootProps.className,\n\t\t\t\t\tclassNames?.base,\n\t\t\t\t\tdropZoneState.isDragging && [\n\t\t\t\t\t\t\"opacity-60\",\n\t\t\t\t\t\tclassNames?.isDragging,\n\t\t\t\t\t\trootProps?.classNames?.isDragging,\n\t\t\t\t\t]\n\t\t\t\t),\n\t\t\t\t\"data-dragging\": dataAttr(dropZoneState.isDragging),\n\t\t\t\t\"data-scope\": \"dropzone\",\n\t\t\t\t// eslint-disable-next-line perfectionist/sort-objects -- I need data-scope to be first\n\t\t\t\t\"data-part\": \"root\",\n\t\t\t\t\"data-slot\": \"dropzone-root\",\n\t\t\t\tonDragEnter: handleDragEnter,\n\t\t\t\tonDragLeave: handleDragLeave,\n\t\t\t\tonDragOver: handleDragOver,\n\t\t\t\tonDrop: handleFileUpload,\n\t\t\t};\n\t\t},\n\t\t[\n\t\t\tclassNames?.base,\n\t\t\tclassNames?.isDragging,\n\t\t\textraRootProps,\n\t\t\tdropZoneState.isDragging,\n\t\t\thandleDragEnter,\n\t\t\thandleDragLeave,\n\t\t\thandleDragOver,\n\t\t\thandleFileUpload,\n\t\t]\n\t);\n\n\tconst getInputProps: UseDropZoneResult[\"getInputProps\"] = useCallback(\n\t\t(inputProps) => {\n\t\t\tconst mergedInputProps = mergeTwoProps(extraInputProps, inputProps);\n\n\t\t\treturn {\n\t\t\t\t...mergedInputProps,\n\t\t\t\taccept: allowedFileTypes ? allowedFileTypes.join(\", \") : mergedInputProps.accept,\n\t\t\t\tclassName: cnMerge(\n\t\t\t\t\t\"absolute inset-0 z-[100] cursor-pointer opacity-0\",\n\t\t\t\t\tclassNames?.input,\n\t\t\t\t\tmergedInputProps.className\n\t\t\t\t),\n\t\t\t\t\"data-dragging\": dataAttr(dropZoneState.isDragging),\n\t\t\t\t\"data-scope\": \"dropzone\",\n\t\t\t\t// eslint-disable-next-line perfectionist/sort-objects -- I need data-scope to be first\n\t\t\t\t\"data-part\": \"input\",\n\t\t\t\t\"data-slot\": \"dropzone-input\",\n\t\t\t\tmultiple: multiple ?? mergedInputProps.multiple,\n\t\t\t\tonChange: (event: React.ChangeEvent<HTMLInputElement>) => {\n\t\t\t\t\tmergedInputProps.onChange?.(event);\n\t\t\t\t\thandleFileUpload(event);\n\t\t\t\t},\n\t\t\t\tref: composeRefs([inputRef, mergedInputProps.ref]),\n\t\t\t\ttype: \"file\",\n\t\t\t};\n\t\t},\n\t\t[\n\t\t\tallowedFileTypes,\n\t\t\tclassNames?.input,\n\t\t\textraInputProps,\n\t\t\tdropZoneState.isDragging,\n\t\t\thandleFileUpload,\n\t\t\tmultiple,\n\t\t]\n\t);\n\n\tconst renderProps = {\n\t\taddFiles,\n\t\tclearErrors,\n\t\tclearFiles,\n\t\tdropZoneState,\n\t\tgetInputProps,\n\t\tgetRootProps,\n\t\thandleDragEnter,\n\t\thandleDragLeave,\n\t\thandleDragOver,\n\t\thandleFileUpload,\n\t\tinputRef,\n\t\topenFilePicker,\n\t\tremoveFile,\n\t} satisfies RenderProps;\n\n\tconst selectedChildren = children ?? render;\n\n\tconst getResolvedChildren = () => {\n\t\treturn isFunction(selectedChildren) ? selectedChildren(renderProps) : selectedChildren;\n\t};\n\n\treturn {\n\t\t...renderProps,\n\t\tgetResolvedChildren,\n\t};\n};\n","\"use client\";\n\nimport * as React from \"react\";\n\nimport {\n\ttype GetSlotComponentProps,\n\tgetSlotMap,\n\twithSlotNameAndSymbol,\n} from \"@zayne-labs/toolkit-react/utils\";\nimport { isArray } from \"@zayne-labs/toolkit-type-helpers\";\nimport { Fragment as ReactFragment, isValidElement } from \"react\";\nimport { type UseDropZoneProps, useDropZone } from \"./use-drop-zone\";\n\ntype DropZoneProps = UseDropZoneProps & {\n\t/**\n\t * Controls whether to include internal elements (root and input) or not.\n\t */\n\twithInternalElements?: boolean;\n};\n\nexport function DropZoneRoot(props: DropZoneProps) {\n\tconst { withInternalElements = true, ...restOfProps } = props;\n\n\tconst api = useDropZone(restOfProps);\n\n\tconst RootComponent = withInternalElements ? \"div\" : ReactFragment;\n\tconst InputComponent = withInternalElements ? \"input\" : ReactFragment;\n\n\tconst rootComponentProps = RootComponent === \"div\" && api.getRootProps();\n\tconst inputComponentProps = InputComponent === \"input\" && api.getInputProps();\n\n\tconst resolvedChildren = api.getResolvedChildren();\n\n\t/**\n\t * Whether the children could contain slots.\n\t */\n\tconst couldChildrenContainSlots =\n\t\tisArray(resolvedChildren)\n\t\t|| (isValidElement(resolvedChildren) && resolvedChildren.type === ReactFragment);\n\n\tconst slots = getSlotMap<SlotComponentProps>(resolvedChildren, {\n\t\tcondition: withInternalElements && couldChildrenContainSlots,\n\t});\n\n\treturn (\n\t\t<>\n\t\t\t<RootComponent {...rootComponentProps}>\n\t\t\t\t<InputComponent {...inputComponentProps} />\n\n\t\t\t\t{slots.default}\n\t\t\t</RootComponent>\n\n\t\t\t{slots.preview}\n\t\t</>\n\t);\n}\n\ntype SlotComponentProps = GetSlotComponentProps<\"preview\">;\n\nexport const DropZoneImagePreview = withSlotNameAndSymbol<SlotComponentProps>(\"preview\");\n","export { DropZoneRoot as Root, DropZoneImagePreview as ImagePreview } from \"./drop-zone\";\n"]}
1
+ {"version":3,"sources":["../../../../src/components/ui/drop-zone/utils.ts","../../../../src/components/ui/drop-zone/use-drop-zone.ts","../../../../src/components/ui/drop-zone/drop-zone.tsx","../../../../src/components/ui/drop-zone/drop-zone-parts.ts"],"names":["ReactFragment"],"mappings":";;;;;;;;;;AAIO,IAAM,gBAAA,GAAmB,CAAC,IAAkC,KAAA;AAClE,EAAI,IAAA,CAAC,MAAO,CAAA,IAAI,CAAG,EAAA;AAClB,IAAA,OAAO,IAAK,CAAA,EAAA;AAAA;AAGb,EAAA,OAAO,GAAG,IAAK,CAAA,IAAI,CAAK,EAAA,EAAA,IAAA,CAAK,MAAM,WAAY,CAAA,GAAA,EAAK,CAAC,KAAK,MAAO,CAAA,UAAA,GAAa,KAAM,CAAA,CAAA,EAAG,CAAC,CAAC,CAAA,CAAA;A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GAAA,CAAI,YAAa,EAAA;AACvE,EAAA,MAAM,mBAAsB,GAAA,cAAA,KAAmB,OAAW,IAAA,GAAA,CAAI,aAAc,EAAA;AAE5E,EAAM,MAAA,gBAAA,GAAmB,IAAI,mBAAoB,EAAA;AAKjD,EAAM,MAAA,yBAAA,GACL,QAAQ,gBAAgB,CAAA,IACpB,eAAe,gBAAgB,CAAA,IAAK,iBAAiB,IAAS,KAAAA,QAAA;AAEnE,EAAM,MAAA,KAAA,GAAQ,WAA+B,gBAAkB,EAAA;AAAA,IAC9D,WAAW,oBAAwB,IAAA;AAAA,GACnC,CAAA;AAED,EAAA,uBAEE,KAAA,CAAA,aAAA,CAAA,KAAA,CAAA,QAAA,EAAA,IAAA,kBAAA,KAAA,CAAA,aAAA,CAAC,aAAe,EAAA,EAAA,GAAG,sCACjB,KAAA,CAAA,aAAA,CAAA,cAAA,EAAA,EAAgB,GAAG,mBAAA,EAAqB,CAExC,EAAA,KAAA,CAAM,OACR,CAAA,EAEC,MAAM,OACR,CAAA;AAEF;AAIa,IAAA,oBAAA,GAAuB,sBAA0C,SAAS;;;AC3DvF,IAAA,uBAAA,GAAA;AAAA,QAAA,CAAA,uBAAA,EAAA;AAAA,EAAA,YAAA,EAAA,MAAA,oBAAA;AAAA,EAAA,IAAA,EAAA,MAAA;AAAA,CAAA,CAAA","file":"index.js","sourcesContent":["import { type FileMeta, createImagePreview } from \"@zayne-labs/toolkit-core\";\nimport { isFile } from \"@zayne-labs/toolkit-type-helpers\";\nimport type { FileWithPreview } from \"./use-drop-zone\";\n\nexport const generateUniqueId = (file: File | FileMeta): string => {\n\tif (!isFile(file)) {\n\t\treturn file.id;\n\t}\n\n\treturn `${file.name}-(${Math.round(performance.now())})-${crypto.randomUUID().slice(0, 8)}`;\n};\n\nexport const createObjectURL = (file: File, disallowPreviewForNonImageFiles: boolean) => {\n\tif (disallowPreviewForNonImageFiles && !file.type.startsWith(\"image/\")) return;\n\n\treturn createImagePreview(file);\n};\n\nexport const clearObjectURL = (\n\tfileWithPreview: FileWithPreview | undefined,\n\tdisallowPreviewForNonImageFiles: boolean\n) => {\n\tif (!isFile(fileWithPreview?.file)) return;\n\n\tif (disallowPreviewForNonImageFiles && !fileWithPreview.file.type.startsWith(\"image/\")) return;\n\n\tif (!fileWithPreview.preview) return;\n\n\tURL.revokeObjectURL(fileWithPreview.preview);\n};\n","import { cnMerge } from \"@/lib/utils/cn\";\nimport { dataAttr } from \"@/lib/utils/common\";\nimport {\n\ttype FileMeta,\n\ttype FileValidationErrorContext,\n\ttype FileValidationOptions,\n\thandleFileValidation,\n\ttoArray,\n} from \"@zayne-labs/toolkit-core\";\nimport { useCallbackRef } from \"@zayne-labs/toolkit-react\";\nimport {\n\ttype DiscriminatedRenderProps,\n\ttype InferProps,\n\tcomposeRefs,\n\tmergeTwoProps,\n} from \"@zayne-labs/toolkit-react/utils\";\nimport { type Prettify, isFunction, isString } from \"@zayne-labs/toolkit-type-helpers\";\nimport { useCallback, useRef, useState } from \"react\";\nimport { clearObjectURL, createObjectURL, generateUniqueId } from \"./utils\";\n\nexport type RootProps = InferProps<HTMLElement> & {\n\tclassNames?: {\n\t\tbase?: string;\n\t\tisDragging?: string;\n\t};\n};\n\nexport type InputProps = InferProps<\"input\">;\n\nexport type FileWithPreview = {\n\t/**\n\t * File object or file metadata\n\t */\n\tfile: File | FileMeta;\n\t/**\n\t * Unique ID for the file\n\t */\n\tid: string;\n\t/**\n\t * Preview URL for the file\n\t * - Will be undefined if `disallowPreviewForNonImageFiles` is set to `true` and the file is not an image\n\t * - Can also be undefined if `URL.createObjectURL` fails\n\t */\n\tpreview: string | undefined;\n};\n\nexport type DropZoneState = {\n\t/**\n\t * List of validation errors\n\t */\n\terrors: FileValidationErrorContext[];\n\t/**\n\t * List of files with their preview URLs and unique IDs\n\t */\n\tfilesWithPreview: FileWithPreview[];\n\t/**\n\t * Whether or not a file is currently being dragged over the drop zone\n\t */\n\tisDragging: boolean;\n};\n\ntype ChangeOrDragEvent = React.ChangeEvent<HTMLInputElement> | React.DragEvent<HTMLElement>;\n\nexport type DropZoneActions = {\n\taddFiles: (fileList: File[] | FileList | null, event?: ChangeOrDragEvent) => void;\n\tclearErrors: () => void;\n\tclearFiles: () => void;\n\thandleDragEnter: (event: React.DragEvent<HTMLElement>) => void;\n\thandleDragLeave: (event: React.DragEvent<HTMLElement>) => void;\n\thandleDragOver: (event: React.DragEvent<HTMLElement>) => void;\n\thandleFileUpload: (event: ChangeOrDragEvent) => void;\n\topenFilePicker: () => void;\n\tremoveFile: (fileToRemoveOrId: string | FileWithPreview) => void;\n};\n\nexport type RenderProps = {\n\tdropZoneActions: DropZoneActions;\n\tdropZoneState: DropZoneState;\n\tgetInputProps: (inputProps?: InputProps) => InputProps;\n\tgetRootProps: (rootProps?: RootProps) => RootProps;\n\tinputRef: React.RefObject<HTMLInputElement | null>;\n};\n\nexport type DropZoneResult = RenderProps & { getResolvedChildren: () => React.ReactNode };\n\ntype DropZoneRenderProps = DiscriminatedRenderProps<\n\tReact.ReactNode | ((props: RenderProps) => React.ReactNode)\n>;\n\nexport type DropZoneProps = DropZoneRenderProps & {\n\t/**\n\t * Allowed file types to be uploaded.\n\t */\n\tallowedFileTypes?: string[];\n\n\t/**\n\t * CSS classes to apply to the various parts of the drop zone\n\t */\n\tclassNames?: Prettify<RootProps[\"classNames\"] & { input?: string }>;\n\n\t/**\n\t * Whether to disallow duplicate files\n\t * @default true\n\t */\n\tdisallowDuplicates?: boolean;\n\n\t/**\n\t * Whether to disallow preview for non-image files\n\t * @default true\n\t */\n\tdisallowPreviewForNonImageFiles?: boolean;\n\n\t/**\n\t * Extra props to pass to the input element\n\t */\n\textraInputProps?: InputProps;\n\n\t/**\n\t * Extra props to pass to the root element\n\t */\n\textraRootProps?: RootProps;\n\n\t/**\n\t * Initial files to populate the drop zone\n\t */\n\tinitialFiles?: FileMeta | FileMeta[] | null;\n\n\t/**\n\t * Maximum number of files that can be uploaded.\n\t */\n\tmaxFileCount?: number;\n\n\t/**\n\t * Maximum file size in MB\n\t */\n\tmaxFileSize?: number;\n\n\t/**\n\t * Whether to allow multiple files to be uploaded\n\t */\n\tmultiple?: boolean;\n\n\t/**\n\t * Callback function to be called when internal files state changes\n\t */\n\tonFilesChange?: (context: { filesWithPreview: FileWithPreview[] }) => void;\n\n\t/**\n\t * Callback function to be called when new files are uploaded\n\t */\n\tonUpload?: (context: { event: ChangeOrDragEvent; filesWithPreview: FileWithPreview[] }) => void;\n\n\t/**\n\t * Callback function to be called on each file upload as they occur\n\t */\n\tonUploadError?: FileValidationOptions[\"onError\"];\n\n\t/**\n\t * Callback function to be called once after all file upload errors have occurred\n\t */\n\tonUploadErrors?: FileValidationOptions[\"onErrors\"];\n\n\t/**\n\t * Callback function to be called on file upload success\n\t */\n\tonUploadSuccess?: FileValidationOptions[\"onSuccess\"];\n\n\t/**\n\t * Custom validator function to handle file validation\n\t */\n\tvalidator?: FileValidationOptions[\"validator\"];\n};\n\nexport const useDropZone = (props?: DropZoneProps): DropZoneResult => {\n\tconst {\n\t\tallowedFileTypes,\n\t\tchildren,\n\t\tclassNames,\n\t\tdisallowDuplicates = true,\n\t\tdisallowPreviewForNonImageFiles = true,\n\t\textraInputProps,\n\t\textraRootProps,\n\t\tinitialFiles,\n\t\tmaxFileCount,\n\t\tmaxFileSize,\n\t\tmultiple,\n\t\tonFilesChange,\n\t\tonUpload,\n\t\tonUploadError,\n\t\tonUploadErrors,\n\t\tonUploadSuccess,\n\t\trender,\n\t\tvalidator,\n\t} = props ?? {};\n\n\tconst inputRef = useRef<HTMLInputElement>(null);\n\n\tconst initialFileArray = toArray(initialFiles).filter(Boolean);\n\n\tconst [dropZoneState, setDropZoneState] = useState<DropZoneState>({\n\t\terrors: [],\n\t\tfilesWithPreview: initialFileArray.map((fileMeta) => ({\n\t\t\tfile: fileMeta,\n\t\t\tid: fileMeta.id,\n\t\t\tpreview: fileMeta.url,\n\t\t})),\n\t\tisDragging: false,\n\t});\n\n\tconst toggleIsDragging = (value: boolean) => {\n\t\tsetDropZoneState((prevState) => ({ ...prevState, isDragging: value }));\n\t};\n\n\tconst addFiles: DropZoneActions[\"addFiles\"] = useCallbackRef((fileList, event) => {\n\t\tif (!fileList || fileList.length === 0) {\n\t\t\tconsole.warn(\"No file selected!\");\n\t\t\treturn;\n\t\t}\n\n\t\t// Clear existing errors when new files are uploaded\n\t\tclearErrors();\n\n\t\t// In single file mode, clear existing files first\n\t\tif (!multiple) {\n\t\t\tclearFiles();\n\t\t}\n\n\t\tconst { errors, validFiles } = handleFileValidation({\n\t\t\texistingFiles: dropZoneState.filesWithPreview.map((fileWithPreview) => fileWithPreview.file),\n\t\t\tnewFiles: fileList,\n\t\t\tonError: onUploadError,\n\t\t\tonErrors: onUploadErrors,\n\t\t\tonSuccess: onUploadSuccess,\n\t\t\tvalidationSettings: { allowedFileTypes, disallowDuplicates, maxFileCount, maxFileSize },\n\t\t\tvalidator,\n\t\t});\n\n\t\tif (validFiles.length === 0) {\n\t\t\tsetDropZoneState((prevState) => ({ ...prevState, errors }));\n\t\t\treturn;\n\t\t}\n\n\t\tconst filesWithPreview: FileWithPreview[] = validFiles.map((file) => ({\n\t\t\tfile,\n\t\t\tid: generateUniqueId(file),\n\t\t\tpreview: createObjectURL(file, disallowPreviewForNonImageFiles),\n\t\t}));\n\n\t\t// == Only call onUpload callback if event is provided, which indicates that new files were uploaded from an event handler\n\n\t\tif (event) {\n\t\t\tonUpload?.({ event, filesWithPreview });\n\t\t}\n\n\t\tconst newFileUploadState = {\n\t\t\t...dropZoneState,\n\t\t\terrors,\n\t\t\t...(event?.type === \"drop\" && { isDragging: false }),\n\t\t\tfilesWithPreview: multiple\n\t\t\t\t? [...dropZoneState.filesWithPreview, ...filesWithPreview]\n\t\t\t\t: filesWithPreview,\n\t\t} satisfies DropZoneState;\n\n\t\tonFilesChange?.({ filesWithPreview: newFileUploadState.filesWithPreview });\n\n\t\tsetDropZoneState(newFileUploadState);\n\n\t\t// == Reset input value after adding files\n\t\tinputRef.current && (inputRef.current.value = \"\");\n\t});\n\n\tconst clearFiles: DropZoneActions[\"clearFiles\"] = useCallbackRef(() => {\n\t\t// == Clean up object URLs if any\n\t\tdropZoneState.filesWithPreview.forEach((fileWithPreview) =>\n\t\t\tclearObjectURL(fileWithPreview, disallowPreviewForNonImageFiles)\n\t\t);\n\n\t\tconst newFileUploadState = {\n\t\t\t...dropZoneState,\n\t\t\terrors: [],\n\t\t\tfilesWithPreview: [],\n\t\t} satisfies DropZoneState;\n\n\t\tonFilesChange?.({ filesWithPreview: newFileUploadState.filesWithPreview });\n\n\t\tsetDropZoneState(newFileUploadState);\n\n\t\t// == Reset input value after clearing files\n\t\tinputRef.current && (inputRef.current.value = \"\");\n\t});\n\n\tconst removeFile: DropZoneActions[\"removeFile\"] = useCallbackRef((fileToRemoveOrId) => {\n\t\tconst actualFileToRemove = isString(fileToRemoveOrId)\n\t\t\t? dropZoneState.filesWithPreview.find((file) => file.id === fileToRemoveOrId)\n\t\t\t: fileToRemoveOrId;\n\n\t\tif (!actualFileToRemove) return;\n\n\t\tclearObjectURL(actualFileToRemove, disallowPreviewForNonImageFiles);\n\n\t\tconst newFilesWithPreview = dropZoneState.filesWithPreview.filter(\n\t\t\t(file) => file.id !== actualFileToRemove.id\n\t\t);\n\n\t\tonFilesChange?.({ filesWithPreview: newFilesWithPreview });\n\n\t\tsetDropZoneState({\n\t\t\t...dropZoneState,\n\t\t\terrors: [],\n\t\t\tfilesWithPreview: newFilesWithPreview,\n\t\t});\n\t});\n\n\tconst clearErrors: DropZoneActions[\"clearErrors\"] = useCallbackRef(() => {\n\t\tsetDropZoneState((prevState) => ({ ...prevState, errors: [] }));\n\t});\n\n\tconst handleFileUpload: DropZoneActions[\"handleFileUpload\"] = useCallbackRef((event) => {\n\t\tif (event.defaultPrevented) return;\n\n\t\tif (inputRef.current?.disabled) return;\n\n\t\tif (event.type === \"drop\") {\n\t\t\tevent.preventDefault();\n\t\t\tevent.stopPropagation();\n\t\t}\n\n\t\tconst fileList =\n\t\t\tevent.type === \"drop\"\n\t\t\t\t? (event as React.DragEvent).dataTransfer.files\n\t\t\t\t: (event as React.ChangeEvent<HTMLInputElement>).target.files;\n\n\t\t// == In single file mode, only use the first file\n\t\tif (!multiple) {\n\t\t\tconst firstFile = fileList?.[0];\n\n\t\t\tfirstFile && addFiles([firstFile], event);\n\n\t\t\treturn;\n\t\t}\n\n\t\taddFiles(fileList, event);\n\t});\n\n\tconst handleDragEnter: DropZoneActions[\"handleDragEnter\"] = useCallbackRef((event) => {\n\t\tevent.preventDefault();\n\t\tevent.stopPropagation();\n\t\ttoggleIsDragging(true);\n\t});\n\n\tconst handleDragOver: DropZoneActions[\"handleDragOver\"] = useCallbackRef((event) => {\n\t\tevent.preventDefault();\n\t\tevent.stopPropagation();\n\t\ttoggleIsDragging(true);\n\t});\n\n\tconst handleDragLeave: DropZoneActions[\"handleDragLeave\"] = useCallbackRef((event) => {\n\t\tevent.preventDefault();\n\t\tevent.stopPropagation();\n\t\ttoggleIsDragging(false);\n\t});\n\n\tconst openFilePicker: DropZoneActions[\"openFilePicker\"] = useCallbackRef(() => {\n\t\tinputRef.current?.click();\n\t});\n\n\tconst getRootProps: DropZoneResult[\"getRootProps\"] = useCallback(\n\t\t(rootProps) => {\n\t\t\tconst mergedRootProps = mergeTwoProps(extraRootProps, rootProps);\n\n\t\t\treturn {\n\t\t\t\t...mergedRootProps,\n\t\t\t\tclassName: cnMerge(\n\t\t\t\t\t\"relative isolate flex flex-col\",\n\t\t\t\t\tmergedRootProps.className,\n\t\t\t\t\tclassNames?.base,\n\t\t\t\t\tdropZoneState.isDragging && [\n\t\t\t\t\t\t\"opacity-60\",\n\t\t\t\t\t\tclassNames?.isDragging,\n\t\t\t\t\t\trootProps?.classNames?.isDragging,\n\t\t\t\t\t]\n\t\t\t\t),\n\t\t\t\t\"data-dragging\": dataAttr(dropZoneState.isDragging),\n\t\t\t\t\"data-scope\": \"dropzone\",\n\t\t\t\t// eslint-disable-next-line perfectionist/sort-objects -- I need data-scope to be first\n\t\t\t\t\"data-part\": \"root\",\n\t\t\t\t\"data-slot\": \"dropzone-root\",\n\t\t\t\tonDragEnter: handleDragEnter,\n\t\t\t\tonDragLeave: handleDragLeave,\n\t\t\t\tonDragOver: handleDragOver,\n\t\t\t\tonDrop: handleFileUpload,\n\t\t\t};\n\t\t},\n\t\t[\n\t\t\tclassNames?.base,\n\t\t\tclassNames?.isDragging,\n\t\t\textraRootProps,\n\t\t\tdropZoneState.isDragging,\n\t\t\thandleDragEnter,\n\t\t\thandleDragLeave,\n\t\t\thandleDragOver,\n\t\t\thandleFileUpload,\n\t\t]\n\t);\n\n\tconst getInputProps: DropZoneResult[\"getInputProps\"] = useCallback(\n\t\t(inputProps) => {\n\t\t\tconst mergedInputProps = mergeTwoProps(extraInputProps, inputProps);\n\n\t\t\treturn {\n\t\t\t\t...mergedInputProps,\n\t\t\t\taccept: allowedFileTypes ? allowedFileTypes.join(\", \") : mergedInputProps.accept,\n\t\t\t\tclassName: cnMerge(\n\t\t\t\t\t\"absolute inset-0 z-[100] cursor-pointer opacity-0\",\n\t\t\t\t\tclassNames?.input,\n\t\t\t\t\tmergedInputProps.className\n\t\t\t\t),\n\t\t\t\t\"data-dragging\": dataAttr(dropZoneState.isDragging),\n\t\t\t\t\"data-scope\": \"dropzone\",\n\t\t\t\t// eslint-disable-next-line perfectionist/sort-objects -- I need data-scope to be first\n\t\t\t\t\"data-part\": \"input\",\n\t\t\t\t\"data-slot\": \"dropzone-input\",\n\t\t\t\tmultiple: multiple ?? mergedInputProps.multiple,\n\t\t\t\tonChange: (event: React.ChangeEvent<HTMLInputElement>) => {\n\t\t\t\t\tmergedInputProps.onChange?.(event);\n\t\t\t\t\thandleFileUpload(event);\n\t\t\t\t},\n\t\t\t\tref: composeRefs([inputRef, mergedInputProps.ref]),\n\t\t\t\ttype: \"file\",\n\t\t\t};\n\t\t},\n\t\t[\n\t\t\tallowedFileTypes,\n\t\t\tclassNames?.input,\n\t\t\textraInputProps,\n\t\t\tdropZoneState.isDragging,\n\t\t\thandleFileUpload,\n\t\t\tmultiple,\n\t\t]\n\t);\n\n\tconst renderProps = {\n\t\tdropZoneActions: {\n\t\t\taddFiles,\n\t\t\tclearErrors,\n\t\t\tclearFiles,\n\t\t\thandleDragEnter,\n\t\t\thandleDragLeave,\n\t\t\thandleDragOver,\n\t\t\thandleFileUpload,\n\t\t\topenFilePicker,\n\t\t\tremoveFile,\n\t\t},\n\t\tdropZoneState,\n\t\tgetInputProps,\n\t\tgetRootProps,\n\t\tinputRef,\n\t} satisfies RenderProps;\n\n\tconst selectedChildren = children ?? render;\n\n\tconst getResolvedChildren = () => {\n\t\treturn isFunction(selectedChildren) ? selectedChildren(renderProps) : selectedChildren;\n\t};\n\n\treturn {\n\t\t...renderProps,\n\t\tgetResolvedChildren,\n\t};\n};\n","\"use client\";\n\nimport * as React from \"react\";\n\nimport {\n\ttype GetSlotComponentProps,\n\tgetSlotMap,\n\twithSlotNameAndSymbol,\n} from \"@zayne-labs/toolkit-react/utils\";\nimport { isArray } from \"@zayne-labs/toolkit-type-helpers\";\nimport { Fragment as ReactFragment, isValidElement } from \"react\";\nimport { type DropZoneProps, useDropZone } from \"./use-drop-zone\";\n\ntype DropZoneWrapperProps = DropZoneProps & {\n\t/**\n\t * Controls whether to include internal elements (root and input) or not.\n\t */\n\twithInternalElements?: boolean;\n};\n\nexport function DropZoneRoot(props: DropZoneWrapperProps) {\n\tconst { withInternalElements = true, ...restOfProps } = props;\n\n\tconst api = useDropZone(restOfProps);\n\n\tconst RootComponent = withInternalElements ? \"div\" : ReactFragment;\n\tconst InputComponent = withInternalElements ? \"input\" : ReactFragment;\n\n\tconst rootComponentProps = RootComponent === \"div\" && api.getRootProps();\n\tconst inputComponentProps = InputComponent === \"input\" && api.getInputProps();\n\n\tconst resolvedChildren = api.getResolvedChildren();\n\n\t/**\n\t * Whether the children could contain slots.\n\t */\n\tconst couldChildrenContainSlots =\n\t\tisArray(resolvedChildren)\n\t\t|| (isValidElement(resolvedChildren) && resolvedChildren.type === ReactFragment);\n\n\tconst slots = getSlotMap<SlotComponentProps>(resolvedChildren, {\n\t\tcondition: withInternalElements && couldChildrenContainSlots,\n\t});\n\n\treturn (\n\t\t<>\n\t\t\t<RootComponent {...rootComponentProps}>\n\t\t\t\t<InputComponent {...inputComponentProps} />\n\n\t\t\t\t{slots.default}\n\t\t\t</RootComponent>\n\n\t\t\t{slots.preview}\n\t\t</>\n\t);\n}\n\ntype SlotComponentProps = GetSlotComponentProps<\"preview\">;\n\nexport const DropZoneImagePreview = withSlotNameAndSymbol<SlotComponentProps>(\"preview\");\n","export { DropZoneRoot as Root, DropZoneImagePreview as ImagePreview } from \"./drop-zone\";\n"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@zayne-labs/ui-react",
3
3
  "type": "module",
4
- "version": "0.8.4",
4
+ "version": "0.8.6",
5
5
  "description": "A composable UI/UI-utilities components library. ",
6
6
  "author": "Ryan Zayne",
7
7
  "license": "MIT",
@@ -53,9 +53,9 @@
53
53
  }
54
54
  },
55
55
  "dependencies": {
56
- "@zayne-labs/toolkit-core": "0.9.22",
57
- "@zayne-labs/toolkit-react": "0.9.22",
58
- "@zayne-labs/toolkit-type-helpers": "0.9.22",
56
+ "@zayne-labs/toolkit-core": "0.9.24",
57
+ "@zayne-labs/toolkit-react": "0.9.24",
58
+ "@zayne-labs/toolkit-type-helpers": "0.9.24",
59
59
  "tailwind-merge": "3.2.0"
60
60
  },
61
61
  "devDependencies": {