@zayne-labs/ui-react 0.11.3 → 0.11.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{esm → components}/common/await/index.d.ts +4 -4
- package/dist/{esm → components}/common/await/index.js +18 -9
- package/dist/components/common/await/index.js.map +1 -0
- package/dist/components/common/error-boundary/index.d.ts +2 -0
- package/dist/{esm → components}/common/error-boundary/index.js +1 -1
- package/dist/components/common/presence/index.js +3 -0
- package/dist/{esm → components}/common/show/index.js +1 -1
- package/dist/components/common/suspense-with-boundary/index.d.ts +2 -0
- package/dist/{esm → components}/common/suspense-with-boundary/index.js +5 -6
- package/dist/components/common/suspense-with-boundary/index.js.map +1 -0
- package/dist/{esm/error-boundary-C4btQhu_.js → components/error-boundary-BOZ3EvMt.js} +33 -31
- package/dist/components/error-boundary-BOZ3EvMt.js.map +1 -0
- package/dist/{esm/index-DC9fblW0.d.ts → components/index-BmD5l0L7.d.ts} +9 -11
- package/dist/{esm/index-D_Ntazyt.d.ts → components/index-dmMYkH2c.d.ts} +4 -7
- package/dist/{esm/presence-CHd9s3IS.js → components/presence-DkWhm7xu.js} +3 -3
- package/dist/{esm/presence-CHd9s3IS.js.map → components/presence-DkWhm7xu.js.map} +1 -1
- package/dist/{esm/show-BzfAw7y3.js → components/show-CMxdpPiN.js} +2 -2
- package/dist/components/show-CMxdpPiN.js.map +1 -0
- package/dist/{esm → components}/ui/carousel/index.d.ts +9 -12
- package/dist/{esm → components}/ui/carousel/index.js +58 -65
- package/dist/components/ui/carousel/index.js.map +1 -0
- package/dist/{esm → components}/ui/drag-scroll/index.d.ts +1 -9
- package/dist/{esm → components}/ui/drag-scroll/index.js +15 -27
- package/dist/components/ui/drag-scroll/index.js.map +1 -0
- package/dist/{esm → components}/ui/drop-zone/index.d.ts +21 -17
- package/dist/{esm → components}/ui/drop-zone/index.js +54 -23
- package/dist/components/ui/drop-zone/index.js.map +1 -0
- package/dist/{esm → components}/ui/form/index.js +11 -8
- package/dist/{esm → components}/ui/form/index.js.map +1 -1
- package/dist/style.css +22 -50
- package/package.json +8 -8
- package/dist/esm/common/await/index.js.map +0 -1
- package/dist/esm/common/error-boundary/index.d.ts +0 -2
- package/dist/esm/common/presence/index.js +0 -3
- package/dist/esm/common/suspense-with-boundary/index.d.ts +0 -2
- package/dist/esm/common/suspense-with-boundary/index.js.map +0 -1
- package/dist/esm/error-boundary-C4btQhu_.js.map +0 -1
- package/dist/esm/show-BzfAw7y3.js.map +0 -1
- package/dist/esm/ui/carousel/index.js.map +0 -1
- package/dist/esm/ui/drag-scroll/index.js.map +0 -1
- package/dist/esm/ui/drop-zone/index.js.map +0 -1
- /package/dist/{esm → components}/chunk-pbuEa-1d.js +0 -0
- /package/dist/{esm → components}/cn-jNZfGhrk.js +0 -0
- /package/dist/{esm → components}/cn-jNZfGhrk.js.map +0 -0
- /package/dist/{esm → components}/common/client-gate/index.d.ts +0 -0
- /package/dist/{esm → components}/common/client-gate/index.js +0 -0
- /package/dist/{esm → components}/common/client-gate/index.js.map +0 -0
- /package/dist/{esm → components}/common/for/index.d.ts +0 -0
- /package/dist/{esm → components}/common/for/index.js +0 -0
- /package/dist/{esm → components}/common/presence/index.d.ts +0 -0
- /package/dist/{esm → components}/common/show/index.d.ts +0 -0
- /package/dist/{esm → components}/common/slot/index.d.ts +0 -0
- /package/dist/{esm → components}/common/slot/index.js +0 -0
- /package/dist/{esm → components}/common/switch/index.d.ts +0 -0
- /package/dist/{esm → components}/common/switch/index.js +0 -0
- /package/dist/{esm → components}/common/teleport/index.d.ts +0 -0
- /package/dist/{esm → components}/common/teleport/index.js +0 -0
- /package/dist/{esm → components}/common/teleport/index.js.map +0 -0
- /package/dist/{esm → components}/for-DGTMIS0w.js +0 -0
- /package/dist/{esm → components}/for-DGTMIS0w.js.map +0 -0
- /package/dist/{esm → components}/slot-DuwoiC2C.js +0 -0
- /package/dist/{esm → components}/slot-DuwoiC2C.js.map +0 -0
- /package/dist/{esm → components}/switch-Dwy5Gzsb.js +0 -0
- /package/dist/{esm → components}/switch-Dwy5Gzsb.js.map +0 -0
- /package/dist/{esm → components}/ui/card/index.d.ts +0 -0
- /package/dist/{esm → components}/ui/card/index.js +0 -0
- /package/dist/{esm → components}/ui/card/index.js.map +0 -0
- /package/dist/{esm → components}/ui/form/index.d.ts +0 -0
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { t as __exportAll } from "../../chunk-pbuEa-1d.js";
|
|
3
3
|
import { n as For } from "../../for-DGTMIS0w.js";
|
|
4
|
-
import { i as ShowRoot, n as ShowContent, r as ShowFallback } from "../../show-
|
|
4
|
+
import { i as ShowRoot, n as ShowContent, r as ShowFallback } from "../../show-CMxdpPiN.js";
|
|
5
5
|
import { t as cnMerge } from "../../cn-jNZfGhrk.js";
|
|
6
6
|
import { isFunction } from "@zayne-labs/toolkit-type-helpers";
|
|
7
7
|
import { useMemo, useState } from "react";
|
|
8
8
|
import { useAnimationInterval, useCallbackRef, useStore } from "@zayne-labs/toolkit-react";
|
|
9
9
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
10
|
-
import { createStore } from "@zayne-labs/toolkit-core";
|
|
10
|
+
import { createStore, dataAttr } from "@zayne-labs/toolkit-core";
|
|
11
11
|
import { createReactStoreContext } from "@zayne-labs/toolkit-react/zustand";
|
|
12
12
|
//#region src/components/ui/carousel/carousel-store-context.ts
|
|
13
13
|
const [CarouselStoreContextProvider, useCarouselStoreContext] = createReactStoreContext({
|
|
@@ -116,14 +116,17 @@ function CarouselRoot(props) {
|
|
|
116
116
|
return /* @__PURE__ */ jsx(CarouselStoreContextProvider, {
|
|
117
117
|
store: carouselStore,
|
|
118
118
|
children: /* @__PURE__ */ jsx(Element, {
|
|
119
|
+
"data-slot": "carousel-root",
|
|
119
120
|
"data-scope": "carousel",
|
|
120
|
-
"data-part": "
|
|
121
|
-
|
|
122
|
-
className: cnMerge("relative select-none", classNames?.base),
|
|
121
|
+
"data-part": "root",
|
|
122
|
+
className: cnMerge("isolate", classNames?.base),
|
|
123
123
|
onMouseEnter: pauseAutoSlide,
|
|
124
124
|
onMouseLeave: resumeAutoSlide,
|
|
125
125
|
children: /* @__PURE__ */ jsx("div", {
|
|
126
|
-
|
|
126
|
+
"data-scope": "carousel",
|
|
127
|
+
"data-part": "content",
|
|
128
|
+
"data-slot": "carousel-content",
|
|
129
|
+
className: cnMerge("relative scrollbar-hidden size-full overflow-x-scroll", classNames?.content),
|
|
127
130
|
children
|
|
128
131
|
})
|
|
129
132
|
})
|
|
@@ -133,11 +136,11 @@ function CarouselButton(props) {
|
|
|
133
136
|
const { classNames, icon, variant } = props;
|
|
134
137
|
const { goToNextSlide, goToPreviousSlide } = useCarouselStoreContext((state) => state.actions);
|
|
135
138
|
return /* @__PURE__ */ jsx("button", {
|
|
139
|
+
"data-slot": `carousel-${variant}-button`,
|
|
136
140
|
"data-scope": "carousel",
|
|
137
141
|
"data-part": "button",
|
|
138
|
-
"data-slot": "carousel-button",
|
|
139
142
|
type: "button",
|
|
140
|
-
className: cnMerge("z-
|
|
143
|
+
className: cnMerge("absolute inset-y-0 z-20 flex items-center justify-center", variant === "prev" && "left-0", variant === "next" && "right-0", classNames?.base),
|
|
141
144
|
onClick: variant === "prev" ? goToPreviousSlide : goToNextSlide,
|
|
142
145
|
children: /* @__PURE__ */ jsx("span", {
|
|
143
146
|
className: cnMerge("transition-transform active:scale-[1.06]", classNames?.iconContainer),
|
|
@@ -147,43 +150,31 @@ function CarouselButton(props) {
|
|
|
147
150
|
}
|
|
148
151
|
function CarouselControls(props) {
|
|
149
152
|
const { classNames, icon } = props;
|
|
150
|
-
return /* @__PURE__ */
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
iconContainer: classNames?.iconContainer
|
|
176
|
-
},
|
|
177
|
-
icon: icon?.prev
|
|
178
|
-
}), /* @__PURE__ */ jsx(CarouselButton, {
|
|
179
|
-
variant: "next",
|
|
180
|
-
classNames: {
|
|
181
|
-
defaultIcon: classNames?.defaultIcon,
|
|
182
|
-
iconContainer: classNames?.iconContainer
|
|
183
|
-
},
|
|
184
|
-
icon: icon?.next
|
|
185
|
-
})] })]
|
|
186
|
-
})
|
|
153
|
+
return /* @__PURE__ */ jsxs(ShowRoot, {
|
|
154
|
+
when: icon?.iconType,
|
|
155
|
+
children: [/* @__PURE__ */ jsxs(ShowContent, { children: [/* @__PURE__ */ jsx(CarouselButton, {
|
|
156
|
+
variant: "prev",
|
|
157
|
+
classNames: {
|
|
158
|
+
...classNames,
|
|
159
|
+
iconContainer: cnMerge(icon?.iconType === "nextIcon" && "rotate-180", classNames?.iconContainer)
|
|
160
|
+
},
|
|
161
|
+
icon: icon?.icon
|
|
162
|
+
}), /* @__PURE__ */ jsx(CarouselButton, {
|
|
163
|
+
variant: "next",
|
|
164
|
+
classNames: {
|
|
165
|
+
...classNames,
|
|
166
|
+
iconContainer: cnMerge(icon?.iconType === "prevIcon" && "rotate-180", classNames?.iconContainer)
|
|
167
|
+
},
|
|
168
|
+
icon: icon?.icon
|
|
169
|
+
})] }), /* @__PURE__ */ jsxs(ShowFallback, { children: [/* @__PURE__ */ jsx(CarouselButton, {
|
|
170
|
+
variant: "prev",
|
|
171
|
+
classNames,
|
|
172
|
+
icon: icon?.prev
|
|
173
|
+
}), /* @__PURE__ */ jsx(CarouselButton, {
|
|
174
|
+
variant: "next",
|
|
175
|
+
classNames,
|
|
176
|
+
icon: icon?.next
|
|
177
|
+
})] })]
|
|
187
178
|
});
|
|
188
179
|
}
|
|
189
180
|
function CarouselItemList(props) {
|
|
@@ -191,10 +182,10 @@ function CarouselItemList(props) {
|
|
|
191
182
|
const currentSlide = useCarouselStoreContext((state) => state.currentSlide);
|
|
192
183
|
const images = useCarouselStoreContext((state) => each ?? state.images);
|
|
193
184
|
return /* @__PURE__ */ jsx("ul", {
|
|
185
|
+
"data-slot": "carousel-item-list",
|
|
194
186
|
"data-scope": "carousel",
|
|
195
187
|
"data-part": "item-list",
|
|
196
|
-
|
|
197
|
-
className: cnMerge(`flex w-full shrink-0 transform-[translate3d(var(--translate-distance),0,0)] snap-center
|
|
188
|
+
className: cnMerge(`flex size-full transform-[translate3d(var(--translate-distance),0,0)] snap-center
|
|
198
189
|
transition-transform duration-800`, className),
|
|
199
190
|
style: { "--translate-distance": `-${currentSlide * 100}%` },
|
|
200
191
|
children: isFunction(children) ? /* @__PURE__ */ jsx(For, {
|
|
@@ -208,22 +199,24 @@ function CarouselItemList(props) {
|
|
|
208
199
|
});
|
|
209
200
|
}
|
|
210
201
|
function CarouselItem(props) {
|
|
211
|
-
const { children, className, ...restOfProps } = props;
|
|
202
|
+
const { children, className, currentIndex, ...restOfProps } = props;
|
|
203
|
+
const isActive = useCarouselStoreContext((state) => state.currentSlide) === currentIndex;
|
|
212
204
|
return /* @__PURE__ */ jsx("li", {
|
|
205
|
+
"data-slot": "carousel-item",
|
|
213
206
|
"data-scope": "carousel",
|
|
214
207
|
"data-part": "item",
|
|
215
|
-
"data-
|
|
216
|
-
className: cnMerge("
|
|
208
|
+
"data-active": dataAttr(isActive),
|
|
209
|
+
className: cnMerge("relative size-full shrink-0 snap-center overflow-hidden", className),
|
|
217
210
|
...restOfProps,
|
|
218
211
|
children
|
|
219
212
|
});
|
|
220
213
|
}
|
|
221
214
|
function CarouselCaption(props) {
|
|
222
|
-
const { as:
|
|
223
|
-
return /* @__PURE__ */ jsx(
|
|
215
|
+
const { as: Element = "div", children, className } = props;
|
|
216
|
+
return /* @__PURE__ */ jsx(Element, {
|
|
217
|
+
"data-slot": "carousel-caption",
|
|
224
218
|
"data-scope": "carousel",
|
|
225
219
|
"data-part": "caption",
|
|
226
|
-
"data-slot": "carousel-caption",
|
|
227
220
|
className: cnMerge("absolute z-10", className),
|
|
228
221
|
children
|
|
229
222
|
});
|
|
@@ -231,11 +224,11 @@ function CarouselCaption(props) {
|
|
|
231
224
|
function CarouselIndicatorList(props) {
|
|
232
225
|
const { children, className, each } = props;
|
|
233
226
|
const images = useCarouselStoreContext((state) => each ?? state.images);
|
|
234
|
-
return /* @__PURE__ */ jsx("
|
|
227
|
+
return /* @__PURE__ */ jsx("div", {
|
|
228
|
+
"data-slot": "carousel-indicator-list",
|
|
235
229
|
"data-scope": "carousel",
|
|
236
230
|
"data-part": "indicator-list",
|
|
237
|
-
|
|
238
|
-
className: cnMerge("absolute bottom-[25px] z-2 flex w-full items-center justify-center gap-[15px]", className),
|
|
231
|
+
className: cnMerge("absolute bottom-6 z-2 flex w-full items-center justify-center gap-4", className),
|
|
239
232
|
children: isFunction(children) ? /* @__PURE__ */ jsx(For, {
|
|
240
233
|
each: images,
|
|
241
234
|
renderItem: (image, index, array) => children({
|
|
@@ -247,18 +240,18 @@ function CarouselIndicatorList(props) {
|
|
|
247
240
|
});
|
|
248
241
|
}
|
|
249
242
|
function CarouselIndicator(props) {
|
|
250
|
-
const { classNames, currentIndex } = props;
|
|
243
|
+
const { className, classNames, currentIndex, ...restOfProps } = props;
|
|
251
244
|
const { actions: { goToSlide }, currentSlide } = useCarouselStoreContext((state) => state);
|
|
252
|
-
|
|
245
|
+
const isActive = currentSlide === currentIndex;
|
|
246
|
+
return /* @__PURE__ */ jsx("button", {
|
|
247
|
+
"data-slot": "carousel-indicator",
|
|
253
248
|
"data-scope": "carousel",
|
|
254
249
|
"data-part": "indicator",
|
|
255
|
-
"data-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
className: cnMerge("size-1.5 rounded-[50%]", classNames?.base, currentIndex === currentSlide && ["w-[35px] rounded-[5px]", classNames?.isActive])
|
|
261
|
-
})
|
|
250
|
+
"data-active": dataAttr(isActive),
|
|
251
|
+
type: "button",
|
|
252
|
+
onClick: () => goToSlide(currentIndex),
|
|
253
|
+
className: cnMerge("size-1.5 rounded-[50%]", className, classNames?.base, isActive && ["w-9 rounded-[6px]", classNames?.isActive]),
|
|
254
|
+
...restOfProps
|
|
262
255
|
});
|
|
263
256
|
}
|
|
264
257
|
//#endregion
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["Show.Root","Show.Content","Show.Fallback"],"sources":["../../../../src/components/ui/carousel/carousel-store-context.ts","../../../../src/components/ui/carousel/icons.tsx","../../../../src/components/ui/carousel/useCarouselOptions.ts","../../../../src/components/ui/carousel/carousel.tsx","../../../../src/components/ui/carousel/carousel-parts.ts"],"sourcesContent":["import { createStore } from \"@zayne-labs/toolkit-core\";\nimport { useCallbackRef, useStore } from \"@zayne-labs/toolkit-react\";\nimport { createReactStoreContext } from \"@zayne-labs/toolkit-react/zustand\";\nimport type { PrettyOmit } from \"@zayne-labs/toolkit-type-helpers\";\nimport { useMemo } from \"react\";\nimport type { CarouselRootProps, CarouselStore, ImagesType } from \"./types\";\n\nconst [CarouselStoreContextProvider, useCarouselStoreContext] = createReactStoreContext<CarouselStore>({\n\thookName: \"useCarouselStore\",\n\tname: \"CarouselStoreContext\",\n\tproviderName: \"CarouselRoot\",\n});\n\n// CarouselStore Creation\nconst createCarouselStore = <TImages extends ImagesType>(\n\tstoreValues: PrettyOmit<CarouselRootProps<TImages>, \"children\">\n) => {\n\tconst { images, onSlideBtnClick } = storeValues;\n\n\tconst carouselStore = createStore<CarouselStore<TImages>>((set, get) => ({\n\t\tcurrentSlide: 0,\n\t\timages,\n\t\tmaxSlide: images.length - 1,\n\n\t\t/* eslint-disable perfectionist/sort-objects -- actions should be last */\n\t\tactions: {\n\t\t\t/* eslint-enable perfectionist/sort-objects -- actions should be last */\n\n\t\t\tgoToNextSlide: () => {\n\t\t\t\tconst { currentSlide, maxSlide } = get();\n\t\t\t\tconst { goToSlide } = get().actions;\n\n\t\t\t\tif (currentSlide === maxSlide) {\n\t\t\t\t\tgoToSlide(0);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tgoToSlide(currentSlide + 1);\n\t\t\t},\n\n\t\t\tgoToPreviousSlide: () => {\n\t\t\t\tconst { currentSlide, maxSlide } = get();\n\t\t\t\tconst { goToSlide } = get().actions;\n\n\t\t\t\tif (currentSlide === 0) {\n\t\t\t\t\tgoToSlide(maxSlide);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tgoToSlide(currentSlide - 1);\n\t\t\t},\n\n\t\t\tgoToSlide: (newValue) => {\n\t\t\t\tonSlideBtnClick?.();\n\n\t\t\t\tset({ currentSlide: newValue });\n\t\t\t},\n\t\t},\n\t}));\n\n\treturn carouselStore;\n};\n\nconst useCarousel = <TImages extends ImagesType>(props: Omit<CarouselRootProps<TImages>, \"children\">) => {\n\tconst { images, onSlideBtnClick } = props;\n\n\tconst savedOnSlideBtnClick = useCallbackRef(onSlideBtnClick);\n\n\tconst carouselStore = useMemo(\n\t\t() => createCarouselStore({ images, onSlideBtnClick: savedOnSlideBtnClick }),\n\t\t[images, savedOnSlideBtnClick]\n\t);\n\n\t// eslint-disable-next-line react-x/component-hook-factories -- Ignore\n\tconst useCarouselStore: typeof useCarouselStoreContext = (selector) => {\n\t\t// eslint-disable-next-line react-hooks/hooks -- Ignore\n\t\treturn useStore(carouselStore, selector);\n\t};\n\n\tconst savedUseCarouselStore = useCallbackRef(useCarouselStore);\n\n\treturn useMemo(\n\t\t() => ({ carouselStore, useCarouselStore: savedUseCarouselStore }),\n\t\t[carouselStore, savedUseCarouselStore]\n\t);\n};\n\nexport { CarouselStoreContextProvider, useCarousel, useCarouselStoreContext };\n","export const ChevronLeftIcon = (props: React.SVGProps<SVGSVGElement>) => (\n\t<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"1em\" height=\"1em\" viewBox=\"0 0 24 24\" {...props}>\n\t\t<g fill=\"none\" stroke=\"currentColor\" strokeLinecap=\"round\" strokeLinejoin=\"round\" strokeWidth=\"2\">\n\t\t\t<circle cx=\"12\" cy=\"12\" r=\"10\" />\n\t\t\t<path d=\"m14 16l-4-4l4-4\" />\n\t\t</g>\n\t</svg>\n);\n","import { useAnimationInterval, useCallbackRef } from \"@zayne-labs/toolkit-react\";\nimport { useState } from \"react\";\nimport type { CarouselStore } from \"./types\";\n\ntype CarouselOptions = {\n\tactions: CarouselStore[\"actions\"];\n\tautoSlideInterval?: number;\n\thasAutoSlide?: boolean;\n\tshouldPauseOnHover?: boolean;\n};\n\nconst useCarouselOptions = (options: CarouselOptions) => {\n\tconst { actions, autoSlideInterval = 5000, hasAutoSlide = false, shouldPauseOnHover = false } = options;\n\n\tconst [isPaused, setIsPaused] = useState(false);\n\n\tconst shouldAutoSlide = hasAutoSlide && !isPaused;\n\n\tuseAnimationInterval({\n\t\tintervalDuration: shouldAutoSlide ? autoSlideInterval : null,\n\t\tonAnimation: actions.goToNextSlide,\n\t});\n\n\tconst pauseAutoSlide = useCallbackRef(() => shouldPauseOnHover && setIsPaused(true));\n\n\tconst resumeAutoSlide = useCallbackRef(() => shouldPauseOnHover && setIsPaused(false));\n\n\treturn { pauseAutoSlide, resumeAutoSlide };\n};\n\nexport { useCarouselOptions };\n","\"use client\";\n\nimport { dataAttr } from \"@zayne-labs/toolkit-core\";\nimport type { CssWithCustomProperties, PolymorphicPropsStrict } from \"@zayne-labs/toolkit-react/utils\";\nimport { isFunction } from \"@zayne-labs/toolkit-type-helpers\";\nimport { For } from \"@/components/common/for\";\nimport { Show } from \"@/components/common/show\";\nimport { cnMerge } from \"@/lib/utils/cn\";\nimport {\n\tCarouselStoreContextProvider,\n\tuseCarousel,\n\tuseCarouselStoreContext,\n} from \"./carousel-store-context\";\nimport { ChevronLeftIcon } from \"./icons\";\nimport type {\n\tCarouselButtonsProps,\n\tCarouselControlProps,\n\tCarouselIndicatorProps,\n\tCarouselItemProps,\n\tCarouselRootProps,\n\tCarouselWrapperProps,\n\tImagesType,\n\tOtherCarouselProps,\n} from \"./types\";\nimport { useCarouselOptions } from \"./useCarouselOptions\";\n\n// TODO - Add dragging and swiping support\nexport function CarouselRoot<TImages extends ImagesType, TElement extends React.ElementType = \"div\">(\n\tprops: PolymorphicPropsStrict<TElement, CarouselRootProps<TImages>>\n) {\n\tconst {\n\t\tas: Element = \"div\",\n\t\tautoSlideInterval,\n\t\tchildren,\n\t\tclassNames,\n\t\thasAutoSlide,\n\t\timages,\n\t\tonSlideBtnClick,\n\t\tshouldPauseOnHover,\n\t} = props;\n\n\tconst { carouselStore } = useCarousel({ images, onSlideBtnClick });\n\n\tconst actions = carouselStore.getState().actions;\n\n\tconst { pauseAutoSlide, resumeAutoSlide } = useCarouselOptions({\n\t\tactions,\n\t\tautoSlideInterval,\n\t\thasAutoSlide,\n\t\tshouldPauseOnHover,\n\t});\n\n\treturn (\n\t\t<CarouselStoreContextProvider store={carouselStore}>\n\t\t\t<Element\n\t\t\t\tdata-slot=\"carousel-root\"\n\t\t\t\tdata-scope=\"carousel\"\n\t\t\t\tdata-part=\"root\"\n\t\t\t\tclassName={cnMerge(\"isolate\", classNames?.base)}\n\t\t\t\tonMouseEnter={pauseAutoSlide}\n\t\t\t\tonMouseLeave={resumeAutoSlide}\n\t\t\t>\n\t\t\t\t<div\n\t\t\t\t\tdata-scope=\"carousel\"\n\t\t\t\t\tdata-part=\"content\"\n\t\t\t\t\tdata-slot=\"carousel-content\"\n\t\t\t\t\tclassName={cnMerge(\n\t\t\t\t\t\t\"relative scrollbar-hidden size-full overflow-x-scroll\",\n\t\t\t\t\t\tclassNames?.content\n\t\t\t\t\t)}\n\t\t\t\t>\n\t\t\t\t\t{children}\n\t\t\t\t</div>\n\t\t\t</Element>\n\t\t</CarouselStoreContextProvider>\n\t);\n}\n\nexport function CarouselButton(props: CarouselButtonsProps) {\n\tconst { classNames, icon, variant } = props;\n\n\tconst { goToNextSlide, goToPreviousSlide } = useCarouselStoreContext((state) => state.actions);\n\n\treturn (\n\t\t<button\n\t\t\tdata-slot={`carousel-${variant}-button`}\n\t\t\tdata-scope=\"carousel\"\n\t\t\tdata-part=\"button\"\n\t\t\ttype=\"button\"\n\t\t\tclassName={cnMerge(\n\t\t\t\t\"absolute inset-y-0 z-20 flex items-center justify-center\",\n\t\t\t\tvariant === \"prev\" && \"left-0\",\n\t\t\t\tvariant === \"next\" && \"right-0\",\n\t\t\t\tclassNames?.base\n\t\t\t)}\n\t\t\tonClick={variant === \"prev\" ? goToPreviousSlide : goToNextSlide}\n\t\t>\n\t\t\t<span className={cnMerge(\"transition-transform active:scale-[1.06]\", classNames?.iconContainer)}>\n\t\t\t\t{icon ?? (\n\t\t\t\t\t<ChevronLeftIcon\n\t\t\t\t\t\tclassName={cnMerge(variant === \"next\" && \"rotate-180\", classNames?.defaultIcon)}\n\t\t\t\t\t/>\n\t\t\t\t)}\n\t\t\t</span>\n\t\t</button>\n\t);\n}\n\nexport function CarouselControls(props: CarouselControlProps) {\n\tconst { classNames, icon } = props;\n\n\treturn (\n\t\t<Show.Root when={icon?.iconType}>\n\t\t\t<Show.Content>\n\t\t\t\t<CarouselButton\n\t\t\t\t\tvariant=\"prev\"\n\t\t\t\t\tclassNames={{\n\t\t\t\t\t\t...classNames,\n\t\t\t\t\t\ticonContainer: cnMerge(\n\t\t\t\t\t\t\ticon?.iconType === \"nextIcon\" && \"rotate-180\",\n\t\t\t\t\t\t\tclassNames?.iconContainer\n\t\t\t\t\t\t),\n\t\t\t\t\t}}\n\t\t\t\t\ticon={icon?.icon}\n\t\t\t\t/>\n\n\t\t\t\t<CarouselButton\n\t\t\t\t\tvariant=\"next\"\n\t\t\t\t\tclassNames={{\n\t\t\t\t\t\t...classNames,\n\t\t\t\t\t\ticonContainer: cnMerge(\n\t\t\t\t\t\t\ticon?.iconType === \"prevIcon\" && \"rotate-180\",\n\t\t\t\t\t\t\tclassNames?.iconContainer\n\t\t\t\t\t\t),\n\t\t\t\t\t}}\n\t\t\t\t\ticon={icon?.icon}\n\t\t\t\t/>\n\t\t\t</Show.Content>\n\n\t\t\t<Show.Fallback>\n\t\t\t\t<CarouselButton variant=\"prev\" classNames={classNames} icon={icon?.prev} />\n\n\t\t\t\t<CarouselButton variant=\"next\" classNames={classNames} icon={icon?.next} />\n\t\t\t</Show.Fallback>\n\t\t</Show.Root>\n\t);\n}\n\nexport function CarouselItemList<TArray extends unknown[]>(props: CarouselWrapperProps<TArray[number]>) {\n\tconst { children, className, each } = props;\n\n\tconst currentSlide = useCarouselStoreContext((state) => state.currentSlide);\n\tconst images = useCarouselStoreContext((state) => each ?? (state.images as TArray));\n\n\treturn (\n\t\t<ul\n\t\t\tdata-slot=\"carousel-item-list\"\n\t\t\tdata-scope=\"carousel\"\n\t\t\tdata-part=\"item-list\"\n\t\t\tclassName={cnMerge(\n\t\t\t\t`flex size-full transform-[translate3d(var(--translate-distance),0,0)] snap-center\n\t\t\t\ttransition-transform duration-800`,\n\t\t\t\tclassName\n\t\t\t)}\n\t\t\tstyle={\n\t\t\t\t{\n\t\t\t\t\t\"--translate-distance\": `-${currentSlide * 100}%`,\n\t\t\t\t} satisfies CssWithCustomProperties as CssWithCustomProperties\n\t\t\t}\n\t\t>\n\t\t\t{isFunction(children) ?\n\t\t\t\t<For each={images} renderItem={(image, index, array) => children({ array, image, index })} />\n\t\t\t:\tchildren}\n\t\t</ul>\n\t);\n}\n\nexport function CarouselItem(props: CarouselItemProps) {\n\tconst { children, className, currentIndex, ...restOfProps } = props;\n\n\tconst currentSlide = useCarouselStoreContext((state) => state.currentSlide);\n\n\tconst isActive = currentSlide === currentIndex;\n\n\treturn (\n\t\t<li\n\t\t\tdata-slot=\"carousel-item\"\n\t\t\tdata-scope=\"carousel\"\n\t\t\tdata-part=\"item\"\n\t\t\tdata-active={dataAttr(isActive)}\n\t\t\tclassName={cnMerge(\"relative size-full shrink-0 snap-center overflow-hidden\", className)}\n\t\t\t{...restOfProps}\n\t\t>\n\t\t\t{children}\n\t\t</li>\n\t);\n}\n\nexport function CarouselCaption<TElement extends React.ElementType = \"div\">(\n\tprops: PolymorphicPropsStrict<TElement, OtherCarouselProps>\n) {\n\tconst { as: Element = \"div\", children, className } = props;\n\n\treturn (\n\t\t<Element\n\t\t\tdata-slot=\"carousel-caption\"\n\t\t\tdata-scope=\"carousel\"\n\t\t\tdata-part=\"caption\"\n\t\t\tclassName={cnMerge(\"absolute z-10\", className)}\n\t\t>\n\t\t\t{children}\n\t\t</Element>\n\t);\n}\n\nexport function CarouselIndicatorList<TArray extends unknown[]>(\n\tprops: CarouselWrapperProps<TArray[number]>\n) {\n\tconst { children, className, each } = props;\n\n\tconst images = useCarouselStoreContext((state) => each ?? (state.images as TArray));\n\n\treturn (\n\t\t<div\n\t\t\tdata-slot=\"carousel-indicator-list\"\n\t\t\tdata-scope=\"carousel\"\n\t\t\tdata-part=\"indicator-list\"\n\t\t\tclassName={cnMerge(\n\t\t\t\t\"absolute bottom-6 z-2 flex w-full items-center justify-center gap-4\",\n\t\t\t\tclassName\n\t\t\t)}\n\t\t>\n\t\t\t{isFunction(children) ?\n\t\t\t\t<For each={images} renderItem={(image, index, array) => children({ array, image, index })} />\n\t\t\t:\tchildren}\n\t\t</div>\n\t);\n}\n\nexport function CarouselIndicator(props: CarouselIndicatorProps) {\n\tconst { className, classNames, currentIndex, ...restOfProps } = props;\n\n\tconst {\n\t\tactions: { goToSlide },\n\t\tcurrentSlide,\n\t} = useCarouselStoreContext((state) => state);\n\n\tconst isActive = currentSlide === currentIndex;\n\n\treturn (\n\t\t<button\n\t\t\tdata-slot=\"carousel-indicator\"\n\t\t\tdata-scope=\"carousel\"\n\t\t\tdata-part=\"indicator\"\n\t\t\tdata-active={dataAttr(isActive)}\n\t\t\ttype=\"button\"\n\t\t\tonClick={() => goToSlide(currentIndex)}\n\t\t\tclassName={cnMerge(\n\t\t\t\t\"size-1.5 rounded-[50%]\",\n\t\t\t\tclassName,\n\t\t\t\tclassNames?.base,\n\t\t\t\tisActive && [\"w-9 rounded-[6px]\", classNames?.isActive]\n\t\t\t)}\n\t\t\t{...restOfProps}\n\t\t/>\n\t);\n}\n","export {\n\tCarouselButton as Button,\n\tCarouselCaption as Caption,\n\tCarouselControls as Controls,\n\tCarouselIndicator as Indicator,\n\tCarouselIndicatorList as IndicatorList,\n\tCarouselItem as Item,\n\tCarouselItemList as ItemList,\n\tCarouselRoot as Root,\n} from \"./carousel\";\n"],"mappings":";;;;;;;;;;;;AAOA,MAAM,CAAC,8BAA8B,2BAA2B,wBAAuC;CACtG,UAAU;CACV,MAAM;CACN,cAAc;CACd,CAAC;AAGF,MAAM,uBACL,gBACI;CACJ,MAAM,EAAE,QAAQ,oBAAoB;AA2CpC,QAzCsB,aAAqC,KAAK,SAAS;EACxE,cAAc;EACd;EACA,UAAU,OAAO,SAAS;EAG1B,SAAS;GAGR,qBAAqB;IACpB,MAAM,EAAE,cAAc,aAAa,KAAK;IACxC,MAAM,EAAE,cAAc,KAAK,CAAC;AAE5B,QAAI,iBAAiB,UAAU;AAC9B,eAAU,EAAE;AACZ;;AAGD,cAAU,eAAe,EAAE;;GAG5B,yBAAyB;IACxB,MAAM,EAAE,cAAc,aAAa,KAAK;IACxC,MAAM,EAAE,cAAc,KAAK,CAAC;AAE5B,QAAI,iBAAiB,GAAG;AACvB,eAAU,SAAS;AACnB;;AAGD,cAAU,eAAe,EAAE;;GAG5B,YAAY,aAAa;AACxB,uBAAmB;AAEnB,QAAI,EAAE,cAAc,UAAU,CAAC;;GAEhC;EACD,EAAE;;AAKJ,MAAM,eAA2C,UAAwD;CACxG,MAAM,EAAE,QAAQ,oBAAoB;CAEpC,MAAM,uBAAuB,eAAe,gBAAgB;CAE5D,MAAM,gBAAgB,cACf,oBAAoB;EAAE;EAAQ,iBAAiB;EAAsB,CAAC,EAC5E,CAAC,QAAQ,qBAAqB,CAC9B;CAGD,MAAM,oBAAoD,aAAa;AAEtE,SAAO,SAAS,eAAe,SAAS;;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AAA;;AAIR,SAAgB,kBAAkB,OAA+B;CAChE,MAAM,EAAE,WAAW,YAAY,cAAc,GAAG,gBAAgB;CAEhE,MAAM,EACL,SAAS,EAAE,aACX,iBACG,yBAAyB,UAAU,MAAM;CAE7C,MAAM,WAAW,iBAAiB;AAElC,QACC,oBAAC,UAAD;EACC,aAAU;EACV,cAAW;EACX,aAAU;EACV,eAAa,SAAS,SAAS;EAC/B,MAAK;EACL,eAAe,UAAU,aAAa;EACtC,WAAW,QACV,0BACA,WACA,YAAY,MACZ,YAAY,CAAC,qBAAqB,YAAY,SAAS,CACvD;EACD,GAAI;EACH,CAAA"}
|
|
@@ -57,7 +57,7 @@ declare const DragScrollStoreContextProvider: (props: {
|
|
|
57
57
|
//#endregion
|
|
58
58
|
//#region src/components/ui/drag-scroll/drag-scroll-store.d.ts
|
|
59
59
|
type RequiredUseDragScrollProps = { [Key in keyof Required<UseDragScrollProps>]: UseDragScrollProps[Key] | undefined };
|
|
60
|
-
type InitStoreValues = Pick<RequiredUseDragScrollProps, "orientation" | "scrollAmount"
|
|
60
|
+
type InitStoreValues = Pick<RequiredUseDragScrollProps, "orientation" | "scrollAmount">;
|
|
61
61
|
declare const createDragScrollStore: (initStoreValues: InitStoreValues) => {
|
|
62
62
|
getInitialState: () => DragScrollStore;
|
|
63
63
|
getListeners: () => Set<(state: DragScrollStore, prevState: DragScrollStore) => void>;
|
|
@@ -156,14 +156,6 @@ type UseDragScrollProps = {
|
|
|
156
156
|
* @default "item"
|
|
157
157
|
*/
|
|
158
158
|
scrollAmount?: "item" | number;
|
|
159
|
-
/**
|
|
160
|
-
* Device usage constraints for drag behavior.
|
|
161
|
-
* - `allScreens`: Drag works on all devices
|
|
162
|
-
* - `desktopOnly`: Drag works only on desktop (width >= 768px)
|
|
163
|
-
* - `mobileAndTabletOnly`: Drag works only on mobile/tablet (width < 768px)
|
|
164
|
-
* @default "allScreens"
|
|
165
|
-
*/
|
|
166
|
-
usage?: "allScreens" | "desktopOnly" | "mobileAndTabletOnly";
|
|
167
159
|
};
|
|
168
160
|
type UseDragScrollResult<TContainerElement extends HTMLElement> = Pick<UseDragScrollProps, "disableInternalStateSubscription"> & {
|
|
169
161
|
listRef: React.RefObject<TContainerElement | null>;
|
|
@@ -32,7 +32,7 @@ const handleScrollSnap = (dragContainer) => {
|
|
|
32
32
|
//#endregion
|
|
33
33
|
//#region src/components/ui/drag-scroll/drag-scroll-store.ts
|
|
34
34
|
const createDragScrollStore = (initStoreValues) => {
|
|
35
|
-
const { orientation = "horizontal", scrollAmount = "item"
|
|
35
|
+
const { orientation = "horizontal", scrollAmount = "item" } = initStoreValues;
|
|
36
36
|
const listRef = { current: null };
|
|
37
37
|
const positionRef = { current: {
|
|
38
38
|
left: 0,
|
|
@@ -84,8 +84,6 @@ const createDragScrollStore = (initStoreValues) => {
|
|
|
84
84
|
});
|
|
85
85
|
},
|
|
86
86
|
handleMouseDown: (event) => {
|
|
87
|
-
if (usage === "mobileAndTabletOnly" && window.innerWidth >= 768) return;
|
|
88
|
-
if (usage === "desktopOnly" && window.innerWidth < 768) return;
|
|
89
87
|
if (!listRef.current) return;
|
|
90
88
|
abortControllerRef.current = {
|
|
91
89
|
mouseLeave: new AbortController(),
|
|
@@ -181,19 +179,14 @@ const getDragScrollScopeAttrs = (part) => {
|
|
|
181
179
|
};
|
|
182
180
|
};
|
|
183
181
|
const useDragScroll = (props) => {
|
|
184
|
-
const { disableInternalStateSubscription = false, orientation = "horizontal", scrollAmount = "item"
|
|
182
|
+
const { disableInternalStateSubscription = false, orientation = "horizontal", scrollAmount = "item" } = props ?? {};
|
|
185
183
|
const listRef = useRef(null);
|
|
186
184
|
const storeApi = useMemo(() => {
|
|
187
185
|
return createDragScrollStore({
|
|
188
186
|
orientation,
|
|
189
|
-
scrollAmount
|
|
190
|
-
usage
|
|
187
|
+
scrollAmount
|
|
191
188
|
});
|
|
192
|
-
}, [
|
|
193
|
-
orientation,
|
|
194
|
-
scrollAmount,
|
|
195
|
-
usage
|
|
196
|
-
]);
|
|
189
|
+
}, [orientation, scrollAmount]);
|
|
197
190
|
const actions = storeApi.getState().actions;
|
|
198
191
|
const useDragScrollStore = (selector) => {
|
|
199
192
|
return useStore(storeApi, selector);
|
|
@@ -217,57 +210,52 @@ const useDragScroll = (props) => {
|
|
|
217
210
|
}, [actions]);
|
|
218
211
|
const getRootProps = useCallbackRef((innerProps) => {
|
|
219
212
|
return {
|
|
220
|
-
...getDragScrollScopeAttrs("root"),
|
|
221
213
|
...innerProps,
|
|
214
|
+
...getDragScrollScopeAttrs("root"),
|
|
222
215
|
className: cnMerge("relative", innerProps?.className)
|
|
223
216
|
};
|
|
224
217
|
});
|
|
225
218
|
const getListProps = useCallback((innerProps) => {
|
|
226
219
|
return {
|
|
220
|
+
...innerProps,
|
|
227
221
|
...getDragScrollScopeAttrs("list"),
|
|
228
222
|
...!disableInternalStateSubscription && { "data-dragging": dataAttr(isDragging) },
|
|
229
|
-
|
|
230
|
-
className: cnMerge(`scrollbar-hidden flex w-full cursor-grab snap-x snap-mandatory overflow-x-scroll 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", innerProps?.className),
|
|
223
|
+
className: cnMerge(`scrollbar-hidden flex w-full cursor-grab snap-x snap-mandatory overflow-x-scroll overflow-y-hidden`, orientation === "horizontal" && "flex-row", orientation === "vertical" && "flex-col", innerProps?.className),
|
|
231
224
|
ref: composeRefs(refCallback, innerProps?.ref)
|
|
232
225
|
};
|
|
233
226
|
}, [
|
|
234
227
|
disableInternalStateSubscription,
|
|
235
228
|
isDragging,
|
|
236
229
|
orientation,
|
|
237
|
-
refCallback
|
|
238
|
-
usage
|
|
230
|
+
refCallback
|
|
239
231
|
]);
|
|
240
232
|
const getItemProps = useCallbackRef((innerProps) => {
|
|
241
233
|
return {
|
|
242
|
-
...getDragScrollScopeAttrs("item"),
|
|
243
234
|
...innerProps,
|
|
235
|
+
...getDragScrollScopeAttrs("item"),
|
|
244
236
|
className: cnMerge("snap-center snap-always", innerProps?.className)
|
|
245
237
|
};
|
|
246
238
|
});
|
|
247
239
|
const getPrevButtonProps = useCallback((innerProps) => {
|
|
248
240
|
const isDisabled = innerProps?.disabled ?? !canGoToPrev;
|
|
249
241
|
return {
|
|
250
|
-
...getDragScrollScopeAttrs("prev-button"),
|
|
251
|
-
type: "button",
|
|
252
242
|
...innerProps,
|
|
253
|
-
"
|
|
254
|
-
"aria-label": innerProps?.["aria-label"] ?? "Scroll back",
|
|
243
|
+
...getDragScrollScopeAttrs("prev-button"),
|
|
255
244
|
"data-disabled": dataAttr(isDisabled),
|
|
256
245
|
disabled: isDisabled,
|
|
257
|
-
onClick: composeTwoEventHandlers(actions.goToPrev, innerProps?.onClick)
|
|
246
|
+
onClick: composeTwoEventHandlers(actions.goToPrev, innerProps?.onClick),
|
|
247
|
+
type: "button"
|
|
258
248
|
};
|
|
259
249
|
}, [actions.goToPrev, canGoToPrev]);
|
|
260
250
|
const getNextButtonProps = useCallback((innerProps) => {
|
|
261
251
|
const isDisabled = innerProps?.disabled ?? !canGoToNext;
|
|
262
252
|
return {
|
|
263
|
-
...getDragScrollScopeAttrs("next-button"),
|
|
264
|
-
type: "button",
|
|
265
253
|
...innerProps,
|
|
266
|
-
"
|
|
267
|
-
"aria-label": innerProps?.["aria-label"] ?? "Scroll forward",
|
|
254
|
+
...getDragScrollScopeAttrs("next-button"),
|
|
268
255
|
"data-disabled": dataAttr(isDisabled),
|
|
269
256
|
disabled: isDisabled,
|
|
270
|
-
onClick: composeTwoEventHandlers(actions.goToNext, innerProps?.onClick)
|
|
257
|
+
onClick: composeTwoEventHandlers(actions.goToNext, innerProps?.onClick),
|
|
258
|
+
type: "button"
|
|
271
259
|
};
|
|
272
260
|
}, [actions.goToNext, canGoToNext]);
|
|
273
261
|
const propGetters = useMemo(() => ({
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["Slot.Root"],"sources":["../../../../src/components/ui/drag-scroll/utils.ts","../../../../src/components/ui/drag-scroll/drag-scroll-store.ts","../../../../src/components/ui/drag-scroll/use-drag-scroll.ts","../../../../src/components/ui/drag-scroll/drag-scroll-context.ts","../../../../src/components/ui/drag-scroll/drag-scroll.tsx","../../../../src/components/ui/drag-scroll/drag-scroll-parts.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 { createStore, on, throttleByFrame } from \"@zayne-labs/toolkit-core\";\nimport { isNumber } from \"@zayne-labs/toolkit-type-helpers\";\nimport type { DragScrollStore, UseDragScrollProps } from \"./types\";\nimport { handleScrollSnap, resetCursor, updateCursor } from \"./utils\";\n\ntype RequiredUseDragScrollProps = {\n\t[Key in keyof Required<UseDragScrollProps>]: UseDragScrollProps[Key] | undefined;\n};\n\ntype InitStoreValues = Pick<RequiredUseDragScrollProps, \"orientation\" | \"scrollAmount\">;\n\nexport const createDragScrollStore = (initStoreValues: InitStoreValues) => {\n\tconst { orientation = \"horizontal\", scrollAmount = \"item\" } = initStoreValues;\n\n\tconst listRef: React.RefObject<HTMLElement | null> = {\n\t\tcurrent: null,\n\t};\n\n\tconst positionRef = {\n\t\tcurrent: {\n\t\t\tleft: 0,\n\t\t\ttop: 0,\n\t\t\tx: 0,\n\t\t\ty: 0,\n\t\t},\n\t};\n\n\tconst abortControllerRef = {\n\t\tcurrent: {\n\t\t\tmouseLeave: new AbortController(),\n\t\t\tmouseMove: new AbortController(),\n\t\t\tmouseUp: new AbortController(),\n\t\t},\n\t};\n\n\t// == Calculate scroll amount based on orientation and settings\n\tconst getScrollAmount = (container: HTMLElement): number => {\n\t\tif (isNumber(scrollAmount)) {\n\t\t\treturn scrollAmount;\n\t\t}\n\n\t\tconst firstChild = container.children[0] as HTMLElement | undefined;\n\n\t\tif (!firstChild) {\n\t\t\treturn 0;\n\t\t}\n\n\t\treturn orientation === \"vertical\" || orientation === \"both\" ?\n\t\t\t\tfirstChild.offsetHeight\n\t\t\t:\tfirstChild.offsetWidth;\n\t};\n\n\tconst store = createStore<DragScrollStore>((set, get) => ({\n\t\tcanGoToNext: true,\n\t\tcanGoToPrev: false,\n\t\tisDragging: false,\n\n\t\t// eslint-disable-next-line perfectionist/sort-objects -- actions should be last\n\t\tactions: {\n\t\t\tcleanupDragListeners: () => {\n\t\t\t\tabortControllerRef.current.mouseMove.abort();\n\t\t\t\tabortControllerRef.current.mouseUp.abort();\n\t\t\t\tabortControllerRef.current.mouseLeave.abort();\n\t\t\t},\n\n\t\t\tgoToNext: () => {\n\t\t\t\tif (!listRef.current) return;\n\n\t\t\t\tconst { canGoToNext } = get();\n\t\t\t\tif (!canGoToNext) return;\n\n\t\t\t\tconst amount = getScrollAmount(listRef.current);\n\n\t\t\t\tlistRef.current.scrollBy({\n\t\t\t\t\tbehavior: \"smooth\",\n\t\t\t\t\tleft: orientation === \"vertical\" ? 0 : amount,\n\t\t\t\t\ttop: orientation === \"vertical\" || orientation === \"both\" ? amount : 0,\n\t\t\t\t});\n\t\t\t},\n\n\t\t\tgoToPrev: () => {\n\t\t\t\tif (!listRef.current) return;\n\n\t\t\t\tconst { canGoToPrev } = get();\n\t\t\t\tif (!canGoToPrev) return;\n\n\t\t\t\tconst amount = getScrollAmount(listRef.current);\n\n\t\t\t\tlistRef.current.scrollBy({\n\t\t\t\t\tbehavior: \"smooth\",\n\t\t\t\t\tleft: orientation === \"vertical\" ? 0 : -amount,\n\t\t\t\t\ttop: orientation === \"vertical\" || orientation === \"both\" ? -amount : 0,\n\t\t\t\t});\n\t\t\t},\n\n\t\t\thandleMouseDown: (event) => {\n\t\t\t\tif (!listRef.current) return;\n\n\t\t\t\t// == Create fresh AbortControllers for each drag session (they cannot be reused after abort)\n\t\t\t\tabortControllerRef.current = {\n\t\t\t\t\tmouseLeave: new AbortController(),\n\t\t\t\t\tmouseMove: new AbortController(),\n\t\t\t\t\tmouseUp: new AbortController(),\n\t\t\t\t};\n\n\t\t\t\t// == Update all initial position properties\n\t\t\t\tif (orientation === \"horizontal\" || orientation === \"both\") {\n\t\t\t\t\tpositionRef.current.x = event.clientX;\n\t\t\t\t\tpositionRef.current.left = listRef.current.scrollLeft;\n\t\t\t\t}\n\n\t\t\t\tif (orientation === \"vertical\" || orientation === \"both\") {\n\t\t\t\t\tpositionRef.current.y = event.clientY;\n\t\t\t\t\tpositionRef.current.top = listRef.current.scrollTop;\n\t\t\t\t}\n\n\t\t\t\tupdateCursor(listRef.current);\n\t\t\t\tset({ isDragging: true });\n\n\t\t\t\tconst { actions } = get();\n\n\t\t\t\ton(listRef.current, \"mousemove\", actions.handleMouseMove, {\n\t\t\t\t\tsignal: abortControllerRef.current.mouseMove.signal,\n\t\t\t\t});\n\t\t\t\ton(listRef.current, \"mouseup\", actions.handleMouseUpOrLeave, {\n\t\t\t\t\tsignal: abortControllerRef.current.mouseUp.signal,\n\t\t\t\t});\n\t\t\t\ton(listRef.current, \"mouseleave\", actions.handleMouseUpOrLeave, {\n\t\t\t\t\tsignal: abortControllerRef.current.mouseLeave.signal,\n\t\t\t\t});\n\t\t\t\t// == Document-level mouseup fallback for when user releases outside the container\n\t\t\t\ton(document, \"mouseup\", actions.handleMouseUpOrLeave, {\n\t\t\t\t\tonce: true,\n\t\t\t\t\tsignal: abortControllerRef.current.mouseUp.signal,\n\t\t\t\t});\n\t\t\t},\n\n\t\t\thandleMouseMove: (event) => {\n\t\t\t\tif (!listRef.current) return;\n\n\t\t\t\tif (orientation === \"horizontal\" || orientation === \"both\") {\n\t\t\t\t\tconst dx = event.clientX - positionRef.current.x;\n\t\t\t\t\tlistRef.current.scrollLeft = positionRef.current.left - dx;\n\t\t\t\t}\n\n\t\t\t\tif (orientation === \"vertical\" || orientation === \"both\") {\n\t\t\t\t\tconst dy = event.clientY - positionRef.current.y;\n\t\t\t\t\tlistRef.current.scrollTop = positionRef.current.top - dy;\n\t\t\t\t}\n\t\t\t},\n\n\t\t\thandleMouseUpOrLeave: () => {\n\t\t\t\tif (!listRef.current) return;\n\n\t\t\t\tresetCursor(listRef.current);\n\t\t\t\tset({ isDragging: false });\n\n\t\t\t\tconst { actions } = get();\n\t\t\t\tactions.cleanupDragListeners();\n\t\t\t},\n\n\t\t\thandleScroll: throttleByFrame(() => {\n\t\t\t\tconst { actions } = get();\n\t\t\t\tactions.updateScrollState();\n\t\t\t}),\n\n\t\t\tinitializeResizeObserver: () => {\n\t\t\t\tif (!listRef.current) return;\n\n\t\t\t\tconst { actions } = get();\n\n\t\t\t\t// == Use ResizeObserver to detect when container or children resize\n\t\t\t\tconst resizeObserver = new ResizeObserver(() => actions.updateScrollState());\n\n\t\t\t\tresizeObserver.observe(listRef.current);\n\n\t\t\t\t// == Also observe children for size changes\n\t\t\t\tfor (const child of listRef.current.children) {\n\t\t\t\t\tresizeObserver.observe(child);\n\t\t\t\t}\n\n\t\t\t\tconst cleanup = () => {\n\t\t\t\t\tresizeObserver.disconnect();\n\t\t\t\t};\n\n\t\t\t\treturn cleanup;\n\t\t\t},\n\n\t\t\tsetListRef: (element) => {\n\t\t\t\tlistRef.current = element as HTMLElement;\n\n\t\t\t\tif (!element) return;\n\n\t\t\t\thandleScrollSnap(element);\n\n\t\t\t\tconst { actions } = get();\n\t\t\t\tactions.updateScrollState();\n\t\t\t},\n\n\t\t\tupdateScrollState: () => {\n\t\t\t\tif (!listRef.current) return;\n\n\t\t\t\tif (orientation === \"horizontal\" || orientation === \"both\") {\n\t\t\t\t\tconst { clientWidth, scrollLeft, scrollWidth } = listRef.current;\n\n\t\t\t\t\tset({\n\t\t\t\t\t\tcanGoToNext: Math.ceil(scrollLeft + clientWidth) < scrollWidth,\n\t\t\t\t\t\tcanGoToPrev: Math.floor(scrollLeft) > 0,\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\tif (orientation === \"vertical\") {\n\t\t\t\t\tconst { clientHeight, scrollHeight, scrollTop } = listRef.current;\n\n\t\t\t\t\tset({\n\t\t\t\t\t\tcanGoToNext: Math.ceil(scrollTop + clientHeight) < scrollHeight,\n\t\t\t\t\t\tcanGoToPrev: Math.floor(scrollTop) > 0,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t}));\n\n\treturn store;\n};\n","import { dataAttr, on } from \"@zayne-labs/toolkit-core\";\nimport { useCallbackRef, useStore } from \"@zayne-labs/toolkit-react\";\nimport { composeRefs, composeTwoEventHandlers } from \"@zayne-labs/toolkit-react/utils\";\nimport { useCallback, useEffect, useMemo, useRef } from \"react\";\nimport { cnMerge } from \"@/lib/utils/cn\";\nimport type { FromCamelToKebabCase } from \"@/lib/utils/type-helpers\";\nimport { createDragScrollStore } from \"./drag-scroll-store\";\nimport type { DragScrollPropGetters, PartProps, UseDragScrollProps, UseDragScrollResult } from \"./types\";\n\nexport const getDragScrollScopeAttrs = (part: FromCamelToKebabCase<keyof PartProps>) => {\n\treturn {\n\t\t/* eslint-disable perfectionist/sort-objects -- I need this order to be maintained */\n\t\t\"data-slot\": `drag-scroll-${part}`,\n\t\t\"data-scope\": \"drag-scroll\",\n\t\t\"data-part\": part,\n\t\t/* eslint-enable perfectionist/sort-objects -- I need this order to be maintained */\n\t} as const;\n};\n\nexport const useDragScroll = <TContainerElement extends HTMLElement = HTMLElement>(\n\tprops?: UseDragScrollProps\n): UseDragScrollResult<TContainerElement> => {\n\tconst {\n\t\tdisableInternalStateSubscription = false,\n\t\torientation = \"horizontal\",\n\t\tscrollAmount = \"item\",\n\t} = props ?? {};\n\n\tconst listRef = useRef<TContainerElement>(null);\n\n\tconst storeApi = useMemo(() => {\n\t\treturn createDragScrollStore({ orientation, scrollAmount });\n\t}, [orientation, scrollAmount]);\n\n\tconst actions = storeApi.getState().actions;\n\n\t/* eslint-disable react-hooks/hooks -- ignore */\n\t// eslint-disable-next-line react-x/component-hook-factories -- Ignore\n\tconst useDragScrollStore: UseDragScrollResult<TContainerElement>[\"useDragScrollStore\"] = (selector) => {\n\t\treturn useStore(storeApi as never, selector);\n\t};\n\n\tconst canGoToPrev = useDragScrollStore((state) =>\n\t\t!disableInternalStateSubscription ? state.canGoToPrev : null\n\t);\n\n\tconst canGoToNext = useDragScrollStore((state) =>\n\t\t!disableInternalStateSubscription ? state.canGoToNext : null\n\t);\n\n\tconst isDragging = useDragScrollStore((state) =>\n\t\t!disableInternalStateSubscription ? state.isDragging : null\n\t);\n\t/* eslint-enable react-hooks/hooks -- ignore */\n\n\tconst refCallback: React.RefCallback<TContainerElement> = useCallbackRef((node) => {\n\t\tlistRef.current = node;\n\t\tactions.setListRef(node);\n\n\t\tif (!node) return;\n\n\t\tconst cleanupMouseDown = on(node, \"mousedown\", actions.handleMouseDown);\n\t\tconst cleanupScroll = on(node, \"scroll\", actions.handleScroll, { passive: true });\n\n\t\treturn () => {\n\t\t\tcleanupMouseDown();\n\t\t\tcleanupScroll();\n\t\t};\n\t});\n\n\t// == Update scroll state when children might change (e.g., async loaded content)\n\tuseEffect(() => {\n\t\tconst cleanup = actions.initializeResizeObserver();\n\n\t\treturn cleanup;\n\t}, [actions]);\n\n\tconst getRootProps: DragScrollPropGetters<TContainerElement>[\"getRootProps\"] = useCallbackRef(\n\t\t(innerProps) => {\n\t\t\treturn {\n\t\t\t\t...innerProps,\n\t\t\t\t...getDragScrollScopeAttrs(\"root\"),\n\t\t\t\tclassName: cnMerge(\"relative\", innerProps?.className),\n\t\t\t};\n\t\t}\n\t);\n\n\tconst getListProps: DragScrollPropGetters<TContainerElement>[\"getListProps\"] = useCallback(\n\t\t(innerProps) => {\n\t\t\treturn {\n\t\t\t\t...innerProps,\n\t\t\t\t...getDragScrollScopeAttrs(\"list\"),\n\t\t\t\t...(!disableInternalStateSubscription && {\n\t\t\t\t\t\"data-dragging\": dataAttr(isDragging),\n\t\t\t\t}),\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 overflow-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\tinnerProps?.className\n\t\t\t\t),\n\t\t\t\tref: composeRefs(\n\t\t\t\t\trefCallback,\n\t\t\t\t\t(innerProps as { ref?: React.Ref<TContainerElement> } | undefined)?.ref\n\t\t\t\t),\n\t\t\t} as never;\n\t\t},\n\t\t[disableInternalStateSubscription, isDragging, orientation, refCallback]\n\t);\n\n\tconst getItemProps: DragScrollPropGetters<TContainerElement>[\"getItemProps\"] = useCallbackRef(\n\t\t(innerProps) => {\n\t\t\treturn {\n\t\t\t\t...innerProps,\n\t\t\t\t...getDragScrollScopeAttrs(\"item\"),\n\t\t\t\tclassName: cnMerge(\"snap-center snap-always\", innerProps?.className),\n\t\t\t};\n\t\t}\n\t);\n\n\tconst getPrevButtonProps: DragScrollPropGetters<TContainerElement>[\"getPrevButtonProps\"] = useCallback(\n\t\t(innerProps) => {\n\t\t\tconst isDisabled = innerProps?.disabled ?? !canGoToPrev;\n\n\t\t\treturn {\n\t\t\t\t...innerProps,\n\t\t\t\t...getDragScrollScopeAttrs(\"prev-button\"),\n\t\t\t\t\"data-disabled\": dataAttr(isDisabled),\n\t\t\t\tdisabled: isDisabled,\n\t\t\t\tonClick: composeTwoEventHandlers(actions.goToPrev, innerProps?.onClick),\n\t\t\t\ttype: \"button\",\n\t\t\t};\n\t\t},\n\t\t[actions.goToPrev, canGoToPrev]\n\t);\n\n\tconst getNextButtonProps: DragScrollPropGetters<TContainerElement>[\"getNextButtonProps\"] = useCallback(\n\t\t(innerProps) => {\n\t\t\tconst isDisabled = innerProps?.disabled ?? !canGoToNext;\n\n\t\t\treturn {\n\t\t\t\t...innerProps,\n\t\t\t\t...getDragScrollScopeAttrs(\"next-button\"),\n\t\t\t\t\"data-disabled\": dataAttr(isDisabled),\n\t\t\t\tdisabled: isDisabled,\n\t\t\t\tonClick: composeTwoEventHandlers(actions.goToNext, innerProps?.onClick),\n\t\t\t\ttype: \"button\",\n\t\t\t};\n\t\t},\n\t\t[actions.goToNext, canGoToNext]\n\t);\n\n\tconst propGetters = useMemo<DragScrollPropGetters<TContainerElement>>(\n\t\t() =>\n\t\t\t({\n\t\t\t\tgetItemProps,\n\t\t\t\tgetListProps,\n\t\t\t\tgetNextButtonProps,\n\t\t\t\tgetPrevButtonProps,\n\t\t\t\tgetRootProps,\n\t\t\t}) satisfies DragScrollPropGetters<TContainerElement>,\n\t\t[getPrevButtonProps, getListProps, getItemProps, getNextButtonProps, getRootProps]\n\t);\n\n\tconst stableUseDragScrollStore = useCallbackRef(useDragScrollStore);\n\n\tconst result = useMemo<UseDragScrollResult<TContainerElement>>(\n\t\t() =>\n\t\t\t({\n\t\t\t\tdisableInternalStateSubscription,\n\t\t\t\tlistRef,\n\t\t\t\tpropGetters,\n\t\t\t\tstoreApi,\n\t\t\t\tuseDragScrollStore: stableUseDragScrollStore,\n\t\t\t}) satisfies UseDragScrollResult<TContainerElement>,\n\t\t[propGetters, disableInternalStateSubscription, storeApi, stableUseDragScrollStore]\n\t);\n\n\treturn result;\n};\n","import { createCustomContext } from \"@zayne-labs/toolkit-react\";\nimport { createReactStoreContext } from \"@zayne-labs/toolkit-react/zustand\";\nimport type { DragScrollStore, UseDragScrollResult } from \"./types\";\n\nconst [DragScrollStoreContextProvider, useDragScrollStoreContext] =\n\tcreateReactStoreContext<DragScrollStore>({\n\t\thookName: \"useDragScrollStoreContext\",\n\t\tname: \"DragScrollStoreContext\",\n\t\tproviderName: \"DragScrollRoot\",\n\t});\n\nexport type DragScrollRootContextType<TElement extends HTMLElement = HTMLElement> = Pick<\n\tUseDragScrollResult<TElement>,\n\t\"disableInternalStateSubscription\" | \"listRef\" | \"propGetters\"\n>;\n\nconst [DragScrollRootContextProvider, useDragScrollRootContext] =\n\tcreateCustomContext<DragScrollRootContextType>({\n\t\thookName: \"useDragScrollRootContext\",\n\t\tname: \"DragScrollRootContext\",\n\t\tproviderName: \"DragScrollRoot\",\n\t});\n\nexport {\n\tDragScrollRootContextProvider,\n\tDragScrollStoreContextProvider,\n\tuseDragScrollRootContext,\n\tuseDragScrollStoreContext,\n};\n","\"use client\";\n\nimport { useCompareSelector } from \"@zayne-labs/toolkit-react\";\nimport type { PolymorphicPropsStrict } from \"@zayne-labs/toolkit-react/utils\";\nimport { isFunction, type SelectorFn } from \"@zayne-labs/toolkit-type-helpers\";\nimport { useMemo } from \"react\";\nimport { Slot } from \"@/components/common/slot\";\nimport {\n\tDragScrollRootContextProvider,\n\tDragScrollStoreContextProvider,\n\tuseDragScrollRootContext,\n\tuseDragScrollStoreContext,\n\ttype DragScrollRootContextType,\n} from \"./drag-scroll-context\";\nimport type { DragScrollStore, PartInputProps, UseDragScrollProps } from \"./types\";\nimport { useDragScroll } from \"./use-drag-scroll\";\n\n/* eslint-disable perfectionist/sort-intersection-types -- I need non-standard props to come first */\n\nexport type DragScrollRootProps = UseDragScrollProps & {\n\tasChild?: boolean;\n\tchildren: React.ReactNode;\n} & PartInputProps[\"root\"];\n\nexport function DragScrollRoot(props: DragScrollRootProps) {\n\tconst { asChild, children, ...restOfProps } = props;\n\n\tconst { disableInternalStateSubscription, listRef, propGetters, storeApi } = useDragScroll(restOfProps);\n\n\tconst rootContextValue = useMemo<DragScrollRootContextType>(\n\t\t() =>\n\t\t\t({\n\t\t\t\tdisableInternalStateSubscription,\n\t\t\t\tlistRef,\n\t\t\t\tpropGetters,\n\t\t\t}) satisfies DragScrollRootContextType,\n\t\t[listRef, disableInternalStateSubscription, propGetters]\n\t);\n\n\tconst Component = asChild ? Slot.Root : \"div\";\n\n\treturn (\n\t\t<DragScrollStoreContextProvider store={storeApi}>\n\t\t\t<DragScrollRootContextProvider value={rootContextValue}>\n\t\t\t\t<Component {...propGetters.getRootProps(restOfProps)}>{children}</Component>\n\t\t\t</DragScrollRootContextProvider>\n\t\t</DragScrollStoreContextProvider>\n\t);\n}\n\nexport type DragScrollContextProps<TSlice> = {\n\tchildren: React.ReactNode | ((context: TSlice) => React.ReactNode);\n\tselector?: SelectorFn<DragScrollStore, TSlice>;\n};\n\nexport function DragScrollContext<TSlice = DragScrollStore>(props: DragScrollContextProps<TSlice>) {\n\tconst { children, selector } = props;\n\n\tconst dragScrollCtx = useDragScrollStoreContext(useCompareSelector(selector));\n\n\tconst resolvedChildren = isFunction(children) ? children(dragScrollCtx) : children;\n\n\treturn resolvedChildren;\n}\n\nexport type DragScrollListProps = {\n\tasChild?: boolean;\n} & PartInputProps[\"list\"];\n\nexport function DragScrollList<TElement extends React.ElementType = \"ul\">(\n\tprops: PolymorphicPropsStrict<TElement, DragScrollListProps>\n) {\n\tconst { as: Element = \"ul\", asChild, ...restOfProps } = props;\n\n\tconst { propGetters } = useDragScrollRootContext();\n\n\tconst Component = asChild ? Slot.Root : Element;\n\n\treturn <Component {...propGetters.getListProps(restOfProps)} />;\n}\n\nexport type DragScrollItemProps = {\n\tasChild?: boolean;\n} & PartInputProps[\"item\"];\n\nexport function DragScrollItem<TElement extends React.ElementType = \"li\">(\n\tprops: PolymorphicPropsStrict<TElement, DragScrollItemProps>\n) {\n\tconst { as: Element = \"li\", asChild, ...restOfProps } = props;\n\n\tconst { propGetters } = useDragScrollRootContext();\n\n\tconst Component = asChild ? Slot.Root : Element;\n\n\treturn <Component {...propGetters.getItemProps(restOfProps)} />;\n}\n\nexport type DragScrollPrevProps = {\n\tasChild?: boolean;\n} & PartInputProps[\"prevButton\"];\n\nexport function DragScrollPrev(props: DragScrollPrevProps) {\n\tconst { asChild, ...restOfProps } = props;\n\n\tconst { propGetters } = useDragScrollRootContext();\n\n\tconst Component = asChild ? Slot.Root : \"button\";\n\n\treturn <Component {...propGetters.getPrevButtonProps(restOfProps)} />;\n}\n\nexport type DragScrollNextProps = {\n\tasChild?: boolean;\n} & PartInputProps[\"nextButton\"];\n\nexport function DragScrollNext(props: DragScrollNextProps) {\n\tconst { asChild, ...restOfProps } = props;\n\n\tconst { propGetters } = useDragScrollRootContext();\n\n\tconst Component = asChild ? Slot.Root : \"button\";\n\n\treturn <Component {...propGetters.getNextButtonProps(restOfProps)} />;\n}\n\n/* eslint-enable perfectionist/sort-intersection-types -- I need non-standard props to come first */\n","export {\n\tDragScrollContext as Context,\n\tDragScrollItem as Item,\n\tDragScrollNext as Next,\n\tDragScrollPrev as Prev,\n\tDragScrollRoot as Root,\n\tDragScrollList as List,\n} from \"./drag-scroll\";\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;;;;ACrBtC,MAAa,yBAAyB,oB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Context) => {
|
|
|
33
33
|
subscribe: _$_zayne_labs_toolkit_core0.SubscribeFn<DropZoneStore>;
|
|
34
34
|
};
|
|
35
35
|
//#endregion
|
|
36
|
-
//#region src/components/ui/drop-zone/utils.d.ts
|
|
37
|
-
declare class DropZoneError extends Error {
|
|
38
|
-
readonly dropZoneErrorSymbol: symbol;
|
|
39
|
-
file?: FileValidationErrorContextEach["file"];
|
|
40
|
-
name: "DropZoneError";
|
|
41
|
-
constructor(ctx: Pick<FileValidationErrorContextEach, "message"> & {
|
|
42
|
-
file?: FileValidationErrorContextEach["file"];
|
|
43
|
-
}, errorOptions?: ErrorOptions);
|
|
44
|
-
static isError(error: unknown): error is DropZoneError;
|
|
45
|
-
}
|
|
46
|
-
//#endregion
|
|
47
36
|
//#region src/components/ui/drop-zone/types.d.ts
|
|
48
37
|
type FileErrorContext = Omit<FileValidationErrorContextEach, "code"> & {
|
|
49
38
|
code: "upload-error" | FileValidationErrorContextEach["code"];
|
|
@@ -89,11 +78,11 @@ type SharedInputProps = {
|
|
|
89
78
|
};
|
|
90
79
|
interface PartProps {
|
|
91
80
|
container: {
|
|
92
|
-
input: PartProps["container"]["output"]
|
|
81
|
+
input: SharedInputProps & PartProps["container"]["output"];
|
|
93
82
|
output: RecordForDataAttr & InferProps<HTMLElement>;
|
|
94
83
|
};
|
|
95
84
|
fileItem: {
|
|
96
|
-
input: PartProps["fileItem"]["output"]
|
|
85
|
+
input: SharedInputProps & PartProps["fileItem"]["output"];
|
|
97
86
|
output: RecordForDataAttr & InferProps<"li">;
|
|
98
87
|
};
|
|
99
88
|
fileItemClear: {
|
|
@@ -128,6 +117,10 @@ interface PartProps {
|
|
|
128
117
|
input: PartProps["input"]["output"];
|
|
129
118
|
output: RecordForDataAttr & InferProps<"input">;
|
|
130
119
|
};
|
|
120
|
+
root: {
|
|
121
|
+
input: SharedInputProps & PartProps["root"]["output"];
|
|
122
|
+
output: RecordForDataAttr & InferProps<"div">;
|
|
123
|
+
};
|
|
131
124
|
trigger: {
|
|
132
125
|
input: PartProps["trigger"]["output"];
|
|
133
126
|
output: RecordForDataAttr & InferProps<"button">;
|
|
@@ -221,7 +214,7 @@ interface UseDropZoneProps extends FileValidationSettingsAsync, Pick<SharedInput
|
|
|
221
214
|
*/
|
|
222
215
|
onUpload?: (context: Pick<DropZoneState, "fileStateArray"> & {
|
|
223
216
|
onError: (ctx: FileStateOrIDProp & {
|
|
224
|
-
error:
|
|
217
|
+
error: unknown;
|
|
225
218
|
}) => void;
|
|
226
219
|
onProgress: (ctx: FileStateOrIDProp & {
|
|
227
220
|
progress: number;
|
|
@@ -300,9 +293,9 @@ type FileItemContextType = {
|
|
|
300
293
|
//#endregion
|
|
301
294
|
//#region src/components/ui/drop-zone/drop-zone.d.ts
|
|
302
295
|
type DropZoneRootProps = UseDropZoneProps & {
|
|
303
|
-
|
|
304
|
-
};
|
|
305
|
-
declare function DropZoneRoot(props: DropZoneRootProps): _$react_jsx_runtime0.JSX.Element;
|
|
296
|
+
asChild?: boolean;
|
|
297
|
+
} & PartInputProps["root"];
|
|
298
|
+
declare function DropZoneRoot<TElement extends React.ElementType = "div">(props: PolymorphicPropsStrict<TElement, DropZoneRootProps>): _$react_jsx_runtime0.JSX.Element;
|
|
306
299
|
type DropZoneContextProps<TSlice> = {
|
|
307
300
|
children: React.ReactNode | ((context: TSlice) => React.ReactNode);
|
|
308
301
|
selector?: SelectorFn<DropZoneStore, TSlice>;
|
|
@@ -430,5 +423,16 @@ declare namespace drop_zone_parts_d_exports {
|
|
|
430
423
|
//#region src/components/ui/drop-zone/use-drop-zone.d.ts
|
|
431
424
|
declare const useDropZone: (props?: UseDropZoneProps) => UseDropZoneResult;
|
|
432
425
|
//#endregion
|
|
426
|
+
//#region src/components/ui/drop-zone/utils.d.ts
|
|
427
|
+
declare class DropZoneError extends Error {
|
|
428
|
+
readonly dropZoneErrorSymbol: symbol;
|
|
429
|
+
file?: FileValidationErrorContextEach["file"];
|
|
430
|
+
name: "DropZoneError";
|
|
431
|
+
constructor(ctx: Pick<FileValidationErrorContextEach, "message"> & {
|
|
432
|
+
file?: FileValidationErrorContextEach["file"];
|
|
433
|
+
}, errorOptions?: ErrorOptions);
|
|
434
|
+
static isError(error: unknown): error is DropZoneError;
|
|
435
|
+
}
|
|
436
|
+
//#endregion
|
|
433
437
|
export { drop_zone_parts_d_exports as DropZone, type DropZoneActions, DropZoneArea, DropZoneAreaProps, DropZoneContainer, DropZoneContainerProps, DropZoneContext, DropZoneContextProps, DropZoneError, DropZoneFileClear, DropZoneFileClearProps, DropZoneFileItem, DropZoneFileItemDelete, DropZoneFileItemDeleteProps, DropZoneFileItemMetadata, DropZoneFileItemMetadataProps, DropZoneFileItemPreview, DropZoneFileItemPreviewProps, DropZoneFileItemProgress, DropZoneFileItemProgressProps, DropZoneFileItemProps, DropZoneFileList, DropZoneFileListProps, DropZoneInput, DropZoneInputProps, DropZoneRoot, DropZoneRootProps, type DropZoneState, type DropZoneStore, DropZoneTrigger, DropZoneTriggerProps, type FileState, type UseDropZoneProps, type UseDropZoneResult, useDropZone, useDropZoneStoreContext };
|
|
434
438
|
//# sourceMappingURL=index.d.ts.map
|