@zayne-labs/ui-react 0.9.21 → 0.10.3

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 (97) hide show
  1. package/dist/esm/{await-Fe4LFRKd.js → await-fjas2Q-C.js} +6 -8
  2. package/dist/esm/await-fjas2Q-C.js.map +1 -0
  3. package/dist/esm/{card-jkLXbuiw.js → card-TD60Xux0.js} +2 -2
  4. package/dist/esm/card-TD60Xux0.js.map +1 -0
  5. package/dist/esm/{carousel-Dvp-qURP.js → carousel-YXXtZ85s.js} +120 -102
  6. package/dist/esm/carousel-YXXtZ85s.js.map +1 -0
  7. package/dist/esm/cn-_FbtIrlZ.js.map +1 -1
  8. package/dist/esm/components/common/await/index.d.ts +4 -5
  9. package/dist/esm/components/common/await/index.js +5 -5
  10. package/dist/esm/components/common/error-boundary/index.d.ts +1 -1
  11. package/dist/esm/components/common/error-boundary/index.js +1 -1
  12. package/dist/esm/components/common/for/index.d.ts +1 -1
  13. package/dist/esm/components/common/for/index.js +1 -1
  14. package/dist/esm/components/common/index.d.ts +9 -10
  15. package/dist/esm/components/common/index.js +10 -10
  16. package/dist/esm/components/common/show/index.d.ts +1 -1
  17. package/dist/esm/components/common/show/index.js +2 -2
  18. package/dist/esm/components/common/slot/index.d.ts +1 -1
  19. package/dist/esm/components/common/slot/index.js +1 -1
  20. package/dist/esm/components/common/suspense-with-boundary/index.d.ts +2 -2
  21. package/dist/esm/components/common/suspense-with-boundary/index.js +2 -2
  22. package/dist/esm/components/common/switch/index.d.ts +1 -1
  23. package/dist/esm/components/common/switch/index.js +2 -2
  24. package/dist/esm/components/common/teleport/index.d.ts +1 -1
  25. package/dist/esm/components/common/teleport/index.js +1 -1
  26. package/dist/esm/components/ui/card/index.d.ts +1 -1
  27. package/dist/esm/components/ui/card/index.js +2 -2
  28. package/dist/esm/components/ui/carousel/index.d.ts +2 -2
  29. package/dist/esm/components/ui/carousel/index.js +12 -12
  30. package/dist/esm/components/ui/drag-scroll/index.d.ts +1 -1
  31. package/dist/esm/components/ui/drag-scroll/index.js +1 -1
  32. package/dist/esm/components/ui/drop-zone/index.d.ts +2 -3
  33. package/dist/esm/components/ui/drop-zone/index.js +12 -12
  34. package/dist/esm/components/ui/form/index.d.ts +1 -1
  35. package/dist/esm/components/ui/form/index.js +4 -4
  36. package/dist/esm/components/ui/index.d.ts +5 -6
  37. package/dist/esm/components/ui/index.js +15 -15
  38. package/dist/esm/{drag-scroll-BLjij7aI.js → drag-scroll-De6-soln.js} +16 -9
  39. package/dist/esm/drag-scroll-De6-soln.js.map +1 -0
  40. package/dist/esm/drop-zone-BPfSu99L.js +381 -0
  41. package/dist/esm/drop-zone-BPfSu99L.js.map +1 -0
  42. package/dist/esm/{error-boundary-B3ycUZ1t.js → error-boundary-xM9An3gz.js} +3 -4
  43. package/dist/esm/error-boundary-xM9An3gz.js.map +1 -0
  44. package/dist/esm/{for-aTw1TgJo.js → for-DGs2XZ21.js} +6 -6
  45. package/dist/esm/for-DGs2XZ21.js.map +1 -0
  46. package/dist/esm/{form-6RV0u4YT.js → form-BnSpmc4f.js} +14 -18
  47. package/dist/esm/form-BnSpmc4f.js.map +1 -0
  48. package/dist/esm/{getSlot-D1_uG-Ym.js → getSlot-Cf5ON6lE.js} +2 -2
  49. package/dist/esm/getSlot-Cf5ON6lE.js.map +1 -0
  50. package/dist/esm/{index-BwnMUHzm.d.ts → index-BBJzo-WC.d.ts} +2 -3
  51. package/dist/esm/index-BEv8nXKb.d.ts +183 -0
  52. package/dist/esm/{getSlotMap-DZlQN8--.d.ts → index-BNrCAe9Y.d.ts} +58 -2
  53. package/dist/esm/{index-gT9tVHv1.d.ts → index-BYhH4Fm0.d.ts} +1 -1
  54. package/dist/esm/{index-YFi-sIuR.d.ts → index-BaONHZq0.d.ts} +6 -6
  55. package/dist/esm/{index-XYFc-mmy.d.ts → index-BeDmH7lX.d.ts} +1 -2
  56. package/dist/esm/{index-CIM4YPg5.d.ts → index-CMwCQ8qR.d.ts} +6 -7
  57. package/dist/esm/{index-B3N6YbN8.d.ts → index-CWKQ5V4B.d.ts} +2 -2
  58. package/dist/esm/{index-CNE9Cime.d.ts → index-CnvH74ea.d.ts} +4 -4
  59. package/dist/esm/{index-UX3DaMVe.d.ts → index-DJjxpXUk.d.ts} +1 -2
  60. package/dist/esm/{index-CGI7EVlK.d.ts → index-DVr1tbxh.d.ts} +1 -2
  61. package/dist/esm/{index-DT8F8QKc.d.ts → index-DqutTJQB.d.ts} +25 -32
  62. package/dist/esm/{index-CFNg1R-m.d.ts → index-eCX5RJ41.d.ts} +2 -2
  63. package/dist/esm/{index-BsjcsNQh.d.ts → index-lKxE9WPi.d.ts} +2 -2
  64. package/dist/esm/lib/utils/index.d.ts +1 -2
  65. package/dist/esm/lib/utils/index.js +2 -2
  66. package/dist/esm/{show-DNPzdLi-.js → show-BabiXbf7.js} +3 -3
  67. package/dist/esm/show-BabiXbf7.js.map +1 -0
  68. package/dist/esm/{slot-RXTKo4L7.js → slot-D1062oA5.js} +29 -28
  69. package/dist/esm/slot-D1062oA5.js.map +1 -0
  70. package/dist/esm/{suspense-with-boundary-TrQxYRG6.js → suspense-with-boundary-CEVORL8K.js} +2 -2
  71. package/dist/esm/suspense-with-boundary-CEVORL8K.js.map +1 -0
  72. package/dist/esm/{switch-B2gKl94R.js → switch-CCMD01Rs.js} +3 -3
  73. package/dist/esm/switch-CCMD01Rs.js.map +1 -0
  74. package/dist/esm/{teleport-dlSjWj_t.js → teleport-DfuYOzsj.js} +2 -2
  75. package/dist/esm/teleport-DfuYOzsj.js.map +1 -0
  76. package/dist/esm/{utils-D4YNWj2X.js → utils-ChjmDoRe.js} +2 -2
  77. package/dist/esm/utils-ChjmDoRe.js.map +1 -0
  78. package/dist/style.css +39 -5
  79. package/package.json +20 -21
  80. package/dist/esm/await-Fe4LFRKd.js.map +0 -1
  81. package/dist/esm/card-jkLXbuiw.js.map +0 -1
  82. package/dist/esm/carousel-Dvp-qURP.js.map +0 -1
  83. package/dist/esm/drag-scroll-BLjij7aI.js.map +0 -1
  84. package/dist/esm/drop-zone-Beip1k4x.js +0 -313
  85. package/dist/esm/drop-zone-Beip1k4x.js.map +0 -1
  86. package/dist/esm/error-boundary-B3ycUZ1t.js.map +0 -1
  87. package/dist/esm/for-aTw1TgJo.js.map +0 -1
  88. package/dist/esm/form-6RV0u4YT.js.map +0 -1
  89. package/dist/esm/getSlot-D1_uG-Ym.js.map +0 -1
  90. package/dist/esm/index-BilTdK_M.d.ts +0 -193
  91. package/dist/esm/index-DRiwJkJC.d.ts +0 -60
  92. package/dist/esm/show-DNPzdLi-.js.map +0 -1
  93. package/dist/esm/slot-RXTKo4L7.js.map +0 -1
  94. package/dist/esm/suspense-with-boundary-TrQxYRG6.js.map +0 -1
  95. package/dist/esm/switch-B2gKl94R.js.map +0 -1
  96. package/dist/esm/teleport-dlSjWj_t.js.map +0 -1
  97. package/dist/esm/utils-D4YNWj2X.js.map +0 -1
@@ -0,0 +1,381 @@
1
+ import { __export } from "./chunk-Cl8Af3a2.js";
2
+ import { SlotRoot } from "./slot-D1062oA5.js";
3
+ import { cnMerge } from "./cn-_FbtIrlZ.js";
4
+ import { isFile, isFunction, isString } from "@zayne-labs/toolkit-type-helpers";
5
+ import { useCallback, useMemo, useRef } from "react";
6
+ import { createImagePreview, createStore, dataAttr, handleFileValidationAsync, toArray } from "@zayne-labs/toolkit-core";
7
+ import { createCustomContext, useCallbackRef, useConstant, useShallowComparedValue, useStore } from "@zayne-labs/toolkit-react";
8
+ import { jsx, jsxs } from "react/jsx-runtime";
9
+ import { composeRefs, composeTwoEventHandlers, mergeTwoProps } from "@zayne-labs/toolkit-react/utils";
10
+ import { createZustandContext } from "@zayne-labs/toolkit-react/zustand";
11
+
12
+ //#region src/components/ui/drop-zone/drop-zone-context.ts
13
+ const [DropZoneStoreContextProvider, useDropZoneStoreContext] = createZustandContext({
14
+ hookName: "useDropZoneStoreContext",
15
+ name: "DropZoneStoreContext",
16
+ providerName: "DropZoneRoot"
17
+ });
18
+ const [DropZonePropGettersContextProvider, usePropGettersContext] = createCustomContext({
19
+ hookName: "usePropGettersContext",
20
+ name: "PropGettersContext",
21
+ providerName: "DropZoneRoot"
22
+ });
23
+
24
+ //#endregion
25
+ //#region src/components/ui/drop-zone/utils.ts
26
+ const generateUniqueId = (file) => {
27
+ if (!isFile(file)) return file.id;
28
+ return `${file.name}-(${Math.round(performance.now())})-${crypto.randomUUID().slice(0, 8)}`;
29
+ };
30
+ const createObjectURL = (file, disallowPreviewForNonImageFiles) => {
31
+ if (disallowPreviewForNonImageFiles && !file.type.startsWith("image/")) return;
32
+ return createImagePreview(file);
33
+ };
34
+ const clearObjectURL = (fileState, disallowPreviewForNonImageFiles) => {
35
+ if (!isFile(fileState?.file)) return;
36
+ if (disallowPreviewForNonImageFiles && !fileState.file.type.startsWith("image/")) return;
37
+ if (!fileState.preview) return;
38
+ URL.revokeObjectURL(fileState.preview);
39
+ };
40
+
41
+ //#endregion
42
+ //#region src/components/ui/drop-zone/drop-zone-store.ts
43
+ const createDropZoneStore = (initStoreValues) => {
44
+ const { allowedFileTypes, disablePreviewForNonImageFiles, initialFiles, inputRef, maxFileCount, maxFileSize, multiple, onFilesChange, onUpload, onUploadError, onUploadErrorCollection, onUploadSuccess, rejectDuplicateFiles, validator } = initStoreValues;
45
+ const initialFileArray = toArray(initialFiles).filter(Boolean);
46
+ const clearInputValue = () => {
47
+ if (!inputRef.current) return;
48
+ inputRef.current.value = "";
49
+ };
50
+ const store = createStore((set, get) => ({
51
+ errors: [],
52
+ fileStateArray: initialFileArray.map((fileMeta) => ({
53
+ file: fileMeta,
54
+ id: fileMeta.id,
55
+ preview: fileMeta.url
56
+ })),
57
+ isDraggingOver: false,
58
+ actions: {
59
+ addFiles: async (files) => {
60
+ if (!files || files.length === 0) {
61
+ console.warn("No file selected!");
62
+ return;
63
+ }
64
+ const { fileStateArray } = get();
65
+ const newFiles = !multiple ? [files[0]] : files;
66
+ const { errors, validFiles } = await handleFileValidationAsync({
67
+ existingFiles: fileStateArray.map((fileWithPreview) => fileWithPreview.file),
68
+ hooks: {
69
+ onError: onUploadError,
70
+ onErrorCollection: onUploadErrorCollection,
71
+ onSuccess: onUploadSuccess
72
+ },
73
+ newFiles,
74
+ settings: {
75
+ allowedFileTypes,
76
+ maxFileCount,
77
+ maxFileSize,
78
+ rejectDuplicateFiles,
79
+ validator
80
+ }
81
+ });
82
+ if (validFiles.length === 0) {
83
+ set({
84
+ errors,
85
+ isDraggingOver: false
86
+ });
87
+ return;
88
+ }
89
+ const newFileStateArray = validFiles.map((file) => ({
90
+ file,
91
+ id: generateUniqueId(file),
92
+ preview: createObjectURL(file, disablePreviewForNonImageFiles)
93
+ }));
94
+ set({
95
+ errors,
96
+ fileStateArray: multiple ? [...fileStateArray, ...newFileStateArray] : newFileStateArray,
97
+ isDraggingOver: false
98
+ });
99
+ await onUpload?.({ fileStateArray: newFileStateArray });
100
+ },
101
+ clearErrors: () => {
102
+ set({ errors: [] });
103
+ },
104
+ clearFiles: () => {
105
+ const { fileStateArray } = get();
106
+ for (const fileState of fileStateArray) clearObjectURL(fileState, disablePreviewForNonImageFiles);
107
+ set({ fileStateArray: [] });
108
+ },
109
+ handleChange: async (event) => {
110
+ const fileList = event.target.files;
111
+ const { actions } = get();
112
+ await actions.addFiles(fileList);
113
+ clearInputValue();
114
+ },
115
+ handleDragEnter: (event) => {
116
+ event.preventDefault();
117
+ event.stopPropagation();
118
+ set({ isDraggingOver: true });
119
+ },
120
+ handleDragLeave: (event) => {
121
+ event.preventDefault();
122
+ event.stopPropagation();
123
+ set({ isDraggingOver: false });
124
+ },
125
+ handleDragOver: (event) => {
126
+ event.preventDefault();
127
+ event.stopPropagation();
128
+ },
129
+ handleDrop: async (event) => {
130
+ event.preventDefault();
131
+ event.stopPropagation();
132
+ if (inputRef.current?.disabled) return;
133
+ const fileList = event.dataTransfer.files;
134
+ const { actions } = get();
135
+ await actions.addFiles(fileList);
136
+ },
137
+ openFilePicker: () => {
138
+ inputRef.current?.click();
139
+ },
140
+ removeFile: (fileToRemoveOrFileId) => {
141
+ const { fileStateArray } = get();
142
+ const actualFileToRemove = isString(fileToRemoveOrFileId) ? fileStateArray.find((file) => file.id === fileToRemoveOrFileId) : fileToRemoveOrFileId;
143
+ if (!actualFileToRemove) return;
144
+ clearObjectURL(actualFileToRemove, disablePreviewForNonImageFiles);
145
+ const updatedFileStateArray = fileStateArray.filter((file) => file.id !== actualFileToRemove.id);
146
+ set({
147
+ errors: [],
148
+ fileStateArray: updatedFileStateArray
149
+ });
150
+ }
151
+ }
152
+ }));
153
+ store.subscribe.withSelector((state) => state.fileStateArray, (fileStateArray) => {
154
+ onFilesChange?.({ fileStateArray });
155
+ });
156
+ return store;
157
+ };
158
+
159
+ //#endregion
160
+ //#region src/components/ui/drop-zone/use-drop-zone.ts
161
+ const useDropZone = (props) => {
162
+ const { allowedFileTypes, classNames, disablePreviewForNonImageFiles = true, extraProps, initialFiles, maxFileCount, maxFileSize, multiple, onFilesChange, onUpload, onUploadError, onUploadErrorCollection, onUploadSuccess, rejectDuplicateFiles = true, shouldOpenFilePickerOnAreaClick = true, validator } = props ?? {};
163
+ const inputRef = useRef(null);
164
+ const savedOnFilesChange = useCallbackRef(onFilesChange);
165
+ const savedOnUpload = useCallbackRef(onUpload);
166
+ const savedOnUploadError = useCallbackRef(onUploadError);
167
+ const savedOnUploadErrorCollection = useCallbackRef(onUploadErrorCollection);
168
+ const savedOnUploadSuccess = useCallbackRef(onUploadSuccess);
169
+ const savedValidator = useCallbackRef(validator);
170
+ const constantInitialFiles = useConstant(() => initialFiles);
171
+ const shallowComparedMaxFileSize = useShallowComparedValue(maxFileSize);
172
+ const shallowComparedAllowedFileTypes = useShallowComparedValue(allowedFileTypes);
173
+ const storeApi = useMemo(() => {
174
+ return createDropZoneStore({
175
+ allowedFileTypes: shallowComparedAllowedFileTypes,
176
+ disablePreviewForNonImageFiles,
177
+ initialFiles: constantInitialFiles,
178
+ inputRef,
179
+ maxFileCount,
180
+ maxFileSize: shallowComparedMaxFileSize,
181
+ multiple,
182
+ onFilesChange: savedOnFilesChange,
183
+ onUpload: savedOnUpload,
184
+ onUploadError: savedOnUploadError,
185
+ onUploadErrorCollection: savedOnUploadErrorCollection,
186
+ onUploadSuccess: savedOnUploadSuccess,
187
+ rejectDuplicateFiles,
188
+ validator: savedValidator
189
+ });
190
+ }, [
191
+ shallowComparedAllowedFileTypes,
192
+ disablePreviewForNonImageFiles,
193
+ constantInitialFiles,
194
+ maxFileCount,
195
+ shallowComparedMaxFileSize,
196
+ multiple,
197
+ savedOnFilesChange,
198
+ savedOnUpload,
199
+ savedOnUploadError,
200
+ savedOnUploadErrorCollection,
201
+ savedOnUploadSuccess,
202
+ rejectDuplicateFiles,
203
+ savedValidator
204
+ ]);
205
+ const useDropZoneStore = (selector) => {
206
+ return useStore(storeApi, selector);
207
+ };
208
+ const isDraggingOver = useDropZoneStore((store) => store.isDraggingOver);
209
+ const actions = useDropZoneStore((store) => store.actions);
210
+ const getContainerProps = useCallback((containerProps) => {
211
+ const mergedContainerProps = mergeTwoProps(extraProps?.container, containerProps);
212
+ return {
213
+ ...mergedContainerProps,
214
+ className: cnMerge("relative isolate flex flex-col", isDraggingOver && "opacity-60", classNames?.container, mergedContainerProps.className),
215
+ "data-drag-over": dataAttr(isDraggingOver),
216
+ "data-scope": "dropzone",
217
+ "data-part": "container",
218
+ "data-slot": "dropzone-container",
219
+ onDragEnter: composeTwoEventHandlers(actions.handleDragEnter, mergedContainerProps.onDragEnter),
220
+ onDragLeave: composeTwoEventHandlers(actions.handleDragLeave, mergedContainerProps.onDragLeave),
221
+ onDragOver: composeTwoEventHandlers(actions.handleDragOver, mergedContainerProps.onDragOver),
222
+ onDrop: composeTwoEventHandlers(actions.handleDrop, mergedContainerProps.onDrop)
223
+ };
224
+ }, [
225
+ actions.handleDragEnter,
226
+ actions.handleDragLeave,
227
+ actions.handleDragOver,
228
+ actions.handleDrop,
229
+ classNames?.container,
230
+ extraProps?.container,
231
+ isDraggingOver
232
+ ]);
233
+ const getInputProps = useCallback((inputProps) => {
234
+ const mergedInputProps = mergeTwoProps(extraProps?.input, inputProps);
235
+ return {
236
+ ...mergedInputProps,
237
+ accept: allowedFileTypes ? allowedFileTypes.join(", ") : mergedInputProps.accept,
238
+ className: cnMerge(shouldOpenFilePickerOnAreaClick ? "absolute inset-0 z-[100] cursor-pointer opacity-0" : "hidden", classNames?.input, mergedInputProps.className),
239
+ "data-drag-over": dataAttr(isDraggingOver),
240
+ "data-scope": "dropzone",
241
+ "data-part": "input",
242
+ "data-slot": "dropzone-input",
243
+ multiple: multiple ?? mergedInputProps.multiple,
244
+ onChange: composeTwoEventHandlers(actions.handleChange, mergedInputProps.onChange),
245
+ ref: composeRefs(inputRef, mergedInputProps.ref),
246
+ type: "file"
247
+ };
248
+ }, [
249
+ actions.handleChange,
250
+ allowedFileTypes,
251
+ classNames?.input,
252
+ extraProps?.input,
253
+ isDraggingOver,
254
+ multiple,
255
+ shouldOpenFilePickerOnAreaClick
256
+ ]);
257
+ const getTriggerProps = useCallback((triggerProps) => {
258
+ const mergedTriggerProps = mergeTwoProps(extraProps?.trigger, triggerProps);
259
+ return {
260
+ ...mergedTriggerProps,
261
+ className: cnMerge(classNames?.trigger, mergedTriggerProps.className),
262
+ "data-scope": "dropzone",
263
+ "data-part": "trigger",
264
+ "data-slot": "dropzone-trigger",
265
+ onClick: composeTwoEventHandlers(actions.openFilePicker, mergedTriggerProps.onClick)
266
+ };
267
+ }, [
268
+ actions.openFilePicker,
269
+ classNames?.trigger,
270
+ extraProps?.trigger
271
+ ]);
272
+ const propGetters = useMemo(() => ({
273
+ getContainerProps,
274
+ getInputProps,
275
+ getTriggerProps
276
+ }), [
277
+ getContainerProps,
278
+ getInputProps,
279
+ getTriggerProps
280
+ ]);
281
+ const savedUseDropZoneStore = useCallbackRef(useDropZoneStore);
282
+ const result = useMemo(() => ({
283
+ inputRef,
284
+ propGetters,
285
+ storeApi,
286
+ useDropZoneStore: savedUseDropZoneStore
287
+ }), [
288
+ propGetters,
289
+ storeApi,
290
+ savedUseDropZoneStore
291
+ ]);
292
+ return result;
293
+ };
294
+
295
+ //#endregion
296
+ //#region src/components/ui/drop-zone/drop-zone.tsx
297
+ function DropZoneRoot(props) {
298
+ const { children,...restOfProps } = props;
299
+ const dropZone = useDropZone(restOfProps);
300
+ return /* @__PURE__ */ jsx(DropZoneStoreContextProvider, {
301
+ store: dropZone.storeApi,
302
+ children: /* @__PURE__ */ jsx(DropZonePropGettersContextProvider, {
303
+ value: dropZone.propGetters,
304
+ children
305
+ })
306
+ });
307
+ }
308
+ function DropZoneContext(props) {
309
+ const { children, selector } = props;
310
+ const dropZoneCtx = useDropZoneStoreContext(selector);
311
+ const resolvedChildren = isFunction(children) ? children(dropZoneCtx) : children;
312
+ return resolvedChildren;
313
+ }
314
+ function DropZoneContainer(props) {
315
+ const { as: Element = "div", asChild,...restOfProps } = props;
316
+ const propGetters = usePropGettersContext();
317
+ const Component$1 = asChild ? SlotRoot : Element;
318
+ return /* @__PURE__ */ jsx(Component$1, { ...propGetters.getContainerProps(restOfProps) });
319
+ }
320
+ function DropZoneInput(props) {
321
+ const { asChild,...restOfProps } = props;
322
+ const propGetters = usePropGettersContext();
323
+ const Component$1 = asChild ? SlotRoot : "input";
324
+ return /* @__PURE__ */ jsx(Component$1, { ...propGetters.getInputProps(restOfProps) });
325
+ }
326
+ function DropZoneArea(props) {
327
+ const { children, extraProps, selector } = props;
328
+ return /* @__PURE__ */ jsxs(DropZoneContainer, {
329
+ ...extraProps?.container,
330
+ children: [/* @__PURE__ */ jsx(DropZoneInput, { ...extraProps?.input }), /* @__PURE__ */ jsx(DropZoneContext, {
331
+ selector,
332
+ children
333
+ })]
334
+ });
335
+ }
336
+ function DropZoneTrigger(props) {
337
+ const { asChild,...restOfProps } = props;
338
+ const propGetters = usePropGettersContext();
339
+ const Component$1 = asChild ? SlotRoot : "button";
340
+ return /* @__PURE__ */ jsx(Component$1, { ...propGetters.getTriggerProps(restOfProps) });
341
+ }
342
+ function DropZoneFilePreview(props) {
343
+ const { children } = props;
344
+ const fileStateArray = useDropZoneStoreContext((store) => store.fileStateArray);
345
+ const actions = useDropZoneStoreContext((store) => store.actions);
346
+ if (fileStateArray.length === 0) return;
347
+ const resolvedChildren = isFunction(children) ? children({
348
+ actions,
349
+ fileStateArray
350
+ }) : children;
351
+ return resolvedChildren;
352
+ }
353
+ function DropZoneErrorPreview(props) {
354
+ const { children } = props;
355
+ const errors = useDropZoneStoreContext((store) => store.errors);
356
+ const actions = useDropZoneStoreContext((store) => store.actions);
357
+ if (errors.length === 0) return;
358
+ const resolvedChildren = isFunction(children) ? children({
359
+ actions,
360
+ errors
361
+ }) : children;
362
+ return resolvedChildren;
363
+ }
364
+
365
+ //#endregion
366
+ //#region src/components/ui/drop-zone/drop-zone-parts.ts
367
+ var drop_zone_parts_exports = {};
368
+ __export(drop_zone_parts_exports, {
369
+ Area: () => DropZoneArea,
370
+ Container: () => DropZoneContainer,
371
+ Context: () => DropZoneContext,
372
+ ErrorPreview: () => DropZoneErrorPreview,
373
+ FilePreview: () => DropZoneFilePreview,
374
+ Input: () => DropZoneInput,
375
+ Root: () => DropZoneRoot,
376
+ Trigger: () => DropZoneTrigger
377
+ });
378
+
379
+ //#endregion
380
+ export { DropZoneArea, DropZoneContainer, DropZoneContext, DropZoneErrorPreview, DropZoneFilePreview, DropZoneInput, DropZoneRoot, DropZoneTrigger, drop_zone_parts_exports, useDropZone, useDropZoneStoreContext };
381
+ //# sourceMappingURL=drop-zone-BPfSu99L.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"drop-zone-BPfSu99L.js","names":["useDropZoneStore: UseDropZoneResult[\"useDropZoneStore\"]","getContainerProps: UseDropZoneResult[\"propGetters\"][\"getContainerProps\"]","getInputProps: UseDropZoneResult[\"propGetters\"][\"getInputProps\"]","getTriggerProps: UseDropZoneResult[\"propGetters\"][\"getTriggerProps\"]","Component"],"sources":["../../src/components/ui/drop-zone/drop-zone-context.ts","../../src/components/ui/drop-zone/utils.ts","../../src/components/ui/drop-zone/drop-zone-store.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"],"sourcesContent":["import { createCustomContext } from \"@zayne-labs/toolkit-react\";\nimport { createZustandContext } from \"@zayne-labs/toolkit-react/zustand\";\nimport type { DropZoneStore } from \"./drop-zone-store\";\nimport type { DropZonePropGetters } from \"./types\";\n\nconst [DropZoneStoreContextProvider, useDropZoneStoreContext] = createZustandContext<DropZoneStore>({\n\thookName: \"useDropZoneStoreContext\",\n\tname: \"DropZoneStoreContext\",\n\tproviderName: \"DropZoneRoot\",\n});\n\nconst [DropZonePropGettersContextProvider, usePropGettersContext] =\n\tcreateCustomContext<DropZonePropGetters>({\n\t\thookName: \"usePropGettersContext\",\n\t\tname: \"PropGettersContext\",\n\t\tproviderName: \"DropZoneRoot\",\n\t});\n\nexport {\n\tDropZoneStoreContextProvider,\n\tuseDropZoneStoreContext,\n\tDropZonePropGettersContextProvider,\n\tusePropGettersContext,\n};\n","import { createImagePreview, type FileMeta } from \"@zayne-labs/toolkit-core\";\nimport { isFile } from \"@zayne-labs/toolkit-type-helpers\";\nimport type { FileState } from \"./types\";\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 | undefined) => {\n\tif (disallowPreviewForNonImageFiles && !file.type.startsWith(\"image/\")) return;\n\n\treturn createImagePreview(file);\n};\n\nexport const clearObjectURL = (\n\tfileState: FileState | undefined,\n\tdisallowPreviewForNonImageFiles: boolean | undefined\n) => {\n\tif (!isFile(fileState?.file)) return;\n\n\tif (disallowPreviewForNonImageFiles && !fileState.file.type.startsWith(\"image/\")) return;\n\n\tif (!fileState.preview) return;\n\n\tURL.revokeObjectURL(fileState.preview);\n};\n","import { createStore, handleFileValidationAsync, toArray } from \"@zayne-labs/toolkit-core\";\nimport { isString } from \"@zayne-labs/toolkit-type-helpers\";\nimport type { DropZoneActions, DropZoneState } from \"./types\";\nimport type { UseDropZoneProps } from \"./use-drop-zone\";\nimport { clearObjectURL, createObjectURL, generateUniqueId } from \"./utils\";\n\nexport type DropZoneStore = DropZoneState & { actions: DropZoneActions };\n\nexport const createDropZoneStore = (\n\tinitStoreValues: Pick<\n\t\tUseDropZoneProps,\n\t\t| \"allowedFileTypes\"\n\t\t| \"disablePreviewForNonImageFiles\"\n\t\t| \"initialFiles\"\n\t\t| \"maxFileCount\"\n\t\t| \"maxFileSize\"\n\t\t| \"multiple\"\n\t\t| \"onFilesChange\"\n\t\t| \"onUpload\"\n\t\t| \"onUploadError\"\n\t\t| \"onUploadErrorCollection\"\n\t\t| \"onUploadSuccess\"\n\t\t| \"rejectDuplicateFiles\"\n\t\t| \"validator\"\n\t> & {\n\t\tinputRef: React.RefObject<HTMLInputElement | null>;\n\t}\n) => {\n\tconst {\n\t\tallowedFileTypes,\n\t\tdisablePreviewForNonImageFiles,\n\t\tinitialFiles,\n\t\tinputRef,\n\t\tmaxFileCount,\n\t\tmaxFileSize,\n\t\tmultiple,\n\t\tonFilesChange,\n\t\tonUpload,\n\t\tonUploadError,\n\t\tonUploadErrorCollection,\n\t\tonUploadSuccess,\n\t\trejectDuplicateFiles,\n\t\tvalidator,\n\t} = initStoreValues;\n\n\tconst initialFileArray = toArray(initialFiles).filter(Boolean);\n\n\tconst clearInputValue = () => {\n\t\tif (!inputRef.current) return;\n\n\t\tinputRef.current.value = \"\";\n\t};\n\n\tconst store = createStore<DropZoneStore>((set, get) => ({\n\t\terrors: [],\n\t\tfileStateArray: 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\tisDraggingOver: false,\n\n\t\t// eslint-disable-next-line perfectionist/sort-objects -- Ignore\n\t\tactions: {\n\t\t\t// registerEventListeners: () => {\n\t\t\t// \tconst containerElement = {}\n\t\t\t// \tconst inputElement = {}\n\n\t\t\t// \tinputRef.current.addEventListener(\"change\", get().actions.handleChange);\n\t\t\t// \tinputRef.current.addEventListener(\"dragenter\", get().actions.handleDragEnter);\n\t\t\t// \tinputRef.current.addEventListener(\"dragleave\", get().actions.handleDragLeave);\n\t\t\t// \tinputRef.current.addEventListener(\"dragover\", get().actions.handleDragOver);\n\t\t\t// \tinputRef.current.addEventListener(\"drop\", get().actions.handleDrop);\n\t\t\t// },\n\t\t\taddFiles: async (files) => {\n\t\t\t\tif (!files || files.length === 0) {\n\t\t\t\t\tconsole.warn(\"No file selected!\");\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst { fileStateArray } = get();\n\n\t\t\t\t// == In single file mode, only use the first file\n\t\t\t\tconst newFiles = !multiple ? [files[0]] : files;\n\n\t\t\t\tconst { errors, validFiles } = await handleFileValidationAsync({\n\t\t\t\t\texistingFiles: fileStateArray.map((fileWithPreview) => fileWithPreview.file),\n\t\t\t\t\thooks: {\n\t\t\t\t\t\tonError: onUploadError,\n\t\t\t\t\t\tonErrorCollection: onUploadErrorCollection,\n\t\t\t\t\t\tonSuccess: onUploadSuccess,\n\t\t\t\t\t},\n\t\t\t\t\tnewFiles,\n\t\t\t\t\tsettings: {\n\t\t\t\t\t\tallowedFileTypes,\n\t\t\t\t\t\tmaxFileCount,\n\t\t\t\t\t\tmaxFileSize,\n\t\t\t\t\t\trejectDuplicateFiles,\n\t\t\t\t\t\tvalidator,\n\t\t\t\t\t},\n\t\t\t\t});\n\n\t\t\t\tif (validFiles.length === 0) {\n\t\t\t\t\tset({ errors, isDraggingOver: false });\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst newFileStateArray = validFiles.map((file) => ({\n\t\t\t\t\tfile,\n\t\t\t\t\tid: generateUniqueId(file),\n\t\t\t\t\tpreview: createObjectURL(file, disablePreviewForNonImageFiles),\n\t\t\t\t}));\n\n\t\t\t\tset({\n\t\t\t\t\terrors,\n\t\t\t\t\tfileStateArray: multiple ? [...fileStateArray, ...newFileStateArray] : newFileStateArray,\n\t\t\t\t\tisDraggingOver: false,\n\t\t\t\t});\n\n\t\t\t\tawait onUpload?.({ fileStateArray: newFileStateArray });\n\t\t\t},\n\t\t\tclearErrors: () => {\n\t\t\t\tset({ errors: [] });\n\t\t\t},\n\t\t\tclearFiles: () => {\n\t\t\t\tconst { fileStateArray } = get();\n\n\t\t\t\tfor (const fileState of fileStateArray) {\n\t\t\t\t\tclearObjectURL(fileState, disablePreviewForNonImageFiles);\n\t\t\t\t}\n\n\t\t\t\tset({ fileStateArray: [] });\n\t\t\t},\n\t\t\thandleChange: async (event) => {\n\t\t\t\tconst fileList = event.target.files;\n\n\t\t\t\tconst { actions } = get();\n\n\t\t\t\tawait actions.addFiles(fileList);\n\n\t\t\t\tclearInputValue();\n\t\t\t},\n\t\t\thandleDragEnter: (event) => {\n\t\t\t\tevent.preventDefault();\n\t\t\t\tevent.stopPropagation();\n\n\t\t\t\tset({ isDraggingOver: true });\n\t\t\t},\n\t\t\thandleDragLeave: (event) => {\n\t\t\t\tevent.preventDefault();\n\t\t\t\tevent.stopPropagation();\n\n\t\t\t\tset({ isDraggingOver: false });\n\t\t\t},\n\t\t\thandleDragOver: (event) => {\n\t\t\t\tevent.preventDefault();\n\t\t\t\tevent.stopPropagation();\n\t\t\t},\n\t\t\thandleDrop: async (event) => {\n\t\t\t\tevent.preventDefault();\n\t\t\t\tevent.stopPropagation();\n\n\t\t\t\tif (inputRef.current?.disabled) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst fileList = event.dataTransfer.files;\n\n\t\t\t\tconst { actions } = get();\n\n\t\t\t\tawait actions.addFiles(fileList);\n\t\t\t},\n\t\t\topenFilePicker: () => {\n\t\t\t\tinputRef.current?.click();\n\t\t\t},\n\t\t\tremoveFile: (fileToRemoveOrFileId) => {\n\t\t\t\tconst { fileStateArray } = get();\n\n\t\t\t\tconst actualFileToRemove =\n\t\t\t\t\tisString(fileToRemoveOrFileId) ?\n\t\t\t\t\t\tfileStateArray.find((file) => file.id === fileToRemoveOrFileId)\n\t\t\t\t\t:\tfileToRemoveOrFileId;\n\n\t\t\t\tif (!actualFileToRemove) return;\n\n\t\t\t\tclearObjectURL(actualFileToRemove, disablePreviewForNonImageFiles);\n\n\t\t\t\tconst updatedFileStateArray = fileStateArray.filter(\n\t\t\t\t\t(file) => file.id !== actualFileToRemove.id\n\t\t\t\t);\n\n\t\t\t\tset({ errors: [], fileStateArray: updatedFileStateArray });\n\t\t\t},\n\t\t},\n\t}));\n\n\tstore.subscribe.withSelector(\n\t\t(state) => state.fileStateArray,\n\t\t(fileStateArray) => {\n\t\t\tonFilesChange?.({ fileStateArray });\n\t\t}\n\t);\n\n\treturn store;\n};\n","import {\n\tdataAttr,\n\ttype FileMeta,\n\ttype FileValidationHooksAsync,\n\ttype FileValidationSettingsAsync,\n} from \"@zayne-labs/toolkit-core\";\nimport { useCallbackRef, useConstant, useShallowComparedValue, useStore } from \"@zayne-labs/toolkit-react\";\nimport type { InferProps } from \"@zayne-labs/toolkit-react/utils\";\nimport { composeRefs, composeTwoEventHandlers, mergeTwoProps } from \"@zayne-labs/toolkit-react/utils\";\nimport type { Awaitable } from \"@zayne-labs/toolkit-type-helpers\";\nimport { useCallback, useMemo, useRef } from \"react\";\nimport { cnMerge } from \"@/lib/utils/cn\";\nimport type { useDropZoneStoreContext } from \"./drop-zone-context\";\nimport { createDropZoneStore } from \"./drop-zone-store\";\nimport type { DropZonePropGetters, DropZoneState } from \"./types\";\n\nexport type ExtraProps = {\n\tcontainer?: InferProps<HTMLElement>;\n\tinput?: InferProps<\"input\">;\n\ttrigger?: InferProps<\"button\">;\n};\n\nexport type ClassNames = {\n\t[key in keyof ExtraProps]: string;\n};\n\nexport type UseDropZoneResult = {\n\tinputRef: React.RefObject<HTMLInputElement | null>;\n\tpropGetters: DropZonePropGetters;\n\tstoreApi: ReturnType<typeof createDropZoneStore>;\n\tuseDropZoneStore: typeof useDropZoneStoreContext;\n};\n\nexport type UseDropZoneProps = FileValidationSettingsAsync & {\n\t/**\n\t * CSS classes to apply to the various parts of the drop zone\n\t */\n\tclassNames?: ClassNames;\n\n\t/**\n\t * Whether to disallow preview for non-image files\n\t * @default true\n\t */\n\tdisablePreviewForNonImageFiles?: boolean;\n\n\t/**\n\t * Extra props to pass to various parts of the dropzone\n\t */\n\textraProps?: ExtraProps;\n\n\t/**\n\t * Initial files to populate the drop zone\n\t */\n\tinitialFiles?: FileMeta | FileMeta[] | null;\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: Pick<DropZoneState, \"fileStateArray\">) => void;\n\n\t/**\n\t * Callback function to be called when new files are uploaded\n\t */\n\tonUpload?: (context: Pick<DropZoneState, \"fileStateArray\">) => Awaitable<void>;\n\n\t/**\n\t * Callback function to be called on each file upload as they occur\n\t */\n\tonUploadError?: FileValidationHooksAsync[\"onError\"];\n\n\t/**\n\t * Callback function to be called once after all file upload errors have occurred\n\t */\n\tonUploadErrorCollection?: FileValidationHooksAsync[\"onErrorCollection\"];\n\n\t/**\n\t * Callback function to be called on file upload success\n\t */\n\tonUploadSuccess?: FileValidationHooksAsync[\"onSuccess\"];\n\n\t/**\n\t * Whether clicking the drop zone area will open the default file picker or not\n\t *\n\t * @default true\n\t */\n\tshouldOpenFilePickerOnAreaClick?: boolean;\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\t */\n\tvalidator?: FileValidationSettingsAsync[\"validator\"];\n};\n\nexport const useDropZone = (props?: UseDropZoneProps): UseDropZoneResult => {\n\tconst {\n\t\tallowedFileTypes,\n\t\tclassNames,\n\t\tdisablePreviewForNonImageFiles = true,\n\t\textraProps,\n\t\tinitialFiles,\n\t\tmaxFileCount,\n\t\tmaxFileSize,\n\t\tmultiple,\n\t\tonFilesChange,\n\t\tonUpload,\n\t\tonUploadError,\n\t\tonUploadErrorCollection,\n\t\tonUploadSuccess,\n\t\trejectDuplicateFiles = true,\n\t\tshouldOpenFilePickerOnAreaClick = true,\n\t\tvalidator,\n\t} = props ?? {};\n\n\tconst inputRef = useRef<HTMLInputElement>(null);\n\n\tconst savedOnFilesChange = useCallbackRef(onFilesChange);\n\tconst savedOnUpload = useCallbackRef(onUpload);\n\tconst savedOnUploadError = useCallbackRef(onUploadError);\n\tconst savedOnUploadErrorCollection = useCallbackRef(onUploadErrorCollection);\n\tconst savedOnUploadSuccess = useCallbackRef(onUploadSuccess);\n\tconst savedValidator = useCallbackRef(validator);\n\n\tconst constantInitialFiles = useConstant(() => initialFiles);\n\tconst shallowComparedMaxFileSize = useShallowComparedValue(maxFileSize);\n\tconst shallowComparedAllowedFileTypes = useShallowComparedValue(allowedFileTypes);\n\n\tconst storeApi = useMemo(() => {\n\t\treturn createDropZoneStore({\n\t\t\tallowedFileTypes: shallowComparedAllowedFileTypes,\n\t\t\tdisablePreviewForNonImageFiles,\n\t\t\tinitialFiles: constantInitialFiles,\n\t\t\tinputRef,\n\t\t\tmaxFileCount,\n\t\t\tmaxFileSize: shallowComparedMaxFileSize,\n\t\t\tmultiple,\n\t\t\tonFilesChange: savedOnFilesChange,\n\t\t\tonUpload: savedOnUpload,\n\t\t\tonUploadError: savedOnUploadError,\n\t\t\tonUploadErrorCollection: savedOnUploadErrorCollection,\n\t\t\tonUploadSuccess: savedOnUploadSuccess,\n\t\t\trejectDuplicateFiles,\n\t\t\tvalidator: savedValidator,\n\t\t});\n\t}, [\n\t\tshallowComparedAllowedFileTypes,\n\t\tdisablePreviewForNonImageFiles,\n\t\tconstantInitialFiles,\n\t\tmaxFileCount,\n\t\tshallowComparedMaxFileSize,\n\t\tmultiple,\n\t\tsavedOnFilesChange,\n\t\tsavedOnUpload,\n\t\tsavedOnUploadError,\n\t\tsavedOnUploadErrorCollection,\n\t\tsavedOnUploadSuccess,\n\t\trejectDuplicateFiles,\n\t\tsavedValidator,\n\t]);\n\n\tconst useDropZoneStore: UseDropZoneResult[\"useDropZoneStore\"] = (selector) => {\n\t\treturn useStore(storeApi, selector);\n\t};\n\n\tconst isDraggingOver = useDropZoneStore((store) => store.isDraggingOver);\n\tconst actions = useDropZoneStore((store) => store.actions);\n\n\tconst getContainerProps: UseDropZoneResult[\"propGetters\"][\"getContainerProps\"] = useCallback(\n\t\t(containerProps) => {\n\t\t\tconst mergedContainerProps = mergeTwoProps(extraProps?.container, 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\tisDraggingOver && \"opacity-60\",\n\t\t\t\t\tclassNames?.container,\n\t\t\t\t\tmergedContainerProps.className\n\t\t\t\t),\n\t\t\t\t\"data-drag-over\": dataAttr(isDraggingOver),\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(\n\t\t\t\t\tactions.handleDragEnter,\n\t\t\t\t\tmergedContainerProps.onDragEnter\n\t\t\t\t),\n\t\t\t\tonDragLeave: composeTwoEventHandlers(\n\t\t\t\t\tactions.handleDragLeave,\n\t\t\t\t\tmergedContainerProps.onDragLeave\n\t\t\t\t),\n\t\t\t\tonDragOver: composeTwoEventHandlers(actions.handleDragOver, mergedContainerProps.onDragOver),\n\t\t\t\tonDrop: composeTwoEventHandlers(actions.handleDrop, mergedContainerProps.onDrop),\n\t\t\t};\n\t\t},\n\t\t[\n\t\t\tactions.handleDragEnter,\n\t\t\tactions.handleDragLeave,\n\t\t\tactions.handleDragOver,\n\t\t\tactions.handleDrop,\n\t\t\tclassNames?.container,\n\t\t\textraProps?.container,\n\t\t\tisDraggingOver,\n\t\t]\n\t);\n\n\tconst getInputProps: UseDropZoneResult[\"propGetters\"][\"getInputProps\"] = useCallback(\n\t\t(inputProps) => {\n\t\t\tconst mergedInputProps = mergeTwoProps(extraProps?.input, 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\tshouldOpenFilePickerOnAreaClick ?\n\t\t\t\t\t\t\"absolute inset-0 z-[100] cursor-pointer opacity-0\"\n\t\t\t\t\t:\t\"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-drag-over\": dataAttr(isDraggingOver),\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(actions.handleChange, 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\tactions.handleChange,\n\t\t\tallowedFileTypes,\n\t\t\tclassNames?.input,\n\t\t\textraProps?.input,\n\t\t\tisDraggingOver,\n\t\t\tmultiple,\n\t\t\tshouldOpenFilePickerOnAreaClick,\n\t\t]\n\t);\n\n\tconst getTriggerProps: UseDropZoneResult[\"propGetters\"][\"getTriggerProps\"] = useCallback(\n\t\t(triggerProps) => {\n\t\t\tconst mergedTriggerProps = mergeTwoProps(extraProps?.trigger, triggerProps);\n\n\t\t\treturn {\n\t\t\t\t...mergedTriggerProps,\n\t\t\t\tclassName: cnMerge(classNames?.trigger, mergedTriggerProps.className),\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\": \"trigger\",\n\t\t\t\t\"data-slot\": \"dropzone-trigger\",\n\t\t\t\tonClick: composeTwoEventHandlers(actions.openFilePicker, mergedTriggerProps.onClick),\n\t\t\t};\n\t\t},\n\t\t[actions.openFilePicker, classNames?.trigger, extraProps?.trigger]\n\t);\n\n\t// const getDeleteProps: UseDropZoneResult[\"propGetters\"][\"getTriggerProps\"] = useCallback(\n\t// \t(triggerProps) => {\n\t// \t\tconst mergedTriggerProps = mergeTwoProps(extraProps?.trigger, triggerProps);\n\n\t// \t\treturn {\n\t// \t\t\t...mergedTriggerProps,\n\t// \t\t\tclassName: cnMerge(classNames?.trigger, mergedTriggerProps.className),\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\": \"trigger\",\n\t// \t\t\t\"data-slot\": \"dropzone-trigger\",\n\t// \t\t\tonClick: composeTwoEventHandlers(actions.openFilePicker, mergedTriggerProps.onClick),\n\t// \t\t};\n\t// \t},\n\t// \t[actions.openFilePicker, classNames?.trigger, extraProps?.trigger]\n\t// );\n\n\tconst propGetters = useMemo(\n\t\t() => ({ getContainerProps, getInputProps, getTriggerProps }),\n\t\t[getContainerProps, getInputProps, getTriggerProps]\n\t);\n\n\tconst savedUseDropZoneStore = useCallbackRef(useDropZoneStore);\n\n\tconst result = useMemo<UseDropZoneResult>(\n\t\t() =>\n\t\t\t({\n\t\t\t\tinputRef,\n\t\t\t\tpropGetters,\n\t\t\t\tstoreApi,\n\t\t\t\tuseDropZoneStore: savedUseDropZoneStore,\n\t\t\t}) satisfies UseDropZoneResult,\n\t\t[propGetters, storeApi, savedUseDropZoneStore]\n\t);\n\n\treturn result;\n};\n","\"use client\";\n\nimport type { PolymorphicProps } from \"@zayne-labs/toolkit-react/utils\";\nimport { isFunction, type SelectorFn } from \"@zayne-labs/toolkit-type-helpers\";\nimport * as React from \"react\";\nimport { Slot } from \"@/components/common\";\nimport {\n\tDropZonePropGettersContextProvider,\n\tDropZoneStoreContextProvider,\n\tuseDropZoneStoreContext,\n\tusePropGettersContext,\n} from \"./drop-zone-context\";\nimport type { DropZoneStore } from \"./drop-zone-store\";\nimport { type ExtraProps, type UseDropZoneProps, useDropZone } from \"./use-drop-zone\";\n\nexport type DropZoneRootProps = UseDropZoneProps & { children: React.ReactNode };\n\nexport function DropZoneRoot(props: DropZoneRootProps) {\n\tconst { children, ...restOfProps } = props;\n\n\tconst dropZone = useDropZone(restOfProps);\n\n\treturn (\n\t\t<DropZoneStoreContextProvider store={dropZone.storeApi}>\n\t\t\t<DropZonePropGettersContextProvider value={dropZone.propGetters}>\n\t\t\t\t{children}\n\t\t\t</DropZonePropGettersContextProvider>\n\t\t</DropZoneStoreContextProvider>\n\t);\n}\n\nexport type DropZoneContextProps<TSlice> = {\n\tchildren: React.ReactNode | ((props: TSlice) => React.ReactNode);\n\tselector?: SelectorFn<DropZoneStore, TSlice>;\n};\n\nexport function DropZoneContext<TSlice = DropZoneStore>(props: DropZoneContextProps<TSlice>) {\n\tconst { children, selector } = props;\n\n\tconst dropZoneCtx = useDropZoneStoreContext(selector);\n\n\tconst resolvedChildren = isFunction(children) ? children(dropZoneCtx) : children;\n\n\treturn resolvedChildren;\n}\n\ntype DropZoneContainerProps = ExtraProps[\"container\"] & { 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 propGetters = usePropGettersContext();\n\n\tconst Component = asChild ? Slot.Root : Element;\n\n\treturn <Component {...propGetters.getContainerProps(restOfProps)} />;\n}\n\ntype DropZoneInputProps = ExtraProps[\"input\"] & { asChild?: boolean };\n\nexport function DropZoneInput(props: DropZoneInputProps) {\n\tconst { asChild, ...restOfProps } = props;\n\n\tconst propGetters = usePropGettersContext();\n\n\tconst Component = asChild ? Slot.Root : \"input\";\n\n\treturn <Component {...propGetters.getInputProps(restOfProps)} />;\n}\n\ntype DropZoneAreaProps<TSlice> = {\n\tchildren: React.ReactNode | ((props: TSlice) => React.ReactNode);\n\textraProps?: Pick<ExtraProps, \"container\" | \"input\">;\n\tselector?: SelectorFn<DropZoneStore, TSlice>;\n};\n\nexport function DropZoneArea<TSlice = DropZoneStore>(props: DropZoneAreaProps<TSlice>) {\n\tconst { children, extraProps, selector } = props;\n\n\treturn (\n\t\t<DropZoneContainer {...extraProps?.container}>\n\t\t\t<DropZoneInput {...extraProps?.input} />\n\n\t\t\t<DropZoneContext selector={selector}>{children}</DropZoneContext>\n\t\t</DropZoneContainer>\n\t);\n}\n\ntype DropZoneTriggerProps = ExtraProps[\"trigger\"] & { asChild?: boolean };\n\nexport function DropZoneTrigger(props: DropZoneTriggerProps) {\n\tconst { asChild, ...restOfProps } = props;\n\n\tconst propGetters = usePropGettersContext();\n\n\tconst Component = asChild ? Slot.Root : \"button\";\n\n\treturn <Component {...propGetters.getTriggerProps(restOfProps)} />;\n}\n\ntype DropZoneFilePreviewProps = {\n\tchildren:\n\t\t| React.ReactNode\n\t\t| ((props: Pick<DropZoneStore, \"actions\" | \"fileStateArray\">) => React.ReactNode);\n};\n\nexport function DropZoneFilePreview(props: DropZoneFilePreviewProps) {\n\tconst { children } = props;\n\n\tconst fileStateArray = useDropZoneStoreContext((store) => store.fileStateArray);\n\tconst actions = useDropZoneStoreContext((store) => store.actions);\n\n\tif (fileStateArray.length === 0) return;\n\n\tconst resolvedChildren = isFunction(children) ? children({ actions, fileStateArray }) : children;\n\n\treturn resolvedChildren;\n}\n\ntype DropZoneErrorPreviewProps = {\n\tchildren: React.ReactNode | ((props: Pick<DropZoneStore, \"actions\" | \"errors\">) => React.ReactNode);\n};\n\nexport function DropZoneErrorPreview(props: DropZoneErrorPreviewProps) {\n\tconst { children } = props;\n\n\tconst errors = useDropZoneStoreContext((store) => store.errors);\n\tconst actions = useDropZoneStoreContext((store) => store.actions);\n\n\tif (errors.length === 0) return;\n\n\tconst resolvedChildren = isFunction(children) ? children({ actions, errors }) : children;\n\n\treturn resolvedChildren;\n}\n","export {\n\tDropZoneArea as Area,\n\tDropZoneContainer as Container,\n\tDropZoneContext as Context,\n\tDropZoneErrorPreview as ErrorPreview,\n\tDropZoneFilePreview as FilePreview,\n\tDropZoneInput as Input,\n\tDropZoneRoot as Root,\n\tDropZoneTrigger as Trigger,\n} from \"./drop-zone\";\n"],"mappings":";;;;;;;;;;;;AAKA,MAAM,CAAC,8BAA8B,wBAAwB,GAAG,qBAAoC;CACnG,UAAU;CACV,MAAM;CACN,cAAc;CACd;AAED,MAAM,CAAC,oCAAoC,sBAAsB,GAChE,oBAAyC;CACxC,UAAU;CACV,MAAM;CACN,cAAc;CACd;;;;ACZF,MAAa,oBAAoB,SAAkC;AAClE,KAAI,CAAC,OAAO,MACX,QAAO,KAAK;AAGb,QAAO,GAAG,KAAK,KAAK,IAAI,KAAK,MAAM,YAAY,OAAO,IAAI,OAAO,aAAa,MAAM,GAAG;AACvF;AAED,MAAa,mBAAmB,MAAY,oCAAyD;AACpG,KAAI,mCAAmC,CAAC,KAAK,KAAK,WAAW,UAAW;AAExE,QAAO,mBAAmB;AAC1B;AAED,MAAa,kBACZ,WACA,oCACI;AACJ,KAAI,CAAC,OAAO,WAAW,MAAO;AAE9B,KAAI,mCAAmC,CAAC,UAAU,KAAK,KAAK,WAAW,UAAW;AAElF,KAAI,CAAC,UAAU,QAAS;AAExB,KAAI,gBAAgB,UAAU;AAC9B;;;;ACrBD,MAAa,uBACZ,oBAkBI;CACJ,MAAM,EACL,kBACA,gCACA,cACA,UACA,cACA,aACA,UACA,eACA,UACA,eACA,yBACA,iBACA,sBACA,WACA,GAAG;CAEJ,MA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B;AACpD;AAID,SAAgB,cAAc,OAA2B;CACxD,MAAM,EAAE,QAAS,GAAG,aAAa,GAAG;CAEpC,MAAM,cAAc;CAEpB,MAAMA,cAAY,qBAAsB;AAExC,QAAO,oBAACA,eAAU,GAAI,YAAY,cAAc;AAChD;AAQD,SAAgB,aAAqC,OAAkC;CACtF,MAAM,EAAE,UAAU,YAAY,UAAU,GAAG;AAE3C,QACC,qBAAC;EAAkB,GAAI,YAAY;aAClC,oBAAC,iBAAc,GAAI,YAAY,UAE/B,oBAAC;GAA0B;GAAW;;;AAGxC;AAID,SAAgB,gBAAgB,OAA6B;CAC5D,MAAM,EAAE,QAAS,GAAG,aAAa,GAAG;CAEpC,MAAM,cAAc;CAEpB,MAAMA,cAAY,qBAAsB;AAExC,QAAO,oBAACA,eAAU,GAAI,YAAY,gBAAgB;AAClD;AAQD,SAAgB,oBAAoB,OAAiC;CACpE,MAAM,EAAE,UAAU,GAAG;CAErB,MAAM,iBAAiB,yBAAyB,UAAU,MAAM;CAChE,MAAM,UAAU,yBAAyB,UAAU,MAAM;AAEzD,KAAI,eAAe,WAAW,EAAG;CAEjC,MAAM,mBAAmB,WAAW,YAAY,SAAS;EAAE;EAAS;EAAgB,IAAI;AAExF,QAAO;AACP;AAMD,SAAgB,qBAAqB,OAAkC;CACtE,MAAM,EAAE,UAAU,GAAG;CAErB,MAAM,SAAS,yBAAyB,UAAU,MAAM;CACxD,MAAM,UAAU,yBAAyB,UAAU,MAAM;AAEzD,KAAI,OAAO,WAAW,EAAG;CAEzB,MAAM,mBAAmB,WAAW,YAAY,SAAS;EAAE;EAAS;EAAQ,IAAI;AAEhF,QAAO;AACP"}
@@ -1,5 +1,5 @@
1
- import { Component, useState } from "react";
2
1
  import { isFunction } from "@zayne-labs/toolkit-type-helpers";
2
+ import { Component, useState } from "react";
3
3
  import { createCustomContext, useCallbackRef } from "@zayne-labs/toolkit-react";
4
4
  import { jsx } from "react/jsx-runtime";
5
5
 
@@ -65,10 +65,9 @@ var ErrorBoundary = class extends Component {
65
65
  childToRender = fallback(fallbackRenderProps);
66
66
  break;
67
67
  }
68
- case Boolean(fallback): {
68
+ case Boolean(fallback):
69
69
  childToRender = fallback;
70
70
  break;
71
- }
72
71
  default: console.warn("No fallback provided to error boundary");
73
72
  }
74
73
  const contextValue = {
@@ -123,4 +122,4 @@ const useErrorBoundary = () => {
123
122
 
124
123
  //#endregion
125
124
  export { ErrorBoundary, useErrorBoundary, useErrorBoundaryContext };
126
- //# sourceMappingURL=error-boundary-B3ycUZ1t.js.map
125
+ //# sourceMappingURL=error-boundary-xM9An3gz.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error-boundary-xM9An3gz.js","names":["initialState: ErrorBoundaryState","#resetErrorBoundary"],"sources":["../../src/components/common/error-boundary/error-boundary-context.ts","../../src/components/common/error-boundary/error-boundary.tsx","../../src/components/common/error-boundary/useErrorBoundary.ts"],"sourcesContent":["import { createCustomContext } from \"@zayne-labs/toolkit-react\";\n\nexport type ErrorBoundaryContextType = {\n\terror: unknown;\n\thasError: boolean;\n\tresetErrorBoundary: (...args: unknown[]) => void;\n};\n\nexport const [ErrorBoundaryContext, useErrorBoundaryContext] =\n\tcreateCustomContext<ErrorBoundaryContextType>({\n\t\thookName: \"useErrorBoundaryContext\",\n\t\tname: \"ErrorBoundaryContext\",\n\t\tproviderName: \"ErrorBoundaryContextProvider\",\n\t});\n","import * as React from \"react\";\n\nimport { isFunction } from \"@zayne-labs/toolkit-type-helpers\";\nimport { Component } from \"react\";\nimport { ErrorBoundaryContext, type ErrorBoundaryContextType } from \"./error-boundary-context\";\nimport type { ErrorBoundaryProps, FallbackProps } from \"./types\";\n\ntype ErrorBoundaryState =\n\t| {\n\t\t\terror: Error;\n\t\t\thasError: true;\n\t }\n\t| {\n\t\t\terror: null;\n\t\t\thasError: false;\n\t };\n\nconst initialState: ErrorBoundaryState = {\n\terror: null,\n\thasError: false,\n};\n\nconst hasArrayChanged = (arrayOne: unknown[] = [], arrayTwo: unknown[] = []) => {\n\treturn (\n\t\tarrayOne.length !== arrayTwo.length\n\t\t|| arrayOne.some((item, index) => !Object.is(item, arrayTwo[index]))\n\t);\n};\n\n/**\n * Copied from react-error-boundary package\n * @see https://github.com/bvaughn/react-error-boundary\n */\n\nexport class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> {\n\tconstructor(props: ErrorBoundaryProps) {\n\t\tsuper(props);\n\n\t\tthis.state = initialState;\n\t}\n\n\tstatic getDerivedStateFromError(error: Error) {\n\t\treturn { error, hasError: true };\n\t}\n\n\toverride componentDidCatch(error: Error, info: React.ErrorInfo) {\n\t\tthis.props.onError?.({\n\t\t\terror,\n\t\t\tinfo,\n\t\t});\n\t}\n\n\toverride componentDidUpdate(prevProps: ErrorBoundaryProps, prevState: ErrorBoundaryState) {\n\t\tconst { hasError } = this.state;\n\t\tconst { resetKeys } = this.props;\n\n\t\t// == There's an edge case where if the thing that triggered the error happens to *also* be in the resetKeys array, we'd end up resetting the error boundary immediately.\n\t\t// == This would likely trigger a second error to be thrown.\n\t\t// == So we make sure that we don't check the resetKeys on the first call of cDU after the error is set.\n\n\t\tif (hasError && prevState.error !== null && hasArrayChanged(prevProps.resetKeys, resetKeys)) {\n\t\t\tthis.props.onReset?.({\n\t\t\t\tnext: resetKeys,\n\t\t\t\tprev: prevProps.resetKeys,\n\t\t\t\treason: \"keys\",\n\t\t\t});\n\n\t\t\tthis.setState(initialState);\n\t\t}\n\t}\n\n\toverride render() {\n\t\tconst { children, fallback } = this.props;\n\t\tconst { error, hasError } = this.state;\n\n\t\tlet childToRender = children;\n\n\t\tif (hasError) {\n\t\t\tswitch (true) {\n\t\t\t\tcase isFunction(fallback): {\n\t\t\t\t\tconst fallbackRenderProps = {\n\t\t\t\t\t\terror,\n\t\t\t\t\t\tresetErrorBoundary: this.#resetErrorBoundary,\n\t\t\t\t\t} satisfies FallbackProps;\n\n\t\t\t\t\tchildToRender = fallback(fallbackRenderProps);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tcase Boolean(fallback): {\n\t\t\t\t\tchildToRender = fallback;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tdefault: {\n\t\t\t\t\tconsole.warn(\"No fallback provided to error boundary\");\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tconst contextValue = {\n\t\t\terror,\n\t\t\thasError,\n\t\t\tresetErrorBoundary: this.#resetErrorBoundary,\n\t\t} satisfies ErrorBoundaryContextType;\n\n\t\treturn <ErrorBoundaryContext value={contextValue}>{childToRender}</ErrorBoundaryContext>;\n\t}\n\n\t#resetErrorBoundary = (...parameters: unknown[]) => {\n\t\tconst { error } = this.state;\n\n\t\tif (error !== null) {\n\t\t\tthis.props.onReset?.({\n\t\t\t\targs: parameters,\n\t\t\t\treason: \"imperative-api\",\n\t\t\t});\n\n\t\t\tthis.setState(initialState);\n\t\t}\n\t};\n}\n","import { useCallbackRef } from \"@zayne-labs/toolkit-react\";\nimport { useState } from \"react\";\nimport { useErrorBoundaryContext } from \"./error-boundary-context\";\n\ntype UseErrorBoundaryState<TError extends Error> =\n\t| {\n\t\t\terror: null;\n\t\t\thasError: false;\n\t }\n\t| {\n\t\t\terror: TError;\n\t\t\thasError: true;\n\t };\n\nexport const useErrorBoundary = <TError extends Error>() => {\n\tconst { resetErrorBoundary } = useErrorBoundaryContext();\n\n\tconst [state, setState] = useState<UseErrorBoundaryState<TError>>({\n\t\terror: null,\n\t\thasError: false,\n\t});\n\n\tif (state.hasError) {\n\t\tthrow state.error;\n\t}\n\n\tconst resetBoundary = useCallbackRef(() => {\n\t\tresetErrorBoundary();\n\n\t\tsetState({\n\t\t\terror: null,\n\t\t\thasError: false,\n\t\t});\n\t});\n\n\tconst showBoundary = useCallbackRef((error: TError) => {\n\t\tsetState({\n\t\t\terror,\n\t\t\thasError: true,\n\t\t});\n\t});\n\n\treturn { resetBoundary, showBoundary };\n};\n"],"mappings":";;;;;;AAQA,MAAa,CAAC,sBAAsB,wB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AA0B;EACnD,MAAM,EAAE,OAAO,GAAG,KAAK;AAEvB,MAAI,UAAU,MAAM;AACnB,QAAK,MAAM,UAAU;IACpB,MAAM;IACN,QAAQ;IACR;AAED,QAAK,SAAS;EACd;CACD;AACD;;;;AC3GD,MAAa,yBAA+C;CAC3D,MAAM,EAAE,oBAAoB,GAAG;CAE/B,MAAM,CAAC,OAAO,SAAS,GAAG,SAAwC;EACjE,OAAO;EACP,UAAU;EACV;AAED,KAAI,MAAM,SACT,OAAM,MAAM;CAGb,MAAM,gBAAgB,qBAAqB;AAC1C;AAEA,WAAS;GACR,OAAO;GACP,UAAU;GACV;CACD;CAED,MAAM,eAAe,gBAAgB,UAAkB;AACtD,WAAS;GACR;GACA,UAAU;GACV;CACD;AAED,QAAO;EAAE;EAAe;EAAc;AACtC"}
@@ -1,20 +1,20 @@
1
- import "react";
2
1
  import { isArray, isNumber } from "@zayne-labs/toolkit-type-helpers";
2
+ import "react";
3
3
  import { jsx } from "react/jsx-runtime";
4
4
 
5
5
  //#region src/components/common/for/for.tsx
6
6
  function For(props) {
7
- const { children, each, fallback = null, render } = props;
7
+ const { children, each, fallback = null, renderItem } = props;
8
8
  if (each == null || isNumber(each) && each === 0 || isArray(each) && each.length === 0) return fallback;
9
9
  const resolvedArray = isNumber(each) ? [...Array(each).keys()] : each;
10
10
  if (resolvedArray.length === 0) return fallback;
11
11
  const JSXElementList = resolvedArray.map((...params) => {
12
- return typeof children === "function" ? children(...params) : render(...params);
12
+ return typeof children === "function" ? children(...params) : renderItem(...params);
13
13
  });
14
14
  return JSXElementList;
15
15
  }
16
16
  function ForWithWrapper(props) {
17
- const { as: ListContainer = "ul", children, className, each, ref, render,...restOfListProps } = props;
17
+ const { as: ListContainer = "ul", children, className, each, ref, renderItem,...restOfListProps } = props;
18
18
  return /* @__PURE__ */ jsx(ListContainer, {
19
19
  ref,
20
20
  className,
@@ -22,7 +22,7 @@ function ForWithWrapper(props) {
22
22
  children: /* @__PURE__ */ jsx(For, {
23
23
  children,
24
24
  each,
25
- render
25
+ renderItem
26
26
  })
27
27
  });
28
28
  }
@@ -39,4 +39,4 @@ const getElementList = (variant) => {
39
39
 
40
40
  //#endregion
41
41
  export { For, ForWithWrapper, getElementList };
42
- //# sourceMappingURL=for-aTw1TgJo.js.map
42
+ //# sourceMappingURL=for-DGs2XZ21.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"for-DGs2XZ21.js","names":[],"sources":["../../src/components/common/for/for.tsx","../../src/components/common/for/getElementList.ts"],"sourcesContent":["import type { DiscriminatedRenderItemProps, PolymorphicProps } from \"@zayne-labs/toolkit-react/utils\";\nimport { type ExtractUnion, isArray, isNumber, type Prettify } from \"@zayne-labs/toolkit-type-helpers\";\nimport * as React from \"react\";\n\n// prettier-ignore\ntype RenderPropFn<TArray> = (\n\titem: TArray extends readonly unknown[] ? ExtractUnion<TArray> : TArray extends number ? number : unknown,\n\tindex: number,\n\tarray: TArray extends readonly unknown[] ? TArray : TArray extends number ? number[] : unknown[]\n) => React.ReactNode;\n\nexport type ForRenderProps<TArrayItem> = DiscriminatedRenderItemProps<RenderPropFn<TArrayItem>>;\n\n/* eslint-disable perfectionist/sort-intersection-types -- Prefer the object to come first before the render props */\ntype ForProps<TArray> = Prettify<\n\t{\n\t\teach: TArray;\n\t\tfallback?: React.ReactNode;\n\t} & ForRenderProps<TArray>\n>;\n\n/* eslint-enable perfectionist/sort-intersection-types -- Prefer the object to come first before the render props */\n\nexport function For<const TArray>(props: ForProps<TArray>) {\n\tconst { children, each, fallback = null, renderItem } = props;\n\n\tif (each == null || (isNumber(each) && each === 0) || (isArray(each) && each.length === 0)) {\n\t\treturn fallback;\n\t}\n\n\tconst resolvedArray = isNumber(each) ? [...Array(each).keys()] : (each as unknown[]);\n\n\tif (resolvedArray.length === 0) {\n\t\treturn fallback;\n\t}\n\n\tconst JSXElementList = resolvedArray.map((...params) => {\n\t\ttype Params = Parameters<RenderPropFn<TArray>>;\n\n\t\treturn typeof children === \"function\" ?\n\t\t\t\tchildren(...(params as Params))\n\t\t\t:\trenderItem(...(params as Params));\n\t});\n\n\treturn JSXElementList;\n}\n\nexport function ForWithWrapper<TArrayItem, TElement extends React.ElementType = \"ul\">(\n\tprops: PolymorphicProps<TElement, ForProps<TArrayItem>>\n) {\n\tconst {\n\t\tas: ListContainer = \"ul\",\n\t\tchildren,\n\t\tclassName,\n\t\teach,\n\t\tref,\n\t\trenderItem,\n\t\t...restOfListProps\n\t} = props;\n\n\treturn (\n\t\t<ListContainer ref={ref} className={className} {...restOfListProps}>\n\t\t\t<For {...({ children, each, renderItem } as ForProps<TArrayItem>)} />\n\t\t</ListContainer>\n\t);\n}\n","import { For, ForWithWrapper } from \"./for\";\n\ntype GetElementListResult<TVariant extends \"base\" | \"withWrapper\"> = TVariant extends \"base\"\n\t? [typeof For]\n\t: [typeof ForWithWrapper];\n\nconst getElementList = <TVariant extends \"base\" | \"withWrapper\" = \"withWrapper\">(\n\tvariant?: TVariant\n): GetElementListResult<TVariant> => {\n\tswitch (variant) {\n\t\tcase \"base\": {\n\t\t\treturn [For] as never;\n\t\t}\n\t\tcase \"withWrapper\": {\n\t\t\treturn [ForWithWrapper] as never;\n\t\t}\n\t\tdefault: {\n\t\t\treturn [ForWithWrapper] as never;\n\t\t}\n\t}\n};\n\nexport { getElementList };\n"],"mappings":";;;;;AAuBA,SAAgB,IAAkB,OAAyB;CAC1D,MAAM,EAAE,UAAU,MAAM,WAAW,MAAM,YAAY,GAAG;AAExD,KAAI,QAAQ,QAAS,SAAS,SAAS,SAAS,KAAO,QAAQ,SAAS,KAAK,WAAW,EACvF,QAAO;CAGR,MAAM,gBAAgB,SAAS,QAAQ,CAAC,GAAG,MAAM,MAAM,OAAO,GAAI;AAElE,KAAI,cAAc,WAAW,EAC5B,QAAO;CAGR,MAAM,iBAAiB,cAAc,KAAK,GAAG,WAAW;AAGvD,SAAO,OAAO,aAAa,aACzB,SAAS,GAAI,UACZ,WAAW,GAAI;CAClB;AAED,QAAO;AACP;AAED,SAAgB,eACf,OACC;CACD,MAAM,EACL,IAAI,gBAAgB,MACpB,UACA,WACA,MACA,KACA,WACA,GAAG,iBACH,GAAG;AAEJ,QACC,oBAAC;EAAmB;EAAgB;EAAW,GAAI;YAClD,oBAAC;GAAW;GAAU;GAAM;;;AAG9B;;;;AC3DD,MAAM,kBACL,YACoC;AACpC,SAAQ,SAAR;EACC,KAAK,OACJ,QAAO,CAAC,IAAI;EAEb,KAAK,cACJ,QAAO,CAAC,eAAe;EAExB,QACC,QAAO,CAAC,eAAe;CAExB;AACD"}
@@ -1,11 +1,11 @@
1
1
  import { __export } from "./chunk-Cl8Af3a2.js";
2
- import { getMultipleSlots } from "./getSlot-D1_uG-Ym.js";
3
- import { SlotRoot } from "./slot-RXTKo4L7.js";
4
- import { getElementList } from "./for-aTw1TgJo.js";
2
+ import { getMultipleSlots } from "./getSlot-Cf5ON6lE.js";
3
+ import { SlotRoot } from "./slot-D1062oA5.js";
4
+ import { getElementList } from "./for-DGs2XZ21.js";
5
5
  import { cnMerge } from "./cn-_FbtIrlZ.js";
6
+ import { defineEnum, isObject } from "@zayne-labs/toolkit-type-helpers";
6
7
  import { Fragment, createElement, useEffect, useId, useMemo, useRef } from "react";
7
8
  import { dataAttr, on, toArray } from "@zayne-labs/toolkit-core";
8
- import { defineEnum, isObject } from "@zayne-labs/toolkit-type-helpers";
9
9
  import { ContextError, createCustomContext, useCallbackRef, useToggle } from "@zayne-labs/toolkit-react";
10
10
  import { jsx, jsxs } from "react/jsx-runtime";
11
11
  import { composeRefs, composeTwoEventHandlers } from "@zayne-labs/toolkit-react/utils";
@@ -200,17 +200,16 @@ function FormFieldContext(props) {
200
200
  return render(fieldContextValues);
201
201
  }
202
202
  function FormLabel(props) {
203
- const { formItemId, name } = useStrictFormFieldContext();
204
- const { children, className,...restOfProps } = props;
205
- const { isDisabled, isInvalid } = useLaxFormFieldState({ name });
203
+ const fieldContextValues = useLaxFormFieldContext();
204
+ const { children, htmlFor = fieldContextValues?.formItemId,...restOfProps } = props;
205
+ const { isDisabled, isInvalid } = useLaxFormFieldState({ name: fieldContextValues?.name });
206
206
  return /* @__PURE__ */ jsx("label", {
207
207
  "data-scope": "form",
208
208
  "data-part": "label",
209
209
  "data-slot": "form-label",
210
210
  "data-disabled": dataAttr(isDisabled),
211
211
  "data-invalid": dataAttr(isInvalid),
212
- htmlFor: formItemId,
213
- className,
212
+ htmlFor,
214
213
  ...restOfProps,
215
214
  children
216
215
  });
@@ -400,7 +399,7 @@ function FormDescription(props) {
400
399
  const FormErrorMessagePrimitive = (props) => {
401
400
  const fieldContextValues = useLaxFormFieldContext();
402
401
  const rootContextValues = useFormMethodsContext({ strict: false });
403
- const { children, className, classNames, control = rootContextValues?.control, disableErrorAnimation = false, disableScrollToErrorField = false, fieldName = fieldContextValues?.name, render, type = "regular" } = props;
402
+ const { children, className, classNames, control = rootContextValues?.control, disableErrorAnimation = false, disableScrollToErrorField = false, fieldName = fieldContextValues?.name, renderItem, type = "regular" } = props;
404
403
  const { errors } = useLaxFormFieldState({
405
404
  control,
406
405
  name: fieldName
@@ -433,9 +432,6 @@ const FormErrorMessagePrimitive = (props) => {
433
432
  const errorMessageElements = getErrorElements();
434
433
  const firstErrorElement = errorMessageElements[0];
435
434
  if (!firstErrorElement) return;
436
- const inputField = document.querySelector(`[name='${fieldName}']`);
437
- const isFocusableInput = inputField?.matches(":is(input, select, textarea, [contenteditable='true'])");
438
- if (isFocusableInput) return;
439
435
  requestAnimationFrame(() => {
440
436
  const rect = firstErrorElement.getBoundingClientRect();
441
437
  const topWithOffset = rect.top - 100;
@@ -490,12 +486,12 @@ const FormErrorMessagePrimitive = (props) => {
490
486
  "data-slot": "form-error-message-container",
491
487
  ref: wrapperRef
492
488
  };
493
- const selectedChildren = typeof children === "function" ? children : render;
489
+ const selectedChildren = typeof children === "function" ? children : renderItem;
494
490
  return /* @__PURE__ */ jsx(WrapperComponent, {
495
491
  ...wrapperComponentProps,
496
492
  children: /* @__PURE__ */ jsx(ErrorMessageList, {
497
493
  each: errorMessageArray,
498
- render: (errorMessage, index) => {
494
+ renderItem: (errorMessage, index) => {
499
495
  return selectedChildren({
500
496
  props: getRenderProps({ index }),
501
497
  state: getRenderState({
@@ -515,7 +511,7 @@ function FormErrorMessage(props) {
515
511
  control,
516
512
  fieldName: errorField,
517
513
  type,
518
- render: ({ props: renderProps, state }) => /* @__PURE__ */ jsx("p", {
514
+ renderItem: ({ props: renderProps, state }) => /* @__PURE__ */ jsx("p", {
519
515
  ...renderProps,
520
516
  className: cnMerge("text-shadcn-destructive text-[13px]", "data-[index=0]:mt-1", renderProps.className, className),
521
517
  children: state.errorMessage
@@ -542,8 +538,8 @@ function FormSubscribeToFieldValue(props) {
542
538
  control,
543
539
  name
544
540
  });
545
- const fieldProps = { value: formValue };
546
541
  const selectedChildren = typeof children === "function" ? children : render;
542
+ const fieldProps = { value: formValue };
547
543
  const resolvedChildren = selectedChildren(fieldProps);
548
544
  return resolvedChildren;
549
545
  }
@@ -587,4 +583,4 @@ __export(form_parts_exports, {
587
583
 
588
584
  //#endregion
589
585
  export { FormDescription, FormErrorMessage, FormErrorMessagePrimitive, FormField, FormFieldContext, FormFieldControlledField, FormFieldController, FormInput, FormInputGroup, FormInputLeftItem, FormInputPrimitive, FormInputRightItem, FormLabel, FormRoot, FormSelect, FormSelectPrimitive, FormSubmit, FormSubscribeToFieldValue, FormSubscribeToFormState, FormTextArea, FormTextAreaPrimitive, form_parts_exports, useFormRootContext, useStrictFormFieldContext };
590
- //# sourceMappingURL=form-6RV0u4YT.js.map
586
+ //# sourceMappingURL=form-BnSpmc4f.js.map