@zayne-labs/ui-react 0.8.18 → 0.9.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/css/animation.css +16 -0
- package/css/preset.css +2 -0
- package/dist/esm/chunk-ET4KZBFA.js +49 -0
- package/dist/esm/chunk-ET4KZBFA.js.map +1 -0
- package/dist/esm/chunk-IUEPHHGO.js +74 -0
- package/dist/esm/chunk-IUEPHHGO.js.map +1 -0
- package/dist/esm/{common → components/common}/await/index.d.ts +2 -2
- package/dist/esm/{common → components/common}/await/index.js +5 -6
- package/dist/esm/components/common/await/index.js.map +1 -0
- package/dist/esm/{common → components/common}/error-boundary/index.d.ts +2 -2
- package/dist/esm/components/common/error-boundary/index.js +4 -0
- package/dist/esm/components/common/for/index.js +4 -0
- package/dist/esm/{common → components/common}/show/index.js +2 -2
- package/dist/esm/components/common/show/index.js.map +1 -0
- package/dist/esm/components/common/slot/index.js +4 -0
- package/dist/esm/components/common/suspense-with-boundary/index.d.ts +11 -0
- package/dist/esm/{common → components/common}/suspense-with-boundary/index.js +4 -4
- package/dist/esm/components/common/suspense-with-boundary/index.js.map +1 -0
- package/dist/esm/{common → components/common}/switch/index.js +2 -2
- package/dist/esm/components/common/switch/index.js.map +1 -0
- package/dist/esm/{common → components/common}/teleport/index.js +1 -1
- package/dist/esm/components/common/teleport/index.js.map +1 -0
- package/dist/esm/{ui → components/ui}/card/index.js +3 -3
- package/dist/esm/components/ui/card/index.js.map +1 -0
- package/dist/esm/{ui → components/ui}/carousel/index.js +3 -3
- package/dist/esm/components/ui/carousel/index.js.map +1 -0
- package/dist/esm/{ui → components/ui}/drag-scroll/index.js +2 -2
- package/dist/esm/components/ui/drag-scroll/index.js.map +1 -0
- package/dist/esm/{ui → components/ui}/drop-zone/index.d.ts +37 -22
- package/dist/esm/{ui → components/ui}/drop-zone/index.js +69 -49
- package/dist/esm/components/ui/drop-zone/index.js.map +1 -0
- package/dist/esm/{ui → components/ui}/form/index.d.ts +29 -13
- package/dist/esm/{ui → components/ui}/form/index.js +208 -103
- package/dist/esm/components/ui/form/index.js.map +1 -0
- package/dist/esm/lib/utils/getSlot/index.d.ts +60 -0
- package/dist/esm/lib/utils/getSlot/index.js +4 -0
- package/dist/esm/lib/utils/getSlot/index.js.map +1 -0
- package/dist/esm/lib/utils/getSlotMap/index.d.ts +82 -0
- package/dist/esm/lib/utils/getSlotMap/index.js +4 -0
- package/dist/esm/lib/utils/getSlotMap/index.js.map +1 -0
- package/dist/style.css +19 -3
- package/package.json +16 -15
- package/dist/esm/common/await/index.js.map +0 -1
- package/dist/esm/common/error-boundary/index.js +0 -4
- package/dist/esm/common/for/index.js +0 -4
- package/dist/esm/common/show/index.js.map +0 -1
- package/dist/esm/common/slot/index.js +0 -4
- package/dist/esm/common/suspense-with-boundary/index.d.ts +0 -11
- package/dist/esm/common/suspense-with-boundary/index.js.map +0 -1
- package/dist/esm/common/switch/index.js.map +0 -1
- package/dist/esm/common/teleport/index.js.map +0 -1
- package/dist/esm/ui/card/index.js.map +0 -1
- package/dist/esm/ui/carousel/index.js.map +0 -1
- package/dist/esm/ui/drag-scroll/index.js.map +0 -1
- package/dist/esm/ui/drop-zone/index.js.map +0 -1
- package/dist/esm/ui/form/index.js.map +0 -1
- /package/dist/esm/{common → components/common}/error-boundary/index.js.map +0 -0
- /package/dist/esm/{common → components/common}/for/index.d.ts +0 -0
- /package/dist/esm/{common → components/common}/for/index.js.map +0 -0
- /package/dist/esm/{common → components/common}/show/index.d.ts +0 -0
- /package/dist/esm/{common → components/common}/slot/index.d.ts +0 -0
- /package/dist/esm/{common → components/common}/slot/index.js.map +0 -0
- /package/dist/esm/{common → components/common}/switch/index.d.ts +0 -0
- /package/dist/esm/{common → components/common}/teleport/index.d.ts +0 -0
- /package/dist/esm/{ui → components/ui}/card/index.d.ts +0 -0
- /package/dist/esm/{ui → components/ui}/carousel/index.d.ts +0 -0
- /package/dist/esm/{ui → components/ui}/drag-scroll/index.d.ts +0 -0
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import * as React$1 from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { GetSlotComponentProps } from '../../../lib/utils/getSlotMap/index.js';
|
|
3
|
+
import { InferProps, DiscriminatedRenderProps, PolymorphicProps } from '@zayne-labs/toolkit-react/utils';
|
|
3
4
|
import { FileMeta, FileValidationErrorContext, FileValidationOptions } from '@zayne-labs/toolkit-core';
|
|
4
5
|
import { Prettify } from '@zayne-labs/toolkit-type-helpers';
|
|
5
6
|
|
|
6
|
-
type
|
|
7
|
+
type ContainerProps = InferProps<HTMLElement> & {
|
|
7
8
|
classNames?: {
|
|
8
9
|
base?: string;
|
|
9
10
|
isDragging?: string;
|
|
@@ -52,18 +53,14 @@ type DropZoneActions = {
|
|
|
52
53
|
openFilePicker: () => void;
|
|
53
54
|
removeFile: (fileToRemoveOrId: string | FileWithPreview) => void;
|
|
54
55
|
};
|
|
55
|
-
type
|
|
56
|
+
type DropZoneResult = {
|
|
56
57
|
dropZoneActions: DropZoneActions;
|
|
57
58
|
dropZoneState: DropZoneState;
|
|
59
|
+
getContainerProps: (containerProps?: ContainerProps) => ContainerProps;
|
|
58
60
|
getInputProps: (inputProps?: InputProps) => InputProps;
|
|
59
|
-
getRootProps: (rootProps?: RootProps) => RootProps;
|
|
60
61
|
inputRef: React.RefObject<HTMLInputElement | null>;
|
|
61
62
|
};
|
|
62
|
-
type
|
|
63
|
-
getResolvedChildren: () => React.ReactNode;
|
|
64
|
-
};
|
|
65
|
-
type DropZoneRenderProps = DiscriminatedRenderProps<React.ReactNode | ((props: RenderProps) => React.ReactNode)>;
|
|
66
|
-
type DropZoneProps = DropZoneRenderProps & {
|
|
63
|
+
type DropZoneProps = {
|
|
67
64
|
/**
|
|
68
65
|
* Allowed file types to be uploaded.
|
|
69
66
|
*/
|
|
@@ -71,7 +68,7 @@ type DropZoneProps = DropZoneRenderProps & {
|
|
|
71
68
|
/**
|
|
72
69
|
* CSS classes to apply to the various parts of the drop zone
|
|
73
70
|
*/
|
|
74
|
-
classNames?: Prettify<
|
|
71
|
+
classNames?: Prettify<ContainerProps["classNames"] & {
|
|
75
72
|
input?: string;
|
|
76
73
|
}>;
|
|
77
74
|
/**
|
|
@@ -85,13 +82,13 @@ type DropZoneProps = DropZoneRenderProps & {
|
|
|
85
82
|
*/
|
|
86
83
|
disallowPreviewForNonImageFiles?: boolean;
|
|
87
84
|
/**
|
|
88
|
-
* Extra props to pass to the
|
|
85
|
+
* Extra props to pass to the container element
|
|
89
86
|
*/
|
|
90
|
-
|
|
87
|
+
extraContainerProps?: ContainerProps;
|
|
91
88
|
/**
|
|
92
|
-
* Extra props to pass to the
|
|
89
|
+
* Extra props to pass to the input element
|
|
93
90
|
*/
|
|
94
|
-
|
|
91
|
+
extraInputProps?: InputProps;
|
|
95
92
|
/**
|
|
96
93
|
* Initial files to populate the drop zone
|
|
97
94
|
*/
|
|
@@ -117,7 +114,7 @@ type DropZoneProps = DropZoneRenderProps & {
|
|
|
117
114
|
/**
|
|
118
115
|
* Callback function to be called when the render props change
|
|
119
116
|
*/
|
|
120
|
-
onRenderPropsChange?: (props:
|
|
117
|
+
onRenderPropsChange?: (props: DropZoneResult) => void;
|
|
121
118
|
/**
|
|
122
119
|
* Callback function to be called when new files are uploaded
|
|
123
120
|
*/
|
|
@@ -138,27 +135,45 @@ type DropZoneProps = DropZoneRenderProps & {
|
|
|
138
135
|
*/
|
|
139
136
|
onUploadSuccess?: FileValidationOptions["onSuccess"];
|
|
140
137
|
/**
|
|
141
|
-
* Custom
|
|
138
|
+
* Custom validation function.
|
|
139
|
+
*
|
|
140
|
+
* If the function returns false, the file will be rejected
|
|
142
141
|
*/
|
|
143
|
-
validator?: FileValidationOptions["validator"];
|
|
142
|
+
validator?: NonNullable<FileValidationOptions["validationSettings"]>["validator"];
|
|
143
|
+
/**
|
|
144
|
+
* Custom validation function that runs after all file validation has occurred
|
|
145
|
+
*/
|
|
146
|
+
validatorForAllFiles?: FileValidationOptions["validatorForAllFiles"];
|
|
144
147
|
};
|
|
145
148
|
declare const useDropZone: (props?: DropZoneProps) => DropZoneResult;
|
|
146
149
|
|
|
147
|
-
type
|
|
150
|
+
type DropZoneRenderPropType = DiscriminatedRenderProps<React$1.ReactNode | ((props: DropZoneResult) => React$1.ReactNode)>;
|
|
151
|
+
type DropZoneRootProps = DropZoneProps & DropZoneRenderPropType & {
|
|
148
152
|
/**
|
|
149
153
|
* Controls whether to include internal elements (root and input) or not.
|
|
150
154
|
*/
|
|
151
155
|
withInternalElements?: boolean;
|
|
152
156
|
};
|
|
153
|
-
declare function DropZoneRoot(props:
|
|
157
|
+
declare function DropZoneRoot(props: DropZoneRootProps): React$1.JSX.Element;
|
|
158
|
+
type DropZoneInputProps = InputProps & {
|
|
159
|
+
asChild?: boolean;
|
|
160
|
+
};
|
|
161
|
+
declare function DropZoneInput(props: DropZoneInputProps): React$1.JSX.Element;
|
|
162
|
+
type DropZoneContainerProps = ContainerProps & {
|
|
163
|
+
asChild?: boolean;
|
|
164
|
+
};
|
|
165
|
+
declare function DropZoneContainer<TElement extends React$1.ElementType = "div">(props: PolymorphicProps<TElement, DropZoneContainerProps>): React$1.JSX.Element;
|
|
166
|
+
type SlotComponentProps = GetSlotComponentProps<"preview", React$1.ReactNode | ((props: DropZoneResult) => React$1.ReactNode)>;
|
|
154
167
|
declare const DropZoneImagePreview: {
|
|
155
|
-
(props: Pick<
|
|
168
|
+
(props: Pick<SlotComponentProps, "children"> & Record<string, unknown>): React$1.ReactNode;
|
|
156
169
|
readonly slotName?: "preview" | undefined;
|
|
157
170
|
readonly slotSymbol?: symbol;
|
|
158
171
|
};
|
|
159
172
|
|
|
160
173
|
declare namespace dropZoneParts {
|
|
161
|
-
export { DropZoneImagePreview as ImagePreview, DropZoneRoot as Root };
|
|
174
|
+
export { DropZoneContainer as Container, DropZoneImagePreview as ImagePreview, DropZoneInput as Input, DropZoneRoot as Root };
|
|
162
175
|
}
|
|
163
176
|
|
|
164
|
-
|
|
177
|
+
declare const useDropZoneContext: () => DropZoneResult;
|
|
178
|
+
|
|
179
|
+
export { type ContainerProps, dropZoneParts as DropZone, type DropZoneActions, DropZoneContainer, DropZoneImagePreview, DropZoneInput, type DropZoneProps, type DropZoneResult, DropZoneRoot, type DropZoneState, type FileWithPreview, type InputProps, useDropZone, useDropZoneContext };
|
|
@@ -1,13 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { withSlotNameAndSymbol, getSlotMap } from '../../../chunk-ET4KZBFA.js';
|
|
2
|
+
import { dataAttr } from '../../../chunk-DNYM6XGW.js';
|
|
3
|
+
import { cnMerge } from '../../../chunk-OHG7GB7O.js';
|
|
4
|
+
import { Slot } from '../../../chunk-2P3P5AXH.js';
|
|
5
|
+
import { __export } from '../../../chunk-PZ5AY32C.js';
|
|
4
6
|
import * as React from 'react';
|
|
5
7
|
import { isValidElement, Fragment, useRef, useState, useCallback, useMemo } from 'react';
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
+
import { isFunction, isArray, isString, isFile } from '@zayne-labs/toolkit-type-helpers';
|
|
9
|
+
import { createCustomContext, useCallbackRef } from '@zayne-labs/toolkit-react';
|
|
8
10
|
import { toArray, handleFileValidation, createImagePreview } from '@zayne-labs/toolkit-core';
|
|
9
|
-
import {
|
|
11
|
+
import { mergeTwoProps, composeTwoEventHandlers, composeRefs } from '@zayne-labs/toolkit-react/utils';
|
|
10
12
|
|
|
13
|
+
var [DropZoneContextProvider, useDropZoneContext] = createCustomContext({
|
|
14
|
+
hookName: "useDropZoneContext",
|
|
15
|
+
name: "DropZoneContext",
|
|
16
|
+
providerName: "DropZoneRoot"
|
|
17
|
+
});
|
|
11
18
|
var generateUniqueId = (file) => {
|
|
12
19
|
if (!isFile(file)) {
|
|
13
20
|
return file.id;
|
|
@@ -29,12 +36,11 @@ var clearObjectURL = (fileWithPreview, disallowPreviewForNonImageFiles) => {
|
|
|
29
36
|
var useDropZone = (props) => {
|
|
30
37
|
const {
|
|
31
38
|
allowedFileTypes,
|
|
32
|
-
children,
|
|
33
39
|
classNames,
|
|
34
40
|
disallowDuplicates = true,
|
|
35
41
|
disallowPreviewForNonImageFiles = true,
|
|
42
|
+
extraContainerProps,
|
|
36
43
|
extraInputProps,
|
|
37
|
-
extraRootProps,
|
|
38
44
|
initialFiles,
|
|
39
45
|
maxFileCount,
|
|
40
46
|
maxFileSize,
|
|
@@ -45,8 +51,8 @@ var useDropZone = (props) => {
|
|
|
45
51
|
onUploadError,
|
|
46
52
|
onUploadErrors,
|
|
47
53
|
onUploadSuccess,
|
|
48
|
-
|
|
49
|
-
|
|
54
|
+
validator,
|
|
55
|
+
validatorForAllFiles
|
|
50
56
|
} = props ?? {};
|
|
51
57
|
const inputRef = useRef(null);
|
|
52
58
|
const initialFileArray = toArray(initialFiles).filter(Boolean);
|
|
@@ -77,8 +83,14 @@ var useDropZone = (props) => {
|
|
|
77
83
|
onError: onUploadError,
|
|
78
84
|
onErrors: onUploadErrors,
|
|
79
85
|
onSuccess: onUploadSuccess,
|
|
80
|
-
validationSettings: {
|
|
81
|
-
|
|
86
|
+
validationSettings: {
|
|
87
|
+
allowedFileTypes,
|
|
88
|
+
disallowDuplicates,
|
|
89
|
+
maxFileCount,
|
|
90
|
+
maxFileSize,
|
|
91
|
+
validator
|
|
92
|
+
},
|
|
93
|
+
validatorForAllFiles
|
|
82
94
|
});
|
|
83
95
|
if (validFiles.length === 0) {
|
|
84
96
|
setDropZoneState((prevState) => ({ ...prevState, errors }));
|
|
@@ -164,36 +176,36 @@ var useDropZone = (props) => {
|
|
|
164
176
|
const openFilePicker = useCallbackRef(() => {
|
|
165
177
|
inputRef.current?.click();
|
|
166
178
|
});
|
|
167
|
-
const
|
|
168
|
-
(
|
|
169
|
-
const
|
|
179
|
+
const getContainerProps = useCallback(
|
|
180
|
+
(containerProps) => {
|
|
181
|
+
const mergedContainerProps = mergeTwoProps(extraContainerProps, containerProps);
|
|
170
182
|
return {
|
|
171
|
-
...
|
|
183
|
+
...mergedContainerProps,
|
|
172
184
|
className: cnMerge(
|
|
173
185
|
"relative isolate flex flex-col",
|
|
174
|
-
|
|
186
|
+
mergedContainerProps.className,
|
|
175
187
|
classNames?.base,
|
|
176
188
|
dropZoneState.isDragging && [
|
|
177
189
|
"opacity-60",
|
|
178
190
|
classNames?.isDragging,
|
|
179
|
-
|
|
191
|
+
containerProps?.classNames?.isDragging
|
|
180
192
|
]
|
|
181
193
|
),
|
|
182
194
|
"data-dragging": dataAttr(dropZoneState.isDragging),
|
|
183
195
|
"data-scope": "dropzone",
|
|
184
196
|
// eslint-disable-next-line perfectionist/sort-objects -- I need data-scope to be first
|
|
185
|
-
"data-part": "
|
|
186
|
-
"data-slot": "dropzone-
|
|
187
|
-
onDragEnter: composeTwoEventHandlers(handleDragEnter,
|
|
188
|
-
onDragLeave: composeTwoEventHandlers(handleDragLeave,
|
|
189
|
-
onDragOver: composeTwoEventHandlers(handleDragOver,
|
|
190
|
-
onDrop: composeTwoEventHandlers(handleFileUpload,
|
|
197
|
+
"data-part": "container",
|
|
198
|
+
"data-slot": "dropzone-container",
|
|
199
|
+
onDragEnter: composeTwoEventHandlers(handleDragEnter, mergedContainerProps.onDragEnter),
|
|
200
|
+
onDragLeave: composeTwoEventHandlers(handleDragLeave, mergedContainerProps.onDragLeave),
|
|
201
|
+
onDragOver: composeTwoEventHandlers(handleDragOver, mergedContainerProps.onDragOver),
|
|
202
|
+
onDrop: composeTwoEventHandlers(handleFileUpload, mergedContainerProps.onDrop)
|
|
191
203
|
};
|
|
192
204
|
},
|
|
193
205
|
[
|
|
194
206
|
classNames?.base,
|
|
195
207
|
classNames?.isDragging,
|
|
196
|
-
|
|
208
|
+
extraContainerProps,
|
|
197
209
|
dropZoneState.isDragging,
|
|
198
210
|
handleDragEnter,
|
|
199
211
|
handleDragLeave,
|
|
@@ -233,7 +245,7 @@ var useDropZone = (props) => {
|
|
|
233
245
|
]
|
|
234
246
|
);
|
|
235
247
|
const savedOnRenderPropsChange = useCallbackRef(onRenderPropsChange);
|
|
236
|
-
const
|
|
248
|
+
const dropZoneResult = useMemo(() => {
|
|
237
249
|
const propsForRenderFn = {
|
|
238
250
|
dropZoneActions: {
|
|
239
251
|
addFiles,
|
|
@@ -247,8 +259,8 @@ var useDropZone = (props) => {
|
|
|
247
259
|
removeFile
|
|
248
260
|
},
|
|
249
261
|
dropZoneState,
|
|
262
|
+
getContainerProps,
|
|
250
263
|
getInputProps,
|
|
251
|
-
getRootProps,
|
|
252
264
|
inputRef
|
|
253
265
|
};
|
|
254
266
|
savedOnRenderPropsChange(propsForRenderFn);
|
|
@@ -260,7 +272,7 @@ var useDropZone = (props) => {
|
|
|
260
272
|
clearFiles,
|
|
261
273
|
dropZoneState,
|
|
262
274
|
getInputProps,
|
|
263
|
-
|
|
275
|
+
getContainerProps,
|
|
264
276
|
handleDragEnter,
|
|
265
277
|
handleDragLeave,
|
|
266
278
|
handleDragOver,
|
|
@@ -268,40 +280,48 @@ var useDropZone = (props) => {
|
|
|
268
280
|
openFilePicker,
|
|
269
281
|
removeFile
|
|
270
282
|
]);
|
|
271
|
-
|
|
272
|
-
const getResolvedChildren = () => {
|
|
273
|
-
return isFunction(selectedChildren) ? selectedChildren(renderProps) : selectedChildren;
|
|
274
|
-
};
|
|
275
|
-
return {
|
|
276
|
-
...renderProps,
|
|
277
|
-
getResolvedChildren
|
|
278
|
-
};
|
|
283
|
+
return dropZoneResult;
|
|
279
284
|
};
|
|
280
285
|
|
|
281
286
|
// src/components/ui/drop-zone/drop-zone.tsx
|
|
282
287
|
function DropZoneRoot(props) {
|
|
283
|
-
const { withInternalElements = true, ...restOfProps } = props;
|
|
284
|
-
const
|
|
285
|
-
const
|
|
286
|
-
const InputComponent = withInternalElements ?
|
|
287
|
-
const
|
|
288
|
-
const
|
|
289
|
-
const resolvedChildren = api.getResolvedChildren();
|
|
288
|
+
const { children, render, withInternalElements = true, ...restOfProps } = props;
|
|
289
|
+
const dropZone = useDropZone(restOfProps);
|
|
290
|
+
const ContainerComponent = withInternalElements ? DropZoneContainer : Fragment;
|
|
291
|
+
const InputComponent = withInternalElements ? DropZoneInput : Fragment;
|
|
292
|
+
const selectedChildren = children ?? render;
|
|
293
|
+
const resolvedChildren = isFunction(selectedChildren) ? selectedChildren(dropZone) : selectedChildren;
|
|
290
294
|
const couldChildrenContainSlots = isArray(resolvedChildren) || isValidElement(resolvedChildren) && resolvedChildren.type === Fragment;
|
|
291
|
-
const slots = getSlotMap(resolvedChildren
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
+
const slots = withInternalElements && couldChildrenContainSlots ? getSlotMap(resolvedChildren) : { default: resolvedChildren };
|
|
296
|
+
return /* @__PURE__ */ React.createElement(DropZoneContextProvider, { value: dropZone }, /* @__PURE__ */ React.createElement(ContainerComponent, null, /* @__PURE__ */ React.createElement(InputComponent, null), slots.default), isFunction(slots.preview) ? slots.preview(dropZone) : slots.preview);
|
|
297
|
+
}
|
|
298
|
+
function DropZoneInput(props) {
|
|
299
|
+
const { asChild, ...restOfProps } = props;
|
|
300
|
+
const dropZoneContext = useDropZoneContext();
|
|
301
|
+
const Component = asChild ? Slot : "input";
|
|
302
|
+
return /* @__PURE__ */ React.createElement(Component, { ...dropZoneContext.getInputProps(restOfProps) });
|
|
295
303
|
}
|
|
296
|
-
|
|
304
|
+
function DropZoneContainer(props) {
|
|
305
|
+
const { as: Element = "div", asChild, ...restOfProps } = props;
|
|
306
|
+
const dropZoneContext = useDropZoneContext();
|
|
307
|
+
const Component = asChild ? Slot : Element;
|
|
308
|
+
return /* @__PURE__ */ React.createElement(Component, { ...dropZoneContext.getContainerProps(restOfProps) });
|
|
309
|
+
}
|
|
310
|
+
var DropZoneImagePreview = withSlotNameAndSymbol("preview", (props) => {
|
|
311
|
+
const { children } = props;
|
|
312
|
+
const dropZoneContext = useDropZoneContext();
|
|
313
|
+
return isFunction(children) ? children(dropZoneContext) : children;
|
|
314
|
+
});
|
|
297
315
|
|
|
298
316
|
// src/components/ui/drop-zone/drop-zone-parts.ts
|
|
299
317
|
var drop_zone_parts_exports = {};
|
|
300
318
|
__export(drop_zone_parts_exports, {
|
|
319
|
+
Container: () => DropZoneContainer,
|
|
301
320
|
ImagePreview: () => DropZoneImagePreview,
|
|
321
|
+
Input: () => DropZoneInput,
|
|
302
322
|
Root: () => DropZoneRoot
|
|
303
323
|
});
|
|
304
324
|
|
|
305
|
-
export { drop_zone_parts_exports as DropZone, DropZoneImagePreview, DropZoneRoot, useDropZone };
|
|
325
|
+
export { drop_zone_parts_exports as DropZone, DropZoneContainer, DropZoneImagePreview, DropZoneInput, DropZoneRoot, useDropZone, useDropZoneContext };
|
|
306
326
|
//# sourceMappingURL=index.js.map
|
|
307
327
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/components/ui/drop-zone/drop-context.ts","../../../../../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":";;;;;;;;;;;;AAKO,IAAM,CAAC,uBAAA,EAAyB,kBAAkB,CAAA,GAAI,mBAAqC,CAAA;AAAA,EACjG,QAAU,EAAA,oBAAA;AAAA,EACV,IAAM,EAAA,iBAAA;AAAA,EACN,YAAc,EAAA;AACf,CAAC;ACLM,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,CA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,CAAA,aAAA,CAAc,WAAW,CAAG,EAAA,CAAA;AACnE;AAIO,SAAS,kBACf,KACC,EAAA;AACD,EAAA,MAAM,EAAE,EAAI,EAAA,OAAA,GAAU,OAAO,OAAS,EAAA,GAAG,aAAgB,GAAA,KAAA;AAEzD,EAAA,MAAM,kBAAkB,kBAAmB,EAAA;AAE3C,EAAM,MAAA,SAAA,GAAY,UAAU,IAAO,GAAA,OAAA;AAEnC,EAAA,2CAAQ,SAAW,EAAA,EAAA,GAAG,eAAgB,CAAA,iBAAA,CAAkB,WAAW,CAAG,EAAA,CAAA;AACvE;AAOO,IAAM,oBAAuB,GAAA,qBAAA,CAA0C,SAAW,EAAA,CAAC,KAAU,KAAA;AACnG,EAAM,MAAA,EAAE,UAAa,GAAA,KAAA;AAErB,EAAA,MAAM,kBAAkB,kBAAmB,EAAA;AAE3C,EAAA,OAAO,UAAW,CAAA,QAAQ,CAAI,GAAA,QAAA,CAAS,eAAe,CAAI,GAAA,QAAA;AAC3D,CAAC;;;ACrGD,IAAA,uBAAA,GAAA;AAAA,QAAA,CAAA,uBAAA,EAAA;AAAA,EAAA,SAAA,EAAA,MAAA,iBAAA;AAAA,EAAA,YAAA,EAAA,MAAA,oBAAA;AAAA,EAAA,KAAA,EAAA,MAAA,aAAA;AAAA,EAAA,IAAA,EAAA,MAAA;AAAA,CAAA,CAAA","file":"index.js","sourcesContent":["import { createCustomContext } from \"@zayne-labs/toolkit-react\";\nimport type { DropZoneResult } from \"./use-drop-zone\";\n\ntype DropZoneContext = DropZoneResult;\n\nexport const [DropZoneContextProvider, useDropZoneContext] = createCustomContext<DropZoneContext>({\n\thookName: \"useDropZoneContext\",\n\tname: \"DropZoneContext\",\n\tproviderName: \"DropZoneRoot\",\n});\n","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 InferProps,\n\tcomposeRefs,\n\tcomposeTwoEventHandlers,\n\tmergeTwoProps,\n} from \"@zayne-labs/toolkit-react/utils\";\nimport { type Prettify, isString } from \"@zayne-labs/toolkit-type-helpers\";\nimport { useCallback, useMemo, useRef, useState } from \"react\";\nimport { clearObjectURL, createObjectURL, generateUniqueId } from \"./utils\";\n\nexport type ContainerProps = 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 DropZoneResult = {\n\tdropZoneActions: DropZoneActions;\n\tdropZoneState: DropZoneState;\n\tgetContainerProps: (containerProps?: ContainerProps) => ContainerProps;\n\tgetInputProps: (inputProps?: InputProps) => InputProps;\n\tinputRef: React.RefObject<HTMLInputElement | null>;\n};\n\nexport type DropZoneProps = {\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<ContainerProps[\"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 container element\n\t */\n\textraContainerProps?: ContainerProps;\n\n\t/**\n\t * Extra props to pass to the input element\n\t */\n\textraInputProps?: InputProps;\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 the render props change\n\t */\n\tonRenderPropsChange?: (props: DropZoneResult) => 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 validation function.\n\t *\n\t * If the function returns false, the file will be rejected\n\t */\n\tvalidator?: NonNullable<FileValidationOptions[\"validationSettings\"]>[\"validator\"];\n\n\t/**\n\t * Custom validation function that runs after all file validation has occurred\n\t */\n\tvalidatorForAllFiles?: FileValidationOptions[\"validatorForAllFiles\"];\n};\n\nexport const useDropZone = (props?: DropZoneProps): DropZoneResult => {\n\tconst {\n\t\tallowedFileTypes,\n\t\tclassNames,\n\t\tdisallowDuplicates = true,\n\t\tdisallowPreviewForNonImageFiles = true,\n\t\textraContainerProps,\n\t\textraInputProps,\n\t\tinitialFiles,\n\t\tmaxFileCount,\n\t\tmaxFileSize,\n\t\tmultiple,\n\t\tonFilesChange,\n\t\tonRenderPropsChange,\n\t\tonUpload,\n\t\tonUploadError,\n\t\tonUploadErrors,\n\t\tonUploadSuccess,\n\t\tvalidator,\n\t\tvalidatorForAllFiles,\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: {\n\t\t\t\tallowedFileTypes,\n\t\t\t\tdisallowDuplicates,\n\t\t\t\tmaxFileCount,\n\t\t\t\tmaxFileSize,\n\t\t\t\tvalidator,\n\t\t\t},\n\t\t\tvalidatorForAllFiles,\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 (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 getContainerProps: DropZoneResult[\"getContainerProps\"] = useCallback(\n\t\t(containerProps) => {\n\t\t\tconst mergedContainerProps = mergeTwoProps(extraContainerProps, containerProps);\n\n\t\t\treturn {\n\t\t\t\t...mergedContainerProps,\n\t\t\t\tclassName: cnMerge(\n\t\t\t\t\t\"relative isolate flex flex-col\",\n\t\t\t\t\tmergedContainerProps.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\tcontainerProps?.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\": \"container\",\n\t\t\t\t\"data-slot\": \"dropzone-container\",\n\t\t\t\tonDragEnter: composeTwoEventHandlers(handleDragEnter, mergedContainerProps.onDragEnter),\n\t\t\t\tonDragLeave: composeTwoEventHandlers(handleDragLeave, mergedContainerProps.onDragLeave),\n\t\t\t\tonDragOver: composeTwoEventHandlers(handleDragOver, mergedContainerProps.onDragOver),\n\t\t\t\tonDrop: composeTwoEventHandlers(handleFileUpload, mergedContainerProps.onDrop),\n\t\t\t};\n\t\t},\n\t\t[\n\t\t\tclassNames?.base,\n\t\t\tclassNames?.isDragging,\n\t\t\textraContainerProps,\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: composeTwoEventHandlers(handleFileUpload, mergedInputProps.onChange),\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 savedOnRenderPropsChange = useCallbackRef(onRenderPropsChange);\n\n\tconst dropZoneResult = useMemo(() => {\n\t\tconst propsForRenderFn = {\n\t\t\tdropZoneActions: {\n\t\t\t\taddFiles,\n\t\t\t\tclearErrors,\n\t\t\t\tclearFiles,\n\t\t\t\thandleDragEnter,\n\t\t\t\thandleDragLeave,\n\t\t\t\thandleDragOver,\n\t\t\t\thandleFileUpload,\n\t\t\t\topenFilePicker,\n\t\t\t\tremoveFile,\n\t\t\t},\n\t\t\tdropZoneState,\n\t\t\tgetContainerProps,\n\t\t\tgetInputProps,\n\t\t\tinputRef,\n\t\t} satisfies DropZoneResult;\n\n\t\tsavedOnRenderPropsChange(propsForRenderFn);\n\n\t\treturn propsForRenderFn;\n\t}, [\n\t\tsavedOnRenderPropsChange,\n\t\taddFiles,\n\t\tclearErrors,\n\t\tclearFiles,\n\t\tdropZoneState,\n\t\tgetInputProps,\n\t\tgetContainerProps,\n\t\thandleDragEnter,\n\t\thandleDragLeave,\n\t\thandleDragOver,\n\t\thandleFileUpload,\n\t\topenFilePicker,\n\t\tremoveFile,\n\t]);\n\n\treturn dropZoneResult;\n};\n","\"use client\";\n\nimport * as React from \"react\";\n\nimport { Slot } from \"@/components/common\";\nimport { type GetSlotComponentProps, getSlotMap, withSlotNameAndSymbol } from \"@/lib/utils/getSlotMap\";\nimport type { DiscriminatedRenderProps, PolymorphicProps } from \"@zayne-labs/toolkit-react/utils\";\nimport { isArray, isFunction } from \"@zayne-labs/toolkit-type-helpers\";\nimport { Fragment as ReactFragment, isValidElement } from \"react\";\nimport { DropZoneContextProvider, useDropZoneContext } from \"./drop-context\";\nimport {\n\ttype ContainerProps,\n\ttype DropZoneProps,\n\ttype DropZoneResult,\n\ttype InputProps,\n\tuseDropZone,\n} from \"./use-drop-zone\";\n\ntype DropZoneRenderPropType = DiscriminatedRenderProps<\n\tReact.ReactNode | ((props: DropZoneResult) => React.ReactNode)\n>;\n\ntype DropZoneRootProps = DropZoneProps\n\t& DropZoneRenderPropType & {\n\t\t/**\n\t\t * Controls whether to include internal elements (root and input) or not.\n\t\t */\n\t\twithInternalElements?: boolean;\n\t};\n\nexport function DropZoneRoot(props: DropZoneRootProps) {\n\tconst { children, render, withInternalElements = true, ...restOfProps } = props;\n\n\tconst dropZone = useDropZone(restOfProps);\n\n\tconst ContainerComponent = withInternalElements ? DropZoneContainer : ReactFragment;\n\tconst InputComponent = withInternalElements ? DropZoneInput : ReactFragment;\n\n\tconst selectedChildren = children ?? render;\n\n\tconst resolvedChildren = isFunction(selectedChildren) ? selectedChildren(dropZone) : selectedChildren;\n\n\tconst couldChildrenContainSlots =\n\t\tisArray(resolvedChildren)\n\t\t|| (isValidElement(resolvedChildren) && resolvedChildren.type === ReactFragment);\n\n\tconst slots =\n\t\twithInternalElements && couldChildrenContainSlots\n\t\t\t? getSlotMap<SlotComponentProps>(resolvedChildren)\n\t\t\t: ({ default: resolvedChildren } as ReturnType<typeof getSlotMap<SlotComponentProps>>);\n\n\treturn (\n\t\t<DropZoneContextProvider value={dropZone}>\n\t\t\t<ContainerComponent>\n\t\t\t\t<InputComponent />\n\n\t\t\t\t{slots.default}\n\t\t\t</ContainerComponent>\n\n\t\t\t{isFunction(slots.preview) ? slots.preview(dropZone) : slots.preview}\n\t\t</DropZoneContextProvider>\n\t);\n}\n\ntype DropZoneInputProps = InputProps & { asChild?: boolean };\n\nexport function DropZoneInput(props: DropZoneInputProps) {\n\tconst { asChild, ...restOfProps } = props;\n\n\tconst dropZoneContext = useDropZoneContext();\n\n\tconst Component = asChild ? Slot : \"input\";\n\n\treturn <Component {...dropZoneContext.getInputProps(restOfProps)} />;\n}\n\ntype DropZoneContainerProps = ContainerProps & { asChild?: boolean };\n\nexport function DropZoneContainer<TElement extends React.ElementType = \"div\">(\n\tprops: PolymorphicProps<TElement, DropZoneContainerProps>\n) {\n\tconst { as: Element = \"div\", asChild, ...restOfProps } = props;\n\n\tconst dropZoneContext = useDropZoneContext();\n\n\tconst Component = asChild ? Slot : Element;\n\n\treturn <Component {...dropZoneContext.getContainerProps(restOfProps)} />;\n}\n\ntype SlotComponentProps = GetSlotComponentProps<\n\t\"preview\",\n\tReact.ReactNode | ((props: DropZoneResult) => React.ReactNode)\n>;\n\nexport const DropZoneImagePreview = withSlotNameAndSymbol<SlotComponentProps>(\"preview\", (props) => {\n\tconst { children } = props;\n\n\tconst dropZoneContext = useDropZoneContext();\n\n\treturn isFunction(children) ? children(dropZoneContext) : children;\n});\n","export {\n\tDropZoneRoot as Root,\n\tDropZoneImagePreview as ImagePreview,\n\tDropZoneInput as Input,\n\tDropZoneContainer as Container,\n} from \"./drop-zone\";\n"]}
|
|
@@ -1,12 +1,23 @@
|
|
|
1
1
|
import * as React$1 from 'react';
|
|
2
2
|
import { DiscriminatedRenderProps, InferProps, PolymorphicProps } from '@zayne-labs/toolkit-react/utils';
|
|
3
|
-
import { UseFormStateReturn,
|
|
3
|
+
import { UseFormStateReturn, Control, FieldPath, ControllerProps, ControllerRenderProps, ControllerFieldState, RegisterOptions, UseFormReturn, FieldPathValues, FieldPathValue } from 'react-hook-form';
|
|
4
4
|
export { useFormContext as useFormRootContext } from 'react-hook-form';
|
|
5
|
+
import { UnionDiscriminator } from '@zayne-labs/toolkit-type-helpers';
|
|
5
6
|
|
|
6
|
-
type
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
type RenderIconProps = {
|
|
8
|
+
isPasswordVisible: boolean;
|
|
9
|
+
};
|
|
10
|
+
type EyeIconObject = UnionDiscriminator<[
|
|
11
|
+
{
|
|
12
|
+
closed: React.ReactNode;
|
|
13
|
+
open: React.ReactNode;
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
renderIcon: (props: RenderIconProps) => React.ReactNode;
|
|
17
|
+
}
|
|
18
|
+
]>;
|
|
19
|
+
type FormRootContext = {
|
|
20
|
+
withEyeIcon: boolean | EyeIconObject | undefined;
|
|
10
21
|
};
|
|
11
22
|
type FieldContextValue = {
|
|
12
23
|
formDescriptionId: `${string}-(${string})-form-item-description`;
|
|
@@ -16,9 +27,14 @@ type FieldContextValue = {
|
|
|
16
27
|
};
|
|
17
28
|
type FormFieldContextProps = DiscriminatedRenderProps<(contextValue: FieldContextValue) => React.ReactNode>;
|
|
18
29
|
declare const useStrictFormFieldContext: () => FieldContextValue;
|
|
30
|
+
type FieldState = {
|
|
31
|
+
errors?: UseFormStateReturn<FieldValues>["errors"];
|
|
32
|
+
isDisabled?: boolean;
|
|
33
|
+
isInvalid?: boolean;
|
|
34
|
+
};
|
|
19
35
|
|
|
20
36
|
type FieldValues = Record<string, unknown>;
|
|
21
|
-
type FormRootProps<TFieldValues extends FieldValues> = React$1.ComponentPropsWithoutRef<"form"> & {
|
|
37
|
+
type FormRootProps<TFieldValues extends FieldValues> = FormRootContext & React$1.ComponentPropsWithoutRef<"form"> & {
|
|
22
38
|
children: React$1.ReactNode;
|
|
23
39
|
methods: UseFormReturn<TFieldValues>;
|
|
24
40
|
};
|
|
@@ -37,7 +53,6 @@ type FormFieldProps<TControl, TFieldValues extends FieldValues> = (TControl exte
|
|
|
37
53
|
withWrapper: false;
|
|
38
54
|
});
|
|
39
55
|
declare function FormField<TControl, TFieldValues extends FieldValues = FieldValues>(props: FormFieldProps<TControl, TFieldValues>): React$1.JSX.Element;
|
|
40
|
-
declare function FormControlledField<TFieldValues extends FieldValues>(props: ControllerProps<TFieldValues>): React$1.JSX.Element;
|
|
41
56
|
type FormFieldControllerRenderFn = (props: {
|
|
42
57
|
field: Omit<ControllerRenderProps, "value"> & {
|
|
43
58
|
value: never;
|
|
@@ -49,6 +64,7 @@ type FormFieldControllerProps = Omit<ControllerProps<FieldValues, FieldPath<Fiel
|
|
|
49
64
|
render: FormFieldControllerRenderFn;
|
|
50
65
|
};
|
|
51
66
|
declare function FormFieldController(props: FormFieldControllerProps): React$1.JSX.Element;
|
|
67
|
+
declare function FormFieldControlledField<TFieldValues extends FieldValues>(props: ControllerProps<TFieldValues>): React$1.JSX.Element;
|
|
52
68
|
declare function FormFieldContext(props: FormFieldContextProps): React$1.ReactNode;
|
|
53
69
|
declare function FormLabel(props: InferProps<"label">): React$1.JSX.Element;
|
|
54
70
|
declare function FormInputGroup(props: InferProps<"div">): React$1.JSX.Element;
|
|
@@ -74,7 +90,7 @@ type FormInputPrimitiveProps<TFieldValues extends FieldValues = FieldValues> = O
|
|
|
74
90
|
control?: Control<TFieldValues>;
|
|
75
91
|
fieldState?: FieldState;
|
|
76
92
|
name?: FieldPath<TFieldValues>;
|
|
77
|
-
withEyeIcon?:
|
|
93
|
+
withEyeIcon?: FormRootContext["withEyeIcon"];
|
|
78
94
|
};
|
|
79
95
|
type FormTextAreaPrimitiveProps<TFieldValues extends FieldValues = FieldValues> = React$1.ComponentPropsWithRef<"textarea"> & {
|
|
80
96
|
classNames?: {
|
|
@@ -131,7 +147,7 @@ type ErrorMessageRenderProps = {
|
|
|
131
147
|
"data-scope": "form";
|
|
132
148
|
"data-slot": "form-error-message";
|
|
133
149
|
id: string | undefined;
|
|
134
|
-
|
|
150
|
+
ref: React$1.RefCallback<HTMLElement>;
|
|
135
151
|
};
|
|
136
152
|
type ErrorMessageRenderState = {
|
|
137
153
|
errorMessage: string;
|
|
@@ -153,10 +169,10 @@ type FormErrorMessagePrimitiveProps<TFieldValues extends FieldValues> = Discrimi
|
|
|
153
169
|
disableErrorAnimation?: boolean;
|
|
154
170
|
disableScrollToErrorField?: boolean;
|
|
155
171
|
} & ({
|
|
156
|
-
|
|
172
|
+
fieldName: FieldPath<TFieldValues>;
|
|
157
173
|
type?: "regular";
|
|
158
174
|
} | {
|
|
159
|
-
|
|
175
|
+
fieldName: string;
|
|
160
176
|
type: "root";
|
|
161
177
|
});
|
|
162
178
|
type FormErrorMessagePrimitiveType = {
|
|
@@ -206,7 +222,7 @@ type FormSubscribeToFormStateProps<TFieldValues extends FieldValues> = Discrimin
|
|
|
206
222
|
declare function FormSubscribeToFormState<TFieldValues extends FieldValues = FieldValues>(props: FormSubscribeToFormStateProps<TFieldValues>): React$1.ReactNode;
|
|
207
223
|
|
|
208
224
|
declare namespace formParts {
|
|
209
|
-
export {
|
|
225
|
+
export { FormFieldControlledField as ControlledField, FormDescription as Description, FormErrorMessage as ErrorMessage, FormErrorMessagePrimitive as ErrorMessagePrimitive, FormField as Field, FormFieldContext as FieldContext, FormFieldController as FieldController, FormInput as Input, FormInputGroup as InputGroup, FormInputLeftItem as InputLeftItem, FormInputPrimitive as InputPrimitive, FormInputRightItem as InputRightItem, FormLabel as Label, FormRoot as Root, FormSelect as Select, FormSubmit as Submit, FormSubscribeToFieldValue as SubscribeToFieldValue, FormSubscribeToFormState as SubscribeToFormState, FormTextArea as TextArea, FormTextAreaPrimitive as TextAreaPrimitive };
|
|
210
226
|
}
|
|
211
227
|
|
|
212
|
-
export { type FieldValues, formParts as Form,
|
|
228
|
+
export { type FieldValues, formParts as Form, FormDescription, FormErrorMessage, FormErrorMessagePrimitive, type FormErrorMessagePrimitiveProps, FormField, FormFieldContext, FormFieldControlledField, FormFieldController, FormInput, FormInputGroup, FormInputLeftItem, FormInputPrimitive, type FormInputProps, FormInputRightItem, FormLabel, FormRoot, FormSelect, FormSelectPrimitive, type FormSelectProps, FormSubmit, FormSubscribeToFieldValue, FormSubscribeToFormState, FormTextArea, FormTextAreaPrimitive, type FormTextAreaProps, useStrictFormFieldContext as useFormFieldContext };
|