@zayne-labs/ui-react 0.9.8 → 0.9.12

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.
Files changed (79) hide show
  1. package/dist/esm/await-parts-BJ6C-y1f.d.ts +36 -0
  2. package/dist/esm/chunk-CLGH26AQ.js +337 -0
  3. package/dist/esm/chunk-CLGH26AQ.js.map +1 -0
  4. package/dist/esm/chunk-CWUEUCR5.js +3 -0
  5. package/dist/esm/chunk-CWUEUCR5.js.map +1 -0
  6. package/dist/esm/chunk-EYWTW54R.js +42 -0
  7. package/dist/esm/chunk-EYWTW54R.js.map +1 -0
  8. package/dist/esm/chunk-G5BNZM66.js +32 -0
  9. package/dist/esm/chunk-G5BNZM66.js.map +1 -0
  10. package/dist/esm/{chunk-IREUBYDK.js → chunk-JC52CA2O.js} +26 -23
  11. package/dist/esm/chunk-JC52CA2O.js.map +1 -0
  12. package/dist/esm/chunk-KLEJZWKY.js +45 -0
  13. package/dist/esm/chunk-KLEJZWKY.js.map +1 -0
  14. package/dist/esm/{chunk-V5DSTESN.js → chunk-M7YXNGT6.js} +3 -3
  15. package/dist/esm/{chunk-V5DSTESN.js.map → chunk-M7YXNGT6.js.map} +1 -1
  16. package/dist/esm/chunk-MT2MQDK2.js +13 -0
  17. package/dist/esm/chunk-MT2MQDK2.js.map +1 -0
  18. package/dist/esm/chunk-MY5NL5PB.js +627 -0
  19. package/dist/esm/chunk-MY5NL5PB.js.map +1 -0
  20. package/dist/esm/{chunk-XZRSR3EM.js → chunk-N4274N5K.js} +6 -2
  21. package/dist/esm/chunk-N4274N5K.js.map +1 -0
  22. package/dist/esm/chunk-V5ZPMMIH.js +121 -0
  23. package/dist/esm/chunk-V5ZPMMIH.js.map +1 -0
  24. package/dist/esm/{chunk-2P3P5AXH.js → chunk-Y5VBSXZS.js} +14 -7
  25. package/dist/esm/chunk-Y5VBSXZS.js.map +1 -0
  26. package/dist/esm/{chunk-IUEPHHGO.js → chunk-YO5LJ7ZJ.js} +2 -2
  27. package/dist/esm/{chunk-IUEPHHGO.js.map → chunk-YO5LJ7ZJ.js.map} +1 -1
  28. package/dist/esm/chunk-Z6JJE4G6.js +68 -0
  29. package/dist/esm/chunk-Z6JJE4G6.js.map +1 -0
  30. package/dist/esm/chunk-ZSDYJOYB.js +274 -0
  31. package/dist/esm/chunk-ZSDYJOYB.js.map +1 -0
  32. package/dist/esm/components/common/await/index.d.ts +10 -12
  33. package/dist/esm/components/common/await/index.js +5 -24
  34. package/dist/esm/components/common/await/index.js.map +1 -1
  35. package/dist/esm/components/common/error-boundary/index.d.ts +6 -30
  36. package/dist/esm/components/common/error-boundary/index.js +1 -2
  37. package/dist/esm/components/common/for/index.d.ts +6 -20
  38. package/dist/esm/components/common/index.d.ts +13 -0
  39. package/dist/esm/components/common/index.js +14 -0
  40. package/dist/esm/components/common/show/index.js +2 -2
  41. package/dist/esm/components/common/slot/index.d.ts +7 -3
  42. package/dist/esm/components/common/slot/index.js +1 -1
  43. package/dist/esm/components/common/suspense-with-boundary/index.d.ts +3 -3
  44. package/dist/esm/components/common/suspense-with-boundary/index.js +2 -12
  45. package/dist/esm/components/common/suspense-with-boundary/index.js.map +1 -1
  46. package/dist/esm/components/common/switch/index.js +3 -40
  47. package/dist/esm/components/common/switch/index.js.map +1 -1
  48. package/dist/esm/components/common/teleport/index.js +1 -29
  49. package/dist/esm/components/common/teleport/index.js.map +1 -1
  50. package/dist/esm/components/ui/card/index.js +4 -43
  51. package/dist/esm/components/ui/card/index.js.map +1 -1
  52. package/dist/esm/components/ui/carousel/index.js +14 -273
  53. package/dist/esm/components/ui/carousel/index.js.map +1 -1
  54. package/dist/esm/components/ui/drag-scroll/index.js +2 -119
  55. package/dist/esm/components/ui/drag-scroll/index.js.map +1 -1
  56. package/dist/esm/components/ui/drop-zone/index.d.ts +8 -181
  57. package/dist/esm/components/ui/drop-zone/index.js +15 -327
  58. package/dist/esm/components/ui/drop-zone/index.js.map +1 -1
  59. package/dist/esm/components/ui/form/index.js +7 -625
  60. package/dist/esm/components/ui/form/index.js.map +1 -1
  61. package/dist/esm/components/ui/index.d.ts +11 -0
  62. package/dist/esm/components/ui/index.js +21 -0
  63. package/dist/esm/drop-zone-parts-CvseSoXA.d.ts +186 -0
  64. package/dist/esm/error-boundary-BD0X61Sg.d.ts +28 -0
  65. package/dist/esm/for-8C6fFbN6.d.ts +21 -0
  66. package/dist/esm/{lib/utils/getSlotMap/index.d.ts → getSlotMap-DTkxtGhd.d.ts} +10 -8
  67. package/dist/esm/lib/utils/{getSlot/index.d.ts → index.d.ts} +1 -0
  68. package/dist/esm/lib/utils/index.js +5 -0
  69. package/dist/esm/lib/utils/index.js.map +1 -0
  70. package/dist/esm/{types-CeWumkhm.d.ts → types-mdfDDNrr.d.ts} +9 -6
  71. package/dist/style.css +1 -1
  72. package/package.json +17 -16
  73. package/dist/esm/chunk-2P3P5AXH.js.map +0 -1
  74. package/dist/esm/chunk-IREUBYDK.js.map +0 -1
  75. package/dist/esm/chunk-XZRSR3EM.js.map +0 -1
  76. package/dist/esm/lib/utils/getSlot/index.js +0 -4
  77. package/dist/esm/lib/utils/getSlotMap/index.js +0 -4
  78. /package/dist/esm/{lib/utils/getSlot → components/common}/index.js.map +0 -0
  79. /package/dist/esm/{lib/utils/getSlotMap → components/ui}/index.js.map +0 -0
@@ -0,0 +1,36 @@
1
+ import * as React from 'react';
2
+ import { a as GetSlotComponentProps } from './getSlotMap-DTkxtGhd.js';
3
+ import { E as ErrorBoundaryProps } from './types-mdfDDNrr.js';
4
+ import { SuspenseWithBoundaryProps } from './components/common/suspense-with-boundary/index.js';
5
+
6
+ type RenderPropFn<TValue> = (result: TValue) => React.ReactNode;
7
+ type ChildrenType<TValue> = React.ReactNode | RenderPropFn<TValue>;
8
+ type AwaitRootProps<TValue> = Pick<SuspenseWithBoundaryProps, "errorFallback" | "fallback"> & {
9
+ asChild?: boolean;
10
+ children: ChildrenType<TValue>;
11
+ promise: Promise<TValue>;
12
+ wrapperVariant?: "all" | "none" | "only-errorBoundary" | "only-suspense";
13
+ };
14
+ declare function AwaitRoot<TValue>(props: AwaitRootProps<TValue>): React.JSX.Element;
15
+ type AwaitSuccessProps<TValue = unknown> = GetSlotComponentProps<"default", ChildrenType<TValue>>;
16
+ declare function AwaitSuccess<TPromiseOrValue, TValue = Awaited<TPromiseOrValue>>(props: Pick<AwaitSuccessProps<TValue>, "children">): React.ReactNode;
17
+ type AwaitPendingProps = GetSlotComponentProps<"pending", React.SuspenseProps["fallback"]>;
18
+ declare const AwaitPending: {
19
+ (props: Pick<AwaitPendingProps, "children">): React.ReactNode;
20
+ readonly slotName?: "pending" | undefined;
21
+ readonly slotSymbol?: symbol;
22
+ };
23
+ type AwaitErrorProps = GetSlotComponentProps<"error", ErrorBoundaryProps["fallback"]>;
24
+ declare const AwaitError: {
25
+ (props: Pick<AwaitErrorProps, "children"> & {
26
+ asChild?: boolean;
27
+ }): React.ReactNode;
28
+ readonly slotName?: "error" | undefined;
29
+ readonly slotSymbol?: symbol;
30
+ };
31
+
32
+ declare namespace awaitParts {
33
+ export { AwaitError as Error, AwaitPending as Pending, AwaitRoot as Root, AwaitSuccess as Success };
34
+ }
35
+
36
+ export { AwaitRoot as A, awaitParts as a, AwaitSuccess as b, AwaitPending as c, AwaitError as d };
@@ -0,0 +1,337 @@
1
+ import { dataAttr } from './chunk-DNYM6XGW.js';
2
+ import { cnMerge } from './chunk-OHG7GB7O.js';
3
+ import { withSlotNameAndSymbol, getSlotMap } from './chunk-N4274N5K.js';
4
+ import { slot_parts_exports } from './chunk-Y5VBSXZS.js';
5
+ import { __export } from './chunk-PZ5AY32C.js';
6
+ import * as React from 'react';
7
+ import { isValidElement, Fragment, useRef, useState, useCallback, useMemo } from 'react';
8
+ import { isFunction, isArray, isString, isFile } from '@zayne-labs/toolkit-type-helpers';
9
+ import { createCustomContext, useCallbackRef } from '@zayne-labs/toolkit-react';
10
+ import { toArray, handleFileValidation, createImagePreview } from '@zayne-labs/toolkit-core';
11
+ import { mergeTwoProps, composeTwoEventHandlers, composeRefs } from '@zayne-labs/toolkit-react/utils';
12
+
13
+ var [DropZoneContextProvider, useDropZoneContext] = createCustomContext({
14
+ hookName: "useDropZoneContext",
15
+ name: "DropZoneContext",
16
+ providerName: "DropZoneRoot"
17
+ });
18
+ var generateUniqueId = (file) => {
19
+ if (!isFile(file)) {
20
+ return file.id;
21
+ }
22
+ return `${file.name}-(${Math.round(performance.now())})-${crypto.randomUUID().slice(0, 8)}`;
23
+ };
24
+ var createObjectURL = (file, disallowPreviewForNonImageFiles) => {
25
+ if (disallowPreviewForNonImageFiles && !file.type.startsWith("image/")) return;
26
+ return createImagePreview(file);
27
+ };
28
+ var clearObjectURL = (fileWithPreview, disallowPreviewForNonImageFiles) => {
29
+ if (!isFile(fileWithPreview?.file)) return;
30
+ if (disallowPreviewForNonImageFiles && !fileWithPreview.file.type.startsWith("image/")) return;
31
+ if (!fileWithPreview.preview) return;
32
+ URL.revokeObjectURL(fileWithPreview.preview);
33
+ };
34
+
35
+ // src/components/ui/drop-zone/use-drop-zone.ts
36
+ var useDropZone = (props) => {
37
+ const {
38
+ allowedFileTypes,
39
+ classNames,
40
+ disallowDuplicates = true,
41
+ disallowPreviewForNonImageFiles = true,
42
+ extraContainerProps,
43
+ extraInputProps,
44
+ initialFiles,
45
+ maxFileCount,
46
+ maxFileSize,
47
+ multiple,
48
+ onFilesChange,
49
+ onRenderPropsChange,
50
+ onUpload,
51
+ onUploadError,
52
+ onUploadErrors,
53
+ onUploadSuccess,
54
+ validator,
55
+ validatorForAllFiles,
56
+ withDefaultFilePicker = true
57
+ } = props ?? {};
58
+ const inputRef = useRef(null);
59
+ const initialFileArray = toArray(initialFiles).filter(Boolean);
60
+ const [dropZoneState, setDropZoneState] = useState({
61
+ errors: [],
62
+ filesWithPreview: initialFileArray.map((fileMeta) => ({
63
+ file: fileMeta,
64
+ id: fileMeta.id,
65
+ preview: fileMeta.url
66
+ })),
67
+ isDragging: false
68
+ });
69
+ const toggleIsDragging = (value) => {
70
+ setDropZoneState((prevState) => ({ ...prevState, isDragging: value }));
71
+ };
72
+ const addFiles = useCallbackRef((fileList, event) => {
73
+ if (!fileList || fileList.length === 0) {
74
+ console.warn("No file selected!");
75
+ return;
76
+ }
77
+ clearErrors();
78
+ if (!multiple) {
79
+ clearFiles();
80
+ }
81
+ const { errors, validFiles } = handleFileValidation({
82
+ existingFiles: dropZoneState.filesWithPreview.map((fileWithPreview) => fileWithPreview.file),
83
+ newFiles: fileList,
84
+ onError: onUploadError,
85
+ onErrors: onUploadErrors,
86
+ onSuccess: onUploadSuccess,
87
+ validationSettings: {
88
+ allowedFileTypes,
89
+ disallowDuplicates,
90
+ maxFileCount,
91
+ maxFileSize,
92
+ validator
93
+ },
94
+ validatorForAllFiles
95
+ });
96
+ if (validFiles.length === 0) {
97
+ setDropZoneState((prevState) => ({ ...prevState, errors }));
98
+ return;
99
+ }
100
+ const filesWithPreview = validFiles.map((file) => ({
101
+ file,
102
+ id: generateUniqueId(file),
103
+ preview: createObjectURL(file, disallowPreviewForNonImageFiles)
104
+ }));
105
+ if (event) {
106
+ onUpload?.({ event, filesWithPreview });
107
+ }
108
+ const newFileUploadState = {
109
+ ...dropZoneState,
110
+ errors,
111
+ ...event?.type === "drop" && { isDragging: false },
112
+ filesWithPreview: multiple ? [...dropZoneState.filesWithPreview, ...filesWithPreview] : filesWithPreview
113
+ };
114
+ onFilesChange?.({ filesWithPreview: newFileUploadState.filesWithPreview });
115
+ setDropZoneState(newFileUploadState);
116
+ inputRef.current && (inputRef.current.value = "");
117
+ });
118
+ const clearFiles = useCallbackRef(() => {
119
+ dropZoneState.filesWithPreview.forEach(
120
+ (fileWithPreview) => clearObjectURL(fileWithPreview, disallowPreviewForNonImageFiles)
121
+ );
122
+ const newFileUploadState = {
123
+ ...dropZoneState,
124
+ errors: [],
125
+ filesWithPreview: []
126
+ };
127
+ onFilesChange?.({ filesWithPreview: newFileUploadState.filesWithPreview });
128
+ setDropZoneState(newFileUploadState);
129
+ inputRef.current && (inputRef.current.value = "");
130
+ });
131
+ const removeFile = useCallbackRef((fileToRemoveOrId) => {
132
+ const actualFileToRemove = isString(fileToRemoveOrId) ? dropZoneState.filesWithPreview.find((file) => file.id === fileToRemoveOrId) : fileToRemoveOrId;
133
+ if (!actualFileToRemove) return;
134
+ clearObjectURL(actualFileToRemove, disallowPreviewForNonImageFiles);
135
+ const newFilesWithPreview = dropZoneState.filesWithPreview.filter(
136
+ (file) => file.id !== actualFileToRemove.id
137
+ );
138
+ onFilesChange?.({ filesWithPreview: newFilesWithPreview });
139
+ setDropZoneState({
140
+ ...dropZoneState,
141
+ errors: [],
142
+ filesWithPreview: newFilesWithPreview
143
+ });
144
+ });
145
+ const clearErrors = useCallbackRef(() => {
146
+ setDropZoneState((prevState) => ({ ...prevState, errors: [] }));
147
+ });
148
+ const handleFileUpload = useCallbackRef((event) => {
149
+ if (inputRef.current?.disabled) return;
150
+ if (event.type === "drop") {
151
+ event.preventDefault();
152
+ event.stopPropagation();
153
+ }
154
+ const fileList = event.type === "drop" ? event.dataTransfer.files : event.target.files;
155
+ if (!multiple) {
156
+ const firstFile = fileList?.[0];
157
+ firstFile && addFiles([firstFile], event);
158
+ return;
159
+ }
160
+ addFiles(fileList, event);
161
+ });
162
+ const handleDragEnter = useCallbackRef((event) => {
163
+ event.preventDefault();
164
+ event.stopPropagation();
165
+ toggleIsDragging(true);
166
+ });
167
+ const handleDragOver = useCallbackRef((event) => {
168
+ event.preventDefault();
169
+ event.stopPropagation();
170
+ toggleIsDragging(true);
171
+ });
172
+ const handleDragLeave = useCallbackRef((event) => {
173
+ event.preventDefault();
174
+ event.stopPropagation();
175
+ toggleIsDragging(false);
176
+ });
177
+ const openFilePicker = useCallbackRef(() => {
178
+ inputRef.current?.click();
179
+ });
180
+ const getContainerProps = useCallback(
181
+ (containerProps) => {
182
+ const mergedContainerProps = mergeTwoProps(extraContainerProps, containerProps);
183
+ return {
184
+ ...mergedContainerProps,
185
+ className: cnMerge(
186
+ "relative isolate flex flex-col",
187
+ mergedContainerProps.className,
188
+ classNames?.base,
189
+ dropZoneState.isDragging && [
190
+ "opacity-60",
191
+ classNames?.isDragging,
192
+ containerProps?.classNames?.isDragging
193
+ ]
194
+ ),
195
+ "data-dragging": dataAttr(dropZoneState.isDragging),
196
+ "data-scope": "dropzone",
197
+ // eslint-disable-next-line perfectionist/sort-objects -- I need data-scope to be first
198
+ "data-part": "container",
199
+ "data-slot": "dropzone-container",
200
+ onDragEnter: composeTwoEventHandlers(handleDragEnter, mergedContainerProps.onDragEnter),
201
+ onDragLeave: composeTwoEventHandlers(handleDragLeave, mergedContainerProps.onDragLeave),
202
+ onDragOver: composeTwoEventHandlers(handleDragOver, mergedContainerProps.onDragOver),
203
+ onDrop: composeTwoEventHandlers(handleFileUpload, mergedContainerProps.onDrop)
204
+ };
205
+ },
206
+ [
207
+ classNames?.base,
208
+ classNames?.isDragging,
209
+ extraContainerProps,
210
+ dropZoneState.isDragging,
211
+ handleDragEnter,
212
+ handleDragLeave,
213
+ handleDragOver,
214
+ handleFileUpload
215
+ ]
216
+ );
217
+ const getInputProps = useCallback(
218
+ (inputProps) => {
219
+ const mergedInputProps = mergeTwoProps(extraInputProps, inputProps);
220
+ return {
221
+ ...mergedInputProps,
222
+ accept: allowedFileTypes ? allowedFileTypes.join(", ") : mergedInputProps.accept,
223
+ className: cnMerge(
224
+ withDefaultFilePicker ? "absolute inset-0 z-[100] cursor-pointer opacity-0" : "hidden",
225
+ classNames?.input,
226
+ mergedInputProps.className
227
+ ),
228
+ "data-dragging": dataAttr(dropZoneState.isDragging),
229
+ "data-scope": "dropzone",
230
+ // eslint-disable-next-line perfectionist/sort-objects -- I need data-scope to be first
231
+ "data-part": "input",
232
+ "data-slot": "dropzone-input",
233
+ multiple: multiple ?? mergedInputProps.multiple,
234
+ onChange: composeTwoEventHandlers(handleFileUpload, mergedInputProps.onChange),
235
+ ref: composeRefs(inputRef, mergedInputProps.ref),
236
+ type: "file"
237
+ };
238
+ },
239
+ [
240
+ allowedFileTypes,
241
+ classNames?.input,
242
+ extraInputProps,
243
+ dropZoneState.isDragging,
244
+ handleFileUpload,
245
+ multiple,
246
+ withDefaultFilePicker
247
+ ]
248
+ );
249
+ const savedOnRenderPropsChange = useCallbackRef(onRenderPropsChange);
250
+ const dropZoneResult = useMemo(() => {
251
+ const propsForRenderFn = {
252
+ dropZoneActions: {
253
+ addFiles,
254
+ clearErrors,
255
+ clearFiles,
256
+ handleDragEnter,
257
+ handleDragLeave,
258
+ handleDragOver,
259
+ handleFileUpload,
260
+ openFilePicker,
261
+ removeFile
262
+ },
263
+ dropZoneState,
264
+ getContainerProps,
265
+ getInputProps,
266
+ inputRef
267
+ };
268
+ savedOnRenderPropsChange(propsForRenderFn);
269
+ return propsForRenderFn;
270
+ }, [
271
+ savedOnRenderPropsChange,
272
+ addFiles,
273
+ clearErrors,
274
+ clearFiles,
275
+ dropZoneState,
276
+ getInputProps,
277
+ getContainerProps,
278
+ handleDragEnter,
279
+ handleDragLeave,
280
+ handleDragOver,
281
+ handleFileUpload,
282
+ openFilePicker,
283
+ removeFile
284
+ ]);
285
+ return dropZoneResult;
286
+ };
287
+
288
+ // src/components/ui/drop-zone/drop-zone.tsx
289
+ function DropZoneRoot(props) {
290
+ const { children, render, withInternalElements = true, ...restOfProps } = props;
291
+ const dropZone = useDropZone(restOfProps);
292
+ const ContainerComponent = withInternalElements ? DropZoneContainer : Fragment;
293
+ const InputComponent = withInternalElements ? DropZoneInput : Fragment;
294
+ const selectedChildren = children ?? render;
295
+ const resolvedChildren = isFunction(selectedChildren) ? selectedChildren(dropZone) : selectedChildren;
296
+ const couldChildrenContainSlots = isArray(resolvedChildren) || isValidElement(resolvedChildren) && resolvedChildren.type === Fragment;
297
+ const slots = withInternalElements && couldChildrenContainSlots ? getSlotMap(resolvedChildren) : { default: resolvedChildren };
298
+ return /* @__PURE__ */ React.createElement(DropZoneContextProvider, { value: dropZone }, /* @__PURE__ */ React.createElement(ContainerComponent, null, /* @__PURE__ */ React.createElement(InputComponent, null), slots.default), slots.preview);
299
+ }
300
+ function DropZoneInput(props) {
301
+ const { asChild, ...restOfProps } = props;
302
+ const dropZoneContext = useDropZoneContext();
303
+ const Component = asChild ? slot_parts_exports.Root : "input";
304
+ return /* @__PURE__ */ React.createElement(Component, { ...dropZoneContext.getInputProps(restOfProps) });
305
+ }
306
+ function DropZoneContainer(props) {
307
+ const { as: Element = "div", asChild, ...restOfProps } = props;
308
+ const dropZoneContext = useDropZoneContext();
309
+ const Component = asChild ? slot_parts_exports.Root : Element;
310
+ return /* @__PURE__ */ React.createElement(Component, { ...dropZoneContext.getContainerProps(restOfProps) });
311
+ }
312
+ function DropZoneContext(props) {
313
+ const { children } = props;
314
+ const dropZoneContext = useDropZoneContext();
315
+ return children(dropZoneContext);
316
+ }
317
+ var DropZoneImagePreview = withSlotNameAndSymbol("preview", (props) => {
318
+ const { children } = props;
319
+ if (isFunction(children)) {
320
+ return /* @__PURE__ */ React.createElement(DropZoneContext, null, children);
321
+ }
322
+ return children;
323
+ });
324
+
325
+ // src/components/ui/drop-zone/drop-zone-parts.ts
326
+ var drop_zone_parts_exports = {};
327
+ __export(drop_zone_parts_exports, {
328
+ Container: () => DropZoneContainer,
329
+ Context: () => DropZoneContext,
330
+ ImagePreview: () => DropZoneImagePreview,
331
+ Input: () => DropZoneInput,
332
+ Root: () => DropZoneRoot
333
+ });
334
+
335
+ export { DropZoneContainer, DropZoneContext, DropZoneImagePreview, DropZoneInput, DropZoneRoot, drop_zone_parts_exports, useDropZone, useDropZoneContext };
336
+ //# sourceMappingURL=chunk-CLGH26AQ.js.map
337
+ //# sourceMappingURL=chunk-CLGH26AQ.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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,GAAA,KAAA;AAErB,EAAI,IAAA,UAAA,CAAW,QAAQ,CAAG,EAAA;AACzB,IAAO,uBAAA,KAAA,CAAA,aAAA,CAAC,uBAAiB,QAAS,CAAA;AAAA;AAGnC,EAAO,OAAA,QAAA;AACR,CAAC;;;AC9GD,IAAA,uBAAA,GAAA;AAAA,QAAA,CAAA,uBAAA,EAAA;AAAA,EAAA,SAAA,EAAA,MAAA,iBAAA;AAAA,EAAA,OAAA,EAAA,MAAA,eAAA;AAAA,EAAA,YAAA,EAAA,MAAA,oBAAA;AAAA,EAAA,KAAA,EAAA,MAAA,aAAA;AAAA,EAAA,IAAA,EAAA,MAAA;AAAA,CAAA,CAAA","file":"chunk-CLGH26AQ.js","sourcesContent":["import { createCustomContext } from \"@zayne-labs/toolkit-react\";\nimport type { UseDropZoneResult } from \"./use-drop-zone\";\n\ntype DropZoneContext = UseDropZoneResult;\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 UseDropZoneResult = {\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 UseDropZoneProps = {\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: UseDropZoneResult) => 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\t/**\n\t * Whether to allow the default file picker via the file input element\n\t * @default true\n\t */\n\twithDefaultFilePicker?: boolean;\n};\n\nexport const useDropZone = (props?: UseDropZoneProps): UseDropZoneResult => {\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\twithDefaultFilePicker = true,\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: UseDropZoneResult[\"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: 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\twithDefaultFilePicker ? \"absolute inset-0 z-[100] cursor-pointer opacity-0\" : \"hidden\",\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\twithDefaultFilePicker,\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 UseDropZoneResult;\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 InputProps,\n\ttype UseDropZoneProps,\n\ttype UseDropZoneResult,\n\tuseDropZone,\n} from \"./use-drop-zone\";\n\nexport type DropZoneRenderPropType = DiscriminatedRenderProps<\n\tReact.ReactNode | ((props: UseDropZoneResult) => React.ReactNode)\n>;\n\nexport type DropZoneRootProps = DropZoneRenderPropType\n\t& UseDropZoneProps & {\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{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.Root : \"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.Root : Element;\n\n\treturn <Component {...dropZoneContext.getContainerProps(restOfProps)} />;\n}\n\ntype RenderPropFn = (props: UseDropZoneResult) => React.ReactNode;\n\ntype SlotComponentProps = GetSlotComponentProps<\"preview\", React.ReactNode | RenderPropFn>;\n\nexport function DropZoneContext(props: { children: RenderPropFn }) {\n\tconst { children } = props;\n\n\tconst dropZoneContext = useDropZoneContext();\n\n\treturn children(dropZoneContext);\n}\n\nexport const DropZoneImagePreview = withSlotNameAndSymbol<SlotComponentProps>(\"preview\", (props) => {\n\tconst { children } = props;\n\n\tif (isFunction(children)) {\n\t\treturn <DropZoneContext>{children}</DropZoneContext>;\n\t}\n\n\treturn children;\n});\n","export {\n\tDropZoneRoot as Root,\n\tDropZoneImagePreview as ImagePreview,\n\tDropZoneContext as Context,\n\tDropZoneInput as Input,\n\tDropZoneContainer as Container,\n} from \"./drop-zone\";\n"]}
@@ -0,0 +1,3 @@
1
+
2
+ //# sourceMappingURL=chunk-CWUEUCR5.js.map
3
+ //# sourceMappingURL=chunk-CWUEUCR5.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"chunk-CWUEUCR5.js"}
@@ -0,0 +1,42 @@
1
+ import { getSingleSlot, getRegularChildren } from './chunk-YO5LJ7ZJ.js';
2
+ import { __export } from './chunk-PZ5AY32C.js';
3
+ import 'react';
4
+ import { isFunction } from '@zayne-labs/toolkit-type-helpers';
5
+
6
+ var defaultValueSymbol = Symbol("default-value");
7
+ function SwitchRoot(props) {
8
+ const { children, value = defaultValueSymbol } = props;
9
+ const defaultCase = getSingleSlot(children, SwitchDefault, {
10
+ errorMessage: "Only one <Switch.Default> component is allowed",
11
+ throwOnMultipleSlotMatch: true
12
+ });
13
+ const childrenCasesArray = getRegularChildren(children, SwitchDefault);
14
+ const matchedCase = childrenCasesArray.find((child) => {
15
+ if (value === defaultValueSymbol) {
16
+ return Boolean(child.props.when);
17
+ }
18
+ return child.props.when === value;
19
+ });
20
+ return matchedCase ?? defaultCase;
21
+ }
22
+ function SwitchMatch(props) {
23
+ const { children, when } = props;
24
+ const resolvedChildren = isFunction(children) ? children(when) : children;
25
+ return resolvedChildren;
26
+ }
27
+ function SwitchDefault({ children }) {
28
+ return children;
29
+ }
30
+ SwitchDefault.slotSymbol = Symbol("switch-default");
31
+
32
+ // src/components/common/switch/switch-parts.ts
33
+ var switch_parts_exports = {};
34
+ __export(switch_parts_exports, {
35
+ Default: () => SwitchDefault,
36
+ Match: () => SwitchMatch,
37
+ Root: () => SwitchRoot
38
+ });
39
+
40
+ export { SwitchDefault, SwitchMatch, SwitchRoot, switch_parts_exports };
41
+ //# sourceMappingURL=chunk-EYWTW54R.js.map
42
+ //# sourceMappingURL=chunk-EYWTW54R.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/components/common/switch/switch.tsx","../../src/components/common/switch/switch-parts.ts"],"names":[],"mappings":";;;;;AAcA,IAAM,kBAAA,GAAqB,OAAO,eAAe,CAAA;AAE1C,SAAS,WAAW,KAAoB,EAAA;AAC9C,EAAA,MAAM,EAAE,QAAA,EAAU,KAAQ,GAAA,kBAAA,EAAuB,GAAA,KAAA;AAEjD,EAAM,MAAA,WAAA,GAAc,aAAc,CAAA,QAAA,EAAU,aAAe,EAAA;AAAA,IAC1D,YAAc,EAAA,gDAAA;AAAA,IACd,wBAA0B,EAAA;AAAA,GAC1B,CAAA;AAED,EAAM,MAAA,kBAAA,GAAqB,kBAAmB,CAAA,QAAA,EAAU,aAAa,CAAA;AAErE,EAAA,MAAM,WAAc,GAAA,kBAAA,CAAmB,IAAK,CAAA,CAAC,KAAU,KAAA;AAEtD,IAAA,IAAI,UAAU,kBAAoB,EAAA;AACjC,MAAO,OAAA,OAAA,CAAQ,KAAM,CAAA,KAAA,CAAM,IAAI,CAAA;AAAA;AAIhC,IAAO,OAAA,KAAA,CAAM,MAAM,IAAS,KAAA,KAAA;AAAA,GAC5B,CAAA;AAED,EAAA,OAAO,WAAe,IAAA,WAAA;AACvB;AAOO,SAAS,YAAmB,KAAgC,EAAA;AAClE,EAAM,MAAA,EAAE,QAAU,EAAA,IAAA,EAAS,GAAA,KAAA;AAE3B,EAAA,MAAM,mBAAmB,UAAW,CAAA,QAAQ,CAAI,GAAA,QAAA,CAAS,IAAa,CAAI,GAAA,QAAA;AAE1E,EAAO,OAAA,gBAAA;AACR;AAEO,SAAS,aAAA,CAAc,EAAE,QAAA,EAA2C,EAAA;AAC1E,EAAO,OAAA,QAAA;AACR;AACA,aAAc,CAAA,UAAA,GAAa,OAAO,gBAAgB,CAAA;;;ACvDlD,IAAA,oBAAA,GAAA;AAAA,QAAA,CAAA,oBAAA,EAAA;AAAA,EAAA,OAAA,EAAA,MAAA,aAAA;AAAA,EAAA,KAAA,EAAA,MAAA,WAAA;AAAA,EAAA,IAAA,EAAA,MAAA;AAAA,CAAA,CAAA","file":"chunk-EYWTW54R.js","sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\n\nimport { getRegularChildren, getSingleSlot } from \"@/lib/utils/getSlot\";\nimport { isFunction } from \"@zayne-labs/toolkit-type-helpers\";\n\ntype ValidSwitchComponentType = React.ReactElement<SwitchMatchProps<unknown>>;\n\ntype SwitchProps = {\n\tchildren: ValidSwitchComponentType | ValidSwitchComponentType[];\n\tvalue?: unknown;\n};\n\nconst defaultValueSymbol = Symbol(\"default-value\");\n\nexport function SwitchRoot(props: SwitchProps) {\n\tconst { children, value = defaultValueSymbol } = props;\n\n\tconst defaultCase = getSingleSlot(children, SwitchDefault, {\n\t\terrorMessage: \"Only one <Switch.Default> component is allowed\",\n\t\tthrowOnMultipleSlotMatch: true,\n\t});\n\n\tconst childrenCasesArray = getRegularChildren(children, SwitchDefault) as ValidSwitchComponentType[];\n\n\tconst matchedCase = childrenCasesArray.find((child) => {\n\t\t// == If value is defaultValueSymbol, match the cases in order like switch(true)\n\t\tif (value === defaultValueSymbol) {\n\t\t\treturn Boolean(child.props.when);\n\t\t}\n\n\t\t// == Otherwise, match the cases like switch(value)\n\t\treturn child.props.when === value;\n\t});\n\n\treturn matchedCase ?? defaultCase;\n}\n\ntype SwitchMatchProps<TWhen> = {\n\tchildren: React.ReactNode | ((value: TWhen) => React.ReactNode);\n\twhen: false | TWhen | null | undefined;\n};\n\nexport function SwitchMatch<TWhen>(props: SwitchMatchProps<TWhen>) {\n\tconst { children, when } = props;\n\n\tconst resolvedChildren = isFunction(children) ? children(when as TWhen) : children;\n\n\treturn resolvedChildren;\n}\n\nexport function SwitchDefault({ children }: { children: React.ReactNode }) {\n\treturn children;\n}\nSwitchDefault.slotSymbol = Symbol(\"switch-default\");\n","export { SwitchDefault as Default, SwitchMatch as Match, SwitchRoot as Root } from \"./switch\";\n"]}
@@ -0,0 +1,32 @@
1
+ import { useState, useEffect } from 'react';
2
+ import { isString } from '@zayne-labs/toolkit-type-helpers';
3
+ import { createPortal } from 'react-dom';
4
+
5
+ // src/components/common/teleport/teleport.tsx
6
+ function Teleport(props) {
7
+ const { children, insertPosition, to } = props;
8
+ const [portalContainer, setPortalContainer] = useState(null);
9
+ useEffect(() => {
10
+ if (!to) return;
11
+ if (insertPosition) return;
12
+ const destination = isString(to) ? document.querySelector(to) : to;
13
+ destination && setPortalContainer(destination);
14
+ }, [to, insertPosition]);
15
+ useEffect(() => {
16
+ if (!to) return;
17
+ if (!insertPosition) return;
18
+ const destination = isString(to) ? document.querySelector(to) : to;
19
+ const tempWrapper = document.createElement("div");
20
+ tempWrapper.style.display = "contents";
21
+ destination?.insertAdjacentElement(insertPosition, tempWrapper);
22
+ setPortalContainer(tempWrapper);
23
+ return () => {
24
+ tempWrapper.remove();
25
+ };
26
+ }, [to, insertPosition]);
27
+ return portalContainer && createPortal(children, portalContainer);
28
+ }
29
+
30
+ export { Teleport };
31
+ //# sourceMappingURL=chunk-G5BNZM66.js.map
32
+ //# sourceMappingURL=chunk-G5BNZM66.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/components/common/teleport/teleport.tsx"],"names":[],"mappings":";;;;;AAgBA,SAAS,SAAS,KAAoB,EAAA;AACrC,EAAA,MAAM,EAAE,QAAA,EAAU,cAAgB,EAAA,EAAA,EAAO,GAAA,KAAA;AAEzC,EAAA,MAAM,CAAC,eAAA,EAAiB,kBAAkB,CAAA,GAAI,SAA6B,IAAI,CAAA;AAI/E,EAAA,SAAA,CAAU,MAAM;AACf,IAAA,IAAI,CAAC,EAAI,EAAA;AAET,IAAA,IAAI,cAAgB,EAAA;AAEpB,IAAA,MAAM,cAAc,QAAS,CAAA,EAAE,IAAI,QAAS,CAAA,aAAA,CAA2B,EAAE,CAAI,GAAA,EAAA;AAE7E,IAAA,WAAA,IAAe,mBAAmB,WAAW,CAAA;AAAA,GAC3C,EAAA,CAAC,EAAI,EAAA,cAAc,CAAC,CAAA;AAEvB,EAAA,SAAA,CAAU,MAAM;AACf,IAAA,IAAI,CAAC,EAAI,EAAA;AAET,IAAA,IAAI,CAAC,cAAgB,EAAA;AAErB,IAAA,MAAM,cAAc,QAAS,CAAA,EAAE,IAAI,QAAS,CAAA,aAAA,CAA2B,EAAE,CAAI,GAAA,EAAA;AAE7E,IAAM,MAAA,WAAA,GAAc,QAAS,CAAA,aAAA,CAAc,KAAK,CAAA;AAChD,IAAA,WAAA,CAAY,MAAM,OAAU,GAAA,UAAA;AAE5B,IAAa,WAAA,EAAA,qBAAA,CAAsB,gBAAgB,WAAW,CAAA;AAE9D,IAAA,kBAAA,CAAmB,WAAW,CAAA;AAE9B,IAAA,OAAO,MAAM;AACZ,MAAA,WAAA,CAAY,MAAO,EAAA;AAAA,KACpB;AAAA,GACE,EAAA,CAAC,EAAI,EAAA,cAAc,CAAC,CAAA;AAIvB,EAAO,OAAA,eAAA,IAAmB,YAAa,CAAA,QAAA,EAAU,eAAe,CAAA;AACjE","file":"chunk-G5BNZM66.js","sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\n\nimport { type AnyString, isString } from \"@zayne-labs/toolkit-type-helpers\";\nimport { useEffect, useState } from \"react\";\nimport { createPortal } from \"react-dom\";\n\ntype ValidHtmlTags = keyof HTMLElementTagNameMap;\n\ntype PortalProps = {\n\tchildren: React.ReactNode;\n\tinsertPosition?: InsertPosition;\n\tto: AnyString | HTMLElement | ValidHtmlTags | null;\n};\n\nfunction Teleport(props: PortalProps) {\n\tconst { children, insertPosition, to } = props;\n\n\tconst [portalContainer, setPortalContainer] = useState<HTMLElement | null>(null);\n\n\t/* eslint-disable react-hooks-extra/no-direct-set-state-in-use-effect -- Allow */\n\n\tuseEffect(() => {\n\t\tif (!to) return;\n\n\t\tif (insertPosition) return;\n\n\t\tconst destination = isString(to) ? document.querySelector<HTMLElement>(to) : to;\n\n\t\tdestination && setPortalContainer(destination);\n\t}, [to, insertPosition]);\n\n\tuseEffect(() => {\n\t\tif (!to) return;\n\n\t\tif (!insertPosition) return;\n\n\t\tconst destination = isString(to) ? document.querySelector<HTMLElement>(to) : to;\n\n\t\tconst tempWrapper = document.createElement(\"div\");\n\t\ttempWrapper.style.display = \"contents\";\n\n\t\tdestination?.insertAdjacentElement(insertPosition, tempWrapper);\n\n\t\tsetPortalContainer(tempWrapper);\n\n\t\treturn () => {\n\t\t\ttempWrapper.remove();\n\t\t};\n\t}, [to, insertPosition]);\n\n\t/* eslint-enable react-hooks-extra/no-direct-set-state-in-use-effect -- Allow */\n\n\treturn portalContainer && createPortal(children, portalContainer);\n}\n\nexport { Teleport };\n"]}
@@ -1,10 +1,10 @@
1
- import { getSingleSlot } from './chunk-IUEPHHGO.js';
2
1
  import { createCustomContext, useCallbackRef } from '@zayne-labs/toolkit-react';
3
2
  import * as React from 'react';
4
3
  import { useState, Component } from 'react';
5
4
  import { isFunction } from '@zayne-labs/toolkit-type-helpers';
6
5
 
7
- var [ErrorBoundaryContextProvider, useErrorBoundaryContext] = createCustomContext({
6
+ // src/components/common/error-boundary/error-boundary-context.ts
7
+ var [ErrorBoundaryContext, useErrorBoundaryContext] = createCustomContext({
8
8
  hookName: "useErrorBoundaryContext",
9
9
  name: "ErrorBoundaryContext",
10
10
  providerName: "ErrorBoundaryContextProvider"
@@ -37,8 +37,8 @@ var initialState = {
37
37
  error: null,
38
38
  hasError: false
39
39
  };
40
- var hasArrayChanged = (a = [], b = []) => {
41
- return a.length !== b.length || a.some((item, index) => !Object.is(item, b[index]));
40
+ var hasArrayChanged = (arrayOne = [], arrayTwo = []) => {
41
+ return arrayOne.length !== arrayTwo.length || arrayOne.some((item, index) => !Object.is(item, arrayTwo[index]));
42
42
  };
43
43
  var ErrorBoundary = class extends Component {
44
44
  constructor(props) {
@@ -49,13 +49,20 @@ var ErrorBoundary = class extends Component {
49
49
  return { error, hasError: true };
50
50
  }
51
51
  componentDidCatch(error, info) {
52
- this.props.onError?.(error, info);
52
+ this.props.onError?.({
53
+ error,
54
+ info
55
+ });
53
56
  }
54
57
  componentDidUpdate(prevProps, prevState) {
55
58
  const { hasError } = this.state;
56
59
  const { resetKeys } = this.props;
57
60
  if (hasError && prevState.error !== null && hasArrayChanged(prevProps.resetKeys, resetKeys)) {
58
- this.props.onReset?.({ next: resetKeys, prev: prevProps.resetKeys, reason: "keys" });
61
+ this.props.onReset?.({
62
+ next: resetKeys,
63
+ prev: prevProps.resetKeys,
64
+ reason: "keys"
65
+ });
59
66
  this.setState(initialState);
60
67
  }
61
68
  }
@@ -63,19 +70,18 @@ var ErrorBoundary = class extends Component {
63
70
  const { children, fallback } = this.props;
64
71
  const { error, hasError } = this.state;
65
72
  let childToRender = children;
66
- const fallBackSlot = getSingleSlot(children, ErrorBoundaryFallBack);
67
73
  if (hasError) {
68
74
  switch (true) {
69
- case Boolean(fallBackSlot): {
70
- childToRender = fallBackSlot;
71
- break;
72
- }
73
- case Boolean(fallback): {
75
+ case isFunction(fallback): {
74
76
  const fallbackRenderProps = {
75
77
  error,
76
78
  resetErrorBoundary: this.#resetErrorBoundary
77
79
  };
78
- childToRender = isFunction(fallback) ? fallback(fallbackRenderProps) : fallback;
80
+ childToRender = fallback(fallbackRenderProps);
81
+ break;
82
+ }
83
+ case Boolean(fallback): {
84
+ childToRender = fallback;
79
85
  break;
80
86
  }
81
87
  default: {
@@ -88,23 +94,20 @@ var ErrorBoundary = class extends Component {
88
94
  hasError,
89
95
  resetErrorBoundary: this.#resetErrorBoundary
90
96
  };
91
- return /* @__PURE__ */ React.createElement(ErrorBoundaryContextProvider, { value: contextValue }, childToRender);
97
+ return /* @__PURE__ */ React.createElement(ErrorBoundaryContext, { value: contextValue }, childToRender);
92
98
  }
93
99
  #resetErrorBoundary = (...parameters) => {
94
100
  const { error } = this.state;
95
101
  if (error !== null) {
96
- this.props.onReset?.({ parameters, reason: "imperative-api" });
102
+ this.props.onReset?.({
103
+ args: parameters,
104
+ reason: "imperative-api"
105
+ });
97
106
  this.setState(initialState);
98
107
  }
99
108
  };
100
109
  };
101
- function ErrorBoundaryFallBack(props) {
102
- const { children } = props;
103
- const { error, resetErrorBoundary } = useErrorBoundaryContext();
104
- const fallbackRenderProps = { error, resetErrorBoundary };
105
- return isFunction(children) ? children(fallbackRenderProps) : children;
106
- }
107
110
 
108
111
  export { ErrorBoundary, useErrorBoundary, useErrorBoundaryContext };
109
- //# sourceMappingURL=chunk-IREUBYDK.js.map
110
- //# sourceMappingURL=chunk-IREUBYDK.js.map
112
+ //# sourceMappingURL=chunk-JC52CA2O.js.map
113
+ //# sourceMappingURL=chunk-JC52CA2O.js.map