@zayne-labs/ui-react 0.10.8 → 0.10.10

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 (76) hide show
  1. package/dist/esm/{cn-s-D7vHW1.js → cn-DdD3uYxA.js} +1 -1
  2. package/dist/esm/{cn-s-D7vHW1.js.map → cn-DdD3uYxA.js.map} +1 -1
  3. package/dist/esm/common/await/index.d.ts +46 -4
  4. package/dist/esm/common/await/index.js +86 -4
  5. package/dist/esm/common/await/index.js.map +1 -0
  6. package/dist/esm/common/error-boundary/index.d.ts +1 -1
  7. package/dist/esm/common/for/index.d.ts +23 -2
  8. package/dist/esm/common/for/index.js +1 -1
  9. package/dist/esm/common/presence/index.js +1 -1
  10. package/dist/esm/common/show/index.d.ts +32 -2
  11. package/dist/esm/common/slot/index.d.ts +16 -2
  12. package/dist/esm/common/suspense-with-boundary/index.d.ts +2 -2
  13. package/dist/esm/common/suspense-with-boundary/index.js +20 -3
  14. package/dist/esm/common/suspense-with-boundary/index.js.map +1 -0
  15. package/dist/esm/common/switch/index.d.ts +28 -2
  16. package/dist/esm/common/switch/index.js +37 -2
  17. package/dist/esm/common/switch/index.js.map +1 -0
  18. package/dist/esm/common/teleport/index.d.ts +14 -2
  19. package/dist/esm/common/teleport/index.js +31 -2
  20. package/dist/esm/common/teleport/index.js.map +1 -0
  21. package/dist/esm/{for-DK5rEY_m.js → for-BYsFEk3R.js} +1 -1
  22. package/dist/esm/{for-DK5rEY_m.js.map → for-BYsFEk3R.js.map} +1 -1
  23. package/dist/esm/{index-C8_O0zCb.d.ts → index-BwhRxsrZ.d.ts} +3 -3
  24. package/dist/esm/{index-B4K9g2v-.d.ts → index-C_2Onnhl.d.ts} +4 -4
  25. package/dist/esm/{presence-CL5_GHQH.js → presence-CAQElNtY.js} +1 -1
  26. package/dist/esm/{presence-CL5_GHQH.js.map → presence-CAQElNtY.js.map} +1 -1
  27. package/dist/esm/ui/card/index.d.ts +20 -2
  28. package/dist/esm/ui/card/index.js +94 -4
  29. package/dist/esm/ui/card/index.js.map +1 -0
  30. package/dist/esm/ui/carousel/index.d.ts +95 -2
  31. package/dist/esm/ui/carousel/index.js +285 -13
  32. package/dist/esm/ui/carousel/index.js.map +1 -0
  33. package/dist/esm/ui/drag-scroll/index.d.ts +23 -2
  34. package/dist/esm/ui/drag-scroll/index.js +114 -3
  35. package/dist/esm/ui/drag-scroll/index.js.map +1 -0
  36. package/dist/esm/ui/drop-zone/index.d.ts +346 -2
  37. package/dist/esm/ui/drop-zone/index.js +1026 -14
  38. package/dist/esm/ui/drop-zone/index.js.map +1 -0
  39. package/dist/esm/ui/form/index.d.ts +227 -2
  40. package/dist/esm/ui/form/index.js +573 -5
  41. package/dist/esm/ui/form/index.js.map +1 -0
  42. package/package.json +6 -8
  43. package/dist/esm/await-DDgVzpvI.js +0 -87
  44. package/dist/esm/await-DDgVzpvI.js.map +0 -1
  45. package/dist/esm/card-DDLJVCwL.js +0 -95
  46. package/dist/esm/card-DDLJVCwL.js.map +0 -1
  47. package/dist/esm/carousel-B051PAAX.js +0 -285
  48. package/dist/esm/carousel-B051PAAX.js.map +0 -1
  49. package/dist/esm/common/index.d.ts +0 -9
  50. package/dist/esm/common/index.js +0 -11
  51. package/dist/esm/common-PS3X58Pj.js +0 -0
  52. package/dist/esm/drag-scroll-Bb1SG4On.js +0 -115
  53. package/dist/esm/drag-scroll-Bb1SG4On.js.map +0 -1
  54. package/dist/esm/drop-zone-C9VpKJAD.js +0 -1013
  55. package/dist/esm/drop-zone-C9VpKJAD.js.map +0 -1
  56. package/dist/esm/form-DyGy9LnA.js +0 -574
  57. package/dist/esm/form-DyGy9LnA.js.map +0 -1
  58. package/dist/esm/index-BoZe50e8.d.ts +0 -340
  59. package/dist/esm/index-BsGxDKlt.d.ts +0 -32
  60. package/dist/esm/index-Bx2BzRRJ.d.ts +0 -16
  61. package/dist/esm/index-C1GPFYKG.d.ts +0 -23
  62. package/dist/esm/index-CZjeBSoQ.d.ts +0 -14
  63. package/dist/esm/index-CffEFE66.d.ts +0 -28
  64. package/dist/esm/index-DWl-QZ3Q.d.ts +0 -46
  65. package/dist/esm/index-DZxgPnK1.d.ts +0 -95
  66. package/dist/esm/index-DbiE_few.d.ts +0 -227
  67. package/dist/esm/index-Df39YVRj.d.ts +0 -23
  68. package/dist/esm/index-SX3cnKP6.d.ts +0 -20
  69. package/dist/esm/suspense-with-boundary-D-1NYDV4.js +0 -21
  70. package/dist/esm/suspense-with-boundary-D-1NYDV4.js.map +0 -1
  71. package/dist/esm/switch-Ch22z21e.js +0 -38
  72. package/dist/esm/switch-Ch22z21e.js.map +0 -1
  73. package/dist/esm/teleport-C8TzRm4M.js +0 -32
  74. package/dist/esm/teleport-C8TzRm4M.js.map +0 -1
  75. package/dist/esm/ui/index.d.ts +0 -6
  76. package/dist/esm/ui/index.js +0 -18
@@ -1,4 +1,115 @@
1
- import "../../cn-s-D7vHW1.js";
2
- import { useDragScroll } from "../../drag-scroll-Bb1SG4On.js";
1
+ import { cnMerge } from "../../cn-DdD3uYxA.js";
2
+ import { composeRefs, mergeTwoProps } from "@zayne-labs/toolkit-react/utils";
3
+ import { useCallback, useMemo, useRef } from "react";
4
+ import { useCallbackRef } from "@zayne-labs/toolkit-react";
5
+ import { checkIsDeviceMobile, off, on } from "@zayne-labs/toolkit-core";
3
6
 
4
- export { useDragScroll };
7
+ //#region src/components/ui/drag-scroll/utils.ts
8
+ const updateCursor = (element) => {
9
+ element.style.cursor = "grabbing";
10
+ element.style.userSelect = "none";
11
+ };
12
+ const onScrollSnap = (action, element) => {
13
+ if (action === "remove") {
14
+ element.style.scrollSnapType = "none";
15
+ return;
16
+ }
17
+ element.style.scrollSnapType = "";
18
+ };
19
+ const resetCursor = (element) => {
20
+ element.style.cursor = "";
21
+ element.style.userSelect = "";
22
+ };
23
+ const handleScrollSnap = (dragContainer) => {
24
+ if (!checkIsDeviceMobile()) onScrollSnap("remove", dragContainer);
25
+ else onScrollSnap("reset", dragContainer);
26
+ };
27
+
28
+ //#endregion
29
+ //#region src/components/ui/drag-scroll/use-drag-scroll.ts
30
+ const useDragScroll = (props) => {
31
+ const { classNames, extraItemProps, extraRootProps, orientation = "horizontal", usage = "allScreens" } = props ?? {};
32
+ const dragContainerRef = useRef(null);
33
+ const positionRef = useRef({
34
+ left: 0,
35
+ top: 0,
36
+ x: 0,
37
+ y: 0
38
+ });
39
+ const handleMouseMove = useCallbackRef((event) => {
40
+ if (!dragContainerRef.current) return;
41
+ if (orientation === "horizontal" || orientation === "both") {
42
+ const dx = event.clientX - positionRef.current.x;
43
+ dragContainerRef.current.scrollLeft = positionRef.current.left - dx;
44
+ }
45
+ if (orientation === "vertical" || orientation === "both") {
46
+ const dy = event.clientY - positionRef.current.y;
47
+ dragContainerRef.current.scrollTop = positionRef.current.top - dy;
48
+ }
49
+ });
50
+ const handleMouseUpOrLeave = useCallbackRef(() => {
51
+ if (!dragContainerRef.current) return;
52
+ off("mousemove", dragContainerRef.current, handleMouseMove);
53
+ off("mouseup", dragContainerRef.current, handleMouseUpOrLeave);
54
+ off("mouseleave", dragContainerRef.current, handleMouseUpOrLeave);
55
+ resetCursor(dragContainerRef.current);
56
+ });
57
+ const handleMouseDown = useCallbackRef((event) => {
58
+ if (usage === "mobileAndTabletOnly" && window.innerWidth >= 768) return;
59
+ if (usage === "desktopOnly" && window.innerWidth < 768) return;
60
+ if (!dragContainerRef.current) return;
61
+ if (orientation === "horizontal" || orientation === "both") {
62
+ positionRef.current.x = event.clientX;
63
+ positionRef.current.left = dragContainerRef.current.scrollLeft;
64
+ }
65
+ if (orientation === "vertical" || orientation === "both") {
66
+ positionRef.current.y = event.clientY;
67
+ positionRef.current.top = dragContainerRef.current.scrollTop;
68
+ }
69
+ updateCursor(dragContainerRef.current);
70
+ on("mousemove", dragContainerRef.current, handleMouseMove);
71
+ on("mouseup", dragContainerRef.current, handleMouseUpOrLeave);
72
+ on("mouseleave", dragContainerRef.current, handleMouseUpOrLeave);
73
+ });
74
+ const refCallBack = useCallbackRef((node) => {
75
+ dragContainerRef.current = node;
76
+ node && handleScrollSnap(node);
77
+ return on("mousedown", dragContainerRef.current, handleMouseDown);
78
+ });
79
+ const getRootProps = useCallback((rootProps) => {
80
+ const mergedRootProps = mergeTwoProps(extraRootProps, rootProps);
81
+ return {
82
+ ...mergedRootProps,
83
+ className: cnMerge(`scrollbar-hidden flex w-full cursor-grab snap-x snap-mandatory overflow-x-scroll
84
+ overflow-y-hidden`, orientation === "horizontal" && "flex-row", orientation === "vertical" && "flex-col", usage === "mobileAndTabletOnly" && "md:cursor-default md:flex-col", usage === "desktopOnly" && "max-md:cursor-default max-md:flex-col", classNames?.base, mergedRootProps.className),
85
+ "data-part": "root",
86
+ "data-scope": "drag-scroll",
87
+ "data-slot": "drag-scroll-root",
88
+ ref: composeRefs(refCallBack, mergedRootProps?.ref)
89
+ };
90
+ }, [
91
+ extraRootProps,
92
+ classNames?.base,
93
+ orientation,
94
+ refCallBack,
95
+ usage
96
+ ]);
97
+ const getItemProps = useCallback((itemProps) => {
98
+ const mergedItemProps = mergeTwoProps(extraItemProps, itemProps);
99
+ return {
100
+ ...mergedItemProps,
101
+ className: cnMerge("snap-center snap-always", classNames?.item, mergedItemProps.className),
102
+ "data-part": "item",
103
+ "data-scope": "drag-scroll",
104
+ "data-slot": "drag-scroll-item"
105
+ };
106
+ }, [extraItemProps, classNames?.item]);
107
+ return useMemo(() => ({
108
+ getItemProps,
109
+ getRootProps
110
+ }), [getItemProps, getRootProps]);
111
+ };
112
+
113
+ //#endregion
114
+ export { useDragScroll };
115
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["refCallBack: RefCallback<TElement>","getRootProps: DragScrollResult<TElement, TItemElement>[\"getRootProps\"]","getItemProps: DragScrollResult<TElement, TItemElement>[\"getItemProps\"]"],"sources":["../../../../src/components/ui/drag-scroll/utils.ts","../../../../src/components/ui/drag-scroll/use-drag-scroll.ts"],"sourcesContent":["import { checkIsDeviceMobile } from \"@zayne-labs/toolkit-core\";\n\n/* eslint-disable no-param-reassign -- Mutation is needed here since it's an element */\nexport const updateCursor = <TElement extends HTMLElement>(element: TElement) => {\n\telement.style.cursor = \"grabbing\";\n\telement.style.userSelect = \"none\";\n};\n\nexport const onScrollSnap = <TElement extends HTMLElement>(\n\taction: \"remove\" | \"reset\",\n\telement: TElement\n) => {\n\tif (action === \"remove\") {\n\t\telement.style.scrollSnapType = \"none\";\n\t\treturn;\n\t}\n\n\telement.style.scrollSnapType = \"\";\n};\n\nexport const resetCursor = <TElement extends HTMLElement>(element: TElement) => {\n\telement.style.cursor = \"\";\n\telement.style.userSelect = \"\";\n};\n/* eslint-enable no-param-reassign -- Mutation is needed here since it's an element */\n\nexport const handleScrollSnap = (dragContainer: HTMLElement) => {\n\tconst isMobile = checkIsDeviceMobile();\n\n\tif (!isMobile) {\n\t\tonScrollSnap(\"remove\", dragContainer);\n\t} else {\n\t\tonScrollSnap(\"reset\", dragContainer);\n\t}\n};\n","import { off, on } from \"@zayne-labs/toolkit-core\";\nimport { useCallbackRef } from \"@zayne-labs/toolkit-react\";\nimport { composeRefs, type InferProps, mergeTwoProps } from \"@zayne-labs/toolkit-react/utils\";\nimport { type RefCallback, useCallback, useMemo, useRef } from \"react\";\nimport { cnMerge } from \"@/lib/utils/cn\";\nimport { handleScrollSnap, resetCursor, updateCursor } from \"./utils\";\n\ntype ItemProps<TItemElement extends HTMLElement> = Omit<InferProps<TItemElement>, \"children\">;\n\ntype RootProps<TElement extends HTMLElement> = Omit<InferProps<TElement>, \"children\">;\n\ntype DragScrollProps<TElement extends HTMLElement, TItemElement extends HTMLElement> = {\n\tclassNames?: { base?: string; item?: string };\n\textraItemProps?: ItemProps<TItemElement>;\n\textraRootProps?: InferProps<TElement>;\n\torientation?: \"both\" | \"horizontal\" | \"vertical\";\n\tusage?: \"allScreens\" | \"desktopOnly\" | \"mobileAndTabletOnly\";\n};\n\ntype DragScrollResult<TElement extends HTMLElement, TItemElement extends HTMLElement> = {\n\tgetItemProps: (itemProps?: ItemProps<TItemElement>) => ItemProps<TItemElement>;\n\tgetRootProps: (rootProps?: RootProps<TElement>) => RootProps<TElement>;\n};\n\nconst useDragScroll = <TElement extends HTMLElement, TItemElement extends HTMLElement = HTMLElement>(\n\tprops?: DragScrollProps<TElement, TItemElement>\n): DragScrollResult<TElement, TItemElement> => {\n\tconst {\n\t\tclassNames,\n\t\textraItemProps,\n\t\textraRootProps,\n\t\torientation = \"horizontal\",\n\t\tusage = \"allScreens\",\n\t} = props ?? {};\n\n\tconst dragContainerRef = useRef<TElement>(null);\n\n\tconst positionRef = useRef({ left: 0, top: 0, x: 0, y: 0 });\n\n\tconst handleMouseMove = useCallbackRef((event: MouseEvent) => {\n\t\tif (!dragContainerRef.current) return;\n\n\t\tif (orientation === \"horizontal\" || orientation === \"both\") {\n\t\t\t// == calculate the current change in the horizontal scroll position based on the difference between the previous mouse position and the new mouse position\n\t\t\tconst dx = event.clientX - positionRef.current.x;\n\n\t\t\t// == Assign the scrollLeft of the container to the difference between its previous horizontal scroll position and the change in the mouse position\n\t\t\tdragContainerRef.current.scrollLeft = positionRef.current.left - dx;\n\t\t}\n\n\t\tif (orientation === \"vertical\" || orientation === \"both\") {\n\t\t\t// == calculate the current change in the vertical scroll position based on the difference between the previous mouse position and the new mouse position\n\t\t\tconst dy = event.clientY - positionRef.current.y;\n\n\t\t\t// == Assign the scrollTop of the container to the difference between its previous vertical scroll position and the change in the mouse position\n\t\t\tdragContainerRef.current.scrollTop = positionRef.current.top - dy;\n\t\t}\n\t});\n\n\tconst handleMouseUpOrLeave = useCallbackRef(() => {\n\t\tif (!dragContainerRef.current) return;\n\n\t\toff(\"mousemove\", dragContainerRef.current, handleMouseMove);\n\t\toff(\"mouseup\", dragContainerRef.current, handleMouseUpOrLeave);\n\t\toff(\"mouseleave\", dragContainerRef.current, handleMouseUpOrLeave);\n\n\t\tresetCursor(dragContainerRef.current);\n\t});\n\n\tconst handleMouseDown = useCallbackRef((event: MouseEvent) => {\n\t\tif (usage === \"mobileAndTabletOnly\" && window.innerWidth >= 768) return;\n\t\tif (usage === \"desktopOnly\" && window.innerWidth < 768) return;\n\n\t\tif (!dragContainerRef.current) return;\n\n\t\t// == Update all initial position properties stored in the positionRef\n\t\tif (orientation === \"horizontal\" || orientation === \"both\") {\n\t\t\tpositionRef.current.x = event.clientX;\n\t\t\tpositionRef.current.left = dragContainerRef.current.scrollLeft;\n\t\t}\n\n\t\tif (orientation === \"vertical\" || orientation === \"both\") {\n\t\t\tpositionRef.current.y = event.clientY;\n\t\t\tpositionRef.current.top = dragContainerRef.current.scrollTop;\n\t\t}\n\n\t\tupdateCursor(dragContainerRef.current);\n\n\t\ton(\"mousemove\", dragContainerRef.current, handleMouseMove);\n\t\ton(\"mouseup\", dragContainerRef.current, handleMouseUpOrLeave);\n\t\ton(\"mouseleave\", dragContainerRef.current, handleMouseUpOrLeave);\n\t});\n\n\tconst refCallBack: RefCallback<TElement> = useCallbackRef((node) => {\n\t\tdragContainerRef.current = node;\n\n\t\tnode && handleScrollSnap(node);\n\n\t\tconst cleanup = on(\"mousedown\", dragContainerRef.current, handleMouseDown);\n\n\t\treturn cleanup;\n\t});\n\n\tconst getRootProps: DragScrollResult<TElement, TItemElement>[\"getRootProps\"] = useCallback(\n\t\t(rootProps) => {\n\t\t\tconst mergedRootProps = mergeTwoProps(extraRootProps, rootProps);\n\n\t\t\treturn {\n\t\t\t\t...mergedRootProps,\n\t\t\t\tclassName: cnMerge(\n\t\t\t\t\t`scrollbar-hidden flex w-full cursor-grab snap-x snap-mandatory overflow-x-scroll\n\t\t\t\t\toverflow-y-hidden`,\n\t\t\t\t\torientation === \"horizontal\" && \"flex-row\",\n\t\t\t\t\torientation === \"vertical\" && \"flex-col\",\n\t\t\t\t\tusage === \"mobileAndTabletOnly\" && \"md:cursor-default md:flex-col\",\n\t\t\t\t\tusage === \"desktopOnly\" && \"max-md:cursor-default max-md:flex-col\",\n\t\t\t\t\tclassNames?.base,\n\t\t\t\t\tmergedRootProps.className\n\t\t\t\t),\n\t\t\t\t\"data-part\": \"root\",\n\t\t\t\t\"data-scope\": \"drag-scroll\",\n\t\t\t\t\"data-slot\": \"drag-scroll-root\",\n\t\t\t\tref: composeRefs(\n\t\t\t\t\trefCallBack,\n\t\t\t\t\t(mergedRootProps as { ref?: React.Ref<TElement> } | undefined)?.ref\n\t\t\t\t),\n\t\t\t};\n\t\t},\n\t\t[extraRootProps, classNames?.base, orientation, refCallBack, usage]\n\t);\n\n\tconst getItemProps: DragScrollResult<TElement, TItemElement>[\"getItemProps\"] = useCallback(\n\t\t(itemProps) => {\n\t\t\tconst mergedItemProps = mergeTwoProps(extraItemProps, itemProps);\n\n\t\t\treturn {\n\t\t\t\t...mergedItemProps,\n\t\t\t\tclassName: cnMerge(\"snap-center snap-always\", classNames?.item, mergedItemProps.className),\n\t\t\t\t\"data-part\": \"item\",\n\t\t\t\t\"data-scope\": \"drag-scroll\",\n\t\t\t\t\"data-slot\": \"drag-scroll-item\",\n\t\t\t};\n\t\t},\n\t\t[extraItemProps, classNames?.item]\n\t);\n\n\tconst result = useMemo(() => ({ getItemProps, getRootProps }), [getItemProps, getRootProps]);\n\n\treturn result;\n};\n\nexport { useDragScroll };\n"],"mappings":";;;;;;;AAGA,MAAa,gBAA8C,YAAsB;AAChF,SAAQ,MAAM,SAAS;AACvB,SAAQ,MAAM,aAAa;;AAG5B,MAAa,gBACZ,QACA,YACI;AACJ,KAAI,WAAW,UAAU;AACxB,UAAQ,MAAM,iBAAiB;AAC/B;;AAGD,SAAQ,MAAM,iBAAiB;;AAGhC,MAAa,eAA6C,YAAsB;AAC/E,SAAQ,MAAM,SAAS;AACvB,SAAQ,MAAM,aAAa;;AAI5B,MAAa,oBAAoB,kBAA+B;AAG/D,KAAI,CAFa,qBAAqB,CAGrC,cAAa,UAAU,cAAc;KAErC,cAAa,SAAS,cAAc;;;;;ACRtC,MAAM,iBACL,UAC8C;CAC9C,MAAM,EACL,YACA,gBACA,gBACA,cAAc,cACd,QAAQ,iBACL,SAAS,EAAE;CAEf,MAAM,mBAAmB,OAAiB,KAAK;CAE/C,MAAM,cAAc,OAAO;EAAE,MAAM;EAAG,KAAK;EAAG,GAAG;EAAG,GAAG;EAAG,CAAC;CAE3D,MAAM,kBAAkB,gBAAgB,UAAsB;AAC7D,MAAI,CAAC,iBAAiB,QAAS;AAE/B,MAAI,gBAAgB,gBAAgB,gBAAgB,QAAQ;GAE3D,MAAM,KAAK,MAAM,UAAU,YAAY,QAAQ;AAG/C,oBAAiB,QAAQ,aAAa,YAAY,QAAQ,OAAO;;AAGlE,MAAI,gBAAgB,cAAc,gBAAgB,QAAQ;GAEzD,MAAM,KAAK,MAAM,UAAU,YAAY,QAAQ;AAG/C,oBAAiB,QAAQ,YAAY,YAAY,QAAQ,MAAM;;GAE/D;CAEF,MAAM,uBAAuB,qBAAqB;AACjD,MAAI,CAAC,iBAAiB,QAAS;AAE/B,MAAI,aAAa,iBAAiB,SAAS,gBAAgB;AAC3D,MAAI,WAAW,iBAAiB,SAAS,qBAAqB;AAC9D,MAAI,cAAc,iBAAiB,SAAS,qBAAqB;AAEjE,cAAY,iBAAiB,QAAQ;GACpC;CAEF,MAAM,kBAAkB,gBAAgB,UAAsB;AAC7D,MAAI,UAAU,yBAAyB,OAAO,cAAc,IAAK;AACjE,MAAI,UAAU,iBAAiB,OAAO,aAAa,IAAK;AAExD,MAAI,CAAC,iBAAiB,QAAS;AAG/B,MAAI,gBAAgB,gBAAgB,gBAAgB,QAAQ;AAC3D,eAAY,QAAQ,IAAI,MAAM;AAC9B,eAAY,QAAQ,OAAO,iBAAiB,QAAQ;;AAGrD,MAAI,gBAAgB,cAAc,gBAAgB,QAAQ;AACzD,eAAY,QAAQ,IAAI,MAAM;AAC9B,eAAY,QAAQ,MAAM,iBAAiB,QAAQ;;AAGpD,eAAa,iBAAiB,QAAQ;AAEtC,KAAG,aAAa,iBAAiB,SAAS,gBAAgB;AAC1D,KAAG,WAAW,iBAAiB,SAAS,qBAAqB;AAC7D,KAAG,cAAc,iBAAiB,SAAS,qBAAqB;GAC/D;CAEF,MAAMA,cAAqC,gBAAgB,SAAS;AACnE,mBAAiB,UAAU;AAE3B,UAAQ,iBAAiB,KAAK;AAI9B,SAFgB,GAAG,aAAa,iBAAiB,SAAS,gBAAgB;GAGzE;CAEF,MAAMC,eAAyE,aAC7E,cAAc;EACd,MAAM,kBAAkB,cAAc,gBAAgB,UAAU;AAEhE,SAAO;GACN,GAAG;GACH,WAAW,QACV;yBAEA,gBAAgB,gBAAgB,YAChC,gBAAgB,cAAc,YAC9B,UAAU,yBAAyB,iCACnC,UAAU,iBAAiB,yCAC3B,YAAY,MACZ,gBAAgB,UAChB;GACD,aAAa;GACb,cAAc;GACd,aAAa;GACb,KAAK,YACJ,aACC,iBAA+D,IAChE;GACD;IAEF;EAAC;EAAgB,YAAY;EAAM;EAAa;EAAa;EAAM,CACnE;CAED,MAAMC,eAAyE,aAC7E,cAAc;EACd,MAAM,kBAAkB,cAAc,gBAAgB,UAAU;AAEhE,SAAO;GACN,GAAG;GACH,WAAW,QAAQ,2BAA2B,YAAY,MAAM,gBAAgB,UAAU;GAC1F,aAAa;GACb,cAAc;GACd,aAAa;GACb;IAEF,CAAC,gBAAgB,YAAY,KAAK,CAClC;AAID,QAFe,eAAe;EAAE;EAAc;EAAc,GAAG,CAAC,cAAc,aAAa,CAAC"}
@@ -1,2 +1,346 @@
1
- import { DropZoneArea, DropZoneContainer, DropZoneContext, DropZoneError, DropZoneFileClear, DropZoneFileItem, DropZoneFileItemDelete, DropZoneFileItemMetadata, DropZoneFileItemPreview, DropZoneFileItemProgress, DropZoneFileList, DropZoneInput, DropZoneRoot, DropZoneTrigger, drop_zone_parts_d_exports, useDropZone, useDropZoneStoreContext } from "../../index-BoZe50e8.js";
2
- export { drop_zone_parts_d_exports as DropZone, DropZoneArea, DropZoneContainer, DropZoneContext, DropZoneError, DropZoneFileClear, DropZoneFileItem, DropZoneFileItemDelete, DropZoneFileItemMetadata, DropZoneFileItemPreview, DropZoneFileItemProgress, DropZoneFileList, DropZoneInput, DropZoneRoot, DropZoneTrigger, useDropZone, useDropZoneStoreContext };
1
+ import { InferProps, PolymorphicPropsStrict } from "@zayne-labs/toolkit-react/utils";
2
+ import * as _zayne_labs_toolkit_type_helpers0 from "@zayne-labs/toolkit-type-helpers";
3
+ import { Awaitable, SelectorFn } from "@zayne-labs/toolkit-type-helpers";
4
+ import * as react4 from "react";
5
+ import "@zayne-labs/toolkit-react";
6
+ import * as react_jsx_runtime26 from "react/jsx-runtime";
7
+ import * as _zayne_labs_toolkit_core1 from "@zayne-labs/toolkit-core";
8
+ import { FileMeta, FileOrFileMeta, FileValidationErrorContextEach, FileValidationHooksAsync, FileValidationSettingsAsync } from "@zayne-labs/toolkit-core";
9
+
10
+ //#region src/components/ui/drop-zone/utils.d.ts
11
+
12
+ declare class DropZoneError extends Error {
13
+ readonly dropZoneErrorSymbol: symbol;
14
+ file?: FileValidationErrorContextEach["file"];
15
+ name: "DropZoneError";
16
+ constructor(ctx: Pick<FileValidationErrorContextEach, "message"> & {
17
+ file?: FileValidationErrorContextEach["file"];
18
+ });
19
+ static isError(error: unknown): error is DropZoneError;
20
+ }
21
+ //#endregion
22
+ //#region src/components/ui/drop-zone/types.d.ts
23
+ type FileErrorContext = Omit<FileValidationErrorContextEach, "code"> & {
24
+ code: "upload-error" | FileValidationErrorContextEach["code"];
25
+ };
26
+ interface FileState {
27
+ /**
28
+ * Validation errors for the file
29
+ *
30
+ */
31
+ error?: FileErrorContext;
32
+ /**
33
+ * File object or file metadata
34
+ */
35
+ file: FileOrFileMeta;
36
+ /**
37
+ * Unique ID for the file
38
+ */
39
+ id: string;
40
+ /**
41
+ * Preview URL for the file
42
+ * - Will be undefined if `disallowPreviewForNonImageFiles` is set to `true` and the file is not an image
43
+ * - Can also be undefined if `URL.createObjectURL` fails
44
+ */
45
+ preview: string | undefined;
46
+ /**
47
+ * Progress of the file upload
48
+ */
49
+ progress: number;
50
+ /**
51
+ * Status of the file upload
52
+ */
53
+ status: "error" | "idle" | "success" | "uploading";
54
+ }
55
+ type FileStateOrIDProp = {
56
+ fileStateOrID: FileOrFileMeta | FileState | FileState["id"];
57
+ };
58
+ type RecordForDataAttr = Record<`data-${string}`, unknown>;
59
+ interface PartProps {
60
+ container: {
61
+ input: PartProps["container"]["output"];
62
+ output: InferProps<HTMLElement> & RecordForDataAttr;
63
+ };
64
+ fileItem: {
65
+ input: PartProps["fileItem"]["output"];
66
+ output: InferProps<"li"> & RecordForDataAttr;
67
+ };
68
+ fileItemClear: {
69
+ input: PartProps["fileItemClear"]["output"];
70
+ output: InferProps<"button"> & RecordForDataAttr;
71
+ };
72
+ fileItemDelete: {
73
+ input: Partial<FileStateOrIDProp> & PartProps["fileItemDelete"]["output"];
74
+ output: InferProps<"button"> & RecordForDataAttr;
75
+ };
76
+ fileItemMetadata: {
77
+ input: PartProps["fileItemMetadata"]["output"];
78
+ output: InferProps<"div"> & RecordForDataAttr;
79
+ };
80
+ fileItemPreview: {
81
+ input: PartProps["fileItemPreview"]["output"];
82
+ output: InferProps<"span"> & RecordForDataAttr;
83
+ };
84
+ fileItemProgress: {
85
+ input: PartProps["fileItemProgress"]["output"] & {
86
+ variant?: "circular" | "fill" | "linear";
87
+ };
88
+ output: InferProps<"span"> & RecordForDataAttr;
89
+ };
90
+ fileList: {
91
+ input: PartProps["fileList"]["output"] & {
92
+ orientation?: "horizontal" | "vertical";
93
+ };
94
+ output: InferProps<"ul"> & RecordForDataAttr;
95
+ };
96
+ input: {
97
+ input: PartProps["input"]["output"];
98
+ output: InferProps<"input"> & RecordForDataAttr;
99
+ };
100
+ trigger: {
101
+ input: PartProps["trigger"]["output"];
102
+ output: InferProps<"button"> & RecordForDataAttr;
103
+ };
104
+ }
105
+ type DropZonePropGetters = { [Key in keyof PartProps as `get${Capitalize<Key>}Props`]: (props: PartProps[Key]["input"]) => PartProps[Key]["output"] };
106
+ type PartInputProps = { [Key in keyof PartProps]: PartProps[Key]["input"] };
107
+ type DropZoneState = {
108
+ /**
109
+ * List of validation errors
110
+ */
111
+ errors: FileErrorContext[];
112
+ /**
113
+ * List of files with their preview URLs and unique IDs
114
+ */
115
+ fileStateArray: FileState[];
116
+ /**
117
+ * Whether or not a file is currently being dragged over the drop zone
118
+ */
119
+ isDraggingOver: boolean;
120
+ /**
121
+ * Whether or not any of the files are invalid
122
+ */
123
+ isInvalid: boolean;
124
+ };
125
+ type DropZoneActions = {
126
+ actions: {
127
+ addFiles: (files: FileList | FileOrFileMeta[] | null) => Awaitable<void>;
128
+ clearErrors: () => void;
129
+ clearFiles: () => void;
130
+ clearObjectURLs: () => void;
131
+ handleChange: (event: React.ChangeEvent<HTMLInputElement>) => Awaitable<void>;
132
+ handleDragEnter: (event: React.DragEvent<HTMLElement>) => void;
133
+ handleDragLeave: (event: React.DragEvent<HTMLElement>) => void;
134
+ handleDragOver: (event: React.DragEvent<HTMLElement>) => void;
135
+ handleDrop: (event: React.DragEvent<HTMLElement>) => Awaitable<void>;
136
+ handleFileUpload: (ctx: {
137
+ newFileStateArray: DropZoneState["fileStateArray"];
138
+ }) => Awaitable<void>;
139
+ handleKeyDown: (event: React.KeyboardEvent<HTMLElement>) => void;
140
+ handlePaste: (event: React.ClipboardEvent<HTMLElement>) => Awaitable<void>;
141
+ openFilePicker: () => void;
142
+ removeFile: (ctx: FileStateOrIDProp) => void;
143
+ updateFileState: (ctx: FileStateOrIDProp & Partial<Omit<FileState, "file" | "id" | "preview">>) => void;
144
+ };
145
+ };
146
+ interface UseDropZoneResult extends Pick<Required<UseDropZoneProps>, "disabled" | "disableInternalStateSubscription"> {
147
+ inputRef: React.RefObject<HTMLInputElement | null>;
148
+ propGetters: DropZonePropGetters;
149
+ storeApi: ReturnType<typeof createDropZoneStore>;
150
+ useDropZoneStore: typeof useDropZoneStoreContext;
151
+ }
152
+ interface UseDropZoneProps extends FileValidationSettingsAsync {
153
+ /**
154
+ * Whether or not the drop zone is disabled
155
+ */
156
+ disabled?: boolean;
157
+ /**
158
+ * Whether to disable the internal state subscription such as drag over state etc for setting things like data attributes
159
+ * - This is useful if you want to subscribe to the state yourself
160
+ * @default false
161
+ */
162
+ disableInternalStateSubscription?: boolean;
163
+ /**
164
+ * Whether to disallow preview for non-image files
165
+ * @default true
166
+ */
167
+ disablePreviewForNonImageFiles?: boolean;
168
+ /**
169
+ * Extra props to pass to various parts of the dropzone
170
+ */
171
+ extraProps?: PartProps;
172
+ /**
173
+ * Initial files to populate the drop zone
174
+ */
175
+ initialFiles?: FileMeta | FileMeta[] | null;
176
+ /**
177
+ * Whether to allow multiple files to be uploaded
178
+ */
179
+ multiple?: boolean;
180
+ /**
181
+ * Callback function to be called when internal files state changes
182
+ */
183
+ onFilesChange?: (context: Pick<DropZoneState, "fileStateArray">) => void;
184
+ /**
185
+ * Callback function to be called when new files are uploaded
186
+ */
187
+ onUpload?: (context: Pick<DropZoneState, "fileStateArray"> & {
188
+ onError: (ctx: FileStateOrIDProp & {
189
+ error: DropZoneError;
190
+ }) => void;
191
+ onProgress: (ctx: FileStateOrIDProp & {
192
+ progress: number;
193
+ }) => void;
194
+ onSuccess: (ctx: FileStateOrIDProp) => void;
195
+ }) => Awaitable<void>;
196
+ /**
197
+ * Callback function to be called on each file validation error as they occur
198
+ */
199
+ onValidationError?: FileValidationHooksAsync["onErrorEach"];
200
+ /**
201
+ * Callback function to be called once after all files have been successfully validated
202
+ */
203
+ onValidationSuccess?: FileValidationHooksAsync["onSuccessBatch"];
204
+ /**
205
+ * Whether clicking the drop zone area will open the default file picker or not
206
+ *
207
+ * @default true
208
+ */
209
+ shouldOpenFilePickerOnAreaClick?: boolean;
210
+ /**
211
+ * Custom validation function.
212
+ *
213
+ * If the function returns false, the file will be rejected
214
+ *
215
+ */
216
+ validator?: FileValidationSettingsAsync["validator"];
217
+ }
218
+ //#endregion
219
+ //#region src/components/ui/drop-zone/drop-zone-store.d.ts
220
+ type DropZoneStore = DropZoneActions & DropZoneState;
221
+ type RequiredUseDropZoneProps = { [Key in keyof Required<UseDropZoneProps>]: UseDropZoneProps[Key] | undefined };
222
+ type InitStoreValues = Omit<RequiredUseDropZoneProps, "disabled" | "disableInternalStateSubscription" | "extraProps" | "shouldOpenFilePickerOnAreaClick"> & {
223
+ inputRef: React.RefObject<HTMLInputElement | null>;
224
+ };
225
+ declare const createDropZoneStore: (initStoreValues: InitStoreValues) => _zayne_labs_toolkit_core1.StoreApi<DropZoneStore>;
226
+ //#endregion
227
+ //#region src/components/ui/drop-zone/drop-zone-context.d.ts
228
+ declare const DropZoneStoreContextProvider: (props: {
229
+ children: React.ReactNode;
230
+ store: _zayne_labs_toolkit_core1.StoreApi<DropZoneStore>;
231
+ }) => react4.FunctionComponentElement<react4.ProviderProps<_zayne_labs_toolkit_core1.StoreApi<DropZoneStore>>>, useDropZoneStoreContext: <TResult = DropZoneStore>(selector?: _zayne_labs_toolkit_type_helpers0.SelectorFn<DropZoneStore, TResult> | undefined) => TResult;
232
+ type FileItemContextType = {
233
+ fileState: FileState;
234
+ };
235
+ //#endregion
236
+ //#region src/components/ui/drop-zone/drop-zone.d.ts
237
+ type DropZoneRootProps = UseDropZoneProps & {
238
+ children: react4.ReactNode;
239
+ };
240
+ declare function DropZoneRoot(props: DropZoneRootProps): react_jsx_runtime26.JSX.Element;
241
+ type DropZoneContextProps<TSlice> = {
242
+ children: react4.ReactNode | ((context: TSlice) => react4.ReactNode);
243
+ selector?: SelectorFn<DropZoneStore, TSlice>;
244
+ };
245
+ declare function DropZoneContext<TSlice = DropZoneStore>(props: DropZoneContextProps<TSlice>): react4.ReactNode;
246
+ type DropZoneContainerProps = PartInputProps["container"] & {
247
+ asChild?: boolean;
248
+ };
249
+ declare function DropZoneContainer<TElement extends react4.ElementType = "div">(props: PolymorphicPropsStrict<TElement, DropZoneContainerProps>): react_jsx_runtime26.JSX.Element;
250
+ type DropZoneInputProps = PartInputProps["input"] & {
251
+ asChild?: boolean;
252
+ };
253
+ declare function DropZoneInput(props: DropZoneInputProps): react_jsx_runtime26.JSX.Element;
254
+ type DropZoneAreaProps<TSlice> = {
255
+ children: react4.ReactNode | ((context: TSlice) => react4.ReactNode);
256
+ classNames?: Partial<Record<Extract<keyof PartInputProps, "container" | "input">, string>>;
257
+ extraProps?: Pick<PartInputProps, "container" | "input">;
258
+ selector?: SelectorFn<DropZoneStore, TSlice>;
259
+ };
260
+ declare function DropZoneArea<TSlice = DropZoneStore>(props: DropZoneAreaProps<TSlice>): react_jsx_runtime26.JSX.Element;
261
+ type DropZoneTriggerProps = PartInputProps["trigger"] & {
262
+ asChild?: boolean;
263
+ };
264
+ declare function DropZoneTrigger(props: DropZoneTriggerProps): react_jsx_runtime26.JSX.Element;
265
+ type ListPerItemContext = Pick<DropZoneStore, "actions"> & {
266
+ array: DropZoneStore["fileStateArray"];
267
+ fileState: DropZoneStore["fileStateArray"][number];
268
+ index: number;
269
+ };
270
+ type FileListPerItemVariant = {
271
+ children: react4.ReactNode | ((context: ListPerItemContext) => react4.ReactNode);
272
+ renderMode?: "per-item";
273
+ };
274
+ type ListManualListContext = Pick<DropZoneStore, "actions" | "fileStateArray">;
275
+ type FileListManualListVariant = {
276
+ children: react4.ReactNode | ((context: ListManualListContext) => react4.ReactNode);
277
+ renderMode: "manual-list";
278
+ };
279
+ type DropZoneFileListProps = Omit<PartInputProps["fileList"], "children"> & {
280
+ asChild?: boolean;
281
+ forceMount?: boolean;
282
+ } & (FileListManualListVariant | FileListPerItemVariant);
283
+ declare function DropZoneFileList<TElement extends react4.ElementType = "ul">(props: PolymorphicPropsStrict<TElement, DropZoneFileListProps>): react_jsx_runtime26.JSX.Element;
284
+ type DropZoneFileItemProps = FileItemContextType & PartInputProps["fileItem"] & {
285
+ asChild?: boolean;
286
+ };
287
+ declare function DropZoneFileItem<TElement extends react4.ElementType = "li">(props: PolymorphicPropsStrict<TElement, DropZoneFileItemProps>): react_jsx_runtime26.JSX.Element;
288
+ type DropZoneFileItemDeleteProps = PartInputProps["fileItemDelete"] & {
289
+ asChild?: boolean;
290
+ };
291
+ declare function DropZoneFileItemDelete(props: DropZoneFileItemDeleteProps): react_jsx_runtime26.JSX.Element;
292
+ type DropZoneFileItemProgressProps = PartInputProps["fileItemProgress"] & {
293
+ asChild?: boolean;
294
+ forceMount?: boolean;
295
+ size?: number;
296
+ };
297
+ declare function DropZoneFileItemProgress<TElement extends react4.ElementType = "span">(props: PolymorphicPropsStrict<TElement, DropZoneFileItemProgressProps>): react_jsx_runtime26.JSX.Element | null;
298
+ type RenderPreviewDetails<TElement extends react4.ElementType = "svg"> = {
299
+ node?: react4.ReactNode;
300
+ } & {
301
+ props?: InferProps<TElement>;
302
+ };
303
+ type RenderPropContext = Pick<FileItemContextType, "fileState"> & {
304
+ fileExtension: string;
305
+ fileType: string;
306
+ };
307
+ type RenderPreview = (context: RenderPropContext) => {
308
+ archive?: RenderPreviewDetails;
309
+ audio?: RenderPreviewDetails;
310
+ code?: RenderPreviewDetails;
311
+ default?: RenderPreviewDetails;
312
+ executable?: RenderPreviewDetails;
313
+ image?: RenderPreviewDetails<"img">;
314
+ text?: RenderPreviewDetails;
315
+ video?: RenderPreviewDetails;
316
+ };
317
+ type DropZoneFileItemPreviewProps = Omit<PartInputProps["fileItemPreview"], "children"> & Partial<Pick<FileItemContextType, "fileState">> & {
318
+ asChild?: boolean;
319
+ children?: react4.ReactNode | ((context: RenderPropContext) => react4.ReactNode);
320
+ renderPreview?: boolean | RenderPreview;
321
+ };
322
+ declare function DropZoneFileItemPreview<TElement extends react4.ElementType>(props: PolymorphicPropsStrict<TElement, DropZoneFileItemPreviewProps>): react_jsx_runtime26.JSX.Element | null;
323
+ type DropZoneFileItemMetadataProps = Omit<PartInputProps["fileItemMetadata"], "children"> & Partial<Pick<FileItemContextType, "fileState">> & {
324
+ asChild?: boolean;
325
+ children?: react4.ReactNode | ((context: Pick<FileItemContextType, "fileState">) => react4.ReactNode);
326
+ classNames?: {
327
+ name?: string;
328
+ size?: string;
329
+ };
330
+ size?: "default" | "sm";
331
+ };
332
+ declare function DropZoneFileItemMetadata(props: DropZoneFileItemMetadataProps): react_jsx_runtime26.JSX.Element | null;
333
+ type DropZoneFileClearProps = PartInputProps["fileItemClear"] & {
334
+ asChild?: boolean;
335
+ forceMount?: boolean;
336
+ };
337
+ declare function DropZoneFileClear(props: DropZoneFileClearProps): react_jsx_runtime26.JSX.Element | null;
338
+ declare namespace drop_zone_parts_d_exports {
339
+ export { DropZoneArea as Area, DropZoneContainer as Container, DropZoneContext as Context, DropZoneFileClear as FileClear, DropZoneFileItem as FileItem, DropZoneFileItemDelete as FileItemDelete, DropZoneFileItemMetadata as FileItemMetadata, DropZoneFileItemPreview as FileItemPreview, DropZoneFileItemProgress as FileItemProgress, DropZoneFileList as FileList, DropZoneInput as Input, DropZoneRoot as Root, DropZoneTrigger as Trigger };
340
+ }
341
+ //#endregion
342
+ //#region src/components/ui/drop-zone/use-drop-zone.d.ts
343
+ declare const useDropZone: (props?: UseDropZoneProps) => UseDropZoneResult;
344
+ //#endregion
345
+ export { drop_zone_parts_d_exports as DropZone, DropZoneArea, DropZoneContainer, DropZoneContext, DropZoneError, DropZoneFileClear, DropZoneFileItem, DropZoneFileItemDelete, DropZoneFileItemMetadata, DropZoneFileItemPreview, DropZoneFileItemProgress, DropZoneFileList, DropZoneInput, DropZoneRoot, DropZoneTrigger, useDropZone, useDropZoneStoreContext };
346
+ //# sourceMappingURL=index.d.ts.map